@poe-platform/safe-bash 0.1.756 → 0.1.757

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 (113) hide show
  1. package/dist/image-ast/index.browser.js +4 -4
  2. package/dist/image-ast/index.js +4 -4
  3. package/dist/safe-bash/chunks/{chunk-LESPJ3OG.js → chunk-WNWIBBJZ.js} +15 -2
  4. package/dist/safe-bash/command-chunks/{chunk-S4J6MSLY.js → chunk-444OTXM7.js} +3 -3
  5. package/dist/safe-bash/command-chunks/{chunk-6AIOGLZO.js → chunk-CE6Z2ULX.js} +2 -2
  6. package/dist/safe-bash/command-chunks/{chunk-5VSGEE6J.js → chunk-F4IQCXZG.js} +5 -5
  7. package/dist/safe-bash/command-chunks/{chunk-F5MORDSU.js → chunk-FDNCPZQS.js} +32 -1
  8. package/dist/safe-bash/command-chunks/{chunk-SG3ZDZCX.js → chunk-FLMLM7Y4.js} +2 -2
  9. package/dist/safe-bash/command-chunks/{chunk-CT3FB722.js → chunk-J7UMKBRK.js} +1 -1
  10. package/dist/safe-bash/command-chunks/{chunk-QQOAK7JQ.js → chunk-KKJCKPTA.js} +1 -1
  11. package/dist/safe-bash/command-chunks/{chunk-7KS6PX4U.js → chunk-KSIGF4AG.js} +3 -3
  12. package/dist/safe-bash/command-chunks/{chunk-4HQ7WYSI.js → chunk-MED2BOOW.js} +30 -5
  13. package/dist/safe-bash/command-chunks/{chunk-JRNLDPLI.js → chunk-OZSWW23M.js} +1 -1
  14. package/dist/safe-bash/command-chunks/{chunk-DKQ5REXF.js → chunk-QDPRSPHQ.js} +1 -1
  15. package/dist/safe-bash/command-chunks/{chunk-WOPU2VWF.js → chunk-RID3B5RE.js} +1 -1
  16. package/dist/safe-bash/command-chunks/{chunk-DVZCHNB5.js → chunk-S4MLIYSN.js} +7 -7
  17. package/dist/safe-bash/command-chunks/{chunk-REYTQLLB.js → chunk-TT2DMDBY.js} +1 -1
  18. package/dist/safe-bash/command-chunks/{chunk-UGX6MXDD.js → chunk-UIIT4ULR.js} +3 -3
  19. package/dist/safe-bash/command-chunks/{chunk-A6NFLWZI.js → chunk-WKPOGTZY.js} +22 -6
  20. package/dist/safe-bash/command-chunks/{chunk-3DOHQQJR.js → chunk-Y64PA6IA.js} +8 -8
  21. package/dist/safe-bash/command-chunks/{chunk-6Z7OS3TZ.js → chunk-ZP5KDHB4.js} +7 -7
  22. package/dist/safe-bash/commands/pandoc/index.d.ts +1 -1
  23. package/dist/safe-bash/commands/pandoc/index.js +5 -3
  24. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  25. package/dist/safe-bash/commands/python/index.js +6 -0
  26. package/dist/safe-bash/commands/python/jspi.js +11 -2
  27. package/dist/safe-bash/core.browser.js +6 -4
  28. package/dist/safe-bash-command-csvkit/index.js +8 -8
  29. package/dist/safe-bash-command-soffice/index.js +16 -16
  30. package/dist/safe-bash-command-ssconvert/core.js +8 -8
  31. package/dist/safe-bash-command-ssconvert/formats/csv.js +9 -9
  32. package/dist/safe-bash-command-ssconvert/formats/ods.js +8 -8
  33. package/dist/safe-bash-command-ssconvert/formats/spreadsheetml.js +1 -1
  34. package/dist/safe-bash-command-ssconvert/formats/xls.js +9 -8
  35. package/dist/safe-bash-command-ssconvert/formats/xlsx.js +8 -8
  36. package/dist/safe-bash-command-ssconvert/index.js +107 -27
  37. package/dist/safe-bash-contracts/filesystem-descriptor.js +1 -1
  38. package/dist/safe-bash-contracts/filesystem-output.js +1 -1
  39. package/dist/safe-bash-mcp/index.js +4 -4
  40. package/dist/spreadsheet-engine/formulas/ast.d.ts +13 -0
  41. package/dist/spreadsheet-engine/formulas/conventions.js +1 -1
  42. package/dist/spreadsheet-engine/formulas/dependencies.js +2 -2
  43. package/dist/spreadsheet-engine/formulas/evaluator.js +2 -2
  44. package/dist/spreadsheet-engine/formulas/named-expressions.d.ts +2 -2
  45. package/dist/spreadsheet-engine/formulas/named-expressions.js +31 -5
  46. package/dist/spreadsheet-engine/formulas/parser.js +34 -0
  47. package/dist/spreadsheet-engine/formulas/rewriting.js +19 -1
  48. package/dist/spreadsheet-engine/formulas/serialization.js +6 -0
  49. package/dist/spreadsheet-format-xls/biff-write-formulas.js +2 -0
  50. package/dist/xlsx-ast/formula-semantics.js +2 -0
  51. package/package.json +2 -2
  52. package/dist/safe-bash/chunks/browser-ECQX6GMK.js +0 -6766
  53. package/dist/safe-bash/chunks/bz2-4OP3OWW3.js +0 -8
  54. package/dist/safe-bash/chunks/chunk-22XPAAOI.js +0 -173
  55. package/dist/safe-bash/chunks/chunk-44WUNUPV.js +0 -649
  56. package/dist/safe-bash/chunks/chunk-4E3SGG37.js +0 -876
  57. package/dist/safe-bash/chunks/chunk-4QTSSQKP.js +0 -898
  58. package/dist/safe-bash/chunks/chunk-5UVGPVXP.js +0 -410
  59. package/dist/safe-bash/chunks/chunk-64OE6Q6X.js +0 -3487
  60. package/dist/safe-bash/chunks/chunk-6IIFUPN2.js +0 -1526
  61. package/dist/safe-bash/chunks/chunk-BENDLTQD.js +0 -7065
  62. package/dist/safe-bash/chunks/chunk-BMO5LWEX.js +0 -534
  63. package/dist/safe-bash/chunks/chunk-BPMCPTNP.js +0 -1920
  64. package/dist/safe-bash/chunks/chunk-BRJTAWP5.js +0 -2955
  65. package/dist/safe-bash/chunks/chunk-C3GEIN7Q.js +0 -20054
  66. package/dist/safe-bash/chunks/chunk-CBVANNKK.js +0 -174814
  67. package/dist/safe-bash/chunks/chunk-CEWCRI6H.js +0 -2813
  68. package/dist/safe-bash/chunks/chunk-CGL53DQQ.js +0 -37
  69. package/dist/safe-bash/chunks/chunk-CTYJJD4O.js +0 -869
  70. package/dist/safe-bash/chunks/chunk-CWSS4MQA.js +0 -7
  71. package/dist/safe-bash/chunks/chunk-DLIGMTCP.js +0 -3266
  72. package/dist/safe-bash/chunks/chunk-EMAJ7WUW.js +0 -1031
  73. package/dist/safe-bash/chunks/chunk-FDKIZ2IJ.js +0 -1950
  74. package/dist/safe-bash/chunks/chunk-FZWJ2A7V.js +0 -3093
  75. package/dist/safe-bash/chunks/chunk-G2VCIF2J.js +0 -22
  76. package/dist/safe-bash/chunks/chunk-GVKBUQDX.js +0 -2649
  77. package/dist/safe-bash/chunks/chunk-IO2OGW3E.js +0 -28051
  78. package/dist/safe-bash/chunks/chunk-ISCZG7WA.js +0 -2648
  79. package/dist/safe-bash/chunks/chunk-JCN3FXLP.js +0 -38983
  80. package/dist/safe-bash/chunks/chunk-KJHDD4A2.js +0 -759
  81. package/dist/safe-bash/chunks/chunk-LB6HVRXS.js +0 -857
  82. package/dist/safe-bash/chunks/chunk-LLWAJOZH.js +0 -15
  83. package/dist/safe-bash/chunks/chunk-LMUKYZIJ.js +0 -708
  84. package/dist/safe-bash/chunks/chunk-M5SCNKIK.js +0 -2012
  85. package/dist/safe-bash/chunks/chunk-MJPFHANT.js +0 -3350
  86. package/dist/safe-bash/chunks/chunk-MZQW2DOL.js +0 -82
  87. package/dist/safe-bash/chunks/chunk-NB2V7EOY.js +0 -1348
  88. package/dist/safe-bash/chunks/chunk-NJVGOIYN.js +0 -17
  89. package/dist/safe-bash/chunks/chunk-OLNZHDIQ.js +0 -5141
  90. package/dist/safe-bash/chunks/chunk-OSUXMC43.js +0 -2317
  91. package/dist/safe-bash/chunks/chunk-OUUVROTM.js +0 -38
  92. package/dist/safe-bash/chunks/chunk-PA6GYKBQ.js +0 -151
  93. package/dist/safe-bash/chunks/chunk-PEFHZ226.js +0 -6957
  94. package/dist/safe-bash/chunks/chunk-QBB5P5KW.js +0 -4839
  95. package/dist/safe-bash/chunks/chunk-RSAWYAEH.js +0 -973
  96. package/dist/safe-bash/chunks/chunk-UWLYRWT4.js +0 -739
  97. package/dist/safe-bash/chunks/chunk-V463NBQH.js +0 -13
  98. package/dist/safe-bash/chunks/chunk-WPUALYUS.js +0 -843
  99. package/dist/safe-bash/chunks/chunk-XHKFSRGU.js +0 -5747
  100. package/dist/safe-bash/chunks/chunk-XHRCLZ3N.js +0 -13391
  101. package/dist/safe-bash/chunks/chunk-XPF5XHLY.js +0 -15
  102. package/dist/safe-bash/chunks/chunk-ZBFOWARG.js +0 -305
  103. package/dist/safe-bash/chunks/chunk-ZG7GWQ5P.js +0 -1859
  104. package/dist/safe-bash/chunks/model-store-EIY3ZQLZ.js +0 -10
  105. package/dist/safe-bash/chunks/pdf-renderer-CMF3CSVU.js +0 -22
  106. package/dist/safe-bash/chunks/pptx-ZL6L7KP2-O425BFIU.js +0 -30658
  107. package/dist/safe-bash/chunks/src-HHEPGR7U.js +0 -18969
  108. package/dist/safe-bash/chunks/src-MXIKQCIC.js +0 -187
  109. package/dist/safe-bash/chunks/usage-6TGVA2OM.js +0 -35
  110. package/dist/safe-bash/chunks/xz-EGQGQUEI.js +0 -8
  111. package/dist/safe-bash/chunks/xz-K2E2WLM6.js +0 -9
  112. package/dist/safe-bash/chunks/zstd-6JBLP5EF.js +0 -8
  113. package/dist/safe-bash/git_rust-C3QYOAZL.wasm +0 -0
@@ -1,410 +0,0 @@
1
- import {
2
- escaping_exports
3
- } from "./chunk-NJVGOIYN.js";
4
- import {
5
- contracts_exports
6
- } from "./chunk-MZQW2DOL.js";
7
- import {
8
- yield_exports
9
- } from "./chunk-XPF5XHLY.js";
10
- import {
11
- path_exports
12
- } from "./chunk-ISCZG7WA.js";
13
- import {
14
- acceptsMimeType,
15
- sniffMimeType
16
- } from "./chunk-ZBFOWARG.js";
17
- import {
18
- init_platform
19
- } from "./chunk-ZG7GWQ5P.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, path_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
- };
410
- //# sourceMappingURL=chunk-5UVGPVXP.js.map