@bastani/atomic-ai 0.10.1-alpha.1 → 0.10.2-alpha.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 (58) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/api/anthropic-messages.d.ts.map +1 -1
  3. package/dist/api/anthropic-messages.js +108 -40
  4. package/dist/api/anthropic-messages.js.map +1 -1
  5. package/dist/api/azure-openai-responses.js +2 -2
  6. package/dist/api/azure-openai-responses.js.map +1 -1
  7. package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
  8. package/dist/api/bedrock-converse-stream.js +51 -19
  9. package/dist/api/bedrock-converse-stream.js.map +1 -1
  10. package/dist/api/google-generative-ai.js +2 -2
  11. package/dist/api/google-generative-ai.js.map +1 -1
  12. package/dist/api/google-shared.js +2 -2
  13. package/dist/api/google-shared.js.map +1 -1
  14. package/dist/api/google-vertex.js +2 -2
  15. package/dist/api/google-vertex.js.map +1 -1
  16. package/dist/api/mistral-conversations.d.ts.map +1 -1
  17. package/dist/api/mistral-conversations.js +13 -7
  18. package/dist/api/mistral-conversations.js.map +1 -1
  19. package/dist/api/openai-codex-responses.js +2 -2
  20. package/dist/api/openai-codex-responses.js.map +1 -1
  21. package/dist/api/openai-completions.d.ts.map +1 -1
  22. package/dist/api/openai-completions.js +35 -11
  23. package/dist/api/openai-completions.js.map +1 -1
  24. package/dist/api/openai-responses-shared.d.ts.map +1 -1
  25. package/dist/api/openai-responses-shared.js +2 -2
  26. package/dist/api/openai-responses-shared.js.map +1 -1
  27. package/dist/api/openai-responses.js +2 -2
  28. package/dist/api/openai-responses.js.map +1 -1
  29. package/dist/api/simple-options.d.ts +13 -0
  30. package/dist/api/simple-options.d.ts.map +1 -1
  31. package/dist/api/simple-options.js +19 -0
  32. package/dist/api/simple-options.js.map +1 -1
  33. package/dist/api/strict-tool-limits.d.ts +9 -0
  34. package/dist/api/strict-tool-limits.d.ts.map +1 -1
  35. package/dist/api/strict-tool-limits.js +22 -0
  36. package/dist/api/strict-tool-limits.js.map +1 -1
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/providers/data/.manifest.json +1 -1
  42. package/dist/providers/data/openrouter.json +1 -1
  43. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  44. package/dist/types.d.ts +23 -0
  45. package/dist/types.d.ts.map +1 -1
  46. package/dist/types.js.map +1 -1
  47. package/dist/utils/tool-results-bridge.d.ts +7 -0
  48. package/dist/utils/tool-results-bridge.d.ts.map +1 -0
  49. package/dist/utils/tool-results-bridge.js +7 -0
  50. package/dist/utils/tool-results-bridge.js.map +1 -0
  51. package/dist/utils/transcript.d.ts +35 -3
  52. package/dist/utils/transcript.d.ts.map +1 -1
  53. package/dist/utils/transcript.js +136 -5
  54. package/dist/utils/transcript.js.map +1 -1
  55. package/dist/utils/version.d.ts +1 -1
  56. package/dist/utils/version.js +1 -1
  57. package/dist/utils/version.js.map +1 -1
  58. package/package.json +3 -3
@@ -17,9 +17,10 @@ import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
17
17
  import { DoneEventWatch } from "../utils/sse.js";
18
18
  import { createStreamDeadline, withStreamDeadline } from "../utils/stream-deadline.js";
19
19
  import { ToolCallArgumentsStream } from "../utils/streaming-json.js";
20
+ import { TOOL_RESULTS_BRIDGE_TEXT } from "../utils/tool-results-bridge.js";
20
21
  import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.js";
21
22
  import { recordLowestThinkingOffFallback, recordThinkingOffFallback } from "../utils/thinking-off.js";
