@qvac/harness 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/CHANGELOG.md +689 -141
  2. package/README.md +29 -7
  3. package/dist/harness.bundle +71 -50
  4. package/dist-lib/index.d.ts +36 -39
  5. package/dist-lib/index.js +279 -114
  6. package/dist-lib/lib/audio-transcode-bare.d.ts +2 -2
  7. package/dist-lib/lib/audio-transcode-bare.js +28 -18
  8. package/dist-lib/lib/audio-transcode-node.d.ts +2 -2
  9. package/dist-lib/lib/capabilities/audio-resample.d.ts +7 -6
  10. package/dist-lib/lib/capabilities/audio-resample.js +30 -18
  11. package/dist-lib/lib/capabilities/completion.d.ts +20 -19
  12. package/dist-lib/lib/capabilities/completion.js +193 -132
  13. package/dist-lib/lib/capabilities/download.d.ts +6 -6
  14. package/dist-lib/lib/capabilities/download.js +15 -8
  15. package/dist-lib/lib/capabilities/embed.js +2 -1
  16. package/dist-lib/lib/capabilities/enhance.d.ts +6 -1
  17. package/dist-lib/lib/capabilities/enhance.js +7 -4
  18. package/dist-lib/lib/capabilities/invoke.js +7 -4
  19. package/dist-lib/lib/capabilities/kv-cache.js +2 -1
  20. package/dist-lib/lib/capabilities/preview-model-source.d.ts +9 -7
  21. package/dist-lib/lib/capabilities/preview-model-source.js +80 -28
  22. package/dist-lib/lib/capabilities/speech-text.js +5 -4
  23. package/dist-lib/lib/capabilities/tool-selection.js +10 -9
  24. package/dist-lib/lib/capabilities/tool-turns.js +30 -16
  25. package/dist-lib/lib/capabilities/usage-breakdown.js +2 -1
  26. package/dist-lib/lib/capabilities/voice.d.ts +5 -1
  27. package/dist-lib/lib/capabilities/voice.js +22 -12
  28. package/dist-lib/lib/connect.d.ts +11 -32
  29. package/dist-lib/lib/connect.js +152 -112
  30. package/dist-lib/lib/context-window.js +25 -21
  31. package/dist-lib/lib/contract-types.d.ts +22 -15
  32. package/dist-lib/lib/diagram-repair.d.ts +4 -4
  33. package/dist-lib/lib/diagram-repair.js +6 -3
  34. package/dist-lib/lib/docx/index.d.ts +3 -2
  35. package/dist-lib/lib/{error-fields.d.ts → guards.d.ts} +1 -0
  36. package/dist-lib/lib/{error-fields.js → guards.js} +3 -0
  37. package/dist-lib/lib/hardware/capability-probe.js +20 -10
  38. package/dist-lib/lib/hardware/gpu-classify.js +6 -3
  39. package/dist-lib/lib/hardware/gpu-probe-addon.js +8 -4
  40. package/dist-lib/lib/hardware/gpu-probe.js +4 -2
  41. package/dist-lib/lib/hardware/gpu-stats.native.cjs +8 -9
  42. package/dist-lib/lib/hardware/parsers.js +8 -4
  43. package/dist-lib/lib/helpers/buffer-burst.js +4 -2
  44. package/dist-lib/lib/helpers/control-tokens.js +4 -2
  45. package/dist-lib/lib/helpers/join-guard.d.ts +2 -2
  46. package/dist-lib/lib/helpers/join-guard.js +4 -2
  47. package/dist-lib/lib/helpers/load-stall.js +4 -2
  48. package/dist-lib/lib/helpers/markup-stream-filter.d.ts +2 -2
  49. package/dist-lib/lib/helpers/markup-stream-filter.js +6 -3
  50. package/dist-lib/lib/helpers/race-abort.js +2 -1
  51. package/dist-lib/lib/helpers/race-timeout.d.ts +5 -0
  52. package/dist-lib/lib/helpers/race-timeout.js +14 -0
  53. package/dist-lib/lib/helpers/run-outcome.d.ts +6 -8
  54. package/dist-lib/lib/helpers/run-outcome.js +36 -20
  55. package/dist-lib/lib/helpers/spawn-path.js +6 -3
  56. package/dist-lib/lib/helpers/text-coalescer.js +6 -3
  57. package/dist-lib/lib/helpers/thinking.js +38 -45
  58. package/dist-lib/lib/helpers/tool-call-markup.d.ts +9 -7
  59. package/dist-lib/lib/helpers/tool-call-markup.js +36 -20
  60. package/dist-lib/lib/helpers/tool-intent.d.ts +3 -2
  61. package/dist-lib/lib/helpers/tool-intent.js +4 -2
  62. package/dist-lib/lib/helpers/tool-label.js +18 -9
  63. package/dist-lib/lib/hooks/built-in/arg-repair.js +23 -13
  64. package/dist-lib/lib/hooks/built-in/egress.js +2 -1
  65. package/dist-lib/lib/hooks/built-in/skill-catalog.js +2 -1
  66. package/dist-lib/lib/hooks/pipeline.d.ts +5 -4
  67. package/dist-lib/lib/hooks/pipeline.js +6 -3
  68. package/dist-lib/lib/hooks/run.js +12 -8
  69. package/dist-lib/lib/model-download-progress.js +10 -8
  70. package/dist-lib/lib/models/context.d.ts +1 -1
  71. package/dist-lib/lib/models/context.js +5 -1
  72. package/dist-lib/lib/models/custom-model-cache.d.ts +10 -1
  73. package/dist-lib/lib/models/custom-model-cache.js +43 -15
  74. package/dist-lib/lib/models/gguf-header.d.ts +3 -2
  75. package/dist-lib/lib/models/gguf-header.js +44 -22
  76. package/dist-lib/lib/models/idle-unload.d.ts +14 -0
  77. package/dist-lib/lib/models/idle-unload.js +51 -0
  78. package/dist-lib/lib/models/kv-cache.d.ts +3 -2
  79. package/dist-lib/lib/models/kv-cache.js +4 -3
  80. package/dist-lib/lib/models/llm-presets.d.ts +2 -2
  81. package/dist-lib/lib/models/llm-presets.js +4 -2
  82. package/dist-lib/lib/models/model-catalog-constants.js +3 -2
  83. package/dist-lib/lib/models/model-catalog.d.ts +13 -20
  84. package/dist-lib/lib/models/model-catalog.js +59 -31
  85. package/dist-lib/lib/models/model-delete.js +18 -8
  86. package/dist-lib/lib/models/model-handle.js +2 -1
  87. package/dist-lib/lib/models/model-list.d.ts +8 -3
  88. package/dist-lib/lib/models/model-list.js +11 -6
  89. package/dist-lib/lib/models/model-pool.d.ts +44 -10
  90. package/dist-lib/lib/models/model-pool.js +47 -42
  91. package/dist-lib/lib/models/model-source.js +10 -5
  92. package/dist-lib/lib/models/music-catalog.d.ts +2 -2
  93. package/dist-lib/lib/models/nmt-catalog.d.ts +4 -3
  94. package/dist-lib/lib/models/nmt-catalog.js +10 -5
  95. package/dist-lib/lib/models/opencl-cache.d.ts +6 -1
  96. package/dist-lib/lib/models/opencl-cache.js +5 -3
  97. package/dist-lib/lib/models/sdk-faults.d.ts +11 -8
  98. package/dist-lib/lib/models/sdk-faults.js +9 -6
  99. package/dist-lib/lib/models/shards.d.ts +11 -0
  100. package/dist-lib/lib/models/shards.js +15 -0
  101. package/dist-lib/lib/models/tool-dialect.js +10 -5
  102. package/dist-lib/lib/no-redirect-fetch-bare.d.ts +3 -3
  103. package/dist-lib/lib/no-redirect-fetch-bare.js +1 -1
  104. package/dist-lib/lib/no-redirect-fetch-impl.js +6 -3
  105. package/dist-lib/lib/no-redirect-fetch-node.d.ts +1 -1
  106. package/dist-lib/lib/no-redirect-fetch-node.js +9 -9
  107. package/dist-lib/lib/office/index.d.ts +3 -2
  108. package/dist-lib/lib/office/python.d.ts +3 -2
  109. package/dist-lib/lib/office/python.js +2 -1
  110. package/dist-lib/lib/prompt.d.ts +5 -4
  111. package/dist-lib/lib/prompt.js +8 -4
  112. package/dist-lib/lib/queue.js +10 -5
  113. package/dist-lib/lib/resolution-detector.js +21 -11
  114. package/dist-lib/lib/rpc-session.js +2 -1
  115. package/dist-lib/lib/sdk-loader.js +2 -1
  116. package/dist-lib/lib/sdk-storage.js +4 -2
  117. package/dist-lib/lib/serve.js +110 -66
  118. package/dist-lib/lib/spawn.js +7 -4
  119. package/dist-lib/lib/tmp-path.d.ts +7 -6
  120. package/dist-lib/lib/tool-call-display.d.ts +2 -2
  121. package/dist-lib/lib/tools/create-documents.js +18 -10
  122. package/dist-lib/lib/tools/edit-documents.js +23 -13
  123. package/dist-lib/lib/tools/edit-image.d.ts +2 -2
  124. package/dist-lib/lib/tools/edit-image.js +60 -36
  125. package/dist-lib/lib/tools/exec/adapters/adapter.d.ts +10 -10
  126. package/dist-lib/lib/tools/exec/adapters/python/attachments.d.ts +17 -11
  127. package/dist-lib/lib/tools/exec/adapters/python/attachments.js +53 -40
  128. package/dist-lib/lib/tools/exec/adapters/python/create-effect.d.ts +2 -2
  129. package/dist-lib/lib/tools/exec/adapters/python/create-effect.js +60 -32
  130. package/dist-lib/lib/tools/exec/adapters/python/guarded-fetch.d.ts +33 -22
  131. package/dist-lib/lib/tools/exec/adapters/python/guarded-fetch.js +58 -29
  132. package/dist-lib/lib/tools/exec/adapters/python/interrupt-timer.d.ts +2 -2
  133. package/dist-lib/lib/tools/exec/adapters/python/loader.js +23 -12
  134. package/dist-lib/lib/tools/exec/adapters/python/memfs.d.ts +13 -11
  135. package/dist-lib/lib/tools/exec/adapters/python/memfs.js +10 -5
  136. package/dist-lib/lib/tools/exec/adapters/python/net-shim.js +3 -1
  137. package/dist-lib/lib/tools/exec/adapters/python/output-policy.d.ts +6 -4
  138. package/dist-lib/lib/tools/exec/adapters/python/output-policy.js +20 -10
  139. package/dist-lib/lib/tools/exec/adapters/python/pyodide.d.ts +2 -2
  140. package/dist-lib/lib/tools/exec/adapters/python/pyodide.js +14 -7
  141. package/dist-lib/lib/tools/exec/adapters/python/python-adapter.d.ts +41 -34
  142. package/dist-lib/lib/tools/exec/adapters/python/python-adapter.js +316 -166
  143. package/dist-lib/lib/tools/exec/adapters/python/run-session.d.ts +9 -8
  144. package/dist-lib/lib/tools/exec/adapters/python/run-session.js +56 -28
  145. package/dist-lib/lib/tools/exec/adapters/python/wheels.d.ts +8 -10
  146. package/dist-lib/lib/tools/exec/adapters/python/wheels.js +22 -11
  147. package/dist-lib/lib/tools/exec/adapters/python/worker/client.d.ts +3 -2
  148. package/dist-lib/lib/tools/exec/adapters/python/worker/client.js +41 -26
  149. package/dist-lib/lib/tools/exec/adapters/python/worker/entry.js +27 -18
  150. package/dist-lib/lib/tools/exec/adapters/python/worker/protocol.d.ts +2 -2
  151. package/dist-lib/lib/tools/exec/adapters/python/worker/protocol.js +14 -13
  152. package/dist-lib/lib/tools/exec/adapters/python/worker/spawn-node.d.ts +4 -4
  153. package/dist-lib/lib/tools/exec/adapters/python/worker/spawn-node.js +10 -5
  154. package/dist-lib/lib/tools/exec/adapters/shell/shell-adapter.d.ts +4 -4
  155. package/dist-lib/lib/tools/exec/adapters/shell/shell-adapter.js +2 -1
  156. package/dist-lib/lib/tools/exec/obsidian/cli-process.d.ts +6 -1
  157. package/dist-lib/lib/tools/exec/obsidian/cli-process.js +8 -5
  158. package/dist-lib/lib/tools/exec/obsidian/cli.d.ts +6 -6
  159. package/dist-lib/lib/tools/exec/obsidian/cli.js +4 -4
  160. package/dist-lib/lib/tools/exec/obsidian/command.d.ts +3 -2
  161. package/dist-lib/lib/tools/exec/obsidian/command.js +6 -3
  162. package/dist-lib/lib/tools/exec/obsidian/output.js +2 -1
  163. package/dist-lib/lib/tools/exec/obsidian/route.d.ts +4 -6
  164. package/dist-lib/lib/tools/exec/obsidian/route.js +17 -11
  165. package/dist-lib/lib/tools/exec/obsidian/safe-path.js +2 -1
  166. package/dist-lib/lib/tools/exec/obsidian/vault-create.js +15 -7
  167. package/dist-lib/lib/tools/exec/obsidian/vault-paths.d.ts +2 -2
  168. package/dist-lib/lib/tools/exec/obsidian/vault-paths.js +20 -10
  169. package/dist-lib/lib/tools/exec/obsidian/vault-read.js +20 -13
  170. package/dist-lib/lib/tools/exec/obsidian/vault-write.js +24 -12
  171. package/dist-lib/lib/tools/exec/runner.d.ts +14 -14
  172. package/dist-lib/lib/tools/exec/runner.js +5 -3
  173. package/dist-lib/lib/tools/exec/scope.js +52 -28
  174. package/dist-lib/lib/tools/exec/shell-argv.js +31 -18
  175. package/dist-lib/lib/tools/exec/shell-guidance.d.ts +6 -1
  176. package/dist-lib/lib/tools/exec/shell-guidance.js +35 -20
  177. package/dist-lib/lib/tools/exec/video-tools.js +2 -2
  178. package/dist-lib/lib/tools/exec.d.ts +6 -8
  179. package/dist-lib/lib/tools/exec.js +113 -54
  180. package/dist-lib/lib/tools/file-glob.d.ts +4 -5
  181. package/dist-lib/lib/tools/file-glob.js +16 -11
  182. package/dist-lib/lib/tools/fs/glob.js +13 -18
  183. package/dist-lib/lib/tools/fs/remote-protocol.d.ts +10 -10
  184. package/dist-lib/lib/tools/fs/remote.d.ts +3 -2
  185. package/dist-lib/lib/tools/fs/remote.js +13 -7
  186. package/dist-lib/lib/tools/fs/scope.d.ts +8 -3
  187. package/dist-lib/lib/tools/fs/scope.js +20 -12
  188. package/dist-lib/lib/tools/fs/walk.js +6 -3
  189. package/dist-lib/lib/tools/fs/write.d.ts +3 -2
  190. package/dist-lib/lib/tools/generate-image.d.ts +11 -9
  191. package/dist-lib/lib/tools/generate-image.js +73 -37
  192. package/dist-lib/lib/tools/generate-music.d.ts +22 -11
  193. package/dist-lib/lib/tools/generate-music.js +79 -48
  194. package/dist-lib/lib/tools/grep.js +66 -41
  195. package/dist-lib/lib/tools/http-request/encode-fields.js +18 -9
  196. package/dist-lib/lib/tools/http-request/{utils.js → request.js} +20 -11
  197. package/dist-lib/lib/tools/http-request/truncate-response.js +57 -46
  198. package/dist-lib/lib/tools/http-request.d.ts +1 -1
  199. package/dist-lib/lib/tools/http-request.js +33 -18
  200. package/dist-lib/lib/tools/mcp/protocol.d.ts +53 -0
  201. package/dist-lib/lib/tools/mcp/{utils.js → protocol.js} +45 -23
  202. package/dist-lib/lib/tools/mcp-call.d.ts +1 -1
  203. package/dist-lib/lib/tools/mcp-call.js +37 -16
  204. package/dist-lib/lib/tools/operations/builders.js +10 -6
  205. package/dist-lib/lib/tools/operations/compile.js +20 -10
  206. package/dist-lib/lib/tools/operations/decoders.js +12 -6
  207. package/dist-lib/lib/tools/operations/gmail-message.js +3 -2
  208. package/dist-lib/lib/tools/outbound-guard.d.ts +4 -3
  209. package/dist-lib/lib/tools/outbound-guard.js +14 -8
  210. package/dist-lib/lib/tools/private-ip.js +8 -7
  211. package/dist-lib/lib/tools/rag-search.js +14 -7
  212. package/dist-lib/lib/tools/read-files.js +23 -20
  213. package/dist-lib/lib/tools/skill.js +19 -10
  214. package/dist-lib/lib/tools/skills/auth-resolver.d.ts +11 -18
  215. package/dist-lib/lib/tools/skills/auth-resolver.js +30 -18
  216. package/dist-lib/lib/tools/skills/bin-check.d.ts +3 -2
  217. package/dist-lib/lib/tools/skills/bin-check.js +10 -3
  218. package/dist-lib/lib/tools/skills/bundled-dir.js +20 -10
  219. package/dist-lib/lib/tools/skills/bundled-hash.d.ts +3 -2
  220. package/dist-lib/lib/tools/skills/bundled-hash.js +6 -1
  221. package/dist-lib/lib/tools/skills/catalog.d.ts +3 -2
  222. package/dist-lib/lib/tools/skills/catalog.js +33 -28
  223. package/dist-lib/lib/tools/skills/cli-argv.d.ts +3 -2
  224. package/dist-lib/lib/tools/skills/cli-argv.js +55 -52
  225. package/dist-lib/lib/tools/skills/cli-schema-check.js +21 -10
  226. package/dist-lib/lib/tools/skills/cli-schema-load.js +28 -20
  227. package/dist-lib/lib/tools/skills/cli-schema-types.d.ts +6 -6
  228. package/dist-lib/lib/tools/skills/cli-schema.js +2 -1
  229. package/dist-lib/lib/tools/skills/credential-check.d.ts +6 -3
  230. package/dist-lib/lib/tools/skills/credential-check.js +24 -12
  231. package/dist-lib/lib/tools/skills/credential-grants.js +1 -6
  232. package/dist-lib/lib/tools/skills/credential-health.d.ts +5 -1
  233. package/dist-lib/lib/tools/skills/credential-health.js +5 -3
  234. package/dist-lib/lib/tools/skills/frontmatter-parser.js +10 -5
  235. package/dist-lib/lib/tools/skills/manifest-parse.js +84 -64
  236. package/dist-lib/lib/tools/skills/mention.js +7 -6
  237. package/dist-lib/lib/tools/skills/obsidian-readiness.d.ts +2 -2
  238. package/dist-lib/lib/tools/skills/obsidian-readiness.js +11 -3
  239. package/dist-lib/lib/tools/skills/overlay-crud.d.ts +6 -4
  240. package/dist-lib/lib/tools/skills/overlay-crud.js +12 -6
  241. package/dist-lib/lib/tools/skills/overlay-dir.js +4 -2
  242. package/dist-lib/lib/tools/skills/overlay-watch.d.ts +3 -2
  243. package/dist-lib/lib/tools/skills/overlay-watch.js +8 -4
  244. package/dist-lib/lib/tools/skills/setup-routes.js +1 -3
  245. package/dist-lib/lib/tools/skills/skill-settings.js +4 -1
  246. package/dist-lib/lib/tools/skills/skill-state.d.ts +6 -11
  247. package/dist-lib/lib/tools/skills/skill-state.js +48 -29
  248. package/dist-lib/lib/tools/skills/tool-grants.js +6 -3
  249. package/dist-lib/lib/tools/toolsets.js +2 -1
  250. package/dist-lib/lib/tools/translate.d.ts +4 -5
  251. package/dist-lib/lib/tools/translate.js +31 -14
  252. package/dist-lib/lib/tools/url-guard.js +2 -1
  253. package/dist-lib/lib/tools/weather-lookup/place.js +8 -4
  254. package/dist-lib/lib/tools/weather-lookup/report.d.ts +7 -1
  255. package/dist-lib/lib/tools/weather-lookup/report.js +46 -9
  256. package/dist-lib/lib/tools/weather-lookup.js +18 -12
  257. package/dist-lib/lib/tools/web-fetch.js +47 -24
  258. package/dist-lib/lib/tools/web-search.js +8 -3
  259. package/dist-lib/lib/validating-lookup.d.ts +4 -4
  260. package/dist-lib/lib/wav-encode.d.ts +1 -1
  261. package/dist-lib/lib/wav-encode.js +11 -10
  262. package/dist-lib/lib/web-fetch/embedded-state.js +24 -12
  263. package/dist-lib/lib/web-fetch/extract.js +4 -2
  264. package/dist-lib/lib/web-fetch/images.js +8 -4
  265. package/dist-lib/lib/web-fetch/video.d.ts +2 -2
  266. package/dist-lib/lib/web-fetch/video.js +8 -4
  267. package/dist-lib/lib/web-search/engine-registry.d.ts +2 -2
  268. package/dist-lib/lib/web-search/engines/aol.js +1 -1
  269. package/dist-lib/lib/web-search/engines/bing.js +1 -1
  270. package/dist-lib/lib/web-search/engines/brave.js +4 -1
  271. package/dist-lib/lib/web-search/engines/duckduckgo.js +3 -2
  272. package/dist-lib/lib/web-search/engines/google.js +7 -3
  273. package/dist-lib/lib/web-search/engines/wikipedia.js +5 -4
  274. package/dist-lib/lib/web-search/engines/yahoo.js +1 -1
  275. package/dist-lib/lib/web-search/fetch-html.d.ts +5 -4
  276. package/dist-lib/lib/web-search/fetch-html.js +13 -7
  277. package/dist-lib/lib/web-search/orchestrator.d.ts +9 -5
  278. package/dist-lib/lib/web-search/orchestrator.js +3 -3
  279. package/dist-lib/lib/wire.d.ts +3 -2
  280. package/dist-lib/lib/wire.js +23 -15
  281. package/dist-lib/schema/baseline.js +10 -5
  282. package/dist-lib/schema/build.js +2 -1
  283. package/dist-lib/schema/harness.d.ts +15 -2
  284. package/dist-lib/schema/harness.js +14 -2
  285. package/dist-lib/schema/release-tags.d.ts +3 -2
  286. package/dist-lib/schema/release-tags.js +6 -3
  287. package/dist-lib/spec/bind.js +3 -0
  288. package/dist-lib/spec/calls.js +1 -0
  289. package/dist-lib/spec/hrpc/hrpc.json +13 -0
  290. package/dist-lib/spec/hrpc/index.js +15 -3
  291. package/dist-lib/spec/hrpc/messages.js +39 -8
  292. package/dist-lib/spec/hyperschema/index.js +39 -8
  293. package/dist-lib/spec/hyperschema/schema.json +30 -1
  294. package/dist-lib/spec/hyperschema/types.d.ts +9 -1
  295. package/package.json +13 -14
  296. package/worker/harness-sidecar.mjs +15 -22
  297. package/worker/stow-entry.mjs +7 -4
  298. package/dist-lib/lib/tools/mcp/utils.d.ts +0 -47
  299. /package/dist-lib/lib/tools/http-request/{utils.d.ts → request.d.ts} +0 -0
