@poe-platform/safe-bash 0.1.789 → 0.1.790
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.
- package/dist/image-ast/index.browser.js +147 -80
- package/dist/image-ast/index.js +147 -80
- package/dist/mp4-ast/mp4.d.ts +2 -0
- package/dist/pdf-ast/cos/parser.d.ts +1 -0
- package/dist/pdf-ast/cos/security.d.ts +2 -0
- package/dist/pdf-ast/cos/writer.d.ts +1 -0
- package/dist/pdf-ast/document.d.ts +3 -0
- package/dist/pdf-ast/edit/forms.d.ts +1 -0
- package/dist/pdf-ast/index.js +171 -82
- package/dist/safe-bash/chunks/{chunk-L5QQLNTO.js → chunk-22PI65AH.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-KHJGUF2W.js → chunk-2TAGYMPK.js} +43 -42
- package/dist/safe-bash/chunks/{chunk-D4PHJK4T.js → chunk-2W4HTMEK.js} +52 -48
- package/dist/safe-bash/chunks/{chunk-FFZXP6ZC.js → chunk-3M7L7XU2.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-XNODZRVD.js → chunk-3QAO6UYS.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-YPETOVQU.js → chunk-3VKFK3NF.js} +2 -2
- package/dist/safe-bash/chunks/chunk-5OST7NOX.js +42 -0
- package/dist/safe-bash/chunks/{chunk-KEBSX2AX.js → chunk-6HLURHVU.js} +2 -2
- package/dist/safe-bash/chunks/chunk-DYEUZE6Z.js +19 -0
- package/dist/safe-bash/chunks/{chunk-T2TGCHKE.js → chunk-FM3WBSZT.js} +2 -2
- package/dist/safe-bash/chunks/chunk-GAYRKQM6.js +22 -0
- package/dist/safe-bash/chunks/{chunk-Q45QCA4J.js → chunk-I3KSESCR.js} +0 -7
- package/dist/safe-bash/chunks/{chunk-OSKDIBQS.js → chunk-JLIMK5TD.js} +1 -1
- package/dist/safe-bash/chunks/{chunk-2AYZCT5X.js → chunk-JQ2FAJJT.js} +27 -23
- package/dist/safe-bash/chunks/{chunk-QA3NVP43.js → chunk-JRE6Z3T7.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-DC5EHLKS.js → chunk-NDIL6T7Y.js} +5 -5
- package/dist/safe-bash/chunks/{chunk-747G42FY.js → chunk-OPR4UAIT.js} +2 -2
- package/dist/safe-bash/chunks/chunk-OSMQCYSP.js +19 -0
- package/dist/safe-bash/chunks/chunk-OYB332PQ.js +17 -0
- package/dist/safe-bash/chunks/{chunk-X5ZCECM6.js → chunk-QTIH2AFE.js} +77 -69
- package/dist/safe-bash/chunks/{chunk-CTUHLNJM.js → chunk-SBESXWT2.js} +43 -44
- package/dist/safe-bash/chunks/{chunk-4FDQJUFW.js → chunk-SDEPGTOF.js} +1 -1
- package/dist/safe-bash/chunks/chunk-UZU5BIJI.js +32 -0
- package/dist/safe-bash/chunks/{chunk-BI6JV62X.js → chunk-VCCMROTL.js} +7 -10
- package/dist/safe-bash/chunks/chunk-W47GHRRF.js +13 -0
- package/dist/safe-bash/chunks/{chunk-NPMQWZUZ.js → chunk-WS7KZIUM.js} +2 -2
- package/dist/safe-bash/chunks/{chunk-3PZYHMGM.js → chunk-YYAERCWS.js} +7 -7
- package/dist/safe-bash/chunks/{chunk-5U7JECDB.js → chunk-ZPGVEUKF.js} +8 -7
- package/dist/safe-bash/chunks/{csvkit-K55OYAQC.js → csvkit-USUJG62I.js} +65 -11
- package/dist/safe-bash/chunks/{ffmpeg-BEFTQ6DZ.js → ffmpeg-KRGG5DLH.js} +21 -10
- package/dist/safe-bash/chunks/{gh-HQWOWLWE.js → gh-UCFDUZCX.js} +16 -8
- package/dist/safe-bash/chunks/{git-HO7WDPHZ.js → git-LPAF6KDG.js} +7 -9
- package/dist/safe-bash/chunks/{imagemagick-53BMHH6D.js → imagemagick-KGREKK4G.js} +38 -7
- package/dist/safe-bash/chunks/{implementation-QUTAAYMT.js → implementation-FXDRYS5A.js} +34 -8
- package/dist/safe-bash/chunks/{pdfimages-4OYI6FLG.js → pdfimages-UADCF4G4.js} +12 -8
- package/dist/safe-bash/chunks/{pdfinfo-I7U6TQPP.js → pdfinfo-O7UWPF4W.js} +38 -13
- package/dist/safe-bash/chunks/{pdftk-SUA6FMHI.js → pdftk-AERXIJTN.js} +13 -8
- package/dist/safe-bash/chunks/{pdftoppm-4C5DGEWX.js → pdftoppm-L466JQKI.js} +17 -10
- package/dist/safe-bash/chunks/{pdftotext-Y4WI225Y.js → pdftotext-SUSI4WXS.js} +19 -9
- package/dist/safe-bash/chunks/{qpdf-IORB4RV5.js → qpdf-YL24KVRH.js} +14 -8
- package/dist/safe-bash/chunks/{sips-WHAMJFEU.js → sips-QXEQZERX.js} +14 -7
- package/dist/safe-bash/chunks/{soffice-SYEK6WJS.js → soffice-TBITRML3.js} +16 -8
- package/dist/safe-bash/chunks/{wkhtmltopdf-ZIICWJLF.js → wkhtmltopdf-NJA2THRC.js} +27 -7
- package/dist/safe-bash/command-chunks/chunk-2C5BEBPY.js +1388 -0
- package/dist/safe-bash/command-chunks/{chunk-2VTMZTV3.js → chunk-2EXV2ZLV.js} +2 -2
- package/dist/safe-bash/command-chunks/{chunk-UJOO6DKY.js → chunk-6EASC5EC.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-ZF3ZVGQC.js → chunk-7JRITHKW.js} +150 -80
- package/dist/safe-bash/{chunks/chunk-LD76P7AG.js → command-chunks/chunk-AKDMCNX4.js} +74 -39
- package/dist/safe-bash/command-chunks/{chunk-6F7QJMJ3.js → chunk-CBDVLMJB.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-H4LWTITX.js +169 -0
- package/dist/safe-bash/command-chunks/chunk-I2MQNBGR.js +145 -0
- package/dist/safe-bash/command-chunks/{chunk-5GRLAARV.js → chunk-IOXI5ZAJ.js} +1 -1
- package/dist/safe-bash/command-chunks/{chunk-XNHSCU6I.js → chunk-MDPIOQUD.js} +6 -6
- package/dist/safe-bash/command-chunks/chunk-QI4MGIN6.js +6 -0
- package/dist/safe-bash/command-chunks/chunk-QTYZAWSB.js +91 -0
- package/dist/safe-bash/command-chunks/chunk-SNK7K3XW.js +90 -0
- package/dist/safe-bash/command-chunks/chunk-T5OLGM43.js +314 -0
- package/dist/safe-bash/command-chunks/chunk-TB7IFMUZ.js +802 -0
- package/dist/safe-bash/command-chunks/{chunk-AT6ZSOE6.js → chunk-TPPBPIWL.js} +1 -1
- package/dist/safe-bash/command-chunks/chunk-VMK4XVKO.js +82 -0
- package/dist/safe-bash/command-chunks/chunk-VNSJKXDU.js +130 -0
- package/dist/safe-bash/command-chunks/chunk-YFNTMH6Z.js +6 -0
- package/dist/safe-bash/commands/csplit/index.browser.js +2 -2
- package/dist/safe-bash/commands/docx/index.browser.js +2 -2
- package/dist/safe-bash/commands/factor/index.browser.js +2 -2
- package/dist/safe-bash/commands/getopt/index.browser.js +2 -2
- package/dist/safe-bash/commands/hexdump/index.browser.js +2 -2
- package/dist/safe-bash/commands/iconv/index.browser.js +2 -2
- package/dist/safe-bash/commands/line-endings/index.browser.js +2 -2
- package/dist/safe-bash/commands/llm/command.d.ts +1 -4
- package/dist/safe-bash/commands/llm/command.js +1 -248
- package/dist/safe-bash/commands/llm/elevenlabs-stream.d.ts +1 -2
- package/dist/safe-bash/commands/llm/elevenlabs-stream.js +1 -117
- package/dist/safe-bash/commands/llm/elevenlabs.d.ts +1 -15
- package/dist/safe-bash/commands/llm/elevenlabs.js +1 -123
- package/dist/safe-bash/commands/llm/index.browser.js +20 -15
- package/dist/safe-bash/commands/llm/index.d.ts +1 -6
- package/dist/safe-bash/commands/llm/index.js +1 -4
- package/dist/safe-bash/commands/llm/mime.d.ts +1 -2
- package/dist/safe-bash/commands/llm/mime.js +1 -136
- package/dist/safe-bash/commands/llm/openai-http.d.ts +1 -8
- package/dist/safe-bash/commands/llm/openai-http.js +1 -143
- package/dist/safe-bash/commands/llm/openai-sse.d.ts +1 -3
- package/dist/safe-bash/commands/llm/openai-sse.js +1 -78
- package/dist/safe-bash/commands/llm/openai.d.ts +1 -14
- package/dist/safe-bash/commands/llm/openai.js +1 -288
- package/dist/safe-bash/commands/llm/providers/elevenlabs.d.ts +1 -1
- package/dist/safe-bash/commands/llm/providers/elevenlabs.js +1 -1
- package/dist/safe-bash/commands/llm/providers/index.browser.js +6 -6
- package/dist/safe-bash/commands/llm/providers/index.d.ts +1 -3
- package/dist/safe-bash/commands/llm/providers/index.js +1 -2
- package/dist/safe-bash/commands/llm/providers/openai.d.ts +1 -1
- package/dist/safe-bash/commands/llm/providers/openai.js +1 -1
- package/dist/safe-bash/commands/llm/providers/shared.d.ts +1 -23
- package/dist/safe-bash/commands/llm/providers/shared.js +1 -65
- package/dist/safe-bash/commands/llm/service.d.ts +1 -37
- package/dist/safe-bash/commands/llm/service.js +1 -151
- package/dist/safe-bash/commands/llm/types.d.ts +1 -52
- package/dist/safe-bash/commands/llm/types.js +1 -1
- package/dist/safe-bash/commands/mdq/index.browser.js +3 -3
- package/dist/safe-bash/commands/media/index.browser.js +1 -1
- package/dist/safe-bash/commands/network/index.browser.js +9 -9
- package/dist/safe-bash/commands/network/types.d.ts +2 -40
- package/dist/safe-bash/commands/node/index.browser.js +6 -8
- package/dist/safe-bash/commands/op/index.browser.js +3 -3
- package/dist/safe-bash/commands/op/index.js +12 -28
- package/dist/safe-bash/commands/pr/index.browser.js +2 -2
- package/dist/safe-bash/commands/python/index.browser.js +8 -8
- package/dist/safe-bash/commands/python/worker.browser.js +2 -2
- package/dist/safe-bash/commands/tsort/index.browser.js +2 -2
- package/dist/safe-bash/commands/xml/index.browser.js +2 -2
- package/dist/safe-bash/commands/yq/index.browser.js +3 -3
- package/dist/safe-bash/core.browser.js +9775 -10975
- package/dist/safe-bash/core.d.ts +0 -1
- package/dist/safe-bash/core.js +0 -1
- package/dist/safe-bash/jobs.browser.js +5 -4
- package/dist/safe-bash/optional-host.browser.js +61 -88
- package/dist/safe-bash/shell/runtime.js +34 -12
- package/dist/safe-bash/yq-browser/index.js +1 -1
- package/dist/safe-bash-command-ffmpeg/index.js +8130 -8011
- package/dist/safe-bash-command-git/git_rust.wasm +0 -0
- package/dist/safe-bash-command-git/wasm.generated.js +1 -1
- package/dist/safe-bash-command-imagemagick/index.js +2 -2
- package/dist/safe-bash-command-llm/LICENSE +21 -0
- package/dist/safe-bash-command-llm/command.d.ts +5 -0
- package/dist/safe-bash-command-llm/command.js +14 -0
- package/dist/safe-bash-command-llm/configuration.d.ts +18 -0
- package/dist/safe-bash-command-llm/elevenlabs-stream.d.ts +2 -0
- package/dist/safe-bash-command-llm/elevenlabs-stream.js +7 -0
- package/dist/safe-bash-command-llm/elevenlabs.d.ts +15 -0
- package/dist/safe-bash-command-llm/elevenlabs.js +10 -0
- package/dist/safe-bash-command-llm/index.d.ts +10 -0
- package/dist/safe-bash-command-llm/index.js +46 -0
- package/dist/safe-bash-command-llm/mime.d.ts +2 -0
- package/dist/safe-bash-command-llm/mime.js +9 -0
- package/dist/safe-bash-command-llm/model-options.d.ts +3 -0
- package/dist/safe-bash-command-llm/openai-http.d.ts +8 -0
- package/dist/safe-bash-command-llm/openai-http.js +17 -0
- package/dist/safe-bash-command-llm/openai-sse.d.ts +3 -0
- package/dist/safe-bash-command-llm/openai-sse.js +8 -0
- package/dist/safe-bash-command-llm/openai.d.ts +14 -0
- package/dist/safe-bash-command-llm/openai.js +12 -0
- package/dist/safe-bash-command-llm/providers/elevenlabs.d.ts +1 -0
- package/dist/safe-bash-command-llm/providers/elevenlabs.js +11 -0
- package/dist/safe-bash-command-llm/providers/index.d.ts +3 -0
- package/dist/safe-bash-command-llm/providers/index.js +24 -0
- package/dist/safe-bash-command-llm/providers/openai.d.ts +1 -0
- package/dist/safe-bash-command-llm/providers/openai.js +13 -0
- package/dist/safe-bash-command-llm/providers/shared.d.ts +23 -0
- package/dist/safe-bash-command-llm/providers/shared.js +13 -0
- package/dist/safe-bash-command-llm/schemas.d.ts +2 -0
- package/dist/safe-bash-command-llm/service.d.ts +42 -0
- package/dist/safe-bash-command-llm/service.js +9 -0
- package/dist/safe-bash-command-llm/templates.d.ts +27 -0
- package/dist/safe-bash-command-llm/types.d.ts +87 -0
- package/dist/safe-bash-command-llm/types.js +6 -0
- package/dist/safe-bash-command-mmdc/command.d.ts +4 -0
- package/dist/safe-bash-command-mmdc/index.d.ts +1 -1
- package/dist/safe-bash-command-mmdc/index.js +7084 -6687
- package/dist/safe-bash-command-mmdc/layout.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/parser.d.ts +1 -0
- package/dist/safe-bash-command-mmdc/png.d.ts +3 -0
- package/dist/safe-bash-command-mmdc/raster.d.ts +1 -0
- package/dist/safe-bash-command-pandoc/command.js +3 -3
- package/dist/safe-bash-command-pandoc/index.js +3 -3
- package/dist/safe-bash-command-pdfimages/index.js +147 -80
- package/dist/safe-bash-command-pdfinfo/index.js +147 -80
- package/dist/safe-bash-command-pdftk/index.js +147 -80
- package/dist/safe-bash-command-pdftoppm/index.js +147 -80
- package/dist/safe-bash-command-pdftotext/index.js +147 -80
- package/dist/safe-bash-command-qpdf/index.js +174 -101
- package/dist/safe-bash-command-sips/index.js +2 -2
- package/dist/safe-bash-command-soffice/index.js +1 -1
- package/dist/safe-bash-command-ssconvert/index.js +147 -80
- package/dist/safe-bash-command-wkhtmltopdf/index.js +147 -80
- package/dist/safe-bash-contracts/default-executor.d.ts +5 -0
- package/dist/safe-bash-contracts/default-executor.js +37 -0
- package/dist/safe-bash-contracts/http.d.ts +41 -0
- package/dist/safe-bash-contracts/http.js +6 -0
- package/dist/safe-bash-io-engine/commands/search/requirements.js +3 -3
- package/dist/safe-bash-io-engine/commands/text-programs/shared.js +3 -3
- package/dist/safe-bash-io-engine/gnu-information.d.ts +1 -1
- package/dist/safe-bash-io-engine/gnu-information.js +1 -1
- package/dist/safe-bash-io-engine/internal.js +2 -2
- package/dist/safe-bash-query-engine/index.js +3 -3
- package/dist/safe-bash-query-engine/interpreter.js +2 -2
- package/dist/safe-bash-query-engine/query-core.js +3 -3
- package/package.json +2 -2
- package/dist/safe-bash/chunks/chunk-2G2T5MEM.js +0 -14
- package/dist/safe-bash/chunks/chunk-2MUJ7RLZ.js +0 -409
- package/dist/safe-bash/chunks/chunk-GJWUEOT6.js +0 -14
- package/dist/safe-bash/chunks/chunk-H7MMJS26.js +0 -37
- package/dist/safe-bash/chunks/chunk-LAPF2XE6.js +0 -14
- package/dist/safe-bash/chunks/chunk-S2LSZFZ6.js +0 -758
- package/dist/safe-bash/chunks/chunk-T3VDYWKZ.js +0 -21
- package/dist/safe-bash/chunks/chunk-VUVKC6HV.js +0 -81
- package/dist/safe-bash/chunks/chunk-VYW4Q6KF.js +0 -12
- package/dist/safe-bash/command-chunks/{chunk-BJ6DGYJA.js → chunk-KNI4GRXF.js} +3 -3
|
@@ -1,118 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
signal.throwIfAborted();
|
|
3
|
-
let onAbort;
|
|
4
|
-
const aborted = new Promise((_resolve, reject) => {
|
|
5
|
-
onAbort = () => reject(signal.reason);
|
|
6
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
7
|
-
});
|
|
8
|
-
try {
|
|
9
|
-
return await Promise.race([Promise.resolve().then(() => { signal.throwIfAborted(); return operation(); }), aborted]);
|
|
10
|
-
}
|
|
11
|
-
finally {
|
|
12
|
-
signal.removeEventListener("abort", onAbort);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export async function* streamElevenLabs(transport, request, limit = Infinity) {
|
|
16
|
-
const { signal } = request;
|
|
17
|
-
signal.throwIfAborted();
|
|
18
|
-
let iterator;
|
|
19
|
-
let finished = false;
|
|
20
|
-
let failed = false;
|
|
21
|
-
let closed = false;
|
|
22
|
-
let size = 0;
|
|
23
|
-
const cleanups = new Map();
|
|
24
|
-
const runCleanup = (entry) => {
|
|
25
|
-
return entry.pending ??= Promise.resolve().then(entry.run);
|
|
26
|
-
};
|
|
27
|
-
const register = (cleanup, receiver) => {
|
|
28
|
-
if (cleanups.has(cleanup))
|
|
29
|
-
return;
|
|
30
|
-
const entry = { run: () => cleanup.call(receiver) };
|
|
31
|
-
cleanups.set(cleanup, entry);
|
|
32
|
-
if (closed)
|
|
33
|
-
void runCleanup(entry).catch(() => { });
|
|
34
|
-
};
|
|
35
|
-
const dispose = async () => {
|
|
36
|
-
closed = true;
|
|
37
|
-
let seen = 0;
|
|
38
|
-
const failures = [];
|
|
39
|
-
while (seen < cleanups.size) {
|
|
40
|
-
const entries = [...cleanups.values()].slice(seen);
|
|
41
|
-
seen = cleanups.size;
|
|
42
|
-
const results = await Promise.allSettled(entries.map(runCleanup));
|
|
43
|
-
for (const result of results)
|
|
44
|
-
if (result.status === "rejected")
|
|
45
|
-
failures.push(result.reason);
|
|
46
|
-
}
|
|
47
|
-
if (failures.length)
|
|
48
|
-
throw failures[0];
|
|
49
|
-
};
|
|
50
|
-
const close = async () => {
|
|
51
|
-
const failures = [];
|
|
52
|
-
try {
|
|
53
|
-
await dispose();
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
failures.push(error);
|
|
57
|
-
}
|
|
58
|
-
if (!finished && iterator?.return) {
|
|
59
|
-
const closing = Promise.resolve().then(() => iterator.return());
|
|
60
|
-
if (signal.aborted)
|
|
61
|
-
void closing.catch(() => { });
|
|
62
|
-
else {
|
|
63
|
-
try {
|
|
64
|
-
await closing;
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
failures.push(error);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (!failed) {
|
|
72
|
-
signal.throwIfAborted();
|
|
73
|
-
if (failures.length)
|
|
74
|
-
throw failures[0];
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
const onAbort = () => { void dispose().catch(() => { }); };
|
|
78
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
79
|
-
try {
|
|
80
|
-
const acquired = await abortable(async () => {
|
|
81
|
-
signal.throwIfAborted();
|
|
82
|
-
const response = await transport({ ...request, registerCleanup: register });
|
|
83
|
-
register(response.dispose, response);
|
|
84
|
-
if (signal.aborted) {
|
|
85
|
-
await dispose();
|
|
86
|
-
signal.throwIfAborted();
|
|
87
|
-
}
|
|
88
|
-
return response;
|
|
89
|
-
}, signal);
|
|
90
|
-
signal.throwIfAborted();
|
|
91
|
-
if (acquired.status < 200 || acquired.status >= 300)
|
|
92
|
-
throw new Error(`ElevenLabs HTTP ${acquired.status}: ${acquired.statusText}`);
|
|
93
|
-
iterator = acquired.body[Symbol.asyncIterator]();
|
|
94
|
-
while (true) {
|
|
95
|
-
const next = await abortable(() => iterator.next(), signal);
|
|
96
|
-
signal.throwIfAborted();
|
|
97
|
-
if (next.done) {
|
|
98
|
-
finished = true;
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (!(next.value instanceof Uint8Array))
|
|
102
|
-
throw new TypeError("ElevenLabs audio stream must yield Uint8Array chunks");
|
|
103
|
-
size += next.value.byteLength;
|
|
104
|
-
if (size > limit)
|
|
105
|
-
throw new RangeError("Provider response byte limit exceeded");
|
|
106
|
-
yield Uint8Array.from(next.value);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
catch (error) {
|
|
110
|
-
failed = true;
|
|
111
|
-
throw error;
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
signal.removeEventListener("abort", onAbort);
|
|
115
|
-
await close();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
1
|
+
export * from "../../../safe-bash-command-llm/elevenlabs-stream.js";
|
|
118
2
|
//# sourceMappingURL=elevenlabs-stream.js.map
|
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { LlmModel, LlmProvider } from "./types.js";
|
|
3
|
-
import { type LlmProviderLimits } from "./providers/shared.js";
|
|
4
|
-
export interface ElevenLabsModel extends LlmModel {
|
|
5
|
-
readonly endpoint: "tts" | "music";
|
|
6
|
-
readonly defaultVoiceId?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface ElevenLabsProviderOptions {
|
|
9
|
-
readonly transport: HttpTransport;
|
|
10
|
-
readonly apiKey: string;
|
|
11
|
-
readonly baseUrl?: string;
|
|
12
|
-
readonly models: readonly ElevenLabsModel[];
|
|
13
|
-
readonly limits?: Partial<LlmProviderLimits>;
|
|
14
|
-
}
|
|
15
|
-
export declare function createElevenLabsProvider(options: ElevenLabsProviderOptions): LlmProvider;
|
|
1
|
+
export * from "../../../safe-bash-command-llm/elevenlabs.js";
|
|
16
2
|
//# sourceMappingURL=elevenlabs.d.ts.map
|
|
@@ -1,124 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { acceptsMimeType } from "./mime.js";
|
|
3
|
-
import { credential, providerLimits, jsonBody } from "./providers/shared.js";
|
|
4
|
-
const outputFormats = new Map([
|
|
5
|
-
["audio/mpeg", "mp3_44100_128"],
|
|
6
|
-
["audio/wav", "wav_44100"],
|
|
7
|
-
["audio/x-wav", "wav_44100"],
|
|
8
|
-
["audio/pcm", "pcm_44100"],
|
|
9
|
-
["audio/basic", "ulaw_8000"],
|
|
10
|
-
["audio/opus", "opus_48000_128"],
|
|
11
|
-
["audio/ogg", "opus_48000_128"],
|
|
12
|
-
]);
|
|
13
|
-
const optionTypes = {
|
|
14
|
-
tts: new Map([
|
|
15
|
-
["stability", "number"], ["similarity_boost", "number"], ["style", "number"],
|
|
16
|
-
["speed", "number"], ["use_speaker_boost", "boolean"],
|
|
17
|
-
]),
|
|
18
|
-
music: new Map([
|
|
19
|
-
["music_length_ms", "integer"], ["seed", "integer"], ["force_instrumental", "boolean"],
|
|
20
|
-
["respect_sections_durations", "boolean"], ["store_for_inpainting", "boolean"],
|
|
21
|
-
["sign_with_c2pa", "boolean"],
|
|
22
|
-
]),
|
|
23
|
-
};
|
|
24
|
-
function parseOptions(options, endpoint) {
|
|
25
|
-
return Object.fromEntries(Object.entries(options).map(([key, value]) => {
|
|
26
|
-
const type = optionTypes[endpoint].get(key);
|
|
27
|
-
if (!type)
|
|
28
|
-
return [key, value];
|
|
29
|
-
if (type === "boolean") {
|
|
30
|
-
if (typeof value === "boolean")
|
|
31
|
-
return [key, value];
|
|
32
|
-
if (value === "true" || value === "false")
|
|
33
|
-
return [key, value === "true"];
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const number = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : NaN;
|
|
37
|
-
if (Number.isFinite(number) && (type !== "integer" || Number.isSafeInteger(number)))
|
|
38
|
-
return [key, number];
|
|
39
|
-
}
|
|
40
|
-
throw new Error(`Invalid ElevenLabs option ${key}: expected ${type}`);
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
export function createElevenLabsProvider(options) {
|
|
44
|
-
const transport = options.transport;
|
|
45
|
-
if (typeof transport !== "function")
|
|
46
|
-
throw new TypeError("Provider transport is required");
|
|
47
|
-
const apiKey = credential(options.apiKey);
|
|
48
|
-
const limits = providerLimits(options.limits);
|
|
49
|
-
const baseUrl = new URL(options.baseUrl ?? "https://api.elevenlabs.io");
|
|
50
|
-
if (!["https:", "http:"].includes(baseUrl.protocol) || baseUrl.username || baseUrl.password || baseUrl.search || baseUrl.hash) {
|
|
51
|
-
throw new Error("Invalid ElevenLabs baseUrl: expected an HTTP(S) URL without credentials, query, or fragment");
|
|
52
|
-
}
|
|
53
|
-
if (!baseUrl.pathname.endsWith("/"))
|
|
54
|
-
baseUrl.pathname += "/";
|
|
55
|
-
const models = options.models.map(model => Object.freeze({
|
|
56
|
-
...model,
|
|
57
|
-
...(model.aliases === undefined ? {} : { aliases: Object.freeze([...model.aliases]) }),
|
|
58
|
-
...(model.attachmentTypes === undefined ? {} : { attachmentTypes: Object.freeze([...model.attachmentTypes]) }),
|
|
59
|
-
}));
|
|
60
|
-
const byId = new Map();
|
|
61
|
-
for (const model of models) {
|
|
62
|
-
if (model.endpoint !== "tts" && model.endpoint !== "music")
|
|
63
|
-
throw new Error(`Invalid ElevenLabs endpoint: ${model.endpoint}`);
|
|
64
|
-
if (!model.outputType)
|
|
65
|
-
throw new TypeError("ElevenLabs models require an audio outputType");
|
|
66
|
-
const mimeType = model.outputType.split(";", 1)[0].trim().toLowerCase();
|
|
67
|
-
const format = outputFormats.get(mimeType);
|
|
68
|
-
if (!format || !acceptsMimeType([mimeType], model.outputType) || (model.endpoint === "music" && format.startsWith("wav_"))) {
|
|
69
|
-
throw new Error(`Unsupported ElevenLabs outputType for ${model.endpoint}: ${model.outputType}`);
|
|
70
|
-
}
|
|
71
|
-
if (model.attachmentTypes?.length)
|
|
72
|
-
throw new Error(`ElevenLabs model ${model.id} does not accept attachments`);
|
|
73
|
-
if (!model.id || byId.has(model.id))
|
|
74
|
-
throw new Error(`Duplicate or empty ElevenLabs model: ${model.id}`);
|
|
75
|
-
byId.set(model.id, { model, format });
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
name: "elevenlabs",
|
|
79
|
-
models: Object.freeze(models),
|
|
80
|
-
async *complete(request) {
|
|
81
|
-
request.signal.throwIfAborted();
|
|
82
|
-
const entry = byId.get(request.model);
|
|
83
|
-
if (!entry)
|
|
84
|
-
throw new Error(`Unknown model: ${request.model}`);
|
|
85
|
-
const { model, format } = entry;
|
|
86
|
-
if (request.attachments.length)
|
|
87
|
-
throw new Error(`Model ${model.id} does not accept ${request.attachments[0].mimeType} attachments`);
|
|
88
|
-
if (request.messages?.length || request.schema !== undefined)
|
|
89
|
-
throw new TypeError("ElevenLabs reference endpoints do not accept messages or schemas");
|
|
90
|
-
if (request.system !== undefined)
|
|
91
|
-
throw new TypeError("ElevenLabs reference endpoints do not accept system prompts");
|
|
92
|
-
const { output_format: requestedFormat, ...requestOptions } = request.options;
|
|
93
|
-
if (requestedFormat !== undefined && requestedFormat !== format)
|
|
94
|
-
throw new TypeError("output_format conflicts with model outputType");
|
|
95
|
-
let path;
|
|
96
|
-
let body;
|
|
97
|
-
if (model.endpoint === "tts") {
|
|
98
|
-
const { voice_id: suppliedVoice, ...settings } = requestOptions;
|
|
99
|
-
const voice = suppliedVoice ?? model.defaultVoiceId;
|
|
100
|
-
if (typeof voice !== "string" || !voice.trim())
|
|
101
|
-
throw new Error(`ElevenLabs model ${model.id} requires voice_id or a configured defaultVoiceId`);
|
|
102
|
-
if (voice === "." || voice === "..")
|
|
103
|
-
throw new Error("Invalid ElevenLabs voice_id: dot segments are not allowed");
|
|
104
|
-
path = `v1/text-to-speech/${encodeURIComponent(voice)}`;
|
|
105
|
-
body = { text: request.prompt, model_id: model.id, voice_settings: parseOptions(settings, model.endpoint) };
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
path = "v1/music";
|
|
109
|
-
body = { ...parseOptions(requestOptions, model.endpoint), prompt: request.prompt, model_id: model.id };
|
|
110
|
-
}
|
|
111
|
-
const url = new URL(path, baseUrl);
|
|
112
|
-
url.searchParams.set("output_format", format);
|
|
113
|
-
const payload = jsonBody(body, limits.maxRequestBytes);
|
|
114
|
-
yield* streamElevenLabs(transport, {
|
|
115
|
-
url: url.href,
|
|
116
|
-
method: "POST",
|
|
117
|
-
headers: [["xi-api-key", apiKey], ...payload.headers, ["accept", model.outputType]],
|
|
118
|
-
body: payload.body,
|
|
119
|
-
signal: request.signal,
|
|
120
|
-
}, limits.maxResponseBytes);
|
|
121
|
-
},
|
|
122
|
-
};
|
|
123
|
-
}
|
|
1
|
+
export * from "../../../safe-bash-command-llm/elevenlabs.js";
|
|
124
2
|
//# sourceMappingURL=elevenlabs.js.map
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
+
createElevenLabsProvider,
|
|
3
|
+
createLlmCommand,
|
|
2
4
|
createLlmCommands,
|
|
5
|
+
createLlmConfiguration,
|
|
3
6
|
createLlmService,
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
createElevenLabsProvider,
|
|
14
|
-
createOpenAiProvider
|
|
15
|
-
} from "../../chunks/chunk-S2LSZFZ6.js";
|
|
16
|
-
import "../../chunks/chunk-LD76P7AG.js";
|
|
17
|
-
import "../../chunks/chunk-Q45QCA4J.js";
|
|
7
|
+
createLlmTemplateStore,
|
|
8
|
+
createOpenAiProvider,
|
|
9
|
+
evaluateLlmTemplate,
|
|
10
|
+
llmCommands,
|
|
11
|
+
parseLlmSchemaDsl,
|
|
12
|
+
validateLlmTemplateParameters,
|
|
13
|
+
validateModelOptions
|
|
14
|
+
} from "../../chunks/chunk-GAYRKQM6.js";
|
|
15
|
+
import "../../chunks/chunk-I3KSESCR.js";
|
|
18
16
|
export {
|
|
19
17
|
createElevenLabsProvider,
|
|
18
|
+
createLlmCommand,
|
|
20
19
|
createLlmCommands,
|
|
20
|
+
createLlmConfiguration,
|
|
21
21
|
createLlmService,
|
|
22
|
+
createLlmTemplateStore,
|
|
22
23
|
createOpenAiProvider,
|
|
23
|
-
|
|
24
|
+
evaluateLlmTemplate,
|
|
25
|
+
llmCommands,
|
|
26
|
+
parseLlmSchemaDsl,
|
|
27
|
+
validateLlmTemplateParameters,
|
|
28
|
+
validateModelOptions
|
|
24
29
|
};
|
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { createLlmService, type LlmService, type LlmServiceOptions, type LlmServiceModel, type LlmStreamEvent, type LlmServiceRequest } from "./service.js";
|
|
3
|
-
export type { LlmOption, LlmCapability, LlmResponseMetadata, LlmEmbeddingRequest, LlmEmbeddingResponse, LlmCommandsOptions, LlmProvider, LlmModel, LlmRequest } from "./types.js";
|
|
4
|
-
export { createOpenAiProvider, type OpenAiModel, type OpenAiProviderOptions } from "./openai.js";
|
|
5
|
-
export { createElevenLabsProvider, type ElevenLabsModel, type ElevenLabsProviderOptions } from "./elevenlabs.js";
|
|
6
|
-
export type { LlmProviderLimits } from "./providers/shared.js";
|
|
1
|
+
export * from "../../../safe-bash-command-llm/index.js";
|
|
7
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { createLlmService } from "./service.js";
|
|
3
|
-
export { createOpenAiProvider } from "./openai.js";
|
|
4
|
-
export { createElevenLabsProvider } from "./elevenlabs.js";
|
|
1
|
+
export * from "../../../safe-bash-command-llm/index.js";
|
|
5
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,137 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
const extensions = {
|
|
3
|
-
png: "image/png", jpg: "image/jpeg", jpeg: "image/jpeg", gif: "image/gif", webp: "image/webp",
|
|
4
|
-
avif: "image/avif", heic: "image/heic", heif: "image/heif", bmp: "image/bmp", tif: "image/tiff", tiff: "image/tiff", svg: "image/svg+xml",
|
|
5
|
-
mp3: "audio/mpeg", wav: "audio/wav", ogg: "audio/ogg", oga: "audio/ogg", opus: "audio/ogg", flac: "audio/flac", aac: "audio/aac", m4a: "audio/mp4", aiff: "audio/aiff",
|
|
6
|
-
mp4: "video/mp4", m4v: "video/mp4", mov: "video/quicktime", webm: "video/webm", mkv: "video/x-matroska", avi: "video/x-msvideo", ogv: "video/ogg", mpeg: "video/mpeg", mpg: "video/mpeg",
|
|
7
|
-
pdf: "application/pdf", json: "application/json", zip: "application/zip", gz: "application/gzip",
|
|
8
|
-
txt: "text/plain", md: "text/markdown", csv: "text/csv", html: "text/html", xml: "application/xml",
|
|
9
|
-
};
|
|
10
|
-
function ebmlInteger(bytes, offset, retainMarker = false) {
|
|
11
|
-
const first = bytes[offset];
|
|
12
|
-
if (!first)
|
|
13
|
-
return undefined;
|
|
14
|
-
let marker = 128, width = 1;
|
|
15
|
-
while (!(first & marker)) {
|
|
16
|
-
marker >>= 1;
|
|
17
|
-
width++;
|
|
18
|
-
}
|
|
19
|
-
if (offset + width > bytes.length)
|
|
20
|
-
return undefined;
|
|
21
|
-
let value = retainMarker ? first : first & (marker - 1);
|
|
22
|
-
for (let index = 1; index < width; index++)
|
|
23
|
-
value = value * 256 + bytes[offset + index];
|
|
24
|
-
if (!Number.isSafeInteger(value) || !retainMarker && value === 2 ** (7 * width) - 1)
|
|
25
|
-
return undefined;
|
|
26
|
-
return { value, width };
|
|
27
|
-
}
|
|
28
|
-
function ebmlMimeType(bytes) {
|
|
29
|
-
const header = ebmlInteger(bytes, 4);
|
|
30
|
-
if (!header)
|
|
31
|
-
return undefined;
|
|
32
|
-
let offset = 4 + header.width;
|
|
33
|
-
const end = Math.min(bytes.length, offset + header.value, 4096);
|
|
34
|
-
while (offset < end) {
|
|
35
|
-
const identifier = ebmlInteger(bytes, offset, true);
|
|
36
|
-
if (!identifier)
|
|
37
|
-
return undefined;
|
|
38
|
-
offset += identifier.width;
|
|
39
|
-
const size = ebmlInteger(bytes, offset);
|
|
40
|
-
if (!size)
|
|
41
|
-
return undefined;
|
|
42
|
-
offset += size.width;
|
|
43
|
-
if (size.value > end - offset)
|
|
44
|
-
return undefined;
|
|
45
|
-
if (identifier.value === 0x4282) {
|
|
46
|
-
const docType = new TextDecoder().decode(bytes.subarray(offset, offset + size.value)).split("\0", 1)[0];
|
|
47
|
-
if (docType === "webm")
|
|
48
|
-
return "video/webm";
|
|
49
|
-
if (docType === "matroska")
|
|
50
|
-
return "video/x-matroska";
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
offset += size.value;
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
export function sniffMimeType(path, bytes) {
|
|
58
|
-
const matches = (signature, offset = 0) => bytes.length >= offset + signature.length && signature.every((byte, index) => bytes[offset + index] === byte);
|
|
59
|
-
const ascii = (offset, text) => bytes.length >= offset + text.length && [...text].every((character, index) => bytes[offset + index] === character.charCodeAt(0));
|
|
60
|
-
if (matches([137, 80, 78, 71, 13, 10, 26, 10]))
|
|
61
|
-
return "image/png";
|
|
62
|
-
if (matches([255, 216, 255]))
|
|
63
|
-
return "image/jpeg";
|
|
64
|
-
if (ascii(0, "GIF87a") || ascii(0, "GIF89a"))
|
|
65
|
-
return "image/gif";
|
|
66
|
-
if (ascii(0, "RIFF")) {
|
|
67
|
-
if (ascii(8, "WEBP"))
|
|
68
|
-
return "image/webp";
|
|
69
|
-
if (ascii(8, "WAVE"))
|
|
70
|
-
return "audio/wav";
|
|
71
|
-
if (ascii(8, "AVI "))
|
|
72
|
-
return "video/x-msvideo";
|
|
73
|
-
}
|
|
74
|
-
if (ascii(0, "fLaC"))
|
|
75
|
-
return "audio/flac";
|
|
76
|
-
if (ascii(0, "OggS")) {
|
|
77
|
-
const packet = 27 + (bytes[26] ?? 0);
|
|
78
|
-
if (bytes[26] && bytes[packet] === 0x80 && ascii(packet + 1, "theora"))
|
|
79
|
-
return "video/ogg";
|
|
80
|
-
return "audio/ogg";
|
|
81
|
-
}
|
|
82
|
-
if (ascii(0, "ID3") || bytes.length >= 2 && bytes[0] === 255 && (bytes[1] & 0xe0) === 0xe0 && (bytes[1] & 0x06) !== 0)
|
|
83
|
-
return "audio/mpeg";
|
|
84
|
-
if (bytes.length >= 2 && bytes[0] === 255 && (bytes[1] & 0xf6) === 0xf0)
|
|
85
|
-
return "audio/aac";
|
|
86
|
-
if (ascii(0, "FORM") && (ascii(8, "AIFF") || ascii(8, "AIFC")))
|
|
87
|
-
return "audio/aiff";
|
|
88
|
-
if (ascii(4, "ftyp")) {
|
|
89
|
-
if (ascii(8, "avif") || ascii(8, "avis"))
|
|
90
|
-
return "image/avif";
|
|
91
|
-
if (ascii(8, "heic") || ascii(8, "heix"))
|
|
92
|
-
return "image/heic";
|
|
93
|
-
if (ascii(8, "mif1") || ascii(8, "msf1"))
|
|
94
|
-
return "image/heif";
|
|
95
|
-
if (ascii(8, "M4A ") || ascii(8, "M4B "))
|
|
96
|
-
return "audio/mp4";
|
|
97
|
-
if (ascii(8, "qt "))
|
|
98
|
-
return "video/quicktime";
|
|
99
|
-
return "video/mp4";
|
|
100
|
-
}
|
|
101
|
-
if (matches([0x1a, 0x45, 0xdf, 0xa3])) {
|
|
102
|
-
const mimeType = ebmlMimeType(bytes);
|
|
103
|
-
if (mimeType)
|
|
104
|
-
return mimeType;
|
|
105
|
-
}
|
|
106
|
-
if (ascii(0, "%PDF-"))
|
|
107
|
-
return "application/pdf";
|
|
108
|
-
if (matches([0x50, 0x4b, 3, 4]) || matches([0x50, 0x4b, 5, 6]))
|
|
109
|
-
return "application/zip";
|
|
110
|
-
if (matches([0x1f, 0x8b]))
|
|
111
|
-
return "application/gzip";
|
|
112
|
-
if (matches([0x49, 0x49, 42, 0]) || matches([0x4d, 0x4d, 0, 42]))
|
|
113
|
-
return "image/tiff";
|
|
114
|
-
if (ascii(0, "BM"))
|
|
115
|
-
return "image/bmp";
|
|
116
|
-
const prefix = bytes.subarray(0, 512);
|
|
117
|
-
const classified = classify(prefix, bytes.length <= prefix.length).mime;
|
|
118
|
-
if (!["application/octet-stream", "text/plain", "inode/x-empty"].includes(classified))
|
|
119
|
-
return classified;
|
|
120
|
-
const filename = path.slice(path.lastIndexOf("/") + 1);
|
|
121
|
-
const dot = filename.lastIndexOf(".");
|
|
122
|
-
const extension = dot < 0 ? "" : filename.slice(dot + 1).toLowerCase();
|
|
123
|
-
return Object.hasOwn(extensions, extension) ? extensions[extension] : classified === "inode/x-empty" ? "application/octet-stream" : classified;
|
|
124
|
-
}
|
|
125
|
-
export function acceptsMimeType(types, mimeType) {
|
|
126
|
-
if ([...mimeType].some(character => character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127))
|
|
127
|
-
return false;
|
|
128
|
-
const mime = mimeType.split(";", 1)[0].trim().toLowerCase();
|
|
129
|
-
const parts = mime.split("/");
|
|
130
|
-
if (parts.length !== 2 || parts.some(part => !part || [...part].some(character => !(character >= "a" && character <= "z" || character >= "0" && character <= "9" || "!#$%&'+-.^_`|~".includes(character)))))
|
|
131
|
-
return false;
|
|
132
|
-
return types.some(type => {
|
|
133
|
-
const accepted = type.toLowerCase();
|
|
134
|
-
return accepted === mime || accepted.endsWith("/*") && accepted.slice(0, -2) === parts[0];
|
|
135
|
-
});
|
|
136
|
-
}
|
|
1
|
+
export * from "../../../safe-bash-command-llm/mime.js";
|
|
137
2
|
//# sourceMappingURL=mime.js.map
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { HttpRequest, HttpResponse, HttpTransport } from "../network/types.js";
|
|
3
|
-
export declare function openAiAbortable<Value>(pending: PromiseLike<Value>, signal: AbortSignal): Promise<Value>;
|
|
4
|
-
export declare function openAiBytes(source: ByteSource, signal: AbortSignal, limit?: number): ByteSource;
|
|
5
|
-
export declare function openAiJson(response: HttpResponse, signal: AbortSignal, maxBytes?: number): Promise<Record<string, unknown>>;
|
|
6
|
-
export declare function openAiRecord(value: unknown): value is Record<string, unknown>;
|
|
7
|
-
export declare function openAiError(value: unknown): string | undefined;
|
|
8
|
-
export declare function openAiResponse(transport: HttpTransport, input: HttpRequest, maxResponseBytes: number): AsyncIterable<HttpResponse>;
|
|
1
|
+
export * from "../../../safe-bash-command-llm/openai-http.js";
|
|
9
2
|
//# sourceMappingURL=openai-http.d.ts.map
|
|
@@ -1,144 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
const abort = () => { signal.removeEventListener("abort", abort); reject(signal.reason); };
|
|
4
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
5
|
-
Promise.resolve(pending).then(value => {
|
|
6
|
-
signal.removeEventListener("abort", abort);
|
|
7
|
-
if (signal.aborted)
|
|
8
|
-
reject(signal.reason);
|
|
9
|
-
else
|
|
10
|
-
resolve(value);
|
|
11
|
-
}, error => {
|
|
12
|
-
signal.removeEventListener("abort", abort);
|
|
13
|
-
reject(signal.aborted ? signal.reason : error);
|
|
14
|
-
});
|
|
15
|
-
if (signal.aborted)
|
|
16
|
-
abort();
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
export async function* openAiBytes(source, signal, limit = Infinity) {
|
|
20
|
-
signal.throwIfAborted();
|
|
21
|
-
const iterator = source[Symbol.asyncIterator]();
|
|
22
|
-
let failed = false, finished = false;
|
|
23
|
-
let size = 0;
|
|
24
|
-
try {
|
|
25
|
-
while (true) {
|
|
26
|
-
signal.throwIfAborted();
|
|
27
|
-
const next = await openAiAbortable(iterator.next(), signal);
|
|
28
|
-
if (next.done) {
|
|
29
|
-
finished = true;
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (!(next.value instanceof Uint8Array))
|
|
33
|
-
throw new Error("OpenAI returned a non-byte response chunk");
|
|
34
|
-
size += next.value.byteLength;
|
|
35
|
-
if (size > limit)
|
|
36
|
-
throw new RangeError("Provider response byte limit exceeded");
|
|
37
|
-
yield Uint8Array.from(next.value);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
failed = true;
|
|
42
|
-
throw signal.aborted ? signal.reason : error;
|
|
43
|
-
}
|
|
44
|
-
finally {
|
|
45
|
-
if (!finished) {
|
|
46
|
-
const returned = Promise.resolve().then(() => iterator.return?.());
|
|
47
|
-
if (signal.aborted)
|
|
48
|
-
void returned.catch(() => undefined);
|
|
49
|
-
else
|
|
50
|
-
await openAiAbortable(returned, signal).catch(error => { if (!failed)
|
|
51
|
-
throw error; });
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
export async function openAiJson(response, signal, maxBytes = Infinity) {
|
|
56
|
-
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
57
|
-
let text = "", length = 0;
|
|
58
|
-
for await (const chunk of openAiBytes(response.body, signal, maxBytes)) {
|
|
59
|
-
length += chunk.byteLength;
|
|
60
|
-
if (length > maxBytes)
|
|
61
|
-
throw new Error("OpenAI JSON response exceeds buffer limit");
|
|
62
|
-
text += decoder.decode(chunk, { stream: true });
|
|
63
|
-
}
|
|
64
|
-
text += decoder.decode();
|
|
65
|
-
let value;
|
|
66
|
-
try {
|
|
67
|
-
value = JSON.parse(text);
|
|
68
|
-
}
|
|
69
|
-
catch {
|
|
70
|
-
throw new Error("OpenAI returned malformed JSON");
|
|
71
|
-
}
|
|
72
|
-
if (!openAiRecord(value))
|
|
73
|
-
throw new Error("OpenAI returned a non-object JSON response");
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
export function openAiRecord(value) {
|
|
77
|
-
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
78
|
-
}
|
|
79
|
-
export function openAiError(value) {
|
|
80
|
-
if (typeof value === "string" && value)
|
|
81
|
-
return value.slice(0, 1024);
|
|
82
|
-
if (openAiRecord(value) && typeof value.message === "string")
|
|
83
|
-
return value.message.slice(0, 1024);
|
|
84
|
-
return undefined;
|
|
85
|
-
}
|
|
86
|
-
export async function* openAiResponse(transport, input, maxResponseBytes) {
|
|
87
|
-
input.signal.throwIfAborted();
|
|
88
|
-
const cleanups = new Map();
|
|
89
|
-
let closed = false, failed = false;
|
|
90
|
-
const run = (cleanup) => {
|
|
91
|
-
cleanup.pending ??= Promise.resolve().then(cleanup.run);
|
|
92
|
-
return cleanup.pending;
|
|
93
|
-
};
|
|
94
|
-
const register = (cleanup, receiver) => {
|
|
95
|
-
if (cleanups.has(cleanup))
|
|
96
|
-
return;
|
|
97
|
-
const entry = { run: () => cleanup.call(receiver) };
|
|
98
|
-
cleanups.set(cleanup, entry);
|
|
99
|
-
if (closed)
|
|
100
|
-
void run(entry).catch(() => undefined);
|
|
101
|
-
};
|
|
102
|
-
const close = async () => {
|
|
103
|
-
closed = true;
|
|
104
|
-
const results = await Promise.allSettled([...cleanups.values()].map(run));
|
|
105
|
-
const rejected = results.find(result => result.status === "rejected");
|
|
106
|
-
if (rejected?.status === "rejected")
|
|
107
|
-
throw rejected.reason;
|
|
108
|
-
};
|
|
109
|
-
const abort = () => { void close().catch(() => undefined); };
|
|
110
|
-
input.signal.addEventListener("abort", abort, { once: true });
|
|
111
|
-
try {
|
|
112
|
-
const pending = Promise.resolve().then(() => {
|
|
113
|
-
input.signal.throwIfAborted();
|
|
114
|
-
return transport({ ...input, registerCleanup: register });
|
|
115
|
-
}).then(response => {
|
|
116
|
-
register(response.dispose, response);
|
|
117
|
-
return response;
|
|
118
|
-
});
|
|
119
|
-
const response = await openAiAbortable(pending, input.signal);
|
|
120
|
-
if (!Number.isInteger(response.status) || response.status < 200 || response.status >= 300) {
|
|
121
|
-
let detail;
|
|
122
|
-
try {
|
|
123
|
-
detail = openAiError((await openAiJson(response, input.signal, maxResponseBytes)).error);
|
|
124
|
-
}
|
|
125
|
-
catch {
|
|
126
|
-
input.signal.throwIfAborted();
|
|
127
|
-
}
|
|
128
|
-
throw new Error(`OpenAI HTTP ${response.status}${detail ? `: ${detail}` : ""}`);
|
|
129
|
-
}
|
|
130
|
-
yield response;
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
failed = true;
|
|
134
|
-
throw input.signal.aborted ? input.signal.reason : error;
|
|
135
|
-
}
|
|
136
|
-
finally {
|
|
137
|
-
input.signal.removeEventListener("abort", abort);
|
|
138
|
-
await close().catch(error => { if (!failed && !input.signal.aborted)
|
|
139
|
-
throw error; });
|
|
140
|
-
if (!failed)
|
|
141
|
-
input.signal.throwIfAborted();
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
export * from "../../../safe-bash-command-llm/openai-http.js";
|
|
144
2
|
//# sourceMappingURL=openai-http.js.map
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ByteSource } from "../../contracts/index.js";
|
|
3
|
-
export declare function openAiChat(source: ByteSource, signal: AbortSignal, limit?: number, responseLimit?: number): AsyncGenerator<string, LlmResponseMetadata>;
|
|
1
|
+
export * from "../../../safe-bash-command-llm/openai-sse.js";
|
|
4
2
|
//# sourceMappingURL=openai-sse.d.ts.map
|