22
- import { getDeclaredTools, resolveTranscript, resolveTranscriptTools, } from "../utils/transcript.js";
23
+ import { getDeclaredTools, resolveRequestTranscript, resolveTranscriptTools, } from "../utils/transcript.js";
23
24
  import { appendGrammarToolInputJsonDelta, closeGrammarToolInputJson, createGrammarToolInputProperties, getGrammarToolInput, getJsonSchemaToolParameters, resolveGrammarConstrainedSampling, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
24
25
  import { buildCopilotDynamicHeaders, hasCopilotVisionInput, preserveCopilotIntegrationHeader, } from "./github-copilot-headers.js";
25
26
  import { clampOpenAIPromptCacheKey } from "./openai-prompt-cache.js";
@@ -185,7 +186,7 @@ function resolveCacheRetention(cacheRetention, env) {
185
186
  }
186
187
  export const stream = (model, context, options) => {
187
188
  const stream = new AssistantMessageEventStream();
188
- const normalizedContext = resolveTranscript(context, getCompat(model).supportsMidConvoSystemMessages);
189
+ const normalizedContext = resolveRequestTranscript(context, getCompat(model).supportsMidConvoSystemMessages);
189
190
  (async () => {
190
191
  const output = {
191
192
  role: "assistant",
@@ -982,6 +983,10 @@ function applyAnthropicCacheControl(messages, tools, cacheControl) {
982
983
  addCacheControlToSystemPrompt(messages, cacheControl);
983
984
  addCacheControlToLastTool(tools, cacheControl);
984
985
  addCacheControlToLastConversationMessage(messages, cacheControl);
986
+ // The fourth and last breakpoint Claude allows.
987
+ const checkpoint = cacheCheckpoints.get(messages);
988
+ if (checkpoint && checkpoint !== messages.at(-1))
989
+ addCacheControlToMessage(checkpoint, cacheControl);
985
990
  }
986
991
  function addCacheControlToSystemPrompt(messages, cacheControl) {
987
992
  for (const message of messages) {
@@ -1046,7 +1051,7 @@ function addCacheControlToTextContent(message, cacheControl) {
1046
1051
  return false;
1047
1052
  }
1048
1053
  export function convertMessages(model, context, compat, options) {
1049
- const normalizedContext = resolveTranscript(context, compat.supportsMidConvoSystemMessages);
1054
+ const normalizedContext = resolveRequestTranscript(context, compat.supportsMidConvoSystemMessages);
1050
1055
  const params = [];
1051
1056
  const normalizeToolCallId = (id) => {
1052
1057
  // Handle pipe-separated IDs from OpenAI Responses API
@@ -1080,14 +1085,23 @@ export function convertMessages(model, context, compat, options) {
1080
1085
  const instructionRole = model.reasoning && compat.supportsDeveloperRole ? "developer" : "system";
1081
1086
  let lastRole = null;
1082
1087
  let systemIndex = 0;
1088
+ // The input sent up to a message with a `cacheBreakpoint` hint ends with the last user or tool message so far.
1089
+ let checkpoint;
1090
+ const markCheckpoint = () => {
1091
+ const last = params.at(-1);
1092
+ if (last?.role === "user" || last?.role === "tool")
1093
+ checkpoint = last;
1094
+ };
1083
1095
  for (let i = 0; i < transformedMessages.length; i++) {
1084
1096
  const msg = transformedMessages[i];
1097
+ if (msg.role === "assistant" && msg.cacheBreakpoint)
1098
+ markCheckpoint();
1085
1099
  // Some providers don't allow user messages directly after tool results
1086
1100
  // Insert a synthetic assistant message to bridge the gap
1087
1101
  if (compat.requiresAssistantAfterToolResult && lastRole === "toolResult" && msg.role === "user") {
1088
1102
  params.push({
1089
1103
  role: "assistant",
1090
- content: "I have processed the tool results.",
1104
+ content: TOOL_RESULTS_BRIDGE_TEXT,
1091
1105
  });
1092
1106
  }
1093
1107
  if (msg.role === "system") {
@@ -1131,13 +1145,17 @@ export function convertMessages(model, context, compat, options) {
1131
1145
  };
1132
1146
  }
1133
1147
  });
1134
- if (content.length === 0)
1135
- continue;
1136
- params.push({
1137
- role: "user",
1138
- content,
1139
- });
1148
+ if (content.length > 0) {
1149
+ params.push({
1150
+ role: "user",
1151
+ content,
1152
+ });
1153
+ }
1140
1154
  }
1155
+ if (msg.cacheBreakpoint)
1156
+ markCheckpoint();
1157
+ if (params.at(-1)?.role !== "user")
1158
+ continue;
1141
1159
  }
1142
1160
  else if (msg.role === "assistant") {
1143
1161
  // Some providers don't accept null content, use empty string instead
@@ -1286,12 +1304,14 @@ export function convertMessages(model, context, compat, options) {
1286
1304
  }
1287
1305
  }
1288
1306
  }
1307
+ if (transformedMessages.slice(i, j).some((message) => message.role === "toolResult" && message.cacheBreakpoint))
1308
+ markCheckpoint();
1289
1309
  i = j - 1;
1290
1310
  if (imageBlocks.length > 0) {
1291
1311
  if (compat.requiresAssistantAfterToolResult) {
1292
1312
  params.push({
1293
1313
  role: "assistant",
1294
- content: "I have processed the tool results.",
1314
+ content: TOOL_RESULTS_BRIDGE_TEXT,
1295
1315
  });
1296
1316
  }
1297
1317
  params.push({
@@ -1313,8 +1333,12 @@ export function convertMessages(model, context, compat, options) {
1313
1333
  }
1314
1334
  lastRole = msg.role;
1315
1335
  }
1336
+ if (checkpoint)
1337
+ cacheCheckpoints.set(params, checkpoint);
1316
1338
  return params;
1317
1339
  }
1340
+ /** The message a `cacheBreakpoint` hint asked a breakpoint for, by the message list `convertMessages` returned. */
1341
+ const cacheCheckpoints = new WeakMap();
1318
1342
  function convertTools(tools, compat) {
1319
1343
  return tools.map((tool) => {
1320
1344
  const grammar = resolveGrammarConstrainedSampling(tool, compat.supportsOpenAIGrammarTools);