@code-yeongyu/senpi-ai 2026.9.7-2 → 2026.9.8

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.
Files changed (45) hide show
  1. package/dist/api/anthropic-messages.d.ts.map +1 -1
  2. package/dist/api/anthropic-messages.js +47 -178
  3. package/dist/api/anthropic-messages.js.map +1 -1
  4. package/dist/api/anthropic-tool-references.d.ts +3 -0
  5. package/dist/api/anthropic-tool-references.d.ts.map +1 -0
  6. package/dist/api/anthropic-tool-references.js +260 -0
  7. package/dist/api/anthropic-tool-references.js.map +1 -0
  8. package/dist/api/openai-codex-responses.d.ts.map +1 -1
  9. package/dist/api/openai-codex-responses.js +1 -0
  10. package/dist/api/openai-codex-responses.js.map +1 -1
  11. package/dist/api/openai-responses.d.ts.map +1 -1
  12. package/dist/api/openai-responses.js +1 -0
  13. package/dist/api/openai-responses.js.map +1 -1
  14. package/dist/auth/oauth/anthropic-callback-listener.d.ts +40 -0
  15. package/dist/auth/oauth/anthropic-callback-listener.d.ts.map +1 -0
  16. package/dist/auth/oauth/anthropic-callback-listener.js +138 -0
  17. package/dist/auth/oauth/anthropic-callback-listener.js.map +1 -0
  18. package/dist/auth/oauth/anthropic.d.ts +2 -3
  19. package/dist/auth/oauth/anthropic.d.ts.map +1 -1
  20. package/dist/auth/oauth/anthropic.js +42 -139
  21. package/dist/auth/oauth/anthropic.js.map +1 -1
  22. package/dist/auth/oauth/authorization-input.d.ts +6 -0
  23. package/dist/auth/oauth/authorization-input.d.ts.map +1 -0
  24. package/dist/auth/oauth/authorization-input.js +29 -0
  25. package/dist/auth/oauth/authorization-input.js.map +1 -0
  26. package/dist/auth/oauth/error-details.d.ts +3 -0
  27. package/dist/auth/oauth/error-details.d.ts.map +1 -0
  28. package/dist/auth/oauth/error-details.js +20 -0
  29. package/dist/auth/oauth/error-details.js.map +1 -0
  30. package/dist/providers/data/.manifest.json +1 -1
  31. package/dist/providers/data/fireworks.json +1 -1
  32. package/dist/providers/data/opengateway.json +1 -1
  33. package/dist/providers/data/openrouter.json +1 -1
  34. package/dist/providers/data/vercel-ai-gateway.json +1 -1
  35. package/dist/tool-call-middleware/recovery-stream-terminal.d.ts.map +1 -1
  36. package/dist/tool-call-middleware/recovery-stream-terminal.js +16 -1
  37. package/dist/tool-call-middleware/recovery-stream-terminal.js.map +1 -1
  38. package/dist/types.d.ts +7 -0
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/types.js.map +1 -1
  41. package/dist/utils/server-fallback-receipt.d.ts +2 -1
  42. package/dist/utils/server-fallback-receipt.d.ts.map +1 -1
  43. package/dist/utils/server-fallback-receipt.js +16 -0
  44. package/dist/utils/server-fallback-receipt.js.map +1 -1
  45. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAMX,+BAA+B,EAK/B,MAAM,uDAAuD,CAAC;AAG/D,OAAO,KAAK,EACX,wBAAwB,EAKxB,OAAO,EAGP,KAAK,EAGL,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAOb,MAAM,aAAa,CAAC;AAqCrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AA6JlE,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AA+FhE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe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AAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,wEAAwE;IACxE,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;IAC5C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB;AAmvBD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CAudzE,CAAC;AAyFF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CA+ClF,CAAC;AA6IF,wBAAgB,mCAAmC,CAClD,KAAK,EAAE,KAAK,CAAC,oBAAoB,CAAC,EAClC,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE,gBAAgB,GACxB,+BAA+B,CAkBjC"}
