@try-works/dsh-tool-mode 0.0.0-stage → 0.5.45

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 (432) hide show
  1. package/LICENSE +205 -0
  2. package/README.md +303 -2
  3. package/bin/dsh-tool-mode-credentials.mjs +20 -0
  4. package/bin/dsh-tool-mode-mcp-stdio.mjs +80 -0
  5. package/bin/dsh-tool-mode.mjs +211 -0
  6. package/builtins.lock.json +26 -0
  7. package/catalog/desert-ant-models.json +693 -0
  8. package/catalog/playbooks.json +531 -0
  9. package/client/client.model-tools.js +1910 -0
  10. package/client/index.js +4158 -0
  11. package/cordis.patch.yml +39 -0
  12. package/lib/adapters/index.d.ts +61 -0
  13. package/lib/adapters/index.d.ts.map +1 -0
  14. package/lib/adapters/index.js +82 -0
  15. package/lib/adapters/types.d.ts +106 -0
  16. package/lib/adapters/types.d.ts.map +1 -0
  17. package/lib/adapters/types.js +85 -0
  18. package/lib/approval.d.ts +189 -0
  19. package/lib/approval.d.ts.map +1 -0
  20. package/lib/approval.js +510 -0
  21. package/lib/asset-acquisition.d.ts +149 -0
  22. package/lib/asset-acquisition.d.ts.map +1 -0
  23. package/lib/asset-acquisition.js +175 -0
  24. package/lib/authority.d.ts +185 -0
  25. package/lib/authority.d.ts.map +1 -0
  26. package/lib/authority.js +223 -0
  27. package/lib/bindings.d.ts +144 -0
  28. package/lib/bindings.d.ts.map +1 -0
  29. package/lib/bindings.js +314 -0
  30. package/lib/builtins.d.ts +27 -0
  31. package/lib/builtins.d.ts.map +1 -0
  32. package/lib/builtins.js +37 -0
  33. package/lib/capability.d.ts +58 -0
  34. package/lib/capability.d.ts.map +1 -0
  35. package/lib/capability.js +192 -0
  36. package/lib/capture-path.d.ts +97 -0
  37. package/lib/capture-path.d.ts.map +1 -0
  38. package/lib/capture-path.js +152 -0
  39. package/lib/catalog.d.ts +37 -0
  40. package/lib/catalog.d.ts.map +1 -0
  41. package/lib/catalog.js +274 -0
  42. package/lib/contract-payload.d.ts +39 -0
  43. package/lib/contract-payload.d.ts.map +1 -0
  44. package/lib/contract-payload.js +56 -0
  45. package/lib/custom-tools/compile.d.ts +25 -0
  46. package/lib/custom-tools/compile.d.ts.map +1 -0
  47. package/lib/custom-tools/compile.js +61 -0
  48. package/lib/custom-tools/composite-executor.d.ts +42 -0
  49. package/lib/custom-tools/composite-executor.d.ts.map +1 -0
  50. package/lib/custom-tools/composite-executor.js +113 -0
  51. package/lib/custom-tools/dispatch.d.ts +28 -0
  52. package/lib/custom-tools/dispatch.d.ts.map +1 -0
  53. package/lib/custom-tools/dispatch.js +34 -0
  54. package/lib/custom-tools/http-executor.d.ts +48 -0
  55. package/lib/custom-tools/http-executor.d.ts.map +1 -0
  56. package/lib/custom-tools/http-executor.js +241 -0
  57. package/lib/custom-tools/index.d.ts +12 -0
  58. package/lib/custom-tools/index.d.ts.map +1 -0
  59. package/lib/custom-tools/index.js +12 -0
  60. package/lib/custom-tools/mcp-surface.d.ts +14 -0
  61. package/lib/custom-tools/mcp-surface.d.ts.map +1 -0
  62. package/lib/custom-tools/mcp-surface.js +41 -0
  63. package/lib/custom-tools/prompt-executor.d.ts +39 -0
  64. package/lib/custom-tools/prompt-executor.d.ts.map +1 -0
  65. package/lib/custom-tools/prompt-executor.js +59 -0
  66. package/lib/custom-tools/registry.d.ts +69 -0
  67. package/lib/custom-tools/registry.d.ts.map +1 -0
  68. package/lib/custom-tools/registry.js +130 -0
  69. package/lib/custom-tools/schema.d.ts +26 -0
  70. package/lib/custom-tools/schema.d.ts.map +1 -0
  71. package/lib/custom-tools/schema.js +375 -0
  72. package/lib/custom-tools/service.d.ts +90 -0
  73. package/lib/custom-tools/service.d.ts.map +1 -0
  74. package/lib/custom-tools/service.js +203 -0
  75. package/lib/custom-tools/store.d.ts +61 -0
  76. package/lib/custom-tools/store.d.ts.map +1 -0
  77. package/lib/custom-tools/store.js +240 -0
  78. package/lib/custom-tools/types.d.ts +131 -0
  79. package/lib/custom-tools/types.d.ts.map +1 -0
  80. package/lib/custom-tools/types.js +11 -0
  81. package/lib/decision-combine.d.ts +113 -0
  82. package/lib/decision-combine.d.ts.map +1 -0
  83. package/lib/decision-combine.js +156 -0
  84. package/lib/decision-evaluate.d.ts +185 -0
  85. package/lib/decision-evaluate.d.ts.map +1 -0
  86. package/lib/decision-evaluate.js +227 -0
  87. package/lib/deployment-coordinator.d.ts +213 -0
  88. package/lib/deployment-coordinator.d.ts.map +1 -0
  89. package/lib/deployment-coordinator.js +274 -0
  90. package/lib/diagnostics.d.ts +169 -0
  91. package/lib/diagnostics.d.ts.map +1 -0
  92. package/lib/diagnostics.js +136 -0
  93. package/lib/discovery-contracts.d.ts +14 -0
  94. package/lib/discovery-contracts.d.ts.map +1 -0
  95. package/lib/discovery-contracts.js +90 -0
  96. package/lib/discovery-describe.d.ts +35 -0
  97. package/lib/discovery-describe.d.ts.map +1 -0
  98. package/lib/discovery-describe.js +99 -0
  99. package/lib/embedding-index.d.ts +55 -0
  100. package/lib/embedding-index.d.ts.map +1 -0
  101. package/lib/embedding-index.js +126 -0
  102. package/lib/extension-dependencies.d.ts +355 -0
  103. package/lib/extension-dependencies.d.ts.map +1 -0
  104. package/lib/extension-dependencies.js +987 -0
  105. package/lib/extension-dispatch.d.ts +150 -0
  106. package/lib/extension-dispatch.d.ts.map +1 -0
  107. package/lib/extension-dispatch.js +178 -0
  108. package/lib/extension-page-state.d.ts +69 -0
  109. package/lib/extension-page-state.d.ts.map +1 -0
  110. package/lib/extension-page-state.js +82 -0
  111. package/lib/extension-registrar.d.ts +116 -0
  112. package/lib/extension-registrar.d.ts.map +1 -0
  113. package/lib/extension-registrar.js +144 -0
  114. package/lib/extensions-api.d.ts +346 -0
  115. package/lib/extensions-api.d.ts.map +1 -0
  116. package/lib/extensions-api.js +17 -0
  117. package/lib/extensions-remote.d.ts +57 -0
  118. package/lib/extensions-remote.d.ts.map +1 -0
  119. package/lib/extensions-remote.js +69 -0
  120. package/lib/extensions-service.d.ts +568 -0
  121. package/lib/extensions-service.d.ts.map +1 -0
  122. package/lib/extensions-service.js +2552 -0
  123. package/lib/harness-budgets.d.ts +158 -0
  124. package/lib/harness-budgets.d.ts.map +1 -0
  125. package/lib/harness-budgets.js +152 -0
  126. package/lib/harness-llm.d.ts +138 -0
  127. package/lib/harness-llm.d.ts.map +1 -0
  128. package/lib/harness-llm.js +218 -0
  129. package/lib/harness-serving.d.ts +115 -0
  130. package/lib/harness-serving.d.ts.map +1 -0
  131. package/lib/harness-serving.js +176 -0
  132. package/lib/headless.d.ts +97 -0
  133. package/lib/headless.d.ts.map +1 -0
  134. package/lib/headless.js +407 -0
  135. package/lib/http-acquisition.d.ts +27 -0
  136. package/lib/http-acquisition.d.ts.map +1 -0
  137. package/lib/http-acquisition.js +140 -0
  138. package/lib/index.d.ts +546 -0
  139. package/lib/index.d.ts.map +1 -0
  140. package/lib/index.js +5273 -0
  141. package/lib/invocation-accounting.d.ts +169 -0
  142. package/lib/invocation-accounting.d.ts.map +1 -0
  143. package/lib/invocation-accounting.js +148 -0
  144. package/lib/jev.d.ts +218 -0
  145. package/lib/jev.d.ts.map +1 -0
  146. package/lib/jev.js +366 -0
  147. package/lib/legacy-migration.d.ts +95 -0
  148. package/lib/legacy-migration.d.ts.map +1 -0
  149. package/lib/legacy-migration.js +429 -0
  150. package/lib/license-basis.d.ts +29 -0
  151. package/lib/license-basis.d.ts.map +1 -0
  152. package/lib/license-basis.js +58 -0
  153. package/lib/managed-workers.d.ts +158 -0
  154. package/lib/managed-workers.d.ts.map +1 -0
  155. package/lib/managed-workers.js +269 -0
  156. package/lib/mcp/auth-selection.d.ts +35 -0
  157. package/lib/mcp/auth-selection.d.ts.map +1 -0
  158. package/lib/mcp/auth-selection.js +64 -0
  159. package/lib/mcp/client-grant.d.ts +89 -0
  160. package/lib/mcp/client-grant.d.ts.map +1 -0
  161. package/lib/mcp/client-grant.js +63 -0
  162. package/lib/mcp/credential-cli.d.ts +38 -0
  163. package/lib/mcp/credential-cli.d.ts.map +1 -0
  164. package/lib/mcp/credential-cli.js +148 -0
  165. package/lib/mcp/credential-store.d.ts +143 -0
  166. package/lib/mcp/credential-store.d.ts.map +1 -0
  167. package/lib/mcp/credential-store.js +461 -0
  168. package/lib/mcp/export-policy.d.ts +25 -0
  169. package/lib/mcp/export-policy.d.ts.map +1 -0
  170. package/lib/mcp/export-policy.js +31 -0
  171. package/lib/mcp/host-binding.d.ts +144 -0
  172. package/lib/mcp/host-binding.d.ts.map +1 -0
  173. package/lib/mcp/host-binding.js +280 -0
  174. package/lib/mcp/http.d.ts +180 -0
  175. package/lib/mcp/http.d.ts.map +1 -0
  176. package/lib/mcp/http.js +602 -0
  177. package/lib/mcp/oauth.d.ts +149 -0
  178. package/lib/mcp/oauth.d.ts.map +1 -0
  179. package/lib/mcp/oauth.js +396 -0
  180. package/lib/mcp/protocol.d.ts +329 -0
  181. package/lib/mcp/protocol.d.ts.map +1 -0
  182. package/lib/mcp/protocol.js +459 -0
  183. package/lib/mcp/rate-limit.d.ts +68 -0
  184. package/lib/mcp/rate-limit.d.ts.map +1 -0
  185. package/lib/mcp/rate-limit.js +114 -0
  186. package/lib/mcp/sdk-v2.d.ts +17 -0
  187. package/lib/mcp/sdk-v2.d.ts.map +1 -0
  188. package/lib/mcp/sdk-v2.js +204 -0
  189. package/lib/mcp/server.d.ts +149 -0
  190. package/lib/mcp/server.d.ts.map +1 -0
  191. package/lib/mcp/server.js +302 -0
  192. package/lib/mcp/stdio.d.ts +80 -0
  193. package/lib/mcp/stdio.d.ts.map +1 -0
  194. package/lib/mcp/stdio.js +184 -0
  195. package/lib/mcp/subscriptions.d.ts +177 -0
  196. package/lib/mcp/subscriptions.d.ts.map +1 -0
  197. package/lib/mcp/subscriptions.js +288 -0
  198. package/lib/mcp-status.d.ts +96 -0
  199. package/lib/mcp-status.d.ts.map +1 -0
  200. package/lib/mcp-status.js +70 -0
  201. package/lib/mcp-usage.d.ts +110 -0
  202. package/lib/mcp-usage.d.ts.map +1 -0
  203. package/lib/mcp-usage.js +189 -0
  204. package/lib/model-qualification.d.ts +192 -0
  205. package/lib/model-qualification.d.ts.map +1 -0
  206. package/lib/model-qualification.js +178 -0
  207. package/lib/model-runtime-lane.d.ts +69 -0
  208. package/lib/model-runtime-lane.d.ts.map +1 -0
  209. package/lib/model-runtime-lane.js +122 -0
  210. package/lib/model-runtime-recipe.d.ts +132 -0
  211. package/lib/model-runtime-recipe.d.ts.map +1 -0
  212. package/lib/model-runtime-recipe.js +291 -0
  213. package/lib/planning.d.ts +256 -0
  214. package/lib/planning.d.ts.map +1 -0
  215. package/lib/planning.js +471 -0
  216. package/lib/playbook.d.ts +42 -0
  217. package/lib/playbook.d.ts.map +1 -0
  218. package/lib/playbook.js +65 -0
  219. package/lib/prepared-assets.d.ts +269 -0
  220. package/lib/prepared-assets.d.ts.map +1 -0
  221. package/lib/prepared-assets.js +471 -0
  222. package/lib/provider-bridge.d.ts +107 -0
  223. package/lib/provider-bridge.d.ts.map +1 -0
  224. package/lib/provider-bridge.js +423 -0
  225. package/lib/ptc-authority.d.ts +154 -0
  226. package/lib/ptc-authority.d.ts.map +1 -0
  227. package/lib/ptc-authority.js +242 -0
  228. package/lib/ptc-confinement.d.ts +60 -0
  229. package/lib/ptc-confinement.d.ts.map +1 -0
  230. package/lib/ptc-confinement.js +212 -0
  231. package/lib/ptc-runtime.d.ts +166 -0
  232. package/lib/ptc-runtime.d.ts.map +1 -0
  233. package/lib/ptc-runtime.js +231 -0
  234. package/lib/publication.d.ts +161 -0
  235. package/lib/publication.d.ts.map +1 -0
  236. package/lib/publication.js +181 -0
  237. package/lib/receipt-store.d.ts +57 -0
  238. package/lib/receipt-store.d.ts.map +1 -0
  239. package/lib/receipt-store.js +143 -0
  240. package/lib/receipt.d.ts +231 -0
  241. package/lib/receipt.d.ts.map +1 -0
  242. package/lib/receipt.js +165 -0
  243. package/lib/registrar.d.ts +75 -0
  244. package/lib/registrar.d.ts.map +1 -0
  245. package/lib/registrar.js +152 -0
  246. package/lib/resource-governance.d.ts +204 -0
  247. package/lib/resource-governance.d.ts.map +1 -0
  248. package/lib/resource-governance.js +213 -0
  249. package/lib/server-lifecycle.d.ts +175 -0
  250. package/lib/server-lifecycle.d.ts.map +1 -0
  251. package/lib/server-lifecycle.js +269 -0
  252. package/lib/skills.d.ts +31 -0
  253. package/lib/skills.d.ts.map +1 -0
  254. package/lib/skills.js +170 -0
  255. package/lib/speech-bridge.d.ts +74 -0
  256. package/lib/speech-bridge.d.ts.map +1 -0
  257. package/lib/speech-bridge.js +115 -0
  258. package/lib/state.d.ts +100 -0
  259. package/lib/state.d.ts.map +1 -0
  260. package/lib/state.js +160 -0
  261. package/lib/title-proposal.d.ts +194 -0
  262. package/lib/title-proposal.d.ts.map +1 -0
  263. package/lib/title-proposal.js +244 -0
  264. package/lib/tool-inventory.d.ts +90 -0
  265. package/lib/tool-inventory.d.ts.map +1 -0
  266. package/lib/tool-inventory.js +102 -0
  267. package/lib/tool-mode-run.d.ts +310 -0
  268. package/lib/tool-mode-run.d.ts.map +1 -0
  269. package/lib/tool-mode-run.js +411 -0
  270. package/lib/tool-sources.d.ts +80 -0
  271. package/lib/tool-sources.d.ts.map +1 -0
  272. package/lib/tool-sources.js +123 -0
  273. package/lib/tool-usage-projection.d.ts +390 -0
  274. package/lib/tool-usage-projection.d.ts.map +1 -0
  275. package/lib/tool-usage-projection.js +1038 -0
  276. package/lib/tool-usage-report.d.ts +153 -0
  277. package/lib/tool-usage-report.d.ts.map +1 -0
  278. package/lib/tool-usage-report.js +274 -0
  279. package/lib/transport.d.ts +158 -0
  280. package/lib/transport.d.ts.map +1 -0
  281. package/lib/transport.js +332 -0
  282. package/lib/types.d.ts +134 -0
  283. package/lib/types.d.ts.map +1 -0
  284. package/lib/types.js +8 -0
  285. package/lib/update-surface.d.ts +79 -0
  286. package/lib/update-surface.d.ts.map +1 -0
  287. package/lib/update-surface.js +224 -0
  288. package/lib/version.d.ts +3 -0
  289. package/lib/version.d.ts.map +1 -0
  290. package/lib/version.js +27 -0
  291. package/node_modules/@try-works/tool-mode-contracts/lib/contract-metadata.d.ts +13 -0
  292. package/node_modules/@try-works/tool-mode-contracts/lib/contract-metadata.d.ts.map +1 -0
  293. package/node_modules/@try-works/tool-mode-contracts/lib/contract-metadata.js +85 -0
  294. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts +16 -0
  295. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.d.ts.map +1 -0
  296. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/lang-detect.js +87 -0
  297. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts +38 -0
  298. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts.map +1 -0
  299. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.js +445 -0
  300. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts +20 -0
  301. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.d.ts.map +1 -0
  302. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/stt-transcribe.js +112 -0
  303. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts +14 -0
  304. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts.map +1 -0
  305. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.js +63 -0
  306. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts +14 -0
  307. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts.map +1 -0
  308. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.js +76 -0
  309. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts +82 -0
  310. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts.map +1 -0
  311. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.js +274 -0
  312. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts +26 -0
  313. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts.map +1 -0
  314. package/node_modules/@try-works/tool-mode-contracts/lib/index.js +53 -0
  315. package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts +133 -0
  316. package/node_modules/@try-works/tool-mode-contracts/lib/meta.d.ts.map +1 -0
  317. package/node_modules/@try-works/tool-mode-contracts/lib/meta.js +64 -0
  318. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts +121 -0
  319. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts.map +1 -0
  320. package/node_modules/@try-works/tool-mode-contracts/lib/registry.js +246 -0
  321. package/node_modules/@try-works/tool-mode-contracts/package.json +35 -0
  322. package/node_modules/@try-works/tool-mode-extension-sdk/bin/dsh-tool-mode.mjs +20 -0
  323. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts +80 -0
  324. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts.map +1 -0
  325. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.js +533 -0
  326. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts +86 -0
  327. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts.map +1 -0
  328. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.js +145 -0
  329. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts +70 -0
  330. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts.map +1 -0
  331. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.js +201 -0
  332. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts +57 -0
  333. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts.map +1 -0
  334. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.js +83 -0
  335. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts +33 -0
  336. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts.map +1 -0
  337. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.js +33 -0
  338. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts +86 -0
  339. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts.map +1 -0
  340. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.js +191 -0
  341. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts +137 -0
  342. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts.map +1 -0
  343. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.js +349 -0
  344. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts +274 -0
  345. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts.map +1 -0
  346. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.js +932 -0
  347. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts +210 -0
  348. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts.map +1 -0
  349. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.js +368 -0
  350. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts +63 -0
  351. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts.map +1 -0
  352. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.js +149 -0
  353. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts +35 -0
  354. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts.map +1 -0
  355. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.js +179 -0
  356. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts +179 -0
  357. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts.map +1 -0
  358. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.js +299 -0
  359. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts +395 -0
  360. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts.map +1 -0
  361. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.js +839 -0
  362. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.d.ts +44 -0
  363. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.d.ts.map +1 -0
  364. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/tar-gzip-source.js +255 -0
  365. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts +185 -0
  366. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts.map +1 -0
  367. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.js +504 -0
  368. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts +17 -0
  369. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts.map +1 -0
  370. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.js +80 -0
  371. package/node_modules/@try-works/tool-mode-extension-sdk/lib/licensing.d.ts +221 -0
  372. package/node_modules/@try-works/tool-mode-extension-sdk/lib/licensing.d.ts.map +1 -0
  373. package/node_modules/@try-works/tool-mode-extension-sdk/lib/licensing.js +188 -0
  374. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts +52 -0
  375. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts.map +1 -0
  376. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.js +102 -0
  377. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts +171 -0
  378. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts.map +1 -0
  379. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.js +271 -0
  380. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts +242 -0
  381. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts.map +1 -0
  382. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.js +58 -0
  383. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts +128 -0
  384. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts.map +1 -0
  385. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.js +113 -0
  386. package/node_modules/@try-works/tool-mode-extension-sdk/lib/test-host.d.ts +41 -0
  387. package/node_modules/@try-works/tool-mode-extension-sdk/lib/test-host.d.ts.map +1 -0
  388. package/node_modules/@try-works/tool-mode-extension-sdk/lib/test-host.js +52 -0
  389. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts +2 -0
  390. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts.map +1 -0
  391. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.js +351 -0
  392. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts +157 -0
  393. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts.map +1 -0
  394. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.js +688 -0
  395. package/node_modules/@try-works/tool-mode-extension-sdk/package.json +54 -0
  396. package/node_modules/@try-works/tool-mode-extension-sdk/schema/extension-manifest-1.1.0.schema.json +253 -0
  397. package/node_modules/@try-works/tool-mode-recipes/bin/tool-mode-recipe.mjs +15 -0
  398. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts +460 -0
  399. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts.map +1 -0
  400. package/node_modules/@try-works/tool-mode-recipes/lib/broker.js +647 -0
  401. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts +61 -0
  402. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts.map +1 -0
  403. package/node_modules/@try-works/tool-mode-recipes/lib/cli.js +1106 -0
  404. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts +237 -0
  405. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts.map +1 -0
  406. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.js +205 -0
  407. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts +85 -0
  408. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts.map +1 -0
  409. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.js +176 -0
  410. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts +119 -0
  411. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts.map +1 -0
  412. package/node_modules/@try-works/tool-mode-recipes/lib/images.js +201 -0
  413. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts +25 -0
  414. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts.map +1 -0
  415. package/node_modules/@try-works/tool-mode-recipes/lib/index.js +25 -0
  416. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts +345 -0
  417. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts.map +1 -0
  418. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.js +1465 -0
  419. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts +51 -0
  420. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts.map +1 -0
  421. package/node_modules/@try-works/tool-mode-recipes/lib/templates.js +310 -0
  422. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts +231 -0
  423. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts.map +1 -0
  424. package/node_modules/@try-works/tool-mode-recipes/lib/titles.js +435 -0
  425. package/node_modules/@try-works/tool-mode-recipes/package.json +56 -0
  426. package/node_modules/@try-works/tool-mode-recipes/recipes/describe-image.json +38 -0
  427. package/node_modules/@try-works/tool-mode-recipes/recipes/text-title.json +45 -0
  428. package/node_modules/@try-works/tool-mode-recipes/schema/harness-model-recipe.schema.json +273 -0
  429. package/package.json +127 -4
  430. package/remote/spec.mjs +993 -0
  431. package/remote/typert.host.mjs +14 -0
  432. package/remote/typert.remote-client.mjs +16 -0
