@nyte-ai/ai 0.0.24 → 0.0.25-beta.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.
Files changed (68) hide show
  1. package/dist/chunks/{account-limits-cache-8qzk56vj.js → account-limits-cache-4qpef10z.js} +14 -1
  2. package/dist/chunks/{account-limits-cache-xds88kxd.js → account-limits-cache-525841fw.js} +12 -2
  3. package/dist/chunks/{account-limits-cache-r7mzqsvd.js → account-limits-cache-5zw0zvpy.js} +4 -4
  4. package/dist/chunks/{account-limits-cache-pfa86y8e.js → account-limits-cache-9twrnvar.js} +1 -1
  5. package/dist/chunks/{account-limits-cache-gznczekg.js → account-limits-cache-b25batbp.js} +1 -1
  6. package/dist/chunks/{account-limits-cache-1ny9js0t.js → account-limits-cache-c8r9ga7d.js} +8 -8
  7. package/dist/chunks/{account-limits-cache-1vkyhjec.js → account-limits-cache-eq2sae8w.js} +3 -3
  8. package/dist/chunks/{account-limits-cache-zn01kscn.js → account-limits-cache-gtv32njs.js} +1 -1
  9. package/dist/chunks/{account-limits-cache-nxkprk3g.js → account-limits-cache-gvscpb51.js} +1 -1
  10. package/dist/chunks/{account-limits-cache-1mjrnf6q.js → account-limits-cache-jt8g1rn2.js} +4 -4
  11. package/dist/chunks/{account-limits-cache-0n99ptc5.js → account-limits-cache-k4zewdqs.js} +1 -1
  12. package/dist/chunks/{account-limits-cache-h0fr16f1.js → account-limits-cache-kn9pwsba.js} +3 -3
  13. package/dist/chunks/{account-limits-cache-tj8a9am1.js → account-limits-cache-n916ac1t.js} +1 -1
  14. package/dist/chunks/{account-limits-cache-fdwad56n.js → account-limits-cache-qnrhx8gg.js} +1 -1
  15. package/dist/chunks/{account-limits-cache-4beqq05p.js → account-limits-cache-rp9ht95p.js} +1 -1
  16. package/dist/chunks/{account-limits-cache-n3yk6g5c.js → account-limits-cache-s77e2bgc.js} +1 -1
  17. package/dist/chunks/{account-limits-cache-bsknrh6t.js → account-limits-cache-sk1m9fsp.js} +1 -1
  18. package/dist/chunks/{account-limits-cache-aazmkcnq.js → account-limits-cache-w0abqhna.js} +2 -2
  19. package/dist/chunks/{account-limits-cache-j8c5ra3q.js → account-limits-cache-wawwj02k.js} +16 -5
  20. package/dist/chunks/{account-limits-cache-6r6bqm7g.js → account-limits-cache-ygydb22m.js} +1 -1
  21. package/dist/chunks/{account-limits-cache-fbkaq46e.js → account-limits-cache-z9mfzg68.js} +1 -1
  22. package/dist/src/api/anthropic-convert.d.ts +9 -3
  23. package/dist/src/api/anthropic-convert.js +5 -2
  24. package/dist/src/api/anthropic-messages.js +47 -16
  25. package/dist/src/api/anthropic-messages.lazy.js +1 -1
  26. package/dist/src/api/deferred.js +1 -1
  27. package/dist/src/api/google-generative-ai.js +1 -1
  28. package/dist/src/api/google-generative-ai.lazy.js +1 -1
  29. package/dist/src/api/openai-codex-compact.js +6 -6
  30. package/dist/src/api/openai-codex-protocol.js +3 -3
  31. package/dist/src/api/openai-codex-responses.js +7 -7
  32. package/dist/src/api/openai-codex-responses.lazy.js +1 -1
  33. package/dist/src/api/openai-codex-websocket.js +6 -6
  34. package/dist/src/api/openai-completions-convert.js +2 -2
  35. package/dist/src/api/openai-completions-params.js +3 -3
  36. package/dist/src/api/openai-completions-reasoning.d.ts +5 -5
  37. package/dist/src/api/openai-completions.js +4 -4
  38. package/dist/src/api/openai-completions.lazy.js +1 -1
  39. package/dist/src/api/openai-responses-convert.js +2 -2
  40. package/dist/src/api/openai-responses-events.d.ts +98 -98
  41. package/dist/src/api/openai-responses-stream.js +4 -4
  42. package/dist/src/api/openai-responses.js +4 -4
  43. package/dist/src/api/openai-responses.lazy.js +1 -1
  44. package/dist/src/api/transform-messages.d.ts +11 -1
  45. package/dist/src/api/transform-messages.js +3 -1
  46. package/dist/src/auth/oauth/authorization-input.d.ts +2 -2
  47. package/dist/src/index.js +19 -19
  48. package/dist/src/providers/anthropic.js +2 -2
  49. package/dist/src/providers/github-copilot.d.ts +1 -1
  50. package/dist/src/providers/github-copilot.js +4 -4
  51. package/dist/src/providers/nyte-catalog.js +14 -14
  52. package/dist/src/providers/openai-codex.js +2 -2
  53. package/dist/src/providers/openai.js +2 -2
  54. package/dist/src/providers/opencode-go.js +6 -6
  55. package/dist/src/providers/opencode.js +5 -5
  56. package/dist/src/providers/openrouter.js +2 -2
  57. package/dist/src/providers/vercel-ai-gateway.js +2 -2
  58. package/dist/src/utils/failure.js +1 -1
  59. package/dist/src/utils/json-parse.js +1 -1
  60. package/dist/src/utils/overflow.js +2 -2
  61. package/dist/src/utils/retry.js +2 -2
  62. package/package.json +3 -4
  63. /package/dist/chunks/{account-limits-cache-eyx1jcxc.js → account-limits-cache-20ttssmw.js} +0 -0
  64. /package/dist/chunks/{account-limits-cache-92q56978.js → account-limits-cache-3as87r3h.js} +0 -0
  65. /package/dist/chunks/{account-limits-cache-hxy4942k.js → account-limits-cache-khyz4r1r.js} +0 -0
  66. /package/dist/chunks/{account-limits-cache-k8z39pe7.js → account-limits-cache-s4xgnvwg.js} +0 -0
  67. /package/dist/chunks/{account-limits-cache-fdhrgjpr.js → account-limits-cache-yck8f1w5.js} +0 -0
  68. /package/dist/chunks/{account-limits-cache-tdgrj49j.js → account-limits-cache-z4y0mmpy.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  // src/api/transform-messages.ts
2
2
  var NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
3
3
  var NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
4
+ var ERROR_TOOL_IMAGE_PLACEHOLDER = "(image attached after the tool results)";
4
5
  function replaceImagesWithPlaceholder(content, placeholder) {
5
6
  const result = [];
6
7
  let previousWasPlaceholder = false;
@@ -17,6 +18,18 @@ function replaceImagesWithPlaceholder(content, placeholder) {
17
18
  }
18
19
  return result;
19
20
  }
21
+ function splitErrorToolResultImages2(msg) {
22
+ if (!msg.isError)
23
+ return;
24
+ const images = msg.content.filter((block) => block.type === "image");
25
+ if (images.length === 0)
26
+ return;
27
+ return {
28
+ content: replaceImagesWithPlaceholder(msg.content, ERROR_TOOL_IMAGE_PLACEHOLDER),
29
+ caption: `Images from the error result of tool call ${msg.toolCallId} (${msg.toolName}):`,
30
+ images
31
+ };
32
+ }
20
33
  function downgradeUnsupportedImages(messages, model) {
21
34
  if (model.input.includes("image")) {
22
35
  return messages;
@@ -157,4 +170,4 @@ function transformMessages2(messages, model, normalizeToolCallId) {
157
170
  return result;
158
171
  }
159
172
 
160
- export { transformMessages2 };
173
+ export { splitErrorToolResultImages2, transformMessages2 };
@@ -62,13 +62,15 @@ var OVERLOADED_PATTERN = pattern([
62
62
  "\\b529\\b",
63
63
  "\\b5(?:00|02|03|04|20|24)\\b",
64
64
  "overload",
65
+ "server_busy",
66
+ "servers are currently busy",
65
67
  "currently experiencing high demand",
66
68
  "model is at capacity",
67
69
  "service.?unavailable",
68
70
  "temporarily unavailable",
69
71
  "server.?error",
70
72
  "internal.?error",
71
- "provider.?returned.?error",
73
+ "provider.?returned.?(?:an.?)?error",
72
74
  "exceeded request buffer limit while retrying upstream",
73
75
  "you can retry your request",
74
76
  "try your request again",
@@ -84,6 +86,12 @@ var NETWORK_PATTERN = pattern([
84
86
  "ENOTFOUND",
85
87
  "EAI_AGAIN",
86
88
  "upstream.?connect",
89
+ "unable to forward upstream",
90
+ "upstream.?request.?failed",
91
+ "upstream_stream_read_error",
92
+ "stream was interrupted",
93
+ "http/?2 stream failed",
94
+ "request to \\S+ failed, reason:",
87
95
  "reset before headers",
88
96
  "socket hang up",
89
97
  "socket connection was closed",
@@ -94,7 +102,9 @@ var NETWORK_PATTERN = pattern([
94
102
  "ended without",
95
103
  "stream ended before message_stop",
96
104
  "stream ended before a terminal response event",
97
- "http2 request did not get a response"
105
+ "http2 request did not get a response",
106
+ "stream disconnected before completion",
107
+ "pending stream has been canceled"
98
108
  ]);
99
109
  var RETRY_DELAY_PATTERN = /server requested ([0-9]+(?:\.[0-9]+)?)s retry delay(?: \(max: ([0-9]+(?:\.[0-9]+)?)s\))?/i;
100
110
  function classForStatus(status) {
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  anthropicMessagesApi2
3
- } from "./account-limits-cache-92q56978.js";
3
+ } from "./account-limits-cache-3as87r3h.js";
4
4
  import {
5
5
  openAICompletionsApi2
6
- } from "./account-limits-cache-eyx1jcxc.js";
6
+ } from "./account-limits-cache-20ttssmw.js";
7
7
  import {
8
8
  openAIResponsesApi2
9
- } from "./account-limits-cache-k8z39pe7.js";
9
+ } from "./account-limits-cache-s4xgnvwg.js";
10
10
  import {
11
11
  envApiKeyAuth2
12
12
  } from "./account-limits-cache-6x05n06z.js";
@@ -18,7 +18,7 @@ import {
18
18
  } from "./account-limits-cache-fht68jp2.js";
19
19
  import {
20
20
  OPENCODE_PROMPT_CACHE2
21
- } from "./account-limits-cache-1mjrnf6q.js";
21
+ } from "./account-limits-cache-jt8g1rn2.js";
22
22
 
23
23
  // src/providers/opencode-go.ts
24
24
  function opencodeGoProvider2() {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  openAICompletionsApi2
3
- } from "./account-limits-cache-eyx1jcxc.js";
3
+ } from "./account-limits-cache-20ttssmw.js";
4
4
  import {
5
5
  envApiKeyAuth2
6
6
  } from "./account-limits-cache-6x05n06z.js";
@@ -35,7 +35,7 @@ import {
35
35
  import {
36
36
  convertResponsesMessages2,
37
37
  convertResponsesTools2
38
- } from "./account-limits-cache-n3yk6g5c.js";
38
+ } from "./account-limits-cache-s77e2bgc.js";
39
39
 
40
40
  // src/api/openai-codex-protocol.ts
41
41
  import { Type } from "typebox";
@@ -12,28 +12,28 @@ import {
12
12
  } from "./account-limits-cache-5jdhn0e1.js";
13
13
  import {
14
14
  anthropicProvider2
15
- } from "./account-limits-cache-0n99ptc5.js";
15
+ } from "./account-limits-cache-k4zewdqs.js";
16
16
  import {
17
17
  githubCopilotProvider2
18
- } from "./account-limits-cache-h0fr16f1.js";
18
+ } from "./account-limits-cache-kn9pwsba.js";
19
19
  import {
20
20
  openaiCodexProvider2
21
- } from "./account-limits-cache-tj8a9am1.js";
21
+ } from "./account-limits-cache-n916ac1t.js";
22
22
  import {
23
23
  openaiProvider2
24
- } from "./account-limits-cache-6r6bqm7g.js";
24
+ } from "./account-limits-cache-ygydb22m.js";
25
25
  import {
26
26
  opencodeProvider2
27
- } from "./account-limits-cache-1mjrnf6q.js";
27
+ } from "./account-limits-cache-jt8g1rn2.js";
28
28
  import {
29
29
  opencodeGoProvider2
30
- } from "./account-limits-cache-r7mzqsvd.js";
30
+ } from "./account-limits-cache-5zw0zvpy.js";
31
31
  import {
32
32
  openrouterProvider2
33
- } from "./account-limits-cache-pfa86y8e.js";
33
+ } from "./account-limits-cache-9twrnvar.js";
34
34
  import {
35
35
  vercelAiGatewayProvider2
36
- } from "./account-limits-cache-4beqq05p.js";
36
+ } from "./account-limits-cache-rp9ht95p.js";
37
37
 
