@2kw/ai 8.3.0-dev.4 → 8.3.0-dev.8
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.js +2 -0
- package/dist/commands/agents.js +42 -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/lib/agent-run.d.ts +14 -0
- package/dist/lib/agent-run.js +24 -0
- package/dist/lib/approval-prompt.js +20 -3
- package/package.json +1 -1
|
@@ -34,6 +34,8 @@ 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",
|
|
37
39
|
};
|
|
38
40
|
/**
|
|
39
41
|
* The three tools `backbone.canvas` grants (#1698). Listing one is refused on the backend too
|
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");
|
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)
|
package/dist/lib/agent-run.d.ts
CHANGED
|
@@ -14,6 +14,20 @@ 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
|
+
}
|
|
22
|
+
/** One row of a KnowledgeApply approval (#1801); every string is untrusted text. */
|
|
23
|
+
export interface KnowledgeApplyEntry {
|
|
24
|
+
index: number;
|
|
25
|
+
/** `add`, `replace` or `remove`; another value is printed as sent. */
|
|
26
|
+
op: string;
|
|
27
|
+
knowledgeBase?: string;
|
|
28
|
+
knowledgeBaseName?: string;
|
|
29
|
+
name?: string;
|
|
30
|
+
sizeBytes?: number;
|
|
17
31
|
}
|
|
18
32
|
export interface ToolCallSummary {
|
|
19
33
|
tool: string;
|
package/dist/lib/agent-run.js
CHANGED
|
@@ -4,6 +4,28 @@ 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
|
+
const KNOWLEDGE_APPLY_MAX_ENTRIES = 10;
|
|
8
|
+
/** The wire `knowledge_apply` field, defensively: anything but `{entries: [...]}` is undefined; bad rows drop out. */
|
|
9
|
+
function parseKnowledgeApply(raw) {
|
|
10
|
+
const entries = raw?.entries;
|
|
11
|
+
if (!Array.isArray(entries))
|
|
12
|
+
return undefined;
|
|
13
|
+
const str = (v) => (typeof v === "string" ? v : undefined);
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const e of entries.slice(0, KNOWLEDGE_APPLY_MAX_ENTRIES)) {
|
|
16
|
+
if (!e || typeof e !== "object" || typeof e.op !== "string")
|
|
17
|
+
continue;
|
|
18
|
+
out.push({
|
|
19
|
+
index: typeof e.index === "number" ? e.index : out.length,
|
|
20
|
+
op: e.op,
|
|
21
|
+
knowledgeBase: str(e.knowledge_base),
|
|
22
|
+
knowledgeBaseName: str(e.knowledge_base_name),
|
|
23
|
+
name: str(e.name),
|
|
24
|
+
sizeBytes: typeof e.size_bytes === "number" ? e.size_bytes : undefined,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
7
29
|
export const CONVERSATION_MODES = ["plan", "ask", "auto"];
|
|
8
30
|
/** `--mode` help text, in the words of the embedded chat's mode chip (#655). */
|
|
9
31
|
export const MODE_OPTION_HELP = "Conversation mode: plan (read-only), ask (calls that need approval wait for you), " +
|
|
@@ -228,6 +250,8 @@ export function buildRunEnvelope(result, agentRef, chatUrl = DEFAULT_CHAT_URL) {
|
|
|
228
250
|
policyClass: String(i.policy_class),
|
|
229
251
|
reason: typeof i.reason === "string" && i.reason ? i.reason : null,
|
|
230
252
|
preview: i.preview && typeof i.preview === "object" && !Array.isArray(i.preview) ? i.preview : null,
|
|
253
|
+
humanOnly: i.human_only === true ? true : undefined,
|
|
254
|
+
knowledgeApply: parseKnowledgeApply(i.knowledge_apply),
|
|
231
255
|
})),
|
|
232
256
|
...output.filter((i) => i.type === "mcp_approval_request").map(connectorApproval),
|
|
233
257
|
];
|
|
@@ -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,15 @@ 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));
|
|
82
86
|
if (a.reason)
|
|
83
87
|
write(chalk.dim(`reason: ${s(a.reason)}`));
|
|
84
|
-
|
|
85
|
-
const
|
|
88
|
+
// A human-only request is decided by a human each time: no standing grant (#1801).
|
|
89
|
+
const noRemember = destructive || a.humanOnly === true;
|
|
90
|
+
const question = noRemember ? "[a]pprove / [r]eject? " : "[a]pprove / [r]eject / approve and [R]emember? ";
|
|
91
|
+
const hint = noRemember
|
|
86
92
|
? "Answer a (approve), r (reject)"
|
|
87
93
|
: "Answer a (approve), r (reject), or R (approve and remember)";
|
|
88
94
|
for (;;) {
|
|
@@ -91,7 +97,7 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
91
97
|
answers.set(a.approvalId, { decision: "approve" });
|
|
92
98
|
break;
|
|
93
99
|
}
|
|
94
|
-
if (reply === "R" && !
|
|
100
|
+
if (reply === "R" && !noRemember) {
|
|
95
101
|
answers.set(a.approvalId, { decision: "approve", remember: true });
|
|
96
102
|
break;
|
|
97
103
|
}
|
|
@@ -105,6 +111,17 @@ export async function promptApprovals(pending, ask, write = (line) => console.er
|
|
|
105
111
|
}
|
|
106
112
|
return answers;
|
|
107
113
|
}
|
|
114
|
+
const KNOWLEDGE_MARKS = { add: "+", replace: "~", remove: "-" };
|
|
115
|
+
/** ` + add Price lists prices-2026-q4.pdf (1.2 MB)`; `s` strips control characters from each string. */
|
|
116
|
+
function knowledgeLine(e, s) {
|
|
117
|
+
const parts = [
|
|
118
|
+
`${KNOWLEDGE_MARKS[e.op] ?? "?"} ${s(e.op).padEnd(8)}`,
|
|
119
|
+
s(e.knowledgeBaseName || e.knowledgeBase || ""),
|
|
120
|
+
s(e.name ?? ""),
|
|
121
|
+
e.sizeBytes === undefined ? "" : `(${formatBytes(e.sizeBytes)})`,
|
|
122
|
+
];
|
|
123
|
+
return ` ${parts.filter(Boolean).join(" ")}`;
|
|
124
|
+
}
|
|
108
125
|
/** Diff lines sit indented six spaces under their file; only those are coloured. */
|
|
109
126
|
function colourPreviewLine(line) {
|
|
110
127
|
if (!line.startsWith(" "))
|
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.8",
|
|
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",
|