@codesoul-co/hypha-memory / external-provider-operations
模块用法
用于把外部或本地 Provider 绑定到 Hypha Port。External provider operations 模块公开 2 类、1 常量、4 函数、2 接口、1 类型。
从包入口导入
ts
import {
InMemoryExternalProviderOperationStore,
StructuredExternalProviderOperationStore,
externalProviderOperationSchema,
createExternalProviderOperation,
externalProviderOperationId,
fingerprintExternalOperationFailure,
resolveExternalProviderOperationStore,
} from '@codesoul-co/hypha-memory';
import type {
ExternalProviderOperation,
ExternalProviderOperationStore,
ExternalProviderOperationState,
} from '@codesoul-co/hypha-memory';使用要点
- 3 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用
import type,运行时不应依赖它们。 - 2 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
- 4 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。
- 1 个常量/枚举提供稳定值、Schema、Definition 或默认配置;应复用这些导出,避免在应用中复制内部值。
公共导出
| Symbol | 种类 | 签名 | 说明 |
|---|---|---|---|
InMemoryExternalProviderOperationStore | 类 | new InMemoryExternalProviderOperationStore(): InMemoryExternalProviderOperationStore | In Memory External Provider Operation Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。 |
StructuredExternalProviderOperationStore | 类 | new StructuredExternalProviderOperationStore(options: { store: StructuredStoreProvider; table?: string; }): StructuredExternalProviderOperationStore | Structured External Provider Operation Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。 |
externalProviderOperationSchema | 常量 | const externalProviderOperationSchema: ZodType<ExternalProviderOperation, ZodTypeDef, ExternalProviderOperation> | External Provider Operation 的运行时 Schema。 |
createExternalProviderOperation | 函数 | createExternalProviderOperation(input: Omit<ExternalProviderOperation, "id" | "scopeHash" | "attempts" | "createdAt" | "updatedAt"> & { now?: string; }): ExternalProviderOperation | Create External Provider Operation 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
externalProviderOperationId | 函数 | externalProviderOperationId(providerId: string, operationId: string): string | External Provider Operation ID 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
fingerprintExternalOperationFailure | 函数 | fingerprintExternalOperationFailure(error: NormalizedMemoryError): string | Fingerprint External Operation Failure 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
resolveExternalProviderOperationStore | 函数 | resolveExternalProviderOperationStore(store: ExternalProviderOperationStore | undefined, profile: "production" | "test" | "ephemeral"): ExternalProviderOperationStore | Resolve External Provider Operation Store 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
ExternalProviderOperation | 接口 | interface ExternalProviderOperation | External Provider Operation 接口,共包含 19 个公开字段或方法。 |
ExternalProviderOperationStore | 接口 | interface ExternalProviderOperationStore | External Provider Operation Store 接口,共包含 5 个公开字段或方法。 |
ExternalProviderOperationState | 类型 | type ExternalProviderOperationState = 'pending' | 'running' | 'reconcile_required' | 'succeeded' | 'failed' | 'cancelled' | 'dead_letter' | External Provider Operation State 公共类型别名;完整类型表达式见声明。 |
InMemoryExternalProviderOperationStore
In Memory External Provider Operation Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { InMemoryExternalProviderOperationStore } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare class InMemoryExternalProviderOperationStore implements ExternalProviderOperationStore {
readonly durability: "ephemeral";
get(providerId: string, operationId: string): Promise<ExternalProviderOperation | null>;
claim(operation: ExternalProviderOperation): Promise<{
operation: ExternalProviderOperation;
created: boolean;
}>;
set(operation: ExternalProviderOperation): Promise<void>;
listRecoverable(providerId?: string, now?: string): Promise<ExternalProviderOperation[]>;
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
claim | 方法 | claim(operation: ExternalProviderOperation): Promise<{ operation: ExternalProviderOperation; created: boolean; }> | 公开方法;参数与返回类型以签名列为准。 |
constructor | 构造函数 | (): InMemoryExternalProviderOperationStore | 创建该类的实例。 |
durability | 属性 | readonly durability: "ephemeral" | 公开属性;类型、只读和可选状态以签名列为准。 |
get | 方法 | get(providerId: string, operationId: string): Promise<ExternalProviderOperation | null> | 公开方法;参数与返回类型以签名列为准。 |
listRecoverable | 方法 | listRecoverable(providerId?: string, now?: string): Promise<ExternalProviderOperation[]> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set(operation: ExternalProviderOperation): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
StructuredExternalProviderOperationStore
Structured External Provider Operation Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
- 种类: 类
- 导入:
import { StructuredExternalProviderOperationStore } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare class StructuredExternalProviderOperationStore implements ExternalProviderOperationStore {
readonly durability: "durable";
constructor(options: {
store: StructuredStoreProvider;
table?: string;
});
get(providerId: string, operationId: string): Promise<ExternalProviderOperation | null>;
claim(operation: ExternalProviderOperation): Promise<{
operation: ExternalProviderOperation;
created: boolean;
}>;
set(operation: ExternalProviderOperation): Promise<void>;
listRecoverable(providerId?: string, now?: string): Promise<ExternalProviderOperation[]>;
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
claim | 方法 | claim(operation: ExternalProviderOperation): Promise<{ operation: ExternalProviderOperation; created: boolean; }> | 公开方法;参数与返回类型以签名列为准。 |
constructor | 构造函数 | (options: { store: StructuredStoreProvider; table?: string; }): StructuredExternalProviderOperationStore | 创建该类的实例。 |
durability | 属性 | readonly durability: "durable" | 公开属性;类型、只读和可选状态以签名列为准。 |
get | 方法 | get(providerId: string, operationId: string): Promise<ExternalProviderOperation | null> | 公开方法;参数与返回类型以签名列为准。 |
listRecoverable | 方法 | listRecoverable(providerId?: string, now?: string): Promise<ExternalProviderOperation[]> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set(operation: ExternalProviderOperation): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
externalProviderOperationSchema
External Provider Operation 的运行时 Schema。
- 种类: 常量
- 导入:
import { externalProviderOperationSchema } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare const externalProviderOperationSchema: ZodType<ExternalProviderOperation, ZodTypeDef, ExternalProviderOperation>;createExternalProviderOperation
Create External Provider Operation 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { createExternalProviderOperation } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare function createExternalProviderOperation(input: Omit<ExternalProviderOperation, 'id' | 'scopeHash' | 'attempts' | 'createdAt' | 'updatedAt'> & {
now?: string;
}): ExternalProviderOperation;调用签名
text
createExternalProviderOperation(input: Omit<ExternalProviderOperation, "id" | "scopeHash" | "attempts" | "createdAt" | "updatedAt"> & { now?: string; }): ExternalProviderOperation参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
input | Omit<ExternalProviderOperation, "id" | "attempts" | "createdAt" | "updatedAt" | "scopeHash"> & { now?: string; } | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
ExternalProviderOperation - 说明: 返回值契约由上述类型定义。
externalProviderOperationId
External Provider Operation ID 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { externalProviderOperationId } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare function externalProviderOperationId(providerId: string, operationId: string): string;调用签名
text
externalProviderOperationId(providerId: string, operationId: string): string参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
providerId | string | 是 | 必需参数;接受的值由类型列定义。 |
operationId | string | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
string - 说明: 返回值契约由上述类型定义。
fingerprintExternalOperationFailure
Fingerprint External Operation Failure 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { fingerprintExternalOperationFailure } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare function fingerprintExternalOperationFailure(error: NormalizedMemoryError): string;调用签名
text
fingerprintExternalOperationFailure(error: NormalizedMemoryError): string参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
error | NormalizedMemoryError | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
string - 说明: 返回值契约由上述类型定义。
resolveExternalProviderOperationStore
Resolve External Provider Operation Store 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { resolveExternalProviderOperationStore } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export declare function resolveExternalProviderOperationStore(store: ExternalProviderOperationStore | undefined, profile: 'production' | 'test' | 'ephemeral'): ExternalProviderOperationStore;调用签名
text
resolveExternalProviderOperationStore(store: ExternalProviderOperationStore | undefined, profile: "production" | "test" | "ephemeral"): ExternalProviderOperationStore参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
store | ExternalProviderOperationStore | 是 | 必需参数;接受的值由类型列定义。 |
profile | "ephemeral" | "production" | "test" | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
ExternalProviderOperationStore - 说明: 返回值契约由上述类型定义。
ExternalProviderOperation
External Provider Operation 接口,共包含 19 个公开字段或方法。
- 种类: 接口
- 导入:
import type { ExternalProviderOperation } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export interface ExternalProviderOperation {
id: string;
providerId: string;
operationId: string;
externalOperationId?: string;
kind: 'mem0_event' | 'vertex_lro' | 'hindsight_operation' | 'unknown_write';
state: ExternalProviderOperationState;
scope: ManagedMemoryScope;
scopeHash: string;
profileRef: MemoryContractSpecRef;
principal: {
principalId: string;
userId?: string;
};
attempts: number;
deadlineAt?: string;
nextAttemptAt?: string;
cancellationRequestedAt?: string;
failure?: NormalizedMemoryError;
failureFingerprint?: string;
createdAt: string;
updatedAt: string;
metadata?: Record<string, unknown>;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
attempts | 属性 | attempts: number | 公开属性;类型、只读和可选状态以签名列为准。 |
cancellationRequestedAt | 属性 | cancellationRequestedAt?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
createdAt | 属性 | createdAt: string | 公开属性;类型、只读和可选状态以签名列为准。 |
deadlineAt | 属性 | deadlineAt?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
externalOperationId | 属性 | externalOperationId?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
failure | 属性 | failure?: NormalizedMemoryError | 公开属性;类型、只读和可选状态以签名列为准。 |
failureFingerprint | 属性 | failureFingerprint?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
id | 属性 | id: string | 公开属性;类型、只读和可选状态以签名列为准。 |
kind | 属性 | kind: "mem0_event" | "vertex_lro" | "hindsight_operation" | "unknown_write" | 公开属性;类型、只读和可选状态以签名列为准。 |
metadata | 属性 | metadata?: Record<string, unknown> | 公开属性;类型、只读和可选状态以签名列为准。 |
nextAttemptAt | 属性 | nextAttemptAt?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
operationId | 属性 | operationId: string | 公开属性;类型、只读和可选状态以签名列为准。 |
principal | 属性 | principal: { principalId: string; userId?: string; } | 公开属性;类型、只读和可选状态以签名列为准。 |
profileRef | 属性 | profileRef: MemoryContractSpecRef | 公开属性;类型、只读和可选状态以签名列为准。 |
providerId | 属性 | providerId: string | 公开属性;类型、只读和可选状态以签名列为准。 |
scope | 属性 | scope: ManagedMemoryScope | 公开属性;类型、只读和可选状态以签名列为准。 |
scopeHash | 属性 | scopeHash: string | 公开属性;类型、只读和可选状态以签名列为准。 |
state | 属性 | state: ExternalProviderOperationState | 公开属性;类型、只读和可选状态以签名列为准。 |
updatedAt | 属性 | updatedAt: string | 公开属性;类型、只读和可选状态以签名列为准。 |
ExternalProviderOperationStore
External Provider Operation Store 接口,共包含 5 个公开字段或方法。
- 种类: 接口
- 导入:
import type { ExternalProviderOperationStore } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export interface ExternalProviderOperationStore {
readonly durability: 'ephemeral' | 'durable';
get(providerId: string, operationId: string): Promise<ExternalProviderOperation | null>;
claim(operation: ExternalProviderOperation): Promise<{
operation: ExternalProviderOperation;
created: boolean;
}>;
set(operation: ExternalProviderOperation): Promise<void>;
listRecoverable(providerId?: string, now?: string): Promise<ExternalProviderOperation[]>;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
claim | 方法 | claim(operation: ExternalProviderOperation): Promise<{ operation: ExternalProviderOperation; created: boolean; }> | 公开方法;参数与返回类型以签名列为准。 |
durability | 属性 | readonly durability: "ephemeral" | "durable" | 公开属性;类型、只读和可选状态以签名列为准。 |
get | 方法 | get(providerId: string, operationId: string): Promise<ExternalProviderOperation | null> | 公开方法;参数与返回类型以签名列为准。 |
listRecoverable | 方法 | listRecoverable(providerId?: string, now?: string): Promise<ExternalProviderOperation[]> | 公开方法;参数与返回类型以签名列为准。 |
set | 方法 | set(operation: ExternalProviderOperation): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
ExternalProviderOperationState
External Provider Operation State 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { ExternalProviderOperationState } from '@codesoul-co/hypha-memory'; - 源码模块:
external-provider-operations
声明
text
export type ExternalProviderOperationState = 'pending' | 'running' | 'reconcile_required' | 'succeeded' | 'failed' | 'cancelled' | 'dead_letter';