@intx/db 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +2 -2
  2. package/dist/approval-store.d.ts +52 -0
  3. package/dist/approval-store.js +79 -0
  4. package/dist/asset-resolution.d.ts +2 -2
  5. package/dist/client.d.ts +10 -0
  6. package/dist/connection.js +11 -8
  7. package/dist/credential-resolution.d.ts +130 -18
  8. package/dist/credential-resolution.js +142 -3
  9. package/dist/grant-store.js +35 -13
  10. package/dist/index.d.ts +13 -4
  11. package/dist/index.js +11 -3
  12. package/dist/model-source-resolution.d.ts +52 -6
  13. package/dist/model-source-resolution.js +145 -19
  14. package/dist/parse-row.d.ts +212 -32
  15. package/dist/parse-row.js +109 -18
  16. package/dist/rekey-credential-secrets.d.ts +13 -0
  17. package/dist/rekey-credential-secrets.js +61 -0
  18. package/dist/schema/approvals.d.ts +245 -0
  19. package/dist/schema/approvals.js +52 -0
  20. package/dist/schema/catalog.d.ts +17 -0
  21. package/dist/schema/catalog.js +7 -1
  22. package/dist/schema/credentials.d.ts +1 -1
  23. package/dist/schema/git-tokens.js +1 -1
  24. package/dist/schema/grants.js +8 -2
  25. package/dist/schema/index.d.ts +8 -4
  26. package/dist/schema/index.js +8 -4
  27. package/dist/schema/messages.d.ts +5 -5
  28. package/dist/schema/messages.js +20 -9
  29. package/dist/schema/offerings.js +8 -2
  30. package/dist/schema/principals.d.ts +2 -2
  31. package/dist/schema/principals.js +7 -5
  32. package/dist/schema/providers.d.ts +17 -0
  33. package/dist/schema/providers.js +5 -0
  34. package/dist/schema/roles.js +6 -2
  35. package/dist/schema/session-assets.d.ts +1 -38
  36. package/dist/schema/session-assets.js +36 -19
  37. package/dist/schema/sessions.js +7 -2
  38. package/dist/schema/sidecar-allocation.d.ts +406 -0
  39. package/dist/schema/sidecar-allocation.js +57 -0
  40. package/dist/schema/sidecar.d.ts +19 -2
  41. package/dist/schema/sidecar.js +13 -3
  42. package/dist/schema/signal-correlations.d.ts +177 -0
  43. package/dist/schema/signal-correlations.js +31 -0
  44. package/dist/schema/wallets.d.ts +3 -3
  45. package/dist/schema/wallets.js +4 -2
  46. package/dist/schema/{agents.d.ts → workflow-definitions.d.ts} +79 -113
  47. package/dist/schema/workflow-definitions.js +97 -0
  48. package/dist/schema/workflow-run-dispatch.d.ts +328 -0
  49. package/dist/schema/workflow-run-dispatch.js +56 -0
  50. package/dist/schema/{workflow-deployments.d.ts → workflow-run-execution.d.ts} +43 -46
  51. package/dist/schema/workflow-run-execution.js +48 -0
  52. package/dist/schema/workflow-run-launch-spec.d.ts +200 -0
  53. package/dist/schema/workflow-run-launch-spec.js +26 -0
  54. package/dist/schema/{instances.d.ts → workflow-run.d.ts} +39 -71
  55. package/dist/schema/workflow-run.js +102 -0
  56. package/dist/sidecar-allocation-store.d.ts +171 -0
  57. package/dist/sidecar-allocation-store.js +512 -0
  58. package/dist/signal-correlation-store.d.ts +36 -0
  59. package/dist/signal-correlation-store.js +63 -0
  60. package/dist/tenant-hierarchy.d.ts +2 -1
  61. package/dist/tenant-hierarchy.js +10 -5
  62. package/dist/workflow-definition-store.d.ts +55 -0
  63. package/dist/workflow-definition-store.js +93 -0
  64. package/dist/workflow-run-dispatch-store.d.ts +80 -0
  65. package/dist/workflow-run-dispatch-store.js +298 -0
  66. package/dist/workflow-run-launch-spec-store.d.ts +13 -0
  67. package/dist/workflow-run-launch-spec-store.js +30 -0
  68. package/dist/workflow-run-store.d.ts +54 -0
  69. package/dist/workflow-run-store.js +85 -0
  70. package/migrations/0037_credential_use_backfill.sql +39 -0
  71. package/migrations/0038_chilly_blacklash.sql +37 -0
  72. package/migrations/0039_quick_carnage.sql +2 -0
  73. package/migrations/0040_reshape_approval_origin.sql +24 -0
  74. package/migrations/0041_make_approval_timeout_at_nullable.sql +1 -0
  75. package/migrations/0042_youthful_mantis.sql +2 -0
  76. package/migrations/0043_signal_correlation_deployment_fk.sql +1 -0
  77. package/migrations/0044_model_offering_quirks.sql +1 -0
  78. package/migrations/0045_create_workflow_run.sql +13 -0
  79. package/migrations/0046_approval_signal_correlation_run_fk.sql +2 -0
  80. package/migrations/0047_create_workflow_definition.sql +30 -0
  81. package/migrations/0048_workflow_definition_origin_agent_id.sql +2 -0
  82. package/migrations/0049_curly_omega_flight.sql +2 -0
  83. package/migrations/0050_late_crystal.sql +10 -0
  84. package/migrations/0051_funny_madelyne_pryor.sql +1 -0
  85. package/migrations/0052_drop_inference_turn_instance_fk.sql +1 -0
  86. package/migrations/0053_session_mail_session_id_index.sql +1 -0
  87. package/migrations/0054_rekey_instance_grants_to_workflow_run.sql +10 -0
  88. package/migrations/0055_backfill_anchor_workflow_runs.sql +69 -0
  89. package/migrations/0056_repoint_deployment_fks_to_anchor_run.sql +32 -0
  90. package/migrations/0057_drop_workflow_deployment_projection.sql +22 -0
  91. package/migrations/0058_repoint_offering_fk_to_definition.sql +41 -0
  92. package/migrations/0059_repoint_transaction_fk_to_run.sql +10 -0
  93. package/migrations/0060_drop_session_mail_instance_fk.sql +6 -0
  94. package/migrations/0061_drop_session_asset_instance_fk.sql +7 -0
  95. package/migrations/0062_drop_agent_asset_table.sql +11 -0
  96. package/migrations/0063_repoint_agent_role_fk_to_definition.sql +39 -0
  97. package/migrations/0064_repoint_agent_session_fk_to_definition.sql +47 -0
  98. package/migrations/0065_add_workflow_definition_model_requirements.sql +37 -0
  99. package/migrations/0066_rekey_agent_definition_principals_to_workflow.sql +27 -0
  100. package/migrations/0067_add_workflow_definition_kind.sql +10 -0
  101. package/migrations/0068_drop_agent_tables_and_origin_agent_id.sql +31 -0
  102. package/migrations/0069_drop_workflow_definition_kind.sql +10 -0
  103. package/migrations/0070_flashy_proteus.sql +13 -0
  104. package/migrations/0072_add_workflow_definition_credential_bindings.sql +1 -0
  105. package/migrations/0073_grant_target_exactly_one_check.sql +13 -0
  106. package/migrations/0074_add_provider_api_base_url.sql +1 -0
  107. package/migrations/0075_workflow_run_launch_spec.sql +17 -0
  108. package/migrations/0076_sidecar_allocation.sql +40 -0
  109. package/migrations/0077_workflow_run_dispatch.sql +29 -0
  110. package/migrations/0078_workflow_run_dispatch_kind.sql +2 -0
  111. package/migrations/0079_rename_workflow_run_deployment_id_to_anchor_run_id.sql +4 -0
  112. package/migrations/0080_rename_correlation_approval_deployment_id_to_anchor_run_id.sql +9 -0
  113. package/migrations/0081_workflow_definition_content_hash_and_approved_wire_hash.sql +4 -0
  114. package/migrations/0082_blue_black_queen.sql +1 -0
  115. package/migrations/0083_replace_launch_spec_snapshot_with_frozen_bundle.sql +3 -0
  116. package/migrations/0084_delete_orphaned_credential_grants.sql +22 -0
  117. package/migrations/meta/0037_snapshot.json +3237 -0
  118. package/migrations/meta/0038_snapshot.json +3470 -0
  119. package/migrations/meta/0039_snapshot.json +3470 -0
  120. package/migrations/meta/0040_snapshot.json +3489 -0
  121. package/migrations/meta/0041_snapshot.json +3489 -0
  122. package/migrations/meta/0042_snapshot.json +3489 -0
  123. package/migrations/meta/0043_snapshot.json +3498 -0
  124. package/migrations/meta/0044_snapshot.json +3504 -0
  125. package/migrations/meta/0045_snapshot.json +3589 -0
  126. package/migrations/meta/0046_snapshot.json +3607 -0
  127. package/migrations/meta/0047_snapshot.json +3832 -0
  128. package/migrations/meta/0048_snapshot.json +3853 -0
  129. package/migrations/meta/0049_snapshot.json +3854 -0
  130. package/migrations/meta/0050_snapshot.json +3924 -0
  131. package/migrations/meta/0051_snapshot.json +3940 -0
  132. package/migrations/meta/0052_snapshot.json +3931 -0
  133. package/migrations/meta/0053_snapshot.json +3952 -0
  134. package/migrations/meta/0054_snapshot.json +3952 -0
  135. package/migrations/meta/0055_snapshot.json +3952 -0
  136. package/migrations/meta/0056_snapshot.json +3952 -0
  137. package/migrations/meta/0057_snapshot.json +3839 -0
  138. package/migrations/meta/0058_snapshot.json +3839 -0
  139. package/migrations/meta/0059_snapshot.json +3839 -0
  140. package/migrations/meta/0060_snapshot.json +3830 -0
  141. package/migrations/meta/0061_snapshot.json +3821 -0
  142. package/migrations/meta/0062_snapshot.json +3723 -0
  143. package/migrations/meta/0063_snapshot.json +3723 -0
  144. package/migrations/meta/0064_snapshot.json +3723 -0
  145. package/migrations/meta/0065_snapshot.json +3729 -0
  146. package/migrations/meta/0066_snapshot.json +3729 -0
  147. package/migrations/meta/0067_snapshot.json +3736 -0
  148. package/migrations/meta/0068_snapshot.json +3347 -0
  149. package/migrations/meta/0069_snapshot.json +3340 -0
  150. package/migrations/meta/0070_snapshot.json +3444 -0
  151. package/migrations/meta/0072_snapshot.json +3450 -0
  152. package/migrations/meta/0073_snapshot.json +3455 -0
  153. package/migrations/meta/0074_snapshot.json +3461 -0
  154. package/migrations/meta/0075_snapshot.json +3567 -0
  155. package/migrations/meta/0076_snapshot.json +3851 -0
  156. package/migrations/meta/0077_snapshot.json +4067 -0
  157. package/migrations/meta/0078_snapshot.json +4078 -0
  158. package/migrations/meta/0079_snapshot.json +4078 -0
  159. package/migrations/meta/0080_snapshot.json +4078 -0
  160. package/migrations/meta/0081_snapshot.json +4096 -0
  161. package/migrations/meta/0082_snapshot.json +4102 -0
  162. package/migrations/meta/0083_snapshot.json +4096 -0
  163. package/migrations/meta/0084_snapshot.json +4096 -0
  164. package/migrations/meta/_journal.json +329 -0
  165. package/package.json +6 -3
  166. package/dist/schema/agent-assets.d.ts +0 -109
  167. package/dist/schema/agent-assets.js +0 -15
  168. package/dist/schema/agents.js +0 -57
  169. package/dist/schema/instances.js +0 -39
  170. package/dist/schema/workflow-deployments.js +0 -37
