apex-code 0.3.0 → 0.5.0

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 (213) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/dist/client/transcript.d.ts.map +1 -1
  3. package/dist/client/transcript.js +1 -1
  4. package/dist/client/transcript.js.map +1 -1
  5. package/dist/core/agent-session-services.d.ts.map +1 -1
  6. package/dist/core/agent-session-services.js +2 -1
  7. package/dist/core/agent-session-services.js.map +1 -1
  8. package/dist/core/delegation/runtime.d.ts.map +1 -1
  9. package/dist/core/delegation/runtime.js +2 -2
  10. package/dist/core/delegation/runtime.js.map +1 -1
  11. package/dist/core/durable-state/daemon.d.ts.map +1 -1
  12. package/dist/core/durable-state/daemon.js +1 -1
  13. package/dist/core/durable-state/daemon.js.map +1 -1
  14. package/dist/core/extensions/types.d.ts +1 -1
  15. package/dist/core/extensions/types.d.ts.map +1 -1
  16. package/dist/core/extensions/types.js.map +1 -1
  17. package/dist/core/keybindings.d.ts +1 -1
  18. package/dist/core/keybindings.d.ts.map +1 -1
  19. package/dist/core/keybindings.js.map +1 -1
  20. package/dist/core/mcp/mcp-tool.d.ts.map +1 -1
  21. package/dist/core/mcp/mcp-tool.js +2 -4
  22. package/dist/core/mcp/mcp-tool.js.map +1 -1
  23. package/dist/core/mcp/oauth/authorize.d.ts.map +1 -1
  24. package/dist/core/mcp/oauth/authorize.js +7 -2
  25. package/dist/core/mcp/oauth/authorize.js.map +1 -1
  26. package/dist/core/mcp/runtime.d.ts +2 -2
  27. package/dist/core/mcp/runtime.d.ts.map +1 -1
  28. package/dist/core/mcp/runtime.js +8 -3
  29. package/dist/core/mcp/runtime.js.map +1 -1
  30. package/dist/core/permissions/store.d.ts +7 -2
  31. package/dist/core/permissions/store.d.ts.map +1 -1
  32. package/dist/core/permissions/store.js +6 -1
  33. package/dist/core/permissions/store.js.map +1 -1
  34. package/dist/core/project-resources.d.ts +12 -0
  35. package/dist/core/project-resources.d.ts.map +1 -1
  36. package/dist/core/project-resources.js +19 -0
  37. package/dist/core/project-resources.js.map +1 -1
  38. package/dist/core/provider-composer.d.ts.map +1 -1
  39. package/dist/core/provider-composer.js +10 -1
  40. package/dist/core/provider-composer.js.map +1 -1
  41. package/dist/core/resource-loader.d.ts +6 -0
  42. package/dist/core/resource-loader.d.ts.map +1 -1
  43. package/dist/core/resource-loader.js +9 -3
  44. package/dist/core/resource-loader.js.map +1 -1
  45. package/dist/core/sdk.d.ts +1 -1
  46. package/dist/core/sdk.d.ts.map +1 -1
  47. package/dist/core/sdk.js +3 -3
  48. package/dist/core/sdk.js.map +1 -1
  49. package/dist/core/settings-manager.d.ts +16 -3
  50. package/dist/core/settings-manager.d.ts.map +1 -1
  51. package/dist/core/settings-manager.js +39 -16
  52. package/dist/core/settings-manager.js.map +1 -1
  53. package/dist/core/tools/bash.d.ts +11 -7
  54. package/dist/core/tools/bash.d.ts.map +1 -1
  55. package/dist/core/tools/bash.js +37 -46
  56. package/dist/core/tools/bash.js.map +1 -1
  57. package/dist/core/tools/delegate.d.ts.map +1 -1
  58. package/dist/core/tools/delegate.js +2 -2
  59. package/dist/core/tools/delegate.js.map +1 -1
  60. package/dist/core/tools/edit.d.ts.map +1 -1
  61. package/dist/core/tools/edit.js +3 -3
  62. package/dist/core/tools/edit.js.map +1 -1
  63. package/dist/core/tools/find.d.ts.map +1 -1
  64. package/dist/core/tools/find.js +4 -4
  65. package/dist/core/tools/find.js.map +1 -1
  66. package/dist/core/tools/grep.d.ts.map +1 -1
  67. package/dist/core/tools/grep.js +4 -4
  68. package/dist/core/tools/grep.js.map +1 -1
  69. package/dist/core/tools/ls.d.ts.map +1 -1
  70. package/dist/core/tools/ls.js +4 -4
  71. package/dist/core/tools/ls.js.map +1 -1
  72. package/dist/core/tools/path-utils.d.ts +9 -0
  73. package/dist/core/tools/path-utils.d.ts.map +1 -1
  74. package/dist/core/tools/path-utils.js +235 -10
  75. package/dist/core/tools/path-utils.js.map +1 -1
  76. package/dist/core/tools/read.d.ts.map +1 -1
  77. package/dist/core/tools/read.js +11 -8
  78. package/dist/core/tools/read.js.map +1 -1
  79. package/dist/core/tools/write.d.ts.map +1 -1
  80. package/dist/core/tools/write.js +7 -8
  81. package/dist/core/tools/write.js.map +1 -1
  82. package/dist/core/workspace/state.d.ts.map +1 -1
  83. package/dist/core/workspace/state.js +1 -1
  84. package/dist/core/workspace/state.js.map +1 -1
  85. package/dist/extensions/llama/ui.d.ts.map +1 -1
  86. package/dist/extensions/llama/ui.js +3 -2
  87. package/dist/extensions/llama/ui.js.map +1 -1
  88. package/dist/main.d.ts.map +1 -1
  89. package/dist/main.js +3 -1
  90. package/dist/main.js.map +1 -1
  91. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  92. package/dist/modes/interactive/components/assistant-message.js +0 -10
  93. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  94. package/dist/modes/interactive/components/autocomplete-source.d.ts +8 -0
  95. package/dist/modes/interactive/components/autocomplete-source.d.ts.map +1 -0
  96. package/dist/modes/interactive/components/autocomplete-source.js +23 -0
  97. package/dist/modes/interactive/components/autocomplete-source.js.map +1 -0
  98. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  99. package/dist/modes/interactive/components/bash-execution.js +6 -4
  100. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  101. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  102. package/dist/modes/interactive/components/bordered-loader.js +1 -1
  103. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  104. package/dist/modes/interactive/components/composer-dock.d.ts +12 -0
  105. package/dist/modes/interactive/components/composer-dock.d.ts.map +1 -0
  106. package/dist/modes/interactive/components/composer-dock.js +24 -0
  107. package/dist/modes/interactive/components/composer-dock.js.map +1 -0
  108. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  109. package/dist/modes/interactive/components/config-selector.js +11 -9
  110. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  111. package/dist/modes/interactive/components/diff.d.ts.map +1 -1
  112. package/dist/modes/interactive/components/diff.js +2 -2
  113. package/dist/modes/interactive/components/diff.js.map +1 -1
  114. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  115. package/dist/modes/interactive/components/extension-editor.js +9 -9
  116. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  117. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  118. package/dist/modes/interactive/components/extension-input.js +9 -5
  119. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  120. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  121. package/dist/modes/interactive/components/extension-selector.js +11 -10
  122. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  123. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  124. package/dist/modes/interactive/components/first-time-setup.js +6 -6
  125. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  126. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  127. package/dist/modes/interactive/components/footer.js +8 -3
  128. package/dist/modes/interactive/components/footer.js.map +1 -1
  129. package/dist/modes/interactive/components/keybinding-hints.d.ts +21 -0
  130. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  131. package/dist/modes/interactive/components/keybinding-hints.js +34 -0
  132. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  133. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  134. package/dist/modes/interactive/components/login-dialog.js +27 -23
  135. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  136. package/dist/modes/interactive/components/model-selector.d.ts +1 -1
  137. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  138. package/dist/modes/interactive/components/model-selector.js +14 -18
  139. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  140. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  141. package/dist/modes/interactive/components/oauth-selector.js +7 -6
  142. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  143. package/dist/modes/interactive/components/permission-preview.d.ts.map +1 -1
  144. package/dist/modes/interactive/components/permission-preview.js +3 -3
  145. package/dist/modes/interactive/components/permission-preview.js.map +1 -1
  146. package/dist/modes/interactive/components/prompt-input.d.ts +12 -0
  147. package/dist/modes/interactive/components/prompt-input.d.ts.map +1 -0
  148. package/dist/modes/interactive/components/prompt-input.js +18 -0
  149. package/dist/modes/interactive/components/prompt-input.js.map +1 -0
  150. package/dist/modes/interactive/components/scoped-models-selector.d.ts +1 -1
  151. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  152. package/dist/modes/interactive/components/scoped-models-selector.js +4 -3
  153. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  154. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  155. package/dist/modes/interactive/components/session-selector.js +26 -19
  156. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  157. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  158. package/dist/modes/interactive/components/settings-selector.js +39 -6
  159. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  160. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  161. package/dist/modes/interactive/components/settings-submenu.js +8 -6
  162. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  163. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  164. package/dist/modes/interactive/components/thinking-selector.js +10 -5
  165. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  166. package/dist/modes/interactive/components/tool-execution.d.ts +1 -11
  167. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  168. package/dist/modes/interactive/components/tool-execution.js +9 -38
  169. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  170. package/dist/modes/interactive/components/tool-panel.d.ts.map +1 -1
  171. package/dist/modes/interactive/components/tool-panel.js +7 -2
  172. package/dist/modes/interactive/components/tool-panel.js.map +1 -1
  173. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  174. package/dist/modes/interactive/components/tree-selector.js +9 -5
  175. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  176. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  177. package/dist/modes/interactive/components/trust-selector.js +11 -11
  178. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  179. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  180. package/dist/modes/interactive/components/user-message-selector.js +2 -2
  181. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  182. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  183. package/dist/modes/interactive/components/user-message.js +6 -3
  184. package/dist/modes/interactive/components/user-message.js.map +1 -1
  185. package/dist/modes/interactive/interactive-mode.d.ts +7 -2
  186. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  187. package/dist/modes/interactive/interactive-mode.js +65 -65
  188. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  189. package/dist/modes/print-mode.d.ts.map +1 -1
  190. package/dist/modes/print-mode.js +49 -23
  191. package/dist/modes/print-mode.js.map +1 -1
  192. package/dist/tsconfig.json +3 -0
  193. package/dist/utils/clipboard-image.d.ts.map +1 -1
  194. package/dist/utils/clipboard-image.js +1 -1
  195. package/dist/utils/clipboard-image.js.map +1 -1
  196. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  197. package/dist/utils/syntax-highlight.js +22 -22
  198. package/dist/utils/syntax-highlight.js.map +1 -1
  199. package/docs/json.md +36 -0
  200. package/docs/models.md +1 -1
  201. package/docs/settings.md +1 -1
  202. package/examples/extensions/gondolin/package-lock.json +3 -3
  203. package/examples/extensions/minimal-mode.ts +6 -6
  204. package/examples/extensions/sandbox/package-lock.json +4 -4
  205. package/examples/extensions/sandbox/package.json +1 -1
  206. package/examples/sdk/10-settings.ts +2 -2
  207. package/examples/sdk/README.md +1 -1
  208. package/npm-shrinkwrap.json +19 -34
  209. package/package.json +6 -6
  210. package/dist/modes/interactive/components/message-spine.d.ts +0 -14
  211. package/dist/modes/interactive/components/message-spine.d.ts.map +0 -1
  212. package/dist/modes/interactive/components/message-spine.js +0 -19
  213. package/dist/modes/interactive/components/message-spine.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"project-resources.d.ts","sourceRoot":"","sources":["../../src/core/project-resources.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,MAAM,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,kBAAkB,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,wBAAwB,CAAC;CAC7C;AAED,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAC3D,eAAO,MAAM,8BAA8B,2BAA2B,CAAC;AACvE,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAC3C,eAAO,MAAM,uBAAuB,cAAc,CAAC;AAEnD,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAY9C,CAAC;AAEX,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,MAAM,CAElF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAI7D;AAED,qEAAqE;AACrE,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3E","sourcesContent":["import { join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\n\n/**\n * The single list of project-controlled resources a repository can supply, and the only\n * place their paths are built.\n *\n * Both halves of the trust boundary resolve through here: the loaders ask for a path,\n * and `hasTrustRequiringProjectResources` asks the same question of the same entries.\n * Before this existed the two were independent, and four resources were read without\n * ever reaching the classifier (`permissions.json`, `permissions.local.json`, `agents/`,\n * and `.mcp.json`), so a cloned repository supplying one of them was classified trusted\n * and the guard that drops untrusted scopes was satisfied rather than triggered.\n *\n * Relocating the list is not enough on its own. A loader that builds `join(cwd,\n * \".apex-code\", …)` by hand diverges the moment `CONFIG_DIR_NAME` is overridden, which\n * reintroduces the same bypass with no test failing, so the path builders below are the\n * supported way to reach a project resource. See\n * `docs/specs/2026-09-11-trust-classification-and-proof-integrity.md`.\n */\n\n/**\n * Where an entry's `name` is resolved from.\n *\n * `config-dir` resolves under `<cwd>/<CONFIG_DIR_NAME>`. `root` resolves at `<cwd>`,\n * which is what lets `.mcp.json` reach the classifier at all.\n *\n * The ancestor `.agents/skills` walk is deliberately not a scope here. It has no fixed\n * depth and one path under the user's home is exempt, so it lives in the classifier\n * rather than as an entry a caller could resolve to a single path. Adding an `ancestor`\n * member without implementing the walk would let an entry silently resolve at `cwd`\n * only, which is the narrowing this registry exists to prevent.\n */\nexport type ProjectResourceScope = \"config-dir\" | \"root\";\n\n/**\n * How presence maps to authority.\n *\n * `presence` means existing is enough. `permission-scope` means the file is parsed and\n * only grants authority when it carries a rule or a mode, because a `{}` permissions\n * file confers nothing and this repository ships one. A prompt carrying no decision\n * teaches people to dismiss prompts.\n */\nexport type ProjectResourceAuthority = \"presence\" | \"permission-scope\";\n\nexport interface ProjectResource {\n\t/** Path relative to the entry's scope root. A single path segment. */\n\treadonly name: string;\n\treadonly scope: ProjectResourceScope;\n\treadonly authority: ProjectResourceAuthority;\n}\n\nexport const PROJECT_PERMISSIONS_FILE = \"permissions.json\";\nexport const PROJECT_LOCAL_PERMISSIONS_FILE = \"permissions.local.json\";\nexport const PROJECT_AGENTS_DIR = \"agents\";\nexport const PROJECT_MCP_CONFIG_FILE = \".mcp.json\";\n\nexport const PROJECT_RESOURCES: readonly ProjectResource[] = [\n\t{ name: \"settings.json\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"extensions\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"skills\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"prompts\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"themes\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"APPEND_SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_LOCAL_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_AGENTS_DIR, scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_MCP_CONFIG_FILE, scope: \"root\", authority: \"presence\" },\n] as const;\n\n/** The project config directory for `cwd`. Honors a `piConfig.configDir` override. */\nexport function projectConfigDir(cwd: string): string {\n\treturn join(cwd, CONFIG_DIR_NAME);\n}\n\n/**\n * Absolute path of one project resource. Loaders call this instead of composing the\n * config directory themselves, so a loader cannot read a path the classifier does not\n * check.\n */\nexport function projectResourcePath(cwd: string, resource: ProjectResource): string {\n\treturn join(resource.scope === \"config-dir\" ? projectConfigDir(cwd) : cwd, resource.name);\n}\n\nexport function projectResource(name: string): ProjectResource {\n\tconst resource = PROJECT_RESOURCES.find((candidate) => candidate.name === name);\n\tif (!resource) throw new Error(`Unknown project resource: ${name}`);\n\treturn resource;\n}\n\n/** Convenience for the common case: a resource addressed by name. */\nexport function projectResourcePathByName(cwd: string, name: string): string {\n\treturn projectResourcePath(cwd, projectResource(name));\n}\n"]}
