@codesoul-co/hypha-core / modules/runtime/session-command-worker
模块用法
用于执行该边界的运行时行为。Session command worker 模块公开 1 类、3 接口、3 类型。
从包入口导入
ts
import {
DurableSessionCommandWorker,
} from '@codesoul-co/hypha-core';
import type {
DurableSessionCommandWorkerOptions,
SessionCommandHandlerContext,
SessionCommandWorkerResult,
SessionCommandHandler,
SessionCommandHandlerResult,
SessionCommandWorkerDisposition,
} from '@codesoul-co/hypha-core';使用要点
- 6 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用
import type,运行时不应依赖它们。 - 1 个类提供可实例化的运行时实现;构造参数与公开方法在各自条目中完整列出。
公共导出
| Symbol | 种类 | 签名 | 说明 |
|---|---|---|---|
DurableSessionCommandWorker | 类 | new DurableSessionCommandWorker(options: DurableSessionCommandWorkerOptions): DurableSessionCommandWorker | Claims and resolves one durable Session command without owning a polling loop. Command handlers must explicitly classify expected retry and failure outcomes. |
DurableSessionCommandWorkerOptions | 接口 | interface DurableSessionCommandWorkerOptions | Durable Session Command Worker Options 接口,共包含 11 个公开字段或方法。 |
SessionCommandHandlerContext | 接口 | interface SessionCommandHandlerContext | Session Command Handler Context 接口,共包含 4 个公开字段或方法。 |
SessionCommandWorkerResult | 接口 | interface SessionCommandWorkerResult | Session Command Worker Result 接口,共包含 5 个公开字段或方法。 |
SessionCommandHandler | 类型 | type SessionCommandHandler = (context: Readonly<SessionCommandHandlerContext>) => Promise<SessionCommandHandlerResult> | Session Command Handler 公共类型别名;完整类型表达式见声明。 |
SessionCommandHandlerResult | 类型 | type SessionCommandHandlerResult = { disposition: 'applied'; resultRunId?: string; resultEventIds?: string[]; } | { disposition: 'retry'; availableAt?: string; } | { disposition: 'failed'; rejectionCode: string; deadLetter?: boolean; } | Session Command Handler Result 公共类型别名;完整类型表达式见声明。 |
SessionCommandWorkerDisposition | 类型 | type SessionCommandWorkerDisposition = 'idle' | 'applied' | 'retry_scheduled' | 'failed' | 'dead_lettered' | 'lease_lost' | 'aborted' | Session Command Worker Disposition 公共类型别名;完整类型表达式见声明。 |
DurableSessionCommandWorker
Claims and resolves one durable Session command without owning a polling loop. Command handlers must explicitly classify expected retry and failure outcomes.
- 种类: 类
- 导入:
import { DurableSessionCommandWorker } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export declare class DurableSessionCommandWorker {
constructor(options: DurableSessionCommandWorkerOptions);
processNext(scope?: SessionQueueScope, signal?: AbortSignal): Promise<SessionCommandWorkerResult>;
}公开成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
constructor | 构造函数 | (options: DurableSessionCommandWorkerOptions): DurableSessionCommandWorker | 创建该类的实例。 |
processNext | 方法 | processNext(scope?: SessionQueueScope, signal?: AbortSignal): Promise<SessionCommandWorkerResult> | 公开方法;参数与返回类型以签名列为准。 |
DurableSessionCommandWorkerOptions
Durable Session Command Worker Options 接口,共包含 11 个公开字段或方法。
- 种类: 接口
- 导入:
import type { DurableSessionCommandWorkerOptions } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export interface DurableSessionCommandWorkerOptions {
queue: SessionQueue;
workerId: string;
leaseMs: number;
handlers: Partial<Record<SessionCommandType, SessionCommandHandler>>;
now?: () => string;
renewalIntervalMs?: number;
maxHandlerDurationMs?: number;
wait?: (delayMs: number, signal: AbortSignal) => Promise<void>;
onLeaseRenewalFailure?: (error: unknown, claim: Readonly<SessionCommandClaim>) => void;
operationalTelemetry?: RuntimeOperationalTelemetry;
monotonicNow?: () => number;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
handlers | 属性 | handlers: Partial<Record<"user_input" | "cancel" | "signal" | "start_run" | "resume" | "transition" | "continue_react" | "close_session", SessionCommandHandler>> | 公开属性;类型、只读和可选状态以签名列为准。 |
leaseMs | 属性 | leaseMs: number | 公开属性;类型、只读和可选状态以签名列为准。 |
maxHandlerDurationMs | 属性 | maxHandlerDurationMs?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
monotonicNow | 方法 | monotonicNow?(): number | 公开方法;参数与返回类型以签名列为准。 |
now | 方法 | now?(): string | 公开方法;参数与返回类型以签名列为准。 |
onLeaseRenewalFailure | 方法 | onLeaseRenewalFailure?(error: unknown, claim: Readonly<SessionCommandClaim>): void | 公开方法;参数与返回类型以签名列为准。 |
operationalTelemetry | 属性 | operationalTelemetry?: RuntimeOperationalTelemetry | 公开属性;类型、只读和可选状态以签名列为准。 |
queue | 属性 | queue: SessionQueue | 公开属性;类型、只读和可选状态以签名列为准。 |
renewalIntervalMs | 属性 | renewalIntervalMs?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
wait | 方法 | wait?(delayMs: number, signal: AbortSignal): Promise<void> | 公开方法;参数与返回类型以签名列为准。 |
workerId | 属性 | workerId: string | 公开属性;类型、只读和可选状态以签名列为准。 |
SessionCommandHandlerContext
Session Command Handler Context 接口,共包含 4 个公开字段或方法。
- 种类: 接口
- 导入:
import type { SessionCommandHandlerContext } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export interface SessionCommandHandlerContext {
command: Readonly<SessionCommandRecord>;
signal: AbortSignal;
claimToken: string;
leaseEpoch: number;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
claimToken | 属性 | claimToken: string | 公开属性;类型、只读和可选状态以签名列为准。 |
command | 属性 | command: Readonly<SessionCommandRecord> | 公开属性;类型、只读和可选状态以签名列为准。 |
leaseEpoch | 属性 | leaseEpoch: number | 公开属性;类型、只读和可选状态以签名列为准。 |
signal | 属性 | signal: AbortSignal | 公开属性;类型、只读和可选状态以签名列为准。 |
SessionCommandWorkerResult
Session Command Worker Result 接口,共包含 5 个公开字段或方法。
- 种类: 接口
- 导入:
import type { SessionCommandWorkerResult } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export interface SessionCommandWorkerResult {
disposition: SessionCommandWorkerDisposition;
commandId?: string;
commandType?: SessionCommandType;
attempts?: number;
rejectionCode?: string;
}契约成员
| 成员 | 种类 | 签名 | 说明 |
|---|---|---|---|
attempts | 属性 | attempts?: number | 公开属性;类型、只读和可选状态以签名列为准。 |
commandId | 属性 | commandId?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
commandType | 属性 | commandType?: "user_input" | "cancel" | "signal" | "start_run" | "resume" | "transition" | "continue_react" | "close_session" | 公开属性;类型、只读和可选状态以签名列为准。 |
disposition | 属性 | disposition: SessionCommandWorkerDisposition | 公开属性;类型、只读和可选状态以签名列为准。 |
rejectionCode | 属性 | rejectionCode?: string | 公开属性;类型、只读和可选状态以签名列为准。 |
SessionCommandHandler
Session Command Handler 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { SessionCommandHandler } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export type SessionCommandHandler = (context: Readonly<SessionCommandHandlerContext>) => Promise<SessionCommandHandlerResult>;SessionCommandHandlerResult
Session Command Handler Result 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { SessionCommandHandlerResult } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export type SessionCommandHandlerResult = {
disposition: 'applied';
resultRunId?: string;
resultEventIds?: string[];
} | {
disposition: 'retry';
availableAt?: string;
} | {
disposition: 'failed';
rejectionCode: string;
deadLetter?: boolean;
};SessionCommandWorkerDisposition
Session Command Worker Disposition 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { SessionCommandWorkerDisposition } from '@codesoul-co/hypha-core'; - 源码模块:
modules/runtime/session-command-worker
声明
text
export type SessionCommandWorkerDisposition = 'idle' | 'applied' | 'retry_scheduled' | 'failed' | 'dead_lettered' | 'lease_lost' | 'aborted';