@code-yeongyu/senpi 2026.7.29-6 → 2026.7.30-2

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 (252) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/README.md +3 -0
  3. package/dist/bun-global-launcher.d.ts +7 -0
  4. package/dist/bun-global-launcher.d.ts.map +1 -0
  5. package/dist/bun-global-launcher.js +21 -0
  6. package/dist/bun-global-launcher.js.map +1 -0
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/config.js +18 -6
  9. package/dist/config.js.map +1 -1
  10. package/dist/core/agent-session.d.ts +10 -0
  11. package/dist/core/agent-session.d.ts.map +1 -1
  12. package/dist/core/agent-session.js +62 -3
  13. package/dist/core/agent-session.js.map +1 -1
  14. package/dist/core/compaction/compaction.d.ts +1 -0
  15. package/dist/core/compaction/compaction.d.ts.map +1 -1
  16. package/dist/core/compaction/compaction.js +1 -0
  17. package/dist/core/compaction/compaction.js.map +1 -1
  18. package/dist/core/extensions/builtin/btw/index.d.ts.map +1 -1
  19. package/dist/core/extensions/builtin/btw/index.js +1 -0
  20. package/dist/core/extensions/builtin/btw/index.js.map +1 -1
  21. package/dist/core/extensions/builtin/claude-agent-sdk/auth-lane.d.ts.map +1 -1
  22. package/dist/core/extensions/builtin/claude-agent-sdk/auth-lane.js +10 -1
  23. package/dist/core/extensions/builtin/claude-agent-sdk/auth-lane.js.map +1 -1
  24. package/dist/core/extensions/builtin/claude-agent-sdk/errors.d.ts.map +1 -1
  25. package/dist/core/extensions/builtin/claude-agent-sdk/errors.js +14 -0
  26. package/dist/core/extensions/builtin/claude-agent-sdk/errors.js.map +1 -1
  27. package/dist/core/extensions/builtin/claude-agent-sdk/options.d.ts.map +1 -1
  28. package/dist/core/extensions/builtin/claude-agent-sdk/options.js +2 -1
  29. package/dist/core/extensions/builtin/claude-agent-sdk/options.js.map +1 -1
  30. package/dist/core/extensions/builtin/claude-agent-sdk/tools.d.ts +3 -0
  31. package/dist/core/extensions/builtin/claude-agent-sdk/tools.d.ts.map +1 -1
  32. package/dist/core/extensions/builtin/claude-agent-sdk/tools.js +19 -0
  33. package/dist/core/extensions/builtin/claude-agent-sdk/tools.js.map +1 -1
  34. package/dist/core/extensions/builtin/compaction/idle.d.ts +16 -0
  35. package/dist/core/extensions/builtin/compaction/idle.d.ts.map +1 -0
  36. package/dist/core/extensions/builtin/compaction/idle.js +21 -0
  37. package/dist/core/extensions/builtin/compaction/idle.js.map +1 -0
  38. package/dist/core/extensions/builtin/compaction/index.d.ts.map +1 -1
  39. package/dist/core/extensions/builtin/compaction/index.js +18 -1
  40. package/dist/core/extensions/builtin/compaction/index.js.map +1 -1
  41. package/dist/core/extensions/builtin/compaction/log.d.ts +1 -1
  42. package/dist/core/extensions/builtin/compaction/log.d.ts.map +1 -1
  43. package/dist/core/extensions/builtin/compaction/log.js.map +1 -1
  44. package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts +1 -2
  45. package/dist/core/extensions/builtin/config-reload/watch-engine.d.ts.map +1 -1
  46. package/dist/core/extensions/builtin/config-reload/watch-engine.js +1 -8
  47. package/dist/core/extensions/builtin/config-reload/watch-engine.js.map +1 -1
  48. package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts +15 -0
  49. package/dist/core/extensions/builtin/config-reload/watch-event-source.d.ts.map +1 -0
  50. package/dist/core/extensions/builtin/config-reload/watch-event-source.js +114 -0
  51. package/dist/core/extensions/builtin/config-reload/watch-event-source.js.map +1 -0
  52. package/dist/core/extensions/builtin/goal/continuation.d.ts +2 -0
  53. package/dist/core/extensions/builtin/goal/continuation.d.ts.map +1 -1
  54. package/dist/core/extensions/builtin/goal/continuation.js +12 -0
  55. package/dist/core/extensions/builtin/goal/continuation.js.map +1 -1
  56. package/dist/core/extensions/builtin/goal/index.d.ts.map +1 -1
  57. package/dist/core/extensions/builtin/goal/index.js +4 -1
  58. package/dist/core/extensions/builtin/goal/index.js.map +1 -1
  59. package/dist/core/extensions/builtin/goal/monitor-continuation.d.ts.map +1 -1
  60. package/dist/core/extensions/builtin/goal/monitor-continuation.js +22 -18
  61. package/dist/core/extensions/builtin/goal/monitor-continuation.js.map +1 -1
  62. package/dist/core/extensions/builtin/goal/prompt.d.ts.map +1 -1
  63. package/dist/core/extensions/builtin/goal/prompt.js +2 -1
  64. package/dist/core/extensions/builtin/goal/prompt.js.map +1 -1
  65. package/dist/core/extensions/builtin/goal/tool-registration.js +1 -1
  66. package/dist/core/extensions/builtin/goal/tool-registration.js.map +1 -1
  67. package/dist/core/extensions/builtin/gpt-apply-patch/apply.d.ts +1 -1
  68. package/dist/core/extensions/builtin/gpt-apply-patch/apply.d.ts.map +1 -1
  69. package/dist/core/extensions/builtin/gpt-apply-patch/apply.js +67 -66
  70. package/dist/core/extensions/builtin/gpt-apply-patch/apply.js.map +1 -1
  71. package/dist/core/extensions/builtin/gpt-apply-patch/recovery.d.ts +4 -0
  72. package/dist/core/extensions/builtin/gpt-apply-patch/recovery.d.ts.map +1 -0
  73. package/dist/core/extensions/builtin/gpt-apply-patch/recovery.js +35 -0
  74. package/dist/core/extensions/builtin/gpt-apply-patch/recovery.js.map +1 -0
  75. package/dist/core/extensions/builtin/gpt-apply-patch/tool.d.ts.map +1 -1
  76. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js +0 -5
  77. package/dist/core/extensions/builtin/gpt-apply-patch/tool.js.map +1 -1
  78. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts +2 -0
  79. package/dist/core/extensions/builtin/gpt-apply-patch/types.d.ts.map +1 -1
  80. package/dist/core/extensions/builtin/gpt-apply-patch/types.js.map +1 -1
  81. package/dist/core/extensions/builtin/rules/rules/project-root.d.ts.map +1 -1
  82. package/dist/core/extensions/builtin/rules/rules/project-root.js +8 -1
  83. package/dist/core/extensions/builtin/rules/rules/project-root.js.map +1 -1
  84. package/dist/core/extensions/builtin/service-tier.d.ts.map +1 -1
  85. package/dist/core/extensions/builtin/service-tier.js +20 -1
  86. package/dist/core/extensions/builtin/service-tier.js.map +1 -1
  87. package/dist/core/extensions/builtin/todotools/normalize.d.ts.map +1 -1
  88. package/dist/core/extensions/builtin/todotools/normalize.js +14 -3
  89. package/dist/core/extensions/builtin/todotools/normalize.js.map +1 -1
  90. package/dist/core/high-reasoning-warning.d.ts +10 -0
  91. package/dist/core/high-reasoning-warning.d.ts.map +1 -0
  92. package/dist/core/high-reasoning-warning.js +28 -0
  93. package/dist/core/high-reasoning-warning.js.map +1 -0
  94. package/dist/core/model-runtime.d.ts.map +1 -1
  95. package/dist/core/model-runtime.js +3 -11
  96. package/dist/core/model-runtime.js.map +1 -1
  97. package/dist/core/resolve-config-value.d.ts.map +1 -1
  98. package/dist/core/resolve-config-value.js +23 -1
  99. package/dist/core/resolve-config-value.js.map +1 -1
  100. package/dist/core/session-log.d.ts +12 -0
  101. package/dist/core/session-log.d.ts.map +1 -0
  102. package/dist/core/session-log.js +101 -0
  103. package/dist/core/session-log.js.map +1 -0
  104. package/dist/core/settings-manager.d.ts +2 -0
  105. package/dist/core/settings-manager.d.ts.map +1 -1
  106. package/dist/core/settings-manager.js +1 -0
  107. package/dist/core/settings-manager.js.map +1 -1
  108. package/dist/modes/interactive/compaction-queue-transfer.d.ts +6 -0
  109. package/dist/modes/interactive/compaction-queue-transfer.d.ts.map +1 -1
  110. package/dist/modes/interactive/compaction-queue-transfer.js +1 -1
  111. package/dist/modes/interactive/compaction-queue-transfer.js.map +1 -1
  112. package/dist/modes/interactive/interactive-mode.d.ts +10 -1
  113. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  114. package/dist/modes/interactive/interactive-mode.js +70 -7
  115. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  116. package/dist/modes/interactive/risky-main-model-warning.d.ts +5 -0
  117. package/dist/modes/interactive/risky-main-model-warning.d.ts.map +1 -0
  118. package/dist/modes/interactive/risky-main-model-warning.js +8 -0
  119. package/dist/modes/interactive/risky-main-model-warning.js.map +1 -0
  120. package/dist/modes/interactive/tips/catalog/subagent-tips.d.ts.map +1 -1
  121. package/dist/modes/interactive/tips/catalog/subagent-tips.js +30 -0
  122. package/dist/modes/interactive/tips/catalog/subagent-tips.js.map +1 -1
  123. package/dist/modes/rpc/rpc-types.d.ts +6 -0
  124. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  125. package/dist/modes/rpc/rpc-types.js.map +1 -1
  126. package/dist/utils/version-check.d.ts.map +1 -1
  127. package/dist/utils/version-check.js +22 -2
  128. package/dist/utils/version-check.js.map +1 -1
  129. package/docs/docs.json +4 -0
  130. package/docs/quickstart.md +3 -0
  131. package/docs/release-guide.md +636 -0
  132. package/node_modules/@code-yeongyu/senpi-codemode/CHANGELOG.md +24 -0
  133. package/node_modules/@code-yeongyu/senpi-codemode/package.json +3 -3
  134. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js +2 -2
  135. package/node_modules/@earendil-works/pi-agent-core/dist/agent-loop.js.map +1 -1
  136. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.d.ts +4 -0
  137. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.d.ts.map +1 -0
  138. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js +106 -0
  139. package/node_modules/@earendil-works/pi-agent-core/dist/empty-assistant-recovery.js.map +1 -0
  140. package/node_modules/@earendil-works/pi-agent-core/dist/stream-fn.d.ts +1 -0
  141. package/node_modules/@earendil-works/pi-agent-core/dist/stream-fn.d.ts.map +1 -1
  142. package/node_modules/@earendil-works/pi-agent-core/dist/stream-fn.js +1 -0
  143. package/node_modules/@earendil-works/pi-agent-core/dist/stream-fn.js.map +1 -1
  144. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  145. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts +1 -1
  146. package/node_modules/@earendil-works/pi-ai/dist/index.d.ts.map +1 -1
  147. package/node_modules/@earendil-works/pi-ai/dist/index.js +1 -1
  148. package/node_modules/@earendil-works/pi-ai/dist/index.js.map +1 -1
  149. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  150. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  151. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  152. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts +2 -1
  153. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.d.ts.map +1 -1
  154. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js +13 -0
  155. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/index.js.map +1 -1
  156. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/recovery-stream.js +2 -2
  157. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/recovery-stream.js.map +1 -1
  158. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.d.ts +3 -0
  159. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.d.ts.map +1 -0
  160. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.js +29 -0
  161. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery-stream.js.map +1 -0
  162. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.d.ts +3 -0
  163. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.d.ts.map +1 -0
  164. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.js +82 -0
  165. package/node_modules/@earendil-works/pi-ai/dist/tool-call-middleware/protocols/kimi-xtml/thinking-recovery.js.map +1 -0
  166. package/node_modules/@earendil-works/pi-ai/package.json +1 -1
  167. package/node_modules/@earendil-works/pi-pty/package.json +1 -1
  168. package/node_modules/@earendil-works/pi-tui/package.json +1 -1
  169. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/index.d.ts.map +1 -1
  170. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/index.js +1 -12
  171. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/index.js.map +1 -1
  172. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.d.ts +7 -0
  173. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.d.ts.map +1 -1
  174. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.js +9 -3
  175. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.js.map +1 -1
  176. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/streamableHttp.d.ts.map +1 -1
  177. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/streamableHttp.js +5 -3
  178. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/streamableHttp.js.map +1 -1
  179. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.d.ts.map +1 -1
  180. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.js +1 -12
  181. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.js.map +1 -1
  182. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.d.ts +5 -0
  183. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.d.ts.map +1 -0
  184. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.js +17 -0
  185. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.js.map +1 -0
  186. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.d.ts +9 -1
  187. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.d.ts.map +1 -1
  188. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.js +10 -4
  189. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.js.map +1 -1
  190. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.d.ts +21 -0
  191. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.d.ts.map +1 -1
  192. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.js +239 -41
  193. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.js.map +1 -1
  194. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/zod-compat.d.ts.map +1 -1
  195. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/zod-compat.js +25 -6
  196. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/zod-compat.js.map +1 -1
  197. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.d.ts +32 -0
  198. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.d.ts.map +1 -0
  199. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.js +64 -0
  200. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.js.map +1 -0
  201. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.d.ts +5 -0
  202. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.d.ts.map +1 -1
  203. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.js +10 -1
  204. package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.js.map +1 -1
  205. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.d.ts.map +1 -1
  206. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js +2 -13
  207. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js.map +1 -1
  208. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.d.ts +7 -0
  209. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.d.ts.map +1 -1
  210. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js +9 -3
  211. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js.map +1 -1
  212. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.d.ts.map +1 -1
  213. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js +5 -3
  214. package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js.map +1 -1
  215. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.d.ts.map +1 -1
  216. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +2 -13
  217. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js.map +1 -1
  218. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.d.ts +5 -0
  219. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.d.ts.map +1 -0
  220. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js +13 -0
  221. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js.map +1 -0
  222. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts +9 -1
  223. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts.map +1 -1
  224. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js +10 -4
  225. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js.map +1 -1
  226. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts +21 -0
  227. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts.map +1 -1
  228. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js +239 -41
  229. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js.map +1 -1
  230. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.d.ts.map +1 -1
  231. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +25 -6
  232. package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js.map +1 -1
  233. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.d.ts +32 -0
  234. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.d.ts.map +1 -0
  235. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js +57 -0
  236. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js.map +1 -0
  237. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.d.ts +5 -0
  238. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.d.ts.map +1 -1
  239. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js +9 -0
  240. package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js.map +1 -1
  241. package/node_modules/@modelcontextprotocol/sdk/package.json +4 -3
  242. package/node_modules/brace-expansion/README.md +12 -0
  243. package/node_modules/brace-expansion/dist/commonjs/index.d.ts +2 -0
  244. package/node_modules/brace-expansion/dist/commonjs/index.d.ts.map +1 -1
  245. package/node_modules/brace-expansion/dist/commonjs/index.js +138 -86
  246. package/node_modules/brace-expansion/dist/commonjs/index.js.map +1 -1
  247. package/node_modules/brace-expansion/dist/esm/index.d.ts +2 -0
  248. package/node_modules/brace-expansion/dist/esm/index.d.ts.map +1 -1
  249. package/node_modules/brace-expansion/dist/esm/index.js +137 -85
  250. package/node_modules/brace-expansion/dist/esm/index.js.map +1 -1
  251. package/node_modules/brace-expansion/package.json +2 -2
  252. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAiB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA6EF,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,aAAa,EAAE,SAAS,SAAS,EAAE,GACjC,iBAAiB,CAsGnB"}
