@poe-platform/safe-bash 0.1.797 → 0.1.798

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 (47) hide show
  1. package/dist/pdf/index.d.ts +1 -1
  2. package/dist/pdf/model.d.ts +7 -2
  3. package/dist/safe-bash/chunks/{chunk-TGOF7VO5.js → chunk-AMTCC256.js} +1 -1
  4. package/dist/safe-bash/chunks/{chunk-TCWZNUVP.js → chunk-CSNXID73.js} +1 -1
  5. package/dist/safe-bash/chunks/{chunk-C2NYCU7O.js → chunk-JSVX4VIA.js} +5 -1
  6. package/dist/safe-bash/chunks/{chunk-ZXKVOJNL.js → chunk-V3VEATEA.js} +6 -5
  7. package/dist/safe-bash/chunks/{chunk-D2XB7XIC.js → chunk-XH26YVGW.js} +6 -0
  8. package/dist/safe-bash/command-chunks/{chunk-A7RIYQIF.js → chunk-DDLQ5YDB.js} +172 -167
  9. package/dist/safe-bash/command-chunks/{chunk-C2DUYVYZ.js → chunk-ESMCX3YV.js} +138 -36
  10. package/dist/safe-bash/command-chunks/chunk-EZ7D6DXC.js +6 -0
  11. package/dist/safe-bash/command-chunks/{chunk-ECAK3JHR.js → chunk-QRRYN2KO.js} +21 -12
  12. package/dist/safe-bash/command-chunks/{chunk-UUR2S7AD.js → chunk-Y6TUZWPS.js} +28 -1
  13. package/dist/safe-bash/command-chunks/{pptx-KY2OJWZW-76LBHCHD.js → pptx-GBPNWNEP-7EQEVXV5.js} +8 -2
  14. package/dist/safe-bash/commands/llm/index.browser.js +9 -1
  15. package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -2
  16. package/dist/safe-bash/core.browser.js +1 -1
  17. package/dist/safe-bash/core.d.ts +5 -1
  18. package/dist/safe-bash/core.js +5 -1
  19. package/dist/safe-bash/full-core.browser.js +134 -5
  20. package/dist/safe-bash/lazy-optional.d.ts +13 -0
  21. package/dist/safe-bash/lazy-optional.js +118 -0
  22. package/dist/safe-bash/plugins/index.browser.js +3 -3
  23. package/dist/safe-bash/registry-entry.browser.js +2 -2
  24. package/dist/safe-bash/shell/env-warning.js +3 -2
  25. package/dist/safe-bash/shell/runtime.js +2 -2
  26. package/dist/safe-bash/shell-entry.browser.js +2 -2
  27. package/dist/safe-bash-command-csvkit/index.js +528 -498
  28. package/dist/safe-bash-command-git/git_rust.wasm +0 -0
  29. package/dist/safe-bash-command-git/wasm.generated.js +1 -1
  30. package/dist/safe-bash-command-llm/base64-stream.d.ts +2 -0
  31. package/dist/safe-bash-command-llm/chat-json.d.ts +10 -0
  32. package/dist/safe-bash-command-llm/index.d.ts +2 -1
  33. package/dist/safe-bash-command-llm/index.js +11 -2
  34. package/dist/safe-bash-command-llm/json-string.d.ts +2 -0
  35. package/dist/safe-bash-command-llm/json-value.d.ts +2 -0
  36. package/dist/safe-bash-command-llm/openai.d.ts +1 -0
  37. package/dist/safe-bash-command-llm/openai.js +4 -2
  38. package/dist/safe-bash-command-llm/provider-serialization.d.ts +6 -0
  39. package/dist/safe-bash-command-llm/providers/index.d.ts +2 -1
  40. package/dist/safe-bash-command-llm/providers/index.js +12 -3
  41. package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -1
  42. package/dist/safe-bash-command-llm/providers/openai.js +4 -2
  43. package/dist/safe-bash-command-pandoc/citeproc-filters.js +1 -1
  44. package/dist/safe-bash-command-pandoc/command.js +3 -3
  45. package/dist/safe-bash-command-pandoc/index.js +3 -3
  46. package/dist/safe-bash-command-ssconvert/index.js +1 -1
  47. package/package.json +5 -4
