@poe-platform/safe-bash 0.1.820 → 0.1.821

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.
@@ -172,6 +172,37 @@ var PythonMultibyteDecoder = class {
172
172
  }
173
173
  };
174
174
 
175
+ // packages/safe-bash-csv-engine/src/python-hz.ts
176
+ var PythonHzDecoder = class {
177
+ shifted = false;
178
+ pending;
179
+ gb = new PythonMultibyteDecoder(pythonMultibyteTables.gb2312);
180
+ decode(bytes = new Uint8Array(), options = {}) {
181
+ let pending = this.pending, output = "";
182
+ if (bytes.length) this.pending = void 0;
183
+ for (const byte of bytes) {
184
+ if (pending !== void 0) {
185
+ const lead = pending;
186
+ pending = void 0;
187
+ if (lead === 126) {
188
+ if (!this.shifted && byte === 123) this.shifted = true;
189
+ else if (this.shifted && byte === 125) this.shifted = false;
190
+ else if (!this.shifted && byte === 126) output += "~";
191
+ else if (!this.shifted && byte === 10) continue;
192
+ else throw new PythonTextDecodeError("Invalid HZ input");
193
+ } else if (this.shifted && lead >= 33 && lead <= 125 && byte >= 33 && byte <= 126) {
194
+ output += this.gb.decode(Uint8Array.of(lead + 128, byte + 128));
195
+ } else throw new PythonTextDecodeError("Invalid HZ input");
196
+ } else if (byte >= 128) throw new PythonTextDecodeError("Invalid HZ input");
197
+ else if (this.shifted || byte === 126) pending = byte;
198
+ else output += String.fromCharCode(byte);
199
+ }
200
+ if (!options.stream && pending !== void 0) throw new PythonTextDecodeError("Incomplete HZ input");
201
+ this.pending = pending;
202
+ return output;
203
+ }
204
+ };
205
+
175
206
  // packages/safe-bash-csv-engine/src/python-utf32.ts
