Skip to content

@codesoul-co/hypha-memory / context-gateway

模块用法

用于使用该功能边界的公共契约与操作。Context gateway 模块公开 1 类、4 接口、1 类型。

从包入口导入

ts
import {
  DefaultMemoryContextGateway,
} from '@codesoul-co/hypha-memory';

import type {
  ContextGatewayRequest,
  ContextGatewayResult,
  DefaultMemoryContextGatewayOptions,
  MemoryContextGateway,
  ContextGatewayConsumer,
} from '@codesoul-co/hypha-memory';

使用要点

  • 5 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 1 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。

公共导出

Symbol种类签名说明
DefaultMemoryContextGatewaynew DefaultMemoryContextGateway(options: DefaultMemoryContextGatewayOptions): DefaultMemoryContextGatewayCanonical Context entry point shared by Chat, Workflow, and Harness consumers.
ContextGatewayRequest接口interface ContextGatewayRequest extends ResolvedContextBuildInputContext Gateway Request 接口,共包含 20 个公开字段或方法。
ContextGatewayResult接口interface ContextGatewayResultContext Gateway Result 接口,共包含 4 个公开字段或方法。
DefaultMemoryContextGatewayOptions接口interface DefaultMemoryContextGatewayOptionsDefault Memory Context Gateway Options 接口,共包含 5 个公开字段或方法。
MemoryContextGateway接口interface MemoryContextGatewayMemory Context Gateway 接口,共包含 1 个公开字段或方法。
ContextGatewayConsumer类型type ContextGatewayConsumer = 'chat' | 'workflow' | 'harness'Context Gateway Consumer 公共类型别名;完整类型表达式见声明。

DefaultMemoryContextGateway

Canonical Context entry point shared by Chat, Workflow, and Harness consumers.

  • 种类: 类
  • 导入: import { DefaultMemoryContextGateway } from '@codesoul-co/hypha-memory';
  • 源码模块: context-gateway

声明

text
export declare class DefaultMemoryContextGateway implements MemoryContextGateway {
    constructor(options: DefaultMemoryContextGatewayOptions);
    build(request: ContextGatewayRequest, signal?: AbortSignal): Promise<ContextGatewayResult>;
}

公开成员

成员种类签名说明
build方法build(request: ContextGatewayRequest, signal?: AbortSignal): Promise<ContextGatewayResult>公开方法;参数与返回类型以签名列为准。
constructor构造函数(options: DefaultMemoryContextGatewayOptions): DefaultMemoryContextGateway创建该类的实例。

ContextGatewayRequest

Context Gateway Request 接口,共包含 20 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ContextGatewayRequest } from '@codesoul-co/hypha-memory';
  • 源码模块: context-gateway

声明

text
export interface ContextGatewayRequest extends ResolvedContextBuildInput {
    consumer: ContextGatewayConsumer;
}

契约成员

成员种类签名说明
consumer属性consumer: ContextGatewayConsumer公开属性;类型、只读和可选状态以签名列为准。
explicitSourceRefs属性explicitSourceRefs?: string[]公开属性;类型、只读和可选状态以签名列为准。
messageCursor属性messageCursor?: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
modelContextWindowTokens属性modelContextWindowTokens: number公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
previousContextHash属性previousContextHash?: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal: MemoryPrincipal公开属性;类型、只读和可选状态以签名列为准。
profile属性profile: ContextProfileSpec公开属性;类型、只读和可选状态以签名列为准。
profileRef属性profileRef: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
query属性query?: string公开属性;类型、只读和可选状态以签名列为准。
reservedInstructionTokens属性reservedInstructionTokens: number公开属性;类型、只读和可选状态以签名列为准。
reservedOutputTokens属性reservedOutputTokens: number公开属性;类型、只读和可选状态以签名列为准。
reservedSystemTokens属性reservedSystemTokens: number公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
runtimeStateRef属性runtimeStateRef?: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: ManagedMemoryScope公开属性;类型、只读和可选状态以签名列为准。
stateId属性stateId?: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tokenizerRef属性tokenizerRef?: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。

ContextGatewayResult

Context Gateway Result 接口,共包含 4 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ContextGatewayResult } from '@codesoul-co/hypha-memory';
  • 源码模块: context-gateway

声明

text
export interface ContextGatewayResult {
    envelope: ContextEnvelope;
    explanation: ContextBuildExplanation;
    sourceItemCount: number;
    consumer: ContextGatewayConsumer;
}

契约成员

成员种类签名说明
consumer属性consumer: ContextGatewayConsumer公开属性;类型、只读和可选状态以签名列为准。
envelope属性envelope: ContextEnvelope公开属性;类型、只读和可选状态以签名列为准。
explanation属性explanation: ContextBuildExplanation公开属性;类型、只读和可选状态以签名列为准。
sourceItemCount属性sourceItemCount: number公开属性;类型、只读和可选状态以签名列为准。

DefaultMemoryContextGatewayOptions

Default Memory Context Gateway Options 接口,共包含 5 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { DefaultMemoryContextGatewayOptions } from '@codesoul-co/hypha-memory';
  • 源码模块: context-gateway

声明

text
export interface DefaultMemoryContextGatewayOptions {
    resolver: ContextSourceResolverRegistry;
    builder: MemoryContextBuilder;
    injection: ContextInjectionGateway;
    activityHook?: MemoryActivityHarnessHook;
    eventContext?: (request: ContextGatewayRequest) => MemoryActivityRequest['eventContext'];
}

契约成员

成员种类签名说明
activityHook属性activityHook?: MemoryActivityHarnessHook公开属性;类型、只读和可选状态以签名列为准。
builder属性builder: MemoryContextBuilder公开属性;类型、只读和可选状态以签名列为准。
eventContext方法eventContext?(request: ContextGatewayRequest): MemoryActivityRequest["eventContext"]公开方法;参数与返回类型以签名列为准。
injection属性injection: ContextInjectionGateway公开属性;类型、只读和可选状态以签名列为准。
resolver属性resolver: ContextSourceResolverRegistry公开属性;类型、只读和可选状态以签名列为准。

MemoryContextGateway

Memory Context Gateway 接口,共包含 1 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { MemoryContextGateway } from '@codesoul-co/hypha-memory';
  • 源码模块: context-gateway

声明

text
export interface MemoryContextGateway {
    build(request: ContextGatewayRequest, signal?: AbortSignal): Promise<ContextGatewayResult>;
}

契约成员

成员种类签名说明
build方法build(request: ContextGatewayRequest, signal?: AbortSignal): Promise<ContextGatewayResult>公开方法;参数与返回类型以签名列为准。

ContextGatewayConsumer

Context Gateway Consumer 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { ContextGatewayConsumer } from '@codesoul-co/hypha-memory';
  • 源码模块: context-gateway

声明

text
export type ContextGatewayConsumer = 'chat' | 'workflow' | 'harness';