1
+ {"version":3,"file":"normalize.d.ts","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/normalize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAiB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7E,MAAM,MAAM,iBAAiB,GAAG;IAC/B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AA6EF,wBAAgB,mBAAmB,CAClC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,aAAa,EAAE,SAAS,SAAS,EAAE,GACjC,iBAAiB,CAiHnB"}
@@ -72,11 +72,23 @@ export function normalizeTodoParams(raw, currentPhases) {
72
72
  const op = isOperation(rawOp) ? rawOp : undefined;
73
73
  const task = nonBlank(raw.task);
74
74
  const phase = nonBlank(raw.phase);
75
+ const corrections = [];
75
76
  if (op === "start" || op === "done" || op === "drop" || op === "rm") {
76
- if (isBlank(raw.task) && !phase) {
77
+ // GPT-5.x-style function calling serializes every schema property and pads
78
+ // omitted strings with "". When BOTH targets arrive blank on rm, the only
79
+ // documented no-target rm form is a bulk clear, so the padding is
80
+ // unambiguous — drop it instead of demanding a field omission the
81
+ // serializer cannot express. Single-blank targets and the destructive-bulk
82
+ // ops (start/done/drop) still error, so a truncated single target never
83
+ // widens into a bulk action.
84
+ if (op === "rm" && isBlank(raw.task) && isBlank(raw.phase)) {
85
+ corrections.push('[auto-corrected] "task" and "phase" were both blank; treated as a bulk clear. ' +
86
+ 'For a single target pass the exact text: {"op":"rm","task":"<exact task content>"}.');
87
+ }
88
+ else if (isBlank(raw.task) && !phase) {
77
89
  return error('Blank "task" — pass the exact task text, or omit the field entirely for a bulk operation.');
78
90
  }
79
- if (isBlank(raw.phase) && !task) {
91
+ else if (isBlank(raw.phase) && !task) {
80
92
  return error('Blank "phase" — pass the exact phase text, or omit the field entirely for a bulk operation.');
81
93
  }
82
94
  }
@@ -94,7 +106,6 @@ export function normalizeTodoParams(raw, currentPhases) {
94
106
  const alias = aliases[0];
95
107
  let effectiveItems = rawItems && rawItems.length > 0 ? rawItems : undefined;
96
108
  let candidate;
97
- const corrections = [];
98
109
  if (alias) {
99
110
  if (op && op !== alias.name)
100
111
  return error(CONFLICTING_SHAPES);
@@ -1 +1 @@
1
- {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/normalize.ts"],"names":[],"mappings":"AAUA,MAAM,kBAAkB,GACvB,gJAAgJ,CAAC;AAElJ,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAClC,QAAQ,KAAK,EAAE,CAAC;QACf,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,IAAI,CAAC;QACV,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM;YACV,OAAO,IAAI,CAAC;QACb;YACC,OAAO,KAAK,CAAC;IACf,CAAC;AACF,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC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E,EAAE,EAAE,WAAW,EAAE,CAAC;YAC/C,IAAI,IAAI;gBAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;YAC5B,IAAI,KAAK;gBAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;YAC/B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAC/B,CAAC;QACD,KAAK,QAAQ;YACZ,IAAI,IAAI,IAAI,OAAO;gBAAE,OAAO,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACtD,OAAO;gBACN,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;gBAC1G,WAAW;aACX,CAAC;QACH,KAAK,MAAM;YACV,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IACpD,CAAC;AACF,CAAC","sourcesContent":["import type { TodoOpEntry, TodoOperation, TodoPhase } from \"./todo-types.ts\";\n\nexport type TodoNormalization = {\n\tentry?: TodoOpEntry;\n\tcorrections: string[];\n\terror?: string;\n};\n\ntype Alias = \"init\" | \"append\";\n\nconst CONFLICTING_SHAPES =\n\t'conflicting shapes. Use {\"op\":\"init\",\"list\":[...]} to replace the list or {\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]} to add tasks.';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isOperation(value: unknown): value is TodoOperation {\n\tswitch (value) {\n\t\tcase \"init\":\n\t\tcase \"start\":\n\t\tcase \"done\":\n\t\tcase \"rm\":\n\t\tcase \"drop\":\n\t\tcase \"append\":\n\t\tcase \"view\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction strings(value: unknown): string[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst parsed: string[] = [];\n\tfor (const item of value) {\n\t\tif (typeof item !== \"string\") return undefined;\n\t\tparsed.push(item);\n\t}\n\treturn parsed;\n}\n\nfunction list(value: unknown): TodoOpEntry[\"list\"] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst parsed: NonNullable<TodoOpEntry[\"list\"]> = [];\n\tfor (const item of value) {\n\t\tif (!isRecord(item) || typeof item.phase !== \"string\") return undefined;\n\t\tconst items = strings(item.items);\n\t\tif (!items) return undefined;\n\t\tparsed.push({ phase: item.phase, items });\n\t}\n\treturn parsed;\n}\n\nfunction nonBlank(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.trim() !== \"\" ? value : undefined;\n}\n\nfunction isBlank(value: unknown): boolean {\n\treturn typeof value === \"string\" && value.trim() === \"\";\n}\n\nfunction error(message: string): TodoNormalization {\n\treturn { corrections: [], error: message };\n}\n\nfunction aliasCorrection(alias: Alias, inferred: boolean): string {\n\tconst form =\n\t\talias === \"init\" ? '{\"op\":\"init\",\"items\":[...]}' : '{\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]}';\n\tif (inferred) {\n\t\treturn `[auto-corrected] \"op\" was missing; interpreted as \"${alias}\" because \"${alias}\" was provided as an items alias. Always pass op explicitly: ${form}`;\n\t}\n\treturn `[auto-corrected] \"${alias}\" was used as an items alias and folded into \"items\". Use: ${form}`;\n}\n\nfunction inferredCorrection(op: \"init\" | \"append\", reason: string, form: string): string {\n\treturn `[auto-corrected] \"op\" was missing; interpreted as \"${op}\" because ${reason}. Always pass op explicitly: ${form}`;\n}\n\nfunction hasTasks(phases: readonly TodoPhase[]): boolean {\n\treturn phases.some((phase) => phase.tasks.length > 0);\n}\n\nexport function normalizeTodoParams(\n\traw: Record<string, unknown>,\n\tcurrentPhases: readonly TodoPhase[],\n): TodoNormalization {\n\tconst rawOp = raw.op;\n\tif (rawOp === \"view\") return { entry: { op: \"view\" }, corrections: [] };\n\tif (rawOp !== undefined && !isOperation(rawOp)) return error('Invalid \"op\".');\n\n\tconst op = isOperation(rawOp) ? rawOp : undefined;\n\tconst task = nonBlank(raw.task);\n\tconst phase = nonBlank(raw.phase);\n\tif (op === \"start\" || op === \"done\" || op === \"drop\" || op === \"rm\") {\n\t\tif (isBlank(raw.task) && !phase) {\n\t\t\treturn error('Blank \"task\" — pass the exact task text, or omit the field entirely for a bulk operation.');\n\t\t}\n\t\tif (isBlank(raw.phase) && !task) {\n\t\t\treturn error('Blank \"phase\" — pass the exact phase text, or omit the field entirely for a bulk operation.');\n\t\t}\n\t}\n\n\tconst rawItems = strings(raw.items);\n\tconst aliases: Array<{ name: Alias; items: string[] }> = [];\n\tfor (const name of [\"init\", \"append\"] as const) {\n\t\tconst items = strings(raw[name]);\n\t\tif (items && items.length > 0) aliases.push({ name, items });\n\t}\n\tif (aliases.length > 1) return error(CONFLICTING_SHAPES);\n\tif (aliases.length === 1 && rawItems && rawItems.length > 0) return error(CONFLICTING_SHAPES);\n\n\tconst alias = aliases[0];\n\tlet effectiveItems = rawItems && rawItems.length > 0 ? rawItems : undefined;\n\tlet candidate: Alias | undefined;\n\tconst corrections: string[] = [];\n\tif (alias) {\n\t\tif (op && op !== alias.name) return error(CONFLICTING_SHAPES);\n\t\teffectiveItems = alias.items;\n\t\tcandidate = op ? undefined : alias.name;\n\t\tcorrections.push(aliasCorrection(alias.name, !op));\n\t}\n\n\tconst effectiveList = list(raw.list);\n\tconst hasList = Boolean(effectiveList && effectiveList.length > 0);\n\tconst hasItems = Boolean(effectiveItems && effectiveItems.length > 0);\n\tif (hasList && hasItems) return error(CONFLICTING_SHAPES);\n\n\tlet effectiveOp = op;\n\tif (!effectiveOp) {\n\t\tif (candidate) {\n\t\t\teffectiveOp = candidate;\n\t\t} else if (hasList) {\n\t\t\teffectiveOp = \"init\";\n\t\t\tcorrections.push(inferredCorrection(\"init\", '\"list\" was provided', '{\"op\":\"init\",\"list\":[...]}'));\n\t\t} else if (hasItems && phase) {\n\t\t\teffectiveOp = \"append\";\n\t\t\tcorrections.push(\n\t\t\t\tinferredCorrection(\n\t\t\t\t\t\"append\",\n\t\t\t\t\t'\"items\" and \"phase\" were provided',\n\t\t\t\t\t'{\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]}',\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (hasItems && !hasTasks(currentPhases)) {\n\t\t\teffectiveOp = \"init\";\n\t\t\tcorrections.push(\n\t\t\t\tinferredCorrection(\"init\", '\"items\" was provided to an empty todo list', '{\"op\":\"init\",\"items\":[...]}'),\n\t\t\t);\n\t\t} else if (hasItems) {\n\t\t\treturn error(\n\t\t\t\t'Missing \"op\": use {\"op\":\"init\",\"list\":[...]} to replace the list, or {\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]} to add tasks.',\n\t\t\t);\n\t\t} else {\n\t\t\treturn error('Missing \"op\". Example: {\"op\":\"init\",\"list\":[{\"phase\":\"Setup\",\"items\":[\"...\"]}]}');\n\t\t}\n\t}\n\n\tswitch (effectiveOp) {\n\t\tcase \"init\": {\n\t\t\tif (task || (effectiveList && effectiveList.length === 0 && hasItems)) return error(CONFLICTING_SHAPES);\n\t\t\tconst entry: TodoOpEntry = { op: \"init\" };\n\t\t\tif (effectiveList) entry.list = effectiveList;\n\t\t\tif (effectiveItems) entry.items = effectiveItems;\n\t\t\tif (phase) entry.phase = phase;\n\t\t\treturn { entry, corrections };\n\t\t}\n\t\tcase \"start\":\n\t\t\tif (phase || hasList || hasItems) return error(CONFLICTING_SHAPES);\n\t\t\treturn { entry: task ? { op: \"start\", task } : { op: \"start\" }, corrections };\n\t\tcase \"done\":\n\t\tcase \"drop\":\n\t\tcase \"rm\": {\n\t\t\tif (hasList || hasItems) return error(CONFLICTING_SHAPES);\n\t\t\tconst entry: TodoOpEntry = { op: effectiveOp };\n\t\t\tif (task) entry.task = task;\n\t\t\tif (phase) entry.phase = phase;\n\t\t\treturn { entry, corrections };\n\t\t}\n\t\tcase \"append\":\n\t\t\tif (task || hasList) return error(CONFLICTING_SHAPES);\n\t\t\treturn {\n\t\t\t\tentry: { op: \"append\", ...(phase ? { phase } : {}), ...(effectiveItems ? { items: effectiveItems } : {}) },\n\t\t\t\tcorrections,\n\t\t\t};\n\t\tcase \"view\":\n\t\t\treturn { entry: { op: \"view\" }, corrections: [] };\n\t}\n}\n"]}
1
+ {"version":3,"file":"normalize.js","sourceRoot":"","sources":["../../../../../src/core/extensions/builtin/todotools/normalize.ts"],"names":[],"mappings":"AAUA,MAAM,kBAAkB,GACvB,gJAAgJ,CAAC;AAElJ,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IAClC,QAAQ,KAAK,EAAE,CAAC;QACf,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,IAAI,CAAC;QACV,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ,CAAC;QACd,KAAK,MAAM;YACV,OAAO,IAAI,CAAC;QACb;YACC,OAAO,KAAK,CAAC;IACf,CAAC;AACF,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,SAAS,CAAC;QAC/C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,KAAc;IAC3B,IAAI,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AAK,CAAC,kBAAkB,CAAC,CAAC;YAC1D,MAAM,KAAK,GAAgB,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC;YAC/C,IAAI,IAAI;gBAAE,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;YAC5B,IAAI,KAAK;gBAAE,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC;YAC/B,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAC/B,CAAC;QACD,KAAK,QAAQ;YACZ,IAAI,IAAI,IAAI,OAAO;gBAAE,OAAO,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACtD,OAAO;gBACN,KAAK,EAAE,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;gBAC1G,WAAW;aACX,CAAC;QACH,KAAK,MAAM;YACV,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;IACpD,CAAC;AACF,CAAC","sourcesContent":["import type { TodoOpEntry, TodoOperation, TodoPhase } from \"./todo-types.ts\";\n\nexport type TodoNormalization = {\n\tentry?: TodoOpEntry;\n\tcorrections: string[];\n\terror?: string;\n};\n\ntype Alias = \"init\" | \"append\";\n\nconst CONFLICTING_SHAPES =\n\t'conflicting shapes. Use {\"op\":\"init\",\"list\":[...]} to replace the list or {\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]} to add tasks.';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction isOperation(value: unknown): value is TodoOperation {\n\tswitch (value) {\n\t\tcase \"init\":\n\t\tcase \"start\":\n\t\tcase \"done\":\n\t\tcase \"rm\":\n\t\tcase \"drop\":\n\t\tcase \"append\":\n\t\tcase \"view\":\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\nfunction strings(value: unknown): string[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst parsed: string[] = [];\n\tfor (const item of value) {\n\t\tif (typeof item !== \"string\") return undefined;\n\t\tparsed.push(item);\n\t}\n\treturn parsed;\n}\n\nfunction list(value: unknown): TodoOpEntry[\"list\"] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst parsed: NonNullable<TodoOpEntry[\"list\"]> = [];\n\tfor (const item of value) {\n\t\tif (!isRecord(item) || typeof item.phase !== \"string\") return undefined;\n\t\tconst items = strings(item.items);\n\t\tif (!items) return undefined;\n\t\tparsed.push({ phase: item.phase, items });\n\t}\n\treturn parsed;\n}\n\nfunction nonBlank(value: unknown): string | undefined {\n\treturn typeof value === \"string\" && value.trim() !== \"\" ? value : undefined;\n}\n\nfunction isBlank(value: unknown): boolean {\n\treturn typeof value === \"string\" && value.trim() === \"\";\n}\n\nfunction error(message: string): TodoNormalization {\n\treturn { corrections: [], error: message };\n}\n\nfunction aliasCorrection(alias: Alias, inferred: boolean): string {\n\tconst form =\n\t\talias === \"init\" ? '{\"op\":\"init\",\"items\":[...]}' : '{\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]}';\n\tif (inferred) {\n\t\treturn `[auto-corrected] \"op\" was missing; interpreted as \"${alias}\" because \"${alias}\" was provided as an items alias. Always pass op explicitly: ${form}`;\n\t}\n\treturn `[auto-corrected] \"${alias}\" was used as an items alias and folded into \"items\". Use: ${form}`;\n}\n\nfunction inferredCorrection(op: \"init\" | \"append\", reason: string, form: string): string {\n\treturn `[auto-corrected] \"op\" was missing; interpreted as \"${op}\" because ${reason}. Always pass op explicitly: ${form}`;\n}\n\nfunction hasTasks(phases: readonly TodoPhase[]): boolean {\n\treturn phases.some((phase) => phase.tasks.length > 0);\n}\n\nexport function normalizeTodoParams(\n\traw: Record<string, unknown>,\n\tcurrentPhases: readonly TodoPhase[],\n): TodoNormalization {\n\tconst rawOp = raw.op;\n\tif (rawOp === \"view\") return { entry: { op: \"view\" }, corrections: [] };\n\tif (rawOp !== undefined && !isOperation(rawOp)) return error('Invalid \"op\".');\n\n\tconst op = isOperation(rawOp) ? rawOp : undefined;\n\tconst task = nonBlank(raw.task);\n\tconst phase = nonBlank(raw.phase);\n\tconst corrections: string[] = [];\n\tif (op === \"start\" || op === \"done\" || op === \"drop\" || op === \"rm\") {\n\t\t// GPT-5.x-style function calling serializes every schema property and pads\n\t\t// omitted strings with \"\". When BOTH targets arrive blank on rm, the only\n\t\t// documented no-target rm form is a bulk clear, so the padding is\n\t\t// unambiguous — drop it instead of demanding a field omission the\n\t\t// serializer cannot express. Single-blank targets and the destructive-bulk\n\t\t// ops (start/done/drop) still error, so a truncated single target never\n\t\t// widens into a bulk action.\n\t\tif (op === \"rm\" && isBlank(raw.task) && isBlank(raw.phase)) {\n\t\t\tcorrections.push(\n\t\t\t\t'[auto-corrected] \"task\" and \"phase\" were both blank; treated as a bulk clear. ' +\n\t\t\t\t\t'For a single target pass the exact text: {\"op\":\"rm\",\"task\":\"<exact task content>\"}.',\n\t\t\t);\n\t\t} else if (isBlank(raw.task) && !phase) {\n\t\t\treturn error('Blank \"task\" — pass the exact task text, or omit the field entirely for a bulk operation.');\n\t\t} else if (isBlank(raw.phase) && !task) {\n\t\t\treturn error('Blank \"phase\" — pass the exact phase text, or omit the field entirely for a bulk operation.');\n\t\t}\n\t}\n\n\tconst rawItems = strings(raw.items);\n\tconst aliases: Array<{ name: Alias; items: string[] }> = [];\n\tfor (const name of [\"init\", \"append\"] as const) {\n\t\tconst items = strings(raw[name]);\n\t\tif (items && items.length > 0) aliases.push({ name, items });\n\t}\n\tif (aliases.length > 1) return error(CONFLICTING_SHAPES);\n\tif (aliases.length === 1 && rawItems && rawItems.length > 0) return error(CONFLICTING_SHAPES);\n\n\tconst alias = aliases[0];\n\tlet effectiveItems = rawItems && rawItems.length > 0 ? rawItems : undefined;\n\tlet candidate: Alias | undefined;\n\tif (alias) {\n\t\tif (op && op !== alias.name) return error(CONFLICTING_SHAPES);\n\t\teffectiveItems = alias.items;\n\t\tcandidate = op ? undefined : alias.name;\n\t\tcorrections.push(aliasCorrection(alias.name, !op));\n\t}\n\n\tconst effectiveList = list(raw.list);\n\tconst hasList = Boolean(effectiveList && effectiveList.length > 0);\n\tconst hasItems = Boolean(effectiveItems && effectiveItems.length > 0);\n\tif (hasList && hasItems) return error(CONFLICTING_SHAPES);\n\n\tlet effectiveOp = op;\n\tif (!effectiveOp) {\n\t\tif (candidate) {\n\t\t\teffectiveOp = candidate;\n\t\t} else if (hasList) {\n\t\t\teffectiveOp = \"init\";\n\t\t\tcorrections.push(inferredCorrection(\"init\", '\"list\" was provided', '{\"op\":\"init\",\"list\":[...]}'));\n\t\t} else if (hasItems && phase) {\n\t\t\teffectiveOp = \"append\";\n\t\t\tcorrections.push(\n\t\t\t\tinferredCorrection(\n\t\t\t\t\t\"append\",\n\t\t\t\t\t'\"items\" and \"phase\" were provided',\n\t\t\t\t\t'{\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]}',\n\t\t\t\t),\n\t\t\t);\n\t\t} else if (hasItems && !hasTasks(currentPhases)) {\n\t\t\teffectiveOp = \"init\";\n\t\t\tcorrections.push(\n\t\t\t\tinferredCorrection(\"init\", '\"items\" was provided to an empty todo list', '{\"op\":\"init\",\"items\":[...]}'),\n\t\t\t);\n\t\t} else if (hasItems) {\n\t\t\treturn error(\n\t\t\t\t'Missing \"op\": use {\"op\":\"init\",\"list\":[...]} to replace the list, or {\"op\":\"append\",\"phase\":\"<active phase>\",\"items\":[...]} to add tasks.',\n\t\t\t);\n\t\t} else {\n\t\t\treturn error('Missing \"op\". Example: {\"op\":\"init\",\"list\":[{\"phase\":\"Setup\",\"items\":[\"...\"]}]}');\n\t\t}\n\t}\n\n\tswitch (effectiveOp) {\n\t\tcase \"init\": {\n\t\t\tif (task || (effectiveList && effectiveList.length === 0 && hasItems)) return error(CONFLICTING_SHAPES);\n\t\t\tconst entry: TodoOpEntry = { op: \"init\" };\n\t\t\tif (effectiveList) entry.list = effectiveList;\n\t\t\tif (effectiveItems) entry.items = effectiveItems;\n\t\t\tif (phase) entry.phase = phase;\n\t\t\treturn { entry, corrections };\n\t\t}\n\t\tcase \"start\":\n\t\t\tif (phase || hasList || hasItems) return error(CONFLICTING_SHAPES);\n\t\t\treturn { entry: task ? { op: \"start\", task } : { op: \"start\" }, corrections };\n\t\tcase \"done\":\n\t\tcase \"drop\":\n\t\tcase \"rm\": {\n\t\t\tif (hasList || hasItems) return error(CONFLICTING_SHAPES);\n\t\t\tconst entry: TodoOpEntry = { op: effectiveOp };\n\t\t\tif (task) entry.task = task;\n\t\t\tif (phase) entry.phase = phase;\n\t\t\treturn { entry, corrections };\n\t\t}\n\t\tcase \"append\":\n\t\t\tif (task || hasList) return error(CONFLICTING_SHAPES);\n\t\t\treturn {\n\t\t\t\tentry: { op: \"append\", ...(phase ? { phase } : {}), ...(effectiveItems ? { items: effectiveItems } : {}) },\n\t\t\t\tcorrections,\n\t\t\t};\n\t\tcase \"view\":\n\t\t\treturn { entry: { op: \"view\" }, corrections: [] };\n\t}\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
2
+ import type { Api, Model } from "@earendil-works/pi-ai";
3
+ export declare function isSensitiveHighReasoningModel(model: Pick<Model<Api>, "id">): boolean;
4
+ export declare function shouldWarnHighReasoning(model: Pick<Model<Api>, "id">, thinkingLevel: ThinkingLevel): boolean;
5
+ export interface HighReasoningWarningContent {
6
+ readonly title: string;
7
+ readonly body: readonly string[];
8
+ }
9
+ export declare function buildHighReasoningWarning(model: Pick<Model<Api>, "id" | "provider">, thinkingLevel: ThinkingLevel): HighReasoningWarningContent;
10
+ //# sourceMappingURL=high-reasoning-warning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"high-reasoning-warning.d.ts","sourceRoot":"","sources":["../../src/core/high-reasoning-warning.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAQxD,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,OAAO,CAEpF;AAED,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,EAAE,aAAa,EAAE,aAAa,GAAG,OAAO,CAE5G;AAED,MAAM,WAAW,2BAA2B;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACjC;AAED,wBAAgB,yBAAyB,CACxC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,GAAG,UAAU,CAAC,EAC1C,aAAa,EAAE,aAAa,GAC1B,2BAA2B,CAe7B"}
@@ -0,0 +1,28 @@
1
+ // Matches only the gpt-5.x "sol" variants (gpt-5.6-sol, -sol-fast, -sol-pro and
2
+ // provider-prefixed forms such as openai/ or openai.). The trailing negative
3
+ // lookahead stops unrelated ids that merely continue with letters after "sol" —
4
+ // notably upstage/solar-pro-3 — from matching.
5
+ const SOL_MODEL_ID_PATTERN = /gpt-5(?:\.\d+)?-sol(?![a-z])/i;
6
+ export function isSensitiveHighReasoningModel(model) {
7
+ return SOL_MODEL_ID_PATTERN.test(model.id);
8
+ }
9
+ export function shouldWarnHighReasoning(model, thinkingLevel) {
10
+ return (thinkingLevel === "xhigh" || thinkingLevel === "max") && isSensitiveHighReasoningModel(model);
11
+ }
12
+ export function buildHighReasoningWarning(model, thinkingLevel) {
13
+ const modelId = model.id;
14
+ const title = `⚠ HIGH-REASONING MODEL WARNING — ${model.provider}/${modelId} @ ${thinkingLevel}`;
15
+ const body = [
16
+ `${modelId} is a frontier reasoning model. Running it at "${thinkingLevel}" effort makes it acutely sensitive to prompt quality.`,
17
+ "Driving this model directly from a human prompt is NOT recommended. Risks include:",
18
+ " • The model may refuse to stop, looping or working far past the stated goal.",
19
+ ' • It may perform unrequested actions in order to "complete" the task.',
20
+ " • It may take risky, irreversible, or dangerous actions to force completion.",
21
+ "Strongly recommended: use this model ONLY through the ultrabrain subagent.",
22
+ "Human prompts leave gaps; an agent-authored prompt is denser and stricter than a human's — exactly what these high-effort models need to stay bounded.",
23
+ 'From the main agent, delegate instead: "query ultrabrain with <task>".',
24
+ `If you drive this model directly at ${thinkingLevel}, YOU assume ALL responsibility for the consequences.`,
25
+ ];
26
+ return { title, body };
27
+ }
28
+ //# sourceMappingURL=high-reasoning-warning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"high-reasoning-warning.js","sourceRoot":"","sources":["../../src/core/high-reasoning-warning.ts"],"names":[],"mappings":"AAGA,gFAAgF;AAChF,6EAA6E;AAC7E,gFAAgF;AAChF,+CAA+C;AAC/C,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAE7D,MAAM,UAAU,6BAA6B,CAAC,KAA6B;IAC1E,OAAO,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,KAA6B,EAAE,aAA4B;IAClG,OAAO,CAAC,aAAa,KAAK,OAAO,IAAI,aAAa,KAAK,KAAK,CAAC,IAAI,6BAA6B,CAAC,KAAK,CAAC,CAAC;AACvG,CAAC;AAOD,MAAM,UAAU,yBAAyB,CACxC,KAA0C,EAC1C,aAA4B;IAE5B,MAAM,OAAO,GAAG,KAAK,CAAC,EAAE,CAAC;IACzB,MAAM,KAAK,GAAG,oCAAoC,KAAK,CAAC,QAAQ,IAAI,OAAO,MAAM,aAAa,EAAE,CAAC;IACjG,MAAM,IAAI,GAAG;QACZ,GAAG,OAAO,kDAAkD,aAAa,wDAAwD;QACjI,oFAAoF;QACpF,gFAAgF;QAChF,yEAAyE;QACzE,gFAAgF;QAChF,4EAA4E;QAC5E,wJAAwJ;QACxJ,wEAAwE;QACxE,uCAAuC,aAAa,uDAAuD;KAC3G,CAAC;IACF,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC","sourcesContent":["import type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { Api, Model } from \"@earendil-works/pi-ai\";\n\n// Matches only the gpt-5.x \"sol\" variants (gpt-5.6-sol, -sol-fast, -sol-pro and\n// provider-prefixed forms such as openai/ or openai.). The trailing negative\n// lookahead stops unrelated ids that merely continue with letters after \"sol\" —\n// notably upstage/solar-pro-3 — from matching.\nconst SOL_MODEL_ID_PATTERN = /gpt-5(?:\\.\\d+)?-sol(?![a-z])/i;\n\nexport function isSensitiveHighReasoningModel(model: Pick<Model<Api>, \"id\">): boolean {\n\treturn SOL_MODEL_ID_PATTERN.test(model.id);\n}\n\nexport function shouldWarnHighReasoning(model: Pick<Model<Api>, \"id\">, thinkingLevel: ThinkingLevel): boolean {\n\treturn (thinkingLevel === \"xhigh\" || thinkingLevel === \"max\") && isSensitiveHighReasoningModel(model);\n}\n\nexport interface HighReasoningWarningContent {\n\treadonly title: string;\n\treadonly body: readonly string[];\n}\n\nexport function buildHighReasoningWarning(\n\tmodel: Pick<Model<Api>, \"id\" | \"provider\">,\n\tthinkingLevel: ThinkingLevel,\n): HighReasoningWarningContent {\n\tconst modelId = model.id;\n\tconst title = `⚠ HIGH-REASONING MODEL WARNING — ${model.provider}/${modelId} @ ${thinkingLevel}`;\n\tconst body = [\n\t\t`${modelId} is a frontier reasoning model. Running it at \"${thinkingLevel}\" effort makes it acutely sensitive to prompt quality.`,\n\t\t\"Driving this model directly from a human prompt is NOT recommended. Risks include:\",\n\t\t\" • The model may refuse to stop, looping or working far past the stated goal.\",\n\t\t' • It may perform unrequested actions in order to \"complete\" the task.',\n\t\t\" • It may take risky, irreversible, or dangerous actions to force completion.\",\n\t\t\"Strongly recommended: use this model ONLY through the ultrabrain subagent.\",\n\t\t\"Human prompts leave gaps; an agent-authored prompt is denser and stricter than a human's — exactly what these high-effort models need to stay bounded.\",\n\t\t'From the main agent, delegate instead: \"query ultrabrain with <task>\".',\n\t\t`If you drive this model directly at ${thinkingLevel}, YOU assume ALL responsibility for the consequences.`,\n\t];\n\treturn { title, body };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"model-runtime.d.ts","sourceRoot":"","sources":["../../src/core/model-runtime.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,OAAO,EACZ,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,eAAe,EAKpB,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,sBAAsB,EAE3B,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EAGhB,KAAK,QAAQ,EAMb,MAAM,uBAAuB,CAAC;AAM/B,OAAO,EACN,KAAK,UAAU,EACf,KAAK,0BAA0B,EAG/B,KAAK,mBAAmB,EAIxB,MAAM,wBAAwB,CAAC;AAYhC,MAAM,WAAW,yBAAyB;IACzC,4DAA4D;IAC5D,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oFAAoF;IACpF,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,yDAAyD;IAC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,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,2BAA2B,CAUlH;IACD,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAElH;IACK,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC,CAIjG;IAEK,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAK9C;IAEK,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAElC;IAEK,OAAO,CAAC,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAqB9E;IAED;;;;;OAKG;IACH,OAAO,CAAC,wBAAwB;IAOhC,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAOvE;IAED,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuC9F;IAED,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAO3C;CACD"}
@@ -1,5 +1,5 @@
1
1
  import { dirname, join } from "node:path";
2
- import { createModels, createXtmlRecoveryStreamParser, hasKimiTextToolCallRecovery, lazyStream, ModelsError, shouldRecoverTextToolCalls, wrapStreamWithInvokeRecovery, } from "@earendil-works/pi-ai";
2
+ import { createModels, lazyStream, ModelsError, wrapStreamWithModelRecovery, } from "@earendil-works/pi-ai";
3
3
  import * as builtinProviderCatalog from "@earendil-works/pi-ai/providers/all";
4
4
  import { getAgentDir } from "../config.js";
5
5
  import { AuthStorage as DefaultAuthStorage } from "./auth-storage.js";
@@ -381,11 +381,7 @@ export class ModelRuntime {
381
381
  return lazyStream(model, async () => {
382
382
  const prepared = await this.prepareRequest(model, options);
383
383
  const inner = prepared.provider.stream(prepared.model, context, withPayloadRequestMetadata(prepared.options, prepared.model));
384
- return shouldRecoverTextToolCalls(model) && context.tools?.length
385
- ? wrapStreamWithInvokeRecovery(inner, context.tools, hasKimiTextToolCallRecovery(model)
386
- ? { createParser: createXtmlRecoveryStreamParser, protocol: "kimi-xtml" }
387
- : undefined)
388
- : inner;
384
+ return wrapStreamWithModelRecovery(inner, model, context.tools ?? []);
389
385
  });
390
386
  }
391
387
  complete(model, context, options) {
@@ -395,11 +391,7 @@ export class ModelRuntime {
395
391
  return lazyStream(model, async () => {
396
392
  const prepared = await this.prepareRequest(model, options);
397
393
  const inner = prepared.provider.streamSimple(prepared.model, context, withPayloadRequestMetadata(prepared.options, prepared.model));
398
- return shouldRecoverTextToolCalls(model) && context.tools?.length
399
- ? wrapStreamWithInvokeRecovery(inner, context.tools, hasKimiTextToolCallRecovery(model)
400
- ? { createParser: createXtmlRecoveryStreamParser, protocol: "kimi-xtml" }
401
- : undefined)
402
- : inner;
394
+ return wrapStreamWithModelRecovery(inner, model, context.tools ?? []);
403
395
  });
404
396
  }
405
397
  completeSimple(model, context, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"model-runtime.js","sourceRoot":"","sources":["../../src/core/model-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAaN,YAAY,EACZ,8BAA8B,EAC9B,2BAA2B,EAC3B,UAAU,EAIV,WAAW,EAWX,0BAA0B,EAC1B,4BAA4B,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,sBAAsB,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,mBAA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AU,EAAE;oBACpB,IAAI,EAAE,SAAS,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS;oBAChE,MAAM,EAAE,qBAAqB;iBAC7B,CAAC,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,QAAQ,GAAG;gBACf,GAAG,IAAI,CAAC,QAAQ;gBAChB,IAAI;gBACJ,mBAAmB;gBACnB,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;aACvF,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,EAAE,CAAC;IACxC,CAAC;IAED,kBAAkB,CAAC,UAAkB;QACpC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;CACD","sourcesContent":["import { dirname, join } from \"node:path\";\nimport {\n\ttype Api,\n\ttype ApiStreamOptions,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype AuthCheck,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype AuthType,\n\ttype Context,\n\ttype Credential,\n\ttype CredentialInfo,\n\ttype CredentialStore,\n\tcreateModels,\n\tcreateXtmlRecoveryStreamParser,\n\thasKimiTextToolCallRecovery,\n\tlazyStream,\n\ttype Model,\n\ttype Models,\n\ttype ModelsApiStreamOptions,\n\tModelsError,\n\ttype ModelsRefreshOptions,\n\ttype ModelsRefreshResult,\n\ttype ModelsSimpleStreamOptions,\n\ttype ModelsStore,\n\ttype ModelsStreamTransforms,\n\ttype MutableModels,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n\tshouldRecoverTextToolCalls,\n\twrapStreamWithInvokeRecovery,\n} from \"@earendil-works/pi-ai\";\nimport * as builtinProviderCatalog from \"@earendil-works/pi-ai/providers/all\";\nimport { getAgentDir } from \"../config.ts\";\nimport { AuthStorage as DefaultAuthStorage } from \"./auth-storage.ts\";\nimport { ModelConfig } from \"./model-config.ts\";\nimport { FileModelsStore, InMemoryCodingAgentModelsStore } from \"./models-store.ts\";\nimport {\n\ttype AuthStatus,\n\ttype CompatibilityRequestConfig,\n\tcomposeModelProvider,\n\tconfiguredRequestAuthStatus,\n\ttype ProviderConfigInput,\n\tresolveCompatibilityRequestConfig,\n\tresolveConfiguredModelHeaders,\n\tvalidateExtensionProvider,\n} from \"./provider-composer.ts\";\nimport { withRemoteCatalog } from \"./remote-catalog-provider.ts\";\nimport { RuntimeCredentials } from \"./runtime-credentials.ts\";\n\ninterface ModelRuntimeSnapshot {\n\tall: readonly Model<Api>[];\n\tavailable: readonly Model<Api>[];\n\tconfiguredProviders: ReadonlySet<string>;\n\tstoredProviders: ReadonlySet<string>;\n\tauth: ReadonlyMap<string, AuthCheck | undefined>;\n}\n\nexport interface CreateModelRuntimeOptions {\n\t/** Credential storage. Defaults to the file at authPath. */\n\tcredentials?: CredentialStore;\n\tauthPath?: string;\n\tmodelsPath?: string | null;\n\tmodelsStore?: ModelsStore;\n\tmodelsStorePath?: string;\n\t/** Allow create() to refresh model catalogs over the network. Defaults to false. */\n\tallowModelNetwork?: boolean;\n\t/** Timeout for the create-time network model refresh. */\n\tmodelRefreshTimeoutMs?: number;\n\tcatalogBaseUrl?: string;\n}\n\nexport interface ModelRuntimeAuthOverrides {\n\tapiKey?: string;\n\tenv?: Record<string, string>;\n}\n\nfunction mergeHeaders(\n\tbase: ProviderHeaders | undefined,\n\toverride: ProviderHeaders | undefined,\n): ProviderHeaders | undefined {\n\tif (!base && !override) return undefined;\n\tconst merged = { ...base };\n\tfor (const [name, value] of Object.entries(override ?? {})) {\n\t\tconst lowerName = name.toLowerCase();\n\t\tfor (const existingName of Object.keys(merged)) {\n\t\t\tif (existingName.toLowerCase() === lowerName) delete merged[existingName];\n\t\t}\n\t\tmerged[name] = value;\n\t}\n\treturn merged;\n}\n\nfunction withPayloadRequestMetadata(options: StreamOptions, model: Model<Api>): StreamOptions {\n\tif (!options.onPayload) return options;\n\tconst onPayload = options.onPayload;\n\treturn {\n\t\t...options,\n\t\tonPayload: async (payload, providerModel) =>\n\t\t\tawait onPayload(payload, providerModel, { model, headers: options.headers ?? {} }),\n\t};\n}\n\n/** Configured pi-ai Models collection used by coding-agent and SDK consumers. */\nexport class ModelRuntime implements Models {\n\tprivate readonly models: MutableModels;\n\tprivate readonly credentials: RuntimeCredentials;\n\tprivate readonly defaultBuiltins: ReadonlyMap<string, Provider>;\n\tprivate readonly builtins = new Map<string, Provider>();\n\tprivate readonly nativeExtensionProviders = new Map<string, Provider>();\n\tprivate readonly extensionProviders = new Map<string, ProviderConfigInput>();\n\tprivate readonly compositionErrors = new Map<string, string>();\n\tprivate readonly modelsPath: string | undefined;\n\tprivate readonly modelNetworkEnabled: boolean;\n\tprivate readonly modelRefreshTimeoutMs: number;\n\tprivate config: ModelConfig;\n\tprivate snapshot: ModelRuntimeSnapshot = {\n\t\tall: [],\n\t\tavailable: [],\n\t\tconfiguredProviders: new Set(),\n\t\tstoredProviders: new Set(),\n\t\tauth: new Map(),\n\t};\n\tprivate availabilityRefresh: Promise<void> | undefined;\n\tprivate availabilityInitialized = false;\n\tprivate availabilityError: string | undefined;\n\tprivate constructor(\n\t\tcredentials: RuntimeCredentials,\n\t\tconfig: ModelConfig,\n\t\tmodelsPath: string | undefined,\n\t\tmodelsStore: ModelsStore,\n\t\tproviders: readonly Provider[],\n\t\tmodelNetworkEnabled: boolean,\n\t\tmodelRefreshTimeoutMs: number,\n\t) {\n\t\tthis.credentials = credentials;\n\t\tthis.config = config;\n\t\tthis.modelsPath = modelsPath;\n\t\tthis.modelNetworkEnabled = modelNetworkEnabled;\n\t\tthis.modelRefreshTimeoutMs = modelRefreshTimeoutMs;\n\t\tthis.defaultBuiltins = new Map(providers.map((provider) => [provider.id, provider]));\n\t\tfor (const [providerId, provider] of this.defaultBuiltins) this.builtins.set(providerId, provider);\n\t\tthis.models = createModels({ credentials, modelsStore });\n\t\tthis.rebuildProviders();\n\t}\n\n\tstatic async create(options: CreateModelRuntimeOptions = {}): Promise<ModelRuntime> {\n\t\tconst credentials = new RuntimeCredentials(options.credentials ?? DefaultAuthStorage.create(options.authPath));\n\t\tconst modelsPath =\n\t\t\toptions.modelsPath === null ? undefined : (options.modelsPath ?? join(getAgentDir(), \"models.json\"));\n\t\tconst config = await ModelConfig.load(modelsPath);\n\t\tconst modelsStore =\n\t\t\toptions.modelsStore ??\n\t\t\t(modelsPath\n\t\t\t\t? new FileModelsStore(options.modelsStorePath ?? join(dirname(modelsPath), \"models-store.json\"))\n\t\t\t\t: new InMemoryCodingAgentModelsStore());\n\t\tconst builtinModelDataGeneratedAt = builtinProviderCatalog.getBuiltinModelDataGeneratedAt();\n\t\tconst providers = builtinProviderCatalog\n\t\t\t.builtinProviders()\n\t\t\t.map((provider) =>\n\t\t\t\tprovider.id === \"radius\"\n\t\t\t\t\t? provider\n\t\t\t\t\t: withRemoteCatalog(provider, options.catalogBaseUrl, builtinModelDataGeneratedAt),\n\t\t\t);\n\t\tconst runtime = new ModelRuntime(\n\t\t\tcredentials,\n\t\t\tconfig,\n\t\t\tmodelsPath,\n\t\t\tmodelsStore,\n\t\t\tproviders,\n\t\t\tprocess.env.PI_OFFLINE === undefined && options.allowModelNetwork === true,\n\t\t\toptions.modelRefreshTimeoutMs ?? 15_000,\n\t\t);\n\t\truntime.configureRadiusProviders();\n\t\truntime.rebuildProviders();\n\t\tconst refreshFromNetwork = runtime.modelNetworkEnabled && options.allowModelNetwork === true;\n\t\tconst controller = refreshFromNetwork ? new AbortController() : undefined;\n\t\tconst timeout = controller\n\t\t\t? setTimeout(() => controller.abort(), options.modelRefreshTimeoutMs ?? 15_000)\n\t\t\t: undefined;\n\t\ttry {\n\t\t\tawait runtime.refresh({ allowNetwork: refreshFromNetwork, signal: controller?.signal });\n\t\t} finally {\n\t\t\tif (timeout) clearTimeout(timeout);\n\t\t}\n\t\treturn runtime;\n\t}\n\n\t/** Synchronous compatibility constructor for legacy ModelRegistry callers. */\n\tstatic createSync(options: CreateModelRuntimeOptions = {}): ModelRuntime {\n\t\tconst credentials = new RuntimeCredentials(options.credentials ?? DefaultAuthStorage.create(options.authPath));\n\t\tconst modelsPath =\n\t\t\toptions.modelsPath === null ? undefined : (options.modelsPath ?? join(getAgentDir(), \"models.json\"));\n\t\tconst config = ModelConfig.loadSync(modelsPath);\n\t\tconst modelsStore =\n\t\t\toptions.modelsStore ??\n\t\t\t(modelsPath\n\t\t\t\t? new FileModelsStore(options.modelsStorePath ?? join(dirname(modelsPath), \"models-store.json\"))\n\t\t\t\t: new InMemoryCodingAgentModelsStore());\n\t\tconst providers = builtinProviderCatalog\n\t\t\t.builtinProviders()\n\t\t\t.map((provider) =>\n\t\t\t\tprovider.id === \"radius\" ? provider : withRemoteCatalog(provider, options.catalogBaseUrl),\n\t\t\t);\n\t\tconst runtime = new ModelRuntime(\n\t\t\tcredentials,\n\t\t\tconfig,\n\t\t\tmodelsPath,\n\t\t\tmodelsStore,\n\t\t\tproviders,\n\t\t\toptions.allowModelNetwork ?? false,\n\t\t\toptions.modelRefreshTimeoutMs ?? 15_000,\n\t\t);\n\t\truntime.configureRadiusProviders();\n\t\truntime.rebuildProviders();\n\t\treturn runtime;\n\t}\n\n\tprivate configureRadiusProviders(): void {\n\t\tthis.builtins.clear();\n\t\tfor (const [providerId, provider] of this.defaultBuiltins) this.builtins.set(providerId, provider);\n\t\tfor (const providerId of this.config.getProviderIds()) {\n\t\t\tconst config = this.config.getProvider(providerId);\n\t\t\tif (config?.oauth !== \"radius\" || !config.baseUrl) continue;\n\t\t\tthis.builtins.set(\n\t\t\t\tproviderId,\n\t\t\t\tbuiltinProviderCatalog.radiusProvider({\n\t\t\t\t\tid: providerId,\n\t\t\t\t\tname: config.name ?? providerId,\n\t\t\t\t\tgateway: config.baseUrl.replace(/\\/v1\\/?$/u, \"\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate providerIds(): Set<string> {\n\t\treturn new Set([\n\t\t\t...this.builtins.keys(),\n\t\t\t...this.nativeExtensionProviders.keys(),\n\t\t\t...this.config.getProviderIds(),\n\t\t\t...this.extensionProviders.keys(),\n\t\t]);\n\t}\n\n\tprivate recomposeProvider(providerId: string): void {\n\t\tif (this.config.isProviderDisabled(providerId)) {\n\t\t\tthis.models.deleteProvider(providerId);\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t\treturn;\n\t\t}\n\t\tconst base = this.nativeExtensionProviders.get(providerId) ?? this.builtins.get(providerId);\n\t\tconst extension = this.extensionProviders.get(providerId);\n\t\tif (!base && !this.config.getProvider(providerId) && !extension) {\n\t\t\tthis.models.deleteProvider(providerId);\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t\treturn;\n\t\t}\n\t\tif (base && !this.config.getProvider(providerId) && !extension) {\n\t\t\t// No overlays: use the builtin untouched so its auth/login/stream behavior is exact.\n\t\t\tthis.models.setProvider(base);\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tthis.models.setProvider(composeModelProvider(providerId, base, this.config, extension));\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t} catch (error) {\n\t\t\tthis.compositionErrors.set(providerId, error instanceof Error ? error.message : String(error));\n\t\t\tif (base) this.models.setProvider(base);\n\t\t\telse this.models.deleteProvider(providerId);\n\t\t}\n\t}\n\n\tprivate rebuildProviders(): void {\n\t\tthis.models.clearProviders();\n\t\tthis.compositionErrors.clear();\n\t\tfor (const providerId of this.providerIds()) this.recomposeProvider(providerId);\n\t\tthis.updateModelSnapshot();\n\t}\n\n\tprivate updateModelSnapshot(): void {\n\t\tconst all = [...this.models.getModels()];\n\t\tthis.snapshot = {\n\t\t\t...this.snapshot,\n\t\t\tall,\n\t\t\tavailable: all.filter((model) => this.snapshot.configuredProviders.has(model.provider)),\n\t\t};\n\t}\n\n\tprivate async runAvailabilityRefresh(): Promise<void> {\n\t\tconst providers = this.models.getProviders();\n\t\tconst [available, checks, credentials] = await Promise.all([\n\t\t\tthis.models.getAvailable(),\n\t\t\tPromise.all(\n\t\t\t\tproviders.map(\n\t\t\t\t\tasync (provider): Promise<[string, AuthCheck | undefined]> => [\n\t\t\t\t\t\tprovider.id,\n\t\t\t\t\t\tawait this.models.checkAuth(provider.id),\n\t\t\t\t\t],\n\t\t\t\t),\n\t\t\t),\n\t\t\tthis.credentials.list(),\n\t\t]);\n\t\tconst auth = new Map(checks);\n\t\tconst configuredProviders = new Set(\n\t\t\tchecks\n\t\t\t\t.filter((entry): entry is [string, AuthCheck] => entry[1] !== undefined)\n\t\t\t\t.map(([providerId]) => providerId),\n\t\t);\n\t\tthis.snapshot = {\n\t\t\tall: [...this.models.getModels()],\n\t\t\tavailable: [...available],\n\t\t\tconfiguredProviders,\n\t\t\tstoredProviders: new Set(credentials.map((entry) => entry.providerId)),\n\t\t\tauth,\n\t\t};\n\t\tthis.availabilityInitialized = true;\n\t\tthis.availabilityError = undefined;\n\t}\n\n\tprivate queueAvailabilityRefresh(after: Promise<void> | undefined): Promise<void> {\n\t\tconst refresh = (after ?? Promise.resolve()).catch(() => {}).then(() => this.runAvailabilityRefresh());\n\t\tconst recorded = refresh.catch((error) => {\n\t\t\tthis.availabilityError = error instanceof Error ? error.message : String(error);\n\t\t\tthrow error;\n\t\t});\n\t\tconst tracked = recorded.finally(() => {\n\t\t\tif (this.availabilityRefresh === tracked) this.availabilityRefresh = undefined;\n\t\t});\n\t\tthis.availabilityRefresh = tracked;\n\t\treturn tracked;\n\t}\n\n\t/** Coalesce concurrent readers onto the pending refresh. */\n\tprivate refreshAvailability(): Promise<void> {\n\t\treturn this.availabilityRefresh ?? this.queueAvailabilityRefresh(undefined);\n\t}\n\n\t/** Mutations must not observe an in-flight refresh started before them. */\n\tprivate forceRefreshAvailability(): Promise<void> {\n\t\treturn this.queueAvailabilityRefresh(this.availabilityRefresh);\n\t}\n\n\tgetProviders(): readonly Provider[] {\n\t\treturn this.models.getProviders();\n\t}\n\tgetProvider(providerId: string): Provider | undefined {\n\t\treturn this.models.getProvider(providerId);\n\t}\n\tgetModels(providerId?: string): readonly Model<Api>[] {\n\t\treturn this.models.getModels(providerId);\n\t}\n\tgetModel(providerId: string, modelId: string): Model<Api> | undefined {\n\t\treturn this.models.getModel(providerId, modelId);\n\t}\n\n\tasync checkAuth(providerId: string): Promise<AuthCheck | undefined> {\n\t\treturn this.models.checkAuth(providerId);\n\t}\n\tasync getAvailable(providerId?: string): Promise<readonly Model<Api>[]> {\n\t\tif (providerId) {\n\t\t\tif (this.availabilityRefresh) {\n\t\t\t\tawait this.availabilityRefresh;\n\t\t\t\treturn this.snapshot.available.filter((model) => model.provider === providerId);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\treturn await this.models.getAvailable(providerId);\n\t\t\t} catch (error) {\n\t\t\t\tthis.availabilityError = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.refreshAvailability();\n\t\treturn this.snapshot.available;\n\t}\n\n\tgetAvailableSnapshot(): readonly Model<Api>[] {\n\t\treturn this.snapshot.available;\n\t}\n\n\t/** True only when the most recent availability refresh completed without error. */\n\thasFreshAvailabilitySnapshot(): boolean {\n\t\treturn this.availabilityInitialized && this.availabilityError === undefined;\n\t}\n\n\thasAvailabilitySnapshot(): boolean {\n\t\treturn this.availabilityInitialized;\n\t}\n\n\tgetError(): string | undefined {\n\t\tconst errors: string[] = [];\n\t\tconst configError = this.config.getError();\n\t\tif (configError) errors.push(configError);\n\t\tfor (const [providerId, error] of this.compositionErrors) {\n\t\t\terrors.push(`Provider \"${providerId}\": ${error}`);\n\t\t}\n\t\tif (this.availabilityError) errors.push(`Availability refresh: ${this.availabilityError}`);\n\t\treturn errors.length > 0 ? errors.join(\"\\n\\n\") : undefined;\n\t}\n\n\tgetRegisteredProviderConfig(providerId: string): ProviderConfigInput | undefined {\n\t\treturn this.extensionProviders.get(providerId);\n\t}\n\n\tgetRegisteredProviderIds(): readonly string[] {\n\t\treturn [...new Set([...this.extensionProviders.keys(), ...this.nativeExtensionProviders.keys()])];\n\t}\n\n\tgetRegisteredNativeProvider(providerId: string): Provider | undefined {\n\t\treturn this.nativeExtensionProviders.get(providerId);\n\t}\n\n\t/** @internal Compatibility fallback for ModelRegistry when provider auth is unconfigured. */\n\tgetCompatibilityRequestConfig(model: Model<Api>, env?: Record<string, string>): CompatibilityRequestConfig {\n\t\treturn resolveCompatibilityRequestConfig(\n\t\t\tmodel,\n\t\t\tthis.config.getProvider(model.provider),\n\t\t\tthis.extensionProviders.get(model.provider),\n\t\t\tenv,\n\t\t);\n\t}\n\n\tisUsingOAuth(providerId: string): boolean {\n\t\treturn this.snapshot.auth.get(providerId)?.type === \"oauth\";\n\t}\n\n\thasConfiguredAuth(providerId: string): boolean {\n\t\treturn this.snapshot.configuredProviders.has(providerId);\n\t}\n\n\tgetAuth(providerId: string, overrides?: ModelRuntimeAuthOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: ModelRuntimeAuthOverrides): Promise<AuthResult | undefined>;\n\tasync getAuth(\n\t\tproviderOrModel: string | Model<Api>,\n\t\toverrides: ModelRuntimeAuthOverrides = {},\n\t): Promise<AuthResult | undefined> {\n\t\tif (typeof providerOrModel === \"string\") return this.models.getAuth(providerOrModel, overrides);\n\t\tconst resolution = await this.models.getAuth(providerOrModel, overrides);\n\t\tif (!resolution) return undefined;\n\t\tconst configuredHeaders = resolveConfiguredModelHeaders(\n\t\t\tproviderOrModel,\n\t\t\tthis.config.getProvider(providerOrModel.provider),\n\t\t\tthis.extensionProviders.get(providerOrModel.provider),\n\t\t\t{ ...(resolution.env ?? {}), ...(overrides.env ?? {}) },\n\t\t);\n\t\treturn {\n\t\t\t...resolution,\n\t\t\tauth: {\n\t\t\t\t...resolution.auth,\n\t\t\t\theaders: mergeHeaders(resolution.auth.headers, configuredHeaders),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync setRuntimeApiKey(\n\t\tproviderId: string,\n\t\tapiKey: string,\n\t\trefreshOptions: ModelsRefreshOptions = {},\n\t): Promise<void> {\n\t\tthis.credentials.setRuntimeApiKey(providerId, apiKey);\n\t\tconst auth = new Map(this.snapshot.auth).set(providerId, { type: \"api_key\", source: \"runtime API key\" });\n\t\tconst configuredProviders = new Set(this.snapshot.configuredProviders).add(providerId);\n\t\tconst storedProviders = new Set(this.snapshot.storedProviders).add(providerId);\n\t\tthis.snapshot = {\n\t\t\t...this.snapshot,\n\t\t\tauth,\n\t\t\tconfiguredProviders,\n\t\t\tstoredProviders,\n\t\t\tavailable: this.snapshot.all.filter((model) => configuredProviders.has(model.provider)),\n\t\t};\n\t\tawait this.refresh(refreshOptions);\n\t}\n\n\tasync removeRuntimeApiKey(providerId: string): Promise<void> {\n\t\tthis.credentials.removeRuntimeApiKey(providerId);\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t}\n\n\tlistCredentials(): Promise<readonly CredentialInfo[]> {\n\t\treturn this.credentials.list();\n\t}\n\n\tgetProviderAuthStatus(providerId: string): AuthStatus {\n\t\tif (this.credentials.hasRuntimeApiKey(providerId)) return { configured: true, source: \"runtime\" };\n\t\tif (this.snapshot.storedProviders.has(providerId)) return { configured: true, source: \"stored\" };\n\t\tconst configured = configuredRequestAuthStatus(\n\t\t\tthis.config.getProvider(providerId),\n\t\t\tthis.extensionProviders.get(providerId),\n\t\t);\n\t\tif (configured) return configured;\n\t\tconst check = this.snapshot.auth.get(providerId);\n\t\treturn check ? { configured: true, source: \"environment\", label: check.source } : { configured: false };\n\t}\n\n\tprivate async prepareRequest(\n\t\tmodel: Model<Api>,\n\t\toptions: (StreamOptions & ModelsStreamTransforms) | undefined,\n\t): Promise<{ provider: Provider; model: Model<Api>; options: StreamOptions }> {\n\t\tconst provider = this.models.getProvider(model.provider);\n\t\tif (!provider) throw new ModelsError(\"provider\", `Unknown provider: ${model.provider}`);\n\t\tconst resolution = await this.getAuth(model, { apiKey: options?.apiKey, env: options?.env });\n\t\tif (!resolution) throw new ModelsError(\"auth\", `Provider is not configured: ${model.provider}`);\n\n\t\tconst { transformHeaders, ...providerOptions } = options ?? {};\n\t\tlet headers = mergeHeaders(resolution.auth.headers, providerOptions.headers);\n\t\tif (transformHeaders) headers = await transformHeaders(headers ?? {});\n\t\tconst compatibility = this.getCompatibilityRequestConfig(model, resolution.env);\n\t\tconst extraBody =\n\t\t\tcompatibility.extraBody || providerOptions.extraBody\n\t\t\t\t? { ...compatibility.extraBody, ...providerOptions.extraBody }\n\t\t\t\t: undefined;\n\t\tconst env =\n\t\t\tresolution.env || providerOptions.env\n\t\t\t\t? { ...(resolution.env ?? {}), ...(providerOptions.env ?? {}) }\n\t\t\t\t: undefined;\n\t\tconst upstreamModelId = compatibility.upstreamModelId;\n\t\tconst requestModel =\n\t\t\tresolution.auth.baseUrl || upstreamModelId\n\t\t\t\t? {\n\t\t\t\t\t\t...model,\n\t\t\t\t\t\t...(upstreamModelId ? { id: upstreamModelId } : {}),\n\t\t\t\t\t\t...(resolution.auth.baseUrl ? { baseUrl: resolution.auth.baseUrl } : {}),\n\t\t\t\t\t}\n\t\t\t\t: model;\n\t\treturn {\n\t\t\tprovider,\n\t\t\tmodel: requestModel,\n\t\t\toptions: {\n\t\t\t\t...providerOptions,\n\t\t\t\tapiKey: providerOptions.apiKey ?? resolution.auth.apiKey,\n\t\t\t\theaders,\n\t\t\t\textraBody,\n\t\t\t\tenv,\n\t\t\t},\n\t\t};\n\t}\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst prepared = await this.prepareRequest(\n\t\t\t\tmodel,\n\t\t\t\toptions as (StreamOptions & ModelsStreamTransforms) | undefined,\n\t\t\t);\n\t\t\tconst inner = prepared.provider.stream(\n\t\t\t\tprepared.model as Model<TApi>,\n\t\t\t\tcontext,\n\t\t\t\twithPayloadRequestMetadata(prepared.options, prepared.model) as ApiStreamOptions<TApi>,\n\t\t\t);\n\t\t\treturn shouldRecoverTextToolCalls(model) && context.tools?.length\n\t\t\t\t? wrapStreamWithInvokeRecovery(\n\t\t\t\t\t\tinner,\n\t\t\t\t\t\tcontext.tools,\n\t\t\t\t\t\thasKimiTextToolCallRecovery(model)\n\t\t\t\t\t\t\t? { createParser: createXtmlRecoveryStreamParser, protocol: \"kimi-xtml\" }\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t)\n\t\t\t\t: inner;\n\t\t});\n\t}\n\n\tcomplete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage> {\n\t\treturn this.stream(model, context, options).result();\n\t}\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst prepared = await this.prepareRequest(model, options);\n\t\t\tconst inner = prepared.provider.streamSimple(\n\t\t\t\tprepared.model,\n\t\t\t\tcontext,\n\t\t\t\twithPayloadRequestMetadata(prepared.options, prepared.model) as SimpleStreamOptions,\n\t\t\t);\n\t\t\treturn shouldRecoverTextToolCalls(model) && context.tools?.length\n\t\t\t\t? wrapStreamWithInvokeRecovery(\n\t\t\t\t\t\tinner,\n\t\t\t\t\t\tcontext.tools,\n\t\t\t\t\t\thasKimiTextToolCallRecovery(model)\n\t\t\t\t\t\t\t? { createParser: createXtmlRecoveryStreamParser, protocol: \"kimi-xtml\" }\n\t\t\t\t\t\t\t: undefined,\n\t\t\t\t\t)\n\t\t\t\t: inner;\n\t\t});\n\t}\n\tcompleteSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): Promise<AssistantMessage> {\n\t\treturn this.streamSimple(model, context, options).result();\n\t}\n\tasync login(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential> {\n\t\tconst credential = await this.models.login(providerId, type, interaction);\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t\treturn credential;\n\t}\n\n\tasync logout(providerId: string): Promise<void> {\n\t\tawait this.models.logout(providerId);\n\t\t// Reset credential-dependent compatibility projections before the unconfigured provider is skipped by refresh.\n\t\tthis.recomposeProvider(providerId);\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t}\n\n\tasync reloadConfig(): Promise<void> {\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t}\n\n\tasync refresh(options: ModelsRefreshOptions = {}): Promise<ModelsRefreshResult> {\n\t\tthis.config = await ModelConfig.load(this.modelsPath);\n\t\tthis.configureRadiusProviders();\n\t\tthis.rebuildProviders();\n\t\tconst refreshOptions = {\n\t\t\t...options,\n\t\t\tallowNetwork: options.allowNetwork ?? this.modelNetworkEnabled,\n\t\t};\n\t\t// Published pi-ai builds before ModelsStore returned void and accepted a provider ID.\n\t\t// The fallback keeps source-mode CLI tests working without rebuilding workspace dependencies.\n\t\tconst result = ((await this.models.refresh(refreshOptions)) as ModelsRefreshResult | undefined) ?? {\n\t\t\taborted: refreshOptions.signal?.aborted ?? false,\n\t\t\terrors: new Map(),\n\t\t};\n\t\tthis.updateModelSnapshot();\n\t\ttry {\n\t\t\tawait this.forceRefreshAvailability();\n\t\t} catch {\n\t\t\t// Availability errors are recorded by forceRefreshAvailability; refreshed models remain usable.\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Providers registered after startup missed the create() refresh. Load their catalogs\n\t * under the runtime network policy, bounded like startup, so newly registered models are\n\t * usable without a manual refresh. Offline policy restores from the store only and never\n\t * touches the network.\n\t */\n\tprivate refreshAfterRegistration(): Promise<ModelsRefreshResult> {\n\t\tif (!this.modelNetworkEnabled) return this.refresh({ allowNetwork: false });\n\t\tconst controller = new AbortController();\n\t\tconst timeout = setTimeout(() => controller.abort(), this.modelRefreshTimeoutMs);\n\t\treturn this.refresh({ allowNetwork: true, signal: controller.signal }).finally(() => clearTimeout(timeout));\n\t}\n\n\tregisterNativeProvider(provider: Provider): Promise<ModelsRefreshResult> {\n\t\tif (!provider.id.trim()) throw new Error(\"Provider id must not be empty.\");\n\t\tthis.extensionProviders.delete(provider.id);\n\t\tthis.nativeExtensionProviders.set(provider.id, provider);\n\t\tthis.recomposeProvider(provider.id);\n\t\tthis.updateModelSnapshot();\n\t\treturn this.refreshAfterRegistration();\n\t}\n\n\tregisterProvider(providerId: string, config: ProviderConfigInput): Promise<ModelsRefreshResult> {\n\t\t// Validate the incoming registration on its own, like the legacy registry:\n\t\t// a broken re-registration must throw without touching the stored config.\n\t\tvalidateExtensionProvider(providerId, this.builtins.get(providerId), this.config.getProvider(providerId), config);\n\t\tthis.nativeExtensionProviders.delete(providerId);\n\t\t// Re-registration merges defined values over the previous registration and\n\t\t// preserves undefined ones, matching the legacy ModelRegistry contract.\n\t\tconst previous = this.extensionProviders.get(providerId);\n\t\tconst effective: ProviderConfigInput = { ...previous };\n\t\tfor (const [key, value] of Object.entries(config)) {\n\t\t\tif (value !== undefined) (effective as Record<string, unknown>)[key] = value;\n\t\t}\n\t\tthis.extensionProviders.set(providerId, effective);\n\t\tthis.recomposeProvider(providerId);\n\t\tconst composedOAuth = this.models.getProvider(providerId)?.auth.oauth;\n\t\tif (composedOAuth) this.credentials.registerOAuthProvider(providerId, composedOAuth);\n\t\telse this.credentials.unregisterOAuthProvider(providerId);\n\t\tthis.updateModelSnapshot();\n\t\tif (\n\t\t\tthis.snapshot.storedProviders.has(providerId) ||\n\t\t\tconfiguredRequestAuthStatus(this.config.getProvider(providerId), effective)?.configured\n\t\t) {\n\t\t\tconst configuredProviders = new Set(this.snapshot.configuredProviders).add(providerId);\n\t\t\tconst auth = new Map(this.snapshot.auth);\n\t\t\t// Provisional entry until the async refresh lands; never clobber a real check result.\n\t\t\tif (!auth.get(providerId)) {\n\t\t\t\tauth.set(providerId, {\n\t\t\t\t\ttype: effective.oauth && !effective.apiKey ? \"oauth\" : \"api_key\",\n\t\t\t\t\tsource: \"configured provider\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.snapshot = {\n\t\t\t\t...this.snapshot,\n\t\t\t\tauth,\n\t\t\t\tconfiguredProviders,\n\t\t\t\tavailable: this.snapshot.all.filter((model) => configuredProviders.has(model.provider)),\n\t\t\t};\n\t\t}\n\t\treturn this.refreshAfterRegistration();\n\t}\n\n\tunregisterProvider(providerId: string): void {\n\t\tthis.extensionProviders.delete(providerId);\n\t\tthis.nativeExtensionProviders.delete(providerId);\n\t\tthis.recomposeProvider(providerId);\n\t\tthis.credentials.unregisterOAuthProvider(providerId);\n\t\tthis.updateModelSnapshot();\n\t\tvoid this.refresh({ allowNetwork: false });\n\t}\n}\n"]}
1
+ {"version":3,"file":"model-runtime.js","sourceRoot":"","sources":["../../src/core/model-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAaN,YAAY,EACZ,UAAU,EAIV,WAAW,EAWX,2BAA2B,GAC3B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,sBAAsB,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,WAAW,IAAI,kBAAkB,EAAE,MAAM,m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,CAAC;aACvF,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,EAAE,CAAC;IACxC,CAAC;IAED,kBAAkB,CAAC,UAAkB;QACpC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QACjD,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;QACnC,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,CAAC;IAC5C,CAAC;CACD","sourcesContent":["import { dirname, join } from \"node:path\";\nimport {\n\ttype Api,\n\ttype ApiStreamOptions,\n\ttype AssistantMessage,\n\ttype AssistantMessageEventStream,\n\ttype AuthCheck,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype AuthType,\n\ttype Context,\n\ttype Credential,\n\ttype CredentialInfo,\n\ttype CredentialStore,\n\tcreateModels,\n\tlazyStream,\n\ttype Model,\n\ttype Models,\n\ttype ModelsApiStreamOptions,\n\tModelsError,\n\ttype ModelsRefreshOptions,\n\ttype ModelsRefreshResult,\n\ttype ModelsSimpleStreamOptions,\n\ttype ModelsStore,\n\ttype ModelsStreamTransforms,\n\ttype MutableModels,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n\twrapStreamWithModelRecovery,\n} from \"@earendil-works/pi-ai\";\nimport * as builtinProviderCatalog from \"@earendil-works/pi-ai/providers/all\";\nimport { getAgentDir } from \"../config.ts\";\nimport { AuthStorage as DefaultAuthStorage } from \"./auth-storage.ts\";\nimport { ModelConfig } from \"./model-config.ts\";\nimport { FileModelsStore, InMemoryCodingAgentModelsStore } from \"./models-store.ts\";\nimport {\n\ttype AuthStatus,\n\ttype CompatibilityRequestConfig,\n\tcomposeModelProvider,\n\tconfiguredRequestAuthStatus,\n\ttype ProviderConfigInput,\n\tresolveCompatibilityRequestConfig,\n\tresolveConfiguredModelHeaders,\n\tvalidateExtensionProvider,\n} from \"./provider-composer.ts\";\nimport { withRemoteCatalog } from \"./remote-catalog-provider.ts\";\nimport { RuntimeCredentials } from \"./runtime-credentials.ts\";\n\ninterface ModelRuntimeSnapshot {\n\tall: readonly Model<Api>[];\n\tavailable: readonly Model<Api>[];\n\tconfiguredProviders: ReadonlySet<string>;\n\tstoredProviders: ReadonlySet<string>;\n\tauth: ReadonlyMap<string, AuthCheck | undefined>;\n}\n\nexport interface CreateModelRuntimeOptions {\n\t/** Credential storage. Defaults to the file at authPath. */\n\tcredentials?: CredentialStore;\n\tauthPath?: string;\n\tmodelsPath?: string | null;\n\tmodelsStore?: ModelsStore;\n\tmodelsStorePath?: string;\n\t/** Allow create() to refresh model catalogs over the network. Defaults to false. */\n\tallowModelNetwork?: boolean;\n\t/** Timeout for the create-time network model refresh. */\n\tmodelRefreshTimeoutMs?: number;\n\tcatalogBaseUrl?: string;\n}\n\nexport interface ModelRuntimeAuthOverrides {\n\tapiKey?: string;\n\tenv?: Record<string, string>;\n}\n\nfunction mergeHeaders(\n\tbase: ProviderHeaders | undefined,\n\toverride: ProviderHeaders | undefined,\n): ProviderHeaders | undefined {\n\tif (!base && !override) return undefined;\n\tconst merged = { ...base };\n\tfor (const [name, value] of Object.entries(override ?? {})) {\n\t\tconst lowerName = name.toLowerCase();\n\t\tfor (const existingName of Object.keys(merged)) {\n\t\t\tif (existingName.toLowerCase() === lowerName) delete merged[existingName];\n\t\t}\n\t\tmerged[name] = value;\n\t}\n\treturn merged;\n}\n\nfunction withPayloadRequestMetadata(options: StreamOptions, model: Model<Api>): StreamOptions {\n\tif (!options.onPayload) return options;\n\tconst onPayload = options.onPayload;\n\treturn {\n\t\t...options,\n\t\tonPayload: async (payload, providerModel) =>\n\t\t\tawait onPayload(payload, providerModel, { model, headers: options.headers ?? {} }),\n\t};\n}\n\n/** Configured pi-ai Models collection used by coding-agent and SDK consumers. */\nexport class ModelRuntime implements Models {\n\tprivate readonly models: MutableModels;\n\tprivate readonly credentials: RuntimeCredentials;\n\tprivate readonly defaultBuiltins: ReadonlyMap<string, Provider>;\n\tprivate readonly builtins = new Map<string, Provider>();\n\tprivate readonly nativeExtensionProviders = new Map<string, Provider>();\n\tprivate readonly extensionProviders = new Map<string, ProviderConfigInput>();\n\tprivate readonly compositionErrors = new Map<string, string>();\n\tprivate readonly modelsPath: string | undefined;\n\tprivate readonly modelNetworkEnabled: boolean;\n\tprivate readonly modelRefreshTimeoutMs: number;\n\tprivate config: ModelConfig;\n\tprivate snapshot: ModelRuntimeSnapshot = {\n\t\tall: [],\n\t\tavailable: [],\n\t\tconfiguredProviders: new Set(),\n\t\tstoredProviders: new Set(),\n\t\tauth: new Map(),\n\t};\n\tprivate availabilityRefresh: Promise<void> | undefined;\n\tprivate availabilityInitialized = false;\n\tprivate availabilityError: string | undefined;\n\tprivate constructor(\n\t\tcredentials: RuntimeCredentials,\n\t\tconfig: ModelConfig,\n\t\tmodelsPath: string | undefined,\n\t\tmodelsStore: ModelsStore,\n\t\tproviders: readonly Provider[],\n\t\tmodelNetworkEnabled: boolean,\n\t\tmodelRefreshTimeoutMs: number,\n\t) {\n\t\tthis.credentials = credentials;\n\t\tthis.config = config;\n\t\tthis.modelsPath = modelsPath;\n\t\tthis.modelNetworkEnabled = modelNetworkEnabled;\n\t\tthis.modelRefreshTimeoutMs = modelRefreshTimeoutMs;\n\t\tthis.defaultBuiltins = new Map(providers.map((provider) => [provider.id, provider]));\n\t\tfor (const [providerId, provider] of this.defaultBuiltins) this.builtins.set(providerId, provider);\n\t\tthis.models = createModels({ credentials, modelsStore });\n\t\tthis.rebuildProviders();\n\t}\n\n\tstatic async create(options: CreateModelRuntimeOptions = {}): Promise<ModelRuntime> {\n\t\tconst credentials = new RuntimeCredentials(options.credentials ?? DefaultAuthStorage.create(options.authPath));\n\t\tconst modelsPath =\n\t\t\toptions.modelsPath === null ? undefined : (options.modelsPath ?? join(getAgentDir(), \"models.json\"));\n\t\tconst config = await ModelConfig.load(modelsPath);\n\t\tconst modelsStore =\n\t\t\toptions.modelsStore ??\n\t\t\t(modelsPath\n\t\t\t\t? new FileModelsStore(options.modelsStorePath ?? join(dirname(modelsPath), \"models-store.json\"))\n\t\t\t\t: new InMemoryCodingAgentModelsStore());\n\t\tconst builtinModelDataGeneratedAt = builtinProviderCatalog.getBuiltinModelDataGeneratedAt();\n\t\tconst providers = builtinProviderCatalog\n\t\t\t.builtinProviders()\n\t\t\t.map((provider) =>\n\t\t\t\tprovider.id === \"radius\"\n\t\t\t\t\t? provider\n\t\t\t\t\t: withRemoteCatalog(provider, options.catalogBaseUrl, builtinModelDataGeneratedAt),\n\t\t\t);\n\t\tconst runtime = new ModelRuntime(\n\t\t\tcredentials,\n\t\t\tconfig,\n\t\t\tmodelsPath,\n\t\t\tmodelsStore,\n\t\t\tproviders,\n\t\t\tprocess.env.PI_OFFLINE === undefined && options.allowModelNetwork === true,\n\t\t\toptions.modelRefreshTimeoutMs ?? 15_000,\n\t\t);\n\t\truntime.configureRadiusProviders();\n\t\truntime.rebuildProviders();\n\t\tconst refreshFromNetwork = runtime.modelNetworkEnabled && options.allowModelNetwork === true;\n\t\tconst controller = refreshFromNetwork ? new AbortController() : undefined;\n\t\tconst timeout = controller\n\t\t\t? setTimeout(() => controller.abort(), options.modelRefreshTimeoutMs ?? 15_000)\n\t\t\t: undefined;\n\t\ttry {\n\t\t\tawait runtime.refresh({ allowNetwork: refreshFromNetwork, signal: controller?.signal });\n\t\t} finally {\n\t\t\tif (timeout) clearTimeout(timeout);\n\t\t}\n\t\treturn runtime;\n\t}\n\n\t/** Synchronous compatibility constructor for legacy ModelRegistry callers. */\n\tstatic createSync(options: CreateModelRuntimeOptions = {}): ModelRuntime {\n\t\tconst credentials = new RuntimeCredentials(options.credentials ?? DefaultAuthStorage.create(options.authPath));\n\t\tconst modelsPath =\n\t\t\toptions.modelsPath === null ? undefined : (options.modelsPath ?? join(getAgentDir(), \"models.json\"));\n\t\tconst config = ModelConfig.loadSync(modelsPath);\n\t\tconst modelsStore =\n\t\t\toptions.modelsStore ??\n\t\t\t(modelsPath\n\t\t\t\t? new FileModelsStore(options.modelsStorePath ?? join(dirname(modelsPath), \"models-store.json\"))\n\t\t\t\t: new InMemoryCodingAgentModelsStore());\n\t\tconst providers = builtinProviderCatalog\n\t\t\t.builtinProviders()\n\t\t\t.map((provider) =>\n\t\t\t\tprovider.id === \"radius\" ? provider : withRemoteCatalog(provider, options.catalogBaseUrl),\n\t\t\t);\n\t\tconst runtime = new ModelRuntime(\n\t\t\tcredentials,\n\t\t\tconfig,\n\t\t\tmodelsPath,\n\t\t\tmodelsStore,\n\t\t\tproviders,\n\t\t\toptions.allowModelNetwork ?? false,\n\t\t\toptions.modelRefreshTimeoutMs ?? 15_000,\n\t\t);\n\t\truntime.configureRadiusProviders();\n\t\truntime.rebuildProviders();\n\t\treturn runtime;\n\t}\n\n\tprivate configureRadiusProviders(): void {\n\t\tthis.builtins.clear();\n\t\tfor (const [providerId, provider] of this.defaultBuiltins) this.builtins.set(providerId, provider);\n\t\tfor (const providerId of this.config.getProviderIds()) {\n\t\t\tconst config = this.config.getProvider(providerId);\n\t\t\tif (config?.oauth !== \"radius\" || !config.baseUrl) continue;\n\t\t\tthis.builtins.set(\n\t\t\t\tproviderId,\n\t\t\t\tbuiltinProviderCatalog.radiusProvider({\n\t\t\t\t\tid: providerId,\n\t\t\t\t\tname: config.name ?? providerId,\n\t\t\t\t\tgateway: config.baseUrl.replace(/\\/v1\\/?$/u, \"\"),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t}\n\n\tprivate providerIds(): Set<string> {\n\t\treturn new Set([\n\t\t\t...this.builtins.keys(),\n\t\t\t...this.nativeExtensionProviders.keys(),\n\t\t\t...this.config.getProviderIds(),\n\t\t\t...this.extensionProviders.keys(),\n\t\t]);\n\t}\n\n\tprivate recomposeProvider(providerId: string): void {\n\t\tif (this.config.isProviderDisabled(providerId)) {\n\t\t\tthis.models.deleteProvider(providerId);\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t\treturn;\n\t\t}\n\t\tconst base = this.nativeExtensionProviders.get(providerId) ?? this.builtins.get(providerId);\n\t\tconst extension = this.extensionProviders.get(providerId);\n\t\tif (!base && !this.config.getProvider(providerId) && !extension) {\n\t\t\tthis.models.deleteProvider(providerId);\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t\treturn;\n\t\t}\n\t\tif (base && !this.config.getProvider(providerId) && !extension) {\n\t\t\t// No overlays: use the builtin untouched so its auth/login/stream behavior is exact.\n\t\t\tthis.models.setProvider(base);\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t\treturn;\n\t\t}\n\t\ttry {\n\t\t\tthis.models.setProvider(composeModelProvider(providerId, base, this.config, extension));\n\t\t\tthis.compositionErrors.delete(providerId);\n\t\t} catch (error) {\n\t\t\tthis.compositionErrors.set(providerId, error instanceof Error ? error.message : String(error));\n\t\t\tif (base) this.models.setProvider(base);\n\t\t\telse this.models.deleteProvider(providerId);\n\t\t}\n\t}\n\n\tprivate rebuildProviders(): void {\n\t\tthis.models.clearProviders();\n\t\tthis.compositionErrors.clear();\n\t\tfor (const providerId of this.providerIds()) this.recomposeProvider(providerId);\n\t\tthis.updateModelSnapshot();\n\t}\n\n\tprivate updateModelSnapshot(): void {\n\t\tconst all = [...this.models.getModels()];\n\t\tthis.snapshot = {\n\t\t\t...this.snapshot,\n\t\t\tall,\n\t\t\tavailable: all.filter((model) => this.snapshot.configuredProviders.has(model.provider)),\n\t\t};\n\t}\n\n\tprivate async runAvailabilityRefresh(): Promise<void> {\n\t\tconst providers = this.models.getProviders();\n\t\tconst [available, checks, credentials] = await Promise.all([\n\t\t\tthis.models.getAvailable(),\n\t\t\tPromise.all(\n\t\t\t\tproviders.map(\n\t\t\t\t\tasync (provider): Promise<[string, AuthCheck | undefined]> => [\n\t\t\t\t\t\tprovider.id,\n\t\t\t\t\t\tawait this.models.checkAuth(provider.id),\n\t\t\t\t\t],\n\t\t\t\t),\n\t\t\t),\n\t\t\tthis.credentials.list(),\n\t\t]);\n\t\tconst auth = new Map(checks);\n\t\tconst configuredProviders = new Set(\n\t\t\tchecks\n\t\t\t\t.filter((entry): entry is [string, AuthCheck] => entry[1] !== undefined)\n\t\t\t\t.map(([providerId]) => providerId),\n\t\t);\n\t\tthis.snapshot = {\n\t\t\tall: [...this.models.getModels()],\n\t\t\tavailable: [...available],\n\t\t\tconfiguredProviders,\n\t\t\tstoredProviders: new Set(credentials.map((entry) => entry.providerId)),\n\t\t\tauth,\n\t\t};\n\t\tthis.availabilityInitialized = true;\n\t\tthis.availabilityError = undefined;\n\t}\n\n\tprivate queueAvailabilityRefresh(after: Promise<void> | undefined): Promise<void> {\n\t\tconst refresh = (after ?? Promise.resolve()).catch(() => {}).then(() => this.runAvailabilityRefresh());\n\t\tconst recorded = refresh.catch((error) => {\n\t\t\tthis.availabilityError = error instanceof Error ? error.message : String(error);\n\t\t\tthrow error;\n\t\t});\n\t\tconst tracked = recorded.finally(() => {\n\t\t\tif (this.availabilityRefresh === tracked) this.availabilityRefresh = undefined;\n\t\t});\n\t\tthis.availabilityRefresh = tracked;\n\t\treturn tracked;\n\t}\n\n\t/** Coalesce concurrent readers onto the pending refresh. */\n\tprivate refreshAvailability(): Promise<void> {\n\t\treturn this.availabilityRefresh ?? this.queueAvailabilityRefresh(undefined);\n\t}\n\n\t/** Mutations must not observe an in-flight refresh started before them. */\n\tprivate forceRefreshAvailability(): Promise<void> {\n\t\treturn this.queueAvailabilityRefresh(this.availabilityRefresh);\n\t}\n\n\tgetProviders(): readonly Provider[] {\n\t\treturn this.models.getProviders();\n\t}\n\tgetProvider(providerId: string): Provider | undefined {\n\t\treturn this.models.getProvider(providerId);\n\t}\n\tgetModels(providerId?: string): readonly Model<Api>[] {\n\t\treturn this.models.getModels(providerId);\n\t}\n\tgetModel(providerId: string, modelId: string): Model<Api> | undefined {\n\t\treturn this.models.getModel(providerId, modelId);\n\t}\n\n\tasync checkAuth(providerId: string): Promise<AuthCheck | undefined> {\n\t\treturn this.models.checkAuth(providerId);\n\t}\n\tasync getAvailable(providerId?: string): Promise<readonly Model<Api>[]> {\n\t\tif (providerId) {\n\t\t\tif (this.availabilityRefresh) {\n\t\t\t\tawait this.availabilityRefresh;\n\t\t\t\treturn this.snapshot.available.filter((model) => model.provider === providerId);\n\t\t\t}\n\t\t\ttry {\n\t\t\t\treturn await this.models.getAvailable(providerId);\n\t\t\t} catch (error) {\n\t\t\t\tthis.availabilityError = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t\tawait this.refreshAvailability();\n\t\treturn this.snapshot.available;\n\t}\n\n\tgetAvailableSnapshot(): readonly Model<Api>[] {\n\t\treturn this.snapshot.available;\n\t}\n\n\t/** True only when the most recent availability refresh completed without error. */\n\thasFreshAvailabilitySnapshot(): boolean {\n\t\treturn this.availabilityInitialized && this.availabilityError === undefined;\n\t}\n\n\thasAvailabilitySnapshot(): boolean {\n\t\treturn this.availabilityInitialized;\n\t}\n\n\tgetError(): string | undefined {\n\t\tconst errors: string[] = [];\n\t\tconst configError = this.config.getError();\n\t\tif (configError) errors.push(configError);\n\t\tfor (const [providerId, error] of this.compositionErrors) {\n\t\t\terrors.push(`Provider \"${providerId}\": ${error}`);\n\t\t}\n\t\tif (this.availabilityError) errors.push(`Availability refresh: ${this.availabilityError}`);\n\t\treturn errors.length > 0 ? errors.join(\"\\n\\n\") : undefined;\n\t}\n\n\tgetRegisteredProviderConfig(providerId: string): ProviderConfigInput | undefined {\n\t\treturn this.extensionProviders.get(providerId);\n\t}\n\n\tgetRegisteredProviderIds(): readonly string[] {\n\t\treturn [...new Set([...this.extensionProviders.keys(), ...this.nativeExtensionProviders.keys()])];\n\t}\n\n\tgetRegisteredNativeProvider(providerId: string): Provider | undefined {\n\t\treturn this.nativeExtensionProviders.get(providerId);\n\t}\n\n\t/** @internal Compatibility fallback for ModelRegistry when provider auth is unconfigured. */\n\tgetCompatibilityRequestConfig(model: Model<Api>, env?: Record<string, string>): CompatibilityRequestConfig {\n\t\treturn resolveCompatibilityRequestConfig(\n\t\t\tmodel,\n\t\t\tthis.config.getProvider(model.provider),\n\t\t\tthis.extensionProviders.get(model.provider),\n\t\t\tenv,\n\t\t);\n\t}\n\n\tisUsingOAuth(providerId: string): boolean {\n\t\treturn this.snapshot.auth.get(providerId)?.type === \"oauth\";\n\t}\n\n\thasConfiguredAuth(providerId: string): boolean {\n\t\treturn this.snapshot.configuredProviders.has(providerId);\n\t}\n\n\tgetAuth(providerId: string, overrides?: ModelRuntimeAuthOverrides): Promise<AuthResult | undefined>;\n\tgetAuth(model: Model<Api>, overrides?: ModelRuntimeAuthOverrides): Promise<AuthResult | undefined>;\n\tasync getAuth(\n\t\tproviderOrModel: string | Model<Api>,\n\t\toverrides: ModelRuntimeAuthOverrides = {},\n\t): Promise<AuthResult | undefined> {\n\t\tif (typeof providerOrModel === \"string\") return this.models.getAuth(providerOrModel, overrides);\n\t\tconst resolution = await this.models.getAuth(providerOrModel, overrides);\n\t\tif (!resolution) return undefined;\n\t\tconst configuredHeaders = resolveConfiguredModelHeaders(\n\t\t\tproviderOrModel,\n\t\t\tthis.config.getProvider(providerOrModel.provider),\n\t\t\tthis.extensionProviders.get(providerOrModel.provider),\n\t\t\t{ ...(resolution.env ?? {}), ...(overrides.env ?? {}) },\n\t\t);\n\t\treturn {\n\t\t\t...resolution,\n\t\t\tauth: {\n\t\t\t\t...resolution.auth,\n\t\t\t\theaders: mergeHeaders(resolution.auth.headers, configuredHeaders),\n\t\t\t},\n\t\t};\n\t}\n\n\tasync setRuntimeApiKey(\n\t\tproviderId: string,\n\t\tapiKey: string,\n\t\trefreshOptions: ModelsRefreshOptions = {},\n\t): Promise<void> {\n\t\tthis.credentials.setRuntimeApiKey(providerId, apiKey);\n\t\tconst auth = new Map(this.snapshot.auth).set(providerId, { type: \"api_key\", source: \"runtime API key\" });\n\t\tconst configuredProviders = new Set(this.snapshot.configuredProviders).add(providerId);\n\t\tconst storedProviders = new Set(this.snapshot.storedProviders).add(providerId);\n\t\tthis.snapshot = {\n\t\t\t...this.snapshot,\n\t\t\tauth,\n\t\t\tconfiguredProviders,\n\t\t\tstoredProviders,\n\t\t\tavailable: this.snapshot.all.filter((model) => configuredProviders.has(model.provider)),\n\t\t};\n\t\tawait this.refresh(refreshOptions);\n\t}\n\n\tasync removeRuntimeApiKey(providerId: string): Promise<void> {\n\t\tthis.credentials.removeRuntimeApiKey(providerId);\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t}\n\n\tlistCredentials(): Promise<readonly CredentialInfo[]> {\n\t\treturn this.credentials.list();\n\t}\n\n\tgetProviderAuthStatus(providerId: string): AuthStatus {\n\t\tif (this.credentials.hasRuntimeApiKey(providerId)) return { configured: true, source: \"runtime\" };\n\t\tif (this.snapshot.storedProviders.has(providerId)) return { configured: true, source: \"stored\" };\n\t\tconst configured = configuredRequestAuthStatus(\n\t\t\tthis.config.getProvider(providerId),\n\t\t\tthis.extensionProviders.get(providerId),\n\t\t);\n\t\tif (configured) return configured;\n\t\tconst check = this.snapshot.auth.get(providerId);\n\t\treturn check ? { configured: true, source: \"environment\", label: check.source } : { configured: false };\n\t}\n\n\tprivate async prepareRequest(\n\t\tmodel: Model<Api>,\n\t\toptions: (StreamOptions & ModelsStreamTransforms) | undefined,\n\t): Promise<{ provider: Provider; model: Model<Api>; options: StreamOptions }> {\n\t\tconst provider = this.models.getProvider(model.provider);\n\t\tif (!provider) throw new ModelsError(\"provider\", `Unknown provider: ${model.provider}`);\n\t\tconst resolution = await this.getAuth(model, { apiKey: options?.apiKey, env: options?.env });\n\t\tif (!resolution) throw new ModelsError(\"auth\", `Provider is not configured: ${model.provider}`);\n\n\t\tconst { transformHeaders, ...providerOptions } = options ?? {};\n\t\tlet headers = mergeHeaders(resolution.auth.headers, providerOptions.headers);\n\t\tif (transformHeaders) headers = await transformHeaders(headers ?? {});\n\t\tconst compatibility = this.getCompatibilityRequestConfig(model, resolution.env);\n\t\tconst extraBody =\n\t\t\tcompatibility.extraBody || providerOptions.extraBody\n\t\t\t\t? { ...compatibility.extraBody, ...providerOptions.extraBody }\n\t\t\t\t: undefined;\n\t\tconst env =\n\t\t\tresolution.env || providerOptions.env\n\t\t\t\t? { ...(resolution.env ?? {}), ...(providerOptions.env ?? {}) }\n\t\t\t\t: undefined;\n\t\tconst upstreamModelId = compatibility.upstreamModelId;\n\t\tconst requestModel =\n\t\t\tresolution.auth.baseUrl || upstreamModelId\n\t\t\t\t? {\n\t\t\t\t\t\t...model,\n\t\t\t\t\t\t...(upstreamModelId ? { id: upstreamModelId } : {}),\n\t\t\t\t\t\t...(resolution.auth.baseUrl ? { baseUrl: resolution.auth.baseUrl } : {}),\n\t\t\t\t\t}\n\t\t\t\t: model;\n\t\treturn {\n\t\t\tprovider,\n\t\t\tmodel: requestModel,\n\t\t\toptions: {\n\t\t\t\t...providerOptions,\n\t\t\t\tapiKey: providerOptions.apiKey ?? resolution.auth.apiKey,\n\t\t\t\theaders,\n\t\t\t\textraBody,\n\t\t\t\tenv,\n\t\t\t},\n\t\t};\n\t}\n\n\tstream<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst prepared = await this.prepareRequest(\n\t\t\t\tmodel,\n\t\t\t\toptions as (StreamOptions & ModelsStreamTransforms) | undefined,\n\t\t\t);\n\t\t\tconst inner = prepared.provider.stream(\n\t\t\t\tprepared.model as Model<TApi>,\n\t\t\t\tcontext,\n\t\t\t\twithPayloadRequestMetadata(prepared.options, prepared.model) as ApiStreamOptions<TApi>,\n\t\t\t);\n\t\t\treturn wrapStreamWithModelRecovery(inner, model, context.tools ?? []);\n\t\t});\n\t}\n\n\tcomplete<TApi extends Api>(\n\t\tmodel: Model<TApi>,\n\t\tcontext: Context,\n\t\toptions?: ModelsApiStreamOptions<TApi>,\n\t): Promise<AssistantMessage> {\n\t\treturn this.stream(model, context, options).result();\n\t}\n\tstreamSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): AssistantMessageEventStream {\n\t\treturn lazyStream(model, async () => {\n\t\t\tconst prepared = await this.prepareRequest(model, options);\n\t\t\tconst inner = prepared.provider.streamSimple(\n\t\t\t\tprepared.model,\n\t\t\t\tcontext,\n\t\t\t\twithPayloadRequestMetadata(prepared.options, prepared.model) as SimpleStreamOptions,\n\t\t\t);\n\t\t\treturn wrapStreamWithModelRecovery(inner, model, context.tools ?? []);\n\t\t});\n\t}\n\tcompleteSimple(model: Model<Api>, context: Context, options?: ModelsSimpleStreamOptions): Promise<AssistantMessage> {\n\t\treturn this.streamSimple(model, context, options).result();\n\t}\n\tasync login(providerId: string, type: AuthType, interaction: AuthInteraction): Promise<Credential> {\n\t\tconst credential = await this.models.login(providerId, type, interaction);\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t\treturn credential;\n\t}\n\n\tasync logout(providerId: string): Promise<void> {\n\t\tawait this.models.logout(providerId);\n\t\t// Reset credential-dependent compatibility projections before the unconfigured provider is skipped by refresh.\n\t\tthis.recomposeProvider(providerId);\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t}\n\n\tasync reloadConfig(): Promise<void> {\n\t\tawait this.refresh({ allowNetwork: this.modelNetworkEnabled });\n\t}\n\n\tasync refresh(options: ModelsRefreshOptions = {}): Promise<ModelsRefreshResult> {\n\t\tthis.config = await ModelConfig.load(this.modelsPath);\n\t\tthis.configureRadiusProviders();\n\t\tthis.rebuildProviders();\n\t\tconst refreshOptions = {\n\t\t\t...options,\n\t\t\tallowNetwork: options.allowNetwork ?? this.modelNetworkEnabled,\n\t\t};\n\t\t// Published pi-ai builds before ModelsStore returned void and accepted a provider ID.\n\t\t// The fallback keeps source-mode CLI tests working without rebuilding workspace dependencies.\n\t\tconst result = ((await this.models.refresh(refreshOptions)) as ModelsRefreshResult | undefined) ?? {\n\t\t\taborted: refreshOptions.signal?.aborted ?? false,\n\t\t\terrors: new Map(),\n\t\t};\n\t\tthis.updateModelSnapshot();\n\t\ttry {\n\t\t\tawait this.forceRefreshAvailability();\n\t\t} catch {\n\t\t\t// Availability errors are recorded by forceRefreshAvailability; refreshed models remain usable.\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Providers registered after startup missed the create() refresh. Load their catalogs\n\t * under the runtime network policy, bounded like startup, so newly registered models are\n\t * usable without a manual refresh. Offline policy restores from the store only and never\n\t * touches the network.\n\t */\n\tprivate refreshAfterRegistration(): Promise<ModelsRefreshResult> {\n\t\tif (!this.modelNetworkEnabled) return this.refresh({ allowNetwork: false });\n\t\tconst controller = new AbortController();\n\t\tconst timeout = setTimeout(() => controller.abort(), this.modelRefreshTimeoutMs);\n\t\treturn this.refresh({ allowNetwork: true, signal: controller.signal }).finally(() => clearTimeout(timeout));\n\t}\n\n\tregisterNativeProvider(provider: Provider): Promise<ModelsRefreshResult> {\n\t\tif (!provider.id.trim()) throw new Error(\"Provider id must not be empty.\");\n\t\tthis.extensionProviders.delete(provider.id);\n\t\tthis.nativeExtensionProviders.set(provider.id, provider);\n\t\tthis.recomposeProvider(provider.id);\n\t\tthis.updateModelSnapshot();\n\t\treturn this.refreshAfterRegistration();\n\t}\n\n\tregisterProvider(providerId: string, config: ProviderConfigInput): Promise<ModelsRefreshResult> {\n\t\t// Validate the incoming registration on its own, like the legacy registry:\n\t\t// a broken re-registration must throw without touching the stored config.\n\t\tvalidateExtensionProvider(providerId, this.builtins.get(providerId), this.config.getProvider(providerId), config);\n\t\tthis.nativeExtensionProviders.delete(providerId);\n\t\t// Re-registration merges defined values over the previous registration and\n\t\t// preserves undefined ones, matching the legacy ModelRegistry contract.\n\t\tconst previous = this.extensionProviders.get(providerId);\n\t\tconst effective: ProviderConfigInput = { ...previous };\n\t\tfor (const [key, value] of Object.entries(config)) {\n\t\t\tif (value !== undefined) (effective as Record<string, unknown>)[key] = value;\n\t\t}\n\t\tthis.extensionProviders.set(providerId, effective);\n\t\tthis.recomposeProvider(providerId);\n\t\tconst composedOAuth = this.models.getProvider(providerId)?.auth.oauth;\n\t\tif (composedOAuth) this.credentials.registerOAuthProvider(providerId, composedOAuth);\n\t\telse this.credentials.unregisterOAuthProvider(providerId);\n\t\tthis.updateModelSnapshot();\n\t\tif (\n\t\t\tthis.snapshot.storedProviders.has(providerId) ||\n\t\t\tconfiguredRequestAuthStatus(this.config.getProvider(providerId), effective)?.configured\n\t\t) {\n\t\t\tconst configuredProviders = new Set(this.snapshot.configuredProviders).add(providerId);\n\t\t\tconst auth = new Map(this.snapshot.auth);\n\t\t\t// Provisional entry until the async refresh lands; never clobber a real check result.\n\t\t\tif (!auth.get(providerId)) {\n\t\t\t\tauth.set(providerId, {\n\t\t\t\t\ttype: effective.oauth && !effective.apiKey ? \"oauth\" : \"api_key\",\n\t\t\t\t\tsource: \"configured provider\",\n\t\t\t\t});\n\t\t\t}\n\t\t\tthis.snapshot = {\n\t\t\t\t...this.snapshot,\n\t\t\t\tauth,\n\t\t\t\tconfiguredProviders,\n\t\t\t\tavailable: this.snapshot.all.filter((model) => configuredProviders.has(model.provider)),\n\t\t\t};\n\t\t}\n\t\treturn this.refreshAfterRegistration();\n\t}\n\n\tunregisterProvider(providerId: string): void {\n\t\tthis.extensionProviders.delete(providerId);\n\t\tthis.nativeExtensionProviders.delete(providerId);\n\t\tthis.recomposeProvider(providerId);\n\t\tthis.credentials.unregisterOAuthProvider(providerId);\n\t\tthis.updateModelSnapshot();\n\t\tvoid this.refresh({ allowNetwork: false });\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-config-value.d.ts","sourceRoot":"","sources":["../../src/core/resolve-config-value.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAUpC;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EAC3C,WAAW,EAAE,MAAM,EACnB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAOpC;AAED,kEAAkE;AAClE,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
@@ -6,6 +6,14 @@ import { execSync, spawnSync } from "child_process";
6
6
  import { getShellConfig } from "../utils/shell.js";
7
7
  // Cache for shell command results (persists for process lifetime)
8
8
  const commandResultCache = new Map();
9
+ // Credential helper commands (auth brokers like `omp token …`) are cold-started on
10
+ // every invocation and can fail transiently — broker lock contention, a slow spawn
11
+ // under load, an OAuth refresh racing another process. A single failed attempt must
12
+ // not read as "credential gone": callers escalate an unresolved API key to a
13
+ // hard-error provider ejection, so one blip would kick the session off its model
14
+ // without any retry. Retry with a short backoff before giving up.
15
+ const COMMAND_EXECUTION_MAX_ATTEMPTS = 3;
16
+ const COMMAND_EXECUTION_BACKOFF_MS = [250, 1000];
9
17
  const ENV_VAR_NAME_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
10
18
  const ENV_VAR_NAME_PREFIX_RE = /^[A-Za-z_][A-Za-z0-9_]*/;
11
19
  function appendLiteral(parts, value) {
@@ -173,7 +181,10 @@ function executeWithDefaultShell(command, env) {
173
181
  return undefined;
174
182
  }
175
183
  }
176
- function executeCommandUncached(commandConfig, env) {
184
+ function sleepBlocking(milliseconds) {
185
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
186
+ }
187
+ function executeCommandOnce(commandConfig, env) {
177
188
  const command = commandConfig.slice(1);
178
189
  return process.platform === "win32"
179
190
  ? (() => {
@@ -182,6 +193,17 @@ function executeCommandUncached(commandConfig, env) {
182
193
  })()
183
194
  : executeWithDefaultShell(command, env);
184
195
  }
196
+ function executeCommandUncached(commandConfig, env) {
197
+ for (let attempt = 0; attempt < COMMAND_EXECUTION_MAX_ATTEMPTS; attempt++) {
198
+ const value = executeCommandOnce(commandConfig, env);
199
+ if (value !== undefined)
200
+ return value;
201
+ const backoffMs = COMMAND_EXECUTION_BACKOFF_MS[attempt];
202
+ if (backoffMs !== undefined)
203
+ sleepBlocking(backoffMs);
204
+ }
205
+ return undefined;
206
+ }
185
207
  function executeCommand(commandConfig) {
186
208
  if (commandResultCache.has(commandConfig)) {
187
209
  return commandResultCache.get(commandConfig);