@poe-platform/safe-bash 0.1.789 → 0.1.790

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 (207) hide show
  1. package/dist/image-ast/index.browser.js +147 -80
  2. package/dist/image-ast/index.js +147 -80
  3. package/dist/mp4-ast/mp4.d.ts +2 -0
  4. package/dist/pdf-ast/cos/parser.d.ts +1 -0
  5. package/dist/pdf-ast/cos/security.d.ts +2 -0
  6. package/dist/pdf-ast/cos/writer.d.ts +1 -0
  7. package/dist/pdf-ast/document.d.ts +3 -0
  8. package/dist/pdf-ast/edit/forms.d.ts +1 -0
  9. package/dist/pdf-ast/index.js +171 -82
  10. package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
  11. package/dist/safe-bash/chunks/{chunk-KHJGUF2W.js → chunk-2TAGYMPK.js} +43 -42
  12. package/dist/safe-bash/chunks/{chunk-D4PHJK4T.js → chunk-2W4HTMEK.js} +52 -48
  13. package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
  14. package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
  15. package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
  16. package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
  17. package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
  18. package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
  19. package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
  20. package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
  21. package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
  22. package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
  23. package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
  24. package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
  25. package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
  26. package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
  27. package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
  28. package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
  29. package/dist/safe-bash/chunks/{chunk-X5ZCECM6.js → chunk-QTIH2AFE.js} +77 -69
  30. package/dist/safe-bash/chunks/{chunk-CTUHLNJM.js → chunk-SBESXWT2.js} +43 -44
  31. package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
  32. package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
  33. package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
  34. package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
  35. package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
  36. package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
  37. package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
  38. package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
  39. package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
  40. package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
  41. package/dist/safe-bash/chunks/{git-HO7WDPHZ.js → git-LPAF6KDG.js} +7 -9
  42. package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
  43. package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
  44. package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
  45. package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
  46. package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
  47. package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
  48. package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
  49. package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
  50. package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
  51. package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
  52. package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
  53. package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
  54. package/dist/safe-bash/command-chunks/{chunk-2VTMZTV3.js → chunk-2EXV2ZLV.js} +2 -2
  55. package/dist/safe-bash/command-chunks/{chunk-UJOO6DKY.js → chunk-6EASC5EC.js} +1 -1
  56. package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
  57. package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
  58. package/dist/safe-bash/command-chunks/{chunk-6F7QJMJ3.js → chunk-CBDVLMJB.js} +1 -1
  59. package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
  60. package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
  61. package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
  62. package/dist/safe-bash/command-chunks/{chunk-XNHSCU6I.js → chunk-MDPIOQUD.js} +6 -6
  63. package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
  64. package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
  65. package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
  66. package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
  67. package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
  68. package/dist/safe-bash/command-chunks/{chunk-AT6ZSOE6.js → chunk-TPPBPIWL.js} +1 -1
  69. package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
  70. package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
  71. package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
  72. package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
  73. package/dist/safe-bash/commands/docx/index.browser.js +2 -2
  74. package/dist/safe-bash/commands/factor/index.browser.js +2 -2
  75. package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
  76. package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
  77. package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
  78. package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
  79. package/dist/safe-bash/commands/llm/command.d.ts +1 -4
  80. package/dist/safe-bash/commands/llm/command.js +1 -248
  81. package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
  82. package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
  83. package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
  84. package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
  85. package/dist/safe-bash/commands/llm/index.browser.js +20 -15
  86. package/dist/safe-bash/commands/llm/index.d.ts +1 -6
  87. package/dist/safe-bash/commands/llm/index.js +1 -4
  88. package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
  89. package/dist/safe-bash/commands/llm/mime.js +1 -136
  90. package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
  91. package/dist/safe-bash/commands/llm/openai-http.js +1 -143
  92. package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
  93. package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
  94. package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
  95. package/dist/safe-bash/commands/llm/openai.js +1 -288
  96. package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
  97. package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
  98. package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
  99. package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
  100. package/dist/safe-bash/commands/llm/providers/index.js +1 -2
  101. package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
  102. package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
  103. package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
  104. package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
  105. package/dist/safe-bash/commands/llm/service.d.ts +1 -37
  106. package/dist/safe-bash/commands/llm/service.js +1 -151
  107. package/dist/safe-bash/commands/llm/types.d.ts +1 -52
  108. package/dist/safe-bash/commands/llm/types.js +1 -1
  109. package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
  110. package/dist/safe-bash/commands/media/index.browser.js +1 -1
  111. package/dist/safe-bash/commands/network/index.browser.js +9 -9
  112. package/dist/safe-bash/commands/network/types.d.ts +2 -40
  113. package/dist/safe-bash/commands/node/index.browser.js +6 -8
  114. package/dist/safe-bash/commands/op/index.browser.js +3 -3
  115. package/dist/safe-bash/commands/op/index.js +12 -28
  116. package/dist/safe-bash/commands/pr/index.browser.js +2 -2
  117. package/dist/safe-bash/commands/python/index.browser.js +8 -8
  118. package/dist/safe-bash/commands/python/worker.browser.js +2 -2
  119. package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
  120. package/dist/safe-bash/commands/xml/index.browser.js +2 -2
  121. package/dist/safe-bash/commands/yq/index.browser.js +3 -3
  122. package/dist/safe-bash/core.browser.js +9775 -10975
  123. package/dist/safe-bash/core.d.ts +0 -1
  124. package/dist/safe-bash/core.js +0 -1
  125. package/dist/safe-bash/jobs.browser.js +5 -4
  126. package/dist/safe-bash/optional-host.browser.js +61 -88
  127. package/dist/safe-bash/shell/runtime.js +34 -12
  128. package/dist/safe-bash/yq-browser/index.js +1 -1
  129. package/dist/safe-bash-command-ffmpeg/index.js +8130 -8011
  130. package/dist/safe-bash-command-git/git_rust.wasm +0 -0
  131. package/dist/safe-bash-command-git/wasm.generated.js +1 -1
  132. package/dist/safe-bash-command-imagemagick/index.js +2 -2
  133. package/dist/safe-bash-command-llm/LICENSE +21 -0
  134. package/dist/safe-bash-command-llm/command.d.ts +5 -0
  135. package/dist/safe-bash-command-llm/command.js +14 -0
  136. package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
  137. package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
  138. package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
  139. package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
  140. package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
  141. package/dist/safe-bash-command-llm/index.d.ts +10 -0
  142. package/dist/safe-bash-command-llm/index.js +46 -0
  143. package/dist/safe-bash-command-llm/mime.d.ts +2 -0
  144. package/dist/safe-bash-command-llm/mime.js +9 -0
  145. package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
  146. package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
  147. package/dist/safe-bash-command-llm/openai-http.js +17 -0
  148. package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
  149. package/dist/safe-bash-command-llm/openai-sse.js +8 -0
  150. package/dist/safe-bash-command-llm/openai.d.ts +14 -0
  151. package/dist/safe-bash-command-llm/openai.js +12 -0
  152. package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
  153. package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
  154. package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
  155. package/dist/safe-bash-command-llm/providers/index.js +24 -0
  156. package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
  157. package/dist/safe-bash-command-llm/providers/openai.js +13 -0
  158. package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
  159. package/dist/safe-bash-command-llm/providers/shared.js +13 -0
  160. package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
  161. package/dist/safe-bash-command-llm/service.d.ts +42 -0
  162. package/dist/safe-bash-command-llm/service.js +9 -0
  163. package/dist/safe-bash-command-llm/templates.d.ts +27 -0
  164. package/dist/safe-bash-command-llm/types.d.ts +87 -0
  165. package/dist/safe-bash-command-llm/types.js +6 -0
  166. package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
  167. package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
  168. package/dist/safe-bash-command-mmdc/index.js +7084 -6687
  169. package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
  170. package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
  171. package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
  172. package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
  173. package/dist/safe-bash-command-pandoc/command.js +3 -3
  174. package/dist/safe-bash-command-pandoc/index.js +3 -3
  175. package/dist/safe-bash-command-pdfimages/index.js +147 -80
  176. package/dist/safe-bash-command-pdfinfo/index.js +147 -80
  177. package/dist/safe-bash-command-pdftk/index.js +147 -80
  178. package/dist/safe-bash-command-pdftoppm/index.js +147 -80
  179. package/dist/safe-bash-command-pdftotext/index.js +147 -80
  180. package/dist/safe-bash-command-qpdf/index.js +174 -101
  181. package/dist/safe-bash-command-sips/index.js +2 -2
  182. package/dist/safe-bash-command-soffice/index.js +1 -1
  183. package/dist/safe-bash-command-ssconvert/index.js +147 -80
  184. package/dist/safe-bash-command-wkhtmltopdf/index.js +147 -80
  185. package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
  186. package/dist/safe-bash-contracts/default-executor.js +37 -0
  187. package/dist/safe-bash-contracts/http.d.ts +41 -0
  188. package/dist/safe-bash-contracts/http.js +6 -0
  189. package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
  190. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
  191. package/dist/safe-bash-io-engine/gnu-information.d.ts +1 -1
  192. package/dist/safe-bash-io-engine/gnu-information.js +1 -1
  193. package/dist/safe-bash-io-engine/internal.js +2 -2
  194. package/dist/safe-bash-query-engine/index.js +3 -3
  195. package/dist/safe-bash-query-engine/interpreter.js +2 -2
  196. package/dist/safe-bash-query-engine/query-core.js +3 -3
  197. package/package.json +2 -2
  198. package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
  199. package/dist/safe-bash/chunks/chunk-2MUJ7RLZ.js +0 -409
  200. package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
  201. package/dist/safe-bash/chunks/chunk-H7MMJS26.js +0 -37
  202. package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
  203. package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
  204. package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
  205. package/dist/safe-bash/chunks/chunk-VUVKC6HV.js +0 -81
  206. package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
  207. package/dist/safe-bash/command-chunks/{chunk-BJ6DGYJA.js → chunk-KNI4GRXF.js} +3 -3
