@2kw/ai 8.3.0-dev.5 → 8.3.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/dist/agent-config/schema.d.ts +25 -0
- package/dist/agent-config/schema.js +14 -0
- package/dist/commands/agents.js +42 -0
- package/dist/commands/batches.d.ts +8 -0
- package/dist/commands/batches.js +99 -0
- package/dist/commands/billing.js +55 -2
- package/dist/commands/convert.d.ts +1 -0
- package/dist/commands/convert.js +1 -1
- package/dist/commands/scheduled-tasks.d.ts +22 -0
- package/dist/commands/scheduled-tasks.js +163 -0
- package/dist/index.js +4 -0
- package/dist/lib/agent-run.d.ts +26 -0
- package/dist/lib/agent-run.js +45 -0
- package/dist/lib/approval-prompt.js +33 -3
- package/package.json +1 -1
|
@@ -330,6 +330,19 @@ export declare const agentSchema: {
|
|
|
330
330
|
};
|
|
331
331
|
};
|
|
332
332
|
};
|
|
333
|
+
readonly batchTool: {
|
|
334
|
+
readonly type: "object";
|
|
335
|
+
readonly additionalProperties: false;
|
|
336
|
+
readonly required: readonly ["type"];
|
|
337
|
+
readonly properties: {
|
|
338
|
+
readonly type: {
|
|
339
|
+
readonly const: "backbone.batch";
|
|
340
|
+
};
|
|
341
|
+
readonly requiresConfirmation: {
|
|
342
|
+
readonly type: "boolean";
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
};
|
|
333
346
|
readonly showTableTool: {
|
|
334
347
|
readonly type: "object";
|
|
335
348
|
readonly additionalProperties: false;
|
|
@@ -560,6 +573,18 @@ export declare const agentSchema: {
|
|
|
560
573
|
readonly then: {
|
|
561
574
|
readonly $ref: "#/$defs/canvasTool";
|
|
562
575
|
};
|
|
576
|
+
}, {
|
|
577
|
+
readonly if: {
|
|
578
|
+
required: string[];
|
|
579
|
+
properties: {
|
|
580
|
+
type: {
|
|
581
|
+
const: string;
|
|
582
|
+
};
|
|
583
|
+
};
|
|
584
|
+
};
|
|
585
|
+
readonly then: {
|
|
586
|
+
readonly $ref: "#/$defs/batchTool";
|
|
587
|
+
};
|
|
563
588
|
}, {
|
|
564
589
|
readonly if: {
|
|
565
590
|
required: string[];
|
|
@@ -34,6 +34,11 @@ export const NON_AUTHORABLE_TOOL_TYPES = {
|
|
|
34
34
|
"backbone.deliver": "it is added at run time while sandbox outputs are held",
|
|
35
35
|
// #1244: injected wherever backbone.bash is advertised; an authored copy is dropped.
|
|
36
36
|
"backbone.view_image": "it is added at run time wherever the sandboxed shell is",
|
|
37
|
+
// #1801: injected for callers allowed to change knowledge; an authored copy is dropped.
|
|
38
|
+
"backbone.knowledge_apply": "it is added at run time for callers allowed to change knowledge",
|
|
39
|
+
// #1818: injected for members in a chat; an authored copy is dropped.
|
|
40
|
+
"backbone.scheduled_task_list": "it is added at run time for members in a chat",
|
|
41
|
+
"backbone.scheduled_task_apply": "it is added at run time for members in a chat",
|
|
37
42
|
};
|
|
38
43
|
/**
|
|
39
44
|
* The three tools `backbone.canvas` grants (#1698). Listing one is refused on the backend too
|
|
@@ -57,6 +62,7 @@ const BUILTIN_TYPES = [
|
|
|
57
62
|
"backbone.skill",
|
|
58
63
|
"backbone.bash",
|
|
59
64
|
"backbone.canvas",
|
|
65
|
+
"backbone.batch",
|
|
60
66
|
"backbone.show_table",
|
|
61
67
|
"backbone.show_chart",
|
|
62
68
|
"function",
|
|
@@ -240,6 +246,13 @@ export const agentSchema = {
|
|
|
240
246
|
required: ["type"],
|
|
241
247
|
properties: { type: { const: "backbone.canvas" }, requiresConfirmation: { type: "boolean" } },
|
|
242
248
|
},
|
|
249
|
+
// #1844: start_batch in the chat; no options. requiresConfirmation as todoTool.
|
|
250
|
+
batchTool: {
|
|
251
|
+
type: "object",
|
|
252
|
+
additionalProperties: false,
|
|
253
|
+
required: ["type"],
|
|
254
|
+
properties: { type: { const: "backbone.batch" }, requiresConfirmation: { type: "boolean" } },
|
|
255
|
+
},
|
|
243
256
|
// #1419, retired by Canvas (#1698) but still valid: no options; requiresConfirmation as todoTool.
|
|
244
257
|
showTableTool: {
|
|
245
258
|
type: "object",
|
|
@@ -313,6 +326,7 @@ export const agentSchema = {
|
|
|
313
326
|
{ if: typeIs("backbone.skill"), then: { $ref: "#/$defs/skillTool" } },
|
|
314
327
|
{ if: typeIs("backbone.bash"), then: { $ref: "#/$defs/bashTool" } },
|
|
315
328
|
{ if: typeIs("backbone.canvas"), then: { $ref: "#/$defs/canvasTool" } },
|
|
329
|
+
{ if: typeIs("backbone.batch"), then: { $ref: "#/$defs/batchTool" } },
|
|
316
330
|
{ if: typeIs("backbone.show_table"), then: { $ref: "#/$defs/showTableTool" } },
|
|
317
331
|
{ if: typeIs("backbone.show_chart"), then: { $ref: "#/$defs/showChartTool" } },
|
|
318
332
|
{ if: typeIs("function"), then: { $ref: "#/$defs/functionTool" } },
|
package/dist/commands/agents.js
CHANGED
|
@@ -13,6 +13,10 @@ import { maskSecrets } from "../agent-config/file.js";
|
|
|
13
13
|
import { ensurePublished } from "../lib/agent-publish.js";
|
|
14
14
|
import { collectModel, MODEL_HELP, MODELS_HELP, modelFieldsFromOptions } from "../lib/agent-models.js";
|
|
15
15
|
import { assertNameNotBlank } from "../lib/overlay.js";
|
|
16
|
+
import { CliUsageError } from "../lib/errors.js";
|
|
17
|
+
function collectTeam(value, previous) {
|
|
18
|
+
return [...previous, value];
|
|
19
|
+
}
|
|
16
20
|
export function makeAgentsCommand() {
|
|
17
21
|
const cmd = new Command("agents").description("Manage agents");
|
|
18
22
|
const list = new Command("list").description("List agents");
|
|
@@ -69,8 +73,17 @@ export function makeAgentsCommand() {
|
|
|
69
73
|
.option("--tools <json>", "Tool definitions as JSON")
|
|
70
74
|
.option("--skills <json>", "Skill definitions as JSON")
|
|
71
75
|
.option("--hitl-policy <json>", "Human-in-the-loop policy as JSON")
|
|
76
|
+
.option("--visibility <visibility>", "Who may use it: organization (default) or restricted to the --team teams")
|
|
77
|
+
.option("--team <id>", "A team a restricted agent is open to (repeatable); a member names only own teams", collectTeam, [])
|
|
72
78
|
.action(async (opts, command) => {
|
|
73
79
|
await runAction(command, async () => {
|
|
80
|
+
if (opts.visibility === undefined && opts.team.length > 0) {
|
|
81
|
+
throw new CliUsageError("--team needs --visibility restricted.");
|
|
82
|
+
}
|
|
83
|
+
if (opts.visibility !== undefined && opts.visibility !== "organization" && opts.visibility !== "restricted") {
|
|
84
|
+
throw new CliUsageError("--visibility must be organization or restricted.");
|
|
85
|
+
}
|
|
86
|
+
const access = opts.visibility === undefined ? {} : { visibility: opts.visibility, teamIds: opts.team };
|
|
74
87
|
const models = modelFieldsFromOptions(opts, true);
|
|
75
88
|
const client = getClient(command);
|
|
76
89
|
const tools = opts.tools ? JSON.parse(opts.tools) : undefined;
|
|
@@ -81,6 +94,7 @@ export function makeAgentsCommand() {
|
|
|
81
94
|
body: {
|
|
82
95
|
name: opts.name,
|
|
83
96
|
...models,
|
|
97
|
+
...access,
|
|
84
98
|
description: opts.description,
|
|
85
99
|
instructions: opts.instructions,
|
|
86
100
|
options,
|
|
@@ -172,6 +186,34 @@ export function makeAgentsCommand() {
|
|
|
172
186
|
formatSuccess(`Agent ${id} deleted.`, command);
|
|
173
187
|
});
|
|
174
188
|
});
|
|
189
|
+
// Who may use an agent: everyone in the organization, or members of the listed teams.
|
|
190
|
+
// Without --visibility it reads; with it, it replaces (administrators and owners).
|
|
191
|
+
cmd
|
|
192
|
+
.command("access")
|
|
193
|
+
.description("Show or set who may use an agent: the whole organization, or members of listed teams")
|
|
194
|
+
.argument("<id>", "Agent ID")
|
|
195
|
+
.option("--visibility <visibility>", "Set access: organization or restricted")
|
|
196
|
+
.option("--team <id>", "A team a restricted agent is open to (repeatable)", collectTeam, [])
|
|
197
|
+
.action(async (id, opts, command) => {
|
|
198
|
+
await runAction(command, async () => {
|
|
199
|
+
const client = getClient(command);
|
|
200
|
+
if (opts.visibility === undefined) {
|
|
201
|
+
if (opts.team.length > 0)
|
|
202
|
+
throw new CliUsageError("--team needs --visibility restricted.");
|
|
203
|
+
const { data } = await client.GET("/v1/agents/{id}/access", { params: { path: { id } } });
|
|
204
|
+
formatDetail(data, command);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (opts.visibility !== "organization" && opts.visibility !== "restricted") {
|
|
208
|
+
throw new CliUsageError("--visibility must be organization or restricted.");
|
|
209
|
+
}
|
|
210
|
+
const { data } = await client.PUT("/v1/agents/{id}/access", {
|
|
211
|
+
params: { path: { id } },
|
|
212
|
+
body: { visibility: opts.visibility, teamIds: opts.team },
|
|
213
|
+
});
|
|
214
|
+
formatDetail(data, command);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
175
217
|
const approvals = new Command("approvals").description("List tool approvals raised by an agent");
|
|
176
218
|
addPaginationOptions(approvals);
|
|
177
219
|
approvals.requiredOption("--agent <id>", "Agent ID");
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
/**
|
|
3
|
+
* Batches: one instruction run by an agent over many files, one item at a time, in the
|
|
4
|
+
* background (#1844, batch spec §8). The ZIP download needs an API key; a browser sign-in
|
|
5
|
+
* gets its own single-use link in the chat app instead.
|
|
6
|
+
*/
|
|
7
|
+
export declare function makeBatchesCommand(): Command;
|
|
8
|
+
//# sourceMappingURL=batches.d.ts.map
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { writeFileSync } from "node:fs";
|
|
5
|
+
import { basename } from "node:path";
|
|
6
|
+
import { getClient, runAction } from "../lib/client.js";
|
|
7
|
+
import { CliUsageError } from "../lib/errors.js";
|
|
8
|
+
import { formatDetail, formatList, withSpinner } from "../lib/output.js";
|
|
9
|
+
const STATUSES = ["queued", "running", "completed", "completed_with_failures", "canceling", "canceled"];
|
|
10
|
+
/**
|
|
11
|
+
* Batches: one instruction run by an agent over many files, one item at a time, in the
|
|
12
|
+
* background (#1844, batch spec §8). The ZIP download needs an API key; a browser sign-in
|
|
13
|
+
* gets its own single-use link in the chat app instead.
|
|
14
|
+
*/
|
|
15
|
+
export function makeBatchesCommand() {
|
|
16
|
+
const cmd = new Command("batches").description("Run one instruction by an agent over many files, in the background, and download the results as one ZIP");
|
|
17
|
+
cmd
|
|
18
|
+
.command("create")
|
|
19
|
+
.description("Start a batch over uploaded files or one uploaded ZIP; each file (or group) is one item")
|
|
20
|
+
.requiredOption("--agent <agent>", "The agent to run, by id or name")
|
|
21
|
+
.requiredOption("--instruction <text>", "What to do with each item, 1 to 4,000 characters")
|
|
22
|
+
.option("--file <fileIds...>", "Uploaded files, each an item")
|
|
23
|
+
.option("--zip <fileId>", "One uploaded ZIP whose files become the items, instead of --file")
|
|
24
|
+
.option("--group-by <mode>", "file: one item per file; stem: files sharing a base name are one item", "file")
|
|
25
|
+
.option("--require <extensions...>", "Extensions every item must produce to succeed, e.g. pdf")
|
|
26
|
+
.option("--idempotency-key <key>", "Sending the same key and body again returns the same batch (default: a new key)")
|
|
27
|
+
.action(async (opts, command) => {
|
|
28
|
+
await runAction(command, async () => {
|
|
29
|
+
if (Boolean(opts.file?.length) === Boolean(opts.zip)) {
|
|
30
|
+
throw new CliUsageError("create needs either --file <fileIds...> or --zip <fileId>");
|
|
31
|
+
}
|
|
32
|
+
const client = getClient(command);
|
|
33
|
+
const { data } = await client.POST("/v1/batches", {
|
|
34
|
+
body: {
|
|
35
|
+
agent: opts.agent,
|
|
36
|
+
instruction: opts.instruction,
|
|
37
|
+
...(opts.file && { file_ids: opts.file }),
|
|
38
|
+
...(opts.zip && { zip_file_id: opts.zip }),
|
|
39
|
+
group_by: opts.groupBy,
|
|
40
|
+
...(opts.require && { required_outputs: opts.require }),
|
|
41
|
+
idempotency_key: opts.idempotencyKey ?? randomUUID(),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
formatDetail(data, command);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
cmd
|
|
48
|
+
.command("list")
|
|
49
|
+
.description("List your batches, newest first, with their counts")
|
|
50
|
+
.option("--status <status>", `Only batches in this status: ${STATUSES.join(", ")}`)
|
|
51
|
+
.option("--all", "Every batch of the organization, status and counts only (admin or owner)")
|
|
52
|
+
.action(async (opts, command) => {
|
|
53
|
+
await runAction(command, async () => {
|
|
54
|
+
const client = getClient(command);
|
|
55
|
+
const { data } = await client.GET("/v1/batches", {
|
|
56
|
+
params: { query: { status: opts.status, all: opts.all } },
|
|
57
|
+
});
|
|
58
|
+
formatList(data, command, ["id", "status", "counts", "created_at"]);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
cmd
|
|
62
|
+
.command("get <id>")
|
|
63
|
+
.description("Show a batch with its counts and items (name, status, reason)")
|
|
64
|
+
.action(async (id, _opts, command) => {
|
|
65
|
+
await runAction(command, async () => {
|
|
66
|
+
const client = getClient(command);
|
|
67
|
+
const { data } = await client.GET("/v1/batches/{id}", { params: { path: { id } } });
|
|
68
|
+
formatDetail(data, command);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
cmd
|
|
72
|
+
.command("cancel <id>")
|
|
73
|
+
.description("Stop a batch: items not started are canceled, running items end when their run stops")
|
|
74
|
+
.action(async (id, _opts, command) => {
|
|
75
|
+
await runAction(command, async () => {
|
|
76
|
+
const client = getClient(command);
|
|
77
|
+
const { data } = await client.POST("/v1/batches/{id}/cancel", { params: { path: { id } } });
|
|
78
|
+
formatDetail(data, command);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
cmd
|
|
82
|
+
.command("download <id>")
|
|
83
|
+
.description("Download a batch's outputs and report.csv as one ZIP (API key only); while it runs, the items finished so far")
|
|
84
|
+
.option("-o, --output <file>", "Write the ZIP to this path instead of the name the server gives")
|
|
85
|
+
.action(async (id, opts, command) => {
|
|
86
|
+
await runAction(command, async () => {
|
|
87
|
+
const client = getClient(command);
|
|
88
|
+
const { data, response } = await withSpinner("Downloading...", () => client.GET("/v1/batches/{id}/archive", { params: { path: { id } }, parseAs: "arrayBuffer" }));
|
|
89
|
+
const bytes = Buffer.from(data);
|
|
90
|
+
const named = /filename="?([^";]+)"?/i.exec(response.headers.get("content-disposition") ?? "")?.[1];
|
|
91
|
+
// basename: never let a header name a path outside the working directory.
|
|
92
|
+
const outputPath = opts.output ?? (named ? basename(named) : `${id}.zip`);
|
|
93
|
+
writeFileSync(outputPath, bytes);
|
|
94
|
+
console.error(chalk.green(`Wrote ${bytes.length} bytes to ${outputPath}`));
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return cmd;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=batches.js.map
|
package/dist/commands/billing.js
CHANGED
|
@@ -185,7 +185,25 @@ function makeUsageCommand() {
|
|
|
185
185
|
console.log(`Period: ${data.periodStart?.slice(0, 10)} → ${data.periodEnd?.slice(0, 10)} (${plan})`);
|
|
186
186
|
console.log(`Used: ${data.usedPercent == null ? "no included usage" : `${data.usedPercent} %`}`);
|
|
187
187
|
for (const meter of data.meters ?? []) {
|
|
188
|
-
|
|
188
|
+
if (!meter.tokens) {
|
|
189
|
+
console.log(` ${(meter.meter ?? "").padEnd(18)} ${meter.percent ?? "-"} % ${meter.quantity} ${meter.unit}`);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
// Token meters show each kind on its own line, never one summed number (#1766).
|
|
193
|
+
console.log(` ${(meter.meter ?? "").padEnd(18)} ${meter.percent ?? "-"} %`);
|
|
194
|
+
for (const [key, label] of TOKEN_KINDS) {
|
|
195
|
+
const share = meter.kindSharePercent?.[key];
|
|
196
|
+
console.log(` ${label.padEnd(16)} ${tokenCount(meter.tokens[key])}${share == null ? "" : ` ${share} %`}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (data.byModel?.length) {
|
|
200
|
+
console.log("By model:");
|
|
201
|
+
formatList(data.byModel.map((group) => ({
|
|
202
|
+
model: group.label,
|
|
203
|
+
requests: group.requests,
|
|
204
|
+
...kindColumns(group.tokens),
|
|
205
|
+
share: group.sharePercent == null ? "-" : `${group.sharePercent} %`,
|
|
206
|
+
})), command, ["model", "requests", "input", "cachedInput", "cacheWrite", "output", "share"]);
|
|
189
207
|
}
|
|
190
208
|
if (data.extraUsage) {
|
|
191
209
|
const state = data.extraUsage.enabled ? "" : chalk.dim(" (off)");
|
|
@@ -228,13 +246,48 @@ function makeUsageCommand() {
|
|
|
228
246
|
provider: row.provider ?? "-",
|
|
229
247
|
model: row.model,
|
|
230
248
|
requests: row.requests,
|
|
249
|
+
...kindColumns({
|
|
250
|
+
uncachedInput: row.uncachedInputTokens,
|
|
251
|
+
cachedInput: row.cachedInputTokens,
|
|
252
|
+
cacheWrite: row.cacheWriteTokens,
|
|
253
|
+
output: row.outputTokens,
|
|
254
|
+
}),
|
|
231
255
|
estimate: row.estimatedCostEur == null ? "-" : `~€${row.estimatedCostEur}`,
|
|
232
256
|
}));
|
|
233
|
-
|
|
257
|
+
const cacheWritten = (data.rows ?? []).some((row) => row.cacheWriteTokens != null && row.cacheWriteTokens !== 0);
|
|
258
|
+
formatList(rows, command, [
|
|
259
|
+
"provider",
|
|
260
|
+
"model",
|
|
261
|
+
"requests",
|
|
262
|
+
"input",
|
|
263
|
+
"cachedInput",
|
|
264
|
+
...(cacheWritten ? ["cacheWrite"] : []),
|
|
265
|
+
"output",
|
|
266
|
+
"estimate",
|
|
267
|
+
]);
|
|
234
268
|
});
|
|
235
269
|
});
|
|
236
270
|
return cmd;
|
|
237
271
|
}
|
|
272
|
+
/** The four token kinds in display order, with their customer words (#1766). */
|
|
273
|
+
const TOKEN_KINDS = [
|
|
274
|
+
["uncachedInput", "Input"],
|
|
275
|
+
["cachedInput", "Cached input"],
|
|
276
|
+
["cacheWrite", "Cache write"],
|
|
277
|
+
["output", "Output"],
|
|
278
|
+
];
|
|
279
|
+
/** A token count, or a dash when the provider did not report it (never 0). */
|
|
280
|
+
function tokenCount(value) {
|
|
281
|
+
return value == null ? "-" : String(value);
|
|
282
|
+
}
|
|
283
|
+
function kindColumns(tokens) {
|
|
284
|
+
return {
|
|
285
|
+
input: tokenCount(tokens?.uncachedInput),
|
|
286
|
+
cachedInput: tokenCount(tokens?.cachedInput),
|
|
287
|
+
cacheWrite: tokenCount(tokens?.cacheWrite),
|
|
288
|
+
output: tokenCount(tokens?.output),
|
|
289
|
+
};
|
|
290
|
+
}
|
|
238
291
|
/** Whole euros from cents, e.g. 1234 → "€12.34". Amounts are net of VAT (#973 D-O). */
|
|
239
292
|
function euros(cents) {
|
|
240
293
|
return `€${((cents ?? 0) / 100).toFixed(2)}`;
|
package/dist/commands/convert.js
CHANGED
|
@@ -32,7 +32,7 @@ function getPrimaryContent(doc, formats) {
|
|
|
32
32
|
return JSON.stringify(doc.jsonContent.content ?? doc.jsonContent, null, 2);
|
|
33
33
|
return doc.mdContent ?? doc.textContent ?? doc.htmlContent ?? "";
|
|
34
34
|
}
|
|
35
|
-
function formatBytes(bytes) {
|
|
35
|
+
export function formatBytes(bytes) {
|
|
36
36
|
if (bytes < 1024)
|
|
37
37
|
return `${bytes} B`;
|
|
38
38
|
if (bytes < 1024 * 1024)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
interface RecurrenceOpts {
|
|
3
|
+
recurrence?: string;
|
|
4
|
+
time?: string;
|
|
5
|
+
date?: string;
|
|
6
|
+
day?: string;
|
|
7
|
+
dayOfMonth?: string;
|
|
8
|
+
minute?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The recurrence the flags describe, or undefined when none is given. The API owns the rules
|
|
12
|
+
* per kind (which fields a kind needs, their ranges), so the fields are passed on as given and
|
|
13
|
+
* its invalid_recurrence detail reaches the user.
|
|
14
|
+
*/
|
|
15
|
+
export declare function recurrenceFrom(opts: RecurrenceOpts): Record<string, unknown> | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Scheduled tasks: an agent that runs on a schedule as you, each run in a new conversation (#1747).
|
|
18
|
+
* The API has no read-by-id, so `get` picks the task out of the list.
|
|
19
|
+
*/
|
|
20
|
+
export declare function makeScheduledTasksCommand(): Command;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=scheduled-tasks.d.ts.map
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import { getClient, runAction } from "../lib/client.js";
|
|
3
|
+
import { CliUsageError } from "../lib/errors.js";
|
|
4
|
+
import { formatDetail, formatList, formatSuccess } from "../lib/output.js";
|
|
5
|
+
const KINDS = ["once", "hourly", "daily", "weekdays", "weekly", "monthly", "manual"];
|
|
6
|
+
function wholeNumber(value, flag) {
|
|
7
|
+
if (!/^\d{1,3}$/.test(value))
|
|
8
|
+
throw new CliUsageError(`${flag} takes a whole number: ${value}`);
|
|
9
|
+
return Number(value);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The recurrence the flags describe, or undefined when none is given. The API owns the rules
|
|
13
|
+
* per kind (which fields a kind needs, their ranges), so the fields are passed on as given and
|
|
14
|
+
* its invalid_recurrence detail reaches the user.
|
|
15
|
+
*/
|
|
16
|
+
export function recurrenceFrom(opts) {
|
|
17
|
+
const { recurrence: kind, time, date, day, dayOfMonth, minute } = opts;
|
|
18
|
+
if (kind === undefined) {
|
|
19
|
+
if ([time, date, day, dayOfMonth, minute].some((v) => v !== undefined)) {
|
|
20
|
+
throw new CliUsageError(`--time, --date, --day, --day-of-month and --minute need --recurrence <${KINDS.join("|")}>`);
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
if (!KINDS.includes(kind)) {
|
|
25
|
+
throw new CliUsageError(`--recurrence must be one of ${KINDS.join(", ")}: ${kind}`);
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
kind,
|
|
29
|
+
...(time !== undefined && { time }),
|
|
30
|
+
...(date !== undefined && { date }),
|
|
31
|
+
...(day !== undefined && { day: day.toLowerCase() }),
|
|
32
|
+
...(dayOfMonth !== undefined && { day_of_month: wholeNumber(dayOfMonth, "--day-of-month") }),
|
|
33
|
+
...(minute !== undefined && { minute: wholeNumber(minute, "--minute") }),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function withRecurrenceOptions(cmd) {
|
|
37
|
+
return cmd
|
|
38
|
+
.option("--recurrence <kind>", `When it runs: ${KINDS.join(", ")}`)
|
|
39
|
+
.option("--time <HH:MM>", "Time of day (once, daily, weekdays, weekly, monthly)")
|
|
40
|
+
.option("--date <YYYY-MM-DD>", "Date of a once task")
|
|
41
|
+
.option("--day <weekday>", "Day of a weekly task, e.g. monday")
|
|
42
|
+
.option("--day-of-month <1-31>", "Day of a monthly task")
|
|
43
|
+
.option("--minute <0-59>", "Minute past each hour of an hourly task");
|
|
44
|
+
}
|
|
45
|
+
const COLUMNS = ["id", "name", "state", "next_run_at", "agent_id"];
|
|
46
|
+
/**
|
|
47
|
+
* Scheduled tasks: an agent that runs on a schedule as you, each run in a new conversation (#1747).
|
|
48
|
+
* The API has no read-by-id, so `get` picks the task out of the list.
|
|
49
|
+
*/
|
|
50
|
+
export function makeScheduledTasksCommand() {
|
|
51
|
+
const cmd = new Command("scheduled-tasks").description("Agents that run on a schedule as you, each run in a new conversation");
|
|
52
|
+
cmd
|
|
53
|
+
.command("list")
|
|
54
|
+
.description("List your scheduled tasks with their next and last run")
|
|
55
|
+
.action(async (_opts, command) => {
|
|
56
|
+
await runAction(command, async () => {
|
|
57
|
+
const client = getClient(command);
|
|
58
|
+
const { data } = await client.GET("/v1/scheduled-tasks");
|
|
59
|
+
formatList(data, command, COLUMNS);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
cmd
|
|
63
|
+
.command("get <id>")
|
|
64
|
+
.description("Show one scheduled task, including the connectors it needs before its first run")
|
|
65
|
+
.action(async (id, _opts, command) => {
|
|
66
|
+
await runAction(command, async () => {
|
|
67
|
+
const client = getClient(command);
|
|
68
|
+
const { data } = await client.GET("/v1/scheduled-tasks");
|
|
69
|
+
const task = data?.find((t) => t.id === id);
|
|
70
|
+
if (!task)
|
|
71
|
+
throw new CliUsageError(`No scheduled task of yours has the id ${id}`);
|
|
72
|
+
formatDetail(task, command);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
withRecurrenceOptions(cmd
|
|
76
|
+
.command("create")
|
|
77
|
+
.description("Schedule an agent to run a message at a recurrence (at most once an hour)")
|
|
78
|
+
.requiredOption("--agent <agentId>", "The agent to run")
|
|
79
|
+
.requiredOption("--name <name>", "1 to 80 characters")
|
|
80
|
+
.requiredOption("--instructions <text>", "The message each run starts with, 1 to 4,000 characters")
|
|
81
|
+
.requiredOption("--time-zone <zone>", "IANA time zone, e.g. Europe/Berlin")).action(async (opts, command) => {
|
|
82
|
+
await runAction(command, async () => {
|
|
83
|
+
const recurrence = recurrenceFrom(opts);
|
|
84
|
+
if (!recurrence)
|
|
85
|
+
throw new CliUsageError("create needs --recurrence");
|
|
86
|
+
const client = getClient(command);
|
|
87
|
+
const { data } = await client.POST("/v1/scheduled-tasks", {
|
|
88
|
+
body: {
|
|
89
|
+
agent_id: opts.agent,
|
|
90
|
+
name: opts.name,
|
|
91
|
+
instructions: opts.instructions,
|
|
92
|
+
time_zone: opts.timeZone,
|
|
93
|
+
recurrence,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
formatDetail(data, command);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
withRecurrenceOptions(cmd
|
|
100
|
+
.command("update <id>")
|
|
101
|
+
.description("Change a scheduled task; fields you leave out stay as they are")
|
|
102
|
+
.option("--name <name>", "1 to 80 characters")
|
|
103
|
+
.option("--instructions <text>", "The message each run starts with")
|
|
104
|
+
.option("--time-zone <zone>", "IANA time zone")).action(async (id, opts, command) => {
|
|
105
|
+
await runAction(command, async () => {
|
|
106
|
+
const recurrence = recurrenceFrom(opts);
|
|
107
|
+
const body = {
|
|
108
|
+
...(opts.name !== undefined && { name: opts.name }),
|
|
109
|
+
...(opts.instructions !== undefined && { instructions: opts.instructions }),
|
|
110
|
+
...(opts.timeZone !== undefined && { time_zone: opts.timeZone }),
|
|
111
|
+
...(recurrence && { recurrence }),
|
|
112
|
+
};
|
|
113
|
+
if (Object.keys(body).length === 0) {
|
|
114
|
+
throw new CliUsageError("Nothing to change: pass --name, --instructions, --time-zone or --recurrence");
|
|
115
|
+
}
|
|
116
|
+
await patch(command, id, body);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
cmd
|
|
120
|
+
.command("pause <id>")
|
|
121
|
+
.description("Stop the schedule; resume starts it again")
|
|
122
|
+
.action(async (id, _opts, command) => {
|
|
123
|
+
await runAction(command, () => patch(command, id, { state: "paused" }));
|
|
124
|
+
});
|
|
125
|
+
cmd
|
|
126
|
+
.command("resume <id>")
|
|
127
|
+
.description("Start a paused or stopped task again; the next run is the next time after now")
|
|
128
|
+
.action(async (id, _opts, command) => {
|
|
129
|
+
await runAction(command, () => patch(command, id, { state: "active" }));
|
|
130
|
+
});
|
|
131
|
+
cmd
|
|
132
|
+
.command("delete <id>")
|
|
133
|
+
.description("Delete a scheduled task; a run in progress finishes and past conversations stay yours")
|
|
134
|
+
.action(async (id, _opts, command) => {
|
|
135
|
+
await runAction(command, async () => {
|
|
136
|
+
const client = getClient(command);
|
|
137
|
+
await client.DELETE("/v1/scheduled-tasks/{id}", { params: { path: { id } } });
|
|
138
|
+
formatSuccess(`Deleted scheduled task ${id}`, command);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
cmd
|
|
142
|
+
.command("run <id>")
|
|
143
|
+
.description("Run a scheduled task now in a new conversation, without changing its schedule")
|
|
144
|
+
.action(async (id, _opts, command) => {
|
|
145
|
+
await runAction(command, async () => {
|
|
146
|
+
const client = getClient(command);
|
|
147
|
+
const { data } = await client.POST("/v1/scheduled-tasks/{id}/run", {
|
|
148
|
+
params: { path: { id } },
|
|
149
|
+
});
|
|
150
|
+
formatDetail(data, command);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
return cmd;
|
|
154
|
+
}
|
|
155
|
+
async function patch(command, id, body) {
|
|
156
|
+
const client = getClient(command);
|
|
157
|
+
const { data } = await client.PATCH("/v1/scheduled-tasks/{id}", {
|
|
158
|
+
params: { path: { id } },
|
|
159
|
+
body: body,
|
|
160
|
+
});
|
|
161
|
+
formatDetail(data, command);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=scheduled-tasks.js.map
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,8 @@ import { makeExperimentsCommand } from "./commands/experiments.js";
|
|
|
23
23
|
import { makeTracingCommand } from "./commands/tracing.js";
|
|
24
24
|
import { makeSettingsCommand } from "./commands/settings.js";
|
|
25
25
|
import { makeMemoryCommand } from "./commands/memory.js";
|
|
26
|
+
import { makeScheduledTasksCommand } from "./commands/scheduled-tasks.js";
|
|
27
|
+
import { makeBatchesCommand } from "./commands/batches.js";
|
|
26
28
|
import { makeEvaluatorsCommand } from "./commands/evaluators.js";
|
|
27
29
|
import { makeScoresCommand } from "./commands/scores.js";
|
|
28
30
|
import { makeQueuesCommand } from "./commands/queues.js";
|
|
@@ -68,6 +70,8 @@ program.addCommand(makeQueuesCommand());
|
|
|
68
70
|
program.addCommand(makeTracingCommand());
|
|
69
71
|
program.addCommand(makeSettingsCommand());
|
|
70
72
|
program.addCommand(makeMemoryCommand());
|
|
73
|
+
program.addCommand(makeScheduledTasksCommand());
|
|
74
|
+
program.addCommand(makeBatchesCommand());
|
|
71
75
|
program.addCommand(makeAgentsCommand());
|
|
72
76
|
program.addCommand(makeConversationsCommand());
|
|
73
77
|
program.addCommand(makeResponsesCommand());
|
package/dist/lib/agent-run.d.ts
CHANGED
|
@@ -14,6 +14,32 @@ export interface PendingApproval {
|
|
|
14
14
|
reason: string | null;
|
|
15
15
|
/** What a built-in SkillsApply change does (#781); null for every other approval. Keyed on presence, not on the tool name (#948). */
|
|
16
16
|
preview: SkillsApplyPreview | null;
|
|
17
|
+
/** Only a human may decide this request (`human_only`): no standing grant is offered (#1801). */
|
|
18
|
+
humanOnly?: boolean;
|
|
19
|
+
/** What a built-in KnowledgeApply change does (#1801); absent for every other approval. */
|
|
20
|
+
knowledgeApply?: KnowledgeApplyEntry[];
|
|
21
|
+
/** What a built-in ScheduledTaskApply operation does (#1818); absent for every other approval. */
|
|
22
|
+
scheduledTaskApply?: ScheduledTaskApplyEntry;
|
|
23
|
+
}
|
|
24
|
+
/** The part of a ScheduledTaskApply card the prompt prints (#1818); every string is untrusted text, the instructions are never kept. */
|
|
25
|
+
export interface ScheduledTaskApplyEntry {
|
|
26
|
+
/** `create`, `update`, `pause`, `resume` or `delete`; another value is printed as sent. */
|
|
27
|
+
op: string;
|
|
28
|
+
name?: string;
|
|
29
|
+
/** The wire `recurrence` object (`kind`, `time`, `day`, ...). */
|
|
30
|
+
recurrence?: AnyRecord;
|
|
31
|
+
timeZone?: string;
|
|
32
|
+
agentName?: string;
|
|
33
|
+
}
|
|
34
|
+
/** One row of a KnowledgeApply approval (#1801); every string is untrusted text. */
|
|
35
|
+
export interface KnowledgeApplyEntry {
|
|
36
|
+
index: number;
|
|
37
|
+
/** `add`, `replace` or `remove`; another value is printed as sent. */
|
|
38
|
+
op: string;
|
|
39
|
+
knowledgeBase?: string;
|
|
40
|
+
knowledgeBaseName?: string;
|
|
41
|
+
name?: string;
|
|
42
|
+
sizeBytes?: number;
|
|
17
43
|
}
|
|
18
44
|
export interface ToolCallSummary {
|
|
19
45
|
tool: string;
|
package/dist/lib/agent-run.js
CHANGED
|
@@ -4,6 +4,48 @@ import { DEFAULT_CHAT_URL } from "./config.js";
|
|
|
4
4
|
import { answerUrlFor, connectCallIds, connectionsPhrase, inputLabelsPhrase, pendingConnectionsOf, pendingInputsOf, } from "./connect-pause.js";
|
|
5
5
|
import { CliUsageError } from "./errors.js";
|
|
6
6
|
import { previewIsIncomplete, previewLines } from "./skills-apply-preview.js";
|
|
7
|
+
/** The wire `scheduled_task_apply` field, defensively: anything without a string `op` is undefined; bad parts drop out. */
|
|
8
|
+
function parseScheduledTaskApply(raw) {
|
|
9
|
+
const r = raw;
|
|
10
|
+
if (!r || typeof r !== "object" || Array.isArray(r) || typeof r.op !== "string")
|
|
11
|
+
return undefined;
|
|
12
|
+
const e = r.effective;
|
|
13
|
+
const str = (v) => (typeof v === "string" ? v : undefined);
|
|
14
|
+
const rec = e?.recurrence;
|
|
15
|
+
const agent = e?.agent;
|
|
16
|
+
const out = { op: r.op };
|
|
17
|
+
if (str(e?.name) !== undefined)
|
|
18
|
+
out.name = str(e?.name);
|
|
19
|
+
if (rec && typeof rec === "object" && !Array.isArray(rec))
|
|
20
|
+
out.recurrence = rec;
|
|
21
|
+
if (str(e?.time_zone) !== undefined)
|
|
22
|
+
out.timeZone = str(e?.time_zone);
|
|
23
|
+
if (str(agent?.name) !== undefined)
|
|
24
|
+
out.agentName = str(agent?.name);
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
const KNOWLEDGE_APPLY_MAX_ENTRIES = 10;
|
|
28
|
+
/** The wire `knowledge_apply` field, defensively: anything but `{entries: [...]}` is undefined; bad rows drop out. */
|
|
29
|
+
function parseKnowledgeApply(raw) {
|
|
30
|
+
const entries = raw?.entries;
|
|
31
|
+
if (!Array.isArray(entries))
|
|
32
|
+
return undefined;
|
|
33
|
+
const str = (v) => (typeof v === "string" ? v : undefined);
|
|
34
|
+
const out = [];
|
|
35
|
+
for (const e of entries.slice(0, KNOWLEDGE_APPLY_MAX_ENTRIES)) {
|
|
36
|
+
if (!e || typeof e !== "object" || typeof e.op !== "string")
|
|
37
|
+
continue;
|
|
38
|
+
out.push({
|
|
39
|
+
index: typeof e.index === "number" ? e.index : out.length,
|
|
40
|
+
op: e.op,
|
|
41
|
+
knowledgeBase: str(e.knowledge_base),
|
|
42
|
+
knowledgeBaseName: str(e.knowledge_base_name),
|
|
43
|
+
name: str(e.name),
|
|
44
|
+
sizeBytes: typeof e.size_bytes === "number" ? e.size_bytes : undefined,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
7
49
|
export const CONVERSATION_MODES = ["plan", "ask", "auto"];
|
|
8
50
|
/** `--mode` help text, in the words of the embedded chat's mode chip (#655). */
|
|
9
51
|
export const MODE_OPTION_HELP = "Conversation mode: plan (read-only), ask (calls that need approval wait for you), " +
|
|
@@ -228,6 +270,9 @@ export function buildRunEnvelope(result, agentRef, chatUrl = DEFAULT_CHAT_URL) {
|
|
|
228
270
|
policyClass: String(i.policy_class),
|
|
229
271
|
reason: typeof i.reason === "string" && i.reason ? i.reason : null,
|
|
230
272
|
preview: i.preview && typeof i.preview === "object" && !Array.isArray(i.preview) ? i.preview : null,
|
|
273
|
+
humanOnly: i.human_only === true ? true : undefined,
|
|
274
|
+
knowledgeApply: parseKnowledgeApply(i.knowledge_apply),
|
|
275
|
+
scheduledTaskApply: parseScheduledTaskApply(i.scheduled_task_apply),
|
|
231
276
|
})),
|
|
232
277
|
...output.filter((i) => i.type === "mcp_approval_request").map(connectorApproval),
|
|
233
278
|
];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createInterface } from "node:readline/promises";
|
|
2
2
|
import chalk from "chalk";
|
|
3
|
+
import { formatBytes } from "../commands/convert.js";
|
|
3
4
|
import { hasInvisible, revealInvisible, stripControl } from "./agent-run.js";
|
|
4
5
|
import { REMEMBER_NOTE, previewIsIncomplete, previewLines } from "./skills-apply-preview.js";
|
|
5
6
|
/** Raised when the prompt's input closes (EOF, Ctrl+C, Ctrl+D) before an answer arrives. */
|
|
@@ -79,10 +80,18 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
79
80
|
else {
|
|
80
81
|
request();
|
|
81
82
|
}
|
|
83
|
+
// A KnowledgeApply change reads as one line per document (#1801); the excerpt is never printed.
|
|
84
|
+
for (const e of a.knowledgeApply ?? [])
|
|
85
|
+
write(knowledgeLine(e, s));
|
|
86
|
+
// A ScheduledTaskApply operation reads as one line; the instructions are never printed here (#1818).
|
|
87
|
+
if (a.scheduledTaskApply)
|
|
88
|
+
write(scheduledTaskLine(a.scheduledTaskApply, s));
|
|
82
89
|
if (a.reason)
|
|
83
90
|
write(chalk.dim(`reason: ${s(a.reason)}`));
|
|
84
|
-
|
|
85
|
-
const
|
|
91
|
+
// A human-only request is decided by a human each time: no standing grant (#1801).
|
|
92
|
+
const noRemember = destructive || a.humanOnly === true;
|
|
93
|
+
const question = noRemember ? "[a]pprove / [r]eject? " : "[a]pprove / [r]eject / approve and [R]emember? ";
|
|
94
|
+
const hint = noRemember
|
|
86
95
|
? "Answer a (approve), r (reject)"
|
|
87
96
|
: "Answer a (approve), r (reject), or R (approve and remember)";
|
|
88
97
|
for (;;) {
|
|
@@ -91,7 +100,7 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
91
100
|
answers.set(a.approvalId, { decision: "approve" });
|
|
92
101
|
break;
|
|
93
102
|
}
|
|
94
|
-
if (reply === "R" && !
|
|
103
|
+
if (reply === "R" && !noRemember) {
|
|
95
104
|
answers.set(a.approvalId, { decision: "approve", remember: true });
|
|
96
105
|
break;
|
|
97
106
|
}
|
|
@@ -105,6 +114,27 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
105
114
|
}
|
|
106
115
|
return answers;
|
|
107
116
|
}
|
|
117
|
+
/** ` create Overdue invoices weekdays 07:00 · Europe/Berlin agent Dolibarr`; missing parts are left out. */
|
|
118
|
+
function scheduledTaskLine(e, s) {
|
|
119
|
+
const r = e.recurrence ?? {};
|
|
120
|
+
const minute = r.minute === undefined ? "" : `:${String(r.minute).padStart(2, "0")}`;
|
|
121
|
+
const dom = r.day_of_month === undefined ? "" : `day ${r.day_of_month}`;
|
|
122
|
+
const when = [r.kind, r.date, r.day, dom, r.time, minute].filter((p) => typeof p === "string" && p).join(" ");
|
|
123
|
+
const schedule = [when, e.timeZone].filter(Boolean).join(" · ");
|
|
124
|
+
const parts = [s(e.op), s(e.name ?? ""), s(schedule), e.agentName ? `agent ${s(e.agentName)}` : ""];
|
|
125
|
+
return ` ${parts.filter(Boolean).join(" ")}`;
|
|
126
|
+
}
|
|
127
|
+
const KNOWLEDGE_MARKS = { add: "+", replace: "~", remove: "-" };
|
|
128
|
+
/** ` + add Price lists prices-2026-q4.pdf (1.2 MB)`; `s` strips control characters from each string. */
|
|
129
|
+
function knowledgeLine(e, s) {
|
|
130
|
+
const parts = [
|
|
131
|
+
`${KNOWLEDGE_MARKS[e.op] ?? "?"} ${s(e.op).padEnd(8)}`,
|
|
132
|
+
s(e.knowledgeBaseName || e.knowledgeBase || ""),
|
|
133
|
+
s(e.name ?? ""),
|
|
134
|
+
e.sizeBytes === undefined ? "" : `(${formatBytes(e.sizeBytes)})`,
|
|
135
|
+
];
|
|
136
|
+
return ` ${parts.filter(Boolean).join(" ")}`;
|
|
137
|
+
}
|
|
108
138
|
/** Diff lines sit indented six spaces under their file; only those are coloured. */
|
|
109
139
|
function colourPreviewLine(line) {
|
|
110
140
|
if (!line.startsWith(" "))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@2kw/ai",
|
|
3
|
-
"version": "8.3.0
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "CLI for 2kw.ai — schema-driven document extraction, an OpenAI-compatible EU LLM gateway, transcription, prompts, datasets, and experiments from your terminal or agentic workflows. Ships as 2kw, backbone, and bb.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|