176
207
  var PythonUtf32Decoder = class {
177
208
  little;
@@ -224,15 +255,15 @@ var PythonTextDecoder = class {
224
255
  constructor(encoding) {
225
256
  const name = normalizeEncoding(encoding);
226
257
  const canonical = Object.hasOwn(pythonCodecAliases, name) ? pythonCodecAliases[name] : void 0;
227
- if (canonical === void 0 || !["utf-8-sig", "utf-8", "utf-16", "utf-16-le", "utf-16-be", "utf-32", "utf-32-le", "utf-32-be"].includes(canonical) && !Object.hasOwn(fileCodepages, canonical) && !Object.hasOwn(pythonMultibyteTables, canonical)) throw new RangeError(`unknown encoding: ${encoding}`);
258
+ if (canonical === void 0 || !["hz", "utf-8-sig", "utf-8", "utf-16", "utf-16-le", "utf-16-be", "utf-32", "utf-32-le", "utf-32-be"].includes(canonical) && !Object.hasOwn(fileCodepages, canonical) && !Object.hasOwn(pythonMultibyteTables, canonical)) throw new RangeError(`unknown encoding: ${encoding}`);
228
259
  this.encoding = canonical;
229
260
  this.codepoints = fileCodepages[canonical];
230
261
  this.signatureComplete = canonical !== "utf-8-sig";
231
- this.decoder = pythonMultibyteTables[canonical] ? new PythonMultibyteDecoder(pythonMultibyteTables[canonical]) : canonical === "utf-16" || canonical === "utf-16-le" || canonical === "utf-16-be" ? new PythonUtf16Decoder(canonical) : canonical === "utf-32" || canonical === "utf-32-le" || canonical === "utf-32-be" ? new PythonUtf32Decoder(canonical) : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
262
+ this.decoder = canonical === "hz" ? new PythonHzDecoder() : pythonMultibyteTables[canonical] ? new PythonMultibyteDecoder(pythonMultibyteTables[canonical]) : canonical === "utf-16" || canonical === "utf-16-le" || canonical === "utf-16-be" ? new PythonUtf16Decoder(canonical) : canonical === "utf-32" || canonical === "utf-32-le" || canonical === "utf-32-be" ? new PythonUtf32Decoder(canonical) : new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
232
263
  }
233
264
  decode(bytes, options) {
234
265
  if (this.codepoints) return decodePythonSingleByte(bytes ?? new Uint8Array(), this.codepoints, this.encoding);
235
- if (this.decoder instanceof PythonUtf16Decoder || this.decoder instanceof PythonUtf32Decoder || this.decoder instanceof PythonMultibyteDecoder) return this.decoder.decode(bytes, options);
266
+ if (this.decoder instanceof PythonHzDecoder || this.decoder instanceof PythonUtf16Decoder || this.decoder instanceof PythonUtf32Decoder || this.decoder instanceof PythonMultibyteDecoder) return this.decoder.decode(bytes, options);
236
267
  try {
237
268
  let offset = 0;
238
269
  if (!this.signatureComplete) {
@@ -15,7 +15,7 @@ import {
15
15
  import {
16
16
  createLlmService,
17
17
  validateModelOptions
18
- } from "./chunk-YNFQ5AXM.js";
18
+ } from "./chunk-SENLC5KK.js";
19
19
  import {
20
20
  validateJsonData
21
21
  } from "./chunk-3PO534WJ.js";
@@ -1929,9 +1929,8 @@ function interpolate(text, params, validateOnly = false, admitText) {
1929
1929
  while (index + 1 < text.length && "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_".includes(text[index + 1])) name += text[++index];
1930
1930
  if (!name || "0123456789".includes(name[0]) || braced && text[index + 1] !== "}") throw new Error(`Invalid placeholder in template at position ${start}`);
1931
1931
  if (braced) index++;
1932
- if (!Object.hasOwn(params, name)) {
1933
- if (!missing.includes(name)) missing.push(name);
1934
- } else if (!validateOnly) append(String(params[name]));
1932
+ if (!Object.hasOwn(params, name)) missing.push(name);
1933
+ else if (!validateOnly) append(String(params[name]));
1935
1934
  }
1936
1935
  if (missing.length) throw new Error(`Missing variables: ${missing.join(", ")}`);
1937
1936
  return result;
@@ -2816,7 +2815,7 @@ var llmReferenceVersion = "0.27.1";
2816
2815
  var LlmPromptUsageError = class extends Error {
2817
2816
  };
2818
2817
  async function parse(length, text, step, chat = false, toolsDebugEnv) {
2819
- const parsed = { toolNames: [], functions: [], chainLimit: 5, prompt: "", queries: [], fragments: [], systemFragments: [], params: {}, options: /* @__PURE__ */ Object.create(null), attachments: [] };
2818
+ const parsed = { toolNames: [], functions: [], chainLimit: 5, prompt: "", queries: [], fragments: [], systemFragments: [], params: {}, optionNames: [], options: /* @__PURE__ */ Object.create(null), attachments: [] };
2820
2819
  const operands = [];
2821
2820
  let ended = false, chainLimit;
2822
2821
  for (let index = 0; index < length; index++) {
@@ -2880,8 +2879,10 @@ Error: No such option: ${flag}${await chatOptionSuggestion(flag, step)}`);
2880
2879
  else if (flag === "-p" || flag === "--param") Object.defineProperty(parsed.params, value, { value: text(++index), enumerable: true, configurable: true, writable: true });
2881
2880
  else if (flag === "-m" || flag === "--model") parsed.model = value;
2882
2881
  else if (flag === "-s" || flag === "--system") parsed.system = value;
2883
- else if (flag === "-o" || flag === "--option") parsed.options[value] = text(++index);
2884
- else if (flag === "--at" || flag === "--attachment-type") parsed.attachments.push({ path: value, mimeType: text(++index) });
2882
+ else if (flag === "-o" || flag === "--option") {
2883
+ if (!Object.hasOwn(parsed.options, value)) parsed.optionNames.push(value);
2884
+ parsed.options[value] = text(++index);
2885
+ } else if (flag === "--at" || flag === "--attachment-type") parsed.attachments.push({ path: value, mimeType: text(++index) });
2885
2886
  else parsed.attachments.push({ path: value });
2886
2887
  break;
2887
2888
  }
@@ -3223,7 +3224,7 @@ async function execute(context, service, limits, templateLoaderOptions, collecti
3223
3224
  if (stored) {
3224
3225
  if (!isChat && stored.schema_object) schema = stored.schema_object;
3225
3226
  try {
3226
- validateLlmTemplateParameters(stored, args.params);
3227
+ if (!isChat) validateLlmTemplateParameters(stored, args.params);
3227
3228
  } catch (error) {
3228
3229
  throw new Error(`Error: ${error instanceof Error ? error.message : "Invalid template"}`);
3229
3230
  }
@@ -3253,6 +3254,25 @@ async function execute(context, service, limits, templateLoaderOptions, collecti
3253
3254
  Try 'llm chat -h' for help.
3254
3255
 
3255
3256
  Error: Got unexpected extra argument (${args.prompt})`);
3257
+ let chatModelOptions;
3258
+ if (isChat) {
3259
+ const configured = await configuration.modelOptions(entry.model.id);
3260
+ const names = args.optionNames;
3261
+ chatModelOptions = names.length ? args.options : configured;
3262
+ if (names.length) {
3263
+ const rules = entry.model.options ?? {}, errors = [];
3264
+ const ordered = [...Object.keys(rules).filter((name) => Object.hasOwn(args.options, name)), ...names.filter((name) => !Object.hasOwn(rules, name))];
3265
+ for (const name of ordered) {
3266
+ await step();
3267
+ try {
3268
+ validateModelOptions(entry.model, { [name]: args.options[name] });
3269
+ } catch (error) {
3270
+ errors.push(error instanceof Error ? error.message : String(error));
3271
+ }
3272
+ }
3273
+ if (errors.length) throw new Error("Error: " + errors.join("\n"));
3274
+ }
3275
+ }
3256
3276
  const loadSelectedTools = async () => {
3257
3277
  let selectedTools2;
3258
3278
  try {
@@ -3444,7 +3464,6 @@ Error: Got unexpected extra argument (${args.prompt})`);
3444
3464
  let initialPromptFragments = [], initialSystemFragments = [];
3445
3465
  const initialAttachments = [], initialSourceAttachments = [];
3446
3466
  if (chat) {
3447
- validateModelOptions(entry.model, { ...await configuration.modelOptions(entry.model.id), ...args.options });
3448
3467
  initialPromptFragments = await prepareFragments(args.fragments, false);
3449
3468
  initialSystemFragments = await prepareFragments(args.systemFragments, true);
3450
3469
  initialAttachments.push(...pluginAttachments);
@@ -3576,7 +3595,7 @@ ${args.prompt}` : evaluated.prompt;
3576
3595
  }
3577
3596
  if (chat && (stored ? ["exit", "quit"].includes(stripPythonWhitespace(prompt)) : chatPrompt.exit)) return { exitCode: 0 };
3578
3597
  if (!entry) throw new Error("No model selected; use --model or configure defaultModel");
3579
- args.options = { ...await configuration.modelOptions(entry.model.id), ...chat ? {} : stored?.options, ...args.options };
3598
+ args.options = chat ? { ...chatModelOptions } : { ...await configuration.modelOptions(entry.model.id), ...stored?.options, ...args.options };
3580
3599
  args.attachments = [
3581
3600
  ...(chat ? [] : stored?.attachments ?? []).map((path) => ({ path })),
3582
3601
  ...args.attachments.filter((item) => item.mimeType === void 0),
@@ -52,7 +52,7 @@ function validateModelOptions(model, values) {
52
52
  const text = String(input).toLowerCase();
53
53
  if (["true", "1", "yes", "on", "y", "t"].includes(text)) value = true;
54
54
  else if (["false", "0", "no", "off", "n", "f"].includes(text)) value = false;
55
- else fail("Input should be a valid boolean");
55
+ else fail(typeof input === "string" ? "Input should be a valid boolean, unable to interpret input" : "Input should be a valid boolean");
56
56
  break;
57
57
  }
58
58
  case "object":
@@ -3,11 +3,11 @@ import {
3
3
  createLlmCommands,
4
4
  llmCommands,
5
5
  llmReferenceVersion
6
- } from "../safe-bash/command-chunks/chunk-FVHPDYV5.js";
6
+ } from "../safe-bash/command-chunks/chunk-RKAL5VFP.js";
7
7
  import "../safe-bash/command-chunks/chunk-MCUDSE4H.js";
8
8
  import "../safe-bash/command-chunks/chunk-WOT2YXBT.js";
9
9
  import "../safe-bash/command-chunks/chunk-BZLLQWRK.js";
10
- import "../safe-bash/command-chunks/chunk-YNFQ5AXM.js";
10
+ import "../safe-bash/command-chunks/chunk-SENLC5KK.js";
11
11
  import "../safe-bash/command-chunks/chunk-3PO534WJ.js";
12
12
  import "../safe-bash/command-chunks/chunk-B74LVFAN.js";
13
13
  import "../safe-bash/command-chunks/chunk-GDH7OVYK.js";
@@ -43,7 +43,7 @@ import {
43
43
  serializeLlmTokenUsage,
44
44
  streamLlmToolChain,
45
45
  validateLlmTemplateParameters
46
- } from "../safe-bash/command-chunks/chunk-FVHPDYV5.js";
46
+ } from "../safe-bash/command-chunks/chunk-RKAL5VFP.js";
47
47
  import "../safe-bash/command-chunks/chunk-MCUDSE4H.js";
48
48
  import {
49
49
  createLlmConfiguration
@@ -54,7 +54,7 @@ import {
54
54
  import {
55
55
  createLlmService,
56
56
  validateModelOptions
57
- } from "../safe-bash/command-chunks/chunk-YNFQ5AXM.js";
57
+ } from "../safe-bash/command-chunks/chunk-SENLC5KK.js";
58
58
  import "../safe-bash/command-chunks/chunk-3PO534WJ.js";
59
59
  import {
60
60
  getLlmAttachmentUrlId
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createLlmService
3
- } from "../safe-bash/command-chunks/chunk-YNFQ5AXM.js";
3
+ } from "../safe-bash/command-chunks/chunk-SENLC5KK.js";
4
4
  import "../safe-bash/command-chunks/chunk-3PO534WJ.js";
5
5
  import "../safe-bash/command-chunks/chunk-CKQ5SXOO.js";
6
6
  import "../safe-bash/command-chunks/chunk-B6NAEWHC.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PythonTextDecoder
3
- } from "../safe-bash/command-chunks/chunk-V2PJO6JL.js";
3
+ } from "../safe-bash/command-chunks/chunk-GRFJKJFN.js";
4
4
  import "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
5
  import "../safe-bash/command-chunks/chunk-OOYVZAWL.js";
6
6
  import "../safe-bash/command-chunks/chunk-ZERCTWUI.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  PythonTextDecoder
3
- } from "../safe-bash/command-chunks/chunk-V2PJO6JL.js";
3
+ } from "../safe-bash/command-chunks/chunk-GRFJKJFN.js";
4
4
  import "../safe-bash/command-chunks/chunk-OLXMWQJ5.js";
5
5
  import {
6
6
  PythonTextDecodeError
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@poe-platform/safe-bash",
3
- "version": "0.1.820",
3
+ "version": "0.1.821",
4
4
  "description": "Extensible virtual shell with pluggable filesystems and streaming commands",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1407,7 +1407,7 @@
1407
1407
  "access": "public"
1408
1408
  },
1409
1409
  "dependencies": {
1410
- "@poe-platform/safe-fs": "0.1.820",
1410
+ "@poe-platform/safe-fs": "0.1.821",
1411
1411
  "pdf-lib": "1.17.1",
1412
1412
  "@types/node": "^25.2.2",
1413
1413
  "@formatjs/intl-numberformat": "9.4.0",