@@ -0,0 +1,5 @@
1
+ import type { CommandDefinition } from "./command.js";
2
+ export { builtInDirectContextExecutors } from "./runtime-control.js";
3
+ export declare function isDefaultCommandOptions(options?: unknown): boolean;
4
+ export declare function registerDefaultExecutor<T extends CommandDefinition>(def: T, options?: unknown): T;
5
+ export declare function registerDefaultExecutors<T extends readonly CommandDefinition[]>(defs: T, options?: unknown): T;
@@ -0,0 +1,37 @@
1
+ import {
2
+ builtInDirectContextExecutors
3
+ } from "../safe-bash/command-chunks/chunk-G3G6W5ZE.js";
4
+ import "../safe-bash/command-chunks/chunk-64LG3EVJ.js";
5
+ import {
6
+ init_buffer
7
+ } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
8
+
9
+ // packages/safe-bash-contracts/dist/default-executor.js
10
+ init_buffer();
11
+ function isDefaultCommandOptions(options) {
12
+ if (!options || typeof options !== "object")
13
+ return true;
14
+ for (const [k, v] of Object.entries(options)) {
15
+ if (k !== "replace" && v !== void 0)
16
+ return false;
17
+ }
18
+ return true;
19
+ }
20
+ function registerDefaultExecutor(def, options) {
21
+ if (isDefaultCommandOptions(options))
22
+ builtInDirectContextExecutors.add(def.execute);
23
+ return def;
24
+ }
25
+ function registerDefaultExecutors(defs, options) {
26
+ if (isDefaultCommandOptions(options)) {
27
+ for (let i = 0; i < defs.length; i++)
28
+ builtInDirectContextExecutors.add(defs[i].execute);
29
+ }
30
+ return defs;
31
+ }
32
+ export {
33
+ builtInDirectContextExecutors,
34
+ isDefaultCommandOptions,
35
+ registerDefaultExecutor,
36
+ registerDefaultExecutors
37
+ };
@@ -0,0 +1,41 @@
1
+ import type { ByteSource } from "./io.js";
2
+ import type { InvocationCleanup } from "./command.js";
3
+ export type HttpHeaders = readonly (readonly [string, string])[];
4
+ export interface HttpRequest {
5
+ /** Explicit VFS PEM trust for this request; replaces transport-default CAs. */
6
+ readonly ca?: Uint8Array;
7
+ readonly httpVersion?: "1.0" | "1.1";
8
+ /** Read until EOF rather than using Content-Length; host transport must opt in. */
9
+ readonly ignoreContentLength?: true;
10
+ /** Validated HTTP(S) origin with curl request-target spelling; transports must preserve it. */
11
+ readonly url: string;
12
+ readonly method: string;
13
+ readonly headers: HttpHeaders;
14
+ readonly body?: ByteSource;
15
+ /** Consumer body intent, independent of method. Omitted means "read".
16
+ * "omit" permits an empty body; "omit-on-http-error" permits it only for
17
+ * status >= 400. Neither changes the HTTP request or response status/headers. */
18
+ readonly responseBodyMode?: "omit" | "omit-on-http-error" | "read";
19
+ readonly signal: AbortSignal;
20
+ /** Deadline for DNS, TCP and TLS setup only; absent means no separate connection deadline. */
21
+ readonly connectTimeoutMs?: number;
22
+ readonly registerCleanup?: (cleanup: InvocationCleanup) => void;
23
+ readonly denyPrivateNetworks?: true;
24
+ }
25
+ export interface HttpResponse {
26
+ readonly status: number;
27
+ readonly statusText: string;
28
+ readonly headers: HttpHeaders;
29
+ readonly httpVersion?: string;
30
+ readonly body: ByteSource;
31
+ /** True when the host already decoded Content-Encoding; encoded length is then unavailable. */
32
+ readonly contentDecoded?: boolean;
33
+ dispose(): Promise<void>;
34
+ }
35
+ export type HttpTransport = ((request: HttpRequest) => Promise<HttpResponse>) & {
36
+ readonly supportsRequestCa?: true;
37
+ readonly supportedHttpVersions?: readonly ("1.0" | "1.1")[];
38
+ readonly supportsIgnoreContentLength?: true;
39
+ readonly supportsPrivateNetworkDeny?: true;
40
+ readonly supportsConnectTimeout?: true;
41
+ };
@@ -0,0 +1,6 @@
1
+ import {
2
+ init_buffer
3
+ } from "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
4
+
5
+ // packages/safe-bash-contracts/dist/http.js
6
+ init_buffer();
@@ -5,10 +5,10 @@ import {
5
5
  requiredFileInput,
6
6
  searchRequirements,
7
7
  sedRequirements
8
- } from "../../../safe-bash/command-chunks/chunk-6F7QJMJ3.js";
9
- import "../../../safe-bash/command-chunks/chunk-UJOO6DKY.js";
8
+ } from "../../../safe-bash/command-chunks/chunk-CBDVLMJB.js";
9
+ import "../../../safe-bash/command-chunks/chunk-6EASC5EC.js";
10
10
  import "../../../safe-bash/command-chunks/chunk-OTYUNKT5.js";
