Skip to content

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

Using this module ​

Use the Context contracts module for declaring and runtime-validating contracts. It exports 28 interfaces, 1 type.

Import from the package entrypoint ​

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

// The complete export list is documented below.

Usage patterns ​

  • Use the 29 type/interface exports as static contracts in application code, adapters, or tests. Import them with import type; they do not exist at runtime.

Public exports ​

SymbolKindSignatureDescription
ContextBudgetPlaninterfaceinterface ContextBudgetPlanContext Budget Plan interface with 6 public fields or methods.
ContextBuildExplanationinterfaceinterface ContextBuildExplanationContext Build Explanation interface with 6 public fields or methods.
ContextBuildInputinterfaceinterface ContextBuildInput extends ContextBuildRequestContext Build Input interface with 20 public fields or methods.
ContextBuildRequestinterfaceinterface ContextBuildRequestContext Build Request interface with 17 public fields or methods.
ContextBundleinterfaceinterface ContextBundleContext Bundle interface with 16 public fields or methods.
ContextCompactionPolicySpecinterfaceinterface ContextCompactionPolicySpecContext Compaction Policy Spec interface with 6 public fields or methods.
ContextConflictinterfaceinterface ContextConflictContext Conflict interface with 3 public fields or methods.
ContextEnvelopeinterfaceinterface ContextEnvelopeContext Envelope interface with 17 public fields or methods.
ContextInjectionGatewayinterfaceinterface ContextInjectionGatewayContext Injection Gateway interface with 1 public fields or methods.
ContextIteminterfaceinterface ContextItemContext Item interface with 14 public fields or methods.
ContextItemPolicyDecisioninterfaceinterface ContextItemPolicyDecisionContext Item Policy Decision interface with 2 public fields or methods.
ContextItemPolicyEvaluatorinterfaceinterface ContextItemPolicyEvaluatorContext Item Policy Evaluator interface with 1 public fields or methods.
ContextItemPolicyInputinterfaceinterface ContextItemPolicyInputContext Item Policy Input interface with 5 public fields or methods.
ContextProfileSpecinterfaceinterface ContextProfileSpecContext Profile Spec interface with 23 public fields or methods.
ContextProvenanceLabelinterfaceinterface ContextProvenanceLabelContext Provenance Label interface with 7 public fields or methods.
ContextRankingPolicySpecinterfaceinterface ContextRankingPolicySpecContext Ranking Policy Spec interface with 8 public fields or methods.
ContextRejectedIteminterfaceinterface ContextRejectedItemContext Rejected Item interface with 2 public fields or methods.
ContextSourceBudgetinterfaceinterface ContextSourceBudgetContext Source Budget interface with 6 public fields or methods.
ContextSourceResolutionInputinterfaceinterface ContextSourceResolutionInput extends ResolvedContextBuildInputContext Source Resolution Input interface with 20 public fields or methods.
ContextSourceResolverinterfaceinterface ContextSourceResolverContext Source Resolver interface with 3 public fields or methods.
ContextSourceResolverRegistryinterfaceinterface ContextSourceResolverRegistryContext Source Resolver Registry interface with 1 public fields or methods.
ContextSourceSpecinterfaceinterface ContextSourceSpecContext Source Spec interface with 9 public fields or methods.
ContextTruncationPolicySpecinterfaceinterface ContextTruncationPolicySpecContext Truncation Policy Spec interface with 5 public fields or methods.
ContextTruncationRecordinterfaceinterface ContextTruncationRecordContext Truncation Record interface with 5 public fields or methods.
MemoryContextBuilderinterfaceinterface MemoryContextBuilderMemory Context Builder interface with 2 public fields or methods.
PromptSegmentinterfaceinterface PromptSegmentPrompt Segment interface with 8 public fields or methods.
ResolvedContextBuildInputinterfaceinterface ResolvedContextBuildInput extends ContextBuildRequestResolved Context Build Input interface with 19 public fields or methods.
TokenEstimatorinterfaceinterface TokenEstimatorToken Estimator interface with 2 public fields or methods.
ContextSourceTypetypetype ContextSourceType = 'system' | 'workflow_state' | 'messages' | 'working_memory' | 'long_term_memory' | 'tool_observation' | 'artifact' | 'human_review' | 'custom'Public type alias for Context Source Type; the declaration contains its complete type expression.

