@bastani/atomic 0.10.2 → 0.10.3

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 (499) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +22 -0
  3. package/dist/builtin/intercom/broker/broker-instance.ts +2 -13
  4. package/dist/builtin/intercom/broker/broker.ts +158 -73
  5. package/dist/builtin/intercom/broker/durable-ended-queue.ts +14 -2
  6. package/dist/builtin/intercom/broker/host-command-environment.ts +13 -0
  7. package/dist/builtin/intercom/broker/hosted-session-errors.ts +1 -0
  8. package/dist/builtin/intercom/broker/multinode-router.ts +111 -16
  9. package/dist/builtin/intercom/broker/multinode-state-store.ts +50 -4
  10. package/dist/builtin/intercom/broker/open-broker-state.ts +5 -4
  11. package/dist/builtin/intercom/broker/spawn.ts +144 -25
  12. package/dist/builtin/intercom/broker/sql-add-column.ts +33 -0
  13. package/dist/builtin/intercom/broker/sql-known-session-store.ts +120 -36
  14. package/dist/builtin/intercom/broker/sql-outbox-store.ts +75 -13
  15. package/dist/builtin/intercom/broker/start-announcement.ts +55 -10
  16. package/dist/builtin/intercom/broker/watchdog.ts +10 -7
  17. package/dist/builtin/intercom/index.bundle.mjs +111 -27
  18. package/dist/builtin/intercom/package.json +1 -1
  19. package/dist/builtin/mcp/package.json +1 -1
  20. package/dist/builtin/subagents/CHANGELOG.md +26 -0
  21. package/dist/builtin/subagents/package.json +1 -1
  22. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +30 -52
  23. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +34 -40
  24. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/viewer.html +2 -2
  25. package/dist/builtin/subagents/skills/skill-creator/scripts/atomic_cli.py +731 -0
  26. package/dist/builtin/subagents/skills/skill-creator/scripts/generate_report.py +3 -3
  27. package/dist/builtin/subagents/skills/skill-creator/scripts/improve_description.py +41 -38
  28. package/dist/builtin/subagents/skills/skill-creator/scripts/run_eval.py +276 -176
  29. package/dist/builtin/subagents/skills/skill-creator/scripts/run_loop.py +20 -11
  30. package/dist/builtin/subagents/skills/skill-creator/scripts/utils.py +1 -1
  31. package/dist/builtin/subagents/src/extension/index.bundle.mjs +163 -97
  32. package/dist/builtin/web-access/CHANGELOG.md +14 -0
  33. package/dist/builtin/web-access/index.bundle.mjs +5 -4
  34. package/dist/builtin/web-access/package.json +1 -1
  35. package/dist/core/agent-session-auto-compaction.d.ts +10 -1
  36. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  37. package/dist/core/agent-session-auto-compaction.js +54 -2
  38. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  39. package/dist/core/agent-session-compaction.d.ts +4 -0
  40. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  41. package/dist/core/agent-session-compaction.js +17 -2
  42. package/dist/core/agent-session-compaction.js.map +1 -1
  43. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
  44. package/dist/core/agent-session-custom-message-commit.js +3 -1
  45. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  46. package/dist/core/agent-session-events.d.ts +2 -0
  47. package/dist/core/agent-session-events.d.ts.map +1 -1
  48. package/dist/core/agent-session-events.js +34 -13
  49. package/dist/core/agent-session-events.js.map +1 -1
  50. package/dist/core/agent-session-export.d.ts.map +1 -1
  51. package/dist/core/agent-session-export.js +3 -0
  52. package/dist/core/agent-session-export.js.map +1 -1
  53. package/dist/core/agent-session-message-queue.d.ts +27 -0
  54. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  55. package/dist/core/agent-session-message-queue.js +213 -30
  56. package/dist/core/agent-session-message-queue.js.map +1 -1
  57. package/dist/core/agent-session-methods.d.ts +6 -1
  58. package/dist/core/agent-session-methods.d.ts.map +1 -1
  59. package/dist/core/agent-session-methods.js.map +1 -1
  60. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  61. package/dist/core/agent-session-prompt.js +35 -3
  62. package/dist/core/agent-session-prompt.js.map +1 -1
  63. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  64. package/dist/core/agent-session-runtime.js +2 -2
  65. package/dist/core/agent-session-runtime.js.map +1 -1
  66. package/dist/core/agent-session-state.d.ts.map +1 -1
  67. package/dist/core/agent-session-state.js +6 -1
  68. package/dist/core/agent-session-state.js.map +1 -1
  69. package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
  70. package/dist/core/agent-session-tool-hooks.js +15 -2
  71. package/dist/core/agent-session-tool-hooks.js.map +1 -1
  72. package/dist/core/agent-session-typed-queue.d.ts +14 -1
  73. package/dist/core/agent-session-typed-queue.d.ts.map +1 -1
  74. package/dist/core/agent-session-typed-queue.js +26 -1
  75. package/dist/core/agent-session-typed-queue.js.map +1 -1
  76. package/dist/core/agent-session-types.d.ts +5 -0
  77. package/dist/core/agent-session-types.d.ts.map +1 -1
  78. package/dist/core/agent-session-types.js.map +1 -1
  79. package/dist/core/agent-session.d.ts.map +1 -1
  80. package/dist/core/agent-session.js +2 -1
  81. package/dist/core/agent-session.js.map +1 -1
  82. package/dist/core/async-scope.d.ts +9 -4
  83. package/dist/core/async-scope.d.ts.map +1 -1
  84. package/dist/core/async-scope.js +13 -5
  85. package/dist/core/async-scope.js.map +1 -1
  86. package/dist/core/builtin-diagnostics.js +2 -2
  87. package/dist/core/builtin-diagnostics.js.map +1 -1
  88. package/dist/core/chat-admission-order.d.ts.map +1 -1
  89. package/dist/core/chat-admission-order.js +2 -1
  90. package/dist/core/chat-admission-order.js.map +1 -1
  91. package/dist/core/chat-record-saves.d.ts +4 -0
  92. package/dist/core/chat-record-saves.d.ts.map +1 -0
  93. package/dist/core/chat-record-saves.js +25 -0
  94. package/dist/core/chat-record-saves.js.map +1 -0
  95. package/dist/core/command-deliveries.d.ts +62 -0
  96. package/dist/core/command-deliveries.d.ts.map +1 -0
  97. package/dist/core/command-deliveries.js +139 -0
  98. package/dist/core/command-deliveries.js.map +1 -0
  99. package/dist/core/diagnostic-writer.d.ts.map +1 -1
  100. package/dist/core/diagnostic-writer.js +5 -4
  101. package/dist/core/diagnostic-writer.js.map +1 -1
  102. package/dist/core/extension-startup-close.d.ts +1 -2
  103. package/dist/core/extension-startup-close.d.ts.map +1 -1
  104. package/dist/core/extension-startup-close.js +2 -2
  105. package/dist/core/extension-startup-close.js.map +1 -1
  106. package/dist/core/extensions/jiti-aliases.d.ts +11 -0
  107. package/dist/core/extensions/jiti-aliases.d.ts.map +1 -0
  108. package/dist/core/extensions/jiti-aliases.js +28 -0
  109. package/dist/core/extensions/jiti-aliases.js.map +1 -0
  110. package/dist/core/extensions/loader-api.js +3 -3
  111. package/dist/core/extensions/loader-api.js.map +1 -1
  112. package/dist/core/extensions/loader-bindings.js +2 -2
  113. package/dist/core/extensions/loader-bindings.js.map +1 -1
  114. package/dist/core/extensions/loader-rollback.d.ts +1 -2
  115. package/dist/core/extensions/loader-rollback.d.ts.map +1 -1
  116. package/dist/core/extensions/loader-rollback.js +2 -2
  117. package/dist/core/extensions/loader-rollback.js.map +1 -1
  118. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  119. package/dist/core/extensions/loader-virtual-modules.js +53 -9
  120. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  121. package/dist/core/extensions/native-builtin-entries.d.ts +5 -0
  122. package/dist/core/extensions/native-builtin-entries.d.ts.map +1 -1
  123. package/dist/core/extensions/native-builtin-entries.js +8 -1
  124. package/dist/core/extensions/native-builtin-entries.js.map +1 -1
  125. package/dist/core/extensions/reloadable-scripts.d.ts +21 -2
  126. package/dist/core/extensions/reloadable-scripts.d.ts.map +1 -1
  127. package/dist/core/extensions/reloadable-scripts.js +11 -3
  128. package/dist/core/extensions/reloadable-scripts.js.map +1 -1
  129. package/dist/core/extensions/source-builtin-imports.d.ts +40 -0
  130. package/dist/core/extensions/source-builtin-imports.d.ts.map +1 -0
  131. package/dist/core/extensions/source-builtin-imports.js +142 -0
  132. package/dist/core/extensions/source-builtin-imports.js.map +1 -0
  133. package/dist/core/extensions/transform-graph.d.ts +15 -0
  134. package/dist/core/extensions/transform-graph.d.ts.map +1 -0
  135. package/dist/core/extensions/transform-graph.js +85 -0
  136. package/dist/core/extensions/transform-graph.js.map +1 -0
  137. package/dist/core/extensions/ts-source-specifiers.d.ts +2 -0
  138. package/dist/core/extensions/ts-source-specifiers.d.ts.map +1 -1
  139. package/dist/core/extensions/ts-source-specifiers.js +7 -0
  140. package/dist/core/extensions/ts-source-specifiers.js.map +1 -1
  141. package/dist/core/extensions/ts-transform-worker.d.ts +2 -0
  142. package/dist/core/extensions/ts-transform-worker.d.ts.map +1 -0
  143. package/dist/core/extensions/ts-transform-worker.js +43 -0
  144. package/dist/core/extensions/ts-transform-worker.js.map +1 -0
  145. package/dist/core/message-admission.d.ts.map +1 -1
  146. package/dist/core/message-admission.js +4 -4
  147. package/dist/core/message-admission.js.map +1 -1
  148. package/dist/core/messages.d.ts +5 -0
  149. package/dist/core/messages.d.ts.map +1 -1
  150. package/dist/core/messages.js +35 -0
  151. package/dist/core/messages.js.map +1 -1
  152. package/dist/core/model-fallback-failures.d.ts +1 -1
  153. package/dist/core/model-fallback-failures.d.ts.map +1 -1
  154. package/dist/core/model-fallback-failures.js +18 -1
  155. package/dist/core/model-fallback-failures.js.map +1 -1
  156. package/dist/core/process-start-token.d.ts +7 -0
  157. package/dist/core/process-start-token.d.ts.map +1 -1
  158. package/dist/core/process-start-token.js +14 -0
  159. package/dist/core/process-start-token.js.map +1 -1
  160. package/dist/core/project-trust-electorate.d.ts +24 -0
  161. package/dist/core/project-trust-electorate.d.ts.map +1 -0
  162. package/dist/core/project-trust-electorate.js +52 -0
  163. package/dist/core/project-trust-electorate.js.map +1 -0
  164. package/dist/core/project-trust-state.d.ts +15 -0
  165. package/dist/core/project-trust-state.d.ts.map +1 -1
  166. package/dist/core/project-trust-state.js +15 -0
  167. package/dist/core/project-trust-state.js.map +1 -1
  168. package/dist/core/provider-request-admission.d.ts.map +1 -1
  169. package/dist/core/provider-request-admission.js +2 -2
  170. package/dist/core/provider-request-admission.js.map +1 -1
  171. package/dist/core/queued-input-admission.js +2 -2
  172. package/dist/core/queued-input-admission.js.map +1 -1
  173. package/dist/core/queued-message-delivery.d.ts +2 -2
  174. package/dist/core/queued-message-delivery.d.ts.map +1 -1
  175. package/dist/core/queued-message-delivery.js +6 -3
  176. package/dist/core/queued-message-delivery.js.map +1 -1
  177. package/dist/core/resource-admission-scope.js +2 -2
  178. package/dist/core/resource-admission-scope.js.map +1 -1
  179. package/dist/core/resume/blueprint/process.d.ts +3 -4
  180. package/dist/core/resume/blueprint/process.d.ts.map +1 -1
  181. package/dist/core/resume/blueprint/process.js +33 -17
  182. package/dist/core/resume/blueprint/process.js.map +1 -1
  183. package/dist/core/resume/path-mapping.js +4 -4
  184. package/dist/core/resume/path-mapping.js.map +1 -1
  185. package/dist/core/resume/session-resume.d.ts +9 -0
  186. package/dist/core/resume/session-resume.d.ts.map +1 -1
  187. package/dist/core/resume/session-resume.js +27 -2
  188. package/dist/core/resume/session-resume.js.map +1 -1
  189. package/dist/core/resume-cache-checkpoint.d.ts +27 -1
  190. package/dist/core/resume-cache-checkpoint.d.ts.map +1 -1
  191. package/dist/core/resume-cache-checkpoint.js +45 -0
  192. package/dist/core/resume-cache-checkpoint.js.map +1 -1
  193. package/dist/core/sdk.d.ts.map +1 -1
  194. package/dist/core/sdk.js +7 -31
  195. package/dist/core/sdk.js.map +1 -1
  196. package/dist/core/session-lifecycle-scope.d.ts +1 -2
  197. package/dist/core/session-lifecycle-scope.d.ts.map +1 -1
  198. package/dist/core/session-lifecycle-scope.js +2 -2
  199. package/dist/core/session-lifecycle-scope.js.map +1 -1
  200. package/dist/core/session-lifecycle-work.js +2 -2
  201. package/dist/core/session-lifecycle-work.js.map +1 -1
  202. package/dist/core/session-manager-core.d.ts.map +1 -1
  203. package/dist/core/session-manager-core.js +3 -0
  204. package/dist/core/session-manager-core.js.map +1 -1
  205. package/dist/core/session-storage.d.ts +12 -0
  206. package/dist/core/session-storage.d.ts.map +1 -1
  207. package/dist/core/session-storage.js +68 -1
  208. package/dist/core/session-storage.js.map +1 -1
  209. package/dist/core/settings-lock-directory.d.ts.map +1 -1
  210. package/dist/core/settings-lock-directory.js +4 -3
  211. package/dist/core/settings-lock-directory.js.map +1 -1
  212. package/dist/core/settings-write-ownership.d.ts +1 -2
  213. package/dist/core/settings-write-ownership.d.ts.map +1 -1
  214. package/dist/core/settings-write-ownership.js +2 -2
  215. package/dist/core/settings-write-ownership.js.map +1 -1
  216. package/dist/core/storage/node-sqlite-thread.d.ts.map +1 -1
  217. package/dist/core/storage/node-sqlite-thread.js +6 -4
  218. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  219. package/dist/core/storage/node-sqlite.d.ts.map +1 -1
  220. package/dist/core/storage/node-sqlite.js +22 -8
  221. package/dist/core/storage/node-sqlite.js.map +1 -1
  222. package/dist/core/system-prompt.d.ts +16 -2
  223. package/dist/core/system-prompt.d.ts.map +1 -1
  224. package/dist/core/system-prompt.js +33 -6
  225. package/dist/core/system-prompt.js.map +1 -1
  226. package/dist/core/tasks/agent-adapter.d.ts.map +1 -1
  227. package/dist/core/tasks/agent-adapter.js +2 -1
  228. package/dist/core/tasks/agent-adapter.js.map +1 -1
  229. package/dist/core/tasks/completion.d.ts +3 -2
  230. package/dist/core/tasks/completion.d.ts.map +1 -1
  231. package/dist/core/tasks/completion.js.map +1 -1
  232. package/dist/core/tasks/execution-scope.js +2 -2
  233. package/dist/core/tasks/execution-scope.js.map +1 -1
  234. package/dist/core/tools/bash.d.ts.map +1 -1
  235. package/dist/core/tools/bash.js +2 -1
  236. package/dist/core/tools/bash.js.map +1 -1
  237. package/dist/core/tools/history-regex-worker.d.ts.map +1 -1
  238. package/dist/core/tools/history-regex-worker.js +3 -2
  239. package/dist/core/tools/history-regex-worker.js.map +1 -1
  240. package/dist/core/tools/shell-task-render.d.ts +3 -2
  241. package/dist/core/tools/shell-task-render.d.ts.map +1 -1
  242. package/dist/core/tools/shell-task-render.js +7 -5
  243. package/dist/core/tools/shell-task-render.js.map +1 -1
  244. package/dist/core/tools/shell-task-status.d.ts +6 -2
  245. package/dist/core/tools/shell-task-status.d.ts.map +1 -1
  246. package/dist/core/tools/shell-task-status.js +13 -8
  247. package/dist/core/tools/shell-task-status.js.map +1 -1
  248. package/dist/core/tools/sqlite-selector-connection.d.ts.map +1 -1
  249. package/dist/core/tools/sqlite-selector-connection.js +4 -3
  250. package/dist/core/tools/sqlite-selector-connection.js.map +1 -1
  251. package/dist/core/tools/windows-directory-security.d.ts.map +1 -1
  252. package/dist/core/tools/windows-directory-security.js +2 -1
  253. package/dist/core/tools/windows-directory-security.js.map +1 -1
  254. package/dist/core/worktree-snapshot/git.js +2 -2
  255. package/dist/core/worktree-snapshot/git.js.map +1 -1
  256. package/dist/extensions/mcp/index.d.ts +6 -1
  257. package/dist/extensions/mcp/index.d.ts.map +1 -1
  258. package/dist/extensions/mcp/index.js +150 -18
  259. package/dist/extensions/mcp/index.js.map +1 -1
  260. package/dist/extensions/mcp/tool-records.d.ts +44 -9
  261. package/dist/extensions/mcp/tool-records.d.ts.map +1 -1
  262. package/dist/extensions/mcp/tool-records.js +58 -16
  263. package/dist/extensions/mcp/tool-records.js.map +1 -1
  264. package/dist/index.d.ts +2 -0
  265. package/dist/index.d.ts.map +1 -1
  266. package/dist/index.js +4 -0
  267. package/dist/index.js.map +1 -1
  268. package/dist/main-session.d.ts +3 -1
  269. package/dist/main-session.d.ts.map +1 -1
  270. package/dist/main-session.js +1 -0
  271. package/dist/main-session.js.map +1 -1
  272. package/dist/main.d.ts.map +1 -1
  273. package/dist/main.js +230 -96
  274. package/dist/main.js.map +1 -1
  275. package/dist/modes/interactive/agent-view/agent-view-bridge.d.ts +5 -0
  276. package/dist/modes/interactive/agent-view/agent-view-bridge.d.ts.map +1 -1
  277. package/dist/modes/interactive/agent-view/agent-view-bridge.js.map +1 -1
  278. package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts +5 -2
  279. package/dist/modes/interactive/agent-view/agent-view-switcher.d.ts.map +1 -1
  280. package/dist/modes/interactive/agent-view/agent-view-switcher.js +3 -3
  281. package/dist/modes/interactive/agent-view/agent-view-switcher.js.map +1 -1
  282. package/dist/modes/interactive/agent-view/contracts.d.ts +6 -0
  283. package/dist/modes/interactive/agent-view/contracts.d.ts.map +1 -1
  284. package/dist/modes/interactive/agent-view/contracts.js.map +1 -1
  285. package/dist/modes/interactive/agent-view/install.d.ts.map +1 -1
  286. package/dist/modes/interactive/agent-view/install.js +2 -1
  287. package/dist/modes/interactive/agent-view/install.js.map +1 -1
  288. package/dist/modes/interactive/agent-view/open-port.d.ts +4 -2
  289. package/dist/modes/interactive/agent-view/open-port.d.ts.map +1 -1
  290. package/dist/modes/interactive/agent-view/open-port.js +4 -3
  291. package/dist/modes/interactive/agent-view/open-port.js.map +1 -1
  292. package/dist/modes/interactive/agent-view/prompt-retarget.d.ts.map +1 -1
  293. package/dist/modes/interactive/agent-view/prompt-retarget.js +18 -5
  294. package/dist/modes/interactive/agent-view/prompt-retarget.js.map +1 -1
  295. package/dist/modes/interactive/agent-view/remote-port.d.ts +10 -1
  296. package/dist/modes/interactive/agent-view/remote-port.d.ts.map +1 -1
  297. package/dist/modes/interactive/agent-view/remote-port.js +36 -4
  298. package/dist/modes/interactive/agent-view/remote-port.js.map +1 -1
  299. package/dist/modes/interactive/agent-view/viewed-keys.d.ts +56 -0
  300. package/dist/modes/interactive/agent-view/viewed-keys.d.ts.map +1 -0
  301. package/dist/modes/interactive/agent-view/viewed-keys.js +63 -0
  302. package/dist/modes/interactive/agent-view/viewed-keys.js.map +1 -0
  303. package/dist/modes/interactive/agent-view/viewed-submit.d.ts +14 -4
  304. package/dist/modes/interactive/agent-view/viewed-submit.d.ts.map +1 -1
  305. package/dist/modes/interactive/agent-view/viewed-submit.js +51 -17
  306. package/dist/modes/interactive/agent-view/viewed-submit.js.map +1 -1
  307. package/dist/modes/interactive/components/agent-panel.d.ts.map +1 -1
  308. package/dist/modes/interactive/components/agent-panel.js +8 -21
  309. package/dist/modes/interactive/components/agent-panel.js.map +1 -1
  310. package/dist/modes/interactive/components/chat-session-host-actions.d.ts.map +1 -1
  311. package/dist/modes/interactive/components/chat-session-host-actions.js +18 -5
  312. package/dist/modes/interactive/components/chat-session-host-actions.js.map +1 -1
  313. package/dist/modes/interactive/components/chat-session-host-rendering.d.ts.map +1 -1
  314. package/dist/modes/interactive/components/chat-session-host-rendering.js +6 -0
  315. package/dist/modes/interactive/components/chat-session-host-rendering.js.map +1 -1
  316. package/dist/modes/interactive/components/chat-session-host-state.d.ts +1 -0
  317. package/dist/modes/interactive/components/chat-session-host-state.d.ts.map +1 -1
  318. package/dist/modes/interactive/components/chat-session-host-state.js +2 -0
  319. package/dist/modes/interactive/components/chat-session-host-state.js.map +1 -1
  320. package/dist/modes/interactive/components/chat-session-host-types.d.ts +5 -0
  321. package/dist/modes/interactive/components/chat-session-host-types.d.ts.map +1 -1
  322. package/dist/modes/interactive/components/chat-session-host-types.js.map +1 -1
  323. package/dist/modes/interactive/components/custom-editor.d.ts +33 -2
  324. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  325. package/dist/modes/interactive/components/custom-editor.js +58 -2
  326. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  327. package/dist/modes/interactive/components/host-session-picker.js +2 -2
  328. package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
  329. package/dist/modes/interactive/components/main-composer-keys.d.ts +16 -5
  330. package/dist/modes/interactive/components/main-composer-keys.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/main-composer-keys.js +27 -8
  332. package/dist/modes/interactive/components/main-composer-keys.js.map +1 -1
  333. package/dist/modes/interactive/components/notice-line.d.ts +8 -25
  334. package/dist/modes/interactive/components/notice-line.d.ts.map +1 -1
  335. package/dist/modes/interactive/components/notice-line.js +18 -17
  336. package/dist/modes/interactive/components/notice-line.js.map +1 -1
  337. package/dist/modes/interactive/components/prompt-slot.d.ts +20 -3
  338. package/dist/modes/interactive/components/prompt-slot.d.ts.map +1 -1
  339. package/dist/modes/interactive/components/prompt-slot.js +82 -32
  340. package/dist/modes/interactive/components/prompt-slot.js.map +1 -1
  341. package/dist/modes/interactive/components/queued-messages-view.d.ts +5 -2
  342. package/dist/modes/interactive/components/queued-messages-view.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/queued-messages-view.js +12 -5
  344. package/dist/modes/interactive/components/queued-messages-view.js.map +1 -1
  345. package/dist/modes/interactive/components/task-board.d.ts +5 -8
  346. package/dist/modes/interactive/components/task-board.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/task-board.js +5 -49
  348. package/dist/modes/interactive/components/task-board.js.map +1 -1
  349. package/dist/modes/interactive/components/task-completion-message.d.ts.map +1 -1
  350. package/dist/modes/interactive/components/task-completion-message.js +9 -2
  351. package/dist/modes/interactive/components/task-completion-message.js.map +1 -1
  352. package/dist/modes/interactive/components/task-marks.d.ts +19 -0
  353. package/dist/modes/interactive/components/task-marks.d.ts.map +1 -0
  354. package/dist/modes/interactive/components/task-marks.js +25 -0
  355. package/dist/modes/interactive/components/task-marks.js.map +1 -0
  356. package/dist/modes/interactive/components/task-row.d.ts +10 -2
  357. package/dist/modes/interactive/components/task-row.d.ts.map +1 -1
  358. package/dist/modes/interactive/components/task-row.js +39 -32
  359. package/dist/modes/interactive/components/task-row.js.map +1 -1
  360. package/dist/modes/interactive/components/task-transcript-page.d.ts +7 -0
  361. package/dist/modes/interactive/components/task-transcript-page.d.ts.map +1 -1
  362. package/dist/modes/interactive/components/task-transcript-page.js +106 -10
  363. package/dist/modes/interactive/components/task-transcript-page.js.map +1 -1
  364. package/dist/modes/interactive/components/tool-block-families.d.ts.map +1 -1
  365. package/dist/modes/interactive/components/tool-block-families.js +8 -9
  366. package/dist/modes/interactive/components/tool-block-families.js.map +1 -1
  367. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  368. package/dist/modes/interactive/components/tool-execution.js +5 -1
  369. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  370. package/dist/modes/interactive/extension-command-hold.d.ts.map +1 -1
  371. package/dist/modes/interactive/extension-command-hold.js +5 -7
  372. package/dist/modes/interactive/extension-command-hold.js.map +1 -1
  373. package/dist/modes/interactive/interactive-extension-dialogs.js +6 -1
  374. package/dist/modes/interactive/interactive-extension-dialogs.js.map +1 -1
  375. package/dist/modes/interactive/interactive-extension-runtime.d.ts.map +1 -1
  376. package/dist/modes/interactive/interactive-extension-runtime.js +21 -7
  377. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  378. package/dist/modes/interactive/interactive-initial-session-binding.d.ts +1 -2
  379. package/dist/modes/interactive/interactive-initial-session-binding.d.ts.map +1 -1
  380. package/dist/modes/interactive/interactive-initial-session-binding.js +2 -2
  381. package/dist/modes/interactive/interactive-initial-session-binding.js.map +1 -1
  382. package/dist/modes/interactive/interactive-input-handling.d.ts.map +1 -1
  383. package/dist/modes/interactive/interactive-input-handling.js +13 -4
  384. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  385. package/dist/modes/interactive/interactive-mode-base.d.ts +2 -1
  386. package/dist/modes/interactive/interactive-mode-base.d.ts.map +1 -1
  387. package/dist/modes/interactive/interactive-mode-base.js +6 -1
  388. package/dist/modes/interactive/interactive-mode-base.js.map +1 -1
  389. package/dist/modes/interactive/interactive-mode-helpers.d.ts +4 -2
  390. package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
  391. package/dist/modes/interactive/interactive-mode-helpers.js +6 -0
  392. package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
  393. package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -0
  394. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  395. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  396. package/dist/modes/interactive/interactive-process-lifecycle.js +96 -17
  397. package/dist/modes/interactive/interactive-process-lifecycle.js.map +1 -1
  398. package/dist/modes/interactive/interactive-queueing.d.ts +5 -0
  399. package/dist/modes/interactive/interactive-queueing.d.ts.map +1 -1
  400. package/dist/modes/interactive/interactive-queueing.js +37 -5
  401. package/dist/modes/interactive/interactive-queueing.js.map +1 -1
  402. package/dist/modes/interactive/interactive-render-chat.d.ts.map +1 -1
  403. package/dist/modes/interactive/interactive-render-chat.js +45 -4
  404. package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
  405. package/dist/modes/interactive/interactive-resource-disclosure.d.ts +4 -1
  406. package/dist/modes/interactive/interactive-resource-disclosure.d.ts.map +1 -1
  407. package/dist/modes/interactive/interactive-resource-disclosure.js +20 -1
  408. package/dist/modes/interactive/interactive-resource-disclosure.js.map +1 -1
  409. package/dist/modes/interactive/interactive-resource-rendering.js +3 -0
  410. package/dist/modes/interactive/interactive-resource-rendering.js.map +1 -1
  411. package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
  412. package/dist/modes/interactive/interactive-startup.js +43 -5
  413. package/dist/modes/interactive/interactive-startup.js.map +1 -1
  414. package/dist/modes/interactive-engine/activity-watchdog.d.ts +6 -3
  415. package/dist/modes/interactive-engine/activity-watchdog.d.ts.map +1 -1
  416. package/dist/modes/interactive-engine/activity-watchdog.js +3 -2
  417. package/dist/modes/interactive-engine/activity-watchdog.js.map +1 -1
  418. package/dist/modes/interactive-engine/engine-health.d.ts +2 -0
  419. package/dist/modes/interactive-engine/engine-health.d.ts.map +1 -1
  420. package/dist/modes/interactive-engine/engine-health.js.map +1 -1
  421. package/dist/modes/interactive-engine/engine-quit-intent.d.ts +10 -0
  422. package/dist/modes/interactive-engine/engine-quit-intent.d.ts.map +1 -1
  423. package/dist/modes/interactive-engine/engine-quit-intent.js +33 -0
  424. package/dist/modes/interactive-engine/engine-quit-intent.js.map +1 -1
  425. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts +7 -1
  426. package/dist/modes/interactive-engine/extension-ui-bridge.d.ts.map +1 -1
  427. package/dist/modes/interactive-engine/extension-ui-bridge.js +15 -2
  428. package/dist/modes/interactive-engine/extension-ui-bridge.js.map +1 -1
  429. package/dist/modes/interactive-engine/host-listener-failures.d.ts +24 -0
  430. package/dist/modes/interactive-engine/host-listener-failures.d.ts.map +1 -0
  431. package/dist/modes/interactive-engine/host-listener-failures.js +98 -0
  432. package/dist/modes/interactive-engine/host-listener-failures.js.map +1 -0
  433. package/dist/modes/interactive-engine/isolated-runtime.d.ts +16 -0
  434. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  435. package/dist/modes/interactive-engine/isolated-runtime.js +74 -7
  436. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  437. package/dist/modes/interactive-engine/protocol.d.ts +5 -0
  438. package/dist/modes/interactive-engine/protocol.d.ts.map +1 -1
  439. package/dist/modes/interactive-engine/protocol.js +8 -2
  440. package/dist/modes/interactive-engine/protocol.js.map +1 -1
  441. package/dist/modes/interactive-engine/remote-component.d.ts +13 -0
  442. package/dist/modes/interactive-engine/remote-component.d.ts.map +1 -1
  443. package/dist/modes/interactive-engine/remote-component.js +69 -4
  444. package/dist/modes/interactive-engine/remote-component.js.map +1 -1
  445. package/dist/modes/print-mode.d.ts.map +1 -1
  446. package/dist/modes/print-mode.js +34 -6
  447. package/dist/modes/print-mode.js.map +1 -1
  448. package/dist/modes/rpc/agent-panel-bridge.d.ts +7 -0
  449. package/dist/modes/rpc/agent-panel-bridge.d.ts.map +1 -1
  450. package/dist/modes/rpc/agent-panel-bridge.js +11 -1
  451. package/dist/modes/rpc/agent-panel-bridge.js.map +1 -1
  452. package/dist/modes/rpc/agent-view-rpc-panel.d.ts.map +1 -1
  453. package/dist/modes/rpc/agent-view-rpc-panel.js +11 -5
  454. package/dist/modes/rpc/agent-view-rpc-panel.js.map +1 -1
  455. package/dist/modes/rpc/rpc-client-process.d.ts +8 -1
  456. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  457. package/dist/modes/rpc/rpc-client-process.js +89 -65
  458. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  459. package/dist/modes/rpc/rpc-client.d.ts +21 -0
  460. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  461. package/dist/modes/rpc/rpc-client.js +77 -33
  462. package/dist/modes/rpc/rpc-client.js.map +1 -1
  463. package/dist/modes/rpc/rpc-event-buffer.d.ts +5 -0
  464. package/dist/modes/rpc/rpc-event-buffer.d.ts.map +1 -1
  465. package/dist/modes/rpc/rpc-event-buffer.js +8 -2
  466. package/dist/modes/rpc/rpc-event-buffer.js.map +1 -1
  467. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  468. package/dist/modes/rpc/rpc-mode.js +9 -2
  469. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  470. package/dist/utils/shell.d.ts +5 -1
  471. package/dist/utils/shell.d.ts.map +1 -1
  472. package/dist/utils/shell.js +14 -7
  473. package/dist/utils/shell.js.map +1 -1
  474. package/dist/utils/worker-threads.d.ts +10 -4
  475. package/dist/utils/worker-threads.d.ts.map +1 -1
  476. package/dist/utils/worker-threads.js +10 -4
  477. package/dist/utils/worker-threads.js.map +1 -1
  478. package/docs/background-tasks.md +10 -10
  479. package/docs/compaction.md +1 -0
  480. package/docs/development.md +1 -1
  481. package/docs/environment-variables.md +4 -0
  482. package/docs/extensions/api-reference.md +2 -0
  483. package/docs/extensions/events.md +1 -1
  484. package/docs/getting-started/installation.md +1 -0
  485. package/docs/guides/non-interactive.md +2 -0
  486. package/docs/guides/resume-on-any-machine.md +3 -1
  487. package/docs/intercom/reference.md +1 -1
  488. package/docs/keybindings.md +6 -5
  489. package/docs/libraries/ai.md +2 -1
  490. package/docs/mcp-servers.md +1 -1
  491. package/docs/sdk/reference.md +1 -1
  492. package/docs/sdk.md +6 -0
  493. package/docs/security.md +4 -2
  494. package/docs/settings.md +2 -1
  495. package/docs/storage.md +2 -0
  496. package/docs/subagents.md +2 -2
  497. package/docs/tui/reference.md +3 -1
  498. package/npm-shrinkwrap.json +49 -49
  499. package/package.json +6 -6
