Skip to content

@codesoul-co/hypha-harness / recovery-supervisor

模块用法

用于处理有界恢复、重试或降级。Recovery supervisor 模块公开 1 函数、6 接口、1 类型。

从包入口导入

ts
import {
  runRecoverySupervisor,
} from '@codesoul-co/hypha-harness';

import type {
  RecoveryParticipant,
  RecoveryParticipantContext,
  RecoveryParticipantResult,
  RecoverySupervisorOptions,
  RecoverySupervisorResult,
  RecoverySupervisorScheduler,
  RecoveryParticipantAction,
} from '@codesoul-co/hypha-harness';

使用要点

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

公共导出

Symbol种类签名说明
runRecoverySupervisor函数runRecoverySupervisor(options: RecoverySupervisorOptions): Promise<RecoverySupervisorResult>Runs a dependency-ordered, FSM-governed recovery workflow. A participant is retried only while its evidence changes or the bounded strategy budget has not been exhausted. Completed upstream participants are not repeated.
RecoveryParticipant接口interface RecoveryParticipantRecovery Participant 接口,共包含 9 个公开字段或方法。
RecoveryParticipantContext接口interface RecoveryParticipantContextRecovery Participant Context 接口,共包含 10 个公开字段或方法。
RecoveryParticipantResult接口interface RecoveryParticipantResultRecovery Participant Result 接口,共包含 3 个公开字段或方法。
RecoverySupervisorOptions接口interface RecoverySupervisorOptionsRecovery Supervisor Options 接口,共包含 18 个公开字段或方法。
RecoverySupervisorResult接口interface RecoverySupervisorResultRecovery Supervisor Result 接口,共包含 5 个公开字段或方法。
RecoverySupervisorScheduler接口interface RecoverySupervisorSchedulerRecovery Supervisor Scheduler 接口,共包含 1 个公开字段或方法。
RecoveryParticipantAction类型type RecoveryParticipantAction = (context: RecoveryParticipantContext) => Promise<RecoveryParticipantResult<TOutput>>Recovery Participant Action 公共类型别名;完整类型表达式见声明。

runRecoverySupervisor

Runs a dependency-ordered, FSM-governed recovery workflow. A participant is retried only while its evidence changes or the bounded strategy budget has not been exhausted. Completed upstream participants are not repeated.

  • 种类: 函数
  • 导入: import { runRecoverySupervisor } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export declare function runRecoverySupervisor(options: RecoverySupervisorOptions): Promise<RecoverySupervisorResult>;

调用签名

text
runRecoverySupervisor(options: RecoverySupervisorOptions): Promise<RecoverySupervisorResult>

Runs a dependency-ordered, FSM-governed recovery workflow. A participant is retried only while its evidence changes or the bounded strategy budget has not been exhausted. Completed upstream participants are not repeated.

参数

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

返回值

  • 类型: Promise<RecoverySupervisorResult>
  • 说明: 返回值契约由上述类型定义。

RecoveryParticipant

Recovery Participant 接口,共包含 9 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RecoveryParticipant } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export interface RecoveryParticipant<TOutput = unknown> {
    id: string;
    module: RecoveryModule;
    dependsOn?: string[];
    execute: RecoveryParticipantAction<TOutput>;
    classify(error: unknown, context: RecoveryParticipantContext): RecoveryFailure | Promise<RecoveryFailure>;
    reconcile?: RecoveryParticipantAction<TOutput>;
    fallback?: RecoveryParticipantAction<TOutput>;
    degrade?: RecoveryParticipantAction<TOutput>;
    compensate?: RecoveryParticipantAction<TOutput>;
}

契约成员

成员种类签名说明
classify方法classify(error: unknown, context: RecoveryParticipantContext): RecoveryFailure | Promise<RecoveryFailure>公开方法;参数与返回类型以签名列为准。
compensate方法compensate?(context: RecoveryParticipantContext): Promise<RecoveryParticipantResult<TOutput>>公开方法;参数与返回类型以签名列为准。
degrade方法degrade?(context: RecoveryParticipantContext): Promise<RecoveryParticipantResult<TOutput>>公开方法;参数与返回类型以签名列为准。
dependsOn属性dependsOn?: string[]公开属性;类型、只读和可选状态以签名列为准。
execute方法execute(context: RecoveryParticipantContext): Promise<RecoveryParticipantResult<TOutput>>公开方法;参数与返回类型以签名列为准。
fallback方法fallback?(context: RecoveryParticipantContext): Promise<RecoveryParticipantResult<TOutput>>公开方法;参数与返回类型以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
module属性module: "memory" | "domain" | "mcp" | "policy" | "workspace" | "tool" | "unknown" | "execution" | "fsm" | "inference" | "storage" | "message_bus" | "cache"公开属性;类型、只读和可选状态以签名列为准。
reconcile方法reconcile?(context: RecoveryParticipantContext): Promise<RecoveryParticipantResult<TOutput>>公开方法;参数与返回类型以签名列为准。

RecoveryParticipantContext

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

  • 种类: 接口
  • 导入: import type { RecoveryParticipantContext } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export interface RecoveryParticipantContext {
    caseId: string;
    runId: string;
    scope: RecoveryKnowledgeScope;
    participantId: string;
    module: RecoveryModule;
    cycle: number;
    outputs: Readonly<Record<string, unknown>>;
    snapshot?: Readonly<RecoveryCaseSnapshot>;
    failure?: RecoveryFailure;
    signal?: AbortSignal;
}

契约成员

