@aexhq/sdk 0.33.1 → 0.34.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/README.md +19 -27
- package/dist/_contracts/operations.d.ts +2 -54
- package/dist/_contracts/operations.js +2 -87
- package/dist/_contracts/run-config.d.ts +19 -13
- package/dist/_contracts/run-config.js +6 -33
- package/dist/_contracts/run-unit.d.ts +1 -33
- package/dist/_contracts/run-unit.js +2 -21
- package/dist/_contracts/runtime-sizes.d.ts +2 -2
- package/dist/_contracts/runtime-sizes.js +2 -2
- package/dist/_contracts/status.d.ts +2 -2
- package/dist/_contracts/status.js +3 -0
- package/dist/_contracts/submission.d.ts +22 -18
- package/dist/_contracts/submission.js +60 -42
- package/dist/agents-md.d.ts +5 -5
- package/dist/agents-md.js +7 -7
- package/dist/agents-md.js.map +1 -1
- package/dist/asset-upload.d.ts +4 -4
- package/dist/asset-upload.js +4 -4
- package/dist/bundle.d.ts +2 -2
- package/dist/bundle.js +2 -2
- package/dist/cli.mjs +354 -12982
- package/dist/cli.mjs.sha256 +1 -1
- package/dist/client.d.ts +218 -386
- package/dist/client.js +347 -645
- package/dist/client.js.map +1 -1
- package/dist/data-tools.d.ts +25 -22
- package/dist/data-tools.js +75 -62
- package/dist/data-tools.js.map +1 -1
- package/dist/fetch-archive.js +16 -16
- package/dist/fetch-archive.js.map +1 -1
- package/dist/file.d.ts +5 -5
- package/dist/file.js +7 -7
- package/dist/file.js.map +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +14 -13
- package/dist/index.js.map +1 -1
- package/dist/mcp-server.d.ts +4 -4
- package/dist/mcp-server.js +4 -4
- package/dist/proxy-endpoint.d.ts +4 -4
- package/dist/proxy-endpoint.js +1 -1
- package/dist/secret.d.ts +8 -8
- package/dist/secret.js +8 -8
- package/dist/secret.js.map +1 -1
- package/dist/skill-tool.d.ts +102 -0
- package/dist/skill-tool.js +190 -0
- package/dist/skill-tool.js.map +1 -0
- package/dist/tool.d.ts +1 -1
- package/dist/tool.js +3 -3
- package/dist/tool.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/cleanup.md +3 -3
- package/docs/concepts/agent-tools.md +6 -25
- package/docs/concepts/composition.md +15 -12
- package/docs/concepts/providers-and-runtimes.md +3 -3
- package/docs/concepts/runs.md +27 -22
- package/docs/credentials.md +52 -84
- package/docs/defaults.md +6 -6
- package/docs/events.md +65 -44
- package/docs/limits-and-quotas.md +3 -4
- package/docs/mcp.md +3 -3
- package/docs/networking.md +8 -8
- package/docs/outputs.md +44 -40
- package/docs/provider-runtime-capabilities.md +1 -1
- package/docs/public-surface.json +2 -2
- package/docs/quickstart.md +20 -10
- package/docs/run-config.md +12 -14
- package/docs/run-record.md +8 -8
- package/docs/secrets.md +16 -26
- package/docs/skills.md +55 -110
- package/docs/vision-skills.md +29 -40
- package/examples/chat-corpus.ts +8 -9
- package/package.json +1 -1
- package/dist/skill.d.ts +0 -149
- package/dist/skill.js +0 -198
- package/dist/skill.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { AexError, DEFAULT_RUN_PROVIDER, HttpClient, RunConfigValidationError, RunStateError, SecretString, customName, isRunSettled, operations, providersForModel, streamCoordinatorEvents, summarizeRunTrace, textOf, parseRunLimits, BUILTIN_TOOL_NAMES, TERMINAL_RUN_STATUSES } from "./_contracts/index.js";
|
|
1
|
+
import { AexError, DEFAULT_RUN_PROVIDER, HttpClient, RunConfigValidationError, RunStateError, SecretString, customName, isRunSettled, operations, providersForModel, streamCoordinatorEvents, decodeAssistantText, summarizeRunTrace, textOf, parseRunLimits, BUILTIN_TOOL_NAMES, TERMINAL_RUN_STATUSES } from "./_contracts/index.js";
|
|
2
2
|
import { AgentsMd } from "./agents-md.js";
|
|
3
3
|
import { uploadAsset } from "./asset-upload.js";
|
|
4
4
|
import { File } from "./file.js";
|
|
5
5
|
import { McpServer } from "./mcp-server.js";
|
|
6
6
|
import { splitProxyEndpoints } from "./proxy-endpoint.js";
|
|
7
7
|
import { splitSecretEnv } from "./secret.js";
|
|
8
|
-
import {
|
|
8
|
+
import { SkillTool } from "./skill-tool.js";
|
|
9
9
|
import { Tool } from "./tool.js";
|
|
10
10
|
export class SessionTurnStream {
|
|
11
11
|
#run;
|
|
@@ -28,7 +28,6 @@ export class SessionTurnStream {
|
|
|
28
28
|
return this.#done;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
export const ChatTurnStream = SessionTurnStream;
|
|
32
31
|
const internalSessionSenders = new WeakMap();
|
|
33
32
|
function sendSessionInternal(session, input, options = {}) {
|
|
34
33
|
const sender = internalSessionSenders.get(session);
|
|
@@ -39,10 +38,12 @@ function sendSessionInternal(session, input, options = {}) {
|
|
|
39
38
|
}
|
|
40
39
|
export class SessionHandle {
|
|
41
40
|
#http;
|
|
41
|
+
#fetch;
|
|
42
42
|
#session;
|
|
43
|
-
constructor(http, session) {
|
|
43
|
+
constructor(http, session, fetch) {
|
|
44
44
|
this.#http = http;
|
|
45
45
|
this.#session = session;
|
|
46
|
+
this.#fetch = fetch;
|
|
46
47
|
internalSessionSenders.set(this, (input, options = {}) => new SessionTurnStream(() => this.#send(input, options)));
|
|
47
48
|
}
|
|
48
49
|
get id() {
|
|
@@ -102,28 +103,128 @@ export class SessionHandle {
|
|
|
102
103
|
this.#session = accepted.session;
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Accessor for the session's decoded assistant messages (buffered output
|
|
108
|
+
* mode: one entry per assistant message). `list()` returns them oldest-first;
|
|
109
|
+
* `last()`/`first()` return a single entry or `undefined` when empty.
|
|
110
|
+
*/
|
|
111
|
+
messages() {
|
|
112
|
+
const http = this.#http;
|
|
113
|
+
const id = this.id;
|
|
114
|
+
const list = async () => decodeAssistantText((await operations.listSessionEvents(http, id)));
|
|
115
|
+
return {
|
|
116
|
+
list,
|
|
117
|
+
last: async () => (await list()).at(-1),
|
|
118
|
+
first: async () => (await list())[0]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Accessor for the session's event stream: the buffered `SessionEvent`
|
|
123
|
+
* snapshots (`list`/`last`/`first`), the polling `RunEvent` iterator
|
|
124
|
+
* (`stream`), the live coordinator envelope iterator (`streamEnvelopes`), and
|
|
125
|
+
* the events-namespace archive (`archiveLink`/`download`).
|
|
126
|
+
*/
|
|
127
|
+
events() {
|
|
128
|
+
const http = this.#http;
|
|
129
|
+
const id = this.id;
|
|
130
|
+
const list = () => operations.listSessionEvents(http, id);
|
|
131
|
+
return {
|
|
132
|
+
list,
|
|
133
|
+
last: async () => (await list()).at(-1),
|
|
134
|
+
first: async () => (await list())[0],
|
|
135
|
+
stream: (options) => streamSessionEventsPolling(http, id, options ?? {}),
|
|
136
|
+
streamEnvelopes: (options) => streamSessionEnvelopes(http, id, options ?? {}),
|
|
137
|
+
archiveLink: (options) => operations.eventArchiveLink(http, id, options),
|
|
138
|
+
download: async (options) => writeOptionalFile(await operations.downloadEvents(http, id), options?.to)
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Accessor for the session's captured output files: `list`/`last`/`first`
|
|
143
|
+
* enumerate them; `read` streams one as capped text; `find`/`findOne`/`link`/
|
|
144
|
+
* `fetch` locate and resolve them; `download` fetches the outputs-namespace
|
|
145
|
+
* zip (no selector) or one file's raw bytes (with selector).
|
|
146
|
+
*/
|
|
147
|
+
outputs() {
|
|
148
|
+
return sessionOutputs(this.#http, this.id, this.#fetch);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Accessor for the session's webhook delivery ledger: `list()` returns the
|
|
152
|
+
* delivery attempts; `redeliver(id)` re-sends the frozen payload under the
|
|
153
|
+
* same `webhook-id` so the consumer dedupes.
|
|
154
|
+
*/
|
|
155
|
+
webhooks() {
|
|
156
|
+
const http = this.#http;
|
|
157
|
+
const id = this.id;
|
|
158
|
+
return {
|
|
159
|
+
list: () => operations.getRunWebhookDeliveries(http, id),
|
|
160
|
+
redeliver: (deliveryId) => operations.redeliverRunWebhook(http, id, deliveryId)
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** Re-read the session record from the server and store it as the current record. */
|
|
164
|
+
async refresh() {
|
|
165
|
+
this.#session = await operations.getSession(this.#http, this.id);
|
|
166
|
+
return this.#session;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Poll the session record until it reaches a parked/terminal status (idle,
|
|
170
|
+
* suspended, error, or any terminal run status). Throws if `timeoutMs`
|
|
171
|
+
* elapses first. Updates the stored record.
|
|
172
|
+
*/
|
|
173
|
+
async wait(options = {}) {
|
|
174
|
+
const intervalMs = options.intervalMs ?? 1_500;
|
|
175
|
+
const timeoutMs = options.timeoutMs;
|
|
176
|
+
const signal = options.signal;
|
|
177
|
+
const deadline = typeof timeoutMs === "number" ? Date.now() + timeoutMs : Number.POSITIVE_INFINITY;
|
|
178
|
+
while (!signal?.aborted) {
|
|
179
|
+
const session = await operations.getSession(this.#http, this.id);
|
|
180
|
+
this.#session = session;
|
|
181
|
+
if (isSessionParked(session.status))
|
|
182
|
+
return session;
|
|
183
|
+
if (Date.now() >= deadline) {
|
|
184
|
+
throw new Error(`SessionHandle.wait: timeout after ${timeoutMs}ms`);
|
|
185
|
+
}
|
|
186
|
+
await sleep(intervalMs, signal);
|
|
187
|
+
}
|
|
188
|
+
throw new Error("SessionHandle.wait: aborted");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Fetch the self-contained `RunUnit` for this session: parsed submission,
|
|
192
|
+
* attempts, indexed events, outputs, capture failures, proxy-call audit, and
|
|
193
|
+
* resolved skills. Use this when you need fields beyond the session record.
|
|
194
|
+
*/
|
|
195
|
+
unit() {
|
|
196
|
+
return operations.getRunUnit(this.#http, this.id);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Download EVERYTHING public about this session as one zip, assembled
|
|
200
|
+
* client-side from the public read endpoints. Organised into `metadata/`,
|
|
201
|
+
* `events/`, and `outputs/` folders, plus a `manifest.json`. Pass `to` to
|
|
202
|
+
* also write the bytes to a file path while still returning them.
|
|
203
|
+
*/
|
|
204
|
+
async download(options) {
|
|
205
|
+
return writeOptionalFile(await operations.download(this.#http, this.id), options?.to);
|
|
107
206
|
}
|
|
108
|
-
|
|
109
|
-
|
|
207
|
+
/** Download only the session record (the `metadata` namespace) as a zip. */
|
|
208
|
+
async downloadMetadata(options) {
|
|
209
|
+
return writeOptionalFile(await operations.downloadMetadata(this.#http, this.id), options?.to);
|
|
110
210
|
}
|
|
111
211
|
}
|
|
112
|
-
export const ChatSession = SessionHandle;
|
|
113
212
|
export class SessionClient {
|
|
114
213
|
#http;
|
|
214
|
+
#fetch;
|
|
115
215
|
#buildCreateRequest;
|
|
116
|
-
constructor(http, buildCreateRequest) {
|
|
216
|
+
constructor(http, buildCreateRequest, fetch) {
|
|
117
217
|
this.#http = http;
|
|
118
218
|
this.#buildCreateRequest = buildCreateRequest;
|
|
219
|
+
this.#fetch = fetch;
|
|
119
220
|
}
|
|
120
221
|
async create(options) {
|
|
121
222
|
const request = await this.#buildCreateRequest(options);
|
|
122
223
|
const session = await operations.createSession(this.#http, request, { idempotencyKey: options.idempotencyKey ?? generateIdempotencyKey() });
|
|
123
|
-
return new SessionHandle(this.#http, session);
|
|
224
|
+
return new SessionHandle(this.#http, session, this.#fetch);
|
|
124
225
|
}
|
|
125
226
|
async open(sessionId) {
|
|
126
|
-
return new SessionHandle(this.#http, await operations.getSession(this.#http, sessionId));
|
|
227
|
+
return new SessionHandle(this.#http, await operations.getSession(this.#http, sessionId), this.#fetch);
|
|
127
228
|
}
|
|
128
229
|
get(sessionId) {
|
|
129
230
|
return operations.getSession(this.#http, sessionId);
|
|
@@ -131,6 +232,73 @@ export class SessionClient {
|
|
|
131
232
|
list(query) {
|
|
132
233
|
return operations.listSessions(this.#http, query);
|
|
133
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Accessor over one session's captured output files, addressed by id without
|
|
237
|
+
* opening a handle. Returns the SAME rich {@link SessionOutputs} surface as
|
|
238
|
+
* `session.outputs()` — `aex.sessions.outputs(id).list()` /
|
|
239
|
+
* `.read(selector)` / `.download()` / … — so the workspace client and the
|
|
240
|
+
* live handle share one accessor convention.
|
|
241
|
+
*/
|
|
242
|
+
outputs(sessionId) {
|
|
243
|
+
return sessionOutputs(this.#http, sessionId, this.#fetch);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Find output files across sessions by filename / extension / content type.
|
|
247
|
+
* Returns lean REFERENCE hits (never bytes; fetch content with `readOutput`).
|
|
248
|
+
* Scope the search to a corpus with `query.runIds` (a session-id allow-list);
|
|
249
|
+
* omit it to scan every session in the workspace. Composed client-side (per-
|
|
250
|
+
* session `listSessionOutputs` + the contracts output filter), bounded by
|
|
251
|
+
* `query.limit` (default 100).
|
|
252
|
+
*/
|
|
253
|
+
async searchOutputs(query = {}) {
|
|
254
|
+
const sessionIds = query.runIds ?? (await this.#allSessionIds());
|
|
255
|
+
const limit = query.limit ?? 100;
|
|
256
|
+
// Translate the search query to an OutputQuery so the contracts output
|
|
257
|
+
// filter does the matching — no re-derived filter logic here.
|
|
258
|
+
const outputQuery = {
|
|
259
|
+
...(query.filename ? { filename: new RegExp(escapeRegExp(query.filename), "i") } : {}),
|
|
260
|
+
...(query.extension ? { extension: query.extension } : {}),
|
|
261
|
+
...(query.contentType ? { contentType: query.contentType } : {})
|
|
262
|
+
};
|
|
263
|
+
const hasFilter = Object.keys(outputQuery).length > 0;
|
|
264
|
+
const hits = [];
|
|
265
|
+
for (const sessionId of sessionIds) {
|
|
266
|
+
const outputs = hasFilter
|
|
267
|
+
? await operations.listSessionOutputs(this.#http, sessionId, outputQuery)
|
|
268
|
+
: await operations.listSessionOutputs(this.#http, sessionId);
|
|
269
|
+
for (const o of outputs) {
|
|
270
|
+
hits.push({
|
|
271
|
+
runId: sessionId,
|
|
272
|
+
outputId: o.id,
|
|
273
|
+
...(o.filename !== undefined ? { filename: o.filename } : {}),
|
|
274
|
+
...(o.sizeBytes !== undefined ? { sizeBytes: o.sizeBytes } : {}),
|
|
275
|
+
...(o.contentType !== undefined ? { contentType: o.contentType } : {})
|
|
276
|
+
});
|
|
277
|
+
if (hits.length >= limit)
|
|
278
|
+
return { hits };
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return { hits };
|
|
282
|
+
}
|
|
283
|
+
/** Enumerate every session id in the workspace by paging `listSessions`. */
|
|
284
|
+
async #allSessionIds() {
|
|
285
|
+
const ids = [];
|
|
286
|
+
const seenCursors = new Set();
|
|
287
|
+
let cursor;
|
|
288
|
+
do {
|
|
289
|
+
if (cursor !== undefined) {
|
|
290
|
+
if (seenCursors.has(cursor)) {
|
|
291
|
+
throw new Error("Aex.sessions.searchOutputs: listSessions returned a repeated cursor");
|
|
292
|
+
}
|
|
293
|
+
seenCursors.add(cursor);
|
|
294
|
+
}
|
|
295
|
+
const page = await operations.listSessions(this.#http, cursor ? { cursor } : {});
|
|
296
|
+
for (const session of page.sessions)
|
|
297
|
+
ids.push(session.id);
|
|
298
|
+
cursor = page.nextCursor;
|
|
299
|
+
} while (cursor);
|
|
300
|
+
return ids;
|
|
301
|
+
}
|
|
134
302
|
async run(options) {
|
|
135
303
|
const { message, deleteAfter, messageIdempotencyKey, stream, ...createOptions } = options;
|
|
136
304
|
assertNoLegacySessionFields(options, "Aex.sessions.run");
|
|
@@ -146,7 +314,6 @@ export class SessionClient {
|
|
|
146
314
|
return result;
|
|
147
315
|
}
|
|
148
316
|
}
|
|
149
|
-
export const ChatClient = SessionClient;
|
|
150
317
|
async function* streamSessionTurnEvents(http, sessionId, turn, options) {
|
|
151
318
|
const first = await operations.getSessionCoordinatorTicket(http, sessionId);
|
|
152
319
|
yield* streamCoordinatorEvents({
|
|
@@ -160,6 +327,98 @@ async function* streamSessionTurnEvents(http, sessionId, turn, options) {
|
|
|
160
327
|
...(options.pingIntervalMs !== undefined ? { pingIntervalMs: options.pingIntervalMs } : {})
|
|
161
328
|
});
|
|
162
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Poll the session's `RunEvent` snapshots until the session parks, the signal
|
|
332
|
+
* aborts, or the caller breaks the iterator, deduping by event id. Module-level
|
|
333
|
+
* so `SessionHandle.events()` can hand it to its accessor object literal.
|
|
334
|
+
*/
|
|
335
|
+
async function* streamSessionEventsPolling(http, id, options) {
|
|
336
|
+
if (options.signal?.aborted)
|
|
337
|
+
return;
|
|
338
|
+
const seenIds = new Set();
|
|
339
|
+
const intervalMs = options.intervalMs ?? 1_000;
|
|
340
|
+
const signal = options.signal;
|
|
341
|
+
while (!signal?.aborted) {
|
|
342
|
+
const events = await operations.listRunEvents(http, id);
|
|
343
|
+
for (const event of events) {
|
|
344
|
+
if (!seenIds.has(event.id)) {
|
|
345
|
+
seenIds.add(event.id);
|
|
346
|
+
yield event;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const session = await operations.getSession(http, id);
|
|
350
|
+
if (isSessionParked(session.status))
|
|
351
|
+
return;
|
|
352
|
+
// `sleep` rejects on abort — treat that as a graceful stop.
|
|
353
|
+
try {
|
|
354
|
+
await sleep(intervalMs, signal);
|
|
355
|
+
}
|
|
356
|
+
catch {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Stream the unified {@link AexEvent} envelope live over the session's
|
|
363
|
+
* coordinator WebSocket. The ticket is re-minted on each (re)connect so a long
|
|
364
|
+
* session never outlives it. Module-level so `SessionHandle.events()` can hand
|
|
365
|
+
* it to its accessor object literal.
|
|
366
|
+
*/
|
|
367
|
+
async function* streamSessionEnvelopes(http, id, options) {
|
|
368
|
+
const first = await operations.getSessionCoordinatorTicket(http, id);
|
|
369
|
+
yield* streamCoordinatorEvents({
|
|
370
|
+
wsUrl: first.wsUrl,
|
|
371
|
+
from: options.from ?? 0,
|
|
372
|
+
fetchTicket: async () => (await operations.getSessionCoordinatorTicket(http, id)).ticket,
|
|
373
|
+
// settleConsistent ends the stream on the post-mirror barrier instead of
|
|
374
|
+
// the earlier RUN_FINISHED UX signal.
|
|
375
|
+
...(options.settleConsistent ? { isTerminal: isRunSettled } : {}),
|
|
376
|
+
...(options.signal ? { signal: options.signal } : {})
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Download captured deliverables. No selector → the full outputs namespace as a
|
|
381
|
+
* zip; a selector → one file's raw bytes. Module-level so
|
|
382
|
+
* `SessionHandle.outputs()` can hand it to its accessor object literal.
|
|
383
|
+
*/
|
|
384
|
+
async function downloadSessionOutput(http, id, selector, options) {
|
|
385
|
+
let bytes;
|
|
386
|
+
if (selector === undefined) {
|
|
387
|
+
bytes = await operations.downloadOutputs(http, id);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const output = isOutputPathSelector(selector)
|
|
391
|
+
? resolveOutputFileSelector(await operations.listOutputs(http, id), selector, id)
|
|
392
|
+
: resolveOutputFileSelector([], selector, id);
|
|
393
|
+
const { response } = await http.download(`/api/runs/${encodeURIComponent(id)}/outputs/${encodeURIComponent(output.id)}/download`);
|
|
394
|
+
bytes = new Uint8Array(await response.arrayBuffer());
|
|
395
|
+
}
|
|
396
|
+
return writeOptionalFile(bytes, options?.to);
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Build the outputs accessor for a session id. Shared by
|
|
400
|
+
* `SessionHandle.outputs()` (bound to the live handle) and
|
|
401
|
+
* `SessionClient.outputs(id)` (addressed by id without opening a handle), so both
|
|
402
|
+
* expose the identical rich {@link SessionOutputs} surface — one accessor
|
|
403
|
+
* convention, one implementation.
|
|
404
|
+
*/
|
|
405
|
+
function sessionOutputs(http, id, fetchLike) {
|
|
406
|
+
const list = (query) => operations.listSessionOutputs(http, id, query);
|
|
407
|
+
return {
|
|
408
|
+
list,
|
|
409
|
+
last: async () => (await list()).at(-1),
|
|
410
|
+
first: async () => (await list())[0],
|
|
411
|
+
read: (selector, options) => operations.readOutputText(http, id, selector, options),
|
|
412
|
+
find: (query) => operations.findOutputs(http, id, query),
|
|
413
|
+
findOne: (query) => operations.findOutput(http, id, query),
|
|
414
|
+
link: (selectorOrQuery, options) => operations.outputLink(http, id, selectorOrQuery, options),
|
|
415
|
+
fetch: async (selectorOrQuery, options) => {
|
|
416
|
+
const link = await operations.outputLink(http, id, selectorOrQuery, options);
|
|
417
|
+
return (fetchLike ?? globalThis.fetch)(link.url);
|
|
418
|
+
},
|
|
419
|
+
download: (selector, options) => downloadSessionOutput(http, id, selector, options)
|
|
420
|
+
};
|
|
421
|
+
}
|
|
163
422
|
function isSessionTurnTerminalEvent(event, turnSeq) {
|
|
164
423
|
const name = customName(event);
|
|
165
424
|
if (name !== "aex.session.idle" &&
|
|
@@ -200,61 +459,12 @@ function withTerminalSessionStatus(session, terminalStatus) {
|
|
|
200
459
|
}
|
|
201
460
|
return { ...session, status: terminalStatus };
|
|
202
461
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Workspace skill admin operations exposed under `client.skills`.
|
|
205
|
-
*
|
|
206
|
-
* New run submissions usually use `Skill.fromFiles(...)` or
|
|
207
|
-
* `Skill.fromPath(...)` directly inside `submit`; the SDK materializes
|
|
208
|
-
* those bytes to the hosted asset store before the run lands. This namespace is the read/delete
|
|
209
|
-
* surface for workspace skill records and the internal transport used by the
|
|
210
|
-
* legacy CLI upload command.
|
|
211
|
-
*/
|
|
212
|
-
export class SkillsClient {
|
|
213
|
-
#http;
|
|
214
|
-
constructor(http) {
|
|
215
|
-
this.#http = http;
|
|
216
|
-
}
|
|
217
|
-
list() {
|
|
218
|
-
return operations.listSkills(this.#http);
|
|
219
|
-
}
|
|
220
|
-
get(skillId) {
|
|
221
|
-
return operations.getSkill(this.#http, skillId);
|
|
222
|
-
}
|
|
223
|
-
delete(skillId) {
|
|
224
|
-
return operations.deleteSkill(this.#http, skillId);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Lookup a live workspace skill by `(name, contentHash)`.
|
|
228
|
-
*
|
|
229
|
-
* Returns the matching `Skill` record or `null` when no live row
|
|
230
|
-
* carries that hash. The `contentHash` is the wire format
|
|
231
|
-
* `sha256:<hex>` returned by `hashSkillBundle` (and stored verbatim
|
|
232
|
-
* on every skill row). The hash space is unique enough that one
|
|
233
|
-
* row at most can match, so this is a single keyed lookup.
|
|
234
|
-
*
|
|
235
|
-
* Consumers can call this directly when they already have a hash in hand
|
|
236
|
-
* and want to know whether the skill is already persisted.
|
|
237
|
-
*/
|
|
238
|
-
findByHash(args) {
|
|
239
|
-
return operations.findSkillByHash(this.#http, args);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Lookup a live workspace skill by `name`. Returns the matching
|
|
243
|
-
* `Skill` record or `null` when no live row carries that name.
|
|
244
|
-
* Implemented as a list-and-filter against the existing `/api/skills`
|
|
245
|
-
* endpoint — typical workspace skill counts are small enough that
|
|
246
|
-
* the cost is negligible.
|
|
247
|
-
*/
|
|
248
|
-
findByName(name) {
|
|
249
|
-
return operations.findSkillByName(this.#http, name);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
462
|
/**
|
|
253
463
|
* Workspace AgentsMd admin operations exposed under `client.agentsMd`.
|
|
254
464
|
*
|
|
255
|
-
* New
|
|
256
|
-
* `AgentsMd.fromPath(...)` directly
|
|
257
|
-
* materializes those bytes to the hosted asset store before the
|
|
465
|
+
* New sessions usually use `AgentsMd.fromContent(...)` or
|
|
466
|
+
* `AgentsMd.fromPath(...)` directly on `openSession` / `run`; the SDK
|
|
467
|
+
* materializes those bytes to the hosted asset store before the session starts. This namespace is
|
|
258
468
|
* the read/delete surface for persisted AgentsMd records.
|
|
259
469
|
*/
|
|
260
470
|
export class AgentsMdClient {
|
|
@@ -275,9 +485,9 @@ export class AgentsMdClient {
|
|
|
275
485
|
/**
|
|
276
486
|
* Workspace File admin operations exposed under `client.files`.
|
|
277
487
|
*
|
|
278
|
-
* New
|
|
279
|
-
* `File.fromBytes(...)` directly
|
|
280
|
-
* those bytes to the hosted asset store before the
|
|
488
|
+
* New sessions usually use `File.fromPath(...)` or
|
|
489
|
+
* `File.fromBytes(...)` directly on `openSession` / `run`; the SDK materializes
|
|
490
|
+
* those bytes to the hosted asset store before the session starts. This namespace is the read/delete
|
|
281
491
|
* surface for persisted file records.
|
|
282
492
|
*/
|
|
283
493
|
export class FilesClient {
|
|
@@ -297,17 +507,16 @@ export class FilesClient {
|
|
|
297
507
|
}
|
|
298
508
|
/**
|
|
299
509
|
* Workspace secret management exposed under `client.secrets`, mirroring
|
|
300
|
-
* `client.
|
|
510
|
+
* `client.agentsMd` / `client.files`.
|
|
301
511
|
*
|
|
302
|
-
* Lifecycle parity with assets
|
|
512
|
+
* Lifecycle parity with assets: a `Secret.value(...)` is per-run and
|
|
303
513
|
* gone at terminal; `set` (or promoting an ephemeral via `secret.upload`)
|
|
304
514
|
* persists a named, searchable workspace secret you can `get` (metadata),
|
|
305
|
-
* `
|
|
306
|
-
*
|
|
515
|
+
* `rotate`, `list`, and `delete`. The identity is the `name`; the value rotates
|
|
516
|
+
* under that stable name.
|
|
307
517
|
*
|
|
308
|
-
* Values are write-only: `set`/`rotate` send the value in
|
|
309
|
-
* the URL); `get`/`list` return metadata only
|
|
310
|
-
* value read.
|
|
518
|
+
* Values are write-only through the public SDK: `set`/`rotate` send the value in
|
|
519
|
+
* the request BODY (never the URL); `get`/`list` return metadata only.
|
|
311
520
|
*/
|
|
312
521
|
export class SecretsClient {
|
|
313
522
|
#http;
|
|
@@ -326,10 +535,6 @@ export class SecretsClient {
|
|
|
326
535
|
get(name) {
|
|
327
536
|
return operations.getSecret(this.#http, name);
|
|
328
537
|
}
|
|
329
|
-
/** Audited value read — the preferred path that returns a workspace secret value. */
|
|
330
|
-
get_value(name) {
|
|
331
|
-
return operations.getSecretValue(this.#http, name);
|
|
332
|
-
}
|
|
333
538
|
/** Replace the value of an existing workspace secret; bumps its version. */
|
|
334
539
|
rotate(args) {
|
|
335
540
|
return operations.rotateSecret(this.#http, { name: args.name, value: unwrapSecretValue(args.value) });
|
|
@@ -370,12 +575,10 @@ export class AgentExecutor {
|
|
|
370
575
|
#http;
|
|
371
576
|
/** The same fetch the HttpClient uses, threaded into `_uploadAsset`. */
|
|
372
577
|
#fetch;
|
|
373
|
-
skills;
|
|
374
578
|
agentsMd;
|
|
375
579
|
files;
|
|
376
580
|
secrets;
|
|
377
581
|
sessions;
|
|
378
|
-
chat;
|
|
379
582
|
constructor(options) {
|
|
380
583
|
if (!options.apiToken) {
|
|
381
584
|
throw new Error("AgentExecutor: apiToken is required");
|
|
@@ -392,12 +595,10 @@ export class AgentExecutor {
|
|
|
392
595
|
: {})
|
|
393
596
|
});
|
|
394
597
|
this.#fetch = options.fetch;
|
|
395
|
-
this.skills = new SkillsClient(this.#http);
|
|
396
598
|
this.agentsMd = new AgentsMdClient(this.#http);
|
|
397
599
|
this.files = new FilesClient(this.#http);
|
|
398
600
|
this.secrets = new SecretsClient(this.#http);
|
|
399
|
-
this.
|
|
400
|
-
this.sessions = this.chat;
|
|
601
|
+
this.sessions = new SessionClient(this.#http, (options) => this.#buildSessionCreateRequest(options), this.#fetch);
|
|
401
602
|
}
|
|
402
603
|
/**
|
|
403
604
|
* Internal: satisfies the `SecretUploader` surface so a
|
|
@@ -410,9 +611,10 @@ export class AgentExecutor {
|
|
|
410
611
|
}
|
|
411
612
|
/**
|
|
412
613
|
* Internal: materialize raw bytes to the content-addressable asset store
|
|
413
|
-
* (`/assets/presign` → PUT → `/assets/finalize`). Used by
|
|
414
|
-
* to
|
|
415
|
-
* `kind:"asset"`
|
|
614
|
+
* (`/assets/presign` → PUT → `/assets/finalize`). Used by the session-create
|
|
615
|
+
* prepare step to upload draft skill-tool / tool / agentsMd / file bundles so
|
|
616
|
+
* the wire submission carries only plain `kind:"asset"` / `kind:"skill"` refs.
|
|
617
|
+
* NOT part of the public API.
|
|
416
618
|
*/
|
|
417
619
|
async _uploadAsset(args) {
|
|
418
620
|
return uploadAsset({
|
|
@@ -484,183 +686,11 @@ export class AgentExecutor {
|
|
|
484
686
|
scopedSignal?.clear();
|
|
485
687
|
}
|
|
486
688
|
}
|
|
487
|
-
/**
|
|
488
|
-
* Explicit, discoverable alias for {@link run}: open a one-shot session turn
|
|
489
|
-
* and collect the full {@link RunResult} in one call.
|
|
490
|
-
*/
|
|
491
|
-
runAndCollect(options, opts) {
|
|
492
|
-
return this.run(options, opts);
|
|
493
|
-
}
|
|
494
689
|
openSession(optionsOrId) {
|
|
495
690
|
return typeof optionsOrId === "string"
|
|
496
691
|
? this.sessions.open(optionsOrId)
|
|
497
692
|
: this.sessions.create(optionsOrId);
|
|
498
693
|
}
|
|
499
|
-
/**
|
|
500
|
-
* Poll `listEvents` until the snapshot is settle-bracketed — both a
|
|
501
|
-
* RUN_STARTED and a terminal (RUN_FINISHED / RUN_ERROR) event present — then
|
|
502
|
-
* return it. The runner emits the terminal AG-UI event BEFORE the platform
|
|
503
|
-
* commits the record, and the `listEvents` snapshot can lag the terminal
|
|
504
|
-
* record by a beat; this closes that race so the decoded trace/text/outputs
|
|
505
|
-
* are complete. Bounded so an older runtime that never emits one of the
|
|
506
|
-
* brackets still returns the best snapshot available.
|
|
507
|
-
*/
|
|
508
|
-
async #collectSettledEvents(runId, signal) {
|
|
509
|
-
const intervalMs = 500;
|
|
510
|
-
const maxAttempts = 20;
|
|
511
|
-
let latest = [];
|
|
512
|
-
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
513
|
-
if (signal?.aborted)
|
|
514
|
-
return latest;
|
|
515
|
-
latest = await this.listEvents(runId);
|
|
516
|
-
const hasStart = latest.some((event) => event.type === "RUN_STARTED");
|
|
517
|
-
const hasTerminal = latest.some((event) => event.type === "RUN_FINISHED" || event.type === "RUN_ERROR");
|
|
518
|
-
if (hasStart && hasTerminal)
|
|
519
|
-
return latest;
|
|
520
|
-
try {
|
|
521
|
-
await sleep(intervalMs, signal);
|
|
522
|
-
}
|
|
523
|
-
catch {
|
|
524
|
-
return latest;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return latest;
|
|
528
|
-
}
|
|
529
|
-
/**
|
|
530
|
-
* Submit a run and return its run id immediately. Use that id with
|
|
531
|
-
* `wait`, `stream`, `outputs`, `download`, `cancel`, or `delete`.
|
|
532
|
-
*
|
|
533
|
-
* The SDK splits `mcpServers[i].headers` into `secrets.mcpServers`
|
|
534
|
-
* and `proxyEndpoints[i]` auth values into `secrets.proxyEndpointAuth`
|
|
535
|
-
* before sending so credentials never enter the hashed submission or
|
|
536
|
-
* the run snapshot.
|
|
537
|
-
*
|
|
538
|
-
* Unstaged inline skills / agentsMd / files (`Skill.fromFiles` /
|
|
539
|
-
* `Skill.fromPath` / `AgentsMd.fromContent` / `File.fromBytes` without a
|
|
540
|
-
* prior `.upload`) are auto-uploaded to the content-addressable asset
|
|
541
|
-
* store (`/assets/presign` → PUT → `/assets/finalize`) before `POST /runs`,
|
|
542
|
-
* deduped by content hash, and referenced in the submission as plain
|
|
543
|
-
* `{ kind:"asset" }` refs — identical to a pre-staged `.upload(client)`.
|
|
544
|
-
*/
|
|
545
|
-
async submit(options) {
|
|
546
|
-
if (!options || typeof options !== "object") {
|
|
547
|
-
throw new RunConfigValidationError("AgentExecutor.submit: options is required");
|
|
548
|
-
}
|
|
549
|
-
assertNoRemovedSubmitFields(options, "AgentExecutor.submit");
|
|
550
|
-
// A model maps to one or more upstream providers (see MODEL_PROVIDER_IDS).
|
|
551
|
-
// `providersForModel` returns the supported providers in priority order, or
|
|
552
|
-
// `[]` for an unknown model string (the model check below then rejects it).
|
|
553
|
-
// An explicit provider is allowed but must be one that serves the model;
|
|
554
|
-
// when omitted the model's default (first-listed) provider is used.
|
|
555
|
-
const supportedProviders = providersForModel(options.model);
|
|
556
|
-
if (options.provider &&
|
|
557
|
-
supportedProviders.length > 0 &&
|
|
558
|
-
!supportedProviders.includes(options.provider)) {
|
|
559
|
-
throw new RunConfigValidationError(`AgentExecutor.submit: provider ${JSON.stringify(options.provider)} is not available for ` +
|
|
560
|
-
`model ${JSON.stringify(options.model)} (supported: ${supportedProviders.join(", ")})`);
|
|
561
|
-
}
|
|
562
|
-
const provider = options.provider ?? supportedProviders[0] ?? DEFAULT_RUN_PROVIDER;
|
|
563
|
-
validateSubmitCredentials(options, provider, "AgentExecutor.submit");
|
|
564
|
-
if (typeof options.model !== "string" || !options.model) {
|
|
565
|
-
throw new RunConfigValidationError("AgentExecutor.submit: model is required");
|
|
566
|
-
}
|
|
567
|
-
const prompt = normalisePrompt(options.prompt, "AgentExecutor.submit", "prompt");
|
|
568
|
-
const { endpoints: proxyEndpointDeclarations, auth: proxyEndpointAuthFromInstances } = splitProxyEndpoints(options.proxyEndpoints ?? []);
|
|
569
|
-
const mergedProxyAuth = mergeProxyEndpointAuth(proxyEndpointAuthFromInstances, options.secrets?.proxyEndpointAuth ?? []);
|
|
570
|
-
// Split secretEnv into value-free declarations (hashed submission) and
|
|
571
|
-
// ephemeral values (vaulted secrets channel), mirroring the proxy split.
|
|
572
|
-
const { declarations: secretEnvDeclarations, values: envSecretValues } = splitSecretEnv(options.secretEnv);
|
|
573
|
-
// Validate the per-run limits override with the SAME parser the server runs
|
|
574
|
-
// (shape + positivity + allow-list), failing fast before any asset upload.
|
|
575
|
-
// Normalizes an all-absent override (e.g. `{}`) away.
|
|
576
|
-
let limits;
|
|
577
|
-
try {
|
|
578
|
-
limits = parseRunLimits(options.limits);
|
|
579
|
-
}
|
|
580
|
-
catch (err) {
|
|
581
|
-
throw new AexError("RUN_CONFIG_INVALID", `AgentExecutor.submit: ${err instanceof Error ? err.message : String(err)}`);
|
|
582
|
-
}
|
|
583
|
-
// Walk Skill / Tool / AgentsMd / File instances. Inline drafts are eagerly
|
|
584
|
-
// uploaded to the content-addressable asset store here (before POST /runs)
|
|
585
|
-
// and referenced as plain `kind:"asset"` refs. Already-materialized asset
|
|
586
|
-
// refs pass through unchanged.
|
|
587
|
-
const uploader = (args) => this._uploadAsset(args);
|
|
588
|
-
const preparedSkills = await prepareSkills(options.skills ?? [], uploader);
|
|
589
|
-
const preparedTools = await prepareTools(options.tools ?? [], uploader);
|
|
590
|
-
const preparedAgentsMd = await prepareAgentsMd(options.agentsMd ?? [], uploader);
|
|
591
|
-
const preparedFiles = await prepareFiles(options.files ?? [], uploader);
|
|
592
|
-
const { submissionMcpServers, mergedMcpSecrets } = mergeMcpServers(options.mcpServers ?? [], options.secrets?.mcpServers ?? []);
|
|
593
|
-
const outputCapture = outputsForWire(options.outputs);
|
|
594
|
-
const submission = {
|
|
595
|
-
model: options.model,
|
|
596
|
-
...(options.system ? { system: options.system } : {}),
|
|
597
|
-
prompt,
|
|
598
|
-
skills: preparedSkills,
|
|
599
|
-
// The wire `tools` is the union: builtin name strings (cherry-picks)
|
|
600
|
-
// followed by the custom tool bundle refs. The shared parser splits them
|
|
601
|
-
// back into `tools` (custom) + `builtinTools` (names). The cast
|
|
602
|
-
// acknowledges the SDK is producing pre-parse wire input here, same as
|
|
603
|
-
// `mcpServers` / `environment` below.
|
|
604
|
-
tools: [...preparedTools.builtinNames, ...preparedTools.refs],
|
|
605
|
-
agentsMd: preparedAgentsMd,
|
|
606
|
-
files: preparedFiles,
|
|
607
|
-
// submissionMcpServers may contain workspace refs of the shape
|
|
608
|
-
// {kind:"workspace", id:"mcp_..."}. The BFF runs
|
|
609
|
-
// `resolveWorkspaceMcpRefsInSubmission` BEFORE the shared parser
|
|
610
|
-
// and replaces them with the resolved {name, url}, so by the
|
|
611
|
-
// time anything reads PlatformSubmission post-parse the
|
|
612
|
-
// shape matches McpServerRef. The cast acknowledges that the
|
|
613
|
-
// SDK is producing pre-resolution wire input here.
|
|
614
|
-
mcpServers: submissionMcpServers,
|
|
615
|
-
...(Object.keys(secretEnvDeclarations).length > 0 ? { secretEnv: secretEnvDeclarations } : {}),
|
|
616
|
-
// `options.environment.packages` carry the customer wire shape
|
|
617
|
-
// (`{name:"pip:pandas"}`); the shared parser resolves the ecosystem
|
|
618
|
-
// prefix into PlatformPackage. The cast acknowledges the SDK is
|
|
619
|
-
// producing pre-parse wire input here, same as `mcpServers` above.
|
|
620
|
-
...(options.environment
|
|
621
|
-
? { environment: options.environment }
|
|
622
|
-
: {}),
|
|
623
|
-
...(options.metadata ? { metadata: options.metadata } : {}),
|
|
624
|
-
...(outputCapture ? { outputs: outputCapture } : {}),
|
|
625
|
-
// Pass-through the builtin-tool toggle verbatim (omitted ⇒ default ON).
|
|
626
|
-
...(options.includeBuiltinTools !== undefined
|
|
627
|
-
? { includeBuiltinTools: options.includeBuiltinTools }
|
|
628
|
-
: {}),
|
|
629
|
-
...(options.outputMode !== undefined ? { outputMode: options.outputMode } : {})
|
|
630
|
-
};
|
|
631
|
-
const secrets = {
|
|
632
|
-
...options.secrets,
|
|
633
|
-
...(mergedMcpSecrets.length > 0 ? { mcpServers: mergedMcpSecrets } : {}),
|
|
634
|
-
...(mergedProxyAuth.length > 0 ? { proxyEndpointAuth: mergedProxyAuth } : {}),
|
|
635
|
-
...(Object.keys(envSecretValues).length > 0 ? { envSecrets: envSecretValues } : {})
|
|
636
|
-
};
|
|
637
|
-
const request = {
|
|
638
|
-
idempotencyKey: options.idempotencyKey ?? generateIdempotencyKey(),
|
|
639
|
-
// Always include `provider` on the wire so dashboard / proxy
|
|
640
|
-
// tooling never has to second-guess what the runtime saw. The
|
|
641
|
-
// shared parser still defaults to `anthropic` when callers omit
|
|
642
|
-
// the field entirely, but the SDK has resolved it by here.
|
|
643
|
-
provider,
|
|
644
|
-
submission,
|
|
645
|
-
...(options.runtimeSize ? { runtimeSize: options.runtimeSize } : {}),
|
|
646
|
-
...(options.timeout ? { timeout: options.timeout } : {}),
|
|
647
|
-
...(options.parentRunId ? { parentRunId: options.parentRunId } : {}),
|
|
648
|
-
// Operational/delivery concern — sibling of idempotencyKey, NOT part of
|
|
649
|
-
// the hashed brief. The idempotency key here is randomly generated, so
|
|
650
|
-
// including the field has no effect on dedup.
|
|
651
|
-
...(options.webhook ? { webhook: options.webhook } : {}),
|
|
652
|
-
// Per-run lineage-limit override — a top-level operational dial (sibling
|
|
653
|
-
// of parentRunId), NOT part of the hashed submission. Validated + normalized
|
|
654
|
-
// above; the server re-clamps against the workspace + platform ceilings.
|
|
655
|
-
...(limits ? { limits } : {}),
|
|
656
|
-
secrets,
|
|
657
|
-
...(proxyEndpointDeclarations.length > 0
|
|
658
|
-
? { proxyEndpoints: proxyEndpointDeclarations }
|
|
659
|
-
: {})
|
|
660
|
-
};
|
|
661
|
-
const run = await operations.submitRun(this.#http, request);
|
|
662
|
-
return getSubmittedRunId(run);
|
|
663
|
-
}
|
|
664
694
|
async #buildSessionCreateRequest(options) {
|
|
665
695
|
if (!options || typeof options !== "object") {
|
|
666
696
|
throw new RunConfigValidationError("Aex.openSession: options is required");
|
|
@@ -691,7 +721,6 @@ export class AgentExecutor {
|
|
|
691
721
|
throw new AexError("RUN_CONFIG_INVALID", `Aex.openSession: ${err instanceof Error ? err.message : String(err)}`);
|
|
692
722
|
}
|
|
693
723
|
const uploader = (args) => this._uploadAsset(args);
|
|
694
|
-
const preparedSkills = await prepareSkills(options.skills ?? [], uploader);
|
|
695
724
|
const preparedTools = await prepareTools(options.tools ?? [], uploader);
|
|
696
725
|
const preparedAgentsMd = await prepareAgentsMd(options.agentsMd ?? [], uploader);
|
|
697
726
|
const preparedFiles = await prepareFiles(options.files ?? [], uploader);
|
|
@@ -701,8 +730,13 @@ export class AgentExecutor {
|
|
|
701
730
|
const submission = {
|
|
702
731
|
model: options.model,
|
|
703
732
|
...(options.system ? { system: options.system } : {}),
|
|
704
|
-
|
|
705
|
-
tools
|
|
733
|
+
// Builtin name strings + custom tool refs + skill-tool refs all ride the
|
|
734
|
+
// one `tools` union; the BFF parser splits them back apart by kind.
|
|
735
|
+
tools: [
|
|
736
|
+
...preparedTools.builtinNames,
|
|
737
|
+
...preparedTools.refs,
|
|
738
|
+
...preparedTools.skillToolRefs
|
|
739
|
+
],
|
|
706
740
|
agentsMd: preparedAgentsMd,
|
|
707
741
|
files: preparedFiles,
|
|
708
742
|
mcpServers: submissionMcpServers,
|
|
@@ -729,275 +763,15 @@ export class AgentExecutor {
|
|
|
729
763
|
...(options.overrides?.timeout ? { timeout: options.overrides.timeout } : {}),
|
|
730
764
|
...(limits ? { limits } : {}),
|
|
731
765
|
retention,
|
|
766
|
+
// Operational/delivery concern — sibling of secrets, NOT part of the
|
|
767
|
+
// hashed submission. Delivered at the settle-consistent barrier.
|
|
768
|
+
...(options.webhook ? { webhook: options.webhook } : {}),
|
|
732
769
|
secrets,
|
|
733
770
|
...(proxyEndpointDeclarations.length > 0
|
|
734
771
|
? { proxyEndpoints: proxyEndpointDeclarations }
|
|
735
772
|
: {})
|
|
736
773
|
};
|
|
737
774
|
}
|
|
738
|
-
getRun(runId) {
|
|
739
|
-
return operations.getRun(this.#http, runId);
|
|
740
|
-
}
|
|
741
|
-
/** Short alias for `getRun`. */
|
|
742
|
-
get(runId) {
|
|
743
|
-
return this.getRun(runId);
|
|
744
|
-
}
|
|
745
|
-
/**
|
|
746
|
-
* List the runs in this workspace, most-recent first, one page at a time.
|
|
747
|
-
* The workspace is derived server-side from the API token, so this only ever
|
|
748
|
-
* enumerates your own runs. Pass `query.cursor` (from a prior page's
|
|
749
|
-
* `nextCursor`) to page; omit it for the first page. Returns public-safe
|
|
750
|
-
* {@link RunSummary} rows — the full submission stays behind `getRunUnit`.
|
|
751
|
-
*
|
|
752
|
-
* This is the workspace-wide discovery entry point: combine it with
|
|
753
|
-
* `listOutputs` / `readOutputText` to reach any run's deliverables.
|
|
754
|
-
*/
|
|
755
|
-
listRuns(query) {
|
|
756
|
-
return operations.listRuns(this.#http, query);
|
|
757
|
-
}
|
|
758
|
-
/**
|
|
759
|
-
* Find output files across runs by filename / extension / content type.
|
|
760
|
-
* Returns lean REFERENCE hits (runId, outputId, filename, size, content type)
|
|
761
|
-
* — never bytes; fetch content with {@link readOutputText}. Scope the search
|
|
762
|
-
* to a corpus with `query.runIds`; omit it to scan the whole workspace (needs
|
|
763
|
-
* the owner-gated `listRuns`). Composed client-side for the MVP (per-run
|
|
764
|
-
* `listOutputs` + the contracts output filter), so it works against any
|
|
765
|
-
* already-terminal run with no new server endpoint. Bounded by
|
|
766
|
-
* `query.limit` (default 100) — for very large corpora prefer the deferred
|
|
767
|
-
* server-side index.
|
|
768
|
-
*/
|
|
769
|
-
async searchOutputs(query = {}) {
|
|
770
|
-
const runIds = query.runIds ?? (await this.#allWorkspaceRunIds());
|
|
771
|
-
const limit = query.limit ?? 100;
|
|
772
|
-
// Translate the search query to an OutputQuery so the contracts output
|
|
773
|
-
// filter (classifyOutput / basename match / contentType wildcard) does the
|
|
774
|
-
// matching — no re-derived filter logic here.
|
|
775
|
-
const outputQuery = {
|
|
776
|
-
...(query.filename ? { filename: new RegExp(escapeRegExp(query.filename), "i") } : {}),
|
|
777
|
-
...(query.extension ? { extension: query.extension } : {}),
|
|
778
|
-
...(query.contentType ? { contentType: query.contentType } : {})
|
|
779
|
-
};
|
|
780
|
-
const hasFilter = Object.keys(outputQuery).length > 0;
|
|
781
|
-
const hits = [];
|
|
782
|
-
for (const runId of runIds) {
|
|
783
|
-
const outputs = hasFilter
|
|
784
|
-
? await this.listOutputs(runId, outputQuery)
|
|
785
|
-
: await this.listOutputs(runId);
|
|
786
|
-
for (const o of outputs) {
|
|
787
|
-
hits.push({
|
|
788
|
-
runId,
|
|
789
|
-
outputId: o.id,
|
|
790
|
-
...(o.filename !== undefined ? { filename: o.filename } : {}),
|
|
791
|
-
...(o.sizeBytes !== undefined ? { sizeBytes: o.sizeBytes } : {}),
|
|
792
|
-
...(o.contentType !== undefined ? { contentType: o.contentType } : {})
|
|
793
|
-
});
|
|
794
|
-
if (hits.length >= limit)
|
|
795
|
-
return { hits };
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
return { hits };
|
|
799
|
-
}
|
|
800
|
-
/** Enumerate every run id in the workspace by paging `listRuns`. */
|
|
801
|
-
async #allWorkspaceRunIds() {
|
|
802
|
-
const ids = [];
|
|
803
|
-
let cursor;
|
|
804
|
-
do {
|
|
805
|
-
const page = await this.listRuns(cursor ? { cursor } : {});
|
|
806
|
-
for (const run of page.runs)
|
|
807
|
-
ids.push(run.id);
|
|
808
|
-
cursor = page.nextCursor;
|
|
809
|
-
} while (cursor);
|
|
810
|
-
return ids;
|
|
811
|
-
}
|
|
812
|
-
/**
|
|
813
|
-
* Fetch the self-contained `RunUnit`: parsed submission inputs,
|
|
814
|
-
* attempts, indexed events (inline + cursor for the tail), raw
|
|
815
|
-
* provider-event Storage manifest, outputs, capture failures,
|
|
816
|
-
* proxy-call audit, pinned workspace skills, provider skills,
|
|
817
|
-
* inline skills. Backed by the same endpoint as `getRun` but
|
|
818
|
-
* typed against the full wire shape — use this when you need
|
|
819
|
-
* fields beyond `{id, status, timestamps, usage}`.
|
|
820
|
-
*/
|
|
821
|
-
getRunUnit(runId) {
|
|
822
|
-
return operations.getRunUnit(this.#http, runId);
|
|
823
|
-
}
|
|
824
|
-
/** Short alias for `getRunUnit`. */
|
|
825
|
-
getUnit(runId) {
|
|
826
|
-
return this.getRunUnit(runId);
|
|
827
|
-
}
|
|
828
|
-
listEvents(runId) {
|
|
829
|
-
return operations.listRunEvents(this.#http, runId);
|
|
830
|
-
}
|
|
831
|
-
/** Short alias for `listEvents`. */
|
|
832
|
-
events(runId) {
|
|
833
|
-
return this.listEvents(runId);
|
|
834
|
-
}
|
|
835
|
-
/**
|
|
836
|
-
* Yield run events (the `RunEvent` snapshot shape) as they arrive, by
|
|
837
|
-
* polling the coordinator-backed `/events` endpoint until the run reaches
|
|
838
|
-
* a terminal state, the signal aborts, or the caller breaks the iterator.
|
|
839
|
-
*
|
|
840
|
-
* For the live, low-latency envelope stream prefer {@link streamEnvelopes}
|
|
841
|
-
* (coordinator WebSocket). This polling form stays for consumers that want
|
|
842
|
-
* the loose `RunEvent` shape without a WS.
|
|
843
|
-
*/
|
|
844
|
-
async *streamEvents(runId, options = {}) {
|
|
845
|
-
if (options.signal?.aborted)
|
|
846
|
-
return;
|
|
847
|
-
yield* this.#streamEventsPolling(runId, { ...options, seenIds: new Set() });
|
|
848
|
-
}
|
|
849
|
-
/** Short alias for `streamEvents`. */
|
|
850
|
-
stream(runId, options) {
|
|
851
|
-
return this.streamEvents(runId, options);
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Stream the unified {@link AexEvent} envelope live over the coordinator
|
|
855
|
-
* WebSocket. The hosted API's ticket broker authorizes the connection (workspace
|
|
856
|
-
* token → short-lived coordinator ticket); the shared client replays from
|
|
857
|
-
* the cursor, tails live, and resumes exactly-once across reconnects. The
|
|
858
|
-
* ticket is re-minted on each (re)connect so a long run never outlives it.
|
|
859
|
-
*/
|
|
860
|
-
async *streamEnvelopes(runId, options = {}) {
|
|
861
|
-
const first = await operations.getCoordinatorTicket(this.#http, runId);
|
|
862
|
-
yield* streamCoordinatorEvents({
|
|
863
|
-
wsUrl: first.wsUrl,
|
|
864
|
-
from: options.from ?? 0,
|
|
865
|
-
fetchTicket: async () => (await operations.getCoordinatorTicket(this.#http, runId)).ticket,
|
|
866
|
-
// settleConsistent ends the stream on the post-mirror barrier instead of the
|
|
867
|
-
// earlier RUN_FINISHED UX signal, so "stream ended" ⇒ getRun is terminal.
|
|
868
|
-
...(options.settleConsistent ? { isTerminal: isRunSettled } : {}),
|
|
869
|
-
...(options.signal ? { signal: options.signal } : {})
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
async *#streamEventsPolling(runId, options) {
|
|
873
|
-
const intervalMs = options.intervalMs ?? 1_000;
|
|
874
|
-
const signal = options.signal;
|
|
875
|
-
while (!signal?.aborted) {
|
|
876
|
-
const events = await this.listEvents(runId);
|
|
877
|
-
for (const event of events) {
|
|
878
|
-
if (!options.seenIds.has(event.id)) {
|
|
879
|
-
options.seenIds.add(event.id);
|
|
880
|
-
yield event;
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
const run = await this.getRun(runId);
|
|
884
|
-
if (isTerminal(run.status))
|
|
885
|
-
return;
|
|
886
|
-
// `sleep` rejects on abort — treat that as a graceful stop.
|
|
887
|
-
try {
|
|
888
|
-
await sleep(intervalMs, signal);
|
|
889
|
-
}
|
|
890
|
-
catch {
|
|
891
|
-
return;
|
|
892
|
-
}
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
/**
|
|
896
|
-
* Poll the run record until it reaches a terminal status (succeeded,
|
|
897
|
-
* failed, terminated). Throws if `timeoutMs` elapses first.
|
|
898
|
-
*/
|
|
899
|
-
async waitForRun(runId, options = {}) {
|
|
900
|
-
const intervalMs = options.intervalMs ?? 1_500;
|
|
901
|
-
const timeoutMs = options.timeoutMs;
|
|
902
|
-
const signal = options.signal;
|
|
903
|
-
const deadline = typeof timeoutMs === "number" ? Date.now() + timeoutMs : Number.POSITIVE_INFINITY;
|
|
904
|
-
while (!signal?.aborted) {
|
|
905
|
-
const run = await this.getRun(runId);
|
|
906
|
-
if (isTerminal(run.status))
|
|
907
|
-
return run;
|
|
908
|
-
if (Date.now() >= deadline) {
|
|
909
|
-
throw new Error(`AgentExecutor.waitForRun: timeout after ${timeoutMs}ms`);
|
|
910
|
-
}
|
|
911
|
-
await sleep(intervalMs, signal);
|
|
912
|
-
}
|
|
913
|
-
throw new Error("AgentExecutor.waitForRun: aborted");
|
|
914
|
-
}
|
|
915
|
-
/** Short alias for `waitForRun`. */
|
|
916
|
-
wait(runId, options) {
|
|
917
|
-
return this.waitForRun(runId, options);
|
|
918
|
-
}
|
|
919
|
-
listOutputs(runId, query) {
|
|
920
|
-
return operations.listOutputs(this.#http, runId, query);
|
|
921
|
-
}
|
|
922
|
-
/** Short alias for `listOutputs`. */
|
|
923
|
-
outputs(runId, query) {
|
|
924
|
-
return this.listOutputs(runId, query);
|
|
925
|
-
}
|
|
926
|
-
findOutputs(runId, query) {
|
|
927
|
-
return operations.findOutputs(this.#http, runId, query);
|
|
928
|
-
}
|
|
929
|
-
findOutput(runId, query) {
|
|
930
|
-
return operations.findOutput(this.#http, runId, query);
|
|
931
|
-
}
|
|
932
|
-
outputLink(runId, selectorOrQuery, options) {
|
|
933
|
-
return operations.outputLink(this.#http, runId, selectorOrQuery, options);
|
|
934
|
-
}
|
|
935
|
-
createOutputLink(runId, selectorOrQuery, options) {
|
|
936
|
-
return this.outputLink(runId, selectorOrQuery, options);
|
|
937
|
-
}
|
|
938
|
-
async fetchOutput(runId, selectorOrQuery, options) {
|
|
939
|
-
const link = await this.outputLink(runId, selectorOrQuery, options);
|
|
940
|
-
return (this.#fetch ?? fetch)(link.url);
|
|
941
|
-
}
|
|
942
|
-
/**
|
|
943
|
-
* Read ONE output file as byte-capped, decoded UTF-8 text. Streams the file and
|
|
944
|
-
* STOPS at `options.maxBytes` (default 50 KB, ceiling 10 MB), so a huge
|
|
945
|
-
* deliverable never fully buffers — ideal for handing a run's output to an LLM
|
|
946
|
-
* tool. Check `result.truncated` before treating the text as complete; pass
|
|
947
|
-
* `options.grep` to keep only matching lines. Select by `{ path }` or `{ id }`,
|
|
948
|
-
* same as `downloadOutput`.
|
|
949
|
-
*/
|
|
950
|
-
readOutputText(runId, selector, options) {
|
|
951
|
-
return operations.readOutputText(this.#http, runId, selector, options);
|
|
952
|
-
}
|
|
953
|
-
eventArchiveLink(runId, options) {
|
|
954
|
-
return operations.eventArchiveLink(this.#http, runId, options);
|
|
955
|
-
}
|
|
956
|
-
async downloadOutput(runId, selectorOrOptions, options) {
|
|
957
|
-
const hasSelector = selectorOrOptions !== undefined && !isOutputDownloadOptionsOnly(selectorOrOptions);
|
|
958
|
-
const selector = hasSelector ? selectorOrOptions : undefined;
|
|
959
|
-
const to = hasSelector ? options?.to : selectorOrOptions?.to ?? options?.to;
|
|
960
|
-
let bytes;
|
|
961
|
-
if (selector === undefined) {
|
|
962
|
-
bytes = await operations.downloadOutputs(this.#http, runId);
|
|
963
|
-
}
|
|
964
|
-
else {
|
|
965
|
-
const output = isOutputPathSelector(selector)
|
|
966
|
-
? resolveOutputFileSelector(await operations.listOutputs(this.#http, runId), selector, runId)
|
|
967
|
-
: resolveOutputFileSelector([], selector, runId);
|
|
968
|
-
const { response } = await this.#http.download(`/api/runs/${encodeURIComponent(runId)}/outputs/${encodeURIComponent(output.id)}/download`);
|
|
969
|
-
bytes = new Uint8Array(await response.arrayBuffer());
|
|
970
|
-
}
|
|
971
|
-
return writeOptionalFile(bytes, to);
|
|
972
|
-
}
|
|
973
|
-
cancelRun(runId) {
|
|
974
|
-
return operations.cancelRun(this.#http, runId);
|
|
975
|
-
}
|
|
976
|
-
/** Short alias for `cancelRun`. */
|
|
977
|
-
cancel(runId) {
|
|
978
|
-
return this.cancelRun(runId);
|
|
979
|
-
}
|
|
980
|
-
deleteRun(runId) {
|
|
981
|
-
return operations.deleteRun(this.#http, runId);
|
|
982
|
-
}
|
|
983
|
-
/** Short alias for `deleteRun`. */
|
|
984
|
-
delete(runId) {
|
|
985
|
-
return this.deleteRun(runId);
|
|
986
|
-
}
|
|
987
|
-
/**
|
|
988
|
-
* List a run's webhook delivery attempts (the per-run delivery ledger).
|
|
989
|
-
* Empty when the run carried no `webhook` or has not yet terminated.
|
|
990
|
-
*/
|
|
991
|
-
getRunWebhookDeliveries(runId) {
|
|
992
|
-
return operations.getRunWebhookDeliveries(this.#http, runId);
|
|
993
|
-
}
|
|
994
|
-
/**
|
|
995
|
-
* Manually re-trigger a run's webhook delivery: re-sends the frozen payload
|
|
996
|
-
* with the SAME `webhook-id` so the consumer dedupes.
|
|
997
|
-
*/
|
|
998
|
-
redeliverRunWebhook(runId, deliveryId) {
|
|
999
|
-
return operations.redeliverRunWebhook(this.#http, runId, deliveryId);
|
|
1000
|
-
}
|
|
1001
775
|
/**
|
|
1002
776
|
* Delete a workspace asset blob from the shared content-addressed store
|
|
1003
777
|
* (`assets/<workspaceId>/<hash>`). Accepts `sha256:<hex>` or a bare
|
|
@@ -1009,29 +783,6 @@ export class AgentExecutor {
|
|
|
1009
783
|
whoami() {
|
|
1010
784
|
return operations.whoami(this.#http);
|
|
1011
785
|
}
|
|
1012
|
-
/**
|
|
1013
|
-
* Download EVERYTHING public about a run as one zip, assembled client-side
|
|
1014
|
-
* from the public read endpoints (`getRun` + `listEvents` +
|
|
1015
|
-
* `listOutputs` + per-output `/download`). Organised into the namespace
|
|
1016
|
-
* folders `metadata/`, `events/`, and `outputs/`, plus a `manifest.json`.
|
|
1017
|
-
* Pass `to` to also write the
|
|
1018
|
-
* bytes to a file path while still returning the bytes.
|
|
1019
|
-
*/
|
|
1020
|
-
async download(runId, options) {
|
|
1021
|
-
return writeOptionalFile(await operations.download(this.#http, runId), options?.to);
|
|
1022
|
-
}
|
|
1023
|
-
/** Download only the run's deliverables (the `outputs` namespace) as a zip. */
|
|
1024
|
-
async downloadOutputs(runId, options) {
|
|
1025
|
-
return writeOptionalFile(await operations.downloadOutputs(this.#http, runId), options?.to);
|
|
1026
|
-
}
|
|
1027
|
-
/** Download only the indexed event archive (the `events` namespace) as a zip. */
|
|
1028
|
-
async downloadEvents(runId, options) {
|
|
1029
|
-
return writeOptionalFile(await operations.downloadEvents(this.#http, runId), options?.to);
|
|
1030
|
-
}
|
|
1031
|
-
/** Download only the run record (the `metadata` namespace) as a zip. */
|
|
1032
|
-
async downloadMetadata(runId, options) {
|
|
1033
|
-
return writeOptionalFile(await operations.downloadMetadata(this.#http, runId), options?.to);
|
|
1034
|
-
}
|
|
1035
786
|
}
|
|
1036
787
|
/** Canonical SDK client name. `AgentExecutor` remains as a compatibility alias. */
|
|
1037
788
|
export class Aex extends AgentExecutor {
|
|
@@ -1043,6 +794,19 @@ const TERMINAL_STATUSES = new Set(TERMINAL_RUN_STATUSES);
|
|
|
1043
794
|
function isTerminal(status) {
|
|
1044
795
|
return typeof status === "string" && TERMINAL_STATUSES.has(status);
|
|
1045
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* A session is "parked" once it stops making progress: it reached one of the
|
|
799
|
+
* turn-terminal statuses (`idle` / `suspended` / `error`) or a terminal run
|
|
800
|
+
* status. `SessionHandle.wait` / `streamEvents` stop here.
|
|
801
|
+
*/
|
|
802
|
+
function isSessionParked(status) {
|
|
803
|
+
return (status === "idle" ||
|
|
804
|
+
status === "suspended" ||
|
|
805
|
+
status === "error" ||
|
|
806
|
+
status === "deleted" ||
|
|
807
|
+
status === "expired" ||
|
|
808
|
+
isTerminal(status));
|
|
809
|
+
}
|
|
1046
810
|
function sessionToRun(session) {
|
|
1047
811
|
const id = session.sessionId ?? session.id;
|
|
1048
812
|
return {
|
|
@@ -1075,13 +839,6 @@ function escapeRegExp(input) {
|
|
|
1075
839
|
function isOutputPathSelector(selector) {
|
|
1076
840
|
return Boolean(selector && typeof selector === "object" && "path" in selector);
|
|
1077
841
|
}
|
|
1078
|
-
function isOutputDownloadOptionsOnly(value) {
|
|
1079
|
-
return Boolean(value &&
|
|
1080
|
-
typeof value === "object" &&
|
|
1081
|
-
"to" in value &&
|
|
1082
|
-
!("id" in value) &&
|
|
1083
|
-
!("path" in value));
|
|
1084
|
-
}
|
|
1085
842
|
function resolveOutputFileSelector(outputs, selector, runId) {
|
|
1086
843
|
if (isOutputPathSelector(selector)) {
|
|
1087
844
|
const target = normalizeOutputLookupPath(selector.path);
|
|
@@ -1148,23 +905,6 @@ function generateIdempotencyKey() {
|
|
|
1148
905
|
return cryptoObj.randomUUID();
|
|
1149
906
|
return `idem-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
1150
907
|
}
|
|
1151
|
-
function normalisePrompt(input, surface = "AgentExecutor.submit", field = "prompt") {
|
|
1152
|
-
if (typeof input === "string") {
|
|
1153
|
-
if (!input) {
|
|
1154
|
-
throw new RunConfigValidationError(`${surface}: ${field} must be a non-empty string`);
|
|
1155
|
-
}
|
|
1156
|
-
return [input];
|
|
1157
|
-
}
|
|
1158
|
-
if (!Array.isArray(input) || input.length === 0) {
|
|
1159
|
-
throw new RunConfigValidationError(`${surface}: ${field} must be a non-empty string or string array`);
|
|
1160
|
-
}
|
|
1161
|
-
for (const segment of input) {
|
|
1162
|
-
if (typeof segment !== "string" || !segment) {
|
|
1163
|
-
throw new RunConfigValidationError(`${surface}: ${field} segments must be non-empty strings`);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
return [...input];
|
|
1167
|
-
}
|
|
1168
908
|
function normaliseSessionInput(input, surface, field) {
|
|
1169
909
|
if (typeof input === "string") {
|
|
1170
910
|
if (!input) {
|
|
@@ -1182,18 +922,6 @@ function normaliseSessionInput(input, surface, field) {
|
|
|
1182
922
|
}
|
|
1183
923
|
return [...input];
|
|
1184
924
|
}
|
|
1185
|
-
function assertNoRemovedSubmitFields(options, surface, extraFields = []) {
|
|
1186
|
-
const record = options;
|
|
1187
|
-
for (const field of ["credentialMode", "runtime", "region", "apiKey", "credentials", "postHook", ...extraFields]) {
|
|
1188
|
-
if (Object.prototype.hasOwnProperty.call(record, field)) {
|
|
1189
|
-
throw new RunConfigValidationError(`${surface}: ${field} is not a supported option; use the managed path with secrets.apiKeys[provider].`);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
const secrets = record.secrets;
|
|
1193
|
-
if (secrets && typeof secrets === "object" && !Array.isArray(secrets) && Object.prototype.hasOwnProperty.call(secrets, "apiKey")) {
|
|
1194
|
-
throw new RunConfigValidationError(`${surface}: secrets.apiKey is not supported; use secrets.apiKeys[provider].`);
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
925
|
function assertNoLegacySessionFields(options, surface) {
|
|
1198
926
|
const record = options;
|
|
1199
927
|
const messages = {
|
|
@@ -1204,14 +932,14 @@ function assertNoLegacySessionFields(options, surface) {
|
|
|
1204
932
|
idleTtl: "use overrides.idleTtl.",
|
|
1205
933
|
retention: "use overrides.idleTtl.",
|
|
1206
934
|
secretEnv: "use environment.secrets.",
|
|
935
|
+
skills: "skills are now tools; build one with Tools.fromSkillDir/fromSkillUrl and pass it in tools.",
|
|
1207
936
|
secrets: "use top-level apiKeys for provider keys and environment.secrets for run secrets.",
|
|
1208
937
|
runtimeSize: "use runtime.",
|
|
1209
938
|
parentRunId: "subagents are session-internal; parentRunId is not part of the session API.",
|
|
1210
939
|
limits: "use overrides.",
|
|
1211
940
|
timeout: "use overrides.timeout.",
|
|
1212
941
|
signal: "use session.cancel() / session.suspend() for remote control.",
|
|
1213
|
-
postHook: "send a follow-up validation message when the session returns idle."
|
|
1214
|
-
webhook: "send a follow-up validation message instead of a submit webhook."
|
|
942
|
+
postHook: "send a follow-up validation message when the session returns idle."
|
|
1215
943
|
};
|
|
1216
944
|
for (const [field, message] of Object.entries(messages)) {
|
|
1217
945
|
if (Object.prototype.hasOwnProperty.call(record, field)) {
|
|
@@ -1232,15 +960,6 @@ function assertNoSessionSendSignal(options, surface) {
|
|
|
1232
960
|
throw new RunConfigValidationError(`${surface}: signal is not a supported option; use session.cancel() / session.suspend() for remote control.`);
|
|
1233
961
|
}
|
|
1234
962
|
}
|
|
1235
|
-
function validateSubmitCredentials(options, provider, surface) {
|
|
1236
|
-
if (options.parentRunId) {
|
|
1237
|
-
return;
|
|
1238
|
-
}
|
|
1239
|
-
const key = options.secrets?.apiKeys?.[provider];
|
|
1240
|
-
if (typeof key !== "string" || key.length === 0) {
|
|
1241
|
-
throw new RunConfigValidationError(`${surface}: a provider API key is required — pass secrets.apiKeys[${JSON.stringify(provider)}].`);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
963
|
function validateApiKeys(apiKeys, provider, surface) {
|
|
1245
964
|
const key = apiKeys?.[provider];
|
|
1246
965
|
if (typeof key !== "string" || key.length === 0) {
|
|
@@ -1304,42 +1023,17 @@ async function resolveAssetId(entry, bundle, uploader) {
|
|
|
1304
1023
|
entry._rememberAsset(uploaded.assetId);
|
|
1305
1024
|
return uploaded.assetId;
|
|
1306
1025
|
}
|
|
1307
|
-
/** Walk Skill[], eagerly upload drafts as assets, and return plain asset refs. */
|
|
1308
|
-
async function prepareSkills(skills, uploader) {
|
|
1309
|
-
const refs = [];
|
|
1310
|
-
for (let i = 0; i < skills.length; i++) {
|
|
1311
|
-
const entry = skills[i];
|
|
1312
|
-
if (!(entry instanceof Skill)) {
|
|
1313
|
-
throw new RunConfigValidationError(`AgentExecutor.submit: skills[${i}] must be a Skill instance`);
|
|
1314
|
-
}
|
|
1315
|
-
const ref = entry.ref;
|
|
1316
|
-
if (ref.kind === "draft") {
|
|
1317
|
-
const bundle = entry._takeDraftBundle();
|
|
1318
|
-
if (!bundle) {
|
|
1319
|
-
throw new RunConfigValidationError(`AgentExecutor.submit: skills[${i}] is draft but has no bytes`);
|
|
1320
|
-
}
|
|
1321
|
-
const assetId = await resolveAssetId(entry, bundle, uploader);
|
|
1322
|
-
refs.push({
|
|
1323
|
-
kind: "asset",
|
|
1324
|
-
assetId,
|
|
1325
|
-
name: bundle.name
|
|
1326
|
-
});
|
|
1327
|
-
continue;
|
|
1328
|
-
}
|
|
1329
|
-
// Already-materialized asset ref.
|
|
1330
|
-
refs.push(ref);
|
|
1331
|
-
}
|
|
1332
|
-
return refs;
|
|
1333
|
-
}
|
|
1334
1026
|
/**
|
|
1335
1027
|
* Split the `tools` union into custom tool refs (drafts eagerly uploaded as
|
|
1336
|
-
* assets)
|
|
1337
|
-
*
|
|
1338
|
-
*
|
|
1339
|
-
* caller
|
|
1028
|
+
* assets), skill-tool refs (skill bundles eagerly uploaded as assets), and
|
|
1029
|
+
* builtin tool-name references (bare strings, validated against the closed
|
|
1030
|
+
* {@link BUILTIN_TOOL_NAMES} set). Builtin names are deduped, in input order;
|
|
1031
|
+
* the three groups are recombined on the wire by the caller (the BFF parser
|
|
1032
|
+
* splits them back apart by kind).
|
|
1340
1033
|
*/
|
|
1341
1034
|
async function prepareTools(tools, uploader) {
|
|
1342
1035
|
const refs = [];
|
|
1036
|
+
const skillToolRefs = [];
|
|
1343
1037
|
const seenBuiltins = new Set();
|
|
1344
1038
|
const builtinNames = [];
|
|
1345
1039
|
for (let i = 0; i < tools.length; i++) {
|
|
@@ -1347,8 +1041,8 @@ async function prepareTools(tools, uploader) {
|
|
|
1347
1041
|
// A bare string is a builtin tool reference.
|
|
1348
1042
|
if (typeof entry === "string") {
|
|
1349
1043
|
if (!BUILTIN_TOOL_NAMES.includes(entry)) {
|
|
1350
|
-
throw new RunConfigValidationError(`
|
|
1351
|
-
`expected a Tool
|
|
1044
|
+
throw new RunConfigValidationError(`aex: tools[${i}] (${JSON.stringify(entry)}) is not a builtin tool name; ` +
|
|
1045
|
+
`expected a Tool, a SkillTool, or one of: ${BUILTIN_TOOL_NAMES.join(", ")}`);
|
|
1352
1046
|
}
|
|
1353
1047
|
if (!seenBuiltins.has(entry)) {
|
|
1354
1048
|
seenBuiltins.add(entry);
|
|
@@ -1356,14 +1050,29 @@ async function prepareTools(tools, uploader) {
|
|
|
1356
1050
|
}
|
|
1357
1051
|
continue;
|
|
1358
1052
|
}
|
|
1053
|
+
// A skill-tool: upload its bundle (if a draft) and emit a `kind:"skill"` ref.
|
|
1054
|
+
if (entry instanceof SkillTool) {
|
|
1055
|
+
const ref = entry.ref;
|
|
1056
|
+
if (ref.kind === "draft") {
|
|
1057
|
+
const bundle = entry._takeDraftBundle();
|
|
1058
|
+
if (!bundle) {
|
|
1059
|
+
throw new RunConfigValidationError(`aex: tools[${i}] is a draft skill-tool but has no bytes`);
|
|
1060
|
+
}
|
|
1061
|
+
const assetId = await resolveAssetId(entry, bundle, uploader);
|
|
1062
|
+
skillToolRefs.push({ kind: "skill", assetId, name: bundle.name, description: bundle.description });
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
skillToolRefs.push(ref);
|
|
1066
|
+
continue;
|
|
1067
|
+
}
|
|
1359
1068
|
if (!(entry instanceof Tool)) {
|
|
1360
|
-
throw new RunConfigValidationError(`
|
|
1069
|
+
throw new RunConfigValidationError(`aex: tools[${i}] must be a Tool, a SkillTool, or a builtin tool name`);
|
|
1361
1070
|
}
|
|
1362
1071
|
const ref = entry.ref;
|
|
1363
1072
|
if (ref.kind === "draft") {
|
|
1364
1073
|
const bundle = entry._takeDraftBundle();
|
|
1365
1074
|
if (!bundle) {
|
|
1366
|
-
throw new RunConfigValidationError(`
|
|
1075
|
+
throw new RunConfigValidationError(`aex: tools[${i}] is draft but has no bytes`);
|
|
1367
1076
|
}
|
|
1368
1077
|
const assetId = await resolveAssetId(entry, bundle, uploader);
|
|
1369
1078
|
refs.push({ ...bundle.ref, assetId });
|
|
@@ -1371,7 +1080,7 @@ async function prepareTools(tools, uploader) {
|
|
|
1371
1080
|
}
|
|
1372
1081
|
refs.push(ref);
|
|
1373
1082
|
}
|
|
1374
|
-
return { refs, builtinNames };
|
|
1083
|
+
return { refs, skillToolRefs, builtinNames };
|
|
1375
1084
|
}
|
|
1376
1085
|
/** Walk AgentsMd[], eagerly upload drafts as assets, and return plain asset refs. */
|
|
1377
1086
|
async function prepareAgentsMd(agentsMds, uploader) {
|
|
@@ -1379,13 +1088,13 @@ async function prepareAgentsMd(agentsMds, uploader) {
|
|
|
1379
1088
|
for (let i = 0; i < agentsMds.length; i++) {
|
|
1380
1089
|
const entry = agentsMds[i];
|
|
1381
1090
|
if (!(entry instanceof AgentsMd)) {
|
|
1382
|
-
throw new RunConfigValidationError(`
|
|
1091
|
+
throw new RunConfigValidationError(`aex: agentsMd[${i}] must be an AgentsMd instance`);
|
|
1383
1092
|
}
|
|
1384
1093
|
const ref = entry.ref;
|
|
1385
1094
|
if (ref.kind === "draft") {
|
|
1386
1095
|
const bundle = entry._takeDraftBundle();
|
|
1387
1096
|
if (!bundle) {
|
|
1388
|
-
throw new RunConfigValidationError(`
|
|
1097
|
+
throw new RunConfigValidationError(`aex: agentsMd[${i}] is draft but has no bytes`);
|
|
1389
1098
|
}
|
|
1390
1099
|
const assetId = await resolveAssetId(entry, bundle, uploader);
|
|
1391
1100
|
refs.push({
|
|
@@ -1405,13 +1114,13 @@ async function prepareFiles(files, uploader) {
|
|
|
1405
1114
|
for (let i = 0; i < files.length; i++) {
|
|
1406
1115
|
const entry = files[i];
|
|
1407
1116
|
if (!(entry instanceof File)) {
|
|
1408
|
-
throw new RunConfigValidationError(`
|
|
1117
|
+
throw new RunConfigValidationError(`aex: files[${i}] must be a File instance`);
|
|
1409
1118
|
}
|
|
1410
1119
|
const ref = entry.ref;
|
|
1411
1120
|
if (ref.kind === "draft") {
|
|
1412
1121
|
const bundle = entry._takeDraftBundle();
|
|
1413
1122
|
if (!bundle) {
|
|
1414
|
-
throw new RunConfigValidationError(`
|
|
1123
|
+
throw new RunConfigValidationError(`aex: files[${i}] is draft but has no bytes`);
|
|
1415
1124
|
}
|
|
1416
1125
|
const assetId = await resolveAssetId(entry, bundle, uploader);
|
|
1417
1126
|
refs.push({
|
|
@@ -1426,13 +1135,6 @@ async function prepareFiles(files, uploader) {
|
|
|
1426
1135
|
}
|
|
1427
1136
|
return refs;
|
|
1428
1137
|
}
|
|
1429
|
-
function getSubmittedRunId(response) {
|
|
1430
|
-
const id = response.id ?? response.runId;
|
|
1431
|
-
if (typeof id !== "string" || id.length === 0) {
|
|
1432
|
-
throw new RunStateError("AgentExecutor.submit: submit response did not include a run id");
|
|
1433
|
-
}
|
|
1434
|
-
return id;
|
|
1435
|
-
}
|
|
1436
1138
|
function mergeMcpServers(inputs, explicitSecrets) {
|
|
1437
1139
|
const submissionMcpServers = [];
|
|
1438
1140
|
const secretByName = new Map();
|
|
@@ -1442,14 +1144,14 @@ function mergeMcpServers(inputs, explicitSecrets) {
|
|
|
1442
1144
|
for (let i = 0; i < inputs.length; i++) {
|
|
1443
1145
|
const entry = inputs[i];
|
|
1444
1146
|
if (!(entry instanceof McpServer)) {
|
|
1445
|
-
throw new RunConfigValidationError(`
|
|
1147
|
+
throw new RunConfigValidationError(`aex: mcpServers[${i}] must be an McpServer instance`);
|
|
1446
1148
|
}
|
|
1447
1149
|
submissionMcpServers.push(entry.toSubmissionEntry());
|
|
1448
1150
|
const secret = entry.toSecretEntry();
|
|
1449
1151
|
if (secret) {
|
|
1450
1152
|
const existing = secretByName.get(secret.name);
|
|
1451
1153
|
if (existing && existing.url !== secret.url) {
|
|
1452
|
-
throw new RunConfigValidationError(`
|
|
1154
|
+
throw new RunConfigValidationError(`aex: mcpServers[${i}].url conflicts with secrets.mcpServers["${secret.name}"]`);
|
|
1453
1155
|
}
|
|
1454
1156
|
secretByName.set(secret.name, secret);
|
|
1455
1157
|
}
|
|
@@ -1477,7 +1179,7 @@ function mergeProxyEndpointAuth(fromInstances, fromExplicitSecrets) {
|
|
|
1477
1179
|
for (const entry of fromInstances) {
|
|
1478
1180
|
const existing = byName.get(entry.name);
|
|
1479
1181
|
if (existing && existing.value.type !== entry.value.type) {
|
|
1480
|
-
throw new RunConfigValidationError(`
|
|
1182
|
+
throw new RunConfigValidationError(`aex: proxyEndpoint "${entry.name}" auth type conflicts ` +
|
|
1481
1183
|
`with secrets.proxyEndpointAuth (instance=${entry.value.type}, secrets=${existing.value.type})`);
|
|
1482
1184
|
}
|
|
1483
1185
|
byName.set(entry.name, entry);
|