11
- import "../../../safe-bash/command-chunks/chunk-XNHSCU6I.js";
11
+ import "../../../safe-bash/command-chunks/chunk-MDPIOQUD.js";
12
12
  import "../../../safe-bash/command-chunks/chunk-YAFQG4SC.js";
13
13
  import "../../../safe-bash/command-chunks/chunk-3746OSHN.js";
14
14
  import "../../../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  requiredFileInput
3
- } from "../../../safe-bash/command-chunks/chunk-6F7QJMJ3.js";
3
+ } from "../../../safe-bash/command-chunks/chunk-CBDVLMJB.js";
4
4
  import {
5
5
  RESOLVED_EXIT_ONE,
6
6
  RESOLVED_EXIT_ZERO,
7
7
  builtInDirectContextExecutors
8
- } from "../../../safe-bash/command-chunks/chunk-UJOO6DKY.js";
8
+ } from "../../../safe-bash/command-chunks/chunk-6EASC5EC.js";
9
9
  import "../../../safe-bash/command-chunks/chunk-OTYUNKT5.js";
10
- import "../../../safe-bash/command-chunks/chunk-XNHSCU6I.js";
10
+ import "../../../safe-bash/command-chunks/chunk-MDPIOQUD.js";
11
11
  import {
12
12
  inputRequirements
13
13
  } from "../../../safe-bash/command-chunks/chunk-YAFQG4SC.js";
