@2kw/ai 8.3.0-dev.8 → 8.3.1
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/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 +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
|
|
@@ -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
|
@@ -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.
|
|
3
|
+
"version": "8.3.1",
|
|
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",
|