@try-works/dsh-model-as-tool 0.1.3 → 0.3.6

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 (257) hide show
  1. package/bin/dsh-tool-mode-credentials.mjs +20 -0
  2. package/bin/dsh-tool-mode.mjs +202 -0
  3. package/catalog/desert-ant-models.json +693 -693
  4. package/client/client.model-tools.js +592 -0
  5. package/client/index.js +1679 -0
  6. package/lib/adapters/index.d.ts.map +1 -1
  7. package/lib/adapters/index.js +4 -4
  8. package/lib/bindings.d.ts.map +1 -1
  9. package/lib/bindings.js +26 -25
  10. package/lib/capability.d.ts.map +1 -1
  11. package/lib/capability.js +17 -0
  12. package/lib/capture-path.d.ts +97 -0
  13. package/lib/capture-path.d.ts.map +1 -0
  14. package/lib/capture-path.js +152 -0
  15. package/lib/diagnostics.d.ts +166 -0
  16. package/lib/diagnostics.d.ts.map +1 -0
  17. package/lib/diagnostics.js +135 -0
  18. package/lib/extension-dependencies.d.ts +197 -0
  19. package/lib/extension-dependencies.d.ts.map +1 -0
  20. package/lib/extension-dependencies.js +369 -0
  21. package/lib/extension-dispatch.d.ts +117 -0
  22. package/lib/extension-dispatch.d.ts.map +1 -0
  23. package/lib/extension-dispatch.js +124 -0
  24. package/lib/extension-registrar.d.ts +100 -0
  25. package/lib/extension-registrar.d.ts.map +1 -0
  26. package/lib/extension-registrar.js +134 -0
  27. package/lib/extensions-api.d.ts +217 -0
  28. package/lib/extensions-api.d.ts.map +1 -0
  29. package/lib/extensions-api.js +17 -0
  30. package/lib/extensions-remote.d.ts +54 -0
  31. package/lib/extensions-remote.d.ts.map +1 -0
  32. package/lib/extensions-remote.js +66 -0
  33. package/lib/extensions-service.d.ts +334 -0
  34. package/lib/extensions-service.d.ts.map +1 -0
  35. package/lib/extensions-service.js +1351 -0
  36. package/lib/harness-llm.d.ts +138 -0
  37. package/lib/harness-llm.d.ts.map +1 -0
  38. package/lib/harness-llm.js +218 -0
  39. package/lib/harness-serving.d.ts +95 -0
  40. package/lib/harness-serving.d.ts.map +1 -0
  41. package/lib/harness-serving.js +157 -0
  42. package/lib/headless.d.ts +97 -0
  43. package/lib/headless.d.ts.map +1 -0
  44. package/lib/headless.js +349 -0
  45. package/lib/http-acquisition.d.ts +27 -0
  46. package/lib/http-acquisition.d.ts.map +1 -0
  47. package/lib/http-acquisition.js +136 -0
  48. package/lib/index.d.ts +250 -7
  49. package/lib/index.d.ts.map +1 -1
  50. package/lib/index.js +2625 -70
  51. package/lib/invocation-accounting.d.ts +169 -0
  52. package/lib/invocation-accounting.d.ts.map +1 -0
  53. package/lib/invocation-accounting.js +148 -0
  54. package/lib/legacy-migration.d.ts +95 -0
  55. package/lib/legacy-migration.d.ts.map +1 -0
  56. package/lib/legacy-migration.js +429 -0
  57. package/lib/managed-workers.d.ts +151 -0
  58. package/lib/managed-workers.d.ts.map +1 -0
  59. package/lib/managed-workers.js +249 -0
  60. package/lib/mcp/client-grant.d.ts +74 -0
  61. package/lib/mcp/client-grant.d.ts.map +1 -0
  62. package/lib/mcp/client-grant.js +60 -0
  63. package/lib/mcp/credential-cli.d.ts +38 -0
  64. package/lib/mcp/credential-cli.d.ts.map +1 -0
  65. package/lib/mcp/credential-cli.js +148 -0
  66. package/lib/mcp/credential-store.d.ts +143 -0
  67. package/lib/mcp/credential-store.d.ts.map +1 -0
  68. package/lib/mcp/credential-store.js +454 -0
  69. package/lib/mcp/host-binding.d.ts +25 -0
  70. package/lib/mcp/host-binding.d.ts.map +1 -1
  71. package/lib/mcp/host-binding.js +107 -14
  72. package/lib/mcp/http.d.ts +68 -18
  73. package/lib/mcp/http.d.ts.map +1 -1
  74. package/lib/mcp/http.js +390 -62
  75. package/lib/mcp/oauth.d.ts +149 -0
  76. package/lib/mcp/oauth.d.ts.map +1 -0
  77. package/lib/mcp/oauth.js +396 -0
  78. package/lib/mcp/protocol.d.ts +46 -7
  79. package/lib/mcp/protocol.d.ts.map +1 -1
  80. package/lib/mcp/protocol.js +63 -16
  81. package/lib/mcp/rate-limit.d.ts +68 -0
  82. package/lib/mcp/rate-limit.d.ts.map +1 -0
  83. package/lib/mcp/rate-limit.js +114 -0
  84. package/lib/mcp/sdk-v2.d.ts +17 -0
  85. package/lib/mcp/sdk-v2.d.ts.map +1 -0
  86. package/lib/mcp/sdk-v2.js +181 -0
  87. package/lib/mcp/server.d.ts +11 -1
  88. package/lib/mcp/server.d.ts.map +1 -1
  89. package/lib/mcp/server.js +80 -13
  90. package/lib/mcp/stdio.d.ts.map +1 -1
  91. package/lib/mcp/stdio.js +9 -1
  92. package/lib/mcp/subscriptions.d.ts +43 -1
  93. package/lib/mcp/subscriptions.d.ts.map +1 -1
  94. package/lib/mcp/subscriptions.js +90 -9
  95. package/lib/model-qualification.d.ts +192 -0
  96. package/lib/model-qualification.d.ts.map +1 -0
  97. package/lib/model-qualification.js +178 -0
  98. package/lib/planning.d.ts +246 -0
  99. package/lib/planning.d.ts.map +1 -0
  100. package/lib/planning.js +457 -0
  101. package/lib/prepared-assets.d.ts +178 -0
  102. package/lib/prepared-assets.d.ts.map +1 -0
  103. package/lib/prepared-assets.js +286 -0
  104. package/lib/provider-bridge.d.ts +37 -0
  105. package/lib/provider-bridge.d.ts.map +1 -1
  106. package/lib/provider-bridge.js +189 -12
  107. package/lib/ptc-authority.d.ts +140 -0
  108. package/lib/ptc-authority.d.ts.map +1 -0
  109. package/lib/ptc-authority.js +216 -0
  110. package/lib/ptc-runtime.d.ts +156 -0
  111. package/lib/ptc-runtime.d.ts.map +1 -0
  112. package/lib/ptc-runtime.js +191 -0
  113. package/lib/publication.d.ts +2 -1
  114. package/lib/publication.d.ts.map +1 -1
  115. package/lib/publication.js +13 -5
  116. package/lib/receipt.d.ts.map +1 -1
  117. package/lib/receipt.js +8 -0
  118. package/lib/title-proposal.d.ts +194 -0
  119. package/lib/title-proposal.d.ts.map +1 -0
  120. package/lib/title-proposal.js +244 -0
  121. package/lib/tool-mode-run.d.ts +235 -0
  122. package/lib/tool-mode-run.d.ts.map +1 -0
  123. package/lib/tool-mode-run.js +283 -0
  124. package/lib/types.d.ts +3 -1
  125. package/lib/types.d.ts.map +1 -1
  126. package/lib/update-surface.d.ts +79 -0
  127. package/lib/update-surface.d.ts.map +1 -0
  128. package/lib/update-surface.js +224 -0
  129. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts +38 -0
  130. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.d.ts.map +1 -0
  131. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/standard.js +445 -0
  132. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts +14 -0
  133. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.d.ts.map +1 -0
  134. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-embed.js +63 -0
  135. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts +14 -0
  136. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.d.ts.map +1 -0
  137. package/node_modules/@try-works/tool-mode-contracts/lib/contracts/text-rerank.js +76 -0
  138. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.d.ts.map +1 -1
  139. package/node_modules/@try-works/tool-mode-contracts/lib/dsh.js +69 -55
  140. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts +4 -1
  141. package/node_modules/@try-works/tool-mode-contracts/lib/index.d.ts.map +1 -1
  142. package/node_modules/@try-works/tool-mode-contracts/lib/index.js +26 -2
  143. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts +28 -2
  144. package/node_modules/@try-works/tool-mode-contracts/lib/registry.d.ts.map +1 -1
  145. package/node_modules/@try-works/tool-mode-contracts/lib/registry.js +93 -10
  146. package/node_modules/@try-works/tool-mode-contracts/package.json +0 -1
  147. package/node_modules/@try-works/tool-mode-extension-sdk/bin/dsh-tool-mode.mjs +20 -0
  148. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts +80 -0
  149. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.d.ts.map +1 -0
  150. package/node_modules/@try-works/tool-mode-extension-sdk/lib/cli.js +533 -0
  151. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts +83 -0
  152. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.d.ts.map +1 -0
  153. package/node_modules/@try-works/tool-mode-extension-sdk/lib/declarative-recipes.js +125 -0
  154. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts +70 -0
  155. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.d.ts.map +1 -0
  156. package/node_modules/@try-works/tool-mode-extension-sdk/lib/discovery.js +201 -0
  157. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts +57 -0
  158. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.d.ts.map +1 -0
  159. package/node_modules/@try-works/tool-mode-extension-sdk/lib/errors.js +83 -0
  160. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts +31 -0
  161. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.d.ts.map +1 -0
  162. package/node_modules/@try-works/tool-mode-extension-sdk/lib/index.js +31 -0
  163. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts +86 -0
  164. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.d.ts.map +1 -0
  165. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/archive.js +185 -0
  166. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts +126 -0
  167. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.d.ts.map +1 -0
  168. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/dependencies.js +297 -0
  169. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts +216 -0
  170. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.d.ts.map +1 -0
  171. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/lifecycle.js +800 -0
  172. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts +210 -0
  173. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.d.ts.map +1 -0
  174. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/migration.js +368 -0
  175. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts +63 -0
  176. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.d.ts.map +1 -0
  177. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/runtime-link.js +149 -0
  178. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts +35 -0
  179. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.d.ts.map +1 -0
  180. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/source-directory.js +179 -0
  181. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts +179 -0
  182. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.d.ts.map +1 -0
  183. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/staged.js +235 -0
  184. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts +367 -0
  185. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.d.ts.map +1 -0
  186. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/store.js +807 -0
  187. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts +185 -0
  188. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.d.ts.map +1 -0
  189. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/update-flow.js +504 -0
  190. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts +17 -0
  191. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.d.ts.map +1 -0
  192. package/node_modules/@try-works/tool-mode-extension-sdk/lib/install/zip-source.js +80 -0
  193. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts +52 -0
  194. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.d.ts.map +1 -0
  195. package/node_modules/@try-works/tool-mode-extension-sdk/lib/load.js +102 -0
  196. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts +171 -0
  197. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.d.ts.map +1 -0
  198. package/node_modules/@try-works/tool-mode-extension-sdk/lib/manifest.js +271 -0
  199. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts +242 -0
  200. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.d.ts.map +1 -0
  201. package/node_modules/@try-works/tool-mode-extension-sdk/lib/runtime.js +58 -0
  202. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts +118 -0
  203. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.d.ts.map +1 -0
  204. package/node_modules/@try-works/tool-mode-extension-sdk/lib/state.js +113 -0
  205. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts +2 -0
  206. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.d.ts.map +1 -0
  207. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker/worker-child.js +351 -0
  208. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts +150 -0
  209. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.d.ts.map +1 -0
  210. package/node_modules/@try-works/tool-mode-extension-sdk/lib/worker.js +670 -0
  211. package/node_modules/@try-works/tool-mode-extension-sdk/package.json +53 -0
  212. package/node_modules/@try-works/tool-mode-extension-sdk/schema/extension-manifest-1.1.0.schema.json +253 -0
  213. package/node_modules/@try-works/tool-mode-recipes/bin/tool-mode-recipe.mjs +15 -0
  214. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts +427 -0
  215. package/node_modules/@try-works/tool-mode-recipes/lib/broker.d.ts.map +1 -0
  216. package/node_modules/@try-works/tool-mode-recipes/lib/broker.js +592 -0
  217. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts +60 -0
  218. package/node_modules/@try-works/tool-mode-recipes/lib/cli.d.ts.map +1 -0
  219. package/node_modules/@try-works/tool-mode-recipes/lib/cli.js +936 -0
  220. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts +237 -0
  221. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.d.ts.map +1 -0
  222. package/node_modules/@try-works/tool-mode-recipes/lib/dsh-adapter.js +200 -0
  223. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts +85 -0
  224. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.d.ts.map +1 -0
  225. package/node_modules/@try-works/tool-mode-recipes/lib/fixture-provider.js +176 -0
  226. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts +105 -0
  227. package/node_modules/@try-works/tool-mode-recipes/lib/images.d.ts.map +1 -0
  228. package/node_modules/@try-works/tool-mode-recipes/lib/images.js +129 -0
  229. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts +25 -0
  230. package/node_modules/@try-works/tool-mode-recipes/lib/index.d.ts.map +1 -0
  231. package/node_modules/@try-works/tool-mode-recipes/lib/index.js +25 -0
  232. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts +325 -0
  233. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.d.ts.map +1 -0
  234. package/node_modules/@try-works/tool-mode-recipes/lib/recipe-format.js +1310 -0
  235. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts +51 -0
  236. package/node_modules/@try-works/tool-mode-recipes/lib/templates.d.ts.map +1 -0
  237. package/node_modules/@try-works/tool-mode-recipes/lib/templates.js +310 -0
  238. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts +227 -0
  239. package/node_modules/@try-works/tool-mode-recipes/lib/titles.d.ts.map +1 -0
  240. package/node_modules/@try-works/tool-mode-recipes/lib/titles.js +407 -0
  241. package/node_modules/@try-works/tool-mode-recipes/package.json +56 -0
  242. package/node_modules/@try-works/tool-mode-recipes/recipes/describe-image.json +38 -0
  243. package/node_modules/@try-works/tool-mode-recipes/recipes/text-title.json +45 -0
  244. package/node_modules/@try-works/tool-mode-recipes/schema/harness-model-recipe.schema.json +273 -0
  245. package/package.json +43 -15
  246. package/remote/spec.mjs +439 -0
  247. package/remote/typert.host.mjs +14 -0
  248. package/remote/typert.remote-client.mjs +16 -0
  249. package/lib/adapters/tongue.d.ts +0 -31
  250. package/lib/adapters/tongue.d.ts.map +0 -1
  251. package/lib/adapters/tongue.js +0 -93
  252. package/lib/adapters/voz.d.ts +0 -28
  253. package/lib/adapters/voz.d.ts.map +0 -1
  254. package/lib/adapters/voz.js +0 -102
  255. /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.d.ts +0 -0
  256. /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.d.ts.map +0 -0
  257. /package/{lib → node_modules/@try-works/tool-mode-extension-sdk/lib}/licensing.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../src/load.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,cAAc,CAAA;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAExD,gEAAgE;AAChE,eAAO,MAAM,eAAe,gBAAgB,CAAA;AAE5C;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,kBAAkB,GAAG,MAAM,CAU3E;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAuCzF;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,mBAAmB,EAC9B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,mBAAmB,CAAC,CA+B9B"}
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Loading an extension through its public entry (EXT-17, EXT-19).
3
+ *
4
+ * The host reaches an extension ONLY through `./tool-mode` and the interfaces in
5
+ * `runtime.ts`. It never imports a file inside the package, never reaches into an
6
+ * adapter registry the host owns, and never special-cases a model name. That is
7
+ * what makes BASE-09's "no private built-in adapter path" true rather than
8
+ * aspirational: a first-party package and a third-party package are loaded by the
9
+ * same function, so there is no second route that only first-party code can take.
10
+ *
11
+ * Loading is split from activation deliberately. `loadExtensionModule` validates
12
+ * the SHAPE of the export; `activateExtension` calls `create()`. EXT-19 requires
13
+ * `create()` to be lightweight, and keeping the two calls separate is what lets a
14
+ * host reject a malformed package without ever running its code.
15
+ *
16
+ * @module @try-works/tool-mode-extension-sdk/load
17
+ */
18
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
19
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
20
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
21
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
22
+ });
23
+ }
24
+ return path;
25
+ };
26
+ import { pathToFileURL } from 'node:url';
27
+ import { ManagementError } from "./errors.js";
28
+ import { EXTENSION_API_VERSION, } from "./runtime.js";
29
+ /** The public entry subpath every module extension declares. */
30
+ export const EXTENSION_ENTRY = './tool-mode';
31
+ /**
32
+ * Resolve the absolute path of an installed extension's public entry.
33
+ *
34
+ * The path comes from the package's own `exports` map rather than from a
35
+ * convention, so the host reads the same declaration a Node resolver would and a
36
+ * package that points its entry elsewhere keeps working.
37
+ * @param discovery - the package discovery result.
38
+ * @returns the absolute entry path.
39
+ * @throws ManagementError when the package declares no importable `./tool-mode` entry.
40
+ */
41
+ export function resolveExtensionEntry(discovery) {
42
+ if (discovery.entryPath === undefined) {
43
+ throw new ManagementError('INVALID_EXTENSION', 'activate', `the package declares no importable ${EXTENSION_ENTRY} export, so it has no module entry`, `Declare "${EXTENSION_ENTRY}": "./<file>.js" in package.json exports; the host does not guess entry points.`);
44
+ }
45
+ return discovery.entryPath;
46
+ }
47
+ /**
48
+ * Import an extension's public entry and validate its shape.
49
+ *
50
+ * Importing runs the package's module top level, which is why EXT-19 constrains it
51
+ * to be lightweight, and why the shape is checked BEFORE `create()` is called.
52
+ * @param entryPath - absolute path of the module to import.
53
+ * @returns the validated extension.
54
+ * @throws ManagementError when the import fails or the export is malformed.
55
+ */
56
+ export async function loadExtensionModule(entryPath) {
57
+ let module;
58
+ try {
59
+ module = await import(__rewriteRelativeImportExtension(pathToFileURL(entryPath).href));
60
+ }
61
+ catch (error) {
62
+ throw new ManagementError('INVALID_EXTENSION', 'activate', `the extension entry could not be imported: ${error instanceof Error ? error.message : String(error)}`, 'Confirm the entry is a valid ES module and that its dependencies are installed.');
63
+ }
64
+ const candidate = (module.default ?? module.extension);
65
+ if (candidate === undefined || typeof candidate !== 'object') {
66
+ throw new ManagementError('INVALID_EXTENSION', 'activate', 'the extension entry default-exports nothing usable', `Default-export an object with apiVersion ${EXTENSION_API_VERSION} and create(context).`);
67
+ }
68
+ if (candidate.apiVersion !== EXTENSION_API_VERSION) {
69
+ throw new ManagementError('INCOMPATIBLE_PROTOCOL', 'activate', `the extension declares apiVersion ${String(candidate.apiVersion)}, but this host implements ${EXTENSION_API_VERSION}`, 'Install a build of the extension for this API major, or upgrade the host.');
70
+ }
71
+ if (typeof candidate.create !== 'function') {
72
+ throw new ManagementError('INVALID_EXTENSION', 'activate', 'the extension entry default-exports no create(context) function', 'Implement create() on the default export.');
73
+ }
74
+ return candidate;
75
+ }
76
+ /**
77
+ * Activate a loaded extension.
78
+ *
79
+ * @param extension - the validated extension.
80
+ * @param context - the host-issued context.
81
+ * @returns the activated instance.
82
+ * @throws ManagementError when `create()` fails or returns no usable instance.
83
+ */
84
+ export async function activateExtension(extension, context) {
85
+ let instance;
86
+ try {
87
+ instance = await extension.create(context);
88
+ }
89
+ catch (error) {
90
+ throw new ManagementError('EXTENSION_FAULT', 'activate', `the extension failed to activate: ${error instanceof Error ? error.message : String(error)}`, 'Check the extension diagnostics; the package was not published.');
91
+ }
92
+ if (instance === null || typeof instance !== 'object' || typeof instance.createProvider !== 'function') {
93
+ throw new ManagementError('INVALID_EXTENSION', 'activate', 'the extension returned no createProvider(modelId, configuration)', 'Return an instance implementing the ExtensionInstanceV1 contract.');
94
+ }
95
+ if (typeof instance.dispose !== 'function') {
96
+ // A missing dispose is worse than a missing feature: the host would have no
97
+ // way to release the instance, so deactivation could never fully stop.
98
+ throw new ManagementError('INVALID_EXTENSION', 'activate', 'the extension instance implements no dispose(reason)', 'Implement dispose() so the host can release the instance on deactivation.');
99
+ }
100
+ return instance;
101
+ }
102
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Manifest validation and normalization (EXT-14, EXT-16).
3
+ *
4
+ * Validation runs on data read from a package before any of its code is imported,
5
+ * so a malformed or hostile manifest is rejected without executing anything.
6
+ *
7
+ * The checks below are the ones a JSON Schema cannot express: uniqueness of local
8
+ * IDs, agreement between the manifest and the package, referenced files that
9
+ * actually exist, and compatibility. EXT-14 is explicit that "unknown required
10
+ * features or incompatible protocol majors block activation", so an unrecognised
11
+ * feature is an error rather than a warning.
12
+ *
13
+ * @module @try-works/tool-mode-extension-sdk/manifest
14
+ */
15
+ /** The TMX protocol version this SDK implements. */
16
+ export declare const TMX_PROTOCOL_VERSION = "1.1.0";
17
+ /** The module runtime API major this SDK implements (EXT-16). */
18
+ export declare const RUNTIME_API_MAJOR = 1;
19
+ /** Features this SDK host knows how to provide (EXT-14). */
20
+ export declare const KNOWN_FEATURES: readonly string[];
21
+ /** Largest manifest accepted, in bytes. Bounded so a huge file cannot be parsed. */
22
+ export declare const MAX_MANIFEST_BYTES: number;
23
+ /** A validated manifest, normalized to the current protocol minor (EXT-16). */
24
+ export interface ExtensionManifest {
25
+ readonly protocolVersion: string;
26
+ readonly id: string;
27
+ readonly version: string;
28
+ readonly displayName: string;
29
+ readonly description: string;
30
+ readonly license?: string;
31
+ readonly activation: {
32
+ readonly policy: 'operator' | 'bundled-default';
33
+ readonly deactivatable: boolean;
34
+ };
35
+ readonly runtimeApi: number;
36
+ readonly compatibility: {
37
+ readonly hostApi: string;
38
+ readonly requiredFeatures: readonly string[];
39
+ };
40
+ readonly execution: {
41
+ readonly kind: 'module' | 'declarative';
42
+ readonly entry?: string;
43
+ readonly isolation?: 'managed-process' | 'host-inline';
44
+ };
45
+ readonly configurationSchema?: string;
46
+ /**
47
+ * Per-layer licences (LIC-01).
48
+ *
49
+ * Absent means UNDECLARED, which the resolution reports as a gap for every layer
50
+ * rather than treating silence as permission.
51
+ */
52
+ readonly licenses?: readonly ManifestLicense[];
53
+ /** Declared network behaviour (LIC-04). */
54
+ readonly network?: ManifestNetwork;
55
+ readonly permissions: {
56
+ readonly networkOrigins: readonly string[];
57
+ readonly inputFiles: boolean;
58
+ readonly storage: 'none' | 'extension-private';
59
+ readonly secrets: readonly string[];
60
+ readonly nativeCode: boolean;
61
+ };
62
+ readonly models: readonly ManifestModel[];
63
+ readonly tools: readonly ManifestTool[];
64
+ readonly implementations: readonly ManifestImplementation[];
65
+ readonly skills: readonly ManifestSkill[];
66
+ /** True when a 1.0 manifest was normalized to module execution (EXT-16). */
67
+ readonly normalizedFrom?: string;
68
+ }
69
+ /** One layer's licence, as the manifest declares it (LIC-01). */
70
+ export interface ManifestLicense {
71
+ readonly layer: 'code' | 'engine' | 'weights' | 'conversion-artifacts' | 'sdk';
72
+ readonly name: string;
73
+ readonly url: string;
74
+ readonly openSource: boolean;
75
+ readonly redistribution: 'permitted' | 'not-permitted' | 'unclear';
76
+ readonly attributionRequired: boolean;
77
+ readonly attributionText?: string;
78
+ readonly obligations?: readonly string[];
79
+ }
80
+ /** Declared network behaviour (LIC-04). */
81
+ export interface ManifestNetwork {
82
+ readonly requiredTelemetry: boolean;
83
+ readonly otherNetworkUse: boolean;
84
+ readonly telemetryContent?: readonly string[];
85
+ }
86
+ /** A declared model and its asset set. */
87
+ export interface ManifestModel {
88
+ readonly id: string;
89
+ readonly assetSet: string;
90
+ readonly assetLock: string;
91
+ readonly platforms: readonly {
92
+ readonly os: string;
93
+ readonly arch: string;
94
+ readonly accelerator?: string;
95
+ }[];
96
+ }
97
+ /** A declared tool contribution. */
98
+ export interface ManifestTool {
99
+ readonly id: string;
100
+ readonly name: string;
101
+ readonly contractId: string;
102
+ readonly contractVersion: string;
103
+ readonly description: string;
104
+ readonly inputSchema: string;
105
+ readonly outputSchema: string;
106
+ }
107
+ /** A declared implementation binding. */
108
+ export interface ManifestImplementation {
109
+ readonly id: string;
110
+ /**
111
+ * `"harness-model"` marks the spec §19.3 recipe binding; absent means the
112
+ * module form. The SDK validates the SHAPE; whether the host supports the
113
+ * binding is negotiated through the declared required features (EXT-14).
114
+ */
115
+ readonly kind?: 'harness-model';
116
+ readonly contractId: string;
117
+ readonly contractVersion: string;
118
+ readonly modelId?: string;
119
+ readonly recipeVersion: string;
120
+ /** The package-relative recipe file of a harness-model binding (RCP-01). */
121
+ readonly recipe?: string;
122
+ }
123
+ /** A declared skill contribution. */
124
+ export interface ManifestSkill {
125
+ readonly id: string;
126
+ readonly name: string;
127
+ readonly description: string;
128
+ readonly path: string;
129
+ readonly requiresTools?: readonly string[];
130
+ }
131
+ /**
132
+ * Validate a raw manifest.
133
+ *
134
+ * Beyond the schema, this enforces the cross-field rules EXT-14 names:
135
+ * unique local IDs, exact agreement with the package, referenced files that
136
+ * exist, and a compatibility range this host satisfies.
137
+ * @param raw - the decoded manifest.
138
+ * @param options - package identity and the directory referenced files resolve against.
139
+ * @returns the validated manifest.
140
+ * @throws ManagementError with `INVALID_EXTENSION` or `INCOMPATIBLE_PROTOCOL`.
141
+ */
142
+ export declare function validateManifest(raw: unknown, options: {
143
+ /** The package's own `name`, which the manifest id must equal exactly. */
144
+ readonly packageName: string;
145
+ /** The package's own `version`, which the manifest version must equal exactly. */
146
+ readonly packageVersion: string;
147
+ /** Directory referenced files resolve against; omit to skip the existence check. */
148
+ readonly packageDir?: string;
149
+ }): ExtensionManifest;
150
+ /**
151
+ * The qualification-record fields a lock may declare (MODEL-05).
152
+ *
153
+ * Mirrored, not imported, from the host's `model-qualification` module, for the
154
+ * same reason the embedding extension mirrors its dimension constants: the SDK
155
+ * must stay buildable without the host (EXT-02), and a second definition that
156
+ * drifts is caught by the discovery test asserting the field set.
157
+ */
158
+ export declare const QUALIFICATION_FIELDS: readonly string[];
159
+ /** Largest lock file accepted, in bytes. Bounded so a huge file cannot be parsed. */
160
+ export declare const MAX_LOCK_BYTES: number;
161
+ /**
162
+ * Validate the qualification records the manifest's asset locks declare.
163
+ *
164
+ * The assetLock path was ALREADY escape-checked and existence-checked by
165
+ * `assertReferencedFilesExist` before this runs (discovery calls that first),
166
+ * so the join here reuses a validated relative path rather than a raw one.
167
+ * @param manifest - the validated manifest.
168
+ * @param packageDir - the package directory.
169
+ */
170
+ export declare function validateLockQualifications(manifest: ExtensionManifest, packageDir: string): void;
171
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAOH,oDAAoD;AACpD,eAAO,MAAM,oBAAoB,UAAU,CAAA;AAE3C,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAElC,4DAA4D;AAC5D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAO3C,CAAA;AAED,oFAAoF;AACpF,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAE5C,+EAA+E;AAC/E,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,eAAe,EAAE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AUG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;IACP,0EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,kFAAkF;IAClF,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,oFAAoF;IACpF,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,GACA,iBAAiB,CAkFnB;AAqED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,SAAS,MAAM,EAGjD,CAAA;AAED,qFAAqF;AACrF,eAAO,MAAM,cAAc,QAAc,CAAA;AAyEzC;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAKhG"}
@@ -0,0 +1,271 @@
1
+ /**
2
+ * Manifest validation and normalization (EXT-14, EXT-16).
3
+ *
4
+ * Validation runs on data read from a package before any of its code is imported,
5
+ * so a malformed or hostile manifest is rejected without executing anything.
6
+ *
7
+ * The checks below are the ones a JSON Schema cannot express: uniqueness of local
8
+ * IDs, agreement between the manifest and the package, referenced files that
9
+ * actually exist, and compatibility. EXT-14 is explicit that "unknown required
10
+ * features or incompatible protocol majors block activation", so an unrecognised
11
+ * feature is an error rather than a warning.
12
+ *
13
+ * @module @try-works/tool-mode-extension-sdk/manifest
14
+ */
15
+ import { existsSync, readFileSync, statSync } from 'node:fs';
16
+ import { isAbsolute, join, normalize, resolve, sep } from 'node:path';
17
+ import { Ajv2020 } from 'ajv/dist/2020.js';
18
+ import { ManagementError } from "./errors.js";
19
+ /** The TMX protocol version this SDK implements. */
20
+ export const TMX_PROTOCOL_VERSION = '1.1.0';
21
+ /** The module runtime API major this SDK implements (EXT-16). */
22
+ export const RUNTIME_API_MAJOR = 1;
23
+ /** Features this SDK host knows how to provide (EXT-14). */
24
+ export const KNOWN_FEATURES = [
25
+ 'provider-worker-v1',
26
+ 'verified-assets-v1',
27
+ 'declarative-recipes-v1',
28
+ 'harness-executors-v1',
29
+ 'harness-model-recipes-v1',
30
+ 'typed-image-input-v1',
31
+ ];
32
+ /** Largest manifest accepted, in bytes. Bounded so a huge file cannot be parsed. */
33
+ export const MAX_MANIFEST_BYTES = 512 * 1024;
34
+ let cachedValidator;
35
+ /**
36
+ * Compile the shipped manifest schema.
37
+ *
38
+ * `strict: false` because the schema uses 2020-12 keywords Ajv's strict mode
39
+ * rejects when they are merely annotated, and `allErrors` so a rejection lists
40
+ * every problem rather than the first.
41
+ * @returns the compiled validator.
42
+ */
43
+ function manifestValidator() {
44
+ cachedValidator ??= (() => {
45
+ const schemaUrl = new URL('../schema/extension-manifest-1.1.0.schema.json', import.meta.url);
46
+ const schema = JSON.parse(readFileSync(schemaUrl, 'utf8'));
47
+ const ajv = new Ajv2020({ allErrors: true, strict: false });
48
+ return ajv.compile(schema);
49
+ })();
50
+ return cachedValidator;
51
+ }
52
+ /** Render Ajv errors as stable strings. */
53
+ function renderErrors(errors) {
54
+ const seen = new Set();
55
+ const out = [];
56
+ for (const error of errors ?? []) {
57
+ const path = error.instancePath === '' ? '(root)' : error.instancePath;
58
+ const line = `${path} ${error.message ?? 'is invalid'}`;
59
+ if (!seen.has(line)) {
60
+ seen.add(line);
61
+ out.push(line);
62
+ }
63
+ }
64
+ return out;
65
+ }
66
+ /**
67
+ * Normalize a raw manifest to the current protocol minor.
68
+ *
69
+ * A 1.0 manifest is lifted to module execution WITHOUT touching its installed
70
+ * bytes: EXT-16 requires the normalization to be a view, not an edit, because the
71
+ * recorded digest must keep describing what is on disk.
72
+ *
73
+ * The provenance of the lift is returned SEPARATELY rather than written into the
74
+ * object. The manifest schema is closed, and rightly so — an SDK-internal
75
+ * annotation is not an author-facing field, and adding it to the document to slip
76
+ * it past validation would be exactly the kind of silent widening the schema
77
+ * exists to prevent.
78
+ * @param raw - the decoded manifest.
79
+ * @returns the normalized value plus the protocol version it was lifted from.
80
+ */
81
+ function normalizeManifest(raw) {
82
+ const protocolVersion = String(raw.protocolVersion ?? '');
83
+ if (protocolVersion.startsWith('1.0.')) {
84
+ return {
85
+ value: { ...raw, execution: { kind: 'module', ...(raw.execution ?? {}) } },
86
+ normalizedFrom: protocolVersion,
87
+ };
88
+ }
89
+ return { value: raw };
90
+ }
91
+ /**
92
+ * Validate a raw manifest.
93
+ *
94
+ * Beyond the schema, this enforces the cross-field rules EXT-14 names:
95
+ * unique local IDs, exact agreement with the package, referenced files that
96
+ * exist, and a compatibility range this host satisfies.
97
+ * @param raw - the decoded manifest.
98
+ * @param options - package identity and the directory referenced files resolve against.
99
+ * @returns the validated manifest.
100
+ * @throws ManagementError with `INVALID_EXTENSION` or `INCOMPATIBLE_PROTOCOL`.
101
+ */
102
+ export function validateManifest(raw, options) {
103
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
104
+ throw new ManagementError('INVALID_EXTENSION', 'discover', 'the manifest is not a JSON object', 'Ship a manifest object; see the extension-manifest schema in the SDK.');
105
+ }
106
+ const normalized = normalizeManifest(raw);
107
+ const validate = manifestValidator();
108
+ if (!validate(normalized.value)) {
109
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the manifest does not satisfy the schema: ${renderErrors(validate.errors).join('; ')}`, 'Correct the reported fields and republish; the schema is shipped with the SDK.');
110
+ }
111
+ // The lift provenance is attached AFTER validation, so the closed schema never
112
+ // has to admit an SDK-internal field. The §19.3 declarative example elides
113
+ // `activation` and `runtimeApi`; the SDK defaults them at VALIDATION (the
114
+ // bytes stay untouched): operator activation + runtime API major 1.
115
+ const rawManifest = normalized.value;
116
+ const manifest = {
117
+ ...rawManifest,
118
+ ...normalized.normalizedFrom === undefined ? {} : { normalizedFrom: normalized.normalizedFrom },
119
+ ...rawManifest.activation === undefined
120
+ ? { activation: { policy: 'operator', deactivatable: true } }
121
+ : {},
122
+ ...rawManifest.runtimeApi === undefined ? { runtimeApi: 1 } : {},
123
+ };
124
+ if (manifest.id !== options.packageName) {
125
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the manifest id ${JSON.stringify(manifest.id)} must equal the package name ${JSON.stringify(options.packageName)} exactly`, 'Make the manifest id and package.json name identical, including scope.');
126
+ }
127
+ if (manifest.version !== options.packageVersion) {
128
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the manifest version ${JSON.stringify(manifest.version)} must equal the package version ${JSON.stringify(options.packageVersion)} exactly`, 'Make the manifest version and package.json version identical.');
129
+ }
130
+ // §19.5: a declarative package with an executable entry is REFUSED — the two
131
+ // execution modes are exclusive, and a declarative package claiming an entry
132
+ // would blur the "no executable code" boundary the recipe path exists for.
133
+ if (manifest.execution.kind === 'declarative' && manifest.execution.entry !== undefined) {
134
+ throw new ManagementError('INVALID_EXTENSION', 'discover', 'a declarative package declares an executable entry; declarative packages ship static recipe files and no executable module (§19.5)', 'Remove the execution.entry and any executable code, or publish the package as a module extension.');
135
+ }
136
+ const unknownFeatures = manifest.compatibility.requiredFeatures.filter(feature => !KNOWN_FEATURES.includes(feature));
137
+ if (unknownFeatures.length > 0) {
138
+ // EXT-14: an unknown REQUIRED feature blocks activation. Reporting it is more
139
+ // useful than silently proceeding without the capability the author asked for.
140
+ throw new ManagementError('INCOMPATIBLE_PROTOCOL', 'discover', `the host does not provide required feature(s): ${unknownFeatures.join(', ')}`, 'Upgrade the host, or drop the feature from compatibility.requiredFeatures if it is optional.');
141
+ }
142
+ assertUniqueIds(manifest);
143
+ if (options.packageDir !== undefined)
144
+ assertReferencedFilesExist(manifest, options.packageDir);
145
+ return manifest;
146
+ }
147
+ /** Reject duplicate local IDs, which would make a contribution ambiguous. */
148
+ function assertUniqueIds(manifest) {
149
+ for (const [label, ids] of [
150
+ ['models', manifest.models.map(model => model.id)],
151
+ ['tools', manifest.tools.map(tool => tool.id)],
152
+ ['implementations', manifest.implementations.map(implementation => implementation.id)],
153
+ ['skills', manifest.skills.map(skill => skill.id)],
154
+ ]) {
155
+ const duplicate = ids.find((id, index) => ids.indexOf(id) !== index);
156
+ if (duplicate !== undefined) {
157
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `duplicate ${label} id ${JSON.stringify(duplicate)}`, 'Give every contribution in the manifest a unique local id.');
158
+ }
159
+ }
160
+ // A tool NAME is caller-facing, so a duplicate there is a naming conflict rather
161
+ // than a manifest error (EXT-22).
162
+ const names = manifest.tools.map(tool => tool.name);
163
+ const duplicateName = names.find((name, index) => names.indexOf(name) !== index);
164
+ if (duplicateName !== undefined) {
165
+ throw new ManagementError('TOOL_NAME_CONFLICT', 'discover', `two tools declare the caller-facing name ${JSON.stringify(duplicateName)}`, 'Give each tool a distinct name, or declare the duplicate as an implementation of the existing contract.');
166
+ }
167
+ }
168
+ /** Reject a manifest referencing a file the package does not ship. */
169
+ function assertReferencedFilesExist(manifest, packageDir) {
170
+ const referenced = [
171
+ ...manifest.models.map(model => model.assetLock),
172
+ ...manifest.tools.flatMap(tool => [tool.inputSchema, tool.outputSchema]),
173
+ ...manifest.skills.map(skill => skill.path),
174
+ ...manifest.configurationSchema === undefined ? [] : [manifest.configurationSchema],
175
+ ...manifest.execution.entry === undefined ? [] : [manifest.execution.entry],
176
+ ...manifest.implementations.flatMap(implementation => implementation.recipe === undefined ? [] : [implementation.recipe]),
177
+ ];
178
+ for (const relative of referenced) {
179
+ // Schema files are offline package files; a remote $ref is never fetched and a
180
+ // path that escapes the package is refused before it can be read.
181
+ const absolute = resolve(packageDir, relative);
182
+ const root = resolve(packageDir);
183
+ if (!absolute.startsWith(root + sep) && absolute !== root) {
184
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the manifest references ${JSON.stringify(relative)}, which escapes the package directory`, 'Reference package-relative files only.');
185
+ }
186
+ const target = isAbsolute(relative) ? normalize(relative) : join(packageDir, relative);
187
+ if (!existsSync(target)) {
188
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the manifest references ${JSON.stringify(relative)}, which the package does not ship`, 'Include the referenced file in the published package, or correct the path.');
189
+ }
190
+ }
191
+ }
192
+ /**
193
+ * The qualification-record fields a lock may declare (MODEL-05).
194
+ *
195
+ * Mirrored, not imported, from the host's `model-qualification` module, for the
196
+ * same reason the embedding extension mirrors its dimension constants: the SDK
197
+ * must stay buildable without the host (EXT-02), and a second definition that
198
+ * drifts is caught by the discovery test asserting the field set.
199
+ */
200
+ export const QUALIFICATION_FIELDS = [
201
+ 'modelRevision', 'artifactSha', 'tokenizer', 'processor',
202
+ 'engineVersion', 'nodeAbi', 'architecture', 'executionProvider',
203
+ ];
204
+ /** Largest lock file accepted, in bytes. Bounded so a huge file cannot be parsed. */
205
+ export const MAX_LOCK_BYTES = 1024 * 1024;
206
+ /**
207
+ * Validate the qualification records an asset lock declares.
208
+ *
209
+ * A `qualification` object is not decoration: if it is present it must carry
210
+ * every field, each a non-blank string, or the package is refused at discovery —
211
+ * a record that can silently rot into a claim the artifacts no longer satisfy is
212
+ * worse than none (MODEL-05: a gap is not a qualification).
213
+ * @param lockPath - the lock file's absolute path.
214
+ * @param assetSet - the asset set whose record to check.
215
+ */
216
+ function assertQualificationRecord(lockPath, assetSet) {
217
+ // STAT FIRST, READ SECOND (review finding): a hostile package can ship a
218
+ // multi-GB lock, and buffering it before the cap check is the unbounded
219
+ // allocation discovery must never perform. The stat is free, so the cap is
220
+ // enforced on the byte count BEFORE any bytes are read.
221
+ let stat;
222
+ try {
223
+ stat = statSync(lockPath);
224
+ }
225
+ catch (error) {
226
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the asset lock cannot be read: ${error instanceof Error ? error.message : String(error)}`, 'Ship a valid JSON asset lock.');
227
+ }
228
+ if (stat.size > MAX_LOCK_BYTES) {
229
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the asset lock is ${stat.size} bytes, over the ${MAX_LOCK_BYTES} cap`, 'Keep the lock under the cap.');
230
+ }
231
+ let lock;
232
+ try {
233
+ lock = JSON.parse(readFileSync(lockPath, 'utf8'));
234
+ }
235
+ catch (error) {
236
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the asset lock cannot be read: ${error instanceof Error ? error.message : String(error)}`, 'Ship a valid JSON asset lock.');
237
+ }
238
+ const sets = lock?.assetSets;
239
+ if (typeof sets !== 'object' || sets === null)
240
+ return;
241
+ const set = sets[assetSet];
242
+ if (typeof set !== 'object' || set === null)
243
+ return;
244
+ const qualification = set.qualification;
245
+ if (qualification === undefined)
246
+ return;
247
+ if (typeof qualification !== 'object' || qualification === null || Array.isArray(qualification)) {
248
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the ${assetSet} qualification record is not an object`, 'Declare the record as an object with every MODEL-05 field, or remove it.');
249
+ }
250
+ const record = qualification;
251
+ const missing = QUALIFICATION_FIELDS.filter(field => typeof record[field] !== 'string' || record[field].length === 0);
252
+ if (missing.length > 0) {
253
+ throw new ManagementError('INVALID_EXTENSION', 'discover', `the ${assetSet} qualification record is missing or has blank: ${missing.join(', ')}`, 'Populate every MODEL-05 field with a non-blank string, or remove the record.');
254
+ }
255
+ }
256
+ /**
257
+ * Validate the qualification records the manifest's asset locks declare.
258
+ *
259
+ * The assetLock path was ALREADY escape-checked and existence-checked by
260
+ * `assertReferencedFilesExist` before this runs (discovery calls that first),
261
+ * so the join here reuses a validated relative path rather than a raw one.
262
+ * @param manifest - the validated manifest.
263
+ * @param packageDir - the package directory.
264
+ */
265
+ export function validateLockQualifications(manifest, packageDir) {
266
+ for (const model of manifest.models) {
267
+ const lockPath = join(packageDir, model.assetLock.replace(/^\.\//, ''));
268
+ assertQualificationRecord(lockPath, model.assetSet);
269
+ }
270
+ }
271
+ //# sourceMappingURL=manifest.js.map