38
38
  // src/providers/nyte-catalog.ts
39
39
  var NYTE_PROVIDERS = [
@@ -29,18 +29,18 @@ import {
29
29
  } from "./account-limits-cache-fvadc36m.js";
30
30
  import {
31
31
  convertResponsesMessages2
32
- } from "./account-limits-cache-n3yk6g5c.js";
32
+ } from "./account-limits-cache-s77e2bgc.js";
33
33
  import {
34
34
  CODEX_TOOL_CALL_PROVIDERS2,
35
35
  codexStreamOptions2,
36
36
  CodexApiError2,
37
37
  CodexProtocolError2,
38
38
  mapCodexEvents2
39
- } from "./account-limits-cache-gznczekg.js";
39
+ } from "./account-limits-cache-b25batbp.js";
40
40
  import {
41
41
  ResponsesUsageError2,
42
42
  processResponsesStream2
43
- } from "./account-limits-cache-aazmkcnq.js";
43
+ } from "./account-limits-cache-w0abqhna.js";
44
44
 
45
45
  // src/api/openai-codex-websocket.ts
46
46
  import { Value } from "typebox/value";
@@ -21,7 +21,7 @@ import {
21
21
  applyAnthropicCacheControl2,
22
22
  convertMessages2,
23
23
  convertTools2
24
- } from "./account-limits-cache-fdwad56n.js";
24
+ } from "./account-limits-cache-qnrhx8gg.js";
25
25
 