@@ -7,7 +7,7 @@ export declare function pdfCapabilities(): {
7
7
  readonly profile: "PDF-1.7-supplied-fonts-ltr";
8
8
  readonly reference: "Adobe PDF Reference sixth edition, November 2006";
9
9
  readonly scripts: readonly ["Latin", "Greek", "Cyrillic"];
10
- readonly fonts: readonly ["sfnt-TrueType-glyf"];
10
+ readonly fonts: readonly ["sfnt-TrueType-glyf", "standard-14"];
11
11
  readonly png: "static-noninterlaced-8bit";
12
12
  readonly jpeg: "8bit-gray-rgb-adobe-cmyk";
13
13
  readonly images: readonly ["png", "jpeg"];
@@ -8,12 +8,17 @@ export interface SuppliedFont {
8
8
  readonly id: string;
9
9
  readonly bytes: Uint8Array;
10
10
  }
11
+ export type StandardFontName = "Helvetica" | "Helvetica-Bold" | "Helvetica-Oblique" | "Helvetica-BoldOblique" | "Courier" | "Courier-Bold" | "Courier-Oblique" | "Courier-BoldOblique" | "Times-Roman" | "Times-Bold" | "Times-Italic" | "Times-BoldItalic" | "Symbol" | "ZapfDingbats";
12
+ export interface StandardFont {
13
+ readonly id: string;
14
+ readonly standard: StandardFontName;
15
+ }
11
16
  export interface TextRun {
12
17
  readonly text: string;
13
18
  readonly font?: string;
14
19
  readonly size?: number;
15
20
  readonly link?: string;
16
- /** Synthetic weight and oblique styling use the supplied font's glyphs. */
21
+ /** Synthetic weight/oblique apply to supplied fonts, including Unicode fallback; standard fonts use their named face. */
17
22
  readonly bold?: boolean;
18
23
  readonly italic?: boolean;
19
24
  readonly strikeout?: boolean;
@@ -67,7 +72,7 @@ export interface LayoutDocument {
67
72
  readonly metadata?: PdfMetadata;
68
73
  readonly page?: PageBox;
69
74
  readonly lineHeight?: number;
70
- readonly fonts: readonly SuppliedFont[];
75
+ readonly fonts: readonly (SuppliedFont | StandardFont)[];
71
76
  readonly blocks: readonly LayoutBlock[];
72
77
  }
73
78
  export interface PdfLimits {
@@ -2,7 +2,7 @@ import {
2
2
  composeAgentCommands,
3
3
  createAgentCommandPlugin,
4
4
  createRegexExecutors
5
- } from "./chunk-TCWZNUVP.js";
5
+ } from "./chunk-CSNXID73.js";
6
6
  import {
7
7
  commandRuntimeIdentity
8
8
  } from "./chunk-LQHGH25W.js";
@@ -86,7 +86,7 @@ import {
86
86
  virtualPath,
87
87
  wcDisplayWidth,
88
88
  write
89
- } from "./chunk-D2XB7XIC.js";
89
+ } from "./chunk-XH26YVGW.js";
90
90
  import {
91
91
  createGetoptCommands
92
92
  } from "./chunk-3L3T6LYV.js";
@@ -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, selectLlmModelByQuery, templateYaml, validateLlmTemplateParameters, validateModelOptions } from "../../safe-bash-command-llm/index.js";
7
+ import { createElevenLabsProvider, createLlmCommand, createLlmCommands, createLlmConfiguration, createLlmService, createLlmTemplateStore, createOpenAiProvider, encodeLlmBase64, evaluateLlmTemplate, findExtractedRange, getLlmModelAliases, llmCommands, llmTemplateUsesInput, parseLlmSchemaDsl, resolveLlmSchemaInput, selectLlmModelByQuery, serializeLlmJsonString, serializeLlmJsonValue, serializeOpenAiChatRequest, templateYaml, validateLlmTemplateParameters, validateModelOptions } from "../../safe-bash-command-llm/index.js";
8
8
 
