Skip to content

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

模块用法

用于声明并运行时校验契约。Context contracts 模块公开 28 接口、1 类型。

从包入口导入

ts
import type {
  ContextBudgetPlan,
  ContextBuildExplanation,
  ContextBuildInput,
  ContextBuildRequest,
  ContextBundle,
  ContextCompactionPolicySpec,
  ContextConflict,
  ContextEnvelope,
} from '@codesoul-co/hypha-memory';

// 完整导出列表见下方。

使用要点

  • 29 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。

公共导出

Symbol种类签名说明
ContextBudgetPlan接口interface ContextBudgetPlanContext Budget Plan 接口,共包含 6 个公开字段或方法。
ContextBuildExplanation接口interface ContextBuildExplanationContext Build Explanation 接口,共包含 6 个公开字段或方法。
ContextBuildInput接口interface ContextBuildInput extends ContextBuildRequestContext Build Input 接口,共包含 20 个公开字段或方法。
ContextBuildRequest接口interface ContextBuildRequestContext Build Request 接口,共包含 17 个公开字段或方法。
ContextBundle接口interface ContextBundleContext Bundle 接口,共包含 16 个公开字段或方法。
ContextCompactionPolicySpec接口interface ContextCompactionPolicySpecContext Compaction Policy Spec 接口,共包含 6 个公开字段或方法。
ContextConflict接口interface ContextConflictContext Conflict 接口,共包含 3 个公开字段或方法。
ContextEnvelope接口interface ContextEnvelopeContext Envelope 接口,共包含 17 个公开字段或方法。
ContextInjectionGateway接口interface ContextInjectionGatewayContext Injection Gateway 接口,共包含 1 个公开字段或方法。
ContextItem接口interface ContextItemContext Item 接口,共包含 14 个公开字段或方法。
ContextItemPolicyDecision接口interface ContextItemPolicyDecisionContext Item Policy Decision 接口,共包含 2 个公开字段或方法。
ContextItemPolicyEvaluator接口interface ContextItemPolicyEvaluatorContext Item Policy Evaluator 接口,共包含 1 个公开字段或方法。
ContextItemPolicyInput接口interface ContextItemPolicyInputContext Item Policy Input 接口,共包含 5 个公开字段或方法。
ContextProfileSpec接口interface ContextProfileSpecContext Profile Spec 接口,共包含 23 个公开字段或方法。
ContextProvenanceLabel接口interface ContextProvenanceLabelContext Provenance Label 接口,共包含 7 个公开字段或方法。
ContextRankingPolicySpec接口interface ContextRankingPolicySpecContext Ranking Policy Spec 接口,共包含 8 个公开字段或方法。
ContextRejectedItem接口interface ContextRejectedItemContext Rejected Item 接口,共包含 2 个公开字段或方法。
ContextSourceBudget接口interface ContextSourceBudgetContext Source Budget 接口,共包含 6 个公开字段或方法。
ContextSourceResolutionInput接口interface ContextSourceResolutionInput extends ResolvedContextBuildInputContext Source Resolution Input 接口,共包含 20 个公开字段或方法。
ContextSourceResolver接口interface ContextSourceResolverContext Source Resolver 接口,共包含 3 个公开字段或方法。
ContextSourceResolverRegistry接口interface ContextSourceResolverRegistryContext Source Resolver Registry 接口,共包含 1 个公开字段或方法。
ContextSourceSpec接口interface ContextSourceSpecContext Source Spec 接口,共包含 9 个公开字段或方法。
ContextTruncationPolicySpec接口interface ContextTruncationPolicySpecContext Truncation Policy Spec 接口,共包含 5 个公开字段或方法。
ContextTruncationRecord接口interface ContextTruncationRecordContext Truncation Record 接口,共包含 5 个公开字段或方法。
MemoryContextBuilder接口interface MemoryContextBuilderMemory Context Builder 接口,共包含 2 个公开字段或方法。
PromptSegment接口interface PromptSegmentPrompt Segment 接口,共包含 8 个公开字段或方法。
ResolvedContextBuildInput接口interface ResolvedContextBuildInput extends ContextBuildRequestResolved Context Build Input 接口,共包含 19 个公开字段或方法。
TokenEstimator接口interface TokenEstimatorToken Estimator 接口,共包含 2 个公开字段或方法。
ContextSourceType类型type ContextSourceType = 'system' | 'workflow_state' | 'messages' | 'working_memory' | 'long_term_memory' | 'tool_observation' | 'artifact' | 'human_review' | 'custom'Context Source Type 公共类型别名;完整类型表达式见声明。

