@nylorun/runtime 0.16.0-beta → 0.19.0-beta
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/CHANGELOG.md +207 -0
- package/README.md +105 -63
- package/dist/adapters/execution/restate.d.ts +1 -3
- package/dist/adapters/execution/restate.js +4 -31
- package/dist/adapters/replication/pgoutput.js +1 -1
- package/dist/adapters/sandbox/local.js +1 -1
- package/dist/adapters/sandbox/virtual.js +1 -1
- package/dist/api/ag-ui/endpoint.js +1 -2
- package/dist/api/ag-ui/routes.d.ts +1 -1
- package/dist/api/ag-ui/routes.js +11 -13
- package/dist/api/ag-ui/translate.d.ts +1 -3
- package/dist/api/ag-ui/translate.js +2 -17
- package/dist/api/components.d.ts +4783 -2588
- package/dist/api/components.js +19 -21
- package/dist/api/gate/routes.d.ts +7 -8
- package/dist/api/gate/routes.js +58 -52
- package/dist/api/http/app.d.ts +6 -0
- package/dist/api/http/app.js +20 -14
- package/dist/api/http/define.d.ts +22 -13
- package/dist/api/http/define.js +43 -39
- package/dist/api/http/routes/access.d.ts +3 -19
- package/dist/api/http/routes/access.js +25 -184
- package/dist/api/http/routes/artifacts.js +3 -7
- package/dist/api/http/routes/files.d.ts +8 -0
- package/dist/api/http/routes/files.js +77 -0
- package/dist/api/http/routes/keys.d.ts +10 -0
- package/dist/api/http/routes/keys.js +64 -0
- package/dist/api/http/routes/me.d.ts +13 -0
- package/dist/api/http/routes/me.js +48 -0
- package/dist/api/http/routes/reads.d.ts +66 -0
- package/dist/api/http/routes/reads.js +127 -0
- package/dist/api/http/routes/sandboxes.d.ts +2 -2
- package/dist/api/http/routes/sandboxes.js +8 -7
- package/dist/api/http/routes/sessions.js +31 -20
- package/dist/api/http/routes/tenant.js +15 -18
- package/dist/api/http/routes/vaults.d.ts +13 -3
- package/dist/api/http/routes/vaults.js +136 -64
- package/dist/api/openapi.d.ts +10 -11
- package/dist/api/openapi.js +292 -68
- package/dist/artifacts/links.js +6 -6
- package/dist/artifacts/service.js +1 -1
- package/dist/core/flow-host.d.ts +44 -23
- package/dist/core/flow-host.js +88 -106
- package/dist/core/provider.d.ts +4 -1
- package/dist/core/provider.js +6 -1
- package/dist/core/sandbox-routes.d.ts +0 -9
- package/dist/core/sandbox-routes.js +2 -21
- package/dist/execution/memory.d.ts +4 -5
- package/dist/execution/memory.js +11 -25
- package/dist/execution/types.d.ts +3 -33
- package/dist/execution/types.js +2 -12
- package/dist/gates/http-tool.d.ts +86 -0
- package/dist/gates/http-tool.js +197 -0
- package/dist/gates/mcp-handler.d.ts +3 -0
- package/dist/gates/mcp-handler.js +6 -4
- package/dist/gates/meter.d.ts +2 -2
- package/dist/gates/meter.js +6 -0
- package/dist/gates/tenant-vaults.d.ts +19 -14
- package/dist/gates/tenant-vaults.js +17 -12
- package/dist/gates/tool-calls.d.ts +7 -15
- package/dist/gates/tool-calls.js +4 -4
- package/dist/gates/tool-client.d.ts +1 -1
- package/dist/gates/tool-client.js +23 -47
- package/dist/gates/tool-contract.d.ts +27 -39
- package/dist/gates/tool-contract.js +30 -21
- package/dist/gates/tool-gate.d.ts +25 -24
- package/dist/gates/tool-gate.js +11 -7
- package/dist/harness/calls.d.ts +10 -4
- package/dist/harness/calls.js +15 -6
- package/dist/harness/executors.d.ts +1 -1
- package/dist/harness/executors.js +17 -12
- package/dist/harness/main.d.ts +2 -2
- package/dist/harness/main.js +5 -13
- package/dist/harness/service.d.ts +4 -5
- package/dist/harness/service.js +9 -2
- package/dist/harness-api/in-process.js +2 -2
- package/dist/harness-api/record.d.ts +6 -3
- package/dist/harness-api/record.js +65 -72
- package/dist/harness-api/server.d.ts +1 -9
- package/dist/harness-api/server.js +19 -17
- package/dist/harness-api/start.js +1 -5
- package/dist/harness-api/workspace.js +2 -3
- package/dist/harness-api/ws-server.js +1 -1
- package/dist/host/app.d.ts +2 -10
- package/dist/host/app.js +24 -44
- package/dist/host/config-for.d.ts +5 -5
- package/dist/host/config-for.js +2 -3
- package/dist/host/config.d.ts +0 -11
- package/dist/host/create-host.d.ts +3 -40
- package/dist/host/create-host.js +18 -91
- package/dist/host/environment.d.ts +0 -3
- package/dist/host/environment.js +0 -9
- package/dist/host/gates.d.ts +4 -1
- package/dist/host/gates.js +9 -3
- package/dist/host/http.d.ts +1 -2
- package/dist/host/http.js +1 -7
- package/dist/host/index.d.ts +2 -2
- package/dist/host/index.js +2 -2
- package/dist/host/main.js +55 -40
- package/dist/host/operate.d.ts +29 -0
- package/dist/host/operate.js +223 -0
- package/dist/host/stack-config.d.ts +23 -20
- package/dist/host/stack-config.js +28 -44
- package/dist/index.d.ts +4 -1
- package/dist/index.js +3 -1
- package/dist/infra/workers.d.ts +1 -1
- package/dist/keys/client.js +9 -1
- package/dist/keys/keys.d.ts +12 -2
- package/dist/keys/keys.js +10 -2
- package/dist/management-openapi.json +6491 -0
- package/dist/mcp/connect.d.ts +8 -4
- package/dist/mcp/connect.js +8 -27
- package/dist/mcp/pool.d.ts +6 -9
- package/dist/mcp/pool.js +8 -18
- package/dist/mcp/snapshot.d.ts +8 -2
- package/dist/mcp/snapshot.js +29 -2
- package/dist/media.d.ts +1 -1
- package/dist/media.js +1 -1
- package/dist/model/pi-model.js +3 -0
- package/dist/openapi.json +6228 -15615
- package/dist/reads/access.d.ts +4 -0
- package/dist/reads/access.js +12 -0
- package/dist/reads/cursor.d.ts +11 -0
- package/dist/reads/cursor.js +80 -0
- package/dist/reads/types.d.ts +25 -0
- package/dist/reads/types.js +1 -0
- package/dist/sandbox/manager.d.ts +16 -0
- package/dist/sandbox/manager.js +40 -0
- package/dist/sandbox/session-sandbox.js +13 -3
- package/dist/sandbox/skills.d.ts +13 -0
- package/dist/sandbox/skills.js +46 -0
- package/dist/sandbox/types.d.ts +2 -2
- package/dist/store/ownership.d.ts +9 -0
- package/dist/store/ownership.js +13 -0
- package/dist/store/postgres/connect.d.ts +2 -0
- package/dist/store/postgres/connect.js +29 -0
- package/dist/store/postgres/drizzle/0008_installation_vaults.sql +2 -0
- package/dist/store/postgres/drizzle/0009_oauth_pending.sql +19 -0
- package/dist/store/postgres/drizzle/0010_oss_auth_removals.sql +3 -0
- package/dist/store/postgres/drizzle/0011_key_roles.sql +3 -0
- package/dist/store/postgres/drizzle/0012_session_reads.sql +8 -0
- package/dist/store/postgres/drizzle/0013_definition_files.sql +16 -0
- package/dist/store/postgres/drizzle/0014_action_endpoints_removed.sql +2 -0
- package/dist/store/postgres/drizzle/meta/_journal.json +49 -0
- package/dist/store/postgres/reads.d.ts +3 -0
- package/dist/store/postgres/reads.js +272 -0
- package/dist/store/postgres/schema.d.ts +423 -594
- package/dist/store/postgres/schema.js +84 -101
- package/dist/store/postgres/store.js +96 -248
- package/dist/store/postgres/tenant.d.ts +34 -2
- package/dist/store/postgres/tenant.js +16 -32
- package/dist/store/types.d.ts +44 -119
- package/dist/store/types.js +0 -1
- package/dist/streams/control.d.ts +0 -7
- package/dist/streams/control.js +0 -13
- package/dist/streams/types.d.ts +2 -20
- package/dist/streams/types.js +1 -1
- package/dist/tenant/advance.d.ts +3 -3
- package/dist/tenant/advance.js +10 -7
- package/dist/tenant/auth.d.ts +24 -15
- package/dist/tenant/auth.js +44 -55
- package/dist/tenant/cause.d.ts +3 -3
- package/dist/tenant/cause.js +1 -1
- package/dist/tenant/commands.d.ts +2 -18
- package/dist/tenant/commands.js +38 -179
- package/dist/tenant/context.d.ts +33 -45
- package/dist/tenant/definition-files.d.ts +24 -0
- package/dist/tenant/definition-files.js +103 -0
- package/dist/tenant/effects.d.ts +20 -18
- package/dist/tenant/effects.js +59 -133
- package/dist/tenant/ephemeral.d.ts +21 -8
- package/dist/tenant/ephemeral.js +11 -12
- package/dist/tenant/host-token.js +5 -5
- package/dist/tenant/identity-file.d.ts +75 -0
- package/dist/tenant/identity-file.js +202 -0
- package/dist/tenant/issuers.d.ts +48 -0
- package/dist/tenant/issuers.js +311 -0
- package/dist/tenant/jwt.js +3 -3
- package/dist/tenant/module.d.ts +1 -4
- package/dist/tenant/module.js +3 -12
- package/dist/tenant/operator-keys.d.ts +44 -0
- package/dist/tenant/operator-keys.js +87 -0
- package/dist/tenant/outbound.d.ts +40 -1
- package/dist/tenant/outbound.js +167 -18
- package/dist/tenant/paths.d.ts +1 -1
- package/dist/tenant/paths.js +1 -3
- package/dist/tenant/principals.d.ts +13 -13
- package/dist/tenant/principals.js +35 -36
- package/dist/tenant/run-token.js +6 -6
- package/dist/tenant/runtime.d.ts +5 -3
- package/dist/tenant/runtime.js +29 -15
- package/dist/tenant/sandboxes.d.ts +9 -6
- package/dist/tenant/sandboxes.js +16 -5
- package/dist/tenant/scheduler.d.ts +1 -5
- package/dist/tenant/scheduler.js +2 -5
- package/dist/tenant/session-streams.d.ts +8 -11
- package/dist/tenant/session-streams.js +48 -32
- package/dist/tenant/session.d.ts +8 -41
- package/dist/tenant/session.js +0 -37
- package/dist/tenant/sessions.d.ts +2 -2
- package/dist/tenant/sessions.js +17 -9
- package/dist/tenant/signing-keys.d.ts +3 -2
- package/dist/tenant/signing-keys.js +5 -5
- package/dist/tenant/skill-tool.d.ts +20 -0
- package/dist/tenant/skill-tool.js +72 -0
- package/dist/tenant/slim.d.ts +1 -1
- package/dist/tenant/slim.js +1 -1
- package/dist/tenant/status.js +7 -12
- package/dist/tenant/store-pg.d.ts +15 -0
- package/dist/tenant/store-pg.js +7 -3
- package/dist/tenant/streams.d.ts +3 -11
- package/dist/tenant/streams.js +2 -29
- package/dist/tenant/sweep.js +0 -5
- package/dist/tenant/transcript.d.ts +2 -2
- package/dist/tenant/transcript.js +2 -2
- package/dist/tenant/types.d.ts +33 -19
- package/dist/tenant/worker.d.ts +1 -3
- package/dist/tenant/worker.js +3 -8
- package/dist/vault/crypto.d.ts +7 -0
- package/dist/vault/crypto.js +16 -0
- package/dist/vault/oauth.d.ts +55 -0
- package/dist/vault/oauth.js +186 -0
- package/dist/vault/service.d.ts +54 -7
- package/dist/vault/service.js +261 -17
- package/dist/vault/sources.d.ts +60 -0
- package/dist/vault/sources.js +196 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -4
- package/dist/admin-openapi.json +0 -604
- package/dist/api/http/routes/actions.d.ts +0 -8
- package/dist/api/http/routes/actions.js +0 -76
- package/dist/api/http/routes/endpoints.d.ts +0 -7
- package/dist/api/http/routes/endpoints.js +0 -100
- package/dist/host/admin-api.d.ts +0 -23
- package/dist/host/admin-api.js +0 -74
- package/dist/host/cors.d.ts +0 -27
- package/dist/host/cors.js +0 -64
- package/dist/mcp/stdio.d.ts +0 -17
- package/dist/mcp/stdio.js +0 -82
- package/dist/tenant/access-policy.d.ts +0 -30
- package/dist/tenant/access-policy.js +0 -52
- package/dist/tenant/actions.d.ts +0 -14
- package/dist/tenant/actions.js +0 -29
- package/dist/tenant/browser.d.ts +0 -15
- package/dist/tenant/browser.js +0 -39
- package/dist/tenant/delivery-token.d.ts +0 -41
- package/dist/tenant/delivery-token.js +0 -104
- package/dist/tenant/delivery.d.ts +0 -62
- package/dist/tenant/delivery.js +0 -481
- package/dist/tenant/endpoints.d.ts +0 -67
- package/dist/tenant/endpoints.js +0 -90
- package/dist/tenant/subject-limits.d.ts +0 -16
- package/dist/tenant/subject-limits.js +0 -45
- package/dist/tenant/tokens.d.ts +0 -14
- package/dist/tenant/tokens.js +0 -187
|
@@ -1,40 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The tables of a Tenant database (session-store.md §2–§3): the source drizzle-kit generates
|
|
3
|
-
* the migrations from (`drizzle/`, `CONTRIBUTING.md` "Adding a migration") and the query
|
|
4
|
-
* builder's view of them. Column names are the camelCase keys in snake_case (`casing:
|
|
5
|
-
* "snake_case"`, here, in `db.ts` and in `drizzle.config.ts`).
|
|
6
|
-
*
|
|
7
|
-
* - `nylorun` holds the Tenant's state: the one `tenant` row, the document tables, Action
|
|
8
|
-
* endpoints, principals, vaults and credentials, signing keys, publishable keys, subject
|
|
9
|
-
* epochs and usage, settings, the model usage ledger, the model budgets, the Tool Gate's
|
|
10
|
-
* crossings and file artifacts with their versions.
|
|
11
|
-
* - `nylorun_streams` holds the record (Durable Streams §6): `session_events`,
|
|
12
|
-
* `session_log_heads` and the relay's `relay_slots`. The relay's publication is custom SQL
|
|
13
|
-
* (`drizzle/0002_stream_relay.sql`).
|
|
14
|
-
*
|
|
15
|
-
* What the columns keep:
|
|
16
|
-
*
|
|
17
|
-
* - **Bodies are `json`, not `jsonb`** (`jsonText`), written as the text `JSON.stringify`
|
|
18
|
-
* wrote, so every string round-trips exactly, key order included. `jsonb` rejects the
|
|
19
|
-
* escapes `\u0000` (`22P05`) and unpaired surrogates (`\ud800`), which tool output can
|
|
20
|
-
* contain; `json` stores the text verbatim and checks only its syntax.
|
|
21
|
-
* - **Indexed fields of a body are stored generated columns** read through
|
|
22
|
-
* `nylorun.doc(body)` (custom SQL, `drizzle/0000_foundation.sql`), which casts to `jsonb`
|
|
23
|
-
* after replacing those two escapes with `\ufffd`: the body is untouched, and only an indexed
|
|
24
|
-
* field that itself contained one (never an id, status or timestamp) would see U+FFFD.
|
|
25
|
-
* Queries never apply `->`/`->>` to a `json` body (Postgres de-escapes the whole text and
|
|
26
|
-
* fails on the same escapes); they read the generated columns.
|
|
27
|
-
* - **Ids and timestamps compared as text are `COLLATE "C"`** (`textC`), so they order by code
|
|
28
|
-
* point whatever the database's collation.
|
|
29
|
-
* - **Timestamps are ISO text**, except the session lease `owner_expires_at` and the record's
|
|
30
|
-
* `committed_at` (`timestamptz`).
|
|
31
|
-
* - **Sealed secrets are `bytea` columns** (`bytes`), never inside a JSON body.
|
|
32
|
-
* - Sessions carry the store-managed ownership columns (`owner`, `epoch`,
|
|
33
|
-
* `owner_expires_at`), which are never in `body`.
|
|
34
|
-
*
|
|
35
|
-
* Columns are listed in the order the tables have them, so a database created by these
|
|
36
|
-
* migrations and one created by the hand-written migrations they replaced dump the same.
|
|
37
|
-
*/
|
|
38
1
|
import { sql } from "drizzle-orm";
|
|
39
2
|
import { bigint, boolean, check, customType, doublePrecision, foreignKey, index, integer, pgSchema, primaryKey, text, timestamp, uniqueIndex, } from "drizzle-orm/pg-core";
|
|
40
3
|
export const TENANT_SCHEMA = "nylorun";
|
|
@@ -92,11 +55,14 @@ export const tenant = nylorun.table("tenant", {
|
|
|
92
55
|
retiredGenerations: integer().array().notNull().default(sql `'{}'`),
|
|
93
56
|
}, () => [check("tenant_singleton_check", sql `singleton`)]);
|
|
94
57
|
export const definitions = documents("definitions");
|
|
58
|
+
const xid8 = customType({ dataType: () => "xid8" });
|
|
95
59
|
export const sessions = nylorun.table("sessions", {
|
|
96
60
|
id: textC().primaryKey(),
|
|
97
61
|
body: jsonText().notNull(),
|
|
98
62
|
status: field("->>'status'"),
|
|
99
63
|
agentId: field("->>'agentId'"),
|
|
64
|
+
/** Unknown for legacy sessions; assigned only on insert. */
|
|
65
|
+
createdAt: timestamp({ withTimezone: true, mode: "string" }).defaultNow(),
|
|
100
66
|
/** The lease holder; store-managed, never in `body`. */
|
|
101
67
|
owner: text(),
|
|
102
68
|
epoch: bigint({ mode: "number" }).notNull().default(0),
|
|
@@ -106,6 +72,7 @@ export const sessions = nylorun.table("sessions", {
|
|
|
106
72
|
/** The sandbox resource the session is attached to (`sandbox: { id }`). */
|
|
107
73
|
sandboxId: field("->>'sandboxId'"),
|
|
108
74
|
}, (t) => [
|
|
75
|
+
index("sessions_created").on(t.createdAt.desc().nullsLast(), t.id.desc().nullsFirst()),
|
|
109
76
|
index("sessions_status").on(t.status, t.ownerExpiresAt),
|
|
110
77
|
index("sessions_agent").on(t.agentId),
|
|
111
78
|
index("sessions_owner_user").on(t.ownerUserId),
|
|
@@ -123,29 +90,16 @@ export const effects = nylorun.table("effects", {
|
|
|
123
90
|
index("effects_session").on(t.sessionId, t.turnId, t.status),
|
|
124
91
|
index("effects_status").on(t.status, t.kind),
|
|
125
92
|
]);
|
|
126
|
-
export const actions = nylorun.table("actions", {
|
|
127
|
-
id: textC().primaryKey(),
|
|
128
|
-
body: jsonText().notNull(),
|
|
129
|
-
sessionId: field("->>'sessionId'"),
|
|
130
|
-
turnId: field("->>'turnId'"),
|
|
131
|
-
agentId: field("->>'agentId'"),
|
|
132
|
-
status: field("->>'status'"),
|
|
133
|
-
kind: field("->>'kind'"),
|
|
134
|
-
/** When the Action being delivered is lost (ISO text). */
|
|
135
|
-
deadlineAt: field("->>'deadlineAt'"),
|
|
136
|
-
}, (t) => [
|
|
137
|
-
index("actions_session").on(t.sessionId, t.turnId, t.status),
|
|
138
|
-
index("actions_agent").on(t.agentId, t.status),
|
|
139
|
-
index("actions_status").on(t.status, t.kind),
|
|
140
|
-
index("actions_deadline").on(t.status, t.deadlineAt),
|
|
141
|
-
]);
|
|
142
93
|
export const sandboxes = documents("sandboxes");
|
|
143
94
|
export const links = nylorun.table("links", {
|
|
144
95
|
id: textC().primaryKey(),
|
|
145
96
|
body: jsonText().notNull(),
|
|
146
97
|
workflowSessionId: field("->>'workflowSessionId'"),
|
|
147
98
|
}, (t) => [index("links_workflow").on(t.workflowSessionId)]);
|
|
148
|
-
/**
|
|
99
|
+
/**
|
|
100
|
+
* A principal: who holds a key, by its SHA-256, and what the key reaches (`role`, protocol 8):
|
|
101
|
+
* `application` the Runtime API, `management` the Management API, `studio` both.
|
|
102
|
+
*/
|
|
149
103
|
export const principals = nylorun.table("principals", {
|
|
150
104
|
id: textC().primaryKey(),
|
|
151
105
|
role: text().$type().notNull(),
|
|
@@ -160,11 +114,15 @@ export const vaults = nylorun.table("vaults", {
|
|
|
160
114
|
/** JSON text, or null. */
|
|
161
115
|
metadataJson: text(),
|
|
162
116
|
createdAt: textC().notNull(),
|
|
163
|
-
|
|
117
|
+
/**
|
|
118
|
+
* `user`: one person's (owner `ownerUserId`); `installation`: the installation's own,
|
|
119
|
+
* attachable to any session (owner `installation`); `host`: the model vault, never attached.
|
|
120
|
+
*/
|
|
121
|
+
scope: text({ enum: ["user", "installation", "host"] }).notNull().default("user"),
|
|
164
122
|
}, (t) => [
|
|
165
123
|
index("vaults_owner").on(t.ownerUserId, t.createdAt, t.id),
|
|
166
124
|
uniqueIndex("vaults_one_host").on(t.scope).where(sql `scope = 'host'`),
|
|
167
|
-
check("vaults_scope_check", sql `scope IN ('user', 'host')`),
|
|
125
|
+
check("vaults_scope_check", sql `scope IN ('user', 'installation', 'host')`),
|
|
168
126
|
]);
|
|
169
127
|
/** A credential of a vault: its binding in the clear, its secret sealed. */
|
|
170
128
|
export const vaultCredentials = nylorun.table("vault_credentials", {
|
|
@@ -207,11 +165,48 @@ export const vaultIdempotency = nylorun.table("vault_idempotency", {
|
|
|
207
165
|
/** JSON text of the original response. */
|
|
208
166
|
response: text().notNull(),
|
|
209
167
|
});
|
|
168
|
+
/**
|
|
169
|
+
* An MCP OAuth connect between its start and its callback (F9 C2): found by the SHA-256 of its
|
|
170
|
+
* `state`, used once, for ten minutes. The PKCE verifier and any client secret are sealed under
|
|
171
|
+
* the vault key (`sealBytes`), which only the keys module holds.
|
|
172
|
+
*/
|
|
173
|
+
export const oauthPending = nylorun.table("oauth_pending", {
|
|
174
|
+
stateHash: text().primaryKey(),
|
|
175
|
+
vaultId: text().notNull(),
|
|
176
|
+
/** The MCP server's name in the agent, the credential's name. */
|
|
177
|
+
server: text().notNull(),
|
|
178
|
+
/** The MCP server's URL (normalized): the credential's binding. */
|
|
179
|
+
url: text().notNull(),
|
|
180
|
+
tokenEndpoint: text().notNull(),
|
|
181
|
+
clientId: text().notNull(),
|
|
182
|
+
/** How the client authenticates at the token endpoint: `none`, `client_secret_basic` or `client_secret_post`. */
|
|
183
|
+
tokenEndpointAuth: text({ enum: ["none", "client_secret_basic", "client_secret_post"] }).notNull(),
|
|
184
|
+
/** The RFC 8707 resource indicator sent with the authorization request, if any. */
|
|
185
|
+
resource: text(),
|
|
186
|
+
kekId: text().notNull(),
|
|
187
|
+
/** Sealed; null for a public client. */
|
|
188
|
+
clientSecret: bytes(),
|
|
189
|
+
/** Sealed. */
|
|
190
|
+
codeVerifier: bytes().notNull(),
|
|
191
|
+
redirectUri: text().notNull(),
|
|
192
|
+
expiresAt: textC().notNull(),
|
|
193
|
+
createdAt: textC().notNull(),
|
|
194
|
+
}, (t) => [
|
|
195
|
+
foreignKey({
|
|
196
|
+
name: "oauth_pending_vault_id_fkey",
|
|
197
|
+
columns: [t.vaultId],
|
|
198
|
+
foreignColumns: [vaults.id],
|
|
199
|
+
}).onDelete("cascade"),
|
|
200
|
+
index("oauth_pending_expires").on(t.expiresAt),
|
|
201
|
+
]);
|
|
210
202
|
export const tenantSettings = nylorun.table("tenant_settings", {
|
|
211
203
|
key: text().primaryKey(),
|
|
212
204
|
value: text().notNull(),
|
|
213
205
|
});
|
|
214
|
-
/**
|
|
206
|
+
/**
|
|
207
|
+
* The Tenant's signing keys (capability links, run and host tokens): the
|
|
208
|
+
* private half sealed, the public JWK not.
|
|
209
|
+
*/
|
|
215
210
|
export const signingKeys = nylorun.table("signing_keys", {
|
|
216
211
|
id: textC().primaryKey(),
|
|
217
212
|
state: text({ enum: ["standby", "current", "previous", "revoked"] }).notNull(),
|
|
@@ -233,50 +228,6 @@ export const signingKeys = nylorun.table("signing_keys", {
|
|
|
233
228
|
uniqueIndex("signing_keys_one_current").on(t.state).where(sql `state = 'current'`),
|
|
234
229
|
uniqueIndex("signing_keys_one_previous").on(t.state).where(sql `state = 'previous'`),
|
|
235
230
|
]);
|
|
236
|
-
/** Each subject's revocation epoch. */
|
|
237
|
-
export const subjectEpochs = nylorun.table("subject_epochs", {
|
|
238
|
-
subject: textC().primaryKey(),
|
|
239
|
-
epoch: bigint({ mode: "number" }).notNull(),
|
|
240
|
-
revokedAt: text().notNull(),
|
|
241
|
-
});
|
|
242
|
-
/** Each subject's turn bucket: tokens left and when they were last refilled. */
|
|
243
|
-
export const subjectUsage = nylorun.table("subject_usage", {
|
|
244
|
-
subject: textC().primaryKey(),
|
|
245
|
-
turnTokens: doublePrecision().notNull(),
|
|
246
|
-
refilledAt: text().notNull(),
|
|
247
|
-
});
|
|
248
|
-
/** Publishable keys (Host feature `browser-access`): public by design. */
|
|
249
|
-
export const publishableKeys = nylorun.table("publishable_keys", {
|
|
250
|
-
id: textC().primaryKey(),
|
|
251
|
-
key: textC().notNull().unique("publishable_keys_key_key"),
|
|
252
|
-
name: text().notNull().unique("publishable_keys_name_key"),
|
|
253
|
-
/** JSON array of allowed origins. */
|
|
254
|
-
originsJson: text().notNull(),
|
|
255
|
-
createdAt: text().notNull(),
|
|
256
|
-
revokedAt: text(),
|
|
257
|
-
});
|
|
258
|
-
/**
|
|
259
|
-
* Action endpoints: where the Runtime delivers each agent's Actions over HTTP, and the health
|
|
260
|
-
* recent deliveries and the last ping report.
|
|
261
|
-
*/
|
|
262
|
-
export const endpoints = nylorun.table("endpoints", {
|
|
263
|
-
agentId: textC().primaryKey(),
|
|
264
|
-
url: text().notNull(),
|
|
265
|
-
implementationVersion: text().notNull(),
|
|
266
|
-
manifestHash: text(),
|
|
267
|
-
timeoutMs: integer().notNull(),
|
|
268
|
-
maxConcurrent: integer().notNull(),
|
|
269
|
-
principalId: text(),
|
|
270
|
-
lastDeliveryAt: text(),
|
|
271
|
-
lastSuccessAt: text(),
|
|
272
|
-
lastErrorCode: text(),
|
|
273
|
-
lastErrorMessage: text(),
|
|
274
|
-
consecutiveFailures: integer().notNull().default(0),
|
|
275
|
-
servedImplementationVersion: text(),
|
|
276
|
-
servedManifestHash: text(),
|
|
277
|
-
createdAt: text().notNull(),
|
|
278
|
-
updatedAt: text().notNull(),
|
|
279
|
-
});
|
|
280
231
|
/**
|
|
281
232
|
* The model usage ledger (P1.3): one row per model call a gate served, written after the call.
|
|
282
233
|
* A second row for the same effect (a call the gate ran again after a gateway restart) is
|
|
@@ -287,6 +238,9 @@ export const modelUsage = nylorun.table("model_usage", {
|
|
|
287
238
|
id: textC().primaryKey(),
|
|
288
239
|
/** The model effect's id; unique per Tenant, since it carries the turn id. */
|
|
289
240
|
effectKey: textC().notNull(),
|
|
241
|
+
tokensReported: boolean(),
|
|
242
|
+
costKnown: boolean(),
|
|
243
|
+
txid: xid8().notNull().default(sql `pg_current_xact_id()`),
|
|
290
244
|
sessionId: textC().notNull(),
|
|
291
245
|
turnId: textC().notNull(),
|
|
292
246
|
agentId: textC().notNull(),
|
|
@@ -303,6 +257,8 @@ export const modelUsage = nylorun.table("model_usage", {
|
|
|
303
257
|
duplicate: boolean().notNull(),
|
|
304
258
|
createdAt: text().notNull(),
|
|
305
259
|
}, (t) => [
|
|
260
|
+
index("model_usage_session").on(t.sessionId, t.createdAt, t.id),
|
|
261
|
+
index("model_usage_export").on(t.txid, t.id),
|
|
306
262
|
index("model_usage_effect").on(t.effectKey),
|
|
307
263
|
index("model_usage_agent").on(t.agentId, t.createdAt),
|
|
308
264
|
index("model_usage_turn").on(t.turnId),
|
|
@@ -452,6 +408,33 @@ export const artifactContent = nylorun.table("artifact_content", {
|
|
|
452
408
|
}).onDelete("cascade"),
|
|
453
409
|
index("artifact_content_sha256").on(t.sha256),
|
|
454
410
|
]);
|
|
411
|
+
/**
|
|
412
|
+
* The definition files the Tenant holds (track R2 M4): files a definition names by the SHA-256
|
|
413
|
+
* of their bytes (a skill's folder), uploaded with `PUT /v1/files/sha256:<hex>`. The bytes are
|
|
414
|
+
* in the Object store at `definitions/sha256/<hex>`; a row counts them only once they are
|
|
415
|
+
* stored. `sha256` is `sha256:<hex>`.
|
|
416
|
+
*/
|
|
417
|
+
export const definitionFiles = nylorun.table("definition_files", {
|
|
418
|
+
sha256: textC().primaryKey(),
|
|
419
|
+
/** What the file is part of: `skill` for now. */
|
|
420
|
+
kind: text().notNull(),
|
|
421
|
+
size: bigint({ mode: "number" }).notNull(),
|
|
422
|
+
contentType: text(),
|
|
423
|
+
createdAt: textC().notNull(),
|
|
424
|
+
});
|
|
425
|
+
/**
|
|
426
|
+
* Which definition version names which definition file: one row per agent id, manifest hash
|
|
427
|
+
* and file, written when the definition is stored. A later sweep deletes the files no
|
|
428
|
+
* definition uses.
|
|
429
|
+
*/
|
|
430
|
+
export const definitionFileUses = nylorun.table("definition_file_uses", {
|
|
431
|
+
agentId: textC().notNull(),
|
|
432
|
+
manifestHash: textC().notNull(),
|
|
433
|
+
sha256: textC().notNull(),
|
|
434
|
+
}, (t) => [
|
|
435
|
+
primaryKey({ name: "definition_file_uses_pkey", columns: [t.agentId, t.manifestHash, t.sha256] }),
|
|
436
|
+
index("definition_file_uses_sha256").on(t.sha256),
|
|
437
|
+
]);
|
|
455
438
|
// ---------------------------------------------------------------------------
|
|
456
439
|
// nylorun_streams: the record
|
|
457
440
|
/**
|