26
26
  // src/api/openai-completions-params.ts
27
27
  function hasToolHistory(messages) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  classifyAssistantFailure2
3
- } from "./account-limits-cache-xds88kxd.js";
3
+ } from "./account-limits-cache-525841fw.js";
4
4
 
5
5
  // src/utils/overflow.ts
6
6
  function overflowsContext2(message, contextWindow) {
@@ -1,15 +1,15 @@
1
1
  import {
2
2
  anthropicMessagesApi2
3
- } from "./account-limits-cache-92q56978.js";
3
+ } from "./account-limits-cache-3as87r3h.js";
4
4
  import {
5
5
  googleGenerativeAIApi2
6
- } from "./account-limits-cache-hxy4942k.js";
6
+ } from "./account-limits-cache-khyz4r1r.js";
7
7
  import {
8
8
  openAICompletionsApi2
9
- } from "./account-limits-cache-eyx1jcxc.js";
9
+ } from "./account-limits-cache-20ttssmw.js";
10
10
  import {
11
11
  openAIResponsesApi2
12
- } from "./account-limits-cache-k8z39pe7.js";
12
+ } from "./account-limits-cache-s4xgnvwg.js";
13
13
  import {
14
14
  envApiKeyAuth2
15
15
  } from "./account-limits-cache-6x05n06z.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  anthropicMessagesApi2
