/** * toolbox 的 sys schema 表(编码规范 §7 / ADR-002 / ADR-009)。 */ import { boolean, index, integer, jsonb, primaryKey, text, timestamp } from 'drizzle-orm/pg-core'; import { sys } from '@shared/db.ts'; export const toolTable = sys.table( 'tool', { name: text('name').primaryKey(), version: text('version').notNull(), description: text('description').notNull(), input: jsonb('input').notNull(), output: jsonb('output').notNull(), effect: text('effect').notNull(), errors: jsonb('errors').notNull().default([]), idempotent: boolean('idempotent').notNull().default(false), timeoutMs: integer('timeout_ms').notNull().default(30_000), retries: integer('retries').notNull().default(1), connectionKeys: jsonb('connection_keys').notNull().default([]), capabilities: jsonb('capabilities'), pure: boolean('pure').notNull().default(false), ownerActivityId: text('owner_activity_id'), /** 凭证隔离:值加密落库,不入包、不入活动、不入留痕明文(ADR-009) */ connectionCipher: jsonb('connection_cipher'), enabled: boolean('enabled').notNull().default(true), registeredAt: timestamp('registered_at', { withTimezone: true }).notNull().defaultNow(), }, (t) => [index('tool_effect_idx').on(t.effect), index('tool_owner_idx').on(t.ownerActivityId)], ); /** 白名单:授权在白名单与契约,不在活动代码(OS 04) */ export const toolAllowlistTable = sys.table( 'tool_allowlist', { activityId: text('activity_id').notNull(), tool: text('tool').notNull(), }, (t) => [primaryKey({ columns: [t.activityId, t.tool] })], ); /** 工具录制回放 —— 与 llm 的 replay_model 同构(§7.3 两缝) */ export const replayToolTable = sys.table('replay_tool', { key: text('key').primaryKey(), call: jsonb('call').notNull(), result: jsonb('result').notNull(), recordedAt: timestamp('recorded_at', { withTimezone: true }).notNull().defaultNow(), });