Skip to content

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

模块用法

用于声明并运行时校验契约。Contracts 模块公开 10 常量、2 函数。

从包入口导入

ts
import {
  executionGovernanceJsonSchemas,
  executionRiskAssessmentExample,
  executionRiskAssessmentJsonSchema,
  executionRiskAssessmentSchema,
  executionSandboxLevelSchema,
  executionToolBindingExample,
  executionToolBindingJsonSchema,
  executionToolBindingSchema,
} from '@codesoul-co/hypha-core';

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

使用要点

  • 2 个函数是该模块的直接操作入口;每个 overload 的必需/可选参数与返回类型均在下方列出。
  • 10 个常量/枚举提供稳定值、Schema、Definition 或默认配置;应复用这些导出,避免在应用中复制内部值。

运行时校验示例

ts
import { executionRiskAssessmentSchema } from '@codesoul-co/hypha-core';

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

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

公共导出

Symbol种类签名说明
executionGovernanceJsonSchemas常量const executionGovernanceJsonSchemas: Record<string, JsonSchema>modules/execution-governance/contracts 模块导出的 Execution Governance JSON Schemas 常量。
executionRiskAssessmentExample常量const executionRiskAssessmentExample: ExecutionRiskAssessmentExecution Risk Assessment 的有效示例值。
executionRiskAssessmentJsonSchema常量const executionRiskAssessmentJsonSchema: JsonSchemaExecution Risk Assessment 的 JSON Schema。
executionRiskAssessmentSchema常量const executionRiskAssessmentSchema: z.ZodEffects<z.ZodObject<{ id: z.ZodString; level: z.ZodEnum<["low", "medium", "high", "critical"]>; reasons: z.ZodArray<z.ZodString, "many">; matchedRules: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; requiresApproval: z.ZodBoolean; recommendedSandboxLevel: z.ZodOptional<z.ZodEnum<["local", "container", "remote_isolated"]>>; evaluatedAt: z.ZodString; }, "strict", z.ZodTypeA...Execution Risk Assessment 的运行时 Schema。
executionSandboxLevelSchema常量const executionSandboxLevelSchema: z.ZodEnum<["local", "container", "remote_isolated"]>Execution Sandbox Level 的运行时 Schema。
executionToolBindingExample常量const executionToolBindingExample: ExecutionToolBindingExecution Tool Binding 的有效示例值。
executionToolBindingJsonSchema常量const executionToolBindingJsonSchema: JsonSchemaExecution Tool Binding 的 JSON Schema。
executionToolBindingSchema常量const executionToolBindingSchema: z.ZodEffects<z.ZodObject<{ toolId: z.ZodString; operation: z.ZodEnum<["file_read", "file_write", "command", "sandbox", "artifact"]>; executionProfileRef: z.ZodString; requiredScopes: z.ZodArray<z.ZodString, "many">; sideEffectLevel: z.ZodEnum<["read", "write", "external_effect", "irreversible"]>; humanReviewPolicyRef: z.ZodOptional<z.ZodString>; }, "strict", z.ZodTypeAny, { operat...Execution Tool Binding 的运行时 Schema。
executionToolOperationSchema常量const executionToolOperationSchema: z.ZodEnum<["file_read", "file_write", "command", "sandbox", "artifact"]>Execution Tool Operation 的运行时 Schema。
executionToolSideEffectLevelSchema常量const executionToolSideEffectLevelSchema: z.ZodEnum<["read", "write", "external_effect", "irreversible"]>Execution Tool Side Effect Level 的运行时 Schema。
validateExecutionRiskAssessment函数validateExecutionRiskAssessment(input: unknown): ExecutionRiskAssessmentValidate Execution Risk Assessment 函数,提供 1 个公开调用签名;参数与返回类型见下表。
validateExecutionToolBinding函数validateExecutionToolBinding(input: unknown): ExecutionToolBindingValidate Execution Tool Binding 函数,提供 1 个公开调用签名;参数与返回类型见下表。

executionGovernanceJsonSchemas

modules/execution-governance/contracts 模块导出的 Execution Governance JSON Schemas 常量。

声明

text
export declare const executionGovernanceJsonSchemas: Record<string, JsonSchema>;

executionRiskAssessmentExample

Execution Risk Assessment 的有效示例值。

声明

text
export declare const executionRiskAssessmentExample: ExecutionRiskAssessment;

executionRiskAssessmentJsonSchema

Execution Risk Assessment 的 JSON Schema。

声明

text
export declare const executionRiskAssessmentJsonSchema: JsonSchema;

executionRiskAssessmentSchema

Execution Risk Assessment 的运行时 Schema。

声明

text
export declare const executionRiskAssessmentSchema: z.ZodEffects<z.ZodObject<{ id: z.ZodString; level: z.ZodEnum<["low", "medium", "high", "critical"]>; reasons: z.ZodArray<z.ZodString, "many">; matchedRules: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; requiresApproval: z.ZodBoolean; recommendedSandboxLevel: z.ZodOptional<z.ZodEnum<["local", "container", "remote_isolated"]>>; evaluatedAt: z.ZodString; }, "strict", z.ZodTypeAny, { id: string; evaluatedAt: string; level: "low" | "medium" | "high" | "critical"; reasons: string[]; requiresApproval: boolean; matchedRules?: string[] | undefined; recommendedSandboxLevel?: "local" | "container" | "remote_isolated" | undefined; }, { id: string; evaluatedAt: string; level: "low" | "medium" | "high" | "critical"; reasons: string[]; requiresApproval: boolean; matchedRules?: string[] | undefined; recommendedSandboxLevel?: "local" | "container" | "remote_isolated" | undefined; }>, { id: string; evaluatedAt: string; level: "low" | "medium" | "high" | "critical"; reasons: string[]; requiresApproval: boolean; matchedRules?: string[] | undefined; recommendedSandboxLevel?: "local" | "container" | "remote_isolated" | undefined; }, { id: string; evaluatedAt: string; level: "low" | "medium" | "high" | "critical"; reasons: string[]; requiresApproval: boolean; matchedRules?: string[] | undefined; recommendedSandboxLevel?: "local" | "container" | "remote_isolated" | undefined; }>;

executionSandboxLevelSchema

Execution Sandbox Level 的运行时 Schema。

声明

text
export declare const executionSandboxLevelSchema: z.ZodEnum<["local", "container", "remote_isolated"]>;

executionToolBindingExample

Execution Tool Binding 的有效示例值。

声明

text
export declare const executionToolBindingExample: ExecutionToolBinding;

executionToolBindingJsonSchema

Execution Tool Binding 的 JSON Schema。

声明

text
export declare const executionToolBindingJsonSchema: JsonSchema;

executionToolBindingSchema

Execution Tool Binding 的运行时 Schema。

声明

text
export declare const executionToolBindingSchema: z.ZodEffects<z.ZodObject<{ toolId: z.ZodString; operation: z.ZodEnum<["file_read", "file_write", "command", "sandbox", "artifact"]>; executionProfileRef: z.ZodString; requiredScopes: z.ZodArray<z.ZodString, "many">; sideEffectLevel: z.ZodEnum<["read", "write", "external_effect", "irreversible"]>; humanReviewPolicyRef: z.ZodOptional<z.ZodString>; }, "strict", z.ZodTypeAny, { operation: "command" | "artifact" | "file_read" | "file_write" | "sandbox"; toolId: string; sideEffectLevel: "external_effect" | "irreversible" | "read" | "write"; executionProfileRef: string; requiredScopes: string[]; humanReviewPolicyRef?: string | undefined; }, { operation: "command" | "artifact" | "file_read" | "file_write" | "sandbox"; toolId: string; sideEffectLevel: "external_effect" | "irreversible" | "read" | "write"; executionProfileRef: string; requiredScopes: string[]; humanReviewPolicyRef?: string | undefined; }>, { operation: "command" | "artifact" | "file_read" | "file_write" | "sandbox"; toolId: string; sideEffectLevel: "external_effect" | "irreversible" | "read" | "write"; executionProfileRef: string; requiredScopes: string[]; humanReviewPolicyRef?: string | undefined; }, { operation: "command" | "artifact" | "file_read" | "file_write" | "sandbox"; toolId: string; sideEffectLevel: "external_effect" | "irreversible" | "read" | "write"; executionProfileRef: string; requiredScopes: string[]; humanReviewPolicyRef?: string | undefined; }>;

executionToolOperationSchema

Execution Tool Operation 的运行时 Schema。

声明

text
export declare const executionToolOperationSchema: z.ZodEnum<["file_read", "file_write", "command", "sandbox", "artifact"]>;

executionToolSideEffectLevelSchema

Execution Tool Side Effect Level 的运行时 Schema。

声明

text
export declare const executionToolSideEffectLevelSchema: z.ZodEnum<["read", "write", "external_effect", "irreversible"]>;

validateExecutionRiskAssessment

Validate Execution Risk Assessment 函数,提供 1 个公开调用签名;参数与返回类型见下表。

声明

text
export declare function validateExecutionRiskAssessment(input: unknown): ExecutionRiskAssessment;

调用签名

text
validateExecutionRiskAssessment(input: unknown): ExecutionRiskAssessment

参数

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

返回值

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

validateExecutionToolBinding

Validate Execution Tool Binding 函数,提供 1 个公开调用签名;参数与返回类型见下表。

声明

text
export declare function validateExecutionToolBinding(input: unknown): ExecutionToolBinding;

调用签名

text
validateExecutionToolBinding(input: unknown): ExecutionToolBinding

参数

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

返回值

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