3
- } from "./account-limits-cache-92q56978.js";
3
+ } from "./account-limits-cache-3as87r3h.js";
4
4
  import {
5
5
  usesClaudeSubscription2
6
6
  } from "./account-limits-cache-ks1sjym9.js";
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  anthropicMessagesApi2
3
- } from "./account-limits-cache-92q56978.js";
3
+ } from "./account-limits-cache-3as87r3h.js";
4
4
  import {
5
5
  openAICompletionsApi2
6
- } from "./account-limits-cache-eyx1jcxc.js";
6
+ } from "./account-limits-cache-20ttssmw.js";
7
7
  import {
8
8
  openAIResponsesApi2
9
- } from "./account-limits-cache-k8z39pe7.js";
9
+ } from "./account-limits-cache-s4xgnvwg.js";
10
10
  import {
11
11
  envApiKeyAuth2
12
12
  } from "./account-limits-cache-6x05n06z.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  openAICodexResponsesApi2
3
- } from "./account-limits-cache-tdgrj49j.js";
3
+ } from "./account-limits-cache-z4y0mmpy.js";
4
4
  import {
5
5
  fetchOpenAICodexAccountLimits2
6
6
  } from "./account-limits-cache-hj3ek3ty.js";
@@ -20,7 +20,7 @@ import {
20
20
  } from "./account-limits-cache-h92bzz1j.js";
21
21
  import {
22
22
  transformMessages2
23
- } from "./account-limits-cache-8qzk56vj.js";
23
+ } from "./account-limits-cache-4qpef10z.js";
24
24
  import {
25
25
  parseOpenAIReasoningDetails2,
26
26
  parseLegacyEncryptedReasoningDetail2,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  anthropicMessagesApi2
3
- } from "./account-limits-cache-92q56978.js";
3
+ } from "./account-limits-cache-3as87r3h.js";
4
4
  import {
5
5
  envApiKeyAuth2
6
6
  } from "./account-limits-cache-6x05n06z.js";
@@ -20,7 +20,7 @@ import {
20
20
  } from "./account-limits-cache-h92bzz1j.js";
21
21
  import {
22
22
  transformMessages2
23
- } from "./account-limits-cache-8qzk56vj.js";
23
+ } from "./account-limits-cache-4qpef10z.js";
24
24
 
25
25
  // src/api/openai-responses-convert.ts
26
26
  import { Type } from "typebox";
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  classifyAssistantFailure2,
6
6
  retryCanHelp2
