@providerprotocol/ai 0.0.23 → 0.0.24

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.
@@ -1,4 +1,4 @@
1
- import { g as Provider } from '../provider-DR1yins0.js';
1
+ import { g as Provider } from '../provider-x4RocsnK.js';
2
2
 
3
3
  /**
4
4
  * @fileoverview Anthropic API type definitions.
@@ -11,10 +11,10 @@ import {
11
11
  isAssistantMessage,
12
12
  isToolResultMessage,
13
13
  isUserMessage
14
- } from "../chunk-MF5ETY5O.js";
14
+ } from "../chunk-6AZVUI6H.js";
15
15
  import {
16
16
  parseSSEStream
17
- } from "../chunk-NWS5IKNR.js";
17
+ } from "../chunk-TOJCZMVU.js";
18
18
  import {
19
19
  resolveApiKey
20
20
  } from "../chunk-55X3W2MN.js";
@@ -277,9 +277,26 @@ function transformMessage(message) {
277
277
  }
278
278
  if (isAssistantMessage(message)) {
279
279
  const validContent = filterValidContent(message.content);
280
- const content = validContent.map(
281
- (block, index, arr) => transformContentBlock(block, index === arr.length - 1 && !message.toolCalls?.length ? cacheControl : void 0)
282
- );
280
+ const content = [];
281
+ const anthropicMeta = message.metadata?.anthropic;
282
+ const thinkingSignatures = anthropicMeta?.thinkingSignatures;
283
+ let reasoningIndex = 0;
284
+ for (let i = 0; i < validContent.length; i++) {
285
+ const block = validContent[i];
286
+ const isLastNonToolBlock = i === validContent.length - 1 && !message.toolCalls?.length;
287
+ if (block.type === "reasoning") {
288
+ const signatureFromArray = thinkingSignatures?.[reasoningIndex];
289
+ const signature = Array.isArray(thinkingSignatures) ? typeof signatureFromArray === "string" ? signatureFromArray : void 0 : anthropicMeta?.thinkingSignature;
290
+ reasoningIndex += 1;
291
+ content.push({
292
+ type: "thinking",
293
+ thinking: block.text,
294
+ ...signature ? { signature } : {}
295
+ });
296
+ } else {
297
+ content.push(transformContentBlock(block, isLastNonToolBlock ? cacheControl : void 0));
298
+ }
299
+ }
283
300
  if (message.toolCalls) {
284
301
  for (let i = 0; i < message.toolCalls.length; i++) {
285
302
  const call = message.toolCalls[i];
@@ -382,11 +399,20 @@ function transformTool(tool) {
382
399
  };
383
400
  }
384
401
  function transformResponse(data, useNativeStructuredOutput = false) {
402
+ const reasoningContent = [];
385
403
  const textContent = [];
386
404
  const toolCalls = [];
387
405
  let structuredData;
406
+ let thinkingSignature;
407
+ const thinkingSignatures = [];
388
408
  for (const block of data.content) {
389
- if (block.type === "text") {
409
+ if (block.type === "thinking") {
410
+ reasoningContent.push({ type: "reasoning", text: block.thinking });
411
+ if (block.signature) {
412
+ thinkingSignature = block.signature;
413
+ }
414
+ thinkingSignatures.push(block.signature ?? null);
415
+ } else if (block.type === "text") {
390
416
  textContent.push({ type: "text", text: block.text });
391
417
  if (useNativeStructuredOutput && structuredData === void 0) {
392
418
  try {
@@ -419,8 +445,10 @@ ${block.content.content}\`\`\`
419
445
  }
420
446
  }
421
447
  }
448
+ const allContent = [...reasoningContent, ...textContent];
449
+ const hasThinkingSignatures = thinkingSignatures.some((signature) => signature);
422
450
  const message = new AssistantMessage(
423
- textContent,
451
+ allContent,
424
452
  toolCalls.length > 0 ? toolCalls : void 0,
425
453
  {
426
454
  id: data.id,
@@ -428,7 +456,9 @@ ${block.content.content}\`\`\`
428
456
  anthropic: {
429
457
  stop_reason: data.stop_reason,
430
458
  stop_sequence: data.stop_sequence,
431
- model: data.model
459
+ model: data.model,
460
+ thinkingSignature,
461
+ ...hasThinkingSignatures ? { thinkingSignatures } : {}
432
462
  }
433
463
  }
434
464
  }
@@ -471,7 +501,9 @@ function transformStreamEvent(event, state) {
471
501
  events.push({ type: StreamEventType.MessageStart, index: 0, delta: {} });
472
502
  break;
473
503
  case "content_block_start":
474
- if (event.content_block.type === "text") {
504
+ if (event.content_block.type === "thinking") {
505
+ state.content[event.index] = { type: "thinking", thinking: "" };
506
+ } else if (event.content_block.type === "text") {
475
507
  state.content[event.index] = { type: "text", text: "" };
476
508
  } else if (event.content_block.type === "tool_use") {
477
509
  state.content[event.index] = {
@@ -533,6 +565,9 @@ function transformStreamEvent(event, state) {
533
565
  break;
534
566
  }
535
567
  if (delta.type === "thinking_delta") {
568
+ if (state.content[event.index]) {
569
+ state.content[event.index].thinking = (state.content[event.index].thinking ?? "") + delta.thinking;
570
+ }
536
571
  events.push({
537
572
  type: StreamEventType.ReasoningDelta,
538
573
  index: event.index,
@@ -540,6 +575,12 @@ function transformStreamEvent(event, state) {
540
575
  });
541
576
  break;
542
577
  }
578
+ if (delta.type === "signature_delta") {
579
+ if (state.content[event.index]) {
580
+ state.content[event.index].signature = delta.signature;
581
+ }
582
+ break;
583
+ }
543
584
  break;
544
585
  }
545
586
  case "content_block_stop":
@@ -561,12 +602,21 @@ function transformStreamEvent(event, state) {
561
602
  return events;
562
603
  }
563
604
  function buildResponseFromState(state, useNativeStructuredOutput = false) {
605
+ const reasoningContent = [];
564
606
  const textContent = [];
565
607
  const toolCalls = [];
566
608
  let structuredData;
609
+ let thinkingSignature;
610
+ const thinkingSignatures = [];
567
611
  for (const block of state.content) {
568
612
  if (!block) continue;
569
- if (block.type === "text" && block.text) {
613
+ if (block.type === "thinking" && block.thinking) {
614
+ reasoningContent.push({ type: "reasoning", text: block.thinking });
615
+ if (block.signature) {
616
+ thinkingSignature = block.signature;
617
+ }
618
+ thinkingSignatures.push(block.signature ?? null);
619
+ } else if (block.type === "text" && block.text) {
570
620
  textContent.push({ type: "text", text: block.text });
571
621
  if (useNativeStructuredOutput && structuredData === void 0) {
572
622
  try {
@@ -602,16 +652,20 @@ ${block.fileContent}\`\`\`
602
652
  ` });
603
653
  }
604
654
  }
655
+ const allContent = [...reasoningContent, ...textContent];
656
+ const hasThinkingSignatures = thinkingSignatures.some((signature) => signature);
605
657
  const messageId = state.messageId || generateId();
606
658
  const message = new AssistantMessage(
607
- textContent,
659
+ allContent,
608
660
  toolCalls.length > 0 ? toolCalls : void 0,
609
661
  {
610
662
  id: messageId,
611
663
  metadata: {
612
664
  anthropic: {
613
665
  stop_reason: state.stopReason,
614
- model: state.model
666
+ model: state.model,
667
+ thinkingSignature,
668
+ ...hasThinkingSignatures ? { thinkingSignatures } : {}
615
669
  }
616
670
  }
617
671
  }