@intx/db 0.1.2 → 0.2.2

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 (121) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +21 -2
  3. package/dist/asset-resolution.d.ts +52 -0
  4. package/dist/asset-resolution.js +66 -0
  5. package/dist/catalog-resolution.d.ts +76 -0
  6. package/dist/catalog-resolution.js +151 -0
  7. package/dist/client.d.ts +9 -0
  8. package/dist/client.js +18 -0
  9. package/dist/config.d.ts +11 -0
  10. package/dist/config.js +16 -0
  11. package/dist/connection.d.ts +3 -0
  12. package/dist/connection.js +23 -0
  13. package/dist/credential-resolution.d.ts +110 -0
  14. package/dist/credential-resolution.js +116 -0
  15. package/dist/grant-store.d.ts +3 -0
  16. package/dist/grant-store.js +37 -0
  17. package/dist/index.d.ts +13 -0
  18. package/dist/index.js +12 -0
  19. package/dist/migrate.d.ts +36 -0
  20. package/dist/migrate.js +135 -0
  21. package/dist/model-source-resolution.d.ts +69 -0
  22. package/dist/model-source-resolution.js +165 -0
  23. package/dist/parse-row.d.ts +193 -0
  24. package/dist/parse-row.js +141 -0
  25. package/dist/pg-error.d.ts +3 -0
  26. package/dist/pg-error.js +19 -0
  27. package/dist/pricing.d.ts +15 -0
  28. package/dist/pricing.js +24 -0
  29. package/dist/schema/agent-assets.d.ts +109 -0
  30. package/dist/schema/agent-assets.js +15 -0
  31. package/dist/schema/agents.d.ts +405 -0
  32. package/dist/schema/agents.js +57 -0
  33. package/dist/schema/assets.d.ts +143 -0
  34. package/{src/schema/assets.ts → dist/schema/assets.js} +7 -16
  35. package/dist/schema/auth.d.ts +606 -0
  36. package/dist/schema/auth.js +47 -0
  37. package/dist/schema/catalog.d.ts +794 -0
  38. package/dist/schema/catalog.js +102 -0
  39. package/dist/schema/column-types.d.ts +26 -0
  40. package/dist/schema/column-types.js +15 -0
  41. package/dist/schema/credentials.d.ts +305 -0
  42. package/{src/schema/credentials.ts → dist/schema/credentials.js} +16 -22
  43. package/dist/schema/git-tokens.d.ts +256 -0
  44. package/{src/schema/git-tokens.ts → dist/schema/git-tokens.js} +15 -38
  45. package/dist/schema/grants.d.ts +211 -0
  46. package/dist/schema/grants.js +24 -0
  47. package/dist/schema/index.d.ts +21 -0
  48. package/dist/schema/index.js +21 -0
  49. package/dist/schema/instances.d.ts +262 -0
  50. package/dist/schema/instances.js +39 -0
  51. package/dist/schema/messages.d.ts +414 -0
  52. package/dist/schema/messages.js +71 -0
  53. package/dist/schema/oauth-clients.d.ts +246 -0
  54. package/{src/schema/oauth-clients.ts → dist/schema/oauth-clients.js} +8 -14
  55. package/dist/schema/offerings.d.ts +160 -0
  56. package/dist/schema/offerings.js +18 -0
  57. package/dist/schema/principals.d.ts +128 -0
  58. package/{src/schema/principals.ts → dist/schema/principals.js} +7 -14
  59. package/dist/schema/providers.d.ts +220 -0
  60. package/{src/schema/providers.ts → dist/schema/providers.js} +5 -11
  61. package/dist/schema/roles.d.ts +242 -0
  62. package/dist/schema/roles.js +33 -0
  63. package/dist/schema/session-assets.d.ts +129 -0
  64. package/dist/schema/session-assets.js +28 -0
  65. package/dist/schema/sessions.d.ts +143 -0
  66. package/dist/schema/sessions.js +24 -0
  67. package/dist/schema/sidecar.d.ts +128 -0
  68. package/dist/schema/sidecar.js +18 -0
  69. package/dist/schema/tenants.d.ts +235 -0
  70. package/{src/schema/tenants.ts → dist/schema/tenants.js} +10 -27
  71. package/dist/schema/wallets.d.ts +354 -0
  72. package/dist/schema/wallets.js +41 -0
  73. package/dist/schema/workflow-deployments.d.ts +129 -0
  74. package/dist/schema/workflow-deployments.js +37 -0
  75. package/dist/tenant-hierarchy.d.ts +22 -0
  76. package/dist/tenant-hierarchy.js +55 -0
  77. package/migrations/0029_loose_warlock.sql +1 -0
  78. package/migrations/0030_session_asset_audit_split.sql +5 -0
  79. package/migrations/0031_gigantic_nicolaos.sql +68 -0
  80. package/migrations/0032_lethal_misty_knight.sql +1 -0
  81. package/migrations/0033_old_payback.sql +1 -0
  82. package/migrations/0034_sleepy_songbird.sql +11 -0
  83. package/migrations/0035_violet_giant_man.sql +3 -0
  84. package/migrations/0036_sharp_the_executioner.sql +2 -0
  85. package/migrations/meta/0029_snapshot.json +2664 -0
  86. package/migrations/meta/0030_snapshot.json +2670 -0
  87. package/migrations/meta/0031_snapshot.json +3100 -0
  88. package/migrations/meta/0032_snapshot.json +3106 -0
  89. package/migrations/meta/0033_snapshot.json +3112 -0
  90. package/migrations/meta/0034_snapshot.json +3198 -0
  91. package/migrations/meta/0035_snapshot.json +3225 -0
  92. package/migrations/meta/0036_snapshot.json +3237 -0
  93. package/migrations/meta/_journal.json +56 -0
  94. package/package.json +22 -11
  95. package/drizzle.config.ts +0 -23
  96. package/src/client.ts +0 -24
  97. package/src/config.ts +0 -19
  98. package/src/connection.ts +0 -27
  99. package/src/credential-resolution.ts +0 -378
  100. package/src/grant-store.ts +0 -51
  101. package/src/index.ts +0 -32
  102. package/src/migrate.test.ts +0 -35
  103. package/src/migrate.ts +0 -168
  104. package/src/parse-row.test.ts +0 -113
  105. package/src/parse-row.ts +0 -185
  106. package/src/schema/agent-assets.ts +0 -21
  107. package/src/schema/agents.ts +0 -49
  108. package/src/schema/auth.ts +0 -51
  109. package/src/schema/grants.ts +0 -26
  110. package/src/schema/index.ts +0 -19
  111. package/src/schema/instances.ts +0 -36
  112. package/src/schema/messages.ts +0 -108
  113. package/src/schema/offerings.ts +0 -20
  114. package/src/schema/roles.ts +0 -51
  115. package/src/schema/session-assets.ts +0 -49
  116. package/src/schema/sessions.ts +0 -26
  117. package/src/schema/sidecar.ts +0 -14
  118. package/src/schema/wallets.ts +0 -44
  119. package/src/tenant-hierarchy.ts +0 -34
  120. package/tsconfig.json +0 -4
  121. package/tsconfig.tsbuildinfo +0 -1
