@reverbia/sdk 1.0.0-next.20260114193116 → 1.0.0-next.20260114225852

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.
@@ -104,9 +104,26 @@ function validateToken(token) {
104
104
  }
105
105
  return { valid: true };
106
106
  }
107
- function parseReasoningTags(content, previousPartialTag = "") {
108
- const OPENING_TAG = "<think>";
109
- const CLOSING_TAG = "</think>";
107
+ var REASONING_TAG_FORMATS = [
108
+ { open: "<reasoning>", close: "</reasoning>" },
109
+ { open: "<think>", close: "</think>" }
110
+ ];
111
+ function detectTagFormat(content, partialTag) {
112
+ const combined = partialTag + content;
113
+ for (const format of REASONING_TAG_FORMATS) {
114
+ if (combined.includes(format.open) || combined.includes(format.close) || format.open.startsWith(combined.slice(0, format.open.length)) || format.close.startsWith(combined.slice(0, format.close.length))) {
115
+ return format;
116
+ }
117
+ }
118
+ if (combined.startsWith("<")) {
119
+ return REASONING_TAG_FORMATS[0];
120
+ }
121
+ return null;
122
+ }
123
+ function parseReasoningTags(content, previousPartialTag = "", wasInsideReasoning = false, detectedFormat) {
124
+ const format = detectedFormat || detectTagFormat(content, previousPartialTag) || REASONING_TAG_FORMATS[0];
125
+ const OPENING_TAG = format.open;
126
+ const CLOSING_TAG = format.close;
110
127
  const OPENING_TAG_LEN = OPENING_TAG.length;
111
128
  const CLOSING_TAG_LEN = CLOSING_TAG.length;
112
129
  const fullContent = previousPartialTag + content;
@@ -114,42 +131,61 @@ function parseReasoningTags(content, previousPartialTag = "") {
114
131
  let reasoningContent = "";
115
132
  let partialTag = "";
116
133
  let i = 0;
117
- let insideReasoning = false;
134
+ let insideReasoning = wasInsideReasoning;
118
135
  if (previousPartialTag) {
119
136
  if (previousPartialTag === OPENING_TAG) {
120
137
  insideReasoning = true;
121
138
  i = OPENING_TAG_LEN;
122
- } else if (OPENING_TAG.startsWith(previousPartialTag)) {
123
- if (fullContent.startsWith(OPENING_TAG)) {
124
- insideReasoning = true;
125
- i = OPENING_TAG_LEN;
126
- } else if (OPENING_TAG.startsWith(fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length)))) {
139
+ } else if (previousPartialTag === CLOSING_TAG) {
140
+ i = CLOSING_TAG_LEN;
141
+ insideReasoning = false;
142
+ } else if (wasInsideReasoning && CLOSING_TAG.startsWith(previousPartialTag)) {
143
+ if (fullContent.startsWith(CLOSING_TAG)) {
144
+ i = CLOSING_TAG_LEN;
145
+ insideReasoning = false;
146
+ } else if (CLOSING_TAG.startsWith(
147
+ fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
148
+ )) {
127
149
  return {
128
150
  messageContent: "",
129
151
  reasoningContent: "",
130
- partialTag: fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
152
+ partialTag: fullContent.slice(
153
+ 0,
154
+ Math.min(CLOSING_TAG_LEN, fullContent.length)
155
+ ),
156
+ insideReasoning: true
131
157
  };
132
158
  } else {
133
- messageContent = previousPartialTag;
159
+ reasoningContent = previousPartialTag;
134
160
  i = previousPartialTag.length;
161
+ insideReasoning = true;
135
162
  }
136
- } else if (CLOSING_TAG.startsWith(previousPartialTag)) {
137
- if (fullContent.startsWith(CLOSING_TAG)) {
138
- i = CLOSING_TAG_LEN;
139
- insideReasoning = false;
140
- } else if (CLOSING_TAG.startsWith(fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length)))) {
163
+ } else if (OPENING_TAG.startsWith(previousPartialTag)) {
164
+ if (fullContent.startsWith(OPENING_TAG)) {
165
+ insideReasoning = true;
166
+ i = OPENING_TAG_LEN;
167
+ } else if (OPENING_TAG.startsWith(
168
+ fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
169
+ )) {
141
170
  return {
142
171
  messageContent: "",
143
172
  reasoningContent: "",
144
- partialTag: fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
173
+ partialTag: fullContent.slice(
174
+ 0,
175
+ Math.min(OPENING_TAG_LEN, fullContent.length)
176
+ ),
177
+ insideReasoning: wasInsideReasoning
145
178
  };
146
179
  } else {
147
- reasoningContent = previousPartialTag;
180
+ if (wasInsideReasoning) {
181
+ reasoningContent = previousPartialTag;
182
+ } else {
183
+ messageContent = previousPartialTag;
184
+ }
148
185
  i = previousPartialTag.length;
149
- insideReasoning = true;
150
186
  }
151
187
  } else {
152
- if (insideReasoning) {
188
+ if (wasInsideReasoning) {
153
189
  reasoningContent = previousPartialTag;
154
190
  } else {
155
191
  messageContent = previousPartialTag;
@@ -201,20 +237,39 @@ function parseReasoningTags(content, previousPartialTag = "") {
201
237
  insideReasoning = true;
202
238
  }
203
239
  }
204
- if (messageContent.includes(OPENING_TAG) || messageContent.includes(CLOSING_TAG)) {
205
- console.warn("[parseReasoningTags] Warning: Tag found in messageContent, removing");
206
- messageContent = messageContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
207
- messageContent = messageContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
208
- }
209
- if (reasoningContent.includes(OPENING_TAG) || reasoningContent.includes(CLOSING_TAG)) {
210
- console.warn("[parseReasoningTags] Warning: Tag found in reasoningContent, removing");
211
- reasoningContent = reasoningContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
212
- reasoningContent = reasoningContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
240
+ for (const tagFormat of REASONING_TAG_FORMATS) {
241
+ if (messageContent.includes(tagFormat.open) || messageContent.includes(tagFormat.close)) {
242
+ console.warn(
243
+ "[parseReasoningTags] Warning: Tag found in messageContent, removing"
244
+ );
245
+ messageContent = messageContent.replace(
246
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
247
+ ""
248
+ );
249
+ messageContent = messageContent.replace(
250
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
251
+ ""
252
+ );
253
+ }
254
+ if (reasoningContent.includes(tagFormat.open) || reasoningContent.includes(tagFormat.close)) {
255
+ console.warn(
256
+ "[parseReasoningTags] Warning: Tag found in reasoningContent, removing"
257
+ );
258
+ reasoningContent = reasoningContent.replace(
259
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
260
+ ""
261
+ );
262
+ reasoningContent = reasoningContent.replace(
263
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
264
+ ""
265
+ );
266
+ }
213
267
  }
214
268
  return {
215
269
  messageContent,
216
270
  reasoningContent,
217
- partialTag
271
+ partialTag,
272
+ insideReasoning
218
273
  };
219
274
  }
220
275
  function createStreamAccumulator(initialModel) {
@@ -280,22 +335,37 @@ function processStreamingChunk(chunk, accumulator) {
280
335
  if (delta) {
281
336
  const deltaText = typeof delta === "string" ? delta : delta.OfString;
282
337
  if (deltaText) {
283
- console.log("[Tool Debug] output_text.delta - adding text:", deltaText.substring(0, 50));
338
+ console.log(
339
+ "[Tool Debug] output_text.delta - adding text:",
340
+ deltaText.substring(0, 50)
341
+ );
284
342
  accumulator.content += deltaText;
285
343
  result.content = deltaText;
286
344
  }
287
345
  }
288
346
  }
289
347
  if (chunk.type === "response.output_item.added" && chunk.item) {
290
- console.log("[Tool Debug] output_item.added:", JSON.stringify(chunk.item, null, 2));
348
+ console.log(
349
+ "[Tool Debug] output_item.added:",
350
+ JSON.stringify(chunk.item, null, 2)
351
+ );
291
352
  if (chunk.item.type === "message") {
292
- console.log("[Tool Debug] Message output item added - ready to receive text deltas");
353
+ console.log(
354
+ "[Tool Debug] Message output item added - ready to receive text deltas"
355
+ );
293
356
  }
294
357
  if (chunk.item.type === "function_call") {
295
358
  const itemId = chunk.item.id || "";
296
359
  const callId = chunk.item.call_id || "";
297
360
  if (itemId && chunk.item.name) {
298
- console.log("[Tool Debug] Detected tool call:", chunk.item.name, "item ID:", itemId, "call ID:", callId);
361
+ console.log(
362
+ "[Tool Debug] Detected tool call:",
363
+ chunk.item.name,
364
+ "item ID:",
365
+ itemId,
366
+ "call ID:",
367
+ callId
368
+ );
299
369
  accumulator.toolCalls.set(itemId, {
300
370
  id: callId || itemId,
301
371
  // Use call_id for the tool call ID
@@ -308,27 +378,54 @@ function processStreamingChunk(chunk, accumulator) {
308
378
  }
309
379
  }
310
380
  if (chunk.type === "response.function_call_arguments.delta") {
311
- console.log("[Tool Debug] Arguments delta event - item_id:", chunk.item_id, "call_id:", chunk.call_id, "args length:", chunk.arguments?.length);
381
+ console.log(
382
+ "[Tool Debug] Arguments delta event - item_id:",
383
+ chunk.item_id,
384
+ "call_id:",
385
+ chunk.call_id,
386
+ "args length:",
387
+ chunk.arguments?.length
388
+ );
312
389
  const itemId = chunk.item_id || chunk.call_id || "";
313
390
  if (itemId && chunk.arguments) {
314
391
  const existing = accumulator.toolCalls.get(itemId);
315
392
  if (existing) {
316
393
  existing.arguments += chunk.arguments;
317
394
  } else {
318
- console.log("[Tool Debug] WARNING: Tool call not found for item ID:", itemId, "Available keys:", Array.from(accumulator.toolCalls.keys()));
395
+ console.log(
396
+ "[Tool Debug] WARNING: Tool call not found for item ID:",
397
+ itemId,
398
+ "Available keys:",
399
+ Array.from(accumulator.toolCalls.keys())
400
+ );
319
401
  }
320
402
  }
321
403
  }
322
404
  if (chunk.type === "response.function_call_arguments.done") {
323
- console.log("[Tool Debug] Arguments done event - item_id:", chunk.item_id, "call_id:", chunk.call_id, "args:", chunk.arguments);
405
+ console.log(
406
+ "[Tool Debug] Arguments done event - item_id:",
407
+ chunk.item_id,
408
+ "call_id:",
409
+ chunk.call_id,
410
+ "args:",
411
+ chunk.arguments
412
+ );
324
413
  const itemId = chunk.item_id || chunk.call_id || "";
325
414
  if (itemId && chunk.arguments) {
326
415
  const existing = accumulator.toolCalls.get(itemId);
327
416
  if (existing) {
328
417
  existing.arguments = chunk.arguments;
329
- console.log("[Tool Debug] Successfully updated arguments:", existing.arguments);
418
+ console.log(
419
+ "[Tool Debug] Successfully updated arguments:",
420
+ existing.arguments
421
+ );
330
422
  } else {
331
- console.log("[Tool Debug] WARNING: Tool call not found for item ID:", itemId, "Available keys:", Array.from(accumulator.toolCalls.keys()));
423
+ console.log(
424
+ "[Tool Debug] WARNING: Tool call not found for item ID:",
425
+ itemId,
426
+ "Available keys:",
427
+ Array.from(accumulator.toolCalls.keys())
428
+ );
332
429
  }
333
430
  }
334
431
  }
@@ -418,7 +515,10 @@ function createToolExecutorMap(tools) {
418
515
  }
419
516
  async function executeToolCall(toolCall, executor) {
420
517
  try {
421
- console.log("[Tool Debug] executeToolCall - raw arguments:", toolCall.arguments);
518
+ console.log(
519
+ "[Tool Debug] executeToolCall - raw arguments:",
520
+ toolCall.arguments
521
+ );
422
522
  let args = {};
423
523
  if (toolCall.arguments) {
424
524
  try {
@@ -669,11 +769,13 @@ var CompletionsStrategy = class {
669
769
  if (choice.delta.content) {
670
770
  const parseResult = parseReasoningTags(
671
771
  choice.delta.content,
672
- accumulator.partialReasoningTag || ""
772
+ accumulator.partialReasoningTag || "",
773
+ accumulator.insideReasoning || false
673
774
  );
674
775
  accumulator.content += parseResult.messageContent;
675
776
  accumulator.thinking += parseResult.reasoningContent;
676
777
  accumulator.partialReasoningTag = parseResult.partialTag;
778
+ accumulator.insideReasoning = parseResult.insideReasoning;
677
779
  const willEmitMessage = parseResult.messageContent && parseResult.messageContent.trim().length > 0;
678
780
  const willEmitReasoning = parseResult.reasoningContent && parseResult.reasoningContent.trim().length > 0;
679
781
  if (willEmitMessage) {
@@ -712,11 +814,13 @@ var CompletionsStrategy = class {
712
814
  if (choice.message.content) {
713
815
  const parseResult = parseReasoningTags(
714
816
  choice.message.content,
715
- accumulator.partialReasoningTag || ""
817
+ accumulator.partialReasoningTag || "",
818
+ accumulator.insideReasoning || false
716
819
  );
717
820
  accumulator.content = parseResult.messageContent;
718
821
  accumulator.thinking += parseResult.reasoningContent;
719
822
  accumulator.partialReasoningTag = parseResult.partialTag;
823
+ accumulator.insideReasoning = parseResult.insideReasoning;
720
824
  if (parseResult.messageContent && parseResult.messageContent.trim().length > 0) {
721
825
  result.content = parseResult.messageContent;
722
826
  }
@@ -755,7 +859,8 @@ var CompletionsStrategy = class {
755
859
  if (accumulator.partialReasoningTag) {
756
860
  const finalParse = parseReasoningTags(
757
861
  "",
758
- accumulator.partialReasoningTag
862
+ accumulator.partialReasoningTag,
863
+ accumulator.insideReasoning || false
759
864
  );
760
865
  finalContent += finalParse.messageContent;
761
866
  if (finalParse.reasoningContent) {
@@ -66,9 +66,26 @@ function validateToken(token) {
66
66
  }
67
67
  return { valid: true };
68
68
  }
69
- function parseReasoningTags(content, previousPartialTag = "") {
70
- const OPENING_TAG = "<think>";
71
- const CLOSING_TAG = "</think>";
69
+ var REASONING_TAG_FORMATS = [
70
+ { open: "<reasoning>", close: "</reasoning>" },
71
+ { open: "<think>", close: "</think>" }
72
+ ];
73
+ function detectTagFormat(content, partialTag) {
74
+ const combined = partialTag + content;
75
+ for (const format of REASONING_TAG_FORMATS) {
76
+ if (combined.includes(format.open) || combined.includes(format.close) || format.open.startsWith(combined.slice(0, format.open.length)) || format.close.startsWith(combined.slice(0, format.close.length))) {
77
+ return format;
78
+ }
79
+ }
80
+ if (combined.startsWith("<")) {
81
+ return REASONING_TAG_FORMATS[0];
82
+ }
83
+ return null;
84
+ }
85
+ function parseReasoningTags(content, previousPartialTag = "", wasInsideReasoning = false, detectedFormat) {
86
+ const format = detectedFormat || detectTagFormat(content, previousPartialTag) || REASONING_TAG_FORMATS[0];
87
+ const OPENING_TAG = format.open;
88
+ const CLOSING_TAG = format.close;
72
89
  const OPENING_TAG_LEN = OPENING_TAG.length;
73
90
  const CLOSING_TAG_LEN = CLOSING_TAG.length;
74
91
  const fullContent = previousPartialTag + content;
@@ -76,42 +93,61 @@ function parseReasoningTags(content, previousPartialTag = "") {
76
93
  let reasoningContent = "";
77
94
  let partialTag = "";
78
95
  let i = 0;
79
- let insideReasoning = false;
96
+ let insideReasoning = wasInsideReasoning;
80
97
  if (previousPartialTag) {
81
98
  if (previousPartialTag === OPENING_TAG) {
82
99
  insideReasoning = true;
83
100
  i = OPENING_TAG_LEN;
84
- } else if (OPENING_TAG.startsWith(previousPartialTag)) {
85
- if (fullContent.startsWith(OPENING_TAG)) {
86
- insideReasoning = true;
87
- i = OPENING_TAG_LEN;
88
- } else if (OPENING_TAG.startsWith(fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length)))) {
101
+ } else if (previousPartialTag === CLOSING_TAG) {
102
+ i = CLOSING_TAG_LEN;
103
+ insideReasoning = false;
104
+ } else if (wasInsideReasoning && CLOSING_TAG.startsWith(previousPartialTag)) {
105
+ if (fullContent.startsWith(CLOSING_TAG)) {
106
+ i = CLOSING_TAG_LEN;
107
+ insideReasoning = false;
108
+ } else if (CLOSING_TAG.startsWith(
109
+ fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
110
+ )) {
89
111
  return {
90
112
  messageContent: "",
91
113
  reasoningContent: "",
92
- partialTag: fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
114
+ partialTag: fullContent.slice(
115
+ 0,
116
+ Math.min(CLOSING_TAG_LEN, fullContent.length)
117
+ ),
118
+ insideReasoning: true
93
119
  };
94
120
  } else {
95
- messageContent = previousPartialTag;
121
+ reasoningContent = previousPartialTag;
96
122
  i = previousPartialTag.length;
123
+ insideReasoning = true;
97
124
  }
98
- } else if (CLOSING_TAG.startsWith(previousPartialTag)) {
99
- if (fullContent.startsWith(CLOSING_TAG)) {
100
- i = CLOSING_TAG_LEN;
101
- insideReasoning = false;
102
- } else if (CLOSING_TAG.startsWith(fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length)))) {
125
+ } else if (OPENING_TAG.startsWith(previousPartialTag)) {
126
+ if (fullContent.startsWith(OPENING_TAG)) {
127
+ insideReasoning = true;
128
+ i = OPENING_TAG_LEN;
129
+ } else if (OPENING_TAG.startsWith(
130
+ fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
131
+ )) {
103
132
  return {
104
133
  messageContent: "",
105
134
  reasoningContent: "",
106
- partialTag: fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
135
+ partialTag: fullContent.slice(
136
+ 0,
137
+ Math.min(OPENING_TAG_LEN, fullContent.length)
138
+ ),
139
+ insideReasoning: wasInsideReasoning
107
140
  };
108
141
  } else {
109
- reasoningContent = previousPartialTag;
142
+ if (wasInsideReasoning) {
143
+ reasoningContent = previousPartialTag;
144
+ } else {
145
+ messageContent = previousPartialTag;
146
+ }
110
147
  i = previousPartialTag.length;
111
- insideReasoning = true;
112
148
  }
113
149
  } else {
114
- if (insideReasoning) {
150
+ if (wasInsideReasoning) {
115
151
  reasoningContent = previousPartialTag;
116
152
  } else {
117
153
  messageContent = previousPartialTag;
@@ -163,20 +199,39 @@ function parseReasoningTags(content, previousPartialTag = "") {
163
199
  insideReasoning = true;
164
200
  }
165
201
  }
166
- if (messageContent.includes(OPENING_TAG) || messageContent.includes(CLOSING_TAG)) {
167
- console.warn("[parseReasoningTags] Warning: Tag found in messageContent, removing");
168
- messageContent = messageContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
169
- messageContent = messageContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
170
- }
171
- if (reasoningContent.includes(OPENING_TAG) || reasoningContent.includes(CLOSING_TAG)) {
172
- console.warn("[parseReasoningTags] Warning: Tag found in reasoningContent, removing");
173
- reasoningContent = reasoningContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
174
- reasoningContent = reasoningContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
202
+ for (const tagFormat of REASONING_TAG_FORMATS) {
203
+ if (messageContent.includes(tagFormat.open) || messageContent.includes(tagFormat.close)) {
204
+ console.warn(
205
+ "[parseReasoningTags] Warning: Tag found in messageContent, removing"
206
+ );
207
+ messageContent = messageContent.replace(
208
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
209
+ ""
210
+ );
211
+ messageContent = messageContent.replace(
212
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
213
+ ""
214
+ );
215
+ }
216
+ if (reasoningContent.includes(tagFormat.open) || reasoningContent.includes(tagFormat.close)) {
217
+ console.warn(
218
+ "[parseReasoningTags] Warning: Tag found in reasoningContent, removing"
219
+ );
220
+ reasoningContent = reasoningContent.replace(
221
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
222
+ ""
223
+ );
224
+ reasoningContent = reasoningContent.replace(
225
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
226
+ ""
227
+ );
228
+ }
175
229
  }
176
230
  return {
177
231
  messageContent,
178
232
  reasoningContent,
179
- partialTag
233
+ partialTag,
234
+ insideReasoning
180
235
  };
181
236
  }
182
237
  function createStreamAccumulator(initialModel) {
@@ -242,22 +297,37 @@ function processStreamingChunk(chunk, accumulator) {
242
297
  if (delta) {
243
298
  const deltaText = typeof delta === "string" ? delta : delta.OfString;
244
299
  if (deltaText) {
245
- console.log("[Tool Debug] output_text.delta - adding text:", deltaText.substring(0, 50));
300
+ console.log(
301
+ "[Tool Debug] output_text.delta - adding text:",
302
+ deltaText.substring(0, 50)
303
+ );
246
304
  accumulator.content += deltaText;
247
305
  result.content = deltaText;
248
306
  }
249
307
  }
250
308
  }
251
309
  if (chunk.type === "response.output_item.added" && chunk.item) {
252
- console.log("[Tool Debug] output_item.added:", JSON.stringify(chunk.item, null, 2));
310
+ console.log(
311
+ "[Tool Debug] output_item.added:",
312
+ JSON.stringify(chunk.item, null, 2)
313
+ );
253
314
  if (chunk.item.type === "message") {
254
- console.log("[Tool Debug] Message output item added - ready to receive text deltas");
315
+ console.log(
316
+ "[Tool Debug] Message output item added - ready to receive text deltas"
317
+ );
255
318
  }
256
319
  if (chunk.item.type === "function_call") {
257
320
  const itemId = chunk.item.id || "";
258
321
  const callId = chunk.item.call_id || "";
259
322
  if (itemId && chunk.item.name) {
260
- console.log("[Tool Debug] Detected tool call:", chunk.item.name, "item ID:", itemId, "call ID:", callId);
323
+ console.log(
324
+ "[Tool Debug] Detected tool call:",
325
+ chunk.item.name,
326
+ "item ID:",
327
+ itemId,
328
+ "call ID:",
329
+ callId
330
+ );
261
331
  accumulator.toolCalls.set(itemId, {
262
332
  id: callId || itemId,
263
333
  // Use call_id for the tool call ID
@@ -270,27 +340,54 @@ function processStreamingChunk(chunk, accumulator) {
270
340
  }
271
341
  }
272
342
  if (chunk.type === "response.function_call_arguments.delta") {
273
- console.log("[Tool Debug] Arguments delta event - item_id:", chunk.item_id, "call_id:", chunk.call_id, "args length:", chunk.arguments?.length);
343
+ console.log(
344
+ "[Tool Debug] Arguments delta event - item_id:",
345
+ chunk.item_id,
346
+ "call_id:",
347
+ chunk.call_id,
348
+ "args length:",
349
+ chunk.arguments?.length
350
+ );
274
351
  const itemId = chunk.item_id || chunk.call_id || "";
275
352
  if (itemId && chunk.arguments) {
276
353
  const existing = accumulator.toolCalls.get(itemId);
277
354
  if (existing) {
278
355
  existing.arguments += chunk.arguments;
279
356
  } else {
280
- console.log("[Tool Debug] WARNING: Tool call not found for item ID:", itemId, "Available keys:", Array.from(accumulator.toolCalls.keys()));
357
+ console.log(
358
+ "[Tool Debug] WARNING: Tool call not found for item ID:",
359
+ itemId,
360
+ "Available keys:",
361
+ Array.from(accumulator.toolCalls.keys())
362
+ );
281
363
  }
282
364
  }
283
365
  }
284
366
  if (chunk.type === "response.function_call_arguments.done") {
285
- console.log("[Tool Debug] Arguments done event - item_id:", chunk.item_id, "call_id:", chunk.call_id, "args:", chunk.arguments);
367
+ console.log(
368
+ "[Tool Debug] Arguments done event - item_id:",
369
+ chunk.item_id,
370
+ "call_id:",
371
+ chunk.call_id,
372
+ "args:",
373
+ chunk.arguments
374
+ );
286
375
  const itemId = chunk.item_id || chunk.call_id || "";
287
376
  if (itemId && chunk.arguments) {
288
377
  const existing = accumulator.toolCalls.get(itemId);
289
378
  if (existing) {
290
379
  existing.arguments = chunk.arguments;
291
- console.log("[Tool Debug] Successfully updated arguments:", existing.arguments);
380
+ console.log(
381
+ "[Tool Debug] Successfully updated arguments:",
382
+ existing.arguments
383
+ );
292
384
  } else {
293
- console.log("[Tool Debug] WARNING: Tool call not found for item ID:", itemId, "Available keys:", Array.from(accumulator.toolCalls.keys()));
385
+ console.log(
386
+ "[Tool Debug] WARNING: Tool call not found for item ID:",
387
+ itemId,
388
+ "Available keys:",
389
+ Array.from(accumulator.toolCalls.keys())
390
+ );
294
391
  }
295
392
  }
296
393
  }
@@ -380,7 +477,10 @@ function createToolExecutorMap(tools) {
380
477
  }
381
478
  async function executeToolCall(toolCall, executor) {
382
479
  try {
383
- console.log("[Tool Debug] executeToolCall - raw arguments:", toolCall.arguments);
480
+ console.log(
481
+ "[Tool Debug] executeToolCall - raw arguments:",
482
+ toolCall.arguments
483
+ );
384
484
  let args = {};
385
485
  if (toolCall.arguments) {
386
486
  try {
@@ -631,11 +731,13 @@ var CompletionsStrategy = class {
631
731
  if (choice.delta.content) {
632
732
  const parseResult = parseReasoningTags(
633
733
  choice.delta.content,
634
- accumulator.partialReasoningTag || ""
734
+ accumulator.partialReasoningTag || "",
735
+ accumulator.insideReasoning || false
635
736
  );
636
737
  accumulator.content += parseResult.messageContent;
637
738
  accumulator.thinking += parseResult.reasoningContent;
638
739
  accumulator.partialReasoningTag = parseResult.partialTag;
740
+ accumulator.insideReasoning = parseResult.insideReasoning;
639
741
  const willEmitMessage = parseResult.messageContent && parseResult.messageContent.trim().length > 0;
640
742
  const willEmitReasoning = parseResult.reasoningContent && parseResult.reasoningContent.trim().length > 0;
641
743
  if (willEmitMessage) {
@@ -674,11 +776,13 @@ var CompletionsStrategy = class {
674
776
  if (choice.message.content) {
675
777
  const parseResult = parseReasoningTags(
676
778
  choice.message.content,
677
- accumulator.partialReasoningTag || ""
779
+ accumulator.partialReasoningTag || "",
780
+ accumulator.insideReasoning || false
678
781
  );
679
782
  accumulator.content = parseResult.messageContent;
680
783
  accumulator.thinking += parseResult.reasoningContent;
681
784
  accumulator.partialReasoningTag = parseResult.partialTag;
785
+ accumulator.insideReasoning = parseResult.insideReasoning;
682
786
  if (parseResult.messageContent && parseResult.messageContent.trim().length > 0) {
683
787
  result.content = parseResult.messageContent;
684
788
  }
@@ -717,7 +821,8 @@ var CompletionsStrategy = class {
717
821
  if (accumulator.partialReasoningTag) {
718
822
  const finalParse = parseReasoningTags(
719
823
  "",
720
- accumulator.partialReasoningTag
824
+ accumulator.partialReasoningTag,
825
+ accumulator.insideReasoning || false
721
826
  );
722
827
  finalContent += finalParse.messageContent;
723
828
  if (finalParse.reasoningContent) {
@@ -1012,9 +1012,26 @@ function validateToken(token) {
1012
1012
  }
1013
1013
  return { valid: true };
1014
1014
  }
1015
- function parseReasoningTags(content, previousPartialTag = "") {
1016
- const OPENING_TAG = "<think>";
1017
- const CLOSING_TAG = "</think>";
1015
+ var REASONING_TAG_FORMATS = [
1016
+ { open: "<reasoning>", close: "</reasoning>" },
1017
+ { open: "<think>", close: "</think>" }
1018
+ ];
1019
+ function detectTagFormat(content, partialTag) {
1020
+ const combined = partialTag + content;
1021
+ for (const format of REASONING_TAG_FORMATS) {
1022
+ if (combined.includes(format.open) || combined.includes(format.close) || format.open.startsWith(combined.slice(0, format.open.length)) || format.close.startsWith(combined.slice(0, format.close.length))) {
1023
+ return format;
1024
+ }
1025
+ }
1026
+ if (combined.startsWith("<")) {
1027
+ return REASONING_TAG_FORMATS[0];
1028
+ }
1029
+ return null;
1030
+ }
1031
+ function parseReasoningTags(content, previousPartialTag = "", wasInsideReasoning = false, detectedFormat) {
1032
+ const format = detectedFormat || detectTagFormat(content, previousPartialTag) || REASONING_TAG_FORMATS[0];
1033
+ const OPENING_TAG = format.open;
1034
+ const CLOSING_TAG = format.close;
1018
1035
  const OPENING_TAG_LEN = OPENING_TAG.length;
1019
1036
  const CLOSING_TAG_LEN = CLOSING_TAG.length;
1020
1037
  const fullContent = previousPartialTag + content;
@@ -1022,42 +1039,61 @@ function parseReasoningTags(content, previousPartialTag = "") {
1022
1039
  let reasoningContent = "";
1023
1040
  let partialTag = "";
1024
1041
  let i = 0;
1025
- let insideReasoning = false;
1042
+ let insideReasoning = wasInsideReasoning;
1026
1043
  if (previousPartialTag) {
1027
1044
  if (previousPartialTag === OPENING_TAG) {
1028
1045
  insideReasoning = true;
1029
1046
  i = OPENING_TAG_LEN;
1030
- } else if (OPENING_TAG.startsWith(previousPartialTag)) {
1031
- if (fullContent.startsWith(OPENING_TAG)) {
1032
- insideReasoning = true;
1033
- i = OPENING_TAG_LEN;
1034
- } else if (OPENING_TAG.startsWith(fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length)))) {
1047
+ } else if (previousPartialTag === CLOSING_TAG) {
1048
+ i = CLOSING_TAG_LEN;
1049
+ insideReasoning = false;
1050
+ } else if (wasInsideReasoning && CLOSING_TAG.startsWith(previousPartialTag)) {
1051
+ if (fullContent.startsWith(CLOSING_TAG)) {
1052
+ i = CLOSING_TAG_LEN;
1053
+ insideReasoning = false;
1054
+ } else if (CLOSING_TAG.startsWith(
1055
+ fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
1056
+ )) {
1035
1057
  return {
1036
1058
  messageContent: "",
1037
1059
  reasoningContent: "",
1038
- partialTag: fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
1060
+ partialTag: fullContent.slice(
1061
+ 0,
1062
+ Math.min(CLOSING_TAG_LEN, fullContent.length)
1063
+ ),
1064
+ insideReasoning: true
1039
1065
  };
1040
1066
  } else {
1041
- messageContent = previousPartialTag;
1067
+ reasoningContent = previousPartialTag;
1042
1068
  i = previousPartialTag.length;
1069
+ insideReasoning = true;
1043
1070
  }
1044
- } else if (CLOSING_TAG.startsWith(previousPartialTag)) {
1045
- if (fullContent.startsWith(CLOSING_TAG)) {
1046
- i = CLOSING_TAG_LEN;
1047
- insideReasoning = false;
1048
- } else if (CLOSING_TAG.startsWith(fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length)))) {
1071
+ } else if (OPENING_TAG.startsWith(previousPartialTag)) {
1072
+ if (fullContent.startsWith(OPENING_TAG)) {
1073
+ insideReasoning = true;
1074
+ i = OPENING_TAG_LEN;
1075
+ } else if (OPENING_TAG.startsWith(
1076
+ fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
1077
+ )) {
1049
1078
  return {
1050
1079
  messageContent: "",
1051
1080
  reasoningContent: "",
1052
- partialTag: fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
1081
+ partialTag: fullContent.slice(
1082
+ 0,
1083
+ Math.min(OPENING_TAG_LEN, fullContent.length)
1084
+ ),
1085
+ insideReasoning: wasInsideReasoning
1053
1086
  };
1054
1087
  } else {
1055
- reasoningContent = previousPartialTag;
1088
+ if (wasInsideReasoning) {
1089
+ reasoningContent = previousPartialTag;
1090
+ } else {
1091
+ messageContent = previousPartialTag;
1092
+ }
1056
1093
  i = previousPartialTag.length;
1057
- insideReasoning = true;
1058
1094
  }
1059
1095
  } else {
1060
- if (insideReasoning) {
1096
+ if (wasInsideReasoning) {
1061
1097
  reasoningContent = previousPartialTag;
1062
1098
  } else {
1063
1099
  messageContent = previousPartialTag;
@@ -1109,20 +1145,39 @@ function parseReasoningTags(content, previousPartialTag = "") {
1109
1145
  insideReasoning = true;
1110
1146
  }
1111
1147
  }
1112
- if (messageContent.includes(OPENING_TAG) || messageContent.includes(CLOSING_TAG)) {
1113
- console.warn("[parseReasoningTags] Warning: Tag found in messageContent, removing");
1114
- messageContent = messageContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
1115
- messageContent = messageContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
1116
- }
1117
- if (reasoningContent.includes(OPENING_TAG) || reasoningContent.includes(CLOSING_TAG)) {
1118
- console.warn("[parseReasoningTags] Warning: Tag found in reasoningContent, removing");
1119
- reasoningContent = reasoningContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
1120
- reasoningContent = reasoningContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
1148
+ for (const tagFormat of REASONING_TAG_FORMATS) {
1149
+ if (messageContent.includes(tagFormat.open) || messageContent.includes(tagFormat.close)) {
1150
+ console.warn(
1151
+ "[parseReasoningTags] Warning: Tag found in messageContent, removing"
1152
+ );
1153
+ messageContent = messageContent.replace(
1154
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
1155
+ ""
1156
+ );
1157
+ messageContent = messageContent.replace(
1158
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
1159
+ ""
1160
+ );
1161
+ }
1162
+ if (reasoningContent.includes(tagFormat.open) || reasoningContent.includes(tagFormat.close)) {
1163
+ console.warn(
1164
+ "[parseReasoningTags] Warning: Tag found in reasoningContent, removing"
1165
+ );
1166
+ reasoningContent = reasoningContent.replace(
1167
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
1168
+ ""
1169
+ );
1170
+ reasoningContent = reasoningContent.replace(
1171
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
1172
+ ""
1173
+ );
1174
+ }
1121
1175
  }
1122
1176
  return {
1123
1177
  messageContent,
1124
1178
  reasoningContent,
1125
- partialTag
1179
+ partialTag,
1180
+ insideReasoning
1126
1181
  };
1127
1182
  }
1128
1183
  function createStreamAccumulator(initialModel) {
@@ -1181,7 +1236,10 @@ function createToolExecutorMap(tools) {
1181
1236
  }
1182
1237
  async function executeToolCall(toolCall, executor) {
1183
1238
  try {
1184
- console.log("[Tool Debug] executeToolCall - raw arguments:", toolCall.arguments);
1239
+ console.log(
1240
+ "[Tool Debug] executeToolCall - raw arguments:",
1241
+ toolCall.arguments
1242
+ );
1185
1243
  let args = {};
1186
1244
  if (toolCall.arguments) {
1187
1245
  try {
@@ -1432,11 +1490,13 @@ var CompletionsStrategy = class {
1432
1490
  if (choice.delta.content) {
1433
1491
  const parseResult = parseReasoningTags(
1434
1492
  choice.delta.content,
1435
- accumulator.partialReasoningTag || ""
1493
+ accumulator.partialReasoningTag || "",
1494
+ accumulator.insideReasoning || false
1436
1495
  );
1437
1496
  accumulator.content += parseResult.messageContent;
1438
1497
  accumulator.thinking += parseResult.reasoningContent;
1439
1498
  accumulator.partialReasoningTag = parseResult.partialTag;
1499
+ accumulator.insideReasoning = parseResult.insideReasoning;
1440
1500
  const willEmitMessage = parseResult.messageContent && parseResult.messageContent.trim().length > 0;
1441
1501
  const willEmitReasoning = parseResult.reasoningContent && parseResult.reasoningContent.trim().length > 0;
1442
1502
  if (willEmitMessage) {
@@ -1475,11 +1535,13 @@ var CompletionsStrategy = class {
1475
1535
  if (choice.message.content) {
1476
1536
  const parseResult = parseReasoningTags(
1477
1537
  choice.message.content,
1478
- accumulator.partialReasoningTag || ""
1538
+ accumulator.partialReasoningTag || "",
1539
+ accumulator.insideReasoning || false
1479
1540
  );
1480
1541
  accumulator.content = parseResult.messageContent;
1481
1542
  accumulator.thinking += parseResult.reasoningContent;
1482
1543
  accumulator.partialReasoningTag = parseResult.partialTag;
1544
+ accumulator.insideReasoning = parseResult.insideReasoning;
1483
1545
  if (parseResult.messageContent && parseResult.messageContent.trim().length > 0) {
1484
1546
  result.content = parseResult.messageContent;
1485
1547
  }
@@ -1518,7 +1580,8 @@ var CompletionsStrategy = class {
1518
1580
  if (accumulator.partialReasoningTag) {
1519
1581
  const finalParse = parseReasoningTags(
1520
1582
  "",
1521
- accumulator.partialReasoningTag
1583
+ accumulator.partialReasoningTag,
1584
+ accumulator.insideReasoning || false
1522
1585
  );
1523
1586
  finalContent += finalParse.messageContent;
1524
1587
  if (finalParse.reasoningContent) {
@@ -875,9 +875,26 @@ function validateToken(token) {
875
875
  }
876
876
  return { valid: true };
877
877
  }
878
- function parseReasoningTags(content, previousPartialTag = "") {
879
- const OPENING_TAG = "<think>";
880
- const CLOSING_TAG = "</think>";
878
+ var REASONING_TAG_FORMATS = [
879
+ { open: "<reasoning>", close: "</reasoning>" },
880
+ { open: "<think>", close: "</think>" }
881
+ ];
882
+ function detectTagFormat(content, partialTag) {
883
+ const combined = partialTag + content;
884
+ for (const format of REASONING_TAG_FORMATS) {
885
+ if (combined.includes(format.open) || combined.includes(format.close) || format.open.startsWith(combined.slice(0, format.open.length)) || format.close.startsWith(combined.slice(0, format.close.length))) {
886
+ return format;
887
+ }
888
+ }
889
+ if (combined.startsWith("<")) {
890
+ return REASONING_TAG_FORMATS[0];
891
+ }
892
+ return null;
893
+ }
894
+ function parseReasoningTags(content, previousPartialTag = "", wasInsideReasoning = false, detectedFormat) {
895
+ const format = detectedFormat || detectTagFormat(content, previousPartialTag) || REASONING_TAG_FORMATS[0];
896
+ const OPENING_TAG = format.open;
897
+ const CLOSING_TAG = format.close;
881
898
  const OPENING_TAG_LEN = OPENING_TAG.length;
882
899
  const CLOSING_TAG_LEN = CLOSING_TAG.length;
883
900
  const fullContent = previousPartialTag + content;
@@ -885,42 +902,61 @@ function parseReasoningTags(content, previousPartialTag = "") {
885
902
  let reasoningContent = "";
886
903
  let partialTag = "";
887
904
  let i = 0;
888
- let insideReasoning = false;
905
+ let insideReasoning = wasInsideReasoning;
889
906
  if (previousPartialTag) {
890
907
  if (previousPartialTag === OPENING_TAG) {
891
908
  insideReasoning = true;
892
909
  i = OPENING_TAG_LEN;
893
- } else if (OPENING_TAG.startsWith(previousPartialTag)) {
894
- if (fullContent.startsWith(OPENING_TAG)) {
895
- insideReasoning = true;
896
- i = OPENING_TAG_LEN;
897
- } else if (OPENING_TAG.startsWith(fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length)))) {
910
+ } else if (previousPartialTag === CLOSING_TAG) {
911
+ i = CLOSING_TAG_LEN;
912
+ insideReasoning = false;
913
+ } else if (wasInsideReasoning && CLOSING_TAG.startsWith(previousPartialTag)) {
914
+ if (fullContent.startsWith(CLOSING_TAG)) {
915
+ i = CLOSING_TAG_LEN;
916
+ insideReasoning = false;
917
+ } else if (CLOSING_TAG.startsWith(
918
+ fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
919
+ )) {
898
920
  return {
899
921
  messageContent: "",
900
922
  reasoningContent: "",
901
- partialTag: fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
923
+ partialTag: fullContent.slice(
924
+ 0,
925
+ Math.min(CLOSING_TAG_LEN, fullContent.length)
926
+ ),
927
+ insideReasoning: true
902
928
  };
903
929
  } else {
904
- messageContent = previousPartialTag;
930
+ reasoningContent = previousPartialTag;
905
931
  i = previousPartialTag.length;
932
+ insideReasoning = true;
906
933
  }
907
- } else if (CLOSING_TAG.startsWith(previousPartialTag)) {
908
- if (fullContent.startsWith(CLOSING_TAG)) {
909
- i = CLOSING_TAG_LEN;
910
- insideReasoning = false;
911
- } else if (CLOSING_TAG.startsWith(fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length)))) {
934
+ } else if (OPENING_TAG.startsWith(previousPartialTag)) {
935
+ if (fullContent.startsWith(OPENING_TAG)) {
936
+ insideReasoning = true;
937
+ i = OPENING_TAG_LEN;
938
+ } else if (OPENING_TAG.startsWith(
939
+ fullContent.slice(0, Math.min(OPENING_TAG_LEN, fullContent.length))
940
+ )) {
912
941
  return {
913
942
  messageContent: "",
914
943
  reasoningContent: "",
915
- partialTag: fullContent.slice(0, Math.min(CLOSING_TAG_LEN, fullContent.length))
944
+ partialTag: fullContent.slice(
945
+ 0,
946
+ Math.min(OPENING_TAG_LEN, fullContent.length)
947
+ ),
948
+ insideReasoning: wasInsideReasoning
916
949
  };
917
950
  } else {
918
- reasoningContent = previousPartialTag;
951
+ if (wasInsideReasoning) {
952
+ reasoningContent = previousPartialTag;
953
+ } else {
954
+ messageContent = previousPartialTag;
955
+ }
919
956
  i = previousPartialTag.length;
920
- insideReasoning = true;
921
957
  }
922
958
  } else {
923
- if (insideReasoning) {
959
+ if (wasInsideReasoning) {
924
960
  reasoningContent = previousPartialTag;
925
961
  } else {
926
962
  messageContent = previousPartialTag;
@@ -972,20 +1008,39 @@ function parseReasoningTags(content, previousPartialTag = "") {
972
1008
  insideReasoning = true;
973
1009
  }
974
1010
  }
975
- if (messageContent.includes(OPENING_TAG) || messageContent.includes(CLOSING_TAG)) {
976
- console.warn("[parseReasoningTags] Warning: Tag found in messageContent, removing");
977
- messageContent = messageContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
978
- messageContent = messageContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
979
- }
980
- if (reasoningContent.includes(OPENING_TAG) || reasoningContent.includes(CLOSING_TAG)) {
981
- console.warn("[parseReasoningTags] Warning: Tag found in reasoningContent, removing");
982
- reasoningContent = reasoningContent.replace(new RegExp(OPENING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
983
- reasoningContent = reasoningContent.replace(new RegExp(CLOSING_TAG.replace(/[<>]/g, "\\$&"), "g"), "");
1011
+ for (const tagFormat of REASONING_TAG_FORMATS) {
1012
+ if (messageContent.includes(tagFormat.open) || messageContent.includes(tagFormat.close)) {
1013
+ console.warn(
1014
+ "[parseReasoningTags] Warning: Tag found in messageContent, removing"
1015
+ );
1016
+ messageContent = messageContent.replace(
1017
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
1018
+ ""
1019
+ );
1020
+ messageContent = messageContent.replace(
1021
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
1022
+ ""
1023
+ );
1024
+ }
1025
+ if (reasoningContent.includes(tagFormat.open) || reasoningContent.includes(tagFormat.close)) {
1026
+ console.warn(
1027
+ "[parseReasoningTags] Warning: Tag found in reasoningContent, removing"
1028
+ );
1029
+ reasoningContent = reasoningContent.replace(
1030
+ new RegExp(tagFormat.open.replace(/[<>/]/g, "\\$&"), "g"),
1031
+ ""
1032
+ );
1033
+ reasoningContent = reasoningContent.replace(
1034
+ new RegExp(tagFormat.close.replace(/[<>/]/g, "\\$&"), "g"),
1035
+ ""
1036
+ );
1037
+ }
984
1038
  }
985
1039
  return {
986
1040
  messageContent,
987
1041
  reasoningContent,
988
- partialTag
1042
+ partialTag,
1043
+ insideReasoning
989
1044
  };
990
1045
  }
991
1046
  function createStreamAccumulator(initialModel) {
@@ -1044,7 +1099,10 @@ function createToolExecutorMap(tools) {
1044
1099
  }
1045
1100
  async function executeToolCall(toolCall, executor) {
1046
1101
  try {
1047
- console.log("[Tool Debug] executeToolCall - raw arguments:", toolCall.arguments);
1102
+ console.log(
1103
+ "[Tool Debug] executeToolCall - raw arguments:",
1104
+ toolCall.arguments
1105
+ );
1048
1106
  let args = {};
1049
1107
  if (toolCall.arguments) {
1050
1108
  try {
@@ -1295,11 +1353,13 @@ var CompletionsStrategy = class {
1295
1353
  if (choice.delta.content) {
1296
1354
  const parseResult = parseReasoningTags(
1297
1355
  choice.delta.content,
1298
- accumulator.partialReasoningTag || ""
1356
+ accumulator.partialReasoningTag || "",
1357
+ accumulator.insideReasoning || false
1299
1358
  );
1300
1359
  accumulator.content += parseResult.messageContent;
1301
1360
  accumulator.thinking += parseResult.reasoningContent;
1302
1361
  accumulator.partialReasoningTag = parseResult.partialTag;
1362
+ accumulator.insideReasoning = parseResult.insideReasoning;
1303
1363
  const willEmitMessage = parseResult.messageContent && parseResult.messageContent.trim().length > 0;
1304
1364
  const willEmitReasoning = parseResult.reasoningContent && parseResult.reasoningContent.trim().length > 0;
1305
1365
  if (willEmitMessage) {
@@ -1338,11 +1398,13 @@ var CompletionsStrategy = class {
1338
1398
  if (choice.message.content) {
1339
1399
  const parseResult = parseReasoningTags(
1340
1400
  choice.message.content,
1341
- accumulator.partialReasoningTag || ""
1401
+ accumulator.partialReasoningTag || "",
1402
+ accumulator.insideReasoning || false
1342
1403
  );
1343
1404
  accumulator.content = parseResult.messageContent;
1344
1405
  accumulator.thinking += parseResult.reasoningContent;
1345
1406
  accumulator.partialReasoningTag = parseResult.partialTag;
1407
+ accumulator.insideReasoning = parseResult.insideReasoning;
1346
1408
  if (parseResult.messageContent && parseResult.messageContent.trim().length > 0) {
1347
1409
  result.content = parseResult.messageContent;
1348
1410
  }
@@ -1381,7 +1443,8 @@ var CompletionsStrategy = class {
1381
1443
  if (accumulator.partialReasoningTag) {
1382
1444
  const finalParse = parseReasoningTags(
1383
1445
  "",
1384
- accumulator.partialReasoningTag
1446
+ accumulator.partialReasoningTag,
1447
+ accumulator.insideReasoning || false
1385
1448
  );
1386
1449
  finalContent += finalParse.messageContent;
1387
1450
  if (finalParse.reasoningContent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reverbia/sdk",
3
- "version": "1.0.0-next.20260114193116",
3
+ "version": "1.0.0-next.20260114225852",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",