@@ -0,0 +1,245 @@
1
+ export declare const approval: import("drizzle-orm/pg-core").PgTableWithColumns<{
2
+ name: "approval";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/pg-core").PgColumn<{
6
+ name: "id";
7
+ tableName: "approval";
8
+ dataType: "string";
9
+ columnType: "PgText";
10
+ data: string;
11
+ driverParam: string;
12
+ notNull: true;
13
+ hasDefault: false;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: [string, ...string[]];
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}, {}>;
22
+ tenantId: import("drizzle-orm/pg-core").PgColumn<{
23
+ name: "tenant_id";
24
+ tableName: "approval";
25
+ dataType: "string";
26
+ columnType: "PgText";
27
+ data: string;
28
+ driverParam: string;
29
+ notNull: true;
30
+ hasDefault: false;
31
+ isPrimaryKey: false;
32
+ isAutoincrement: false;
33
+ hasRuntimeDefault: false;
34
+ enumValues: [string, ...string[]];
35
+ baseColumn: never;
36
+ identity: undefined;
37
+ generated: undefined;
38
+ }, {}, {}>;
39
+ anchorRunId: import("drizzle-orm/pg-core").PgColumn<{
40
+ name: "anchor_run_id";
41
+ tableName: "approval";
42
+ dataType: "string";
43
+ columnType: "PgText";
44
+ data: string;
45
+ driverParam: string;
46
+ notNull: true;
47
+ hasDefault: false;
48
+ isPrimaryKey: false;
49
+ isAutoincrement: false;
50
+ hasRuntimeDefault: false;
51
+ enumValues: [string, ...string[]];
52
+ baseColumn: never;
53
+ identity: undefined;
54
+ generated: undefined;
55
+ }, {}, {}>;
56
+ runId: import("drizzle-orm/pg-core").PgColumn<{
57
+ name: "run_id";
58
+ tableName: "approval";
59
+ dataType: "string";
60
+ columnType: "PgText";
61
+ data: string;
62
+ driverParam: string;
63
+ notNull: true;
64
+ hasDefault: false;
65
+ isPrimaryKey: false;
66
+ isAutoincrement: false;
67
+ hasRuntimeDefault: false;
68
+ enumValues: [string, ...string[]];
69
+ baseColumn: never;
70
+ identity: undefined;
71
+ generated: undefined;
72
+ }, {}, {}>;
73
+ agentAddress: import("drizzle-orm/pg-core").PgColumn<{
74
+ name: "agent_address";
75
+ tableName: "approval";
76
+ dataType: "string";
77
+ columnType: "PgText";
78
+ data: string;
79
+ driverParam: string;
80
+ notNull: true;
81
+ hasDefault: false;
82
+ isPrimaryKey: false;
83
+ isAutoincrement: false;
84
+ hasRuntimeDefault: false;
85
+ enumValues: [string, ...string[]];
86
+ baseColumn: never;
87
+ identity: undefined;
88
+ generated: undefined;
89
+ }, {}, {}>;
90
+ correlationId: import("drizzle-orm/pg-core").PgColumn<{
91
+ name: "correlation_id";
92
+ tableName: "approval";
93
+ dataType: "string";
94
+ columnType: "PgText";
95
+ data: string;
96
+ driverParam: string;
97
+ notNull: true;
98
+ hasDefault: false;
99
+ isPrimaryKey: false;
100
+ isAutoincrement: false;
101
+ hasRuntimeDefault: false;
102
+ enumValues: [string, ...string[]];
103
+ baseColumn: never;
104
+ identity: undefined;
105
+ generated: undefined;
106
+ }, {}, {}>;
107
+ toolDefinition: import("drizzle-orm/pg-core").PgColumn<{
108
+ name: "tool_definition";
109
+ tableName: "approval";
110
+ dataType: "json";
111
+ columnType: "PgJsonb";
112
+ data: unknown;
113
+ driverParam: unknown;
114
+ notNull: true;
115
+ hasDefault: false;
116
+ isPrimaryKey: false;
117
+ isAutoincrement: false;
118
+ hasRuntimeDefault: false;
119
+ enumValues: undefined;
120
+ baseColumn: never;
121
+ identity: undefined;
122
+ generated: undefined;
123
+ }, {}, {}>;
124
+ toolArguments: import("drizzle-orm/pg-core").PgColumn<{
125
+ name: "tool_arguments";
126
+ tableName: "approval";
127
+ dataType: "json";
128
+ columnType: "PgJsonb";
129
+ data: unknown;
130
+ driverParam: unknown;
131
+ notNull: true;
132
+ hasDefault: false;
133
+ isPrimaryKey: false;
134
+ isAutoincrement: false;
135
+ hasRuntimeDefault: false;
136
+ enumValues: undefined;
137
+ baseColumn: never;
138
+ identity: undefined;
139
+ generated: undefined;
140
+ }, {}, {}>;
141
+ scope: import("drizzle-orm/pg-core").PgColumn<{
142
+ name: "scope";
143
+ tableName: "approval";
144
+ dataType: "string";
145
+ columnType: "PgText";
146
+ data: "always" | "once";
147
+ driverParam: string;
148
+ notNull: false;
149
+ hasDefault: false;
150
+ isPrimaryKey: false;
151
+ isAutoincrement: false;
152
+ hasRuntimeDefault: false;
153
+ enumValues: ["once", "always"];
154
+ baseColumn: never;
155
+ identity: undefined;
156
+ generated: undefined;
157
+ }, {}, {}>;
158
+ status: import("drizzle-orm/pg-core").PgColumn<{
159
+ name: "status";
160
+ tableName: "approval";
161
+ dataType: "string";
162
+ columnType: "PgText";
163
+ data: "pending" | "approved" | "rejected" | "timeout" | "expired";
164
+ driverParam: string;
165
+ notNull: true;
166
+ hasDefault: true;
167
+ isPrimaryKey: false;
168
+ isAutoincrement: false;
169
+ hasRuntimeDefault: false;
170
+ enumValues: ["pending", "approved", "rejected", "timeout", "expired"];
171
+ baseColumn: never;
172
+ identity: undefined;
173
+ generated: undefined;
174
+ }, {}, {}>;
175
+ timeoutAt: import("drizzle-orm/pg-core").PgColumn<{
176
+ name: "timeout_at";
177
+ tableName: "approval";
178
+ dataType: "date";
179
+ columnType: "PgTimestamp";
180
+ data: Date;
181
+ driverParam: string;
182
+ notNull: false;
183
+ hasDefault: false;
184
+ isPrimaryKey: false;
185
+ isAutoincrement: false;
186
+ hasRuntimeDefault: false;
187
+ enumValues: undefined;
188
+ baseColumn: never;
189
+ identity: undefined;
190
+ generated: undefined;
191
+ }, {}, {}>;
192
+ resolvedAt: import("drizzle-orm/pg-core").PgColumn<{
193
+ name: "resolved_at";
194
+ tableName: "approval";
195
+ dataType: "date";
196
+ columnType: "PgTimestamp";
197
+ data: Date;
198
+ driverParam: string;
199
+ notNull: false;
200
+ hasDefault: false;
201
+ isPrimaryKey: false;
202
+ isAutoincrement: false;
203
+ hasRuntimeDefault: false;
204
+ enumValues: undefined;
205
+ baseColumn: never;
206
+ identity: undefined;
207
+ generated: undefined;
208
+ }, {}, {}>;
209
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
210
+ name: "created_at";
211
+ tableName: "approval";
212
+ dataType: "date";
213
+ columnType: "PgTimestamp";
214
+ data: Date;
215
+ driverParam: string;
216
+ notNull: true;
217
+ hasDefault: true;
218
+ isPrimaryKey: false;
219
+ isAutoincrement: false;
220
+ hasRuntimeDefault: false;
221
+ enumValues: undefined;
222
+ baseColumn: never;
223
+ identity: undefined;
224
+ generated: undefined;
225
+ }, {}, {}>;
226
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
227
+ name: "updated_at";
228
+ tableName: "approval";
229
+ dataType: "date";
230
+ columnType: "PgTimestamp";
231
+ data: Date;
232
+ driverParam: string;
233
+ notNull: true;
234
+ hasDefault: true;
235
+ isPrimaryKey: false;
236
+ isAutoincrement: false;
237
+ hasRuntimeDefault: false;
238
+ enumValues: undefined;
239
+ baseColumn: never;
240
+ identity: undefined;
241
+ generated: undefined;
242
+ }, {}, {}>;
243
+ };
244
+ dialect: "pg";
245
+ }>;
@@ -0,0 +1,52 @@
1
+ import { index, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
+ import { tenant } from "./tenants.js";
3
+ import { workflowRun } from "./workflow-run.js";
4
+ // Every approval originates from a workflow deployment, so the origin is
5
+ // modeled as the deployment's anchor run -- the workflow_run whose id equals
6
+ // the deployment id -- rather than a launched single agent. A workflow
7
+ // deployment has no `agent_instance` or `agent` row, and the principal its run
8
+ // executes under is a substrate principal, not a `principal`-table row -- so
9
+ // none of those tables can hold a valid referent for an approval's origin.
10
+ export const approval = pgTable("approval", {
11
+ id: text("id").primaryKey(),
12
+ tenantId: text("tenant_id")
13
+ .notNull()
14
+ .references(() => tenant.id, { onDelete: "cascade" }),
15
+ anchorRunId: text("anchor_run_id")
16
+ .notNull()
17
+ .references(() => workflowRun.id, { onDelete: "cascade" }),
18
+ // References the run this approval belongs to, making "this approval is for
19
+ // a real run of this deployment" a database invariant. Cascades on the
20
+ // run's delete; the `anchor_run_id` FK above stays as the lock and cascade
21
+ // anchor the co-write orders against.
22
+ runId: text("run_id")
23
+ .notNull()
24
+ .references(() => workflowRun.id, { onDelete: "cascade" }),
25
+ agentAddress: text("agent_address").notNull(),
26
+ correlationId: text("correlation_id").notNull().unique(),
27
+ // Always populated: the ask rail is the sole co-writer and the register
28
+ // frame's required snapshot guarantees both fields at insert time.
29
+ toolDefinition: jsonb("tool_definition").notNull(),
30
+ toolArguments: jsonb("tool_arguments").notNull(),
31
+ scope: text("scope", { enum: ["once", "always"] }),
32
+ status: text("status", {
33
+ enum: ["pending", "approved", "rejected", "timeout", "expired"],
34
+ })
35
+ .notNull()
36
+ .default("pending"),
37
+ // Nullable so an approval that holds indefinitely can be recorded with no
38
+ // deadline. An agent-step suspend parks on its correlation's signal with no
39
+ // timeout (`parkOnSignal` is called without a `timeout`), so no `timeoutAt`
40
+ // reaches the sidecar frame that co-writes this row -- the deadline lives in
41
+ // the reactor's gate, which the hold-indefinitely suspend path never sets.
42
+ // A null `timeoutAt` is the hold-indefinitely case; a resolver that adds
43
+ // per-workflow expiry populates it when a deadline is configured. Parallels
44
+ // the tool-snapshot columns above, which are likewise deferred.
45
+ timeoutAt: timestamp("timeout_at"),
46
+ resolvedAt: timestamp("resolved_at"),
47
+ createdAt: timestamp("created_at").notNull().defaultNow(),
48
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
49
+ }, (t) => [
50
+ index("approval_tenant_status_idx").on(t.tenantId, t.status, t.createdAt),
51
+ index("approval_anchor_run_idx").on(t.anchorRunId),
52
+ ]);
@@ -493,6 +493,23 @@ export declare const modelOffering: import("drizzle-orm/pg-core").PgTableWithCol
493
493
  }, {}, {}, import("drizzle-orm").ColumnBuilderExtraConfig>;
