Skip to content

@codesoul-co/hypha-core / contracts/execution

模块用法

用于声明并运行时校验契约。Execution 模块公开 3 接口。

从包入口导入

ts
import type {
  ExecutionPrincipal,
  NormalizedExecutionError,
  ProviderHealth,
} from '@codesoul-co/hypha-core';

使用要点

  • 3 个类型/接口用于应用代码、Adapter 或测试中的静态契约;请使用 import type,运行时不应依赖它们。

公共导出

Symbol种类签名说明
ExecutionPrincipal接口interface ExecutionPrincipalExecution Principal 接口,共包含 8 个公开字段或方法。
NormalizedExecutionError接口interface NormalizedExecutionErrorNormalized Execution Error 接口,共包含 6 个公开字段或方法。
ProviderHealth接口interface ProviderHealthProvider Health 接口,共包含 5 个公开字段或方法。

ExecutionPrincipal

Execution Principal 接口,共包含 8 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ExecutionPrincipal } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/execution

声明

text
export interface ExecutionPrincipal {
    principalId: string;
    type: 'user' | 'agent' | 'service' | 'system';
    tenantId?: string;
    userId?: string;
    agentId?: string;
    roles?: string[];
    permissionScopes: string[];
    metadata?: Record<string, unknown>;
}

契约成员

成员种类签名说明
agentId属性agentId?: string公开属性;类型、只读和可选状态以签名列为准。
metadata属性metadata?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
permissionScopes属性permissionScopes: string[]公开属性;类型、只读和可选状态以签名列为准。
principalId属性principalId: string公开属性;类型、只读和可选状态以签名列为准。
roles属性roles?: string[]公开属性;类型、只读和可选状态以签名列为准。
tenantId属性tenantId?: string公开属性;类型、只读和可选状态以签名列为准。
type属性type: "system" | "agent" | "user" | "service"公开属性;类型、只读和可选状态以签名列为准。
userId属性userId?: string公开属性;类型、只读和可选状态以签名列为准。

NormalizedExecutionError

Normalized Execution Error 接口,共包含 6 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { NormalizedExecutionError } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/execution

声明

text
export interface NormalizedExecutionError {
    code: 'EXECUTION_INVALID_REQUEST' | 'EXECUTION_PERMISSION_DENIED' | 'EXECUTION_POLICY_DENIED' | 'EXECUTION_APPROVAL_REQUIRED' | 'EXECUTION_WORKSPACE_NOT_FOUND' | 'EXECUTION_PATH_ESCAPE' | 'EXECUTION_PATH_DENIED' | 'EXECUTION_QUOTA_EXCEEDED' | 'EXECUTION_ENVIRONMENT_UNAVAILABLE' | 'EXECUTION_SANDBOX_CREATE_FAILED' | 'EXECUTION_SANDBOX_START_FAILED' | 'EXECUTION_IMAGE_UNTRUSTED' | 'EXECUTION_NETWORK_DENIED' | 'EXECUTION_SECRET_DENIED' | 'EXECUTION_PROCESS_START_FAILED' | 'EXECUTION_TIMEOUT' | 'EXECUTION_IDLE_TIMEOUT' | 'EXECUTION_CANCELLED' | 'EXECUTION_OOM_KILLED' | 'EXECUTION_RESOURCE_EXCEEDED' | 'EXECUTION_OUTPUT_LIMIT' | 'EXECUTION_RESULT_UNKNOWN' | 'EXECUTION_REVISION_CONFLICT' | 'EXECUTION_LEASE_HELD' | 'EXECUTION_LEASE_LOST' | 'EXECUTION_IDEMPOTENCY_CONFLICT' | 'EXECUTION_CLEANUP_FAILED' | 'EXECUTION_INTERNAL_ERROR';
    message: string;
    retryable: boolean;
    providerCode?: string | number;
    details?: Record<string, unknown>;
    causeRef?: string;
}

契约成员

成员种类签名说明
causeRef属性causeRef?: string公开属性;类型、只读和可选状态以签名列为准。
code属性code: "EXECUTION_INVALID_REQUEST" | "EXECUTION_PERMISSION_DENIED" | "EXECUTION_POLICY_DENIED" | "EXECUTION_APPROVAL_REQUIRED" | "EXECUTION_WORKSPACE_NOT_FOUND" | "EXECUTION_PATH_ESCAPE" | "EXECUTION_PATH_DENIED" | "EXECUTION_QUOTA_EXCEEDED" | "EXECUTION_ENVIRONMENT_UNAVAILABLE" | "EXECUTION_SANDBOX_CREATE_FAILED" | "EXECUTION_SANDBOX_START_FAILED" | "EXECUTION_IMAGE_UNTRUSTED" | "EXECUTION_NETWORK_DENIED" | "EXECU...公开属性;类型、只读和可选状态以签名列为准。
details属性details?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
message属性message: string公开属性;类型、只读和可选状态以签名列为准。
providerCode属性providerCode?: string | number公开属性;类型、只读和可选状态以签名列为准。
retryable属性retryable: boolean公开属性;类型、只读和可选状态以签名列为准。

ProviderHealth

Provider Health 接口,共包含 5 个公开字段或方法。

  • 种类: 接口
  • 导入: import type { ProviderHealth } from '@codesoul-co/hypha-core';
  • 源码模块: contracts/execution

声明

text
export interface ProviderHealth {
    status: 'healthy' | 'degraded' | 'unhealthy' | 'unknown';
    checkedAt: string;
    latencyMs?: number;
    message?: string;
    details?: Record<string, unknown>;
}

契约成员

成员种类签名说明
checkedAt属性checkedAt: string公开属性;类型、只读和可选状态以签名列为准。
details属性details?: Record<string, unknown>公开属性;类型、只读和可选状态以签名列为准。
latencyMs属性latencyMs?: number公开属性;类型、只读和可选状态以签名列为准。
message属性message?: string公开属性;类型、只读和可选状态以签名列为准。
status属性status: "healthy" | "degraded" | "unhealthy" | "unknown"公开属性;类型、只读和可选状态以签名列为准。