@armadra/agent 0.17.2 → 0.18.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.
Files changed (88) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/CHANGELOG.zh-CN.md +36 -0
  3. package/THIRD_PARTY_NOTICES.md +6 -0
  4. package/assets/quickjs/LICENSE +57 -0
  5. package/assets/quickjs/README.md +14 -0
  6. package/assets/quickjs/quickjs.wasm +0 -0
  7. package/dist/agent/recovery-reminder.js +6 -1
  8. package/dist/agent/schema-coerce.d.ts +24 -0
  9. package/dist/agent/schema-coerce.js +157 -0
  10. package/dist/agent/schema.d.ts +1 -1
  11. package/dist/agent/schema.js +1 -1
  12. package/dist/agent/session-cache.js +12 -0
  13. package/dist/agent/tool-runner.js +57 -28
  14. package/dist/agent/types.d.ts +4 -0
  15. package/dist/ai/apis/anthropic-compat.d.ts +3 -1
  16. package/dist/ai/apis/anthropic-compat.js +8 -1
  17. package/dist/ai/apis/anthropic-messages.js +54 -2
  18. package/dist/ai/apis/anthropic-request.d.ts +3 -0
  19. package/dist/ai/apis/anthropic-request.js +7 -1
  20. package/dist/ai/apis/anthropic-threads.d.ts +64 -0
  21. package/dist/ai/apis/anthropic-threads.js +192 -0
  22. package/dist/ai/providers/catalog-data.js +5 -5
  23. package/dist/ai/providers/models-dev-data.js +22 -22
  24. package/dist/ai/types.d.ts +16 -0
  25. package/dist/bundle/ama-sandbox.cjs +96 -2
  26. package/dist/bundle/ama.cjs +2386 -890
  27. package/dist/cli/subcommands/config.d.ts +3 -0
  28. package/dist/cli/subcommands/config.js +22 -7
  29. package/dist/cli/subcommands/doctor.js +1 -0
  30. package/dist/cli/subcommands/models-discover.js +6 -2
  31. package/dist/codemode/capability.d.ts +14 -2
  32. package/dist/codemode/capability.js +19 -2
  33. package/dist/codemode/host-side.d.ts +14 -0
  34. package/dist/codemode/host-side.js +81 -10
  35. package/dist/codemode/inner-calls.d.ts +19 -0
  36. package/dist/codemode/inner-calls.js +24 -0
  37. package/dist/codemode/protocol.d.ts +14 -0
  38. package/dist/codemode/protocol.js +9 -1
  39. package/dist/codemode/quickjs/host.d.ts +15 -0
  40. package/dist/codemode/quickjs/host.js +243 -0
  41. package/dist/codemode/quickjs/wasm.d.ts +21 -0
  42. package/dist/codemode/quickjs/wasm.js +39 -0
  43. package/dist/codemode/quickjs/worker.d.ts +55 -0
  44. package/dist/codemode/quickjs/worker.js +457 -0
  45. package/dist/codemode/sandbox-entry.d.ts +4 -0
  46. package/dist/codemode/sandbox-entry.js +95 -3
  47. package/dist/codemode/script-images.d.ts +18 -0
  48. package/dist/codemode/script-images.js +38 -0
  49. package/dist/codemode/script-output.d.ts +19 -0
  50. package/dist/codemode/script-output.js +67 -0
  51. package/dist/codemode/search-tools.d.ts +27 -0
  52. package/dist/codemode/search-tools.js +83 -0
  53. package/dist/codemode/tool.d.ts +4 -0
  54. package/dist/codemode/tool.js +60 -9
  55. package/dist/codemode/worker-pool.d.ts +65 -0
  56. package/dist/codemode/worker-pool.js +131 -0
  57. package/dist/config/json-schema.js +3 -1
  58. package/dist/config/key-docs.js +7 -1
  59. package/dist/config/schema.js +4 -2
  60. package/dist/config/settings-registry.js +2 -0
  61. package/dist/config/types.d.ts +10 -0
  62. package/dist/config/types.js +1 -0
  63. package/dist/i18n/catalog.d.ts +8 -0
  64. package/dist/i18n/messages/config-keys.d.ts +4 -0
  65. package/dist/i18n/messages/config-keys.js +6 -2
  66. package/dist/i18n/messages/config.d.ts +4 -0
  67. package/dist/i18n/messages/interactive-view.d.ts +2 -0
  68. package/dist/i18n/messages/interactive-view.js +2 -0
  69. package/dist/i18n/messages/interactive.d.ts +2 -0
  70. package/dist/i18n/messages/report.d.ts +2 -0
  71. package/dist/i18n/messages/report.js +2 -0
  72. package/dist/i18n/messages/subcommands-config.d.ts +8 -0
  73. package/dist/i18n/messages/subcommands-config.js +8 -0
  74. package/dist/i18n/messages/subcommands.d.ts +8 -0
  75. package/dist/modes/interactive/tool-view.d.ts +8 -2
  76. package/dist/modes/interactive/tool-view.js +12 -5
  77. package/dist/session/unclean-end.d.ts +8 -0
  78. package/dist/session/unclean-end.js +39 -7
  79. package/docs/en/guides/providers.md +27 -7
  80. package/docs/en/guides/tui.md +1 -1
  81. package/docs/en/reference/rpc.md +3 -1
  82. package/docs/guides/codemode.md +52 -12
  83. package/docs/guides/providers.md +21 -1
  84. package/docs/guides/sandbox.md +2 -0
  85. package/docs/guides/tui.md +1 -1
  86. package/docs/reference/rpc.md +3 -1
  87. package/docs/reference/session-format.md +10 -9
  88. package/package.json +2 -1
@@ -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