7
- } from "./account-limits-cache-xds88kxd.js";
7
+ } from "./account-limits-cache-525841fw.js";
8
8
 
9
9
  // src/utils/retry.ts
10
10
  var DEFAULT_MAX_AGENT_RETRY_DELAY_MS2 = 60000;
@@ -5,7 +5,7 @@ import {
5
5
  parseStreamingJson2,
6
6
  parseToolCallArguments2,
7
7
  unfinishedToolCallArguments2
8
- } from "./account-limits-cache-fbkaq46e.js";
8
+ } from "./account-limits-cache-z9mfzg68.js";
9
9
  import {
10
10
  appendGrammarToolInputJsonDelta2
11
11
  } from "./account-limits-cache-h92bzz1j.js";
@@ -18,7 +18,7 @@ import {
18
18
  } from "./account-limits-cache-736tdyme.js";
19
19
  import {
20
20
  encodeTextSignatureV12
21
- } from "./account-limits-cache-n3yk6g5c.js";
21
+ } from "./account-limits-cache-s77e2bgc.js";
22
22
  import {
23
23
  TerminalReasoningItemSchema2,
24
24
  StoredReasoningItemSchema2,
@@ -11,6 +11,9 @@ import {
11
11
  import {
12
12
  toClaudeCodeName2
13
13
  } from "./account-limits-cache-ks1sjym9.js";
14
+ import {
15
+ splitErrorToolResultImages2
16
+ } from "./account-limits-cache-4qpef10z.js";
14
17
 
15
18
  // src/api/anthropic-convert.ts
16
19
  import { IsProperties, IsRequired } from "typebox/schema";
@@ -134,7 +137,6 @@ function convertMessages3(transformedMessages, isOAuthToken, cacheControl, allow
134
137
  });
135
138
  }