ContextBudgetPlan ​

Context Budget Plan interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { ContextBudgetPlan } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
dynamicTokenspropertydynamicTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
fixedTokenspropertyfixedTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
safetyMarginTokenspropertysafetyMarginTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceBudgetspropertysourceBudgets: ContextSourceBudget[]Public property; its type, readonly modifier and optionality are shown in the signature.
tokenizerRefpropertytokenizerRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
totalAvailableTokenspropertytotalAvailableTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextBuildExplanation ​

Context Build Explanation interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { ContextBuildExplanation } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
budgetPlanpropertybudgetPlan: ContextBudgetPlanPublic property; its type, readonly modifier and optionality are shown in the signature.
contextHashpropertycontextHash: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
omittedItemIdspropertyomittedItemIds: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
rankingpropertyranking: { itemId: string; score: number; reasons: string[]; }[]Public property; its type, readonly modifier and optionality are shown in the signature.
rejectedItemspropertyrejectedItems: ContextRejectedItem[]Public property; its type, readonly modifier and optionality are shown in the signature.
selectedItemIdspropertyselectedItemIds: string[]Public property; its type, readonly modifier and optionality are shown in the signature.

ContextBuildInput ​

Context Build Input interface with 20 public fields or methods.

  • Kind: interface
  • Import: import type { ContextBuildInput } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
explicitSourceRefspropertyexplicitSourceRefs?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
messageCursorpropertymessageCursor?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
modelContextWindowTokenspropertymodelContextWindowTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
operationIdpropertyoperationId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
previousContextHashpropertypreviousContextHash?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
principalpropertyprincipal: MemoryPrincipalPublic property; its type, readonly modifier and optionality are shown in the signature.
profilepropertyprofile: ContextProfileSpecPublic property; its type, readonly modifier and optionality are shown in the signature.
profileRefpropertyprofileRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
querypropertyquery?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedInstructionTokenspropertyreservedInstructionTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedOutputTokenspropertyreservedOutputTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedSystemTokenspropertyreservedSystemTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
runtimeStateRefpropertyruntimeStateRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: ManagedMemoryScopePublic property; its type, readonly modifier and optionality are shown in the signature.
sourceItemspropertysourceItems: ContextItem[]Public property; its type, readonly modifier and optionality are shown in the signature.
stateIdpropertystateId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stepIdpropertystepId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tokenizerRefpropertytokenizerRef?: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextBuildRequest ​

Context Build Request interface with 17 public fields or methods.

  • Kind: interface
  • Import: import type { ContextBuildRequest } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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>;
}

Contract members ​

MemberKindSignatureDescription
explicitSourceRefspropertyexplicitSourceRefs?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
messageCursorpropertymessageCursor?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
modelContextWindowTokenspropertymodelContextWindowTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
operationIdpropertyoperationId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
previousContextHashpropertypreviousContextHash?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
principalpropertyprincipal: MemoryPrincipalPublic property; its type, readonly modifier and optionality are shown in the signature.
profileRefpropertyprofileRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
querypropertyquery?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedInstructionTokenspropertyreservedInstructionTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedOutputTokenspropertyreservedOutputTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedSystemTokenspropertyreservedSystemTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
runtimeStateRefpropertyruntimeStateRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: ManagedMemoryScopePublic property; its type, readonly modifier and optionality are shown in the signature.
stateIdpropertystateId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stepIdpropertystepId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextBundle ​

Context Bundle interface with 16 public fields or methods.

  • Kind: interface
  • Import: import type { ContextBundle } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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[];
}

Contract members ​

