@2kw/ai 8.3.0-dev.12 → 8.3.0-dev.16
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 +12 -0
- package/dist/commands/batches.d.ts +8 -0
- package/dist/commands/batches.js +99 -0
- package/dist/index.js +2 -0
- package/dist/lib/agent-run.d.ts +12 -0
- package/dist/lib/agent-run.js +21 -0
- package/dist/lib/approval-prompt.js +13 -0
- 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[];
|
|
@@ -36,6 +36,9 @@ export const NON_AUTHORABLE_TOOL_TYPES = {
|
|
|
36
36
|
"backbone.view_image": "it is added at run time wherever the sandboxed shell is",
|
|
37
37
|
// #1801: injected for callers allowed to change knowledge; an authored copy is dropped.
|
|
38
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",
|
|
39
42
|
};
|
|
40
43
|
/**
|
|
41
44
|
* The three tools `backbone.canvas` grants (#1698). Listing one is refused on the backend too
|
|
@@ -59,6 +62,7 @@ const BUILTIN_TYPES = [
|
|
|
59
62
|
"backbone.skill",
|
|
60
63
|
"backbone.bash",
|
|
61
64
|
"backbone.canvas",
|
|
65
|
+
"backbone.batch",
|
|
62
66
|
"backbone.show_table",
|
|
63
67
|
"backbone.show_chart",
|
|
64
68
|
"function",
|
|
@@ -242,6 +246,13 @@ export const agentSchema = {
|
|
|
242
246
|
required: ["type"],
|
|
243
247
|
properties: { type: { const: "backbone.canvas" }, requiresConfirmation: { type: "boolean" } },
|
|
244
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
|
+
},
|
|
245
256
|
// #1419, retired by Canvas (#1698) but still valid: no options; requiresConfirmation as todoTool.
|
|
246
257
|
showTableTool: {
|
|
247
258
|
type: "object",
|
|
@@ -315,6 +326,7 @@ export const agentSchema = {
|
|
|
315
326
|
{ if: typeIs("backbone.skill"), then: { $ref: "#/$defs/skillTool" } },
|
|
316
327
|
{ if: typeIs("backbone.bash"), then: { $ref: "#/$defs/bashTool" } },
|
|
317
328
|
{ if: typeIs("backbone.canvas"), then: { $ref: "#/$defs/canvasTool" } },
|
|
329
|
+
{ if: typeIs("backbone.batch"), then: { $ref: "#/$defs/batchTool" } },
|
|
318
330
|
{ if: typeIs("backbone.show_table"), then: { $ref: "#/$defs/showTableTool" } },
|
|
319
331
|
{ if: typeIs("backbone.show_chart"), then: { $ref: "#/$defs/showChartTool" } },
|
|
320
332
|
{ if: typeIs("function"), then: { $ref: "#/$defs/functionTool" } },
|
|
@@ -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/index.js
CHANGED
|
@@ -24,6 +24,7 @@ import { makeTracingCommand } from "./commands/tracing.js";
|
|
|
24
24
|
import { makeSettingsCommand } from "./commands/settings.js";
|
|
25
25
|
import { makeMemoryCommand } from "./commands/memory.js";
|
|
26
26
|
import { makeScheduledTasksCommand } from "./commands/scheduled-tasks.js";
|
|
27
|
+
import { makeBatchesCommand } from "./commands/batches.js";
|
|
27
28
|
import { makeEvaluatorsCommand } from "./commands/evaluators.js";
|
|
28
29
|
import { makeScoresCommand } from "./commands/scores.js";
|
|
29
30
|
import { makeQueuesCommand } from "./commands/queues.js";
|
|
@@ -70,6 +71,7 @@ program.addCommand(makeTracingCommand());
|
|
|
70
71
|
program.addCommand(makeSettingsCommand());
|
|
71
72
|
program.addCommand(makeMemoryCommand());
|
|
72
73
|
program.addCommand(makeScheduledTasksCommand());
|
|
74
|
+
program.addCommand(makeBatchesCommand());
|
|
73
75
|
program.addCommand(makeAgentsCommand());
|
|
74
76
|
program.addCommand(makeConversationsCommand());
|
|
75
77
|
program.addCommand(makeResponsesCommand());
|
package/dist/lib/agent-run.d.ts
CHANGED
|
@@ -18,6 +18,18 @@ export interface PendingApproval {
|
|
|
18
18
|
humanOnly?: boolean;
|
|
19
19
|
/** What a built-in KnowledgeApply change does (#1801); absent for every other approval. */
|
|
20
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;
|
|
21
33
|
}
|
|
22
34
|
/** One row of a KnowledgeApply approval (#1801); every string is untrusted text. */
|
|
23
35
|
export interface KnowledgeApplyEntry {
|
package/dist/lib/agent-run.js
CHANGED
|
@@ -4,6 +4,26 @@ 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
|
+
}
|
|
7
27
|
const KNOWLEDGE_APPLY_MAX_ENTRIES = 10;
|
|
8
28
|
/** The wire `knowledge_apply` field, defensively: anything but `{entries: [...]}` is undefined; bad rows drop out. */
|
|
9
29
|
function parseKnowledgeApply(raw) {
|
|
@@ -252,6 +272,7 @@ export function buildRunEnvelope(result, agentRef, chatUrl = DEFAULT_CHAT_URL) {
|
|
|
252
272
|
preview: i.preview && typeof i.preview === "object" && !Array.isArray(i.preview) ? i.preview : null,
|
|
253
273
|
humanOnly: i.human_only === true ? true : undefined,
|
|
254
274
|
knowledgeApply: parseKnowledgeApply(i.knowledge_apply),
|
|
275
|
+
scheduledTaskApply: parseScheduledTaskApply(i.scheduled_task_apply),
|
|
255
276
|
})),
|
|
256
277
|
...output.filter((i) => i.type === "mcp_approval_request").map(connectorApproval),
|
|
257
278
|
];
|
|
@@ -83,6 +83,9 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
83
83
|
// A KnowledgeApply change reads as one line per document (#1801); the excerpt is never printed.
|
|
84
84
|
for (const e of a.knowledgeApply ?? [])
|
|
85
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));
|
|
86
89
|
if (a.reason)
|
|
87
90
|
write(chalk.dim(`reason: ${s(a.reason)}`));
|
|
88
91
|
// A human-only request is decided by a human each time: no standing grant (#1801).
|
|
@@ -111,6 +114,16 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
111
114
|
}
|
|
112
115
|
return answers;
|
|
113
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
|
+
}
|
|
114
127
|
const KNOWLEDGE_MARKS = { add: "+", replace: "~", remove: "-" };
|
|
115
128
|
/** ` + add Price lists prices-2026-q4.pdf (1.2 MB)`; `s` strips control characters from each string. */
|
|
116
129
|
function knowledgeLine(e, s) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@2kw/ai",
|
|
3
|
-
"version": "8.3.0-dev.
|
|
3
|
+
"version": "8.3.0-dev.16",
|
|
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",
|