@armadra/agent 0.17.3 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/CHANGELOG.zh-CN.md +50 -0
- package/README.md +4 -0
- package/README.zh-CN.md +4 -0
- package/THIRD_PARTY_NOTICES.md +6 -0
- package/assets/quickjs/LICENSE +57 -0
- package/assets/quickjs/README.md +14 -0
- package/assets/quickjs/quickjs.wasm +0 -0
- package/dist/agent/recovery-reminder.js +6 -1
- package/dist/agent/schema-coerce.d.ts +24 -0
- package/dist/agent/schema-coerce.js +157 -0
- package/dist/agent/schema.d.ts +1 -1
- package/dist/agent/schema.js +1 -1
- package/dist/agent/session-cache.js +12 -0
- package/dist/agent/tool-runner.js +57 -28
- package/dist/agent/types.d.ts +4 -0
- package/dist/ai/apis/anthropic-compat.d.ts +3 -1
- package/dist/ai/apis/anthropic-compat.js +8 -1
- package/dist/ai/apis/anthropic-messages.js +54 -2
- package/dist/ai/apis/anthropic-request.d.ts +3 -0
- package/dist/ai/apis/anthropic-request.js +7 -1
- package/dist/ai/apis/anthropic-threads.d.ts +64 -0
- package/dist/ai/apis/anthropic-threads.js +192 -0
- package/dist/ai/providers/catalog-data.js +5 -5
- package/dist/ai/providers/models-dev-data.js +22 -22
- package/dist/ai/types.d.ts +16 -0
- package/dist/bundle/ama-sandbox.cjs +96 -2
- package/dist/bundle/ama.cjs +29964 -27673
- package/dist/cli/bootstrap.js +32 -6
- package/dist/cli/compose-agents.js +2 -1
- package/dist/cli/compose-extensions-load.d.ts +20 -0
- package/dist/cli/compose-extensions-load.js +38 -0
- package/dist/cli/compose.js +1 -0
- package/dist/cli/deps.d.ts +11 -0
- package/dist/cli/runtime.d.ts +7 -0
- package/dist/cli/subcommands/config.d.ts +3 -0
- package/dist/cli/subcommands/config.js +22 -7
- package/dist/cli/subcommands/doctor.js +34 -0
- package/dist/cli/subcommands/models-discover.js +6 -2
- package/dist/codemode/capability.d.ts +14 -2
- package/dist/codemode/capability.js +19 -2
- package/dist/codemode/host-side.d.ts +14 -0
- package/dist/codemode/host-side.js +81 -10
- package/dist/codemode/inner-calls.d.ts +19 -0
- package/dist/codemode/inner-calls.js +24 -0
- package/dist/codemode/protocol.d.ts +14 -0
- package/dist/codemode/protocol.js +9 -1
- package/dist/codemode/quickjs/host.d.ts +15 -0
- package/dist/codemode/quickjs/host.js +243 -0
- package/dist/codemode/quickjs/wasm.d.ts +21 -0
- package/dist/codemode/quickjs/wasm.js +39 -0
- package/dist/codemode/quickjs/worker.d.ts +55 -0
- package/dist/codemode/quickjs/worker.js +457 -0
- package/dist/codemode/sandbox-entry.d.ts +4 -0
- package/dist/codemode/sandbox-entry.js +95 -3
- package/dist/codemode/script-images.d.ts +18 -0
- package/dist/codemode/script-images.js +38 -0
- package/dist/codemode/script-output.d.ts +19 -0
- package/dist/codemode/script-output.js +67 -0
- package/dist/codemode/search-tools.d.ts +27 -0
- package/dist/codemode/search-tools.js +83 -0
- package/dist/codemode/tool.d.ts +4 -0
- package/dist/codemode/tool.js +60 -9
- package/dist/codemode/worker-pool.d.ts +65 -0
- package/dist/codemode/worker-pool.js +131 -0
- package/dist/config/extension-tree-hash.d.ts +31 -0
- package/dist/config/extension-tree-hash.js +88 -0
- package/dist/config/extension-trust.d.ts +70 -0
- package/dist/config/extension-trust.js +112 -0
- package/dist/config/json-schema.js +3 -1
- package/dist/config/key-docs.js +7 -1
- package/dist/config/profile.d.ts +2 -0
- package/dist/config/profile.js +1 -0
- package/dist/config/schema-trust.d.ts +7 -0
- package/dist/config/schema-trust.js +46 -0
- package/dist/config/schema.d.ts +4 -5
- package/dist/config/schema.js +7 -27
- package/dist/config/settings-registry.js +2 -0
- package/dist/config/trust.d.ts +2 -0
- package/dist/config/trust.js +5 -1
- package/dist/config/types.d.ts +23 -0
- package/dist/config/types.js +1 -0
- package/dist/drivers/host-runners.d.ts +15 -4
- package/dist/drivers/host-runners.js +31 -17
- package/dist/errors.d.ts +1 -1
- package/dist/host/api-impl.d.ts +47 -4
- package/dist/host/api-impl.js +181 -20
- package/dist/host/commands.d.ts +23 -0
- package/dist/host/commands.js +76 -0
- package/dist/host/extensions.d.ts +43 -0
- package/dist/host/extensions.js +117 -0
- package/dist/host/resources.d.ts +2 -0
- package/dist/host/resources.js +5 -0
- package/dist/host/types.d.ts +41 -2
- package/dist/host/types.js +4 -2
- package/dist/i18n/catalog.d.ts +39 -0
- package/dist/i18n/messages/cli.d.ts +24 -0
- package/dist/i18n/messages/cli.js +24 -0
- package/dist/i18n/messages/config-keys.d.ts +4 -0
- package/dist/i18n/messages/config-keys.js +6 -2
- package/dist/i18n/messages/config.d.ts +4 -0
- package/dist/i18n/messages/drivers.d.ts +22 -0
- package/dist/i18n/messages/drivers.js +22 -0
- package/dist/i18n/messages/errors.d.ts +1 -1
- package/dist/i18n/messages/interactive-startup.d.ts +4 -0
- package/dist/i18n/messages/interactive-startup.js +4 -0
- package/dist/i18n/messages/interactive-view.d.ts +2 -0
- package/dist/i18n/messages/interactive-view.js +2 -0
- package/dist/i18n/messages/interactive.d.ts +6 -0
- package/dist/i18n/messages/report.d.ts +14 -0
- package/dist/i18n/messages/report.js +14 -0
- package/dist/i18n/messages/subcommands-config.d.ts +8 -0
- package/dist/i18n/messages/subcommands-config.js +8 -0
- package/dist/i18n/messages/subcommands.d.ts +8 -0
- package/dist/modes/acp/acp-config.d.ts +4 -2
- package/dist/modes/acp/acp-config.js +17 -3
- package/dist/modes/acp/acp-events.d.ts +2 -0
- package/dist/modes/acp/acp-events.js +4 -0
- package/dist/modes/acp/acp-server.js +6 -2
- package/dist/modes/acp/acp-sessions.d.ts +8 -1
- package/dist/modes/acp/acp-sessions.js +18 -0
- package/dist/modes/commands-core.d.ts +14 -1
- package/dist/modes/commands-core.js +34 -2
- package/dist/modes/interactive/startup-ui.js +21 -0
- package/dist/modes/interactive/status-area.js +1 -1
- package/dist/modes/interactive/tool-view.d.ts +8 -2
- package/dist/modes/interactive/tool-view.js +12 -5
- package/dist/modes/print/print-mode.d.ts +3 -0
- package/dist/modes/print/print-mode.js +35 -8
- package/dist/modes/rpc/commands.d.ts +2 -0
- package/dist/modes/rpc/commands.js +22 -7
- package/dist/modes/rpc/rpc-mode.js +3 -0
- package/dist/modes/startup-ui-text.js +11 -0
- package/dist/rpc.d.ts +2 -1
- package/dist/session/unclean-end.d.ts +8 -0
- package/dist/session/unclean-end.js +39 -7
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/registry.js +13 -0
- package/dist/tools/types.d.ts +7 -0
- package/docs/README.md +1 -1
- package/docs/en/README.md +3 -3
- package/docs/en/guides/extensions.md +141 -0
- package/docs/en/guides/providers.md +27 -7
- package/docs/en/guides/tui.md +1 -1
- package/docs/en/reference/acp.md +1 -1
- package/docs/en/reference/host-api.md +55 -27
- package/docs/en/reference/rpc.md +12 -8
- package/docs/guides/codemode.md +52 -12
- package/docs/guides/extensions.md +136 -0
- package/docs/guides/providers.md +21 -1
- package/docs/guides/sandbox.md +2 -0
- package/docs/guides/tui.md +1 -1
- package/docs/reference/acp.md +1 -1
- package/docs/reference/host-api.md +55 -27
- package/docs/reference/rpc.md +12 -8
- package/docs/reference/session-format.md +10 -9
- package/package.json +5 -2
package/dist/ai/types.d.ts
CHANGED
|
@@ -226,6 +226,12 @@ export interface AnthropicMessagesCompat {
|
|
|
226
226
|
sendInterleavedThinkingBeta?: boolean;
|
|
227
227
|
/** [W5-C0] 打 `cache_control`;缺省 true,忽略它的端点(DeepSeek 等)可关以减小请求体。 */
|
|
228
228
|
sendCacheControl?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* 请求按 message threads 续接(beta `message-threads-2026-08-12`):有稳定 sessionId 且提示缓存开着时,
|
|
231
|
+
* 服务端沿用上一条回复,请求只发新增消息。缺省:官方端点 true,Anthropic 兼容的第三方 / 中转 false
|
|
232
|
+
* (丢弃未知字段的网关会把续接静默变成缺前文的请求)。
|
|
233
|
+
*/
|
|
234
|
+
messageThreads?: boolean;
|
|
229
235
|
}
|
|
230
236
|
/** B8 补全。 */
|
|
231
237
|
export interface GoogleCompat {
|
|
@@ -401,6 +407,16 @@ export interface StreamOptions {
|
|
|
401
407
|
thinkingLevel?: ModelThinkingLevel;
|
|
402
408
|
cacheRetention?: CacheRetention;
|
|
403
409
|
sessionId?: string;
|
|
410
|
+
/**
|
|
411
|
+
* 服务端线程键(Anthropic message threads),缺省 `sessionId`。fork 会话与根会话共用提示缓存键
|
|
412
|
+
* (`sessionId`),但各用自己的线程键,各续各的线程。
|
|
413
|
+
*/
|
|
414
|
+
threadKey?: string;
|
|
415
|
+
/**
|
|
416
|
+
* 本次请求不使用、也不替换服务端的续接状态(Anthropic message threads)。重放或重复上一条请求的
|
|
417
|
+
* 调用(缓存保温、压缩摘要)必须置位,否则会占掉真实回合的续接点。
|
|
418
|
+
*/
|
|
419
|
+
disableContinuation?: boolean;
|
|
404
420
|
/** [W3-C0] 请求用途(第三波 §1.2);缺省 `turn`。协议层只透传给观测方,不进请求体。 */
|
|
405
421
|
purpose?: RequestPurpose;
|
|
406
422
|
/**
|
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/codemode/sandbox-entry.ts
|
|
21
21
|
var sandbox_entry_exports = {};
|
|
22
22
|
__export(sandbox_entry_exports, {
|
|
23
|
+
BOOTSTRAP: () => BOOTSTRAP,
|
|
23
24
|
MAX_CONCURRENT: () => MAX_CONCURRENT,
|
|
25
|
+
MAX_SCRIPT_IMAGES: () => MAX_SCRIPT_IMAGES,
|
|
24
26
|
MAX_STORE_TOTAL_CHARS: () => MAX_STORE_TOTAL_CHARS,
|
|
25
27
|
MAX_STORE_VALUE_CHARS: () => MAX_STORE_VALUE_CHARS,
|
|
26
28
|
describeError: () => describeError
|
|
@@ -160,6 +162,86 @@ var BOOTSTRAP = String.raw`(function (host, config) {
|
|
|
160
162
|
const json = storeMap.get(key);
|
|
161
163
|
return json === undefined ? undefined : parse(json);
|
|
162
164
|
}
|
|
165
|
+
// image(): one implementation for both engines (the QuickJS worker cannot import source files)
|
|
166
|
+
const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
167
|
+
const IMAGE_FORMS = "image(value): pass a base64 data: URL, { image_url }, or { type: 'image', data, mimeType }";
|
|
168
|
+
let imageCount = 0;
|
|
169
|
+
// the first 12 bytes of a base64 string, enough for every signature below
|
|
170
|
+
function headBytes(b64) {
|
|
171
|
+
const bytes = [];
|
|
172
|
+
let acc = 0;
|
|
173
|
+
let bits = 0;
|
|
174
|
+
for (let i = 0; i < b64.length && bytes.length < 12; i++) {
|
|
175
|
+
const v = BASE64_ALPHABET.indexOf(b64[i]);
|
|
176
|
+
if (v < 0) break;
|
|
177
|
+
acc = (acc << 6) | v;
|
|
178
|
+
bits += 6;
|
|
179
|
+
if (bits >= 8) {
|
|
180
|
+
bits -= 8;
|
|
181
|
+
bytes.push((acc >> bits) & 255);
|
|
182
|
+
acc &= (1 << bits) - 1;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return bytes;
|
|
186
|
+
}
|
|
187
|
+
function ascii(bytes, from, to) {
|
|
188
|
+
let out = "";
|
|
189
|
+
for (let i = from; i < to; i++) out += String.fromCharCode(bytes[i]);
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
// PNG / JPEG / GIF / WebP by magic bytes only; the declared MIME type is never trusted
|
|
193
|
+
function sniffImage(b) {
|
|
194
|
+
if (b.length >= 8 && b[0] === 0x89 && ascii(b, 1, 4) === "PNG" && b[4] === 0x0d && b[5] === 0x0a && b[6] === 0x1a && b[7] === 0x0a) return "image/png";
|
|
195
|
+
if (b.length >= 3 && b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return "image/jpeg";
|
|
196
|
+
if (b.length >= 6 && /^GIF8[79]a$/.test(ascii(b, 0, 6))) return "image/gif";
|
|
197
|
+
if (b.length >= 12 && ascii(b, 0, 4) === "RIFF" && ascii(b, 8, 12) === "WEBP") return "image/webp";
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
function normalizeImage(value) {
|
|
201
|
+
let raw = value;
|
|
202
|
+
if (typeof raw === "object" && raw !== null) {
|
|
203
|
+
if (raw.type === "image" && typeof raw.data === "string") raw = raw.data;
|
|
204
|
+
else if (typeof raw.image_url === "string") raw = raw.image_url;
|
|
205
|
+
else if (typeof raw.image_url === "object" && raw.image_url !== null && typeof raw.image_url.url === "string") raw = raw.image_url.url;
|
|
206
|
+
}
|
|
207
|
+
if (typeof raw !== "string") return IMAGE_FORMS;
|
|
208
|
+
let base64 = raw.trim();
|
|
209
|
+
const schemeMatch = /^([a-z][a-z0-9+.-]*):/i.exec(base64);
|
|
210
|
+
const scheme = schemeMatch === null ? undefined : schemeMatch[1].toLowerCase();
|
|
211
|
+
if (scheme !== undefined && scheme !== "data") {
|
|
212
|
+
return "image(value): remote URLs are not supported; pass a base64 data: URL";
|
|
213
|
+
}
|
|
214
|
+
if (scheme === "data") {
|
|
215
|
+
const match = /^data:[^,]*;base64,([\s\S]*)$/i.exec(base64);
|
|
216
|
+
if (match === null) return "image(value): the data: URL must be base64-encoded";
|
|
217
|
+
base64 = match[1].trim();
|
|
218
|
+
}
|
|
219
|
+
base64 = base64.replace(/\s+/g, "");
|
|
220
|
+
if (base64 === "" || !/^[A-Za-z0-9+/]*={0,2}$/.test(base64)) {
|
|
221
|
+
return "image(value): the image data is not valid base64";
|
|
222
|
+
}
|
|
223
|
+
const mimeType = sniffImage(headBytes(base64));
|
|
224
|
+
if (mimeType === undefined) return "image(value): not a PNG, JPEG, GIF or WebP image";
|
|
225
|
+
return { data: base64, mimeType: mimeType };
|
|
226
|
+
}
|
|
227
|
+
function image(value) {
|
|
228
|
+
let normalized;
|
|
229
|
+
try {
|
|
230
|
+
normalized = normalizeImage(value);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
throw new TypeError("image(value): value must be JSON-serializable");
|
|
233
|
+
}
|
|
234
|
+
if (typeof normalized === "string") throw new TypeError(normalized);
|
|
235
|
+
if (imageCount >= config.maxImages) {
|
|
236
|
+
throw new TypeError("image(value): at most " + config.maxImages + " images per script");
|
|
237
|
+
}
|
|
238
|
+
imageCount++;
|
|
239
|
+
host("image", stringify(normalized));
|
|
240
|
+
}
|
|
241
|
+
// reserved call name, same as SEARCH_TOOLS_CALL in protocol.ts; the parent ranks tools with BM25
|
|
242
|
+
function searchTools(query, options) {
|
|
243
|
+
return callTool("@searchTools", { query: query, options: options });
|
|
244
|
+
}
|
|
163
245
|
function describeTool(name) {
|
|
164
246
|
return declByName.get(callName.get(name) ?? name);
|
|
165
247
|
}
|
|
@@ -175,6 +257,8 @@ var BOOTSTRAP = String.raw`(function (host, config) {
|
|
|
175
257
|
load: load,
|
|
176
258
|
ALL_TOOLS: names,
|
|
177
259
|
describeTool: describeTool,
|
|
260
|
+
searchTools: searchTools,
|
|
261
|
+
image: image,
|
|
178
262
|
};
|
|
179
263
|
for (const [key, value] of Object.entries(globals)) {
|
|
180
264
|
Object.defineProperty(globalThis, key, { value: value, writable: false, enumerable: false, configurable: false });
|
|
@@ -230,11 +314,17 @@ function done(ok, error) {
|
|
|
230
314
|
send(message);
|
|
231
315
|
process.stdout.write("", () => process.exit(0));
|
|
232
316
|
}
|
|
317
|
+
var MAX_SCRIPT_IMAGES = 8;
|
|
233
318
|
function host(kind, payload) {
|
|
234
|
-
if (finished) return;
|
|
319
|
+
if (finished) return void 0;
|
|
320
|
+
if (kind === "image") {
|
|
321
|
+
const normalized = JSON.parse(payload);
|
|
322
|
+
send({ type: "image", data: normalized.data, mimeType: normalized.mimeType });
|
|
323
|
+
return void 0;
|
|
324
|
+
}
|
|
235
325
|
if (kind === "output") {
|
|
236
326
|
send({ type: "output", text: payload });
|
|
237
|
-
return;
|
|
327
|
+
return void 0;
|
|
238
328
|
}
|
|
239
329
|
if (kind === "tool_call") {
|
|
240
330
|
const newline = payload.indexOf("\n");
|
|
@@ -242,6 +332,7 @@ function host(kind, payload) {
|
|
|
242
332
|
const call = JSON.parse(payload.slice(newline + 1));
|
|
243
333
|
send({ type: "tool_call", id, name: call.name, input: call.input });
|
|
244
334
|
}
|
|
335
|
+
return void 0;
|
|
245
336
|
}
|
|
246
337
|
function start(run) {
|
|
247
338
|
started = true;
|
|
@@ -254,6 +345,7 @@ function start(run) {
|
|
|
254
345
|
maxConcurrent: MAX_CONCURRENT,
|
|
255
346
|
maxValueChars: MAX_STORE_VALUE_CHARS,
|
|
256
347
|
maxTotalChars: MAX_STORE_TOTAL_CHARS,
|
|
348
|
+
maxImages: MAX_SCRIPT_IMAGES,
|
|
257
349
|
tools: JSON.stringify(run.tools),
|
|
258
350
|
store: JSON.stringify(run.store ?? {})
|
|
259
351
|
};
|
|
@@ -317,7 +409,9 @@ function main() {
|
|
|
317
409
|
if (process.argv.includes("--ama-codemode-sandbox")) main();
|
|
318
410
|
// Annotate the CommonJS export names for ESM import in node:
|
|
319
411
|
0 && (module.exports = {
|
|
412
|
+
BOOTSTRAP,
|
|
320
413
|
MAX_CONCURRENT,
|
|
414
|
+
MAX_SCRIPT_IMAGES,
|
|
321
415
|
MAX_STORE_TOTAL_CHARS,
|
|
322
416
|
MAX_STORE_VALUE_CHARS,
|
|
323
417
|
describeError
|