@warlock.js/ai-anthropic 5.52.0 → 5.53.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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to `@warlock.js/ai-anthropic` are documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
6
6
 
7
+ ## 5.53.0 - 2026-11-11
8
+
9
+ ### Changed
10
+
11
+ - The adapter no longer deep-copies the whole request body (the full history, including base64 attachments and long tool results) on every `complete()`, `stream()` and `countTokens()` call. Only `providerOptions.anthropic.body` values are copied, so a value that cannot be copied is still refused before anything is sent. The public `buildRequest()` still returns a fully detached copy.
12
+
7
13
  ## 5.49.0 - 2026-11-08
8
14
 
9
15
  ### Fixed
package/cjs/index.cjs CHANGED
@@ -1328,12 +1328,30 @@ var AnthropicModel = class {
1328
1328
  }), { signal: options?.signal });
1329
1329
  }
1330
1330
  buildRequest(messages, options) {
1331
+ return this.assembleRequest(messages, options, true);
1332
+ }
1333
+ /**
1334
+ * Build the request. `detach: true` (the public `buildRequest()`) returns
1335
+ * a deep copy that shares nothing with the caller's messages or options.
1336
+ * The adapter's own calls send the body at once, so they skip that copy —
1337
+ * it would duplicate every string in the history (base64 attachments,
1338
+ * long tool results) on each trip — and copy only the caller's
1339
+ * `providerOptions.anthropic.body` values, which keeps the same
1340
+ * validation for values that cannot be copied.
1341
+ */
1342
+ assembleRequest(messages, options, detach) {
1343
+ const anthropic = resolveAnthropicOptions(options);
1331
1344
  const built = this.buildBody(messages, options);
1332
- const betas = [.../* @__PURE__ */ new Set([...resolveAnthropicOptions(options).betas ?? [], ...built.betas])];
1333
- const body = structuredClone({
1345
+ const betas = [.../* @__PURE__ */ new Set([...anthropic.betas ?? [], ...built.betas])];
1346
+ const stream = options?.stream ?? false;
1347
+ const body = detach ? structuredClone({
1334
1348
  ...built.body,
1335
- stream: options?.stream ?? false
1336
- });
1349
+ stream
1350
+ }) : {
1351
+ ...built.body,
1352
+ ...anthropic.body === void 0 ? {} : structuredClone(anthropic.body),
1353
+ stream
1354
+ };
1337
1355
  return {
1338
1356
  endpoint: betas.length > 0 ? "beta.messages" : "messages",
1339
1357
  body,
@@ -1342,7 +1360,7 @@ var AnthropicModel = class {
1342
1360
  }
1343
1361
  buildLoggedRequest(messages, options) {
1344
1362
  try {
1345
- return this.buildRequest(messages, options);
1363
+ return this.assembleRequest(messages, options, false);
1346
1364
  } catch (thrown) {
1347
1365
  throw this.logAndWrap(thrown instanceof _warlock_js_ai.AIError ? thrown : new _warlock_js_ai.InvalidRequestError(`Could not build the Anthropic request: ${thrown instanceof Error ? thrown.message : String(thrown)}`, { cause: thrown }));
1348
1366
  }