@@ -15,12 +15,12 @@ import { retryProviderRequest } from "../utils/provider-retry.js";
15
15
  import { appendRetryAfterMsMarker, extract429RetryAfterMs } from "../utils/retry-hint.js";
16
16
  import { normalizeAnthropicRetryFailure } from "../utils/retry-profile/failure.js";
17
17
  import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
18
- import { applyServerFallbackAbort, parseServerFallbackReceipt, parseStickyFallbackReceipt, } from "../utils/server-fallback-receipt.js";
18
+ import { applyServerFallbackAbort, applyServerFallbackContinuation, parseServerFallbackReceipt, parseStickyFallbackReceipt, } from "../utils/server-fallback-receipt.js";
19
19
  import { normalizeToolCallId } from "../utils/tool-call-id.js";
20
20
  import { isForcedToolChoiceUnsupportedError, omitToolChoiceParam } from "../utils/tool-choice-fallback.js";
21
21
  import { resolveRootObjectSchema } from "../utils/tool-schema-compat.js";
22
- import { demotedToolCallText, demotedToolResultText } from "../utils/unavailable-tool-text.js";
23
22
  import { sanitizeAnthropicToolPairs } from "./anthropic-tool-pairs.js";
23
+ import { demoteUnavailableToolReferences } from "./anthropic-tool-references.js";
24
24
  import { resolveCloudflareBaseUrl } from "./cloudflare.js";
25
25
  import { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling } from "./constrained-sampling.js";
26
26
  import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
@@ -571,157 +571,12 @@ function sanitizeUnsupportedNativeTools(model, params) {
571
571
  }
572
572
  return changed ? sanitized : params;
573
573
  }