9
9
  export {
10
10
  createElevenLabsProvider,
@@ -14,6 +14,7 @@ export {
14
14
  createLlmService,
15
15
  createLlmTemplateStore,
16
16
  createOpenAiProvider,
17
+ encodeLlmBase64,
17
18
  evaluateLlmTemplate,
18
19
  findExtractedRange,
19
20
  getLlmModelAliases,
@@ -22,6 +23,9 @@ export {
22
23
  parseLlmSchemaDsl,
23
24
  resolveLlmSchemaInput,
24
25
  selectLlmModelByQuery,
26
+ serializeLlmJsonString,
27
+ serializeLlmJsonValue,
28
+ serializeOpenAiChatRequest,
25
29
  templateYaml,
26
30
  validateLlmTemplateParameters,
27
31
  validateModelOptions
@@ -92,7 +92,7 @@ import {
92
92
  tryMatchesPatternSync,
93
93
  variablePresence,
94
94
  wcDisplayWidth
95
- } from "./chunk-D2XB7XIC.js";
95
+ } from "./chunk-XH26YVGW.js";
96
96
  import {
97
97
  evalSyncGetopt
98
98
  } from "./chunk-3L3T6LYV.js";
@@ -4216,9 +4216,10 @@ import { createDeviceFileSystem } from "@poe-platform/safe-fs/core";
4216
4216
  init_platform();
4217
4217
  var warned = /* @__PURE__ */ new WeakSet();
4218
4218
  function warnIfHostProcessEnv(env) {
4219
- if (!env || true) return;
4219
+ const hostProcess = globalThis.process;
4220
+ if (!env || !hostProcess?.env) return;
4220
4221
  if (warned.has(env)) return;
4221
- if (env !== (void 0).env) return;
4222
+ if (env !== hostProcess.env) return;
4222
4223
  warned.add(env);
4223
4224
  console.warn("[safe-bash] warning: the shell `env` is the host `process.env`. Scripts executed in this shell can read every value in it, including secrets; on Cloudflare Workers with nodejs_compat, process.env contains the Worker's secret bindings. Pass only the variables your scripts need. See docs/issues/safe-bash-cloudflare-security-audit.md (finding 1).");
4224
4225
  }
@@ -35711,7 +35712,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
35711
35712
  }
35712
35713
  if (part.length) return String(binding?.values.size ?? (part.name === "FUNCNAME" && state.variables.FUNCNAME === void 0 ? state.functionNames?.length ?? 0 : state.variables[part.name] === void 0 ? 0 : 1));
35713
35714
  const values = await this.arrayMembers(part.name, state, io, selector.kind === "keys" || part.keys === true, part.substring);
35714
- const space = selector.kind === "keys" || part.keys === true ? Boolean(hereDocument || (selector.separator === "@" ? !part.quoted && !split || state.variables.IFS === "" : !part.quoted && split && state.variables.IFS === "")) : !split && selector.separator === "@" && (!part.substring || !part.quoted || state.variables.IFS === "");
35715
+ const space = selector.kind === "keys" || part.keys === true ? Boolean(hereDocument || (selector.separator === "@" ? !part.quoted && !split || state.variables.IFS === "" : !part.quoted && split && state.variables.IFS === "")) : !split && selector.separator === "@";
35715
35716
  return this.arrayJoin(store.owner, values, space ? " " : this.ifsSeparator(state, io));
35716
35717
  }
