@nylorun/agents 0.13.0-beta → 0.16.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 +139 -0
- package/README.md +220 -235
- package/dist/access.d.ts +6 -97
- package/dist/access.js +1 -103
- package/dist/ag-ui/handler.d.ts +3 -6
- package/dist/ag-ui/handler.js +2 -2
- package/dist/artifacts.d.ts +1 -1
- package/dist/files.d.ts +31 -0
- package/dist/files.js +60 -0
- package/dist/http.d.ts +6 -13
- package/dist/http.js +4 -16
- package/dist/index.d.ts +8 -16
- package/dist/index.js +4 -7
- package/dist/plugins/load.d.ts +3 -2
- package/dist/plugins/load.js +40 -100
- package/dist/plugins/plugin.d.ts +6 -1
- package/dist/plugins/plugin.js +20 -7
- package/dist/reads.d.ts +17 -0
- package/dist/reads.js +17 -0
- package/dist/sandboxes.d.ts +29 -0
- package/dist/sandboxes.js +10 -1
- package/dist/session-client.d.ts +94 -112
- package/dist/session-client.js +80 -107
- package/dist/skills/index.d.ts +1 -1
- package/dist/skills/load.d.ts +14 -3
- package/dist/skills/load.js +50 -32
- package/dist/skills/skills.d.ts +6 -4
- package/dist/skills/skills.js +17 -10
- package/dist/sse.js +1 -1
- package/dist/studio-embed.d.ts +1 -1
- package/dist/studio-embed.js +1 -1
- package/package.json +3 -7
- package/dist/action-handler.d.ts +0 -63
- package/dist/action-handler.js +0 -279
- package/dist/browser.d.ts +0 -104
- package/dist/browser.js +0 -281
- package/dist/delivery-token.d.ts +0 -62
- package/dist/delivery-token.js +0 -159
- package/dist/execute-action.d.ts +0 -16
- package/dist/execute-action.js +0 -288
- package/dist/plugins/launch.d.ts +0 -17
- package/dist/plugins/launch.js +0 -71
- package/dist/sandbox/client.d.ts +0 -63
- package/dist/sandbox/client.js +0 -29
- package/dist/sandbox/index.d.ts +0 -2
- package/dist/sandbox/index.js +0 -1
- package/dist/served-definitions.d.ts +0 -20
- package/dist/served-definitions.js +0 -100
- package/dist/token-endpoint.d.ts +0 -23
- package/dist/token-endpoint.js +0 -30
package/dist/action-handler.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { type EndpointPingResponse } from "@nylorun/core/contracts";
|
|
2
|
-
import type { BuiltWorkflow } from "@nylorun/core/define";
|
|
3
|
-
import { toNodeListener } from "./ag-ui/node.js";
|
|
4
|
-
import { type AgentSource, type AgentsClient } from "./client.js";
|
|
5
|
-
export interface ActionHandlerOptions {
|
|
6
|
-
/** The agents and workflows this endpoint serves. Agents they embed are served too. */
|
|
7
|
-
agents: readonly (AgentSource | BuiltWorkflow)[];
|
|
8
|
-
/**
|
|
9
|
-
* Application client, used by `register` (and, when `runtime` is not set, to read the
|
|
10
|
-
* Tenant's public keys). Default: `createClient()`, from the environment or the Project link.
|
|
11
|
-
*/
|
|
12
|
-
client?: AgentsClient | Promise<AgentsClient>;
|
|
13
|
-
/**
|
|
14
|
-
* Where to read the Tenant's public keys without a key. Set it for a process that only
|
|
15
|
-
* serves Actions and holds no application key.
|
|
16
|
-
*/
|
|
17
|
-
runtime?: {
|
|
18
|
-
url: string;
|
|
19
|
-
fetch?: typeof fetch;
|
|
20
|
-
};
|
|
21
|
-
/** The Tenant's public keys, instead of reading them from the Runtime. */
|
|
22
|
-
jwks?: {
|
|
23
|
-
keys: readonly JsonWebKey[];
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The URL the Runtime calls, as registered. Every delivery token must name it. Default: the
|
|
27
|
-
* URL passed to `register` in this process; until then, any URL of the Tenant.
|
|
28
|
-
*/
|
|
29
|
-
url?: string;
|
|
30
|
-
/** Registered with each endpoint. Default: `NYLORUN_IMPLEMENTATION_VERSION`, else `dev`. */
|
|
31
|
-
implementationVersion?: string;
|
|
32
|
-
/** Receives errors that are answered with a status instead of thrown. */
|
|
33
|
-
onError?: (error: unknown) => void;
|
|
34
|
-
/**
|
|
35
|
-
* Keeps the process alive for a background tool's work after its `202` answer, on platforms
|
|
36
|
-
* that end a request's work with its response (for example a serverless platform's
|
|
37
|
-
* `waitUntil`). A Node server needs nothing.
|
|
38
|
-
*/
|
|
39
|
-
waitUntil?: (work: Promise<unknown>) => void;
|
|
40
|
-
}
|
|
41
|
-
export interface RegisterOptions {
|
|
42
|
-
/** The URL the Runtime calls, e.g. `http://localhost:3000/nylorun/actions`. */
|
|
43
|
-
url: string;
|
|
44
|
-
/** Save the definitions first. Default true. */
|
|
45
|
-
saveDefinitions?: boolean;
|
|
46
|
-
/** How long one inline delivery may take, in milliseconds. */
|
|
47
|
-
timeoutMs?: number;
|
|
48
|
-
/** In-flight deliveries per agent. */
|
|
49
|
-
maxConcurrent?: number;
|
|
50
|
-
signal?: AbortSignal;
|
|
51
|
-
}
|
|
52
|
-
export interface ActionHandler {
|
|
53
|
-
/** A web-standard handler: Hono, Next.js route handlers, Workers, Bun, Deno. */
|
|
54
|
-
fetch(request: Request): Promise<Response>;
|
|
55
|
-
/** The same handler for `node:http` and Express. */
|
|
56
|
-
readonly node: ReturnType<typeof toNodeListener>;
|
|
57
|
-
/**
|
|
58
|
-
* Saves the definitions, points the Runtime at `url` for every served agent and pings each
|
|
59
|
-
* one through the Runtime, so a wrong URL or a tunnel that is down fails here.
|
|
60
|
-
*/
|
|
61
|
-
register(options: RegisterOptions): Promise<EndpointPingResponse[]>;
|
|
62
|
-
}
|
|
63
|
-
export declare function createActionHandler(options: ActionHandlerOptions): ActionHandler;
|
package/dist/action-handler.js
DELETED
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An Action endpoint (design: Action endpoints): the application mounts this handler at a URL
|
|
3
|
-
* and registers the URL; the Runtime POSTs each Action for the served agents to it and records
|
|
4
|
-
* the answer as the Action's outcome. No stream, no claim, no key needed to serve.
|
|
5
|
-
*
|
|
6
|
-
* Each request is checked before any code runs: the delivery token must be signed by the
|
|
7
|
-
* Tenant's signing key, be for this Tenant, this URL (once known), this Action and this
|
|
8
|
-
* generation, and cover the exact body. The Action then runs through `executeAction`, with the
|
|
9
|
-
* request's signal as `ctx.signal`.
|
|
10
|
-
*/
|
|
11
|
-
import { OUTCOME_HEADER, SIGNATURE_HEADER, } from "@nylorun/core/compatibility";
|
|
12
|
-
import { ActionDeliverySchema, DeliveryHeartbeatResponseSchema, EndpointPingResponseSchema, PutEndpointsRequestSchema, } from "@nylorun/core/contracts";
|
|
13
|
-
import { toNodeListener } from "./ag-ui/node.js";
|
|
14
|
-
import { createClient } from "./client.js";
|
|
15
|
-
import { DeliveryVerificationError, JwksCache, verifyDeliveryToken, } from "./delivery-token.js";
|
|
16
|
-
import { executeAction, runsInBackground, } from "./execute-action.js";
|
|
17
|
-
import { RuntimeError, Transport, delay, segment } from "./http.js";
|
|
18
|
-
import { createActionSandbox } from "./sandbox/client.js";
|
|
19
|
-
import { buildAgents, embeddedIn, flowManifestHash, implementationVersionOf, } from "./served-definitions.js";
|
|
20
|
-
/** The Host feature `register` needs. */
|
|
21
|
-
const REQUIRED_FEATURE = "action-endpoints";
|
|
22
|
-
export function createActionHandler(options) {
|
|
23
|
-
const agents = buildAgents(options.agents, "createActionHandler");
|
|
24
|
-
const version = implementationVersionOf(options);
|
|
25
|
-
let client;
|
|
26
|
-
const clientOf = () => (client ??= Promise.resolve(options.client ?? createClient()));
|
|
27
|
-
let audience = options.url;
|
|
28
|
-
let verification;
|
|
29
|
-
const verificationOf = () => (verification ??= resolveVerification(options, clientOf)).catch((error) => {
|
|
30
|
-
verification = undefined;
|
|
31
|
-
throw error;
|
|
32
|
-
});
|
|
33
|
-
let callbacks;
|
|
34
|
-
const report = (error) => {
|
|
35
|
-
try {
|
|
36
|
-
options.onError?.(error);
|
|
37
|
-
}
|
|
38
|
-
catch { }
|
|
39
|
-
};
|
|
40
|
-
const handle = async (request) => {
|
|
41
|
-
if (request.method !== "POST")
|
|
42
|
-
return answer(405, "method_not_allowed", "An Action endpoint accepts POST only");
|
|
43
|
-
const body = new Uint8Array(await request.arrayBuffer());
|
|
44
|
-
const { url, fetch, keys } = await verificationOf();
|
|
45
|
-
const token = request.headers.get(SIGNATURE_HEADER);
|
|
46
|
-
let claims;
|
|
47
|
-
try {
|
|
48
|
-
claims = await verifyDeliveryToken(token, {
|
|
49
|
-
keys: keys.lookup,
|
|
50
|
-
body,
|
|
51
|
-
...(audience === undefined ? {} : { audience }),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
if (!(error instanceof DeliveryVerificationError))
|
|
56
|
-
throw error;
|
|
57
|
-
// A key this endpoint has not seen yet (a rotation within the refetch interval) is not
|
|
58
|
-
// a refusal: the Runtime retries a 503, while a 401 would fail the Action.
|
|
59
|
-
return answer(error.code === "key_unknown" ? 503 : 401, error.code, error.message);
|
|
60
|
-
}
|
|
61
|
-
let delivery;
|
|
62
|
-
try {
|
|
63
|
-
delivery = ActionDeliverySchema.parse(JSON.parse(new TextDecoder().decode(body)));
|
|
64
|
-
}
|
|
65
|
-
catch {
|
|
66
|
-
return answer(400, "invalid_delivery", "The body is not an Action delivery");
|
|
67
|
-
}
|
|
68
|
-
if (delivery.type === "ping") {
|
|
69
|
-
if (claims.sub !== "ping" || claims.agt !== delivery.agentId)
|
|
70
|
-
return answer(401, "signature_invalid", "The token is for another delivery");
|
|
71
|
-
const agent = agents.get(delivery.agentId);
|
|
72
|
-
if (!agent)
|
|
73
|
-
return notServed(delivery.agentId);
|
|
74
|
-
const manifestHash = flowManifestHash(agent);
|
|
75
|
-
return Response.json({
|
|
76
|
-
agentId: agent.id,
|
|
77
|
-
implementationVersion: version,
|
|
78
|
-
...(manifestHash === undefined ? {} : { manifestHash }),
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
const { action } = delivery;
|
|
82
|
-
if (claims.sub !== action.actionId ||
|
|
83
|
-
claims.gen !== action.generation ||
|
|
84
|
-
claims.agt !== action.agentId)
|
|
85
|
-
return answer(401, "signature_invalid", "The token is for another delivery");
|
|
86
|
-
const agent = agents.get(action.agentId);
|
|
87
|
-
if (!agent)
|
|
88
|
-
return notServed(action.agentId);
|
|
89
|
-
const served = flowManifestHash(agent);
|
|
90
|
-
if (served !== undefined && "key" in action && action.manifestHash !== served)
|
|
91
|
-
return answer(409, "version_mismatch", `Action ${action.actionId} belongs to manifest ${action.manifestHash} of '${action.agentId}'; this endpoint serves ${served}`);
|
|
92
|
-
if (runsInBackground(action, agent)) {
|
|
93
|
-
const work = runInBackground({
|
|
94
|
-
action,
|
|
95
|
-
agent,
|
|
96
|
-
token: token,
|
|
97
|
-
sandbox: delivery.sandbox,
|
|
98
|
-
runtime: { url, ...(fetch ? { fetch } : {}) },
|
|
99
|
-
report,
|
|
100
|
-
});
|
|
101
|
-
options.waitUntil?.(work);
|
|
102
|
-
return new Response(null, { status: 202 });
|
|
103
|
-
}
|
|
104
|
-
const sandbox = delivery.sandbox
|
|
105
|
-
? createActionSandbox({
|
|
106
|
-
transport: (callbacks = callbacks
|
|
107
|
-
? callbacks.withKey(token)
|
|
108
|
-
: new Transport({ url, key: token, ...(fetch ? { fetch } : {}) })),
|
|
109
|
-
actionId: action.actionId,
|
|
110
|
-
signal: request.signal,
|
|
111
|
-
})
|
|
112
|
-
: undefined;
|
|
113
|
-
try {
|
|
114
|
-
const outcome = await executeAction(action, agent, request.signal, {
|
|
115
|
-
...(sandbox ? { sandbox } : {}),
|
|
116
|
-
});
|
|
117
|
-
return Response.json(outcome, { headers: { [OUTCOME_HEADER]: "1" } });
|
|
118
|
-
}
|
|
119
|
-
catch (error) {
|
|
120
|
-
if (request.signal.aborted)
|
|
121
|
-
return answer(503, "aborted", "The Runtime closed the delivery");
|
|
122
|
-
// Tool errors are outcomes; a throw means this endpoint cannot run the Action at all.
|
|
123
|
-
report(error);
|
|
124
|
-
return answer(404, "action_not_served", error instanceof Error ? error.message : String(error));
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const fetchHandler = async (request) => {
|
|
128
|
-
try {
|
|
129
|
-
return await handle(request);
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
report(error);
|
|
133
|
-
// Not run: the Runtime retries a 503 whatever the Action's kind.
|
|
134
|
-
return answer(503, "endpoint_unavailable", error instanceof Error ? error.message : String(error));
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
return {
|
|
138
|
-
fetch: fetchHandler,
|
|
139
|
-
node: toNodeListener({ fetch: fetchHandler }),
|
|
140
|
-
async register(register) {
|
|
141
|
-
const application = await clientOf();
|
|
142
|
-
const { transport } = application;
|
|
143
|
-
await transport.requireFeature(REQUIRED_FEATURE, register.signal);
|
|
144
|
-
if (register.saveDefinitions ?? true) {
|
|
145
|
-
const embedded = embeddedIn(agents);
|
|
146
|
-
for (const agent of agents.values())
|
|
147
|
-
if (!embedded.has(agent.id))
|
|
148
|
-
await application.saveAgent(agent, { implementationVersion: version });
|
|
149
|
-
}
|
|
150
|
-
const endpoints = [...agents.values()].map((agent) => {
|
|
151
|
-
const manifestHash = flowManifestHash(agent);
|
|
152
|
-
return {
|
|
153
|
-
agentId: agent.id,
|
|
154
|
-
url: register.url,
|
|
155
|
-
implementationVersion: version,
|
|
156
|
-
...(manifestHash === undefined ? {} : { manifestHash }),
|
|
157
|
-
...(register.timeoutMs === undefined ? {} : { timeoutMs: register.timeoutMs }),
|
|
158
|
-
...(register.maxConcurrent === undefined
|
|
159
|
-
? {}
|
|
160
|
-
: { maxConcurrent: register.maxConcurrent }),
|
|
161
|
-
};
|
|
162
|
-
});
|
|
163
|
-
await transport.json("/v1/endpoints", "PUT", PutEndpointsRequestSchema.parse({ endpoints }), register.signal);
|
|
164
|
-
audience = register.url;
|
|
165
|
-
const answers = [];
|
|
166
|
-
for (const agent of agents.values())
|
|
167
|
-
answers.push(EndpointPingResponseSchema.parse(await transport.json(`/v1/endpoints/${segment(agent.id)}/ping`, "POST", {}, register.signal)));
|
|
168
|
-
return answers;
|
|
169
|
-
},
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
/** How long a background tool waits before its first heartbeat, and after a failed one. */
|
|
173
|
-
const HEARTBEAT_RETRY_MS = 1_000;
|
|
174
|
-
/**
|
|
175
|
-
* A background tool (`ToolDefinition.background`): runs after the `202` answer, heartbeats on
|
|
176
|
-
* the deadline the Runtime returns, stops when a heartbeat answers `409` (cancelled, lost or
|
|
177
|
-
* sent again), and posts its outcome. Every callback uses the newest delivery token.
|
|
178
|
-
*/
|
|
179
|
-
async function runInBackground(input) {
|
|
180
|
-
const { action, report } = input;
|
|
181
|
-
let current = new Transport({ ...input.runtime, key: input.token });
|
|
182
|
-
const live = {
|
|
183
|
-
json: (...args) => current.json(...args),
|
|
184
|
-
};
|
|
185
|
-
const path = `/v1/actions/${segment(action.actionId)}`;
|
|
186
|
-
const stop = new AbortController();
|
|
187
|
-
const done = new AbortController();
|
|
188
|
-
const heartbeats = (async () => {
|
|
189
|
-
let wait = HEARTBEAT_RETRY_MS;
|
|
190
|
-
while (!done.signal.aborted && !stop.signal.aborted) {
|
|
191
|
-
try {
|
|
192
|
-
await delay(wait, done.signal);
|
|
193
|
-
}
|
|
194
|
-
catch {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
try {
|
|
198
|
-
const renewed = DeliveryHeartbeatResponseSchema.parse(await current.json(`${path}/heartbeat`, "POST", undefined, done.signal));
|
|
199
|
-
current = current.withKey(renewed.token);
|
|
200
|
-
wait = Math.max(HEARTBEAT_RETRY_MS, Math.floor((Date.parse(renewed.deadlineAt) - Date.now()) / 3));
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
if (done.signal.aborted)
|
|
204
|
-
return;
|
|
205
|
-
if (error instanceof RuntimeError && error.status === 409) {
|
|
206
|
-
stop.abort(error);
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
report(error);
|
|
210
|
-
wait = HEARTBEAT_RETRY_MS;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
})();
|
|
214
|
-
let outcome;
|
|
215
|
-
try {
|
|
216
|
-
outcome = await executeAction(action, input.agent, stop.signal, {
|
|
217
|
-
...(input.sandbox
|
|
218
|
-
? { sandbox: createActionSandbox({ transport: live, actionId: action.actionId, signal: stop.signal }) }
|
|
219
|
-
: {}),
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
catch (error) {
|
|
223
|
-
// Not served here: say so rather than leave the Runtime waiting for the deadline.
|
|
224
|
-
report(error);
|
|
225
|
-
outcome = {
|
|
226
|
-
value: {
|
|
227
|
-
kind: "failed",
|
|
228
|
-
code: "action_not_served",
|
|
229
|
-
message: error instanceof Error ? error.message : String(error),
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
finally {
|
|
234
|
-
done.abort();
|
|
235
|
-
}
|
|
236
|
-
await heartbeats;
|
|
237
|
-
if (stop.signal.aborted)
|
|
238
|
-
return;
|
|
239
|
-
for (let attempt = 0;; attempt++) {
|
|
240
|
-
try {
|
|
241
|
-
await current.json(`${path}/result`, "POST", outcome);
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
if (attempt >= 4 ||
|
|
246
|
-
(error instanceof RuntimeError && error.status < 500 && error.status !== 429)) {
|
|
247
|
-
report(error);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
await delay(Math.min(4_000, 250 * 2 ** attempt), new AbortController().signal);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
async function resolveVerification(options, clientOf) {
|
|
255
|
-
if (options.runtime) {
|
|
256
|
-
const { url, fetch } = options.runtime;
|
|
257
|
-
return {
|
|
258
|
-
url,
|
|
259
|
-
...(fetch ? { fetch } : {}),
|
|
260
|
-
keys: new JwksCache(options.jwks ?? { url, ...(fetch ? { fetch } : {}) }),
|
|
261
|
-
};
|
|
262
|
-
}
|
|
263
|
-
const { transport } = await clientOf();
|
|
264
|
-
return {
|
|
265
|
-
url: transport.url,
|
|
266
|
-
fetch: transport.fetcher,
|
|
267
|
-
keys: new JwksCache(options.jwks ?? {
|
|
268
|
-
url: transport.url,
|
|
269
|
-
key: transport.key,
|
|
270
|
-
fetch: transport.fetcher,
|
|
271
|
-
}),
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function notServed(agentId) {
|
|
275
|
-
return answer(404, "agent_not_served", `This endpoint does not serve '${agentId}'`);
|
|
276
|
-
}
|
|
277
|
-
function answer(status, code, message) {
|
|
278
|
-
return Response.json({ code, message }, { status });
|
|
279
|
-
}
|
package/dist/browser.d.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import type { CredentialSelection, VaultInfo } from "@nylorun/core/contracts";
|
|
2
|
-
import type { TokenSource } from "./http.js";
|
|
3
|
-
import { AgentsClient, type SessionClient } from "./session-client.js";
|
|
4
|
-
import type { ArtifactsClient } from "./artifacts.js";
|
|
5
|
-
/** What the token callback returns: the token, or the app server's `{ token, expiresAt }`. */
|
|
6
|
-
export type TokenReply = string | {
|
|
7
|
-
token: string;
|
|
8
|
-
expiresAt?: string;
|
|
9
|
-
};
|
|
10
|
-
export interface BrowserClientOptions {
|
|
11
|
-
/** The Runtime's URL, as the page reaches it. */
|
|
12
|
-
url: string;
|
|
13
|
-
/** The Tenant's publishable key for this app (`nr_pub_…`). */
|
|
14
|
-
publishableKey: string;
|
|
15
|
-
/** Returns a subject token for the signed-in person, usually from your app server. */
|
|
16
|
-
token(signal?: AbortSignal): Promise<TokenReply>;
|
|
17
|
-
fetch?: typeof fetch;
|
|
18
|
-
}
|
|
19
|
-
interface Claims {
|
|
20
|
-
sub?: string;
|
|
21
|
-
exp?: number;
|
|
22
|
-
}
|
|
23
|
-
/** The token's claims, read without verifying (the Runtime verifies). */
|
|
24
|
-
export declare function readClaims(token: string): Claims;
|
|
25
|
-
/** A token kept in memory, fetched on demand, one fetch at a time. */
|
|
26
|
-
export declare class CachedToken implements TokenSource {
|
|
27
|
-
private readonly fetchToken;
|
|
28
|
-
private readonly now;
|
|
29
|
-
private current;
|
|
30
|
-
private pending;
|
|
31
|
-
constructor(fetchToken: (signal?: AbortSignal) => Promise<TokenReply>, now?: () => number);
|
|
32
|
-
get(signal?: AbortSignal): Promise<string>;
|
|
33
|
-
invalidate(): void;
|
|
34
|
-
/** The subject of the current token, fetching one if needed. */
|
|
35
|
-
subject(signal?: AbortSignal): Promise<string>;
|
|
36
|
-
}
|
|
37
|
-
/** The signed-in person's view of the Runtime: their sessions and vaults, the agents they may use. */
|
|
38
|
-
export declare class BrowserClient {
|
|
39
|
-
/** The underlying Tenant API client, for anything this class does not wrap. */
|
|
40
|
-
readonly client: AgentsClient;
|
|
41
|
-
readonly url: string;
|
|
42
|
-
readonly publishableKey: string;
|
|
43
|
-
private readonly tokens;
|
|
44
|
-
private readonly fetcher;
|
|
45
|
-
constructor(options: BrowserClientOptions);
|
|
46
|
-
/** The person the tokens are for. */
|
|
47
|
-
subject(signal?: AbortSignal): Promise<string>;
|
|
48
|
-
/** A current token, e.g. for a request this client does not make itself. */
|
|
49
|
-
token(signal?: AbortSignal): Promise<string>;
|
|
50
|
-
/** The agents the person may use: id, name and description. */
|
|
51
|
-
listAgents(signal?: AbortSignal): Promise<{
|
|
52
|
-
agents: {
|
|
53
|
-
agentId: string;
|
|
54
|
-
name?: string;
|
|
55
|
-
description?: string;
|
|
56
|
-
}[];
|
|
57
|
-
}>;
|
|
58
|
-
listSessions(agentId?: string, signal?: AbortSignal): Promise<{
|
|
59
|
-
sessions: import("./session-client.js").SessionView[];
|
|
60
|
-
}>;
|
|
61
|
-
session(sessionId: string): SessionClient;
|
|
62
|
-
/** The person's file artifacts, in their own sessions (protocol 6). */
|
|
63
|
-
get artifacts(): ArtifactsClient;
|
|
64
|
-
/** A session of the person's own; the owner is always the token's subject. */
|
|
65
|
-
createSession(options: {
|
|
66
|
-
id?: string;
|
|
67
|
-
agentId: string;
|
|
68
|
-
vaultIds?: readonly string[];
|
|
69
|
-
credentialSelections?: readonly CredentialSelection[];
|
|
70
|
-
/** A sandbox the token's `sandboxes` grants reach (Host feature `sandboxes`). */
|
|
71
|
-
sandbox?: {
|
|
72
|
-
id: string;
|
|
73
|
-
};
|
|
74
|
-
}): Promise<SessionClient>;
|
|
75
|
-
createVault(options: {
|
|
76
|
-
name: string;
|
|
77
|
-
idempotencyKey: string;
|
|
78
|
-
metadata?: Record<string, string>;
|
|
79
|
-
}): Promise<VaultInfo>;
|
|
80
|
-
listVaults(signal?: AbortSignal): Promise<{
|
|
81
|
-
vaults: VaultInfo[];
|
|
82
|
-
}>;
|
|
83
|
-
/** `fetch` with this client's credentials, retrying once after `401 token_expired`. */
|
|
84
|
-
private send;
|
|
85
|
-
/**
|
|
86
|
-
* For `@ag-ui/client`'s `HttpAgent`: `new HttpAgent({ url, fetch })`. The `fetch` adds the
|
|
87
|
-
* publishable key and a current token, and when the Runtime ends a run's stream because the
|
|
88
|
-
* token expired or was revoked, it reattaches with a new token from the last event, so the
|
|
89
|
-
* agent sees one run.
|
|
90
|
-
*/
|
|
91
|
-
agUi(agentId: string): {
|
|
92
|
-
url: string;
|
|
93
|
-
fetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
94
|
-
};
|
|
95
|
-
/** The thread's messages, for `HttpAgent`'s `initialMessages`. */
|
|
96
|
-
agUiHistory(agentId: string, threadId: string, signal?: AbortSignal): Promise<unknown[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Passes a run's frames through; on `nylorun.stream_closed` before the run finished, fetches
|
|
99
|
-
* the rest from the last event id and continues without repeating `RUN_STARTED`.
|
|
100
|
-
*/
|
|
101
|
-
private stitch;
|
|
102
|
-
}
|
|
103
|
-
export declare function createBrowserClient(options: BrowserClientOptions): BrowserClient;
|
|
104
|
-
export {};
|