Skip to content

@codesoul-co/hypha-fsm / recovery

模块用法

用于处理有界恢复、重试或降级。Recovery 模块公开 7 常量、5 函数、10 接口、5 类型。

从包入口导入

ts
import {
  defaultFSMRecoveryPolicy,
  FSM_ANOMALY_CATEGORIES,
  FSM_ANOMALY_SOURCES,
  FSM_RECOVERY_ACTIONS,
  fsmAnomalySchema,
  fsmRecoveryPolicySpecSchema,
  fsmRecoverySnapshotSchema,
  classifyFSMAnomaly,
} from '@codesoul-co/hypha-fsm';

import type {
  FSMAnomaly,
  FSMAnomalyClassificationInput,
  FSMCircuitBreakerPolicy,
  FSMCircuitSnapshot,
  FSMRecoveryBackoffPolicy,
  FSMRecoveryDecision,
  FSMRecoveryPlan,
  FSMRecoveryPolicySpec,
} from '@codesoul-co/hypha-fsm';

// 完整导出列表见下方。

使用要点

  • 15 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。
  • 5 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。
  • 7 个常量/枚举提供稳定值、Schema、Definition 或默认配置;应复用这些导出,避免在应用中复制内部值。

运行时校验示例

ts
import { fsmAnomalySchema } from '@codesoul-co/hypha-fsm';

declare function loadExternalInput(): unknown;
const input: unknown = loadExternalInput();
const parsed = fsmAnomalySchema.parse(input);

配置、网络请求或持久化数据等不可信输入应先通过 Runtime Schema,再传给只接受已校验契约的函数或类。

公共导出

