Skip to content

@codesoul-co/hypha-memory / memory-events

模块用法

用于创建、记录或读取 Event 契约。Memory events 模块公开 2 函数、3 接口、1 类型。

从包入口导入

ts
import {
  memoryEventIdempotencyKey,
  sanitizeMemoryEventPayload,
} from '@codesoul-co/hypha-memory';

import type {
  MemoryEventContext,
  MemoryEventPayloadBase,
  MemoryEventPublisher,
  MemoryEventType,
} from '@codesoul-co/hypha-memory';

使用要点

  • 4 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 2 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。

公共导出

Symbol种类签名说明
memoryEventIdempotencyKey函数memoryEventIdempotencyKey(type: MemoryEventType, payload: MemoryEventPayloadBase): stringMemory Event Idempotency Key 函数,提供 1 个公开调用签名;参数与返回类型见下表。
sanitizeMemoryEventPayload函数sanitizeMemoryEventPayload(payload: MemoryEventPayloadBase): MemoryEventPayloadBaseSanitize Memory Event Payload 函数,提供 1 个公开调用签名;参数与返回类型见下表。
MemoryEventContext接口interface MemoryEventContextMemory Event Context 接口,共包含 7 个公开字段或方法。
MemoryEventPayloadBase接口interface MemoryEventPayloadBaseMemory Event Payload Base 接口,共包含 12 个公开字段或方法。
MemoryEventPublisher接口interface MemoryEventPublisherMemory Event Publisher 接口,共包含 1 个公开字段或方法。
MemoryEventType类型type MemoryEventType = Extract<FrameworkEventType, memory.${string} | context.${string}>Memory Event Type 公共类型别名;完整类型表达式见声明。

memoryEventIdempotencyKey

Memory Event Idempotency Key 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function memoryEventIdempotencyKey(type: MemoryEventType, payload: MemoryEventPayloadBase): string;

调用签名

text
memoryEventIdempotencyKey(type: MemoryEventType, payload: MemoryEventPayloadBase): string

参数

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

返回值

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

sanitizeMemoryEventPayload

Sanitize Memory Event Payload 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function sanitizeMemoryEventPayload(payload: MemoryEventPayloadBase): MemoryEventPayloadBase;

调用签名

text
sanitizeMemoryEventPayload(payload: MemoryEventPayloadBase): MemoryEventPayloadBase

参数

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

返回值

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

MemoryEventContext

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

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

声明

text
export interface MemoryEventContext {
    userId: string;
    tenantId?: string;
    runId: string;
    sessionId?: string;
    workspaceId?: string;
    stepId?: string;
    agentId?: string;
}

契约成员

成员种类签名说明
agentId属性agentId?: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
userId属性userId: string公开属性;类型、只读和可选状态以签名列为准。
workspaceId属性workspaceId?: string公开属性;类型、只读和可选状态以签名列为准。

MemoryEventPayloadBase

Memory Event Payload Base 接口,共包含 12 个公开字段或方法。

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

声明

text
export interface MemoryEventPayloadBase {
    operationId: string;
    profileId?: string;
    profileRevision?: string;
    providerId?: string;
    scopeHash: string;
    memoryId?: string;
    memoryVersionId?: string;
    itemCount?: number;
    latencyMs?: number;
    status?: string;
    error?: NormalizedMemoryError;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
error属性error?: NormalizedMemoryError公开属性;类型、只读和可选状态以签名列为准。
itemCount属性itemCount?: number公开属性;类型、只读和可选状态以签名列为准。
latencyMs属性latencyMs?: number公开属性;类型、只读和可选状态以签名列为准。
memoryId属性memoryId?: string公开属性;类型、只读和可选状态以签名列为准。
memoryVersionId属性memoryVersionId?: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
operationId属性operationId: string公开属性;类型、只读和可选状态以签名列为准。
profileId属性profileId?: string公开属性;类型、只读和可选状态以签名列为准。
profileRevision属性profileRevision?: string公开属性;类型、只读和可选状态以签名列为准。
providerId属性providerId?: string公开属性;类型、只读和可选状态以签名列为准。
scopeHash属性scopeHash: string公开属性;类型、只读和可选状态以签名列为准。
status属性status?: string公开属性;类型、只读和可选状态以签名列为准。

MemoryEventPublisher

Memory Event Publisher 接口,共包含 1 个公开字段或方法。

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

声明

text
export interface MemoryEventPublisher {
    publish(type: MemoryEventType, payload: MemoryEventPayloadBase, context: MemoryEventContext): Promise<string>;
}

契约成员

成员种类签名说明
publish方法publish(type: MemoryEventType, payload: MemoryEventPayloadBase, context: MemoryEventContext): Promise<string>公开方法;参数与返回类型以签名列为准。

MemoryEventType

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

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

声明

text
export type MemoryEventType = Extract<FrameworkEventType, `memory.${string}` | `context.${string}`>;