/** * module: toolbox —— 本模块要外界提供的能力(编码规范 §10.1 / §5.3)。 */ import type { ToolContract } from './internal/domain/tool-contract.ts'; import type { ToolCall, ToolResult } from './contract.ts'; export type Clock = { now(): Date; }; export type IdGenerator = { next(): string; }; /** 凭证密封 —— 与 llm 同一实现,由 app 注入(ADR-009) */ export type SecretBox = { seal(plaintext: string): string; open(cipher: string): string; }; export type ToolRegistry = { list(): Promise; get(name: string): Promise; isEnabled(name: string): Promise; upsert(contract: ToolContract, connectionCipher: Record | null): Promise; setEnabled(name: string, enabled: boolean): Promise; connectionCipher(name: string): Promise | undefined>; setAllowlist(activityId: string, tools: readonly string[]): Promise; allowlistOf(activityId: string): Promise; /** 有活动声明引用即不得删除 */ referencedBy(name: string): Promise; }; /** 工具录制回放存储 —— 与 llm 的 ReplayStore 同构,另存一表(§7.3) */ export type ToolReplayStore = { put(record: { key: string; call: ToolCall; result: ToolResult; recordedAt: Date; }): Promise; get(key: string): Promise<{ call: ToolCall; result: ToolResult; } | undefined>; }; /** * 工具执行 —— 实现对系统:server 侧执行代码,运行时受限, * **只可访问注册申报的连接目标,无其他环境能力**(OS 7.3)。 */ export type ToolRuntime = { execute(input: { readonly contract: ToolContract; readonly connection: Readonly>; readonly call: ToolCall; readonly idempotencyKey?: string; }): Promise<{ ok: boolean; output?: Record; error?: { code: string; retryable: boolean; message: string; }; }>; }; /** JSON Schema 校验 —— ajv 在 adapter,usecase 只见本端口(ADR-003) */ export type SchemaValidator = { validate(schema: Record, value: unknown): { ok: boolean; errors: string[]; }; };