@chibitek/chibi 0.1.176 → 0.1.178
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/assets/{abnfDiagram-O67JEVCF-sRKEv3Mr.js → abnfDiagram-O67JEVCF-dWHl3jkm.js} +1 -1
- package/dist/assets/{arc-BmpSdaQx.js → arc-CZzCs6es.js} +1 -1
- package/dist/assets/{architectureDiagram-NJMV4G6O-D7wISetH.js → architectureDiagram-NJMV4G6O-YwZAu6Y7.js} +1 -1
- package/dist/assets/{blockDiagram-BEXU5L5S-DNgLsg2M.js → blockDiagram-BEXU5L5S-WmC_extb.js} +1 -1
- package/dist/assets/{c4Diagram-YGBWAQC7-Bx9bZh8W.js → c4Diagram-YGBWAQC7-B65Jnm1V.js} +1 -1
- package/dist/assets/channel-ClZ5TVsZ.js +1 -0
- package/dist/assets/{chunk-2Q5K7J3B-D3fVaZ4m.js → chunk-2Q5K7J3B-CKo9M6W3.js} +1 -1
- package/dist/assets/{chunk-3FUC2YCW-CwGz6Ha8.js → chunk-3FUC2YCW-7yQVJbNw.js} +2 -2
- package/dist/assets/{chunk-5VM5RSS4-B6OEecjg.js → chunk-5VM5RSS4-De0KYP62.js} +1 -1
- package/dist/assets/{chunk-GTNCS2PH-BQcidIif.js → chunk-GTNCS2PH-CLr-nzve.js} +1 -1
- package/dist/assets/{chunk-GWA4HPMP-k9aUZSoo.js → chunk-GWA4HPMP-CtuDeI-a.js} +1 -1
- package/dist/assets/{chunk-JWPE2WC7-h3JmRvjC.js → chunk-JWPE2WC7-y52neVCm.js} +1 -1
- package/dist/assets/{chunk-NETBCI7D-neWbjUzw.js → chunk-NETBCI7D-CTQRNeEv.js} +1 -1
- package/dist/assets/{chunk-WEXAMYUT-5CvO78xu.js → chunk-WEXAMYUT-7zNFA7Tc.js} +1 -1
- package/dist/assets/{chunk-XXDRQBXY-WB5mOypF.js → chunk-XXDRQBXY-CF0jLMvs.js} +1 -1
- package/dist/assets/{classDiagram-v2-NBCMYWYE-BTPH5g_T.js → classDiagram-v2-NBCMYWYE-WBfBG6F9.js} +1 -1
- package/dist/assets/{cose-bilkent-JH36ORCC-D3vHHTSV.js → cose-bilkent-JH36ORCC-BN-OWUOQ.js} +1 -1
- package/dist/assets/{cynefin-OW5HDTMX-DgqNPGWZ.js → cynefin-OW5HDTMX-icxZUnEx.js} +1 -1
- package/dist/assets/{cynefinDiagram-VND7K2PF-R5Tq_pW2.js → cynefinDiagram-VND7K2PF-Clgujiet.js} +1 -1
- package/dist/assets/{dagre-6A5THRUB-CxOlFmnC.js → dagre-6A5THRUB-B-mr-ojn.js} +1 -1
- package/dist/assets/{diagram-22UHCM2B-CR0cl7m3.js → diagram-22UHCM2B-0VKN1h9d.js} +1 -1
- package/dist/assets/{diagram-3UASUU5V-CbKL4FKO.js → diagram-3UASUU5V-9Nvuaj11.js} +1 -1
- package/dist/assets/{diagram-ATOU4E4O-CrJLqyZe.js → diagram-ATOU4E4O-B-uzDb8p.js} +1 -1
- package/dist/assets/{diagram-CDSNMT55-B9Yv89qV.js → diagram-CDSNMT55-CTvDjLvE.js} +1 -1
- package/dist/assets/{diagram-MLGK6HIB-DmiwzM_2.js → diagram-MLGK6HIB-DxDrNPv6.js} +1 -1
- package/dist/assets/{diagram-MPIPVDR6-CcOb0oW2.js → diagram-MPIPVDR6-CGHXB_-s.js} +1 -1
- package/dist/assets/{ebnfDiagram-ZINNZB2B-CBPLHI7_.js → ebnfDiagram-ZINNZB2B-DNkShTCq.js} +1 -1
- package/dist/assets/{elk-276RUBZZ-6FqNvi_J.js → elk-276RUBZZ-CNZgZP06.js} +1 -1
- package/dist/assets/{erDiagram-OPXOYQCR-DMzFBP5h.js → erDiagram-OPXOYQCR-CVlJu0RH.js} +1 -1
- package/dist/assets/{flowDiagram-KWPJA3E3-DPy8GVYu.js → flowDiagram-KWPJA3E3-ZWXAAVoE.js} +1 -1
- package/dist/assets/{ganttDiagram-FUAMR5RP-BQd_gAGi.js → ganttDiagram-FUAMR5RP-BaPFE0m8.js} +1 -1
- package/dist/assets/{gitGraphDiagram-X574FWY7-DJfl14ff.js → gitGraphDiagram-X574FWY7-B__eRHIL.js} +1 -1
- package/dist/assets/index-CI0vGAif.css +1 -0
- package/dist/assets/{index-BgeuRd0K.js → index-CluLWh67.js} +1 -1
- package/dist/assets/{index-CiUkZ0_j.js → index-DxRLJ091.js} +197 -195
- package/dist/assets/{infoDiagram-VRGFBTTK-BV8yVtja.js → infoDiagram-VRGFBTTK-DQkxDIsw.js} +1 -1
- package/dist/assets/{ishikawaDiagram-OU5B5YK6-DyDmA3-6.js → ishikawaDiagram-OU5B5YK6-dc12aZx1.js} +1 -1
- package/dist/assets/{journeyDiagram-ZHPQQLJL-Bm31t8C8.js → journeyDiagram-ZHPQQLJL-BUQgOHxW.js} +1 -1
- package/dist/assets/{kanban-definition-PNTS6WVX-DJHtOiRR.js → kanban-definition-PNTS6WVX-0G8FTiwC.js} +1 -1
- package/dist/assets/{linear-CfkoYheD.js → linear-BsZ0eCh6.js} +1 -1
- package/dist/assets/{mermaid.core-BjvwttN3.js → mermaid.core-CBJIrEjV.js} +5 -5
- package/dist/assets/{mindmap-definition-NLK3R4M7-9Qb6NZdz.js → mindmap-definition-NLK3R4M7-oSFMOeAf.js} +1 -1
- package/dist/assets/{pegDiagram-GJSIUBJH-CkmUVrtf.js → pegDiagram-GJSIUBJH-DfF1Bylk.js} +1 -1
- package/dist/assets/{pieDiagram-5QR66LMP-DslnXTwg.js → pieDiagram-5QR66LMP-B75tQFJV.js} +1 -1
- package/dist/assets/{quadrantDiagram-O4NWA36T-ezbFZDsw.js → quadrantDiagram-O4NWA36T-Bzost4vl.js} +1 -1
- package/dist/assets/{railroadDiagram-XR7U4H2S-D4BEU9x6.js → railroadDiagram-XR7U4H2S-Kj-_EJse.js} +1 -1
- package/dist/assets/{requirementDiagram-PLB6GJNP-BbzX7pvK.js → requirementDiagram-PLB6GJNP-DgGyLbhO.js} +1 -1
- package/dist/assets/{sankeyDiagram-IPEJSGJF-3CkqEiXd.js → sankeyDiagram-IPEJSGJF-Ds7nNV4g.js} +1 -1
- package/dist/assets/{sequenceDiagram-PO4LG4MO-CgCGVT2m.js → sequenceDiagram-PO4LG4MO-BherGJTE.js} +1 -1
- package/dist/assets/{sizeCapture-INFHLROL-3WvzT1S8.js → sizeCapture-INFHLROL-his3_ohk.js} +1 -1
- package/dist/assets/{stateDiagram-v2-GCMORJYK-DJLDdpcK.js → stateDiagram-v2-GCMORJYK-Dm1QWOxb.js} +1 -1
- package/dist/assets/{swimlanes-2SLR337P-D91mFQnO.js → swimlanes-2SLR337P-CCDiiGy4.js} +1 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX-7bU41JJL.js +8 -0
- package/dist/assets/{timeline-definition-EJHVYXUP-BjIDeT1V.js → timeline-definition-EJHVYXUP-CTgG6kVO.js} +1 -1
- package/dist/assets/{usecaseDiagram-POWQR4AR-B0Ai3gPB.js → usecaseDiagram-POWQR4AR-B9FjIil8.js} +1 -1
- package/dist/assets/{vennDiagram-UO4OBE2U-CwfOPn1H.js → vennDiagram-UO4OBE2U-D_WKiutd.js} +1 -1
- package/dist/assets/{wardleyDiagram-VNRHLVJA-Dpw6_U0p.js → wardleyDiagram-VNRHLVJA-DqAabdPt.js} +1 -1
- package/dist/assets/{xychartDiagram-PMCCYNJV-DqXC0ReF.js → xychartDiagram-PMCCYNJV-CYpL8DXw.js} +1 -1
- package/dist/index.html +2 -2
- package/dist-server/drivers/agents-proxy.js +3 -2
- package/dist-server/index.js +1851 -1632
- package/dist-server/openmausbot.js +649 -490
- package/dist-server/pair-cli.js +649 -490
- package/dist-server/server/attachment-mimes.js +31 -7
- package/dist-server/server/attachments.js +16 -20
- package/dist-server/server/drivers/acp/core.js +10 -37
- package/dist-server/server/drivers/acp/droid.js +1 -0
- package/dist-server/server/drivers/acp/gemini.js +10 -0
- package/dist-server/server/drivers/acp/kimi.js +1 -0
- package/dist-server/server/drivers/acp/mode-readback.js +72 -0
- package/dist-server/server/drivers/acp/qwen.js +12 -0
- package/dist-server/server/drivers/acp/tool-log.js +40 -0
- package/dist-server/server/drivers/acp/vibe.js +14 -1
- package/dist-server/server/drivers/agents-catalog.js +2 -2
- package/dist-server/server/drivers/chat-mcp-tools.js +21 -1
- package/dist-server/server/drivers/openai-chat.js +1 -1
- package/dist-server/server/engine-tiers.js +1 -1
- package/dist-server/server/free-turn-guard.js +32 -0
- package/dist-server/server/harness-import/history.js +1 -1
- package/dist-server/server/incidents.js +9 -2
- package/dist-server/server/index.js +40 -21
- package/dist-server/server/mcp-secrets.js +33 -5
- package/dist-server/server/routes/engine-tiers.js +3 -1
- package/dist-server/server/vault/routes.js +1 -1
- package/dist-server/server/vault/store.js +1 -1
- package/dist-server/shared/approval-readback.js +52 -0
- package/dist-server/shared/provider-accounts.js +4 -4
- package/dist-server/shared/vault-csv.js +32 -10
- package/dist-server/src/lib/composer-attachments.js +5 -6
- package/package.json +1 -1
- package/dist/assets/channel-hUu8lOok.js +0 -1
- package/dist/assets/index-D17LLrYN.css +0 -1
- package/dist/assets/swimlanesDiagram-TC7HE7FX--A9LvTBi.js +0 -8
|
@@ -7,11 +7,10 @@ export const IMAGE_MIMES = {
|
|
|
7
7
|
"image/gif": ".gif",
|
|
8
8
|
"image/webp": ".webp",
|
|
9
9
|
};
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* an attacker-controlled filename never does. */
|
|
10
|
+
/** Document and audio formats with a canonical stored extension. For these
|
|
11
|
+
* the claimed mime determines the extension; the filename never does. Any
|
|
12
|
+
* other type is accepted too (see extensionForFileMime) and is only ever
|
|
13
|
+
* served back as an octet-stream download, never rendered. */
|
|
15
14
|
export const FILE_MIMES = {
|
|
16
15
|
"audio/opus": ".opus",
|
|
17
16
|
"audio/ogg": ".ogg",
|
|
@@ -27,6 +26,7 @@ export const FILE_MIMES = {
|
|
|
27
26
|
"audio/webm": ".webm",
|
|
28
27
|
"text/plain": ".txt",
|
|
29
28
|
"text/markdown": ".md",
|
|
29
|
+
"text/html": ".html",
|
|
30
30
|
"text/csv": ".csv",
|
|
31
31
|
"text/tab-separated-values": ".tsv",
|
|
32
32
|
"application/json": ".json",
|
|
@@ -42,7 +42,21 @@ export const FILE_MIMES = {
|
|
|
42
42
|
"application/vnd.oasis.opendocument.text": ".odt",
|
|
43
43
|
"application/vnd.oasis.opendocument.spreadsheet": ".ods",
|
|
44
44
|
"application/vnd.oasis.opendocument.presentation": ".odp",
|
|
45
|
+
"video/mp4": ".mp4",
|
|
46
|
+
"video/quicktime": ".mov",
|
|
47
|
+
"video/x-m4v": ".m4v",
|
|
45
48
|
};
|
|
49
|
+
/** Stored extension for a file of any other type. */
|
|
50
|
+
export const OTHER_FILE_EXTENSION = ".bin";
|
|
51
|
+
/** Extensions the canonical maps own, plus the ones the file route serves
|
|
52
|
+
* with a real content type. A sender's filename may not claim these for a
|
|
53
|
+
* different mime, so bytes can never be disguised as a known format. */
|
|
54
|
+
const RESERVED_EXTENSIONS = new Set([
|
|
55
|
+
...Object.values(IMAGE_MIMES),
|
|
56
|
+
...Object.values(FILE_MIMES),
|
|
57
|
+
".jpeg",
|
|
58
|
+
OTHER_FILE_EXTENSION,
|
|
59
|
+
]);
|
|
46
60
|
export function extensionForMime(mime) {
|
|
47
61
|
if (!mime)
|
|
48
62
|
return null;
|
|
@@ -52,7 +66,17 @@ export function normalizedMime(mime) {
|
|
|
52
66
|
const value = mime?.split(";")[0]?.trim().toLowerCase();
|
|
53
67
|
return value || null;
|
|
54
68
|
}
|
|
55
|
-
|
|
69
|
+
/** `type/subtype` with only token characters, else null. */
|
|
70
|
+
export function fileMime(mime) {
|
|
56
71
|
const value = normalizedMime(mime);
|
|
57
|
-
return value
|
|
72
|
+
return value && /^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/.test(value) && value.length <= 127 ? value : null;
|
|
73
|
+
}
|
|
74
|
+
/** Canonical extension for a known mime. Any other type keeps the sender's
|
|
75
|
+
* extension when it is short, plain and not reserved, else `.bin`. */
|
|
76
|
+
export function extensionForFileMime(mime, name = "") {
|
|
77
|
+
const known = FILE_MIMES[normalizedMime(mime) ?? ""];
|
|
78
|
+
if (known)
|
|
79
|
+
return known;
|
|
80
|
+
const extension = /\.([a-z0-9]{1,16})$/i.exec(name.trim())?.[0].toLowerCase();
|
|
81
|
+
return extension && !RESERVED_EXTENSIONS.has(extension) ? extension : OTHER_FILE_EXTENSION;
|
|
58
82
|
}
|
|
@@ -6,7 +6,7 @@ import { createReadStream, linkSync, mkdirSync, readFileSync, readdirSync, statS
|
|
|
6
6
|
import { link, open, unlink } from "node:fs/promises";
|
|
7
7
|
import { join, extname } from "node:path";
|
|
8
8
|
import { DATA_DIR } from "./config.js";
|
|
9
|
-
import { FILE_MIMES, IMAGE_MIMES, extensionForFileMime, extensionForMime,
|
|
9
|
+
import { FILE_MIMES, IMAGE_MIMES, OTHER_FILE_EXTENSION, extensionForFileMime, extensionForMime, fileMime } from "./attachment-mimes.js";
|
|
10
10
|
export { extensionForFileMime, extensionForMime };
|
|
11
11
|
export const ATTACHMENTS_DIR = join(DATA_DIR, "attachments");
|
|
12
12
|
/** The spec's ceiling: a screenshot bigger than this is rejected before it
|
|
@@ -255,12 +255,13 @@ async function withUploadLock(uploadId, operation) {
|
|
|
255
255
|
uploadLocks.delete(uploadId);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
|
-
/**
|
|
259
|
-
* fixed extensions
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
|
|
258
|
+
/** Committed attachment names are `${uuid}${extension}`, mostly for one of
|
|
259
|
+
* these fixed extensions, so whether a given upload ID is already committed,
|
|
260
|
+
* and under which content type, can be answered with a handful of direct
|
|
261
|
+
* stats instead of a scan over every file in the directory.
|
|
262
|
+
* ponytail: a file of another type keeps its own extension, so reusing one
|
|
263
|
+
* upload ID across two such extensions is not caught; a prefix scan would. */
|
|
264
|
+
const KNOWN_ATTACHMENT_EXTENSIONS = Array.from(new Set([...Object.values(IMAGE_MIMES), ...Object.values(FILE_MIMES), OTHER_FILE_EXTENSION]));
|
|
264
265
|
/** Missing or unreadable candidates count as absent here; the atomic link
|
|
265
266
|
* still detects a collision if a file exists when an upload commits. */
|
|
266
267
|
function statSizeIfFile(path) {
|
|
@@ -297,14 +298,12 @@ async function digestFile(path) {
|
|
|
297
298
|
function statusError(status, message) {
|
|
298
299
|
return Object.assign(new Error(message), { status });
|
|
299
300
|
}
|
|
300
|
-
/** Strip platform-reserved characters
|
|
301
|
-
* extension with
|
|
302
|
-
*
|
|
303
|
-
* remain visible as bad requests. */
|
|
301
|
+
/** Strip platform-reserved characters. A known mime replaces any
|
|
302
|
+
* sender-provided extension with its canonical one; any other type keeps the
|
|
303
|
+
* sender's name as written. Separators and encoded separators are rejected
|
|
304
|
+
* rather than massaged so traversal attempts remain visible as bad requests. */
|
|
304
305
|
export function sanitizeSharedFileName(name, mime) {
|
|
305
|
-
const extension =
|
|
306
|
-
if (!extension)
|
|
307
|
-
throw statusError(400, "content-type must be a supported document or audio type");
|
|
306
|
+
const extension = FILE_MIMES[fileMime(mime) ?? ""] ?? "";
|
|
308
307
|
const normalized = name.normalize("NFKC").trim();
|
|
309
308
|
if (!normalized)
|
|
310
309
|
throw statusError(400, "name is required");
|
|
@@ -314,7 +313,7 @@ export function sanitizeSharedFileName(name, mime) {
|
|
|
314
313
|
throw statusError(400, "name must be a filename, not a path");
|
|
315
314
|
}
|
|
316
315
|
const dot = normalized.lastIndexOf(".");
|
|
317
|
-
const withoutExtension = dot > 0 ? normalized.slice(0, dot) : normalized;
|
|
316
|
+
const withoutExtension = extension && dot > 0 ? normalized.slice(0, dot) : normalized;
|
|
318
317
|
const safeCharacters = Array.from(withoutExtension, (character) => {
|
|
319
318
|
const code = character.charCodeAt(0);
|
|
320
319
|
return code <= 31 || code === 127 || "<>:\"|?*".includes(character) ? "_" : character;
|
|
@@ -333,12 +332,9 @@ export function sanitizeSharedFileName(name, mime) {
|
|
|
333
332
|
* the request in memory. A failed, empty, or oversized upload leaves no
|
|
334
333
|
* partial file behind. */
|
|
335
334
|
export async function saveFile(chunks, originalName, mime, options = {}) {
|
|
336
|
-
const normalized =
|
|
337
|
-
if (!normalized || !extensionForFileMime(normalized)) {
|
|
338
|
-
throw statusError(400, "content-type must be a supported document or audio type");
|
|
339
|
-
}
|
|
335
|
+
const normalized = fileMime(mime) ?? "application/octet-stream";
|
|
340
336
|
const name = sanitizeSharedFileName(originalName, normalized);
|
|
341
|
-
const extension = extensionForFileMime(normalized);
|
|
337
|
+
const extension = extensionForFileMime(normalized, name);
|
|
342
338
|
const uploadId = validateAttachmentUploadId(options.uploadId);
|
|
343
339
|
const expectedBytes = options.expectedBytes;
|
|
344
340
|
if (expectedBytes !== undefined && (!Number.isSafeInteger(expectedBytes) || expectedBytes < 0)) {
|
|
@@ -54,6 +54,8 @@ import { isModelRejection } from "../retry.js";
|
|
|
54
54
|
import { engineFailureFromCode, isCredentialDead, isOpaqueRequestRejection, logAuthFailure, parseResetAt, resetHintFromData } from "../../engine-failure.js";
|
|
55
55
|
import { turnMcpServers } from "../turn-mcp.js";
|
|
56
56
|
import { volatileNote, volatileSectionsOf, withNote } from "../volatile-notes.js";
|
|
57
|
+
import { sanitizeAcpToolMessage } from "./tool-log.js";
|
|
58
|
+
import { armModeReadback, forgetStaleModeReport, noteModeReport, noteModeUpdate } from "./mode-readback.js";
|
|
57
59
|
/** ACP vendors put the actionable cause in error.data while keeping the
|
|
58
60
|
* JSON-RPC message generic. Only surface known text fields, never a response
|
|
59
61
|
* body/config dump, and redact before bounding the displayed diagnostic. */
|
|
@@ -171,7 +173,6 @@ function acpVariantOption(result) {
|
|
|
171
173
|
...(typeof option.currentValue === "string" ? { currentValue: option.currentValue } : {}),
|
|
172
174
|
};
|
|
173
175
|
}
|
|
174
|
-
const TOOL_LOG_TEXT_LIMIT = 64_000;
|
|
175
176
|
async function readAcpImageBlocks(images) {
|
|
176
177
|
return Promise.all(images.map(async (image) => ({
|
|
177
178
|
type: "image",
|
|
@@ -179,42 +180,6 @@ async function readAcpImageBlocks(images) {
|
|
|
179
180
|
mimeType: image.mime,
|
|
180
181
|
})));
|
|
181
182
|
}
|
|
182
|
-
function sanitizeToolLogValue(value, budget, depth = 0) {
|
|
183
|
-
if (depth > 12 || budget.nodes-- <= 0)
|
|
184
|
-
return undefined;
|
|
185
|
-
if (typeof value === "string") {
|
|
186
|
-
if (/^data:image\//iu.test(value) || budget.text <= 0)
|
|
187
|
-
return undefined;
|
|
188
|
-
const limit = Math.min(TOOL_LOG_TEXT_LIMIT, budget.text);
|
|
189
|
-
const text = value.length <= limit ? value : `[Earlier output truncated]\n\n${value.slice(-limit)}`;
|
|
190
|
-
budget.text -= text.length;
|
|
191
|
-
return text;
|
|
192
|
-
}
|
|
193
|
-
if (Array.isArray(value)) {
|
|
194
|
-
return value.flatMap((entry) => {
|
|
195
|
-
const sanitized = sanitizeToolLogValue(entry, budget, depth + 1);
|
|
196
|
-
return sanitized === undefined ? [] : [sanitized];
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
if (!value || typeof value !== "object")
|
|
200
|
-
return value;
|
|
201
|
-
const record = value;
|
|
202
|
-
return Object.fromEntries(Object.entries(record).flatMap(([key, entry]) => {
|
|
203
|
-
if ((record.type === "image" && (key === "data" || key === "blob")) ||
|
|
204
|
-
(key === "blob" && typeof record.mimeType === "string" && record.mimeType.startsWith("image/")))
|
|
205
|
-
return [];
|
|
206
|
-
const sanitized = sanitizeToolLogValue(entry, budget, depth + 1);
|
|
207
|
-
return sanitized === undefined ? [] : [[key, sanitized]];
|
|
208
|
-
}));
|
|
209
|
-
}
|
|
210
|
-
function sanitizeAcpToolMessage(message) {
|
|
211
|
-
const isToolUpdate = message?.method === "session/update"
|
|
212
|
-
&& ["tool_call", "tool_call_update"].includes(message?.params?.update?.sessionUpdate);
|
|
213
|
-
const isPermission = message?.method === "session/request_permission";
|
|
214
|
-
if (!isToolUpdate && !isPermission)
|
|
215
|
-
return message;
|
|
216
|
-
return sanitizeToolLogValue(message, { nodes: 512, text: TOOL_LOG_TEXT_LIMIT });
|
|
217
|
-
}
|
|
218
183
|
function decodeAcpConfig(defaultCli) {
|
|
219
184
|
return (raw) => {
|
|
220
185
|
const o = (raw ?? {});
|
|
@@ -796,6 +761,8 @@ export function createAcpDriver(support) {
|
|
|
796
761
|
current.receiveModelVariants(p.update);
|
|
797
762
|
return;
|
|
798
763
|
}
|
|
764
|
+
if (noteModeUpdate(session, p))
|
|
765
|
+
return;
|
|
799
766
|
if (!current || !current.state.promptSent)
|
|
800
767
|
return;
|
|
801
768
|
const u = p.update ?? {};
|
|
@@ -1264,6 +1231,7 @@ export function createAcpDriver(support) {
|
|
|
1264
1231
|
loaded = true;
|
|
1265
1232
|
session.sessionId = cursor;
|
|
1266
1233
|
session.sessionKey = sessionKey;
|
|
1234
|
+
noteModeReport(session, result);
|
|
1267
1235
|
receiveModelVariants(result);
|
|
1268
1236
|
}
|
|
1269
1237
|
});
|
|
@@ -1319,6 +1287,7 @@ export function createAcpDriver(support) {
|
|
|
1319
1287
|
sessionResult = await request("session/new", { cwd, mcpServers: sessionServers }, NEW_SESSION_TIMEOUT, (result) => {
|
|
1320
1288
|
session.sessionId = typeof result?.sessionId === "string" ? result.sessionId : null;
|
|
1321
1289
|
session.sessionKey = sessionKey;
|
|
1290
|
+
noteModeReport(session, result);
|
|
1322
1291
|
receiveModelVariants(result);
|
|
1323
1292
|
});
|
|
1324
1293
|
break;
|
|
@@ -1356,6 +1325,7 @@ export function createAcpDriver(support) {
|
|
|
1356
1325
|
}
|
|
1357
1326
|
}
|
|
1358
1327
|
if (support.configureSession) {
|
|
1328
|
+
forgetStaleModeReport(session, support);
|
|
1359
1329
|
const sessionModels = Array.isArray(sessionResult?.models?.availableModels) ? sessionResult.models.availableModels : [];
|
|
1360
1330
|
const configure = (model) => support.configureSession({
|
|
1361
1331
|
request: (method, params, timeoutMs) => request(method, params, timeoutMs ?? SESSION_CONFIG_TIMEOUT),
|
|
@@ -1436,6 +1406,9 @@ export function createAcpDriver(support) {
|
|
|
1436
1406
|
if (turn.variant !== undefined && requestedVariantOption().currentValue !== turn.variant) {
|
|
1437
1407
|
throw new Error(`${support.displayName} changed variant before the prompt`);
|
|
1438
1408
|
}
|
|
1409
|
+
armModeReadback({ support, session, config: turnConfig, turn: cliTurn, isCurrent: () => session.current === current && !current.state.settled,
|
|
1410
|
+
log: (readback) => appendNative(threadId, { dir: "out", source: SOURCE, msg: { approvalReadback: readback } }),
|
|
1411
|
+
stop: (message) => { emit({ ...base(threadId, turnId), type: "runtime.error", message }); interrupt(); } });
|
|
1439
1412
|
state.promptSent = true;
|
|
1440
1413
|
const promptIdleMs = promptIdleTimeoutMs(support, cliTurn.model);
|
|
1441
1414
|
const result = await request("session/prompt", { sessionId, prompt: [{ type: "text", text }, ...imageBlocks] }, undefined, undefined, promptIdleMs, `${DRIVER_KIND} went fully silent ${Math.round(promptIdleMs / 1000)} s after the message and the turn was stopped. ` +
|
|
@@ -177,6 +177,7 @@ const MODELS = {
|
|
|
177
177
|
};
|
|
178
178
|
const support = {
|
|
179
179
|
driverKind: "droidAgent",
|
|
180
|
+
approvalModeReadback: { ladder: "droidAgent", expected: (config) => (config.fullAuto ? MODE_FULL_AUTO : MODE_DEFAULT), setsModeOverWire: true },
|
|
180
181
|
displayName: "Droid",
|
|
181
182
|
models: MODELS,
|
|
182
183
|
defaultCli: "droid",
|
|
@@ -74,8 +74,18 @@ export function geminiApprovalArgs(fullAuto, approvalMode) {
|
|
|
74
74
|
return ["--approval-mode", "auto_edit"];
|
|
75
75
|
return [];
|
|
76
76
|
}
|
|
77
|
+
/** The ACP session mode geminiApprovalArgs should leave Gemini in. */
|
|
78
|
+
export function geminiExpectedMode(fullAuto, approvalMode) {
|
|
79
|
+
if (fullAuto)
|
|
80
|
+
return "yolo";
|
|
81
|
+
if (approvalMode === "edits")
|
|
82
|
+
return "autoEdit";
|
|
83
|
+
return "default";
|
|
84
|
+
}
|
|
77
85
|
const support = {
|
|
78
86
|
driverKind: "geminiAgent",
|
|
87
|
+
// Gemini takes the mode on argv; session/new reports the one it applied.
|
|
88
|
+
approvalModeReadback: { ladder: "geminiAgent", expected: (config, turn) => geminiExpectedMode(config.fullAuto, turn.approvalMode) },
|
|
79
89
|
displayName: "Gemini",
|
|
80
90
|
models: {
|
|
81
91
|
default: "gemini-2.5-pro",
|
|
@@ -507,6 +507,7 @@ function readKimiModelCatalog(env) {
|
|
|
507
507
|
}
|
|
508
508
|
const support = {
|
|
509
509
|
driverKind: "kimiAgent",
|
|
510
|
+
approvalModeReadback: { ladder: "kimiAgent", expected: (config) => kimiSessionMode(config.fullAuto), setsModeOverWire: true },
|
|
510
511
|
displayName: "Kimi",
|
|
511
512
|
// Aliases from the CLI's own catalog (~/.kimi-code/config.toml
|
|
512
513
|
// [models."kimi-code/…"] — `kimi provider list` reports the same four).
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// ACP engines: read back the approval mode the agent actually applied
|
|
2
|
+
// (shared/approval-readback.ts has the comparison and the wording).
|
|
3
|
+
//
|
|
4
|
+
// The agent reports its mode in session/new or session/load
|
|
5
|
+
// (`modes.currentModeId`) and in `current_mode_update` notifications. A turn
|
|
6
|
+
// whose agent reports a LOOSER mode than requested is stopped before the
|
|
7
|
+
// prompt is sent, or interrupted if the report arrives mid-turn. An agent
|
|
8
|
+
// that does not report is logged as unverified: Atomic's permission broker
|
|
9
|
+
// still sees every request it does send.
|
|
10
|
+
import { compareEffectiveMode, looserModeMessage } from "../../../shared/approval-readback.js";
|
|
11
|
+
const states = new WeakMap();
|
|
12
|
+
const stateOf = (session) => {
|
|
13
|
+
let state = states.get(session);
|
|
14
|
+
if (!state)
|
|
15
|
+
states.set(session, (state = { reported: null }));
|
|
16
|
+
return state;
|
|
17
|
+
};
|
|
18
|
+
/** The mode the agent last reported on this native session, if any. */
|
|
19
|
+
export function reportedMode(session) {
|
|
20
|
+
return states.get(session)?.reported ?? null;
|
|
21
|
+
}
|
|
22
|
+
/** session/new or session/load answered: keep `modes.currentModeId`. */
|
|
23
|
+
export function noteModeReport(session, result) {
|
|
24
|
+
const id = result?.modes?.currentModeId;
|
|
25
|
+
if (typeof id === "string" && id)
|
|
26
|
+
stateOf(session).reported = id;
|
|
27
|
+
}
|
|
28
|
+
/** A session/update params object. True when it was a current_mode_update
|
|
29
|
+
* (recorded, and re-checked against a running turn). */
|
|
30
|
+
export function noteModeUpdate(session, raw) {
|
|
31
|
+
const params = raw;
|
|
32
|
+
if (params?.update?.sessionUpdate !== "current_mode_update")
|
|
33
|
+
return false;
|
|
34
|
+
if (session.sessionId && params.sessionId === session.sessionId && typeof params.update.currentModeId === "string") {
|
|
35
|
+
const state = stateOf(session);
|
|
36
|
+
state.reported = params.update.currentModeId;
|
|
37
|
+
state.onReported?.();
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
/** Before configureSession sends session/set_mode, an earlier report is stale. */
|
|
42
|
+
export function forgetStaleModeReport(session, support) {
|
|
43
|
+
if (support.approvalModeReadback?.setsModeOverWire)
|
|
44
|
+
stateOf(session).reported = null;
|
|
45
|
+
}
|
|
46
|
+
/** Compare what this turn asked for with what the agent reported. */
|
|
47
|
+
export function approvalReadbackFor(support, config, turn, reported) {
|
|
48
|
+
const rules = support.approvalModeReadback;
|
|
49
|
+
if (!rules)
|
|
50
|
+
return { status: "unverified", requested: null, reported };
|
|
51
|
+
return compareEffectiveMode(rules.ladder, rules.expected(config, turn), reported);
|
|
52
|
+
}
|
|
53
|
+
/** Called right before session/prompt. Throws (the turn fails) when the agent
|
|
54
|
+
* already reported a looser mode; logs an unverified one; and watches for a
|
|
55
|
+
* later looser report while the turn runs. */
|
|
56
|
+
export function armModeReadback(input) {
|
|
57
|
+
const { support, session, config, turn } = input;
|
|
58
|
+
const state = stateOf(session);
|
|
59
|
+
const now = approvalReadbackFor(support, config, turn, state.reported);
|
|
60
|
+
if (now.status === "looser")
|
|
61
|
+
throw new Error(looserModeMessage(support.displayName, now));
|
|
62
|
+
if (now.status === "unverified")
|
|
63
|
+
input.log(now);
|
|
64
|
+
state.onReported = () => {
|
|
65
|
+
if (!input.isCurrent())
|
|
66
|
+
return;
|
|
67
|
+
const later = approvalReadbackFor(support, config, turn, state.reported);
|
|
68
|
+
input.log(later);
|
|
69
|
+
if (later.status === "looser")
|
|
70
|
+
input.stop(looserModeMessage(support.displayName, later));
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -220,8 +220,20 @@ export function qwenApprovalArgs(fullAuto, approvalMode) {
|
|
|
220
220
|
return ["--approval-mode", "auto-edit"];
|
|
221
221
|
return [];
|
|
222
222
|
}
|
|
223
|
+
/** The ACP session mode qwenApprovalArgs should leave Qwen in. */
|
|
224
|
+
export function qwenExpectedMode(fullAuto, approvalMode) {
|
|
225
|
+
if (fullAuto)
|
|
226
|
+
return "yolo";
|
|
227
|
+
if (approvalMode === "auto")
|
|
228
|
+
return "auto";
|
|
229
|
+
if (approvalMode === "edits")
|
|
230
|
+
return "auto-edit";
|
|
231
|
+
return "default";
|
|
232
|
+
}
|
|
223
233
|
const support = {
|
|
224
234
|
driverKind: "qwenAgent",
|
|
235
|
+
// Qwen takes the mode on argv; session/new reports the one it applied.
|
|
236
|
+
approvalModeReadback: { ladder: "qwenAgent", expected: (config, turn) => qwenExpectedMode(config.fullAuto, turn.approvalMode) },
|
|
225
237
|
displayName: "Qwen",
|
|
226
238
|
access: "custom",
|
|
227
239
|
models: EMPTY,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Native-log copies of ACP tool traffic, kept small: image bytes are dropped
|
|
2
|
+
// and long text is cut to its tail. Moved out of core.ts unchanged.
|
|
3
|
+
const TOOL_LOG_TEXT_LIMIT = 64_000;
|
|
4
|
+
function sanitizeToolLogValue(value, budget, depth = 0) {
|
|
5
|
+
if (depth > 12 || budget.nodes-- <= 0)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (typeof value === "string") {
|
|
8
|
+
if (/^data:image\//iu.test(value) || budget.text <= 0)
|
|
9
|
+
return undefined;
|
|
10
|
+
const limit = Math.min(TOOL_LOG_TEXT_LIMIT, budget.text);
|
|
11
|
+
const text = value.length <= limit ? value : `[Earlier output truncated]\n\n${value.slice(-limit)}`;
|
|
12
|
+
budget.text -= text.length;
|
|
13
|
+
return text;
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return value.flatMap((entry) => {
|
|
17
|
+
const sanitized = sanitizeToolLogValue(entry, budget, depth + 1);
|
|
18
|
+
return sanitized === undefined ? [] : [sanitized];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (!value || typeof value !== "object")
|
|
22
|
+
return value;
|
|
23
|
+
const record = value;
|
|
24
|
+
return Object.fromEntries(Object.entries(record).flatMap(([key, entry]) => {
|
|
25
|
+
if ((record.type === "image" && (key === "data" || key === "blob")) ||
|
|
26
|
+
(key === "blob" && typeof record.mimeType === "string" && record.mimeType.startsWith("image/")))
|
|
27
|
+
return [];
|
|
28
|
+
const sanitized = sanitizeToolLogValue(entry, budget, depth + 1);
|
|
29
|
+
return sanitized === undefined ? [] : [[key, sanitized]];
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
export function sanitizeAcpToolMessage(message) {
|
|
33
|
+
const m = message;
|
|
34
|
+
const isToolUpdate = m?.method === "session/update"
|
|
35
|
+
&& ["tool_call", "tool_call_update"].includes(m?.params?.update?.sessionUpdate);
|
|
36
|
+
const isPermission = m?.method === "session/request_permission";
|
|
37
|
+
if (!isToolUpdate && !isPermission)
|
|
38
|
+
return message;
|
|
39
|
+
return sanitizeToolLogValue(message, { nodes: 512, text: TOOL_LOG_TEXT_LIMIT });
|
|
40
|
+
}
|
|
@@ -2,6 +2,7 @@ import { PROVIDER_CREDENTIAL_ENV, stripControlPlaneEnv, WORKSPACE_CREDENTIAL_ENV
|
|
|
2
2
|
import { augmentedPath } from "../../env-path.js";
|
|
3
3
|
import { VibeLoginController, vibeSignedIn } from "../vibe-login.js";
|
|
4
4
|
import { createAcpDriver } from "./core.js";
|
|
5
|
+
import { assertEffectiveModeNotLooser } from "../../../shared/approval-readback.js";
|
|
5
6
|
export const VIBE_DRIVER_KIND = "vibeAgent";
|
|
6
7
|
/** Vibe's own model aliases (vibe/core/config/vibe_schema.py, 3.x): Medium
|
|
7
8
|
* 3.5 is its default, a 256K-context model Mistral tunes for coding. */
|
|
@@ -14,6 +15,14 @@ const MODELS = {
|
|
|
14
15
|
* tool call and asks only for risky ones), Edits is `accept-edits`, and every
|
|
15
16
|
* other level is `ask`, so a session Vibe saved in a looser mode never
|
|
16
17
|
* carries into an Ask turn. */
|
|
18
|
+
/** The "mode" option's current value in a set_config_option reply, if any. */
|
|
19
|
+
export function vibeReportedMode(reply) {
|
|
20
|
+
const options = reply?.configOptions;
|
|
21
|
+
if (!Array.isArray(options))
|
|
22
|
+
return null;
|
|
23
|
+
const mode = options.find((option) => option && typeof option === "object" && option.id === "mode");
|
|
24
|
+
return typeof mode?.currentValue === "string" ? mode.currentValue : null;
|
|
25
|
+
}
|
|
17
26
|
export function vibeSessionMode(fullAuto, approvalMode) {
|
|
18
27
|
if (fullAuto)
|
|
19
28
|
return "auto-approve";
|
|
@@ -63,12 +72,16 @@ const support = {
|
|
|
63
72
|
isAuthenticated: (env, config, instanceId) => cachedSignedIn(`${instanceId}:${env.VIBE_HOME ?? ""}`, () => vibeSignedIn(config.cli || "vibe-acp", env)),
|
|
64
73
|
async configureSession({ request, sessionId, config, turn }) {
|
|
65
74
|
const value = vibeSessionMode(config.fullAuto, turn.approvalMode);
|
|
75
|
+
let reply;
|
|
66
76
|
try {
|
|
67
|
-
await request("session/set_config_option", { sessionId, configId: "mode", value });
|
|
77
|
+
reply = await request("session/set_config_option", { sessionId, configId: "mode", value });
|
|
68
78
|
}
|
|
69
79
|
catch (e) {
|
|
70
80
|
throw new Error(`Mistral Vibe rejected permission mode "${value}": ${e.message}. Update Mistral Vibe (3.0 or newer).`);
|
|
71
81
|
}
|
|
82
|
+
// The reply carries the config options as applied: the mode must not
|
|
83
|
+
// come back looser than asked (shared/approval-readback.ts).
|
|
84
|
+
assertEffectiveModeNotLooser("Mistral Vibe", "vibeAgent", value, vibeReportedMode(reply));
|
|
72
85
|
},
|
|
73
86
|
buildPromptText: (turn) => (turn.system ? `${turn.system}\n\n${turn.text}` : turn.text),
|
|
74
87
|
};
|
|
@@ -23,7 +23,7 @@ export function catalogProfileFromEnv(env) {
|
|
|
23
23
|
skillAuthoring: env.OMB_SKILL_AUTHORING_ENABLED === "1",
|
|
24
24
|
sharedComputers: env.OMB_SHARED_COMPUTERS_ENABLED === "1",
|
|
25
25
|
threatScan: env.OMB_THREAT_SCAN_ENABLED === "1",
|
|
26
|
-
botId: env.OMB_BOT_ID ?? "", privateBot: env.OMB_PRIVATE_BOT === "1",
|
|
26
|
+
botId: env.OMB_BOT_ID ?? "", privateBot: env.OMB_PRIVATE_BOT === "1", freeModel: env.OMB_FREE_MODEL === "1",
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
export const WEEKDAYS = [
|
|
@@ -752,7 +752,7 @@ function adminToolEntry(deferred) {
|
|
|
752
752
|
/** Every tool a profile may call, admin tools written out in full. */
|
|
753
753
|
function profileTools(profile) {
|
|
754
754
|
const ALL_TOOLS = toolDefinitions(profile.externalRuntime);
|
|
755
|
-
const TOOLS =
|
|
755
|
+
const TOOLS = ALL_TOOLS.filter((tool) => (profile.threatScan || tool.name !== "threat_scan") && !(profile.freeModel && tool.name.startsWith("nexus_")));
|
|
756
756
|
const AUTHORING_TOOLS = profile.skillAuthoring
|
|
757
757
|
? TOOLS
|
|
758
758
|
: TOOLS.filter((tool) => !SKILL_TOOL_NAMES.has(tool.name));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Per-turn MCP transport for the shared Chat Completions runtime. Approval is
|
|
2
2
|
// owned by the caller; only registered, schema-validated calls reach this file.
|
|
3
|
+
import { homedir } from "node:os";
|
|
3
4
|
import { Ajv } from "ajv";
|
|
4
5
|
import { Ajv2020 } from "ajv/dist/2020.js";
|
|
5
6
|
import formats from "ajv-formats";
|
|
@@ -274,7 +275,23 @@ function boundedText(value) {
|
|
|
274
275
|
* that will not start, advertises tools this runtime cannot use, or breaks
|
|
275
276
|
* during a call is dropped for the rest of the turn, the model is told, and
|
|
276
277
|
* the harness hears (`report`). Atomic's own servers stay all-or-nothing. */
|
|
277
|
-
|
|
278
|
+
/** Whether any string in a tool call's arguments names a path inside one of
|
|
279
|
+
* `roots`: absolute, `~/`, or home-relative, with either slash. Substring
|
|
280
|
+
* matching on purpose, so a path inside a shell command counts too. */
|
|
281
|
+
export function namesBlockedPath(args, roots, home = homedir()) {
|
|
282
|
+
const slash = (text) => text.replaceAll("\\", "/").toLowerCase();
|
|
283
|
+
const needles = roots.flatMap((root) => {
|
|
284
|
+
const full = slash(root).replace(/\/+$/, "");
|
|
285
|
+
const base = slash(home).replace(/\/+$/, "");
|
|
286
|
+
return full.startsWith(`${base}/`) ? [full, `~/${full.slice(base.length + 1)}`, full.slice(base.length + 1)] : [full];
|
|
287
|
+
});
|
|
288
|
+
const visit = (value) => typeof value === "string"
|
|
289
|
+
? needles.some((needle) => slash(value).includes(needle))
|
|
290
|
+
: Array.isArray(value) ? value.some(visit)
|
|
291
|
+
: object(value) ? Object.values(value).some(visit) : false;
|
|
292
|
+
return needles.length > 0 && visit(args);
|
|
293
|
+
}
|
|
294
|
+
export async function mountChatTools(integrations, signal, computerUse = false, report = reportMcpFailure, blockedPaths = []) {
|
|
278
295
|
const servers = [];
|
|
279
296
|
if (computerUse && integrations?.computer)
|
|
280
297
|
servers.push(["computer", integrations.computer]);
|
|
@@ -421,6 +438,9 @@ export async function mountChatTools(integrations, signal, computerUse = false,
|
|
|
421
438
|
throw new Error(`The "${tool.server}" tools stopped working earlier in this turn and are unavailable now; carry on without them.`);
|
|
422
439
|
if (!object(args) || !tool.schema(args))
|
|
423
440
|
throw new Error("Tool arguments do not match the advertised input schema; use its required fields and types");
|
|
441
|
+
if (namesBlockedPath(args, blockedPaths)) {
|
|
442
|
+
throw new Error("This turn runs on a free model, so the PAW and ICM folders are off limits. Work only from the message itself.");
|
|
443
|
+
}
|
|
424
444
|
};
|
|
425
445
|
return {
|
|
426
446
|
definitions, validate, close,
|
|
@@ -298,7 +298,7 @@ export function createOpenAIChatRuntime(options) {
|
|
|
298
298
|
const denials = [];
|
|
299
299
|
const seenCalls = new Set();
|
|
300
300
|
try {
|
|
301
|
-
tools = await mountChatTools(options.tools === false ? undefined : turn.integrations, abort.signal, options.computerUse);
|
|
301
|
+
tools = await mountChatTools(options.tools === false ? undefined : turn.integrations, abort.signal, options.computerUse, undefined, turn.blockedPaths);
|
|
302
302
|
for (let round = 0; round < 16; round++) {
|
|
303
303
|
abort.signal.throwIfAborted();
|
|
304
304
|
native("out", options.nativeLog.outgoing(turn, messages, model));
|
|
@@ -463,7 +463,7 @@ export function engineLabel(candidates, selection) {
|
|
|
463
463
|
const candidate = candidates.find((entry) => entry.instanceId === selection.instanceId);
|
|
464
464
|
const name = candidate?.displayName ?? selection.instanceId;
|
|
465
465
|
const model = candidate?.models.options.find((option) => option.id === selection.model)?.label ?? selection.model;
|
|
466
|
-
return model && model !== name ? `${name} · ${model}` : name
|
|
466
|
+
return `${model && model !== name ? `${name} · ${model}` : name}${candidate && freeCandidate(candidate) ? " · free" : ""}`;
|
|
467
467
|
}
|
|
468
468
|
/** The account an engine is signed in to, as resting keys it. */
|
|
469
469
|
export const engineAccount = (candidate) => candidate.snapshot.account?.email ?? candidate.snapshot.account?.organization;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// A turn on a free-tier engine never sees Nexus or PAW (docs/specs/free-models-in-auto).
|
|
2
|
+
// Free providers may keep and train on what they are sent, so such a turn gets
|
|
3
|
+
// no Nexus tools, no PAW, ICM, Nexus or About-the-user context, and no tool
|
|
4
|
+
// call that names the PAW or ICM folders.
|
|
5
|
+
import { accountProvider } from "../shared/provider-accounts.js";
|
|
6
|
+
import { isChibitekNexus } from "./company-mcp-tenancy.js";
|
|
7
|
+
/** Threads whose current turn runs on a free-tier engine. */
|
|
8
|
+
const freeTurnThreads = new Set();
|
|
9
|
+
/** Marks the thread's turn free or paid and, when free, strips the Nexus MCP
|
|
10
|
+
* server and the nexus_recall / nexus_file tools from its integrations.
|
|
11
|
+
* Returns the folders its tool calls may not name, or undefined on a paid turn. */
|
|
12
|
+
export function guardFreeTurn(threadId, account, integrations, roots) {
|
|
13
|
+
if (accountProvider(account)?.billing !== "free") {
|
|
14
|
+
freeTurnThreads.delete(threadId);
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
freeTurnThreads.add(threadId);
|
|
18
|
+
if (integrations.custom) {
|
|
19
|
+
integrations.custom = Object.fromEntries(Object.entries(integrations.custom).filter(([, server]) => !isChibitekNexus(server)));
|
|
20
|
+
if (!Object.keys(integrations.custom).length)
|
|
21
|
+
delete integrations.custom;
|
|
22
|
+
}
|
|
23
|
+
if (integrations.agents)
|
|
24
|
+
integrations.agents.env = { ...integrations.agents.env, OMB_FREE_MODEL: "1" };
|
|
25
|
+
return roots.filter(Boolean);
|
|
26
|
+
}
|
|
27
|
+
/** Why the Nexus endpoint refuses this thread's turn, if it does. */
|
|
28
|
+
export function freeTurnNexusRefusal(threadId) {
|
|
29
|
+
return freeTurnThreads.has(threadId)
|
|
30
|
+
? "This turn runs on a free model, so Nexus is off limits: free providers may keep and train on what they are sent."
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
@@ -173,7 +173,7 @@ export function uploadIdFor(key) {
|
|
|
173
173
|
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-5${hex.slice(13, 16)}-${variant}${hex.slice(17, 20)}-${hex.slice(20, 32)}`;
|
|
174
174
|
}
|
|
175
175
|
/** The extension Atomic's store gives this file, for the already-saved check. */
|
|
176
|
-
export const storedExtension = (file) => file.mime ? (file.image ? extensionForMime(file.mime) : extensionForFileMime(file.mime)) : null;
|
|
176
|
+
export const storedExtension = (file) => file.mime ? (file.image ? extensionForMime(file.mime) : extensionForFileMime(file.mime, file.name)) : null;
|
|
177
177
|
export function formatBytes(bytes) {
|
|
178
178
|
if (bytes < 1024)
|
|
179
179
|
return `${bytes} B`;
|
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
// The policy here is pure so it can be read and tested on its own; the
|
|
12
12
|
// harness (server/index.ts) supplies the store and starts the turns.
|
|
13
13
|
import { canAccessTeam, peerAllowed, reachesEveryTeam } from "./peer-roster.js";
|
|
14
|
+
/** A fallback, or a turn that ran on without a broken tool server: the run
|
|
15
|
+
* went on, nothing needs a retry. */
|
|
16
|
+
export const runWentOn = (kind) => kind === "model-fallback" || kind === "engine-fallback" || kind === "free-fallback" || kind === "mcp-unavailable";
|
|
14
17
|
export const INCIDENTS_THREAD_TITLE = "Team incidents";
|
|
15
18
|
const sectionKey = (section) => section?.trim() || "";
|
|
16
19
|
/** The Chief responsible for a bot: the Chief of the bot's own section, else
|
|
@@ -78,6 +81,8 @@ function whatHappened(incident) {
|
|
|
78
81
|
return `${incident.bot.name}'s run ${where} continued on another model because its engine refused the one it was set to${detail}`;
|
|
79
82
|
case "engine-fallback":
|
|
80
83
|
return `${incident.bot.name}'s run ${where} continued on another engine after its selected engine failed${detail}`;
|
|
84
|
+
case "free-fallback":
|
|
85
|
+
return `${incident.bot.name}'s run ${where} ran on a free model because no subscription or pay-per-use engine could take it${detail}`;
|
|
81
86
|
case "mcp-unavailable":
|
|
82
87
|
return `${incident.bot.name}'s run ${where} continued without one of its tool servers${detail}`;
|
|
83
88
|
default:
|
|
@@ -101,7 +106,7 @@ export function incidentText(incident, count) {
|
|
|
101
106
|
lines.push(`${incident.bot.name} last said: "${fold(incident.lastReply, 300)}"`);
|
|
102
107
|
if (count.count > 1)
|
|
103
108
|
lines.push(`This is the ${ordinal(count.count)} incident on that thread within the hour.`);
|
|
104
|
-
if (incident.kind
|
|
109
|
+
if (runWentOn(incident.kind)) {
|
|
105
110
|
// Nothing broke: the turn ran. The failed selection, engine or tool
|
|
106
111
|
// server still needs attention, but the completed work must never be retried.
|
|
107
112
|
lines.push("The run was not interrupted and needs no retry; do not call retry_thread.");
|
|
@@ -109,7 +114,9 @@ export function incidentText(incident, count) {
|
|
|
109
114
|
? "Tell the person in one or two plain sentences that this engine no longer offers that model and that the bot's or the conversation's model setting should be changed, then stop."
|
|
110
115
|
: incident.kind === "mcp-unavailable"
|
|
111
116
|
? "Tell the person in one or two plain sentences which tool server is not working, that bots carry on without it until it answers again, and that its command and settings in Settings may need a look, then stop."
|
|
112
|
-
:
|
|
117
|
+
: incident.kind === "free-fallback"
|
|
118
|
+
? "Tell the person in one or two plain sentences that the turn ran on a free model, which engines were out, and that a subscription or key needs attention to stop relying on the free band, then stop."
|
|
119
|
+
: "Use the incident detail to correct the failed engine if action is needed, then report what happened in one or two plain sentences and stop.");
|
|
113
120
|
return lines.join("\n");
|
|
114
121
|
}
|
|
115
122
|
lines.push(count.mayRetry
|