| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| import { |
| pgTable, |
| text, |
| timestamp, |
| jsonb, |
| integer, |
| doublePrecision, |
| boolean, |
| index, |
| uniqueIndex, |
| } from "drizzle-orm/pg-core"; |
|
|
| |
|
|
| export const problemClasses = pgTable( |
| "problem_classes", |
| { |
| id: text("id").primaryKey(), |
| |
| path: text("path").notNull().unique(), |
| parentPath: text("parent_path"), |
| label: text("label").notNull(), |
| description: text("description").notNull().default(""), |
| |
| |
| |
| |
| |
| capabilityTags: jsonb("capability_tags").notNull().default([]), |
| |
| reviewerWeights: jsonb("reviewer_weights"), |
| |
| |
| |
| |
| |
| |
| |
| status: text("status").notNull().default("active"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byParent: index("problem_classes_parent_idx").on(t.parentPath), |
| byStatus: index("problem_classes_status_idx").on(t.status), |
| }), |
| ); |
|
|
| export type ProblemClassRow = typeof problemClasses.$inferSelect; |
| export type InsertProblemClassRow = typeof problemClasses.$inferInsert; |
|
|
| |
|
|
| export const toolNetworks = pgTable( |
| "tool_networks", |
| { |
| id: text("id").primaryKey(), |
| |
| name: text("name").notNull().unique(), |
| |
| problemClassPath: text("problem_class_path").notNull(), |
| description: text("description").notNull().default(""), |
| |
| |
| |
| |
| |
| inputContract: jsonb("input_contract").notNull(), |
| |
| outputContract: jsonb("output_contract").notNull(), |
| |
| |
| |
| |
| |
| internalGraph: jsonb("internal_graph").notNull(), |
| |
| |
| |
| |
| activeVariantId: text("active_variant_id"), |
| |
| |
| |
| |
| |
| builderModelTier: text("builder_model_tier").notNull().default("strong"), |
| |
| |
| |
| |
| |
| |
| releaseTierFloor: text("release_tier_floor").notNull().default("strong"), |
| |
| |
| |
| |
| config: jsonb("config").notNull().default({}), |
| |
| status: text("status").notNull().default("active"), |
| costHint: doublePrecision("cost_hint"), |
| latencyHintMs: integer("latency_hint_ms"), |
| |
| |
| |
| |
| |
| capabilityTags: jsonb("capability_tags").notNull().default([]), |
| |
| |
| |
| |
| |
| legacyAliasNodeId: text("legacy_alias_node_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byClass: index("tool_networks_class_idx").on(t.problemClassPath), |
| byStatus: index("tool_networks_status_idx").on(t.status), |
| }), |
| ); |
|
|
| export type ToolNetworkRow = typeof toolNetworks.$inferSelect; |
| export type InsertToolNetworkRow = typeof toolNetworks.$inferInsert; |
|
|
| |
|
|
| export const networkVersions = pgTable( |
| "network_versions", |
| { |
| id: text("id").primaryKey(), |
| networkId: text("network_id").notNull(), |
| versionLabel: text("version_label").notNull(), |
| internalGraph: jsonb("internal_graph").notNull(), |
| |
| config: jsonb("config").notNull().default({}), |
| |
| status: text("status").notNull().default("draft"), |
| |
| builtBy: text("built_by").notNull().default("system"), |
| builderModelTier: text("builder_model_tier").notNull().default("strong"), |
| |
| |
| |
| |
| |
| |
| |
| privateNamespace: text("private_namespace"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_versions_net_idx").on(t.networkId), |
| byStatus: index("network_versions_status_idx").on(t.status), |
| uniqLabel: uniqueIndex("network_versions_uniq_label").on( |
| t.networkId, |
| t.versionLabel, |
| ), |
| byPrivateNs: index("network_versions_private_ns_idx").on(t.privateNamespace), |
| |
| |
| |
| |
| |
| |
| |
| |
| }), |
| ); |
|
|
| export type NetworkVersionRow = typeof networkVersions.$inferSelect; |
| export type InsertNetworkVersionRow = typeof networkVersions.$inferInsert; |
|
|
| |
|
|
| export const networkPromotions = pgTable( |
| "network_promotions", |
| { |
| id: text("id").primaryKey(), |
| networkId: text("network_id").notNull(), |
| fromVariantId: text("from_variant_id"), |
| toVariantId: text("to_variant_id").notNull(), |
| |
| reason: text("reason").notNull(), |
| metricsSnapshot: jsonb("metrics_snapshot").notNull().default({}), |
| decidedBy: text("decided_by").notNull().default("system"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_promotions_net_idx").on(t.networkId), |
| }), |
| ); |
|
|
| export type NetworkPromotionRow = typeof networkPromotions.$inferSelect; |
| export type InsertNetworkPromotionRow = typeof networkPromotions.$inferInsert; |
|
|
| |
|
|
| export const networkVersionMetrics = pgTable( |
| "network_version_metrics", |
| { |
| id: text("id").primaryKey(), |
| networkId: text("network_id").notNull(), |
| versionId: text("version_id").notNull(), |
| problemClassPath: text("problem_class_path").notNull(), |
| |
| reviewerScore: doublePrecision("reviewer_score").notNull(), |
| |
| channelBreakdown: jsonb("channel_breakdown").notNull().default({}), |
| |
| |
| |
| |
| |
| |
| |
| channelFallbackFlags: jsonb("channel_fallback_flags").notNull().default({}), |
| |
| costMs: integer("cost_ms"), |
| |
| retries: integer("retries").notNull().default(0), |
| |
| budgetExceeded: boolean("budget_exceeded").notNull().default(false), |
| |
| conversationId: text("conversation_id"), |
| messageId: text("message_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_version_metrics_net_idx").on(t.networkId), |
| byVersion: index("network_version_metrics_ver_idx").on(t.versionId), |
| byClass: index("network_version_metrics_class_idx").on(t.problemClassPath), |
| }), |
| ); |
|
|
| export type NetworkVersionMetricRow = |
| typeof networkVersionMetrics.$inferSelect; |
| export type InsertNetworkVersionMetricRow = |
| typeof networkVersionMetrics.$inferInsert; |
|
|
| |
|
|
| export const executionPlans = pgTable( |
| "execution_plans", |
| { |
| id: text("id").primaryKey(), |
| |
| conversationId: text("conversation_id"), |
| |
| ownerUserId: text("owner_user_id"), |
| problemClassPath: text("problem_class_path").notNull(), |
| networkId: text("network_id").notNull(), |
| versionId: text("version_id").notNull(), |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| blueprint: jsonb("blueprint").notNull(), |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| status: text("status").notNull().default("draft"), |
| approvedBy: text("approved_by"), |
| approvedAt: timestamp("approved_at", { withTimezone: true }), |
| |
| outputArtifactPath: text("output_artifact_path"), |
| |
| |
| |
| |
| notes: text("notes").notNull().default(""), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byStatus: index("execution_plans_status_idx").on(t.status), |
| byOwner: index("execution_plans_owner_idx").on(t.ownerUserId), |
| }), |
| ); |
|
|
| export type ExecutionPlanRow = typeof executionPlans.$inferSelect; |
| export type InsertExecutionPlanRow = typeof executionPlans.$inferInsert; |
|
|
| |
|
|
| export const taskLedger = pgTable( |
| "task_ledger", |
| { |
| id: text("id").primaryKey(), |
| planId: text("plan_id").notNull(), |
| |
| taskKey: text("task_key").notNull(), |
| params: jsonb("params").notNull().default({}), |
| |
| status: text("status").notNull().default("pending"), |
| attempts: integer("attempts").notNull().default(0), |
| maxAttempts: integer("max_attempts").notNull().default(3), |
| result: jsonb("result"), |
| errorText: text("error_text"), |
| |
| metrics: jsonb("metrics"), |
| |
| durationMs: integer("duration_ms"), |
| startedAt: timestamp("started_at", { withTimezone: true }), |
| finishedAt: timestamp("finished_at", { withTimezone: true }), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byPlan: index("task_ledger_plan_idx").on(t.planId), |
| byStatus: index("task_ledger_status_idx").on(t.status), |
| uniq: uniqueIndex("task_ledger_uniq").on(t.planId, t.taskKey), |
| }), |
| ); |
|
|
| export type TaskLedgerRow = typeof taskLedger.$inferSelect; |
| export type InsertTaskLedgerRow = typeof taskLedger.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| export const networkShadowSamples = pgTable( |
| "network_shadow_samples", |
| { |
| id: text("id").primaryKey(), |
| networkId: text("network_id").notNull(), |
| activeVariantId: text("active_variant_id").notNull(), |
| shadowVariantId: text("shadow_variant_id").notNull(), |
| problemClassPath: text("problem_class_path").notNull(), |
| |
| activeScore: doublePrecision("active_score").notNull(), |
| |
| shadowScore: doublePrecision("shadow_score").notNull(), |
| |
| criticalSignal: boolean("critical_signal").notNull().default(false), |
| activeCostMs: integer("active_cost_ms"), |
| shadowCostMs: integer("shadow_cost_ms"), |
| |
| budgetSkipped: boolean("budget_skipped").notNull().default(false), |
| conversationId: text("conversation_id"), |
| messageId: text("message_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_shadow_samples_net_idx").on(t.networkId), |
| byShadow: index("network_shadow_samples_shadow_idx").on(t.shadowVariantId), |
| byCreated: index("network_shadow_samples_created_idx").on(t.createdAt), |
| }), |
| ); |
|
|
| export type NetworkShadowSampleRow = typeof networkShadowSamples.$inferSelect; |
| export type InsertNetworkShadowSampleRow = |
| typeof networkShadowSamples.$inferInsert; |
|
|
| |
|
|
| export const networkEvolutionEvents = pgTable( |
| "network_evolution_events", |
| { |
| id: text("id").primaryKey(), |
| networkId: text("network_id").notNull(), |
| |
| |
| |
| |
| |
| |
| |
| kind: text("kind").notNull(), |
| |
| variantId: text("variant_id"), |
| |
| payload: jsonb("payload").notNull().default({}), |
| |
| relatedEventId: text("related_event_id"), |
| |
| promotionId: text("promotion_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_evolution_events_net_idx").on(t.networkId), |
| byKind: index("network_evolution_events_kind_idx").on(t.kind), |
| byCreated: index("network_evolution_events_created_idx").on(t.createdAt), |
| }), |
| ); |
|
|
| export type NetworkEvolutionEventRow = |
| typeof networkEvolutionEvents.$inferSelect; |
| export type InsertNetworkEvolutionEventRow = |
| typeof networkEvolutionEvents.$inferInsert; |
|
|
| |
|
|
| export const networkRegressionSamples = pgTable( |
| "network_regression_samples", |
| { |
| id: text("id").primaryKey(), |
| networkId: text("network_id").notNull(), |
| problemClassPath: text("problem_class_path").notNull(), |
| label: text("label").notNull().default(""), |
| |
| inputPayload: jsonb("input_payload").notNull(), |
| |
| |
| |
| |
| expectedFloor: doublePrecision("expected_floor").notNull().default(0.6), |
| |
| expectedShape: jsonb("expected_shape").notNull().default({}), |
| |
| status: text("status").notNull().default("active"), |
| createdBy: text("created_by").notNull().default("system"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_regression_samples_net_idx").on(t.networkId), |
| byStatus: index("network_regression_samples_status_idx").on(t.status), |
| }), |
| ); |
|
|
| export type NetworkRegressionSampleRow = |
| typeof networkRegressionSamples.$inferSelect; |
| export type InsertNetworkRegressionSampleRow = |
| typeof networkRegressionSamples.$inferInsert; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| export const submissionFeedbackLedger = pgTable( |
| "submission_feedback_ledger", |
| { |
| id: text("id").primaryKey(), |
| |
| submissionId: text("submission_id").notNull(), |
| networkId: text("network_id").notNull(), |
| networkVersionId: text("network_version_id").notNull(), |
| |
| taskId: text("task_id").notNull(), |
| |
| metricRowId: text("metric_row_id").notNull(), |
| submittedAt: timestamp("submitted_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| |
| externalTruthStatus: text("external_truth_status") |
| .notNull() |
| .default("pending"), |
| |
| externalTruthValue: doublePrecision("external_truth_value"), |
| externalTruthReceivedAt: timestamp("external_truth_received_at", { |
| withTimezone: true, |
| }), |
| }, |
| (t) => ({ |
| bySubmission: index("submission_feedback_ledger_sub_idx").on(t.submissionId), |
| byTask: index("submission_feedback_ledger_task_idx").on(t.taskId), |
| byMetric: index("submission_feedback_ledger_metric_idx").on(t.metricRowId), |
| byStatus: index("submission_feedback_ledger_status_idx").on( |
| t.externalTruthStatus, |
| ), |
| uniqByPair: uniqueIndex("submission_feedback_ledger_uniq").on( |
| t.submissionId, |
| t.taskId, |
| ), |
| }), |
| ); |
|
|
| export type SubmissionFeedbackLedgerRow = |
| typeof submissionFeedbackLedger.$inferSelect; |
| export type InsertSubmissionFeedbackLedgerRow = |
| typeof submissionFeedbackLedger.$inferInsert; |
|
|