@@ -2,30 +2,25 @@ export function compileGlob(pattern) {
2
2
  let source = '';
3
3
  let i = 0;
4
4
  while (i < pattern.length) {
5
- const c = pattern[i];
6
- if (c === '*') {
7
- if (pattern[i + 1] === '*') {
8
- if (pattern[i + 2] === '/') {
9
- source += '(?:.*/)?';
10
- i += 3;
11
- }
12
- else {
13
- source += '.*';
14
- i += 2;
15
- }
16
- }
17
- else {
18
- source += '[^/]*';
19
- i += 1;
20
- }
5
+ const c = pattern.charAt(i);
6
+ if (c === '*' && pattern[i + 1] === '*' && pattern[i + 2] === '/') {
7
+ source += '(?:.*/)?';
8
+ i += 3;
9
+ }
10
+ else if (c === '*' && pattern[i + 1] === '*') {
11
+ source += '.*';
12
+ i += 2;
13
+ }
14
+ else if (c === '*') {
15
+ source += '[^/]*';
16
+ i += 1;
21
17
  }
22
18
  else if (c === '?') {
23
19
  source += '[^/]';
24
20
  i += 1;
25
21
  }
26
22
  else {
27
- const ch = c;
28
- source += /[.+^${}()|[\]\\]/.test(ch) ? `\\${ch}` : ch;
23
+ source += /[.+^${}()|[\]\\]/.test(c) ? `\\${c}` : c;
29
24
  i += 1;
30
25
  }
31
26
  }
@@ -1,34 +1,34 @@
1
1
  import type { DriveEntry } from './drive.ts';
2
- export type DriveEntryRequest = {
2
+ export interface DriveEntryRequest {
3
3
  op: 'entry';
4
4
  driveKey: string;
5
5
  key: string;
6
- };
7
- export type DriveGetRequest = {
6
+ }
7
+ export interface DriveGetRequest {
8
8
  op: 'get';
9
9
  driveKey: string;
10
10
  key: string;
11
- };
12
- export type DriveReadRequest = {
11
+ }
12
+ export interface DriveReadRequest {
13
13
  op: 'read';
14
14
  driveKey: string;
15
15
  key: string;
16
- };
17
- export type DriveListRequest = {
16
+ }
17
+ export interface DriveListRequest {
18
18
  op: 'list';
19
19
  driveKey: string;
20
20
  folder: string;
21
21
  skip: string[];
22
22
  limit: number;
23
23
  cursor: string | null;
24
- };
25
- export type DriveWriteRequest = {
24
+ }
25
+ export interface DriveWriteRequest {
26
26
  op: 'write';
27
27
  driveKey: string;
28
28
  key: string;
29
29
  path: string;
30
30
  executable?: boolean;
31
- };
31
+ }
32
32
  export type DriveRequest = DriveEntryRequest | DriveGetRequest | DriveReadRequest | DriveListRequest | DriveWriteRequest;
33
33
  export interface DriveResponse {
34
34
  error?: string;
@@ -12,6 +12,7 @@ export declare class DriveReadTruncatedError extends Error {
12
12
  constructor(key: string);
13
13
  }
14
14
  export declare function isDriveReadTruncated(err: unknown): err is DriveReadTruncatedError;
15
- export declare function createRemoteRoots(drives: readonly GrantedDrive[], driveOp: DriveOpFn, opts?: {
15
+ export interface RemoteRootsOptions {
16
16
  readonly timeoutMs?: number;
17
- }): HyperRoot[];
17
+ }
18
+ export declare function createRemoteRoots(drives: readonly GrantedDrive[], driveOp: DriveOpFn, opts?: RemoteRootsOptions): HyperRoot[];
@@ -29,8 +29,9 @@ function withTimeout(promise, ms, op) {
29
29
  }
30
30
  async function call(driveOp, request, timeoutMs) {
31
31
  const response = await withTimeout(driveOp(request), timeoutMs, request.op);
32
- if (response.error)
32
+ if (response.error) {
33
33
  throw new Error(response.error);
34
+ }
34
35
  return response;
35
36
  }
36
37
  async function readStaged(stagedPath) {
@@ -54,8 +55,9 @@ function remoteDrive(driveKey, driveOp, timeoutMs) {
54
55
  },
55
56
  async get(getKey) {
56
57
  const response = await call(driveOp, { op: 'get', driveKey, key: getKey }, timeoutMs);
57
- if (!response.path)
58
+ if (!response.path) {
58
59
  return null;
60
+ }
59
61
  return readStaged(response.path);
60
62
  },
61
63
  async *list(folder = '/', opts) {
@@ -64,25 +66,29 @@ function remoteDrive(driveKey, driveOp, timeoutMs) {
64
66
  while (true) {
65
67
  const response = await call(driveOp, { op: 'list', driveKey, folder, skip, limit: DRIVE_LIST_PAGE, cursor }, timeoutMs);
66
68
  const entries = response.entries ?? [];
67
- for (const entry of entries)
69
+ for (const entry of entries) {
68
70
  yield entry;
69
- if (!response.cursor || entries.length === 0)
71
+ }
72
+ if (!response.cursor || entries.length === 0) {
70
73
  return;
74
+ }
71
75
  cursor = response.cursor;
72
76
  }
73
77
  },
74
78
  async *createReadStream(readKey) {
75
79
  const response = await call(driveOp, { op: 'read', driveKey, key: readKey }, timeoutMs);
76
- if (!response.path)
80
+ if (!response.path) {
77
81
  return;
82
+ }
78
83
  try {
79
84
  yield* fs.createReadStream(response.path);
80
85
  }
81
86
  finally {
82
87
  await fs.promises.unlink(response.path).catch(noop);
83
88
  }
84
- if (response.truncated)
89
+ if (response.truncated) {
85
90
  throw new DriveReadTruncatedError(readKey);
91
+ }
86
92
  },
87
93
  createWriteStream(writeKey, writeOpts) {
88
94
  const stagedPath = stagedWritePath();
@@ -108,7 +114,7 @@ function remoteDrive(driveKey, driveOp, timeoutMs) {
108
114
  driveKey,
109
115
  key: writeKey,
110
116
  path: stagedPath,
111
- ...(writeOpts?.executable ? { executable: true } : {})
117
+ executable: writeOpts?.executable || undefined
112
118
  }, timeoutMs).then(() => cb(null), (err) => {
113
119
  fs.promises.unlink(stagedPath).catch(noop);
114
120
  cb(err);
@@ -19,6 +19,9 @@ export interface FsToolOptions {
19
19
  readonly deniedRoots?: readonly string[];
20
20
  }
21
21
  export declare const NO_DIRS_GRANTED = "no directories are granted";
22
+ export interface FsToolError {
23
+ error: string;
24
+ }
22
25
  export declare const NO_STORAGE_ROOT = "cannot fence the app storage root: the SDK home is unknown";
23
26
  export declare function deniedRootsFor(sdkHome: string | undefined): readonly string[];
24
27
  export declare const PROTECTED_PATH_ERROR = "path is inside a protected app directory";
@@ -32,6 +35,8 @@ export interface ResolvedKey {
32
35
  key: string;
33
36
  exists: boolean;
34
37
  }
35
- export declare function resolveKey(p: string, roots: readonly DriveRoot[], realpath: Realpath, deny?: readonly string[]): Promise<ResolvedKey | {
36
- error: string;
37
- }>;
38
+ export interface ResolveKeyOptions {
39
+ readonly realpath: Realpath;
40
+ readonly deny?: readonly string[];
41
+ }
42
+ export declare function resolveKey(p: string, roots: readonly DriveRoot[], { realpath, deny }: ResolveKeyOptions): Promise<ResolvedKey | FsToolError>;
@@ -33,13 +33,13 @@ export async function canonicalDenyRoots(deniedRoots, realpath) {
33
33
  }));
34
34
  }
35
35
  export function isDeniedPath(hostPath, canonicalDenyRoots) {
36
- return canonicalDenyRoots.some((root) => contained(hostPath, root, true));
36
+ return canonicalDenyRoots.some((root) => contained(hostPath, root, { ignoreCase: true }));
37
37
  }
38
38
  const FOLD_CASE = process.platform === 'darwin' || process.platform === 'win32';
39
39
  function within(candidate, root) {
40
- return contained(candidate, root, FOLD_CASE);
40
+ return contained(candidate, root, { ignoreCase: FOLD_CASE });
41
41
  }
42
- function contained(candidate, root, ignoreCase) {
42
+ function contained(candidate, root, { ignoreCase }) {
43
43
  const a = ignoreCase ? candidate.toLowerCase() : candidate;
44
44
  const b = ignoreCase ? root.toLowerCase() : root;
45
45
  return a === b || a.startsWith(b + path.sep);
@@ -66,17 +66,20 @@ export function normalizeDriveKey(prefix, input) {
66
66
  return null;
67
67
  if (WINDOWS_DRIVE_LETTER.test(input))
68
68
  return null;
69
- if (CONTROL_OR_NUL.test(input))
69
+ if (CONTROL_OR_NUL.test(input)) {
70
70
  return null;
71
- if (input.includes('://'))
71
+ }
72
+ if (input.includes('://')) {
72
73
  return null;
74
+ }
73
75
  const segments = [];
74
76
  for (const segment of input.split('/')) {
75
77
  if (segment === '' || segment === '.')
76
78
  continue;
77
79
  if (segment === '..') {
78
- if (segments.length === 0)
80
+ if (segments.length === 0) {
79
81
  return null;
82
+ }
80
83
  segments.pop();
81
84
  continue;
82
85
  }
@@ -88,19 +91,22 @@ export function normalizeDriveKey(prefix, input) {
88
91
  function matchHyperRoot(rest, roots) {
89
92
  return roots.find((r) => rest === r.key || rest.startsWith(r.key + '/'));
90
93
  }
91
- export async function resolveKey(p, roots, realpath, deny = []) {
92
- if (roots.length === 0)
94
+ export async function resolveKey(p, roots, { realpath, deny = [] }) {
95
+ if (roots.length === 0) {
93
96
  return { error: NO_DIRS_GRANTED };
97
+ }
94
98
  if (p.startsWith(HYPER_PREFIX)) {
95
99
  const rest = p.slice(HYPER_PREFIX.length);
96
100
  const hyperRoots = roots.filter((r) => r.kind === 'hyper');
97
101
  const root = matchHyperRoot(rest, hyperRoots);
98
- if (!root)
102
+ if (!root) {
99
103
  return outside(roots);
104
+ }
100
105
  const tail = rest.slice(root.key.length);
101
106
  const key = normalizeDriveKey(root.prefix, tail || '/');
102
- if (key === null)
107
+ if (key === null) {
103
108
  return outside(roots);
109
+ }
104
110
  return { root, key, exists: true };
105
111
  }
106
112
  const localRoots = roots.filter((r) => r.kind === 'local');
@@ -111,8 +117,9 @@ export async function resolveKey(p, roots, realpath, deny = []) {
111
117
  const canonical = await realpath(ancestor);
112
118
  const target = tail.length ? path.join(canonical, ...tail) : canonical;
113
119
  const root = localRoots.find((r) => within(target, r.root));
114
- if (!root)
120
+ if (!root) {
115
121
  return outside(roots);
122
+ }
116
123
  if (isDeniedPath(target, deny)) {
117
124
  return protectedPath();
118
125
  }
@@ -120,8 +127,9 @@ export async function resolveKey(p, roots, realpath, deny = []) {
120
127
  }
121
128
  catch {
122
129
  const parent = path.dirname(ancestor);
123
- if (parent === ancestor)
130
+ if (parent === ancestor) {
124
131
  break;
132
+ }
125
133
  tail.unshift(path.basename(ancestor));
126
134
  ancestor = parent;
127
135
  }
@@ -1,3 +1,4 @@
1
+ import { errorMessage } from '../../guards.js';
1
2
  import { hlog } from '../../log.js';
2
3
  import { displayPath } from './scope.js';
3
4
  export const WALK_SKIP_DIRS = new Set(['.git', 'node_modules']);
@@ -10,10 +11,12 @@ export async function walkFiles(root, folder = '/') {
10
11
  const deadline = Date.now() + MAX_WALK_MS;
11
12
  try {
12
13
  for await (const entry of root.drive.list(folder, { skip: WALK_SKIP_DIRS })) {
13
- if (++visited > MAX_WALK_ENTRIES)
14
+ if (++visited > MAX_WALK_ENTRIES) {
14
15
  return { files, truncated: true, skippedLinks };
15
- if (Date.now() > deadline)
16
+ }
17
+ if (Date.now() > deadline) {
16
18
  return { files, truncated: true, skippedLinks };
19
+ }
17
20
  if (entry.value.linkname !== null) {
18
21
  skippedLinks++;
19
22
  continue;
@@ -30,7 +33,7 @@ export async function walkFiles(root, folder = '/') {
30
33
  root: displayPath(root, '/'),
31
34
  folder,
32
35
  visited,
33
- err: err.message
36
+ err: errorMessage(err)
34
37
  });
35
38
  return { files, truncated: true, skippedLinks };
36
39
  }
@@ -1,4 +1,5 @@
1
1
  import type { Drive } from './drive.ts';
2
- export declare function writeText(drive: Drive, key: string, text: string, opts?: {
2
+ export interface WriteTextOptions {
3
3
  executable?: boolean;
4
- }): Promise<void>;
4
+ }
5
+ export declare function writeText(drive: Drive, key: string, text: string, opts?: WriteTextOptions): Promise<void>;
@@ -89,22 +89,24 @@ export declare function generationPercentTick(onPercent: (percentage: number) =>
89
89
  export declare const IMAGE_LOAD_STALL_ERROR = "image model download stalled";
90
90
  export declare function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBeforeLoad, loads, stallMs, ...base }: DiffusionRuntimeOptions): DiffusionRuntime;
91
91
  export declare const BUSY_ERROR = "an image generation is already running; try again when it finishes";
92
- export declare function runDiffusion(sdk: DiffusionSdk, modelId: string, params: DiffusionParams, signal?: BareAbortSignal, onTick?: (tick: DiffusionTick) => void): Promise<Uint8Array | {
92
+ export interface ImageToolError {
93
93
  error: string;
94
- }>;
94
+ }
95
+ export interface RunDiffusionOptions {
96
+ readonly modelId: string;
97
+ readonly params: DiffusionParams;
98
+ readonly signal?: BareAbortSignal;
99
+ readonly onTick?: (tick: DiffusionTick) => void;
100
+ }
101
+ export declare function runDiffusion(sdk: DiffusionSdk, { modelId, params, signal, onTick }: RunDiffusionOptions): Promise<Uint8Array | ImageToolError>;
95
102
  export interface CommonImageArgs {
96
103
  prompt: string;
97
104
  steps?: number;
98
105
  seed?: number;
99
106
  negativePrompt?: string;
100
107
  }
101
- export declare function parseCommonArgs(args: Record<string, unknown>, maxSteps?: number): CommonImageArgs | {
102
- error: string;
103
- };
104
- export declare function normalizeClamps(clamps?: ImageClamps): {
105
- maxDim: number;
106
- maxSteps: number;
107
- };
108
+ export declare function parseCommonArgs(args: Record<string, unknown>, maxSteps?: number): CommonImageArgs | ImageToolError;
109
+ export declare function normalizeClamps(clamps?: ImageClamps): Required<ImageClamps>;
108
110
  export declare function settingsDimension(value: number | undefined, maxDim?: number): number | undefined;
109
111
  export declare function settingsSteps(value: number | undefined, maxSteps?: number): number | undefined;
110
112
  export declare function effectiveSteps(parsedSteps: number | undefined, settingsValue: number | undefined, stepsCap: number | undefined): number | undefined;
@@ -22,11 +22,13 @@ export function generationPercentTick(onPercent, encodePhases = 0) {
22
22
  }
23
23
  prevStep = step;
24
24
  prevTotal = totalSteps;
25
- if (phase !== encodePhases)
25
+ if (phase !== encodePhases) {
26
26
  return;
27
+ }
27
28
  const percentage = totalSteps > 0 ? Math.min(100, Math.max(0, Math.round((step / totalSteps) * 100))) : 0;
28
- if (percentage <= last)
29
+ if (percentage <= last) {
29
30
  return;
31
+ }
30
32
  last = percentage;
31
33
  onPercent(percentage);
32
34
  };
@@ -76,19 +78,23 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
76
78
  const fingerprint = fingerprintOf(set);
77
79
  await lock.lock();
78
80
  try {
79
- if (loading && residentFingerprint !== fingerprint)
81
+ if (loading && residentFingerprint !== fingerprint) {
80
82
  await doUnload();
81
- if (!loading && onBeforeLoad)
83
+ }
84
+ if (!loading && onBeforeLoad) {
82
85
  await onBeforeLoad(signal);
86
+ }
83
87
  residentFingerprint = fingerprint;
84
88
  loading ??= (async () => {
85
89
  onProgress?.(diffusionProgressName(set), {});
86
90
  const modelSrc = await resolveModelSrc(sdk, set.model, 'diffusion');
87
91
  const config = {};
88
- if (set.prediction)
92
+ if (set.prediction) {
89
93
  config.prediction = set.prediction;
90
- if (set.llmModel)
94
+ }
95
+ if (set.llmModel) {
91
96
  config.llmModelSrc = await resolveModelSrc(sdk, set.llmModel, 'llm');
97
+ }
92
98
  if (set.vaeModel) {
93
99
  config.vaeModelSrc = await resolveModelSrc(sdk, set.vaeModel, 'diffusion');
94
100
  }
@@ -112,7 +118,7 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
112
118
  if (err instanceof Error &&
113
119
  err.message === IMAGE_LOAD_STALL_ERROR &&
114
120
  pending.requestId) {
115
- void sdk.cancel?.({ requestId: pending.requestId }).catch(() => { });
121
+ void sdk.cancel?.({ requestId: pending.requestId }).catch(noop);
116
122
  }
117
123
  throw err;
118
124
  }
@@ -139,33 +145,39 @@ export function createDiffusionRuntime({ loadSdk, onProgress, onLoaded, onBefore
139
145
  };
140
146
  }
141
147
  export const BUSY_ERROR = 'an image generation is already running; try again when it finishes';
142
- export async function runDiffusion(sdk, modelId, params, signal, onTick) {
148
+ export async function runDiffusion(sdk, { modelId, params, signal, onTick }) {
143
149
  const onAbort = () => {
144
- void sdk.cancel?.({ operation: 'inference', modelId }).catch(() => { });
150
+ void sdk.cancel?.({ operation: 'inference', modelId }).catch(noop);
145
151
  };
146
- if (signal?.aborted)
152
+ if (signal?.aborted) {
147
153
  return { error: 'image generation canceled' };
154
+ }
148
155
  signal?.addEventListener('abort', onAbort, { once: true });
149
156
  let settled = false;
150
157
  try {
151
158
  const run = sdk.diffusion({ modelId, vae_tiling: true, ...params });
152
159
  const drained = (async () => {
153
- for await (const tick of run.progressStream)
154
- if (!settled)
160
+ for await (const tick of run.progressStream) {
161
+ if (!settled) {
155
162
  onTick?.(tick);
156
- })().catch(() => { });
163
+ }
164
+ }
165
+ })().catch(noop);
157
166
  const outputs = await run.outputs;
158
167
  await drained;
159
168
  const image = outputs[0];
160
- if (signal?.aborted)
169
+ if (signal?.aborted) {
161
170
  return { error: 'image generation canceled' };
162
- if (!image?.length)
171
+ }
172
+ if (!image?.length) {
163
173
  return { error: 'the diffusion model produced no image' };
174
+ }
164
175
  return image;
165
176
  }
166
177
  catch (err) {
167
- if (signal?.aborted)
178
+ if (signal?.aborted) {
168
179
  return { error: 'image generation canceled' };
180
+ }
169
181
  throw err;
170
182
  }
171
183
  finally {
@@ -175,8 +187,9 @@ export async function runDiffusion(sdk, modelId, params, signal, onTick) {
175
187
  }
176
188
  export function parseCommonArgs(args, maxSteps = MAX_STEPS) {
177
189
  const prompt = typeof args.prompt === 'string' ? args.prompt.trim() : '';
178
- if (!prompt)
190
+ if (!prompt) {
179
191
  return { error: 'prompt must be a non-empty string' };
192
+ }
180
193
  if (prompt.length > MAX_PROMPT_CHARS) {
181
194
  return { error: `prompt exceeds ${MAX_PROMPT_CHARS} characters` };
182
195
  }
@@ -194,8 +207,9 @@ export function parseCommonArgs(args, maxSteps = MAX_STEPS) {
194
207
  if (!Number.isInteger(seed) || seed < -1 || seed > MAX_SEED) {
195
208
  return { error: `seed must be an integer between -1 (random) and ${MAX_SEED}` };
196
209
  }
197
- if (seed === -1)
210
+ if (seed === -1) {
198
211
  seed = undefined;
212
+ }
199
213
  }
200
214
  const negativePrompt = typeof args.negative_prompt === 'string' ? args.negative_prompt : undefined;
201
215
  if (negativePrompt && negativePrompt.length > MAX_PROMPT_CHARS) {
@@ -212,7 +226,7 @@ export function normalizeClamps(clamps) {
212
226
  : MAX_STEPS;
213
227
  return { maxDim, maxSteps };
214
228
  }
215
- function dimension(value, name, fallback, maxDim = MAX_DIM) {
229
+ function dimension(value, { name, fallback, maxDim = MAX_DIM }) {
216
230
  if (value === undefined || value === null)
217
231
  return fallback;
218
232
  const n = Number(value);
@@ -238,15 +252,26 @@ export function effectiveSteps(parsedSteps, settingsValue, stepsCap) {
238
252
  }
239
253
  function parseArgs(args, defaults, cap) {
240
254
  const common = parseCommonArgs(args, cap.maxSteps);
241
- if ('error' in common)
255
+ if ('error' in common) {
242
256
  return common;
257
+ }
243
258
  const fallback = Math.min(DEFAULT_DIM, cap.maxDim);
244
- const width = dimension(args.width, 'width', defaults.width ?? fallback, cap.maxDim);
245
- if (typeof width === 'object')
259
+ const width = dimension(args.width, {
260
+ name: 'width',
261
+ fallback: defaults.width ?? fallback,
262
+ maxDim: cap.maxDim
263
+ });
264
+ if (typeof width === 'object') {
246
265
  return width;
247
- const height = dimension(args.height, 'height', defaults.height ?? fallback, cap.maxDim);
248
- if (typeof height === 'object')
266
+ }
267
+ const height = dimension(args.height, {
268
+ name: 'height',
269
+ fallback: defaults.height ?? fallback,
270
+ maxDim: cap.maxDim
271
+ });
272
+ if (typeof height === 'object') {
249
273
  return height;
274
+ }
250
275
  return { ...common, width, height };
251
276
  }
252
277
  export function createGenerateImageTool(runtime, clamps) {
@@ -295,27 +320,36 @@ export function createGenerateImageTool(runtime, clamps) {
295
320
  width: settingsDimension(ctx?.image?.width, cap.maxDim),
296
321
  height: settingsDimension(ctx?.image?.height, cap.maxDim)
297
322
  }, cap);
298
- if ('error' in parsed)
323
+ if ('error' in parsed) {
299
324
  return parsed;
300
- if (!ctx?.attach)
325
+ }
326
+ if (!ctx?.attach) {
301
327
  return { error: 'this device cannot persist generated images' };
302
- if (!runtime.acquire())
328
+ }
329
+ if (!runtime.acquire()) {
303
330
  return { error: BUSY_ERROR, code: 'busy' };
331
+ }
304
332
  const report = ctx.progress;
305
333
  const onTick = report && generationPercentTick((percentage) => report({ percentage }));
306
334
  try {
307
335
  const sdk = await runtime.loadSdk();
308
336
  const { modelId } = await runtime.ensureLoaded(sdk, ctx.signal, ctx.image?.modelChoice);
309
- const image = await runDiffusion(sdk, modelId, {
310
- prompt: parsed.prompt,
311
- width: parsed.width,
312
- height: parsed.height,
313
- steps: effectiveSteps(parsed.steps, ctx.image?.steps, stepsCap),
314
- seed: parsed.seed,
315
- negative_prompt: parsed.negativePrompt
316
- }, ctx.signal, onTick);
317
- if (!(image instanceof Uint8Array))
337
+ const image = await runDiffusion(sdk, {
338
+ modelId,
339
+ params: {
340
+ prompt: parsed.prompt,
341
+ width: parsed.width,
342
+ height: parsed.height,
343
+ steps: effectiveSteps(parsed.steps, ctx.image?.steps, stepsCap),
344
+ seed: parsed.seed,
345
+ negative_prompt: parsed.negativePrompt
346
+ },
347
+ signal: ctx.signal,
348
+ onTick
349
+ });
350
+ if (!(image instanceof Uint8Array)) {
318
351
  return image;
352
+ }
319
353
  const record = await ctx.attach({
320
354
  fileName: `generated-${Date.now()}.png`,
321
355
  mimeType: 'image/png',
@@ -331,8 +365,9 @@ export function createGenerateImageTool(runtime, clamps) {
331
365
  };
332
366
  }
333
367
  catch (err) {
334
- if (err instanceof AbortedError)
368
+ if (err instanceof AbortedError) {
335
369
  return { error: 'image generation canceled' };
370
+ }
336
371
  if (err instanceof Error && err.message === IMAGE_LOAD_STALL_ERROR) {
337
372
  return { error: IMAGE_LOAD_STALL_ERROR };
338
373
  }
@@ -345,3 +380,4 @@ export function createGenerateImageTool(runtime, clamps) {
345
380
  }
346
381
  };
347
382
  }
383
+ function noop() { }
@@ -81,11 +81,16 @@ export interface MusicRuntimeOptions extends MusicModelStages {
81
81
  export interface LoadedMusicModel {
82
82
  modelId: string;
83
83
  }
84
+ export interface EnsureMusicLoadedOptions {
85
+ readonly signal?: BareAbortSignal;
86
+ readonly modelChoice?: string;
87
+ readonly inferenceSteps?: number;
88
+ }
84
89
  export interface MusicRuntime {
85
90
  loadSdk: () => Promise<MusicGenSdk>;
86
91
  gpuRequested: boolean;
87
92
  defaultSteps?: number;
88
- ensureLoaded: (sdk: MusicGenSdk, signal?: BareAbortSignal, modelChoice?: string, inferenceSteps?: number) => Promise<LoadedMusicModel>;
93
+ ensureLoaded: (sdk: MusicGenSdk, options?: EnsureMusicLoadedOptions) => Promise<LoadedMusicModel>;
89
94
  unload(): Promise<void>;
90
95
  unloadIdle(): Promise<void>;
91
96
  acquire(): boolean;
@@ -94,18 +99,27 @@ export interface MusicRuntime {
94
99
  export declare function musicPercentTick(onPercent: (percentage: number) => void): (tick: MusicTick) => void;
95
100
  export declare function createMusicRuntime({ loadSdk, onProgress, onBeforeLoad, loads, inferenceSteps: baseSteps, useGpu, ...base }: MusicRuntimeOptions): MusicRuntime;
96
101
  export declare const BUSY_ERROR = "a music generation is already running; try again when it finishes";
97
- export declare function runAudioGen(sdk: MusicGenSdk, modelId: string, params: AudioGenParams, signal?: BareAbortSignal, onTick?: (tick: MusicTick) => void): Promise<(GeneratedAudio & {
98
- stats?: MusicStats;
99
- }) | {
102
+ export interface MusicToolError {
100
103
  error: string;
101
- }>;
104
+ }
105
+ export interface GeneratedTrack extends GeneratedAudio {
106
+ stats?: MusicStats;
107
+ }
108
+ export interface RunAudioGenOptions {
109
+ readonly modelId: string;
110
+ readonly params: AudioGenParams;
111
+ readonly signal?: BareAbortSignal;
112
+ readonly onTick?: (tick: MusicTick) => void;
113
+ }
114
+ export declare function runAudioGen(sdk: MusicGenSdk, { modelId, params, signal, onTick }: RunAudioGenOptions): Promise<GeneratedTrack | MusicToolError>;
102
115
  export declare function audioDurationSeconds(audio: GeneratedAudio): number;
103
116
  export declare function presentStats(stats: MusicStats | undefined): MusicStats | undefined;
104
117
  export declare const CPU_FALLBACK_NOTICE = "The GPU was unavailable, so this track was generated on the CPU and took much longer than usual.";
105
- export declare function gpuFallback({ gpuRequested, stats }: {
118
+ export interface GpuFallbackOptions {
106
119
  gpuRequested: boolean;
107
120
  stats: MusicStats | undefined;
108
- }): boolean;
121
+ }
122
+ export declare function gpuFallback({ gpuRequested, stats }: GpuFallbackOptions): boolean;
109
123
  export declare function backendDevice(stats: MusicStats | undefined): 'gpu' | 'cpu' | 'unknown';
110
124
  export declare function backendName(backendId: number | undefined): string;
111
125
  export declare function pcmToWav(audio: GeneratedAudio): Uint8Array;
@@ -115,10 +129,7 @@ export interface MusicClamps {
115
129
  }
116
130
  export declare function settingsDuration(value: number | undefined, maxDuration: number): number | undefined;
117
131
  export declare function settingsSteps(value: number | undefined, maxSteps?: number): number | undefined;
118
- export declare function normalizeClamps(clamps?: MusicClamps): {
119
- maxDuration: number;
120
- maxSteps: number;
121
- };
132
+ export declare function normalizeClamps(clamps?: MusicClamps): Required<MusicClamps>;
122
133
  export declare function resolveMusicSettings(ctx: ToolExecuteContext | undefined): MusicSettings;
123
134
  export declare function createGenerateMusicTool(runtime: MusicRuntime, clamps?: MusicClamps): ToolDefinition;
124
135
  export {};