@kenkaiiii/gg-ai 4.3.230 → 4.3.231

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/index.cjs CHANGED
@@ -44,7 +44,9 @@ __export(index_exports, {
44
44
  providerRegistry: () => providerRegistry,
45
45
  registerPalsuProvider: () => registerPalsuProvider,
46
46
  setProviderDiagnostic: () => setProviderDiagnostic,
47
- stream: () => stream
47
+ stream: () => stream,
48
+ toAnthropicMessages: () => toAnthropicMessages,
49
+ toOpenAIMessages: () => toOpenAIMessages
48
50
  });
49
51
  module.exports = __toCommonJS(index_exports);
50
52
 
@@ -406,13 +408,60 @@ function normalizeRootForAnthropic(schema) {
406
408
  }
407
409
 
408
410
  // src/providers/transform.ts
411
+ function hasValidThinkingSignature(part) {
412
+ return typeof part.signature === "string" && part.signature.trim().length > 0;
413
+ }
414
+ function isRawThinking(part) {
415
+ if (part.type !== "raw") return false;
416
+ const t = part.data.type;
417
+ return t === "thinking" || t === "redacted_thinking";
418
+ }
409
419
  function isPositionSensitiveThinking(part) {
410
- if (part.type === "thinking") return !!part.signature;
411
- if (part.type === "raw") {
412
- const t = part.data.type;
413
- return t === "thinking" || t === "redacted_thinking";
420
+ if (part.type === "thinking") return hasValidThinkingSignature(part);
421
+ return isRawThinking(part);
422
+ }
423
+ function toAnthropicAssistantPart(part, idMap) {
424
+ if (part.type === "text") return { type: "text", text: part.text };
425
+ if (part.type === "thinking") {
426
+ const sig = part.signature;
427
+ return sig && sig.trim().length > 0 ? { type: "thinking", thinking: part.text, signature: sig } : { type: "text", text: part.text };
414
428
  }
415
- return false;
429
+ if (part.type === "tool_call")
430
+ return {
431
+ type: "tool_use",
432
+ id: remapAnthropicToolCallId(part.id, idMap),
433
+ name: part.name,
434
+ input: part.args
435
+ };
436
+ if (part.type === "server_tool_call")
437
+ return {
438
+ type: "server_tool_use",
439
+ id: part.id,
440
+ name: part.name,
441
+ input: part.input
442
+ };
443
+ if (part.type === "server_tool_result")
444
+ return part.data;
445
+ if (part.type === "raw") return part.data;
446
+ return null;
447
+ }
448
+ function toAnthropicAssistantContent(content, isLatest, idMap) {
449
+ if (!isLatest) {
450
+ return content.filter((part) => {
451
+ if (part.type === "thinking" || isRawThinking(part)) return false;
452
+ if (part.type === "text" && !part.text) return false;
453
+ return true;
454
+ }).map((part) => toAnthropicAssistantPart(part, idMap)).filter((b) => b !== null);
455
+ }
456
+ const lastThinkingIdx = content.reduce(
457
+ (last, part, idx) => isPositionSensitiveThinking(part) ? idx : last,
458
+ -1
459
+ );
460
+ return content.filter((part, idx) => {
461
+ if (part.type === "thinking" && !hasValidThinkingSignature(part) && !part.text) return false;
462
+ if (part.type === "text" && !part.text && idx > lastThinkingIdx) return false;
463
+ return true;
464
+ }).map((part) => toAnthropicAssistantPart(part, idMap)).filter((b) => b !== null);
416
465
  }
417
466
  var NON_VISION_USER_IMAGE_PLACEHOLDER = "(image omitted: model does not support images)";
418
467
  var NON_VISION_TOOL_IMAGE_PLACEHOLDER = "(tool image omitted: model does not support images)";
@@ -490,7 +539,13 @@ function toAnthropicMessages(messages, cacheControl) {
490
539
  let systemText;
491
540
  const out = [];
492
541
  const idMap = /* @__PURE__ */ new Map();
542
+ const lastAssistantIdx = messages.reduce(
543
+ (last, m, i) => m.role === "assistant" ? i : last,
544
+ -1
545
+ );
546
+ let msgIdx = -1;
493
547
  for (const msg of messages) {
548
+ msgIdx++;
494
549
  if (msg.role === "system") {
495
550
  systemText = msg.content;
496
551
  continue;
@@ -513,38 +568,7 @@ function toAnthropicMessages(messages, cacheControl) {
513
568
  continue;
514
569
  }
515
570
  if (msg.role === "assistant") {
516
- const lastThinkingIdx = typeof msg.content === "string" ? -1 : msg.content.reduce(
517
- (last, part, idx) => isPositionSensitiveThinking(part) ? idx : last,
518
- -1
519
- );
520
- const content = typeof msg.content === "string" ? msg.content : msg.content.filter((part, idx) => {
521
- if (part.type === "thinking" && !part.signature && !part.text) return false;
522
- if (part.type === "text" && !part.text && idx > lastThinkingIdx) return false;
523
- return true;
524
- }).map((part) => {
525
- if (part.type === "text") return { type: "text", text: part.text };
526
- if (part.type === "thinking") {
527
- return part.signature ? { type: "thinking", thinking: part.text, signature: part.signature } : { type: "text", text: part.text };
528
- }
529
- if (part.type === "tool_call")
530
- return {
531
- type: "tool_use",
532
- id: remapAnthropicToolCallId(part.id, idMap),
533
- name: part.name,
534
- input: part.args
535
- };
536
- if (part.type === "server_tool_call")
537
- return {
538
- type: "server_tool_use",
539
- id: part.id,
540
- name: part.name,
541
- input: part.input
542
- };
543
- if (part.type === "server_tool_result")
544
- return part.data;
545
- if (part.type === "raw") return part.data;
546
- return null;
547
- }).filter(Boolean);
571
+ const content = typeof msg.content === "string" ? msg.content : toAnthropicAssistantContent(msg.content, msgIdx === lastAssistantIdx, idMap);
548
572
  if (Array.isArray(content) && content.length === 0) continue;
549
573
  out.push({ role: "assistant", content });
550
574
  continue;
@@ -2876,6 +2900,8 @@ function registerPalsuProvider(config) {
2876
2900
  providerRegistry,
2877
2901
  registerPalsuProvider,
2878
2902
  setProviderDiagnostic,
2879
- stream
2903
+ stream,
2904
+ toAnthropicMessages,
2905
+ toOpenAIMessages
2880
2906
  });
2881
2907
  //# sourceMappingURL=index.cjs.map