Skip to content

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

模块用法

用于使用该功能边界的公共契约与操作。Context artifacts 模块公开 2 类、2 函数、6 接口、1 类型。

从包入口导入

ts
import {
  InMemoryContextArtifactStore,
  ProviderBackedContextArtifactStore,
  contextArtifactContentHash,
  validateContextArtifactReference,
} from '@codesoul-co/hypha-memory';

import type {
  ContextArtifactReadExpectation,
  ContextArtifactRecord,
  ContextArtifactRef,
  ContextArtifactStore,
  ContextArtifactWriteRequest,
  ProviderBackedContextArtifactStoreOptions,
  InMemoryContextArtifactBacking,
} from '@codesoul-co/hypha-memory';

使用要点

  • 7 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 2 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
  • 2 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。

公共导出

Symbol种类签名说明
InMemoryContextArtifactStorenew InMemoryContextArtifactStore(records?: InMemoryContextArtifactBacking): InMemoryContextArtifactStoreIn Memory Context Artifact Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。
ProviderBackedContextArtifactStorenew ProviderBackedContextArtifactStore(options: ProviderBackedContextArtifactStoreOptions): ProviderBackedContextArtifactStoreProvider Backed Context Artifact Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。
contextArtifactContentHash函数contextArtifactContentHash(content: string): stringContext Artifact Content Hash 函数,提供 1 个公开调用签名;参数与返回类型见下表。
validateContextArtifactReference函数validateContextArtifactReference(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): voidValidate Context Artifact Reference 函数,提供 1 个公开调用签名;参数与返回类型见下表。
ContextArtifactReadExpectation接口interface ContextArtifactReadExpectationContext Artifact Read Expectation 接口,共包含 2 个公开字段或方法。
ContextArtifactRecord接口interface ContextArtifactRecordContext Artifact Record 接口,共包含 2 个公开字段或方法。
ContextArtifactRef接口interface ContextArtifactRefContext Artifact Ref 接口,共包含 10 个公开字段或方法。
ContextArtifactStore接口interface ContextArtifactStoreContext Artifact Store 接口,共包含 4 个公开字段或方法。
ContextArtifactWriteRequest接口interface ContextArtifactWriteRequestContext Artifact Write Request 接口,共包含 6 个公开字段或方法。
ProviderBackedContextArtifactStoreOptions接口interface ProviderBackedContextArtifactStoreOptionsProvider Backed Context Artifact Store Options 接口,共包含 2 个公开字段或方法。
InMemoryContextArtifactBacking类型type InMemoryContextArtifactBacking = Map<string, ContextArtifactRecord>In Memory Context Artifact Backing 公共类型别名;完整类型表达式见声明。

InMemoryContextArtifactStore

In Memory Context Artifact Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。

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

声明

text
export declare class InMemoryContextArtifactStore implements ContextArtifactStore {
    readonly durability: "ephemeral";
    constructor(records?: InMemoryContextArtifactBacking);
    put(request: ContextArtifactWriteRequest): Promise<ContextArtifactRef>;
    read(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): Promise<string>;
    delete(reference: ContextArtifactRef): Promise<void>;
}

公开成员

成员种类签名说明
constructor构造函数(records?: InMemoryContextArtifactBacking): InMemoryContextArtifactStore创建该类的实例。
delete方法delete(reference: ContextArtifactRef): Promise<void>公开方法;参数与返回类型以签名列为准。
durability属性readonly durability: "ephemeral"公开属性;类型、只读和可选状态以签名列为准。
put方法put(request: ContextArtifactWriteRequest): Promise<ContextArtifactRef>公开方法;参数与返回类型以签名列为准。
read方法read(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): Promise<string>公开方法;参数与返回类型以签名列为准。

ProviderBackedContextArtifactStore

Provider Backed Context Artifact Store 类,共公开 5 个构造函数或成员;精确签名见本条目的声明与成员表。

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

声明

text
export declare class ProviderBackedContextArtifactStore implements ContextArtifactStore {
    readonly durability: 'ephemeral' | 'durable';
    constructor(options: ProviderBackedContextArtifactStoreOptions);
    put(request: ContextArtifactWriteRequest): Promise<ContextArtifactRef>;
    read(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): Promise<string>;
    delete(reference: ContextArtifactRef): Promise<void>;
}

公开成员

成员种类签名说明
constructor构造函数(options: ProviderBackedContextArtifactStoreOptions): ProviderBackedContextArtifactStore创建该类的实例。
delete方法delete(reference: ContextArtifactRef): Promise<void>公开方法;参数与返回类型以签名列为准。
durability属性readonly durability: "ephemeral" | "durable"公开属性;类型、只读和可选状态以签名列为准。
put方法put(request: ContextArtifactWriteRequest): Promise<ContextArtifactRef>公开方法;参数与返回类型以签名列为准。
read方法read(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): Promise<string>公开方法;参数与返回类型以签名列为准。