MemberKindSignatureDescription
artifactRefspropertyartifactRefs?: ContextArtifactRef[]Public property; its type, readonly modifier and optionality are shown in the signature.
conflictspropertyconflicts: ContextConflict[]Public property; its type, readonly modifier and optionality are shown in the signature.
contextHashpropertycontextHash: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
createdAtpropertycreatedAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
itemspropertyitems: ContextItem[]Public property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
omittedItemIdspropertyomittedItemIds: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
profileRefpropertyprofileRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
profileRevisionpropertyprofileRevision: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
rejectedItemspropertyrejectedItems: ContextRejectedItem[]Public property; its type, readonly modifier and optionality are shown in the signature.
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceHashespropertysourceHashes: Record<string, string>Public property; its type, readonly modifier and optionality are shown in the signature.
stepIdpropertystepId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
totalCharacterspropertytotalCharacters: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
totalTokenspropertytotalTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextCompactionPolicySpec ​

Context Compaction Policy Spec interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { ContextCompactionPolicySpec } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
enabledpropertyenabled: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
persistSummaryAsMemorypropertypersistSummaryAsMemory?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
preserveLastMessagespropertypreserveLastMessages?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
summaryMemoryTypepropertysummaryMemoryType?: import("/Users/erwin/Downloads/codespace/Hypha/packages/memory/dist/contracts").ManagedMemoryTypePublic property; its type, readonly modifier and optionality are shown in the signature.
summaryProviderRefpropertysummaryProviderRef?: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
triggerRatiopropertytriggerRatio: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextConflict ​

Context Conflict interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { ContextConflict } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
conflictGroupIdpropertyconflictGroupId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
itemIdspropertyitemIds: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
resolutionpropertyresolution?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextEnvelope ​

Context Envelope interface with 17 public fields or methods.

  • Kind: interface
  • Import: import type { ContextEnvelope } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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[];
}

Contract members ​

MemberKindSignatureDescription
artifactRefspropertyartifactRefs?: ContextArtifactRef[]Public property; its type, readonly modifier and optionality are shown in the signature.
budgetPlanpropertybudgetPlan: ContextBudgetPlanPublic property; its type, readonly modifier and optionality are shown in the signature.
conflictspropertyconflicts: ContextConflict[]Public property; its type, readonly modifier and optionality are shown in the signature.
contextHashpropertycontextHash: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
createdAtpropertycreatedAt: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
dataSegmentspropertydataSegments: PromptSegment[]Public property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
includedSourceRefspropertyincludedSourceRefs: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
instructionSegmentspropertyinstructionSegments: PromptSegment[]Public property; its type, readonly modifier and optionality are shown in the signature.
omittedSourceRefspropertyomittedSourceRefs: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
profileRevisionpropertyprofileRevision: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
provenanceIndexpropertyprovenanceIndex: Record<string, ContextProvenanceLabel>Public property; its type, readonly modifier and optionality are shown in the signature.
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stepIdpropertystepId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
systemSegmentspropertysystemSegments: PromptSegment[]Public property; its type, readonly modifier and optionality are shown in the signature.
totalTokenspropertytotalTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
truncationRecordspropertytruncationRecords: ContextTruncationRecord[]Public property; its type, readonly modifier and optionality are shown in the signature.

ContextInjectionGateway ​

Context Injection Gateway interface with 1 public fields or methods.

  • Kind: interface
  • Import: import type { ContextInjectionGateway } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
buildEnvelopemethodbuildEnvelope(bundle: ContextBundle, profile: ContextProfileSpec): Promise<ContextEnvelope>Public method; parameters and return type are shown in the signature.

ContextItem ​

Context Item interface with 14 public fields or methods.

  • Kind: interface
  • Import: import type { ContextItem } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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;
}

Contract members ​

MemberKindSignatureDescription
artifactRefpropertyartifactRef?: ContextArtifactRefPublic property; its type, readonly modifier and optionality are shown in the signature.
conflictGroupIdpropertyconflictGroupId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
contentpropertycontent: unknownPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
prioritypropertypriority: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
provenancepropertyprovenance?: Record<string, unknown> | MemoryProvenancePublic property; its type, readonly modifier and optionality are shown in the signature.
requiredpropertyrequired?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
scorepropertyscore?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceIdpropertysourceId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceTypepropertysourceType: ContextSourceTypePublic property; its type, readonly modifier and optionality are shown in the signature.
textpropertytext: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tokenEstimatepropertytokenEstimate: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
untrustedpropertyuntrusted?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextItemPolicyDecision ​

