@poe-platform/safe-bash 0.1.792 → 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 (43) hide show
  1. package/dist/safe-bash/chunks/{chunk-BENDQWMV.js → chunk-6IBTC4YL.js} +16 -2
  2. package/dist/safe-bash/chunks/{chunk-6AKPBNRF.js → chunk-6P25QN5M.js} +20 -25
  3. package/dist/safe-bash/chunks/{chunk-DVSLGXQU.js → chunk-C2NYCU7O.js} +2 -1
  4. package/dist/safe-bash/command-chunks/{chunk-JCORWQ2I.js → chunk-7FKUC34S.js} +1 -1
  5. package/dist/safe-bash/command-chunks/{chunk-ZJB7XJXD.js → chunk-XAFSZDY2.js} +1 -1
  6. package/dist/safe-bash/command-chunks/{chunk-UVHLUL62.js → chunk-YFSDDFGV.js} +42 -12
  7. package/dist/safe-bash/commands/llm/index.browser.js +3 -1
  8. package/dist/safe-bash/commands/python/index.browser.js +1 -1
  9. package/dist/safe-bash/commands/python/llm-capability.js +11 -2
  10. package/dist/safe-bash/commands/python/llm-module.js +6 -0
  11. package/dist/safe-bash/contracts/escaping.d.ts +2 -0
  12. package/dist/safe-bash/contracts/escaping.js +2 -0
  13. package/dist/safe-bash/core.browser.js +1 -1
  14. package/dist/safe-bash/full-core.browser.js +5 -3
  15. package/dist/safe-bash/opt-in/optional/commands/shuf/args.js +270 -168
  16. package/dist/safe-bash/opt-in/optional/commands/shuf/filesystem-output.js +19 -1
  17. package/dist/safe-bash/opt-in/optional/commands/shuf/input.js +121 -5
  18. package/dist/safe-bash/opt-in/optional/commands/shuf/random.d.ts +3 -0
  19. package/dist/safe-bash/opt-in/optional/commands/shuf/random.js +31 -23
  20. package/dist/safe-bash/opt-in/optional/commands/shuf/shuf.js +39 -37
  21. package/dist/safe-bash/shell/runtime.d.ts +1 -1
  22. package/dist/safe-bash/shell/runtime.js +14 -20
  23. package/dist/safe-bash/shell-entry.browser.js +1 -1
  24. package/dist/safe-bash-command-llm/command.js +1 -1
  25. package/dist/safe-bash-command-llm/index.d.ts +1 -1
  26. package/dist/safe-bash-command-llm/index.js +3 -1
  27. package/dist/safe-bash-command-llm/model-selection.d.ts +5 -0
  28. package/dist/safe-bash-command-shuf/args.d.ts +6 -4
  29. package/dist/safe-bash-command-shuf/args.js +270 -168
  30. package/dist/safe-bash-command-shuf/filesystem-output.js +19 -1
  31. package/dist/safe-bash-command-shuf/input.d.ts +19 -1
  32. package/dist/safe-bash-command-shuf/input.js +121 -5
  33. package/dist/safe-bash-command-shuf/random.d.ts +3 -0
  34. package/dist/safe-bash-command-shuf/random.js +31 -23
  35. package/dist/safe-bash-command-shuf/shuf.js +39 -37
  36. package/dist/safe-bash-command-sqlite3/btree.d.ts +1 -1
  37. package/dist/safe-bash-command-sqlite3/engine.d.ts +1 -1
  38. package/dist/safe-bash-command-sqlite3/index.js +61 -63
  39. package/dist/safe-bash-io-engine/commands/search/requirements.js +2 -2
  40. package/dist/safe-bash-io-engine/commands/text-programs/shared.js +2 -2
  41. package/dist/safe-bash-io-engine/internal.js +1 -1
  42. package/package.json +3 -3
  43. package/dist/safe-bash-command-llm/models-list.d.ts +0 -10