contextArtifactContentHash

Context Artifact Content Hash 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function contextArtifactContentHash(content: string): string;

调用签名

text
contextArtifactContentHash(content: string): string

参数

参数类型必需说明
contentstring必需参数;接受的值由类型列定义。

返回值

  • 类型: string
  • 说明: 返回值契约由上述类型定义。

validateContextArtifactReference

Validate Context Artifact Reference 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function validateContextArtifactReference(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): void;

调用签名

text
validateContextArtifactReference(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): void

参数

参数类型必需说明
referenceContextArtifactRef必需参数;接受的值由类型列定义。
expectedContextArtifactReadExpectation必需参数;接受的值由类型列定义。

返回值

  • 类型: void
  • 说明: 不返回值。

ContextArtifactReadExpectation

Context Artifact Read Expectation 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface ContextArtifactReadExpectation {
    scopeHash: string;
    profileRevision: string;
}

契约成员

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

ContextArtifactRecord

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

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

声明

text
export interface ContextArtifactRecord {
    reference: ContextArtifactRef;
    content: string;
}

契约成员

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

ContextArtifactRef

Context Artifact Ref 接口,共包含 10 个公开字段或方法。

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

声明

text
export interface ContextArtifactRef {
    id: string;
    path: string;
    contentHash: string;
    sizeBytes: number;
    contentType: 'text/plain; charset=utf-8';
    scopeHash: string;
    profileRevision: string;
    sourceItemId: string;
    createdAt: string;
    expiresAt?: string;
}

契约成员

成员种类签名说明
contentHash属性contentHash: string公开属性;类型、只读和可选状态以签名列为准。
contentType属性contentType: "text/plain; charset=utf-8"公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
path属性path: string公开属性;类型、只读和可选状态以签名列为准。
profileRevision属性profileRevision: string公开属性;类型、只读和可选状态以签名列为准。
scopeHash属性scopeHash: string公开属性;类型、只读和可选状态以签名列为准。
sizeBytes属性sizeBytes: number公开属性;类型、只读和可选状态以签名列为准。
sourceItemId属性sourceItemId: string公开属性;类型、只读和可选状态以签名列为准。

ContextArtifactStore

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

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

声明

text
export interface ContextArtifactStore {
    readonly durability: 'ephemeral' | 'durable';
    put(request: ContextArtifactWriteRequest): Promise<ContextArtifactRef>;
    read(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): Promise<string>;
    delete(reference: ContextArtifactRef): Promise<void>;
}

契约成员

成员种类签名说明
delete方法delete(reference: ContextArtifactRef): Promise<void>公开方法;参数与返回类型以签名列为准。
durability属性readonly durability: "ephemeral" | "durable"公开属性;类型、只读和可选状态以签名列为准。
put方法put(request: ContextArtifactWriteRequest): Promise<ContextArtifactRef>公开方法;参数与返回类型以签名列为准。
read方法read(reference: ContextArtifactRef, expected: ContextArtifactReadExpectation): Promise<string>公开方法;参数与返回类型以签名列为准。

ContextArtifactWriteRequest

Context Artifact Write Request 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface ContextArtifactWriteRequest {
    content: string;
    scopeHash: string;
    profileRevision: string;
    sourceItemId: string;
    createdAt: string;
    expiresAt?: string;
}

契约成员

成员种类签名说明
content属性content: string公开属性;类型、只读和可选状态以签名列为准。
createdAt属性createdAt: string公开属性;类型、只读和可选状态以签名列为准。
expiresAt属性expiresAt?: string公开属性;类型、只读和可选状态以签名列为准。
profileRevision属性profileRevision: string公开属性;类型、只读和可选状态以签名列为准。
scopeHash属性scopeHash: string公开属性;类型、只读和可选状态以签名列为准。
sourceItemId属性sourceItemId: string公开属性;类型、只读和可选状态以签名列为准。

ProviderBackedContextArtifactStoreOptions

Provider Backed Context Artifact Store Options 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface ProviderBackedContextArtifactStoreOptions {
    provider: ArtifactStoreProvider;
    durability?: 'ephemeral' | 'durable';
}

契约成员

成员种类签名说明
durability属性durability?: "ephemeral" | "durable"公开属性;类型、只读和可选状态以签名列为准。
provider属性provider: ArtifactStoreProvider公开属性;类型、只读和可选状态以签名列为准。

InMemoryContextArtifactBacking

In Memory Context Artifact Backing 公共类型别名;完整类型表达式见声明。

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

声明

text
export type InMemoryContextArtifactBacking = Map<string, ContextArtifactRecord>;