@intx/db 0.1.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.
- package/LICENSE +176 -0
- package/README.md +23 -4
- package/dist/approval-store.d.ts +52 -0
- package/dist/approval-store.js +79 -0
- package/dist/asset-resolution.d.ts +52 -0
- package/dist/asset-resolution.js +66 -0
- package/dist/catalog-resolution.d.ts +76 -0
- package/dist/catalog-resolution.js +151 -0
- package/dist/client.d.ts +19 -0
- package/dist/client.js +18 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +16 -0
- package/dist/connection.d.ts +3 -0
- package/dist/connection.js +26 -0
- package/dist/credential-resolution.d.ts +222 -0
- package/dist/credential-resolution.js +255 -0
- package/dist/grant-store.d.ts +3 -0
- package/dist/grant-store.js +59 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +20 -0
- package/dist/migrate.d.ts +36 -0
- package/dist/migrate.js +135 -0
- package/dist/model-source-resolution.d.ts +115 -0
- package/dist/model-source-resolution.js +291 -0
- package/dist/parse-row.d.ts +373 -0
- package/dist/parse-row.js +232 -0
- package/dist/pg-error.d.ts +3 -0
- package/dist/pg-error.js +19 -0
- package/dist/pricing.d.ts +15 -0
- package/dist/pricing.js +24 -0
- package/dist/rekey-credential-secrets.d.ts +13 -0
- package/dist/rekey-credential-secrets.js +61 -0
- package/dist/schema/approvals.d.ts +245 -0
- package/dist/schema/approvals.js +52 -0
- package/dist/schema/assets.d.ts +143 -0
- package/{src/schema/assets.ts → dist/schema/assets.js} +7 -16
- package/dist/schema/auth.d.ts +606 -0
- package/dist/schema/auth.js +47 -0
- package/dist/schema/catalog.d.ts +811 -0
- package/dist/schema/catalog.js +108 -0
- package/dist/schema/column-types.d.ts +26 -0
- package/dist/schema/column-types.js +15 -0
- package/dist/schema/credentials.d.ts +305 -0
- package/{src/schema/credentials.ts → dist/schema/credentials.js} +16 -22
- package/dist/schema/git-tokens.d.ts +256 -0
- package/{src/schema/git-tokens.ts → dist/schema/git-tokens.js} +16 -39
- package/dist/schema/grants.d.ts +211 -0
- package/dist/schema/grants.js +30 -0
- package/dist/schema/index.d.ts +25 -0
- package/dist/schema/index.js +25 -0
- package/dist/schema/messages.d.ts +414 -0
- package/dist/schema/messages.js +82 -0
- package/dist/schema/oauth-clients.d.ts +246 -0
- package/{src/schema/oauth-clients.ts → dist/schema/oauth-clients.js} +8 -14
- package/dist/schema/offerings.d.ts +160 -0
- package/dist/schema/offerings.js +24 -0
- package/dist/schema/principals.d.ts +128 -0
- package/dist/schema/principals.js +23 -0
- package/dist/schema/providers.d.ts +237 -0
- package/dist/schema/providers.js +22 -0
- package/dist/schema/roles.d.ts +242 -0
- package/dist/schema/roles.js +37 -0
- package/dist/schema/session-assets.d.ts +92 -0
- package/dist/schema/session-assets.js +45 -0
- package/dist/schema/sessions.d.ts +143 -0
- package/dist/schema/sessions.js +29 -0
- package/dist/schema/sidecar-allocation.d.ts +406 -0
- package/dist/schema/sidecar-allocation.js +57 -0
- package/dist/schema/sidecar.d.ts +145 -0
- package/dist/schema/sidecar.js +28 -0
- package/dist/schema/signal-correlations.d.ts +177 -0
- package/dist/schema/signal-correlations.js +31 -0
- package/dist/schema/tenants.d.ts +235 -0
- package/{src/schema/tenants.ts → dist/schema/tenants.js} +10 -27
- package/dist/schema/wallets.d.ts +354 -0
- package/dist/schema/wallets.js +43 -0
- package/dist/schema/workflow-definitions.d.ts +371 -0
- package/dist/schema/workflow-definitions.js +97 -0
- package/dist/schema/workflow-run-dispatch.d.ts +328 -0
- package/dist/schema/workflow-run-dispatch.js +56 -0
- package/dist/schema/workflow-run-execution.d.ts +126 -0
- package/dist/schema/workflow-run-execution.js +48 -0
- package/dist/schema/workflow-run-launch-spec.d.ts +200 -0
- package/dist/schema/workflow-run-launch-spec.js +26 -0
- package/dist/schema/workflow-run.d.ts +230 -0
- package/dist/schema/workflow-run.js +102 -0
- package/dist/sidecar-allocation-store.d.ts +171 -0
- package/dist/sidecar-allocation-store.js +512 -0
- package/dist/signal-correlation-store.d.ts +36 -0
- package/dist/signal-correlation-store.js +63 -0
- package/dist/tenant-hierarchy.d.ts +23 -0
- package/dist/tenant-hierarchy.js +60 -0
- package/dist/workflow-definition-store.d.ts +55 -0
- package/dist/workflow-definition-store.js +93 -0
- package/dist/workflow-run-dispatch-store.d.ts +80 -0
- package/dist/workflow-run-dispatch-store.js +298 -0
- package/dist/workflow-run-launch-spec-store.d.ts +13 -0
- package/dist/workflow-run-launch-spec-store.js +30 -0
- package/dist/workflow-run-store.d.ts +54 -0
- package/dist/workflow-run-store.js +85 -0
- package/migrations/0029_loose_warlock.sql +1 -0
- package/migrations/0030_session_asset_audit_split.sql +5 -0
- package/migrations/0031_gigantic_nicolaos.sql +68 -0
- package/migrations/0032_lethal_misty_knight.sql +1 -0
- package/migrations/0033_old_payback.sql +1 -0
- package/migrations/0034_sleepy_songbird.sql +11 -0
- package/migrations/0035_violet_giant_man.sql +3 -0
- package/migrations/0036_sharp_the_executioner.sql +2 -0
- package/migrations/0037_credential_use_backfill.sql +39 -0
- package/migrations/0038_chilly_blacklash.sql +37 -0
- package/migrations/0039_quick_carnage.sql +2 -0
- package/migrations/0040_reshape_approval_origin.sql +24 -0
- package/migrations/0041_make_approval_timeout_at_nullable.sql +1 -0
- package/migrations/0042_youthful_mantis.sql +2 -0
- package/migrations/0043_signal_correlation_deployment_fk.sql +1 -0
- package/migrations/0044_model_offering_quirks.sql +1 -0
- package/migrations/0045_create_workflow_run.sql +13 -0
- package/migrations/0046_approval_signal_correlation_run_fk.sql +2 -0
- package/migrations/0047_create_workflow_definition.sql +30 -0
- package/migrations/0048_workflow_definition_origin_agent_id.sql +2 -0
- package/migrations/0049_curly_omega_flight.sql +2 -0
- package/migrations/0050_late_crystal.sql +10 -0
- package/migrations/0051_funny_madelyne_pryor.sql +1 -0
- package/migrations/0052_drop_inference_turn_instance_fk.sql +1 -0
- package/migrations/0053_session_mail_session_id_index.sql +1 -0
- package/migrations/0054_rekey_instance_grants_to_workflow_run.sql +10 -0
- package/migrations/0055_backfill_anchor_workflow_runs.sql +69 -0
- package/migrations/0056_repoint_deployment_fks_to_anchor_run.sql +32 -0
- package/migrations/0057_drop_workflow_deployment_projection.sql +22 -0
- package/migrations/0058_repoint_offering_fk_to_definition.sql +41 -0
- package/migrations/0059_repoint_transaction_fk_to_run.sql +10 -0
- package/migrations/0060_drop_session_mail_instance_fk.sql +6 -0
- package/migrations/0061_drop_session_asset_instance_fk.sql +7 -0
- package/migrations/0062_drop_agent_asset_table.sql +11 -0
- package/migrations/0063_repoint_agent_role_fk_to_definition.sql +39 -0
- package/migrations/0064_repoint_agent_session_fk_to_definition.sql +47 -0
- package/migrations/0065_add_workflow_definition_model_requirements.sql +37 -0
- package/migrations/0066_rekey_agent_definition_principals_to_workflow.sql +27 -0
- package/migrations/0067_add_workflow_definition_kind.sql +10 -0
- package/migrations/0068_drop_agent_tables_and_origin_agent_id.sql +31 -0
- package/migrations/0069_drop_workflow_definition_kind.sql +10 -0
- package/migrations/0070_flashy_proteus.sql +13 -0
- package/migrations/0072_add_workflow_definition_credential_bindings.sql +1 -0
- package/migrations/0073_grant_target_exactly_one_check.sql +13 -0
- package/migrations/0074_add_provider_api_base_url.sql +1 -0
- package/migrations/0075_workflow_run_launch_spec.sql +17 -0
- package/migrations/0076_sidecar_allocation.sql +40 -0
- package/migrations/0077_workflow_run_dispatch.sql +29 -0
- package/migrations/0078_workflow_run_dispatch_kind.sql +2 -0
- package/migrations/0079_rename_workflow_run_deployment_id_to_anchor_run_id.sql +4 -0
- package/migrations/0080_rename_correlation_approval_deployment_id_to_anchor_run_id.sql +9 -0
- package/migrations/0081_workflow_definition_content_hash_and_approved_wire_hash.sql +4 -0
- package/migrations/0082_blue_black_queen.sql +1 -0
- package/migrations/0083_replace_launch_spec_snapshot_with_frozen_bundle.sql +3 -0
- package/migrations/0084_delete_orphaned_credential_grants.sql +22 -0
- package/migrations/meta/0029_snapshot.json +2664 -0
- package/migrations/meta/0030_snapshot.json +2670 -0
- package/migrations/meta/0031_snapshot.json +3100 -0
- package/migrations/meta/0032_snapshot.json +3106 -0
- package/migrations/meta/0033_snapshot.json +3112 -0
- package/migrations/meta/0034_snapshot.json +3198 -0
- package/migrations/meta/0035_snapshot.json +3225 -0
- package/migrations/meta/0036_snapshot.json +3237 -0
- package/migrations/meta/0037_snapshot.json +3237 -0
- package/migrations/meta/0038_snapshot.json +3470 -0
- package/migrations/meta/0039_snapshot.json +3470 -0
- package/migrations/meta/0040_snapshot.json +3489 -0
- package/migrations/meta/0041_snapshot.json +3489 -0
- package/migrations/meta/0042_snapshot.json +3489 -0
- package/migrations/meta/0043_snapshot.json +3498 -0
- package/migrations/meta/0044_snapshot.json +3504 -0
- package/migrations/meta/0045_snapshot.json +3589 -0
- package/migrations/meta/0046_snapshot.json +3607 -0
- package/migrations/meta/0047_snapshot.json +3832 -0
- package/migrations/meta/0048_snapshot.json +3853 -0
- package/migrations/meta/0049_snapshot.json +3854 -0
- package/migrations/meta/0050_snapshot.json +3924 -0
- package/migrations/meta/0051_snapshot.json +3940 -0
- package/migrations/meta/0052_snapshot.json +3931 -0
- package/migrations/meta/0053_snapshot.json +3952 -0
- package/migrations/meta/0054_snapshot.json +3952 -0
- package/migrations/meta/0055_snapshot.json +3952 -0
- package/migrations/meta/0056_snapshot.json +3952 -0
- package/migrations/meta/0057_snapshot.json +3839 -0
- package/migrations/meta/0058_snapshot.json +3839 -0
- package/migrations/meta/0059_snapshot.json +3839 -0
- package/migrations/meta/0060_snapshot.json +3830 -0
- package/migrations/meta/0061_snapshot.json +3821 -0
- package/migrations/meta/0062_snapshot.json +3723 -0
- package/migrations/meta/0063_snapshot.json +3723 -0
- package/migrations/meta/0064_snapshot.json +3723 -0
- package/migrations/meta/0065_snapshot.json +3729 -0
- package/migrations/meta/0066_snapshot.json +3729 -0
- package/migrations/meta/0067_snapshot.json +3736 -0
- package/migrations/meta/0068_snapshot.json +3347 -0
- package/migrations/meta/0069_snapshot.json +3340 -0
- package/migrations/meta/0070_snapshot.json +3444 -0
- package/migrations/meta/0072_snapshot.json +3450 -0
- package/migrations/meta/0073_snapshot.json +3455 -0
- package/migrations/meta/0074_snapshot.json +3461 -0
- package/migrations/meta/0075_snapshot.json +3567 -0
- package/migrations/meta/0076_snapshot.json +3851 -0
- package/migrations/meta/0077_snapshot.json +4067 -0
- package/migrations/meta/0078_snapshot.json +4078 -0
- package/migrations/meta/0079_snapshot.json +4078 -0
- package/migrations/meta/0080_snapshot.json +4078 -0
- package/migrations/meta/0081_snapshot.json +4096 -0
- package/migrations/meta/0082_snapshot.json +4102 -0
- package/migrations/meta/0083_snapshot.json +4096 -0
- package/migrations/meta/0084_snapshot.json +4096 -0
- package/migrations/meta/_journal.json +385 -0
- package/package.json +25 -11
- package/drizzle.config.ts +0 -23
- package/src/client.ts +0 -24
- package/src/config.ts +0 -19
- package/src/connection.ts +0 -27
- package/src/credential-resolution.ts +0 -378
- package/src/grant-store.ts +0 -51
- package/src/index.ts +0 -32
- package/src/migrate.test.ts +0 -35
- package/src/migrate.ts +0 -168
- package/src/parse-row.test.ts +0 -113
- package/src/parse-row.ts +0 -185
- package/src/schema/agent-assets.ts +0 -21
- package/src/schema/agents.ts +0 -49
- package/src/schema/auth.ts +0 -51
- package/src/schema/grants.ts +0 -26
- package/src/schema/index.ts +0 -19
- package/src/schema/instances.ts +0 -36
- package/src/schema/messages.ts +0 -108
- package/src/schema/offerings.ts +0 -20
- package/src/schema/principals.ts +0 -28
- package/src/schema/providers.ts +0 -23
- package/src/schema/roles.ts +0 -51
- package/src/schema/session-assets.ts +0 -49
- package/src/schema/sessions.ts +0 -26
- package/src/schema/sidecar.ts +0 -14
- package/src/schema/wallets.ts +0 -44
- package/src/tenant-hierarchy.ts +0 -34
- package/tsconfig.json +0 -4
- package/tsconfig.tsbuildinfo +0 -1
package/src/parse-row.test.ts
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { RepoAction } from "@intx/types/sidecar";
|
|
4
|
-
|
|
5
|
-
import { GitTokenKindValidator, parseGitTokenRow } from "./parse-row";
|
|
6
|
-
import type { gitToken } from "./schema";
|
|
7
|
-
|
|
8
|
-
type GitTokenRow = typeof gitToken.$inferSelect;
|
|
9
|
-
|
|
10
|
-
function makeRow(overrides: Partial<GitTokenRow> = {}): GitTokenRow {
|
|
11
|
-
const now = new Date();
|
|
12
|
-
return {
|
|
13
|
-
id: "gtk_0123456789abcdef0123456789abcdef",
|
|
14
|
-
tenantId: null,
|
|
15
|
-
userId: "user_alice",
|
|
16
|
-
principalId: null,
|
|
17
|
-
name: "laptop",
|
|
18
|
-
kind: "pat",
|
|
19
|
-
tokenHashSha256: new Uint8Array(32),
|
|
20
|
-
resource: "agent-state:ins_test",
|
|
21
|
-
refPattern: "refs/heads/*",
|
|
22
|
-
actions: ["receivePack", "createPack", "resolveRef"],
|
|
23
|
-
expiresAt: new Date("2027-01-01T00:00:00Z"),
|
|
24
|
-
revokedAt: null,
|
|
25
|
-
createdAt: now,
|
|
26
|
-
...overrides,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
describe("parseGitTokenRow", () => {
|
|
31
|
-
test("round-trips a personal pat with concrete repo scope", () => {
|
|
32
|
-
const row = makeRow();
|
|
33
|
-
const parsed = parseGitTokenRow(row);
|
|
34
|
-
|
|
35
|
-
expect(parsed.id).toBe(row.id);
|
|
36
|
-
expect(parsed.tenantId).toBeNull();
|
|
37
|
-
expect(parsed.userId).toBe(row.userId);
|
|
38
|
-
expect(parsed.principalId).toBeNull();
|
|
39
|
-
expect(parsed.name).toBe(row.name);
|
|
40
|
-
expect(parsed.kind).toBe("pat");
|
|
41
|
-
expect(parsed.tokenHashSha256).toBe(row.tokenHashSha256);
|
|
42
|
-
expect(parsed.actions).toEqual(["receivePack", "createPack", "resolveRef"]);
|
|
43
|
-
expect(parsed.resource).toBe("agent-state:ins_test");
|
|
44
|
-
expect(parsed.refPattern).toBe("refs/heads/*");
|
|
45
|
-
expect(parsed.expiresAt).toBe(row.expiresAt);
|
|
46
|
-
expect(parsed.revokedAt).toBeNull();
|
|
47
|
-
expect(parsed.createdAt).toBe(row.createdAt);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test("round-trips a tenant-restricted pat", () => {
|
|
51
|
-
const row = makeRow({
|
|
52
|
-
tenantId: "tnt_acme",
|
|
53
|
-
name: "acme-only",
|
|
54
|
-
});
|
|
55
|
-
const parsed = parseGitTokenRow(row);
|
|
56
|
-
|
|
57
|
-
expect(parsed.kind).toBe("pat");
|
|
58
|
-
expect(parsed.tenantId).toBe("tnt_acme");
|
|
59
|
-
expect(parsed.principalId).toBeNull();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("round-trips a tenant-bound svc token", () => {
|
|
63
|
-
const row = makeRow({
|
|
64
|
-
kind: "svc",
|
|
65
|
-
tenantId: "tnt_acme",
|
|
66
|
-
principalId: "prn_tenant_user",
|
|
67
|
-
name: "ci-runner",
|
|
68
|
-
actions: ["createPack", "resolveRef"],
|
|
69
|
-
resource: "asset:def_skill_xyz",
|
|
70
|
-
refPattern: "refs/tags/v*",
|
|
71
|
-
});
|
|
72
|
-
const parsed = parseGitTokenRow(row);
|
|
73
|
-
|
|
74
|
-
expect(parsed.kind).toBe("svc");
|
|
75
|
-
expect(parsed.tenantId).toBe("tnt_acme");
|
|
76
|
-
expect(parsed.principalId).toBe("prn_tenant_user");
|
|
77
|
-
expect(parsed.actions).toEqual(["createPack", "resolveRef"]);
|
|
78
|
-
expect(parsed.resource).toBe("asset:def_skill_xyz");
|
|
79
|
-
expect(parsed.refPattern).toBe("refs/tags/v*");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("preserves revokedAt for soft-revoked rows", () => {
|
|
83
|
-
const revoked = new Date("2026-01-15T00:00:00Z");
|
|
84
|
-
const row = makeRow({ revokedAt: revoked });
|
|
85
|
-
const parsed = parseGitTokenRow(row);
|
|
86
|
-
|
|
87
|
-
expect(parsed.revokedAt).toBe(revoked);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("preserves expiresAt", () => {
|
|
91
|
-
const expires = new Date("2027-01-01T00:00:00Z");
|
|
92
|
-
const row = makeRow({ expiresAt: expires });
|
|
93
|
-
const parsed = parseGitTokenRow(row);
|
|
94
|
-
|
|
95
|
-
expect(parsed.expiresAt).toBe(expires);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("rejects an unknown kind", () => {
|
|
99
|
-
expect(() => GitTokenKindValidator.assert("rogue")).toThrow();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("rejects an unknown action in the actions array", () => {
|
|
103
|
-
expect(() =>
|
|
104
|
-
RepoAction.array().assert(["receivePack", "fly-the-helicopter"]),
|
|
105
|
-
).toThrow();
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test("accepts an empty actions array", () => {
|
|
109
|
-
const row = makeRow({ actions: [] });
|
|
110
|
-
const parsed = parseGitTokenRow(row);
|
|
111
|
-
expect(parsed.actions).toEqual([]);
|
|
112
|
-
});
|
|
113
|
-
});
|
package/src/parse-row.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { type } from "arktype";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
CredentialRequirement,
|
|
5
|
-
GrantRequirement,
|
|
6
|
-
grantEffects,
|
|
7
|
-
grantOrigins,
|
|
8
|
-
sidecarStatuses,
|
|
9
|
-
} from "@intx/types";
|
|
10
|
-
import { RepoAction } from "@intx/types/sidecar";
|
|
11
|
-
|
|
12
|
-
import type {
|
|
13
|
-
agent,
|
|
14
|
-
agentVersion,
|
|
15
|
-
credential,
|
|
16
|
-
gitToken,
|
|
17
|
-
grant,
|
|
18
|
-
oauthClient,
|
|
19
|
-
offering,
|
|
20
|
-
provider,
|
|
21
|
-
tenant,
|
|
22
|
-
transaction,
|
|
23
|
-
turnPart,
|
|
24
|
-
wallet,
|
|
25
|
-
} from "./schema";
|
|
26
|
-
|
|
27
|
-
const JSONObject = type("Record<string, unknown>");
|
|
28
|
-
|
|
29
|
-
const GrantEffectValidator = type.enumerated(...grantEffects);
|
|
30
|
-
const GrantOriginValidator = type.enumerated(...grantOrigins);
|
|
31
|
-
|
|
32
|
-
const agentVersionStatuses = ["active", "inactive", "failed"] as const;
|
|
33
|
-
const AgentVersionStatusValidator = type.enumerated(...agentVersionStatuses);
|
|
34
|
-
|
|
35
|
-
const credentialTypes = [
|
|
36
|
-
"api_key",
|
|
37
|
-
"oauth_token",
|
|
38
|
-
"certificate",
|
|
39
|
-
"other",
|
|
40
|
-
] as const;
|
|
41
|
-
const CredentialTypeValidator = type.enumerated(...credentialTypes);
|
|
42
|
-
|
|
43
|
-
const credentialStatuses = ["active", "expired", "revoked", "error"] as const;
|
|
44
|
-
const CredentialStatusValidator = type.enumerated(...credentialStatuses);
|
|
45
|
-
|
|
46
|
-
const walletBackendTypes = ["crypto", "fiat", "credits"] as const;
|
|
47
|
-
const WalletBackendTypeValidator = type.enumerated(...walletBackendTypes);
|
|
48
|
-
|
|
49
|
-
const transactionDirections = ["inbound", "outbound"] as const;
|
|
50
|
-
const TransactionDirectionValidator = type.enumerated(...transactionDirections);
|
|
51
|
-
|
|
52
|
-
const transactionStatuses = ["pending", "completed", "failed"] as const;
|
|
53
|
-
const TransactionStatusValidator = type.enumerated(...transactionStatuses);
|
|
54
|
-
|
|
55
|
-
const SidecarStatusValidator = type.enumerated(...sidecarStatuses);
|
|
56
|
-
|
|
57
|
-
const gitTokenKinds = ["pat", "svc"] as const;
|
|
58
|
-
export const GitTokenKindValidator = type.enumerated(...gitTokenKinds);
|
|
59
|
-
|
|
60
|
-
const turnPartTypes = [
|
|
61
|
-
"text",
|
|
62
|
-
"reasoning",
|
|
63
|
-
"tool",
|
|
64
|
-
"file",
|
|
65
|
-
"error",
|
|
66
|
-
"refusal",
|
|
67
|
-
"step-start",
|
|
68
|
-
"step-finish",
|
|
69
|
-
"snapshot",
|
|
70
|
-
"patch",
|
|
71
|
-
] as const;
|
|
72
|
-
const TurnPartTypeValidator = type.enumerated(...turnPartTypes);
|
|
73
|
-
|
|
74
|
-
export function parseAgentRow(row: typeof agent.$inferSelect) {
|
|
75
|
-
return {
|
|
76
|
-
...row,
|
|
77
|
-
contextConfig:
|
|
78
|
-
row.contextConfig !== null ? JSONObject.assert(row.contextConfig) : null,
|
|
79
|
-
initialState:
|
|
80
|
-
row.initialState !== null ? JSONObject.assert(row.initialState) : null,
|
|
81
|
-
modelConfig:
|
|
82
|
-
row.modelConfig !== null ? JSONObject.assert(row.modelConfig) : null,
|
|
83
|
-
capabilities:
|
|
84
|
-
row.capabilities !== null ? JSONObject.assert(row.capabilities) : null,
|
|
85
|
-
credentialRequirements:
|
|
86
|
-
row.credentialRequirements !== null
|
|
87
|
-
? CredentialRequirement.array().assert(row.credentialRequirements)
|
|
88
|
-
: null,
|
|
89
|
-
grantRequirements:
|
|
90
|
-
row.grantRequirements !== null
|
|
91
|
-
? GrantRequirement.array().assert(row.grantRequirements)
|
|
92
|
-
: null,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function parseAgentVersionRow(row: typeof agentVersion.$inferSelect) {
|
|
97
|
-
return {
|
|
98
|
-
...row,
|
|
99
|
-
status: AgentVersionStatusValidator.assert(row.status),
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export function parseGrantRow(row: typeof grant.$inferSelect) {
|
|
104
|
-
return {
|
|
105
|
-
...row,
|
|
106
|
-
effect: GrantEffectValidator.assert(row.effect),
|
|
107
|
-
origin: GrantOriginValidator.assert(row.origin),
|
|
108
|
-
conditions:
|
|
109
|
-
row.conditions !== null ? JSONObject.assert(row.conditions) : null,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
export function parseOfferingRow(row: typeof offering.$inferSelect) {
|
|
114
|
-
return {
|
|
115
|
-
...row,
|
|
116
|
-
pricing: row.pricing !== null ? JSONObject.assert(row.pricing) : null,
|
|
117
|
-
schema: row.schema !== null ? JSONObject.assert(row.schema) : null,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export function parseCredentialRow(row: typeof credential.$inferSelect) {
|
|
122
|
-
return {
|
|
123
|
-
...row,
|
|
124
|
-
type: CredentialTypeValidator.assert(row.type),
|
|
125
|
-
status: CredentialStatusValidator.assert(row.status),
|
|
126
|
-
metadata: row.metadata !== null ? JSONObject.assert(row.metadata) : null,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function parseProviderRow(row: typeof provider.$inferSelect) {
|
|
131
|
-
return {
|
|
132
|
-
...row,
|
|
133
|
-
metadata: row.metadata !== null ? JSONObject.assert(row.metadata) : null,
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function parseTenantRow(row: typeof tenant.$inferSelect) {
|
|
138
|
-
return {
|
|
139
|
-
...row,
|
|
140
|
-
config: row.config !== null ? JSONObject.assert(row.config) : null,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function parseWalletRow(row: typeof wallet.$inferSelect) {
|
|
145
|
-
return {
|
|
146
|
-
...row,
|
|
147
|
-
backendType: WalletBackendTypeValidator.assert(row.backendType),
|
|
148
|
-
config: row.config !== null ? JSONObject.assert(row.config) : null,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function parseTransactionRow(row: typeof transaction.$inferSelect) {
|
|
153
|
-
return {
|
|
154
|
-
...row,
|
|
155
|
-
direction: TransactionDirectionValidator.assert(row.direction),
|
|
156
|
-
status: TransactionStatusValidator.assert(row.status),
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function parseOAuthClientRow(row: typeof oauthClient.$inferSelect) {
|
|
161
|
-
return {
|
|
162
|
-
...row,
|
|
163
|
-
metadata: row.metadata !== null ? JSONObject.assert(row.metadata) : null,
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export function parseGitTokenRow(row: typeof gitToken.$inferSelect) {
|
|
168
|
-
return {
|
|
169
|
-
...row,
|
|
170
|
-
kind: GitTokenKindValidator.assert(row.kind),
|
|
171
|
-
actions: RepoAction.array().assert(row.actions),
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function parseSidecarStatus(
|
|
176
|
-
status: string,
|
|
177
|
-
): "online" | "offline" | "error" {
|
|
178
|
-
return SidecarStatusValidator.assert(status);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function parseTurnPartType(
|
|
182
|
-
partType: string,
|
|
183
|
-
): (typeof turnPart.$inferInsert)["type"] {
|
|
184
|
-
return TurnPartTypeValidator.assert(partType);
|
|
185
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { pgTable, text, timestamp, unique } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
import { agent } from "./agents";
|
|
4
|
-
import { asset } from "./assets";
|
|
5
|
-
|
|
6
|
-
export const agentAsset = pgTable(
|
|
7
|
-
"agent_asset",
|
|
8
|
-
{
|
|
9
|
-
id: text("id").primaryKey(),
|
|
10
|
-
agentId: text("agent_id")
|
|
11
|
-
.notNull()
|
|
12
|
-
.references(() => agent.id, { onDelete: "cascade" }),
|
|
13
|
-
assetId: text("asset_id")
|
|
14
|
-
.notNull()
|
|
15
|
-
.references(() => asset.id, { onDelete: "cascade" }),
|
|
16
|
-
ref: text("ref").notNull(),
|
|
17
|
-
accessMode: text("access_mode").notNull().default("read-only"),
|
|
18
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
19
|
-
},
|
|
20
|
-
(t) => [unique("agent_asset_agent_asset").on(t.agentId, t.assetId)],
|
|
21
|
-
);
|
package/src/schema/agents.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
import { principal } from "./principals";
|
|
4
|
-
import { tenant } from "./tenants";
|
|
5
|
-
|
|
6
|
-
export const agent = pgTable("agent", {
|
|
7
|
-
id: text("id").primaryKey(),
|
|
8
|
-
tenantId: text("tenant_id")
|
|
9
|
-
.notNull()
|
|
10
|
-
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
11
|
-
// Tracks the definition author's principal for resolving source:"creator"
|
|
12
|
-
// grant requirements at launch. See AUTH.md § Grant Requirements on Definitions.
|
|
13
|
-
creatorPrincipalId: text("creator_principal_id")
|
|
14
|
-
.notNull()
|
|
15
|
-
.references(() => principal.id),
|
|
16
|
-
name: text("name").notNull(),
|
|
17
|
-
description: text("description"),
|
|
18
|
-
systemPrompt: text("system_prompt"),
|
|
19
|
-
contextConfig: jsonb("context_config"),
|
|
20
|
-
initialState: jsonb("initial_state"),
|
|
21
|
-
modelConfig: jsonb("model_config"),
|
|
22
|
-
capabilities: jsonb("capabilities"),
|
|
23
|
-
credentialRequirements: jsonb("credential_requirements"),
|
|
24
|
-
// Grant requirements manifest — resolved at launch into materialized grants
|
|
25
|
-
// on the instance principal. See AUTH.md § Grant Requirements on Definitions.
|
|
26
|
-
grantRequirements: jsonb("grant_requirements"),
|
|
27
|
-
currentVersion: text("current_version").notNull().default("1"),
|
|
28
|
-
status: text("status", {
|
|
29
|
-
enum: ["deployed", "stopped"],
|
|
30
|
-
})
|
|
31
|
-
.notNull()
|
|
32
|
-
.default("deployed"),
|
|
33
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
34
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
export const agentVersion = pgTable("agent_version", {
|
|
38
|
-
id: text("id").primaryKey(),
|
|
39
|
-
agentId: text("agent_id")
|
|
40
|
-
.notNull()
|
|
41
|
-
.references(() => agent.id, { onDelete: "cascade" }),
|
|
42
|
-
version: text("version").notNull(),
|
|
43
|
-
status: text("status", {
|
|
44
|
-
enum: ["active", "inactive", "failed"],
|
|
45
|
-
})
|
|
46
|
-
.notNull()
|
|
47
|
-
.default("active"),
|
|
48
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
49
|
-
});
|
package/src/schema/auth.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { boolean, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
export const user = pgTable("user", {
|
|
4
|
-
id: text("id").primaryKey(),
|
|
5
|
-
name: text("name").notNull(),
|
|
6
|
-
email: text("email").notNull().unique(),
|
|
7
|
-
emailVerified: boolean("email_verified").notNull().default(false),
|
|
8
|
-
image: text("image"),
|
|
9
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
10
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
export const session = pgTable("session", {
|
|
14
|
-
id: text("id").primaryKey(),
|
|
15
|
-
userId: text("user_id")
|
|
16
|
-
.notNull()
|
|
17
|
-
.references(() => user.id, { onDelete: "cascade" }),
|
|
18
|
-
token: text("token").notNull().unique(),
|
|
19
|
-
expiresAt: timestamp("expires_at").notNull(),
|
|
20
|
-
ipAddress: text("ip_address"),
|
|
21
|
-
userAgent: text("user_agent"),
|
|
22
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
23
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const account = pgTable("account", {
|
|
27
|
-
id: text("id").primaryKey(),
|
|
28
|
-
userId: text("user_id")
|
|
29
|
-
.notNull()
|
|
30
|
-
.references(() => user.id, { onDelete: "cascade" }),
|
|
31
|
-
accountId: text("account_id").notNull(),
|
|
32
|
-
providerId: text("provider_id").notNull(),
|
|
33
|
-
accessToken: text("access_token"),
|
|
34
|
-
refreshToken: text("refresh_token"),
|
|
35
|
-
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
|
36
|
-
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
|
37
|
-
scope: text("scope"),
|
|
38
|
-
idToken: text("id_token"),
|
|
39
|
-
password: text("password"),
|
|
40
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
41
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
export const verification = pgTable("verification", {
|
|
45
|
-
id: text("id").primaryKey(),
|
|
46
|
-
identifier: text("identifier").notNull(),
|
|
47
|
-
value: text("value").notNull(),
|
|
48
|
-
expiresAt: timestamp("expires_at").notNull(),
|
|
49
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
50
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
51
|
-
});
|
package/src/schema/grants.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { jsonb, pgTable, text, timestamp } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
import { principal } from "./principals";
|
|
4
|
-
import { role } from "./roles";
|
|
5
|
-
import { tenant } from "./tenants";
|
|
6
|
-
|
|
7
|
-
export const grant = pgTable("grant", {
|
|
8
|
-
id: text("id").primaryKey(),
|
|
9
|
-
tenantId: text("tenant_id")
|
|
10
|
-
.notNull()
|
|
11
|
-
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
12
|
-
roleId: text("role_id").references(() => role.id, { onDelete: "cascade" }),
|
|
13
|
-
principalId: text("principal_id").references(() => principal.id, {
|
|
14
|
-
onDelete: "cascade",
|
|
15
|
-
}),
|
|
16
|
-
resource: text("resource").notNull(),
|
|
17
|
-
action: text("action").notNull(),
|
|
18
|
-
effect: text("effect", { enum: ["allow", "deny", "ask"] }).notNull(),
|
|
19
|
-
conditions: jsonb("conditions"),
|
|
20
|
-
origin: text("origin", {
|
|
21
|
-
enum: ["system", "role", "creator", "invoker"],
|
|
22
|
-
}).notNull(),
|
|
23
|
-
expiresAt: timestamp("expires_at"),
|
|
24
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
25
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
26
|
-
});
|
package/src/schema/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from "./auth";
|
|
2
|
-
export * from "./tenants";
|
|
3
|
-
export * from "./principals";
|
|
4
|
-
export * from "./roles";
|
|
5
|
-
export * from "./grants";
|
|
6
|
-
export * from "./agents";
|
|
7
|
-
export * from "./providers";
|
|
8
|
-
export * from "./oauth-clients";
|
|
9
|
-
export * from "./credentials";
|
|
10
|
-
export * from "./assets";
|
|
11
|
-
export * from "./agent-assets";
|
|
12
|
-
export * from "./wallets";
|
|
13
|
-
export * from "./offerings";
|
|
14
|
-
export * from "./sidecar";
|
|
15
|
-
export * from "./sessions";
|
|
16
|
-
export * from "./instances";
|
|
17
|
-
export * from "./session-assets";
|
|
18
|
-
export * from "./messages";
|
|
19
|
-
export * from "./git-tokens";
|
package/src/schema/instances.ts
DELETED
|
@@ -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
|
-
});
|
package/src/schema/messages.ts
DELETED
|
@@ -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
|
-
);
|
package/src/schema/offerings.ts
DELETED
|
@@ -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
|
-
});
|
package/src/schema/principals.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { pgTable, text, timestamp, unique } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
import { user } from "./auth";
|
|
4
|
-
import { tenant } from "./tenants";
|
|
5
|
-
|
|
6
|
-
export const principal = pgTable(
|
|
7
|
-
"principal",
|
|
8
|
-
{
|
|
9
|
-
id: text("id").primaryKey(),
|
|
10
|
-
tenantId: text("tenant_id")
|
|
11
|
-
.notNull()
|
|
12
|
-
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
13
|
-
kind: text("kind", { enum: ["user", "agent"] }).notNull(),
|
|
14
|
-
refId: text("ref_id").notNull(),
|
|
15
|
-
status: text("status", {
|
|
16
|
-
enum: ["active", "suspended", "invited", "deactivated"],
|
|
17
|
-
}).notNull(),
|
|
18
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
19
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
20
|
-
},
|
|
21
|
-
(t) => [unique().on(t.tenantId, t.kind, t.refId)],
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
// The refId on a user principal points to the auth user table.
|
|
25
|
-
// We don't add a FK constraint because refId also points to agent.id
|
|
26
|
-
// when kind='agent', and Postgres can't do conditional FKs.
|
|
27
|
-
// The application layer enforces referential integrity.
|
|
28
|
-
export { user };
|
package/src/schema/providers.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { jsonb, pgTable, text, timestamp, unique } from "drizzle-orm/pg-core";
|
|
2
|
-
|
|
3
|
-
import { tenant } from "./tenants";
|
|
4
|
-
|
|
5
|
-
export const provider = pgTable(
|
|
6
|
-
"provider",
|
|
7
|
-
{
|
|
8
|
-
id: text("id").primaryKey(),
|
|
9
|
-
tenantId: text("tenant_id")
|
|
10
|
-
.notNull()
|
|
11
|
-
.references(() => tenant.id, { onDelete: "cascade" }),
|
|
12
|
-
name: text("name").notNull(),
|
|
13
|
-
plugin: text("plugin").notNull(),
|
|
14
|
-
authorizationUrl: text("authorization_url"),
|
|
15
|
-
tokenUrl: text("token_url"),
|
|
16
|
-
userInfoUrl: text("user_info_url"),
|
|
17
|
-
scopes: text("scopes").array(),
|
|
18
|
-
metadata: jsonb("metadata"),
|
|
19
|
-
createdAt: timestamp("created_at").notNull().defaultNow(),
|
|
20
|
-
updatedAt: timestamp("updated_at").notNull().defaultNow(),
|
|
21
|
-
},
|
|
22
|
-
(t) => [unique("provider_tenant_name").on(t.tenantId, t.name)],
|
|
23
|
-
);
|