574
- /**
575
- * Anthropic validates that every tool referenced by the message history is
576
- * available in the same request — defined in `tools` or discovered through a
577
- * `tool_reference` block — and rejects the whole request otherwise
578
- * ("Tool reference '<name>' not found in available tools"). Sessions outlive
579
- * their tools: an MCP server can be absent after a resume, an extension can
580
- * stop registering a tool, or a payload hook can strip a definition while the
581
- * history still carries the call. Demote those references to plain text so
582
- * the turn can proceed; the matching tool_result is demoted in lockstep so no
583
- * orphan pairing error replaces the original one.
584
- */
585
- function demoteUnavailableToolReferences(params) {
586
- const messages = params.messages;
587
- if (!Array.isArray(messages) || messages.length === 0)
588
- return params;
589
- const definedNames = new Set();
590
- if (Array.isArray(params.tools)) {
591
- for (const tool of params.tools) {
592
- if (isRecord(tool) && typeof tool.name === "string")
593
- definedNames.add(tool.name);
594
- }
595
- }
596
- // `tool_reference` blocks — emitted for deferred tools or replayed from a
597
- // server-side tool search — make their targets available without a
598
- // non-deferred definition.
599
- const discoveredNames = new Set();
600
- collectToolReferenceNames(messages, discoveredNames);
601
- const demotedCallNames = new Map();
602
- for (const message of messages) {
603
- if (message.role !== "assistant" || !Array.isArray(message.content))
604
- continue;
605
- for (const block of message.content) {
606
- if (isRecord(block) &&
607
- block.type === "tool_use" &&
608
- typeof block.name === "string" &&
609
- !definedNames.has(block.name) &&
610
- !discoveredNames.has(block.name)) {
611
- demotedCallNames.set(block.id, block.name);
612
- }
613
- }
614
- }
615
- // A `tool_reference` without its definition 400s the same way.
616
- const danglingReferenceNames = new Set();
617
- for (const name of discoveredNames) {
618
- if (!definedNames.has(name))
619
- danglingReferenceNames.add(name);
620
- }
621
- if (demotedCallNames.size === 0 && danglingReferenceNames.size === 0)
622
- return params;
623
- let changed = false;
624
- const availableToolNames = [...definedNames];
625
- const seenDemotedCallNames = new Set();
626
- const rewrittenMessages = [];
627
- for (const message of messages) {
628
- if (!Array.isArray(message.content)) {
629
- rewrittenMessages.push(message);
630
- continue;
631
- }
632
- let messageChanged = false;
633
- const content = [];
634
- for (const block of message.content) {
635
- if (message.role === "assistant" && isRecord(block) && block.type === "tool_use") {
636
- const demotedName = demotedCallNames.get(block.id);
637
- if (demotedName !== undefined) {
638
- messageChanged = true;
639
- const firstOccurrence = !seenDemotedCallNames.has(demotedName);
640
- seenDemotedCallNames.add(demotedName);
641
- content.push({
642
- type: "text",
643
- text: demotedToolCallText(demotedName, availableToolNames, firstOccurrence),
644
- });
645
- continue;
646
- }
647
- }
648
- if (isRecord(block) && block.type === "tool_result") {
649
- const demotedName = demotedCallNames.get(block.tool_use_id);
650
- if (demotedName !== undefined) {
651
- messageChanged = true;
652
- content.push({ type: "text", text: demotedToolResultText(demotedName, toolResultText(block.content)) });
653
- continue;
654
- }
655
- if (danglingReferenceNames.size > 0 && Array.isArray(block.content)) {
656
- const kept = [];
657
- const omitted = [];
658
- for (const item of block.content) {
659
- if (isRecord(item) &&
660
- item.type === "tool_reference" &&
661
- typeof item.tool_name === "string" &&
662
- danglingReferenceNames.has(item.tool_name)) {
663
- omitted.push(item.tool_name);
664
- continue;
665
- }
666
- kept.push(item);
667
- }
668
- if (omitted.length > 0) {
669
- messageChanged = true;
670
- const nextContent = kept.length > 0
671
- ? kept
672
- : [{ type: "text", text: `Tool reference unavailable: ${[...new Set(omitted)].join(", ")}` }];
673
- content.push({ ...block, content: nextContent });
674
- continue;
675
- }
676
- }
677
- }
678
- content.push(block);
679
- }
680
- if (content.length === 0) {
681
- changed = true;
682
- continue;
683
- }
684
- if (messageChanged) {
685
- changed = true;
686
- rewrittenMessages.push({ ...message, content });
687
- continue;
688
- }
689
- rewrittenMessages.push(message);
690
- }
691
- if (!changed)
692
- return params;
693
- return { ...params, messages: rewrittenMessages };
694
- }
695
- function collectToolReferenceNames(value, names) {
696
- if (Array.isArray(value)) {
697
- for (const item of value)
698
- collectToolReferenceNames(item, names);
699
- return;
700
- }
701
- if (!isRecord(value))
702
- return;
703
- if (value.type === "tool_reference" && typeof value.tool_name === "string")
704
- names.add(value.tool_name);
705
- for (const nested of Object.values(value))
706
- collectToolReferenceNames(nested, names);
707
- }
708
- function toolResultText(content) {
709
- if (typeof content === "string")
710
- return content;
711
- if (Array.isArray(content)) {
712
- const parts = [];
713
- for (const item of content) {
714
- if (!isRecord(item))
715
- continue;
716
- if (item.type === "text" && typeof item.text === "string")
717
- parts.push(item.text);
718
- else if (typeof item.type === "string")
719
- parts.push(`[${item.type}]`);
720
- }
721
- if (parts.length > 0)
722
- return parts.join("\n");
723
- }
724
- return "Tool output unavailable.";
574
+ /** Numeric HTTP status carried by an SDK error (Anthropic APIError.status), if any. */
575
+ function httpStatusOfError(error) {
576
+ if (!isRecord(error))
577
+ return undefined;
578
+ const status = error.status;
579
+ return typeof status === "number" && Number.isInteger(status) && status >= 100 && status < 600 ? status : undefined;
725
580
  }
726
581
  function sanitizeAdaptiveThinkingPayload(model, params, options) {
727
582
  if (!supportsAdaptiveThinking(model)) {
@@ -1046,24 +901,40 @@ export const stream = (model, context, options) => {
1046
901
  throw error;
1047
902
  }
1048
903
  };
1049
- const { params: sentParams, response } = await retryProviderRequest(async () => {
1050
- try {
1051
- return await createRequest();
1052
- }
1053
- catch (error) {
1054
- if (unsignedThinkingReplay !== "text" && isInvalidUnsignedThinkingSignatureError(error)) {
1055
- unsignedThinkingReplay = "text";
1056
- if (fallbackKey)
1057
- unsignedThinkingTextReplayFallbacks.add(fallbackKey);
1058
- return createRequest();
904
+ let requestOutcome;
905
+ try {
906
+ requestOutcome = await retryProviderRequest(async () => {
907
+ try {
908
+ return await createRequest();
1059
909
  }
1060
- throw error;
910
+ catch (error) {
911
+ if (unsignedThinkingReplay !== "text" && isInvalidUnsignedThinkingSignatureError(error)) {
912
+ unsignedThinkingReplay = "text";
913
+ if (fallbackKey)
914
+ unsignedThinkingTextReplayFallbacks.add(fallbackKey);
915
+ return createRequest();
916
+ }
917
+ throw error;
918
+ }
919
+ }, {
920
+ maxRetries: options?.maxRetries,
921
+ maxRetryDelayMs: options?.maxRetryDelayMs,
922
+ signal: requestSignal,
923
+ });
924
+ }
925
+ catch (error) {
926
+ // The SDK rejects HTTP failures instead of returning a Response, so a
927
+ // rejected request never reached onResponse. Deliver the numeric status
928
+ // once, after every internal retry, before the caller handles the error;
929
+ // errors without a status (network, aborts) report nothing rather than
930
+ // a fabricated code.
931
+ const status = httpStatusOfError(error);
932
+ if (status !== undefined) {
933
+ await options?.onResponse?.({ status, headers: {} }, model);
1061
934
  }
1062
- }, {
1063
- maxRetries: options?.maxRetries,
1064
- maxRetryDelayMs: options?.maxRetryDelayMs,
1065
- signal: requestSignal,
1066
- });
935
+ throw error;
936
+ }
937
+ const { params: sentParams, response } = requestOutcome;
1067
938
  await options?.onResponse?.({ status: response.status, headers: headersToRecord(response.headers) }, model);
1068
939
  stream.push({ type: "start", partial: output });
1069
940
  const blocks = output.content;
@@ -1102,16 +973,14 @@ export const stream = (model, context, options) => {
1102
973
  }
1103
974
  }
1104
975
  else if (event.type === "content_block_start") {
1105
- if (event.content_block.type === "fallback" && output.content.length > 0) {
1106
- throw new Error("Anthropic performed an unsupported mid-output model fallback");
1107
- }
1108
- const receipt = options?.abortServerSideFallback === true
1109
- ? parseServerFallbackReceipt(event.content_block)
1110
- : undefined;
976
+ const receipt = parseServerFallbackReceipt(event.content_block);
1111
977
  if (receipt !== undefined) {
1112
- serverFallbackReceipt = receipt;
1113
- serverFallbackAbort.abort();
1114
- break;
978
+ if (options?.abortServerSideFallback === true) {
979
+ serverFallbackReceipt = receipt;
980
+ serverFallbackAbort.abort();
981
+ break;
982
+ }
983
+ usageModel = applyServerFallbackContinuation(output, model, receipt);
1115
984
  }
1116
985
  if (event.content_block.type === "text") {
1117
986
  const block = {