@@ -1,3 +1,3 @@
1
1
  import { type CommandContext, type CommandResult } from "../safe-bash-contracts/index.js";
2
- export declare function gnuInformationSync(name: string, args: readonly string[], externalInvocation?: boolean): string | undefined;
2
+ export declare function gnuInformationSync(name: string, args: readonly string[], externalInvocation?: boolean, posixlyCorrect?: boolean): string | undefined;
3
3
  export declare function gnuInformation(name: string, context: CommandContext): Promise<CommandResult | undefined> | undefined;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  gnuInformation,
3
3
  gnuInformationSync
4
- } from "../safe-bash/command-chunks/chunk-XNHSCU6I.js";
4
+ } from "../safe-bash/command-chunks/chunk-MDPIOQUD.js";
5
5
  import "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
6
6
  export {
7
7
  gnuInformation,
@@ -44,9 +44,9 @@ import {
44
44
  requireOperands,
45
45
  syncCommandEvaluators,
46
46
  value
47
- } from "../safe-bash/command-chunks/chunk-UJOO6DKY.js";
47
+ } from "../safe-bash/command-chunks/chunk-6EASC5EC.js";
48
48
  import "../safe-bash/command-chunks/chunk-OTYUNKT5.js";
49
- import "../safe-bash/command-chunks/chunk-XNHSCU6I.js";
49
+ import "../safe-bash/command-chunks/chunk-MDPIOQUD.js";
50
50
  import "../safe-bash/command-chunks/chunk-YAFQG4SC.js";
51
51
  import "../safe-bash/command-chunks/chunk-3746OSHN.js";
52
52
  import "../safe-bash/command-chunks/chunk-HX3SHTCE.js";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-AT6ZSOE6.js";
4
+ } from "../safe-bash/command-chunks/chunk-TPPBPIWL.js";
5
5
  import "../safe-bash/command-chunks/chunk-JUMF6JDJ.js";
6
- import "../safe-bash/command-chunks/chunk-BJ6DGYJA.js";
6
+ import "../safe-bash/command-chunks/chunk-KNI4GRXF.js";
7
7
  import "../safe-bash/command-chunks/chunk-5PM5TEPM.js";
8
8
  import "../safe-bash/command-chunks/chunk-CXMOCPPH.js";
9
9
  import "../safe-bash/command-chunks/chunk-3KROFHBT.js";
10
+ import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
10
11
  import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
11
12
  import "../safe-bash/command-chunks/chunk-VQLFJCG7.js";
12
13
  import "../safe-bash/command-chunks/chunk-HETU7MYN.js";
13
14
  import "../safe-bash/command-chunks/chunk-MYKK3Q5G.js";
14
- import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
15
15
  import "../safe-bash/command-chunks/chunk-5L62A5RO.js";
16
16
  import "../safe-bash/command-chunks/chunk-NYUMOVF2.js";
17
17
  import "../safe-bash/command-chunks/chunk-VUG324ER.js";
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  Interpreter
3
- } from "../safe-bash/command-chunks/chunk-BJ6DGYJA.js";
3
+ } from "../safe-bash/command-chunks/chunk-KNI4GRXF.js";
4
4
  import "../safe-bash/command-chunks/chunk-5PM5TEPM.js";
5
5
  import "../safe-bash/command-chunks/chunk-CXMOCPPH.js";
6
6
  import "../safe-bash/command-chunks/chunk-3KROFHBT.js";
7
+ import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
7
8
  import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
8
9
  import "../safe-bash/command-chunks/chunk-VQLFJCG7.js";
9
10
  import "../safe-bash/command-chunks/chunk-HETU7MYN.js";
10
11
  import "../safe-bash/command-chunks/chunk-MYKK3Q5G.js";
11
- import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
12
12
  import "../safe-bash/command-chunks/chunk-5L62A5RO.js";
13
13
  import "../safe-bash/command-chunks/chunk-NYUMOVF2.js";
14
14
  import "../safe-bash/command-chunks/chunk-VUG324ER.js";
@@ -1,17 +1,17 @@
1
1
  import {
2
2
  YqValueFailure,
3
3
  createYqQuerySession
4
- } from "../safe-bash/command-chunks/chunk-AT6ZSOE6.js";
4
+ } from "../safe-bash/command-chunks/chunk-TPPBPIWL.js";
5
5
  import "../safe-bash/command-chunks/chunk-JUMF6JDJ.js";
6
- import "../safe-bash/command-chunks/chunk-BJ6DGYJA.js";
6
+ import "../safe-bash/command-chunks/chunk-KNI4GRXF.js";
7
7
  import "../safe-bash/command-chunks/chunk-5PM5TEPM.js";
8
8
  import "../safe-bash/command-chunks/chunk-CXMOCPPH.js";
9
9
  import "../safe-bash/command-chunks/chunk-3KROFHBT.js";
10
+ import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
10
11
  import "../safe-bash/command-chunks/chunk-SNXWY3KV.js";
