@providerprotocol/ai 0.0.23 → 0.0.25
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/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +66 -12
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-MF5ETY5O.js → chunk-6AZVUI6H.js} +8 -1
- package/dist/chunk-6AZVUI6H.js.map +1 -0
- package/dist/{chunk-NWS5IKNR.js → chunk-TOJCZMVU.js} +3 -12
- package/dist/chunk-TOJCZMVU.js.map +1 -0
- package/dist/google/index.d.ts +34 -3
- package/dist/google/index.js +62 -22
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +1 -1
- package/dist/ollama/index.js +14 -8
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +1 -1
- package/dist/openai/index.js +60 -4
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +60 -1
- package/dist/openrouter/index.js +116 -21
- package/dist/openrouter/index.js.map +1 -1
- package/dist/{provider-DR1yins0.d.ts → provider-x4RocsnK.d.ts} +52 -3
- package/dist/proxy/index.d.ts +2 -2
- package/dist/proxy/index.js +1 -1
- package/dist/{retry-DJiqAslw.d.ts → retry-DTfjXXPh.d.ts} +1 -1
- package/dist/{stream-BuTrqt_j.d.ts → stream-ITNFNnO4.d.ts} +6 -1
- package/dist/xai/index.d.ts +1 -1
- package/dist/xai/index.js +151 -32
- package/dist/xai/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-MF5ETY5O.js.map +0 -1
- package/dist/chunk-NWS5IKNR.js.map +0 -1
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
declare const ContentBlockType: {
|
|
27
27
|
/** Text content */
|
|
28
28
|
readonly Text: "text";
|
|
29
|
+
/** Reasoning/thinking content from extended thinking models */
|
|
30
|
+
readonly Reasoning: "reasoning";
|
|
29
31
|
/** Image content */
|
|
30
32
|
readonly Image: "image";
|
|
31
33
|
/** Audio content */
|
|
@@ -124,6 +126,26 @@ interface TextBlock {
|
|
|
124
126
|
/** The text content */
|
|
125
127
|
text: string;
|
|
126
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Reasoning content block.
|
|
131
|
+
*
|
|
132
|
+
* Contains model reasoning/thinking from extended thinking or chain-of-thought.
|
|
133
|
+
* This content represents the model's internal reasoning process.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* const reasoningBlock: ReasoningBlock = {
|
|
138
|
+
* type: 'reasoning',
|
|
139
|
+
* text: 'Let me think about this step by step...'
|
|
140
|
+
* };
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
interface ReasoningBlock {
|
|
144
|
+
/** Discriminator for reasoning blocks */
|
|
145
|
+
type: 'reasoning';
|
|
146
|
+
/** The reasoning/thinking text */
|
|
147
|
+
text: string;
|
|
148
|
+
}
|
|
127
149
|
/**
|
|
128
150
|
* Image content block.
|
|
129
151
|
*
|
|
@@ -238,7 +260,7 @@ interface BinaryBlock {
|
|
|
238
260
|
*
|
|
239
261
|
* Used when a function or property can accept any type of content block.
|
|
240
262
|
*/
|
|
241
|
-
type ContentBlock = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
|
|
263
|
+
type ContentBlock = TextBlock | ReasoningBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBlock;
|
|
242
264
|
/**
|
|
243
265
|
* Content types allowed in user messages.
|
|
244
266
|
*
|
|
@@ -250,7 +272,7 @@ type UserContent = TextBlock | ImageBlock | AudioBlock | VideoBlock | BinaryBloc
|
|
|
250
272
|
*
|
|
251
273
|
* Assistants can generate text and media but not arbitrary binary data.
|
|
252
274
|
*/
|
|
253
|
-
type AssistantContent = TextBlock | ImageBlock | AudioBlock | VideoBlock;
|
|
275
|
+
type AssistantContent = TextBlock | ReasoningBlock | ImageBlock | AudioBlock | VideoBlock;
|
|
254
276
|
/**
|
|
255
277
|
* Creates a text content block from a string.
|
|
256
278
|
*
|
|
@@ -264,6 +286,19 @@ type AssistantContent = TextBlock | ImageBlock | AudioBlock | VideoBlock;
|
|
|
264
286
|
* ```
|
|
265
287
|
*/
|
|
266
288
|
declare function text(content: string): TextBlock;
|
|
289
|
+
/**
|
|
290
|
+
* Creates a reasoning content block from a string.
|
|
291
|
+
*
|
|
292
|
+
* @param content - The reasoning/thinking content
|
|
293
|
+
* @returns A ReasoningBlock containing the provided text
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* const block = reasoning('Let me think step by step...');
|
|
298
|
+
* // { type: 'reasoning', text: 'Let me think step by step...' }
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
declare function reasoning(content: string): ReasoningBlock;
|
|
267
302
|
/**
|
|
268
303
|
* Type guard for TextBlock.
|
|
269
304
|
*
|
|
@@ -278,6 +313,20 @@ declare function text(content: string): TextBlock;
|
|
|
278
313
|
* ```
|
|
279
314
|
*/
|
|
280
315
|
declare function isTextBlock(block: ContentBlock): block is TextBlock;
|
|
316
|
+
/**
|
|
317
|
+
* Type guard for ReasoningBlock.
|
|
318
|
+
*
|
|
319
|
+
* @param block - The content block to check
|
|
320
|
+
* @returns True if the block is a ReasoningBlock
|
|
321
|
+
*
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* if (isReasoningBlock(block)) {
|
|
325
|
+
* console.log(block.text);
|
|
326
|
+
* }
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
declare function isReasoningBlock(block: ContentBlock): block is ReasoningBlock;
|
|
281
330
|
/**
|
|
282
331
|
* Type guard for ImageBlock.
|
|
283
332
|
*
|
|
@@ -1422,4 +1471,4 @@ type ImageProvider<TParams = unknown, TOptions = unknown> = Provider<TOptions> &
|
|
|
1422
1471
|
readonly __params?: TParams;
|
|
1423
1472
|
};
|
|
1424
1473
|
|
|
1425
|
-
export { type
|
|
1474
|
+
export { type ImageCapabilities as $, type AssistantContent as A, type BoundEmbeddingModel as B, type ContentBlock as C, type RetryStrategy as D, type EmbeddingInput as E, type EmbeddingProvider as F, type ImageProvider as G, type EmbeddingRequest as H, type ImageOptions as I, type EmbeddingResponse as J, type KeyStrategy as K, type LLMProvider as L, type ModelReference as M, type EmbeddingVector as N, type ImageInput as O, type ProviderIdentity as P, type ImageEditInput as Q, type ReasoningBlock as R, type ImageGenerateOptions as S, type TextBlock as T, type UserContent as U, type VideoBlock as V, type GeneratedImage as W, type ImageUsage as X, type ImageResult as Y, type ImageStreamEvent as Z, type ImageStreamResult as _, type ProviderConfig as a, type ImageRequest as a0, type ImageEditRequest as a1, type ImageResponse as a2, type ImageProviderStreamResult as a3, type BoundImageModel as a4, type ImageHandler$1 as a5, type ImageModelInput as a6, type EmbeddingUsage as b, type ImageInstance as c, type LLMHandler as d, type EmbeddingHandler as e, type ImageHandler as f, type Provider as g, Image as h, UPPError as i, ErrorCode as j, ModalityType as k, type Modality as l, type ImageBlock as m, type AudioBlock as n, type BinaryBlock as o, type ImageSource as p, ContentBlockType as q, ImageSourceType as r, reasoning as s, text as t, isTextBlock as u, isReasoningBlock as v, isImageBlock as w, isAudioBlock as x, isVideoBlock as y, isBinaryBlock as z };
|
package/dist/proxy/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { g as Provider, M as ModelReference } from '../provider-
|
|
2
|
-
import { M as Message, b as MessageJSON, T as Turn, I as TurnJSON, f as StreamEvent, S as StreamResult, J as JSONSchema, k as ToolMetadata, c as Tool } from '../stream-
|
|
1
|
+
import { g as Provider, M as ModelReference } from '../provider-x4RocsnK.js';
|
|
2
|
+
import { M as Message, b as MessageJSON, T as Turn, I as TurnJSON, f as StreamEvent, S as StreamResult, J as JSONSchema, k as ToolMetadata, c as Tool } from '../stream-ITNFNnO4.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @fileoverview Proxy provider types.
|
package/dist/proxy/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { K as KeyStrategy, a as ProviderConfig, l as Modality,
|
|
1
|
+
import { K as KeyStrategy, a as ProviderConfig, l as Modality, D as RetryStrategy, i as UPPError } from './provider-x4RocsnK.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* API key management strategies for load balancing and dynamic key selection.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as ContentBlock, m as ImageBlock, n as AudioBlock, V as VideoBlock, A as AssistantContent, U as UserContent } from './provider-
|
|
1
|
+
import { C as ContentBlock, m as ImageBlock, n as AudioBlock, V as VideoBlock, R as ReasoningBlock, A as AssistantContent, U as UserContent } from './provider-x4RocsnK.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @fileoverview JSON Schema types for tool parameters and structured outputs.
|
|
@@ -549,6 +549,11 @@ declare abstract class Message {
|
|
|
549
549
|
* All video content blocks in this message.
|
|
550
550
|
*/
|
|
551
551
|
get video(): VideoBlock[];
|
|
552
|
+
/**
|
|
553
|
+
* All reasoning/thinking content blocks in this message.
|
|
554
|
+
* Available when using extended thinking models.
|
|
555
|
+
*/
|
|
556
|
+
get reasoning(): ReasoningBlock[];
|
|
552
557
|
}
|
|
553
558
|
/**
|
|
554
559
|
* User input message.
|
package/dist/xai/index.d.ts
CHANGED
package/dist/xai/index.js
CHANGED
|
@@ -14,10 +14,10 @@ import {
|
|
|
14
14
|
isAssistantMessage,
|
|
15
15
|
isToolResultMessage,
|
|
16
16
|
isUserMessage
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-6AZVUI6H.js";
|
|
18
18
|
import {
|
|
19
19
|
parseSSEStream
|
|
20
|
-
} from "../chunk-
|
|
20
|
+
} from "../chunk-TOJCZMVU.js";
|
|
21
21
|
import {
|
|
22
22
|
resolveApiKey
|
|
23
23
|
} from "../chunk-55X3W2MN.js";
|
|
@@ -228,10 +228,13 @@ function transformResponse(data) {
|
|
|
228
228
|
if (!choice) {
|
|
229
229
|
throw new Error("No choices in xAI response");
|
|
230
230
|
}
|
|
231
|
-
const
|
|
231
|
+
const content = [];
|
|
232
232
|
let structuredData;
|
|
233
|
+
if (choice.message.reasoning_content) {
|
|
234
|
+
content.push({ type: "reasoning", text: choice.message.reasoning_content });
|
|
235
|
+
}
|
|
233
236
|
if (choice.message.content) {
|
|
234
|
-
|
|
237
|
+
content.push({ type: "text", text: choice.message.content });
|
|
235
238
|
try {
|
|
236
239
|
structuredData = JSON.parse(choice.message.content);
|
|
237
240
|
} catch {
|
|
@@ -239,7 +242,7 @@ function transformResponse(data) {
|
|
|
239
242
|
}
|
|
240
243
|
let hadRefusal = false;
|
|
241
244
|
if (choice.message.refusal) {
|
|
242
|
-
|
|
245
|
+
content.push({ type: "text", text: choice.message.refusal });
|
|
243
246
|
hadRefusal = true;
|
|
244
247
|
}
|
|
245
248
|
const toolCalls = [];
|
|
@@ -259,7 +262,7 @@ function transformResponse(data) {
|
|
|
259
262
|
}
|
|
260
263
|
const responseId = data.id || generateId();
|
|
261
264
|
const message = new AssistantMessage(
|
|
262
|
-
|
|
265
|
+
content,
|
|
263
266
|
toolCalls.length > 0 ? toolCalls : void 0,
|
|
264
267
|
{
|
|
265
268
|
id: responseId,
|
|
@@ -311,6 +314,7 @@ function createStreamState() {
|
|
|
311
314
|
id: "",
|
|
312
315
|
model: "",
|
|
313
316
|
text: "",
|
|
317
|
+
reasoning: "",
|
|
314
318
|
toolCalls: /* @__PURE__ */ new Map(),
|
|
315
319
|
finishReason: null,
|
|
316
320
|
inputTokens: 0,
|
|
@@ -330,6 +334,14 @@ function transformStreamEvent(chunk, state) {
|
|
|
330
334
|
}
|
|
331
335
|
const choice = chunk.choices[0];
|
|
332
336
|
if (choice) {
|
|
337
|
+
if (choice.delta.reasoning_content) {
|
|
338
|
+
state.reasoning += choice.delta.reasoning_content;
|
|
339
|
+
events.push({
|
|
340
|
+
type: StreamEventType.ReasoningDelta,
|
|
341
|
+
index: 0,
|
|
342
|
+
delta: { text: choice.delta.reasoning_content }
|
|
343
|
+
});
|
|
344
|
+
}
|
|
333
345
|
if (choice.delta.content) {
|
|
334
346
|
state.text += choice.delta.content;
|
|
335
347
|
events.push({
|
|
@@ -388,10 +400,13 @@ function transformStreamEvent(chunk, state) {
|
|
|
388
400
|
return events;
|
|
389
401
|
}
|
|
390
402
|
function buildResponseFromState(state) {
|
|
391
|
-
const
|
|
403
|
+
const content = [];
|
|
392
404
|
let structuredData;
|
|
405
|
+
if (state.reasoning) {
|
|
406
|
+
content.push({ type: "reasoning", text: state.reasoning });
|
|
407
|
+
}
|
|
393
408
|
if (state.text) {
|
|
394
|
-
|
|
409
|
+
content.push({ type: "text", text: state.text });
|
|
395
410
|
try {
|
|
396
411
|
structuredData = JSON.parse(state.text);
|
|
397
412
|
} catch {
|
|
@@ -414,7 +429,7 @@ function buildResponseFromState(state) {
|
|
|
414
429
|
}
|
|
415
430
|
const messageId = state.id || generateId();
|
|
416
431
|
const message = new AssistantMessage(
|
|
417
|
-
|
|
432
|
+
content,
|
|
418
433
|
toolCalls.length > 0 ? toolCalls : void 0,
|
|
419
434
|
{
|
|
420
435
|
id: messageId,
|
|
@@ -760,6 +775,23 @@ function transformMessage2(message) {
|
|
|
760
775
|
}
|
|
761
776
|
const xaiMeta = message.metadata?.xai;
|
|
762
777
|
const functionCallItems = xaiMeta?.functionCallItems;
|
|
778
|
+
if (xaiMeta?.reasoningEncryptedContent) {
|
|
779
|
+
try {
|
|
780
|
+
const reasoningData = JSON.parse(xaiMeta.reasoningEncryptedContent);
|
|
781
|
+
if (reasoningData.encrypted_content) {
|
|
782
|
+
const reasoningItem = {
|
|
783
|
+
type: "reasoning",
|
|
784
|
+
id: reasoningData.id,
|
|
785
|
+
encrypted_content: reasoningData.encrypted_content
|
|
786
|
+
};
|
|
787
|
+
if (Array.isArray(reasoningData.summary)) {
|
|
788
|
+
reasoningItem.summary = reasoningData.summary;
|
|
789
|
+
}
|
|
790
|
+
items.push(reasoningItem);
|
|
791
|
+
}
|
|
792
|
+
} catch {
|
|
793
|
+
}
|
|
794
|
+
}
|
|
763
795
|
if (functionCallItems && functionCallItems.length > 0) {
|
|
764
796
|
for (const fc of functionCallItems) {
|
|
765
797
|
items.push({
|
|
@@ -839,25 +871,26 @@ function transformTool2(tool) {
|
|
|
839
871
|
};
|
|
840
872
|
}
|
|
841
873
|
function transformResponse2(data) {
|
|
842
|
-
const
|
|
874
|
+
const content = [];
|
|
843
875
|
const toolCalls = [];
|
|
844
876
|
const functionCallItems = [];
|
|
845
877
|
let hadRefusal = false;
|
|
846
878
|
let structuredData;
|
|
879
|
+
let reasoningEncryptedContent;
|
|
847
880
|
for (const item of data.output) {
|
|
848
881
|
if (item.type === "message") {
|
|
849
882
|
const messageItem = item;
|
|
850
|
-
for (const
|
|
851
|
-
if (
|
|
852
|
-
|
|
883
|
+
for (const outputContent of messageItem.content) {
|
|
884
|
+
if (outputContent.type === "output_text") {
|
|
885
|
+
content.push({ type: "text", text: outputContent.text });
|
|
853
886
|
if (structuredData === void 0) {
|
|
854
887
|
try {
|
|
855
|
-
structuredData = JSON.parse(
|
|
888
|
+
structuredData = JSON.parse(outputContent.text);
|
|
856
889
|
} catch {
|
|
857
890
|
}
|
|
858
891
|
}
|
|
859
|
-
} else if (
|
|
860
|
-
|
|
892
|
+
} else if (outputContent.type === "refusal") {
|
|
893
|
+
content.push({ type: "text", text: outputContent.refusal });
|
|
861
894
|
hadRefusal = true;
|
|
862
895
|
}
|
|
863
896
|
}
|
|
@@ -879,11 +912,24 @@ function transformResponse2(data) {
|
|
|
879
912
|
name: functionCall.name,
|
|
880
913
|
arguments: functionCall.arguments
|
|
881
914
|
});
|
|
915
|
+
} else if (item.type === "reasoning") {
|
|
916
|
+
const reasoningItem = item;
|
|
917
|
+
if (reasoningItem.summary) {
|
|
918
|
+
const reasoningText = reasoningItem.summary.filter((s) => s.type === "summary_text").map((s) => s.text).join("");
|
|
919
|
+
if (reasoningText) {
|
|
920
|
+
content.push({ type: "reasoning", text: reasoningText });
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
reasoningEncryptedContent = JSON.stringify({
|
|
924
|
+
id: reasoningItem.id,
|
|
925
|
+
summary: reasoningItem.summary,
|
|
926
|
+
encrypted_content: reasoningItem.encrypted_content
|
|
927
|
+
});
|
|
882
928
|
}
|
|
883
929
|
}
|
|
884
930
|
const responseId = data.id || generateId();
|
|
885
931
|
const message = new AssistantMessage(
|
|
886
|
-
|
|
932
|
+
content,
|
|
887
933
|
toolCalls.length > 0 ? toolCalls : void 0,
|
|
888
934
|
{
|
|
889
935
|
id: responseId,
|
|
@@ -894,7 +940,8 @@ function transformResponse2(data) {
|
|
|
894
940
|
response_id: responseId,
|
|
895
941
|
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0,
|
|
896
942
|
citations: data.citations,
|
|
897
|
-
inline_citations: data.inline_citations
|
|
943
|
+
inline_citations: data.inline_citations,
|
|
944
|
+
reasoningEncryptedContent
|
|
898
945
|
}
|
|
899
946
|
}
|
|
900
947
|
}
|
|
@@ -929,6 +976,7 @@ function createStreamState2() {
|
|
|
929
976
|
id: "",
|
|
930
977
|
model: "",
|
|
931
978
|
textByIndex: /* @__PURE__ */ new Map(),
|
|
979
|
+
reasoningByIndex: /* @__PURE__ */ new Map(),
|
|
932
980
|
toolCalls: /* @__PURE__ */ new Map(),
|
|
933
981
|
status: "in_progress",
|
|
934
982
|
inputTokens: 0,
|
|
@@ -994,6 +1042,13 @@ function transformStreamEvent2(event, state) {
|
|
|
994
1042
|
existing.arguments = functionCall.arguments;
|
|
995
1043
|
}
|
|
996
1044
|
state.toolCalls.set(event.output_index, existing);
|
|
1045
|
+
} else if (event.item.type === "reasoning") {
|
|
1046
|
+
const reasoningItem = event.item;
|
|
1047
|
+
state.reasoningEncryptedContent = JSON.stringify({
|
|
1048
|
+
id: reasoningItem.id,
|
|
1049
|
+
summary: reasoningItem.summary,
|
|
1050
|
+
encrypted_content: reasoningItem.encrypted_content
|
|
1051
|
+
});
|
|
997
1052
|
}
|
|
998
1053
|
events.push({
|
|
999
1054
|
type: StreamEventType.ContentBlockStop,
|
|
@@ -1069,6 +1124,19 @@ function transformStreamEvent2(event, state) {
|
|
|
1069
1124
|
toolCall.arguments = event.arguments;
|
|
1070
1125
|
break;
|
|
1071
1126
|
}
|
|
1127
|
+
case "response.reasoning_summary_text.delta": {
|
|
1128
|
+
const currentReasoning = state.reasoningByIndex.get(event.output_index) ?? "";
|
|
1129
|
+
state.reasoningByIndex.set(event.output_index, currentReasoning + event.delta);
|
|
1130
|
+
events.push({
|
|
1131
|
+
type: StreamEventType.ReasoningDelta,
|
|
1132
|
+
index: event.output_index,
|
|
1133
|
+
delta: { text: event.delta }
|
|
1134
|
+
});
|
|
1135
|
+
break;
|
|
1136
|
+
}
|
|
1137
|
+
case "response.reasoning_summary_text.done":
|
|
1138
|
+
state.reasoningByIndex.set(event.output_index, event.text);
|
|
1139
|
+
break;
|
|
1072
1140
|
case "error":
|
|
1073
1141
|
break;
|
|
1074
1142
|
default:
|
|
@@ -1077,11 +1145,22 @@ function transformStreamEvent2(event, state) {
|
|
|
1077
1145
|
return events;
|
|
1078
1146
|
}
|
|
1079
1147
|
function buildResponseFromState2(state) {
|
|
1080
|
-
const
|
|
1148
|
+
const content = [];
|
|
1081
1149
|
let structuredData;
|
|
1082
|
-
|
|
1150
|
+
const orderedReasoningEntries = [...state.reasoningByIndex.entries()].sort(
|
|
1151
|
+
([leftIndex], [rightIndex]) => leftIndex - rightIndex
|
|
1152
|
+
);
|
|
1153
|
+
for (const [, reasoning] of orderedReasoningEntries) {
|
|
1154
|
+
if (reasoning) {
|
|
1155
|
+
content.push({ type: "reasoning", text: reasoning });
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
const orderedTextEntries = [...state.textByIndex.entries()].sort(
|
|
1159
|
+
([leftIndex], [rightIndex]) => leftIndex - rightIndex
|
|
1160
|
+
);
|
|
1161
|
+
for (const [, text] of orderedTextEntries) {
|
|
1083
1162
|
if (text) {
|
|
1084
|
-
|
|
1163
|
+
content.push({ type: "text", text });
|
|
1085
1164
|
if (structuredData === void 0) {
|
|
1086
1165
|
try {
|
|
1087
1166
|
structuredData = JSON.parse(text);
|
|
@@ -1119,7 +1198,7 @@ function buildResponseFromState2(state) {
|
|
|
1119
1198
|
}
|
|
1120
1199
|
const responseId = state.id || generateId();
|
|
1121
1200
|
const message = new AssistantMessage(
|
|
1122
|
-
|
|
1201
|
+
content,
|
|
1123
1202
|
toolCalls.length > 0 ? toolCalls : void 0,
|
|
1124
1203
|
{
|
|
1125
1204
|
id: responseId,
|
|
@@ -1128,7 +1207,8 @@ function buildResponseFromState2(state) {
|
|
|
1128
1207
|
model: state.model,
|
|
1129
1208
|
status: state.status,
|
|
1130
1209
|
response_id: responseId,
|
|
1131
|
-
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0
|
|
1210
|
+
functionCallItems: functionCallItems.length > 0 ? functionCallItems : void 0,
|
|
1211
|
+
reasoningEncryptedContent: state.reasoningEncryptedContent
|
|
1132
1212
|
}
|
|
1133
1213
|
}
|
|
1134
1214
|
}
|
|
@@ -1412,7 +1492,19 @@ function transformMessage3(message) {
|
|
|
1412
1492
|
}
|
|
1413
1493
|
if (isAssistantMessage(message)) {
|
|
1414
1494
|
const validContent = filterValidContent3(message.content);
|
|
1415
|
-
const content =
|
|
1495
|
+
const content = [];
|
|
1496
|
+
const xaiMeta = message.metadata?.xai;
|
|
1497
|
+
for (const block of validContent) {
|
|
1498
|
+
if (block.type === "reasoning") {
|
|
1499
|
+
content.push({
|
|
1500
|
+
type: "thinking",
|
|
1501
|
+
thinking: block.text,
|
|
1502
|
+
signature: xaiMeta?.thinkingSignature
|
|
1503
|
+
});
|
|
1504
|
+
} else {
|
|
1505
|
+
content.push(transformContentBlock2(block));
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1416
1508
|
if (message.toolCalls) {
|
|
1417
1509
|
for (const call of message.toolCalls) {
|
|
1418
1510
|
content.push({
|
|
@@ -1500,12 +1592,18 @@ function transformTool3(tool) {
|
|
|
1500
1592
|
};
|
|
1501
1593
|
}
|
|
1502
1594
|
function transformResponse3(data) {
|
|
1503
|
-
const
|
|
1595
|
+
const content = [];
|
|
1504
1596
|
const toolCalls = [];
|
|
1505
1597
|
let structuredData;
|
|
1598
|
+
let thinkingSignature;
|
|
1506
1599
|
for (const block of data.content) {
|
|
1507
1600
|
if (block.type === "text") {
|
|
1508
|
-
|
|
1601
|
+
content.push({ type: "text", text: block.text });
|
|
1602
|
+
} else if (block.type === "thinking") {
|
|
1603
|
+
content.push({ type: "reasoning", text: block.thinking });
|
|
1604
|
+
if (block.signature) {
|
|
1605
|
+
thinkingSignature = block.signature;
|
|
1606
|
+
}
|
|
1509
1607
|
} else if (block.type === "tool_use") {
|
|
1510
1608
|
if (block.name === "json_response") {
|
|
1511
1609
|
structuredData = block.input;
|
|
@@ -1518,7 +1616,7 @@ function transformResponse3(data) {
|
|
|
1518
1616
|
}
|
|
1519
1617
|
}
|
|
1520
1618
|
const message = new AssistantMessage(
|
|
1521
|
-
|
|
1619
|
+
content,
|
|
1522
1620
|
toolCalls.length > 0 ? toolCalls : void 0,
|
|
1523
1621
|
{
|
|
1524
1622
|
id: data.id,
|
|
@@ -1526,7 +1624,9 @@ function transformResponse3(data) {
|
|
|
1526
1624
|
xai: {
|
|
1527
1625
|
stop_reason: data.stop_reason,
|
|
1528
1626
|
stop_sequence: data.stop_sequence,
|
|
1529
|
-
model: data.model
|
|
1627
|
+
model: data.model,
|
|
1628
|
+
// Store thinking signature for multi-turn context
|
|
1629
|
+
thinkingSignature
|
|
1530
1630
|
}
|
|
1531
1631
|
}
|
|
1532
1632
|
}
|
|
@@ -1571,6 +1671,8 @@ function transformStreamEvent3(event, state) {
|
|
|
1571
1671
|
state.currentIndex = event.index;
|
|
1572
1672
|
if (event.content_block.type === "text") {
|
|
1573
1673
|
state.content[event.index] = { type: "text", text: "" };
|
|
1674
|
+
} else if (event.content_block.type === "thinking") {
|
|
1675
|
+
state.content[event.index] = { type: "thinking", thinking: "" };
|
|
1574
1676
|
} else if (event.content_block.type === "tool_use") {
|
|
1575
1677
|
state.content[event.index] = {
|
|
1576
1678
|
type: "tool_use",
|
|
@@ -1610,12 +1712,22 @@ function transformStreamEvent3(event, state) {
|
|
|
1610
1712
|
};
|
|
1611
1713
|
}
|
|
1612
1714
|
if (delta.type === "thinking_delta") {
|
|
1715
|
+
if (!state.content[index]) {
|
|
1716
|
+
state.content[index] = { type: "thinking", thinking: "" };
|
|
1717
|
+
}
|
|
1718
|
+
state.content[index].thinking = (state.content[index].thinking ?? "") + delta.thinking;
|
|
1613
1719
|
return {
|
|
1614
1720
|
type: StreamEventType.ReasoningDelta,
|
|
1615
1721
|
index,
|
|
1616
1722
|
delta: { text: delta.thinking }
|
|
1617
1723
|
};
|
|
1618
1724
|
}
|
|
1725
|
+
if (delta.type === "signature_delta") {
|
|
1726
|
+
if (state.content[index]) {
|
|
1727
|
+
state.content[index].signature = delta.signature;
|
|
1728
|
+
}
|
|
1729
|
+
return null;
|
|
1730
|
+
}
|
|
1619
1731
|
return null;
|
|
1620
1732
|
}
|
|
1621
1733
|
case "content_block_stop":
|
|
@@ -1634,12 +1746,18 @@ function transformStreamEvent3(event, state) {
|
|
|
1634
1746
|
}
|
|
1635
1747
|
}
|
|
1636
1748
|
function buildResponseFromState3(state) {
|
|
1637
|
-
const
|
|
1749
|
+
const content = [];
|
|
1638
1750
|
const toolCalls = [];
|
|
1639
1751
|
let structuredData;
|
|
1752
|
+
let thinkingSignature;
|
|
1640
1753
|
for (const block of state.content) {
|
|
1641
1754
|
if (block.type === "text" && block.text) {
|
|
1642
|
-
|
|
1755
|
+
content.push({ type: "text", text: block.text });
|
|
1756
|
+
} else if (block.type === "thinking" && block.thinking) {
|
|
1757
|
+
content.push({ type: "reasoning", text: block.thinking });
|
|
1758
|
+
if (block.signature) {
|
|
1759
|
+
thinkingSignature = block.signature;
|
|
1760
|
+
}
|
|
1643
1761
|
} else if (block.type === "tool_use" && block.id && block.name) {
|
|
1644
1762
|
let args = {};
|
|
1645
1763
|
if (block.input) {
|
|
@@ -1660,14 +1778,15 @@ function buildResponseFromState3(state) {
|
|
|
1660
1778
|
}
|
|
1661
1779
|
const messageId = state.messageId || generateId();
|
|
1662
1780
|
const message = new AssistantMessage(
|
|
1663
|
-
|
|
1781
|
+
content,
|
|
1664
1782
|
toolCalls.length > 0 ? toolCalls : void 0,
|
|
1665
1783
|
{
|
|
1666
1784
|
id: messageId,
|
|
1667
1785
|
metadata: {
|
|
1668
1786
|
xai: {
|
|
1669
1787
|
stop_reason: state.stopReason,
|
|
1670
|
-
model: state.model
|
|
1788
|
+
model: state.model,
|
|
1789
|
+
thinkingSignature
|
|
1671
1790
|
}
|
|
1672
1791
|
}
|
|
1673
1792
|
}
|