@@ -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", ())),
@@ -13614,7 +13614,7 @@ async function umaskBuiltin(context, state) {
13614
13614
 
13615
13615
  // packages/safe-bash/src/shell/runtime.ts
13616
13616
  import { abortManagedController as abortManagedController2, addAbortSignalWaiter as addAbortSignalWaiter2, combineManagedSignals as combineManagedSignals2, createManagedControlController as createManagedControlController2, getRuntimeBackingFileSystem as getRuntimeBackingFileSystem2, interruptible as interruptible2, isSyncResolved as isSyncResolved5, registerRuntimeBackingFileSystem, removeAbortSignalWaiter as removeAbortSignalWaiter2, toNativeAbortSignal } from "../../safe-bash-contracts/runtime-control.js";
13617
- var sharedCaptureDecoder = new TextDecoder();
13617
+ var sharedCaptureDecoder = new TextDecoder("utf-8", { ignoreBOM: true });
13618
13618
  var cachedCaptureAsciiBytes = new Uint8Array(4096);
13619
13619
  var cachedCaptureAsciiLen = 0;
13620
13620
  var cachedCaptureAsciiStr = "";
@@ -22613,14 +22613,14 @@ var Runtime = class _Runtime {
22613
22613
  posMut = m ? { varName: m[1], op: m[2], posIdx: Number(m[3] ?? m[4]) - 1 } : null;
22614
22614
  expr._cachedPosMut = posMut;
22615
22615
  }
22616
- if (posMut !== null && posMut.varName !== "OPTIND" && posMut.varName !== "PIPESTATUS" && !store?.get(posMut.varName)) {
22616
+ if (!hasActiveVariableAttributes(rawState) && posMut !== null && posMut.varName !== "OPTIND" && posMut.varName !== "PIPESTATUS" && !store?.get(posMut.varName)) {
22617
22617
  const posVal = (this._fastSubPositional ?? rawState.positional)[posMut.posIdx];
22618
- if (posVal !== void 0 && posVal.length > 0 && posVal.length <= 12) {
22618
+ if (posVal !== void 0 && /^-?(?:0|[1-9][0-9]{0,12})$/.test(posVal)) {
22619
22619
  const rhsNum = Number(posVal);
22620
22620
  if (Number.isSafeInteger(rhsNum)) {
22621
22621
  const curVal = this._syncArithRawWriteOnly && this._syncArithTouched?.has(posMut.varName) ? rawState.variables[posMut.varName] ?? "0" : monitor.values.get(posMut.varName, rawState.variables[posMut.varName] ?? "0") ?? rawState.variables[posMut.varName] ?? "0";
22622
22622
  const curNum = curVal === "" ? 0 : Number(curVal);
22623
- if (typeof curVal === "string" && Number.isSafeInteger(curNum)) {
22623
+ if (typeof curVal === "string" && (curVal === "" || /^-?(?:0|[1-9][0-9]{0,12})$/.test(curVal)) && Number.isSafeInteger(curNum)) {
22624
22624
  const nextNum = posMut.op === "=" ? rhsNum : posMut.op === "+=" ? curNum + rhsNum : curNum - rhsNum;
22625
22625
  if (Number.isSafeInteger(nextNum)) {
22626
22626
  this.budget.parsing.admit(4);
@@ -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);
@@ -4,7 +4,7 @@ import {
4
4
 
5
5
  // packages/safe-bash/src/commands/llm/index.ts
6
6
  init_platform();
7
- import { createElevenLabsProvider, createLlmCommand, createLlmCommands, createLlmConfiguration, createLlmService, createLlmTemplateStore, createOpenAiProvider, evaluateLlmTemplate, findExtractedRange, getLlmModelAliases, llmCommands, llmTemplateUsesInput, parseLlmSchemaDsl, resolveLlmSchemaInput, templateYaml, validateLlmTemplateParameters, validateModelOptions } from "../../safe-bash-command-llm/index.js";
7
+ import { createElevenLabsProvider, createLlmCommand, createLlmCommands, createLlmConfiguration, createLlmService, createLlmTemplateStore, createOpenAiProvider, evaluateLlmTemplate, findExtractedRange, getLlmModelAliases, llmCommands, llmTemplateUsesInput, parseLlmSchemaDsl, resolveLlmSchemaInput, selectLlmModelByQuery, templateYaml, validateLlmTemplateParameters, validateModelOptions } from "../../safe-bash-command-llm/index.js";
8
8
 
9
9
  export {
10
10
  createElevenLabsProvider,
@@ -21,6 +21,7 @@ export {
21
21
  llmTemplateUsesInput,
22
22
  parseLlmSchemaDsl,
23
23
  resolveLlmSchemaInput,
24
+ selectLlmModelByQuery,
24
25
  templateYaml,
25
26
  validateLlmTemplateParameters,
26
27
  validateModelOptions
@@ -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) {
@@ -13,7 +13,7 @@ import {
13
13
  // packages/safe-bash-command-llm/src/command.ts
14
14
  init_buffer();
15
15
  import { createOutputOperation, getCommandArguments, FsError as FsError7 } from "../../safe-bash-contracts/index.js";
16
- import { inheritYieldCheckpoint, yieldTurn as yieldTurn2 } from "../../safe-bash-contracts/yield.js";
16
+ import { inheritYieldCheckpoint, yieldTurn as yieldTurn3 } from "../../safe-bash-contracts/yield.js";
17
17
  import { writeDiagnostic } from "../../safe-bash-contracts/escaping.js";
18
18
  import { pathOf as pathOf4 } from "../../safe-bash-contracts/path.js";
19
19
 
@@ -1172,6 +1172,34 @@ async function listOptions(configuration, output, diagnostic) {
1172
1172
 
1173
1173
  // packages/safe-bash-command-llm/src/models-list.ts
1174
1174
  init_buffer();
1175
+
1176
+ // packages/safe-bash-command-llm/src/model-selection.ts
1177
+ init_buffer();
1178
+ import { yieldTurn as yieldTurn2 } from "../../safe-bash-contracts/yield.js";
1179
+ function getLlmModelAliases({ provider, model }, configured) {
1180
+ const aliases = new Set(model.aliases);
1181
+ for (const [alias, target] of Object.entries(configured)) {
1182
+ if (target === model.id || target === `${provider.name}/${model.id}` || model.aliases?.includes(target)) aliases.add(alias);
1183
+ }
1184
+ return [...aliases];
1185
+ }
1186
+ async function selectLlmModelByQuery(models, queries, configuredAliases = {}, signal) {
1187
+ if (!queries.length) throw new TypeError("Model selection requires a query");
1188
+ let selected;
1189
+ const normalized = queries.map((query) => query.toLowerCase());
1190
+ for (let index = 0; index < models.length; index++) {
1191
+ signal?.throwIfAborted();
1192
+ if (signal && index && index % 256 === 0) await yieldTurn2(signal);
1193
+ const entry = models[index];
1194
+ const terms = [`${entry.provider.name}: ${entry.model.id}`, ...getLlmModelAliases(entry, configuredAliases)].map((value) => value.toLowerCase());
1195
+ if (normalized.every((query) => terms.some((term) => term.includes(query))) && (!selected || [...entry.model.id].length < [...selected.model.id].length)) selected = entry;
1196
+ }
1197
+ signal?.throwIfAborted();
1198
+ if (!selected) throw new Error(`No model found matching queries ${queries.join(", ")}`);
1199
+ return selected;
1200
+ }
1201
+
1202
+ // packages/safe-bash-command-llm/src/models-list.ts
1175
1203
  var modelsGroupHelp = "Usage: llm models [OPTIONS] COMMAND [ARGS]...\n\n Manage available models\n\nOptions:\n -h, --help Show this message and exit.\n\nCommands:\n list* List available models\n default Show or set the default model\n options Manage default options for models\n";
1176
1204
  var LlmModelsUsageError = class extends Error {
1177
1205
  constructor(message, usage = true) {
@@ -1192,13 +1220,6 @@ function wrapDescription(description) {
1192
1220
  if (line) lines.push(line);
1193
1221
  return lines.join("\n ");
1194
1222
  }
1195
- function getLlmModelAliases({ provider, model }, configured) {
1196
- const aliases = new Set(model.aliases);
1197
- for (const [alias, target] of Object.entries(configured)) {
1198
- if (target === model.id || target === `${provider.name}/${model.id}` || model.aliases?.includes(target)) aliases.add(alias);
1199
- }
1200
- return [...aliases];
1201
- }
1202
1223
  async function listLlmModels(context, service, tokens, emit, step) {
1203
1224
  const explicit = tokens[0] === "list";
1204
1225
  const terminator = tokens.indexOf("--");
@@ -1306,7 +1327,7 @@ async function listLlmModels(context, service, tokens, emit, step) {
1306
1327
 
1307
1328
  // packages/safe-bash-command-llm/src/command.ts
1308
1329
  async function parse(length, text, step) {
1309
- const parsed = { prompt: "", params: {}, options: /* @__PURE__ */ Object.create(null), attachments: [] };
1330
+ const parsed = { prompt: "", queries: [], params: {}, options: /* @__PURE__ */ Object.create(null), attachments: [] };
1310
1331
  const operands = [];
1311
1332
  let ended = false;
1312
1333
  for (let index = 0; index < length; index++) {
@@ -1338,9 +1359,10 @@ async function parse(length, text, step) {
1338
1359
  if (++index >= length) throw new Error(`Option ${flag} requires an argument`);
1339
1360
  return text(index);
1340
1361
  };
1341
- if (!["-m", "--model", "-s", "--system", "-o", "--option", "-a", "--attachment", "--at", "--attachment-type", "-t", "--template", "--save", "-p", "--param", "--key", "--schema", "--schema-multi"].includes(flag)) throw new Error(`Unknown option: ${flag}`);
1362
+ if (!["-q", "--query", "-m", "--model", "-s", "--system", "-o", "--option", "-a", "--attachment", "--at", "--attachment-type", "-t", "--template", "--save", "-p", "--param", "--key", "--schema", "--schema-multi"].includes(flag)) throw new Error(`Unknown option: ${flag}`);
1342
1363
  const value = attached ?? take();
1343
- if (flag === "-t" || flag === "--template") parsed.template = value;
1364
+ if (flag === "-q" || flag === "--query") parsed.queries.push(value);
1365
+ else if (flag === "-t" || flag === "--template") parsed.template = value;
1344
1366
  else if (flag === "--schema") parsed.schema = value;
1345
1367
  else if (flag === "--schema-multi") parsed.schemaMulti = value;
1346
1368
  else if (flag === "--key") parsed.key = value;
@@ -1399,7 +1421,7 @@ async function execute(context, service, limits, templateLoaderOptions) {
1399
1421
  signal.throwIfAborted();
1400
1422
  if (closed) throw new Error("LLM invocation is closed");
1401
1423
  work++;
1402
- if (work % 256 === 0) await yieldTurn2(signal);
1424
+ if (work % 256 === 0) await yieldTurn3(signal);
1403
1425
  };
1404
1426
  let outputSpool;
1405
1427
  let outputBytes = 0;
@@ -1508,6 +1530,13 @@ async function execute(context, service, limits, templateLoaderOptions) {
1508
1530
  const promptOffset = argumentsValue.args[0] === "prompt" ? 1 : 0;
1509
1531
  const args = await parse(argumentsValue.args.length - promptOffset, (index) => argumentText(index + promptOffset), step);
1510
1532
  const configuration = createLlmConfiguration(context);
1533
+ if (args.model === void 0 && args.queries.length) {
1534
+ try {
1535
+ args.model = (await selectLlmModelByQuery(service.models, args.queries, await configuration.aliases(), signal)).model.id;
1536
+ } catch (error) {
1537
+ throw new Error(`Error: ${error instanceof Error ? error.message : "Model selection failed"}`);
1538
+ }
1539
+ }
1511
1540
  const templateStore = createLlmTemplateStore(context, templateLoaderOptions);
1512
1541
  const schemaInput = args.schemaMulti ?? args.schema;
1513
1542
  let schema = schemaInput ? await resolveLlmSchemaInput({ ...context, signal }, schemaInput, {
@@ -1795,6 +1824,7 @@ export {
1795
1824
  parseLlmSchemaDsl,
1796
1825
  resolveLlmSchemaInput,
1797
1826
  getLlmModelAliases,
1827
+ selectLlmModelByQuery,
1798
1828
  createLlmCommand,
1799
1829
  createLlmCommands,
1800
1830
  llmCommands
@@ -13,10 +13,11 @@ import {
13
13
  llmTemplateUsesInput,
14
14
  parseLlmSchemaDsl,
15
15
  resolveLlmSchemaInput,
16
+ selectLlmModelByQuery,
16
17
  templateYaml,
17
18
  validateLlmTemplateParameters,
18
19
  validateModelOptions
19
- } from "../../chunks/chunk-DVSLGXQU.js";
20
+ } from "../../chunks/chunk-C2NYCU7O.js";
20
21
  import "../../chunks/chunk-YG5WAHK7.js";
21
22
  export {
22
23
  createElevenLabsProvider,
@@ -33,6 +34,7 @@ export {
33
34
  llmTemplateUsesInput,
34
35
  parseLlmSchemaDsl,
35
36
  resolveLlmSchemaInput,
37
+ selectLlmModelByQuery,
36
38
  templateYaml,
37
39
  validateLlmTemplateParameters,
38
40
  validateModelOptions
@@ -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
@@ -4,5 +4,5 @@ export { baseAgentCommands, createBoundedRegexProvider } from "./registry-entry.
4
4
  export { agentCommands, createAgentCommands } from "./plugins/index.browser.js";
5
5
  export { EreLedger, EreProfileLimitError, EreSyntaxError, EreUnsupportedError, EreUsageUnknownError, RegexExecutionError, RegexExecutor, RegexSession, compileEre, matchEre } from "./commands/regex-execution/public.browser.js";
6
6
  export { PythonFailure, PythonPackageConflictError, createPythonCommands, createPythonExecutorPool, createPythonHostBridge, createPythonJspiAssets, createPythonJspiExecutor, createPythonJspiNativeCall, createPythonJspiStatResult, createPythonJspiTrampoline, createPythonLlmCapability, createPythonPackageCache, createPythonPackageEnvironment, createPythonPackageManifestStore, createPythonShellCapability, inspectPythonCapabilities, pythonCommands, pythonDocumentPackages, pythonHostFailureCode } from "./commands/python/index.browser.js";
7
- export { createElevenLabsProvider, createLlmCommand, createLlmCommands, createLlmConfiguration, createLlmService, createLlmTemplateStore, createOpenAiProvider, evaluateLlmTemplate, findExtractedRange, getLlmModelAliases, llmCommands, llmTemplateUsesInput, parseLlmSchemaDsl, resolveLlmSchemaInput, templateYaml, validateLlmTemplateParameters, validateModelOptions } from "./commands/llm/index.browser.js";
7
+ export { createElevenLabsProvider, createLlmCommand, createLlmCommands, createLlmConfiguration, createLlmService, createLlmTemplateStore, createOpenAiProvider, evaluateLlmTemplate, findExtractedRange, getLlmModelAliases, llmCommands, llmTemplateUsesInput, parseLlmSchemaDsl, resolveLlmSchemaInput, selectLlmModelByQuery, templateYaml, validateLlmTemplateParameters, validateModelOptions } from "./commands/llm/index.browser.js";
8
8
  import "./chunks/chunk-KV7PKOHV.js";
@@ -57,7 +57,7 @@ import {
57
57
  parseShell,
58
58
  searchCommands,
59
59
  unrtfCommands
60
- } from "./chunks/chunk-6AKPBNRF.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";
@@ -411,10 +411,11 @@ import {
411
411
  llmTemplateUsesInput,
412
412
  parseLlmSchemaDsl,
413
413
  resolveLlmSchemaInput,
414
+ selectLlmModelByQuery,
414
415
  templateYaml,
415
416
  validateLlmTemplateParameters,
416
417
  validateModelOptions
417
- } from "./chunks/chunk-DVSLGXQU.js";
418
+ } from "./chunks/chunk-C2NYCU7O.js";
418
419
  import {
419
420
  init_platform
420
421
  } from "./chunks/chunk-YG5WAHK7.js";
@@ -1904,6 +1905,7 @@ export {
1904
1905
  restoreEnvironment,
1905
1906
  safeJsNodeCommands as safeJsCommands,
1906
1907
  searchCommands,
1908
+ selectLlmModelByQuery,
1907
1909
  selectOpBackendContext,
1908
1910
  selectOpGlobalFlags,
1909
1911
  sha512sumCommands,