Context Item Policy Decision interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ContextItemPolicyDecision } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
allowedpropertyallowed: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
reasonpropertyreason?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextItemPolicyEvaluator ​

Context Item Policy Evaluator interface with 1 public fields or methods.

  • Kind: interface
  • Import: import type { ContextItemPolicyEvaluator } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
evaluatemethodevaluate(input: ContextItemPolicyInput): Promise<ContextItemPolicyDecision>Public method; parameters and return type are shown in the signature.

ContextItemPolicyInput ​

Context Item Policy Input interface with 5 public fields or methods.

  • Kind: interface
  • Import: import type { ContextItemPolicyInput } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
itempropertyitem: ContextItemPublic property; its type, readonly modifier and optionality are shown in the signature.
operationIdpropertyoperationId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
principalpropertyprincipal: MemoryPrincipalPublic property; its type, readonly modifier and optionality are shown in the signature.
profileRefpropertyprofileRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: ManagedMemoryScopePublic property; its type, readonly modifier and optionality are shown in the signature.

ContextProfileSpec ​

Context Profile Spec interface with 23 public fields or methods.

  • Kind: interface
  • Import: import type { ContextProfileSpec } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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>;
}

Contract members ​

MemberKindSignatureDescription
compactionPolicypropertycompactionPolicy?: ContextCompactionPolicySpecPublic property; its type, readonly modifier and optionality are shown in the signature.
conflictPolicypropertyconflictPolicy?: "include_marked" | "prefer_latest" | "prefer_verified"Public property; its type, readonly modifier and optionality are shown in the signature.
deduplicationpropertydeduplication: "none" | "id" | "semantic" | "hash"Public property; its type, readonly modifier and optionality are shown in the signature.
descriptionpropertydescription?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
includeProvenancepropertyincludeProvenance: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
includeScorespropertyincludeScores?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
instructionBoundarypropertyinstructionBoundary: "strict" | "tagged" | "quoted"Public property; its type, readonly modifier and optionality are shown in the signature.
maxCharacterspropertymaxCharacters?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxItemspropertymaxItems?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxSerializedBytespropertymaxSerializedBytes?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxTokenspropertymaxTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
namepropertyname?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
rankingpropertyranking: ContextRankingPolicySpecPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedOutputTokenspropertyreservedOutputTokens?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedSystemTokenspropertyreservedSystemTokens?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
revisionpropertyrevision?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
semanticDedupThresholdpropertysemanticDedupThreshold?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
sourcespropertysources: ContextSourceSpec[]Public property; its type, readonly modifier and optionality are shown in the signature.
truncationpropertytruncation: ContextTruncationPolicySpecPublic property; its type, readonly modifier and optionality are shown in the signature.
untrustedContentPolicypropertyuntrustedContentPolicy: "reject" | "escape" | "tag"Public property; its type, readonly modifier and optionality are shown in the signature.
versionpropertyversion: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextProvenanceLabel ​

Context Provenance Label interface with 7 public fields or methods.

  • Kind: interface
  • Import: import type { ContextProvenanceLabel } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
authoritypropertyauthority?: "verified" | "unverified" | "user_asserted" | "system_observed" | "authoritative"Public property; its type, readonly modifier and optionality are shown in the signature.
citationLabelpropertycitationLabel: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
memoryIdpropertymemoryId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
memoryVersionIdpropertymemoryVersionId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
observedAtpropertyobservedAt?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceIdpropertysourceId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceTypepropertysourceType: ContextSourceTypePublic property; its type, readonly modifier and optionality are shown in the signature.

ContextRankingPolicySpec ​

Context Ranking Policy Spec interface with 8 public fields or methods.

  • Kind: interface
  • Import: import type { ContextRankingPolicySpec } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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;
}

Contract members ​

MemberKindSignatureDescription
confidenceWeightpropertyconfidenceWeight?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
importanceWeightpropertyimportanceWeight?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
methodpropertymethod: "custom" | "priority" | "score_fusion" | "reranker"Public property; its type, readonly modifier and optionality are shown in the signature.
provenanceWeightpropertyprovenanceWeight?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
recencyWeightpropertyrecencyWeight?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
relevanceWeightpropertyrelevanceWeight?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
rerankerProviderRefpropertyrerankerProviderRef?: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceWeightspropertysourceWeights?: Record<string, number>Public property; its type, readonly modifier and optionality are shown in the signature.

