| import { |
| pgTable, |
| text, |
| timestamp, |
| jsonb, |
| integer, |
| doublePrecision, |
| index, |
| uniqueIndex, |
| } from "drizzle-orm/pg-core"; |
|
|
| |
| |
| |
| |
| |
| |
| export const toolNodes = pgTable( |
| "tool_nodes", |
| { |
| id: text("id").primaryKey(), |
| name: text("name").notNull().unique(), |
| description: text("description").notNull().default(""), |
| capabilityTags: jsonb("capability_tags").notNull().default([]), |
| inputKind: text("input_kind").notNull().default("json"), |
| outputKind: text("output_kind").notNull().default("json"), |
| |
| status: text("status").notNull().default("verified"), |
| |
| ownerProcess: text("owner_process").notNull(), |
| |
| specJson: jsonb("spec_json").notNull(), |
| |
| createdBy: text("created_by").notNull().default("system"), |
| |
| handlerRef: text("handler_ref"), |
| |
| handlerStub: text("handler_stub"), |
| |
| costHint: doublePrecision("cost_hint"), |
| latencyHintMs: integer("latency_hint_ms"), |
| version: integer("version").notNull().default(1), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byStatus: index("tool_nodes_status_idx").on(t.status), |
| byOwner: index("tool_nodes_owner_idx").on(t.ownerProcess), |
| }), |
| ); |
|
|
| |
| |
| |
| |
| |
| export const toolEdges = pgTable( |
| "tool_edges", |
| { |
| id: text("id").primaryKey(), |
| fromNode: text("from_node") |
| .notNull() |
| .references(() => toolNodes.id, { onDelete: "cascade" }), |
| toNode: text("to_node") |
| .notNull() |
| .references(() => toolNodes.id, { onDelete: "cascade" }), |
| relation: text("relation").notNull(), |
| weight: doublePrecision("weight").notNull().default(1.0), |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| contract: jsonb("contract"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byFrom: index("tool_edges_from_idx").on(t.fromNode), |
| byTo: index("tool_edges_to_idx").on(t.toNode), |
| uniq: uniqueIndex("tool_edges_uniq").on(t.fromNode, t.toNode, t.relation), |
| }), |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| export const toolNodeEvidence = pgTable( |
| "tool_node_evidence", |
| { |
| id: text("id").primaryKey(), |
| nodeId: text("node_id") |
| .notNull() |
| .references(() => toolNodes.id, { onDelete: "cascade" }), |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| kind: text("kind").notNull(), |
| |
| payload: jsonb("payload").notNull(), |
| |
| success: integer("success").notNull().default(0), |
| failure: integer("failure").notNull().default(0), |
| |
| shadowUserId: text("shadow_user_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| seamFoldedAt: timestamp("seam_folded_at", { withTimezone: true }), |
| }, |
| (t) => ({ |
| byNode: index("tool_node_evidence_node_idx").on(t.nodeId), |
| byKind: index("tool_node_evidence_kind_idx").on(t.kind), |
| bySeamUnfolded: index("tool_node_evidence_seam_unfolded_idx").on( |
| t.kind, |
| t.seamFoldedAt, |
| ), |
| }), |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| export const toolGapSignals = pgTable( |
| "tool_gap_signals", |
| { |
| id: text("id").primaryKey(), |
| capabilityTag: text("capability_tag").notNull(), |
| invocationCount: integer("invocation_count").notNull().default(0), |
| |
| status: text("status").notNull().default("open"), |
| |
| lastContext: jsonb("last_context"), |
| |
| extendedNodeId: text("extended_node_id"), |
| firstSeenAt: timestamp("first_seen_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| lastSeenAt: timestamp("last_seen_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byTag: uniqueIndex("tool_gap_signals_tag_idx").on(t.capabilityTag), |
| byStatus: index("tool_gap_signals_status_idx").on(t.status), |
| }), |
| ); |
|
|
| export type ToolNodeRow = typeof toolNodes.$inferSelect; |
| export type InsertToolNodeRow = typeof toolNodes.$inferInsert; |
| export type ToolEdgeRow = typeof toolEdges.$inferSelect; |
| export type InsertToolEdgeRow = typeof toolEdges.$inferInsert; |
| export type ToolNodeEvidenceRow = typeof toolNodeEvidence.$inferSelect; |
| export type InsertToolNodeEvidenceRow = typeof toolNodeEvidence.$inferInsert; |
| export type ToolGapSignalRow = typeof toolGapSignals.$inferSelect; |
| export type InsertToolGapSignalRow = typeof toolGapSignals.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const toolEdgeHealth = pgTable( |
| "tool_edge_health", |
| { |
| id: text("id").primaryKey(), |
| edgeId: text("edge_id") |
| .notNull() |
| .references(() => toolEdges.id, { onDelete: "cascade" }), |
| |
| traversalCount: integer("traversal_count").notNull().default(0), |
| |
| contractIssueCount: integer("contract_issue_count").notNull().default(0), |
| |
| missingFieldCount: integer("missing_field_count").notNull().default(0), |
| |
| emaCoverage: doublePrecision("ema_coverage").notNull().default(1.0), |
| |
| emaHealthScore: doublePrecision("ema_health_score").notNull().default(1.0), |
| |
| topMissingFields: jsonb("top_missing_fields").notNull().default({}), |
| |
| topContractIssues: jsonb("top_contract_issues").notNull().default({}), |
| |
| formulaVersion: integer("formula_version").notNull().default(1), |
| lastSampleAt: timestamp("last_sample_at", { withTimezone: true }), |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| lastFoldedEvidenceId: text("last_folded_evidence_id"), |
| computedAt: timestamp("computed_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byEdge: uniqueIndex("tool_edge_health_edge_idx").on(t.edgeId), |
| byScore: index("tool_edge_health_score_idx").on(t.emaHealthScore), |
| }), |
| ); |
|
|
| export type ToolEdgeHealthRow = typeof toolEdgeHealth.$inferSelect; |
| export type InsertToolEdgeHealthRow = typeof toolEdgeHealth.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const toolDeprecationCandidates = pgTable( |
| "tool_deprecation_candidates", |
| { |
| id: text("id").primaryKey(), |
| nodeId: text("node_id") |
| .notNull() |
| .references(() => toolNodes.id, { onDelete: "cascade" }), |
| |
| classification: text("classification").notNull(), |
| |
| status: text("status").notNull().default("open"), |
| proposalContext: jsonb("proposal_context").notNull().default({}), |
| |
| deferUntil: timestamp("defer_until", { withTimezone: true }), |
| |
| reArmUntil: timestamp("re_arm_until", { withTimezone: true }), |
| decidedBy: text("decided_by"), |
| decidedAt: timestamp("decided_at", { withTimezone: true }), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNode: uniqueIndex("tool_deprecation_candidates_node_idx").on(t.nodeId), |
| byStatus: index("tool_deprecation_candidates_status_idx").on(t.status), |
| }), |
| ); |
|
|
| export type ToolDeprecationCandidateRow = |
| typeof toolDeprecationCandidates.$inferSelect; |
| export type InsertToolDeprecationCandidateRow = |
| typeof toolDeprecationCandidates.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const toolNodesArchive = pgTable( |
| "tool_nodes_archive", |
| { |
| id: text("id").primaryKey(), |
| name: text("name").notNull(), |
| description: text("description").notNull().default(""), |
| capabilityTags: jsonb("capability_tags").notNull().default([]), |
| inputKind: text("input_kind").notNull().default("json"), |
| outputKind: text("output_kind").notNull().default("json"), |
| status: text("status").notNull(), |
| ownerProcess: text("owner_process").notNull(), |
| specJson: jsonb("spec_json").notNull(), |
| createdBy: text("created_by").notNull().default("system"), |
| handlerRef: text("handler_ref"), |
| handlerStub: text("handler_stub"), |
| costHint: doublePrecision("cost_hint"), |
| latencyHintMs: integer("latency_hint_ms"), |
| version: integer("version").notNull().default(1), |
| createdAt: timestamp("created_at", { withTimezone: true }).notNull(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(), |
| archivedAt: timestamp("archived_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byName: index("tool_nodes_archive_name_idx").on(t.name), |
| byArchivedAt: index("tool_nodes_archive_archived_at_idx").on(t.archivedAt), |
| }), |
| ); |
|
|
| export const toolEdgesArchive = pgTable( |
| "tool_edges_archive", |
| { |
| id: text("id").primaryKey(), |
| fromNode: text("from_node").notNull(), |
| toNode: text("to_node").notNull(), |
| relation: text("relation").notNull(), |
| weight: doublePrecision("weight").notNull().default(1.0), |
| contract: jsonb("contract"), |
| createdAt: timestamp("created_at", { withTimezone: true }).notNull(), |
| archivedAt: timestamp("archived_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byFrom: index("tool_edges_archive_from_idx").on(t.fromNode), |
| byTo: index("tool_edges_archive_to_idx").on(t.toNode), |
| }), |
| ); |
|
|
| export const toolNodeEvidenceArchive = pgTable( |
| "tool_node_evidence_archive", |
| { |
| id: text("id").primaryKey(), |
| nodeId: text("node_id").notNull(), |
| kind: text("kind").notNull(), |
| payload: jsonb("payload").notNull(), |
| success: integer("success").notNull().default(0), |
| failure: integer("failure").notNull().default(0), |
| shadowUserId: text("shadow_user_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }).notNull(), |
| seamFoldedAt: timestamp("seam_folded_at", { withTimezone: true }), |
| archivedAt: timestamp("archived_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNode: index("tool_node_evidence_archive_node_idx").on(t.nodeId), |
| }), |
| ); |
|
|
| export type ToolNodeArchiveRow = typeof toolNodesArchive.$inferSelect; |
| export type ToolEdgeArchiveRow = typeof toolEdgesArchive.$inferSelect; |
| export type ToolNodeEvidenceArchiveRow = |
| typeof toolNodeEvidenceArchive.$inferSelect; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const toolSummaryPaths = pgTable( |
| "tool_summary_paths", |
| { |
| id: text("id").primaryKey(), |
| name: text("name").notNull().unique(), |
| aliasNodeId: text("alias_node_id").references(() => toolNodes.id, { |
| onDelete: "set null", |
| }), |
| descriptionDerived: text("description_derived").notNull().default(""), |
| descriptionOverride: text("description_override"), |
| expansionNodeNames: jsonb("expansion_node_names").notNull().default([]), |
| headAtomName: text("head_atom_name"), |
| tailAtomName: text("tail_atom_name"), |
| capabilityTags: jsonb("capability_tags").notNull().default([]), |
| estCostHint: doublePrecision("est_cost_hint"), |
| estLatencyMsHint: integer("est_latency_ms_hint"), |
| status: text("status").notNull().default("active"), |
| version: integer("version").notNull().default(1), |
| traversalCount: integer("traversal_count").notNull().default(0), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byStatus: index("tool_summary_paths_status_idx").on(t.status), |
| }), |
| ); |
|
|
| export type ToolSummaryPathRow = typeof toolSummaryPaths.$inferSelect; |
| export type InsertToolSummaryPathRow = |
| typeof toolSummaryPaths.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| export const toolSpawnTemplates = pgTable( |
| "tool_spawn_templates", |
| { |
| id: text("id").primaryKey(), |
| |
| fingerprintHash: text("fingerprint_hash").notNull(), |
| fingerprintAlgoVersion: integer("fingerprint_algo_version") |
| .notNull() |
| .default(1), |
| |
| |
| |
| |
| |
| failureMode: text("failure_mode").notNull(), |
| |
| |
| |
| |
| |
| missingFieldTypes: jsonb("missing_field_types").notNull().default([]), |
| |
| |
| |
| |
| unusedFieldTypes: jsonb("unused_field_types").notNull().default([]), |
| |
| |
| |
| |
| |
| downstreamInputSchemaFingerprint: text( |
| "downstream_input_schema_fingerprint", |
| ).notNull(), |
| |
| promotedInputSchemaFingerprint: text( |
| "promoted_input_schema_fingerprint", |
| ).notNull(), |
| |
| promotedOutputSchemaFingerprint: text( |
| "promoted_output_schema_fingerprint", |
| ).notNull(), |
| |
| |
| |
| |
| handlerSkeleton: text("handler_skeleton").notNull().default(""), |
| |
| |
| |
| |
| specSkeleton: jsonb("spec_skeleton").notNull().default({}), |
| |
| |
| |
| |
| capabilityTag: text("capability_tag").notNull().default(""), |
| |
| sourceNodeName: text("source_node_name").notNull(), |
| |
| offeredCount: integer("offered_count").notNull().default(0), |
| |
| reuseCount: integer("reuse_count").notNull().default(0), |
| |
| successCount: integer("success_count").notNull().default(0), |
| |
| rejectCount: integer("reject_count").notNull().default(0), |
| |
| status: text("status").notNull().default("active"), |
| demotedAt: timestamp("demoted_at", { withTimezone: true }), |
| demotedReason: text("demoted_reason"), |
| version: integer("version").notNull().default(1), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byFingerprint: index("tool_spawn_templates_fingerprint_idx").on( |
| t.fingerprintHash, |
| ), |
| byStatus: index("tool_spawn_templates_status_idx").on(t.status), |
| byFailureMode: index("tool_spawn_templates_failure_mode_idx").on( |
| t.failureMode, |
| ), |
| uniq: uniqueIndex("tool_spawn_templates_uniq_idx").on( |
| t.fingerprintHash, |
| t.fingerprintAlgoVersion, |
| ), |
| }), |
| ); |
|
|
| export type ToolSpawnTemplateRow = typeof toolSpawnTemplates.$inferSelect; |
| export type InsertToolSpawnTemplateRow = |
| typeof toolSpawnTemplates.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| export const toolGoals = pgTable( |
| "tool_goals", |
| { |
| id: text("id").primaryKey(), |
| name: text("name").notNull(), |
| description: text("description").notNull().default(""), |
| datasetNodeId: text("dataset_node_id").notNull(), |
| evaluatorNodeId: text("evaluator_node_id").notNull(), |
| |
| budget: jsonb("budget").notNull().default({}), |
| |
| constraints: jsonb("constraints").notNull().default({}), |
| |
| status: text("status").notNull().default("active"), |
| createdBy: text("created_by").notNull().default("system"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byStatus: index("tool_goals_status_idx").on(t.status), |
| }), |
| ); |
|
|
| |
| |
| |
| |
| export const toolGoalRuns = pgTable( |
| "tool_goal_runs", |
| { |
| id: text("id").primaryKey(), |
| goalId: text("goal_id") |
| .notNull() |
| .references(() => toolGoals.id, { onDelete: "cascade" }), |
| |
| status: text("status").notNull().default("running"), |
| |
| |
| goalSnapshot: jsonb("goal_snapshot").notNull().default({}), |
| |
| bestMetric: doublePrecision("best_metric"), |
| |
| bestCandidateId: text("best_candidate_id"), |
| iterations: integer("iterations").notNull().default(0), |
| candidatesEvaluated: integer("candidates_evaluated").notNull().default(0), |
| error: text("error"), |
| startedAt: timestamp("started_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| finishedAt: timestamp("finished_at", { withTimezone: true }), |
| }, |
| (t) => ({ |
| byGoal: index("tool_goal_runs_goal_idx").on(t.goalId), |
| byStatus: index("tool_goal_runs_status_idx").on(t.status), |
| }), |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| export const toolGoalCandidates = pgTable( |
| "tool_goal_candidates", |
| { |
| id: text("id").primaryKey(), |
| runId: text("run_id") |
| .notNull() |
| .references(() => toolGoalRuns.id, { onDelete: "cascade" }), |
| |
| generation: integer("generation").notNull().default(0), |
| |
| primitive: text("primitive").notNull(), |
| |
| parentCandidateId: text("parent_candidate_id"), |
| |
| subgraph: jsonb("subgraph").notNull(), |
| |
| contractOk: integer("contract_ok").notNull().default(1), |
| contractIssues: jsonb("contract_issues").notNull().default([]), |
| |
| metric: doublePrecision("metric"), |
| |
| evaluatorPayload: jsonb("evaluator_payload"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byRun: index("tool_goal_candidates_run_idx").on(t.runId), |
| byMetric: index("tool_goal_candidates_metric_idx").on(t.metric), |
| }), |
| ); |
|
|
| |
| |
| |
| |
| |
| |
| |
| export const toolPromotionAudit = pgTable( |
| "tool_promotion_audit", |
| { |
| id: text("id").primaryKey(), |
| nodeId: text("node_id").notNull(), |
| |
| action: text("action").notNull(), |
| fromStatus: text("from_status").notNull(), |
| toStatus: text("to_status").notNull(), |
| actor: text("actor").notNull().default("system"), |
| |
| evidenceSnapshot: jsonb("evidence_snapshot").notNull().default({}), |
| |
| runId: text("run_id"), |
| candidateId: text("candidate_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNode: index("tool_promotion_audit_node_idx").on(t.nodeId), |
| byAction: index("tool_promotion_audit_action_idx").on(t.action), |
| }), |
| ); |
|
|
| export type ToolGoalRow = typeof toolGoals.$inferSelect; |
| export type InsertToolGoalRow = typeof toolGoals.$inferInsert; |
| export type ToolGoalRunRow = typeof toolGoalRuns.$inferSelect; |
| export type InsertToolGoalRunRow = typeof toolGoalRuns.$inferInsert; |
| export type ToolGoalCandidateRow = typeof toolGoalCandidates.$inferSelect; |
| export type InsertToolGoalCandidateRow = typeof toolGoalCandidates.$inferInsert; |
| export type ToolPromotionAuditRow = typeof toolPromotionAudit.$inferSelect; |
| export type InsertToolPromotionAuditRow = typeof toolPromotionAudit.$inferInsert; |
|
|