ContextBudgetPlan

Context Budget Plan 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface ContextBudgetPlan {
    totalAvailableTokens: number;
    fixedTokens: number;
    dynamicTokens: number;
    sourceBudgets: ContextSourceBudget[];
    tokenizerRef: MemoryContractSpecRef;
    safetyMarginTokens: number;
}

契约成员

成员种类签名说明
dynamicTokens属性dynamicTokens: number公开属性;类型、只读和可选状态以签名列为准。
fixedTokens属性fixedTokens: number公开属性;类型、只读和可选状态以签名列为准。
safetyMarginTokens属性safetyMarginTokens: number公开属性;类型、只读和可选状态以签名列为准。
sourceBudgets属性sourceBudgets: ContextSourceBudget[]公开属性;类型、只读和可选状态以签名列为准。
tokenizerRef属性tokenizerRef: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
totalAvailableTokens属性totalAvailableTokens: number公开属性;类型、只读和可选状态以签名列为准。

ContextBuildExplanation

Context Build Explanation 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface ContextBuildExplanation {
    contextHash: string;
    selectedItemIds: string[];
    omittedItemIds: string[];
    rejectedItems: ContextRejectedItem[];
    ranking: Array<{
        itemId: string;
        score: number;
        reasons: string[];
    }>;
    budgetPlan: ContextBudgetPlan;
}

契约成员

成员种类签名说明
budgetPlan属性budgetPlan: ContextBudgetPlan公开属性;类型、只读和可选状态以签名列为准。
contextHash属性contextHash: string公开属性;类型、只读和可选状态以签名列为准。
omittedItemIds属性omittedItemIds: string[]公开属性;类型、只读和可选状态以签名列为准。
ranking属性ranking: { itemId: string; score: number; reasons: string[]; }[]公开属性;类型、只读和可选状态以签名列为准。
rejectedItems属性rejectedItems: ContextRejectedItem[]公开属性;类型、只读和可选状态以签名列为准。
selectedItemIds属性selectedItemIds: string[]公开属性;类型、只读和可选状态以签名列为准。

ContextBuildInput

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

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

声明

text
export interface ContextBuildInput extends ContextBuildRequest {
    profile: ContextProfileSpec;
    sourceItems: ContextItem[];
    tokenizerRef?: MemoryContractSpecRef;
}

契约成员

成员种类签名说明
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公开属性;类型、只读和可选状态以签名列为准。
sourceItems属性sourceItems: ContextItem[]公开属性;类型、只读和可选状态以签名列为准。
stateId属性stateId?: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tokenizerRef属性tokenizerRef?: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。

ContextBuildRequest

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

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

声明

