@absolutejs/ai 0.1.1 → 0.1.3

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.
@@ -877,11 +877,12 @@ var extractUsage = (response) => {
877
877
  const outputDetails = isRecord(usage.output_tokens_details) ? usage.output_tokens_details : undefined;
878
878
  const inputDetails = isRecord(usage.input_tokens_details) ? usage.input_tokens_details : undefined;
879
879
  const costDetails = isRecord(usage.cost_details) ? usage.cost_details : undefined;
880
+ const written = inputDetails && typeof inputDetails.cache_write_tokens === "number" ? inputDetails.cache_write_tokens : 0;
880
881
  const normalized = {
881
882
  cacheReadInputTokens: cached,
882
- cacheWriteInputTokens: inputDetails && typeof inputDetails.cache_write_tokens === "number" ? inputDetails.cache_write_tokens : undefined,
883
+ cacheWriteInputTokens: written || undefined,
883
884
  costCredits: typeof usage.cost === "number" ? usage.cost : undefined,
884
- inputTokens: Math.max(0, input - cached),
885
+ inputTokens: Math.max(0, input - cached - written),
885
886
  outputTokens: typeof usage.output_tokens === "number" ? usage.output_tokens : 0,
886
887
  reasoningTokens: outputDetails && typeof outputDetails.reasoning_tokens === "number" ? outputDetails.reasoning_tokens : undefined,
887
888
  upstreamInferenceCostCredits: costDetails && typeof costDetails.upstream_inference_cost === "number" ? costDetails.upstream_inference_cost : undefined
@@ -1262,30 +1263,6 @@ var buildToolMessages = (blocks) => {
1262
1263
  }
1263
1264
  return messages;
1264
1265
  };
1265
- var processMessageAtIndex = (result, msg, idx) => {
1266
- if (!hasArrayContent(msg)) {
1267
- return;
1268
- }
1269
- const hasToolBlocks2 = msg.content.some((block) => block.type === "tool_use" || block.type === "tool_result");
1270
- if (!hasToolBlocks2) {
1271
- return;
1272
- }
1273
- const toolMessages = buildToolMessages(msg.content);
1274
- result.splice(idx, 1, ...toolMessages);
1275
- };
1276
- var convertSingleMessage = (result, msg, idx) => {
1277
- if (!msg) {
1278
- return;
1279
- }
1280
- processMessageAtIndex(result, msg, idx);
1281
- };
1282
- var convertToolResultMessages = (messages, params) => {
1283
- const result = [...messages];
1284
- for (let idx = 0;idx < params.messages.length; idx++) {
1285
- convertSingleMessage(result, params.messages[idx], idx);
1286
- }
1287
- return result;
1288
- };
1289
1266
  var mapToolDefinitions = (tools) => tools.map((tool) => ({
1290
1267
  function: {
1291
1268
  description: tool.description,
@@ -1342,10 +1319,11 @@ var mapOpenAIContent = (msg) => {
1342
1319
  return msg.content.map(mapContentBlockToOpenAI).filter((mapped) => mapped !== null);
1343
1320
  };
1344
1321
  var buildRequestBody = (params, capabilityModel = params.model) => {
1345
- const messages = convertToolResultMessages(params.messages.map((msg) => ({
1346
- content: mapOpenAIContent(msg),
1347
- role: msg.role
1348
- })), params);
1322
+ const messages = params.messages.flatMap((msg) => {
1323
+ if (hasArrayContent(msg) && msg.content.some((block) => block.type === "tool_use" || block.type === "tool_result"))
1324
+ return buildToolMessages(msg.content);
1325
+ return [{ content: mapOpenAIContent(msg), role: msg.role }];
1326
+ });
1349
1327
  if (params.systemPrompt) {
1350
1328
  messages.unshift({ content: params.systemPrompt, role: "system" });
1351
1329
  }
@@ -1433,11 +1411,12 @@ var flushPendingToolCalls = function* (pendingToolCalls) {
1433
1411
  var extractUsage2 = (parsedUsage) => {
1434
1412
  const prompt = parsedUsage.prompt_tokens ?? 0;
1435
1413
  const cached = parsedUsage.cached_tokens ?? 0;
1414
+ const written = parsedUsage.cache_write_tokens ?? 0;
1436
1415
  return {
1437
1416
  cacheReadInputTokens: cached,
1438
- cacheWriteInputTokens: parsedUsage.cache_write_tokens || undefined,
1417
+ cacheWriteInputTokens: written || undefined,
1439
1418
  costCredits: parsedUsage.cost,
1440
- inputTokens: Math.max(0, prompt - cached),
1419
+ inputTokens: Math.max(0, prompt - cached - written),
1441
1420
  outputTokens: parsedUsage.completion_tokens ?? 0,
1442
1421
  reasoningTokens: parsedUsage.reasoning_tokens || undefined,
1443
1422
  upstreamInferenceCostCredits: parsedUsage.upstream_inference_cost || undefined
@@ -1809,5 +1788,5 @@ export {
1809
1788
  xai
1810
1789
  };
1811
1790
 
1812
- //# debugId=4F4027EEB930CE6D64756E2164756E21
1791
+ //# debugId=E875F1C4139B39C064756E2164756E21
1813
1792
  //# sourceMappingURL=openaiCompatible.js.map