Skip to content

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

模块用法

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

从包入口导入

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

import type {
  FSMRecoveryAttemptContext,
  FSMRecoveryLoopOptions,
  FSMRecoveryLoopResult,
  FSMRecoveryLoopScheduler,
} from '@codesoul-co/hypha-harness';

使用要点

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

公共导出

Symbol种类签名说明
runFSMRecoveryLoop函数runFSMRecoveryLoop<TOutput>(options: FSMRecoveryLoopOptions<TOutput>): Promise<FSMRecoveryLoopResult<TOutput>>Runs only the bounded recovery loop described by the FSM recovery policy. Delayed retries are suspended by default; a caller must inject a scheduler and explicitly opt into an inline delay budget to keep them in-process.
FSMRecoveryAttemptContext接口interface FSMRecoveryAttemptContextFSM Recovery Attempt Context 接口,共包含 2 个公开字段或方法。
FSMRecoveryLoopOptions接口interface FSMRecoveryLoopOptionsFSM Recovery Loop Options 接口,共包含 12 个公开字段或方法。
FSMRecoveryLoopResult接口interface FSMRecoveryLoopResultFSM Recovery Loop Result 接口,共包含 5 个公开字段或方法。
FSMRecoveryLoopScheduler接口interface FSMRecoveryLoopSchedulerFSM Recovery Loop Scheduler 接口,共包含 1 个公开字段或方法。

runFSMRecoveryLoop

Runs only the bounded recovery loop described by the FSM recovery policy. Delayed retries are suspended by default; a caller must inject a scheduler and explicitly opt into an inline delay budget to keep them in-process.

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

声明

text
export declare function runFSMRecoveryLoop<TOutput>(options: FSMRecoveryLoopOptions<TOutput>): Promise<FSMRecoveryLoopResult<TOutput>>;

调用签名

text
runFSMRecoveryLoop<TOutput>(options: FSMRecoveryLoopOptions<TOutput>): Promise<FSMRecoveryLoopResult<TOutput>>

Runs only the bounded recovery loop described by the FSM recovery policy. Delayed retries are suspended by default; a caller must inject a scheduler and explicitly opt into an inline delay budget to keep them in-process.

参数

参数类型必需说明
optionsFSMRecoveryLoopOptions<TOutput>必需参数;接受的值由类型列定义。

返回值

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

FSMRecoveryAttemptContext

FSM Recovery Attempt Context 接口,共包含 2 个公开字段或方法。

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

声明

text
export interface FSMRecoveryAttemptContext {
    attempt: number;
    signal?: AbortSignal;
}

契约成员

成员种类签名说明
attempt属性attempt: number公开属性;类型、只读和可选状态以签名列为准。
signal属性signal?: AbortSignal公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryLoopOptions

FSM Recovery Loop Options 接口,共包含 12 个公开字段或方法。

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

声明

text
export interface FSMRecoveryLoopOptions<TOutput> {
    fsm: FSMRuntime;
    source: FSMAnomalySource;
    execute(context: FSMRecoveryAttemptContext): Promise<TOutput>;
    classify?: (error: unknown, context: FSMRecoveryAttemptContext) => FSMAnomaly | Promise<FSMAnomaly>;
    compensate?: (decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext) => Promise<void>;
    reconcile?: (decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext) => Promise<TOutput>;
    fallback?: (decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext) => Promise<TOutput>;
    degrade?: (decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext) => Promise<TOutput>;
    scheduler?: FSMRecoveryLoopScheduler;
    maxInlineDelayMs?: number;
    signal?: AbortSignal;
    now?: () => string;
}

契约成员

成员种类签名说明
classify方法classify?(error: unknown, context: FSMRecoveryAttemptContext): FSMAnomaly | Promise<FSMAnomaly>公开方法;参数与返回类型以签名列为准。
compensate方法compensate?(decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext): Promise<void>公开方法;参数与返回类型以签名列为准。
degrade方法degrade?(decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext): Promise<TOutput>公开方法;参数与返回类型以签名列为准。
execute方法execute(context: FSMRecoveryAttemptContext): Promise<TOutput>公开方法;参数与返回类型以签名列为准。
fallback方法fallback?(decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext): Promise<TOutput>公开方法;参数与返回类型以签名列为准。
fsm属性fsm: FSMRuntime公开属性;类型、只读和可选状态以签名列为准。
maxInlineDelayMs属性maxInlineDelayMs?: number公开属性;类型、只读和可选状态以签名列为准。
now方法now?(): string公开方法;参数与返回类型以签名列为准。
reconcile方法reconcile?(decision: FSMRecoveryDecision, context: FSMRecoveryAttemptContext): Promise<TOutput>公开方法;参数与返回类型以签名列为准。
scheduler属性scheduler?: FSMRecoveryLoopScheduler公开属性;类型、只读和可选状态以签名列为准。
signal属性signal?: AbortSignal公开属性;类型、只读和可选状态以签名列为准。
source属性source: "memory" | "domain" | "mcp" | "policy" | "workspace" | "tool" | "unknown" | "execution" | "fsm" | "inference" | "storage" | "message_bus" | "cache"公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryLoopResult

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

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

声明

text
export interface FSMRecoveryLoopResult<TOutput> {
    status: 'succeeded' | 'degraded' | 'suspended' | 'compensated' | 'failed' | 'cancelled';
    output?: TOutput;
    error?: unknown;
    decision?: FSMRecoveryDecision;
    attempts: number;
}

契约成员

成员种类签名说明
attempts属性attempts: number公开属性;类型、只读和可选状态以签名列为准。
decision属性decision?: FSMRecoveryDecision公开属性;类型、只读和可选状态以签名列为准。
error属性error?: unknown公开属性;类型、只读和可选状态以签名列为准。
output属性output?: TOutput公开属性;类型、只读和可选状态以签名列为准。
status属性status: "degraded" | "cancelled" | "failed" | "succeeded" | "suspended" | "compensated"公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryLoopScheduler

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

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

声明

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

契约成员

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