text
export interface ContextBuildRequest {
    operationId: string;
    principal: MemoryPrincipal;
    scope: ManagedMemoryScope;
    runId: string;
    stepId?: string;
    stateId?: string;
    profileRef: MemoryContractSpecRef;
    modelContextWindowTokens: number;
    reservedSystemTokens: number;
    reservedInstructionTokens: number;
    reservedOutputTokens: number;
    runtimeStateRef?: string;
    messageCursor?: string;
    explicitSourceRefs?: string[];
    query?: string;
    previousContextHash?: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
explicitSourceRefs属性explicitSourceRefs?: string[]公开属性;类型、只读和可选状态以签名列为准。
messageCursor属性messageCursor?: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
modelContextWindowTokens属性modelContextWindowTokens: number公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
previousContextHash属性previousContextHash?: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal: MemoryPrincipal公开属性;类型、只读和可选状态以签名列为准。
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公开属性;类型、只读和可选状态以签名列为准。

ContextBundle

Context Bundle 接口,共包含 16 个公开字段或方法。

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

声明

text
export interface ContextBundle {
    id: string;
    runId: string;
    stepId?: string;
    profileRef: MemoryContractSpecRef;
    profileRevision: string;
    items: ContextItem[];
    totalTokens: number;
    totalCharacters: number;
    omittedItemIds: string[];
    rejectedItems: ContextRejectedItem[];
    conflicts: ContextConflict[];
    sourceHashes: Record<string, string>;
    contextHash: string;
    createdAt: string;
    metadata?: Record<string, unknown>;
    artifactRefs?: ContextArtifactRef[];
}

契约成员

成员种类签名说明
artifactRefs属性artifactRefs?: ContextArtifactRef[]公开属性;类型、只读和可选状态以签名列为准。
conflicts属性conflicts: ContextConflict[]公开属性;类型、只读和可选状态以签名列为准。
contextHash属性contextHash: string公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
items属性items: ContextItem[]公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
omittedItemIds属性omittedItemIds: string[]公开属性;类型、只读和可选状态以签名列为准。
profileRef属性profileRef: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
profileRevision属性profileRevision: string公开属性;类型、只读和可选状态以签名列为准。
rejectedItems属性rejectedItems: ContextRejectedItem[]公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
sourceHashes属性sourceHashes: Record<string, string>公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
totalCharacters属性totalCharacters: number公开属性;类型、只读和可选状态以签名列为准。
totalTokens属性totalTokens: number公开属性;类型、只读和可选状态以签名列为准。

ContextCompactionPolicySpec

Context Compaction Policy Spec 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface ContextCompactionPolicySpec {
    enabled: boolean;
    triggerRatio: number;
    summaryProviderRef?: MemoryContractSpecRef;
    preserveLastMessages?: number;
    persistSummaryAsMemory?: boolean;
    summaryMemoryType?: import('./contracts').ManagedMemoryType;
}

契约成员

成员种类签名说明
enabled属性enabled: boolean公开属性;类型、只读和可选状态以签名列为准。
persistSummaryAsMemory属性persistSummaryAsMemory?: boolean公开属性;类型、只读和可选状态以签名列为准。
preserveLastMessages属性preserveLastMessages?: number公开属性;类型、只读和可选状态以签名列为准。
summaryMemoryType属性summaryMemoryType?: import("/Users/erwin/Downloads/codespace/Hypha/packages/memory/dist/contracts").ManagedMemoryType公开属性;类型、只读和可选状态以签名列为准。
summaryProviderRef属性summaryProviderRef?: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
triggerRatio属性triggerRatio: number公开属性;类型、只读和可选状态以签名列为准。

ContextConflict

Context Conflict 接口,共包含 3 个公开字段或方法。

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

声明

text
export interface ContextConflict {
    conflictGroupId: string;
    itemIds: string[];
    resolution?: string;
}

契约成员

成员种类签名说明
conflictGroupId属性conflictGroupId: string公开属性;类型、只读和可选状态以签名列为准。
itemIds属性itemIds: string[]公开属性;类型、只读和可选状态以签名列为准。
resolution属性resolution?: string公开属性;类型、只读和可选状态以签名列为准。

ContextEnvelope

Context Envelope 接口,共包含 17 个公开字段或方法。

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

声明

text
export interface ContextEnvelope {
    id: string;
    runId: string;
    stepId?: string;
    contextHash: string;
    profileRevision: string;
    budgetPlan: ContextBudgetPlan;
    systemSegments: PromptSegment[];
    instructionSegments: PromptSegment[];
    dataSegments: PromptSegment[];
    includedSourceRefs: string[];
    omittedSourceRefs: string[];
    truncationRecords: ContextTruncationRecord[];
    provenanceIndex: Record<string, ContextProvenanceLabel>;
    conflicts: ContextConflict[];
    totalTokens: number;
    createdAt: string;
    artifactRefs?: ContextArtifactRef[];
}

契约成员

成员种类签名说明
artifactRefs属性artifactRefs?: ContextArtifactRef[]公开属性;类型、只读和可选状态以签名列为准。
budgetPlan属性budgetPlan: ContextBudgetPlan公开属性;类型、只读和可选状态以签名列为准。
conflicts属性conflicts: ContextConflict[]公开属性;类型、只读和可选状态以签名列为准。
contextHash属性contextHash: string公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
dataSegments属性dataSegments: PromptSegment[]公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
includedSourceRefs属性includedSourceRefs: string[]公开属性;类型、只读和可选状态以签名列为准。
instructionSegments属性instructionSegments: PromptSegment[]公开属性;类型、只读和可选状态以签名列为准。
omittedSourceRefs属性omittedSourceRefs: string[]公开属性;类型、只读和可选状态以签名列为准。
profileRevision属性profileRevision: string公开属性;类型、只读和可选状态以签名列为准。
provenanceIndex属性provenanceIndex: Record<string, ContextProvenanceLabel>公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
systemSegments属性systemSegments: PromptSegment[]公开属性;类型、只读和可选状态以签名列为准。
totalTokens属性totalTokens: number公开属性;类型、只读和可选状态以签名列为准。
truncationRecords属性truncationRecords: ContextTruncationRecord[]公开属性;类型、只读和可选状态以签名列为准。

ContextInjectionGateway

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

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

声明

text
export interface ContextInjectionGateway {
    buildEnvelope(bundle: ContextBundle, profile: ContextProfileSpec): Promise<ContextEnvelope>;
}

契约成员

成员种类签名说明
buildEnvelope方法buildEnvelope(bundle: ContextBundle, profile: ContextProfileSpec): Promise<ContextEnvelope>公开方法;参数与返回类型以签名列为准。

ContextItem

Context Item 接口,共包含 14 个公开字段或方法。

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

声明

text
export interface ContextItem {
    id: string;
    sourceType: ContextSourceType;
    sourceId?: string;
    content: unknown;
    text: string;
    tokenEstimate: number;
    priority: number;
    score?: number;
    required?: boolean;
    untrusted?: boolean;
    provenance?: MemoryProvenance | Record<string, unknown>;
    conflictGroupId?: string;
    metadata?: Record<string, unknown>;
    artifactRef?: ContextArtifactRef;
}

契约成员

成员种类签名说明
artifactRef属性artifactRef?: ContextArtifactRef公开属性;类型、只读和可选状态以签名列为准。
conflictGroupId属性conflictGroupId?: string公开属性;类型、只读和可选状态以签名列为准。
content属性content: unknown公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
priority属性priority: number公开属性;类型、只读和可选状态以签名列为准。
provenance属性provenance?: Record<string, unknown> | MemoryProvenance公开属性;类型、只读和可选状态以签名列为准。
required属性required?: boolean公开属性;类型、只读和可选状态以签名列为准。
score属性score?: number公开属性;类型、只读和可选状态以签名列为准。
sourceId属性sourceId?: string公开属性;类型、只读和可选状态以签名列为准。
sourceType属性sourceType: ContextSourceType公开属性;类型、只读和可选状态以签名列为准。
text属性text: string公开属性;类型、只读和可选状态以签名列为准。
tokenEstimate属性tokenEstimate: number公开属性;类型、只读和可选状态以签名列为准。
untrusted属性untrusted?: boolean公开属性;类型、只读和可选状态以签名列为准。

ContextItemPolicyDecision

Context Item Policy Decision 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface ContextItemPolicyDecision {
    allowed: boolean;
    reason?: string;
}

契约成员

成员种类签名说明
allowed属性allowed: boolean公开属性;类型、只读和可选状态以签名列为准。
reason属性reason?: string公开属性;类型、只读和可选状态以签名列为准。

ContextItemPolicyEvaluator

Context Item Policy Evaluator 接口,共包含 1 个公开字段或方法。

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

声明

text
export interface ContextItemPolicyEvaluator {
    evaluate(input: ContextItemPolicyInput): Promise<ContextItemPolicyDecision>;
}

契约成员

成员种类签名说明
evaluate方法evaluate(input: ContextItemPolicyInput): Promise<ContextItemPolicyDecision>公开方法;参数与返回类型以签名列为准。

ContextItemPolicyInput

Context Item Policy Input 接口,共包含 5 个公开字段或方法。

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

声明

text
export interface ContextItemPolicyInput {
    operationId: string;
    principal: MemoryPrincipal;
    scope: ManagedMemoryScope;
    profileRef: MemoryContractSpecRef;
    item: ContextItem;
}

契约成员

成员种类签名说明
item属性item: ContextItem公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
principal属性principal: MemoryPrincipal公开属性;类型、只读和可选状态以签名列为准。
profileRef属性profileRef: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: ManagedMemoryScope公开属性;类型、只读和可选状态以签名列为准。

ContextProfileSpec

Context Profile Spec 接口,共包含 23 个公开字段或方法。

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

声明

text
export interface ContextProfileSpec {
    id: string;
    version: string;
    revision?: string;
    name?: string;
    description?: string;
    sources: ContextSourceSpec[];
    maxItems?: number;
    maxCharacters?: number;
    maxSerializedBytes?: number;
    maxTokens: number;
    reservedOutputTokens?: number;
    reservedSystemTokens?: number;
    deduplication: 'none' | 'id' | 'hash' | 'semantic';
    semanticDedupThreshold?: number;
    ranking: ContextRankingPolicySpec;
    truncation: ContextTruncationPolicySpec;
    conflictPolicy?: 'include_marked' | 'prefer_latest' | 'prefer_verified';
    includeProvenance: boolean;
    includeScores?: boolean;
    instructionBoundary: 'strict' | 'tagged' | 'quoted';
    untrustedContentPolicy: 'escape' | 'tag' | 'reject';
    compactionPolicy?: ContextCompactionPolicySpec;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
compactionPolicy属性compactionPolicy?: ContextCompactionPolicySpec公开属性;类型、只读和可选状态以签名列为准。
conflictPolicy属性conflictPolicy?: "include_marked" | "prefer_latest" | "prefer_verified"公开属性;类型、只读和可选状态以签名列为准。
deduplication属性deduplication: "none" | "id" | "semantic" | "hash"公开属性;类型、只读和可选状态以签名列为准。
description属性description?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
includeProvenance属性includeProvenance: boolean公开属性;类型、只读和可选状态以签名列为准。
includeScores属性includeScores?: boolean公开属性;类型、只读和可选状态以签名列为准。
instructionBoundary属性instructionBoundary: "strict" | "tagged" | "quoted"公开属性;类型、只读和可选状态以签名列为准。
maxCharacters属性maxCharacters?: number公开属性;类型、只读和可选状态以签名列为准。
maxItems属性maxItems?: number公开属性;类型、只读和可选状态以签名列为准。
maxSerializedBytes属性maxSerializedBytes?: number公开属性;类型、只读和可选状态以签名列为准。
maxTokens属性maxTokens: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
name属性name?: string公开属性;类型、只读和可选状态以签名列为准。
ranking属性ranking: ContextRankingPolicySpec公开属性;类型、只读和可选状态以签名列为准。
reservedOutputTokens属性reservedOutputTokens?: number公开属性;类型、只读和可选状态以签名列为准。
reservedSystemTokens属性reservedSystemTokens?: number公开属性;类型、只读和可选状态以签名列为准。
revision属性revision?: string公开属性;类型、只读和可选状态以签名列为准。
semanticDedupThreshold属性semanticDedupThreshold?: number公开属性;类型、只读和可选状态以签名列为准。
sources属性sources: ContextSourceSpec[]公开属性;类型、只读和可选状态以签名列为准。
truncation属性truncation: ContextTruncationPolicySpec公开属性;类型、只读和可选状态以签名列为准。
untrustedContentPolicy属性untrustedContentPolicy: "reject" | "escape" | "tag"公开属性;类型、只读和可选状态以签名列为准。
version属性version: string公开属性;类型、只读和可选状态以签名列为准。

ContextProvenanceLabel

Context Provenance Label 接口,共包含 7 个公开字段或方法。

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

声明

text
export interface ContextProvenanceLabel {
    sourceType: ContextSourceType;
    sourceId: string;
    memoryId?: string;
    memoryVersionId?: string;
    authority?: 'unverified' | 'user_asserted' | 'system_observed' | 'verified' | 'authoritative';
    observedAt?: string;
    citationLabel: string;
}

契约成员

成员种类签名说明
authority属性authority?: "verified" | "unverified" | "user_asserted" | "system_observed" | "authoritative"公开属性;类型、只读和可选状态以签名列为准。
citationLabel属性citationLabel: string公开属性;类型、只读和可选状态以签名列为准。
memoryId属性memoryId?: string公开属性;类型、只读和可选状态以签名列为准。
memoryVersionId属性memoryVersionId?: string公开属性;类型、只读和可选状态以签名列为准。
observedAt属性observedAt?: string公开属性;类型、只读和可选状态以签名列为准。
sourceId属性sourceId: string公开属性;类型、只读和可选状态以签名列为准。
sourceType属性sourceType: ContextSourceType公开属性;类型、只读和可选状态以签名列为准。

ContextRankingPolicySpec

Context Ranking Policy Spec 接口,共包含 8 个公开字段或方法。

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

声明

text
export interface ContextRankingPolicySpec {
    method: 'priority' | 'score_fusion' | 'reranker' | 'custom';
    recencyWeight?: number;
    relevanceWeight?: number;
    importanceWeight?: number;
    confidenceWeight?: number;
    provenanceWeight?: number;
    sourceWeights?: Record<string, number>;
    rerankerProviderRef?: MemoryContractSpecRef;
}

契约成员

成员种类签名说明
confidenceWeight属性confidenceWeight?: number公开属性;类型、只读和可选状态以签名列为准。
importanceWeight属性importanceWeight?: number公开属性;类型、只读和可选状态以签名列为准。
method属性method: "custom" | "priority" | "score_fusion" | "reranker"公开属性;类型、只读和可选状态以签名列为准。
provenanceWeight属性provenanceWeight?: number公开属性;类型、只读和可选状态以签名列为准。
recencyWeight属性recencyWeight?: number公开属性;类型、只读和可选状态以签名列为准。
relevanceWeight属性relevanceWeight?: number公开属性;类型、只读和可选状态以签名列为准。
rerankerProviderRef属性rerankerProviderRef?: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
sourceWeights属性sourceWeights?: Record<string, number>公开属性;类型、只读和可选状态以签名列为准。

ContextRejectedItem

Context Rejected Item 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface ContextRejectedItem {
    itemId: string;
    reason: 'scope_denied' | 'policy_denied' | 'invalid_status' | 'duplicate' | 'budget_exceeded' | 'untrusted_rejected' | 'invalid_input';
}

契约成员

成员种类签名说明
itemId属性itemId: string公开属性;类型、只读和可选状态以签名列为准。
reason属性reason: "policy_denied" | "duplicate" | "scope_denied" | "invalid_status" | "budget_exceeded" | "untrusted_rejected" | "invalid_input"公开属性;类型、只读和可选状态以签名列为准。

ContextSourceBudget

Context Source Budget 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface ContextSourceBudget {
    sourceId: string;
    minTokens?: number;
    targetTokens?: number;
    maxTokens: number;
    required: boolean;
    overflowPolicy: 'drop' | 'truncate' | 'summarize' | 'spill_to_artifact' | 'fail';
}

契约成员

成员种类签名说明
maxTokens属性maxTokens: number公开属性;类型、只读和可选状态以签名列为准。
minTokens属性minTokens?: number公开属性;类型、只读和可选状态以签名列为准。
overflowPolicy属性overflowPolicy: "fail" | "summarize" | "drop" | "truncate" | "spill_to_artifact"公开属性;类型、只读和可选状态以签名列为准。
required属性required: boolean公开属性;类型、只读和可选状态以签名列为准。
sourceId属性sourceId: string公开属性;类型、只读和可选状态以签名列为准。
targetTokens属性targetTokens?: number公开属性;类型、只读和可选状态以签名列为准。

ContextSourceResolutionInput

Context Source Resolution Input 接口,共包含 20 个公开字段或方法。

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

声明

text
export interface ContextSourceResolutionInput extends ResolvedContextBuildInput {
    source: ContextSourceSpec;
}

契约成员

成员种类签名说明
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公开属性;类型、只读和可选状态以签名列为准。
source属性source: ContextSourceSpec公开属性;类型、只读和可选状态以签名列为准。
stateId属性stateId?: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tokenizerRef属性tokenizerRef?: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。

ContextSourceResolver

Context Source Resolver 接口,共包含 3 个公开字段或方法。

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

声明

text
export interface ContextSourceResolver {
    readonly id: string;
    supports(source: ContextSourceSpec): boolean;
    resolve(request: ContextSourceResolutionInput): Promise<ContextItem[]>;
}

契约成员

成员种类签名说明
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。
resolve方法resolve(request: ContextSourceResolutionInput): Promise<ContextItem[]>公开方法;参数与返回类型以签名列为准。
supports方法supports(source: ContextSourceSpec): boolean公开方法;参数与返回类型以签名列为准。

ContextSourceResolverRegistry

Context Source Resolver Registry 接口,共包含 1 个公开字段或方法。

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

声明

text
export interface ContextSourceResolverRegistry {
    resolve(request: ResolvedContextBuildInput): Promise<ContextItem[]>;
}

契约成员

成员种类签名说明
resolve方法resolve(request: ResolvedContextBuildInput): Promise<ContextItem[]>公开方法;参数与返回类型以签名列为准。

ContextSourceSpec

Context Source Spec 接口,共包含 9 个公开字段或方法。

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

声明

text
export interface ContextSourceSpec {
    id: string;
    type: ContextSourceType;
    ref?: MemoryContractSpecRef;
    required?: boolean;
    priority: number;
    maxItems?: number;
    maxTokens?: number;
    overflowPolicy?: ContextSourceBudget['overflowPolicy'];
    filters?: Record<string, unknown>;
}

契约成员

成员种类签名说明
filters属性filters?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
maxItems属性maxItems?: number公开属性;类型、只读和可选状态以签名列为准。
maxTokens属性maxTokens?: number公开属性;类型、只读和可选状态以签名列为准。
overflowPolicy属性overflowPolicy?: "fail" | "summarize" | "drop" | "truncate" | "spill_to_artifact"公开属性;类型、只读和可选状态以签名列为准。
priority属性priority: number公开属性;类型、只读和可选状态以签名列为准。
ref属性ref?: MemoryContractSpecRef公开属性;类型、只读和可选状态以签名列为准。
required属性required?: boolean公开属性;类型、只读和可选状态以签名列为准。
type属性type: ContextSourceType公开属性;类型、只读和可选状态以签名列为准。

ContextTruncationPolicySpec

Context Truncation Policy Spec 接口,共包含 5 个公开字段或方法。

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

声明

text
export interface ContextTruncationPolicySpec {
    method: 'drop_lowest' | 'truncate_items' | 'summarize' | 'hybrid';
    preserveRequiredSources: boolean;
    preserveLatestMessages?: number;
    minItemTokens?: number;
    truncationMarker?: string;
}

契约成员

成员种类签名说明
method属性method: "hybrid" | "summarize" | "drop_lowest" | "truncate_items"公开属性;类型、只读和可选状态以签名列为准。
minItemTokens属性minItemTokens?: number公开属性;类型、只读和可选状态以签名列为准。
preserveLatestMessages属性preserveLatestMessages?: number公开属性;类型、只读和可选状态以签名列为准。
preserveRequiredSources属性preserveRequiredSources: boolean公开属性;类型、只读和可选状态以签名列为准。
truncationMarker属性truncationMarker?: string公开属性;类型、只读和可选状态以签名列为准。

ContextTruncationRecord

Context Truncation Record 接口,共包含 5 个公开字段或方法。

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

声明

text
export interface ContextTruncationRecord {
    itemId: string;
    originalTokens: number;
    retainedTokens: number;
    method: 'drop' | 'truncate' | 'summarize' | 'spill_to_artifact';
    reason: string;
}

契约成员

成员种类签名说明
itemId属性itemId: string公开属性;类型、只读和可选状态以签名列为准。
method属性method: "summarize" | "drop" | "truncate" | "spill_to_artifact"公开属性;类型、只读和可选状态以签名列为准。
originalTokens属性originalTokens: number公开属性;类型、只读和可选状态以签名列为准。
reason属性reason: string公开属性;类型、只读和可选状态以签名列为准。
retainedTokens属性retainedTokens: number公开属性;类型、只读和可选状态以签名列为准。

MemoryContextBuilder

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

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

声明

text
export interface MemoryContextBuilder {
    build(request: ContextBuildInput): Promise<ContextBundle>;
    explain(contextHash: string): Promise<ContextBuildExplanation | null>;
}

契约成员

成员种类签名说明
build方法build(request: ContextBuildInput): Promise<ContextBundle>公开方法;参数与返回类型以签名列为准。
explain方法explain(contextHash: string): Promise<ContextBuildExplanation | null>公开方法;参数与返回类型以签名列为准。

PromptSegment

Prompt Segment 接口,共包含 8 个公开字段或方法。

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

声明

text
export interface PromptSegment {
    id: string;
    role: 'system' | 'developer' | 'user' | 'assistant' | 'tool' | 'data';
    text: string;
    tokenCount: number;
    trustLevel: 'trusted_instruction' | 'trusted_data' | 'untrusted_data';
    sourceRefs: string[];
    required?: boolean;
    artifactRefs?: ContextArtifactRef[];
}

契约成员

成员种类签名说明
artifactRefs属性artifactRefs?: ContextArtifactRef[]公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
required属性required?: boolean公开属性;类型、只读和可选状态以签名列为准。
role属性role: "system" | "tool" | "user" | "assistant" | "developer" | "data"公开属性;类型、只读和可选状态以签名列为准。
sourceRefs属性sourceRefs: string[]公开属性;类型、只读和可选状态以签名列为准。
text属性text: string公开属性;类型、只读和可选状态以签名列为准。
tokenCount属性tokenCount: number公开属性;类型、只读和可选状态以签名列为准。
trustLevel属性trustLevel: "trusted_instruction" | "trusted_data" | "untrusted_data"公开属性;类型、只读和可选状态以签名列为准。

ResolvedContextBuildInput

Resolved Context Build Input 接口,共包含 19 个公开字段或方法。

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

声明

text
export interface ResolvedContextBuildInput extends ContextBuildRequest {
    profile: ContextProfileSpec;
    tokenizerRef?: MemoryContractSpecRef;
}

契约成员

成员种类签名说明
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公开属性;类型、只读和可选状态以签名列为准。

TokenEstimator

Token Estimator 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface TokenEstimator {
    readonly id: string;
    estimate(text: string): number;
}

契约成员

成员种类签名说明
estimate方法estimate(text: string): number公开方法;参数与返回类型以签名列为准。
id属性readonly id: string公开属性;类型、只读和可选状态以签名列为准。

ContextSourceType

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

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

声明

text
export type ContextSourceType = 'system' | 'workflow_state' | 'messages' | 'working_memory' | 'long_term_memory' | 'tool_observation' | 'artifact' | 'human_review' | 'custom';