494
494
  size: undefined;
495
495
  }>;
496
+ quirks: import("drizzle-orm/pg-core").PgColumn<{
497
+ name: "quirks";
498
+ tableName: "model_offering";
499
+ dataType: "json";
500
+ columnType: "PgJsonb";
501
+ data: unknown;
502
+ driverParam: unknown;
503
+ notNull: false;
504
+ hasDefault: false;
505
+ isPrimaryKey: false;
506
+ isAutoincrement: false;
507
+ hasRuntimeDefault: false;
508
+ enumValues: undefined;
509
+ baseColumn: never;
510
+ identity: undefined;
511
+ generated: undefined;
512
+ }, {}, {}>;
496
513
  disabled: import("drizzle-orm/pg-core").PgColumn<{
497
514
  name: "disabled";
498
515
  tableName: "model_offering";
@@ -1,5 +1,5 @@
1
1
  import { sql } from "drizzle-orm";
2
- import { boolean, check, integer, pgTable, text, timestamp, unique, } from "drizzle-orm/pg-core";
2
+ import { boolean, check, integer, jsonb, pgTable, text, timestamp, unique, } from "drizzle-orm/pg-core";
3
3
  import { credential } from "./credentials.js";
4
4
  import { tenant } from "./tenants.js";
5
5
  import { wallet } from "./wallets.js";
@@ -63,6 +63,12 @@ export const modelOffering = pgTable("model_offering", {
63
63
  // Curated-capability tags. This issue creates the column; the values are
64
64
  // populated by the discovery-support-matrix seeding work.
65
65
  capabilities: text("capabilities").array().notNull().default([]),
66
+ // Opaque per-deployment bag of provider-specific adapter accommodations
67
+ // (e.g. OpenAI's forceAssistantReasoningContent). Interpreted and
68
+ // validated only at the adapter factory, which alone knows the provider
69
+ // shape. NULL means the factory receives no bag and applies its default
70
+ // behavior.
71
+ quirks: jsonb("quirks"),
66
72
  // Own-row disable. Inherited-row suppression is resolved separately.
67
73
  disabled: boolean("disabled").notNull().default(false),
68
74
  createdAt: timestamp("created_at").notNull().defaultNow(),
@@ -237,7 +237,7 @@ export declare const credential: import("drizzle-orm/pg-core").PgTableWithColumn
237
237
  tableName: "credential";
238
238
  dataType: "string";
239
239
  columnType: "PgText";
240
- data: "active" | "expired" | "revoked" | "error";
240
+ data: "active" | "error" | "expired" | "revoked";
241
241
  driverParam: string;
242
242
  notNull: true;
243
243
  hasDefault: true;
@@ -24,7 +24,7 @@ import { tenant } from "./tenants.js";
24
24
  // (`receivePack`, `createPack`, `resolveRef`, ...). The mint API
25
25
  // translates user-facing aliases to canonical names before insert.
26
26
  // `resource` is the single substrate authz resource string
27
- // (e.g. `agent-state:ins_xxx`, `asset:def_yyy`) that the token grants
27
+ // (e.g. `agent-state:run_xxx`, `asset:def_yyy`) that the token grants
28
28
  // access to. `refPattern` is a glob restricting which refs within the
29
29
  // resource the token may read or write.
30
30
  //
@@ -1,4 +1,5 @@
1
- import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
1
+ import { check, jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
+ import { sql } from "drizzle-orm";
2
3
  import { principal } from "./principals.js";
3
4
  import { role } from "./roles.js";
4
5
  import { tenant } from "./tenants.js";
@@ -21,4 +22,9 @@ export const grant = pgTable("grant", {
21
22
  expiresAt: timestamp("expires_at"),
22
23
  createdAt: timestamp("created_at").notNull().defaultNow(),
23
24
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
24
- });
25
+ }, (t) => [
26
+ // Exactly one target: a grant hangs off a role OR a principal, never both
27
+ // and never neither. Documented in AUTH.md; enforced in the DB so a
28
+ // malformed row is rejected at write rather than silently mis-targeted.
29
+ check("grant_target_exactly_one", sql `num_nonnulls(${t.principalId}, ${t.roleId}) = 1`),
30
+ ]);
@@ -3,19 +3,23 @@ export * from "./tenants.js";
3
3
  export * from "./principals.js";
4
4
  export * from "./roles.js";
5
5
  export * from "./grants.js";
6
- export * from "./agents.js";
6
+ export * from "./approvals.js";
7
+ export * from "./signal-correlations.js";
7
8
  export * from "./providers.js";
8
9
  export * from "./oauth-clients.js";
9
10
  export * from "./credentials.js";
10
11
  export * from "./assets.js";
11
- export * from "./agent-assets.js";
12
12
  export * from "./wallets.js";
13
13
  export * from "./offerings.js";
14
14
  export * from "./catalog.js";
15
15
  export * from "./sidecar.js";
16
+ export * from "./sidecar-allocation.js";
16
17
  export * from "./sessions.js";
17
- export * from "./instances.js";
18
18
  export * from "./session-assets.js";
19
19
  export * from "./messages.js";
20
20
  export * from "./git-tokens.js";
21
- export * from "./workflow-deployments.js";
21
+ export * from "./workflow-definitions.js";
22
+ export * from "./workflow-run.js";
23
+ export * from "./workflow-run-dispatch.js";
24
+ export * from "./workflow-run-launch-spec.js";
25
+ export * from "./workflow-run-execution.js";
@@ -3,19 +3,23 @@ export * from "./tenants.js";
3
3
  export * from "./principals.js";
4
4
  export * from "./roles.js";
5
5
  export * from "./grants.js";
6
- export * from "./agents.js";
6
+ export * from "./approvals.js";
7
+ export * from "./signal-correlations.js";
7
8
  export * from "./providers.js";
8
9
  export * from "./oauth-clients.js";
9
10
  export * from "./credentials.js";
10
11
  export * from "./assets.js";
11
- export * from "./agent-assets.js";
12
12
  export * from "./wallets.js";
13
13
  export * from "./offerings.js";
14
14
  export * from "./catalog.js";
15
15
  export * from "./sidecar.js";
16
+ export * from "./sidecar-allocation.js";
16
17
  export * from "./sessions.js";
17
- export * from "./instances.js";
18
18
  export * from "./session-assets.js";
19
19
  export * from "./messages.js";
20
20
  export * from "./git-tokens.js";
21
- export * from "./workflow-deployments.js";
21
+ export * from "./workflow-definitions.js";
22
+ export * from "./workflow-run.js";
23
+ export * from "./workflow-run-dispatch.js";
24
+ export * from "./workflow-run-launch-spec.js";
25
+ export * from "./workflow-run-execution.js";
@@ -36,7 +36,7 @@ export declare const inferenceTurn: import("drizzle-orm/pg-core").PgTableWithCol
36
36
  identity: undefined;
37
37
  generated: undefined;
38
38
  }, {}, {}>;
39
- instanceId: import("drizzle-orm/pg-core").PgColumn<{
39
+ runId: import("drizzle-orm/pg-core").PgColumn<{
40
40
  name: "instance_id";
41
41
  tableName: "inference_turn";
42
42
  dataType: "string";
@@ -92,7 +92,7 @@ export declare const inferenceTurn: import("drizzle-orm/pg-core").PgTableWithCol
92
92
  tableName: "inference_turn";
93
93
  dataType: "string";
94
94
  columnType: "PgText";
95
- data: "failed" | "completed" | "running";
95
+ data: "failed" | "running" | "completed";
96
96
  driverParam: string;
97
97
  notNull: true;
98
98
  hasDefault: true;
@@ -201,14 +201,14 @@ export declare const turnPart: import("drizzle-orm/pg-core").PgTableWithColumns<
201
201
  tableName: "turn_part";
202
202
  dataType: "string";
203
203
  columnType: "PgText";
204
- data: "error" | "text" | "reasoning" | "tool" | "file" | "refusal" | "step-start" | "step-finish" | "snapshot" | "patch";
204
+ data: "error" | "tool" | "text" | "file" | "refusal" | "safety_rating" | "reasoning" | "step-start" | "step-finish" | "snapshot" | "patch";
205
205
  driverParam: string;
206
206
  notNull: true;
207
207
  hasDefault: false;
208
208
  isPrimaryKey: false;
209
209
  isAutoincrement: false;
210
210
  hasRuntimeDefault: false;
211
- enumValues: ["text", "reasoning", "tool", "file", "error", "refusal", "step-start", "step-finish", "snapshot", "patch"];
211
+ enumValues: ["text", "reasoning", "tool", "file", "error", "refusal", "safety_rating", "step-start", "step-finish", "snapshot", "patch"];
212
212
  baseColumn: never;
213
213
  identity: undefined;
214
214
  generated: undefined;
@@ -305,7 +305,7 @@ export declare const sessionMail: import("drizzle-orm/pg-core").PgTableWithColum
305
305
  identity: undefined;
306
306
  generated: undefined;
307
307
  }, {}, {}>;
308
- instanceId: import("drizzle-orm/pg-core").PgColumn<{
308
+ runId: import("drizzle-orm/pg-core").PgColumn<{
309
309
  name: "instance_id";
310
310
  tableName: "session_mail";
311
311
  dataType: "string";
@@ -1,6 +1,5 @@
1
1
  import { index, integer, jsonb, pgTable, text, timestamp, } from "drizzle-orm/pg-core";
2
2
  import { bytea } from "./column-types.js";
3
- import { agentInstance } from "./instances.js";
4
3
  import { agentSession } from "./sessions.js";
5
4
  import { tenant } from "./tenants.js";
6
5
  export const inferenceTurn = pgTable("inference_turn", {
@@ -8,9 +7,13 @@ export const inferenceTurn = pgTable("inference_turn", {
8
7
  sessionId: text("session_id")
9
8
  .notNull()
10
9
  .references(() => agentSession.id, { onDelete: "cascade" }),
11
- instanceId: text("instance_id")
12
- .notNull()
13
- .references(() => agentInstance.id, { onDelete: "cascade" }),
10
+ // The endpoint that produced this turn: a workflow_run id (older rows may
11
+ // carry an abandoned agent_instance id from before the fold, since the two
12
+ // shared one id space). This is a polymorphic reference that carries no
13
+ // foreign key; the collector-creation layer owns the invariant that the id
14
+ // names a live endpoint. It stays NOT NULL -- a turn always names its
15
+ // producer.
16
+ runId: text("instance_id").notNull(),
14
17
  tenantId: text("tenant_id")
15
18
  .notNull()
16
19
  .references(() => tenant.id, { onDelete: "cascade" }),
@@ -21,7 +24,7 @@ export const inferenceTurn = pgTable("inference_turn", {
21
24
  startedAt: timestamp("started_at").notNull(),
22
25
  endedAt: timestamp("ended_at"),
23
26
  }, (t) => [
24
- index("inference_turn_instance_id_started_at_idx").on(t.instanceId, t.startedAt),
27
+ index("inference_turn_instance_id_started_at_idx").on(t.runId, t.startedAt),
25
28
  ]);
26
29
  export const turnPart = pgTable("turn_part", {
27
30
  id: text("id").primaryKey(),
@@ -39,6 +42,7 @@ export const turnPart = pgTable("turn_part", {
39
42
  "file",
40
43
  "error",
41
44
  "refusal",
45
+ "safety_rating",
42
46
  "step-start",
43
47
  "step-finish",
44
48
  "snapshot",
@@ -54,9 +58,12 @@ export const sessionMail = pgTable("session_mail", {
54
58
  sessionId: text("session_id")
55
59
  .notNull()
56
60
  .references(() => agentSession.id, { onDelete: "cascade" }),
57
- instanceId: text("instance_id").references(() => agentInstance.id, {
58
- onDelete: "set null",
59
- }),
61
+ // The endpoint whose mail this is: null for a folded run (which keys its
62
+ // mail on the session instead), or -- on older rows from before the fold --
63
+ // an abandoned agent_instance id. A polymorphic reference that carries no
64
+ // foreign key (mirroring inference_turn.runId); the mail-write layer
65
+ // owns the invariant. Nullable -- absent for folded runs.
66
+ runId: text("instance_id"),
60
67
  tenantId: text("tenant_id")
61
68
  .notNull()
62
69
  .references(() => tenant.id, { onDelete: "cascade" }),
@@ -67,5 +74,9 @@ export const sessionMail = pgTable("session_mail", {
67
74
  raw: bytea("raw").notNull(),
68
75
  createdAt: timestamp("created_at").notNull().defaultNow(),
69
76
  }, (t) => [
70
- index("session_mail_instance_id_created_at_idx").on(t.instanceId, t.createdAt),
77
+ index("session_mail_instance_id_created_at_idx").on(t.runId, t.createdAt),
78
+ // A folded run's mail carries a null runId, so its history and prior-
79
+ // mail queries key on the session instead. This index supports that scan
80
+ // the way the runId index supports a legacy instance's.
81
+ index("session_mail_session_id_created_at_idx").on(t.sessionId, t.createdAt),
71
82
  ]);
@@ -1,11 +1,17 @@
1
1
  import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
- import { agent } from "./agents.js";
3
2
  import { tenant } from "./tenants.js";
3
+ import { workflowDefinition } from "./workflow-definitions.js";
4
4
  export const offering = pgTable("offering", {
5
5
  id: text("id").primaryKey(),
6
+ // The workflow definition this offering prices. The column keeps its
7
+ // `agent_id` name for contract stability -- the offering API exposes
8
+ // `agentId`/`agentName` -- but it now holds a workflow_definition id (a folded
9
+ // agent's definition). `restrict`, not cascade: an offering is a commercial
10
+ // pricing record, so deleting its definition must consciously deal with the
11
+ // offering rather than silently vaporize it.
6
12
  agentId: text("agent_id")
7
13
  .notNull()
8
- .references(() => agent.id, { onDelete: "cascade" }),
14
+ .references(() => workflowDefinition.id, { onDelete: "restrict" }),
9
15
  tenantId: text("tenant_id")
10
16
  .notNull()
11
17
  .references(() => tenant.id, { onDelete: "cascade" }),
@@ -42,14 +42,14 @@ export declare const principal: import("drizzle-orm/pg-core").PgTableWithColumns
42
42
  tableName: "principal";
43
43
  dataType: "string";
44
44
  columnType: "PgText";
45
- data: "user" | "agent";
45
+ data: "user" | "agent" | "workflow";
46
46
  driverParam: string;
47
47
  notNull: true;
48
48
  hasDefault: false;
49
49
  isPrimaryKey: false;
50
50
  isAutoincrement: false;
51
51
  hasRuntimeDefault: false;
52
- enumValues: ["user", "agent"];
52
+ enumValues: ["user", "agent", "workflow"];
53
53
  baseColumn: never;
54
54
  identity: undefined;
55
55
  generated: undefined;
@@ -6,7 +6,7 @@ export const principal = pgTable("principal", {
6
6
  tenantId: text("tenant_id")
7
7
  .notNull()
8
8
  .references(() => tenant.id, { onDelete: "cascade" }),
9
- kind: text("kind", { enum: ["user", "agent"] }).notNull(),
9
+ kind: text("kind", { enum: ["user", "agent", "workflow"] }).notNull(),
10
10
  refId: text("ref_id").notNull(),
11
11
  status: text("status", {
12
12
  enum: ["active", "suspended", "invited", "deactivated"],
@@ -14,8 +14,10 @@ export const principal = pgTable("principal", {
14
14
  createdAt: timestamp("created_at").notNull().defaultNow(),
15
15
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
16
16
  }, (t) => [unique().on(t.tenantId, t.kind, t.refId)]);
17
- // The refId on a user principal points to the auth user table.
18
- // We don't add a FK constraint because refId also points to agent.id
19
- // when kind='agent', and Postgres can't do conditional FKs.
20
- // The application layer enforces referential integrity.
17
+ // refId is polymorphic on kind: the auth user for kind='user', and either a
18
+ // workflow_run or a workflow_definition for kind='workflow'. A `kind='agent'`
19
+ // principal is a legacy survivor of the fold -- its refId named an
20
+ // `agent_instance` row, a table now dropped, so it dangles and is inert.
21
+ // Postgres can't express a conditional FK across those targets, so there is no
22
+ // FK constraint here and the application layer enforces referential integrity.
21
23
  export { user };
@@ -70,6 +70,23 @@ export declare const provider: import("drizzle-orm/pg-core").PgTableWithColumns<
70
70
  identity: undefined;
71
71
  generated: undefined;
72
72
  }, {}, {}>;
73
+ apiBaseUrl: import("drizzle-orm/pg-core").PgColumn<{
74
+ name: "api_base_url";
75
+ tableName: "provider";
76
+ dataType: "string";
77
+ columnType: "PgText";
78
+ data: string;
79
+ driverParam: string;
80
+ notNull: false;
81
+ hasDefault: false;
82
+ isPrimaryKey: false;
83
+ isAutoincrement: false;
84
+ hasRuntimeDefault: false;
85
+ enumValues: [string, ...string[]];
86
+ baseColumn: never;
87
+ identity: undefined;
88
+ generated: undefined;
89
+ }, {}, {}>;
73
90
  authorizationUrl: import("drizzle-orm/pg-core").PgColumn<{
74
91
  name: "authorization_url";
75
92
  tableName: "provider";
@@ -7,6 +7,11 @@ export const provider = pgTable("provider", {
7
7
  .references(() => tenant.id, { onDelete: "cascade" }),
8
8
  name: text("name").notNull(),
9
9
  plugin: text("plugin").notNull(),
10
+ // The API origin a credential from this provider authenticates to (e.g.
11
+ // https://api.github.com). Optional: OAuth-login-only providers have no
12
+ // API-call origin. A provider that backs an origin-pinned credential must
13
+ // have one, enforced loudly at credential-shape time, not by the schema.
14
+ apiBaseUrl: text("api_base_url"),
10
15
  authorizationUrl: text("authorization_url"),
11
16
  tokenUrl: text("token_url"),
12
17
  userInfoUrl: text("user_info_url"),