@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
|
@@ -17,11 +17,6 @@
|
|
|
17
17
|
* - `<prefix>NylorunTimer`, key `<tenantId>:<timer key>`. `set` records the
|
|
18
18
|
* latest time and sends a delayed `fire`; a `fire` for an older time is a
|
|
19
19
|
* no-op, which is how setting a key again replaces it.
|
|
20
|
-
* - `<prefix>NylorunAction`, key `<tenantId>:<actionId>`. Its exclusive
|
|
21
|
-
* `deliver` handler calls `WorkerHandlers.deliver`. Like `advance`, it keeps
|
|
22
|
-
* no state and makes no `ctx.run`: its only journal entry is the delayed
|
|
23
|
-
* self-send after a `retry` result, so an endpoint that is down never spends
|
|
24
|
-
* the retry budget, which is for infrastructure errors.
|
|
25
20
|
* - `<prefix>NylorunSandbox`, key `<tenantId>:<sandboxId>` (F7.2). Its
|
|
26
21
|
* exclusive handlers serialize a pod sandbox's reconciles and timers:
|
|
27
22
|
* `reconcile` calls `WorkerHandlers.sandbox`; `arm` records a timer's latest
|
|
@@ -29,7 +24,7 @@
|
|
|
29
24
|
* `fire`; a `fire` for an older time is a no-op, as the timer object's.
|
|
30
25
|
* What a run answers arms its timers and its retry.
|
|
31
26
|
*
|
|
32
|
-
* Wakes,
|
|
27
|
+
* Wakes, sandbox reconciles, timers and sweep arming go through the ingress as one-way
|
|
33
28
|
* sends, so an API node can call them without ever calling `start`.
|
|
34
29
|
*/
|
|
35
30
|
import { createServer } from "node:http2";
|
|
@@ -60,7 +55,6 @@ export class RestateExecution {
|
|
|
60
55
|
session: `${prefix}NylorunSession`,
|
|
61
56
|
tenant: `${prefix}NylorunTenant`,
|
|
62
57
|
timer: `${prefix}NylorunTimer`,
|
|
63
|
-
action: `${prefix}NylorunAction`,
|
|
64
58
|
sandbox: `${prefix}NylorunSandbox`,
|
|
65
59
|
};
|
|
66
60
|
this.ingressUrl = options.ingressUrl.replace(/\/+$/, "");
|
|
@@ -76,9 +70,6 @@ export class RestateExecution {
|
|
|
76
70
|
throw new Error(`Unknown wake reason: ${String(wake.reason)}`);
|
|
77
71
|
await this.send(this.names.session, sessionKey(tenantId, sessionId), "advance", { reason: wake.reason }, wake.dedupeKey);
|
|
78
72
|
}
|
|
79
|
-
async deliver(tenantId, actionId) {
|
|
80
|
-
await this.send(this.names.action, sessionKey(tenantId, actionId), "deliver", {});
|
|
81
|
-
}
|
|
82
73
|
async sandbox(tenantId, sandboxId, signal) {
|
|
83
74
|
const key = sessionKey(tenantId, sandboxId);
|
|
84
75
|
if (signal.kind === "reconcile")
|
|
@@ -259,24 +250,6 @@ export class RestateExecution {
|
|
|
259
250
|
},
|
|
260
251
|
options: serviceOptions,
|
|
261
252
|
});
|
|
262
|
-
const action = restate.object({
|
|
263
|
-
name: names.action,
|
|
264
|
-
handlers: {
|
|
265
|
-
deliver: async (ctx, _input) => {
|
|
266
|
-
const { tenantId, sessionId: actionId } = parseSessionKey(ctx.key);
|
|
267
|
-
const result = await this.runAborted(ctx.request().attemptCompletedSignal, (handlers, signal) => {
|
|
268
|
-
if (!handlers.deliver)
|
|
269
|
-
throw new Error("WorkerHandlers.deliver is required for deliveries");
|
|
270
|
-
return handlers.deliver(tenantId, actionId, signal);
|
|
271
|
-
});
|
|
272
|
-
if (result.status === "retry")
|
|
273
|
-
ctx
|
|
274
|
-
.objectSendClient({ name: names.action }, ctx.key)
|
|
275
|
-
.deliver({}, restate.rpc.sendOpts({ delay: Math.max(0, result.retryAfterMs) }));
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
options: serviceOptions,
|
|
279
|
-
});
|
|
280
253
|
/** Sets a sandbox timer: the latest time wins; `fire` checks it. */
|
|
281
254
|
const armSandbox = async (ctx, input) => {
|
|
282
255
|
ctx.set(`at:${input.timer}`, input.at);
|
|
@@ -318,11 +291,11 @@ export class RestateExecution {
|
|
|
318
291
|
},
|
|
319
292
|
options: serviceOptions,
|
|
320
293
|
});
|
|
321
|
-
return [session, tenant, timer,
|
|
294
|
+
return [session, tenant, timer, sandbox];
|
|
322
295
|
}
|
|
323
296
|
/**
|
|
324
297
|
* Runs a Worker handler with a signal aborted by `stop` or by the end of the Restate
|
|
325
|
-
* attempt (`advance` and `
|
|
298
|
+
* attempt (`advance` and `reconcile`).
|
|
326
299
|
*/
|
|
327
300
|
async runAborted(attemptDone, fn) {
|
|
328
301
|
const controller = new AbortController();
|
|
@@ -424,7 +397,7 @@ export async function listStuckInvocations(options) {
|
|
|
424
397
|
const prefix = options.servicePrefix ?? "";
|
|
425
398
|
if (!/^[A-Za-z0-9_]*$/.test(prefix))
|
|
426
399
|
throw new Error(`Invalid Restate service prefix: ${prefix}`);
|
|
427
|
-
const services = ["NylorunSession", "NylorunTenant", "NylorunTimer", "
|
|
400
|
+
const services = ["NylorunSession", "NylorunTenant", "NylorunTimer", "NylorunSandbox"].map((name) => `'${prefix}${name}'`);
|
|
428
401
|
const clauses = [
|
|
429
402
|
`target_service_name IN (${services.join(", ")})`,
|
|
430
403
|
`status IN ('paused', 'backing-off')`,
|
|
@@ -146,7 +146,7 @@ export function createPgoutputSource(options) {
|
|
|
146
146
|
},
|
|
147
147
|
async lag() {
|
|
148
148
|
// An idle relay confirms one byte past the last record, ahead of pg_current_wal_lsn():
|
|
149
|
-
// that is no lag, not -1
|
|
149
|
+
// that is no lag, not -1.
|
|
150
150
|
const { rows } = await pool.query(`SELECT GREATEST(pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn), 0)::text AS lag
|
|
151
151
|
FROM pg_replication_slots WHERE slot_name = $1`, [slot]);
|
|
152
152
|
return rows[0]?.lag == null ? undefined : Number(rows[0].lag);
|
|
@@ -164,7 +164,7 @@ export function localBackend(options) {
|
|
|
164
164
|
return { entries, truncated: !complete };
|
|
165
165
|
},
|
|
166
166
|
async writeFile(path, content) {
|
|
167
|
-
await writeFile(path, content, "utf8");
|
|
167
|
+
await (typeof content === "string" ? writeFile(path, content, "utf8") : writeFile(path, content));
|
|
168
168
|
},
|
|
169
169
|
async stop() { },
|
|
170
170
|
};
|
|
@@ -140,7 +140,7 @@ export function virtualBackend(options) {
|
|
|
140
140
|
return { entries, truncated: !complete };
|
|
141
141
|
},
|
|
142
142
|
async writeFile(path, content) {
|
|
143
|
-
await fs.writeFile(path, content, "utf8");
|
|
143
|
+
await (typeof content === "string" ? fs.writeFile(path, content, "utf8") : fs.writeFile(path, content));
|
|
144
144
|
},
|
|
145
145
|
async stop() { },
|
|
146
146
|
};
|
|
@@ -29,7 +29,6 @@ function registerComponents(api) {
|
|
|
29
29
|
const FOR_A_PERSON = {
|
|
30
30
|
credentials: ["subject", "token"],
|
|
31
31
|
scopes: ["sessions:own"],
|
|
32
|
-
browser: true,
|
|
33
32
|
};
|
|
34
33
|
const events = (description) => ({
|
|
35
34
|
description,
|
|
@@ -50,7 +49,7 @@ export function agUiRoutes(api) {
|
|
|
50
49
|
path: "/v1/ag-ui/agents/{agentId}",
|
|
51
50
|
tags: TAGS,
|
|
52
51
|
summary: "Run an agent",
|
|
53
|
-
description: "For a person, named by a
|
|
52
|
+
description: "For a person, named by a trusted issuer's token or by `Nylorun-Subject`. The thread is one session per person, agent and thread, created on its first run with `forwardedProps.nylorun.session`. The trailing user message starts a turn (its id is the idempotency key); `resume` answers interrupts. A busy session is a `RUN_ERROR` in the stream.",
|
|
54
53
|
request: {
|
|
55
54
|
params: agentId,
|
|
56
55
|
body: {
|
|
@@ -2,7 +2,7 @@ import type { ServerResponse } from "node:http";
|
|
|
2
2
|
import { type Message } from "@ag-ui/core";
|
|
3
3
|
import { type AuthScope, type SessionAccess, type TenantContext } from "../../tenant/context.js";
|
|
4
4
|
/**
|
|
5
|
-
* Who an AG-UI request acts for, once its agent is known: a person (
|
|
5
|
+
* Who an AG-UI request acts for, once its agent is known: a person (an issuer token's subject,
|
|
6
6
|
* or `Nylorun-Subject`), who may use the agent; else 400, or the 404 of a missing agent.
|
|
7
7
|
*/
|
|
8
8
|
export declare function agUiCaller(scope: AuthScope, agentId: string): {
|
package/dist/api/ag-ui/routes.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The Runtime's AG-UI endpoint (Host feature `ag-ui-endpoint`): the Tenant's agents served to
|
|
3
|
-
* AG-UI clients, for a person named by a
|
|
3
|
+
* AG-UI clients, for a person named by a trusted issuer's token (a browser or app) or by subject headers
|
|
4
4
|
* (an app server's `createAgUiHandler`, which forwards here). One implementation for both, so
|
|
5
5
|
* a thread is the same session whichever way it is reached.
|
|
6
6
|
*
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
* idempotency key, approvals become interrupts resumed through `resume`, and the last AG-UI
|
|
16
16
|
* event made from each Runtime event carries its cursor as the SSE id. A run's session is
|
|
17
17
|
* created on its first run with the options in `forwardedProps.nylorun.session` and never
|
|
18
|
-
* changed afterwards. A stream opened with
|
|
19
|
-
*
|
|
18
|
+
* changed afterwards. A stream opened with an issuer token ends at the token's expiry with
|
|
19
|
+
* `CUSTOM nylorun.stream_closed`, and the client reattaches with a new token.
|
|
20
20
|
*/
|
|
21
21
|
import { randomUUID } from "node:crypto";
|
|
22
22
|
import { EventType, } from "@ag-ui/core";
|
|
@@ -30,9 +30,9 @@ import { accessOf } from "../../tenant/auth.js";
|
|
|
30
30
|
import { command } from "../../tenant/commands.js";
|
|
31
31
|
import { loadSession, sessionOf, } from "../../tenant/context.js";
|
|
32
32
|
import { fail, HttpError } from "../../tenant/http.js";
|
|
33
|
-
import { observeSession, readHistory, StreamClosed, } from "../../tenant/session-streams.js";
|
|
33
|
+
import { observeSession, readHistory, StreamClosed, streamHolderOf, } from "../../tenant/session-streams.js";
|
|
34
34
|
import { putSession, sessionView } from "../../tenant/sessions.js";
|
|
35
|
-
import { mayUseAgent } from "../../tenant/
|
|
35
|
+
import { mayUseAgent } from "../../tenant/auth.js";
|
|
36
36
|
import { sandboxGrantsOf } from "../../tenant/sandboxes.js";
|
|
37
37
|
const HEARTBEAT_MS = 15_000;
|
|
38
38
|
const TERMINAL = new Set([
|
|
@@ -41,16 +41,14 @@ const TERMINAL = new Set([
|
|
|
41
41
|
"turn.failed",
|
|
42
42
|
"turn.cancelled",
|
|
43
43
|
]);
|
|
44
|
-
/** The person a request acts for:
|
|
44
|
+
/** The person a request acts for: an issuer token's subject, or `Nylorun-Subject`. */
|
|
45
45
|
function personOf(scope) {
|
|
46
46
|
if (scope.kind === "token" || scope.kind === "subject")
|
|
47
47
|
return scope.subject;
|
|
48
|
-
return fail(400, "AG-UI runs act for a person: send a
|
|
48
|
+
return fail(400, "AG-UI runs act for a person: send a trusted issuer's token, or Nylorun-Subject with the application key", { code: "invalid_request" });
|
|
49
49
|
}
|
|
50
50
|
function holderOf(scope) {
|
|
51
|
-
return scope
|
|
52
|
-
? { subject: scope.subject, epoch: scope.epoch, expiresAt: scope.expiresAt }
|
|
53
|
-
: undefined;
|
|
51
|
+
return streamHolderOf(scope);
|
|
54
52
|
}
|
|
55
53
|
/** A refusal a client can act on, streamed as `RUN_ERROR` rather than an HTTP error. */
|
|
56
54
|
function runError(error) {
|
|
@@ -96,7 +94,7 @@ function sessionOptions(input, scope) {
|
|
|
96
94
|
});
|
|
97
95
|
// Agent code may trust `info`: only an app server sets it.
|
|
98
96
|
if (scope.kind === "token" && parsed.data.info !== undefined)
|
|
99
|
-
return fail(403, "A
|
|
97
|
+
return fail(403, "A token caller cannot set session info", {
|
|
100
98
|
code: "scope_required",
|
|
101
99
|
});
|
|
102
100
|
return parsed.data;
|
|
@@ -220,7 +218,7 @@ async function historyFrom(ctx, id, cursor) {
|
|
|
220
218
|
return items;
|
|
221
219
|
}
|
|
222
220
|
/**
|
|
223
|
-
* Who an AG-UI request acts for, once its agent is known: a person (
|
|
221
|
+
* Who an AG-UI request acts for, once its agent is known: a person (an issuer token's subject,
|
|
224
222
|
* or `Nylorun-Subject`), who may use the agent; else 400, or the 404 of a missing agent.
|
|
225
223
|
*/
|
|
226
224
|
export function agUiCaller(scope, agentId) {
|
|
@@ -236,7 +234,7 @@ export async function startRun(ctx, scope, agentId, caller, body, response) {
|
|
|
236
234
|
if (!parsed.success)
|
|
237
235
|
return fail(400, "Invalid RunAgentInput", { code: "invalid_request" });
|
|
238
236
|
const input = parsed.data;
|
|
239
|
-
// Nylorun tools run in the Runtime
|
|
237
|
+
// Nylorun tools run in the Runtime (HTTP, MCP and built-in tools); the browser runs none.
|
|
240
238
|
if (input.tools?.length)
|
|
241
239
|
return fail(400, "Frontend tools are not supported", { code: "invalid_request" });
|
|
242
240
|
const id = sessionIdFor(caller.subject, agentId, input.threadId);
|
|
@@ -13,7 +13,7 @@ export interface Step {
|
|
|
13
13
|
readonly events: BaseEvent[];
|
|
14
14
|
readonly finished: boolean;
|
|
15
15
|
}
|
|
16
|
-
/** A tool result from
|
|
16
|
+
/** A tool result from either of the two places a call can end. */
|
|
17
17
|
export declare function toolResultOf(event: TranscriptEvent): {
|
|
18
18
|
callId: string;
|
|
19
19
|
content: string;
|
|
@@ -21,8 +21,6 @@ export declare function toolResultOf(event: TranscriptEvent): {
|
|
|
21
21
|
export declare class RunTranslator {
|
|
22
22
|
private readonly threadId;
|
|
23
23
|
private readonly runId;
|
|
24
|
-
/** Tool invocation → the model's call id, for interrupts that name the invocation. */
|
|
25
|
-
private readonly callIds;
|
|
26
24
|
private readonly closed;
|
|
27
25
|
private sawAssistant;
|
|
28
26
|
/**
|
|
@@ -24,16 +24,9 @@ export function outputText(output) {
|
|
|
24
24
|
return typeof output === "string" ? output : JSON.stringify(output);
|
|
25
25
|
}
|
|
26
26
|
const none = { events: [], finished: false };
|
|
27
|
-
/** A tool result from
|
|
27
|
+
/** A tool result from either of the two places a call can end. */
|
|
28
28
|
export function toolResultOf(event) {
|
|
29
29
|
switch (event.type) {
|
|
30
|
-
case "action.completed": {
|
|
31
|
-
const p = event.payload;
|
|
32
|
-
if (p.kind !== "tool" || !p.callId || p.agent)
|
|
33
|
-
return undefined;
|
|
34
|
-
const content = toolResultText(p.result);
|
|
35
|
-
return content === undefined ? undefined : { callId: p.callId, content };
|
|
36
|
-
}
|
|
37
30
|
case "tool.completed": {
|
|
38
31
|
const p = event.payload;
|
|
39
32
|
if (p.agent)
|
|
@@ -60,8 +53,6 @@ export function toolResultOf(event) {
|
|
|
60
53
|
export class RunTranslator {
|
|
61
54
|
threadId;
|
|
62
55
|
runId;
|
|
63
|
-
/** Tool invocation → the model's call id, for interrupts that name the invocation. */
|
|
64
|
-
callIds = new Map();
|
|
65
56
|
closed = new Set();
|
|
66
57
|
sawAssistant;
|
|
67
58
|
/**
|
|
@@ -77,11 +68,6 @@ export class RunTranslator {
|
|
|
77
68
|
const event = parseTranscriptEvent(raw);
|
|
78
69
|
if (!event)
|
|
79
70
|
return none;
|
|
80
|
-
if (event.type === "action.pending" || event.type === "action.completed") {
|
|
81
|
-
const { callId, invocationId } = event.payload;
|
|
82
|
-
if (callId && invocationId)
|
|
83
|
-
this.callIds.set(invocationId, callId);
|
|
84
|
-
}
|
|
85
71
|
const result = toolResultOf(event);
|
|
86
72
|
if (result) {
|
|
87
73
|
if (this.closed.has(result.callId))
|
|
@@ -122,7 +108,7 @@ export class RunTranslator {
|
|
|
122
108
|
case "turn.paused": {
|
|
123
109
|
const interrupts = event.payload.interactions.map((w) => {
|
|
124
110
|
const interaction = w.interaction;
|
|
125
|
-
const toolCallId =
|
|
111
|
+
const toolCallId = w.callId;
|
|
126
112
|
return {
|
|
127
113
|
id: interaction.id,
|
|
128
114
|
reason: interaction.kind === "approval" ? "tool_approval" : "input_required",
|
|
@@ -163,7 +149,6 @@ export class RunTranslator {
|
|
|
163
149
|
};
|
|
164
150
|
}
|
|
165
151
|
case "effect.uncertain":
|
|
166
|
-
case "action.uncertain":
|
|
167
152
|
// The Runtime cannot tell whether a side effect happened; the run goes on.
|
|
168
153
|
return {
|
|
169
154
|
events: [
|