ContextRejectedItem ​

Context Rejected Item interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { ContextRejectedItem } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
itemIdpropertyitemId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reasonpropertyreason: "policy_denied" | "duplicate" | "scope_denied" | "invalid_status" | "budget_exceeded" | "untrusted_rejected" | "invalid_input"Public property; its type, readonly modifier and optionality are shown in the signature.

ContextSourceBudget ​

Context Source Budget interface with 6 public fields or methods.

  • Kind: interface
  • Import: import type { ContextSourceBudget } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
maxTokenspropertymaxTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
minTokenspropertyminTokens?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
overflowPolicypropertyoverflowPolicy: "fail" | "summarize" | "drop" | "truncate" | "spill_to_artifact"Public property; its type, readonly modifier and optionality are shown in the signature.
requiredpropertyrequired: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
sourceIdpropertysourceId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
targetTokenspropertytargetTokens?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextSourceResolutionInput ​

Context Source Resolution Input interface with 20 public fields or methods.

  • Kind: interface
  • Import: import type { ContextSourceResolutionInput } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
explicitSourceRefspropertyexplicitSourceRefs?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
messageCursorpropertymessageCursor?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
modelContextWindowTokenspropertymodelContextWindowTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
operationIdpropertyoperationId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
previousContextHashpropertypreviousContextHash?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
principalpropertyprincipal: MemoryPrincipalPublic property; its type, readonly modifier and optionality are shown in the signature.
profilepropertyprofile: ContextProfileSpecPublic property; its type, readonly modifier and optionality are shown in the signature.
profileRefpropertyprofileRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
querypropertyquery?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedInstructionTokenspropertyreservedInstructionTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedOutputTokenspropertyreservedOutputTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedSystemTokenspropertyreservedSystemTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
runtimeStateRefpropertyruntimeStateRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: ManagedMemoryScopePublic property; its type, readonly modifier and optionality are shown in the signature.
sourcepropertysource: ContextSourceSpecPublic property; its type, readonly modifier and optionality are shown in the signature.
stateIdpropertystateId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stepIdpropertystepId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tokenizerRefpropertytokenizerRef?: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextSourceResolver ​

Context Source Resolver interface with 3 public fields or methods.

  • Kind: interface
  • Import: import type { ContextSourceResolver } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
idpropertyreadonly id: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
resolvemethodresolve(request: ContextSourceResolutionInput): Promise<ContextItem[]>Public method; parameters and return type are shown in the signature.
supportsmethodsupports(source: ContextSourceSpec): booleanPublic method; parameters and return type are shown in the signature.

ContextSourceResolverRegistry ​

Context Source Resolver Registry interface with 1 public fields or methods.

  • Kind: interface
  • Import: import type { ContextSourceResolverRegistry } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
resolvemethodresolve(request: ResolvedContextBuildInput): Promise<ContextItem[]>Public method; parameters and return type are shown in the signature.

ContextSourceSpec ​

Context Source Spec interface with 9 public fields or methods.

  • Kind: interface
  • Import: import type { ContextSourceSpec } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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>;
}

Contract members ​

MemberKindSignatureDescription
filterspropertyfilters?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
maxItemspropertymaxItems?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
maxTokenspropertymaxTokens?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
overflowPolicypropertyoverflowPolicy?: "fail" | "summarize" | "drop" | "truncate" | "spill_to_artifact"Public property; its type, readonly modifier and optionality are shown in the signature.
prioritypropertypriority: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
refpropertyref?: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
requiredpropertyrequired?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
typepropertytype: ContextSourceTypePublic property; its type, readonly modifier and optionality are shown in the signature.

ContextTruncationPolicySpec ​

Context Truncation Policy Spec interface with 5 public fields or methods.

  • Kind: interface
  • Import: import type { ContextTruncationPolicySpec } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