@@ -1 +1 @@
1
- {"version":3,"file":"model-fallback-failures.js","sourceRoot":"","sources":["../../src/core/model-fallback-failures.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,sBAAsB,EAGtB,kCAAkC,GAClC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,gCAAgC,GAAsB;IAC3D,eAAe;IACf,wBAAwB;IACxB,wBAAwB;IACxB,SAAS;IACT,QAAQ;IACR,oBAAoB;IACpB,UAAU;IACV,SAAS;IACT,gCAAgC;IAChC,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,sBAAsB;IACtB,sCAAsC;IACtC,+CAA+C;IAC/C,YAAY;IACZ,gBAAgB;IAChB,aAAa;IACb,4BAA4B;IAC5B,wBAAwB;IACxB,UAAU;IACV,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,uBAAuB;IACvB,WAAW;IACX,UAAU;IACV,cAAc;IACd,aAAa;IACb,aAAa;IACb,SAAS;IACT,4BAA4B;IAC5B,gBAAgB;IAChB,kBAAkB;IAClB,oBAAoB;IACpB,mBAAmB;IACnB,qBAAqB;IACrB,oBAAoB;IACpB,sFAAsF;IACtF,oBAAoB;IACpB,oBAAoB;IACpB,mBAAmB;IACnB,uBAAuB;IACvB,iBAAiB;IACjB,gBAAgB;IAChB,mCAAmC;IACnC,gDAAgD;IAChD,uCAAuC;IACvC,mCAAmC;IACnC,cAAc;IACd,2BAA2B;IAC3B,aAAa;IACb,6BAA6B;IAC7B,yBAAyB;IACzB,4BAA4B;IAC5B,2EAA2E;IAC3E,oBAAoB;CACpB,CAAC;AAEF,MAAM,8BAA8B,GAAsB;IACzD,iBAAiB;IACjB,gBAAgB;IAChB,QAAQ;IACR,eAAe;IACf,eAAe;CACf,CAAC;AAEF,uHAAuH;AACvH,wBAAwB;AACxB,MAAM,0BAA0B,GAAsB,CAAC,uBAAuB,EAAE,QAAQ,EAAE,cAAc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;AACnG,CAAC","sourcesContent":["/**\n * Shared model/provider failure classification.\n *\n * Subagents and the main chat all need the same decision about\n * whether a provider failure may spend another model candidate. Keep this\n * module free of AgentSession imports so the published SDK can\n * expose it to the raw-TypeScript companion packages without a cycle.\n */\n\nimport {\n\tfindGitHubCopilotError,\n\ttype GitHubCopilotError,\n\ttype GitHubCopilotErrorCode,\n\tGitHubCopilotStreamEndedEarlyError,\n} from \"@bastani/atomic-ai\";\nimport { isExtensionStartupFailure } from \"./extension-startup-failure.ts\";\n\nconst RETRYABLE_MODEL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/rate\\s*limit/i,\n\t/too\\s*many\\s*requests/i,\n\t/\\bthrottl(?:ing|ed)\\b/i,\n\t/\\b429\\b/,\n\t/quota/i,\n\t/usage[\\s_-]*limit/i,\n\t/billing/i,\n\t/credit/i,\n\t/auth(?:entication|orization)?/i,\n\t/unauthori[sz]ed/i,\n\t/\\b40[13]\\b/,\n\t/api[_\\s-]*key/i,\n\t/token[_\\s-]*expired/i,\n\t/token[_\\s-]*(?:revoked|invalidated)/i,\n\t/invalidated[_\\s-]+(?:oauth|auth)[_\\s-]+token/i,\n\t/forbidden/i,\n\t/invalid\\s*key/i,\n\t/overloaded/i,\n\t/temporarily\\s*unavailable/i,\n\t/service\\s*unavailable/i,\n\t/network/i,\n\t/fetch/i,\n\t/getaddrinfo/i,\n\t/ENOTFOUND/i,\n\t/EAI_AGAIN/i,\n\t/socket/i,\n\t/connection\\s*refused/i,\n\t/upstream/i,\n\t/timeout/i,\n\t/timed\\s+out/i,\n\t/\\b50[0-4]\\b/,\n\t/\\b52[0-4]\\b/,\n\t/\\b529\\b/,\n\t/provider.?returned.?error/i,\n\t/server.?error/i,\n\t/internal.?error/i,\n\t/connection.?error/i,\n\t/connection.?lost/i,\n\t/connection.?closed/i,\n\t/connection.?reset/i,\n\t/(?<![a-z0-9_])(?:ECONNRESET|ECONNABORTED|ECONNREFUSED|ETIMEDOUT|EPIPE)(?![a-z0-9_])/i,\n\t/other side closed/i,\n\t/websocket.?closed/i,\n\t/websocket.?error/i,\n\t/reset before headers/i,\n\t/socket hang up/i,\n\t/ended without/i,\n\t/stream ended before message_stop/i,\n\t/stream ended before a terminal response event/i,\n\t/http2 request did not get a response/i,\n\t/pending stream has been canceled/i,\n\t/retry delay/i,\n\t/finish.?reason:?\\s*error/i,\n\t/terminated/i,\n\t/you can retry your request/i,\n\t/try your request again/i,\n\t/please retry your request/i,\n\t// gRPC based providers (e.g. NVIDIA NIM); upstream pi-ai retries this too.\n\t/ResourceExhausted/i,\n];\n\nconst NON_RETRYABLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/command failed/i,\n\t/tests? failed/i,\n\t/shell/i,\n\t/missing file/i,\n\t/no such file/i,\n];\n\n// \"cancel\" as a word of its own: an HTTP/2 stream error code such as `NGHTTP2_CANCEL` is a transport reset, not a user\n// cancellation (#4918).\nconst CANCELLED_FAILURE_PATTERNS: readonly RegExp[] = [/(?<![a-z0-9_])cancel/i, /abort/i, /interrupted/i];\n\nconst TRANSPORT_CANCELLATION_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/getaddrinfo|ENOTFOUND|EAI_AGAIN/i,\n\t/(?<![a-z0-9_])ECONNABORTED(?![a-z0-9_])|software caused connection abort/i,\n\t/pending stream has been canceled/i,\n\t// An HTTP/2 stream reset by the peer or a proxy, such as `Stream closed with error code NGHTTP2_CANCEL`.\n\t/(?<![a-z0-9])NGHTTP2_[A-Z_]+|(?<![a-z0-9_])ERR_HTTP2_STREAM_(?:ERROR|CANCEL)(?![a-z0-9_])/i,\n];\n\nexport type ModelFallbackFailureKind =\n\t| \"auth_on_candidate_provider\"\n\t| \"rate_limit\"\n\t| \"quota_exhausted\"\n\t| \"provider_unavailable\"\n\t| \"network_timeout\"\n\t| \"transport_error\"\n\t| \"model_unavailable\"\n\t| \"request_incompatible\"\n\t| \"content_filter\"\n\t| \"cancelled\"\n\t| \"task_failure\"\n\t| \"unknown\";\n\nexport type ModelFallbackFailureSource =\n\t| \"assistant_message\"\n\t| \"diagnostic\"\n\t| \"throw\"\n\t| \"structured\"\n\t| \"string_fallback\";\n\nexport interface ModelFallbackFailureSignal {\n\treadonly kind: ModelFallbackFailureKind;\n\treadonly message: string;\n\treadonly source: ModelFallbackFailureSource;\n\treadonly stopReason?: string;\n\treadonly status?: number;\n\treadonly code?: string | number;\n\treadonly name?: string;\n}\n\n/** How a caller treats a provider content-filter refusal; `retry.fallbackOnContentFilter` in settings. */\nexport interface ModelFallbackFailureOptions {\n\t/** Whether a content-filter refusal may spend the next fallback candidate. Defaults to true. */\n\treadonly fallbackOnContentFilter?: boolean;\n}\n\nconst FALLBACKABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"auth_on_candidate_provider\",\n\t\"rate_limit\",\n\t\"quota_exhausted\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n\t\"model_unavailable\",\n\t\"request_incompatible\",\n]);\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value !== null && typeof value === \"object\" ? (value as Record<string, unknown>) : undefined;\n}\n\nfunction field(value: unknown, key: string): unknown {\n\treturn asRecord(value)?.[key];\n}\n\nfunction stringField(value: unknown, key: string): string | undefined {\n\tconst raw = field(value, key);\n\treturn typeof raw === \"string\" && raw.trim().length > 0 ? raw : undefined;\n}\n\nfunction errorName(value: unknown): string | undefined {\n\treturn value instanceof Error ? value.name : stringField(value, \"name\");\n}\n\nfunction directMessageFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"errorMessage\") ?? stringField(value, \"message\") ?? stringField(value, \"statusText\");\n}\n\nfunction integerFrom(value: unknown): number | undefined {\n\tif (typeof value === \"number\" && Number.isInteger(value)) return value;\n\tif (typeof value !== \"string\" || value.trim().length === 0) return undefined;\n\tconst parsed = Number(value.trim());\n\treturn Number.isInteger(parsed) ? parsed : undefined;\n}\n\nfunction statusFrom(value: unknown): number | undefined {\n\treturn (\n\t\tintegerFrom(field(value, \"status\")) ??\n\t\tintegerFrom(field(value, \"statusCode\")) ??\n\t\tintegerFrom(field(value, \"httpStatus\")) ??\n\t\t// Provider failure diagnostics (`bedrock_response_failure`) keep the HTTP status in `details.status` (#4918).\n\t\tintegerFrom(field(field(value, \"details\"), \"status\"))\n\t);\n}\n\nfunction codeFrom(value: unknown): string | number | undefined {\n\tconst rawCode = field(value, \"code\");\n\tif (typeof rawCode === \"string\" || typeof rawCode === \"number\") return rawCode;\n\t// Provider failure diagnostics (`bedrock_response_failure`) keep the modeled error code in `details.errorCode`,\n\t// because the provider's display message replaces the exception name with a readable prefix.\n\tconst detailsCode = field(field(value, \"details\"), \"errorCode\");\n\treturn typeof detailsCode === \"string\" ? detailsCode : undefined;\n}\n\nfunction stopReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"stopReason\");\n}\n\nfunction finishReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"finish_reason\") ?? stringField(value, \"finishReason\");\n}\n\nfunction causeOf(value: unknown): unknown {\n\treturn value instanceof Error ? value.cause : field(value, \"cause\");\n}\n\nfunction diagnosticErrors(value: unknown): readonly unknown[] {\n\tconst diagnostics = field(value, \"diagnostics\");\n\tif (!Array.isArray(diagnostics)) return [];\n\tconst errors: unknown[] = [];\n\tfor (const diagnostic of diagnostics) {\n\t\tconst diagnosticType = stringField(diagnostic, \"type\");\n\t\tconst diagnosticError = field(diagnostic, \"error\");\n\t\terrors.push(\n\t\t\tnormalizeCode(diagnosticType) === \"provider_transport_failure\" ? diagnostic : (diagnosticError ?? diagnostic),\n\t\t);\n\t}\n\treturn errors;\n}\n\nfunction normalizeCode(value: string | number | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst raw = String(value).trim().toLowerCase();\n\tif (!raw) return undefined;\n\tlet normalized = \"\";\n\tlet needsSeparator = false;\n\tfor (const char of raw) {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst isLowerAlpha = code >= 97 && code <= 122;\n\t\tconst isDigit = code >= 48 && code <= 57;\n\t\tif (isLowerAlpha || isDigit) {\n\t\t\tnormalized += char;\n\t\t\tneedsSeparator = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (needsSeparator && normalized[normalized.length - 1] !== \"_\") normalized += \"_\";\n\t}\n\tif (normalized.endsWith(\"_\")) normalized = normalized.slice(0, -1);\n\treturn normalized.length > 0 ? normalized : undefined;\n}\n\nfunction messageLooksLikeModelUnavailable(message: string): boolean {\n\tconst lower = message.toLowerCase();\n\treturn (\n\t\tlower.includes(\"model\") &&\n\t\t(lower.includes(\"unavailable\") ||\n\t\t\tlower.includes(\"disabled\") ||\n\t\t\tlower.includes(\"not found\") ||\n\t\t\tlower.includes(\"unknown\"))\n\t);\n}\n\nfunction kindFromStatus(status: number | undefined): ModelFallbackFailureKind | undefined {\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treturn \"request_incompatible\";\n\t\tcase 401:\n\t\tcase 403:\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase 408:\n\t\t\treturn \"network_timeout\";\n\t\tcase 404:\n\t\t\treturn \"model_unavailable\";\n\t\tcase 402:\n\t\t\treturn \"quota_exhausted\";\n\t\tcase 429:\n\t\t\treturn \"rate_limit\";\n\t\tdefault:\n\t\t\tif (status !== undefined && status >= 500 && status <= 599) return \"provider_unavailable\";\n\t\t\treturn undefined;\n\t}\n}\n\nfunction refusalKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\t// A refused tool call, such as `tool_call_refusal` or `tool_use_refused_by_policy`, before the policy words.\n\tif (/(?:^|_)tool(?:_|$)/.test(normalizedCode) && normalizedCode.includes(\"refus\")) return \"task_failure\";\n\tif (normalizedCode.includes(\"content_filter\") || normalizedCode.includes(\"contentfilter\")) return \"content_filter\";\n\t// Includes OpenAI's `cyber_policy`.\n\tif (normalizedCode.includes(\"safety\") || normalizedCode.includes(\"policy\")) return \"content_filter\";\n\tswitch (normalizedCode) {\n\t\tcase \"blocked\":\n\t\tcase \"blocked_by_provider\":\n\t\tcase \"blocked_by_safety\":\n\t\tcase \"blocked_by_policy\":\n\t\tcase \"provider_refusal\":\n\t\tcase \"refusal\":\n\t\t\treturn \"content_filter\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_CODES: ReadonlySet<string> = new Set([\n\t\"invalid_request\",\n\t\"invalid_request_error\",\n\t\"bad_request\",\n\t\"context_length_exceeded\",\n\t\"request_too_large\",\n\t\"too_large\",\n\t\"request_entity_too_large\",\n\t\"max_tokens\",\n\t\"max_context_length\",\n\t\"context_window_exceeded\",\n]);\n\nfunction requestIncompatibleKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalized = normalizeCode(code);\n\treturn normalized !== undefined && REQUEST_INCOMPATIBLE_CODES.has(normalized) ? \"request_incompatible\" : undefined;\n}\n\nfunction kindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\tconst refusalKind = refusalKindFromCode(code);\n\tif (refusalKind !== undefined) return refusalKind;\n\tif (CREDENTIAL_REJECTION_CODES.has(normalizedCode)) return \"auth_on_candidate_provider\";\n\tconst httpStatusKind = kindFromStatus(integerFrom(code));\n\tif (httpStatusKind !== undefined) return httpStatusKind;\n\tconst requestIncompatibleKind = requestIncompatibleKindFromCode(code);\n\tif (requestIncompatibleKind !== undefined) return requestIncompatibleKind;\n\n\tswitch (normalizedCode) {\n\t\tcase \"auth\":\n\t\tcase \"auth_required\":\n\t\tcase \"authentication_required\":\n\t\tcase \"unauthorized\":\n\t\tcase \"forbidden\":\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase \"etimedout\":\n\t\tcase \"econnreset\":\n\t\tcase \"econnrefused\":\n\t\tcase \"econnaborted\":\n\t\tcase \"epipe\":\n\t\tcase \"enotfound\":\n\t\tcase \"eai_again\":\n\t\tcase \"fetch_failed\":\n\t\tcase \"network_error\":\n\t\tcase \"timeout\":\n\t\tcase \"timeout_error\":\n\t\tcase \"und_err_connect_timeout\":\n\t\t\treturn \"network_timeout\";\n\t\tcase \"err_http2_stream_error\":\n\t\tcase \"err_http2_stream_cancel\":\n\t\t\treturn \"transport_error\";\n\t\tcase \"rate_limit\":\n\t\tcase \"rate_limit_exceeded\":\n\t\tcase \"too_many_requests\":\n\t\tcase \"throttlingexception\":\n\t\tcase \"resource_exhausted\":\n\t\t\treturn \"rate_limit\";\n\t\tcase \"quota_exceeded\":\n\t\tcase \"insufficient_quota\":\n\t\tcase \"usage_limit\":\n\t\tcase \"usage_limit_reached\":\n\t\tcase \"usage_limit_exceeded\":\n\t\tcase \"payment_required\":\n\t\tcase \"servicequotaexceededexception\":\n\t\t\treturn \"quota_exhausted\";\n\t\tcase \"aborterror\":\n\t\tcase \"aborted\":\n\t\tcase \"cancelled\":\n\t\tcase \"canceled\":\n\t\t\treturn \"cancelled\";\n\t\tcase \"model_not_found\":\n\t\tcase \"model_unavailable\":\n\t\tcase \"model_disabled\":\n\t\tcase \"unknown_model\":\n\t\tcase \"model_not_available_for_integrator\":\n\t\t\treturn \"model_unavailable\";\n\t\tcase \"provider_error\":\n\t\tcase \"api_error\":\n\t\tcase \"service_unavailable\":\n\t\tcase \"temporarily_unavailable\":\n\t\tcase \"overloaded\":\n\t\t// Amazon Bedrock's transient service exceptions (#4918).\n\t\tcase \"serviceunavailableexception\":\n\t\tcase \"internalserverexception\":\n\t\tcase \"modelnotreadyexception\":\n\t\t// Google's provider status for an overloaded or unavailable service (#4994).\n\t\tcase \"unavailable\":\n\t\t\treturn \"provider_unavailable\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bcontext[_\\s-]?length(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bcontext[_\\s-]?window(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bmax[_\\s-]?context\\b/i,\n\t/\\bmax[_\\s-]?tokens?\\b/i,\n\t/\\brequest(?:[_\\s-]?entity)?[_\\s-]?too[_\\s-]?large\\b/i,\n\t/\\btoo[_\\s-]?large\\b/i,\n\t/\\b(?:unsupported|unknown|invalid)\\s+(?:tool|parameter|function)\\b/i,\n\t/\\b(?:tool|parameter|function)\\s+(?:not\\s+(?:supported|found|allowed)|unknown|invalid)\\b/i,\n\t/\\binvalid[_\\s-]?request(?:[_\\s-]?error)?\\b/i,\n\t/\\bbad[_\\s-]?request\\b/i,\n];\n\n/** A provider declined the request's content under its usage policy: the model will refuse it again. */\nconst CONTENT_FILTER_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bthe\\s+model\\s+refused\\s+to\\s+complete\\s+the\\s+request\\b/i,\n\t/\\bfinish[_\\s-]?reason\\b[^\\n]*\\bcontent[_\\s-]?filter\\b/i,\n\t/\\bcontent[_\\s-]?filter(?:ed|ing)?\\b/i,\n\t/\\bcyber[_\\s-]?policy\\b/i,\n\t// OpenAI's cyber safeguard: \"This content was flagged for possible cybersecurity risk.\"\n\t/\\bflagged\\s+for\\s+(?:possible|potential(?:ly)?)\\b[^\\n]*\\b(?:risk|harm(?:ful)?|safety|policy|cyber\\w*)\\b/i,\n\t/\\b(?:safety|policy)\\b[^\\n]*\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b/i,\n\t/\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b[^\\n]*\\b(?:safety|policy)\\b/i,\n\t/\\bprovider[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\bprovider\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\b(?:prompt|request|content|policy|safety)\\b/i,\n];\n\nconst TOOL_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\btool[_\\s-]?(?:call|use)?[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\btool(?:\\s+call|\\s+use)?\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\btool(?:\\s+call|\\s+use)?\\b/i,\n];\n\nconst PROVIDER_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t...CONTENT_FILTER_FAILURE_PATTERNS,\n\t...TOOL_REFUSAL_FAILURE_PATTERNS,\n];\n\nconst TRANSPORT_OUTAGE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/^connection\\s+error\\.?$/i,\n\t/^fetch\\s+failed\\.?$/i,\n\t// Response-body decompression failures reported by Node/Bun zlib, optionally\n\t// behind the fetch/WebSocket layer's \"Library error:\" wrapper. GitHub Copilot\n\t// on the default `transport: \"auto\"` surfaces this as\n\t// \"Library error: zlib error: incorrect header check\" (#2553). These are\n\t// unanchored because the wrapper text varies by runtime and transport. `zlib`\n\t// has no trailing word boundary on purpose: Bun 1.4.0, the shipped runtime\n\t// when verified, throws `ZlibError fetching \"...\"` as one word.\n\t/\\bzlib/i,\n\t/\\bincorrect\\s+header\\s+check\\b/i,\n\t/\\bdecompress(?:ion|ing|ed)?\\b/i,\n\t/^library\\s+error\\b/i,\n\t// Idle-stream deadline enforced below the HTTP layer by pi-ai's\n\t// `withStreamDeadline`, so a stalled stream fails over instead of hanging.\n\t/\\bstream\\s+deadline\\s+exceeded\\b/i,\n\t// A streamed response cut off before its finish reason, as GitHub Copilot's Gemini models do now and then: the\n\t// same request normally completes when sent again (#4223).\n\t/\\bstream\\s+ended\\s+without\\s+finish[_\\s-]?reason\\b/i,\n];\n\n// HTTP 402 and explicit quota exhaustion: the account cannot be served again until its quota resets.\n// Codes that also appear as free-text wording for short limits (\"quota exceeded\", \"usage limit reached\")\n// count only as a JSON `code`/`type` value, as in a raw error body some providers put in the message.\n// A service-quota exception and a per-day quota violation in a JSON error body (`\"quotaId\": \"...PerDay...\"`)\n// also last until the quota resets.\nconst QUOTA_EXHAUSTED_FAILURE_PATTERN =\n\t/(?<![a-z0-9.])402(?![a-z0-9.])|payment[_\\s-]*required|insufficient[_\\s-]*quota|\\bServiceQuotaExceededException\\b|\"quotaId\"\\s*:\\s*\"[^\"]*PerDay|\"(?:code|type|error_code)\"\\s*:\\s*\"(?:quota_exceeded|usage_limit|usage_limit_reached|usage_limit_exceeded)\"/i;\n\n// An account out of credit or money: nothing serves it again until it is topped up, so a short rate-limit cooldown would\n// spend one failed request per cooldown. Anthropic answers with HTTP 400 and `invalid_request_error`, and OpenRouter's\n// affordability error names `max_tokens`, so this wording outranks the request-error grammar and the status.\nconst BILLING_EXHAUSTED_FAILURE_PATTERN =\n\t/credit\\s+balance\\s+is\\s+too\\s+low|insufficient[_\\s-]*(?:credits?|balance|funds)|(?:requires|purchase|buy|add)\\s+more\\s+credits|used\\s+all\\s+(?:of\\s+)?(?:your\\s+)?available\\s+credits|out\\s+of\\s+(?:credits?|budget)|spending\\s+limit|available\\s+balance|check\\s+your\\s+plan\\s+and\\s+billing/i;\n\nconst API_KEY_REJECTED_FAILURE_PATTERN =\n\t/\\b(?:invalid|incorrect|expired|disabled|leaked)[_\\s-]*api[_\\s-]*key\\b|\\bapi[_\\s-]+key[_\\s-]+(?:(?:is|was|has|been)[_\\s-]+){0,3}(?:not[_\\s-]+valid|invalid|incorrect|expired|disabled|leaked|rejected|reported[_\\s-]+as[_\\s-]+leaked)\\b/i;\n\nconst TOKEN_REJECTED_FAILURE_PATTERN =\n\t/\\b(?:expired|revoked|invalidated)[_\\s-]+(?:(?:oauth|auth|access|refresh)[_\\s-]+)?token\\b|\\b(?:(?:oauth|auth|access|refresh)[_\\s-]+)?token[_\\s-]+(?:(?:is|was|has|been)[_\\s-]+){0,3}(?:expired|revoked|invalidated)\\b|\\bsecurity\\s+token\\s+(?:included\\s+in\\s+the\\s+request\\s+)?(?:is|has)\\s+(?:expired|invalid)\\b/i;\n\nfunction transportOutageKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\treturn TRANSPORT_OUTAGE_FAILURE_PATTERNS.some((pattern) => pattern.test(message.trim()))\n\t\t? \"transport_error\"\n\t\t: undefined;\n}\n\nfunction refusalKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\tif (TRANSPORT_CANCELLATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"network_timeout\";\n\tif (CANCELLED_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"cancelled\";\n\tif (NON_RETRYABLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\t// A refused tool call is about that call, whatever policy the provider names: another model is asked the same\n\t// tool call. So it is checked before the content-filter grammar, which \"refused ... safety policy\" also matches.\n\tif (TOOL_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\tif (CONTENT_FILTER_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"content_filter\";\n\treturn undefined;\n}\n\n// A status that leads an adapter's error message: `503: …`, `529 {…}`, or `OpenAI API error (503): …`.\nconst LEADING_HTTP_STATUS_PATTERN = /^(?:[^\\n():]*\\((\\d{3})\\):|(\\d{3})(?=[:\\s]))/;\n// The status in a JSON error body, as Google's `{\"error\":{\"code\":503,…,\"status\":\"UNAVAILABLE\"}}`.\nconst JSON_ERROR_CODE_PATTERN = /\"code\"\\s*:\\s*(\\d{3})(?!\\d)/;\nconst JSON_PROVIDER_STATUS_PATTERN = /\"status\"\\s*:\\s*\"([A-Z_]+)\"/;\n\n/**\n * The transient kind the provider's own error text names, so no text rule condemns the model over it: an HTTP status\n * leading the message or in its JSON error body, a provider status such as `UNAVAILABLE`, or an overloaded service. A\n * permanent HTTP status in the text names no transient kind (#4994).\n */\nfunction transientKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\tconst leadingStatus = LEADING_HTTP_STATUS_PATTERN.exec(message);\n\tconst status = integerFrom(leadingStatus?.[1] ?? leadingStatus?.[2] ?? JSON_ERROR_CODE_PATTERN.exec(message)?.[1]);\n\tconst kind =\n\t\tstatus === undefined\n\t\t\t? (kindFromCode(JSON_PROVIDER_STATUS_PATTERN.exec(message)?.[1]) ??\n\t\t\t\t(/overloaded/i.test(message) ? \"provider_unavailable\" : undefined))\n\t\t\t: kindFromStatus(status);\n\treturn kind !== undefined && SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(kind) ? kind : undefined;\n}\n\nfunction fallbackKindFromMessage(message: string, name: string | undefined): ModelFallbackFailureKind | undefined {\n\tconst refusalKind = refusalKindFromMessage(message);\n\tif (refusalKind !== undefined) return refusalKind;\n\tconst transportOutageKind = transportOutageKindFromMessage(message);\n\tif (transportOutageKind !== undefined) return transportOutageKind;\n\tif (BILLING_EXHAUSTED_FAILURE_PATTERN.test(message)) return \"quota_exhausted\";\n\tif (\n\t\tAPI_KEY_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tTOKEN_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tCREDENTIAL_REJECTION_CODE_PATTERN.test(message)\n\t)\n\t\treturn \"auth_on_candidate_provider\";\n\tif (REQUEST_INCOMPATIBLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"request_incompatible\";\n\tconst nameKind = kindFromCode(name);\n\tif (nameKind !== undefined) return nameKind;\n\tif (QUOTA_EXHAUSTED_FAILURE_PATTERN.test(message)) return \"quota_exhausted\";\n\tconst transientKind = transientKindFromMessage(message);\n\tconst hasRetryablePattern =\n\t\ttransientKind !== undefined ||\n\t\tRETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(message)) ||\n\t\tmessageLooksLikeModelUnavailable(message);\n\tif (!hasRetryablePattern) return undefined;\n\tif (\n\t\t/rate\\s*limit|too\\s*many\\s*requests|\\bthrottl(?:ing|ed)\\b|\\b429\\b|quota|usage[\\s_-]*limit|billing|credit/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"rate_limit\";\n\t// Text that would condemn the model does not decide over a transient failure the provider names (#4994).\n\tif (\n\t\ttransientKind === undefined &&\n\t\t/auth|unauthori[sz]ed|\\b40[13]\\b|api[_\\s-]*key|token[_\\s-]*(?:expired|revoked|invalidated|rejected)|forbidden|invalid[_\\s-]*key/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"auth_on_candidate_provider\";\n\tif (transientKind === undefined && messageLooksLikeModelUnavailable(message)) return \"model_unavailable\";\n\tif (\n\t\t/network|fetch|socket|connection\\s*refused|(?<![a-z0-9_])(?:ECONNRESET|ECONNABORTED|ECONNREFUSED|ETIMEDOUT|EPIPE)(?![a-z0-9_])|getaddrinfo|ENOTFOUND|EAI_AGAIN|timeout|timed\\s+out/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"network_timeout\";\n\treturn transientKind ?? \"provider_unavailable\";\n}\n\nfunction signalSource(value: unknown, fallback: ModelFallbackFailureSource | undefined): ModelFallbackFailureSource {\n\tif (fallback !== undefined) return fallback;\n\tif (stopReasonFrom(value) !== undefined || diagnosticErrors(value).length > 0) return \"assistant_message\";\n\tif (value instanceof Error) return \"throw\";\n\treturn \"structured\";\n}\n\nfunction makeSignal(\n\tkind: ModelFallbackFailureKind,\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal {\n\tconst status = statusFrom(value);\n\tconst code = codeFrom(value);\n\tconst name = errorName(value);\n\tconst stopReason = stopReasonFrom(value);\n\treturn {\n\t\tkind,\n\t\tmessage: errorMessage(value),\n\t\tsource: signalSource(value, source),\n\t\t...(stopReason !== undefined ? { stopReason } : {}),\n\t\t...(status !== undefined ? { status } : {}),\n\t\t...(code !== undefined ? { code } : {}),\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\nfunction fallbackSignalFromDirectMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tif (normalizeCode(codeFrom(value)) === \"econnaborted\") return undefined;\n\tconst message = directMessageFrom(value);\n\tif (message === undefined) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\nfunction fallbackSignalFromMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst message = classifiableMessage(value);\n\tif (message === undefined) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\n/** Kinds that condemn the model for the turn: message text alone must not assign one over a transient status. */\nconst MODEL_BLOCKING_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"auth_on_candidate_provider\",\n\t\"model_unavailable\",\n\t\"request_incompatible\",\n]);\n\n/**\n * The direct message's signal, unless the failure's own HTTP status or provider code names a transient failure and\n * the text would condemn the model instead. Structured fields decide first; text is the fallback (#4918).\n */\nfunction directMessageSignalUnlessTransient(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst signal = fallbackSignalFromDirectMessage(value, source);\n\tif (signal === undefined || !MODEL_BLOCKING_FAILURE_KINDS.has(signal.kind)) return signal;\n\t// An adapter's `provider_response_failure` diagnostic carries the HTTP status of the failed request (#4994).\n\tconst rawDiagnostics = field(value, \"diagnostics\");\n\tconst structuredKinds = [value, ...(Array.isArray(rawDiagnostics) ? rawDiagnostics : [])].flatMap((source) => [\n\t\tkindFromStatus(statusFrom(source)),\n\t\tkindFromCode(codeFrom(source)),\n\t]);\n\treturn structuredKinds.some((kind) => kind !== undefined && SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(kind))\n\t\t? undefined\n\t\t: signal;\n}\n\nfunction classifyAssistantRefusalSignal(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tif (normalizeCode(codeFrom(value)) === \"econnaborted\") return undefined;\n\tconst codeRefusalKind =\n\t\trefusalKindFromCode(codeFrom(value)) ??\n\t\trefusalKindFromCode(errorName(value)) ??\n\t\trefusalKindFromCode(finishReasonFrom(value));\n\tif (codeRefusalKind !== undefined) return makeSignal(codeRefusalKind, value, source);\n\n\tconst messageRefusalKind = refusalKindFromMessage(directMessageFrom(value) ?? \"\");\n\treturn messageRefusalKind === undefined ? undefined : makeSignal(messageRefusalKind, value, source);\n}\n\nfunction isRefusalSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn signal.kind === \"cancelled\" || signal.kind === \"task_failure\" || signal.kind === \"content_filter\";\n}\n\nfunction nestedSignalPriority(signal: ModelFallbackFailureSignal): number {\n\tswitch (signal.kind) {\n\t\tcase \"cancelled\":\n\t\tcase \"task_failure\":\n\t\tcase \"content_filter\":\n\t\t\treturn 100;\n\t\tcase \"auth_on_candidate_provider\":\n\t\t\treturn 90;\n\t\tcase \"request_incompatible\":\n\t\t\treturn 85;\n\t\tcase \"model_unavailable\":\n\t\t\treturn 80;\n\t\tcase \"quota_exhausted\":\n\t\t\treturn 75;\n\t\tcase \"rate_limit\":\n\t\t\treturn 70;\n\t\tcase \"provider_unavailable\":\n\t\t\treturn 60;\n\t\tcase \"network_timeout\":\n\t\t\treturn 50;\n\t\tcase \"transport_error\":\n\t\t\treturn 82;\n\t\tcase \"unknown\":\n\t\t\treturn 0;\n\t}\n}\nfunction structuredSignal(\n\tvalue: unknown,\n\tseen: Set<unknown>,\n\tsource?: ModelFallbackFailureSource,\n): ModelFallbackFailureSignal | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"object\") seen.add(value);\n\n\tconst stopReason = stopReasonFrom(value)?.toLowerCase();\n\tconst diagnosticType = stringField(value, \"type\");\n\tconst providerTransportSignal =\n\t\tdiagnosticType !== undefined && normalizeCode(diagnosticType) === \"provider_transport_failure\"\n\t\t\t? makeSignal(\"transport_error\", value, source)\n\t\t\t: undefined;\n\tif (stopReason === \"aborted\") return makeSignal(\"cancelled\", value, source);\n\n\t// Defer direct refusal/cancellation signals until nested diagnostics and\n\t// causes have been inspected. A transport wrapper can carry a cancellation\n\t// or provider refusal that must win over the wrapper's transport label.\n\tconst directRefusalSignal = classifyAssistantRefusalSignal(value, source);\n\tconst codeKind = kindFromCode(codeFrom(value));\n\tconst nameKind = kindFromCode(errorName(value));\n\tconst directCancellationSignal =\n\t\tcodeKind === \"cancelled\" || nameKind === \"cancelled\" ? makeSignal(\"cancelled\", value, source) : undefined;\n\n\tlet bestNestedFallbackSignal: ModelFallbackFailureSignal | undefined;\n\tconst nestedSeen = new Set(seen);\n\tconst nestedValues: readonly { value: unknown; source?: ModelFallbackFailureSource }[] = [\n\t\t...diagnosticErrors(value).map((diagnosticError) => ({ value: diagnosticError, source: \"diagnostic\" as const })),\n\t\t...(field(value, \"error\") === undefined ? [] : [{ value: field(value, \"error\"), source }]),\n\t];\n\tfor (const nested of nestedValues) {\n\t\tconst nestedSignal =\n\t\t\tstructuredSignal(nested.value, nestedSeen, nested.source) ??\n\t\t\tfallbackSignalFromMessage(nested.value, nested.source);\n\t\tif (nestedSignal === undefined) continue;\n\t\tif (isRefusalSignal(nestedSignal)) return nestedSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(nestedSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = nestedSignal;\n\t\t}\n\t}\n\tconst cause = causeOf(value);\n\tconst causeSignal = structuredSignal(cause, nestedSeen, source) ?? fallbackSignalFromMessage(cause, source);\n\tif (causeSignal !== undefined) {\n\t\tif (isRefusalSignal(causeSignal)) return causeSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(causeSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = causeSignal;\n\t\t}\n\t}\n\n\t// This code names the exact cause, so the generic 400 status and its request-error text must not outrank it.\n\tif (\n\t\tdirectRefusalSignal === undefined &&\n\t\tdirectCancellationSignal === undefined &&\n\t\tnormalizeCode(codeFrom(value)) === \"model_not_available_for_integrator\"\n\t)\n\t\treturn makeSignal(\"model_unavailable\", value, source);\n\n\tconst directMessageSignal = directMessageSignalUnlessTransient(value, source);\n\t// An exhausted quota the failure names outranks a generic request error: Anthropic answers an account out of\n\t// credit with HTTP 400 and `invalid_request_error`.\n\tconst quotaExhausted =\n\t\tdirectMessageSignal?.kind === \"quota_exhausted\" || bestNestedFallbackSignal?.kind === \"quota_exhausted\";\n\tconst directSignals = [\n\t\tdirectRefusalSignal,\n\t\tdirectCancellationSignal,\n\t\tproviderTransportSignal,\n\t\tdirectMessageSignal,\n\t\t// A provider error code names the cause more exactly than its HTTP status: Bedrock answers a service-quota\n\t\t// exception with a generic 400.\n\t\tkindFromStatus(statusFrom(value)) === undefined || kindFromCode(codeFrom(value)) !== undefined || quotaExhausted\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromStatus(statusFrom(value))!, value, source),\n\t\tkindFromCode(codeFrom(value)) === undefined ||\n\t\t(quotaExhausted && kindFromCode(codeFrom(value)) === \"request_incompatible\")\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(codeFrom(value))!, value, source),\n\t\tkindFromCode(errorName(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(errorName(value))!, value, source),\n\t].filter((signal): signal is ModelFallbackFailureSignal => signal !== undefined);\n\tfor (const directSignal of directSignals) {\n\t\tif (isRefusalSignal(directSignal)) return directSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(directSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = directSignal;\n\t\t}\n\t}\n\n\tif (bestNestedFallbackSignal !== undefined) return bestNestedFallbackSignal;\n\tif (stopReason === \"error\") return makeSignal(\"provider_unavailable\", value, source);\n\treturn undefined;\n}\n\n/**\n * A message to describe the failure. With `describeStatusAndCode`, a failure with only a status or code gets a\n * generated sentence naming it; text classification never reads that sentence, because its words are ours, not the\n * provider's: \"Model request failed with code ServiceUnavailableException\" reads as an unavailable model (#4918).\n */\nfunction messageFromUnknown(value: unknown, seen: Set<unknown>, describeStatusAndCode = true): string | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"string\") return value.trim().length > 0 ? value : undefined;\n\tif (typeof value === \"number\" || typeof value === \"boolean\" || typeof value === \"bigint\") return String(value);\n\tif (typeof value === \"symbol\" || typeof value === \"function\") return undefined;\n\tseen.add(value);\n\n\tif (value instanceof Error && value.message.trim().length > 0) return value.message;\n\tconst directMessage = directMessageFrom(value);\n\tif (directMessage !== undefined) return directMessage;\n\tfor (const diagnosticError of diagnosticErrors(value)) {\n\t\tconst diagnosticMessage = messageFromUnknown(diagnosticError, seen, describeStatusAndCode);\n\t\tif (diagnosticMessage !== undefined) return diagnosticMessage;\n\t}\n\tconst causeMessage = messageFromUnknown(causeOf(value), seen, describeStatusAndCode);\n\tif (causeMessage !== undefined) return causeMessage;\n\tconst finishReason = finishReasonFrom(value);\n\tif (finishReason !== undefined) return `Model request finished with finish_reason:${finishReason}`;\n\tconst stopReason = stopReasonFrom(value);\n\tif (stopReason !== undefined) return `Assistant message ended with stopReason:${stopReason}`;\n\tif (!describeStatusAndCode) return undefined;\n\tconst status = statusFrom(value);\n\tif (status !== undefined) return `Model request failed with status ${status}`;\n\tconst code = codeFrom(value);\n\tif (code !== undefined) return `Model request failed with code ${String(code)}`;\n\treturn undefined;\n}\n\nexport function errorMessage(error: unknown): string {\n\tconst structuredMessage = messageFromUnknown(error, new Set());\n\tif (structuredMessage !== undefined) return structuredMessage;\n\tconst rendered = String(error);\n\treturn rendered === \"[object Object]\" ? \"Model request failed\" : rendered;\n}\n\n/** The failure's own text, for text classification: never a sentence generated from its status or code. */\nfunction classifiableMessage(error: unknown): string | undefined {\n\treturn messageFromUnknown(error, new Set(), false);\n}\n\n/** Alias used by the subagent package's older public helper name. */\nexport const modelFailureMessage = errorMessage;\n\n/** The fallback decision each typed GitHub Copilot failure stands for. */\nconst GITHUB_COPILOT_FAILURE_KINDS: Readonly<Record<GitHubCopilotErrorCode, ModelFallbackFailureKind>> = {\n\t\"model-unavailable\": \"model_unavailable\",\n\t\"rate-limited\": \"rate_limit\",\n\t\"quota-exhausted\": \"quota_exhausted\",\n\t\"content-filtered\": \"content_filter\",\n\t\"prompt-too-large\": \"request_incompatible\",\n\t\"invalid-request\": \"request_incompatible\",\n\t\"authentication-failed\": \"auth_on_candidate_provider\",\n\t\"service-unavailable\": \"provider_unavailable\",\n\t\"stream-ended-early\": \"transport_error\",\n\t\"empty-response\": \"transport_error\",\n\t\"unrecognized-response\": \"provider_unavailable\",\n};\n\n/**\n * A GitHub Copilot failure is typed at the provider: its code decides, never its text. The typed error is found on\n * the failure, anywhere in its cause chain, or in the diagnostics of a failed assistant message in that chain, as\n * when a caller wraps the message.\n */\nfunction githubCopilotSignal(error: unknown): ModelFallbackFailureSignal | undefined {\n\tconst copilotError: GitHubCopilotError | undefined = findGitHubCopilotError(error);\n\tif (copilotError === undefined) return undefined;\n\treturn makeSignal(GITHUB_COPILOT_FAILURE_KINDS[copilotError.code], copilotError, signalSource(error, undefined));\n}\n\n/**\n * How long the attempt ran, in milliseconds, before its response stream ended early. It is read from the typed GitHub\n * Copilot failure, never from message text: on the error, anywhere in its cause chain, or in the diagnostics of a\n * failed assistant message. Undefined for any other failure, and for a stream-cut error that carries no duration.\n */\nexport function streamCutDurationMs(error: unknown): number | undefined {\n\tconst copilotError = findGitHubCopilotError(error);\n\treturn copilotError instanceof GitHubCopilotStreamEndedEarlyError ? copilotError.durationMs : undefined;\n}\n\nexport function normalizeModelFailureSignal(error: unknown): ModelFallbackFailureSignal {\n\t// Extension startup is not a model request. Its message names extension paths\n\t// and their own errors, which must not read as a provider failure.\n\tif (isExtensionStartupFailure(error)) {\n\t\tconst name = errorName(error);\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\tmessage: errorMessage(error),\n\t\t\tsource: \"string_fallback\",\n\t\t\t...(name !== undefined ? { name } : {}),\n\t\t};\n\t}\n\tconst copilot = githubCopilotSignal(error);\n\tif (copilot !== undefined) return copilot;\n\tconst structured = structuredSignal(error, new Set());\n\tif (structured !== undefined) return structured;\n\tconst message = errorMessage(error);\n\tconst name = errorName(error);\n\tconst textToClassify = classifiableMessage(error);\n\tconst fallbackKind = textToClassify === undefined ? undefined : fallbackKindFromMessage(textToClassify, name);\n\treturn {\n\t\tkind: fallbackKind ?? \"unknown\",\n\t\tmessage,\n\t\tsource: \"string_fallback\",\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\nconst AUTHENTICATION_FAILURE_CODES: ReadonlySet<string> = new Set([\n\t\"auth_required\",\n\t\"authentication_required\",\n\t\"authentication_failed\",\n\t\"authentication_error\",\n\t\"unauthorized\",\n]);\n\nconst CREDENTIAL_REJECTION_CODES: ReadonlySet<string> = new Set([\n\t\"invalid_api_key\",\n\t\"api_key_invalid\",\n\t\"api_key_expired\",\n\t\"api_key_disabled\",\n\t\"api_key_leaked\",\n\t\"missing_api_key\",\n\t\"invalid_key\",\n\t\"token_expired\",\n\t\"token_revoked\",\n\t\"token_invalidated\",\n\t\"oauth_token_invalidated\",\n\t\"expired_token_exception\",\n\t\"expiredtokenexception\",\n\t\"unrecognized_client_exception\",\n\t\"unrecognizedclientexception\",\n\t\"invalid_signature_exception\",\n\t\"invalidsignatureexception\",\n\t\"consumer_suspended\",\n\t\"api_key_service_blocked\",\n\t\"api_key_http_referrer_blocked\",\n\t\"api_key_ip_address_blocked\",\n\t\"api_key_android_app_blocked\",\n\t\"api_key_ios_app_blocked\",\n]);\n\nconst CREDENTIAL_REJECTION_CODE_PATTERN = new RegExp(`\\\\b(?:${[...CREDENTIAL_REJECTION_CODES].join(\"|\")})\\\\b`, \"i\");\n\nexport function isProviderCredentialRejection(error: unknown): boolean {\n\tconst signal = normalizeModelFailureSignal(error);\n\tif (isRefusalSignal(signal)) return false;\n\tconst leadingStatus = LEADING_HTTP_STATUS_PATTERN.exec(signal.message);\n\tconst status =\n\t\tsignal.status ??\n\t\tintegerFrom(\n\t\t\tleadingStatus?.[1] ??\n\t\t\t\tleadingStatus?.[2] ??\n\t\t\t\t/^HTTP(?:\\/\\d(?:\\.\\d)?)?\\s+(\\d{3})\\b/i.exec(signal.message)?.[1] ??\n\t\t\t\tJSON_ERROR_CODE_PATTERN.exec(signal.message)?.[1],\n\t\t);\n\tif (status === 401 || integerFrom(signal.code) === 401) return true;\n\tif (signal.kind !== \"auth_on_candidate_provider\") return false;\n\tconst typedFailure = findGitHubCopilotError(error);\n\tconst providerCode = typedFailure?.providerCode ?? stringField(error, \"providerCode\");\n\tconst codes = providerCode === undefined ? [signal.code, signal.name] : [providerCode];\n\tif (\n\t\tcodes.some((value) => {\n\t\t\tconst code = normalizeCode(value);\n\t\t\treturn (\n\t\t\t\tcode !== undefined &&\n\t\t\t\t(CREDENTIAL_REJECTION_CODES.has(code) || (status !== 403 && AUTHENTICATION_FAILURE_CODES.has(code)))\n\t\t\t);\n\t\t})\n\t)\n\t\treturn true;\n\tconst message = `${signal.message}\\n${typedFailure?.detail ?? stringField(error, \"detail\") ?? \"\"}`;\n\treturn (\n\t\tAPI_KEY_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tTOKEN_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tCREDENTIAL_REJECTION_CODE_PATTERN.test(message)\n\t);\n}\n\n/** Whether a failure is a provider safety/refusal response: a content-filter refusal, or a refused tool call. */\nexport function isSafetyRefusalFailure(error: unknown): boolean {\n\tconst signal = normalizeModelFailureSignal(error);\n\tif (signal.kind === \"content_filter\") return true;\n\tif (signal.kind !== \"task_failure\") return false;\n\tconst text = `${signal.message}\\n${signal.code ?? \"\"}\\n${signal.name ?? \"\"}`;\n\treturn PROVIDER_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(text));\n}\n\n/** Whether a provider's content filter refused the request, as OpenAI's HTTP 422 `cyber_policy` does. */\nexport function isContentFilterRefusal(error: unknown): boolean {\n\treturn normalizeModelFailureSignal(error).kind === \"content_filter\";\n}\n\n/**\n * True when this failure may spend a configured model fallback candidate. A content-filter refusal does unless\n * `options.fallbackOnContentFilter` is false.\n */\nexport function isRetryableModelFailure(error: unknown, options?: ModelFallbackFailureOptions): boolean {\n\tif (error === undefined) return false;\n\tconst kind = normalizeModelFailureSignal(error).kind;\n\tif (kind === \"content_filter\") return options?.fallbackOnContentFilter !== false;\n\treturn FALLBACKABLE_FAILURE_KINDS.has(kind);\n}\n\nconst SAME_MODEL_RETRYABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"rate_limit\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n]);\n\n/**\n * An assistant error that only its `stopReason` marks as a model failure: no status, code or name, and text that no\n * pattern recognizes. It may spend a fallback candidate, but it is not retried on the same model on its own.\n */\nfunction isUnrecognizedSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn (\n\t\tsignal.kind === \"provider_unavailable\" &&\n\t\tsignal.source === \"assistant_message\" &&\n\t\tsignal.status === undefined &&\n\t\tsignal.code === undefined &&\n\t\tsignal.name === undefined &&\n\t\ttransientKindFromMessage(signal.message) === undefined &&\n\t\t!RETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(signal.message))\n\t);\n}\n\n/** True when the same model may be requested again before fallback advances. */\nexport function isRetryableSameModelFailure(error: unknown): boolean {\n\tif (!isRetryableModelFailure(error)) return false;\n\tconst signal = normalizeModelFailureSignal(error);\n\treturn SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(signal.kind) && !isUnrecognizedSignal(signal);\n}\n\n/**\n * True for a failure that may spend a fallback candidate although nothing recognizes it: an assistant error with no\n * status, code or name whose text matches no known pattern. A session with a fallback chain retries it on the same\n * model first, so such an error never switches models on its first occurrence (#4223).\n */\nexport function isUnrecognizedModelFailure(error: unknown): boolean {\n\treturn isRetryableModelFailure(error) && isUnrecognizedSignal(normalizeModelFailureSignal(error));\n}\n"]}
1
+ {"version":3,"file":"model-fallback-failures.js","sourceRoot":"","sources":["../../src/core/model-fallback-failures.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACN,sBAAsB,EACtB,yBAAyB,EAGzB,kCAAkC,EAClC,wBAAwB,GACxB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,MAAM,gCAAgC,GAAsB;IAC3D,eAAe;IACf,wBAAwB;IACxB,wBAAwB;IACxB,SAAS;IACT,QAAQ;IACR,oBAAoB;IACpB,UAAU;IACV,SAAS;IACT,gCAAgC;IAChC,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,sBAAsB;IACtB,sCAAsC;IACtC,+CAA+C;IAC/C,YAAY;IACZ,gBAAgB;IAChB,aAAa;IACb,4BAA4B;IAC5B,wBAAwB;IACxB,UAAU;IACV,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,uBAAuB;IACvB,WAAW;IACX,UAAU;IACV,cAAc;IACd,aAAa;IACb,aAAa;IACb,SAAS;IACT,4BAA4B;IAC5B,gBAAgB;IAChB,kBAAkB;IAClB,oBAAoB;IACpB,mBAAmB;IACnB,qBAAqB;IACrB,oBAAoB;IACpB,sFAAsF;IACtF,oBAAoB;IACpB,oBAAoB;IACpB,mBAAmB;IACnB,uBAAuB;IACvB,iBAAiB;IACjB,gBAAgB;IAChB,mCAAmC;IACnC,gDAAgD;IA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B,CAAC,MAAkC;IAC/D,OAAO,CACN,MAAM,CAAC,IAAI,KAAK,sBAAsB;QACtC,MAAM,CAAC,MAAM,KAAK,mBAAmB;QACrC,MAAM,CAAC,MAAM,KAAK,SAAS;QAC3B,MAAM,CAAC,IAAI,KAAK,SAAS;QACzB,MAAM,CAAC,IAAI,KAAK,SAAS;QACzB,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,SAAS;QACtD,CAAC,gCAAgC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CACjF,CAAC;AACH,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,2BAA2B,CAAC,KAAc;IACzD,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAClD,OAAO,kCAAkC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACxD,OAAO,uBAAuB,CAAC,KAAK,CAAC,IAAI,oBAAoB,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC,CAAC;AACnG,CAAC","sourcesContent":["/**\n * Shared model/provider failure classification.\n *\n * Subagents and the main chat all need the same decision about\n * whether a provider failure may spend another model candidate. Keep this\n * module free of AgentSession imports so the published SDK can\n * expose it to the raw-TypeScript companion packages without a cycle.\n */\n\nimport {\n\tfindGitHubCopilotError,\n\tfindTlsCertificateRefusal,\n\ttype GitHubCopilotError,\n\ttype GitHubCopilotErrorCode,\n\tGitHubCopilotStreamEndedEarlyError,\n\tgetTlsCertificateRefusal,\n} from \"@bastani/atomic-ai\";\nimport { isExtensionStartupFailure } from \"./extension-startup-failure.ts\";\n\nconst RETRYABLE_MODEL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/rate\\s*limit/i,\n\t/too\\s*many\\s*requests/i,\n\t/\\bthrottl(?:ing|ed)\\b/i,\n\t/\\b429\\b/,\n\t/quota/i,\n\t/usage[\\s_-]*limit/i,\n\t/billing/i,\n\t/credit/i,\n\t/auth(?:entication|orization)?/i,\n\t/unauthori[sz]ed/i,\n\t/\\b40[13]\\b/,\n\t/api[_\\s-]*key/i,\n\t/token[_\\s-]*expired/i,\n\t/token[_\\s-]*(?:revoked|invalidated)/i,\n\t/invalidated[_\\s-]+(?:oauth|auth)[_\\s-]+token/i,\n\t/forbidden/i,\n\t/invalid\\s*key/i,\n\t/overloaded/i,\n\t/temporarily\\s*unavailable/i,\n\t/service\\s*unavailable/i,\n\t/network/i,\n\t/fetch/i,\n\t/getaddrinfo/i,\n\t/ENOTFOUND/i,\n\t/EAI_AGAIN/i,\n\t/socket/i,\n\t/connection\\s*refused/i,\n\t/upstream/i,\n\t/timeout/i,\n\t/timed\\s+out/i,\n\t/\\b50[0-4]\\b/,\n\t/\\b52[0-4]\\b/,\n\t/\\b529\\b/,\n\t/provider.?returned.?error/i,\n\t/server.?error/i,\n\t/internal.?error/i,\n\t/connection.?error/i,\n\t/connection.?lost/i,\n\t/connection.?closed/i,\n\t/connection.?reset/i,\n\t/(?<![a-z0-9_])(?:ECONNRESET|ECONNABORTED|ECONNREFUSED|ETIMEDOUT|EPIPE)(?![a-z0-9_])/i,\n\t/other side closed/i,\n\t/websocket.?closed/i,\n\t/websocket.?error/i,\n\t/reset before headers/i,\n\t/socket hang up/i,\n\t/ended without/i,\n\t/stream ended before message_stop/i,\n\t/stream ended before a terminal response event/i,\n\t/http2 request did not get a response/i,\n\t/pending stream has been canceled/i,\n\t/retry delay/i,\n\t/finish.?reason:?\\s*error/i,\n\t/terminated/i,\n\t/you can retry your request/i,\n\t/try your request again/i,\n\t/please retry your request/i,\n\t// gRPC based providers (e.g. NVIDIA NIM); upstream pi-ai retries this too.\n\t/ResourceExhausted/i,\n];\n\nconst NON_RETRYABLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/command failed/i,\n\t/tests? failed/i,\n\t/shell/i,\n\t/missing file/i,\n\t/no such file/i,\n];\n\n// \"cancel\" as a word of its own: an HTTP/2 stream error code such as `NGHTTP2_CANCEL` is a transport reset, not a user\n// cancellation (#4918).\nconst CANCELLED_FAILURE_PATTERNS: readonly RegExp[] = [/(?<![a-z0-9_])cancel/i, /abort/i, /interrupted/i];\n\nconst TRANSPORT_CANCELLATION_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/getaddrinfo|ENOTFOUND|EAI_AGAIN/i,\n\t/(?<![a-z0-9_])ECONNABORTED(?![a-z0-9_])|software caused connection abort/i,\n\t/pending stream has been canceled/i,\n\t// An HTTP/2 stream reset by the peer or a proxy, such as `Stream closed with error code NGHTTP2_CANCEL`.\n\t/(?<![a-z0-9])NGHTTP2_[A-Z_]+|(?<![a-z0-9_])ERR_HTTP2_STREAM_(?:ERROR|CANCEL)(?![a-z0-9_])/i,\n];\n\nexport type ModelFallbackFailureKind =\n\t| \"auth_on_candidate_provider\"\n\t| \"certificate_refused\"\n\t| \"rate_limit\"\n\t| \"quota_exhausted\"\n\t| \"provider_unavailable\"\n\t| \"network_timeout\"\n\t| \"transport_error\"\n\t| \"model_unavailable\"\n\t| \"request_incompatible\"\n\t| \"content_filter\"\n\t| \"cancelled\"\n\t| \"task_failure\"\n\t| \"unknown\";\n\nexport type ModelFallbackFailureSource =\n\t| \"assistant_message\"\n\t| \"diagnostic\"\n\t| \"throw\"\n\t| \"structured\"\n\t| \"string_fallback\";\n\nexport interface ModelFallbackFailureSignal {\n\treadonly kind: ModelFallbackFailureKind;\n\treadonly message: string;\n\treadonly source: ModelFallbackFailureSource;\n\treadonly stopReason?: string;\n\treadonly status?: number;\n\treadonly code?: string | number;\n\treadonly name?: string;\n}\n\n/** How a caller treats a provider content-filter refusal; `retry.fallbackOnContentFilter` in settings. */\nexport interface ModelFallbackFailureOptions {\n\t/** Whether a content-filter refusal may spend the next fallback candidate. Defaults to true. */\n\treadonly fallbackOnContentFilter?: boolean;\n}\n\nconst FALLBACKABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"auth_on_candidate_provider\",\n\t// The next candidate's endpoint may show a certificate the runtime trusts (#6114).\n\t\"certificate_refused\",\n\t\"rate_limit\",\n\t\"quota_exhausted\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n\t\"model_unavailable\",\n\t\"request_incompatible\",\n]);\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n\treturn value !== null && typeof value === \"object\" ? (value as Record<string, unknown>) : undefined;\n}\n\nfunction field(value: unknown, key: string): unknown {\n\treturn asRecord(value)?.[key];\n}\n\nfunction stringField(value: unknown, key: string): string | undefined {\n\tconst raw = field(value, key);\n\treturn typeof raw === \"string\" && raw.trim().length > 0 ? raw : undefined;\n}\n\nfunction errorName(value: unknown): string | undefined {\n\treturn value instanceof Error ? value.name : stringField(value, \"name\");\n}\n\nfunction directMessageFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"errorMessage\") ?? stringField(value, \"message\") ?? stringField(value, \"statusText\");\n}\n\nfunction integerFrom(value: unknown): number | undefined {\n\tif (typeof value === \"number\" && Number.isInteger(value)) return value;\n\tif (typeof value !== \"string\" || value.trim().length === 0) return undefined;\n\tconst parsed = Number(value.trim());\n\treturn Number.isInteger(parsed) ? parsed : undefined;\n}\n\nfunction statusFrom(value: unknown): number | undefined {\n\treturn (\n\t\tintegerFrom(field(value, \"status\")) ??\n\t\tintegerFrom(field(value, \"statusCode\")) ??\n\t\tintegerFrom(field(value, \"httpStatus\")) ??\n\t\t// Provider failure diagnostics (`bedrock_response_failure`) keep the HTTP status in `details.status` (#4918).\n\t\tintegerFrom(field(field(value, \"details\"), \"status\"))\n\t);\n}\n\nfunction codeFrom(value: unknown): string | number | undefined {\n\tconst rawCode = field(value, \"code\");\n\tif (typeof rawCode === \"string\" || typeof rawCode === \"number\") return rawCode;\n\t// Provider failure diagnostics (`bedrock_response_failure`) keep the modeled error code in `details.errorCode`,\n\t// because the provider's display message replaces the exception name with a readable prefix.\n\tconst detailsCode = field(field(value, \"details\"), \"errorCode\");\n\treturn typeof detailsCode === \"string\" ? detailsCode : undefined;\n}\n\nfunction stopReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"stopReason\");\n}\n\nfunction finishReasonFrom(value: unknown): string | undefined {\n\treturn stringField(value, \"finish_reason\") ?? stringField(value, \"finishReason\");\n}\n\nfunction causeOf(value: unknown): unknown {\n\treturn value instanceof Error ? value.cause : field(value, \"cause\");\n}\n\nfunction diagnosticErrors(value: unknown): readonly unknown[] {\n\tconst diagnostics = field(value, \"diagnostics\");\n\tif (!Array.isArray(diagnostics)) return [];\n\tconst errors: unknown[] = [];\n\tfor (const diagnostic of diagnostics) {\n\t\tconst diagnosticType = stringField(diagnostic, \"type\");\n\t\tconst diagnosticError = field(diagnostic, \"error\");\n\t\terrors.push(\n\t\t\tnormalizeCode(diagnosticType) === \"provider_transport_failure\" ? diagnostic : (diagnosticError ?? diagnostic),\n\t\t);\n\t}\n\treturn errors;\n}\n\nfunction normalizeCode(value: string | number | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\tconst raw = String(value).trim().toLowerCase();\n\tif (!raw) return undefined;\n\tlet normalized = \"\";\n\tlet needsSeparator = false;\n\tfor (const char of raw) {\n\t\tconst code = char.charCodeAt(0);\n\t\tconst isLowerAlpha = code >= 97 && code <= 122;\n\t\tconst isDigit = code >= 48 && code <= 57;\n\t\tif (isLowerAlpha || isDigit) {\n\t\t\tnormalized += char;\n\t\t\tneedsSeparator = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (needsSeparator && normalized[normalized.length - 1] !== \"_\") normalized += \"_\";\n\t}\n\tif (normalized.endsWith(\"_\")) normalized = normalized.slice(0, -1);\n\treturn normalized.length > 0 ? normalized : undefined;\n}\n\nfunction messageLooksLikeModelUnavailable(message: string): boolean {\n\tconst lower = message.toLowerCase();\n\treturn (\n\t\tlower.includes(\"model\") &&\n\t\t(lower.includes(\"unavailable\") ||\n\t\t\tlower.includes(\"disabled\") ||\n\t\t\tlower.includes(\"not found\") ||\n\t\t\tlower.includes(\"unknown\"))\n\t);\n}\n\nfunction kindFromStatus(status: number | undefined): ModelFallbackFailureKind | undefined {\n\tswitch (status) {\n\t\tcase 400:\n\t\tcase 413:\n\t\tcase 422:\n\t\t\treturn \"request_incompatible\";\n\t\tcase 401:\n\t\tcase 403:\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase 408:\n\t\t\treturn \"network_timeout\";\n\t\tcase 404:\n\t\t\treturn \"model_unavailable\";\n\t\tcase 402:\n\t\t\treturn \"quota_exhausted\";\n\t\tcase 429:\n\t\t\treturn \"rate_limit\";\n\t\tdefault:\n\t\t\tif (status !== undefined && status >= 500 && status <= 599) return \"provider_unavailable\";\n\t\t\treturn undefined;\n\t}\n}\n\nfunction refusalKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\t// A refused tool call, such as `tool_call_refusal` or `tool_use_refused_by_policy`, before the policy words.\n\tif (/(?:^|_)tool(?:_|$)/.test(normalizedCode) && normalizedCode.includes(\"refus\")) return \"task_failure\";\n\tif (normalizedCode.includes(\"content_filter\") || normalizedCode.includes(\"contentfilter\")) return \"content_filter\";\n\t// Includes OpenAI's `cyber_policy`.\n\tif (normalizedCode.includes(\"safety\") || normalizedCode.includes(\"policy\")) return \"content_filter\";\n\tswitch (normalizedCode) {\n\t\tcase \"blocked\":\n\t\tcase \"blocked_by_provider\":\n\t\tcase \"blocked_by_safety\":\n\t\tcase \"blocked_by_policy\":\n\t\tcase \"provider_refusal\":\n\t\tcase \"refusal\":\n\t\t\treturn \"content_filter\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_CODES: ReadonlySet<string> = new Set([\n\t\"invalid_request\",\n\t\"invalid_request_error\",\n\t\"bad_request\",\n\t\"context_length_exceeded\",\n\t\"request_too_large\",\n\t\"too_large\",\n\t\"request_entity_too_large\",\n\t\"max_tokens\",\n\t\"max_context_length\",\n\t\"context_window_exceeded\",\n]);\n\nfunction requestIncompatibleKindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalized = normalizeCode(code);\n\treturn normalized !== undefined && REQUEST_INCOMPATIBLE_CODES.has(normalized) ? \"request_incompatible\" : undefined;\n}\n\nfunction kindFromCode(code: string | number | undefined): ModelFallbackFailureKind | undefined {\n\tconst normalizedCode = normalizeCode(code);\n\tif (normalizedCode === undefined) return undefined;\n\tconst refusalKind = refusalKindFromCode(code);\n\tif (refusalKind !== undefined) return refusalKind;\n\tif (CREDENTIAL_REJECTION_CODES.has(normalizedCode)) return \"auth_on_candidate_provider\";\n\tconst httpStatusKind = kindFromStatus(integerFrom(code));\n\tif (httpStatusKind !== undefined) return httpStatusKind;\n\tconst requestIncompatibleKind = requestIncompatibleKindFromCode(code);\n\tif (requestIncompatibleKind !== undefined) return requestIncompatibleKind;\n\n\tswitch (normalizedCode) {\n\t\tcase \"auth\":\n\t\tcase \"auth_required\":\n\t\tcase \"authentication_required\":\n\t\tcase \"unauthorized\":\n\t\tcase \"forbidden\":\n\t\t\treturn \"auth_on_candidate_provider\";\n\t\tcase \"etimedout\":\n\t\tcase \"econnreset\":\n\t\tcase \"econnrefused\":\n\t\tcase \"econnaborted\":\n\t\tcase \"epipe\":\n\t\tcase \"enotfound\":\n\t\tcase \"eai_again\":\n\t\tcase \"fetch_failed\":\n\t\tcase \"network_error\":\n\t\tcase \"timeout\":\n\t\tcase \"timeout_error\":\n\t\tcase \"und_err_connect_timeout\":\n\t\t\treturn \"network_timeout\";\n\t\tcase \"err_http2_stream_error\":\n\t\tcase \"err_http2_stream_cancel\":\n\t\t\treturn \"transport_error\";\n\t\tcase \"rate_limit\":\n\t\tcase \"rate_limit_exceeded\":\n\t\tcase \"too_many_requests\":\n\t\tcase \"throttlingexception\":\n\t\tcase \"resource_exhausted\":\n\t\t\treturn \"rate_limit\";\n\t\tcase \"quota_exceeded\":\n\t\tcase \"insufficient_quota\":\n\t\tcase \"usage_limit\":\n\t\tcase \"usage_limit_reached\":\n\t\tcase \"usage_limit_exceeded\":\n\t\tcase \"payment_required\":\n\t\tcase \"servicequotaexceededexception\":\n\t\t\treturn \"quota_exhausted\";\n\t\tcase \"aborterror\":\n\t\tcase \"aborted\":\n\t\tcase \"cancelled\":\n\t\tcase \"canceled\":\n\t\t\treturn \"cancelled\";\n\t\tcase \"model_not_found\":\n\t\tcase \"model_unavailable\":\n\t\tcase \"model_disabled\":\n\t\tcase \"unknown_model\":\n\t\tcase \"model_not_available_for_integrator\":\n\t\t\treturn \"model_unavailable\";\n\t\tcase \"provider_error\":\n\t\tcase \"api_error\":\n\t\tcase \"service_unavailable\":\n\t\tcase \"temporarily_unavailable\":\n\t\tcase \"overloaded\":\n\t\t// Amazon Bedrock's transient service exceptions (#4918).\n\t\tcase \"serviceunavailableexception\":\n\t\tcase \"internalserverexception\":\n\t\tcase \"modelnotreadyexception\":\n\t\t// Google's provider status for an overloaded or unavailable service (#4994).\n\t\tcase \"unavailable\":\n\t\t\treturn \"provider_unavailable\";\n\t\tdefault:\n\t\t\treturn undefined;\n\t}\n}\n\nconst REQUEST_INCOMPATIBLE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bcontext[_\\s-]?length(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bcontext[_\\s-]?window(?:[_\\s-]?exceeded)?\\b/i,\n\t/\\bmax[_\\s-]?context\\b/i,\n\t/\\bmax[_\\s-]?tokens?\\b/i,\n\t/\\brequest(?:[_\\s-]?entity)?[_\\s-]?too[_\\s-]?large\\b/i,\n\t/\\btoo[_\\s-]?large\\b/i,\n\t/\\b(?:unsupported|unknown|invalid)\\s+(?:tool|parameter|function)\\b/i,\n\t/\\b(?:tool|parameter|function)\\s+(?:not\\s+(?:supported|found|allowed)|unknown|invalid)\\b/i,\n\t/\\binvalid[_\\s-]?request(?:[_\\s-]?error)?\\b/i,\n\t/\\bbad[_\\s-]?request\\b/i,\n];\n\n/** A provider declined the request's content under its usage policy: the model will refuse it again. */\nconst CONTENT_FILTER_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\bthe\\s+model\\s+refused\\s+to\\s+complete\\s+the\\s+request\\b/i,\n\t/\\bfinish[_\\s-]?reason\\b[^\\n]*\\bcontent[_\\s-]?filter\\b/i,\n\t/\\bcontent[_\\s-]?filter(?:ed|ing)?\\b/i,\n\t/\\bcyber[_\\s-]?policy\\b/i,\n\t// OpenAI's cyber safeguard: \"This content was flagged for possible cybersecurity risk.\"\n\t/\\bflagged\\s+for\\s+(?:possible|potential(?:ly)?)\\b[^\\n]*\\b(?:risk|harm(?:ful)?|safety|policy|cyber\\w*)\\b/i,\n\t/\\b(?:safety|policy)\\b[^\\n]*\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b/i,\n\t/\\b(?:refus(?:e|al|ed|es|ing)?|block(?:ed|ing)?|filter(?:ed|ing)?|violat(?:e|ion|ed|ing)?|disallow(?:ed|ing)?|reject(?:ed|ion|ing)?)\\b[^\\n]*\\b(?:safety|policy)\\b/i,\n\t/\\bprovider[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\bprovider\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\b(?:prompt|request|content|policy|safety)\\b/i,\n];\n\nconst TOOL_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/\\btool[_\\s-]?(?:call|use)?[_\\s-]?refus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\btool(?:\\s+call|\\s+use)?\\b[^\\n]*\\brefus(?:e|al|ed|es|ing)?\\b/i,\n\t/\\brefus(?:e|al|ed|es|ing)?\\b[^\\n]*\\btool(?:\\s+call|\\s+use)?\\b/i,\n];\n\nconst PROVIDER_REFUSAL_FAILURE_PATTERNS: readonly RegExp[] = [\n\t...CONTENT_FILTER_FAILURE_PATTERNS,\n\t...TOOL_REFUSAL_FAILURE_PATTERNS,\n];\n\nconst TRANSPORT_OUTAGE_FAILURE_PATTERNS: readonly RegExp[] = [\n\t/^connection\\s+error\\.?$/i,\n\t/^fetch\\s+failed\\.?$/i,\n\t// Response-body decompression failures reported by Node/Bun zlib, optionally\n\t// behind the fetch/WebSocket layer's \"Library error:\" wrapper. GitHub Copilot\n\t// on the default `transport: \"auto\"` surfaces this as\n\t// \"Library error: zlib error: incorrect header check\" (#2553). These are\n\t// unanchored because the wrapper text varies by runtime and transport. `zlib`\n\t// has no trailing word boundary on purpose: Bun 1.4.0, the shipped runtime\n\t// when verified, throws `ZlibError fetching \"...\"` as one word.\n\t/\\bzlib/i,\n\t/\\bincorrect\\s+header\\s+check\\b/i,\n\t/\\bdecompress(?:ion|ing|ed)?\\b/i,\n\t/^library\\s+error\\b/i,\n\t// Idle-stream deadline enforced below the HTTP layer by pi-ai's\n\t// `withStreamDeadline`, so a stalled stream fails over instead of hanging.\n\t/\\bstream\\s+deadline\\s+exceeded\\b/i,\n\t// A streamed response cut off before its finish reason, as GitHub Copilot's Gemini models do now and then: the\n\t// same request normally completes when sent again (#4223).\n\t/\\bstream\\s+ended\\s+without\\s+finish[_\\s-]?reason\\b/i,\n];\n\n// HTTP 402 and explicit quota exhaustion: the account cannot be served again until its quota resets.\n// Codes that also appear as free-text wording for short limits (\"quota exceeded\", \"usage limit reached\")\n// count only as a JSON `code`/`type` value, as in a raw error body some providers put in the message.\n// A service-quota exception and a per-day quota violation in a JSON error body (`\"quotaId\": \"...PerDay...\"`)\n// also last until the quota resets.\nconst QUOTA_EXHAUSTED_FAILURE_PATTERN =\n\t/(?<![a-z0-9.])402(?![a-z0-9.])|payment[_\\s-]*required|insufficient[_\\s-]*quota|\\bServiceQuotaExceededException\\b|\"quotaId\"\\s*:\\s*\"[^\"]*PerDay|\"(?:code|type|error_code)\"\\s*:\\s*\"(?:quota_exceeded|usage_limit|usage_limit_reached|usage_limit_exceeded)\"/i;\n\n// An account out of credit or money: nothing serves it again until it is topped up, so a short rate-limit cooldown would\n// spend one failed request per cooldown. Anthropic answers with HTTP 400 and `invalid_request_error`, and OpenRouter's\n// affordability error names `max_tokens`, so this wording outranks the request-error grammar and the status.\nconst BILLING_EXHAUSTED_FAILURE_PATTERN =\n\t/credit\\s+balance\\s+is\\s+too\\s+low|insufficient[_\\s-]*(?:credits?|balance|funds)|(?:requires|purchase|buy|add)\\s+more\\s+credits|used\\s+all\\s+(?:of\\s+)?(?:your\\s+)?available\\s+credits|out\\s+of\\s+(?:credits?|budget)|spending\\s+limit|available\\s+balance|check\\s+your\\s+plan\\s+and\\s+billing/i;\n\nconst API_KEY_REJECTED_FAILURE_PATTERN =\n\t/\\b(?:invalid|incorrect|expired|disabled|leaked)[_\\s-]*api[_\\s-]*key\\b|\\bapi[_\\s-]+key[_\\s-]+(?:(?:is|was|has|been)[_\\s-]+){0,3}(?:not[_\\s-]+valid|invalid|incorrect|expired|disabled|leaked|rejected|reported[_\\s-]+as[_\\s-]+leaked)\\b/i;\n\nconst TOKEN_REJECTED_FAILURE_PATTERN =\n\t/\\b(?:expired|revoked|invalidated)[_\\s-]+(?:(?:oauth|auth|access|refresh)[_\\s-]+)?token\\b|\\b(?:(?:oauth|auth|access|refresh)[_\\s-]+)?token[_\\s-]+(?:(?:is|was|has|been)[_\\s-]+){0,3}(?:expired|revoked|invalidated)\\b|\\bsecurity\\s+token\\s+(?:included\\s+in\\s+the\\s+request\\s+)?(?:is|has)\\s+(?:expired|invalid)\\b/i;\n\nfunction transportOutageKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\treturn TRANSPORT_OUTAGE_FAILURE_PATTERNS.some((pattern) => pattern.test(message.trim()))\n\t\t? \"transport_error\"\n\t\t: undefined;\n}\n\nfunction refusalKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\tif (TRANSPORT_CANCELLATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"network_timeout\";\n\tif (CANCELLED_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"cancelled\";\n\tif (NON_RETRYABLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\t// A refused tool call is about that call, whatever policy the provider names: another model is asked the same\n\t// tool call. So it is checked before the content-filter grammar, which \"refused ... safety policy\" also matches.\n\tif (TOOL_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"task_failure\";\n\tif (CONTENT_FILTER_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"content_filter\";\n\treturn undefined;\n}\n\n// A status that leads an adapter's error message: `503: …`, `529 {…}`, or `OpenAI API error (503): …`.\nconst LEADING_HTTP_STATUS_PATTERN = /^(?:[^\\n():]*\\((\\d{3})\\):|(\\d{3})(?=[:\\s]))/;\n// The status in a JSON error body, as Google's `{\"error\":{\"code\":503,…,\"status\":\"UNAVAILABLE\"}}`.\nconst JSON_ERROR_CODE_PATTERN = /\"code\"\\s*:\\s*(\\d{3})(?!\\d)/;\nconst JSON_PROVIDER_STATUS_PATTERN = /\"status\"\\s*:\\s*\"([A-Z_]+)\"/;\n\n/**\n * The transient kind the provider's own error text names, so no text rule condemns the model over it: an HTTP status\n * leading the message or in its JSON error body, a provider status such as `UNAVAILABLE`, or an overloaded service. A\n * permanent HTTP status in the text names no transient kind (#4994).\n */\nfunction transientKindFromMessage(message: string): ModelFallbackFailureKind | undefined {\n\tconst leadingStatus = LEADING_HTTP_STATUS_PATTERN.exec(message);\n\tconst status = integerFrom(leadingStatus?.[1] ?? leadingStatus?.[2] ?? JSON_ERROR_CODE_PATTERN.exec(message)?.[1]);\n\tconst kind =\n\t\tstatus === undefined\n\t\t\t? (kindFromCode(JSON_PROVIDER_STATUS_PATTERN.exec(message)?.[1]) ??\n\t\t\t\t(/overloaded/i.test(message) ? \"provider_unavailable\" : undefined))\n\t\t\t: kindFromStatus(status);\n\treturn kind !== undefined && SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(kind) ? kind : undefined;\n}\n\nfunction fallbackKindFromMessage(message: string, name: string | undefined): ModelFallbackFailureKind | undefined {\n\tconst refusalKind = refusalKindFromMessage(message);\n\tif (refusalKind !== undefined) return refusalKind;\n\tconst transportOutageKind = transportOutageKindFromMessage(message);\n\tif (transportOutageKind !== undefined) return transportOutageKind;\n\tif (BILLING_EXHAUSTED_FAILURE_PATTERN.test(message)) return \"quota_exhausted\";\n\tif (\n\t\tAPI_KEY_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tTOKEN_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tCREDENTIAL_REJECTION_CODE_PATTERN.test(message)\n\t)\n\t\treturn \"auth_on_candidate_provider\";\n\tif (REQUEST_INCOMPATIBLE_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) return \"request_incompatible\";\n\tconst nameKind = kindFromCode(name);\n\tif (nameKind !== undefined) return nameKind;\n\tif (QUOTA_EXHAUSTED_FAILURE_PATTERN.test(message)) return \"quota_exhausted\";\n\tconst transientKind = transientKindFromMessage(message);\n\tconst hasRetryablePattern =\n\t\ttransientKind !== undefined ||\n\t\tRETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(message)) ||\n\t\tmessageLooksLikeModelUnavailable(message);\n\tif (!hasRetryablePattern) return undefined;\n\tif (\n\t\t/rate\\s*limit|too\\s*many\\s*requests|\\bthrottl(?:ing|ed)\\b|\\b429\\b|quota|usage[\\s_-]*limit|billing|credit/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"rate_limit\";\n\t// Text that would condemn the model does not decide over a transient failure the provider names (#4994).\n\tif (\n\t\ttransientKind === undefined &&\n\t\t/auth|unauthori[sz]ed|\\b40[13]\\b|api[_\\s-]*key|token[_\\s-]*(?:expired|revoked|invalidated|rejected)|forbidden|invalid[_\\s-]*key/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"auth_on_candidate_provider\";\n\tif (transientKind === undefined && messageLooksLikeModelUnavailable(message)) return \"model_unavailable\";\n\tif (\n\t\t/network|fetch|socket|connection\\s*refused|(?<![a-z0-9_])(?:ECONNRESET|ECONNABORTED|ECONNREFUSED|ETIMEDOUT|EPIPE)(?![a-z0-9_])|getaddrinfo|ENOTFOUND|EAI_AGAIN|timeout|timed\\s+out/i.test(\n\t\t\tmessage,\n\t\t)\n\t)\n\t\treturn \"network_timeout\";\n\treturn transientKind ?? \"provider_unavailable\";\n}\n\nfunction signalSource(value: unknown, fallback: ModelFallbackFailureSource | undefined): ModelFallbackFailureSource {\n\tif (fallback !== undefined) return fallback;\n\tif (stopReasonFrom(value) !== undefined || diagnosticErrors(value).length > 0) return \"assistant_message\";\n\tif (value instanceof Error) return \"throw\";\n\treturn \"structured\";\n}\n\nfunction makeSignal(\n\tkind: ModelFallbackFailureKind,\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal {\n\tconst status = statusFrom(value);\n\tconst code = codeFrom(value);\n\tconst name = errorName(value);\n\tconst stopReason = stopReasonFrom(value);\n\treturn {\n\t\tkind,\n\t\tmessage: errorMessage(value),\n\t\tsource: signalSource(value, source),\n\t\t...(stopReason !== undefined ? { stopReason } : {}),\n\t\t...(status !== undefined ? { status } : {}),\n\t\t...(code !== undefined ? { code } : {}),\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\nfunction fallbackSignalFromDirectMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tif (normalizeCode(codeFrom(value)) === \"econnaborted\") return undefined;\n\tconst message = directMessageFrom(value);\n\tif (message === undefined) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\nfunction fallbackSignalFromMessage(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst message = classifiableMessage(value);\n\tif (message === undefined) return undefined;\n\tconst kind = fallbackKindFromMessage(message, errorName(value));\n\treturn kind === undefined ? undefined : makeSignal(kind, value, source);\n}\n\n/** Kinds that condemn the model for the turn: message text alone must not assign one over a transient status. */\nconst MODEL_BLOCKING_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"auth_on_candidate_provider\",\n\t\"model_unavailable\",\n\t\"request_incompatible\",\n]);\n\n/**\n * The direct message's signal, unless the failure's own HTTP status or provider code names a transient failure and\n * the text would condemn the model instead. Structured fields decide first; text is the fallback (#4918).\n */\nfunction directMessageSignalUnlessTransient(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tconst signal = fallbackSignalFromDirectMessage(value, source);\n\tif (signal === undefined || !MODEL_BLOCKING_FAILURE_KINDS.has(signal.kind)) return signal;\n\t// An adapter's `provider_response_failure` diagnostic carries the HTTP status of the failed request (#4994).\n\tconst rawDiagnostics = field(value, \"diagnostics\");\n\tconst structuredKinds = [value, ...(Array.isArray(rawDiagnostics) ? rawDiagnostics : [])].flatMap((source) => [\n\t\tkindFromStatus(statusFrom(source)),\n\t\tkindFromCode(codeFrom(source)),\n\t]);\n\treturn structuredKinds.some((kind) => kind !== undefined && SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(kind))\n\t\t? undefined\n\t\t: signal;\n}\n\nfunction classifyAssistantRefusalSignal(\n\tvalue: unknown,\n\tsource: ModelFallbackFailureSource | undefined,\n): ModelFallbackFailureSignal | undefined {\n\tif (normalizeCode(codeFrom(value)) === \"econnaborted\") return undefined;\n\tconst codeRefusalKind =\n\t\trefusalKindFromCode(codeFrom(value)) ??\n\t\trefusalKindFromCode(errorName(value)) ??\n\t\trefusalKindFromCode(finishReasonFrom(value));\n\tif (codeRefusalKind !== undefined) return makeSignal(codeRefusalKind, value, source);\n\n\tconst messageRefusalKind = refusalKindFromMessage(directMessageFrom(value) ?? \"\");\n\treturn messageRefusalKind === undefined ? undefined : makeSignal(messageRefusalKind, value, source);\n}\n\nfunction isRefusalSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn signal.kind === \"cancelled\" || signal.kind === \"task_failure\" || signal.kind === \"content_filter\";\n}\n\nfunction nestedSignalPriority(signal: ModelFallbackFailureSignal): number {\n\tswitch (signal.kind) {\n\t\tcase \"cancelled\":\n\t\tcase \"task_failure\":\n\t\tcase \"content_filter\":\n\t\t\treturn 100;\n\t\tcase \"auth_on_candidate_provider\":\n\t\tcase \"certificate_refused\":\n\t\t\treturn 90;\n\t\tcase \"request_incompatible\":\n\t\t\treturn 85;\n\t\tcase \"model_unavailable\":\n\t\t\treturn 80;\n\t\tcase \"quota_exhausted\":\n\t\t\treturn 75;\n\t\tcase \"rate_limit\":\n\t\t\treturn 70;\n\t\tcase \"provider_unavailable\":\n\t\t\treturn 60;\n\t\tcase \"network_timeout\":\n\t\t\treturn 50;\n\t\tcase \"transport_error\":\n\t\t\treturn 82;\n\t\tcase \"unknown\":\n\t\t\treturn 0;\n\t}\n}\nfunction structuredSignal(\n\tvalue: unknown,\n\tseen: Set<unknown>,\n\tsource?: ModelFallbackFailureSource,\n): ModelFallbackFailureSignal | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"object\") seen.add(value);\n\n\tconst stopReason = stopReasonFrom(value)?.toLowerCase();\n\tconst diagnosticType = stringField(value, \"type\");\n\tconst providerTransportSignal =\n\t\tdiagnosticType !== undefined && normalizeCode(diagnosticType) === \"provider_transport_failure\"\n\t\t\t? makeSignal(\"transport_error\", value, source)\n\t\t\t: undefined;\n\tif (stopReason === \"aborted\") return makeSignal(\"cancelled\", value, source);\n\n\t// Defer direct refusal/cancellation signals until nested diagnostics and\n\t// causes have been inspected. A transport wrapper can carry a cancellation\n\t// or provider refusal that must win over the wrapper's transport label.\n\tconst directRefusalSignal = classifyAssistantRefusalSignal(value, source);\n\tconst codeKind = kindFromCode(codeFrom(value));\n\tconst nameKind = kindFromCode(errorName(value));\n\tconst directCancellationSignal =\n\t\tcodeKind === \"cancelled\" || nameKind === \"cancelled\" ? makeSignal(\"cancelled\", value, source) : undefined;\n\n\tlet bestNestedFallbackSignal: ModelFallbackFailureSignal | undefined;\n\tconst nestedSeen = new Set(seen);\n\tconst nestedValues: readonly { value: unknown; source?: ModelFallbackFailureSource }[] = [\n\t\t...diagnosticErrors(value).map((diagnosticError) => ({ value: diagnosticError, source: \"diagnostic\" as const })),\n\t\t...(field(value, \"error\") === undefined ? [] : [{ value: field(value, \"error\"), source }]),\n\t];\n\tfor (const nested of nestedValues) {\n\t\tconst nestedSignal =\n\t\t\tstructuredSignal(nested.value, nestedSeen, nested.source) ??\n\t\t\tfallbackSignalFromMessage(nested.value, nested.source);\n\t\tif (nestedSignal === undefined) continue;\n\t\tif (isRefusalSignal(nestedSignal)) return nestedSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(nestedSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = nestedSignal;\n\t\t}\n\t}\n\tconst cause = causeOf(value);\n\tconst causeSignal = structuredSignal(cause, nestedSeen, source) ?? fallbackSignalFromMessage(cause, source);\n\tif (causeSignal !== undefined) {\n\t\tif (isRefusalSignal(causeSignal)) return causeSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(causeSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = causeSignal;\n\t\t}\n\t}\n\n\t// This code names the exact cause, so the generic 400 status and its request-error text must not outrank it.\n\tif (\n\t\tdirectRefusalSignal === undefined &&\n\t\tdirectCancellationSignal === undefined &&\n\t\tnormalizeCode(codeFrom(value)) === \"model_not_available_for_integrator\"\n\t)\n\t\treturn makeSignal(\"model_unavailable\", value, source);\n\n\tconst directMessageSignal = directMessageSignalUnlessTransient(value, source);\n\t// An exhausted quota the failure names outranks a generic request error: Anthropic answers an account out of\n\t// credit with HTTP 400 and `invalid_request_error`.\n\tconst quotaExhausted =\n\t\tdirectMessageSignal?.kind === \"quota_exhausted\" || bestNestedFallbackSignal?.kind === \"quota_exhausted\";\n\tconst directSignals = [\n\t\tdirectRefusalSignal,\n\t\tdirectCancellationSignal,\n\t\tproviderTransportSignal,\n\t\tdirectMessageSignal,\n\t\t// A provider error code names the cause more exactly than its HTTP status: Bedrock answers a service-quota\n\t\t// exception with a generic 400.\n\t\tkindFromStatus(statusFrom(value)) === undefined || kindFromCode(codeFrom(value)) !== undefined || quotaExhausted\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromStatus(statusFrom(value))!, value, source),\n\t\tkindFromCode(codeFrom(value)) === undefined ||\n\t\t(quotaExhausted && kindFromCode(codeFrom(value)) === \"request_incompatible\")\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(codeFrom(value))!, value, source),\n\t\tkindFromCode(errorName(value)) === undefined\n\t\t\t? undefined\n\t\t\t: makeSignal(kindFromCode(errorName(value))!, value, source),\n\t].filter((signal): signal is ModelFallbackFailureSignal => signal !== undefined);\n\tfor (const directSignal of directSignals) {\n\t\tif (isRefusalSignal(directSignal)) return directSignal;\n\t\tif (\n\t\t\tbestNestedFallbackSignal === undefined ||\n\t\t\tnestedSignalPriority(directSignal) > nestedSignalPriority(bestNestedFallbackSignal)\n\t\t) {\n\t\t\tbestNestedFallbackSignal = directSignal;\n\t\t}\n\t}\n\n\tif (bestNestedFallbackSignal !== undefined) return bestNestedFallbackSignal;\n\tif (stopReason === \"error\") return makeSignal(\"provider_unavailable\", value, source);\n\treturn undefined;\n}\n\n/**\n * A message to describe the failure. With `describeStatusAndCode`, a failure with only a status or code gets a\n * generated sentence naming it; text classification never reads that sentence, because its words are ours, not the\n * provider's: \"Model request failed with code ServiceUnavailableException\" reads as an unavailable model (#4918).\n */\nfunction messageFromUnknown(value: unknown, seen: Set<unknown>, describeStatusAndCode = true): string | undefined {\n\tif (value === undefined || value === null || seen.has(value)) return undefined;\n\tif (typeof value === \"string\") return value.trim().length > 0 ? value : undefined;\n\tif (typeof value === \"number\" || typeof value === \"boolean\" || typeof value === \"bigint\") return String(value);\n\tif (typeof value === \"symbol\" || typeof value === \"function\") return undefined;\n\tseen.add(value);\n\n\tif (value instanceof Error && value.message.trim().length > 0) return value.message;\n\tconst directMessage = directMessageFrom(value);\n\tif (directMessage !== undefined) return directMessage;\n\tfor (const diagnosticError of diagnosticErrors(value)) {\n\t\tconst diagnosticMessage = messageFromUnknown(diagnosticError, seen, describeStatusAndCode);\n\t\tif (diagnosticMessage !== undefined) return diagnosticMessage;\n\t}\n\tconst causeMessage = messageFromUnknown(causeOf(value), seen, describeStatusAndCode);\n\tif (causeMessage !== undefined) return causeMessage;\n\tconst finishReason = finishReasonFrom(value);\n\tif (finishReason !== undefined) return `Model request finished with finish_reason:${finishReason}`;\n\tconst stopReason = stopReasonFrom(value);\n\tif (stopReason !== undefined) return `Assistant message ended with stopReason:${stopReason}`;\n\tif (!describeStatusAndCode) return undefined;\n\tconst status = statusFrom(value);\n\tif (status !== undefined) return `Model request failed with status ${status}`;\n\tconst code = codeFrom(value);\n\tif (code !== undefined) return `Model request failed with code ${String(code)}`;\n\treturn undefined;\n}\n\nexport function errorMessage(error: unknown): string {\n\tconst structuredMessage = messageFromUnknown(error, new Set());\n\tif (structuredMessage !== undefined) return structuredMessage;\n\tconst rendered = String(error);\n\treturn rendered === \"[object Object]\" ? \"Model request failed\" : rendered;\n}\n\n/** The failure's own text, for text classification: never a sentence generated from its status or code. */\nfunction classifiableMessage(error: unknown): string | undefined {\n\treturn messageFromUnknown(error, new Set(), false);\n}\n\n/** Alias used by the subagent package's older public helper name. */\nexport const modelFailureMessage = errorMessage;\n\n/** The fallback decision each typed GitHub Copilot failure stands for. */\nconst GITHUB_COPILOT_FAILURE_KINDS: Readonly<Record<GitHubCopilotErrorCode, ModelFallbackFailureKind>> = {\n\t\"model-unavailable\": \"model_unavailable\",\n\t\"rate-limited\": \"rate_limit\",\n\t\"quota-exhausted\": \"quota_exhausted\",\n\t\"content-filtered\": \"content_filter\",\n\t\"prompt-too-large\": \"request_incompatible\",\n\t\"invalid-request\": \"request_incompatible\",\n\t\"authentication-failed\": \"auth_on_candidate_provider\",\n\t\"service-unavailable\": \"provider_unavailable\",\n\t\"stream-ended-early\": \"transport_error\",\n\t\"empty-response\": \"transport_error\",\n\t\"unrecognized-response\": \"provider_unavailable\",\n};\n\n/**\n * A GitHub Copilot failure is typed at the provider: its code decides, never its text. The typed error is found on\n * the failure, anywhere in its cause chain, or in the diagnostics of a failed assistant message in that chain, as\n * when a caller wraps the message.\n */\nfunction githubCopilotSignal(error: unknown): ModelFallbackFailureSignal | undefined {\n\tconst copilotError: GitHubCopilotError | undefined = findGitHubCopilotError(error);\n\tif (copilotError === undefined) return undefined;\n\treturn makeSignal(GITHUB_COPILOT_FAILURE_KINDS[copilotError.code], copilotError, signalSource(error, undefined));\n}\n\n/**\n * A request the runtime refused for its endpoint's TLS certificate (#6114): recorded by the adapter on a failed assistant\n * message, or along a thrown failure's causes. The same request is refused again, so it is never retried on the same\n * model; like a rejected credential, it may spend a fallback candidate, whose endpoint may be trusted.\n */\nfunction certificateRefusalSignal(error: unknown): ModelFallbackFailureSignal | undefined {\n\tconst refusal = getTlsCertificateRefusal(asRecord(error)) ?? findTlsCertificateRefusal(error);\n\tif (refusal === undefined) return undefined;\n\treturn { ...makeSignal(\"certificate_refused\", error, undefined), code: refusal.code };\n}\n\n/**\n * How long the attempt ran, in milliseconds, before its response stream ended early. It is read from the typed GitHub\n * Copilot failure, never from message text: on the error, anywhere in its cause chain, or in the diagnostics of a\n * failed assistant message. Undefined for any other failure, and for a stream-cut error that carries no duration.\n */\nexport function streamCutDurationMs(error: unknown): number | undefined {\n\tconst copilotError = findGitHubCopilotError(error);\n\treturn copilotError instanceof GitHubCopilotStreamEndedEarlyError ? copilotError.durationMs : undefined;\n}\n\nexport function normalizeModelFailureSignal(error: unknown): ModelFallbackFailureSignal {\n\t// Extension startup is not a model request. Its message names extension paths\n\t// and their own errors, which must not read as a provider failure.\n\tif (isExtensionStartupFailure(error)) {\n\t\tconst name = errorName(error);\n\t\treturn {\n\t\t\tkind: \"unknown\",\n\t\t\tmessage: errorMessage(error),\n\t\t\tsource: \"string_fallback\",\n\t\t\t...(name !== undefined ? { name } : {}),\n\t\t};\n\t}\n\tconst copilot = githubCopilotSignal(error);\n\tif (copilot !== undefined) return copilot;\n\tconst certificate = certificateRefusalSignal(error);\n\tif (certificate !== undefined) return certificate;\n\tconst structured = structuredSignal(error, new Set());\n\tif (structured !== undefined) return structured;\n\tconst message = errorMessage(error);\n\tconst name = errorName(error);\n\tconst textToClassify = classifiableMessage(error);\n\tconst fallbackKind = textToClassify === undefined ? undefined : fallbackKindFromMessage(textToClassify, name);\n\treturn {\n\t\tkind: fallbackKind ?? \"unknown\",\n\t\tmessage,\n\t\tsource: \"string_fallback\",\n\t\t...(name !== undefined ? { name } : {}),\n\t};\n}\n\nconst AUTHENTICATION_FAILURE_CODES: ReadonlySet<string> = new Set([\n\t\"auth_required\",\n\t\"authentication_required\",\n\t\"authentication_failed\",\n\t\"authentication_error\",\n\t\"unauthorized\",\n]);\n\nconst CREDENTIAL_REJECTION_CODES: ReadonlySet<string> = new Set([\n\t\"invalid_api_key\",\n\t\"api_key_invalid\",\n\t\"api_key_expired\",\n\t\"api_key_disabled\",\n\t\"api_key_leaked\",\n\t\"missing_api_key\",\n\t\"invalid_key\",\n\t\"token_expired\",\n\t\"token_revoked\",\n\t\"token_invalidated\",\n\t\"oauth_token_invalidated\",\n\t\"expired_token_exception\",\n\t\"expiredtokenexception\",\n\t\"unrecognized_client_exception\",\n\t\"unrecognizedclientexception\",\n\t\"invalid_signature_exception\",\n\t\"invalidsignatureexception\",\n\t\"consumer_suspended\",\n\t\"api_key_service_blocked\",\n\t\"api_key_http_referrer_blocked\",\n\t\"api_key_ip_address_blocked\",\n\t\"api_key_android_app_blocked\",\n\t\"api_key_ios_app_blocked\",\n]);\n\nconst CREDENTIAL_REJECTION_CODE_PATTERN = new RegExp(`\\\\b(?:${[...CREDENTIAL_REJECTION_CODES].join(\"|\")})\\\\b`, \"i\");\n\nexport function isProviderCredentialRejection(error: unknown): boolean {\n\tconst signal = normalizeModelFailureSignal(error);\n\tif (isRefusalSignal(signal)) return false;\n\tconst leadingStatus = LEADING_HTTP_STATUS_PATTERN.exec(signal.message);\n\tconst status =\n\t\tsignal.status ??\n\t\tintegerFrom(\n\t\t\tleadingStatus?.[1] ??\n\t\t\t\tleadingStatus?.[2] ??\n\t\t\t\t/^HTTP(?:\\/\\d(?:\\.\\d)?)?\\s+(\\d{3})\\b/i.exec(signal.message)?.[1] ??\n\t\t\t\tJSON_ERROR_CODE_PATTERN.exec(signal.message)?.[1],\n\t\t);\n\tif (status === 401 || integerFrom(signal.code) === 401) return true;\n\tif (signal.kind !== \"auth_on_candidate_provider\") return false;\n\tconst typedFailure = findGitHubCopilotError(error);\n\tconst providerCode = typedFailure?.providerCode ?? stringField(error, \"providerCode\");\n\tconst codes = providerCode === undefined ? [signal.code, signal.name] : [providerCode];\n\tif (\n\t\tcodes.some((value) => {\n\t\t\tconst code = normalizeCode(value);\n\t\t\treturn (\n\t\t\t\tcode !== undefined &&\n\t\t\t\t(CREDENTIAL_REJECTION_CODES.has(code) || (status !== 403 && AUTHENTICATION_FAILURE_CODES.has(code)))\n\t\t\t);\n\t\t})\n\t)\n\t\treturn true;\n\tconst message = `${signal.message}\\n${typedFailure?.detail ?? stringField(error, \"detail\") ?? \"\"}`;\n\treturn (\n\t\tAPI_KEY_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tTOKEN_REJECTED_FAILURE_PATTERN.test(message) ||\n\t\tCREDENTIAL_REJECTION_CODE_PATTERN.test(message)\n\t);\n}\n\n/** Whether a failure is a provider safety/refusal response: a content-filter refusal, or a refused tool call. */\nexport function isSafetyRefusalFailure(error: unknown): boolean {\n\tconst signal = normalizeModelFailureSignal(error);\n\tif (signal.kind === \"content_filter\") return true;\n\tif (signal.kind !== \"task_failure\") return false;\n\tconst text = `${signal.message}\\n${signal.code ?? \"\"}\\n${signal.name ?? \"\"}`;\n\treturn PROVIDER_REFUSAL_FAILURE_PATTERNS.some((pattern) => pattern.test(text));\n}\n\n/** Whether a provider's content filter refused the request, as OpenAI's HTTP 422 `cyber_policy` does. */\nexport function isContentFilterRefusal(error: unknown): boolean {\n\treturn normalizeModelFailureSignal(error).kind === \"content_filter\";\n}\n\n/**\n * True when this failure may spend a configured model fallback candidate. A content-filter refusal does unless\n * `options.fallbackOnContentFilter` is false.\n */\nexport function isRetryableModelFailure(error: unknown, options?: ModelFallbackFailureOptions): boolean {\n\tif (error === undefined) return false;\n\tconst kind = normalizeModelFailureSignal(error).kind;\n\tif (kind === \"content_filter\") return options?.fallbackOnContentFilter !== false;\n\treturn FALLBACKABLE_FAILURE_KINDS.has(kind);\n}\n\nconst SAME_MODEL_RETRYABLE_FAILURE_KINDS: ReadonlySet<ModelFallbackFailureKind> = new Set([\n\t\"rate_limit\",\n\t\"provider_unavailable\",\n\t\"network_timeout\",\n\t\"transport_error\",\n]);\n\n/**\n * An assistant error that only its `stopReason` marks as a model failure: no status, code or name, and text that no\n * pattern recognizes. It may spend a fallback candidate, but it is not retried on the same model on its own.\n */\nfunction isUnrecognizedSignal(signal: ModelFallbackFailureSignal): boolean {\n\treturn (\n\t\tsignal.kind === \"provider_unavailable\" &&\n\t\tsignal.source === \"assistant_message\" &&\n\t\tsignal.status === undefined &&\n\t\tsignal.code === undefined &&\n\t\tsignal.name === undefined &&\n\t\ttransientKindFromMessage(signal.message) === undefined &&\n\t\t!RETRYABLE_MODEL_FAILURE_PATTERNS.some((pattern) => pattern.test(signal.message))\n\t);\n}\n\n/** True when the same model may be requested again before fallback advances. */\nexport function isRetryableSameModelFailure(error: unknown): boolean {\n\tif (!isRetryableModelFailure(error)) return false;\n\tconst signal = normalizeModelFailureSignal(error);\n\treturn SAME_MODEL_RETRYABLE_FAILURE_KINDS.has(signal.kind) && !isUnrecognizedSignal(signal);\n}\n\n/**\n * True for a failure that may spend a fallback candidate although nothing recognizes it: an assistant error with no\n * status, code or name whose text matches no known pattern. A session with a fallback chain retries it on the same\n * model first, so such an error never switches models on its first occurrence (#4223).\n */\nexport function isUnrecognizedModelFailure(error: unknown): boolean {\n\treturn isRetryableModelFailure(error) && isUnrecognizedSignal(normalizeModelFailureSignal(error));\n}\n"]}
@@ -11,6 +11,13 @@
11
11
  export declare function processStartToken(pid: number): string | undefined;
12
12
  export declare function readProcessStartToken(pid: number): Promise<string | undefined>;
13
13
  export declare function processStartTokenAsync(pid: number): Promise<string | undefined>;
14
+ /**
15
+ * When Windows process `pid` was created, as the decimal count of 100-nanosecond intervals since 1601-01-01 UTC, read
16
+ * now: never an answer remembered from an earlier read, which may describe an earlier process given the same id (#6133).
17
+ * Read by the native module, or where that is not available by a bounded PowerShell query. Undefined where it cannot be
18
+ * read: on platforms other than Windows, once the process is gone, or when the query fails.
19
+ */
20
+ export declare function readProcessCreationTime(pid: number): Promise<string | undefined>;
14
21
  export declare function processStartTokenForSynchronousTakeover(pid: number): string | undefined;
15
22
  export declare function ownProcessStartToken(): string | undefined;
16
23
  type CreationTimeReader = (pid: number) => string | null;
@@ -1 +1 @@
1
- {"version":3,"file":"process-start-token.d.ts","sourceRoot":"","sources":["../../src/core/process-start-token.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOjE;AAED,wBAAsB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,C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BD,wBAAgB,oBAAoB,IAAI,MAAM,GAAG,SAAS,CAOzD;AAkBD,KAAK,kBAAkB,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;AA+BzD,KAAK,iBAAiB,GAAG;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,SAAS,MAAM,EAAE,CAAC;CAClD,CAAC;AAsHF,mHAAmH;AACnH,wBAAgB,sCAAsC,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAG1G;AAED,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,iBAAiB,GAAG,SAAS,GAAG,IAAI,CAGhG"}
@@ -36,6 +36,20 @@ export async function readProcessStartToken(pid) {
36
36
  export async function processStartTokenAsync(pid) {
37
37
  return readProcessStartToken(pid);
38
38
  }
39
+ /**
40
+ * When Windows process `pid` was created, as the decimal count of 100-nanosecond intervals since 1601-01-01 UTC, read
41
+ * now: never an answer remembered from an earlier read, which may describe an earlier process given the same id (#6133).
42
+ * Read by the native module, or where that is not available by a bounded PowerShell query. Undefined where it cannot be
43
+ * read: on platforms other than Windows, once the process is gone, or when the query fails.
44
+ */
45
+ export async function readProcessCreationTime(pid) {
46
+ if (process.platform !== "win32")
47
+ return undefined;
48
+ const native = nativeCreationTime();
49
+ if (native !== null)
50
+ return nativeCreation(native, pid);
51
+ return (await queryCreationTime(pid)).created;
52
+ }
39
53
  export function processStartTokenForSynchronousTakeover(pid) {
40
54
  if (process.platform !== "win32")
41
55
  return procStartToken(pid);
@@ -1 +1 @@
1
- {"version":3,"file":"process-start-token.js","sourceRoot":"","sources":["../../src/core/process-start-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;A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createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { createModuleRequire } from \"../utils/module-require.js\";\nimport { windowsPowerShellEnvironment } from \"../utils/windows-powershell.ts\";\n\n/**\n * When process `pid` of this host started, as `sha12` of a start that no later process given the same id shares, so a\n * holder named by its pid is told apart from that later process (#4990, #5141); undefined where that cannot be read:\n * on platforms other than Linux and Windows, or once the process is gone.\n *\n * On Linux it is the boot and the process's start time since boot, from `/proc`. On Windows it is the process's\n * creation time, read by the native module. Where that is not available it is read by a bounded PowerShell query that\n * never blocks the main thread (#5315): this answers with what such a query already read, and otherwise starts one and\n * answers undefined; {@link readProcessStartToken} waits for it.\n */\nexport function processStartToken(pid: number): string | undefined {\n\tif (process.platform !== \"win32\") return procStartToken(pid);\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, pid));\n\tconst known = knownFallbackCreation(pid);\n\tif (known === undefined) void readFallbackCreation(pid);\n\treturn windowsStartToken(known?.created);\n}\n\nexport async function readProcessStartToken(pid: number): Promise<string | undefined> {\n\tif (process.platform !== \"win32\") return procStartTokenAsync(pid);\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, pid));\n\treturn windowsStartToken(await readFallbackCreation(pid));\n}\n\nexport async function processStartTokenAsync(pid: number): Promise<string | undefined> {\n\treturn readProcessStartToken(pid);\n}\n\nexport function processStartTokenForSynchronousTakeover(pid: number): string | undefined {\n\tif (process.platform !== \"win32\") return procStartToken(pid);\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, pid));\n\tconst known = knownFallbackCreation(pid);\n\tif (known !== undefined) return windowsStartToken(known.created);\n\tlet answer: FallbackAnswer;\n\ttry {\n\t\tconst output = execFileSync(fallbackQuery.file, fallbackQuery.args(pid), {\n\t\t\tcwd: process.env.SystemRoot || process.env.windir || \"C:\\\\Windows\",\n\t\t\tencoding: \"utf8\",\n\t\t\tenv: windowsPowerShellEnvironment(),\n\t\t\twindowsHide: true,\n\t\t\ttimeout: FALLBACK_TIMEOUT_MS,\n\t\t\tkillSignal: \"SIGKILL\",\n\t\t\tmaxBuffer: 1024,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"ignore\"],\n\t\t}).trim();\n\t\tanswer = { created: CREATION_TIME.test(output) ? output : undefined, unstartable: false };\n\t} catch (error) {\n\t\tanswer = { created: undefined, unstartable: (error as NodeJS.ErrnoException).code === \"ENOENT\" };\n\t}\n\trememberFallbackCreation(pid, answer);\n\treturn windowsStartToken(answer.created);\n}\n\nfunction procStartToken(pid: number): string | undefined {\n\ttry {\n\t\treturn linuxStartToken(readFileSync(`/proc/${pid}/stat`, \"utf8\"), readFileSync(BOOT_ID, \"utf8\"));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function procStartTokenAsync(pid: number): Promise<string | undefined> {\n\ttry {\n\t\treturn linuxStartToken(await readFile(`/proc/${pid}/stat`, \"utf8\"), await readFile(BOOT_ID, \"utf8\"));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nconst BOOT_ID = \"/proc/sys/kernel/random/boot_id\";\nconst OWN_PROC_START = process.platform === \"win32\" ? undefined : procStartToken(process.pid);\n\nexport function ownProcessStartToken(): string | undefined {\n\tif (process.platform !== \"win32\") return OWN_PROC_START;\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, process.pid));\n\tconst known = knownFallbackCreation(process.pid);\n\tif (known === undefined) void readFallbackCreation(process.pid);\n\treturn windowsStartToken(known?.created);\n}\n\nfunction linuxStartToken(stat: string, bootId: string): string | undefined {\n\t// Fields after the command name, which may hold spaces and parentheses: the start time is the 22nd field.\n\tconst started = stat.slice(stat.lastIndexOf(\")\") + 2).split(\" \")[19];\n\tconst boot = bootId.trim();\n\tif (started === undefined || !/^\\d+$/.test(started) || boot === \"\") return undefined;\n\treturn sha12(`${boot}\\n${started}`);\n}\n\nfunction windowsStartToken(created: string | undefined): string | undefined {\n\treturn created === undefined ? undefined : sha12(`windows\\n${created}`);\n}\n\nfunction sha12(text: string): string {\n\treturn createHash(\"sha256\").update(text).digest(\"hex\").slice(0, 12);\n}\n\ntype CreationTimeReader = (pid: number) => string | null;\n\nlet nativeReader: CreationTimeReader | null | undefined;\n\n/** The native module's `processCreationTime`, or null where the module or that binding (added in #5141) is missing. */\nfunction nativeCreationTime(): CreationTimeReader | null {\n\tif (nativeReader === undefined) {\n\t\ttry {\n\t\t\tconst binding = createModuleRequire(import.meta.url)(\"@bastani/atomic-natives\") as {\n\t\t\t\tprocessCreationTime?: CreationTimeReader;\n\t\t\t};\n\t\t\tnativeReader = binding.processCreationTime ?? null;\n\t\t} catch {\n\t\t\tnativeReader = null;\n\t\t}\n\t}\n\treturn nativeReader;\n}\n\nconst CREATION_TIME = /^[1-9]\\d*$/;\n\n/** Process `pid`'s creation time in 100-nanosecond intervals since 1601 UTC, as the native module reads it. */\nfunction nativeCreation(native: CreationTimeReader, pid: number): string | undefined {\n\ttry {\n\t\tconst created = native(pid);\n\t\treturn created !== null && CREATION_TIME.test(created) ? created : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype CreationTimeQuery = {\n\treadonly file: string;\n\treadonly args: (pid: number) => readonly string[];\n};\n\nconst POWERSHELL_QUERY: CreationTimeQuery = {\n\tfile: \"powershell.exe\",\n\targs: (pid) => [\n\t\t\"-NoProfile\",\n\t\t\"-NonInteractive\",\n\t\t\"-Command\",\n\t\t`$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue; if ($p -and -not $p.HasExited) { $p.StartTime.ToFileTimeUtc() }`,\n\t],\n};\n\n/** How long the fallback's PowerShell query may take before the start is judged unreadable. */\nconst FALLBACK_TIMEOUT_MS = 5_000;\n/** How long a creation time the fallback read is reused: each read starts PowerShell. */\nconst FALLBACK_CACHE_MS = 5_000;\n\ninterface FallbackAnswer {\n\treadonly created: string | undefined;\n\treadonly unstartable: boolean;\n}\n\nconst UNREAD: FallbackAnswer = { created: undefined, unstartable: false };\n\nlet fallbackQuery = POWERSHELL_QUERY;\nlet fallbackGeneration = 0;\nlet fallbackBroken = false;\nlet ownCreation: string | undefined;\nconst fallbackReads = new Map<number, { readonly at: number; readonly created: string | undefined }>();\nconst pendingReads = new Map<number, { readonly reading: Promise<string | undefined>; superseded: boolean }>();\nconst runningQueries = new Set<ChildProcess>();\n\nfunction knownFallbackCreation(pid: number): { readonly created: string | undefined } | undefined {\n\tif (pid === process.pid && ownCreation !== undefined) return { created: ownCreation };\n\tif (fallbackBroken) return { created: undefined };\n\tconst cached = fallbackReads.get(pid);\n\treturn cached !== undefined && Date.now() - cached.at < FALLBACK_CACHE_MS ? cached : undefined;\n}\n\nfunction readFallbackCreation(pid: number): Promise<string | undefined> {\n\tconst known = knownFallbackCreation(pid);\n\tif (known !== undefined) return Promise.resolve(known.created);\n\tconst pending = pendingReads.get(pid);\n\tif (pending !== undefined) return pending.reading;\n\tconst generation = fallbackGeneration;\n\tconst current = {\n\t\tsuperseded: false,\n\t\treading: queryCreationTime(pid).then((answer) => {\n\t\t\tif (generation !== fallbackGeneration) return undefined;\n\t\t\tpendingReads.delete(pid);\n\t\t\tif (current.superseded) return knownFallbackCreation(pid)?.created;\n\t\t\trememberFallbackCreation(pid, answer);\n\t\t\treturn answer.created;\n\t\t}),\n\t};\n\tpendingReads.set(pid, current);\n\treturn current.reading;\n}\n\nfunction rememberFallbackCreation(pid: number, { created, unstartable }: FallbackAnswer): void {\n\tconst pending = pendingReads.get(pid);\n\tif (pending !== undefined) pending.superseded = true;\n\tfallbackBroken ||= unstartable;\n\tconst now = Date.now();\n\tfor (const [read, { at }] of fallbackReads) if (now - at >= FALLBACK_CACHE_MS) fallbackReads.delete(read);\n\tfallbackReads.set(pid, { at: now, created });\n\tif (pid === process.pid && created !== undefined) ownCreation = created;\n}\n\nfunction queryCreationTime(pid: number): Promise<FallbackAnswer> {\n\treturn new Promise((resolve) => {\n\t\tlet bound: ReturnType<typeof setTimeout> | undefined;\n\t\tconst answer = (value: FallbackAnswer) => {\n\t\t\tclearTimeout(bound);\n\t\t\tresolve(value);\n\t\t};\n\t\tlet child: ChildProcess;\n\t\ttry {\n\t\t\tchild = execFile(\n\t\t\t\tfallbackQuery.file,\n\t\t\t\tfallbackQuery.args(pid),\n\t\t\t\t{\n\t\t\t\t\tcwd: process.env.SystemRoot || process.env.windir || \"C:\\\\Windows\",\n\t\t\t\t\tencoding: \"utf8\",\n\t\t\t\t\tenv: windowsPowerShellEnvironment(),\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t\t(error, stdout) => {\n\t\t\t\t\trunningQueries.delete(child);\n\t\t\t\t\tconst output = stdout.trim();\n\t\t\t\t\tanswer({\n\t\t\t\t\t\tcreated: error === null && CREATION_TIME.test(output) ? output : undefined,\n\t\t\t\t\t\tunstartable: (error as NodeJS.ErrnoException | null)?.code === \"ENOENT\",\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\t\t} catch {\n\t\t\tanswer(UNREAD);\n\t\t\treturn;\n\t\t}\n\t\trunningQueries.add(child);\n\t\tbound = setTimeout(() => {\n\t\t\tchild.kill();\n\t\t\tanswer(UNREAD);\n\t\t}, FALLBACK_TIMEOUT_MS);\n\t});\n}\n\nfunction resetFallback(): void {\n\tfallbackGeneration++;\n\tfor (const child of runningQueries) child.kill();\n\trunningQueries.clear();\n\tpendingReads.clear();\n\tfallbackReads.clear();\n\tfallbackBroken = false;\n\townCreation = undefined;\n}\n\n/** Test seam: replaces the native reader (`null` forces the PowerShell fallback); `undefined` restores loading. */\nexport function setNativeProcessCreationTimeForTesting(reader: CreationTimeReader | null | undefined): void {\n\tnativeReader = reader;\n\tresetFallback();\n}\n\nexport function setProcessCreationTimeQueryForTesting(query: CreationTimeQuery | undefined): void {\n\tfallbackQuery = query ?? POWERSHELL_QUERY;\n\tresetFallback();\n}\n"]}
1
+ {"version":3,"file":"process-start-token.js","sourceRoot":"","sources":["../../src/core/process-start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I,EAAE,CAAC;IACjD,cAAc,CAAC,KAAK,EAAE,CAAC;IACvB,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,aAAa,CAAC,KAAK,EAAE,CAAC;IACtB,cAAc,GAAG,KAAK,CAAC;IACvB,WAAW,GAAG,SAAS,CAAC;AACzB,CAAC;AAED,mHAAmH;AACnH,MAAM,UAAU,sCAAsC,CAAC,MAA6C;IACnG,YAAY,GAAG,MAAM,CAAC;IACtB,aAAa,EAAE,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,qCAAqC,CAAC,KAAoC;IACzF,aAAa,GAAG,KAAK,IAAI,gBAAgB,CAAC;IAC1C,aAAa,EAAE,CAAC;AACjB,CAAC","sourcesContent":["import { type ChildProcess, execFile, execFileSync } from \"node:child_process\";\nimport { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { createModuleRequire } from \"../utils/module-require.js\";\nimport { windowsPowerShellEnvironment } from \"../utils/windows-powershell.ts\";\n\n/**\n * When process `pid` of this host started, as `sha12` of a start that no later process given the same id shares, so a\n * holder named by its pid is told apart from that later process (#4990, #5141); undefined where that cannot be read:\n * on platforms other than Linux and Windows, or once the process is gone.\n *\n * On Linux it is the boot and the process's start time since boot, from `/proc`. On Windows it is the process's\n * creation time, read by the native module. Where that is not available it is read by a bounded PowerShell query that\n * never blocks the main thread (#5315): this answers with what such a query already read, and otherwise starts one and\n * answers undefined; {@link readProcessStartToken} waits for it.\n */\nexport function processStartToken(pid: number): string | undefined {\n\tif (process.platform !== \"win32\") return procStartToken(pid);\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, pid));\n\tconst known = knownFallbackCreation(pid);\n\tif (known === undefined) void readFallbackCreation(pid);\n\treturn windowsStartToken(known?.created);\n}\n\nexport async function readProcessStartToken(pid: number): Promise<string | undefined> {\n\tif (process.platform !== \"win32\") return procStartTokenAsync(pid);\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, pid));\n\treturn windowsStartToken(await readFallbackCreation(pid));\n}\n\nexport async function processStartTokenAsync(pid: number): Promise<string | undefined> {\n\treturn readProcessStartToken(pid);\n}\n\n/**\n * When Windows process `pid` was created, as the decimal count of 100-nanosecond intervals since 1601-01-01 UTC, read\n * now: never an answer remembered from an earlier read, which may describe an earlier process given the same id (#6133).\n * Read by the native module, or where that is not available by a bounded PowerShell query. Undefined where it cannot be\n * read: on platforms other than Windows, once the process is gone, or when the query fails.\n */\nexport async function readProcessCreationTime(pid: number): Promise<string | undefined> {\n\tif (process.platform !== \"win32\") return undefined;\n\tconst native = nativeCreationTime();\n\tif (native !== null) return nativeCreation(native, pid);\n\treturn (await queryCreationTime(pid)).created;\n}\n\nexport function processStartTokenForSynchronousTakeover(pid: number): string | undefined {\n\tif (process.platform !== \"win32\") return procStartToken(pid);\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, pid));\n\tconst known = knownFallbackCreation(pid);\n\tif (known !== undefined) return windowsStartToken(known.created);\n\tlet answer: FallbackAnswer;\n\ttry {\n\t\tconst output = execFileSync(fallbackQuery.file, fallbackQuery.args(pid), {\n\t\t\tcwd: process.env.SystemRoot || process.env.windir || \"C:\\\\Windows\",\n\t\t\tencoding: \"utf8\",\n\t\t\tenv: windowsPowerShellEnvironment(),\n\t\t\twindowsHide: true,\n\t\t\ttimeout: FALLBACK_TIMEOUT_MS,\n\t\t\tkillSignal: \"SIGKILL\",\n\t\t\tmaxBuffer: 1024,\n\t\t\tstdio: [\"ignore\", \"pipe\", \"ignore\"],\n\t\t}).trim();\n\t\tanswer = { created: CREATION_TIME.test(output) ? output : undefined, unstartable: false };\n\t} catch (error) {\n\t\tanswer = { created: undefined, unstartable: (error as NodeJS.ErrnoException).code === \"ENOENT\" };\n\t}\n\trememberFallbackCreation(pid, answer);\n\treturn windowsStartToken(answer.created);\n}\n\nfunction procStartToken(pid: number): string | undefined {\n\ttry {\n\t\treturn linuxStartToken(readFileSync(`/proc/${pid}/stat`, \"utf8\"), readFileSync(BOOT_ID, \"utf8\"));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nasync function procStartTokenAsync(pid: number): Promise<string | undefined> {\n\ttry {\n\t\treturn linuxStartToken(await readFile(`/proc/${pid}/stat`, \"utf8\"), await readFile(BOOT_ID, \"utf8\"));\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nconst BOOT_ID = \"/proc/sys/kernel/random/boot_id\";\nconst OWN_PROC_START = process.platform === \"win32\" ? undefined : procStartToken(process.pid);\n\nexport function ownProcessStartToken(): string | undefined {\n\tif (process.platform !== \"win32\") return OWN_PROC_START;\n\tconst native = nativeCreationTime();\n\tif (native !== null) return windowsStartToken(nativeCreation(native, process.pid));\n\tconst known = knownFallbackCreation(process.pid);\n\tif (known === undefined) void readFallbackCreation(process.pid);\n\treturn windowsStartToken(known?.created);\n}\n\nfunction linuxStartToken(stat: string, bootId: string): string | undefined {\n\t// Fields after the command name, which may hold spaces and parentheses: the start time is the 22nd field.\n\tconst started = stat.slice(stat.lastIndexOf(\")\") + 2).split(\" \")[19];\n\tconst boot = bootId.trim();\n\tif (started === undefined || !/^\\d+$/.test(started) || boot === \"\") return undefined;\n\treturn sha12(`${boot}\\n${started}`);\n}\n\nfunction windowsStartToken(created: string | undefined): string | undefined {\n\treturn created === undefined ? undefined : sha12(`windows\\n${created}`);\n}\n\nfunction sha12(text: string): string {\n\treturn createHash(\"sha256\").update(text).digest(\"hex\").slice(0, 12);\n}\n\ntype CreationTimeReader = (pid: number) => string | null;\n\nlet nativeReader: CreationTimeReader | null | undefined;\n\n/** The native module's `processCreationTime`, or null where the module or that binding (added in #5141) is missing. */\nfunction nativeCreationTime(): CreationTimeReader | null {\n\tif (nativeReader === undefined) {\n\t\ttry {\n\t\t\tconst binding = createModuleRequire(import.meta.url)(\"@bastani/atomic-natives\") as {\n\t\t\t\tprocessCreationTime?: CreationTimeReader;\n\t\t\t};\n\t\t\tnativeReader = binding.processCreationTime ?? null;\n\t\t} catch {\n\t\t\tnativeReader = null;\n\t\t}\n\t}\n\treturn nativeReader;\n}\n\nconst CREATION_TIME = /^[1-9]\\d*$/;\n\n/** Process `pid`'s creation time in 100-nanosecond intervals since 1601 UTC, as the native module reads it. */\nfunction nativeCreation(native: CreationTimeReader, pid: number): string | undefined {\n\ttry {\n\t\tconst created = native(pid);\n\t\treturn created !== null && CREATION_TIME.test(created) ? created : undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\ntype CreationTimeQuery = {\n\treadonly file: string;\n\treadonly args: (pid: number) => readonly string[];\n};\n\nconst POWERSHELL_QUERY: CreationTimeQuery = {\n\tfile: \"powershell.exe\",\n\targs: (pid) => [\n\t\t\"-NoProfile\",\n\t\t\"-NonInteractive\",\n\t\t\"-Command\",\n\t\t`$p = Get-Process -Id ${pid} -ErrorAction SilentlyContinue; if ($p -and -not $p.HasExited) { $p.StartTime.ToFileTimeUtc() }`,\n\t],\n};\n\n/** How long the fallback's PowerShell query may take before the start is judged unreadable. */\nconst FALLBACK_TIMEOUT_MS = 5_000;\n/** How long a creation time the fallback read is reused: each read starts PowerShell. */\nconst FALLBACK_CACHE_MS = 5_000;\n\ninterface FallbackAnswer {\n\treadonly created: string | undefined;\n\treadonly unstartable: boolean;\n}\n\nconst UNREAD: FallbackAnswer = { created: undefined, unstartable: false };\n\nlet fallbackQuery = POWERSHELL_QUERY;\nlet fallbackGeneration = 0;\nlet fallbackBroken = false;\nlet ownCreation: string | undefined;\nconst fallbackReads = new Map<number, { readonly at: number; readonly created: string | undefined }>();\nconst pendingReads = new Map<number, { readonly reading: Promise<string | undefined>; superseded: boolean }>();\nconst runningQueries = new Set<ChildProcess>();\n\nfunction knownFallbackCreation(pid: number): { readonly created: string | undefined } | undefined {\n\tif (pid === process.pid && ownCreation !== undefined) return { created: ownCreation };\n\tif (fallbackBroken) return { created: undefined };\n\tconst cached = fallbackReads.get(pid);\n\treturn cached !== undefined && Date.now() - cached.at < FALLBACK_CACHE_MS ? cached : undefined;\n}\n\nfunction readFallbackCreation(pid: number): Promise<string | undefined> {\n\tconst known = knownFallbackCreation(pid);\n\tif (known !== undefined) return Promise.resolve(known.created);\n\tconst pending = pendingReads.get(pid);\n\tif (pending !== undefined) return pending.reading;\n\tconst generation = fallbackGeneration;\n\tconst current = {\n\t\tsuperseded: false,\n\t\treading: queryCreationTime(pid).then((answer) => {\n\t\t\tif (generation !== fallbackGeneration) return undefined;\n\t\t\tpendingReads.delete(pid);\n\t\t\tif (current.superseded) return knownFallbackCreation(pid)?.created;\n\t\t\trememberFallbackCreation(pid, answer);\n\t\t\treturn answer.created;\n\t\t}),\n\t};\n\tpendingReads.set(pid, current);\n\treturn current.reading;\n}\n\nfunction rememberFallbackCreation(pid: number, { created, unstartable }: FallbackAnswer): void {\n\tconst pending = pendingReads.get(pid);\n\tif (pending !== undefined) pending.superseded = true;\n\tfallbackBroken ||= unstartable;\n\tconst now = Date.now();\n\tfor (const [read, { at }] of fallbackReads) if (now - at >= FALLBACK_CACHE_MS) fallbackReads.delete(read);\n\tfallbackReads.set(pid, { at: now, created });\n\tif (pid === process.pid && created !== undefined) ownCreation = created;\n}\n\nfunction queryCreationTime(pid: number): Promise<FallbackAnswer> {\n\treturn new Promise((resolve) => {\n\t\tlet bound: ReturnType<typeof setTimeout> | undefined;\n\t\tconst answer = (value: FallbackAnswer) => {\n\t\t\tclearTimeout(bound);\n\t\t\tresolve(value);\n\t\t};\n\t\tlet child: ChildProcess;\n\t\ttry {\n\t\t\tchild = execFile(\n\t\t\t\tfallbackQuery.file,\n\t\t\t\tfallbackQuery.args(pid),\n\t\t\t\t{\n\t\t\t\t\tcwd: process.env.SystemRoot || process.env.windir || \"C:\\\\Windows\",\n\t\t\t\t\tencoding: \"utf8\",\n\t\t\t\t\tenv: windowsPowerShellEnvironment(),\n\t\t\t\t\twindowsHide: true,\n\t\t\t\t},\n\t\t\t\t(error, stdout) => {\n\t\t\t\t\trunningQueries.delete(child);\n\t\t\t\t\tconst output = stdout.trim();\n\t\t\t\t\tanswer({\n\t\t\t\t\t\tcreated: error === null && CREATION_TIME.test(output) ? output : undefined,\n\t\t\t\t\t\tunstartable: (error as NodeJS.ErrnoException | null)?.code === \"ENOENT\",\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\t\t} catch {\n\t\t\tanswer(UNREAD);\n\t\t\treturn;\n\t\t}\n\t\trunningQueries.add(child);\n\t\tbound = setTimeout(() => {\n\t\t\tchild.kill();\n\t\t\tanswer(UNREAD);\n\t\t}, FALLBACK_TIMEOUT_MS);\n\t});\n}\n\nfunction resetFallback(): void {\n\tfallbackGeneration++;\n\tfor (const child of runningQueries) child.kill();\n\trunningQueries.clear();\n\tpendingReads.clear();\n\tfallbackReads.clear();\n\tfallbackBroken = false;\n\townCreation = undefined;\n}\n\n/** Test seam: replaces the native reader (`null` forces the PowerShell fallback); `undefined` restores loading. */\nexport function setNativeProcessCreationTimeForTesting(reader: CreationTimeReader | null | undefined): void {\n\tnativeReader = reader;\n\tresetFallback();\n}\n\nexport function setProcessCreationTimeQueryForTesting(query: CreationTimeQuery | undefined): void {\n\tfallbackQuery = query ?? POWERSHELL_QUERY;\n\tresetFallback();\n}\n"]}
@@ -0,0 +1,24 @@
1
+ /** The extension sources startup loads before it decides a project's trust, as configured for this run. */
2
+ export interface ProjectTrustElectorateInput {
3
+ /** The `-e` sources of this run. */
4
+ readonly cliExtensionPaths: readonly string[] | undefined;
5
+ /** Extension factories an SDK caller passed in addition to Atomic's own. */
6
+ readonly sdkExtensionFactoryCount: number;
7
+ /** Builtin package paths an SDK caller passed instead of Atomic's bundled packages. */
8
+ readonly customBuiltinPackagePaths: readonly string[] | undefined;
9
+ /** `--no-extensions`: settings, packages and the extensions folders load nothing. */
10
+ readonly noExtensions: boolean;
11
+ /** The global settings' `extensions` and `packages` entries. */
12
+ readonly globalExtensions: readonly unknown[] | undefined;
13
+ readonly globalPackages: readonly unknown[] | undefined;
14
+ /** The Atomic home whose `extensions` folder loads automatically. */
15
+ readonly agentDir: string;
16
+ }
17
+ /**
18
+ * Whether an extension that loads before a project's trust is decided could register a `project_trust` handler, read
19
+ * from the configuration alone, before any extension code runs. Atomic's own extensions and bundled packages register
20
+ * none. Any other source counts, whether or not it registers a handler: only running it would tell, and a handler
21
+ * answers ahead of a saved decision (#5693).
22
+ */
23
+ export declare function extensionsCanDecideProjectTrust(input: ProjectTrustElectorateInput): Promise<boolean>;
24
+ //# sourceMappingURL=project-trust-electorate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-trust-electorate.d.ts","sourceRoot":"","sources":["../../src/core/project-trust-electorate.ts"],"names":[],"mappings":"AAKA,2GAA2G;AAC3G,MAAM,WAAW,2BAA2B;IAC3C,oCAAoC;IACpC,QAAQ,CAAC,iBAAiB,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAC1D,4EAA4E;IAC5E,QAAQ,CAAC,wBAAwB,EAAE,MAAM,CAAC;IAC1C,uFAAuF;IACvF,QAAQ,CAAC,yBAAyB,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IAClE,qFAAqF;IACrF,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,gEAAgE;IAChE,QAAQ,CAAC,gBAAgB,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;IAC1D,QAAQ,CAAC,cAAc,EAAE,SAAS,OAAO,EAAE,GAAG,SAAS,CAAC;IACxD,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAqBD;;;;;GAKG;AACH,wBAAsB,+BAA+B,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,CAW1G"}
@@ -0,0 +1,52 @@
1
+ import { opendir } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { getAgentDir, getAgentDirs } from "../config.js";
4
+ import { isOverridePattern } from "./package-manager-resource-patterns.js";
5
+ /**
6
+ * Whether `dir` holds anything the extensions folder could load: a `.ts` or `.js` file, a `package.json` that can name
7
+ * extensions, or a folder or link the loader would look into. A folder that cannot be read counts as one.
8
+ */
9
+ async function hasExtensionCandidates(dir) {
10
+ try {
11
+ // Stops at the first candidate: a folder of many files is not listed in full.
12
+ for await (const entry of await opendir(dir)) {
13
+ if (entry.name.startsWith(".") || entry.name === "node_modules")
14
+ continue;
15
+ if (entry.isDirectory() || entry.isSymbolicLink() || !entry.isFile())
16
+ return true;
17
+ if (entry.name.endsWith(".ts") || entry.name.endsWith(".js") || entry.name === "package.json")
18
+ return true;
19
+ }
20
+ return false;
21
+ }
22
+ catch (error) {
23
+ const code = error.code;
24
+ return code !== "ENOENT" && code !== "ENOTDIR";
25
+ }
26
+ }
27
+ /**
28
+ * Whether an extension that loads before a project's trust is decided could register a `project_trust` handler, read
29
+ * from the configuration alone, before any extension code runs. Atomic's own extensions and bundled packages register
30
+ * none. Any other source counts, whether or not it registers a handler: only running it would tell, and a handler
31
+ * answers ahead of a saved decision (#5693).
32
+ */
33
+ export async function extensionsCanDecideProjectTrust(input) {
34
+ if ((input.cliExtensionPaths?.length ?? 0) > 0)
35
+ return true;
36
+ if (input.sdkExtensionFactoryCount > 0)
37
+ return true;
38
+ if ((input.customBuiltinPackagePaths?.length ?? 0) > 0)
39
+ return true;
40
+ if (input.noExtensions)
41
+ return false;
42
+ if ((input.globalPackages?.length ?? 0) > 0)
43
+ return true;
44
+ if ((input.globalExtensions ?? []).some((entry) => typeof entry !== "string" || !isOverridePattern(entry)))
45
+ return true;
46
+ const homes = input.agentDir === getAgentDir() ? getAgentDirs() : [input.agentDir];
47
+ for (const home of homes)
48
+ if (await hasExtensionCandidates(join(home, "extensions")))
49
+ return true;
50
+ return false;
51
+ }
52
+ //# sourceMappingURL=project-trust-electorate.js.map