Symbol种类签名说明
defaultFSMRecoveryPolicy常量const defaultFSMRecoveryPolicy: FSMRecoveryPolicySpecrecovery 模块导出的 Default FSM Recovery Policy 常量。
FSM_ANOMALY_CATEGORIES常量const FSM_ANOMALY_CATEGORIES: readonly ["validation", "policy_denied", "authentication", "authorization", "rate_limit", "timeout", "transient_dependency", "permanent_dependency", "concurrency_conflict", "resource_exhausted", "tool_failure", "inference_failure", "memory_failure", "execution_failure", "storage_failure", "message_failure", "cache_failure", "invariant_violation", "cancellation", "unknown"]recovery 模块导出的 FSM ANOMALY CATEGORIES 常量。
FSM_ANOMALY_SOURCES常量const FSM_ANOMALY_SOURCES: readonly ["fsm", "inference", "tool", "memory", "execution", "mcp", "workspace", "storage", "message_bus", "cache", "policy", "domain", "unknown"]recovery 模块导出的 FSM ANOMALY SOURCES 常量。
FSM_RECOVERY_ACTIONS常量const FSM_RECOVERY_ACTIONS: readonly ["retry", "reconcile", "fallback", "degrade", "wait", "compensate", "human_review", "quarantine", "fail", "cancel"]recovery 模块导出的 FSM RECOVERY ACTIONS 常量。
fsmAnomalySchema常量const fsmAnomalySchema: z.ZodObject<{ id: z.ZodString; source: z.ZodEnum<["fsm", "inference", "tool", "memory", "execution", "mcp", "workspace", "storage", "message_bus", "cache", "policy", "domain", "unknown"]>; category: z.ZodEnum<["validation", "policy_denied", "authentication", "authorization", "rate_limit", "timeout", "transient_dependency", "permanent_dependency", "concurrency_conflict", "resource_exhausted"...FSM Anomaly 的运行时 Schema。
fsmRecoveryPolicySpecSchema常量const fsmRecoveryPolicySpecSchema: z.ZodObject<{ maxAttemptsPerState: z.ZodNumber; maxTotalAttempts: z.ZodNumber; maxElapsedMs: z.ZodNumber; retryableCategories: z.ZodArray<z.ZodEnum<["validation", "policy_denied", "authentication", "authorization", "rate_limit", "timeout", "transient_dependency", "permanent_dependency", "concurrency_conflict", "resource_exhausted", "tool_failure", "inference_failure", "memory_fai...FSM Recovery Policy Spec 的运行时 Schema。
fsmRecoverySnapshotSchema常量const fsmRecoverySnapshotSchema: z.ZodObject<{ startedAt: z.ZodString; updatedAt: z.ZodString; totalAttempts: z.ZodNumber; attemptsByState: z.ZodRecord<z.ZodString, z.ZodNumber>; circuits: z.ZodRecord<z.ZodString, z.ZodObject<{ status: z.ZodEnum<["closed", "open", "half_open"]>; consecutiveFailures: z.ZodNumber; halfOpenAttempts: z.ZodNumber; openedAt: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { status...FSM Recovery Snapshot 的运行时 Schema。
classifyFSMAnomaly函数classifyFSMAnomaly(error: unknown, input: FSMAnomalyClassificationInput): FSMAnomalyClassify FSM Anomaly 函数,提供 1 个公开调用签名;参数与返回类型见下表。
computeFSMRecoveryDelay函数computeFSMRecoveryDelay(policy: FSMRecoveryBackoffPolicy, attempt: number, seed: string): numberCompute FSM Recovery Delay 函数,提供 1 个公开调用签名;参数与返回类型见下表。
createInitialFSMRecoverySnapshot函数createInitialFSMRecoverySnapshot(now?: string): FSMRecoverySnapshotCreate Initial FSM Recovery Snapshot 函数,提供 1 个公开调用签名;参数与返回类型见下表。
planFSMRecovery函数planFSMRecovery(input: { anomaly: FSMAnomaly; stateId: string; policy?: FSMRecoveryPolicySpec; snapshot?: FSMRecoverySnapshot; now?: string; }): FSMRecoveryPlanPlan FSM Recovery 函数,提供 1 个公开调用签名;参数与返回类型见下表。
registerFSMRecoverySuccess函数registerFSMRecoverySuccess(snapshot: FSMRecoverySnapshot, circuitKey: string, now?: string): FSMRecoverySnapshotRegister FSM Recovery Success 函数,提供 1 个公开调用签名;参数与返回类型见下表。
FSMAnomaly接口interface FSMAnomalyFSM Anomaly 接口,共包含 15 个公开字段或方法。
FSMAnomalyClassificationInput接口interface FSMAnomalyClassificationInputFSM Anomaly Classification Input 接口,共包含 12 个公开字段或方法。
FSMCircuitBreakerPolicy接口interface FSMCircuitBreakerPolicyFSM Circuit Breaker Policy 接口,共包含 3 个公开字段或方法。
FSMCircuitSnapshot接口interface FSMCircuitSnapshotFSM Circuit Snapshot 接口,共包含 4 个公开字段或方法。
FSMRecoveryBackoffPolicy接口interface FSMRecoveryBackoffPolicyFSM Recovery Backoff Policy 接口,共包含 4 个公开字段或方法。
FSMRecoveryDecision接口interface FSMRecoveryDecisionFSM Recovery Decision 接口,共包含 16 个公开字段或方法。
FSMRecoveryPlan接口interface FSMRecoveryPlanFSM Recovery Plan 接口,共包含 2 个公开字段或方法。
FSMRecoveryPolicySpec接口interface FSMRecoveryPolicySpecFSM Recovery Policy Spec 接口,共包含 10 个公开字段或方法。
FSMRecoverySnapshot接口interface FSMRecoverySnapshotFSM Recovery Snapshot 接口,共包含 7 个公开字段或方法。
FSMRecoveryStateTargets接口interface FSMRecoveryStateTargetsFSM Recovery State Targets 接口,共包含 6 个公开字段或方法。
FSMAnomalyCategory类型type FSMAnomalyCategory = RecoveryCategoryFSM Anomaly Category 公共类型别名;完整类型表达式见声明。
FSMAnomalySource类型type FSMAnomalySource = RecoveryModuleFSM Anomaly Source 公共类型别名;完整类型表达式见声明。
FSMCircuitStatus类型type FSMCircuitStatus = 'closed' | 'open' | 'half_open'FSM Circuit Status 公共类型别名;完整类型表达式见声明。
FSMRecoveryAction类型type FSMRecoveryAction = (typeof FSM_RECOVERY_ACTIONS)[number]FSM Recovery Action 公共类型别名;完整类型表达式见声明。
FSMSideEffectState类型type FSMSideEffectState = RecoverySideEffectStateFSM Side Effect State 公共类型别名;完整类型表达式见声明。

defaultFSMRecoveryPolicy

recovery 模块导出的 Default FSM Recovery Policy 常量。

  • 种类: 常量
  • 导入: import { defaultFSMRecoveryPolicy } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const defaultFSMRecoveryPolicy: FSMRecoveryPolicySpec;

FSM_ANOMALY_CATEGORIES

recovery 模块导出的 FSM ANOMALY CATEGORIES 常量。

  • 种类: 常量
  • 导入: import { FSM_ANOMALY_CATEGORIES } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const FSM_ANOMALY_CATEGORIES: readonly ["validation", "policy_denied", "authentication", "authorization", "rate_limit", "timeout", "transient_dependency", "permanent_dependency", "concurrency_conflict", "resource_exhausted", "tool_failure", "inference_failure", "memory_failure", "execution_failure", "storage_failure", "message_failure", "cache_failure", "invariant_violation", "cancellation", "unknown"];

FSM_ANOMALY_SOURCES

recovery 模块导出的 FSM ANOMALY SOURCES 常量。

  • 种类: 常量
  • 导入: import { FSM_ANOMALY_SOURCES } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const FSM_ANOMALY_SOURCES: readonly ["fsm", "inference", "tool", "memory", "execution", "mcp", "workspace", "storage", "message_bus", "cache", "policy", "domain", "unknown"];

FSM_RECOVERY_ACTIONS

recovery 模块导出的 FSM RECOVERY ACTIONS 常量。

  • 种类: 常量
  • 导入: import { FSM_RECOVERY_ACTIONS } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const FSM_RECOVERY_ACTIONS: readonly ["retry", "reconcile", "fallback", "degrade", "wait", "compensate", "human_review", "quarantine", "fail", "cancel"];

fsmAnomalySchema

FSM Anomaly 的运行时 Schema。

  • 种类: 常量
  • 导入: import { fsmAnomalySchema } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const fsmAnomalySchema: z.ZodObject<{ id: z.ZodString; source: z.ZodEnum<["fsm", "inference", "tool", "memory", "execution", "mcp", "workspace", "storage", "message_bus", "cache", "policy", "domain", "unknown"]>; category: z.ZodEnum<["validation", "policy_denied", "authentication", "authorization", "rate_limit", "timeout", "transient_dependency", "permanent_dependency", "concurrency_conflict", "resource_exhausted", "tool_failure", "inference_failure", "memory_failure", "execution_failure", "storage_failure", "message_failure", "cache_failure", "invariant_violation", "cancellation", "unknown"]>; code: z.ZodString; message: z.ZodString; occurredAt: z.ZodString; retryable: z.ZodOptional<z.ZodBoolean>; retryAfterMs: z.ZodOptional<z.ZodNumber>; circuitKey: z.ZodOptional<z.ZodString>; sideEffectState: z.ZodOptional<z.ZodEnum<["none", "not_started", "committed", "unknown"]>>; compensationAvailable: z.ZodOptional<z.ZodBoolean>; reconciliationAvailable: z.ZodOptional<z.ZodBoolean>; fallbackAvailable: z.ZodOptional<z.ZodBoolean>; degradationAvailable: z.ZodOptional<z.ZodBoolean>; metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>; }, "strip", z.ZodTypeAny, { id: string; source: "fsm" | "inference" | "tool" | "memory" | "execution" | "mcp" | "workspace" | "storage" | "message_bus" | "cache" | "policy" | "domain" | "unknown"; category: "unknown" | "validation" | "policy_denied" | "authentication" | "authorization" | "rate_limit" | "timeout" | "transient_dependency" | "permanent_dependency" | "concurrency_conflict" | "resource_exhausted" | "tool_failure" | "inference_failure" | "memory_failure" | "execution_failure" | "storage_failure" | "message_failure" | "cache_failure" | "invariant_violation" | "cancellation"; code: string; message: string; occurredAt: string; retryable?: boolean | undefined; retryAfterMs?: number | undefined; circuitKey?: string | undefined; sideEffectState?: "unknown" | "none" | "not_started" | "committed" | undefined; compensationAvailable?: boolean | undefined; reconciliationAvailable?: boolean | undefined; fallbackAvailable?: boolean | undefined; degradationAvailable?: boolean | undefined; metadata?: Record<string, unknown> | undefined; }, { id: string; source: "fsm" | "inference" | "tool" | "memory" | "execution" | "mcp" | "workspace" | "storage" | "message_bus" | "cache" | "policy" | "domain" | "unknown"; category: "unknown" | "validation" | "policy_denied" | "authentication" | "authorization" | "rate_limit" | "timeout" | "transient_dependency" | "permanent_dependency" | "concurrency_conflict" | "resource_exhausted" | "tool_failure" | "inference_failure" | "memory_failure" | "execution_failure" | "storage_failure" | "message_failure" | "cache_failure" | "invariant_violation" | "cancellation"; code: string; message: string; occurredAt: string; retryable?: boolean | undefined; retryAfterMs?: number | undefined; circuitKey?: string | undefined; sideEffectState?: "unknown" | "none" | "not_started" | "committed" | undefined; compensationAvailable?: boolean | undefined; reconciliationAvailable?: boolean | undefined; fallbackAvailable?: boolean | undefined; degradationAvailable?: boolean | undefined; metadata?: Record<string, unknown> | undefined; }>;

fsmRecoveryPolicySpecSchema

FSM Recovery Policy Spec 的运行时 Schema。

  • 种类: 常量
  • 导入: import { fsmRecoveryPolicySpecSchema } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const fsmRecoveryPolicySpecSchema: z.ZodObject<{ maxAttemptsPerState: z.ZodNumber; maxTotalAttempts: z.ZodNumber; maxElapsedMs: z.ZodNumber; retryableCategories: z.ZodArray<z.ZodEnum<["validation", "policy_denied", "authentication", "authorization", "rate_limit", "timeout", "transient_dependency", "permanent_dependency", "concurrency_conflict", "resource_exhausted", "tool_failure", "inference_failure", "memory_failure", "execution_failure", "storage_failure", "message_failure", "cache_failure", "invariant_violation", "cancellation", "unknown"]>, "many">; nonRetryableCodes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; backoff: z.ZodObject<{ initialDelayMs: z.ZodNumber; maxDelayMs: z.ZodNumber; multiplier: z.ZodNumber; jitterRatio: z.ZodNumber; }, "strip", z.ZodTypeAny, { initialDelayMs: number; maxDelayMs: number; multiplier: number; jitterRatio: number; }, { initialDelayMs: number; maxDelayMs: number; multiplier: number; jitterRatio: number; }>; circuitBreaker: z.ZodObject<{ failureThreshold: z.ZodNumber; resetTimeoutMs: z.ZodNumber; halfOpenMaxAttempts: z.ZodNumber; }, "strip", z.ZodTypeAny, { failureThreshold: number; resetTimeoutMs: number; halfOpenMaxAttempts: number; }, { failureThreshold: number; resetTimeoutMs: number; halfOpenMaxAttempts: number; }>; stateTargets: z.ZodObject<{ recovering: z.ZodString; compensating: z.ZodString; humanReview: z.ZodString; quarantined: z.ZodString; failed: z.ZodString; cancelled: z.ZodString; }, "strip", z.ZodTypeAny, { recovering: string; compensating: string; humanReview: string; quarantined: string; failed: string; cancelled: string; }, { recovering: string; compensating: string; humanReview: string; quarantined: string; failed: string; cancelled: string; }>; onExhausted: z.ZodEnum<["human_review", "quarantine", "fail"]>; afterCompensation: z.ZodEnum<["human_review", "quarantine", "fail"]>; }, "strip", z.ZodTypeAny, { maxAttemptsPerState: number; maxTotalAttempts: number; maxElapsedMs: number; retryableCategories: ("unknown" | "validation" | "policy_denied" | "authentication" | "authorization" | "rate_limit" | "timeout" | "transient_dependency" | "permanent_dependency" | "concurrency_conflict" | "resource_exhausted" | "tool_failure" | "inference_failure" | "memory_failure" | "execution_failure" | "storage_failure" | "message_failure" | "cache_failure" | "invariant_violation" | "cancellation")[]; backoff: { initialDelayMs: number; maxDelayMs: number; multiplier: number; jitterRatio: number; }; circuitBreaker: { failureThreshold: number; resetTimeoutMs: number; halfOpenMaxAttempts: number; }; stateTargets: { recovering: string; compensating: string; humanReview: string; quarantined: string; failed: string; cancelled: string; }; onExhausted: "human_review" | "quarantine" | "fail"; afterCompensation: "human_review" | "quarantine" | "fail"; nonRetryableCodes?: string[] | undefined; }, { maxAttemptsPerState: number; maxTotalAttempts: number; maxElapsedMs: number; retryableCategories: ("unknown" | "validation" | "policy_denied" | "authentication" | "authorization" | "rate_limit" | "timeout" | "transient_dependency" | "permanent_dependency" | "concurrency_conflict" | "resource_exhausted" | "tool_failure" | "inference_failure" | "memory_failure" | "execution_failure" | "storage_failure" | "message_failure" | "cache_failure" | "invariant_violation" | "cancellation")[]; backoff: { initialDelayMs: number; maxDelayMs: number; multiplier: number; jitterRatio: number; }; circuitBreaker: { failureThreshold: number; resetTimeoutMs: number; halfOpenMaxAttempts: number; }; stateTargets: { recovering: string; compensating: string; humanReview: string; quarantined: string; failed: string; cancelled: string; }; onExhausted: "human_review" | "quarantine" | "fail"; afterCompensation: "human_review" | "quarantine" | "fail"; nonRetryableCodes?: string[] | undefined; }>;

fsmRecoverySnapshotSchema

FSM Recovery Snapshot 的运行时 Schema。

  • 种类: 常量
  • 导入: import { fsmRecoverySnapshotSchema } from '@codesoul-co/hypha-fsm';
  • 源码模块: recovery

声明

text
export declare const fsmRecoverySnapshotSchema: z.ZodObject<{ startedAt: z.ZodString; updatedAt: z.ZodString; totalAttempts: z.ZodNumber; attemptsByState: z.ZodRecord<z.ZodString, z.ZodNumber>; circuits: z.ZodRecord<z.ZodString, z.ZodObject<{ status: z.ZodEnum<["closed", "open", "half_open"]>; consecutiveFailures: z.ZodNumber; halfOpenAttempts: z.ZodNumber; openedAt: z.ZodOptional<z.ZodString>; }, "strip", z.ZodTypeAny, { status: "closed" | "open" | "half_open"; consecutiveFailures: number; halfOpenAttempts: number; openedAt?: string | undefined; }, { status: "closed" | "open" | "half_open"; consecutiveFailures: number; halfOpenAttempts: number; openedAt?: string | undefined; }>>; lastAnomalyId: z.ZodOptional<z.ZodString>; lastAction: z.ZodOptional<z.ZodEnum<["retry", "reconcile", "fallback", "degrade", "wait", "compensate", "human_review", "quarantine", "fail", "cancel"]>>; }, "strip", z.ZodTypeAny, { startedAt: string; updatedAt: string; totalAttempts: number; attemptsByState: Record<string, number>; circuits: Record<string, { status: "closed" | "open" | "half_open"; consecutiveFailures: number; halfOpenAttempts: number; openedAt?: string | undefined; }>; lastAnomalyId?: string | undefined; lastAction?: "retry" | "reconcile" | "fallback" | "degrade" | "wait" | "compensate" | "human_review" | "quarantine" | "fail" | "cancel" | undefined; }, { startedAt: string; updatedAt: string; totalAttempts: number; attemptsByState: Record<string, number>; circuits: Record<string, { status: "closed" | "open" | "half_open"; consecutiveFailures: number; halfOpenAttempts: number; openedAt?: string | undefined; }>; lastAnomalyId?: string | undefined; lastAction?: "retry" | "reconcile" | "fallback" | "degrade" | "wait" | "compensate" | "human_review" | "quarantine" | "fail" | "cancel" | undefined; }>;

classifyFSMAnomaly

Classify FSM Anomaly 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function classifyFSMAnomaly(error: unknown, input: FSMAnomalyClassificationInput): FSMAnomaly;

调用签名

text
classifyFSMAnomaly(error: unknown, input: FSMAnomalyClassificationInput): FSMAnomaly

参数

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

返回值

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

computeFSMRecoveryDelay

Compute FSM Recovery Delay 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function computeFSMRecoveryDelay(policy: FSMRecoveryBackoffPolicy, attempt: number, seed: string): number;

调用签名

text
computeFSMRecoveryDelay(policy: FSMRecoveryBackoffPolicy, attempt: number, seed: string): number

参数

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

返回值

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

createInitialFSMRecoverySnapshot

Create Initial FSM Recovery Snapshot 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function createInitialFSMRecoverySnapshot(now?: string): FSMRecoverySnapshot;

调用签名

text
createInitialFSMRecoverySnapshot(now?: string): FSMRecoverySnapshot

参数

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

返回值

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

planFSMRecovery

Plan FSM Recovery 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function planFSMRecovery(input: {
    anomaly: FSMAnomaly;
    stateId: string;
    policy?: FSMRecoveryPolicySpec;
    snapshot?: FSMRecoverySnapshot;
    now?: string;
}): FSMRecoveryPlan;

调用签名

text
planFSMRecovery(input: { anomaly: FSMAnomaly; stateId: string; policy?: FSMRecoveryPolicySpec; snapshot?: FSMRecoverySnapshot; now?: string; }): FSMRecoveryPlan

参数

参数类型必需说明
input{ anomaly: FSMAnomaly; stateId: string; policy?: FSMRecoveryPolicySpec; snapshot?: FSMRecoverySnapshot; now?: string; }必需参数;接受的值由类型列定义。

返回值

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

registerFSMRecoverySuccess

Register FSM Recovery Success 函数,提供 1 个公开调用签名;参数与返回类型见下表。

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

声明

text
export declare function registerFSMRecoverySuccess(snapshot: FSMRecoverySnapshot, circuitKey: string, now?: string): FSMRecoverySnapshot;

调用签名

text
registerFSMRecoverySuccess(snapshot: FSMRecoverySnapshot, circuitKey: string, now?: string): FSMRecoverySnapshot

参数

参数类型必需说明
snapshotFSMRecoverySnapshot必需参数;接受的值由类型列定义。
circuitKeystring必需参数;接受的值由类型列定义。
nowstring可选参数;接受的值由类型列定义。

返回值

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

FSMAnomaly

FSM Anomaly 接口,共包含 15 个公开字段或方法。

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

声明

text
export interface FSMAnomaly {
    id: string;
    source: FSMAnomalySource;
    category: FSMAnomalyCategory;
    code: string;
    message: string;
    occurredAt: string;
    retryable?: boolean;
    retryAfterMs?: number;
    circuitKey?: string;
    sideEffectState?: FSMSideEffectState;
    compensationAvailable?: boolean;
    reconciliationAvailable?: boolean;
    fallbackAvailable?: boolean;
    degradationAvailable?: boolean;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
category属性category: "unknown" | "cancellation" | "timeout" | "validation" | "policy_denied" | "authentication" | "authorization" | "rate_limit" | "transient_dependency" | "permanent_dependency" | "concurrency_conflict" | "resource_exhausted" | "tool_failure" | "inference_failure" | "memory_failure" | "execution_failure" | "storage_failure" | "message_failure" | "cache_failure" | "invariant_violation"公开属性;类型、只读和可选状态以签名列为准。
circuitKey属性circuitKey?: string公开属性;类型、只读和可选状态以签名列为准。
code属性code: string公开属性;类型、只读和可选状态以签名列为准。
compensationAvailable属性compensationAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
degradationAvailable属性degradationAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
fallbackAvailable属性fallbackAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
message属性message: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
occurredAt属性occurredAt: string公开属性;类型、只读和可选状态以签名列为准。
reconciliationAvailable属性reconciliationAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
retryable属性retryable?: boolean公开属性;类型、只读和可选状态以签名列为准。
retryAfterMs属性retryAfterMs?: number公开属性;类型、只读和可选状态以签名列为准。
sideEffectState属性sideEffectState?: RecoverySideEffectState公开属性;类型、只读和可选状态以签名列为准。
source属性source: "memory" | "domain" | "mcp" | "policy" | "workspace" | "tool" | "unknown" | "execution" | "fsm" | "inference" | "storage" | "message_bus" | "cache"公开属性;类型、只读和可选状态以签名列为准。

FSMAnomalyClassificationInput

FSM Anomaly Classification Input 接口,共包含 12 个公开字段或方法。

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

声明

text
export interface FSMAnomalyClassificationInput {
    id: string;
    source?: FSMAnomalySource;
    occurredAt?: string;
    sideEffectState?: FSMSideEffectState;
    compensationAvailable?: boolean;
    reconciliationAvailable?: boolean;
    fallbackAvailable?: boolean;
    degradationAvailable?: boolean;
    retryable?: boolean;
    retryAfterMs?: number;
    circuitKey?: string;
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
circuitKey属性circuitKey?: string公开属性;类型、只读和可选状态以签名列为准。
compensationAvailable属性compensationAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
degradationAvailable属性degradationAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
fallbackAvailable属性fallbackAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
id属性id: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
occurredAt属性occurredAt?: string公开属性;类型、只读和可选状态以签名列为准。
reconciliationAvailable属性reconciliationAvailable?: boolean公开属性;类型、只读和可选状态以签名列为准。
retryable属性retryable?: boolean公开属性;类型、只读和可选状态以签名列为准。
retryAfterMs属性retryAfterMs?: number公开属性;类型、只读和可选状态以签名列为准。
sideEffectState属性sideEffectState?: RecoverySideEffectState公开属性;类型、只读和可选状态以签名列为准。
source属性source?: "memory" | "domain" | "mcp" | "policy" | "workspace" | "tool" | "unknown" | "execution" | "fsm" | "inference" | "storage" | "message_bus" | "cache"公开属性;类型、只读和可选状态以签名列为准。

FSMCircuitBreakerPolicy

FSM Circuit Breaker Policy 接口,共包含 3 个公开字段或方法。

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

声明

text
export interface FSMCircuitBreakerPolicy {
    failureThreshold: number;
    resetTimeoutMs: number;
    halfOpenMaxAttempts: number;
}

契约成员

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

FSMCircuitSnapshot

FSM Circuit Snapshot 接口,共包含 4 个公开字段或方法。

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

声明

text
export interface FSMCircuitSnapshot {
    status: FSMCircuitStatus;
    consecutiveFailures: number;
    halfOpenAttempts: number;
    openedAt?: string;
}

契约成员

成员种类签名说明
consecutiveFailures属性consecutiveFailures: number公开属性;类型、只读和可选状态以签名列为准。
halfOpenAttempts属性halfOpenAttempts: number公开属性;类型、只读和可选状态以签名列为准。
openedAt属性openedAt?: string公开属性;类型、只读和可选状态以签名列为准。
status属性status: FSMCircuitStatus公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryBackoffPolicy

FSM Recovery Backoff Policy 接口,共包含 4 个公开字段或方法。

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

声明

text
export interface FSMRecoveryBackoffPolicy {
    initialDelayMs: number;
    maxDelayMs: number;
    multiplier: number;
    jitterRatio: number;
}

契约成员

成员种类签名说明
initialDelayMs属性initialDelayMs: number公开属性;类型、只读和可选状态以签名列为准。
jitterRatio属性jitterRatio: number公开属性;类型、只读和可选状态以签名列为准。
maxDelayMs属性maxDelayMs: number公开属性;类型、只读和可选状态以签名列为准。
multiplier属性multiplier: number公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryDecision

FSM Recovery Decision 接口,共包含 16 个公开字段或方法。

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

声明

text
export interface FSMRecoveryDecision {
    anomaly: FSMAnomaly;
    action: FSMRecoveryAction;
    fromState: string;
    transitionState: string;
    resumeState?: string;
    attempt: number;
    totalAttempts: number;
    delayMs: number;
    decidedAt: string;
    nextEligibleAt?: string;
    circuitKey: string;
    circuitStatus: FSMCircuitStatus;
    reason: string;
    quarantineState: string;
    afterCompensationAction?: Extract<FSMRecoveryAction, 'human_review' | 'quarantine' | 'fail'>;
    afterCompensationState?: string;
}

契约成员

成员种类签名说明
action属性action: "fail" | "retry" | "human_review" | "reconcile" | "fallback" | "degrade" | "compensate" | "wait" | "quarantine" | "cancel"公开属性;类型、只读和可选状态以签名列为准。
afterCompensationAction属性afterCompensationAction?: "fail" | "human_review" | "quarantine"公开属性;类型、只读和可选状态以签名列为准。
afterCompensationState属性afterCompensationState?: string公开属性;类型、只读和可选状态以签名列为准。
anomaly属性anomaly: FSMAnomaly公开属性;类型、只读和可选状态以签名列为准。
attempt属性attempt: number公开属性;类型、只读和可选状态以签名列为准。
circuitKey属性circuitKey: string公开属性;类型、只读和可选状态以签名列为准。
circuitStatus属性circuitStatus: FSMCircuitStatus公开属性;类型、只读和可选状态以签名列为准。
decidedAt属性decidedAt: string公开属性;类型、只读和可选状态以签名列为准。
delayMs属性delayMs: number公开属性;类型、只读和可选状态以签名列为准。
fromState属性fromState: string公开属性;类型、只读和可选状态以签名列为准。
nextEligibleAt属性nextEligibleAt?: string公开属性;类型、只读和可选状态以签名列为准。
quarantineState属性quarantineState: string公开属性;类型、只读和可选状态以签名列为准。
reason属性reason: string公开属性;类型、只读和可选状态以签名列为准。
resumeState属性resumeState?: string公开属性;类型、只读和可选状态以签名列为准。
totalAttempts属性totalAttempts: number公开属性;类型、只读和可选状态以签名列为准。
transitionState属性transitionState: string公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryPlan

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

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

声明

text
export interface FSMRecoveryPlan {
    decision: FSMRecoveryDecision;
    snapshot: FSMRecoverySnapshot;
}

契约成员

成员种类签名说明
decision属性decision: FSMRecoveryDecision公开属性;类型、只读和可选状态以签名列为准。
snapshot属性snapshot: FSMRecoverySnapshot公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryPolicySpec

FSM Recovery Policy Spec 接口,共包含 10 个公开字段或方法。

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

声明

text
export interface FSMRecoveryPolicySpec {
    maxAttemptsPerState: number;
    maxTotalAttempts: number;
    maxElapsedMs: number;
    retryableCategories: FSMAnomalyCategory[];
    nonRetryableCodes?: string[];
    backoff: FSMRecoveryBackoffPolicy;
    circuitBreaker: FSMCircuitBreakerPolicy;
    stateTargets: FSMRecoveryStateTargets;
    onExhausted: Extract<FSMRecoveryAction, 'human_review' | 'quarantine' | 'fail'>;
    afterCompensation: Extract<FSMRecoveryAction, 'human_review' | 'quarantine' | 'fail'>;
}

契约成员

成员种类签名说明
afterCompensation属性afterCompensation: "fail" | "human_review" | "quarantine"公开属性;类型、只读和可选状态以签名列为准。
backoff属性backoff: FSMRecoveryBackoffPolicy公开属性;类型、只读和可选状态以签名列为准。
circuitBreaker属性circuitBreaker: FSMCircuitBreakerPolicy公开属性;类型、只读和可选状态以签名列为准。
maxAttemptsPerState属性maxAttemptsPerState: number公开属性;类型、只读和可选状态以签名列为准。
maxElapsedMs属性maxElapsedMs: number公开属性;类型、只读和可选状态以签名列为准。
maxTotalAttempts属性maxTotalAttempts: number公开属性;类型、只读和可选状态以签名列为准。
nonRetryableCodes属性nonRetryableCodes?: string[]公开属性;类型、只读和可选状态以签名列为准。
onExhausted属性onExhausted: "fail" | "human_review" | "quarantine"公开属性;类型、只读和可选状态以签名列为准。
retryableCategories属性retryableCategories: ("unknown" | "cancellation" | "timeout" | "validation" | "policy_denied" | "authentication" | "authorization" | "rate_limit" | "transient_dependency" | "permanent_dependency" | "concurrency_conflict" | "resource_exhausted" | "tool_failure" | "inference_failure" | "memory_failure" | "execution_failure" | "storage_failure" | "message_failure" | "cache_failure" | "invariant_violation")[]公开属性;类型、只读和可选状态以签名列为准。
stateTargets属性stateTargets: FSMRecoveryStateTargets公开属性;类型、只读和可选状态以签名列为准。

FSMRecoverySnapshot

FSM Recovery Snapshot 接口,共包含 7 个公开字段或方法。

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

声明

text
export interface FSMRecoverySnapshot {
    startedAt: string;
    updatedAt: string;
    totalAttempts: number;
    attemptsByState: Record<string, number>;
    circuits: Record<string, FSMCircuitSnapshot>;
    lastAnomalyId?: string;
    lastAction?: FSMRecoveryAction;
}

契约成员

成员种类签名说明
attemptsByState属性attemptsByState: Record<string, number>公开属性;类型、只读和可选状态以签名列为准。
circuits属性circuits: Record<string, FSMCircuitSnapshot>公开属性;类型、只读和可选状态以签名列为准。
lastAction属性lastAction?: "fail" | "retry" | "human_review" | "reconcile" | "fallback" | "degrade" | "compensate" | "wait" | "quarantine" | "cancel"公开属性;类型、只读和可选状态以签名列为准。
lastAnomalyId属性lastAnomalyId?: string公开属性;类型、只读和可选状态以签名列为准。
startedAt属性startedAt: string公开属性;类型、只读和可选状态以签名列为准。
totalAttempts属性totalAttempts: number公开属性;类型、只读和可选状态以签名列为准。
updatedAt属性updatedAt: string公开属性;类型、只读和可选状态以签名列为准。

FSMRecoveryStateTargets

FSM Recovery State Targets 接口,共包含 6 个公开字段或方法。

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

声明

text
export interface FSMRecoveryStateTargets {
    recovering: string;
    compensating: string;
    humanReview: string;
    quarantined: string;
    failed: string;
    cancelled: string;
}

契约成员

成员种类签名说明
cancelled属性cancelled: string公开属性;类型、只读和可选状态以签名列为准。
compensating属性compensating: string公开属性;类型、只读和可选状态以签名列为准。
failed属性failed: string公开属性;类型、只读和可选状态以签名列为准。
humanReview属性humanReview: string公开属性;类型、只读和可选状态以签名列为准。
quarantined属性quarantined: string公开属性;类型、只读和可选状态以签名列为准。
recovering属性recovering: string公开属性;类型、只读和可选状态以签名列为准。

FSMAnomalyCategory

FSM Anomaly Category 公共类型别名;完整类型表达式见声明。

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

声明

text
export type FSMAnomalyCategory = RecoveryCategory;

FSMAnomalySource

FSM Anomaly Source 公共类型别名;完整类型表达式见声明。

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

声明

text
export type FSMAnomalySource = RecoveryModule;

FSMCircuitStatus

FSM Circuit Status 公共类型别名;完整类型表达式见声明。

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

声明

text
export type FSMCircuitStatus = 'closed' | 'open' | 'half_open';

FSMRecoveryAction

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

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

声明

text
export type FSMRecoveryAction = (typeof FSM_RECOVERY_ACTIONS)[number];

FSMSideEffectState

FSM Side Effect State 公共类型别名;完整类型表达式见声明。

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

声明

text
export type FSMSideEffectState = RecoverySideEffectState;