1
+ {"version":3,"file":"project-resources.d.ts","sourceRoot":"","sources":["../../src/core/project-resources.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAAG,MAAM,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,MAAM,wBAAwB,GAAG,UAAU,GAAG,kBAAkB,CAAC;AAEvE,MAAM,WAAW,eAAe;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,oBAAoB,CAAC;IACrC,QAAQ,CAAC,SAAS,EAAE,wBAAwB,CAAC;CAC7C;AAED,eAAO,MAAM,wBAAwB,qBAAqB,CAAC;AAC3D,eAAO,MAAM,8BAA8B,2BAA2B,CAAC;AACvE,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAC3C,eAAO,MAAM,uBAAuB,cAAc,CAAC;AAEnD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,qFAM5B,CAAC;AAEX,eAAO,MAAM,iBAAiB,EAAE,SAAS,eAAe,EAe9C,CAAC;AAEX,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,GAAG,MAAM,CAElF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,CAI7D;AAED,qEAAqE;AACrE,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE3E","sourcesContent":["import { join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\n\n/**\n * The single list of project-controlled resources a repository can supply, and the only\n * place their paths are built.\n *\n * Both halves of the trust boundary resolve through here: the loaders ask for a path,\n * and `hasTrustRequiringProjectResources` asks the same question of the same entries.\n * Before this existed the two were independent, and four resources were read without\n * ever reaching the classifier (`permissions.json`, `permissions.local.json`, `agents/`,\n * and `.mcp.json`), so a cloned repository supplying one of them was classified trusted\n * and the guard that drops untrusted scopes was satisfied rather than triggered.\n *\n * Relocating the list is not enough on its own. A loader that builds `join(cwd,\n * \".apex-code\", …)` by hand diverges the moment `CONFIG_DIR_NAME` is overridden, which\n * reintroduces the same bypass with no test failing, so the path builders below are the\n * supported way to reach a project resource. See\n * `docs/specs/2026-09-11-trust-classification-and-proof-integrity.md`.\n */\n\n/**\n * Where an entry's `name` is resolved from.\n *\n * `config-dir` resolves under `<cwd>/<CONFIG_DIR_NAME>`. `root` resolves at `<cwd>`,\n * which is what lets `.mcp.json` reach the classifier at all.\n *\n * The ancestor `.agents/skills` walk is deliberately not a scope here. It has no fixed\n * depth and one path under the user's home is exempt, so it lives in the classifier\n * rather than as an entry a caller could resolve to a single path. Adding an `ancestor`\n * member without implementing the walk would let an entry silently resolve at `cwd`\n * only, which is the narrowing this registry exists to prevent.\n */\nexport type ProjectResourceScope = \"config-dir\" | \"root\";\n\n/**\n * How presence maps to authority.\n *\n * `presence` means existing is enough. `permission-scope` means the file is parsed and\n * only grants authority when it carries a rule or a mode, because a `{}` permissions\n * file confers nothing and this repository ships one. A prompt carrying no decision\n * teaches people to dismiss prompts.\n */\nexport type ProjectResourceAuthority = \"presence\" | \"permission-scope\";\n\nexport interface ProjectResource {\n\t/** Path relative to the entry's scope root. A single path segment. */\n\treadonly name: string;\n\treadonly scope: ProjectResourceScope;\n\treadonly authority: ProjectResourceAuthority;\n}\n\nexport const PROJECT_PERMISSIONS_FILE = \"permissions.json\";\nexport const PROJECT_LOCAL_PERMISSIONS_FILE = \"permissions.local.json\";\nexport const PROJECT_AGENTS_DIR = \"agents\";\nexport const PROJECT_MCP_CONFIG_FILE = \".mcp.json\";\n\n/**\n * The repository instruction files, in the order the loader prefers them.\n *\n * These are wrapped as `<project_instructions>` and handed to the model as instructions,\n * so a checkout supplying one is steering the agent. That is what the trust prompt asks\n * about, and until this list was registered they reached the system prompt through no gate.\n *\n * The loader reads this array rather than its own copy. A sixth spelling added to one and\n * not the other is the exact divergence this registry exists to prevent, and the earlier\n * form of that bug is why the registry exists at all.\n */\nexport const PROJECT_INSTRUCTION_FILES = [\n\t\"AGENTS.override.md\",\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n] as const;\n\nexport const PROJECT_RESOURCES: readonly ProjectResource[] = [\n\t{ name: \"settings.json\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"extensions\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"skills\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"prompts\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"themes\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"APPEND_SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_LOCAL_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_AGENTS_DIR, scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_MCP_CONFIG_FILE, scope: \"root\", authority: \"presence\" },\n\t...PROJECT_INSTRUCTION_FILES.map(\n\t\t(name) => ({ name, scope: \"root\", authority: \"presence\" }) as const satisfies ProjectResource,\n\t),\n] as const;\n\n/** The project config directory for `cwd`. Honors a `piConfig.configDir` override. */\nexport function projectConfigDir(cwd: string): string {\n\treturn join(cwd, CONFIG_DIR_NAME);\n}\n\n/**\n * Absolute path of one project resource. Loaders call this instead of composing the\n * config directory themselves, so a loader cannot read a path the classifier does not\n * check.\n */\nexport function projectResourcePath(cwd: string, resource: ProjectResource): string {\n\treturn join(resource.scope === \"config-dir\" ? projectConfigDir(cwd) : cwd, resource.name);\n}\n\nexport function projectResource(name: string): ProjectResource {\n\tconst resource = PROJECT_RESOURCES.find((candidate) => candidate.name === name);\n\tif (!resource) throw new Error(`Unknown project resource: ${name}`);\n\treturn resource;\n}\n\n/** Convenience for the common case: a resource addressed by name. */\nexport function projectResourcePathByName(cwd: string, name: string): string {\n\treturn projectResourcePath(cwd, projectResource(name));\n}\n"]}
@@ -4,6 +4,24 @@ export const PROJECT_PERMISSIONS_FILE = "permissions.json";
4
4
  export const PROJECT_LOCAL_PERMISSIONS_FILE = "permissions.local.json";
5
5
  export const PROJECT_AGENTS_DIR = "agents";
6
6
  export const PROJECT_MCP_CONFIG_FILE = ".mcp.json";
7
+ /**
8
+ * The repository instruction files, in the order the loader prefers them.
9
+ *
10
+ * These are wrapped as `<project_instructions>` and handed to the model as instructions,
11
+ * so a checkout supplying one is steering the agent. That is what the trust prompt asks
12
+ * about, and until this list was registered they reached the system prompt through no gate.
13
+ *
14
+ * The loader reads this array rather than its own copy. A sixth spelling added to one and
15
+ * not the other is the exact divergence this registry exists to prevent, and the earlier
16
+ * form of that bug is why the registry exists at all.
17
+ */
18
+ export const PROJECT_INSTRUCTION_FILES = [
19
+ "AGENTS.override.md",
20
+ "AGENTS.md",
21
+ "AGENTS.MD",
22
+ "CLAUDE.md",
23
+ "CLAUDE.MD",
24
+ ];
7
25
  export const PROJECT_RESOURCES = [
8
26
  { name: "settings.json", scope: "config-dir", authority: "presence" },
9
27
  { name: "extensions", scope: "config-dir", authority: "presence" },
@@ -16,6 +34,7 @@ export const PROJECT_RESOURCES = [
16
34
  { name: PROJECT_LOCAL_PERMISSIONS_FILE, scope: "config-dir", authority: "permission-scope" },
17
35
  { name: PROJECT_AGENTS_DIR, scope: "config-dir", authority: "presence" },
18
36
  { name: PROJECT_MCP_CONFIG_FILE, scope: "root", authority: "presence" },
37
+ ...PROJECT_INSTRUCTION_FILES.map((name) => ({ name, scope: "root", authority: "presence" })),
19
38
  ];
20
39
  /** The project config directory for `cwd`. Honors a `piConfig.configDir` override. */
21
40
  export function projectConfigDir(cwd) {
@@ -1 +1 @@
1
- {"version":3,"file":"project-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YAAY,EAAE,SAAS,EAAE,UAAU,EAAE;IACxE,EAAE,IAAI,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE;CAC9D,CAAC;AAEX,sFAAsF;AACtF,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAU;IACrD,OAAO,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AAAA,CAClC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,QAAyB,EAAU;IACnF,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;AAAA,CAC1F;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAmB;IAC9D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAChF,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;IACpE,OAAO,QAAQ,CAAC;AAAA,CAChB;AAED,qEAAqE;AACrE,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,IAAY,EAAU;IAC5E,OAAO,mBAAmB,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;AAAA,CACvD","sourcesContent":["import { join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\n\n/**\n * The single list of project-controlled resources a repository can supply, and the only\n * place their paths are built.\n *\n * Both halves of the trust boundary resolve through here: the loaders ask for a path,\n * and `hasTrustRequiringProjectResources` asks the same question of the same entries.\n * Before this existed the two were independent, and four resources were read without\n * ever reaching the classifier (`permissions.json`, `permissions.local.json`, `agents/`,\n * and `.mcp.json`), so a cloned repository supplying one of them was classified trusted\n * and the guard that drops untrusted scopes was satisfied rather than triggered.\n *\n * Relocating the list is not enough on its own. A loader that builds `join(cwd,\n * \".apex-code\", …)` by hand diverges the moment `CONFIG_DIR_NAME` is overridden, which\n * reintroduces the same bypass with no test failing, so the path builders below are the\n * supported way to reach a project resource. See\n * `docs/specs/2026-09-11-trust-classification-and-proof-integrity.md`.\n */\n\n/**\n * Where an entry's `name` is resolved from.\n *\n * `config-dir` resolves under `<cwd>/<CONFIG_DIR_NAME>`. `root` resolves at `<cwd>`,\n * which is what lets `.mcp.json` reach the classifier at all.\n *\n * The ancestor `.agents/skills` walk is deliberately not a scope here. It has no fixed\n * depth and one path under the user's home is exempt, so it lives in the classifier\n * rather than as an entry a caller could resolve to a single path. Adding an `ancestor`\n * member without implementing the walk would let an entry silently resolve at `cwd`\n * only, which is the narrowing this registry exists to prevent.\n */\nexport type ProjectResourceScope = \"config-dir\" | \"root\";\n\n/**\n * How presence maps to authority.\n *\n * `presence` means existing is enough. `permission-scope` means the file is parsed and\n * only grants authority when it carries a rule or a mode, because a `{}` permissions\n * file confers nothing and this repository ships one. A prompt carrying no decision\n * teaches people to dismiss prompts.\n */\nexport type ProjectResourceAuthority = \"presence\" | \"permission-scope\";\n\nexport interface ProjectResource {\n\t/** Path relative to the entry's scope root. A single path segment. */\n\treadonly name: string;\n\treadonly scope: ProjectResourceScope;\n\treadonly authority: ProjectResourceAuthority;\n}\n\nexport const PROJECT_PERMISSIONS_FILE = \"permissions.json\";\nexport const PROJECT_LOCAL_PERMISSIONS_FILE = \"permissions.local.json\";\nexport const PROJECT_AGENTS_DIR = \"agents\";\nexport const PROJECT_MCP_CONFIG_FILE = \".mcp.json\";\n\nexport const PROJECT_RESOURCES: readonly ProjectResource[] = [\n\t{ name: \"settings.json\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"extensions\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"skills\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"prompts\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"themes\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"APPEND_SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_LOCAL_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_AGENTS_DIR, scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_MCP_CONFIG_FILE, scope: \"root\", authority: \"presence\" },\n] as const;\n\n/** The project config directory for `cwd`. Honors a `piConfig.configDir` override. */\nexport function projectConfigDir(cwd: string): string {\n\treturn join(cwd, CONFIG_DIR_NAME);\n}\n\n/**\n * Absolute path of one project resource. Loaders call this instead of composing the\n * config directory themselves, so a loader cannot read a path the classifier does not\n * check.\n */\nexport function projectResourcePath(cwd: string, resource: ProjectResource): string {\n\treturn join(resource.scope === \"config-dir\" ? projectConfigDir(cwd) : cwd, resource.name);\n}\n\nexport function projectResource(name: string): ProjectResource {\n\tconst resource = PROJECT_RESOURCES.find((candidate) => candidate.name === name);\n\tif (!resource) throw new Error(`Unknown project resource: ${name}`);\n\treturn resource;\n}\n\n/** Convenience for the common case: a resource addressed by name. */\nexport function projectResourcePathByName(cwd: string, name: string): string {\n\treturn projectResourcePath(cwd, projectResource(name));\n}\n"]}
1
+ {"version":3,"file":"project-resources.js","sourceRoot":"","sources":["../../src/core/project-resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAmD/C,MAAM,CAAC,MAAM,wBAAwB,GAAG,kBAAkB,CAAC;AAC3D,MAAM,CAAC,MAAM,8BAA8B,GAAG,wBAAwB,CAAC;AACvE,MAAM,CAAC,MAAM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AG,CAC/B,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAoC,CAC7F;CACQ,CAAC;AAEX,sFAAsF;AACtF,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAU;IACrD,OAAO,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AAAA,CAClC;AAED;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW,EAAE,QAAyB,EAAU;IACnF,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,KAAK,YAAY,CAAC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;AAAA,CAC1F;AAED,MAAM,UAAU,eAAe,CAAC,IAAY,EAAmB;IAC9D,MAAM,QAAQ,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAChF,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,EAAE,CAAC,CAAC;IACpE,OAAO,QAAQ,CAAC;AAAA,CAChB;AAED,qEAAqE;AACrE,MAAM,UAAU,yBAAyB,CAAC,GAAW,EAAE,IAAY,EAAU;IAC5E,OAAO,mBAAmB,CAAC,GAAG,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC;AAAA,CACvD","sourcesContent":["import { join } from \"node:path\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\n\n/**\n * The single list of project-controlled resources a repository can supply, and the only\n * place their paths are built.\n *\n * Both halves of the trust boundary resolve through here: the loaders ask for a path,\n * and `hasTrustRequiringProjectResources` asks the same question of the same entries.\n * Before this existed the two were independent, and four resources were read without\n * ever reaching the classifier (`permissions.json`, `permissions.local.json`, `agents/`,\n * and `.mcp.json`), so a cloned repository supplying one of them was classified trusted\n * and the guard that drops untrusted scopes was satisfied rather than triggered.\n *\n * Relocating the list is not enough on its own. A loader that builds `join(cwd,\n * \".apex-code\", …)` by hand diverges the moment `CONFIG_DIR_NAME` is overridden, which\n * reintroduces the same bypass with no test failing, so the path builders below are the\n * supported way to reach a project resource. See\n * `docs/specs/2026-09-11-trust-classification-and-proof-integrity.md`.\n */\n\n/**\n * Where an entry's `name` is resolved from.\n *\n * `config-dir` resolves under `<cwd>/<CONFIG_DIR_NAME>`. `root` resolves at `<cwd>`,\n * which is what lets `.mcp.json` reach the classifier at all.\n *\n * The ancestor `.agents/skills` walk is deliberately not a scope here. It has no fixed\n * depth and one path under the user's home is exempt, so it lives in the classifier\n * rather than as an entry a caller could resolve to a single path. Adding an `ancestor`\n * member without implementing the walk would let an entry silently resolve at `cwd`\n * only, which is the narrowing this registry exists to prevent.\n */\nexport type ProjectResourceScope = \"config-dir\" | \"root\";\n\n/**\n * How presence maps to authority.\n *\n * `presence` means existing is enough. `permission-scope` means the file is parsed and\n * only grants authority when it carries a rule or a mode, because a `{}` permissions\n * file confers nothing and this repository ships one. A prompt carrying no decision\n * teaches people to dismiss prompts.\n */\nexport type ProjectResourceAuthority = \"presence\" | \"permission-scope\";\n\nexport interface ProjectResource {\n\t/** Path relative to the entry's scope root. A single path segment. */\n\treadonly name: string;\n\treadonly scope: ProjectResourceScope;\n\treadonly authority: ProjectResourceAuthority;\n}\n\nexport const PROJECT_PERMISSIONS_FILE = \"permissions.json\";\nexport const PROJECT_LOCAL_PERMISSIONS_FILE = \"permissions.local.json\";\nexport const PROJECT_AGENTS_DIR = \"agents\";\nexport const PROJECT_MCP_CONFIG_FILE = \".mcp.json\";\n\n/**\n * The repository instruction files, in the order the loader prefers them.\n *\n * These are wrapped as `<project_instructions>` and handed to the model as instructions,\n * so a checkout supplying one is steering the agent. That is what the trust prompt asks\n * about, and until this list was registered they reached the system prompt through no gate.\n *\n * The loader reads this array rather than its own copy. A sixth spelling added to one and\n * not the other is the exact divergence this registry exists to prevent, and the earlier\n * form of that bug is why the registry exists at all.\n */\nexport const PROJECT_INSTRUCTION_FILES = [\n\t\"AGENTS.override.md\",\n\t\"AGENTS.md\",\n\t\"AGENTS.MD\",\n\t\"CLAUDE.md\",\n\t\"CLAUDE.MD\",\n] as const;\n\nexport const PROJECT_RESOURCES: readonly ProjectResource[] = [\n\t{ name: \"settings.json\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"extensions\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"skills\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"prompts\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"themes\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: \"APPEND_SYSTEM.md\", scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_LOCAL_PERMISSIONS_FILE, scope: \"config-dir\", authority: \"permission-scope\" },\n\t{ name: PROJECT_AGENTS_DIR, scope: \"config-dir\", authority: \"presence\" },\n\t{ name: PROJECT_MCP_CONFIG_FILE, scope: \"root\", authority: \"presence\" },\n\t...PROJECT_INSTRUCTION_FILES.map(\n\t\t(name) => ({ name, scope: \"root\", authority: \"presence\" }) as const satisfies ProjectResource,\n\t),\n] as const;\n\n/** The project config directory for `cwd`. Honors a `piConfig.configDir` override. */\nexport function projectConfigDir(cwd: string): string {\n\treturn join(cwd, CONFIG_DIR_NAME);\n}\n\n/**\n * Absolute path of one project resource. Loaders call this instead of composing the\n * config directory themselves, so a loader cannot read a path the classifier does not\n * check.\n */\nexport function projectResourcePath(cwd: string, resource: ProjectResource): string {\n\treturn join(resource.scope === \"config-dir\" ? projectConfigDir(cwd) : cwd, resource.name);\n}\n\nexport function projectResource(name: string): ProjectResource {\n\tconst resource = PROJECT_RESOURCES.find((candidate) => candidate.name === name);\n\tif (!resource) throw new Error(`Unknown project resource: ${name}`);\n\treturn resource;\n}\n\n/** Convenience for the common case: a resource addressed by name. */\nexport function projectResourcePathByName(cwd: string, name: string): string {\n\treturn projectResourcePath(cwd, projectResource(name));\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"provider-composer.d.ts","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,2BAA2B,EAIhC,KAAK,OAAO,EAGZ,KAAK,KAAK,EAGV,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAA4C,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACnH,OAAO,EACN,qBAAqB,EAMrB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gGAAgG;IAChG,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACjE,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC5F,SAAS,CAAC,WAAW,EAAE,gBAAgB,GAAG,MAAM,CAAC;IACjD,YAAY,CAAC,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,EAAE,EAAE,WAAW,EAAE,gBAAgB,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;CACjF;AAED,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IACnC,IAAI,CAAC,EAAE,MAAM,CAAC;I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cesContent":["import {\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEventStream,\n\ttype AuthContext,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype Context,\n\ttype Credential,\n\tlazyStream,\n\ttype Model,\n\ttype ModelAuth,\n\ttype OAuthAuth,\n\ttype OAuthCredentials,\n\ttype OAuthLoginCallbacks,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype RefreshModelsContext,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getApiProvider } from \"@earendil-works/pi-ai/compat\";\nimport type { ModelConfig, ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\t/** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tapi?: Api;\n\t\tbaseUrl?: string;\n\t\treasoning: boolean;\n\t\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcost: Model<Api>[\"cost\"];\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t\tsamplingParams?: Record<string, unknown>;\n\t\theaders?: Record<string, string>;\n\t\tcompat?: Model<Api>[\"compat\"];\n\t}>;\n\trefreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput[\"models\"]>>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as (\"text\" | \"image\")[] | undefined) ?? model.input,\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly Model<Api>[],\n\tconfig: ModelsJsonProvider | undefined,\n): Model<Api>[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: Model<Api>[] = baseModels.map((model) => ({\n\t\t...model,\n\t\tbaseUrl: config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl),\n\t\tcompat: mergeCompat(model.compat, config.compat),\n\t}));\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => model.id === definition.id);\n\t\tconst defaults = existingIndex >= 0 ? models[existingIndex] : models[0];\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nfunction applyExtension(\n\tproviderId: string,\n\tmodels: readonly Model<Api>[],\n\tconfig: ProviderConfigInput | undefined,\n): Model<Api>[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => {\n\t\tconst defaults = models.find((model) => model.id === definition.id) ?? models[0];\n\t\tconst api = definition.api ?? config.api ?? defaults?.api;\n\t\tif (!api) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t);\n\t\t}\n\t\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\t\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\t\treturn {\n\t\t\t...definition,\n\t\t\tapi,\n\t\t\tprovider: providerId,\n\t\t\tbaseUrl,\n\t\t\theaders: undefined,\n\t\t};\n\t});\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tisSubscription: config.isSubscription,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst credential = await config.login({\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t});\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nfunction configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nfunction configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nfunction composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\tlogin:\n\t\t\tinherited?.login ??\n\t\t\t(async (interaction: AuthInteraction) => ({\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t})),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nfunction composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nfunction rawModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tconst definition = config?.models?.find((entry) => entry.id === model.id);\n\tconst extensionModel = extension?.models?.find((entry) => entry.id === model.id);\n\tconst headers = {\n\t\t...config?.modelOverrides?.[model.id]?.headers,\n\t\t...definition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getModels = () => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, base?.getModels() ?? [], config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\tmodels = extension.oauth.modifyModels(models, extensionOAuthCredential);\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn override ? applyModelOverride(model, override) : model;\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(model, async () => {\n\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t}\n\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\treturn simple\n\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t}\n\t\t\tconst api = getApiProvider(model.api);\n\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\treturn simple\n\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t: api.stream(model, context, options);\n\t\t});\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
1
+ {"version":3,"file":"provider-composer.d.ts","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,GAAG,EAER,KAAK,2BAA2B,EAIhC,KAAK,OAAO,EAGZ,KAAK,KAAK,EAGV,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAExB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EAExB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,WAAW,EAA4C,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACnH,OAAO,EACN,qBAAqB,EAMrB,MAAM,2BAA2B,CAAC;AAEnC,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,oFAAoF;IACpF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gGAAgG;IAChG,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,SAAS,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACjE,YAAY,CAAC,WAAW,EAAE,gBAAgB,EAAE,MAA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B,UAAU,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,iCAAiC,CAChD,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,EACjB,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,0BAA0B,CAS5B;AAED,wBAAgB,2BAA2B,CAC1C,MAAM,EAAE,kBAAkB,GAAG,SAAS,EACtC,SAAS,EAAE,mBAAmB,GAAG,SAAS,GACxC,UAAU,GAAG,SAAS,CAWxB","sourcesContent":["import {\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEventStream,\n\ttype AuthContext,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype Context,\n\ttype Credential,\n\tlazyStream,\n\ttype Model,\n\ttype ModelAuth,\n\ttype OAuthAuth,\n\ttype OAuthCredentials,\n\ttype OAuthLoginCallbacks,\n\ttype OpenAIResponsesCompat,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype RefreshModelsContext,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getApiProvider } from \"@earendil-works/pi-ai/compat\";\nimport type { ModelConfig, ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\t/** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tapi?: Api;\n\t\tbaseUrl?: string;\n\t\treasoning: boolean;\n\t\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcost: Model<Api>[\"cost\"];\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t\tsamplingParams?: Record<string, unknown>;\n\t\theaders?: Record<string, string>;\n\t\tcompat?: Model<Api>[\"compat\"];\n\t}>;\n\trefreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput[\"models\"]>>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as (\"text\" | \"image\")[] | undefined) ?? model.input,\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction applyCompatibilityDefaults(model: Model<Api>): Model<Api> {\n\tconst compat = model.api === \"openai-responses\" ? (model.compat as OpenAIResponsesCompat | undefined) : undefined;\n\tif (model.api !== \"openai-responses\" || compat?.supportsStrictMode !== undefined) return model;\n\treturn {\n\t\t...model,\n\t\tcompat: { ...compat, supportsStrictMode: true },\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly Model<Api>[],\n\tconfig: ModelsJsonProvider | undefined,\n): Model<Api>[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: Model<Api>[] = baseModels.map((model) => ({\n\t\t...model,\n\t\tbaseUrl: config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl),\n\t\tcompat: mergeCompat(model.compat, config.compat),\n\t}));\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => model.id === definition.id);\n\t\tconst defaults = existingIndex >= 0 ? models[existingIndex] : models[0];\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nfunction applyExtension(\n\tproviderId: string,\n\tmodels: readonly Model<Api>[],\n\tconfig: ProviderConfigInput | undefined,\n): Model<Api>[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => {\n\t\tconst defaults = models.find((model) => model.id === definition.id) ?? models[0];\n\t\tconst api = definition.api ?? config.api ?? defaults?.api;\n\t\tif (!api) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t);\n\t\t}\n\t\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\t\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\t\treturn {\n\t\t\t...definition,\n\t\t\tapi,\n\t\t\tprovider: providerId,\n\t\t\tbaseUrl,\n\t\t\theaders: undefined,\n\t\t};\n\t});\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tisSubscription: config.isSubscription,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst credential = await config.login({\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t});\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nfunction configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nfunction configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nfunction composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\tlogin:\n\t\t\tinherited?.login ??\n\t\t\t(async (interaction: AuthInteraction) => ({\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t})),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nfunction composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nfunction rawModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tconst definition = config?.models?.find((entry) => entry.id === model.id);\n\tconst extensionModel = extension?.models?.find((entry) => entry.id === model.id);\n\tconst headers = {\n\t\t...config?.modelOverrides?.[model.id]?.headers,\n\t\t...definition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getModels = () => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, base?.getModels() ?? [], config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\tmodels = extension.oauth.modifyModels(models, extensionOAuthCredential);\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn applyCompatibilityDefaults(override ? applyModelOverride(model, override) : model);\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(model, async () => {\n\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t}\n\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\treturn simple\n\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t}\n\t\t\tconst api = getApiProvider(model.api);\n\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\treturn simple\n\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t: api.stream(model, context, options);\n\t\t});\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
@@ -45,6 +45,15 @@ function applyModelOverride(model, override) {
45
45
  compat: mergeCompat(model.compat, override.compat),
46
46
  };
47
47
  }
48
+ function applyCompatibilityDefaults(model) {
49
+ const compat = model.api === "openai-responses" ? model.compat : undefined;
50
+ if (model.api !== "openai-responses" || compat?.supportsStrictMode !== undefined)
51
+ return model;
52
+ return {
53
+ ...model,
54
+ compat: { ...compat, supportsStrictMode: true },
55
+ };
56
+ }
48
57
  function modelFromJson(providerId, definition, providerConfig, defaults) {
49
58
  const api = definition.api ?? providerConfig.api ?? defaults?.api;
50
59
  if (!api) {
@@ -296,7 +305,7 @@ export function composeModelProvider(providerId, base, modelConfig, extension) {
296
305
  }
297
306
  return models.map((model) => {
298
307
  const override = config?.modelOverrides?.[model.id];
299
- return override ? applyModelOverride(model, override) : model;
308
+ return applyCompatibilityDefaults(override ? applyModelOverride(model, override) : model);
300
309
  });
301
310
  };
302
311
  // Validate eagerly so registration/reload reports structural errors immediately.
@@ -1 +1 @@
1
- {"version":3,"file":"provider-composer.js","sourceRoot":"","sources":["../../src/core/provider-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EASN,UAAU,GAWV,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,OAAO,EACN,qBAAqB,EACrB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,qBAAqB,GACrB,MAAM,2BAA2B,CAAC;AAgDnC,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAEtD,SAAS,WAAW,CACnB,IAA0B,EAC1B,QAAkE,EAC3C;IACvB,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,MAAM,MAAM,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,EAAuC,CAAC;IAC7E,MAAM,UAAU,GAAG,IAA2C,CAAC;IAC/D,MAAM,cAAc,GAAG,QAAmC,CAAC;IAC3D,MAAM,YAAY,GAAG,MAAiC,CAAC;IACvD,KAAK,MAAM,GAAG,IAAI,CAAC,mBAAmB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,kBAAkB,CAAU,EAAE,CAAC;QACpH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,MAAM,EAAE,SAAS,CAAC,CAAC;IAClD,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC5F,MAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,uBAAuB,CAAC,KAAK,CAAC;YACpC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AAAA,CACtG","sourcesContent":["import {\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEventStream,\n\ttype AuthContext,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype Context,\n\ttype Credential,\n\tlazyStream,\n\ttype Model,\n\ttype ModelAuth,\n\ttype OAuthAuth,\n\ttype OAuthCredentials,\n\ttype OAuthLoginCallbacks,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype RefreshModelsContext,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getApiProvider } from \"@earendil-works/pi-ai/compat\";\nimport type { ModelConfig, ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\t/** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tapi?: Api;\n\t\tbaseUrl?: string;\n\t\treasoning: boolean;\n\t\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcost: Model<Api>[\"cost\"];\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t\tsamplingParams?: Record<string, unknown>;\n\t\theaders?: Record<string, string>;\n\t\tcompat?: Model<Api>[\"compat\"];\n\t}>;\n\trefreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput[\"models\"]>>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as (\"text\" | \"image\")[] | undefined) ?? model.input,\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly Model<Api>[],\n\tconfig: ModelsJsonProvider | undefined,\n): Model<Api>[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: Model<Api>[] = baseModels.map((model) => ({\n\t\t...model,\n\t\tbaseUrl: config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl),\n\t\tcompat: mergeCompat(model.compat, config.compat),\n\t}));\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => model.id === definition.id);\n\t\tconst defaults = existingIndex >= 0 ? models[existingIndex] : models[0];\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nfunction applyExtension(\n\tproviderId: string,\n\tmodels: readonly Model<Api>[],\n\tconfig: ProviderConfigInput | undefined,\n): Model<Api>[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => {\n\t\tconst defaults = models.find((model) => model.id === definition.id) ?? models[0];\n\t\tconst api = definition.api ?? config.api ?? defaults?.api;\n\t\tif (!api) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t);\n\t\t}\n\t\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\t\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\t\treturn {\n\t\t\t...definition,\n\t\t\tapi,\n\t\t\tprovider: providerId,\n\t\t\tbaseUrl,\n\t\t\theaders: undefined,\n\t\t};\n\t});\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tisSubscription: config.isSubscription,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst credential = await config.login({\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t});\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nfunction configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nfunction configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nfunction composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\tlogin:\n\t\t\tinherited?.login ??\n\t\t\t(async (interaction: AuthInteraction) => ({\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t})),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nfunction composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nfunction rawModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tconst definition = config?.models?.find((entry) => entry.id === model.id);\n\tconst extensionModel = extension?.models?.find((entry) => entry.id === model.id);\n\tconst headers = {\n\t\t...config?.modelOverrides?.[model.id]?.headers,\n\t\t...definition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getModels = () => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, base?.getModels() ?? [], config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\tmodels = extension.oauth.modifyModels(models, extensionOAuthCredential);\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn override ? applyModelOverride(model, override) : model;\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(model, async () => {\n\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t}\n\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\treturn simple\n\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t}\n\t\t\tconst api = getApiProvider(model.api);\n\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\treturn simple\n\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t: api.stream(model, context, options);\n\t\t});\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
1
+ {"version":3,"file":"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AS,CAAC;IAC1C,IAAI,oBAAoB,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC5F,MAAM,KAAK,GAAG,yBAAyB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,uBAAuB,CAAC,KAAK,CAAC;YACpC,CAAC,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACtE,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC;AAAA,CACtG","sourcesContent":["import {\n\ttype Api,\n\ttype ApiKeyAuth,\n\ttype AssistantMessageEventStream,\n\ttype AuthContext,\n\ttype AuthInteraction,\n\ttype AuthResult,\n\ttype Context,\n\ttype Credential,\n\tlazyStream,\n\ttype Model,\n\ttype ModelAuth,\n\ttype OAuthAuth,\n\ttype OAuthCredentials,\n\ttype OAuthLoginCallbacks,\n\ttype OpenAIResponsesCompat,\n\ttype Provider,\n\ttype ProviderHeaders,\n\ttype RefreshModelsContext,\n\ttype SimpleStreamOptions,\n\ttype StreamOptions,\n} from \"@earendil-works/pi-ai\";\nimport { getApiProvider } from \"@earendil-works/pi-ai/compat\";\nimport type { ModelConfig, ModelsJsonModel, ModelsJsonModelOverride, ModelsJsonProvider } from \"./model-config.ts\";\nimport {\n\tclearConfigValueCache,\n\tgetConfigValueEnvVarNames,\n\tisCommandConfigValue,\n\tisConfigValueConfigured,\n\tresolveConfigValueOrThrow,\n\tresolveHeadersOrThrow,\n} from \"./resolve-config-value.ts\";\n\nexport interface ExtensionOAuthConfig {\n\tname: string;\n\t/** Whether access through this auth method is backed by a provider subscription. */\n\tisSubscription?: boolean;\n\t/** @deprecated Retained for extension source compatibility; ignored by canonical auth flows. */\n\tusesCallbackServer?: boolean;\n\tlogin(callbacks: OAuthLoginCallbacks): Promise<OAuthCredentials>;\n\trefreshToken(credentials: OAuthCredentials, signal: AbortSignal): Promise<OAuthCredentials>;\n\tgetApiKey(credentials: OAuthCredentials): string;\n\tmodifyModels?(models: Model<Api>[], credentials: OAuthCredentials): Model<Api>[];\n}\n\n/** Input type for the extension registerProvider API. */\nexport interface ProviderConfigInput {\n\tname?: string;\n\tbaseUrl?: string;\n\tapiKey?: string;\n\tapi?: Api;\n\tstreamSimple?: (model: Model<Api>, context: Context, options?: SimpleStreamOptions) => AssistantMessageEventStream;\n\theaders?: Record<string, string>;\n\tauthHeader?: boolean;\n\toauth?: ExtensionOAuthConfig;\n\tmodels?: Array<{\n\t\tid: string;\n\t\tname: string;\n\t\tapi?: Api;\n\t\tbaseUrl?: string;\n\t\treasoning: boolean;\n\t\tthinkingLevelMap?: Model<Api>[\"thinkingLevelMap\"];\n\t\tinput: (\"text\" | \"image\")[];\n\t\tcost: Model<Api>[\"cost\"];\n\t\tcontextWindow: number;\n\t\tmaxTokens: number;\n\t\tsamplingParams?: Record<string, unknown>;\n\t\theaders?: Record<string, string>;\n\t\tcompat?: Model<Api>[\"compat\"];\n\t}>;\n\trefreshModels?(context: RefreshModelsContext): Promise<NonNullable<ProviderConfigInput[\"models\"]>>;\n}\n\nexport type AuthStatus = {\n\tconfigured: boolean;\n\tsource?: \"stored\" | \"runtime\" | \"environment\" | \"fallback\" | \"models_json_key\" | \"models_json_command\";\n\tlabel?: string;\n};\n\nexport const clearApiKeyCache = clearConfigValueCache;\n\nfunction mergeCompat(\n\tbase: Model<Api>[\"compat\"],\n\toverride: Model<Api>[\"compat\"] | ModelsJsonModelOverride[\"compat\"],\n): Model<Api>[\"compat\"] {\n\tif (!override) return base;\n\tconst merged = { ...base, ...override } as NonNullable<Model<Api>[\"compat\"]>;\n\tconst baseNested = base as Record<string, unknown> | undefined;\n\tconst overrideNested = override as Record<string, unknown>;\n\tconst mergedNested = merged as Record<string, unknown>;\n\tfor (const key of [\"openRouterRouting\", \"vercelGatewayRouting\", \"chatTemplateKwargs\", \"chatTemplateArgs\"] as const) {\n\t\tconst baseValue = baseNested?.[key];\n\t\tconst overrideValue = overrideNested[key];\n\t\tif (\n\t\t\t(typeof baseValue === \"object\" && baseValue !== null) ||\n\t\t\t(typeof overrideValue === \"object\" && overrideValue !== null)\n\t\t) {\n\t\t\tmergedNested[key] = { ...(baseValue as object | undefined), ...(overrideValue as object | undefined) };\n\t\t}\n\t}\n\treturn merged;\n}\n\nfunction applyModelOverride(model: Model<Api>, override: ModelsJsonModelOverride): Model<Api> {\n\treturn {\n\t\t...model,\n\t\tname: override.name ?? model.name,\n\t\treasoning: override.reasoning ?? model.reasoning,\n\t\tthinkingLevelMap: override.thinkingLevelMap\n\t\t\t? { ...model.thinkingLevelMap, ...override.thinkingLevelMap }\n\t\t\t: model.thinkingLevelMap,\n\t\tinput: (override.input as (\"text\" | \"image\")[] | undefined) ?? model.input,\n\t\tcost: override.cost\n\t\t\t? {\n\t\t\t\t\tinput: override.cost.input ?? model.cost.input,\n\t\t\t\t\toutput: override.cost.output ?? model.cost.output,\n\t\t\t\t\tcacheRead: override.cost.cacheRead ?? model.cost.cacheRead,\n\t\t\t\t\tcacheWrite: override.cost.cacheWrite ?? model.cost.cacheWrite,\n\t\t\t\t\ttiers: override.cost.tiers ?? model.cost.tiers,\n\t\t\t\t}\n\t\t\t: model.cost,\n\t\tcontextWindow: override.contextWindow ?? model.contextWindow,\n\t\tmaxTokens: override.maxTokens ?? model.maxTokens,\n\t\tsamplingParams: override.samplingParams\n\t\t\t? { ...model.samplingParams, ...override.samplingParams }\n\t\t\t: model.samplingParams,\n\t\tcompat: mergeCompat(model.compat, override.compat),\n\t};\n}\n\nfunction applyCompatibilityDefaults(model: Model<Api>): Model<Api> {\n\tconst compat = model.api === \"openai-responses\" ? (model.compat as OpenAIResponsesCompat | undefined) : undefined;\n\tif (model.api !== \"openai-responses\" || compat?.supportsStrictMode !== undefined) return model;\n\treturn {\n\t\t...model,\n\t\tcompat: { ...compat, supportsStrictMode: true },\n\t};\n}\n\nfunction modelFromJson(\n\tproviderId: string,\n\tdefinition: ModelsJsonModel,\n\tproviderConfig: ModelsJsonProvider,\n\tdefaults: Model<Api> | undefined,\n): Model<Api> {\n\tconst api = definition.api ?? providerConfig.api ?? defaults?.api;\n\tif (!api) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t);\n\t}\n\tconst baseUrl = definition.baseUrl ?? providerConfig.baseUrl ?? defaults?.baseUrl;\n\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\tif (definition.contextWindow !== undefined && definition.contextWindow <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid contextWindow`);\n\t}\n\tif (definition.maxTokens !== undefined && definition.maxTokens <= 0) {\n\t\tthrow new Error(`Provider ${providerId}, model ${definition.id}: invalid maxTokens`);\n\t}\n\treturn {\n\t\tid: definition.id,\n\t\tname: definition.name ?? definition.id,\n\t\tapi: api as Api,\n\t\tprovider: providerId,\n\t\tbaseUrl,\n\t\treasoning: definition.reasoning ?? false,\n\t\tthinkingLevelMap: definition.thinkingLevelMap,\n\t\tinput: (definition.input ?? [\"text\"]) as (\"text\" | \"image\")[],\n\t\tcost: definition.cost ?? { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },\n\t\tcontextWindow: definition.contextWindow ?? 128000,\n\t\tmaxTokens: definition.maxTokens ?? 16384,\n\t\tsamplingParams: definition.samplingParams,\n\t\theaders: undefined,\n\t\tcompat: mergeCompat(providerConfig.compat, definition.compat),\n\t};\n}\n\nfunction applyModelsJson(\n\tproviderId: string,\n\tbaseModels: readonly Model<Api>[],\n\tconfig: ModelsJsonProvider | undefined,\n): Model<Api>[] {\n\tif (!config) return [...baseModels];\n\tif (config.oauth && !config.baseUrl) {\n\t\tthrow new Error(`Provider ${providerId}: \"baseUrl\" is required when \"oauth\" is set.`);\n\t}\n\tconst hasOverrides = config.modelOverrides && Object.keys(config.modelOverrides).length > 0;\n\tif (\n\t\t!config.models?.length &&\n\t\t!config.baseUrl &&\n\t\t!config.headers &&\n\t\t!config.compat &&\n\t\t!hasOverrides &&\n\t\t!config.apiKey &&\n\t\t!config.oauth &&\n\t\tconfig.authHeader === undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Provider ${providerId}: must specify \"baseUrl\", \"headers\", \"compat\", \"modelOverrides\", or \"models\".`,\n\t\t);\n\t}\n\n\tconst models: Model<Api>[] = baseModels.map((model) => ({\n\t\t...model,\n\t\tbaseUrl: config.oauth === \"radius\" ? model.baseUrl : (config.baseUrl ?? model.baseUrl),\n\t\tcompat: mergeCompat(model.compat, config.compat),\n\t}));\n\tfor (const definition of config.models ?? []) {\n\t\tconst existingIndex = models.findIndex((model) => model.id === definition.id);\n\t\tconst defaults = existingIndex >= 0 ? models[existingIndex] : models[0];\n\t\tconst model = modelFromJson(providerId, definition, config, defaults);\n\t\tif (existingIndex >= 0) models[existingIndex] = model;\n\t\telse models.push(model);\n\t}\n\treturn models;\n}\n\nfunction applyExtension(\n\tproviderId: string,\n\tmodels: readonly Model<Api>[],\n\tconfig: ProviderConfigInput | undefined,\n): Model<Api>[] {\n\tif (!config) return [...models];\n\tif (!config.models) {\n\t\treturn config.baseUrl ? models.map((model) => ({ ...model, baseUrl: config.baseUrl! })) : [...models];\n\t}\n\treturn config.models.map((definition) => {\n\t\tconst defaults = models.find((model) => model.id === definition.id) ?? models[0];\n\t\tconst api = definition.api ?? config.api ?? defaults?.api;\n\t\tif (!api) {\n\t\t\tthrow new Error(\n\t\t\t\t`Provider ${providerId}, model ${definition.id}: no \"api\" specified. Set at provider or model level.`,\n\t\t\t);\n\t\t}\n\t\tconst baseUrl = definition.baseUrl ?? config.baseUrl ?? defaults?.baseUrl;\n\t\tif (!baseUrl) throw new Error(`Provider ${providerId}: \"baseUrl\" is required when defining custom models.`);\n\t\treturn {\n\t\t\t...definition,\n\t\t\tapi,\n\t\t\tprovider: providerId,\n\t\t\tbaseUrl,\n\t\t\theaders: undefined,\n\t\t};\n\t});\n}\n\nfunction adaptOAuth(config: ExtensionOAuthConfig): OAuthAuth {\n\treturn {\n\t\tname: config.name,\n\t\tisSubscription: config.isSubscription,\n\t\tlogin: async (callbacks) => {\n\t\t\tconst credential = await config.login({\n\t\t\t\tonAuth: (info) => callbacks.notify({ type: \"auth_url\", ...info }),\n\t\t\t\tonDeviceCode: (info) => callbacks.notify({ type: \"device_code\", ...info }),\n\t\t\t\tonPrompt: (prompt) => callbacks.prompt({ type: \"text\", ...prompt }),\n\t\t\t\tonProgress: (message) => callbacks.notify({ type: \"progress\", message }),\n\t\t\t\tonManualCodeInput: () => callbacks.prompt({ type: \"manual_code\", message: \"Paste the authorization code\" }),\n\t\t\t\tonSelect: (prompt) => callbacks.prompt({ type: \"select\", ...prompt }),\n\t\t\t\tsignal: callbacks.signal,\n\t\t\t});\n\t\t\treturn { ...credential, type: \"oauth\" };\n\t\t},\n\t\trefresh: async (credential, signal) => ({ ...(await config.refreshToken(credential, signal)), type: \"oauth\" }),\n\t\ttoAuth: async (credential) => ({ apiKey: config.getApiKey(credential) }),\n\t};\n}\n\nfunction withConfiguredAuth(\n\tauth: ModelAuth,\n\theaders: Record<string, string> | undefined,\n\tauthHeader: boolean,\n): ModelAuth {\n\tlet mergedHeaders: ProviderHeaders | undefined =\n\t\tauth.headers || headers ? { ...auth.headers, ...headers } : undefined;\n\tif (authHeader) {\n\t\tif (!auth.apiKey) throw new Error(\"authHeader requires a resolved API key\");\n\t\tmergedHeaders = { ...mergedHeaders, Authorization: `Bearer ${auth.apiKey}` };\n\t}\n\treturn { ...auth, headers: mergedHeaders };\n}\n\nfunction configuredApiKey(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): string | undefined {\n\treturn extension?.apiKey ?? config?.apiKey;\n}\n\nfunction configuredHeaders(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tif (!config?.headers && !extension?.headers) return undefined;\n\treturn { ...config?.headers, ...extension?.headers };\n}\n\nasync function configContextEnv(\n\tvalues: readonly string[],\n\tctx: AuthContext,\n\texplicit?: Record<string, string>,\n): Promise<Record<string, string> | undefined> {\n\tconst env = { ...explicit };\n\tfor (const name of new Set(values.flatMap(getConfigValueEnvVarNames))) {\n\t\tif (env[name] !== undefined) continue;\n\t\tconst value = await ctx.env(name);\n\t\tif (value !== undefined) env[name] = value;\n\t}\n\treturn Object.keys(env).length > 0 ? env : undefined;\n}\n\nfunction composeApiKeyAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): ApiKeyAuth | undefined {\n\tconst inherited = base?.auth.apiKey;\n\tconst rawKey = configuredApiKey(config, extension);\n\tconst oauth = extension?.oauth ?? base?.auth.oauth;\n\t// OAuth-only providers get no fabricated API-key login method.\n\tif (!inherited && rawKey === undefined && oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\tname: inherited?.name ?? \"API key\",\n\t\tlogin:\n\t\t\tinherited?.login ??\n\t\t\t(async (interaction: AuthInteraction) => ({\n\t\t\t\ttype: \"api_key\",\n\t\t\t\tkey: await interaction.prompt({ type: \"secret\", message: \"Enter API key\" }),\n\t\t\t})),\n\t\tcheck: async (input) => {\n\t\t\tif (input.credential) {\n\t\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\t\tif (input.credential.key) return { type: \"api_key\", source: \"stored credential\" };\n\t\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t\t}\n\t\t\tif (rawKey !== undefined) {\n\t\t\t\tif (isCommandConfigValue(rawKey)) return { type: \"api_key\", source: \"configured API key\" };\n\t\t\t\tconst envNames = getConfigValueEnvVarNames(rawKey);\n\t\t\t\tfor (const name of envNames) {\n\t\t\t\t\tif ((await input.ctx.env(name)) === undefined) return undefined;\n\t\t\t\t}\n\t\t\t\treturn { type: \"api_key\", source: \"configured API key\" };\n\t\t\t}\n\t\t\tif (inherited?.check) return inherited.check(input);\n\t\t\tconst resolved = await inherited?.resolve(input);\n\t\t\treturn resolved ? { type: \"api_key\", source: resolved.source } : undefined;\n\t\t},\n\t\tresolve: async (input) => {\n\t\t\tlet result: AuthResult | undefined;\n\t\t\tif (input.credential) {\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve(input)\n\t\t\t\t\t: input.credential.key\n\t\t\t\t\t\t? { auth: { apiKey: input.credential.key }, env: input.credential.env, source: \"stored credential\" }\n\t\t\t\t\t\t: undefined;\n\t\t\t} else if (rawKey !== undefined) {\n\t\t\t\tconst env = await configContextEnv([rawKey], input.ctx);\n\t\t\t\tconst key = resolveConfigValueOrThrow(rawKey, `API key for provider \"${providerId}\"`, env);\n\t\t\t\tresult = inherited\n\t\t\t\t\t? await inherited.resolve({ ...input, credential: { type: \"api_key\", key } })\n\t\t\t\t\t: { auth: { apiKey: key }, source: \"configured API key\" };\n\t\t\t} else {\n\t\t\t\tresult = await inherited?.resolve(input);\n\t\t\t}\n\t\t\tif (!result) return undefined;\n\t\t\tconst explicitEnv = { ...(input.credential?.env ?? {}), ...(result.env ?? {}) };\n\t\t\tconst headerEnv = await configContextEnv(Object.values(rawHeaders ?? {}), input.ctx, explicitEnv);\n\t\t\tconst headers = resolveHeadersOrThrow(rawHeaders, `provider \"${providerId}\"`, headerEnv);\n\t\t\treturn { ...result, auth: withConfiguredAuth(result.auth, headers, authHeader) };\n\t\t},\n\t};\n}\n\nfunction composeOAuthAuth(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): OAuthAuth | undefined {\n\tconst oauth = extension?.oauth ? adaptOAuth(extension.oauth) : base?.auth.oauth;\n\tif (!oauth) return undefined;\n\tconst rawHeaders = configuredHeaders(config, extension);\n\tconst authHeader = extension?.authHeader ?? config?.authHeader ?? false;\n\treturn {\n\t\t...oauth,\n\t\ttoAuth: async (credential) => {\n\t\t\tconst auth = await oauth.toAuth(credential);\n\t\t\tconst env = credential.env;\n\t\t\tconst headers = resolveHeadersOrThrow(\n\t\t\t\trawHeaders,\n\t\t\t\t`provider \"${providerId}\"`,\n\t\t\t\ttypeof env === \"object\" && env !== null ? (env as Record<string, string>) : undefined,\n\t\t\t);\n\t\t\treturn withConfiguredAuth(auth, headers, authHeader);\n\t\t},\n\t};\n}\n\nfunction rawModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): Record<string, string> | undefined {\n\tconst definition = config?.models?.find((entry) => entry.id === model.id);\n\tconst extensionModel = extension?.models?.find((entry) => entry.id === model.id);\n\tconst headers = {\n\t\t...config?.modelOverrides?.[model.id]?.headers,\n\t\t...definition?.headers,\n\t\t...extensionModel?.headers,\n\t};\n\treturn Object.keys(headers).length > 0 ? headers : undefined;\n}\n\nexport function validateExtensionProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelsConfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput,\n): void {\n\tif (extension.streamSimple && !extension.api) {\n\t\tthrow new Error(`Provider ${providerId}: \"api\" is required when registering streamSimple.`);\n\t}\n\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], modelsConfig), extension);\n}\n\n/** Compose built-in, models.json, and extension layers without reading credentials. */\nexport function composeModelProvider(\n\tproviderId: string,\n\tbase: Provider | undefined,\n\tmodelConfig: ModelConfig,\n\textension: ProviderConfigInput | undefined,\n): Provider {\n\tconst config = modelConfig.getProvider(providerId);\n\tlet extensionOAuthCredential: OAuthCredentials | undefined;\n\tlet refreshedExtensionModels: ProviderConfigInput[\"models\"];\n\tconst currentExtension = (): ProviderConfigInput | undefined =>\n\t\textension && refreshedExtensionModels ? { ...extension, models: refreshedExtensionModels } : extension;\n\t// models.json modelOverrides are the topmost user-config layer: they apply once,\n\t// after custom-model upserts, extension model replacement, and legacy OAuth projection.\n\tconst getModels = () => {\n\t\tlet models = applyExtension(\n\t\t\tproviderId,\n\t\t\tapplyModelsJson(providerId, base?.getModels() ?? [], config),\n\t\t\tcurrentExtension(),\n\t\t);\n\t\tif (extensionOAuthCredential && extension?.oauth?.modifyModels) {\n\t\t\tmodels = extension.oauth.modifyModels(models, extensionOAuthCredential);\n\t\t}\n\t\treturn models.map((model) => {\n\t\t\tconst override = config?.modelOverrides?.[model.id];\n\t\t\treturn applyCompatibilityDefaults(override ? applyModelOverride(model, override) : model);\n\t\t});\n\t};\n\t// Validate eagerly so registration/reload reports structural errors immediately.\n\tgetModels();\n\tconst apiKey = composeApiKeyAuth(providerId, base, config, extension);\n\tconst oauth = composeOAuthAuth(providerId, base, config, extension);\n\tif (!apiKey && !oauth) throw new Error(`Provider ${providerId}: no authentication method configured.`);\n\n\tconst supportsBaseApi = (model: Model<Api>) => base?.getModels().some((entry) => entry.api === model.api) ?? false;\n\tconst streamWith = (\n\t\tmodel: Model<Api>,\n\t\tcontext: Context,\n\t\toptions: StreamOptions | undefined,\n\t\tsimple: boolean,\n\t): AssistantMessageEventStream =>\n\t\tlazyStream(model, async () => {\n\t\t\tif (extension?.streamSimple && model.api === extension.api) {\n\t\t\t\treturn extension.streamSimple(model, context, options as SimpleStreamOptions);\n\t\t\t}\n\t\t\tif (base && supportsBaseApi(model)) {\n\t\t\t\treturn simple\n\t\t\t\t\t? base.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t\t: base.stream(model, context, options);\n\t\t\t}\n\t\t\tconst api = getApiProvider(model.api);\n\t\t\tif (!api) throw new Error(`No API provider registered for api: ${model.api}`);\n\t\t\treturn simple\n\t\t\t\t? api.streamSimple(model, context, options as SimpleStreamOptions)\n\t\t\t\t: api.stream(model, context, options);\n\t\t});\n\n\tconst provider: Provider = {\n\t\tid: providerId,\n\t\tname: extension?.name ?? config?.name ?? base?.name ?? extension?.oauth?.name ?? providerId,\n\t\tbaseUrl: extension?.baseUrl ?? config?.baseUrl ?? base?.baseUrl,\n\t\theaders: base?.headers,\n\t\tauth: { ...(apiKey ? { apiKey } : {}), ...(oauth ? { oauth } : {}) },\n\t\tgetModels,\n\t\trefreshModels:\n\t\t\tbase?.refreshModels || extension?.refreshModels || extension?.oauth?.modifyModels\n\t\t\t\t? async (context) => {\n\t\t\t\t\t\tawait base?.refreshModels?.(context);\n\t\t\t\t\t\tlet refreshed: NonNullable<ProviderConfigInput[\"models\"]> | undefined;\n\t\t\t\t\t\tif (extension?.refreshModels) refreshed = await extension.refreshModels(context);\n\t\t\t\t\t\tif (context.signal.aborted) return;\n\t\t\t\t\t\tconst oauthCredential = context.credential?.type === \"oauth\" ? context.credential : undefined;\n\t\t\t\t\t\tawait context.publish({\n\t\t\t\t\t\t\tupdate: () => {\n\t\t\t\t\t\t\t\tif (refreshed) {\n\t\t\t\t\t\t\t\t\t// Validate before publishing the new synchronous list.\n\t\t\t\t\t\t\t\t\tapplyExtension(providerId, applyModelsJson(providerId, base?.getModels() ?? [], config), {\n\t\t\t\t\t\t\t\t\t\t...extension,\n\t\t\t\t\t\t\t\t\t\tmodels: refreshed,\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\trefreshedExtensionModels = refreshed;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\textensionOAuthCredential = oauthCredential;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t\tfilterModels: base?.filterModels\n\t\t\t? (models, credential: Credential | undefined) => base.filterModels!(models, credential)\n\t\t\t: undefined,\n\t\tstream: (model, context, options) => streamWith(model, context, options, false),\n\t\tstreamSimple: (model, context, options) => streamWith(model, context, options, true),\n\t};\n\n\tconst fetchDeferred = base?.fetchDeferred;\n\tif (fetchDeferred) {\n\t\tprovider.fetchDeferred = (model, handle, options) => fetchDeferred(model, handle, options);\n\t}\n\tconst cancelDeferred = base?.cancelDeferred;\n\tif (cancelDeferred) {\n\t\tprovider.cancelDeferred = (model, handle, options) => cancelDeferred(model, handle, options);\n\t}\n\n\treturn provider;\n}\n\nexport function resolveConfiguredModelHeaders(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n\tenv?: Record<string, string>,\n): Record<string, string> | undefined {\n\treturn resolveHeadersOrThrow(\n\t\trawModelHeaders(model, config, extension),\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t\tenv,\n\t);\n}\n\nexport interface CompatibilityRequestConfig {\n\theaders?: ProviderHeaders;\n\tauthHeader: boolean;\n}\n\nexport function resolveCompatibilityRequestConfig(\n\tmodel: Model<Api>,\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): CompatibilityRequestConfig {\n\tconst configured = resolveHeadersOrThrow(\n\t\t{ ...configuredHeaders(config, extension), ...rawModelHeaders(model, config, extension) },\n\t\t`model \"${model.provider}/${model.id}\"`,\n\t);\n\treturn {\n\t\theaders: model.headers || configured ? { ...model.headers, ...configured } : undefined,\n\t\tauthHeader: extension?.authHeader ?? config?.authHeader ?? false,\n\t};\n}\n\nexport function configuredRequestAuthStatus(\n\tconfig: ModelsJsonProvider | undefined,\n\textension: ProviderConfigInput | undefined,\n): AuthStatus | undefined {\n\tconst value = configuredApiKey(config, extension);\n\tif (value === undefined) return undefined;\n\tif (isCommandConfigValue(value)) return { configured: true, source: \"models_json_command\" };\n\tconst names = getConfigValueEnvVarNames(value);\n\tif (names.length > 0) {\n\t\treturn isConfigValueConfigured(value)\n\t\t\t? { configured: true, source: \"environment\", label: names.join(\", \") }\n\t\t\t: { configured: false };\n\t}\n\treturn { configured: true, source: extension?.apiKey !== undefined ? \"fallback\" : \"models_json_key\" };\n}\n"]}
@@ -60,6 +60,12 @@ export interface ResourceLoader {
60
60
  export declare function loadProjectContextFiles(options: {
61
61
  cwd: string;
62
62
  agentDir: string;
63
+ /**
64
+ * Required. False keeps the checkout's and its ancestors' instruction files out, and
65
+ * leaves the agent directory's own, which is the user's and not the project's. The
66
+ * same exemption the `~/.agents/skills` walk gets, for the same reason.
67
+ */
68
+ projectTrusted: boolean;
63
69
  }): Array<{
64
70
  path: string;
65
71
  content: string;