@intx/db 0.2.2 → 0.4.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 (207) hide show
  1. package/README.md +13 -2
  2. package/dist/approval-store.d.ts +59 -0
  3. package/dist/approval-store.js +92 -0
  4. package/dist/asset-resolution.d.ts +2 -2
  5. package/dist/backfill-principal-keys.d.ts +9 -0
  6. package/dist/backfill-principal-keys.js +51 -0
  7. package/dist/client.d.ts +37 -2
  8. package/dist/client.js +6 -0
  9. package/dist/config.d.ts +1 -0
  10. package/dist/config.js +2 -0
  11. package/dist/connection.js +12 -8
  12. package/dist/credential-resolution.d.ts +181 -20
  13. package/dist/credential-resolution.js +251 -3
  14. package/dist/grant-store.js +35 -13
  15. package/dist/index.d.ts +20 -5
  16. package/dist/index.js +19 -5
  17. package/dist/model-source-resolution.d.ts +54 -7
  18. package/dist/model-source-resolution.js +177 -22
  19. package/dist/parse-row.d.ts +245 -34
  20. package/dist/parse-row.js +117 -18
  21. package/dist/principal-key-store.d.ts +51 -0
  22. package/dist/principal-key-store.js +82 -0
  23. package/dist/principal-store.d.ts +44 -0
  24. package/dist/principal-store.js +67 -0
  25. package/dist/rekey-credential-secrets.d.ts +13 -0
  26. package/dist/rekey-credential-secrets.js +61 -0
  27. package/dist/schema/approvals.d.ts +245 -0
  28. package/dist/schema/approvals.js +57 -0
  29. package/dist/schema/catalog.d.ts +17 -0
  30. package/dist/schema/catalog.js +7 -1
  31. package/dist/schema/credentials.d.ts +1 -1
  32. package/dist/schema/git-tokens.js +1 -1
  33. package/dist/schema/grants.js +8 -2
  34. package/dist/schema/index.d.ts +10 -4
  35. package/dist/schema/index.js +10 -4
  36. package/dist/schema/messages.d.ts +5 -5
  37. package/dist/schema/messages.js +20 -9
  38. package/dist/schema/offerings.js +8 -2
  39. package/dist/schema/{workflow-deployments.d.ts → principal-keys.d.ts} +29 -32
  40. package/dist/schema/principal-keys.js +28 -0
  41. package/dist/schema/principals.d.ts +2 -2
  42. package/dist/schema/principals.js +7 -5
  43. package/dist/schema/providers.d.ts +17 -0
  44. package/dist/schema/providers.js +5 -0
  45. package/dist/schema/roles.js +6 -2
  46. package/dist/schema/session-assets.d.ts +1 -38
  47. package/dist/schema/session-assets.js +36 -19
  48. package/dist/schema/sessions.js +7 -2
  49. package/dist/schema/sidecar-allocation.d.ts +385 -0
  50. package/dist/schema/sidecar-allocation.js +53 -0
  51. package/dist/schema/sidecar.d.ts +2 -2
  52. package/dist/schema/sidecar.js +3 -1
  53. package/dist/schema/signal-correlations.d.ts +177 -0
  54. package/dist/schema/signal-correlations.js +31 -0
  55. package/dist/schema/tenants.js +13 -3
  56. package/dist/schema/wallets.d.ts +3 -3
  57. package/dist/schema/wallets.js +4 -2
  58. package/dist/schema/{agents.d.ts → workflow-definitions.d.ts} +79 -113
  59. package/dist/schema/workflow-definitions.js +97 -0
  60. package/dist/schema/workflow-probe.d.ts +358 -0
  61. package/dist/schema/workflow-probe.js +51 -0
  62. package/dist/schema/workflow-run-dispatch.d.ts +345 -0
  63. package/dist/schema/workflow-run-dispatch.js +63 -0
  64. package/dist/schema/{agent-assets.d.ts → workflow-run-execution.d.ts} +44 -27
  65. package/dist/schema/workflow-run-execution.js +48 -0
  66. package/dist/schema/workflow-run-launch-spec.d.ts +200 -0
  67. package/dist/schema/workflow-run-launch-spec.js +26 -0
  68. package/dist/schema/{instances.d.ts → workflow-run.d.ts} +61 -66
  69. package/dist/schema/workflow-run.js +110 -0
  70. package/dist/sender-key-resolver.d.ts +91 -0
  71. package/dist/sender-key-resolver.js +184 -0
  72. package/dist/sidecar-allocation-store.d.ts +206 -0
  73. package/dist/sidecar-allocation-store.js +714 -0
  74. package/dist/signal-correlation-store.d.ts +36 -0
  75. package/dist/signal-correlation-store.js +63 -0
  76. package/dist/signer-identity.d.ts +12 -0
  77. package/dist/signer-identity.js +15 -0
  78. package/dist/tenant-hierarchy.d.ts +4 -1
  79. package/dist/tenant-hierarchy.js +37 -5
  80. package/dist/workflow-definition-store.d.ts +55 -0
  81. package/dist/workflow-definition-store.js +93 -0
  82. package/dist/workflow-probe-store.d.ts +47 -0
  83. package/dist/workflow-probe-store.js +124 -0
  84. package/dist/workflow-run-dispatch-store.d.ts +83 -0
  85. package/dist/workflow-run-dispatch-store.js +308 -0
  86. package/dist/workflow-run-launch-spec-store.d.ts +13 -0
  87. package/dist/workflow-run-launch-spec-store.js +30 -0
  88. package/dist/workflow-run-store.d.ts +54 -0
  89. package/dist/workflow-run-store.js +85 -0
  90. package/migrations/0037_credential_use_backfill.sql +39 -0
  91. package/migrations/0038_chilly_blacklash.sql +37 -0
  92. package/migrations/0039_quick_carnage.sql +2 -0
  93. package/migrations/0040_reshape_approval_origin.sql +24 -0
  94. package/migrations/0041_make_approval_timeout_at_nullable.sql +1 -0
  95. package/migrations/0042_youthful_mantis.sql +2 -0
  96. package/migrations/0043_signal_correlation_deployment_fk.sql +1 -0
  97. package/migrations/0044_model_offering_quirks.sql +1 -0
  98. package/migrations/0045_create_workflow_run.sql +13 -0
  99. package/migrations/0046_approval_signal_correlation_run_fk.sql +2 -0
  100. package/migrations/0047_create_workflow_definition.sql +30 -0
  101. package/migrations/0048_workflow_definition_origin_agent_id.sql +2 -0
  102. package/migrations/0049_curly_omega_flight.sql +2 -0
  103. package/migrations/0050_late_crystal.sql +10 -0
  104. package/migrations/0051_funny_madelyne_pryor.sql +1 -0
  105. package/migrations/0052_drop_inference_turn_instance_fk.sql +1 -0
  106. package/migrations/0053_session_mail_session_id_index.sql +1 -0
  107. package/migrations/0054_rekey_instance_grants_to_workflow_run.sql +10 -0
  108. package/migrations/0055_backfill_anchor_workflow_runs.sql +69 -0
  109. package/migrations/0056_repoint_deployment_fks_to_anchor_run.sql +32 -0
  110. package/migrations/0057_drop_workflow_deployment_projection.sql +22 -0
  111. package/migrations/0058_repoint_offering_fk_to_definition.sql +41 -0
  112. package/migrations/0059_repoint_transaction_fk_to_run.sql +10 -0
  113. package/migrations/0060_drop_session_mail_instance_fk.sql +6 -0
  114. package/migrations/0061_drop_session_asset_instance_fk.sql +7 -0
  115. package/migrations/0062_drop_agent_asset_table.sql +11 -0
  116. package/migrations/0063_repoint_agent_role_fk_to_definition.sql +39 -0
  117. package/migrations/0064_repoint_agent_session_fk_to_definition.sql +47 -0
  118. package/migrations/0065_add_workflow_definition_model_requirements.sql +37 -0
  119. package/migrations/0066_rekey_agent_definition_principals_to_workflow.sql +27 -0
  120. package/migrations/0067_add_workflow_definition_kind.sql +10 -0
  121. package/migrations/0068_drop_agent_tables_and_origin_agent_id.sql +31 -0
  122. package/migrations/0069_drop_workflow_definition_kind.sql +10 -0
  123. package/migrations/0070_flashy_proteus.sql +13 -0
  124. package/migrations/0072_add_workflow_definition_credential_bindings.sql +1 -0
  125. package/migrations/0073_grant_target_exactly_one_check.sql +13 -0
  126. package/migrations/0074_add_provider_api_base_url.sql +1 -0
  127. package/migrations/0075_workflow_run_launch_spec.sql +17 -0
  128. package/migrations/0076_sidecar_allocation.sql +40 -0
  129. package/migrations/0077_workflow_run_dispatch.sql +29 -0
  130. package/migrations/0078_workflow_run_dispatch_kind.sql +2 -0
  131. package/migrations/0079_rename_workflow_run_deployment_id_to_anchor_run_id.sql +4 -0
  132. package/migrations/0080_rename_correlation_approval_deployment_id_to_anchor_run_id.sql +9 -0
  133. package/migrations/0081_workflow_definition_content_hash_and_approved_wire_hash.sql +4 -0
  134. package/migrations/0082_blue_black_queen.sql +1 -0
  135. package/migrations/0083_replace_launch_spec_snapshot_with_frozen_bundle.sql +3 -0
  136. package/migrations/0084_delete_orphaned_credential_grants.sql +22 -0
  137. package/migrations/0085_add_approval_run_idx.sql +1 -0
  138. package/migrations/0086_cool_human_cannonball.sql +1 -0
  139. package/migrations/0087_drop_sidecar_placement.sql +3 -0
  140. package/migrations/0088_thick_sprite.sql +32 -0
  141. package/migrations/0089_tense_selene.sql +13 -0
  142. package/migrations/0090_tenant_domain_lower_unique.sql +2 -0
  143. package/migrations/0091_workflow_run_dispatch_sender_address.sql +21 -0
  144. package/migrations/0092_sidecar_destroy_failed.sql +4 -0
  145. package/migrations/0093_sidecar_initialization.sql +2 -0
  146. package/migrations/meta/0037_snapshot.json +3237 -0
  147. package/migrations/meta/0038_snapshot.json +3470 -0
  148. package/migrations/meta/0039_snapshot.json +3470 -0
  149. package/migrations/meta/0040_snapshot.json +3489 -0
  150. package/migrations/meta/0041_snapshot.json +3489 -0
  151. package/migrations/meta/0042_snapshot.json +3489 -0
  152. package/migrations/meta/0043_snapshot.json +3498 -0
  153. package/migrations/meta/0044_snapshot.json +3504 -0
  154. package/migrations/meta/0045_snapshot.json +3589 -0
  155. package/migrations/meta/0046_snapshot.json +3607 -0
  156. package/migrations/meta/0047_snapshot.json +3832 -0
  157. package/migrations/meta/0048_snapshot.json +3853 -0
  158. package/migrations/meta/0049_snapshot.json +3854 -0
  159. package/migrations/meta/0050_snapshot.json +3924 -0
  160. package/migrations/meta/0051_snapshot.json +3940 -0
  161. package/migrations/meta/0052_snapshot.json +3931 -0
  162. package/migrations/meta/0053_snapshot.json +3952 -0
  163. package/migrations/meta/0054_snapshot.json +3952 -0
  164. package/migrations/meta/0055_snapshot.json +3952 -0
  165. package/migrations/meta/0056_snapshot.json +3952 -0
  166. package/migrations/meta/0057_snapshot.json +3839 -0
  167. package/migrations/meta/0058_snapshot.json +3839 -0
  168. package/migrations/meta/0059_snapshot.json +3839 -0
  169. package/migrations/meta/0060_snapshot.json +3830 -0
  170. package/migrations/meta/0061_snapshot.json +3821 -0
  171. package/migrations/meta/0062_snapshot.json +3723 -0
  172. package/migrations/meta/0063_snapshot.json +3723 -0
  173. package/migrations/meta/0064_snapshot.json +3723 -0
  174. package/migrations/meta/0065_snapshot.json +3729 -0
  175. package/migrations/meta/0066_snapshot.json +3729 -0
  176. package/migrations/meta/0067_snapshot.json +3736 -0
  177. package/migrations/meta/0068_snapshot.json +3347 -0
  178. package/migrations/meta/0069_snapshot.json +3340 -0
  179. package/migrations/meta/0070_snapshot.json +3444 -0
  180. package/migrations/meta/0072_snapshot.json +3450 -0
  181. package/migrations/meta/0073_snapshot.json +3455 -0
  182. package/migrations/meta/0074_snapshot.json +3461 -0
  183. package/migrations/meta/0075_snapshot.json +3567 -0
  184. package/migrations/meta/0076_snapshot.json +3851 -0
  185. package/migrations/meta/0077_snapshot.json +4067 -0
  186. package/migrations/meta/0078_snapshot.json +4078 -0
  187. package/migrations/meta/0079_snapshot.json +4078 -0
  188. package/migrations/meta/0080_snapshot.json +4078 -0
  189. package/migrations/meta/0081_snapshot.json +4096 -0
  190. package/migrations/meta/0082_snapshot.json +4102 -0
  191. package/migrations/meta/0083_snapshot.json +4096 -0
  192. package/migrations/meta/0084_snapshot.json +4096 -0
  193. package/migrations/meta/0085_snapshot.json +4111 -0
  194. package/migrations/meta/0086_snapshot.json +4117 -0
  195. package/migrations/meta/0087_snapshot.json +4100 -0
  196. package/migrations/meta/0088_snapshot.json +4286 -0
  197. package/migrations/meta/0089_snapshot.json +4376 -0
  198. package/migrations/meta/0090_snapshot.json +4387 -0
  199. package/migrations/meta/0091_snapshot.json +4397 -0
  200. package/migrations/meta/0092_snapshot.json +4397 -0
  201. package/migrations/meta/0093_snapshot.json +4407 -0
  202. package/migrations/meta/_journal.json +392 -0
  203. package/package.json +7 -3
  204. package/dist/schema/agent-assets.js +0 -15
  205. package/dist/schema/agents.js +0 -57
  206. package/dist/schema/instances.js +0 -39
  207. package/dist/schema/workflow-deployments.js +0 -37
