| import { |
| pgTable, |
| text, |
| timestamp, |
| jsonb, |
| integer, |
| index, |
| uniqueIndex, |
| } from "drizzle-orm/pg-core"; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
|
|
| export const capabilities = pgTable( |
| "capabilities", |
| { |
| id: text("id").primaryKey(), |
| |
| name: text("name").notNull().unique(), |
| |
| domain: text("domain").notNull(), |
| description: text("description").notNull().default(""), |
| |
| currentLifecycleState: text("current_lifecycle_state") |
| .notNull() |
| .default("created"), |
| |
| boundNetworkName: text("bound_network_name"), |
| |
| meta: jsonb("meta").notNull().default({}), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| updatedAt: timestamp("updated_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byDomain: index("capabilities_domain_idx").on(t.domain), |
| byState: index("capabilities_state_idx").on(t.currentLifecycleState), |
| }), |
| ); |
|
|
| export type CapabilityRow = typeof capabilities.$inferSelect; |
| export type InsertCapabilityRow = typeof capabilities.$inferInsert; |
|
|
| |
|
|
| export const capabilityLifecycleEvents = pgTable( |
| "capability_lifecycle_events", |
| { |
| id: text("id").primaryKey(), |
| capabilityId: text("capability_id").notNull(), |
| fromState: text("from_state"), |
| toState: text("to_state").notNull(), |
| |
| reason: text("reason").notNull(), |
| payload: jsonb("payload").notNull().default({}), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byCapability: index("capability_lifecycle_events_cap_idx").on( |
| t.capabilityId, |
| ), |
| byCreatedAt: index("capability_lifecycle_events_created_at_idx").on( |
| t.createdAt, |
| ), |
| }), |
| ); |
|
|
| export type CapabilityLifecycleEventRow = |
| typeof capabilityLifecycleEvents.$inferSelect; |
| export type InsertCapabilityLifecycleEventRow = |
| typeof capabilityLifecycleEvents.$inferInsert; |
|
|
| |
|
|
| export const capabilityInnerLoopRuns = pgTable( |
| "capability_inner_loop_runs", |
| { |
| id: text("id").primaryKey(), |
| capabilityId: text("capability_id").notNull(), |
| |
| |
| |
| |
| |
| stepsJson: jsonb("steps_json").notNull(), |
| sourceRunId: text("source_run_id"), |
| durationMs: integer("duration_ms"), |
| |
| status: text("status").notNull().default("ok"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byCapability: index("capability_inner_loop_runs_cap_idx").on( |
| t.capabilityId, |
| ), |
| byCreatedAt: index("capability_inner_loop_runs_created_at_idx").on( |
| t.createdAt, |
| ), |
| }), |
| ); |
|
|
| export type CapabilityInnerLoopRunRow = |
| typeof capabilityInnerLoopRuns.$inferSelect; |
| export type InsertCapabilityInnerLoopRunRow = |
| typeof capabilityInnerLoopRuns.$inferInsert; |
|
|
| |
| |
| |
| |
|
|
| export const capabilityDataFoundation = pgTable( |
| "capability_data_foundation", |
| { |
| id: text("id").primaryKey(), |
| capabilityId: text("capability_id").notNull(), |
| kind: text("kind").notNull(), |
| payload: jsonb("payload").notNull(), |
| sourceRunId: text("source_run_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byCapability: index("capability_data_foundation_capability_idx").on( |
| t.capabilityId, |
| ), |
| byKind: index("capability_data_foundation_kind_idx").on(t.kind), |
| byCapabilityKind: index("capability_data_foundation_cap_kind_idx").on( |
| t.capabilityId, |
| t.kind, |
| ), |
| }), |
| ); |
|
|
| export type CapabilityDataFoundationRow = |
| typeof capabilityDataFoundation.$inferSelect; |
| export type InsertCapabilityDataFoundationRow = |
| typeof capabilityDataFoundation.$inferInsert; |
|
|
| |
| |
| |
|
|
| export const capabilityExternalKnowledgeCalls = pgTable( |
| "capability_external_knowledge_calls", |
| { |
| id: text("id").primaryKey(), |
| adapter: text("adapter").notNull(), |
| capabilityId: text("capability_id"), |
| latencyMs: integer("latency_ms").notNull(), |
| hitCount: integer("hit_count").notNull().default(0), |
| cacheHit: text("cache_hit"), |
| error: text("error"), |
| paramsFingerprint: text("params_fingerprint"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byAdapter: index("capability_ek_calls_adapter_idx").on(t.adapter), |
| byCapability: index("capability_ek_calls_capability_idx").on( |
| t.capabilityId, |
| ), |
| byCreatedAt: index("capability_ek_calls_created_at_idx").on(t.createdAt), |
| }), |
| ); |
|
|
| export type CapabilityExternalKnowledgeCallRow = |
| typeof capabilityExternalKnowledgeCalls.$inferSelect; |
| export type InsertCapabilityExternalKnowledgeCallRow = |
| typeof capabilityExternalKnowledgeCalls.$inferInsert; |
|
|
| |
|
|
| export const networkDispatchViolations = pgTable( |
| "network_dispatch_violations", |
| { |
| id: text("id").primaryKey(), |
| networkName: text("network_name").notNull(), |
| toolName: text("tool_name").notNull(), |
| |
| argsHash: text("args_hash").notNull(), |
| |
| detailsJson: jsonb("details_json").notNull(), |
| |
| mode: text("mode").notNull().default("enforced"), |
| |
| conversationId: text("conversation_id"), |
| ownerUserId: text("owner_user_id"), |
| createdAt: timestamp("created_at", { withTimezone: true }) |
| .notNull() |
| .defaultNow(), |
| }, |
| (t) => ({ |
| byNetwork: index("network_dispatch_violations_net_idx").on(t.networkName), |
| byCreatedAt: index("network_dispatch_violations_created_at_idx").on( |
| t.createdAt, |
| ), |
| uniqArgsHashRecent: uniqueIndex( |
| "network_dispatch_violations_uniq_recent", |
| ).on(t.networkName, t.argsHash, t.createdAt), |
| }), |
| ); |
|
|
| export type NetworkDispatchViolationRow = |
| typeof networkDispatchViolations.$inferSelect; |
| export type InsertNetworkDispatchViolationRow = |
| typeof networkDispatchViolations.$inferInsert; |
|
|