成员种类签名说明
caseId属性caseId: string公开属性;类型、只读和可选状态以签名列为准。
cycle属性cycle: number公开属性;类型、只读和可选状态以签名列为准。
failure属性failure?: RecoveryFailure公开属性;类型、只读和可选状态以签名列为准。
module属性module: "memory" | "domain" | "mcp" | "policy" | "workspace" | "tool" | "unknown" | "execution" | "fsm" | "inference" | "storage" | "message_bus" | "cache"公开属性;类型、只读和可选状态以签名列为准。
outputs属性outputs: Readonly<Record<string, unknown>>公开属性;类型、只读和可选状态以签名列为准。
participantId属性participantId: string公开属性;类型、只读和可选状态以签名列为准。
runId属性runId: string公开属性;类型、只读和可选状态以签名列为准。
scope属性scope: RecoveryKnowledgeScope公开属性;类型、只读和可选状态以签名列为准。
signal属性signal?: AbortSignal公开属性;类型、只读和可选状态以签名列为准。
snapshot属性snapshot?: Readonly<RecoveryCaseSnapshot>公开属性;类型、只读和可选状态以签名列为准。

RecoveryParticipantResult

Recovery Participant Result 接口,共包含 3 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RecoveryParticipantResult } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export interface RecoveryParticipantResult<TOutput = unknown> {
    output: TOutput;
    evidence: RecoveryEvidence;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
evidence属性evidence: RecoveryEvidence公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
output属性output: TOutput公开属性;类型、只读和可选状态以签名列为准。

RecoverySupervisorOptions

Recovery Supervisor Options 接口,共包含 18 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RecoverySupervisorOptions } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export interface RecoverySupervisorOptions {
    fsm: FSMRuntime;
    caseId: string;
    userId: string;
    tenantId?: string;
    participants: RecoveryParticipant[];
    policy?: Partial<RecoveryConvergencePolicy>;
    knowledge?: RecoveryKnowledgePort;
    trace?: TraceRecorder;
    sessionId?: string;
    workspaceId?: string;
    stepId?: string;
    agentId?: string;
    domainPackId?: string;
    scheduler?: RecoverySupervisorScheduler;
    maxInlineDelayMs?: number;
    signal?: AbortSignal;
    now?: () => string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
agentId属性agentId?: string公开属性;类型、只读和可选状态以签名列为准。
caseId属性caseId: string公开属性;类型、只读和可选状态以签名列为准。
domainPackId属性domainPackId?: string公开属性;类型、只读和可选状态以签名列为准。
fsm属性fsm: FSMRuntime公开属性;类型、只读和可选状态以签名列为准。
knowledge属性knowledge?: RecoveryKnowledgePort公开属性;类型、只读和可选状态以签名列为准。
maxInlineDelayMs属性maxInlineDelayMs?: number公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
now方法now?(): string公开方法;参数与返回类型以签名列为准。
participants属性participants: RecoveryParticipant<unknown>[]公开属性;类型、只读和可选状态以签名列为准。
policy属性policy?: Partial<RecoveryConvergencePolicy>公开属性;类型、只读和可选状态以签名列为准。
scheduler属性scheduler?: RecoverySupervisorScheduler公开属性;类型、只读和可选状态以签名列为准。
sessionId属性sessionId?: string公开属性;类型、只读和可选状态以签名列为准。
signal属性signal?: AbortSignal公开属性;类型、只读和可选状态以签名列为准。
stepId属性stepId?: string公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
trace属性trace?: TraceRecorder公开属性;类型、只读和可选状态以签名列为准。
userId属性userId: string公开属性;类型、只读和可选状态以签名列为准。
workspaceId属性workspaceId?: string公开属性;类型、只读和可选状态以签名列为准。

RecoverySupervisorResult

Recovery Supervisor Result 接口,共包含 5 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RecoverySupervisorResult } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export interface RecoverySupervisorResult {
    status: 'succeeded' | 'degraded' | 'compensated' | 'suspended' | 'quarantined' | 'failed' | 'cancelled';
    outputs: Record<string, unknown>;
    snapshot?: RecoveryCaseSnapshot;
    failure?: RecoveryFailure;
    error?: unknown;
}

契约成员

成员种类签名说明
error属性error?: unknown公开属性;类型、只读和可选状态以签名列为准。
failure属性failure?: RecoveryFailure公开属性;类型、只读和可选状态以签名列为准。
outputs属性outputs: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
snapshot属性snapshot?: RecoveryCaseSnapshot公开属性;类型、只读和可选状态以签名列为准。
status属性status: "degraded" | "cancelled" | "failed" | "quarantined" | "succeeded" | "suspended" | "compensated"公开属性;类型、只读和可选状态以签名列为准。

RecoverySupervisorScheduler

Recovery Supervisor Scheduler 接口,共包含 1 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { RecoverySupervisorScheduler } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export interface RecoverySupervisorScheduler {
    wait(delayMs: number, decision: FSMRecoveryDecision, signal?: AbortSignal): Promise<void>;
}

契约成员

成员种类签名说明
wait方法wait(delayMs: number, decision: FSMRecoveryDecision, signal?: AbortSignal): Promise<void>公开方法;参数与返回类型以签名列为准。

RecoveryParticipantAction

Recovery Participant Action 公共类型别名;完整类型表达式见声明。

  • 种类: 类型
  • 导入: import type { RecoveryParticipantAction } from '@codesoul-co/hypha-harness';
  • 源码模块: recovery-supervisor

声明

text
export type RecoveryParticipantAction<TOutput = unknown> = (context: RecoveryParticipantContext) => Promise<RecoveryParticipantResult<TOutput>>;