35717
35718
  if (part.substring && (part.name === "@" || part.name === "*")) {
@@ -36277,7 +36278,7 @@ ${prefix} line ${offset + line}: \`${source.split("\n")[line - 1] ?? ""}'
36277
36278
  }
36278
36279
  const ifsVal = monitor?.values.get("IFS", rawVars.IFS ?? " ") ?? rawVars.IFS ?? " ";
36279
36280
  if (validElemOp && typeof ifsVal === "string" && (ifsVal.length === 0 || ifsVal.charCodeAt(0) < 128)) {
36280
- const sep = selector.separator === "@" && (ifsVal.length === 0 || !isKeys && part.operator === void 0 && !part.substring) ? " " : ifsVal.length > 0 ? ifsVal[0] : "";
36281
+ const sep = selector.separator === "@" && (ifsVal.length === 0 || !isKeys && part.operator === void 0) ? " " : ifsVal.length > 0 ? ifsVal[0] : "";
36281
36282
  const parameterLine = part.line ?? overrideDiagnosticLine;
36282
36283
  const evalSliceInt = (w) => {
36283
36284
  if (w.parts.length === 0) return 0;
@@ -12836,6 +12836,11 @@ function createCalCommand(options2 = {}) {
12836
12836
  if (isDefaultCalOptions(options2)) builtInDirectContextExecutors.add(def.execute);
12837
12837
  return def;
12838
12838
  }
12839
+ function createNcalCommand(options2 = {}) {
12840
+ const def = createRawNcalCommand(options2);
12841
+ if (isDefaultCalOptions(options2)) builtInDirectContextExecutors.add(def.execute);
12842
+ return def;
12843
+ }
12839
12844
  function createCalCommands(options2 = {}) {
12840
12845
  const defs = createRawCalCommands(options2);
12841
12846
  if (isDefaultCalOptions(options2)) {
@@ -22999,6 +23004,7 @@ export {
22999
23004
  envsubstCommands,
23000
23005
  evalSyncCal,
23001
23006
  createCalCommand,
23007
+ createNcalCommand,
23002
23008
  createCalCommands,
23003
23009
  calCommands,
23004
23010
  createPathchkCommand,
@@ -27,173 +27,6 @@ import {
27
27
  // packages/safe-bash-command-llm/src/openai.ts
28
28
  init_buffer();
29
29
 
30
- // packages/safe-bash-command-llm/src/openai-chat-options.ts
31
- init_buffer();
32
-
33
- // packages/safe-bash-command-llm/src/token-integer.ts
34
- init_buffer();
35
- var decimalZeroes = [
36
- 48,
37
- 1632,
38
- 1776,
39
- 1984,
40
- 2406,
41
- 2534,
42
- 2662,
43
- 2790,
44
- 2918,
45
- 3046,
46
- 3174,
47
- 3302,
48
- 3430,
49
- 3558,
50
- 3664,
51
- 3792,
52
- 3872,
53
- 4160,
54
- 4240,
55
- 6112,
56
- 6160,
57
- 6470,
58
- 6608,
59
- 6784,
60
- 6800,
61
- 6992,
62
- 7088,
63
- 7232,
64
- 7248,
65
- 42528,
66
- 43216,
67
- 43264,
68
- 43472,
69
- 43504,
70
- 43600,
71
- 44016,
72
- 65296,
73
- 66720,
74
- 68912,
75
- 69734,
76
- 69872,
77
- 69942,
78
- 70096,
79
- 70384,
80
- 70736,
81
- 70864,
82
- 71248,
83
- 71360,
84
- 71472,
85
- 71904,
86
- 72016,
87
- 72784,
88
- 73040,
89
- 73120,
90
- 92768,
91
- 93008,
92
- 120782,
93
- 120792,
94
- 120802,
95
- 120812,
96
- 120822,
97
- 123200,
98
- 123632,
99
- 125264,
100
- 130032
101
- ];
102
- function digit(code) {
103
- if (code === void 0) return void 0;
104
- if (code >= 48 && code <= 57) return code - 48;
105
- for (const zero of decimalZeroes) if (code >= zero && code < zero + 10) return code - zero;
106
- return void 0;
107
- }
108
- function whitespace(code) {
109
- return code >= 9 && code <= 13 || code === 32 || code === 133 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288;
110
- }
111
- function tokenInteger(input) {
112
- let start = 0, end = input.length;
113
- while (start < end && whitespace(input.charCodeAt(start))) start++;
114
- while (end > start && whitespace(input.charCodeAt(end - 1))) end--;
115
- let normalized = "", previousDigit = false, digits = 0;
116
- if (input[start] === "+" || input[start] === "-") normalized = input[start++];
117
- for (let index = start; index < end; ) {
118
- const code = input.codePointAt(index);
119
- const value = digit(code);
120
- if (value !== void 0) {
121
- normalized += String(value);
122
- digits++;
123
- previousDigit = true;
124
- } else if (code === 95 && previousDigit && digit(input.codePointAt(index + 1)) !== void 0) previousDigit = false;
125
- else return void 0;
126
- index += code > 65535 ? 2 : 1;
127
- }
128
- return digits ? BigInt(normalized).toString() : void 0;
129
- }
130
-
131
- // packages/safe-bash-command-llm/src/openai-chat-options.ts
132
- function biasInteger(value) {
133
- if (typeof value === "boolean") return Number(value);
134
- if (typeof value === "number") return Number.isFinite(value) ? Math.trunc(value) : void 0;
135
- if (typeof value !== "string") return void 0;
136
- const integer = tokenInteger(value);
137
- return integer === void 0 ? void 0 : Number(integer);
138
- }
139
- function dictionaryKeys(json) {
140
- const keys = /* @__PURE__ */ new Set();
141
- let depth = 0;
142
- let expectingKey = false;
143
- for (let index = 0; index < json.length; index++) {
144
- const char = json[index];
145
- if (char === '"') {
146
- const start = index;
147
- while (++index < json.length) {
148
- if (json[index] === "\\") index++;
149
- else if (json[index] === '"') break;
150
- }
151
- if (depth === 1 && expectingKey) {
152
- keys.add(JSON.parse(json.slice(start, index + 1)));
153
- expectingKey = false;
154
- }
155
- } else if (char === "{" || char === "[") {
156
- depth++;
157
- if (depth === 1) expectingKey = true;
158
- } else if (char === "}" || char === "]") depth--;
159
- else if (char === "," && depth === 1) expectingKey = true;
160
- }
161
- return [...keys];
162
- }
163
- function logitBias(input) {
164
- if (typeof input !== "string") throw new TypeError("Invalid OpenAI logit_bias: expected a JSON dictionary");
165
- let parsed;
166
- try {
167
- parsed = JSON.parse(input);
168
- } catch {
169
- throw new TypeError("Invalid OpenAI logit_bias: Invalid JSON in logit_bias string");
170
- }
171
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new TypeError("Invalid OpenAI logit_bias: expected a JSON dictionary");
172
- const result = {};
173
- for (const key of dictionaryKeys(input)) {
174
- const value = parsed[key];
175
- const token = tokenInteger(key);
176
- const bias = biasInteger(value);
177
- if (token === void 0 || bias === void 0 || !Number.isSafeInteger(bias) || bias < -100 || bias > 100) throw new TypeError("Invalid OpenAI logit_bias: Invalid key-value pair in logit_bias dictionary");
178
- Object.defineProperty(result, token, { value: bias, enumerable: true, configurable: true, writable: true });
179
- }
180
- return result;
181
- }
182
- function openAiChatOptions(options) {
183
- const { json_object: jsonObject, logit_bias: bias, ...values } = options;
184
- const result = { ...values };
185
- if (bias !== void 0 && bias !== null) result.logit_bias = logitBias(bias);
186
- if (jsonObject !== void 0 && jsonObject !== null) {
187
- const text = String(jsonObject).toLowerCase();
188
- if (!["true", "false", "1", "0", "yes", "no", "on", "off", "y", "n", "t", "f"].includes(text)) throw new TypeError("Invalid OpenAI json_object: expected boolean");
189
- if (["true", "1", "yes", "on", "y", "t"].includes(text)) {
190
- if (Object.hasOwn(values, "response_format")) throw new TypeError("OpenAI json_object conflicts with response_format");
191
- result.response_format = { type: "json_object" };
192
- }
193
- }
194
- return result;
195
- }
196
-
197
30
  // packages/safe-bash-command-llm/src/chat-json.ts
198
31
  init_buffer();
199
32
 
@@ -377,6 +210,7 @@ function jsonValue(value, signal) {
377
210
  // packages/safe-bash-command-llm/src/chat-json.ts
378
211
  function chatJson(request, limit) {
379
212
  request.signal.throwIfAborted();
213
+ if (limit !== Infinity && (!Number.isSafeInteger(limit) || limit < 0)) throw new RangeError("Invalid provider request byte limit");
380
214
  for (const field of ["model", "messages", "stream"]) if (Object.hasOwn(request.options, field)) throw new TypeError(`${field} is controlled by the provider`);
381
215
  if (request.schema && Object.hasOwn(request.options, "response_format")) throw new TypeError("schema conflicts with response_format");
382
216
  for (const attachment of request.attachments) if (!acceptsMimeType(["image/*"], attachment.mimeType)) throw new TypeError("Only image attachments are supported");
@@ -426,6 +260,173 @@ function chatJson(request, limit) {
426
260
  return limited();
427
261
  }
428
262
 
263
+ // packages/safe-bash-command-llm/src/openai-chat-options.ts
264
+ init_buffer();
265
+
266
+ // packages/safe-bash-command-llm/src/token-integer.ts
267
+ init_buffer();
268
+ var decimalZeroes = [
269
+ 48,
270
+ 1632,
271
+ 1776,
272
+ 1984,
273
+ 2406,
274
+ 2534,
275
+ 2662,
276
+ 2790,
277
+ 2918,
278
+ 3046,
279
+ 3174,
280
+ 3302,
281
+ 3430,
282
+ 3558,
283
+ 3664,
284
+ 3792,
285
+ 3872,
286
+ 4160,
287
+ 4240,
288
+ 6112,
289
+ 6160,
290
+ 6470,
291
+ 6608,
292
+ 6784,
293
+ 6800,
294
+ 6992,
295
+ 7088,
296
+ 7232,
297
+ 7248,
298
+ 42528,
299
+ 43216,
300
+ 43264,
301
+ 43472,
302
+ 43504,
303
+ 43600,
304
+ 44016,
305
+ 65296,
306
+ 66720,
307
+ 68912,
308
+ 69734,
309
+ 69872,
310
+ 69942,
311
+ 70096,
312
+ 70384,
313
+ 70736,
314
+ 70864,
315
+ 71248,
316
+ 71360,
317
+ 71472,
318
+ 71904,
319
+ 72016,
320
+ 72784,
321
+ 73040,
322
+ 73120,
323
+ 92768,
324
+ 93008,
325
+ 120782,
326
+ 120792,
327
+ 120802,
328
+ 120812,
329
+ 120822,
330
+ 123200,
331
+ 123632,
332
+ 125264,
333
+ 130032
334
+ ];
335
+ function digit(code) {
336
+ if (code === void 0) return void 0;
337
+ if (code >= 48 && code <= 57) return code - 48;
338
+ for (const zero of decimalZeroes) if (code >= zero && code < zero + 10) return code - zero;
339
+ return void 0;
340
+ }
341
+ function whitespace(code) {
342
+ return code >= 9 && code <= 13 || code === 32 || code === 133 || code === 160 || code === 5760 || code >= 8192 && code <= 8202 || code === 8232 || code === 8233 || code === 8239 || code === 8287 || code === 12288;
343
+ }
344
+ function tokenInteger(input) {
345
+ let start = 0, end = input.length;
346
+ while (start < end && whitespace(input.charCodeAt(start))) start++;
347
+ while (end > start && whitespace(input.charCodeAt(end - 1))) end--;
348
+ let normalized = "", previousDigit = false, digits = 0;
349
+ if (input[start] === "+" || input[start] === "-") normalized = input[start++];
350
+ for (let index = start; index < end; ) {
351
+ const code = input.codePointAt(index);
352
+ const value = digit(code);
353
+ if (value !== void 0) {
354
+ normalized += String(value);
355
+ digits++;
356
+ previousDigit = true;
357
+ } else if (code === 95 && previousDigit && digit(input.codePointAt(index + 1)) !== void 0) previousDigit = false;
358
+ else return void 0;
359
+ index += code > 65535 ? 2 : 1;
360
+ }
361
+ return digits ? BigInt(normalized).toString() : void 0;
362
+ }
363
+
364
+ // packages/safe-bash-command-llm/src/openai-chat-options.ts
365
+ function biasInteger(value) {
366
+ if (typeof value === "boolean") return Number(value);
367
+ if (typeof value === "number") return Number.isFinite(value) ? Math.trunc(value) : void 0;
368
+ if (typeof value !== "string") return void 0;
369
+ const integer = tokenInteger(value);
370
+ return integer === void 0 ? void 0 : Number(integer);
371
+ }
372
+ function dictionaryKeys(json) {
373
+ const keys = /* @__PURE__ */ new Set();
374
+ let depth = 0;
375
+ let expectingKey = false;
376
+ for (let index = 0; index < json.length; index++) {
377
+ const char = json[index];
378
+ if (char === '"') {
379
+ const start = index;
380
+ while (++index < json.length) {
381
+ if (json[index] === "\\") index++;
382
+ else if (json[index] === '"') break;
383
+ }
384
+ if (depth === 1 && expectingKey) {
385
+ keys.add(JSON.parse(json.slice(start, index + 1)));
386
+ expectingKey = false;
387
+ }
388
+ } else if (char === "{" || char === "[") {
389
+ depth++;
390
+ if (depth === 1) expectingKey = true;
391
+ } else if (char === "}" || char === "]") depth--;
392
+ else if (char === "," && depth === 1) expectingKey = true;
393
+ }
394
+ return [...keys];
395
+ }
396
+ function logitBias(input) {
397
+ if (typeof input !== "string") throw new TypeError("Invalid OpenAI logit_bias: expected a JSON dictionary");
398
+ let parsed;
399
+ try {
400
+ parsed = JSON.parse(input);
401
+ } catch {
402
+ throw new TypeError("Invalid OpenAI logit_bias: Invalid JSON in logit_bias string");
403
+ }
404
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new TypeError("Invalid OpenAI logit_bias: expected a JSON dictionary");
405
+ const result = {};
406
+ for (const key of dictionaryKeys(input)) {
407
+ const value = parsed[key];
408
+ const token = tokenInteger(key);
409
+ const bias = biasInteger(value);
410
+ if (token === void 0 || bias === void 0 || !Number.isSafeInteger(bias) || bias < -100 || bias > 100) throw new TypeError("Invalid OpenAI logit_bias: Invalid key-value pair in logit_bias dictionary");
411
+ Object.defineProperty(result, token, { value: bias, enumerable: true, configurable: true, writable: true });
412
+ }
413
+ return result;
414
+ }
415
+ function openAiChatOptions(options) {
416
+ const { json_object: jsonObject, logit_bias: bias, ...values } = options;
417
+ const result = { ...values };
418
+ if (bias !== void 0 && bias !== null) result.logit_bias = logitBias(bias);
419
+ if (jsonObject !== void 0 && jsonObject !== null) {
420
+ const text = String(jsonObject).toLowerCase();
421
+ if (!["true", "false", "1", "0", "yes", "no", "on", "off", "y", "n", "t", "f"].includes(text)) throw new TypeError("Invalid OpenAI json_object: expected boolean");
422
+ if (["true", "1", "yes", "on", "y", "t"].includes(text)) {
423
+ if (Object.hasOwn(values, "response_format")) throw new TypeError("OpenAI json_object conflicts with response_format");
424
+ result.response_format = { type: "json_object" };
425
+ }
426
+ }
427
+ return result;
428
+ }
429
+
429
430
  // packages/safe-bash-command-llm/src/openai.ts
430
431
  var numericOptions = {
431
432
  chat: /* @__PURE__ */ new Map([
@@ -728,5 +729,9 @@ function createOpenAiProvider(options) {
728
729
  }
729
730
 
730
731
  export {
732
+ jsonString,
733
+ jsonValue,
734
+ base64Stream,
735
+ chatJson,
731
736
  createOpenAiProvider
732
737
  };