withruntime 0.35.0 → 0.45.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/BLAXEL.md +207 -204
- package/COMPATIBILITY.md +367 -337
- package/DAYTONA.md +180 -173
- package/E2B.md +246 -230
- package/README.md +182 -142
- package/README.src.md +182 -142
- package/VERCEL.md +173 -168
- package/agent-platforms-inventory.json +387 -0
- package/dist/agents-cli.d.ts +7 -1
- package/dist/agents-cli.js +470 -6
- package/dist/agents-deploy.d.ts +1 -1
- package/dist/agents-deploy.js +62 -1
- package/dist/apps-cli.d.ts +3 -3
- package/dist/apps-cli.js +10 -5
- package/dist/browsers-cli.d.ts +1 -1
- package/dist/browsers-cli.js +122 -3
- package/dist/ci-cli.d.ts +11 -1
- package/dist/ci-cli.js +69 -6
- package/dist/cli-update.d.ts +11 -0
- package/dist/cli-update.js +46 -0
- package/dist/cli-words.js +1 -0
- package/dist/cli.d.ts +4 -6
- package/dist/cli.js +249 -58
- package/dist/daytona/daytona.js +1 -1
- package/dist/e2b/sandbox.d.ts +6 -5
- package/dist/e2b/sandbox.js +6 -5
- package/dist/errors.d.ts +4 -3
- package/dist/errors.js +7 -3
- package/dist/index.d.ts +5 -5
- package/dist/inngest/index.d.ts +96 -0
- package/dist/inngest/index.js +183 -0
- package/dist/jobs-code/cron.d.ts +12 -0
- package/dist/jobs-code/cron.js +93 -0
- package/dist/jobs-code/registry.d.ts +31 -0
- package/dist/jobs-code/registry.js +30 -0
- package/dist/jobs-code/runner.d.ts +1 -0
- package/dist/jobs-code/runner.js +74 -0
- package/dist/jobs-deploy.d.ts +22 -0
- package/dist/jobs-deploy.js +247 -0
- package/dist/jobs-import.d.ts +15 -0
- package/dist/jobs-import.js +231 -0
- package/dist/products/agents.d.ts +413 -2
- package/dist/products/agents.js +176 -0
- package/dist/products/apps.d.ts +2 -1
- package/dist/products/browsers.d.ts +87 -0
- package/dist/products/browsers.js +67 -0
- package/dist/products/builds.d.ts +11 -2
- package/dist/products/ci.d.ts +21 -1
- package/dist/products/jobs.d.ts +77 -0
- package/dist/products/jobs.js +5 -0
- package/dist/products/observability.d.ts +31 -3
- package/dist/products/plans.d.ts +5 -3
- package/dist/products/secrets.d.ts +67 -14
- package/dist/products/secrets.js +41 -12
- package/dist/transport.d.ts +6 -1
- package/dist/transport.js +38 -1
- package/dist/trigger/index.d.ts +202 -0
- package/dist/trigger/index.js +244 -0
- package/dist/types.d.ts +14 -0
- package/package.json +14 -3
package/dist/agents-cli.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
2
2
|
import { dirname, join, resolve } from "node:path";
|
|
3
3
|
import { me, named } from "./cli-name.js";
|
|
4
4
|
import { AGENT_TEMPLATES, agentTemplate, AGENT_USES, agents, } from "./products/agents.js";
|
|
5
|
+
import { secrets } from "./products/secrets.js";
|
|
5
6
|
export const AGENT_HELP = `runtime agents <command>
|
|
6
7
|
|
|
7
8
|
An agent runs a harness (Claude Code, Codex, Gemini CLI, or your own code on
|
|
@@ -21,33 +22,75 @@ export const AGENT_HELP = `runtime agents <command>
|
|
|
21
22
|
create <name> (--template <harness> | --command "<cmd>") [--use support|team]
|
|
22
23
|
[--instructions <text> | --instructions-file <path>] [--secret NAME]... [--pool NAME]...
|
|
23
24
|
[--env KEY=VALUE]... [--image <image> | --snapshot <id>] [--vcpu n] [--memory n]
|
|
24
|
-
[--max-concurrent n] [--idle-pause n] [--
|
|
25
|
+
[--max-concurrent n] [--idle-pause n] [--max-children n] [--advisor <model>]
|
|
26
|
+
[--advisor-secret NAME] [--model <model>] [--session-overrides '<json>']
|
|
27
|
+
[--permissions '<json>'] [--label key=value]...
|
|
25
28
|
Make an agent; prints its id. --secret names an egress
|
|
26
29
|
secret it may use: its model key, of any provider.
|
|
27
30
|
--pool names a Claude account's secret (each one
|
|
28
31
|
given replaces the template's): each session takes
|
|
29
|
-
the one with the most usage left
|
|
32
|
+
the one with the most usage left. --advisor names a
|
|
33
|
+
model its sessions may ask for advice (advise), its
|
|
34
|
+
key the egress secret --advisor-secret names (that
|
|
35
|
+
provider's usual one by default, among --secret).
|
|
36
|
+
--session-overrides sets what a session's start may
|
|
37
|
+
override:
|
|
38
|
+
'{"models":["claude-opus-5-5"],"instructions":"replace",
|
|
39
|
+
"maxVcpu":8,"maxMemoryMiB":16384,"maxSessionDollars":20}'
|
|
30
40
|
ls Your agents
|
|
31
41
|
get <agent> One agent, in full (an id or its name)
|
|
32
42
|
update <agent> [the options of create] A new version: what you give changes, the rest stays
|
|
33
43
|
rm <agent> Delete it, its triggers, and stop its sessions
|
|
34
|
-
start <agent> <words...> [--key <key>] [--follow]
|
|
44
|
+
start <agent> <words...> [--key <key>] [--follow] [--model <model>]
|
|
45
|
+
[--instructions <text> | --instructions-file <path>] [--replace-instructions]
|
|
46
|
+
[--mcp <server>]... [--no-mcp] [--disallow <tool>]... [--vcpu n] [--memory n]
|
|
47
|
+
[--max-dollars n]
|
|
35
48
|
A session with these words, or the open one with the
|
|
36
49
|
key (such as customer:42); --follow prints its log
|
|
37
|
-
until it ends
|
|
50
|
+
until it ends. The other options override the
|
|
51
|
+
agent's definition for this session alone, within
|
|
52
|
+
its session overrides: its model, instructions added
|
|
53
|
+
(or in place of the agent's), the MCP servers it
|
|
54
|
+
keeps, tools it may not use, its size and budget
|
|
38
55
|
send <session> <words...> Words into a session
|
|
39
56
|
events <session> [--after <seq>] [--follow] A session's log; --follow until it ends
|
|
57
|
+
trace <session> [--otlp] [--export [--endpoint <url>] [--header key=value]...]
|
|
58
|
+
Every model turn and tool call: timing, tokens and
|
|
59
|
+
cost, totals by model and tool. --otlp prints
|
|
60
|
+
OpenTelemetry traces (OTLP/JSON); --export sends them
|
|
61
|
+
to a collector (--endpoint, or
|
|
62
|
+
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT /
|
|
63
|
+
OTEL_EXPORTER_OTLP_ENDPOINT and _HEADERS)
|
|
40
64
|
sessions [--agent <agent>] [--state <state>]...
|
|
41
65
|
Sessions, newest first
|
|
42
66
|
sessions delete <session> Delete an ended session and its log; its history is
|
|
43
67
|
storage, kept until you delete it
|
|
44
68
|
stop <session> Stop a session
|
|
69
|
+
switch anthropic Run Claude Managed Agents code on Runtime: the
|
|
70
|
+
base URL to give Anthropic's SDK, and whether
|
|
71
|
+
the model key (ANTHROPIC_API_KEY) is set
|
|
45
72
|
asks [--state <state>]... [--agent <agent>] [--label key=value]...
|
|
46
73
|
The inbox: what your agents' sessions need answered,
|
|
47
74
|
one row per step however many sessions ask it
|
|
48
75
|
asks get <ask> One ask: its options, pick and the sessions asking
|
|
49
76
|
answer <ask> [<option>] [--text <words>] Answer it with an option's label, words, or both:
|
|
50
77
|
every session asking reads it next and wakes
|
|
78
|
+
workflow run <file.json | -> [--follow] Run a workflow: many sessions in phases, fanned out
|
|
79
|
+
and pipelined, with maxSessions, maxConcurrent and
|
|
80
|
+
maxDollars; prints its id, or --follow prints each
|
|
81
|
+
phase's progress until it ends, then its result
|
|
82
|
+
workflow get <workflow> Its state, each phase's progress, cost and result
|
|
83
|
+
workflow watch <workflow> Its progress as it changes, until it ends
|
|
84
|
+
workflow steps <workflow> [--state <state>]...
|
|
85
|
+
Each step: its phase, item, session and state
|
|
86
|
+
workflow stop <workflow> Nothing more starts; its open sessions stop
|
|
87
|
+
workflows [--state running|done|failed|stopped]...
|
|
88
|
+
Workflows, newest first
|
|
89
|
+
approve <ask> Let a tool call the agent's permissions held run
|
|
90
|
+
deny <ask> [--message <words>] Keep a held tool call from running; the message is
|
|
91
|
+
told to the agent
|
|
92
|
+
slack install A link that adds Runtime's Slack app to a workspace
|
|
93
|
+
slack ls | rm <team> The workspaces added; remove one
|
|
51
94
|
triggers <agent> Its triggers
|
|
52
95
|
triggers add <agent> --kind <slack|github|schedule|webhook> --config '<json>' [--rules '<json>']
|
|
53
96
|
triggers rules <triggerId> '<json>' Set its rules in place: priority, maxStartsPerHour,
|
|
@@ -82,12 +125,20 @@ Examples
|
|
|
82
125
|
printf %s "$ANTHROPIC_API_KEY" | runtime secrets set ANTHROPIC_API_KEY --host api.anthropic.com
|
|
83
126
|
runtime agents create helper --template claude-code --use support --instructions "Answer briefly."
|
|
84
127
|
runtime agents start helper "How do I reset my password?" --key customer:42 --follow
|
|
128
|
+
runtime agents start helper "Summarize this ticket" --model claude-haiku-5-5 --disallow Bash
|
|
85
129
|
runtime agents memory put helper faq/refunds.md refunds.md
|
|
86
130
|
runtime agents asks && runtime agents answer <ask> "Raise to 20 TB"
|
|
131
|
+
runtime agents workflow run review.json --follow
|
|
132
|
+
runtime agents update helper --permissions '{"default":"auto","tools":{"shell":"always_ask"}}'
|
|
133
|
+
runtime agents approve <ask>
|
|
134
|
+
runtime agents trace <session> --export --endpoint https://otel.example.com
|
|
87
135
|
runtime agents init --template claude-code && runtime agents deploy --dry-run
|
|
88
136
|
runtime agents create ci-review --template review --pool CLAUDE_1 --pool CLAUDE_2
|
|
137
|
+
runtime agents switch anthropic
|
|
89
138
|
`;
|
|
90
139
|
const when = (iso) => iso ?? "-";
|
|
140
|
+
/** The guide to running Claude Managed Agents code on Runtime. */
|
|
141
|
+
const SWITCH_DOCS = "https://withruntime.com/docs/switch-from-claude-managed-agents";
|
|
91
142
|
/** A trigger's rules as the CLI takes them: one JSON object. */
|
|
92
143
|
function rulesOf(text, kit) {
|
|
93
144
|
let rules;
|
|
@@ -116,6 +167,12 @@ const OPTIONS = [
|
|
|
116
167
|
"memory",
|
|
117
168
|
"max-concurrent",
|
|
118
169
|
"idle-pause",
|
|
170
|
+
"model",
|
|
171
|
+
"session-overrides",
|
|
172
|
+
"max-children",
|
|
173
|
+
"advisor",
|
|
174
|
+
"advisor-secret",
|
|
175
|
+
"permissions",
|
|
119
176
|
"label",
|
|
120
177
|
];
|
|
121
178
|
const ASK_STATES = ["open", "answered", "expired", "withdrawn", "closed"];
|
|
@@ -125,6 +182,7 @@ const askLine = (a) => {
|
|
|
125
182
|
`${a.id} ${a.state}${a.step ? ` step ${a.step}` : ""}, ${a.sessions.length} session${a.sessions.length === 1 ? "" : "s"} asking`,
|
|
126
183
|
` ${a.question}`,
|
|
127
184
|
...(a.why ? [` why: ${a.why}`] : []),
|
|
185
|
+
...(a.toolCall ? [` tool call: ${a.toolCall.tool} ${JSON.stringify(a.toolCall.input)}`] : []),
|
|
128
186
|
...(options.length ? [` options: ${options.join(" | ")}`] : []),
|
|
129
187
|
...(a.expiresAt ? [` expires ${a.expiresAt}`] : []),
|
|
130
188
|
...(a.answer
|
|
@@ -188,9 +246,142 @@ function definitionOf(args, kit, env, base) {
|
|
|
188
246
|
set("memoryMiB", integer(args, "memory"));
|
|
189
247
|
set("maxConcurrent", integer(args, "max-concurrent"));
|
|
190
248
|
set("idlePauseSeconds", integer(args, "idle-pause"));
|
|
249
|
+
set("model", flag(args, "model"));
|
|
250
|
+
const limits = flag(args, "session-overrides");
|
|
251
|
+
if (limits !== undefined)
|
|
252
|
+
set("sessionOverrides", jsonObject(limits, "--session-overrides", kit));
|
|
253
|
+
set("maxChildren", integer(args, "max-children"));
|
|
254
|
+
const advisor = flag(args, "advisor");
|
|
255
|
+
const advisorSecret = flag(args, "advisor-secret");
|
|
256
|
+
if (advisorSecret !== undefined && advisor === undefined && !definition.advisor)
|
|
257
|
+
throw usage("Give --advisor <model> with --advisor-secret.");
|
|
258
|
+
if (advisor !== undefined || advisorSecret !== undefined)
|
|
259
|
+
set("advisor", {
|
|
260
|
+
...(definition.advisor ?? {}),
|
|
261
|
+
...(advisor === undefined ? {} : { model: advisor }),
|
|
262
|
+
...(advisorSecret === undefined ? {} : { secret: advisorSecret }),
|
|
263
|
+
});
|
|
264
|
+
const permissions = flag(args, "permissions");
|
|
265
|
+
if (permissions !== undefined) {
|
|
266
|
+
try {
|
|
267
|
+
set("permissions", JSON.parse(permissions));
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
throw usage(`--permissions takes JSON: '{"default":"auto","tools":{"shell":"always_ask"}}'.`);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
191
273
|
return definition;
|
|
192
274
|
}
|
|
193
|
-
|
|
275
|
+
/** A flag's JSON object, or a usage error that says so. */
|
|
276
|
+
function jsonObject(text, name, kit) {
|
|
277
|
+
let value;
|
|
278
|
+
try {
|
|
279
|
+
value = JSON.parse(text);
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
value = undefined;
|
|
283
|
+
}
|
|
284
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
285
|
+
throw kit.usage(`${name} takes a JSON object, such as '{"models":["claude-opus-5-5"]}'.`);
|
|
286
|
+
return value;
|
|
287
|
+
}
|
|
288
|
+
/** A session's overrides, from start's options; none given, none. */
|
|
289
|
+
function overridesOf(args, kit) {
|
|
290
|
+
const { flag, has, integer, usage } = kit;
|
|
291
|
+
const file = flag(args, "instructions-file");
|
|
292
|
+
const instructions = file !== undefined ? readFileSync(file, "utf8") : flag(args, "instructions");
|
|
293
|
+
if (has(args, "replace-instructions") && instructions === undefined)
|
|
294
|
+
throw usage("--replace-instructions needs --instructions or --instructions-file.");
|
|
295
|
+
if (has(args, "no-mcp") && args.flags.has("mcp"))
|
|
296
|
+
throw usage("Give --mcp or --no-mcp, not both.");
|
|
297
|
+
const dollars = flag(args, "max-dollars");
|
|
298
|
+
if (dollars !== undefined && !(Number(dollars) > 0))
|
|
299
|
+
throw usage("--max-dollars takes a number of dollars, such as 2.5.");
|
|
300
|
+
const o = {};
|
|
301
|
+
const model = flag(args, "model");
|
|
302
|
+
if (model !== undefined)
|
|
303
|
+
o.model = model;
|
|
304
|
+
if (instructions !== undefined)
|
|
305
|
+
o.instructions = instructions;
|
|
306
|
+
if (has(args, "replace-instructions"))
|
|
307
|
+
o.instructionsMode = "replace";
|
|
308
|
+
if (has(args, "no-mcp"))
|
|
309
|
+
o.mcp = [];
|
|
310
|
+
else if (args.flags.has("mcp"))
|
|
311
|
+
o.mcp = [...new Set(args.flags.get("mcp"))];
|
|
312
|
+
if (args.flags.has("disallow"))
|
|
313
|
+
o.disallowedTools = [...new Set(args.flags.get("disallow"))];
|
|
314
|
+
const vcpu = integer(args, "vcpu");
|
|
315
|
+
if (vcpu !== undefined)
|
|
316
|
+
o.vcpu = vcpu;
|
|
317
|
+
const memory = integer(args, "memory");
|
|
318
|
+
if (memory !== undefined)
|
|
319
|
+
o.memoryMiB = memory;
|
|
320
|
+
if (dollars !== undefined)
|
|
321
|
+
o.maxSessionDollars = Number(dollars);
|
|
322
|
+
return Object.keys(o).length ? o : undefined;
|
|
323
|
+
}
|
|
324
|
+
const WORKFLOW_STATES = ["running", "done", "failed", "stopped"];
|
|
325
|
+
/** A workflow in a few lines: its state, cost, each phase's progress and,
|
|
326
|
+
* once ended, its result. */
|
|
327
|
+
const workflowLines = (w) => [
|
|
328
|
+
`${w.id}${w.name ? ` ${w.name}` : ""} ${w.state}${w.reason && w.reason !== "done" ? ` (${w.reason})` : ""}, ${w.started} session${w.started === 1 ? "" : "s"}, $${w.cost.dollars.toFixed(2)} of $${w.maxDollars}`,
|
|
329
|
+
...w.phases.map((p) => ` ${p.name.padEnd(16)} ${p.done}/${p.total}${p.ready ? "" : "+"} done, ${p.running} running, ${p.pending} waiting${p.failed ? `, ${p.failed} failed` : ""}`),
|
|
330
|
+
...(w.result !== null ? ["", w.result] : []),
|
|
331
|
+
].join("\n");
|
|
332
|
+
const line = (e) => `${String(e.seq).padStart(4)} ${e.kind.padEnd(6)} ${e.actor}: ${e.kind === "turn"
|
|
333
|
+
? turnLine(e.body)
|
|
334
|
+
: e.kind === "tool"
|
|
335
|
+
? toolLine(e.body)
|
|
336
|
+
: typeof e.body.text === "string"
|
|
337
|
+
? e.body.text
|
|
338
|
+
: JSON.stringify(e.body)}`;
|
|
339
|
+
const count = (n) => n.toLocaleString("en-US");
|
|
340
|
+
const seconds = (ms) => `${(ms / 1000).toFixed(1)} s`;
|
|
341
|
+
const dollars = (usd) => usd === null ? "unpriced" : `$${usd < 1 ? usd.toFixed(4) : usd.toFixed(2)}`;
|
|
342
|
+
function turnLine(t) {
|
|
343
|
+
const calls = t.toolCalls.length ? ` -> ${t.toolCalls.map((c) => c.name).join(", ")}` : "";
|
|
344
|
+
const failed = t.error ? ` FAILED ${t.error}` : "";
|
|
345
|
+
return `${t.model} ${seconds(t.durationMs)}, ${count(t.inputTokens)} in, ${count(t.outputTokens)} out, ${count(t.cacheReadTokens)} cached, ${dollars(t.costUsd)}${calls}${failed}`;
|
|
346
|
+
}
|
|
347
|
+
function toolLine(t) {
|
|
348
|
+
return `${t.name} ${seconds(t.durationMs)}${t.error ? " FAILED" : ""}${t.input ? ` ${t.input.slice(0, 100)}` : ""}`;
|
|
349
|
+
}
|
|
350
|
+
/** Spans a trace command reads a request: the API's most. */
|
|
351
|
+
const TRACE_PAGE = 500;
|
|
352
|
+
/** The span list of an OTLP page, as the API writes it: one resource, one scope. */
|
|
353
|
+
function otlpSpans(otlp) {
|
|
354
|
+
const scope = otlp.resourceSpans[0]
|
|
355
|
+
?.scopeSpans?.[0];
|
|
356
|
+
if (!scope)
|
|
357
|
+
return [];
|
|
358
|
+
scope.spans ??= [];
|
|
359
|
+
return scope.spans;
|
|
360
|
+
}
|
|
361
|
+
/** Where --export sends OTLP: --endpoint, else the OpenTelemetry SDK's own
|
|
362
|
+
* variables; a base URL gets /v1/traces, as an OTLP/HTTP exporter adds it. */
|
|
363
|
+
export function otlpTarget(endpoint, env, headers) {
|
|
364
|
+
const full = endpoint ?? env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;
|
|
365
|
+
const base = endpoint ? undefined : env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
366
|
+
const url = full
|
|
367
|
+
? endpoint && !/\/v1\/traces\/?$/.test(endpoint)
|
|
368
|
+
? `${endpoint.replace(/\/+$/, "")}/v1/traces`
|
|
369
|
+
: full
|
|
370
|
+
: base
|
|
371
|
+
? `${base.replace(/\/+$/, "")}/v1/traces`
|
|
372
|
+
: null;
|
|
373
|
+
if (!url)
|
|
374
|
+
return null;
|
|
375
|
+
const fromEnv = {};
|
|
376
|
+
for (const pair of (env.OTEL_EXPORTER_OTLP_TRACES_HEADERS ??
|
|
377
|
+
env.OTEL_EXPORTER_OTLP_HEADERS ??
|
|
378
|
+
"").split(",")) {
|
|
379
|
+
const at = pair.indexOf("=");
|
|
380
|
+
if (at > 0)
|
|
381
|
+
fromEnv[decodeURIComponent(pair.slice(0, at).trim())] = decodeURIComponent(pair.slice(at + 1).trim());
|
|
382
|
+
}
|
|
383
|
+
return { url, headers: { ...fromEnv, ...headers } };
|
|
384
|
+
}
|
|
194
385
|
export async function agentsCommand(argv, env, out, client, kit) {
|
|
195
386
|
const { parse, flag, has, need, pairs, table, usage, unknown } = kit;
|
|
196
387
|
const [verb, ...rest] = argv;
|
|
@@ -292,15 +483,27 @@ export async function agentsCommand(argv, env, out, client, kit) {
|
|
|
292
483
|
return 0;
|
|
293
484
|
}
|
|
294
485
|
case "start": {
|
|
295
|
-
const args = parse(rest, ["follow"
|
|
486
|
+
const args = parse(rest, ["follow", "replace-instructions", "no-mcp"], [
|
|
487
|
+
"key",
|
|
488
|
+
"model",
|
|
489
|
+
"instructions",
|
|
490
|
+
"instructions-file",
|
|
491
|
+
"mcp",
|
|
492
|
+
"disallow",
|
|
493
|
+
"vcpu",
|
|
494
|
+
"memory",
|
|
495
|
+
"max-dollars",
|
|
496
|
+
]);
|
|
296
497
|
const target = need(args.positional[0], "an agent's id or name");
|
|
297
498
|
const input = args.positional.slice(1).join(" ");
|
|
298
499
|
if (!input)
|
|
299
500
|
throw usage(`Give the words: ${me} agents start ${target} "Fix the failing test"`);
|
|
300
501
|
const key = flag(args, "key");
|
|
502
|
+
const overrides = overridesOf(args, kit);
|
|
301
503
|
const session = await api.start(target, {
|
|
302
504
|
input,
|
|
303
505
|
...(key === undefined ? {} : { key }),
|
|
506
|
+
...(overrides ? { overrides } : {}),
|
|
304
507
|
});
|
|
305
508
|
if (!has(args, "follow")) {
|
|
306
509
|
print(session.id, { session: session.session, joined: session.joined, seq: session.seq });
|
|
@@ -337,6 +540,98 @@ export async function agentsCommand(argv, env, out, client, kit) {
|
|
|
337
540
|
print(read.data.map(line).join("\n") || "No events yet.", read);
|
|
338
541
|
return 0;
|
|
339
542
|
}
|
|
543
|
+
case "trace": {
|
|
544
|
+
const args = parse(rest, ["otlp", "export"], ["endpoint", "header"]);
|
|
545
|
+
const id = need(args.positional[0], "a session's id");
|
|
546
|
+
if (has(args, "export")) {
|
|
547
|
+
const target = otlpTarget(flag(args, "endpoint"), env, args.flags.has("header") ? pairs(args, "header") : {});
|
|
548
|
+
if (!target)
|
|
549
|
+
throw usage("Give --endpoint, or set OTEL_EXPORTER_OTLP_ENDPOINT: where your collector takes OTLP/HTTP.");
|
|
550
|
+
// One export request a page: the collector joins them by trace id.
|
|
551
|
+
let spans = 0;
|
|
552
|
+
for (let after = 0; after !== null;) {
|
|
553
|
+
const { nextAfter, ...otlp } = await api.sessions.trace(id, {
|
|
554
|
+
format: "otlp",
|
|
555
|
+
after,
|
|
556
|
+
limit: TRACE_PAGE,
|
|
557
|
+
});
|
|
558
|
+
const sent = await fetch(target.url, {
|
|
559
|
+
method: "POST",
|
|
560
|
+
headers: { "content-type": "application/json", ...target.headers },
|
|
561
|
+
body: JSON.stringify(otlp),
|
|
562
|
+
});
|
|
563
|
+
if (!sent.ok) {
|
|
564
|
+
out.error(`${target.url} returned ${sent.status}: ${(await sent.text()).slice(0, 500)}`);
|
|
565
|
+
return 1;
|
|
566
|
+
}
|
|
567
|
+
spans += otlpSpans(otlp).length;
|
|
568
|
+
after = nextAfter;
|
|
569
|
+
}
|
|
570
|
+
print(`Sent ${spans} spans to ${target.url}.`, { sent: spans, url: target.url });
|
|
571
|
+
return 0;
|
|
572
|
+
}
|
|
573
|
+
if (has(args, "otlp")) {
|
|
574
|
+
// Every page's spans in one ExportTraceServiceRequest.
|
|
575
|
+
let whole;
|
|
576
|
+
for (let after = 0; after !== null;) {
|
|
577
|
+
const page = await api.sessions.trace(id, {
|
|
578
|
+
format: "otlp",
|
|
579
|
+
after,
|
|
580
|
+
limit: TRACE_PAGE,
|
|
581
|
+
});
|
|
582
|
+
if (whole)
|
|
583
|
+
otlpSpans(whole).push(...otlpSpans(page));
|
|
584
|
+
else
|
|
585
|
+
whole = page;
|
|
586
|
+
after = page.nextAfter;
|
|
587
|
+
}
|
|
588
|
+
const { nextAfter: _, ...otlp } = whole;
|
|
589
|
+
out.write(JSON.stringify(otlp));
|
|
590
|
+
return 0;
|
|
591
|
+
}
|
|
592
|
+
const trace = await api.sessions.trace(id, { limit: TRACE_PAGE });
|
|
593
|
+
for (let after = trace.nextAfter; after !== null;) {
|
|
594
|
+
const page = await api.sessions.trace(id, { after, limit: TRACE_PAGE });
|
|
595
|
+
trace.spans.push(...page.spans);
|
|
596
|
+
after = trace.nextAfter = page.nextAfter;
|
|
597
|
+
}
|
|
598
|
+
const t = trace.totals;
|
|
599
|
+
print([
|
|
600
|
+
`${count(t.turns)} turns, ${count(t.toolCalls)} tool calls, ${dollars(t.costUsd)}${t.unpricedTurns ? ` (${t.unpricedTurns} turns unpriced)` : ""}`,
|
|
601
|
+
`${count(t.inputTokens)} in, ${count(t.outputTokens)} out, ${count(t.cacheReadTokens)} cache read, ${count(t.cacheWriteTokens)} cache write; ${seconds(t.modelMs)} in the model, ${seconds(t.toolMs)} in tools`,
|
|
602
|
+
"",
|
|
603
|
+
trace.models.length
|
|
604
|
+
? table([
|
|
605
|
+
["MODEL", "TURNS", "IN", "OUT", "CACHE READ", "COST"],
|
|
606
|
+
...trace.models.map((m) => [
|
|
607
|
+
m.model,
|
|
608
|
+
count(m.turns),
|
|
609
|
+
count(m.inputTokens),
|
|
610
|
+
count(m.outputTokens),
|
|
611
|
+
count(m.cacheReadTokens),
|
|
612
|
+
m.unpricedTurns === m.turns ? "unpriced" : dollars(m.costUsd),
|
|
613
|
+
]),
|
|
614
|
+
])
|
|
615
|
+
: "No turns yet.",
|
|
616
|
+
...(trace.tools.length
|
|
617
|
+
? [
|
|
618
|
+
"",
|
|
619
|
+
table([
|
|
620
|
+
["TOOL", "CALLS", "FAILED", "TIME"],
|
|
621
|
+
...trace.tools.map((k) => [
|
|
622
|
+
k.name,
|
|
623
|
+
count(k.calls),
|
|
624
|
+
count(k.failed),
|
|
625
|
+
seconds(k.durationMs),
|
|
626
|
+
]),
|
|
627
|
+
]),
|
|
628
|
+
]
|
|
629
|
+
: []),
|
|
630
|
+
"",
|
|
631
|
+
...trace.spans.map((x) => `${String(x.seq).padStart(4)} ${x.startedAt} ${x.kind.padEnd(4)} ${x.kind === "turn" ? turnLine(x) : toolLine(x)}`),
|
|
632
|
+
].join("\n"), trace);
|
|
633
|
+
return 0;
|
|
634
|
+
}
|
|
340
635
|
case "sessions": {
|
|
341
636
|
if (rest[0] === "delete" || rest[0] === "rm") {
|
|
342
637
|
const target = need(rest[1], "a session's id");
|
|
@@ -406,11 +701,175 @@ export async function agentsCommand(argv, env, out, client, kit) {
|
|
|
406
701
|
print(`${answered.id} answered; ${answered.sessions.filter((x) => x.state === "answered").length} session(s) woken.`, answered);
|
|
407
702
|
return 0;
|
|
408
703
|
}
|
|
704
|
+
case "workflows": {
|
|
705
|
+
const args = parse(rest, [], ["state"]);
|
|
706
|
+
const states = args.flags.get("state");
|
|
707
|
+
for (const state of states ?? [])
|
|
708
|
+
if (!WORKFLOW_STATES.includes(state))
|
|
709
|
+
throw usage(`--state takes ${WORKFLOW_STATES.join(", ")}.`);
|
|
710
|
+
const page = await api.workflows.list({
|
|
711
|
+
limit: 100,
|
|
712
|
+
...(states ? { state: states } : {}),
|
|
713
|
+
});
|
|
714
|
+
print(page.data.length
|
|
715
|
+
? table([
|
|
716
|
+
["ID", "NAME", "STATE", "SESSIONS", "COST", "CREATED"],
|
|
717
|
+
...page.data.map((w) => [
|
|
718
|
+
w.id,
|
|
719
|
+
w.name ?? "-",
|
|
720
|
+
w.reason && w.reason !== "done" ? `${w.state} (${w.reason})` : w.state,
|
|
721
|
+
String(w.started),
|
|
722
|
+
`$${w.cost.dollars.toFixed(2)}`,
|
|
723
|
+
when(w.createdAt),
|
|
724
|
+
]),
|
|
725
|
+
])
|
|
726
|
+
: `No workflows. Run one: ${me} agents workflow run workflow.json`, page.data);
|
|
727
|
+
return 0;
|
|
728
|
+
}
|
|
729
|
+
case "workflow": {
|
|
730
|
+
const [sub, ...more] = rest;
|
|
731
|
+
const watch = async (id, after) => {
|
|
732
|
+
let last;
|
|
733
|
+
for await (const now of api.workflows.follow(id, { after })) {
|
|
734
|
+
last = now;
|
|
735
|
+
out.write(out.json ? JSON.stringify(now) : `${workflowLines({ ...now, result: null })}\n`);
|
|
736
|
+
}
|
|
737
|
+
last ??= await api.workflows.get(id);
|
|
738
|
+
if (!out.json && last.result !== null)
|
|
739
|
+
out.write(last.result);
|
|
740
|
+
return last.state === "done" ? 0 : 1;
|
|
741
|
+
};
|
|
742
|
+
if (sub === "run") {
|
|
743
|
+
const args = parse(more, ["follow"], []);
|
|
744
|
+
const file = need(args.positional[0], "a workflow's JSON file, or - for stdin");
|
|
745
|
+
let text;
|
|
746
|
+
if (file === "-") {
|
|
747
|
+
const chunks = [];
|
|
748
|
+
for await (const chunk of process.stdin)
|
|
749
|
+
chunks.push(chunk);
|
|
750
|
+
text = Buffer.concat(chunks).toString("utf8");
|
|
751
|
+
}
|
|
752
|
+
else
|
|
753
|
+
text = readFileSync(file, "utf8");
|
|
754
|
+
let spec;
|
|
755
|
+
try {
|
|
756
|
+
spec = JSON.parse(text);
|
|
757
|
+
}
|
|
758
|
+
catch (error) {
|
|
759
|
+
throw usage(`${file} is not JSON: ${error.message}`);
|
|
760
|
+
}
|
|
761
|
+
const made = await api.workflows.run(spec);
|
|
762
|
+
if (!has(args, "follow")) {
|
|
763
|
+
print(made.id, made.workflow);
|
|
764
|
+
return 0;
|
|
765
|
+
}
|
|
766
|
+
if (!out.json)
|
|
767
|
+
out.error(`Workflow ${made.id}`);
|
|
768
|
+
out.write(out.json ? JSON.stringify(made.workflow) : `${workflowLines(made.workflow)}\n`);
|
|
769
|
+
return watch(made.id, made.workflow.version);
|
|
770
|
+
}
|
|
771
|
+
if (sub === "get") {
|
|
772
|
+
const w = await api.workflows.get(need(more[0], "a workflow's id"));
|
|
773
|
+
print(workflowLines(w), w);
|
|
774
|
+
return 0;
|
|
775
|
+
}
|
|
776
|
+
if (sub === "watch")
|
|
777
|
+
return watch(need(more[0], "a workflow's id"), 0);
|
|
778
|
+
if (sub === "steps") {
|
|
779
|
+
const args = parse(more, [], ["state"]);
|
|
780
|
+
const id = need(args.positional[0], "a workflow's id");
|
|
781
|
+
const states = args.flags.get("state");
|
|
782
|
+
const all = await (await api.workflows.steps(id, {
|
|
783
|
+
limit: 100,
|
|
784
|
+
...(states ? { state: states } : {}),
|
|
785
|
+
})).toArray(Infinity);
|
|
786
|
+
print(all.length
|
|
787
|
+
? table([
|
|
788
|
+
["PHASE", "ITEM", "STATE", "SESSION", "ITEM TEXT"],
|
|
789
|
+
...all.map((x) => [
|
|
790
|
+
x.phase,
|
|
791
|
+
String(x.item + 1),
|
|
792
|
+
x.state,
|
|
793
|
+
x.sessionId ?? "-",
|
|
794
|
+
(x.itemText ?? "-").replace(/\s+/g, " ").slice(0, 60),
|
|
795
|
+
]),
|
|
796
|
+
])
|
|
797
|
+
: "No steps yet.", all);
|
|
798
|
+
return 0;
|
|
799
|
+
}
|
|
800
|
+
if (sub === "stop") {
|
|
801
|
+
const w = await api.workflows.stop(need(more[0], "a workflow's id"));
|
|
802
|
+
print(`${w.id} ${w.state}.`, w);
|
|
803
|
+
return 0;
|
|
804
|
+
}
|
|
805
|
+
throw unknown("agents workflow command", sub ?? "", ["run", "get", "watch", "steps", "stop"]);
|
|
806
|
+
}
|
|
807
|
+
case "approve":
|
|
808
|
+
case "deny": {
|
|
809
|
+
const args = parse(rest, [], verb === "deny" ? ["message"] : []);
|
|
810
|
+
const id = need(args.positional[0], "an ask's id");
|
|
811
|
+
const message = verb === "deny" ? flag(args, "message") : undefined;
|
|
812
|
+
const answered = verb === "approve" ? await api.asks.approve(id) : await api.asks.deny(id, message);
|
|
813
|
+
print(`${answered.id}: ${answered.toolCall?.tool ?? "the call"} ${verb === "approve" ? "allowed" : "denied"}.`, answered);
|
|
814
|
+
return 0;
|
|
815
|
+
}
|
|
409
816
|
case "stop": {
|
|
410
817
|
const session = await (await api.session(need(rest[0], "a session's id"))).stop();
|
|
411
818
|
print(`${session.id} ${session.state}.`, session);
|
|
412
819
|
return 0;
|
|
413
820
|
}
|
|
821
|
+
case "switch": {
|
|
822
|
+
const platform = need(rest[0], "the platform to switch from: anthropic");
|
|
823
|
+
if (platform !== "anthropic")
|
|
824
|
+
throw usage(`runtime agents switch takes anthropic (Claude Managed Agents); ${platform} is not available yet.`);
|
|
825
|
+
const { baseURL } = await api.anthropic();
|
|
826
|
+
const modelKey = (await secrets(transport).list()).find((s) => s.name === "ANTHROPIC_API_KEY");
|
|
827
|
+
const value = {
|
|
828
|
+
platform,
|
|
829
|
+
baseURL,
|
|
830
|
+
modelKey: modelKey ? { name: modelKey.name, hosts: modelKey.hosts } : null,
|
|
831
|
+
docs: SWITCH_DOCS,
|
|
832
|
+
};
|
|
833
|
+
print([
|
|
834
|
+
"Claude Managed Agents code runs on Runtime with its client's base URL and key changed:",
|
|
835
|
+
"",
|
|
836
|
+
` new Anthropic({ baseURL: "${baseURL}", apiKey: process.env.RUNTIME_API_KEY })`,
|
|
837
|
+
` anthropic.Anthropic(base_url="${baseURL}", api_key=os.environ["RUNTIME_API_KEY"])`,
|
|
838
|
+
"",
|
|
839
|
+
modelKey
|
|
840
|
+
? `Model key: ANTHROPIC_API_KEY is set (${modelKey.hosts.join(", ")}); sessions use it.`
|
|
841
|
+
: [
|
|
842
|
+
"Model key: ANTHROPIC_API_KEY is not set. Agents run on your own Anthropic key;",
|
|
843
|
+
"store it once, and the sandbox never sees it:",
|
|
844
|
+
' printf %s "$ANTHROPIC_API_KEY" | runtime secrets set ANTHROPIC_API_KEY --host api.anthropic.com',
|
|
845
|
+
].join("\n"),
|
|
846
|
+
`What maps and what does not: ${SWITCH_DOCS}`,
|
|
847
|
+
"",
|
|
848
|
+
].join("\n"), value);
|
|
849
|
+
return 0;
|
|
850
|
+
}
|
|
851
|
+
case "slack": {
|
|
852
|
+
const [sub, ...more] = rest;
|
|
853
|
+
if (sub === "install") {
|
|
854
|
+
const link = await api.slack.install();
|
|
855
|
+
print(`Open this link to add Runtime's Slack app to a workspace (good until ${link.expiresAt}):\n${link.url}`, link);
|
|
856
|
+
return 0;
|
|
857
|
+
}
|
|
858
|
+
if (sub === "rm") {
|
|
859
|
+
const team = need(more[0], "a workspace's id (T…), from `agents slack ls`");
|
|
860
|
+
await api.slack.remove(team);
|
|
861
|
+
print(`${team} removed.`, { team, removed: true });
|
|
862
|
+
return 0;
|
|
863
|
+
}
|
|
864
|
+
if (sub === undefined || sub === "ls") {
|
|
865
|
+
const teams = await api.slack.teams();
|
|
866
|
+
print(teams.length
|
|
867
|
+
? teams.map((w) => `${w.team} ${w.name ?? ""} added ${w.installedAt}`).join("\n")
|
|
868
|
+
: `No Slack workspace is added. Add one: ${me} agents slack install`, teams);
|
|
869
|
+
return 0;
|
|
870
|
+
}
|
|
871
|
+
throw usage(`Use ${me} agents slack install, ls or rm <team>.`);
|
|
872
|
+
}
|
|
414
873
|
case "triggers": {
|
|
415
874
|
const [sub, ...more] = rest;
|
|
416
875
|
if (sub === "add") {
|
|
@@ -546,10 +1005,15 @@ export async function agentsCommand(argv, env, out, client, kit) {
|
|
|
546
1005
|
"start",
|
|
547
1006
|
"send",
|
|
548
1007
|
"events",
|
|
1008
|
+
"trace",
|
|
549
1009
|
"sessions",
|
|
550
1010
|
"stop",
|
|
551
1011
|
"asks",
|
|
552
1012
|
"answer",
|
|
1013
|
+
"workflow",
|
|
1014
|
+
"workflows",
|
|
1015
|
+
"approve",
|
|
1016
|
+
"deny",
|
|
553
1017
|
"triggers",
|
|
554
1018
|
"memory",
|
|
555
1019
|
]);
|
package/dist/agents-deploy.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type AgentsFileTrigger = {
|
|
|
12
12
|
* what it leaves out, then each definition field it sets. */
|
|
13
13
|
export type AgentsFileAgent = Omit<Partial<AgentDefinition>, "template"> & {
|
|
14
14
|
/** A harness: claude-code, codex, gemini-cli, claude-agent-sdk,
|
|
15
|
-
* openai-agents-sdk, review, judge. Fills in `command` and its model keys. */
|
|
15
|
+
* openai-agents-sdk, review, judge, browser. Fills in `command` and its model keys. */
|
|
16
16
|
template?: string;
|
|
17
17
|
/** support or team: a size and bounds for that use (`agents.uses`). */
|
|
18
18
|
use?: "support" | "team";
|