/** * task 的 sys schema 表(编码规范 §7 / ADR-002)。 */ import { index, integer, jsonb, text, timestamp } from 'drizzle-orm/pg-core'; import { sys } from '@shared/db.ts'; export const taskTable = sys.table( 'task', { id: text('id').primaryKey(), activityId: text('activity_id').notNull(), paradigm: text('paradigm').notNull(), workflowId: text('workflow_id'), nodeId: text('node_id'), /** 恰有一名负责人 */ ownerId: text('owner_id').notNull(), title: text('title').notNull(), runtime: text('runtime').notNull().default('running'), /** 终态五名 —— 封闭枚举 */ terminal: text('terminal'), reason: text('reason'), /** 装载信封:包版本 + 各资产生效版 —— 行为可归因 */ envelope: jsonb('envelope').notNull(), /** 起单入参 —— 步序声明按字段名读它;不存下来,断点续跑后作用域就空了 */ inputData: jsonb('input_data').notNull().default({}), caps: jsonb('caps').notNull(), usedSteps: integer('used_steps').notNull().default(0), usedTokens: integer('used_tokens').notNull().default(0), usedActiveMs: integer('used_active_ms').notNull().default(0), usedHumanCalls: integer('used_human_calls').notNull().default(0), lastProgressAt: timestamp('last_progress_at', { withTimezone: true }), startedAt: timestamp('started_at', { withTimezone: true }).notNull().defaultNow(), finishedAt: timestamp('finished_at', { withTimezone: true }), }, (t) => [ index('task_owner_idx').on(t.ownerId, t.runtime), index('task_workflow_idx').on(t.workflowId), index('task_terminal_idx').on(t.terminal), ], );