Skip to content

@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种类签名说明
InMemoryExternalProviderOperationStorenew InMemoryExternalProviderOperationStore(): InMemoryExternalProviderOperationStoreIn Memory External Provider Operation Store 类,共公开 6 个构造函数或成员;精确签名见本条目的声明与成员表。
StructuredExternalProviderOperationStorenew StructuredExternalProviderOperationStore(options: { store: StructuredStoreProvider; table?: string; }): StructuredExternalProviderOperationStoreStructured 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; }): ExternalProviderOperationCreate External Provider Operation 函数,提供 1 个公开调用签名;参数与返回类型见下表。
externalProviderOperationId函数externalProviderOperationId(providerId: string, operationId: string): stringExternal Provider Operation ID 函数,提供 1 个公开调用签名;参数与返回类型见下表。
fingerprintExternalOperationFailure函数fingerprintExternalOperationFailure(error: NormalizedMemoryError): stringFingerprint External Operation Failure 函数,提供 1 个公开调用签名;参数与返回类型见下表。
resolveExternalProviderOperationStore函数resolveExternalProviderOperationStore(store: ExternalProviderOperationStore | undefined, profile: "production" | "test" | "ephemeral"): ExternalProviderOperationStoreResolve External Provider Operation Store 函数,提供 1 个公开调用签名;参数与返回类型见下表。
ExternalProviderOperation接口interface ExternalProviderOperationExternal Provider Operation 接口,共包含 19 个公开字段或方法。
ExternalProviderOperationStore接口interface ExternalProviderOperationStoreExternal 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

参数

参数类型必需说明
inputOmit<ExternalProviderOperation, "id" | "attempts" | "createdAt" | "updatedAt" | "scopeHash"> & { now?: string; }必需参数;接受的值由类型列定义。

返回值

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

externalProviderOperationId

External Provider Operation ID 函数,提供 1 个公开调用签名;参数与返回类型见下表。

声明

text
export declare function externalProviderOperationId(providerId: string, operationId: string): string;

调用签名

text
externalProviderOperationId(providerId: string, operationId: string): string

参数

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

返回值

  • 类型: 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

参数

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

返回值

  • 类型: 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

参数

参数类型必需说明
storeExternalProviderOperationStore必需参数;接受的值由类型列定义。
profile"ephemeral" | "production" | "test"必需参数;接受的值由类型列定义。

返回值

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

ExternalProviderOperation

External Provider Operation 接口,共包含 19 个公开字段或方法。

声明

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