@@ -1,11 +1,10 @@
1
- export type WorkflowDeploymentStatus = "deployed" | "error";
2
- export declare const workflowDeployment: import("drizzle-orm/pg-core").PgTableWithColumns<{
3
- name: "workflow_deployment";
1
+ export declare const principalKey: import("drizzle-orm/pg-core").PgTableWithColumns<{
2
+ name: "principal_key";
4
3
  schema: undefined;
5
4
  columns: {
6
5
  id: import("drizzle-orm/pg-core").PgColumn<{
7
6
  name: "id";
8
- tableName: "workflow_deployment";
7
+ tableName: "principal_key";
9
8
  dataType: "string";
10
9
  columnType: "PgText";
11
10
  data: string;
@@ -20,9 +19,9 @@ export declare const workflowDeployment: import("drizzle-orm/pg-core").PgTableWi
20
19
  identity: undefined;
21
20
  generated: undefined;
22
21
  }, {}, {}>;
23
- tenantId: import("drizzle-orm/pg-core").PgColumn<{
24
- name: "tenant_id";
25
- tableName: "workflow_deployment";
22
+ principalId: import("drizzle-orm/pg-core").PgColumn<{
23
+ name: "principal_id";
24
+ tableName: "principal_key";
26
25
  dataType: "string";
27
26
  columnType: "PgText";
28
27
  data: string;
@@ -37,9 +36,9 @@ export declare const workflowDeployment: import("drizzle-orm/pg-core").PgTableWi
37
36
  identity: undefined;
38
37
  generated: undefined;
39
38
  }, {}, {}>;
40
- definitionAssetId: import("drizzle-orm/pg-core").PgColumn<{
41
- name: "definition_asset_id";
42
- tableName: "workflow_deployment";
39
+ publicKey: import("drizzle-orm/pg-core").PgColumn<{
40
+ name: "public_key";
41
+ tableName: "principal_key";
43
42
  dataType: "string";
44
43
  columnType: "PgText";
45
44
  data: string;
@@ -54,9 +53,9 @@ export declare const workflowDeployment: import("drizzle-orm/pg-core").PgTableWi
54
53
  identity: undefined;
55
54
  generated: undefined;
56
55
  }, {}, {}>;
57
- address: import("drizzle-orm/pg-core").PgColumn<{
58
- name: "address";
59
- tableName: "workflow_deployment";
56
+ privateKey: import("drizzle-orm/pg-core").PgColumn<{
57
+ name: "private_key";
58
+ tableName: "principal_key";
60
59
  dataType: "string";
61
60
  columnType: "PgText";
62
61
  data: string;
@@ -71,45 +70,43 @@ export declare const workflowDeployment: import("drizzle-orm/pg-core").PgTableWi
71
70
  identity: undefined;
72
71
  generated: undefined;
73
72
  }, {}, {}>;
74
- publicKey: import("drizzle-orm/pg-core").PgColumn<{
75
- name: "public_key";
76
- tableName: "workflow_deployment";
73
+ status: import("drizzle-orm/pg-core").PgColumn<{
74
+ name: "status";
75
+ tableName: "principal_key";
77
76
  dataType: "string";
78
77
  columnType: "PgText";
79
- data: string;
78
+ data: "active" | "retired";
80
79
  driverParam: string;
81
- notNull: false;
80
+ notNull: true;
82
81
  hasDefault: false;
83
82
  isPrimaryKey: false;
84
83
  isAutoincrement: false;
85
84
  hasRuntimeDefault: false;
86
- enumValues: [string, ...string[]];
85
+ enumValues: ["active", "retired"];
87
86
  baseColumn: never;
88
87
  identity: undefined;
89
88
  generated: undefined;
90
89
  }, {}, {}>;
91
- status: import("drizzle-orm/pg-core").PgColumn<{
92
- name: "status";
93
- tableName: "workflow_deployment";
94
- dataType: "string";
95
- columnType: "PgText";
96
- data: WorkflowDeploymentStatus;
90
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
91
+ name: "created_at";
92
+ tableName: "principal_key";
93
+ dataType: "date";
94
+ columnType: "PgTimestamp";
95
+ data: Date;
97
96
  driverParam: string;
98
97
  notNull: true;
99
98
  hasDefault: true;
100
99
  isPrimaryKey: false;
101
100
  isAutoincrement: false;
102
101
  hasRuntimeDefault: false;
103
- enumValues: [string, ...string[]];
102
+ enumValues: undefined;
104
103
  baseColumn: never;
105
104
  identity: undefined;
106
105
  generated: undefined;
107
- }, {}, {
108
- $type: WorkflowDeploymentStatus;
109
- }>;
110
- createdAt: import("drizzle-orm/pg-core").PgColumn<{
111
- name: "created_at";
112
- tableName: "workflow_deployment";
106
+ }, {}, {}>;
107
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
108
+ name: "updated_at";
109
+ tableName: "principal_key";
113
110
  dataType: "date";
114
111
  columnType: "PgTimestamp";
115
112
  data: Date;
@@ -0,0 +1,28 @@
1
+ import { sql } from "drizzle-orm";
2
+ import { pgTable, text, timestamp, uniqueIndex } from "drizzle-orm/pg-core";
3
+ import { principal } from "./principals.js";
4
+ // A principal's Ed25519 signing key. `public_key` is the hex-encoded 32-byte
5
+ // public point; `private_key` holds the hex-encoded 32-byte seed sealed by the
6
+ // credential cipher (`enc:aead:...` ciphertext), so the seed is never at rest in
7
+ // plaintext under a configured key. The hub custodies the private key: a
8
+ // signature attributes an action to the principal, but is not non-repudiable
9
+ // against the hub operator. See docs/AUTH.md.
10
+ //
11
+ // The `status` axis expresses the one-active-key-per-principal invariant, which
12
+ // the partial unique index below enforces at the database. No path retires a
13
+ // key; every key a principal holds today is "active".
14
+ export const principalKey = pgTable("principal_key", {
15
+ id: text("id").primaryKey(),
16
+ principalId: text("principal_id")
17
+ .notNull()
18
+ .references(() => principal.id, { onDelete: "cascade" }),
19
+ publicKey: text("public_key").notNull().unique(),
20
+ privateKey: text("private_key").notNull(),
21
+ status: text("status", { enum: ["active", "retired"] }).notNull(),
22
+ createdAt: timestamp("created_at").notNull().defaultNow(),
23
+ updatedAt: timestamp("updated_at").notNull().defaultNow(),
24
+ }, (t) => [
25
+ uniqueIndex("principal_key_one_active")
26
+ .on(t.principalId)
27
+ .where(sql `${t.status} = 'active'`),
28
+ ]);
@@ -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"),
@@ -1,7 +1,7 @@
1
1
  import { boolean, pgTable, primaryKey, text, timestamp, } from "drizzle-orm/pg-core";
2
- import { agent } from "./agents.js";
3
2
  import { principal } from "./principals.js";
4
3
  import { tenant } from "./tenants.js";
4
+ import { workflowDefinition } from "./workflow-definitions.js";
5
5
  export const role = pgTable("role", {
6
6
  id: text("id").primaryKey(),
7
7
  tenantId: text("tenant_id")
@@ -14,9 +14,13 @@ export const role = pgTable("role", {
14
14
  updatedAt: timestamp("updated_at").notNull().defaultNow(),
15
15
  });
16
16
  export const agentRole = pgTable("agent_role", {
17
+ // Retains the agent_id column name, but its values are workflow_definition
18
+ // ids: every agent was folded to exactly one definition, and role
19
+ // assignments follow the definition so they survived the agent table's
20
+ // retirement.
17
21
  agentId: text("agent_id")
18
22
  .notNull()
19
- .references(() => agent.id, { onDelete: "cascade" }),
23
+ .references(() => workflowDefinition.id, { onDelete: "cascade" }),
20
24
  roleId: text("role_id")
21
25
  .notNull()
22
26
  .references(() => role.id, { onDelete: "cascade" }),
@@ -1,9 +1,8 @@
1
- export type SessionAssetSource = "direct" | "resolved";
2
1
  export declare const sessionAsset: import("drizzle-orm/pg-core").PgTableWithColumns<{
3
2
  name: "session_asset";
4
3
  schema: undefined;
5
4
  columns: {
6
- instanceId: import("drizzle-orm/pg-core").PgColumn<{
5
+ runId: import("drizzle-orm/pg-core").PgColumn<{
7
6
  name: "instance_id";
8
7
  tableName: "session_asset";
9
8
  dataType: "string";
@@ -20,23 +19,6 @@ export declare const sessionAsset: import("drizzle-orm/pg-core").PgTableWithColu
20
19
  identity: undefined;
21
20
  generated: undefined;
22
21
  }, {}, {}>;
23
- agentAssetId: import("drizzle-orm/pg-core").PgColumn<{
24
- name: "agent_asset_id";
25
- tableName: "session_asset";
26
- dataType: "string";
27
- columnType: "PgText";
28
- data: string;
29
- driverParam: string;
30
- notNull: false;
31
- hasDefault: false;
32
- isPrimaryKey: false;
33
- isAutoincrement: false;
34
- hasRuntimeDefault: false;
35
- enumValues: [string, ...string[]];
36
- baseColumn: never;
37
- identity: undefined;
38
- generated: undefined;
39
- }, {}, {}>;
40
22
  mountPath: import("drizzle-orm/pg-core").PgColumn<{
41
23
  name: "mount_path";
42
24
  tableName: "session_asset";
@@ -88,25 +70,6 @@ export declare const sessionAsset: import("drizzle-orm/pg-core").PgTableWithColu
88
70
  identity: undefined;
89
71
  generated: undefined;
90
72
  }, {}, {}>;
91
- source: import("drizzle-orm/pg-core").PgColumn<{
92
- name: "source";
93
- tableName: "session_asset";
94
- dataType: "string";
95
- columnType: "PgText";
96
- data: SessionAssetSource;
97
- driverParam: string;
98
- notNull: true;
99
- hasDefault: false;
100
- isPrimaryKey: false;
101
- isAutoincrement: false;
102
- hasRuntimeDefault: false;
103
- enumValues: [string, ...string[]];
104
- baseColumn: never;
105
- identity: undefined;
106
- generated: undefined;
107
- }, {}, {
108
- $type: SessionAssetSource;
109
- }>;
110
73
  materializedAt: import("drizzle-orm/pg-core").PgColumn<{
111
74
  name: "materialized_at";
112
75
  tableName: "session_asset";
@@ -1,28 +1,45 @@
1
1
  import { index, pgTable, primaryKey, text, timestamp, } from "drizzle-orm/pg-core";
2
- import { agentAsset } from "./agent-assets.js";
3
- import { agentInstance } from "./instances.js";
2
+ // session_asset rows record per-(instance, materialization) pack
3
+ // acknowledgments. A row exists iff the sidecar acked the pack that
4
+ // materialized that asset for that instance. The launchSession flow
5
+ // inserts each row before the corresponding pack send and rolls it
6
+ // back if that single send fails, so each row reflects an ack the
7
+ // hub actually observed for that attachment.
8
+ //
9
+ // Assets reach an instance through the tool-package resolver: it picks
10
+ // package-registry assets out of the tenant-visible set, and the launch
11
+ // fan-out materializes each into the workspace. The mount path and
12
+ // source commit are recorded so forensic queries can trace every
13
+ // materialization.
14
+ //
15
+ // Caveat on multi-attachment partial-success: when a session attaches
16
+ // N assets and the fan-out succeeds for attachments 1..k-1 and fails
17
+ // on attachment k, only attachment k's row is rolled back. Rows
18
+ // 1..k-1 stay. The session as a whole never reached the running
19
+ // state -- attemptCleanup runs sendAgentUndeploy -- but the per-
20
+ // attachment ack invariant holds for the rows that remain.
21
+ // Forensics queries should treat row count as "packs the sidecar
22
+ // acked during this instance's launch," not "sessions that ran with
23
+ // assets." Pairing with agent_instance.status (or its successor
24
+ // session-lifecycle signal) is necessary to distinguish a row left
25
+ // behind by a partially-successful failed launch from one belonging
26
+ // to a fully-running session.
4
27
  export const sessionAsset = pgTable("session_asset", {
5
- instanceId: text("instance_id")
6
- .notNull()
7
- .references(() => agentInstance.id, { onDelete: "cascade" }),
8
- // Nullable: resolver-derived materializations have no per-agent
9
- // attachment row. Direct attachments carry the agent_asset id.
10
- agentAssetId: text("agent_asset_id").references(() => agentAsset.id, {
11
- onDelete: "cascade",
12
- }),
28
+ // The endpoint this materialization is for: a legacy agent_instance id or a
29
+ // folded workflow_run id, from one shared id space. A polymorphic reference
30
+ // carrying no foreign key (mirroring inference_turn.runId); the launch
31
+ // layer owns the invariant. NOT NULL -- a materialization always names its
32
+ // endpoint -- and part of the (instance_id, mount_path) key. A folded run
33
+ // writes its run id here, which the dropped agent_instance FK would reject.
34
+ runId: text("instance_id").notNull(),
13
35
  mountPath: text("mount_path").notNull(),
14
36
  assetPackSha: text("asset_pack_sha").notNull(),
15
37
  sourceCommitSha: text("source_commit_sha").notNull(),
16
- source: text("source").$type().notNull(),
17
38
  materializedAt: timestamp("materialized_at").notNull().defaultNow(),
18
39
  }, (t) => [
19
- // (instanceId, mountPath) is the natural key: every materialized
20
- // asset lands at a distinct mount path inside one instance, so
21
- // this pair uniquely identifies a row regardless of whether the
22
- // pack came from a direct attachment or a resolver-derived
23
- // package-registry pick. Pre-split the PK was (instanceId,
24
- // agentAssetId), but that column is now nullable for the
25
- // resolved-source rows and Postgres rejects nullable PK columns.
26
- primaryKey({ columns: [t.instanceId, t.mountPath] }),
40
+ // (runId, mountPath) is the natural key: every materialized
41
+ // asset lands at a distinct mount path inside one run, so this
42
+ // pair uniquely identifies a row.
43
+ primaryKey({ columns: [t.runId, t.mountPath] }),
27
44
  index("session_asset_pack_sha_idx").on(t.assetPackSha),
28
45
  ]);
@@ -1,15 +1,20 @@
1
1
  import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
- import { agent } from "./agents.js";
3
2
  import { principal } from "./principals.js";
4
3
  import { tenant } from "./tenants.js";
4
+ import { workflowDefinition } from "./workflow-definitions.js";
5
5
  export const agentSession = pgTable("agent_session", {
6
6
  id: text("id").primaryKey(),
7
7
  tenantId: text("tenant_id")
8
8
  .notNull()
9
9
  .references(() => tenant.id, { onDelete: "cascade" }),
10
+ // Retains the agent_id column name, but its values are workflow_definition
11
+ // ids: a launched session is keyed to the folded definition it runs, so it
12
+ // survives the agent table's retirement. ON DELETE restrict -- session
13
+ // history is an audit record, so a definition with live sessions cannot be
14
+ // dropped out from under them.
10
15
  agentId: text("agent_id")
11
16
  .notNull()
12
- .references(() => agent.id, { onDelete: "cascade" }),
17
+ .references(() => workflowDefinition.id, { onDelete: "restrict" }),
13
18
  principalId: text("principal_id")
14
19
  .notNull()
15
20
  .references(() => principal.id),