@poe-platform/safe-bash 0.1.793 → 0.1.794

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 (34) hide show
  1. package/dist/safe-bash/chunks/{chunk-BENDQWMV.js → chunk-6IBTC4YL.js} +16 -2
  2. package/dist/safe-bash/chunks/{chunk-HEENNMEW.js → chunk-6P25QN5M.js} +16 -21
  3. package/dist/safe-bash/command-chunks/{chunk-JCORWQ2I.js → chunk-7FKUC34S.js} +1 -1
  4. package/dist/safe-bash/command-chunks/{chunk-ZJB7XJXD.js → chunk-XAFSZDY2.js} +1 -1
  5. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  6. package/dist/safe-bash/commands/python/llm-capability.js +11 -2
  7. package/dist/safe-bash/commands/python/llm-module.js +6 -0
  8. package/dist/safe-bash/contracts/escaping.d.ts +2 -0
  9. package/dist/safe-bash/contracts/escaping.js +2 -0
  10. package/dist/safe-bash/full-core.browser.js +2 -2
  11. package/dist/safe-bash/opt-in/optional/commands/shuf/args.js +270 -168
  12. package/dist/safe-bash/opt-in/optional/commands/shuf/filesystem-output.js +19 -1
  13. package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +121 -5
  14. package/dist/safe-bash/opt-in/optional/commands/shuf/random.d.ts +3 -0
  15. package/dist/safe-bash/opt-in/optional/commands/shuf/random.js +31 -23
  16. package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +39 -37
  17. package/dist/safe-bash/shell/runtime.d.ts +1 -1
  18. package/dist/safe-bash/shell/runtime.js +10 -16
  19. package/dist/safe-bash/shell-entry.browser.js +1 -1
  20. package/dist/safe-bash-command-shuf/args.d.ts +6 -4
  21. package/dist/safe-bash-command-shuf/args.js +270 -168
  22. package/dist/safe-bash-command-shuf/filesystem-output.js +19 -1
  23. package/dist/safe-bash-command-shuf/input.d.ts +19 -1
  24. package/dist/safe-bash-command-shuf/input.js +121 -5
  25. package/dist/safe-bash-command-shuf/random.d.ts +3 -0
  26. package/dist/safe-bash-command-shuf/random.js +31 -23
  27. package/dist/safe-bash-command-shuf/shuf.js +39 -37
  28. package/dist/safe-bash-command-sqlite3/btree.d.ts +1 -1
  29. package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -1
  30. package/dist/safe-bash-command-sqlite3/index.js +61 -63
  31. package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
  32. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +2 -2
  33. package/dist/safe-bash-io-engine/internal.js +1 -1
  34. package/package.json +3 -3