@@ -0,0 +1,647 @@
1
+ /**
2
+ * The DSH LLM broker: one provider-neutral harness executor for declarative recipes
3
+ * (HLM-01, HLM-02, HLM-05, HLM-06, HLM-07, HLM-09, HLM-10, HLM-11).
4
+ *
5
+ * The broker's whole job is to build ONE request that contains nothing but the recipe's
6
+ * instructions and the validated bound inputs, and then to report honestly what came
7
+ * back. Every invariant here is a way the request could stop being that request, or the
8
+ * result stop being the result:
9
+ *
10
+ * - **The request is isolated by construction.** It is built from the recipe and the
11
+ * bound values alone. There is no parameter through which parent history, a parent
12
+ * system prompt, a tool catalog, skills, attachments or memory could arrive, and the
13
+ * shape is frozen so nothing can be added to it after validation (HLM-05, AT-68).
14
+ * - **Images are typed media, or the call is refused.** An image recipe on a provider
15
+ * whose capabilities do not cover images fails with `IMAGE_INPUT_UNAVAILABLE`. It does
16
+ * not quietly degrade to a text-only call that "describes" an image the model never
17
+ * received — that fallback produces a fluent invention, which is worse than an error
18
+ * (HLM-11).
19
+ * - **An unknown capability is not permission.** A provider that has not reported its
20
+ * image support fails with `EXECUTOR_CAPABILITY_UNKNOWN` rather than being assumed
21
+ * capable (MODEL-06's three-state rule, reused here).
22
+ * - **Remote is a policy decision, not an implementation detail.** `permitsDestination`
23
+ * is mirrored from RES-10 so a local-only profile refuses a remote provider however
24
+ * the tool was built.
25
+ * - **Cancellation is reported as cancellation.** An aborted signal can never produce a
26
+ * success, and never an empty one: an empty success is exactly what a caller writes
27
+ * into a document (HLM-10).
28
+ * - **Refusal, truncation, an empty completion and a stray tool call are errors, each
29
+ * with its own code.** HLM-07 requires them to be distinct failures, because a caller
30
+ * that cannot tell "the model refused" from "the model was cut off" cannot respond
31
+ * correctly to either (RCP-11).
32
+ * - **Recording is a precondition, not a side effect.** A recipe that declines recording
33
+ * under a host that requires it is refused with `CAPTURE_POLICY_CONFLICT` BEFORE the
34
+ * provider is called, because refusing after the call would report a refusal for work
35
+ * that has already been billed (HLM-09).
36
+ *
37
+ * @module @try-works/tool-mode-recipes/broker
38
+ */
39
+ import { errorCodeOf, INITIAL_MAX_IMAGE_INPUTS, INITIAL_MAX_OUTPUT_TOKENS, renderPrompt, validateRecipeInputs, } from "./recipe-format.js";
40
+ /**
41
+ * RCP-11: the complete public vocabulary, exported so a host projects THESE codes
42
+ * into its own transport instead of inventing or flattening one.
43
+ */
44
+ export const BROKER_ERROR_CODES = Object.freeze([
45
+ 'EXECUTOR_NOT_CONFIGURED',
46
+ 'EXECUTOR_CAPABILITY_UNKNOWN',
47
+ 'UNSUPPORTED_MODALITY',
48
+ 'IMAGE_INPUT_UNAVAILABLE',
49
+ 'IMAGE_INPUT_INVALID',
50
+ 'CAPTURE_POLICY_CONFLICT',
51
+ 'MODEL_REFUSED',
52
+ 'MODEL_OUTPUT_TRUNCATED',
53
+ 'INVALID_MODEL_OUTPUT',
54
+ 'UNEXPECTED_MODEL_TOOL_CALL',
55
+ 'MODEL_BUDGET_EXCEEDED',
56
+ 'INVALID_RECIPE',
57
+ 'RECIPE_BINDING_ERROR',
58
+ 'CANCELLED',
59
+ 'PROVIDER_FAILED',
60
+ 'RECORDING_FAILED',
61
+ ]);
62
+ /**
63
+ * The initial policy: RES-10's initial per-leaf maxima, with recording required.
64
+ *
65
+ * Recording defaults to REQUIRED because HLM-09 makes reconstructability a DSH
66
+ * requirement, and a default of "off" is how a harness call ends up unrecorded without
67
+ * anyone deciding that.
68
+ */
69
+ export const INITIAL_HOST_POLICY = {
70
+ requireRecording: true,
71
+ remoteDestinations: true,
72
+ outputTokens: INITIAL_MAX_OUTPUT_TOKENS,
73
+ imageInputs: INITIAL_MAX_IMAGE_INPUTS,
74
+ };
75
+ /** A local-only policy, which forbids remote destinations however the tool was built. */
76
+ export const LOCAL_ONLY_HOST_POLICY = {
77
+ ...INITIAL_HOST_POLICY,
78
+ remoteDestinations: false,
79
+ };
80
+ /**
81
+ * Whether a policy permits reaching a destination (RES-10).
82
+ *
83
+ * Mirrored from the host's `harness-budgets.permitsDestination`: a local-only profile
84
+ * prohibits remote destinations INDEPENDENTLY of how the tool was implemented, so this
85
+ * asks the policy rather than the implementation. `local` is always permitted.
86
+ * @param policy - the policy in force.
87
+ * @param destination - the destination being considered.
88
+ * @returns whether it is permitted.
89
+ */
90
+ export function permitsDestination(policy, destination) {
91
+ return destination === 'local' ? true : policy.remoteDestinations;
92
+ }
93
+ /**
94
+ * Narrow a policy by a requested reduction (RES-10, HLM-07).
95
+ *
96
+ * Every figure takes the MINIMUM, so a request can only lower a limit; that direction is
97
+ * the point, since a caller asking for more than the profile permits must get the
98
+ * profile's figure. `requireRecording` is an OR: a request can demand recording where
99
+ * the base was silent, and can never switch it off.
100
+ * @param base - the policy in force.
101
+ * @param requested - what the caller asked for.
102
+ * @returns the effective policy.
103
+ */
104
+ export function narrowBrokerPolicy(base, requested) {
105
+ const lower = (a, b) => (b === undefined ? a : Math.min(a, b));
106
+ return {
107
+ requireRecording: base.requireRecording || (requested.requireRecording ?? false),
108
+ // A reduction can never ENABLE remote destinations, so this is an AND.
109
+ remoteDestinations: base.remoteDestinations && (requested.remoteDestinations ?? true),
110
+ outputTokens: lower(base.outputTokens, requested.outputTokens),
111
+ imageInputs: lower(base.imageInputs, requested.imageInputs),
112
+ };
113
+ }
114
+ /** Raised by {@link HarnessBroker.runOrThrow}. */
115
+ export class BrokerError extends Error {
116
+ name = 'BrokerError';
117
+ /** The failure code. */
118
+ code;
119
+ constructor(code, message) {
120
+ super(`${code}: ${message}`);
121
+ this.code = code;
122
+ }
123
+ }
124
+ /** Normalise the two-state shorthand into the three-state capability. */
125
+ function imageCapability(value) {
126
+ if (value === true)
127
+ return 'supported';
128
+ if (value === false)
129
+ return 'unsupported';
130
+ return value;
131
+ }
132
+ /** Name a thrown value for a failure reason. */
133
+ function messageOf(error) {
134
+ try {
135
+ return error instanceof Error ? error.message : String(error);
136
+ }
137
+ catch {
138
+ return '<unrenderable>';
139
+ }
140
+ }
141
+ /** The codes a binding error may carry, most specific first in the report. */
142
+ const BINDING_CODES = ['RECIPE_BINDING_ERROR', 'MODEL_BUDGET_EXCEEDED', 'UNSUPPORTED_MODALITY'];
143
+ /**
144
+ * The code a binding failure reports.
145
+ *
146
+ * The individual errors carry their own codes, and collapsing a specific one into a
147
+ * blanket `RECIPE_BINDING_ERROR` would destroy the distinction RCP-11 exists to keep: a
148
+ * caller that cannot tell "you sent a PDF where an image belongs" from "you misspelled a
149
+ * field" cannot respond correctly to either. The first error is used, because that is the
150
+ * one the caller has to fix first.
151
+ * @param errors - the rendered binding errors.
152
+ * @returns the code to report.
153
+ */
154
+ function bindingCode(errors) {
155
+ const code = errorCodeOf(errors[0] ?? '');
156
+ return BINDING_CODES.find(candidate => candidate === code) ?? 'RECIPE_BINDING_ERROR';
157
+ }
158
+ /**
159
+ * Build the ONE request a recipe can produce (HLM-05).
160
+ *
161
+ * Exported because the isolation property deserves to be checkable without a provider:
162
+ * the request object's key set IS the claim that nothing else is sent.
163
+ * @param recipe - the recipe being run.
164
+ * @param values - validated bindings.
165
+ * @param maxOutputTokens - the effective ceiling.
166
+ * @param signal - the cancellation channel.
167
+ * @returns the frozen request.
168
+ */
169
+ export function buildIsolatedRequest(recipe, values, maxOutputTokens, signal) {
170
+ const images = imagesOf(recipe, values);
171
+ return Object.freeze({
172
+ prompt: renderPrompt(recipe, values),
173
+ ...(images.length === 0
174
+ ? {}
175
+ : { images: Object.freeze(images.map(image => Object.freeze({ mediaType: image.mediaType, bytes: image.bytes }))) }),
176
+ maxOutputTokens,
177
+ signal,
178
+ /*
179
+ * `system` is absent, and that is the assertion: a recipe in this format cannot
180
+ * supply a system prompt, and the parent's must not be inherited (HLM-05). A request
181
+ * with a system member would be one built from something other than the recipe.
182
+ */
183
+ });
184
+ }
185
+ /** The bound images of a recipe, in declaration order. */
186
+ function imagesOf(recipe, values) {
187
+ const images = [];
188
+ for (const [name, declaration] of Object.entries(recipe.inputs)) {
189
+ if (declaration.type !== 'image')
190
+ continue;
191
+ const value = values[name];
192
+ if (value !== undefined)
193
+ images.push(value);
194
+ }
195
+ return images;
196
+ }
197
+ /**
198
+ * The harness broker.
199
+ *
200
+ * One instance holds the authorizations (which tool may use which provider generation)
201
+ * and the host policy. It is deliberately not a registry of tools: nothing here switches
202
+ * on a tool name, which is what RCP-12 forbids and what the tests assert by running two
203
+ * different recipes through the same code path.
204
+ */
205
+ export class HarnessBroker {
206
+ #grants = new Map();
207
+ #policy;
208
+ #record;
209
+ constructor(options = {}) {
210
+ this.#policy = options.policy ?? INITIAL_HOST_POLICY;
211
+ this.#record = options.record;
212
+ /**
213
+ * Refuse to exist in a state where recording would be claimed and not performed.
214
+ *
215
+ * The alternative — accepting the policy and journaling nothing — is the failure
216
+ * mode HLM-09 names: a request that must be reconstructable and is not, with nothing
217
+ * in the pipeline looking wrong.
218
+ */
219
+ if (this.#policy.requireRecording && this.#record === undefined) {
220
+ throw new Error('the host policy requires recording (HLM-09) but no journal sink was provided. Refusing to construct a broker '
221
+ + 'that would report recorded requests it never recorded; pass a sink or set requireRecording to false');
222
+ }
223
+ }
224
+ /** The host policy in force. */
225
+ get policy() {
226
+ return this.#policy;
227
+ }
228
+ /**
229
+ * Authorize a provider generation for one tool (HLM-02).
230
+ *
231
+ * The generation is CAPTURED here rather than read at dispatch time, so a provider that
232
+ * reloads between authorization and dispatch stops being authorized instead of being
233
+ * silently used under the old decision.
234
+ * @param toolName - the tool this authorization covers.
235
+ * @param provider - the provider.
236
+ */
237
+ authorize(toolName, provider) {
238
+ const grant = { toolName, provider, generation: provider.generation };
239
+ this.#grants.set(toolName, grant);
240
+ return grant;
241
+ }
242
+ /**
243
+ * Revoke a tool's authorization.
244
+ * @param toolName - the tool to revoke.
245
+ * @returns whether an authorization existed.
246
+ */
247
+ revoke(toolName) {
248
+ return this.#grants.delete(toolName);
249
+ }
250
+ /**
251
+ * The live authorization for a tool, or `undefined`.
252
+ *
253
+ * `undefined` covers both "never authorized" and "authorized for a generation this
254
+ * provider no longer is", because from a caller's point of view both mean the same
255
+ * thing: this invocation has no authorized executor. {@link resolveGrant} keeps the
256
+ * two apart for the error message.
257
+ * @param toolName - the tool to look up.
258
+ * @returns the grant, when it is still valid.
259
+ */
260
+ grantFor(toolName) {
261
+ const resolved = this.#resolveGrant(toolName);
262
+ return resolved.kind === 'ok' ? this.#grants.get(toolName) : undefined;
263
+ }
264
+ /** Resolve, keeping "missing" and "stale" distinct for the refusal reason. */
265
+ #resolveGrant(toolName) {
266
+ const grant = this.#grants.get(toolName);
267
+ if (grant === undefined)
268
+ return { kind: 'missing' };
269
+ const current = grant.provider.generation;
270
+ if (current !== grant.generation) {
271
+ return { kind: 'stale', authorized: grant.generation, current };
272
+ }
273
+ return { kind: 'ok', provider: grant.provider, generation: grant.generation };
274
+ }
275
+ /**
276
+ * Run one recipe invocation.
277
+ *
278
+ * Cancellation, policy refusals and provider failures all come back as outcomes rather
279
+ * than exceptions, so a caller that must report a result cannot lose one to an
280
+ * unhandled rejection. Use {@link runOrThrow} where an exception is the right shape.
281
+ * @param recipe - the recipe to run.
282
+ * @param args - the caller's arguments, validated against the recipe's inputs.
283
+ * @param options - the cancellation channel and deadline.
284
+ * @returns the outcome: never a success that carries no text.
285
+ */
286
+ async run(recipe, args, options = {}) {
287
+ const controller = new AbortController();
288
+ let cancelReason = 'the caller aborted the invocation';
289
+ const caller = options.signal;
290
+ const onCallerAbort = () => {
291
+ cancelReason = 'the caller aborted the invocation';
292
+ controller.abort();
293
+ };
294
+ if (caller !== undefined) {
295
+ if (caller.aborted) {
296
+ cancelReason = 'the caller aborted the invocation before it started';
297
+ controller.abort();
298
+ }
299
+ else {
300
+ caller.addEventListener('abort', onCallerAbort, { once: true });
301
+ }
302
+ }
303
+ const deadlineMs = options.deadlineMs;
304
+ const startedAt = performance.now();
305
+ const timer = deadlineMs === undefined
306
+ ? undefined
307
+ : setTimeout(() => {
308
+ cancelReason = `the invocation deadline of ${deadlineMs}ms expired`;
309
+ controller.abort();
310
+ }, deadlineMs);
311
+ try {
312
+ return await this.#invoke(recipe, args, controller.signal, () => cancelReason, startedAt, options.policy ?? this.#policy);
313
+ }
314
+ finally {
315
+ // Cleaning up here is not tidiness: a listener left on a long-lived signal is a
316
+ // leak per invocation, and a timer left running keeps the process alive.
317
+ if (timer !== undefined)
318
+ clearTimeout(timer);
319
+ if (caller !== undefined)
320
+ caller.removeEventListener('abort', onCallerAbort);
321
+ }
322
+ }
323
+ /**
324
+ * Run one recipe invocation, throwing on failure or cancellation.
325
+ * @param recipe - the recipe to run.
326
+ * @param args - the caller's arguments.
327
+ * @param options - the cancellation channel and deadline.
328
+ * @returns the completed outcome.
329
+ * @throws BrokerError on any failure, including cancellation.
330
+ */
331
+ async runOrThrow(recipe, args, options = {}) {
332
+ const outcome = await this.run(recipe, args, options);
333
+ if (outcome.kind === 'completed')
334
+ return outcome;
335
+ if (outcome.kind === 'cancelled')
336
+ throw new BrokerError('CANCELLED', outcome.reason);
337
+ throw new BrokerError(outcome.code, outcome.reason);
338
+ }
339
+ /** The invocation itself: checks in the order they must happen, then one dispatch. */
340
+ async #invoke(recipe, args, signal, reason, startedAt, policy) {
341
+ // Cancellation first: a cancelled call must not do any of the work below, and the
342
+ // provider must not be called at all.
343
+ if (signal.aborted)
344
+ return { kind: 'cancelled', reason: reason() };
345
+ const binding = validateRecipeInputs(recipe, args);
346
+ if (!binding.ok) {
347
+ return { kind: 'failed', code: bindingCode(binding.errors), reason: binding.errors.join('; ') };
348
+ }
349
+ const resolved = this.#resolveGrant(recipe.tool.name);
350
+ if (resolved.kind === 'missing') {
351
+ return {
352
+ kind: 'failed',
353
+ code: 'EXECUTOR_NOT_CONFIGURED',
354
+ reason: `no executor is authorized for ${recipe.tool.name}. A recipe is a request for a host-approved harness `
355
+ + 'model, not an authorization to reach one (RCP-05)',
356
+ };
357
+ }
358
+ if (resolved.kind === 'stale') {
359
+ return {
360
+ kind: 'failed',
361
+ code: 'EXECUTOR_NOT_CONFIGURED',
362
+ reason: `the authorization for ${recipe.tool.name} covers provider generation ${resolved.authorized}, but the `
363
+ + `provider now reports generation ${resolved.current}. An authorization is for a generation, not for a `
364
+ + 'name: re-authorize it rather than running new endpoint code under the old decision (HLM-02)',
365
+ };
366
+ }
367
+ const provider = resolved.provider;
368
+ /**
369
+ * ONE capability snapshot per invocation.
370
+ *
371
+ * Reading capabilities again after the call, or per check, is how one model's facts
372
+ * end up combined with another endpoint's after a concurrent switch (HLM-02).
373
+ */
374
+ const capabilities = provider.capabilities();
375
+ if (capabilities.inputModalities !== undefined && !capabilities.inputModalities.includes('text')) {
376
+ return {
377
+ kind: 'failed',
378
+ code: 'UNSUPPORTED_MODALITY',
379
+ reason: `provider "${provider.id}" declares input modalities ${capabilities.inputModalities.join(', ')}, `
380
+ + 'which do not include text; a recipe prompt cannot be sent as a modality the model does not accept',
381
+ };
382
+ }
383
+ if (capabilities.outputModalities !== undefined && !capabilities.outputModalities.includes('text')) {
384
+ return {
385
+ kind: 'failed',
386
+ code: 'UNSUPPORTED_MODALITY',
387
+ reason: `provider "${provider.id}" declares output modalities ${capabilities.outputModalities.join(', ')}, `
388
+ + 'which do not include text; this recipe cannot consume its output',
389
+ };
390
+ }
391
+ const values = binding.values;
392
+ const images = imagesOf(recipe, values);
393
+ if (images.length > 0 && capabilities.inputModalities !== undefined
394
+ && !capabilities.inputModalities.includes('image')) {
395
+ return {
396
+ kind: 'failed',
397
+ code: 'IMAGE_INPUT_UNAVAILABLE',
398
+ reason: `provider "${provider.id}" declares input modalities ${capabilities.inputModalities.join(', ')}, `
399
+ + 'which do not include image; the image capability flag is not allowed to override the declared modalities',
400
+ };
401
+ }
402
+ if (images.length > 0) {
403
+ const imagesCapability = imageCapability(capabilities.images);
404
+ if (imagesCapability === 'unsupported') {
405
+ return {
406
+ kind: 'failed',
407
+ code: 'IMAGE_INPUT_UNAVAILABLE',
408
+ reason: `${recipe.tool.name} binds ${images.length} image input(s) but provider "${provider.id}" reports no `
409
+ + 'image support. Refusing rather than sending the text alone: a model asked to describe an image it never '
410
+ + 'received produces a fluent invention, and that is worse than an error (HLM-11)',
411
+ };
412
+ }
413
+ if (imagesCapability === 'unknown') {
414
+ return {
415
+ kind: 'failed',
416
+ code: 'EXECUTOR_CAPABILITY_UNKNOWN',
417
+ reason: `provider "${provider.id}" has not reported whether it accepts images, and ${recipe.tool.name} binds `
418
+ + 'an image input. An unevaluated capability is not a capability: refusing rather than assuming it '
419
+ + '(MODEL-06)',
420
+ };
421
+ }
422
+ }
423
+ /**
424
+ * The image ceiling is the INTERSECTION of every limit (HLM-07, RES-10).
425
+ *
426
+ * A narrowed host policy must be able to refuse images a recipe permits, which is
427
+ * the only direction a limit may move.
428
+ */
429
+ const imageCeiling = Math.min(recipe.imageInputs.max, policy.imageInputs, INITIAL_MAX_IMAGE_INPUTS);
430
+ if (images.length > imageCeiling) {
431
+ return {
432
+ kind: 'failed',
433
+ code: 'MODEL_BUDGET_EXCEEDED',
434
+ reason: `${images.length} image input(s) supplied against an effective ceiling of ${imageCeiling} (recipe `
435
+ + `${recipe.imageInputs.max}, host ${policy.imageInputs}, RES-10 ${INITIAL_MAX_IMAGE_INPUTS})`,
436
+ };
437
+ }
438
+ if (!permitsDestination(policy, provider.destination)) {
439
+ return {
440
+ kind: 'failed',
441
+ code: 'EXECUTOR_NOT_CONFIGURED',
442
+ reason: `provider "${provider.id}" is a ${provider.destination} destination and the policy in force permits `
443
+ + 'local destinations only. A local-only profile prohibits remote destinations however the tool was built, '
444
+ + 'so this is refused rather than routed (RES-10)',
445
+ };
446
+ }
447
+ const maxOutputTokens = Math.min(recipe.maxOutputTokens, policy.outputTokens, capabilities.maxOutputTokens);
448
+ if (!Number.isInteger(maxOutputTokens) || maxOutputTokens < 1) {
449
+ return {
450
+ kind: 'failed',
451
+ code: 'MODEL_BUDGET_EXCEEDED',
452
+ reason: `the effective output-token ceiling is ${maxOutputTokens} (recipe ${recipe.maxOutputTokens}, host `
453
+ + `${policy.outputTokens}, provider ${capabilities.maxOutputTokens}). A call permitted to produce `
454
+ + 'nothing cannot produce a result (RES-10)',
455
+ };
456
+ }
457
+ /**
458
+ * Recording is settled BEFORE dispatch.
459
+ *
460
+ * HLM-09: if mandatory recording conflicts with policy, refuse rather than silently
461
+ * drop it. Refusing here means no provider is called, so a refused invocation is not
462
+ * a billed one.
463
+ */
464
+ if (!recipe.policy.record && policy.requireRecording) {
465
+ return {
466
+ kind: 'failed',
467
+ code: 'CAPTURE_POLICY_CONFLICT',
468
+ reason: `${recipe.tool.name} declares record: false while the host requires the prepared request to be `
469
+ + 'journaled. Refusing rather than running unrecorded: a request that must be reconstructable and is not is '
470
+ + 'the failure HLM-09 names, and it leaves nothing in the pipeline looking wrong',
471
+ };
472
+ }
473
+ let recorded = false;
474
+ /**
475
+ * The request is built BEFORE the journal entry, and the entry quotes THAT request.
476
+ *
477
+ * HLM-09 asks the journal to record the exact prepared request. Rendering the prompt
478
+ * separately for the entry would make the record a second rendering that merely ought
479
+ * to agree with the one that was sent; quoting the request's own prompt makes the two
480
+ * the same string by construction.
481
+ */
482
+ const request = buildIsolatedRequest(recipe, values, maxOutputTokens, signal);
483
+ if (recipe.policy.record) {
484
+ const sink = this.#record;
485
+ if (sink === undefined) {
486
+ return {
487
+ kind: 'failed',
488
+ code: 'CAPTURE_POLICY_CONFLICT',
489
+ reason: 'recording is required but no journal sink is configured, so the prepared request would be lost',
490
+ };
491
+ }
492
+ const entry = {
493
+ kind: 'harness-model-auxiliary-call',
494
+ toolName: recipe.tool.name,
495
+ contractId: recipe.tool.contractId,
496
+ recipeId: recipe.id,
497
+ recipeVersion: recipe.version,
498
+ providerId: provider.id,
499
+ providerGeneration: resolved.generation,
500
+ destination: provider.destination,
501
+ maxOutputTokens,
502
+ imageCount: images.length,
503
+ prompt: request.prompt,
504
+ context: 'recipe-only',
505
+ };
506
+ try {
507
+ await sink(entry);
508
+ recorded = true;
509
+ }
510
+ catch (error) {
511
+ return {
512
+ kind: 'failed',
513
+ code: 'RECORDING_FAILED',
514
+ reason: `the auxiliary-call journal rejected the entry (${messageOf(error)}), so the call did not run. A call `
515
+ + 'whose record cannot be written is not one this broker will make',
516
+ };
517
+ }
518
+ }
519
+ const dispatched = await dispatch(provider, request, signal, reason);
520
+ if (dispatched.kind === 'cancelled')
521
+ return { kind: 'cancelled', reason: dispatched.reason };
522
+ if (dispatched.kind === 'failed') {
523
+ return { kind: 'failed', code: 'PROVIDER_FAILED', reason: dispatched.reason };
524
+ }
525
+ /**
526
+ * A signal aborted while the provider was working is a cancellation, whatever came
527
+ * back.
528
+ *
529
+ * Checking after the await is the difference between "we stopped asking" and "we
530
+ * stopped caring": the caller cancelled, so a result that arrived afterwards is not
531
+ * one it asked for, and reporting it as a success would attach an answer to a
532
+ * cancelled invocation (HLM-10).
533
+ */
534
+ if (signal.aborted) {
535
+ return { kind: 'cancelled', reason: `${reason()}; the provider's result was discarded rather than reported` };
536
+ }
537
+ /**
538
+ * The generation is rechecked when the call returns, and a change makes the result
539
+ * UNATTRIBUTABLE.
540
+ *
541
+ * HLM-02 forbids combining one model's capability facts with another endpoint, and a
542
+ * provider that reloads while the call is in flight leaves the broker holding a result
543
+ * it cannot honestly attribute to either generation. Reporting it under the resolved
544
+ * generation would be a receipt claiming provenance the broker does not have.
545
+ */
546
+ if (provider.generation !== resolved.generation) {
547
+ return {
548
+ kind: 'failed',
549
+ code: 'PROVIDER_FAILED',
550
+ reason: `provider "${provider.id}" changed generation from ${resolved.generation} to ${provider.generation} `
551
+ + 'while the call was in flight, so the result cannot be attributed to the endpoint this invocation '
552
+ + 'resolved. Refusing rather than reporting it under either generation (HLM-02)',
553
+ };
554
+ }
555
+ const completion = dispatched.completion;
556
+ const identity = {
557
+ provider: { id: provider.id, generation: resolved.generation, destination: provider.destination },
558
+ recipe: {
559
+ id: recipe.id,
560
+ version: recipe.version,
561
+ toolName: recipe.tool.name,
562
+ contractId: recipe.tool.contractId,
563
+ },
564
+ };
565
+ switch (completion.kind) {
566
+ case 'refused':
567
+ return {
568
+ kind: 'failed',
569
+ code: 'MODEL_REFUSED',
570
+ reason: `the model declined: ${completion.reason}. A refusal is an error and never an empty result, because a `
571
+ + 'caller writing an empty result into a document sees a blank field rather than a failure',
572
+ };
573
+ case 'truncated':
574
+ return {
575
+ kind: 'failed',
576
+ code: 'MODEL_OUTPUT_TRUNCATED',
577
+ reason: 'the generation was cut short, so no complete result was produced. Partial prose is not a successful '
578
+ + 'result (HLM-07)',
579
+ };
580
+ case 'tool_call':
581
+ return {
582
+ kind: 'failed',
583
+ code: 'UNEXPECTED_MODEL_TOOL_CALL',
584
+ reason: `the provider emitted a tool call for "${completion.toolName}". No tool catalog was supplied, so a `
585
+ + 'tool call is not executed and no agent loop continues from it (HLM-06)',
586
+ };
587
+ case 'text': {
588
+ if (completion.text.trim().length === 0) {
589
+ return {
590
+ kind: 'failed',
591
+ code: 'INVALID_MODEL_OUTPUT',
592
+ reason: 'the provider returned empty text. An empty completion is not a result: reporting it as one '
593
+ + 'produces an empty title, an empty description and no error anywhere',
594
+ };
595
+ }
596
+ const usage = completion.usage ?? {
597
+ known: false,
598
+ reason: 'the provider reported no usage for this call',
599
+ };
600
+ return {
601
+ kind: 'completed',
602
+ text: completion.text,
603
+ usage,
604
+ aggregate: {
605
+ attempts: 1,
606
+ images: images.length,
607
+ elapsedMs: Math.max(0, performance.now() - startedAt),
608
+ usage,
609
+ },
610
+ recorded,
611
+ ...identity,
612
+ };
613
+ }
614
+ }
615
+ }
616
+ }
617
+ /**
618
+ * Dispatch one call, honouring cancellation and turning a provider throw into a failure.
619
+ * @param provider - the provider.
620
+ * @param request - the isolated request.
621
+ * @param signal - the cancellation channel.
622
+ * @param reason - reads the current cancellation reason.
623
+ * @returns how the dispatch settled.
624
+ */
625
+ async function dispatch(provider, request, signal, reason) {
626
+ if (signal.aborted)
627
+ return { kind: 'cancelled', reason: reason() };
628
+ let onAbort;
629
+ const cancelled = new Promise((resolve) => {
630
+ onAbort = () => resolve({ kind: 'cancelled', reason: reason() });
631
+ signal.addEventListener('abort', onAbort, { once: true });
632
+ });
633
+ try {
634
+ return await Promise.race([
635
+ provider.complete(request).then((completion) => ({ kind: 'completion', completion }),
636
+ // The provider's own rejection is handled here rather than escaping as an
637
+ // unhandled rejection after a cancellation already won the race.
638
+ (error) => ({ kind: 'failed', reason: `provider "${provider.id}" failed: ${messageOf(error)}` })),
639
+ cancelled,
640
+ ]);
641
+ }
642
+ finally {
643
+ if (onAbort !== undefined)
644
+ signal.removeEventListener('abort', onAbort);
645
+ }
646
+ }
647
+ //# sourceMappingURL=broker.js.map