@code-yeongyu/senpi 2026.10.5 → 2026.10.7

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 (151) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/bundle/chunks/{anthropic-messages-G5236QNK.js → anthropic-messages-4MNFPQ66.js} +1 -1
  3. package/dist/bundle/chunks/{app-server-command-3Q5G4CAF.js → app-server-command-SO5RJ2N7.js} +1 -1
  4. package/dist/bundle/chunks/{azure-openai-responses-NTA2HGG4.js → azure-openai-responses-A5OEHSJM.js} +1 -1
  5. package/dist/bundle/chunks/bedrock-converse-stream.js +1 -1
  6. package/dist/bundle/chunks/{chunk-ECDLITEY.js → chunk-6EH7QXOG.js} +2 -2
  7. package/dist/bundle/chunks/{chunk-JVSOW4QU.js → chunk-7A3WRAKP.js} +1 -1
  8. package/dist/bundle/chunks/chunk-7SMFF2QJ.js +14 -0
  9. package/dist/bundle/chunks/{chunk-WTJU5B2C.js → chunk-BE66QJ3Z.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-6JXPZACL.js → chunk-CM5QTRC2.js} +1 -1
  11. package/dist/bundle/chunks/{chunk-UHRXXTFZ.js → chunk-D2W3MXRF.js} +2 -2
  12. package/dist/bundle/chunks/{chunk-U7CI2JGX.js → chunk-DDEAZX22.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-UXIQK5NQ.js → chunk-ESSQUSRC.js} +1 -1
  14. package/dist/bundle/chunks/{chunk-EEOKVSNF.js → chunk-EUU6W5B3.js} +180 -176
  15. package/dist/bundle/chunks/{chunk-KLBKUBDV.js → chunk-GQ3YLXVZ.js} +1 -1
  16. package/dist/bundle/chunks/{chunk-HKG7XL4H.js → chunk-HY4AOLON.js} +1 -1
  17. package/dist/bundle/chunks/{chunk-2WV426OJ.js → chunk-JJNIU2A2.js} +8 -4
  18. package/dist/bundle/chunks/{chunk-22DAHAHO.js → chunk-LUWWM7GA.js} +2 -2
  19. package/dist/bundle/chunks/{chunk-CTQU2XNX.js → chunk-MLNJNJFE.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-BPX6QWPD.js → chunk-PELNNWGO.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-BBK6SSYT.js → chunk-TAV6QZFM.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-QUROHJLP.js → chunk-TFO5JGLR.js} +1 -1
  23. package/dist/bundle/chunks/chunk-VJJ53ORU.js +2 -0
  24. package/dist/bundle/chunks/{chunk-XYDZ3LIE.js → chunk-YI7SPFDN.js} +2 -2
  25. package/dist/bundle/chunks/chunk-ZJHRDQCH.js +2 -0
  26. package/dist/bundle/chunks/cli-main-XBQN73O2.js +3 -0
  27. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-5ZUHUKMU.js → cloudflare-workers-ai-system-one-TE3OEJEL.js} +1 -1
  28. package/dist/bundle/chunks/{google-generative-ai-OTMG6ZXI.js → google-generative-ai-JBC53AMK.js} +1 -1
  29. package/dist/bundle/chunks/{google-vertex-2LXS3ICC.js → google-vertex-46ODNPM2.js} +1 -1
  30. package/dist/bundle/chunks/{help-fast-path-SHZJ3QWQ.js → help-fast-path-FUMH5NSA.js} +1 -1
  31. package/dist/bundle/chunks/host-command-YXQAXNKK.js +2 -0
  32. package/dist/bundle/chunks/{host-lifecycle-7OVWGVIZ.js → host-lifecycle-L4XQIATP.js} +1 -1
  33. package/dist/bundle/chunks/host-lifecycle.js +1 -1
  34. package/dist/bundle/chunks/interactive-mode-ROO5W56P.js +2 -0
  35. package/dist/bundle/chunks/{llama-cpp-classify-U5XAMKZE.js → llama-cpp-classify-AD6TTKNL.js} +1 -1
  36. package/dist/bundle/chunks/{multi-session-host-34WOINP4.js → multi-session-host-5WTKAQJM.js} +5 -5
  37. package/dist/bundle/chunks/{openai-codex-responses-WNTYIPFZ.js → openai-codex-responses-Q4OWIK7Y.js} +1 -1
  38. package/dist/bundle/chunks/{openai-completions-VSH22FCN.js → openai-completions-6HU7GIGD.js} +1 -1
  39. package/dist/bundle/chunks/{openai-images-XBTUJXPR.js → openai-images-M73YANTR.js} +1 -1
  40. package/dist/bundle/chunks/{openai-responses-WLBHCFYL.js → openai-responses-S4QYZXF3.js} +1 -1
  41. package/dist/bundle/chunks/{openrouter-images-3LVJZY3G.js → openrouter-images-PCJFX2KO.js} +1 -1
  42. package/dist/bundle/chunks/{package-manager-cli-2QLVGQSC.js → package-manager-cli-NCD5FQGV.js} +1 -1
  43. package/dist/bundle/chunks/{rotation-stream-JUCEXHWU.js → rotation-stream-7E37KOCX.js} +1 -1
  44. package/dist/bundle/chunks/rpc-mode-MWURKCP2.js +2 -0
  45. package/dist/bundle/chunks/{schedule-command-QTYSUYO2.js → schedule-command-UTXB465F.js} +1 -1
  46. package/dist/bundle/chunks/session-control-endpoint-J6RHZXWB.js +3 -0
  47. package/dist/bundle/chunks/{session-picker-HX4LOJZ7.js → session-picker-VTTRFGE7.js} +1 -1
  48. package/dist/bundle/chunks/session-worker.js +376 -368
  49. package/dist/bundle/chunks/{typesafe-system-one-FNI3UASE.js → typesafe-system-one-TF23RUVG.js} +1 -1
  50. package/dist/bundle/cli.js +1 -1
  51. package/dist/bundle/index.js +1 -1
  52. package/dist/bundle/rpc-entry.js +1 -1
  53. package/dist/bundle/runtime-manifest.json +1 -1
  54. package/dist/core/agent-session-runtime.d.ts +12 -0
  55. package/dist/core/agent-session.d.ts +18 -0
  56. package/dist/core/agent-session.js +55 -19
  57. package/dist/core/dynamic-prompt/handoff.d.ts +4 -2
  58. package/dist/core/dynamic-prompt/handoff.js +1 -1
  59. package/dist/core/extensions/builtin/diff.js +14 -9
  60. package/dist/core/extensions/builtin/files.js +6 -2
  61. package/dist/core/extensions/builtin/gpt-apply-patch/parser.js +5 -1
  62. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-parser.d.ts +8 -0
  63. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-parser.js +26 -2
  64. package/dist/core/extensions/builtin/gpt-apply-patch/streaming-render.js +82 -11
  65. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts +9 -1
  66. package/dist/core/extensions/builtin/permission-system/auto-credentials.d.ts +2 -0
  67. package/dist/core/extensions/builtin/permission-system/auto-credentials.js +17 -0
  68. package/dist/core/extensions/builtin/permission-system/auto-paths.d.ts +14 -0
  69. package/dist/core/extensions/builtin/permission-system/auto-paths.js +93 -0
  70. package/dist/core/extensions/builtin/permission-system/auto-policy.d.ts +20 -0
  71. package/dist/core/extensions/builtin/permission-system/auto-policy.js +126 -0
  72. package/dist/core/extensions/builtin/permission-system/auto-program-rules.d.ts +6 -0
  73. package/dist/core/extensions/builtin/permission-system/auto-program-rules.js +139 -0
  74. package/dist/core/extensions/builtin/permission-system/auto-shell-grammar.d.ts +29 -0
  75. package/dist/core/extensions/builtin/permission-system/auto-shell-grammar.js +74 -0
  76. package/dist/core/extensions/builtin/permission-system/auto-shell-segments.d.ts +13 -0
  77. package/dist/core/extensions/builtin/permission-system/auto-shell-segments.js +23 -0
  78. package/dist/core/extensions/builtin/permission-system/cli.d.ts +1 -0
  79. package/dist/core/extensions/builtin/permission-system/cli.js +9 -10
  80. package/dist/core/extensions/builtin/permission-system/config.d.ts +4 -1
  81. package/dist/core/extensions/builtin/permission-system/config.js +13 -1
  82. package/dist/core/extensions/builtin/permission-system/index.js +20 -12
  83. package/dist/core/extensions/builtin/permission-system/non-interactive.d.ts +11 -6
  84. package/dist/core/extensions/builtin/permission-system/non-interactive.js +8 -33
  85. package/dist/core/extensions/builtin/permission-system/service.d.ts +20 -1
  86. package/dist/core/extensions/builtin/permission-system/service.js +43 -7
  87. package/dist/core/extensions/builtin/permission-system/settings.d.ts +1 -0
  88. package/dist/core/extensions/builtin/permission-system/settings.js +4 -3
  89. package/dist/core/extensions/builtin/permission-system/types.d.ts +1 -1
  90. package/dist/core/extensions/builtin/prompt-preset/claude-fable-5-1.js +16 -3
  91. package/dist/core/extensions/eval-handle-host.d.ts +82 -0
  92. package/dist/core/extensions/eval-handle-host.js +28 -0
  93. package/dist/core/extensions/loader.js +5 -0
  94. package/dist/core/extensions/runner.js +4 -0
  95. package/dist/core/extensions/types.d.ts +15 -0
  96. package/dist/core/retry-fallback/usage-limit.js +5 -1
  97. package/dist/core/tools/diff-render.d.ts +4 -0
  98. package/dist/core/tools/diff-render.js +13 -0
  99. package/dist/core/tools/renderers/edit.js +6 -4
  100. package/dist/index.d.ts +1 -0
  101. package/dist/index.js +1 -0
  102. package/dist/main.js +12 -0
  103. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  104. package/dist/modes/interactive/interactive-mode.js +55 -11
  105. package/dist/modes/interactive/provider-error-presentation.d.ts +25 -0
  106. package/dist/modes/interactive/provider-error-presentation.js +42 -0
  107. package/dist/modes/interactive/session-control-registry.js +2 -0
  108. package/dist/modes/interactive/theme/dark.json +5 -5
  109. package/dist/modes/interactive/theme/light.json +5 -5
  110. package/dist/modes/rpc/custom-capability.d.ts +6 -0
  111. package/dist/modes/rpc/custom-capability.js +6 -0
  112. package/dist/modes/rpc/host-daemon-registration.d.ts +9 -0
  113. package/dist/modes/rpc/host-daemon-registration.js +2 -4
  114. package/dist/modes/rpc/host-ensure-start.js +2 -0
  115. package/dist/modes/rpc/host-handoff-unregistered.d.ts +24 -0
  116. package/dist/modes/rpc/host-handoff-unregistered.js +50 -0
  117. package/dist/modes/rpc/host-handoff.d.ts +7 -2
  118. package/dist/modes/rpc/host-handoff.js +7 -3
  119. package/dist/modes/rpc/host-legacy.d.ts +3 -0
  120. package/dist/modes/rpc/host-legacy.js +10 -5
  121. package/dist/modes/rpc/host-probe.d.ts +12 -0
  122. package/dist/modes/rpc/host-probe.js +53 -5
  123. package/dist/modes/rpc/host-runner.js +1 -1
  124. package/dist/modes/rpc/host-successor.d.ts +5 -4
  125. package/dist/modes/rpc/host-successor.js +11 -4
  126. package/dist/modes/rpc/rpc-client.d.ts +3 -0
  127. package/dist/modes/rpc/rpc-input-validation.d.ts +7 -0
  128. package/dist/modes/rpc/rpc-input-validation.js +37 -0
  129. package/dist/modes/rpc/rpc-types.d.ts +9 -0
  130. package/dist/modes/rpc/session-command-activity.d.ts +2 -0
  131. package/dist/modes/rpc/session-command-activity.js +25 -0
  132. package/dist/modes/rpc/session-command-router.js +11 -4
  133. package/dist/modes/rpc/session-registry-attach.js +1 -0
  134. package/dist/modes/rpc/session-registry-types.d.ts +7 -0
  135. package/dist/modes/rpc/session-registry-types.js +11 -0
  136. package/dist/modes/rpc/session-registry.js +6 -3
  137. package/dist/modes/rpc/session-sweep.d.ts +12 -2
  138. package/dist/modes/rpc/session-sweep.js +36 -3
  139. package/dist/modes/rpc/session-teardown.d.ts +2 -0
  140. package/dist/modes/rpc/session-teardown.js +1 -0
  141. package/dist/modes/rpc/worker-session-registry.js +5 -1
  142. package/docs/rpc.md +49 -7
  143. package/docs/settings.md +3 -1
  144. package/package.json +6 -6
  145. package/dist/bundle/chunks/chunk-K3BXFPWZ.js +0 -2
  146. package/dist/bundle/chunks/chunk-UUAKEDVS.js +0 -14
  147. package/dist/bundle/chunks/cli-main-VZWSUHFB.js +0 -3
  148. package/dist/bundle/chunks/host-command-7JIGGOWR.js +0 -2
  149. package/dist/bundle/chunks/interactive-mode-JA7AHYYL.js +0 -2
  150. package/dist/bundle/chunks/rpc-mode-QEBSN2OH.js +0 -2
  151. package/dist/bundle/chunks/session-control-endpoint-UGQIP6ZN.js +0 -3