136
139
  } else if (msg.role === "assistant") {
137
- flushPendingSystemMessages();
138
140
  const blocks = [];
139
141
  for (const block of msg.content) {
140
142
  if (block.type === "text") {
@@ -183,6 +185,7 @@ function convertMessages3(transformedMessages, isOAuthToken, cacheControl, allow
183
185
  }
184
186
  if (blocks.length === 0)
185
187
  continue;
188
+ flushPendingSystemMessages();
186
189
  params.push({
187
190
  role: "assistant",
188
191
  content: blocks
@@ -195,9 +198,13 @@ function convertMessages3(transformedMessages, isOAuthToken, cacheControl, allow
195
198
  const next = transformedMessages[j];
196
199
  if (next.role !== "toolResult")
197
200
  break;
198
- const converted = convertToolResult(next, isOAuthToken, deferredToolNames, loadedToolNames, normalizeToolName);
201
+ const split = splitErrorToolResultImages2(next);
202
+ const converted = convertToolResult(split ? { ...next, content: split.content } : next, isOAuthToken, deferredToolNames, loadedToolNames, normalizeToolName);
199
203
  toolResults.push(converted.toolResult);
200
204
  siblingContent.push(...converted.siblingContent);
205
+ if (split) {
206
+ siblingContent.push({ type: "text", text: split.caption }, ...split.images.map(convertImageBlock));
207
+ }
201
208
  }
202
209
  i = j - 1;
203
210
  params.push({
@@ -262,11 +269,15 @@ var rejectedByAnthropicStrictTools = (key, value) => {
262
269
  return typeof value !== "string" || !ANTHROPIC_STRICT_STRING_FORMATS.has(value);
263
270
  return false;
264
271
  };
265
- function convertTools3(tools, isOAuthToken, supportsEagerToolInputStreaming, supportsStrictTools, cacheControl, deferLoading = false) {
272
+ function prefersStrictSampling2(tool) {
273
+ const config = tool.constrainedSampling;
274
+ return config !== undefined && config !== false && config.type === "json_schema" && config.strict === "prefer";
275
+ }
276
+ function convertTools3(tools, isOAuthToken, supportsEagerToolInputStreaming, supportsStrictTools, cacheControl, deferLoading = false, disablePreferredStrictTools = false) {
266
277
  if (!tools)
267
278
  return [];
268
279
  return tools.map((tool, index) => {
269
- const strict = resolveJsonSchemaStrictSampling2(tool, supportsStrictTools, rejectedByAnthropicStrictTools);
280
+ const strict = disablePreferredStrictTools && prefersStrictSampling2(tool) ? undefined : resolveJsonSchemaStrictSampling2(tool, supportsStrictTools, rejectedByAnthropicStrictTools);
270
281
  const parameters = getJsonSchemaToolParameters2(tool, strict);
271
282
  const legacyInputSchema = {
272
283
  type: "object",
@@ -290,4 +301,4 @@ function convertTools3(tools, isOAuthToken, supportsEagerToolInputStreaming, sup
290
301
  });
291
302
  }
292
303
 
293
- export { normalizeToolCallId2, convertMessages3, convertTools3 };
304
+ export { normalizeToolCallId2, convertMessages3, prefersStrictSampling2, convertTools3 };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  openAIResponsesApi2
3
- } from "./account-limits-cache-k8z39pe7.js";
3
+ } from "./account-limits-cache-s4xgnvwg.js";
4
4
  import {
5
5
  envApiKeyAuth2
6
6
  } from "./account-limits-cache-6x05n06z.js";
@@ -3,7 +3,7 @@ import { parse as partialParse } from "partial-json";
3
3
  import { Type } from "typebox";
4
4
  import { Value } from "typebox/value";
5
5
  var ToolArgumentsSchema = Type.Record(Type.String(), Type.Unknown());
6
- var VALID_JSON_ESCAPES = new Set(['"', "\\", "/", "b", "f", "n", "r", "t", "u"]);
6
+ var VALID_JSON_ESCAPES = new Set(['"', "\\", "/", "b", "f", "n", "r", "t"]);
7
7
  function escapeControlCharacter(char) {
8
8
  switch (char) {
9
9
  case "\b":
@@ -5,13 +5,19 @@ export declare function normalizeToolCallId(id: string): string;
5
5
  * The transcript as Anthropic messages.
6
6
  *
7
7
  * - Anthropic requires `tool_result` immediately after `tool_use`, so system updates are held
8
- * until the next assistant message or the end of the transcript.
8
+ * until the next assistant message that is sent, or the end of the transcript. Holding past an
9
+ * assistant message that converts to no blocks keeps the update from landing before a user
10
+ * message, which Anthropic rejects.
9
11
  * - A thinking block whose signature is missing or empty, e.g. from an aborted stream, becomes
10
12
  * plain text; models marked `allowEmptySignature` emit and accept empty signatures, so they
11
13
  * keep the block.
12
14
  * - Consecutive tool results go into one user message, which the z.ai Anthropic endpoint needs;
13
- * content displaced by tool references follows every `tool_result` block.
15
+ * content displaced by tool references, and the images of error results (which Anthropic
16
+ * rejects inside them), follow every `tool_result` block.
14
17
  * - The last user or system message carries `cache_control`, caching the conversation history.
15
18
  */
16
19
  export declare function convertMessages(transformedMessages: Message[], isOAuthToken: boolean, cacheControl?: BetaCacheControlEphemeral, allowEmptySignature?: boolean, deferredToolNames?: ReadonlySet<string>, normalizeToolName?: (name: string) => string, nativeToolChanges?: boolean): BetaMessageParam[];
17
- export declare function convertTools(tools: Tool[], isOAuthToken: boolean, supportsEagerToolInputStreaming: boolean, supportsStrictTools: boolean, cacheControl?: BetaCacheControlEphemeral, deferLoading?: boolean): BetaTool[];
20
+ /** Whether the tool asks for strict sampling only where the provider can honor it. */
21
+ export declare function prefersStrictSampling(tool: Tool): boolean;
22
+ /** `disablePreferredStrictTools` sends `prefer` tools non-strict; `require` tools stay strict. */
23
+ export declare function convertTools(tools: Tool[], isOAuthToken: boolean, supportsEagerToolInputStreaming: boolean, supportsStrictTools: boolean, cacheControl?: BetaCacheControlEphemeral, deferLoading?: boolean, disablePreferredStrictTools?: boolean): BetaTool[];
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  normalizeToolCallId2,
3
3
  convertMessages3,
4
+ prefersStrictSampling2,
4
5
  convertTools3
5
- } from "../../chunks/account-limits-cache-j8c5ra3q.js";
6
+ } from "../../chunks/account-limits-cache-wawwj02k.js";
7
+ import"../../chunks/account-limits-cache-4qpef10z.js";
6
8
  import"../../chunks/account-limits-cache-h92bzz1j.js";
7
9
  import"../../chunks/account-limits-cache-eqwweapz.js";
8
10
  import"../../chunks/account-limits-cache-ks1sjym9.js";
@@ -10,5 +12,6 @@ import"../../chunks/account-limits-cache-b4edaybk.js";
10
12
  export {
11
13
  convertMessages3 as convertMessages,
12
14
  convertTools3 as convertTools,
13
- normalizeToolCallId2 as normalizeToolCallId
15
+ normalizeToolCallId2 as normalizeToolCallId,
16
+ prefersStrictSampling2 as prefersStrictSampling
14
17
  };
@@ -12,6 +12,10 @@ import {
12
12
  import {
13
13
  splitDeferredTools2
14
14
  } from "../../chunks/account-limits-cache-8s8bz4dr.js";
15
+ import {
16
+ createAssistantMessageDiagnostic2,
17
+ appendAssistantMessageDiagnostic2
18
+ } from "../../chunks/account-limits-cache-9wqk28n5.js";
15
19
  import {
16
20
  headersToRecord2
17
21
  } from "../../chunks/account-limits-cache-ag5b8dja.js";
@@ -19,7 +23,7 @@ import {
19
23
  repairJson2,
20
24
  parseStreamingJson2,
21
25
  parseToolCallArguments2
22
- } from "../../chunks/account-limits-cache-fbkaq46e.js";
26
+ } from "../../chunks/account-limits-cache-z9mfzg68.js";
23
27
  import"../../chunks/account-limits-cache-j2bt392s.js";
24
28
  import {
25
29
  retryProviderRequest2
@@ -63,7 +67,7 @@ import {
63
67
  } from "../../chunks/account-limits-cache-k0pkzhbx.js";
64
68
  import {
65
69
  transformMessages2
66
- } from "../../chunks/account-limits-cache-8qzk56vj.js";
70
+ } from "../../chunks/account-limits-cache-4qpef10z.js";
67
71
  import {
68
72
  toClaudeCodeName2,
69
73
  fromClaudeCodeName2
@@ -90,10 +94,12 @@ import"../../chunks/account-limits-cache-h92bzz1j.js";
90
94
  import {
91
95
  normalizeToolCallId2,
92
96
  convertMessages3,
97
+ prefersStrictSampling2,
93
98
  convertTools3
94
- } from "../../chunks/account-limits-cache-j8c5ra3q.js";
99
+ } from "../../chunks/account-limits-cache-wawwj02k.js";
95
100
 
96
101
  // src/api/anthropic-messages.ts
102
+ import Anthropic from "@anthropic-ai/sdk";
97
103
  import { Type } from "typebox";
98
104
  import { Value } from "typebox/value";
99
105
  function getCacheControl(model, cacheRetention, env) {
@@ -215,8 +221,6 @@ var stream = (model, context, requested) => {
215
221
  client = created.client;
216
222
  isOAuth = created.isOAuthToken;
217
223
  }
218
- const params = buildParams(model, normalizedContext, isOAuth, nativeToolChanges, options);
219
- await options?.onPayload?.(params, model);
220
224
  const requestOptions = {
221
225
  signal: options?.signal,
222
226
  maxRetries: 0
@@ -232,11 +236,30 @@ var stream = (model, context, requested) => {
232
236
  requestOptions.headers = requestBetas.reduce(appendAnthropicBeta2, mergeAnthropicHeaders2(model.headers, options.headers));
233
237
  }
234
238
  }
235
- const response = await retryProviderRequest2(() => client.beta.messages.create({ ...params, stream: true }, requestOptions).asResponse(), {
236
- maxRetries: options?.maxRetries,
237
- maxRetryDelayMs: options?.maxRetryDelayMs,
238
- signal: options?.signal
239
- });
239
+ const send = async (disablePreferredStrictTools) => {
240
+ const built = buildParams(model, normalizedContext, isOAuth, nativeToolChanges, options, disablePreferredStrictTools);
241
+ await options?.onPayload?.(built.params, model);
242
+ try {
243
+ return await retryProviderRequest2(() => client.beta.messages.create({ ...built.params, stream: true }, requestOptions).asResponse(), {
244
+ maxRetries: options?.maxRetries,
245
+ maxRetryDelayMs: options?.maxRetryDelayMs,
246
+ signal: options?.signal
247
+ });
248
+ } catch (error) {
249
+ if (disablePreferredStrictTools || !built.hasPreferredStrictTools || !(error instanceof Anthropic.APIError) || error.status !== 400 || error.type !== "invalid_request_error" || ![
250
+ "The compiled grammar is too large",
251
+ "Too many strict tools (",
252
+ "Schemas contains too many parameters with union types ("
253
+ ].some((message) => error.message.includes(message))) {
254
+ throw error;
255
+ }
256
+ appendAssistantMessageDiagnostic2(output, createAssistantMessageDiagnostic2("anthropic_strict_tools_fallback", error, {
257
+ reason: "strict_tool_limits_exceeded"
258
+ }));
259
+ return send(true);
260
+ }
261
+ };
262
+ const response = await send(false);
240
263
  const responseHeaders = headersToRecord2(response.headers);
241
264
  await options?.onResponse?.({ status: response.status, headers: responseHeaders }, model);
242
265
  if (options?.onAccountLimits !== undefined) {
@@ -453,9 +476,17 @@ function systemBlock(text, cacheControl) {
453
476
  return block;
454
477
  }
455
478
  var AnthropicMetadataSchema = Type.Object({ user_id: Type.String() });
456
- function buildParams(model, context, isOAuthToken, nativeToolChanges, options) {
479
+ function buildParams(model, context, isOAuthToken, nativeToolChanges, options, disablePreferredStrictTools) {
457
480
  const cacheControl = getCacheControl(model, options?.cacheRetention, options?.env);
458
481
  const compat = getAnthropicCompat2(model);
482
+ let hasPreferredStrictTools = false;
483
+ const toolDefinitions = (tools, toolCacheControl, deferLoading = false) => {
484
+ const definitions = convertTools3(tools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl, deferLoading, disablePreferredStrictTools);
485
+ if (tools.some((tool, index) => prefersStrictSampling2(tool) && definitions[index].strict)) {
486
+ hasPreferredStrictTools = true;
487
+ }
488
+ return definitions;
489
+ };
459
490
  const initialSystemMessage = getInitialSystemMessage2(context.messages);
460
491
  const initialSystemText = initialSystemMessage ? getSystemMessageText2(initialSystemMessage) : "";
461
492
  const transformedMessages = transformMessages2(context.messages, model, normalizeToolCallId2);
@@ -494,14 +525,14 @@ function buildParams(model, context, isOAuthToken, nativeToolChanges, options) {
494
525
  const initialNames = new Set(initialTools.map((tool) => tool.name));
495
526
  const laterTools = getDeclaredTools2(context.messages).filter((tool) => !initialNames.has(tool.name));
496
527
  params.tools = [
497
- ...convertTools3(initialTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl),
528
+ ...toolDefinitions(initialTools, toolCacheControl),
498
529
  DEFERRED_TOOL_PLACEHOLDER,
499
- ...convertTools3(laterTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools).map((tool) => ({ ...tool, defer_loading: true }))
530
+ ...toolDefinitions(laterTools, undefined, true)
500
531
  ];
501
532
  } else if (immediateTools.length > 0 || deferredTools.length > 0) {
502
533
  params.tools = [
503
- ...convertTools3(immediateTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl),
504
- ...convertTools3(deferredTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, undefined, true)
534
+ ...toolDefinitions(immediateTools, toolCacheControl),
535
+ ...toolDefinitions(deferredTools, undefined, true)
505
536
  ];
506
537
  }
507
538
  if (model.reasoning) {
@@ -543,7 +574,7 @@ function buildParams(model, context, isOAuthToken, nativeToolChanges, options) {
543
574
  if (allowedFallbackModels && allowedFallbackModels.length > 0) {
544
575
  params.fallbacks = allowedFallbackModels.map((fallback) => ({ model: fallback.model }));
545
576
  }
546
- return params;
577
+ return { params, hasPreferredStrictTools };
547
578
  }
548
579
  function mapStopReason(delta) {
549
580
  const reason = delta.stop_reason;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  anthropicMessagesApi2
3
- } from "../../chunks/account-limits-cache-92q56978.js";
3
+ } from "../../chunks/account-limits-cache-3as87r3h.js";
4
4
  import"../../chunks/account-limits-cache-90c9c2eb.js";
5
5
  import"../../chunks/account-limits-cache-fsktnetm.js";
6
6
  import"../../chunks/account-limits-cache-zcbkmrvy.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  compactOpenAICodexContext2,
3
3
  compactOpenAIResponsesContext2
4
- } from "../../chunks/account-limits-cache-fdhrgjpr.js";
4
+ } from "../../chunks/account-limits-cache-yck8f1w5.js";
5
5
  import"../../chunks/account-limits-cache-031vfpt3.js";
6
6
  import"../../chunks/account-limits-cache-f9z00x8c.js";
7
7
  export {
@@ -41,7 +41,7 @@ import {
41
41
  } from "../../chunks/account-limits-cache-k0pkzhbx.js";
42
42
  import {
43
43
  transformMessages2
44
- } from "../../chunks/account-limits-cache-8qzk56vj.js";
44
+ } from "../../chunks/account-limits-cache-4qpef10z.js";
45
45
 
46
46
  // src/api/google-generative-ai.ts
47
47
  import {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  googleGenerativeAIApi2
3
- } from "../../chunks/account-limits-cache-hxy4942k.js";
3
+ } from "../../chunks/account-limits-cache-khyz4r1r.js";
4
4
  import"../../chunks/account-limits-cache-90c9c2eb.js";
5
5
  import"../../chunks/account-limits-cache-fsktnetm.js";
6
6
  import"../../chunks/account-limits-cache-zcbkmrvy.js";