11
12
  import "../safe-bash/command-chunks/chunk-VQLFJCG7.js";
12
13
  import "../safe-bash/command-chunks/chunk-HETU7MYN.js";
13
14
  import "../safe-bash/command-chunks/chunk-MYKK3Q5G.js";
14
- import "../safe-bash/command-chunks/chunk-OYZ534IK.js";
15
15
  import "../safe-bash/command-chunks/chunk-5L62A5RO.js";
16
16
  import "../safe-bash/command-chunks/chunk-NYUMOVF2.js";
17
17
  import "../safe-bash/command-chunks/chunk-VUG324ER.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.789",
3
+ "version": "0.1.790",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -847,7 +847,7 @@
847
847
  "access": "public"
848
848
  },
849
849
  "dependencies": {
850
- "@poe-platform/safe-fs": "0.1.789",
850
+ "@poe-platform/safe-fs": "0.1.790",
851
851
  "pdf-lib": "1.17.1",
852
852
  "@noble/hashes": "2.4.0",
853
853
  "pako": "3.0.1",
@@ -1,14 +0,0 @@
1
- import {
2
- __reExport,
3
- init_platform
4
- } from "./chunk-Q45QCA4J.js";
5
-
6
- // packages/safe-bash/src/escaping.ts
7
- var escaping_exports = {};
8
- init_platform();
9
- __reExport(escaping_exports, escaping_star);
10
- import * as escaping_star from "../../safe-bash-query-engine/escaping.js";
11
-
12
- export {
13
- escaping_exports
14
- };
@@ -1,409 +0,0 @@
1
- import {
2
- escaping_exports
3
- } from "./chunk-2G2T5MEM.js";
4
- import {
5
- contracts_exports
6
- } from "./chunk-VUVKC6HV.js";
7
- import {
8
- yield_exports
9
- } from "./chunk-LAPF2XE6.js";
10
- import {
11
- internal_exports
12
- } from "./chunk-GJWUEOT6.js";
13
- import {
14
- acceptsMimeType,
15
- sniffMimeType
16
- } from "./chunk-LD76P7AG.js";
17
- import {
18
- init_platform
19
- } from "./chunk-Q45QCA4J.js";
20
-
21
- // packages/safe-bash/src/commands/llm/index.ts
22
- init_platform();
23
-
24
- // packages/safe-bash/src/commands/llm/command.ts
25
- init_platform();
26
-
27
- // packages/safe-bash/src/commands/llm/service.ts
28
- init_platform();
29
- function abortable(start, signal) {
30
- signal.throwIfAborted();
31
- return new Promise((resolve, reject) => {
32
- const abort = () => {
33
- signal.removeEventListener("abort", abort);
34
- reject(signal.reason);
35
- };
36
- signal.addEventListener("abort", abort, { once: true });
37
- Promise.resolve().then(() => {
38
- signal.throwIfAborted();
39
- return start();
40
- }).then(
41
- (value) => {
42
- signal.removeEventListener("abort", abort);
43
- if (signal.aborted) reject(signal.reason);
44
- else resolve(value);
45
- },
46
- (error) => {
47
- signal.removeEventListener("abort", abort);
48
- reject(signal.aborted ? signal.reason : error);
49
- }
50
- );
51
- if (signal.aborted) abort();
52
- });
53
- }
54
- function validateMetadata(value) {
55
- for (const field of [value.usage, value.metadata]) {
56
- if (field !== void 0 && (!field || typeof field !== "object" || Array.isArray(field))) throw new TypeError("Invalid LLM response metadata");
57
- }
58
- }
59
- function validateOptions(options) {
60
- for (const [key, value] of Object.entries(options)) {
61
- if (!key || value !== null && !["string", "number", "boolean"].includes(typeof value) || typeof value === "number" && !Number.isFinite(value)) {
62
- throw new TypeError(`Invalid model option ${key}: expected a finite scalar`);
63
- }
64
- }
65
- }
66
- function createLlmService(options) {
67
- const models = [];
68
- const lookup = /* @__PURE__ */ new Map();
69
- const defaultModel = options.defaultModel;
70
- for (const provider of options.providers) {
71
- if (!provider.name || typeof provider.complete !== "function") throw new TypeError("Providers require a name and complete function");
72
- for (const declared of provider.models) {
73
- if (!declared.id) throw new TypeError("Models require a nonempty id");
74
- const model = Object.freeze({
75
- ...declared,
76
- ...declared.capabilities ? { capabilities: Object.freeze([...declared.capabilities]) } : {},
77
- ...declared.aliases ? { aliases: Object.freeze([...declared.aliases]) } : {},
78
- ...declared.attachmentTypes ? { attachmentTypes: Object.freeze([...declared.attachmentTypes]) } : {}
79
- });
80
- const entry = Object.freeze({ provider, model });
81
- for (const name of /* @__PURE__ */ new Set([model.id, `${provider.name}/${model.id}`, ...model.aliases ?? []])) {
82
- if (!name) throw new TypeError("Model aliases must not be empty");
83
- if (lookup.has(name)) throw new Error(`Duplicate model id or alias: ${name}`);
84
- lookup.set(name, entry);
85
- }
86
- models.push(entry);
87
- }
88
- }
89
- return Object.freeze({
90
- version: 1,
91
- models: Object.freeze(models),
92
- resolve(model) {
93
- const selected = model ?? defaultModel;
94
- if (selected === void 0) throw new Error("No model selected; use --model or configure defaultModel");
95
- const entry = lookup.get(selected);
96
- if (!entry) throw new Error(`Unknown model: ${selected}`);
97
- return entry;
98
- },
99
- complete(request) {
100
- request.signal.throwIfAborted();
101
- validateOptions(request.options);
102
- if (typeof request.prompt !== "string" || request.system !== void 0 && typeof request.system !== "string") throw new TypeError("Invalid LLM prompt");
103
- const entry = this.resolve(request.model);
104
- if (request.messages?.length && !entry.model.capabilities?.includes("messages")) throw new Error(`Model ${entry.model.id} does not support messages`);
105
- if (request.messages?.some((message) => !["system", "user", "assistant"].includes(message.role) || typeof message.content !== "string")) throw new TypeError("Invalid LLM message");
106
- if (request.schema !== void 0) {
107
- if (!entry.model.capabilities?.includes("schema")) throw new Error(`Model ${entry.model.id} does not support schema`);
108
- if (!request.schema || typeof request.schema !== "object" || Array.isArray(request.schema)) throw new TypeError("Invalid LLM schema");
109
- }
110
- for (const attachment of request.attachments) {
111
- if (!acceptsMimeType(entry.model.attachmentTypes ?? [], attachment.mimeType)) {
112
- throw new Error(`Model ${entry.model.id} does not accept ${attachment.mimeType}`);
113
- }
114
- }
115
- const { maxOutputBytes: ignoredMaxOutputBytes, ...input } = request;
116
- return entry.provider.complete({ ...input, model: entry.model.id });
117
- },
118
- async *stream(request) {
119
- const limit = request.maxOutputBytes ?? Infinity;
120
- if (limit !== Infinity && (!Number.isSafeInteger(limit) || limit < 0)) throw new RangeError("Invalid LLM output limit");
121
- const entry = this.resolve(request.model);
122
- const iterator = this.complete(request)[Symbol.asyncIterator]();
123
- let ended = false;
124
- let size = 0;
125
- try {
126
- while (true) {
127
- request.signal.throwIfAborted();
128
- const result = await abortable(() => iterator.next(), request.signal);
129
- request.signal.throwIfAborted();
130
- if (result.done) {
131
- ended = true;
132
- const metadata = result.value;
133
- if (metadata !== void 0 && (!metadata || typeof metadata !== "object" || Array.isArray(metadata))) throw new TypeError("Invalid LLM response metadata");
134
- const details = metadata;
135
- if (details) validateMetadata(details);
136
- yield { type: "response", response: { model: entry.model.id, ...details?.usage ? { usage: details.usage } : {}, ...details?.metadata ? { metadata: details.metadata } : {} } };
137
- return;
138
- }
139
- const chunk = result.value;
140
- const text = (entry.model.outputType ?? "text/plain").toLowerCase().startsWith("text/");
141
- if (text ? typeof chunk !== "string" : !(chunk instanceof Uint8Array)) throw new TypeError("Provider returned an incompatible LLM output chunk");
142
- size += typeof chunk === "string" ? new TextEncoder().encode(chunk).length : chunk.byteLength;
143
- if (size > limit) throw new RangeError("LLM output byte limit exceeded");
144
- yield typeof chunk === "string" ? { type: "text", text: chunk } : { type: "bytes", data: new Uint8Array(chunk) };
145
- }
146
- } finally {
147
- if (!ended) {
148
- const closing = Promise.resolve().then(() => iterator.return?.());
149
- if (request.signal.aborted) void closing.catch(() => void 0);
150
- else await closing;
151
- }
152
- }
153
- },
154
- async embed(request) {
155
- request.signal.throwIfAborted();
156
- validateOptions(request.options);
157
- if (!Array.isArray(request.inputs) || Array.from(request.inputs).some((input) => typeof input !== "string")) throw new TypeError("Embedding inputs must be strings");
158
- const entry = this.resolve(request.model);
159
- if (!entry.model.capabilities?.includes("embed") || !entry.provider.embed) throw new Error(`Model ${entry.model.id} does not support embeddings`);
160
- const embed = entry.provider.embed.bind(entry.provider);
161
- const result = await abortable(() => embed({ ...request, model: entry.model.id }), request.signal);
162
- request.signal.throwIfAborted();
163
- if (result.model !== entry.model.id || !Array.isArray(result.vectors) || result.vectors.length !== request.inputs.length || Array.from(result.vectors).some((vector) => !Array.isArray(vector) || !vector.length || Array.from(vector).some((value) => typeof value !== "number" || !Number.isFinite(value)) || vector.length !== result.vectors[0]?.length)) throw new TypeError("Invalid embedding response");
164
- validateMetadata(result);
165
- return result;
166
- }
167
- });
168
- }
169
-
170
- // packages/safe-bash/src/commands/llm/command.ts
171
- async function parse(length, text, step) {
172
- const parsed = { prompt: "", options: /* @__PURE__ */ Object.create(null), attachments: [] };
173
- const operands = [];
174
- let ended = false;
175
- for (let index = 0; index < length; index++) {
176
- await step();
177
- const argument = text(index);
178
- if (ended || !argument.startsWith("-") || argument === "-") {
179
- operands.push(argument);
180
- continue;
181
- }
182
- if (argument === "--") {
183
- ended = true;
184
- continue;
185
- }
186
- const equals = argument.indexOf("=");
187
- const long = argument.startsWith("--");
188
- const flag = long ? argument.slice(0, equals < 0 ? void 0 : equals) : argument.slice(0, 2);
189
- const attached = long ? equals < 0 ? void 0 : argument.slice(equals + 1) : argument.length > 2 ? argument.slice(2) : void 0;
190
- const take = () => {
191
- if (++index >= length) throw new Error(`Option ${flag} requires an argument`);
192
- return text(index);
193
- };
194
- if (!["-m", "--model", "-s", "--system", "-o", "--option", "-a", "--attachment", "--at"].includes(flag)) throw new Error(`Unknown option: ${flag}`);
195
- const value = attached ?? take();
196
- if (flag === "-m" || flag === "--model") parsed.model = value;
197
- else if (flag === "-s" || flag === "--system") parsed.system = value;
198
- else if (flag === "-o" || flag === "--option") parsed.options[value] = take();
199
- else if (flag === "--at") parsed.attachments.push({ path: value, mimeType: take() });
200
- else parsed.attachments.push({ path: value });
201
- }
202
- parsed.prompt = operands.join(" ");
203
- return parsed;
204
- }
205
- async function interrupted(start, signal) {
206
- signal.throwIfAborted();
207
- return new Promise((resolve, reject) => {
208
- const aborted = () => reject(signal.reason);
209
- signal.addEventListener("abort", aborted, { once: true });
210
- Promise.resolve().then(() => {
211
- signal.throwIfAborted();
212
- return start();
213
- }).then(
214
- (value) => {
215
- signal.removeEventListener("abort", aborted);
216
- resolve(value);
217
- },
218
- (error) => {
219
- signal.removeEventListener("abort", aborted);
220
- reject(error);
221
- }
222
- );
223
- });
224
- }
225
- async function execute(context, service) {
226
- context.signal.throwIfAborted();
227
- const controller = new AbortController();
228
- const operation = (0, contracts_exports.createOutputOperation)(context, context.stdout);
229
- const signal = AbortSignal.any([operation.signal, controller.signal]);
230
- (0, yield_exports.inheritYieldCheckpoint)(context.signal, signal);
231
- let iterator;
232
- let closed = false;
233
- let ended = false;
234
- operation.registerCleanup(() => {
235
- if (closed) return;
236
- closed = true;
237
- controller.abort(new Error("llm request closed"));
238
- if (!ended && iterator) {
239
- const resource = iterator;
240
- void Promise.resolve().then(() => resource.return?.()).catch(() => {
241
- });
242
- }
243
- });
244
- let work = 0;
245
- const step = async () => {
246
- signal.throwIfAborted();
247
- if (closed) throw new Error("LLM invocation is closed");
248
- work++;
249
- if (work % 256 === 0) await (0, yield_exports.yieldTurn)(signal);
250
- };
251
- let writing = false;
252
- const write = async (chunk) => {
253
- writing = true;
254
- await operation.output.write(chunk);
255
- writing = false;
256
- };
257
- const emitText = async (text) => {
258
- for (let offset = 0; offset < text.length; ) {
259
- await step();
260
- let end = Math.min(text.length, offset + 16384);
261
- const last = text.charCodeAt(end - 1);
262
- if (end < text.length && last >= 55296 && last <= 56319) end--;
263
- await write(new TextEncoder().encode(text.slice(offset, end)));
264
- offset = end;
265
- }
266
- };
267
- let inputBytes = 0;
268
- const inputLimit = context.inputBudget?.maxBytes ?? Infinity;
269
- const checkInput = (size) => {
270
- context.inputBudget?.check(inputBytes + size);
271
- if (size > inputLimit - inputBytes) throw new contracts_exports.FsError("EFBIG", { message: "llm input byte limit exceeded" });
272
- };
273
- const admitInput = (size) => {
274
- checkInput(size);
275
- inputBytes += size;
276
- };
277
- try {
278
- const argumentsValue = (0, contracts_exports.getCommandArguments)(context);
279
- const argumentText = (index) => {
280
- const bytes = argumentsValue.bytes(index);
281
- if (!bytes) throw new Error("Missing option argument");
282
- return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
283
- };
284
- if (argumentsValue.args.length === 1 && ["--help", "-h"].includes(argumentsValue.args[0])) {
285
- argumentText(0);
286
- await emitText("Usage: llm [prompt] [-m MODEL] [-s SYSTEM] [-o KEY VALUE] [-a PATH] [--at PATH MIMETYPE]\n llm models\nOptions: --model, --system, --option, --attachment; -- ends options\n");
287
- return { exitCode: 0 };
288
- }
289
- if (argumentsValue.args.length === 2 && argumentsValue.args[0] === "models" && ["--help", "-h"].includes(argumentsValue.args[1])) {
290
- argumentText(0);
291
- argumentText(1);
292
- await emitText("Usage: llm models [OPTIONS]\n\n List configured models\n\nOptions:\n -h, --help Show this message and exit.\n");
293
- return { exitCode: 0 };
294
- }
295
- const args = await parse(argumentsValue.args.length, argumentText, step);
296
- if (argumentsValue.args[0] === "models" && args.prompt === "models" && !args.attachments.length) {
297
- for (const { provider, model } of service.models) {
298
- await step();
299
- await emitText(`${provider.name}/${model.id} aliases: ${model.aliases?.join(", ") || "-"} attachments: ${model.attachmentTypes?.join(", ") || "-"} output: ${model.outputType ?? "text/plain"}
300
- `);
301
- }
302
- return { exitCode: 0 };
303
- }
304
- const entry = service.resolve(args.model);
305
- const fragments = [];
306
- const decoder = new TextDecoder("utf-8", { fatal: true });
307
- const input = await operation.acquire(() => context.stdinInput ? { next: () => context.stdinInput.read(Math.min(65536, inputLimit - inputBytes + 1), signal) } : context.stdin[Symbol.asyncIterator](), async (iterator2) => {
308
- await iterator2.return?.();
309
- });
310
- while (true) {
311
- await step();
312
- const result = await interrupted(() => input.next(), signal);
313
- signal.throwIfAborted();
314
- if (result.done) break;
315
- const chunk = result.value;
316
- if (!(chunk instanceof Uint8Array)) throw new TypeError("Byte sources must yield Uint8Array chunks");
317
- admitInput(chunk.byteLength);
318
- fragments.push(decoder.decode(chunk, { stream: true }));
319
- }
320
- fragments.push(decoder.decode());
321
- const content = fragments.join("");
322
- const attachments = [];
323
- for (const attachment of args.attachments) {
324
- await step();
325
- if (attachment.path.includes("://")) throw new Error("URL attachments are not supported");
326
- const path = (0, internal_exports.pathOf)(context, attachment.path);
327
- const stat = await interrupted(() => context.fs.stat(path, { signal }), signal);
328
- checkInput(stat.size);
329
- const bytes = await interrupted(() => context.fs.readFile(path, {
330
- signal,
331
- ...inputLimit === Infinity ? {} : { maxBytes: inputLimit - inputBytes }
332
- }), signal);
333
- signal.throwIfAborted();
334
- if (!(bytes instanceof Uint8Array)) throw new TypeError("Attachment read must return Uint8Array");
335
- admitInput(bytes.byteLength);
336
- const mimeType = attachment.mimeType ?? sniffMimeType(path, bytes);
337
- if (!acceptsMimeType(entry.model.attachmentTypes ?? [], mimeType)) throw new Error(`Model ${entry.model.id} does not accept ${mimeType}`);
338
- attachments.push({ mimeType, bytes: new Uint8Array(bytes) });
339
- }
340
- const request = {
341
- model: entry.model.id,
342
- prompt: content && args.prompt ? `${content}
343
-
344
- ${args.prompt}` : content || args.prompt,
345
- ...args.system === void 0 ? {} : { system: args.system },
346
- attachments,
347
- options: args.options,
348
- signal
349
- };
350
- signal.throwIfAborted();
351
- iterator = service.complete(request)[Symbol.asyncIterator]();
352
- const text = (entry.model.outputType ?? "text/plain").toLowerCase().startsWith("text/");
353
- let pendingSurrogate = "";
354
- while (true) {
355
- await step();
356
- const result = await interrupted(() => iterator.next(), signal);
357
- signal.throwIfAborted();
358
- if (result.done) {
359
- ended = true;
360
- break;
361
- }
362
- if (text ? typeof result.value !== "string" : !(result.value instanceof Uint8Array)) throw new Error(`Provider ${entry.provider.name} returned a response chunk incompatible with ${entry.model.outputType ?? "text/plain"}`);
363
- if (typeof result.value === "string") {
364
- let chunk = pendingSurrogate + result.value;
365
- const last = chunk.charCodeAt(chunk.length - 1);
366
- pendingSurrogate = last >= 55296 && last <= 56319 ? chunk.slice(-1) : "";
367
- if (pendingSurrogate) chunk = chunk.slice(0, -1);
368
- if (chunk) await emitText(chunk);
369
- } else await write(result.value);
370
- }
371
- if (text) {
372
- if (pendingSurrogate) await emitText(pendingSurrogate);
373
- await write(Uint8Array.of(10));
374
- }
375
- return { exitCode: 0 };
376
- } catch (error) {
377
- context.signal.throwIfAborted();
378
- operation.signal.throwIfAborted();
379
- controller.abort(error);
380
- if (writing) throw error;
381
- await operation.close();
382
- await (0, escaping_exports.writeDiagnostic)(context.stderr, `${error instanceof Error ? error.message.slice(0, 4096) : "llm provider failed"}
383
- `, context.signal);
384
- return { exitCode: 1 };
385
- } finally {
386
- controller.abort(new Error("llm request closed"));
387
- await operation.close();
388
- }
389
- }
390
- function createLlmCommands(options) {
391
- if (!options.service && options.providers === void 0) throw new TypeError("Provide LLM providers or an authorized service");
392
- if (options.service && (options.providers || options.defaultModel !== void 0)) throw new TypeError("Configure providers and defaultModel on the injected LLM service");
393
- const service = options.service ?? createLlmService({ ...options, providers: options.providers ?? [] });
394
- return [{ name: "llm", description: "Query injected language and media models", execute: (context) => execute(context, service) }];
395
- }
396
- function llmCommands(options) {
397
- const definitions = createLlmCommands(options);
398
- const replace = options.replace ?? false;
399
- return { name: "llm-commands", setup(host) {
400
- if (!replace && host.commands.has("llm")) throw new Error("Command already registered: llm");
401
- for (const definition of definitions) host.commands.register(definition, { replace });
402
- } };
403
- }
404
-
405
- export {
406
- createLlmService,
407
- createLlmCommands,
408
- llmCommands
409
- };