@@ -1,36 +0,0 @@
1
- import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
-
3
- import { agent, agentVersion } from "./agents";
4
- import { agentSession } from "./sessions";
5
- import { principal } from "./principals";
6
- import { sidecar } from "./sidecar";
7
- import { tenant } from "./tenants";
8
-
9
- export const agentInstance = pgTable("agent_instance", {
10
- id: text("id").primaryKey(),
11
- agentId: text("agent_id")
12
- .notNull()
13
- .references(() => agent.id, { onDelete: "cascade" }),
14
- tenantId: text("tenant_id")
15
- .notNull()
16
- .references(() => tenant.id, { onDelete: "cascade" }),
17
- principalId: text("principal_id")
18
- .notNull()
19
- .references(() => principal.id),
20
- address: text("address").notNull().unique(),
21
- versionId: text("version_id").references(() => agentVersion.id),
22
- sessionId: text("session_id").references(() => agentSession.id),
23
- status: text("status", {
24
- enum: ["deployed", "running", "updating", "error", "stopped"],
25
- })
26
- .notNull()
27
- .default("deployed"),
28
- sidecarId: text("sidecar_id").references(() => sidecar.id, {
29
- onDelete: "set null",
30
- }),
31
- publicKey: text("public_key"),
32
- kernelId: text("kernel_id"),
33
- createdAt: timestamp("created_at").notNull().defaultNow(),
34
- updatedAt: timestamp("updated_at").notNull().defaultNow(),
35
- endedAt: timestamp("ended_at"),
36
- });
@@ -1,108 +0,0 @@
1
- import {
2
- customType,
3
- index,
4
- integer,
5
- jsonb,
6
- pgTable,
7
- text,
8
- timestamp,
9
- } from "drizzle-orm/pg-core";
10
-
11
- import { agentInstance } from "./instances";
12
- import { agentSession } from "./sessions";
13
- import { tenant } from "./tenants";
14
-
15
- const bytea = customType<{ data: Uint8Array; driverData: Buffer }>({
16
- dataType() {
17
- return "bytea";
18
- },
19
- toDriver(value) {
20
- return Buffer.from(value);
21
- },
22
- fromDriver(value) {
23
- return new Uint8Array(value);
24
- },
25
- });
26
-
27
- export const inferenceTurn = pgTable(
28
- "inference_turn",
29
- {
30
- id: text("id").primaryKey(),
31
- sessionId: text("session_id")
32
- .notNull()
33
- .references(() => agentSession.id, { onDelete: "cascade" }),
34
- instanceId: text("instance_id")
35
- .notNull()
36
- .references(() => agentInstance.id, { onDelete: "cascade" }),
37
- tenantId: text("tenant_id")
38
- .notNull()
39
- .references(() => tenant.id, { onDelete: "cascade" }),
40
- model: text("model").notNull(),
41
- status: text("status", { enum: ["running", "completed", "failed"] })
42
- .notNull()
43
- .default("running"),
44
- startedAt: timestamp("started_at").notNull(),
45
- endedAt: timestamp("ended_at"),
46
- },
47
- (t) => [
48
- index("inference_turn_instance_id_started_at_idx").on(
49
- t.instanceId,
50
- t.startedAt,
51
- ),
52
- ],
53
- );
54
-
55
- export const turnPart = pgTable("turn_part", {
56
- id: text("id").primaryKey(),
57
- turnId: text("turn_id")
58
- .notNull()
59
- .references(() => inferenceTurn.id, { onDelete: "cascade" }),
60
- sessionId: text("session_id")
61
- .notNull()
62
- .references(() => agentSession.id, { onDelete: "cascade" }),
63
- type: text("type", {
64
- enum: [
65
- "text",
66
- "reasoning",
67
- "tool",
68
- "file",
69
- "error",
70
- "refusal",
71
- "step-start",
72
- "step-finish",
73
- "snapshot",
74
- "patch",
75
- ],
76
- }).notNull(),
77
- content: text("content"),
78
- metadata: jsonb("metadata"),
79
- ordinal: integer("ordinal").notNull(),
80
- });
81
-
82
- export const sessionMail = pgTable(
83
- "session_mail",
84
- {
85
- id: text("id").primaryKey(),
86
- sessionId: text("session_id")
87
- .notNull()
88
- .references(() => agentSession.id, { onDelete: "cascade" }),
89
- instanceId: text("instance_id").references(() => agentInstance.id, {
90
- onDelete: "set null",
91
- }),
92
- tenantId: text("tenant_id")
93
- .notNull()
94
- .references(() => tenant.id, { onDelete: "cascade" }),
95
- direction: text("direction", { enum: ["inbound", "outbound"] }).notNull(),
96
- status: text("status", { enum: ["pending", "delivered"] })
97
- .notNull()
98
- .default("pending"),
99
- raw: bytea("raw").notNull(),
100
- createdAt: timestamp("created_at").notNull().defaultNow(),
101
- },
102
- (t) => [
103
- index("session_mail_instance_id_created_at_idx").on(
104
- t.instanceId,
105
- t.createdAt,
106
- ),
107
- ],
108
- );
@@ -1,20 +0,0 @@
1
- import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
-
3
- import { agent } from "./agents";
4
- import { tenant } from "./tenants";
5
-
6
- export const offering = pgTable("offering", {
7
- id: text("id").primaryKey(),
8
- agentId: text("agent_id")
9
- .notNull()
10
- .references(() => agent.id, { onDelete: "cascade" }),
11
- tenantId: text("tenant_id")
12
- .notNull()
13
- .references(() => tenant.id, { onDelete: "cascade" }),
14
- name: text("name").notNull(),
15
- description: text("description"),
16
- pricing: jsonb("pricing"),
17
- schema: jsonb("schema"),
18
- createdAt: timestamp("created_at").notNull().defaultNow(),
19
- updatedAt: timestamp("updated_at").notNull().defaultNow(),
20
- });
@@ -1,51 +0,0 @@
1
- import {
2
- boolean,
3
- pgTable,
4
- primaryKey,
5
- text,
6
- timestamp,
7
- } from "drizzle-orm/pg-core";
8
-
9
- import { agent } from "./agents";
10
- import { principal } from "./principals";
11
- import { tenant } from "./tenants";
12
-
13
- export const role = pgTable("role", {
14
- id: text("id").primaryKey(),
15
- tenantId: text("tenant_id")
16
- .notNull()
17
- .references(() => tenant.id, { onDelete: "cascade" }),
18
- name: text("name").notNull(),
19
- description: text("description"),
20
- isSystem: boolean("is_system").notNull().default(false),
21
- createdAt: timestamp("created_at").notNull().defaultNow(),
22
- updatedAt: timestamp("updated_at").notNull().defaultNow(),
23
- });
24
-
25
- export const agentRole = pgTable(
26
- "agent_role",
27
- {
28
- agentId: text("agent_id")
29
- .notNull()
30
- .references(() => agent.id, { onDelete: "cascade" }),
31
- roleId: text("role_id")
32
- .notNull()
33
- .references(() => role.id, { onDelete: "cascade" }),
34
- createdAt: timestamp("created_at").notNull().defaultNow(),
35
- },
36
- (t) => [primaryKey({ columns: [t.agentId, t.roleId] })],
37
- );
38
-
39
- export const principalRole = pgTable(
40
- "principal_role",
41
- {
42
- principalId: text("principal_id")
43
- .notNull()
44
- .references(() => principal.id, { onDelete: "cascade" }),
45
- roleId: text("role_id")
46
- .notNull()
47
- .references(() => role.id, { onDelete: "cascade" }),
48
- createdAt: timestamp("created_at").notNull().defaultNow(),
49
- },
50
- (t) => [primaryKey({ columns: [t.principalId, t.roleId] })],
51
- );
@@ -1,49 +0,0 @@
1
- import {
2
- index,
3
- pgTable,
4
- primaryKey,
5
- text,
6
- timestamp,
7
- } from "drizzle-orm/pg-core";
8
-
9
- import { agentAsset } from "./agent-assets";
10
- import { agentInstance } from "./instances";
11
-
12
- // session_asset rows record per-(instance, agent_asset) pack
13
- // acknowledgments. A row exists iff the sidecar acked the pack that
14
- // materialized that asset for that instance. The launchSession flow
15
- // inserts each row before the corresponding pack send and rolls it
16
- // back if that single send fails, so each row reflects an ack the
17
- // hub actually observed for that attachment.
18
- //
19
- // Caveat on multi-attachment partial-success: when a session attaches
20
- // N assets and the fan-out succeeds for attachments 1..k-1 and fails
21
- // on attachment k, only attachment k's row is rolled back. Rows
22
- // 1..k-1 stay. The session as a whole never reached the running
23
- // state — attemptCleanup runs sendAgentUndeploy — but the per-
24
- // attachment ack invariant holds for the rows that remain.
25
- // Forensics queries should treat row count as "packs the sidecar
26
- // acked during this instance's launch," not "sessions that ran with
27
- // assets." Pairing with agent_instance.status (or its successor
28
- // session-lifecycle signal) is necessary to distinguish a row left
29
- // behind by a partially-successful failed launch from one belonging
30
- // to a fully-running session.
31
- export const sessionAsset = pgTable(
32
- "session_asset",
33
- {
34
- instanceId: text("instance_id")
35
- .notNull()
36
- .references(() => agentInstance.id, { onDelete: "cascade" }),
37
- agentAssetId: text("agent_asset_id")
38
- .notNull()
39
- .references(() => agentAsset.id, { onDelete: "cascade" }),
40
- mountPath: text("mount_path").notNull(),
41
- assetPackSha: text("asset_pack_sha").notNull(),
42
- sourceCommitSha: text("source_commit_sha").notNull(),
43
- materializedAt: timestamp("materialized_at").notNull().defaultNow(),
44
- },
45
- (t) => [
46
- primaryKey({ columns: [t.instanceId, t.agentAssetId] }),
47
- index("session_asset_pack_sha_idx").on(t.assetPackSha),
48
- ],
49
- );
@@ -1,26 +0,0 @@
1
- import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
-
3
- import { agent } from "./agents";
4
- import { principal } from "./principals";
5
- import { tenant } from "./tenants";
6
-
7
- export const agentSession = pgTable("agent_session", {
8
- id: text("id").primaryKey(),
9
- tenantId: text("tenant_id")
10
- .notNull()
11
- .references(() => tenant.id, { onDelete: "cascade" }),
12
- agentId: text("agent_id")
13
- .notNull()
14
- .references(() => agent.id, { onDelete: "cascade" }),
15
- principalId: text("principal_id")
16
- .notNull()
17
- .references(() => principal.id),
18
- status: text("status", {
19
- enum: ["active", "ending", "ended"],
20
- })
21
- .notNull()
22
- .default("active"),
23
- createdAt: timestamp("created_at").notNull().defaultNow(),
24
- updatedAt: timestamp("updated_at").notNull().defaultNow(),
25
- endedAt: timestamp("ended_at"),
26
- });
@@ -1,14 +0,0 @@
1
- import { pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
-
3
- export const sidecar = pgTable("sidecar", {
4
- id: text("id").primaryKey(),
5
- url: text("url").notNull(),
6
- status: text("status", {
7
- enum: ["online", "offline", "error"],
8
- })
9
- .notNull()
10
- .default("online"),
11
- lastHeartbeat: timestamp("last_heartbeat"),
12
- createdAt: timestamp("created_at").notNull().defaultNow(),
13
- updatedAt: timestamp("updated_at").notNull().defaultNow(),
14
- });
@@ -1,44 +0,0 @@
1
- import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
2
-
3
- import { agent } from "./agents";
4
- import { tenant } from "./tenants";
5
-
6
- export const wallet = pgTable("wallet", {
7
- id: text("id").primaryKey(),
8
- tenantId: text("tenant_id")
9
- .notNull()
10
- .references(() => tenant.id, { onDelete: "cascade" }),
11
- name: text("name").notNull(),
12
- backendType: text("backend_type", {
13
- enum: ["crypto", "fiat", "credits"],
14
- }).notNull(),
15
- currency: text("currency").notNull(),
16
- balance: text("balance").notNull().default("0"),
17
- config: jsonb("config"),
18
- createdAt: timestamp("created_at").notNull().defaultNow(),
19
- updatedAt: timestamp("updated_at").notNull().defaultNow(),
20
- });
21
-
22
- export const transaction = pgTable("transaction", {
23
- id: text("id").primaryKey(),
24
- walletId: text("wallet_id")
25
- .notNull()
26
- .references(() => wallet.id, { onDelete: "cascade" }),
27
- agentId: text("agent_id").references(() => agent.id, {
28
- onDelete: "set null",
29
- }),
30
- direction: text("direction", {
31
- enum: ["inbound", "outbound"],
32
- }).notNull(),
33
- amount: text("amount").notNull(),
34
- currency: text("currency").notNull(),
35
- recipientId: text("recipient_id"),
36
- senderId: text("sender_id"),
37
- requestId: text("request_id"),
38
- status: text("status", {
39
- enum: ["pending", "completed", "failed"],
40
- })
41
- .notNull()
42
- .default("pending"),
43
- createdAt: timestamp("created_at").notNull().defaultNow(),
44
- });
@@ -1,34 +0,0 @@
1
- import { eq } from "drizzle-orm";
2
-
3
- import type { DB } from "./client";
4
- import { tenant } from "./schema/tenants";
5
-
6
- const MAX_DEPTH = 20;
7
-
8
- /**
9
- * Walks the tenant parentId chain from the given tenant up to the root.
10
- * Returns an ordered array of tenant IDs: [tenantId, parentId, grandparentId, ...rootId].
11
- *
12
- * Protects against cycles with a depth limit.
13
- */
14
- export async function getAncestorChain(
15
- db: DB["db"],
16
- tenantId: string,
17
- ): Promise<string[]> {
18
- const chain: string[] = [tenantId];
19
- let currentId = tenantId;
20
-
21
- for (let depth = 0; depth < MAX_DEPTH; depth++) {
22
- const row = await db.query.tenant.findFirst({
23
- where: eq(tenant.id, currentId),
24
- columns: { parentId: true },
25
- });
26
-
27
- if (!row?.parentId) break;
28
-
29
- chain.push(row.parentId);
30
- currentId = row.parentId;
31
- }
32
-
33
- return chain;
34
- }
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "include": ["src/**/*.ts"]
4
- }