@codesoul-co/hypha-fsm / recovery
- 包索引:
@codesoul-co/hypha-fsm - 源码:
packages/fsm/src/recovery.ts - 导出数: 27
模块用法
用于处理有界恢复、重试或降级。Recovery 模块公开 7 常量、5 函数、10 接口、5 类型。
从包入口导入
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 或默认配置;应复用这些导出,避免在应用中复制内部值。
运行时校验示例
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: FSMRecoveryPolicySpec | 由 recovery 模块导出的 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): FSMAnomaly | Classify FSM Anomaly 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
computeFSMRecoveryDelay | 函数 | computeFSMRecoveryDelay(policy: FSMRecoveryBackoffPolicy, attempt: number, seed: string): number | Compute FSM Recovery Delay 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
createInitialFSMRecoverySnapshot | 函数 | createInitialFSMRecoverySnapshot(now?: string): FSMRecoverySnapshot | Create Initial FSM Recovery Snapshot 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
planFSMRecovery | 函数 | planFSMRecovery(input: { anomaly: FSMAnomaly; stateId: string; policy?: FSMRecoveryPolicySpec; snapshot?: FSMRecoverySnapshot; now?: string; }): FSMRecoveryPlan | Plan FSM Recovery 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
registerFSMRecoverySuccess | 函数 | registerFSMRecoverySuccess(snapshot: FSMRecoverySnapshot, circuitKey: string, now?: string): FSMRecoverySnapshot | Register FSM Recovery Success 函数,提供 1 个公开调用签名;参数与返回类型见下表。 |
FSMAnomaly | 接口 | interface FSMAnomaly | FSM Anomaly 接口,共包含 15 个公开字段或方法。 |
FSMAnomalyClassificationInput | 接口 | interface FSMAnomalyClassificationInput | FSM Anomaly Classification Input 接口,共包含 12 个公开字段或方法。 |
FSMCircuitBreakerPolicy | 接口 | interface FSMCircuitBreakerPolicy | FSM Circuit Breaker Policy 接口,共包含 3 个公开字段或方法。 |
FSMCircuitSnapshot | 接口 | interface FSMCircuitSnapshot | FSM Circuit Snapshot 接口,共包含 4 个公开字段或方法。 |
FSMRecoveryBackoffPolicy | 接口 | interface FSMRecoveryBackoffPolicy | FSM Recovery Backoff Policy 接口,共包含 4 个公开字段或方法。 |
FSMRecoveryDecision | 接口 | interface FSMRecoveryDecision | FSM Recovery Decision 接口,共包含 16 个公开字段或方法。 |
FSMRecoveryPlan | 接口 | interface FSMRecoveryPlan | FSM Recovery Plan 接口,共包含 2 个公开字段或方法。 |
FSMRecoveryPolicySpec | 接口 | interface FSMRecoveryPolicySpec | FSM Recovery Policy Spec 接口,共包含 10 个公开字段或方法。 |
FSMRecoverySnapshot | 接口 | interface FSMRecoverySnapshot | FSM Recovery Snapshot 接口,共包含 7 个公开字段或方法。 |
FSMRecoveryStateTargets | 接口 | interface FSMRecoveryStateTargets | FSM Recovery State Targets 接口,共包含 6 个公开字段或方法。 |
FSMAnomalyCategory | 类型 | type FSMAnomalyCategory = RecoveryCategory | FSM Anomaly Category 公共类型别名;完整类型表达式见声明。 |
FSMAnomalySource | 类型 | type FSMAnomalySource = RecoveryModule | FSM 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 = RecoverySideEffectState | FSM Side Effect State 公共类型别名;完整类型表达式见声明。 |
defaultFSMRecoveryPolicy
由 recovery 模块导出的 Default FSM Recovery Policy 常量。
- 种类: 常量
- 导入:
import { defaultFSMRecoveryPolicy } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export declare const defaultFSMRecoveryPolicy: FSMRecoveryPolicySpec;FSM_ANOMALY_CATEGORIES
由 recovery 模块导出的 FSM ANOMALY CATEGORIES 常量。
- 种类: 常量
- 导入:
import { FSM_ANOMALY_CATEGORIES } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
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
声明
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
声明
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
声明
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
声明
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
声明
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
声明
export declare function classifyFSMAnomaly(error: unknown, input: FSMAnomalyClassificationInput): FSMAnomaly;调用签名
classifyFSMAnomaly(error: unknown, input: FSMAnomalyClassificationInput): FSMAnomaly参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
error | unknown | 是 | 必需参数;接受的值由类型列定义。 |
input | FSMAnomalyClassificationInput | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
FSMAnomaly - 说明: 返回值契约由上述类型定义。
computeFSMRecoveryDelay
Compute FSM Recovery Delay 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { computeFSMRecoveryDelay } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export declare function computeFSMRecoveryDelay(policy: FSMRecoveryBackoffPolicy, attempt: number, seed: string): number;调用签名
computeFSMRecoveryDelay(policy: FSMRecoveryBackoffPolicy, attempt: number, seed: string): number参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
policy | FSMRecoveryBackoffPolicy | 是 | 必需参数;接受的值由类型列定义。 |
attempt | number | 是 | 必需参数;接受的值由类型列定义。 |
seed | string | 是 | 必需参数;接受的值由类型列定义。 |
返回值
- 类型:
number - 说明: 返回值契约由上述类型定义。
createInitialFSMRecoverySnapshot
Create Initial FSM Recovery Snapshot 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { createInitialFSMRecoverySnapshot } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export declare function createInitialFSMRecoverySnapshot(now?: string): FSMRecoverySnapshot;调用签名
createInitialFSMRecoverySnapshot(now?: string): FSMRecoverySnapshot参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
now | string | 否 | 可选参数;接受的值由类型列定义。 |
返回值
- 类型:
FSMRecoverySnapshot - 说明: 返回值契约由上述类型定义。
planFSMRecovery
Plan FSM Recovery 函数,提供 1 个公开调用签名;参数与返回类型见下表。
- 种类: 函数
- 导入:
import { planFSMRecovery } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export declare function planFSMRecovery(input: {
anomaly: FSMAnomaly;
stateId: string;
policy?: FSMRecoveryPolicySpec;
snapshot?: FSMRecoverySnapshot;
now?: string;
}): FSMRecoveryPlan;调用签名
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
声明
export declare function registerFSMRecoverySuccess(snapshot: FSMRecoverySnapshot, circuitKey: string, now?: string): FSMRecoverySnapshot;调用签名
registerFSMRecoverySuccess(snapshot: FSMRecoverySnapshot, circuitKey: string, now?: string): FSMRecoverySnapshot参数
| 参数 | 类型 | 必需 | 说明 |
|---|---|---|---|
snapshot | FSMRecoverySnapshot | 是 | 必需参数;接受的值由类型列定义。 |
circuitKey | string | 是 | 必需参数;接受的值由类型列定义。 |
now | string | 否 | 可选参数;接受的值由类型列定义。 |
返回值
- 类型:
FSMRecoverySnapshot - 说明: 返回值契约由上述类型定义。
FSMAnomaly
FSM Anomaly 接口,共包含 15 个公开字段或方法。
- 种类: 接口
- 导入:
import type { FSMAnomaly } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
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
声明
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
声明
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
声明
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
声明
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
声明
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
声明
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
声明
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
声明
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
声明
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
声明
export type FSMAnomalyCategory = RecoveryCategory;FSMAnomalySource
FSM Anomaly Source 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { FSMAnomalySource } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export type FSMAnomalySource = RecoveryModule;FSMCircuitStatus
FSM Circuit Status 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { FSMCircuitStatus } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export type FSMCircuitStatus = 'closed' | 'open' | 'half_open';FSMRecoveryAction
FSM Recovery Action 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { FSMRecoveryAction } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export type FSMRecoveryAction = (typeof FSM_RECOVERY_ACTIONS)[number];FSMSideEffectState
FSM Side Effect State 公共类型别名;完整类型表达式见声明。
- 种类: 类型
- 导入:
import type { FSMSideEffectState } from '@codesoul-co/hypha-fsm'; - 源码模块:
recovery
声明
export type FSMSideEffectState = RecoverySideEffectState;