@@ -1021,7 +1021,7 @@ function createPythonShellCapability(context, options = {}) {
1021
1021
 
1022
1022
  // packages/safe-bash/src/commands/python/llm-capability.ts
1023
1023
  init_platform();
1024
- import { getLlmModelAliases, createLlmConfiguration, createLlmTemplateStore, evaluateLlmTemplate, findExtractedRange, llmTemplateUsesInput, validateLlmTemplateParameters } from "../../safe-bash-command-llm/index.js";
1024
+ import { selectLlmModelByQuery, getLlmModelAliases, createLlmConfiguration, createLlmTemplateStore, evaluateLlmTemplate, findExtractedRange, llmTemplateUsesInput, validateLlmTemplateParameters } from "../../safe-bash-command-llm/index.js";
1025
1025
 
1026
1026
  // packages/safe-bash/src/commands/llm/mime.ts
1027
1027
  init_platform();
@@ -1126,7 +1126,7 @@ function createPythonLlmCapability(context, service, options = {}) {
1126
1126
  const bufferedLimit = options.maxBufferedResponseBytes ?? Infinity;
1127
1127
  const eventLimit = options.maxBufferedEvents ?? bufferedLimit;
1128
1128
  const metadataLimit = options.maxMetadataBytes ?? bufferedLimit;
1129
- const maxRemoteBytes = options.maxRemoteTemplateBytes ?? context.inputBudget?.maxBytes ?? 1048576;
1129
+ const maxRemoteBytes = options.maxRemoteTemplateBytes ?? (context.inputBudget?.maxBytes === Infinity ? void 0 : context.inputBudget?.maxBytes) ?? 1048576;
1130
1130
  if (!Number.isSafeInteger(maxRemoteBytes) || maxRemoteBytes < 1) throw new RangeError("Invalid Python LLM remote template limit");
1131
1131
  const templateLoaderOptions = { maxRemoteBytes, ...options.templateLoaders ? { loaders: options.templateLoaders } : {} };
1132
1132
  for (const limit of [bufferedLimit, eventLimit, metadataLimit]) {
@@ -1329,6 +1329,14 @@ ${input}` : evaluated.prompt : input,
1329
1329
  signal.throwIfAborted();
1330
1330
  const operation = record(value);
1331
1331
  const payload = record(operation.payload ?? {});
1332
+ if (operation.operation === "select_model") {
1333
+ const queries = payload.queries;
1334
+ if (!Array.isArray(queries) || !queries.length || queries.some((query) => typeof query !== "string")) throw new TypeError("Model queries must be a nonempty array of strings");
1335
+ const configuration = createLlmConfiguration(configurationContext(context, payload, signal));
1336
+ const selected = await selectLlmModelByQuery(service.models, queries, await configuration.aliases(), signal);
1337
+ jsonBytes(selected.model.id, bufferedLimit);
1338
+ return selected.model.id;
1339
+ }
1332
1340
  if (operation.operation === "models") {
1333
1341
  const configuration = createLlmConfiguration(configurationContext(context, payload, signal));
1334
1342
  const aliases = await configuration.aliases();
@@ -1927,6 +1935,12 @@ class Client:
1927
1935
  aliases=copy.deepcopy(value.get("aliases", {})),
1928
1936
  model_options=copy.deepcopy(value.get("model_options", {})))
1929
1937
 
1938
+ async def select_model(self, *queries: str) -> str:
1939
+ if not queries or not all(isinstance(query, str) for query in queries):
1940
+ raise TypeError("Model queries must be one or more strings")
1941
+ payload = {**_configuration_context(), "queries": list(queries)}
1942
+ return await self._run(lambda: self._bridge.call("select_model", payload), self._timeout)
1943
+
1930
1944
  async def models(self):
1931
1945
  values = await self._run(lambda: self._bridge.call("models", _configuration_context()), self._timeout)
1932
1946
  return tuple(Model(id=value["id"], aliases=tuple(value.get("aliases", ())),
@@ -35321,7 +35321,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35321
35321
  }
35322
35322
  this.requireParameter(value === void 0 ? void 0 : shellValueText(value), part.name, state, io, part.line);
35323
35323
  if (part.length) return this.valueLength(value ?? "", state, io);
35324
- if (part.substring) return this.substring(part, value === void 0 ? void 0 : shellValueText(value), state, io);
35324
+ if (part.substring) return this.substring(part, value, state, io);
35325
35325
  if (part.transform) return part.transform === "a" || part.transform === "A" || part.transform === "K" || part.transform === "k" ? this.variableMetaTransform(part, state, io) : value === void 0 ? "" : this.transformValue(value, part.transform, state, io);
35326
35326
  if (part.operator) return this.parameterPattern(part, value ?? "", state, io, hereString);
35327
35327
  return value ?? "";
@@ -35737,7 +35737,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35737
35737
  }
35738
35738
  if (part.substring) {
35739
35739
  this.requireParameter(value, part.name, state, io, part.line);
35740
- return this.substring(part, value, state, io);
35740
+ return this.substring(part, retained, state, io);
35741
35741
  }
35742
35742
  if (part.operator) {
35743
35743
  if (["#", "##", "%", "%%", "^", "^^", ",", ",,"].includes(part.operator) || part.operator.startsWith("/")) {
@@ -35824,14 +35824,14 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35824
35824
  let retained;
35825
35825
  for (const entry of word.parts) {
35826
35826
  this.signal.throwIfAborted();
35827
- const text2 = entry.kind === "text" ? entry.value : await this.part(entry, state, operandIO);
35828
- bytes2 += shellValueByteLength(text2);
35827
+ const text3 = entry.kind === "text" ? entry.value : await this.part(entry, state, operandIO);
35828
+ bytes2 += shellValueByteLength(text3);
35829
35829
  if (bytes2 > limit) this.budget.fail("maxExpansionBytes");
35830
- owner?.reserve({ metadata: 32, payload: bytes2, work: text2.length + 4 });
35831
- const pending = stringCheckpoint(work, text2.length + 1);
35830
+ owner?.reserve({ metadata: 32, payload: bytes2, work: text3.length + 4 });
35831
+ const pending = stringCheckpoint(work, text3.length + 1);
35832
35832
  if (pending) await pending;
35833
- const next = scratch.reserve((source.length + text2.length) * 2, 0);
35834
- source += text2;
35833
+ const next = scratch.reserve((source.length + text3.length) * 2, 0);
35834
+ source += text3;
35835
35835
  retained?.release();
35836
35836
  retained = next;
35837
35837
  }
@@ -35848,10 +35848,10 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35848
35848
  const offsetExpression = await arithmetic(expression.offset);
35849
35849
  let bytes;
35850
35850
  if (byteLocale(state.variables)) {
35851
- scratch.reserve(shellValueByteLength(value), 0);
35852
- bytes = fastSharedTextEncoder.encode(value);
35851
+ bytes = shellValueBytes(value, scratch);
35853
35852
  }
35854
- const size = BigInt(bytes?.byteLength ?? (await scanString(value, work)).count);
35853
+ const text2 = shellValueText(value);
35854
+ const size = BigInt(bytes?.byteLength ?? (await scanString(text2, work)).count);
35855
35855
  const offset = offsetExpression.value < 0n ? size + offsetExpression.value : offsetExpression.value;
35856
35856
  if (offset < 0n || offset > size) return "";
35857
35857
  let end = size;
@@ -35863,17 +35863,12 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35863
35863
  }
35864
35864
  this.signal.throwIfAborted();
35865
35865
  if (!bytes) {
35866
- const start = (await scanString(value, work, 0, value.length, Number(offset))).end;
35867
- const finish = (await scanString(value, work, start, value.length, Number(end - offset))).end;
35866
+ const start = (await scanString(text2, work, 0, text2.length, Number(offset))).end;
35867
+ const finish = (await scanString(text2, work, start, text2.length, Number(end - offset))).end;
35868
35868
  if (finish > start) scratch.reserve((finish - start) * 2, 0);
35869
- return value.slice(start, finish);
35870
- }
35871
- scratch.reserve(Number(end - offset) * 2, 0);
35872
- try {
35873
- return new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes.subarray(Number(offset), Number(end)));
35874
- } catch {
35875
- throw new ExpansionFailure("substring expansion splits a UTF-8 character in a byte locale", line);
35869
+ return text2.slice(start, finish);
35876
35870
  }
35871
+ return shellValueFromBytes(bytes.subarray(Number(offset), Number(end)), io[valueScope]);
35877
35872
  } finally {
35878
35873
  scratch.close();
35879
35874
  }
@@ -35961,7 +35956,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35961
35956
  const replacementIO = part.replacement ? this.parameterOperandIO(part.replacement, state, io) : io;
35962
35957
  for (const [index, entry] of (part.replacement?.parts ?? []).entries()) {
35963
35958
  let value2 = entry.kind === "text" ? entry.value : await this.part(entry, state, replacementIO, hereString);
35964
- if (index === 0 && entry.kind === "text" && !part.quoted && !entry.quoted && /^~(?:\/|$)/u.test(value2)) {
35959
+ if (index === 0 && entry.kind === "text" && !entry.quoted && /^~(?:\/|$)/u.test(value2)) {
35965
35960
  const home = state.variables.HOME ?? "~";
35966
35961
  scratch.reserve((home.length + value2.length - 1) * 2, 0);
35967
35962
  value2 = home + value2.slice(1);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  pathOf
3
- } from "./chunk-ZJB7XJXD.js";
3
+ } from "./chunk-XAFSZDY2.js";
4
4
  import {
5
5
  inputRequirements
6
6
  } from "./chunk-773DWG4H.js";
@@ -59,7 +59,7 @@ async function handleDefineError(context, error, failureCode, usageFailureCode)
59
59
  return { exitCode: error instanceof UsageError ? usageFailureCode : failureCode };
60
60
  }
61
61
  var encoder = new TextEncoder();
62
- var decoder = new TextDecoder();
62
+ var decoder = new TextDecoder("utf-8", { ignoreBOM: true });
63
63
  var bufferLimit = Infinity;
64
64
  var specificationsCache = /* @__PURE__ */ new Map();
65
65
  function options(args, short, long = {}, stopAtOperand = false, onOperand, onValue, onOption) {
@@ -16,7 +16,7 @@ import {
16
16
  pythonCommands,
17
17
  pythonDocumentPackages,
18
18
  pythonHostFailureCode
19
- } from "../../chunks/chunk-BENDQWMV.js";
19
+ } from "../../chunks/chunk-6IBTC4YL.js";
20
20
  import "../../chunks/chunk-KCVSVD65.js";
21
21
  import "../../chunks/chunk-KMH2DF3I.js";
22
22
  import "../../chunks/chunk-IUTD5FH5.js";
@@ -1,4 +1,4 @@
1
- import { getLlmModelAliases, createLlmConfiguration, createLlmTemplateStore, evaluateLlmTemplate, findExtractedRange, llmTemplateUsesInput, validateLlmTemplateParameters } from "../../../safe-bash-command-llm/index.js";
1
+ import { selectLlmModelByQuery, getLlmModelAliases, createLlmConfiguration, createLlmTemplateStore, evaluateLlmTemplate, findExtractedRange, llmTemplateUsesInput, validateLlmTemplateParameters } from "../../../safe-bash-command-llm/index.js";
2
2
  import { sniffMimeType } from '../llm/mime.js';
3
3
  import { pathOf } from '../internal.js';
4
4
  function record(value) {
@@ -125,7 +125,7 @@ export function createPythonLlmCapability(context, service, options = {}) {
125
125
  const bufferedLimit = options.maxBufferedResponseBytes ?? Infinity;
126
126
  const eventLimit = options.maxBufferedEvents ?? bufferedLimit;
127
127
  const metadataLimit = options.maxMetadataBytes ?? bufferedLimit;
128
- const maxRemoteBytes = options.maxRemoteTemplateBytes ?? context.inputBudget?.maxBytes ?? 1_048_576;
128
+ const maxRemoteBytes = options.maxRemoteTemplateBytes ?? (context.inputBudget?.maxBytes === Infinity ? undefined : context.inputBudget?.maxBytes) ?? 1_048_576;
129
129
  if (!Number.isSafeInteger(maxRemoteBytes) || maxRemoteBytes < 1)
130
130
  throw new RangeError('Invalid Python LLM remote template limit');
131
131
  const templateLoaderOptions = { maxRemoteBytes, ...(options.templateLoaders ? { loaders: options.templateLoaders } : {}) };
@@ -343,6 +343,15 @@ export function createPythonLlmCapability(context, service, options = {}) {
343
343
  signal.throwIfAborted();
344
344
  const operation = record(value);
345
345
  const payload = record(operation.payload ?? {});
346
+ if (operation.operation === 'select_model') {
347
+ const queries = payload.queries;
348
+ if (!Array.isArray(queries) || !queries.length || queries.some(query => typeof query !== 'string'))
349
+ throw new TypeError('Model queries must be a nonempty array of strings');
350
+ const configuration = createLlmConfiguration(configurationContext(context, payload, signal));
351
+ const selected = await selectLlmModelByQuery(service.models, queries, await configuration.aliases(), signal);
352
+ jsonBytes(selected.model.id, bufferedLimit);
353
+ return selected.model.id;
354
+ }
346
355
  if (operation.operation === 'models') {
347
356
  const configuration = createLlmConfiguration(configurationContext(context, payload, signal));
348
357
  const aliases = await configuration.aliases();
@@ -386,6 +386,12 @@ class Client:
386
386
  aliases=copy.deepcopy(value.get("aliases", {})),
387
387
  model_options=copy.deepcopy(value.get("model_options", {})))
388
388
 
389
+ async def select_model(self, *queries: str) -> str:
390
+ if not queries or not all(isinstance(query, str) for query in queries):
391
+ raise TypeError("Model queries must be one or more strings")
392
+ payload = {**_configuration_context(), "queries": list(queries)}
393
+ return await self._run(lambda: self._bridge.call("select_model", payload), self._timeout)
394
+
389
395
  async def models(self):
390
396
  values = await self._run(lambda: self._bridge.call("models", _configuration_context()), self._timeout)
391
397
  return tuple(Model(id=value["id"], aliases=tuple(value.get("aliases", ())),
@@ -0,0 +1,2 @@
1
+ export * from "../../safe-bash-contracts/escaping.js";
2
+ //# sourceMappingURL=escaping.d.ts.map
@@ -0,0 +1,2 @@
1
+ export * from "../../safe-bash-contracts/escaping.js";
2
+ //# sourceMappingURL=escaping.js.map
@@ -57,7 +57,7 @@ import {
57
57
  parseShell,
58
58
  searchCommands,
59
59
  unrtfCommands
60
- } from "./chunks/chunk-HEENNMEW.js";
60
+ } from "./chunks/chunk-6P25QN5M.js";
61
61
  import {
62
62
  createYqCommand,
63
63
  createYqCommands,
@@ -347,7 +347,7 @@ import {
347
347
  pythonCommands,
348
348
  pythonDocumentPackages,
349
349
  pythonHostFailureCode
350
- } from "./chunks/chunk-BENDQWMV.js";
350
+ } from "./chunks/chunk-6IBTC4YL.js";
351
351
  import "./chunks/chunk-KCVSVD65.js";
352
352
  import "./chunks/chunk-KMH2DF3I.js";
353
353
  import "./chunks/chunk-IUTD5FH5.js";