@@ -1,3 +1,3 @@
1
1
  import { createRequire as __piCreateRequire } from "node:module"; const require = __piCreateRequire(import.meta.url); { const __piWorkerThreads = require("node:worker_threads"); if (typeof __piWorkerThreads.markAsUncloneable !== "function") { __piWorkerThreads.markAsUncloneable = () => {}; } }
2
- import{classifyProviderFailure}from"./chunk-YOPVJDSU.js";import{attachProviderDiagnostic}from"./chunk-45SZOLCU.js";import{normalizeProviderError}from"./chunk-BBK6SSYT.js";import{formatProviderRequestId}from"./chunk-XL5KIYQF.js";import{appendAssistantMessageDiagnostic}from"./chunk-DMI55M2N.js";var GITHUB_COPILOT_TOOL_LIMIT=128,GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC="github_copilot_tool_limit";function isRecord(value){return typeof value=="object"&&value!==null}function selectedToolName(toolChoice){if(isRecord(toolChoice)){if(toolChoice.type==="function")return isRecord(toolChoice.function)&&typeof toolChoice.function.name=="string"?toolChoice.function.name:typeof toolChoice.name=="string"?toolChoice.name:void 0;if(!(toolChoice.type!=="custom"&&toolChoice.type!=="tool"))return typeof toolChoice.name=="string"?toolChoice.name:void 0}}function toolName(tool){if(isRecord(tool))return tool.type==="function"&&isRecord(tool.function)&&typeof tool.function.name=="string"?tool.function.name:typeof tool.name=="string"?tool.name:void 0}function limitGitHubCopilotTools(provider,tools,toolChoice){if(provider!=="github-copilot"||tools===void 0||tools.length<=GITHUB_COPILOT_TOOL_LIMIT)return{tools,omittedCount:0};let forcedName=selectedToolName(toolChoice),forcedIndex=forcedName===void 0?-1:tools.findIndex(tool=>toolName(tool)===forcedName);if(forcedIndex>=GITHUB_COPILOT_TOOL_LIMIT){let forcedTool=tools[forcedIndex];if(forcedTool!==void 0)return{tools:[...tools.slice(0,GITHUB_COPILOT_TOOL_LIMIT-1),forcedTool],omittedCount:tools.length-GITHUB_COPILOT_TOOL_LIMIT}}return{tools:tools.slice(0,GITHUB_COPILOT_TOOL_LIMIT),omittedCount:tools.length-GITHUB_COPILOT_TOOL_LIMIT}}function recordGitHubCopilotToolLimit(message,omittedCount){omittedCount===0||message.diagnostics?.some(diagnostic=>diagnostic.type===GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC)||appendAssistantMessageDiagnostic(message,{type:GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC,timestamp:Date.now(),details:{limit:GITHUB_COPILOT_TOOL_LIMIT,omittedCount,message:`GitHub Copilot accepts at most ${GITHUB_COPILOT_TOOL_LIMIT} tools on endpoints without tool search; senpi omitted ${omittedCount} excess tool definition${omittedCount===1?"":"s"}.`}})}function formatGitHubCopilotToolLimitError(message,errorMessage){let toolLimitApplied=message.diagnostics?.some(diagnostic=>diagnostic.type===GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC);return message.provider!=="github-copilot"||!toolLimitApplied||message.providerDiagnostic?.httpStatus!==400||!/400 Bad Request$/i.test(errorMessage)?errorMessage:`GitHub Copilot rejected the request after senpi limited its tool list to ${GITHUB_COPILOT_TOOL_LIMIT}. The endpoint may enforce a lower limit or count additional hosted tools. (${errorMessage})`}var SSE_ERROR_ENVELOPE_MAX_BYTES=8192;function isRecord2(value){return typeof value=="object"&&value!==null&&!Array.isArray(value)}function optionalString(value){if(value!=null)return typeof value=="string"?value:null}function anthropicProviderDiagnosticFromError(error){try{if(!(error instanceof Error))return;let status=Reflect.get(error,"status"),direct=optionalString(Reflect.get(error,"type")),body=Reflect.get(error,"error"),nested=isRecord2(body)&&isRecord2(body.error)?optionalString(body.error.type):void 0;if(direct===null||nested===null||direct!==void 0&&nested!==void 0&&direct!==nested)return;let code=direct??nested;return code===void 0&&status==null?void 0:classifyProviderFailure({status,code})}catch{return}}function anthropicProviderDiagnosticFromSseData(data){try{if(new TextEncoder().encode(data).length>SSE_ERROR_ENVELOPE_MAX_BYTES)return;let parsed=JSON.parse(data);if(!isRecord2(parsed)||parsed.type!=="error"||!isRecord2(parsed.error))return;let code=parsed.error.type;return typeof code!="string"?void 0:classifyProviderFailure({status:void 0,code})}catch{return}}function openAICompatibleProviderDiagnosticFromError(error){try{if(!(error instanceof Error))return;let status=Reflect.get(error,"status"),code=optionalString(Reflect.get(error,"code"));return code===null||code===void 0&&status==null?void 0:classifyProviderFailure({status,code})}catch{return}}async function awaitProviderTransport(request,classify){try{return await request()}catch(error){throw typeof error=="object"&&error!==null&&attachProviderDiagnostic(error,classify(error)),error}}async function*iterateProviderTransport(source,classify){try{yield*source}catch(error){throw typeof error=="object"&&error!==null&&attachProviderDiagnostic(error,classify(error)),error}}var QUOTA_CODES=new Set(["quota_exceeded","free_quota_exceeded","overage_limit_reached","billing_not_configured","additional_spend_limit_reached"]);function headerValue(headers,name){if(headers instanceof Headers)return headers.get(name)??void 0;if(!(typeof headers!="object"||headers===null)){for(let[key,value]of Object.entries(headers))if(key.toLowerCase()===name&&typeof value=="string")return value}}function errorCode(body){if(body!==void 0)try{let parsed=JSON.parse(body);if(typeof parsed!="object"||parsed===null)return;let nested=Reflect.get(parsed,"error"),code=Reflect.get(typeof nested=="object"&&nested!==null?nested:parsed,"code");return typeof code=="string"?code:void 0}catch{return}}function isQuotaFailure(status,body,limitKey){let code=errorCode(body);return code!==void 0&&QUOTA_CODES.has(code)||status===402?!0:status===429&&(limitKey?.includes("quota")===!0||/quota exceeded/i.test(body??""))}function describeGitHubCopilotFailure(error){if(!(error instanceof Error))return;let{status,body}=normalizeProviderError(error);if(status===void 0)return;let headers=Reflect.get(error,"headers"),requestId=headerValue(headers,"x-github-request-id"),reference=requestId===void 0?"":` ${formatProviderRequestId("GitHub",requestId)}.`;if(isQuotaFailure(status,body,headerValue(headers,"x-ratelimit-exceeded")))return`GitHub Copilot quota exceeded (HTTP ${status}): the plan's included usage or its additional-usage limit is used up, so premium models are refused until it resets or the limit is raised. Usage is shown at https://github.com/settings/copilot.${reference}`;if(status===421)return`GitHub Copilot sent this account to a different API host (HTTP 421 Misdirected Request): Business and Enterprise accounts are served from their own host, which senpi reads from the Copilot token. Run /login github-copilot so senpi stores the account's endpoint, and report it with the GitHub request id if it persists.${reference}`;if(status===403)return`GitHub Copilot refused the request (HTTP 403${body===void 0?" with an empty body":""}). Copilot checks access per model and per client; if a fresh /login github-copilot does not help, report it with the GitHub request id.${reference}`}function withGitHubCopilotFailureNote(message,provider,error){if(provider!=="github-copilot")return message;let note=describeGitHubCopilotFailure(error);return note===void 0?message:`${message}
2
+ import{classifyProviderFailure}from"./chunk-YOPVJDSU.js";import{attachProviderDiagnostic}from"./chunk-45SZOLCU.js";import{normalizeProviderError}from"./chunk-TAV6QZFM.js";import{formatProviderRequestId}from"./chunk-XL5KIYQF.js";import{appendAssistantMessageDiagnostic}from"./chunk-DMI55M2N.js";var GITHUB_COPILOT_TOOL_LIMIT=128,GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC="github_copilot_tool_limit";function isRecord(value){return typeof value=="object"&&value!==null}function selectedToolName(toolChoice){if(isRecord(toolChoice)){if(toolChoice.type==="function")return isRecord(toolChoice.function)&&typeof toolChoice.function.name=="string"?toolChoice.function.name:typeof toolChoice.name=="string"?toolChoice.name:void 0;if(!(toolChoice.type!=="custom"&&toolChoice.type!=="tool"))return typeof toolChoice.name=="string"?toolChoice.name:void 0}}function toolName(tool){if(isRecord(tool))return tool.type==="function"&&isRecord(tool.function)&&typeof tool.function.name=="string"?tool.function.name:typeof tool.name=="string"?tool.name:void 0}function limitGitHubCopilotTools(provider,tools,toolChoice){if(provider!=="github-copilot"||tools===void 0||tools.length<=GITHUB_COPILOT_TOOL_LIMIT)return{tools,omittedCount:0};let forcedName=selectedToolName(toolChoice),forcedIndex=forcedName===void 0?-1:tools.findIndex(tool=>toolName(tool)===forcedName);if(forcedIndex>=GITHUB_COPILOT_TOOL_LIMIT){let forcedTool=tools[forcedIndex];if(forcedTool!==void 0)return{tools:[...tools.slice(0,GITHUB_COPILOT_TOOL_LIMIT-1),forcedTool],omittedCount:tools.length-GITHUB_COPILOT_TOOL_LIMIT}}return{tools:tools.slice(0,GITHUB_COPILOT_TOOL_LIMIT),omittedCount:tools.length-GITHUB_COPILOT_TOOL_LIMIT}}function recordGitHubCopilotToolLimit(message,omittedCount){omittedCount===0||message.diagnostics?.some(diagnostic=>diagnostic.type===GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC)||appendAssistantMessageDiagnostic(message,{type:GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC,timestamp:Date.now(),details:{limit:GITHUB_COPILOT_TOOL_LIMIT,omittedCount,message:`GitHub Copilot accepts at most ${GITHUB_COPILOT_TOOL_LIMIT} tools on endpoints without tool search; senpi omitted ${omittedCount} excess tool definition${omittedCount===1?"":"s"}.`}})}function formatGitHubCopilotToolLimitError(message,errorMessage){let toolLimitApplied=message.diagnostics?.some(diagnostic=>diagnostic.type===GITHUB_COPILOT_TOOL_LIMIT_DIAGNOSTIC);return message.provider!=="github-copilot"||!toolLimitApplied||message.providerDiagnostic?.httpStatus!==400||!/400 Bad Request$/i.test(errorMessage)?errorMessage:`GitHub Copilot rejected the request after senpi limited its tool list to ${GITHUB_COPILOT_TOOL_LIMIT}. The endpoint may enforce a lower limit or count additional hosted tools. (${errorMessage})`}var SSE_ERROR_ENVELOPE_MAX_BYTES=8192;function isRecord2(value){return typeof value=="object"&&value!==null&&!Array.isArray(value)}function optionalString(value){if(value!=null)return typeof value=="string"?value:null}function anthropicProviderDiagnosticFromError(error){try{if(!(error instanceof Error))return;let status=Reflect.get(error,"status"),direct=optionalString(Reflect.get(error,"type")),body=Reflect.get(error,"error"),nested=isRecord2(body)&&isRecord2(body.error)?optionalString(body.error.type):void 0;if(direct===null||nested===null||direct!==void 0&&nested!==void 0&&direct!==nested)return;let code=direct??nested;return code===void 0&&status==null?void 0:classifyProviderFailure({status,code})}catch{return}}function anthropicProviderDiagnosticFromSseData(data){try{if(new TextEncoder().encode(data).length>SSE_ERROR_ENVELOPE_MAX_BYTES)return;let parsed=JSON.parse(data);if(!isRecord2(parsed)||parsed.type!=="error"||!isRecord2(parsed.error))return;let code=parsed.error.type;return typeof code!="string"?void 0:classifyProviderFailure({status:void 0,code})}catch{return}}function openAICompatibleProviderDiagnosticFromError(error){try{if(!(error instanceof Error))return;let status=Reflect.get(error,"status"),code=optionalString(Reflect.get(error,"code"));return code===null||code===void 0&&status==null?void 0:classifyProviderFailure({status,code})}catch{return}}async function awaitProviderTransport(request,classify){try{return await request()}catch(error){throw typeof error=="object"&&error!==null&&attachProviderDiagnostic(error,classify(error)),error}}async function*iterateProviderTransport(source,classify){try{yield*source}catch(error){throw typeof error=="object"&&error!==null&&attachProviderDiagnostic(error,classify(error)),error}}var QUOTA_CODES=new Set(["quota_exceeded","free_quota_exceeded","overage_limit_reached","billing_not_configured","additional_spend_limit_reached"]);function headerValue(headers,name){if(headers instanceof Headers)return headers.get(name)??void 0;if(!(typeof headers!="object"||headers===null)){for(let[key,value]of Object.entries(headers))if(key.toLowerCase()===name&&typeof value=="string")return value}}function errorCode(body){if(body!==void 0)try{let parsed=JSON.parse(body);if(typeof parsed!="object"||parsed===null)return;let nested=Reflect.get(parsed,"error"),code=Reflect.get(typeof nested=="object"&&nested!==null?nested:parsed,"code");return typeof code=="string"?code:void 0}catch{return}}function isQuotaFailure(status,body,limitKey){let code=errorCode(body);return code!==void 0&&QUOTA_CODES.has(code)||status===402?!0:status===429&&(limitKey?.includes("quota")===!0||/quota exceeded/i.test(body??""))}function describeGitHubCopilotFailure(error){if(!(error instanceof Error))return;let{status,body}=normalizeProviderError(error);if(status===void 0)return;let headers=Reflect.get(error,"headers"),requestId=headerValue(headers,"x-github-request-id"),reference=requestId===void 0?"":` ${formatProviderRequestId("GitHub",requestId)}.`;if(isQuotaFailure(status,body,headerValue(headers,"x-ratelimit-exceeded")))return`GitHub Copilot quota exceeded (HTTP ${status}): the plan's included usage or its additional-usage limit is used up, so premium models are refused until it resets or the limit is raised. Usage is shown at https://github.com/settings/copilot.${reference}`;if(status===421)return`GitHub Copilot sent this account to a different API host (HTTP 421 Misdirected Request): Business and Enterprise accounts are served from their own host, which senpi reads from the Copilot token. Run /login github-copilot so senpi stores the account's endpoint, and report it with the GitHub request id if it persists.${reference}`;if(status===403)return`GitHub Copilot refused the request (HTTP 403${body===void 0?" with an empty body":""}). Copilot checks access per model and per client; if a fresh /login github-copilot does not help, report it with the GitHub request id.${reference}`}function withGitHubCopilotFailureNote(message,provider,error){if(provider!=="github-copilot")return message;let note=describeGitHubCopilotFailure(error);return note===void 0?message:`${message}
3
3
  ${note}`}export{limitGitHubCopilotTools,recordGitHubCopilotToolLimit,formatGitHubCopilotToolLimitError,anthropicProviderDiagnosticFromError,anthropicProviderDiagnosticFromSseData,openAICompatibleProviderDiagnosticFromError,awaitProviderTransport,iterateProviderTransport,withGitHubCopilotFailureNote};