methodpropertymethod: "hybrid" | "summarize" | "drop_lowest" | "truncate_items"Public property; its type, readonly modifier and optionality are shown in the signature.
minItemTokenspropertyminItemTokens?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
preserveLatestMessagespropertypreserveLatestMessages?: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
preserveRequiredSourcespropertypreserveRequiredSources: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
truncationMarkerpropertytruncationMarker?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextTruncationRecord ​

Context Truncation Record interface with 5 public fields or methods.

  • Kind: interface
  • Import: import type { ContextTruncationRecord } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
itemIdpropertyitemId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
methodpropertymethod: "summarize" | "drop" | "truncate" | "spill_to_artifact"Public property; its type, readonly modifier and optionality are shown in the signature.
originalTokenspropertyoriginalTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reasonpropertyreason: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
retainedTokenspropertyretainedTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.

MemoryContextBuilder ​

Memory Context Builder interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { MemoryContextBuilder } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
buildmethodbuild(request: ContextBuildInput): Promise<ContextBundle>Public method; parameters and return type are shown in the signature.
explainmethodexplain(contextHash: string): Promise<ContextBuildExplanation | null>Public method; parameters and return type are shown in the signature.

PromptSegment ​

Prompt Segment interface with 8 public fields or methods.

  • Kind: interface
  • Import: import type { PromptSegment } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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[];
}

Contract members ​

MemberKindSignatureDescription
artifactRefspropertyartifactRefs?: ContextArtifactRef[]Public property; its type, readonly modifier and optionality are shown in the signature.
idpropertyid: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
requiredpropertyrequired?: booleanPublic property; its type, readonly modifier and optionality are shown in the signature.
rolepropertyrole: "system" | "tool" | "user" | "assistant" | "developer" | "data"Public property; its type, readonly modifier and optionality are shown in the signature.
sourceRefspropertysourceRefs: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
textpropertytext: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tokenCountpropertytokenCount: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
trustLevelpropertytrustLevel: "trusted_instruction" | "trusted_data" | "untrusted_data"Public property; its type, readonly modifier and optionality are shown in the signature.

ResolvedContextBuildInput ​

Resolved Context Build Input interface with 19 public fields or methods.

  • Kind: interface
  • Import: import type { ResolvedContextBuildInput } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
explicitSourceRefspropertyexplicitSourceRefs?: string[]Public property; its type, readonly modifier and optionality are shown in the signature.
messageCursorpropertymessageCursor?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
metadatapropertymetadata?: Record<string, unknown>Public property; its type, readonly modifier and optionality are shown in the signature.
modelContextWindowTokenspropertymodelContextWindowTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
operationIdpropertyoperationId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
previousContextHashpropertypreviousContextHash?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
principalpropertyprincipal: MemoryPrincipalPublic property; its type, readonly modifier and optionality are shown in the signature.
profilepropertyprofile: ContextProfileSpecPublic property; its type, readonly modifier and optionality are shown in the signature.
profileRefpropertyprofileRef: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.
querypropertyquery?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedInstructionTokenspropertyreservedInstructionTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedOutputTokenspropertyreservedOutputTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
reservedSystemTokenspropertyreservedSystemTokens: numberPublic property; its type, readonly modifier and optionality are shown in the signature.
runIdpropertyrunId: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
runtimeStateRefpropertyruntimeStateRef?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
scopepropertyscope: ManagedMemoryScopePublic property; its type, readonly modifier and optionality are shown in the signature.
stateIdpropertystateId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
stepIdpropertystepId?: stringPublic property; its type, readonly modifier and optionality are shown in the signature.
tokenizerRefpropertytokenizerRef?: MemoryContractSpecRefPublic property; its type, readonly modifier and optionality are shown in the signature.

TokenEstimator ​

Token Estimator interface with 2 public fields or methods.

  • Kind: interface
  • Import: import type { TokenEstimator } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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

Contract members ​

MemberKindSignatureDescription
estimatemethodestimate(text: string): numberPublic method; parameters and return type are shown in the signature.
idpropertyreadonly id: stringPublic property; its type, readonly modifier and optionality are shown in the signature.

ContextSourceType ​

Public type alias for Context Source Type; the declaration contains its complete type expression.

  • Kind: type
  • Import: import type { ContextSourceType } from '@codesoul-co/hypha-memory';
  • Source module: context-contracts

Declaration ​

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