poe-code 15.0.21 → 15.0.22
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/metafile.json +1 -1
- package/package.json +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-UO33SQJU.js → chunk-2PQ3XOCQ.js} +239 -2
- package/packages/safe-bash/dist/chunks/chunk-2PQ3XOCQ.js.map +7 -0
- package/packages/safe-bash/dist/chunks/{chunk-WISNTI7E.js → chunk-3Y5PKSHX.js} +7 -11
- package/packages/safe-bash/dist/chunks/{chunk-WISNTI7E.js.map → chunk-3Y5PKSHX.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-VY5N6O6I.js → chunk-BXVGCJXW.js} +108 -21
- package/packages/safe-bash/dist/chunks/chunk-BXVGCJXW.js.map +7 -0
- package/packages/safe-bash/dist/chunks/chunk-C7QNJ3D4.js +13 -0
- package/packages/safe-bash/dist/chunks/chunk-C7QNJ3D4.js.map +7 -0
- package/packages/safe-bash/dist/chunks/{chunk-AWP6Z3RR.js → chunk-E3NZKSTA.js} +8 -12
- package/packages/safe-bash/dist/chunks/{chunk-AWP6Z3RR.js.map → chunk-E3NZKSTA.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-WXUZXY35.js → chunk-FMTBJ7SG.js} +3 -3
- package/packages/safe-bash/dist/chunks/{chunk-QX2X5EC5.js → chunk-H6E6F5KJ.js} +7 -11
- package/packages/safe-bash/dist/chunks/{chunk-QX2X5EC5.js.map → chunk-H6E6F5KJ.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-IDJQT32M.js → chunk-HQCBEAFK.js} +7 -11
- package/packages/safe-bash/dist/chunks/{chunk-IDJQT32M.js.map → chunk-HQCBEAFK.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-4V3NGZAG.js → chunk-IYFB6VED.js} +6 -10
- package/packages/safe-bash/dist/chunks/{chunk-4V3NGZAG.js.map → chunk-IYFB6VED.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/chunk-KJYVSFGF.js +284 -0
- package/packages/safe-bash/dist/chunks/chunk-KJYVSFGF.js.map +7 -0
- package/packages/safe-bash/dist/chunks/{chunk-O7BRWSKX.js → chunk-LHKAA57T.js} +60 -17
- package/packages/safe-bash/dist/chunks/chunk-LHKAA57T.js.map +7 -0
- package/packages/safe-bash/dist/chunks/chunk-LR32SJ3D.js +915 -0
- package/packages/safe-bash/dist/chunks/chunk-LR32SJ3D.js.map +7 -0
- package/packages/safe-bash/dist/chunks/{chunk-EUNOVYVT.js → chunk-OECKXHVJ.js} +2 -2
- package/packages/safe-bash/dist/chunks/{chunk-DKT746UJ.js → chunk-PE5NZIA2.js} +5 -9
- package/packages/safe-bash/dist/chunks/{chunk-DKT746UJ.js.map → chunk-PE5NZIA2.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-4JW32W4B.js → chunk-PMBBUNNN.js} +7 -11
- package/packages/safe-bash/dist/chunks/{chunk-4JW32W4B.js.map → chunk-PMBBUNNN.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-YFFFBLBC.js → chunk-TJVKGNKA.js} +6 -10
- package/packages/safe-bash/dist/chunks/{chunk-YFFFBLBC.js.map → chunk-TJVKGNKA.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-FIY2BMTU.js → chunk-W3TLNFDB.js} +8 -12
- package/packages/safe-bash/dist/chunks/{chunk-FIY2BMTU.js.map → chunk-W3TLNFDB.js.map} +1 -1
- package/packages/safe-bash/dist/chunks/{chunk-PPFWG34Y.js → chunk-XBLVOMEJ.js} +2 -2
- package/packages/safe-bash/dist/chunks/{chunk-WJWYJDQE.js → chunk-XYVCXUGM.js} +7 -11
- package/packages/safe-bash/dist/chunks/{chunk-WJWYJDQE.js.map → chunk-XYVCXUGM.js.map} +1 -1
- package/packages/safe-bash/dist/commands/csplit/index.browser.js +4 -6
- package/packages/safe-bash/dist/commands/factor/index.browser.js +3 -5
- package/packages/safe-bash/dist/commands/getopt/index.browser.js +3 -5
- package/packages/safe-bash/dist/commands/hexdump/index.browser.js +3 -5
- package/packages/safe-bash/dist/commands/iconv/index.browser.js +3 -5
- package/packages/safe-bash/dist/commands/line-endings/index.browser.js +4 -6
- package/packages/safe-bash/dist/commands/llm/command.d.ts +3 -2
- package/packages/safe-bash/dist/commands/llm/command.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/llm/command.js +260 -181
- package/packages/safe-bash/dist/commands/llm/command.js.map +1 -1
- package/packages/safe-bash/dist/commands/llm/elevenlabs-stream.d.ts +3 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs-stream.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs-stream.js +118 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs-stream.js.map +1 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs.d.ts +16 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs.js +120 -0
- package/packages/safe-bash/dist/commands/llm/elevenlabs.js.map +1 -0
- package/packages/safe-bash/dist/commands/llm/index.browser.js +10 -4
- package/packages/safe-bash/dist/commands/llm/index.d.ts +5 -5
- package/packages/safe-bash/dist/commands/llm/index.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/llm/index.js +3 -11
- package/packages/safe-bash/dist/commands/llm/index.js.map +1 -1
- package/packages/safe-bash/dist/commands/llm/mime.d.ts +2 -1
- package/packages/safe-bash/dist/commands/llm/mime.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/llm/mime.js +125 -21
- package/packages/safe-bash/dist/commands/llm/mime.js.map +1 -1
- package/packages/safe-bash/dist/commands/llm/openai-http.d.ts +9 -0
- package/packages/safe-bash/dist/commands/llm/openai-http.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/llm/openai-http.js +144 -0
- package/packages/safe-bash/dist/commands/llm/openai-http.js.map +1 -0
- package/packages/safe-bash/dist/commands/llm/openai-sse.d.ts +3 -0
- package/packages/safe-bash/dist/commands/llm/openai-sse.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/llm/openai-sse.js +67 -0
- package/packages/safe-bash/dist/commands/llm/openai-sse.js.map +1 -0
- package/packages/safe-bash/dist/commands/llm/openai.d.ts +15 -0
- package/packages/safe-bash/dist/commands/llm/openai.d.ts.map +1 -0
- package/packages/safe-bash/dist/commands/llm/openai.js +203 -0
- package/packages/safe-bash/dist/commands/llm/openai.js.map +1 -0
- package/packages/safe-bash/dist/commands/llm/providers/elevenlabs.d.ts +1 -15
- package/packages/safe-bash/dist/commands/llm/providers/elevenlabs.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/llm/providers/elevenlabs.js +1 -50
- package/packages/safe-bash/dist/commands/llm/providers/elevenlabs.js.map +1 -1
- package/packages/safe-bash/dist/commands/llm/providers/index.browser.js +2 -4
- package/packages/safe-bash/dist/commands/llm/providers/openai.d.ts +1 -14
- package/packages/safe-bash/dist/commands/llm/providers/openai.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/llm/providers/openai.js +1 -77
- package/packages/safe-bash/dist/commands/llm/providers/openai.js.map +1 -1
- package/packages/safe-bash/dist/commands/llm/providers/shared.d.ts +4 -14
- package/packages/safe-bash/dist/commands/llm/providers/shared.d.ts.map +1 -1
- package/packages/safe-bash/dist/commands/llm/providers/shared.js +3 -156
- package/packages/safe-bash/dist/commands/llm/providers/shared.js.map +1 -1
- package/packages/safe-bash/dist/commands/network/index.browser.js +8 -13
- package/packages/safe-bash/dist/commands/pr/index.browser.js +3 -5
- package/packages/safe-bash/dist/commands/tsort/index.browser.js +3 -5
- package/packages/safe-bash/dist/commands/xml/index.browser.js +4 -7
- package/packages/safe-bash/dist/commands/yq/index.browser.js +5 -8
- package/packages/safe-bash/dist/core.browser.js +36 -43
- package/packages/safe-bash/dist/core.browser.js.map +1 -1
- package/packages/safe-bash/dist/chunks/chunk-BZUQJTOZ.js +0 -322
- package/packages/safe-bash/dist/chunks/chunk-BZUQJTOZ.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-EUTSYRNM.js +0 -111
- package/packages/safe-bash/dist/chunks/chunk-EUTSYRNM.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-F5AOPLRZ.js +0 -355
- package/packages/safe-bash/dist/chunks/chunk-F5AOPLRZ.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-FDGESHPB.js +0 -224
- package/packages/safe-bash/dist/chunks/chunk-FDGESHPB.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-KYU6MXVK.js +0 -58
- package/packages/safe-bash/dist/chunks/chunk-KYU6MXVK.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-O7BRWSKX.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-TTTOMUAY.js +0 -33
- package/packages/safe-bash/dist/chunks/chunk-TTTOMUAY.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-UO33SQJU.js.map +0 -7
- package/packages/safe-bash/dist/chunks/chunk-VY5N6O6I.js.map +0 -7
- /package/packages/safe-bash/dist/chunks/{chunk-WXUZXY35.js.map → chunk-FMTBJ7SG.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-EUNOVYVT.js.map → chunk-OECKXHVJ.js.map} +0 -0
- /package/packages/safe-bash/dist/chunks/{chunk-PPFWG34Y.js.map → chunk-XBLVOMEJ.js.map} +0 -0
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createOutputOperation
|
|
3
|
-
} from "./chunk-EUNOVYVT.js";
|
|
4
|
-
import {
|
|
5
|
-
resolvePath
|
|
6
|
-
} from "./chunk-DPJWEGIX.js";
|
|
7
|
-
import {
|
|
8
|
-
getCommandArguments
|
|
9
|
-
} from "./chunk-UO33SQJU.js";
|
|
10
|
-
import {
|
|
11
|
-
readBytes,
|
|
12
|
-
writeBytes,
|
|
13
|
-
yieldTurn
|
|
14
|
-
} from "./chunk-FDGESHPB.js";
|
|
15
|
-
import {
|
|
16
|
-
init_platform
|
|
17
|
-
} from "./chunk-2KL6W6NB.js";
|
|
18
|
-
|
|
19
|
-
// packages/safe-bash/src/commands/llm/index.ts
|
|
20
|
-
init_platform();
|
|
21
|
-
|
|
22
|
-
// packages/safe-bash/src/commands/llm/command.ts
|
|
23
|
-
init_platform();
|
|
24
|
-
|
|
25
|
-
// packages/safe-bash/src/commands/llm/mime.ts
|
|
26
|
-
init_platform();
|
|
27
|
-
|
|
28
|
-
// packages/safe-bash/src/commands/file/classify.ts
|
|
29
|
-
init_platform();
|
|
30
|
-
var binary = { description: "data", mime: "application/octet-stream", encoding: "binary" };
|
|
31
|
-
function result(description, mime, encoding = "binary") {
|
|
32
|
-
return { description, mime, encoding };
|
|
33
|
-
}
|
|
34
|
-
function matches(bytes, signature, offset = 0) {
|
|
35
|
-
return bytes.length >= offset + signature.length && signature.every((value, index) => bytes[offset + index] === value);
|
|
36
|
-
}
|
|
37
|
-
function ascii(bytes, start, length) {
|
|
38
|
-
return String.fromCharCode(...bytes.subarray(start, start + length));
|
|
39
|
-
}
|
|
40
|
-
function magic(bytes) {
|
|
41
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
42
|
-
if (bytes.length >= 33 && matches(bytes, [137, 80, 78, 71, 13, 10, 26, 10]) && view.getUint32(8) === 13 && ascii(bytes, 12, 4) === "IHDR" && view.getUint32(16) > 0 && view.getUint32(20) > 0 && bytes[26] === 0 && bytes[27] === 0 && bytes[28] <= 1) {
|
|
43
|
-
const allowed = { 0: [1, 2, 4, 8, 16], 2: [8, 16], 3: [1, 2, 4, 8], 4: [8, 16], 6: [8, 16] };
|
|
44
|
-
if (allowed[bytes[25]]?.includes(bytes[24])) return result("PNG image data", "image/png");
|
|
45
|
-
}
|
|
46
|
-
if (bytes.length >= 13 && ["GIF87a", "GIF89a"].includes(ascii(bytes, 0, 6)) && view.getUint16(6, true) > 0 && view.getUint16(8, true) > 0) return result("GIF image data", "image/gif");
|
|
47
|
-
if (bytes.length >= 4 && matches(bytes, [255, 216, 255]) && bytes[3] >= 192 && bytes[3] <= 254) return result("JPEG image data", "image/jpeg");
|
|
48
|
-
if (bytes.length >= 20 && ascii(bytes, 0, 4) === "RIFF" && ascii(bytes, 8, 4) === "WEBP" && ["VP8 ", "VP8L", "VP8X"].includes(ascii(bytes, 12, 4)) && view.getUint32(4, true) >= 12) return result("WebP image data", "image/webp");
|
|
49
|
-
if (bytes.length >= 8 && (matches(bytes, [73, 73, 42, 0]) || matches(bytes, [77, 77, 0, 42]))) return result("TIFF image data", "image/tiff");
|
|
50
|
-
if (bytes.length >= 26 && ascii(bytes, 0, 2) === "BM" && [12, 40, 52, 56, 108, 124].includes(view.getUint32(14, true))) return result("PC bitmap image data", "image/bmp");
|
|
51
|
-
if (bytes.length >= 22 && matches(bytes, [0, 0, 1, 0]) && view.getUint16(4, true) > 0) return result("MS Windows icon resource", "image/vnd.microsoft.icon");
|
|
52
|
-
if (/^%PDF-[12]\.[0-9](?:\r|\n|\s)/u.test(ascii(bytes, 0, 16))) return result("PDF document", "application/pdf");
|
|
53
|
-
if (bytes.length >= 10 && matches(bytes, [31, 139, 8]) && (bytes[3] & 224) === 0) return result("gzip compressed data", "application/gzip");
|
|
54
|
-
if (bytes.length >= 10 && ascii(bytes, 0, 3) === "BZh" && bytes[3] >= 49 && bytes[3] <= 57 && (ascii(bytes, 4, 6) === "1AY&SY" || matches(bytes, [23, 114, 69, 56, 80, 144], 4))) return result("bzip2 compressed data", "application/x-bzip2");
|
|
55
|
-
if (bytes.length >= 12 && matches(bytes, [253, 55, 122, 88, 90, 0]) && bytes[6] === 0 && bytes[7] <= 15) return result("XZ compressed data", "application/x-xz");
|
|
56
|
-
if (bytes.length >= 6 && matches(bytes, [40, 181, 47, 253]) && (bytes[4] & 24) === 0) return result("Zstandard compressed data", "application/zstd");
|
|
57
|
-
if (bytes.length >= 30 && matches(bytes, [80, 75, 3, 4]) || bytes.length >= 22 && matches(bytes, [80, 75, 5, 6])) return result("Zip archive data", "application/zip");
|
|
58
|
-
if (bytes.length >= 32 && matches(bytes, [55, 122, 188, 175, 39, 28])) return result("7-zip archive data", "application/x-7z-compressed");
|
|
59
|
-
if (bytes.length >= 14 && matches(bytes, [82, 97, 114, 33, 26, 7, 0]) || bytes.length >= 16 && matches(bytes, [82, 97, 114, 33, 26, 7, 1, 0])) return result("RAR archive data", "application/x-rar");
|
|
60
|
-
if (bytes.length >= 512 && ascii(bytes, 257, 5) === "ustar") {
|
|
61
|
-
const checksum = ascii(bytes, 148, 8).replace(/\0.*$/u, "").trim();
|
|
62
|
-
if (/^[0-7]+$/u.test(checksum)) {
|
|
63
|
-
let total = 0;
|
|
64
|
-
for (let index = 0; index < 512; index++) total += index >= 148 && index < 156 ? 32 : bytes[index];
|
|
65
|
-
if (parseInt(checksum, 8) === total) return result("POSIX tar archive", "application/x-tar");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
if (bytes.length >= 52 && matches(bytes, [127, 69, 76, 70]) && [1, 2].includes(bytes[4]) && [1, 2].includes(bytes[5]) && bytes[6] === 1 && (bytes[4] === 1 || bytes.length >= 64)) {
|
|
69
|
-
const type = view.getUint16(16, bytes[5] === 1);
|
|
70
|
-
const mime = type === 1 ? "application/x-object" : type === 2 ? "application/x-executable" : type === 3 ? "application/x-sharedlib" : "application/octet-stream";
|
|
71
|
-
return result(`ELF ${bytes[4] === 1 ? "32" : "64"}-bit ${type === 2 ? "executable" : type === 3 ? "shared object" : "object"}`, mime);
|
|
72
|
-
}
|
|
73
|
-
if (bytes.length >= 64 && ascii(bytes, 0, 2) === "MZ") {
|
|
74
|
-
const offset = view.getUint32(60, true);
|
|
75
|
-
if (offset >= 64 && offset <= bytes.length - 24 && matches(bytes, [80, 69, 0, 0], offset)) return result("PE executable", "application/vnd.microsoft.portable-executable");
|
|
76
|
-
return result("DOS executable", "application/x-dosexec");
|
|
77
|
-
}
|
|
78
|
-
if (bytes.length >= 8 && matches(bytes, [0, 97, 115, 109, 1, 0, 0, 0])) return result("WebAssembly binary module", "application/wasm");
|
|
79
|
-
if (bytes.length >= 100 && ascii(bytes, 0, 16) === "SQLite format 3\0") {
|
|
80
|
-
const size = view.getUint16(16);
|
|
81
|
-
if ((size === 1 || size >= 512 && size <= 32768 && (size & size - 1) === 0) && [1, 2].includes(bytes[18]) && [1, 2].includes(bytes[19]) && matches(bytes, [64, 32, 32], 21)) return result("SQLite 3.x database", "application/vnd.sqlite3");
|
|
82
|
-
}
|
|
83
|
-
if (bytes.length >= 512 && matches(bytes, [208, 207, 17, 224, 161, 177, 26, 225]) && matches(bytes, [254, 255], 28)) return result("OLE Compound Document", "application/x-ole-storage");
|
|
84
|
-
return void 0;
|
|
85
|
-
}
|
|
86
|
-
function classify(bytes, complete) {
|
|
87
|
-
if (!bytes.length) return complete ? result("empty", "inode/x-empty") : binary;
|
|
88
|
-
const recognized = magic(bytes);
|
|
89
|
-
if (recognized) return recognized;
|
|
90
|
-
if (matches(bytes, [255, 254, 0, 0]) || matches(bytes, [0, 0, 254, 255])) return binary;
|
|
91
|
-
let encoding = "utf-8";
|
|
92
|
-
let bom = 0;
|
|
93
|
-
if (matches(bytes, [239, 187, 191])) bom = 3;
|
|
94
|
-
else if (matches(bytes, [255, 254])) {
|
|
95
|
-
encoding = "utf-16le";
|
|
96
|
-
bom = 2;
|
|
97
|
-
} else if (matches(bytes, [254, 255])) {
|
|
98
|
-
encoding = "utf-16be";
|
|
99
|
-
bom = 2;
|
|
100
|
-
}
|
|
101
|
-
let text;
|
|
102
|
-
try {
|
|
103
|
-
text = new TextDecoder(encoding, { fatal: true }).decode(bytes, { stream: !complete });
|
|
104
|
-
} catch {
|
|
105
|
-
return binary;
|
|
106
|
-
}
|
|
107
|
-
if (!text.length && bytes.length > bom) return binary;
|
|
108
|
-
for (const character of text) {
|
|
109
|
-
const code = character.codePointAt(0);
|
|
110
|
-
if (code < 32 && ![8, 9, 10, 12, 13, 27].includes(code) || code >= 127 && code <= 159) return binary;
|
|
111
|
-
}
|
|
112
|
-
if (!bom && encoding === "utf-8" && bytes.every((value) => value < 128)) encoding = "us-ascii";
|
|
113
|
-
if (complete && /^[\x20\t\r\n]*(?:\{|\[)/u.test(text)) {
|
|
114
|
-
try {
|
|
115
|
-
JSON.parse(text);
|
|
116
|
-
return result("JSON text data", "application/json", encoding);
|
|
117
|
-
} catch {
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
const description = encoding === "us-ascii" ? "ASCII text" : encoding === "utf-8" ? "Unicode text, UTF-8" : `Unicode text, ${encoding === "utf-16le" ? "UTF-16, little-endian" : "UTF-16, big-endian"}`;
|
|
121
|
-
return result(description, "text/plain", encoding);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// packages/safe-bash/src/commands/llm/mime.ts
|
|
125
|
-
var extensions = {
|
|
126
|
-
png: "image/png",
|
|
127
|
-
jpg: "image/jpeg",
|
|
128
|
-
jpeg: "image/jpeg",
|
|
129
|
-
gif: "image/gif",
|
|
130
|
-
webp: "image/webp",
|
|
131
|
-
svg: "image/svg+xml",
|
|
132
|
-
mp3: "audio/mpeg",
|
|
133
|
-
wav: "audio/wav",
|
|
134
|
-
ogg: "audio/ogg",
|
|
135
|
-
flac: "audio/flac",
|
|
136
|
-
m4a: "audio/mp4",
|
|
137
|
-
aac: "audio/aac",
|
|
138
|
-
mp4: "video/mp4",
|
|
139
|
-
mov: "video/quicktime",
|
|
140
|
-
webm: "video/webm",
|
|
141
|
-
mkv: "video/x-matroska",
|
|
142
|
-
avi: "video/x-msvideo",
|
|
143
|
-
pdf: "application/pdf",
|
|
144
|
-
txt: "text/plain",
|
|
145
|
-
json: "application/json",
|
|
146
|
-
csv: "text/csv"
|
|
147
|
-
};
|
|
148
|
-
function attachmentMime(bytes, path) {
|
|
149
|
-
const prefix = bytes.subarray(0, 512);
|
|
150
|
-
const ascii2 = (offset, length) => String.fromCharCode(...prefix.subarray(offset, offset + length));
|
|
151
|
-
if (prefix.length >= 7 && prefix[0] === 255 && (prefix[1] & 246) === 240) return "audio/aac";
|
|
152
|
-
if (ascii2(0, 3) === "ID3" || prefix[0] === 255 && (prefix[1] & 224) === 224 && (prefix[1] & 6) !== 0) return "audio/mpeg";
|
|
153
|
-
if (ascii2(0, 4) === "fLaC") return "audio/flac";
|
|
154
|
-
if (ascii2(0, 4) === "OggS") return "audio/ogg";
|
|
155
|
-
if (ascii2(0, 4) === "RIFF") {
|
|
156
|
-
if (ascii2(8, 4) === "WAVE") return "audio/wav";
|
|
157
|
-
if (ascii2(8, 4) === "AVI ") return "video/x-msvideo";
|
|
158
|
-
}
|
|
159
|
-
if (ascii2(4, 4) === "ftyp") return ascii2(8, 4) === "M4A " ? "audio/mp4" : ascii2(8, 4) === "qt " ? "video/quicktime" : "video/mp4";
|
|
160
|
-
const classified = classify(prefix, bytes.length <= prefix.length).mime;
|
|
161
|
-
if (!["application/octet-stream", "text/plain", "inode/x-empty"].includes(classified)) return classified;
|
|
162
|
-
const extension = path.slice(path.lastIndexOf(".") + 1).toLowerCase();
|
|
163
|
-
return Object.hasOwn(extensions, extension) ? extensions[extension] : classified === "inode/x-empty" ? "application/octet-stream" : classified;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// packages/safe-bash/src/commands/llm/command.ts
|
|
167
|
-
var maxBytes = 64 * 1024 * 1024;
|
|
168
|
-
function createCommand(options) {
|
|
169
|
-
const models = /* @__PURE__ */ new Map();
|
|
170
|
-
const declarations = [];
|
|
171
|
-
for (const provider of options.providers) {
|
|
172
|
-
if (!provider.name || typeof provider.complete !== "function") throw new TypeError("Invalid LLM provider");
|
|
173
|
-
for (const source of provider.models) {
|
|
174
|
-
const model = { ...source, ...source.aliases ? { aliases: [...source.aliases] } : {}, ...source.attachmentTypes ? { attachmentTypes: [...source.attachmentTypes] } : {} };
|
|
175
|
-
const entry = { provider, model };
|
|
176
|
-
for (const name of [model.id, ...model.aliases ?? []]) {
|
|
177
|
-
if (!name) throw new TypeError("Model names must be nonempty");
|
|
178
|
-
if (models.has(name)) throw new Error(`Duplicate model: ${name}`);
|
|
179
|
-
models.set(name, entry);
|
|
180
|
-
}
|
|
181
|
-
declarations.push(entry);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return { name: "llm", description: "Query explicitly injected language and media models", async execute(context) {
|
|
185
|
-
const output = createOutputOperation(context, context.stdout);
|
|
186
|
-
const signal = output.signal;
|
|
187
|
-
let iterator;
|
|
188
|
-
let closed = false;
|
|
189
|
-
let ended = false;
|
|
190
|
-
output.registerCleanup(() => {
|
|
191
|
-
if (closed) return;
|
|
192
|
-
closed = true;
|
|
193
|
-
if (!ended && iterator?.return) {
|
|
194
|
-
const returned = Promise.resolve().then(() => iterator.return());
|
|
195
|
-
void returned.catch(() => {
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
});
|
|
199
|
-
const wait = (pending) => new Promise((resolve, reject) => {
|
|
200
|
-
const abort = () => reject(signal.reason);
|
|
201
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
202
|
-
if (signal.aborted) abort();
|
|
203
|
-
Promise.resolve(pending).then((value) => {
|
|
204
|
-
signal.removeEventListener("abort", abort);
|
|
205
|
-
resolve(value);
|
|
206
|
-
}, (error) => {
|
|
207
|
-
signal.removeEventListener("abort", abort);
|
|
208
|
-
reject(error);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
let inputBytes = 0;
|
|
212
|
-
let argumentBytes = 0;
|
|
213
|
-
let work = 0;
|
|
214
|
-
const step = async () => {
|
|
215
|
-
signal.throwIfAborted();
|
|
216
|
-
if (closed) throw new Error("LLM invocation is closed");
|
|
217
|
-
if (++work > 1e6) throw new Error("LLM work limit exceeded");
|
|
218
|
-
if (work % 256 === 0) await yieldTurn(signal);
|
|
219
|
-
};
|
|
220
|
-
const admit = (bytes) => {
|
|
221
|
-
context.inputBudget?.check(inputBytes + bytes);
|
|
222
|
-
if (bytes > maxBytes - inputBytes) throw new Error("LLM input byte limit exceeded");
|
|
223
|
-
inputBytes += bytes;
|
|
224
|
-
};
|
|
225
|
-
const emitText = async (text) => {
|
|
226
|
-
for (let offset = 0; offset < text.length; ) {
|
|
227
|
-
await step();
|
|
228
|
-
let end = Math.min(text.length, offset + 16384);
|
|
229
|
-
if (end < text.length && text.charCodeAt(end - 1) >= 55296 && text.charCodeAt(end - 1) <= 56319) end--;
|
|
230
|
-
await output.output.write(new TextEncoder().encode(text.slice(offset, end)));
|
|
231
|
-
offset = end;
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
try {
|
|
235
|
-
const args = getCommandArguments(context);
|
|
236
|
-
const text = (index) => {
|
|
237
|
-
const bytes = args.bytes(index);
|
|
238
|
-
if (!bytes) throw new Error("Missing option argument");
|
|
239
|
-
if (bytes.length > maxBytes - argumentBytes) throw new Error("LLM argument byte limit exceeded");
|
|
240
|
-
argumentBytes += bytes.length;
|
|
241
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
242
|
-
};
|
|
243
|
-
const positional = [];
|
|
244
|
-
const files = [];
|
|
245
|
-
const settings = /* @__PURE__ */ Object.create(null);
|
|
246
|
-
let modelName = options.defaultModel;
|
|
247
|
-
let system;
|
|
248
|
-
let operands = false;
|
|
249
|
-
for (let index = 0; index < args.args.length; index++) {
|
|
250
|
-
await step();
|
|
251
|
-
const arg = text(index);
|
|
252
|
-
if (!operands && arg === "--") {
|
|
253
|
-
operands = true;
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
if (!operands && ["-m", "--model"].includes(arg)) modelName = text(++index);
|
|
257
|
-
else if (!operands && ["-s", "--system"].includes(arg)) system = text(++index);
|
|
258
|
-
else if (!operands && ["-o", "--option"].includes(arg)) {
|
|
259
|
-
const key = text(++index);
|
|
260
|
-
settings[key] = text(++index);
|
|
261
|
-
} else if (!operands && ["-a", "--attachment", "--at"].includes(arg)) {
|
|
262
|
-
const path = text(++index);
|
|
263
|
-
files.push(arg === "--at" ? { path, mime: text(++index) } : { path });
|
|
264
|
-
} else if (!operands && arg.startsWith("-")) throw new Error(`Unknown option: ${arg}`);
|
|
265
|
-
else positional.push(arg);
|
|
266
|
-
}
|
|
267
|
-
if (args.args[0] === "models" && positional.length === 1 && !files.length) {
|
|
268
|
-
for (const { provider, model } of declarations) {
|
|
269
|
-
await step();
|
|
270
|
-
await emitText(`${provider.name}/${model.id} aliases: ${(model.aliases ?? []).join(", ")} attachments: ${(model.attachmentTypes ?? []).join(", ")} output: ${model.outputType ?? "text/plain"}
|
|
271
|
-
`);
|
|
272
|
-
}
|
|
273
|
-
return { exitCode: 0 };
|
|
274
|
-
}
|
|
275
|
-
const selected = modelName === void 0 ? void 0 : models.get(modelName);
|
|
276
|
-
if (!selected) throw new Error(`Unknown model: ${modelName ?? "(no default model)"}`);
|
|
277
|
-
const chunks = [];
|
|
278
|
-
let stdinBytes = 0;
|
|
279
|
-
for await (const bytes of readBytes(context.stdin, signal)) {
|
|
280
|
-
await step();
|
|
281
|
-
admit(bytes.length);
|
|
282
|
-
stdinBytes += bytes.length;
|
|
283
|
-
chunks.push(new Uint8Array(bytes));
|
|
284
|
-
}
|
|
285
|
-
const stdin = new Uint8Array(stdinBytes);
|
|
286
|
-
let offset = 0;
|
|
287
|
-
for (const bytes of chunks) {
|
|
288
|
-
stdin.set(bytes, offset);
|
|
289
|
-
offset += bytes.length;
|
|
290
|
-
}
|
|
291
|
-
const content = new TextDecoder("utf-8", { fatal: true }).decode(stdin);
|
|
292
|
-
const instruction = positional.join(" ");
|
|
293
|
-
const attachments = [];
|
|
294
|
-
for (const file of files) {
|
|
295
|
-
await step();
|
|
296
|
-
const path = resolvePath(context.cwd, file.path);
|
|
297
|
-
const stat = await wait(context.fs.stat(path, { signal }));
|
|
298
|
-
context.inputBudget?.check(inputBytes + stat.size);
|
|
299
|
-
if (stat.size > maxBytes - inputBytes) throw new Error("LLM input byte limit exceeded");
|
|
300
|
-
const bytes = await wait(context.fs.readFile(path, { signal, maxBytes: Math.min(maxBytes, context.inputBudget?.maxBytes ?? maxBytes) - inputBytes }));
|
|
301
|
-
signal.throwIfAborted();
|
|
302
|
-
admit(bytes.length);
|
|
303
|
-
const mimeType = file.mime ?? attachmentMime(bytes, file.path);
|
|
304
|
-
if (!selected.model.attachmentTypes?.some((type) => type === mimeType || type.endsWith("/*") && mimeType.startsWith(type.slice(0, -1)))) throw new Error(`Model ${selected.model.id} does not accept ${mimeType}`);
|
|
305
|
-
attachments.push({ mimeType, bytes: new Uint8Array(bytes) });
|
|
306
|
-
}
|
|
307
|
-
const request = { model: selected.model.id, prompt: content && instruction ? `${content}
|
|
308
|
-
|
|
309
|
-
${instruction}` : content || instruction, attachments, options: settings, signal, ...system === void 0 ? {} : { system } };
|
|
310
|
-
signal.throwIfAborted();
|
|
311
|
-
iterator = selected.provider.complete(request)[Symbol.asyncIterator]();
|
|
312
|
-
const binary2 = !(selected.model.outputType ?? "text/plain").startsWith("text/");
|
|
313
|
-
while (true) {
|
|
314
|
-
await step();
|
|
315
|
-
const next = await wait(iterator.next());
|
|
316
|
-
signal.throwIfAborted();
|
|
317
|
-
if (next.done) {
|
|
318
|
-
ended = true;
|
|
319
|
-
break;
|
|
320
|
-
}
|
|
321
|
-
if (binary2 ? !(next.value instanceof Uint8Array) : typeof next.value !== "string") throw new Error("Invalid provider response: mixed text and binary chunks or wrong output type");
|
|
322
|
-
if (typeof next.value === "string") await emitText(next.value);
|
|
323
|
-
else await output.output.write(next.value);
|
|
324
|
-
}
|
|
325
|
-
if (!binary2) await output.output.write(new Uint8Array([10]));
|
|
326
|
-
return { exitCode: 0 };
|
|
327
|
-
} catch (error) {
|
|
328
|
-
context.signal.throwIfAborted();
|
|
329
|
-
signal.throwIfAborted();
|
|
330
|
-
await writeBytes(context.stderr, new TextEncoder().encode(`llm: ${error instanceof Error ? error.message.slice(0, 4096) : "Provider failed"}
|
|
331
|
-
`), context.signal);
|
|
332
|
-
return { exitCode: 1 };
|
|
333
|
-
} finally {
|
|
334
|
-
await output.close();
|
|
335
|
-
}
|
|
336
|
-
} };
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
// packages/safe-bash/src/commands/llm/index.ts
|
|
340
|
-
function createLlmCommands(options) {
|
|
341
|
-
return [createCommand(options)];
|
|
342
|
-
}
|
|
343
|
-
function llmCommands(options) {
|
|
344
|
-
const commands = createLlmCommands(options);
|
|
345
|
-
return { name: "llm-commands", setup(host) {
|
|
346
|
-
for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });
|
|
347
|
-
} };
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export {
|
|
351
|
-
classify,
|
|
352
|
-
createLlmCommands,
|
|
353
|
-
llmCommands
|
|
354
|
-
};
|
|
355
|
-
//# sourceMappingURL=chunk-F5AOPLRZ.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/commands/llm/index.ts", "../../src/commands/llm/command.ts", "../../src/commands/llm/mime.ts", "../../src/commands/file/classify.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CommandDefinition, VirtualShellPlugin } from \"../../contracts/index.js\";\nimport { createCommand } from \"./command.js\";\nimport type { LlmCommandsOptions } from \"./types.js\";\nexport type { LlmProvider, LlmModel, LlmRequest, LlmCommandsOptions } from \"./types.js\";\n\nexport function createLlmCommands(options: LlmCommandsOptions): readonly CommandDefinition[] {\n return [createCommand(options)];\n}\n\nexport function llmCommands(options: LlmCommandsOptions): VirtualShellPlugin {\n const commands = createLlmCommands(options);\n return { name: \"llm-commands\", setup(host) {\n for (const command of commands) host.commands.register(command, { replace: options.replace ?? false });\n } };\n}\n", "import { createOutputOperation, getCommandArguments, readBytes, resolvePath, writeBytes, type CommandDefinition } from \"../../contracts/index.js\";\nimport { yieldTurn } from \"../../contracts/yield.js\";\nimport { attachmentMime } from \"./mime.js\";\nimport type { LlmCommandsOptions, LlmModel, LlmProvider, LlmRequest } from \"./types.js\";\n\nconst maxBytes = 64 * 1024 * 1024;\n\nexport function createCommand(options: LlmCommandsOptions): CommandDefinition {\n const models = new Map<string, { provider: LlmProvider; model: LlmModel }>();\n const declarations: { provider: LlmProvider; model: LlmModel }[] = [];\n for (const provider of options.providers) {\n if (!provider.name || typeof provider.complete !== \"function\") throw new TypeError(\"Invalid LLM provider\");\n for (const source of provider.models) {\n const model: LlmModel = { ...source, ...(source.aliases ? { aliases: [...source.aliases] } : {}), ...(source.attachmentTypes ? { attachmentTypes: [...source.attachmentTypes] } : {}) };\n const entry = { provider, model };\n for (const name of [model.id, ...(model.aliases ?? [])]) {\n if (!name) throw new TypeError(\"Model names must be nonempty\");\n if (models.has(name)) throw new Error(`Duplicate model: ${name}`);\n models.set(name, entry);\n }\n declarations.push(entry);\n }\n }\n return { name: \"llm\", description: \"Query explicitly injected language and media models\", async execute(context) {\n const output = createOutputOperation(context, context.stdout);\n const signal = output.signal;\n let iterator: AsyncIterator<string | Uint8Array> | undefined;\n let closed = false;\n let ended = false;\n output.registerCleanup(() => {\n if (closed) return;\n closed = true;\n if (!ended && iterator?.return) {\n const returned = Promise.resolve().then(() => iterator!.return!());\n void returned.catch(() => {});\n }\n });\n const wait = <Value>(pending: PromiseLike<Value>): Promise<Value> => new Promise((resolve, reject) => {\n const abort = () => reject(signal.reason);\n signal.addEventListener(\"abort\", abort, { once: true });\n if (signal.aborted) abort();\n Promise.resolve(pending).then(value => {\n signal.removeEventListener(\"abort\", abort); resolve(value);\n }, error => { signal.removeEventListener(\"abort\", abort); reject(error); });\n });\n let inputBytes = 0;\n let argumentBytes = 0;\n let work = 0;\n const step = async () => {\n signal.throwIfAborted();\n if (closed) throw new Error(\"LLM invocation is closed\");\n if (++work > 1_000_000) throw new Error(\"LLM work limit exceeded\");\n if (work % 256 === 0) await yieldTurn(signal);\n };\n const admit = (bytes: number) => {\n context.inputBudget?.check(inputBytes + bytes);\n if (bytes > maxBytes - inputBytes) throw new Error(\"LLM input byte limit exceeded\");\n inputBytes += bytes;\n };\n const emitText = async (text: string) => {\n for (let offset = 0; offset < text.length;) {\n await step();\n let end = Math.min(text.length, offset + 16_384);\n if (end < text.length && text.charCodeAt(end - 1) >= 0xd800 && text.charCodeAt(end - 1) <= 0xdbff) end--;\n await output.output.write(new TextEncoder().encode(text.slice(offset, end)));\n offset = end;\n }\n };\n try {\n const args = getCommandArguments(context);\n const text = (index: number): string => {\n const bytes = args.bytes(index);\n if (!bytes) throw new Error(\"Missing option argument\");\n if (bytes.length > maxBytes - argumentBytes) throw new Error(\"LLM argument byte limit exceeded\");\n argumentBytes += bytes.length;\n return new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes);\n };\n const positional: string[] = [];\n const files: { path: string; mime?: string }[] = [];\n const settings: Record<string, string> = Object.create(null) as Record<string, string>;\n let modelName = options.defaultModel;\n let system: string | undefined;\n let operands = false;\n for (let index = 0; index < args.args.length; index++) {\n await step();\n const arg = text(index);\n if (!operands && arg === \"--\") { operands = true; continue; }\n if (!operands && [\"-m\", \"--model\"].includes(arg)) modelName = text(++index);\n else if (!operands && [\"-s\", \"--system\"].includes(arg)) system = text(++index);\n else if (!operands && [\"-o\", \"--option\"].includes(arg)) { const key = text(++index); settings[key] = text(++index); }\n else if (!operands && [\"-a\", \"--attachment\", \"--at\"].includes(arg)) {\n const path = text(++index);\n files.push(arg === \"--at\" ? { path, mime: text(++index) } : { path });\n } else if (!operands && arg.startsWith(\"-\")) throw new Error(`Unknown option: ${arg}`);\n else positional.push(arg);\n }\n if (args.args[0] === \"models\" && positional.length === 1 && !files.length) {\n for (const { provider, model } of declarations) {\n await step();\n await emitText(`${provider.name}/${model.id}\\taliases: ${(model.aliases ?? []).join(\", \")}\\tattachments: ${(model.attachmentTypes ?? []).join(\", \")}\\toutput: ${model.outputType ?? \"text/plain\"}\\n`);\n }\n return { exitCode: 0 };\n }\n const selected = modelName === undefined ? undefined : models.get(modelName);\n if (!selected) throw new Error(`Unknown model: ${modelName ?? \"(no default model)\"}`);\n const chunks: Uint8Array[] = [];\n let stdinBytes = 0;\n for await (const bytes of readBytes(context.stdin, signal)) {\n await step(); admit(bytes.length); stdinBytes += bytes.length; chunks.push(new Uint8Array(bytes));\n }\n const stdin = new Uint8Array(stdinBytes);\n let offset = 0;\n for (const bytes of chunks) { stdin.set(bytes, offset); offset += bytes.length; }\n const content = new TextDecoder(\"utf-8\", { fatal: true }).decode(stdin);\n const instruction = positional.join(\" \");\n const attachments: LlmRequest[\"attachments\"][number][] = [];\n for (const file of files) {\n await step();\n const path = resolvePath(context.cwd, file.path);\n const stat = await wait(context.fs.stat(path, { signal }));\n context.inputBudget?.check(inputBytes + stat.size);\n if (stat.size > maxBytes - inputBytes) throw new Error(\"LLM input byte limit exceeded\");\n const bytes = await wait(context.fs.readFile(path, { signal, maxBytes: Math.min(maxBytes, context.inputBudget?.maxBytes ?? maxBytes) - inputBytes }));\n signal.throwIfAborted(); admit(bytes.length);\n const mimeType = file.mime ?? attachmentMime(bytes, file.path);\n if (!selected.model.attachmentTypes?.some(type => type === mimeType || (type.endsWith(\"/*\") && mimeType.startsWith(type.slice(0, -1))))) throw new Error(`Model ${selected.model.id} does not accept ${mimeType}`);\n attachments.push({ mimeType, bytes: new Uint8Array(bytes) });\n }\n const request: LlmRequest = { model: selected.model.id, prompt: content && instruction ? `${content}\\n\\n${instruction}` : content || instruction, attachments, options: settings, signal, ...(system === undefined ? {} : { system }) };\n signal.throwIfAborted();\n iterator = selected.provider.complete(request)[Symbol.asyncIterator]();\n const binary = !(selected.model.outputType ?? \"text/plain\").startsWith(\"text/\");\n while (true) {\n await step();\n const next = await wait(iterator.next());\n signal.throwIfAborted();\n if (next.done) { ended = true; break; }\n if (binary ? !(next.value instanceof Uint8Array) : typeof next.value !== \"string\") throw new Error(\"Invalid provider response: mixed text and binary chunks or wrong output type\");\n if (typeof next.value === \"string\") await emitText(next.value);\n else await output.output.write(next.value);\n }\n if (!binary) await output.output.write(new Uint8Array([10]));\n return { exitCode: 0 };\n } catch (error) {\n context.signal.throwIfAborted();\n signal.throwIfAborted();\n await writeBytes(context.stderr, new TextEncoder().encode(`llm: ${error instanceof Error ? error.message.slice(0, 4096) : \"Provider failed\"}\\n`), context.signal);\n return { exitCode: 1 };\n } finally { await output.close(); }\n } };\n}\n", "import { classify } from \"../file/classify.js\";\n\nconst extensions: Readonly<Record<string, string>> = {\n png: \"image/png\", jpg: \"image/jpeg\", jpeg: \"image/jpeg\", gif: \"image/gif\", webp: \"image/webp\", svg: \"image/svg+xml\",\n mp3: \"audio/mpeg\", wav: \"audio/wav\", ogg: \"audio/ogg\", flac: \"audio/flac\", m4a: \"audio/mp4\", aac: \"audio/aac\",\n mp4: \"video/mp4\", mov: \"video/quicktime\", webm: \"video/webm\", mkv: \"video/x-matroska\", avi: \"video/x-msvideo\",\n pdf: \"application/pdf\", txt: \"text/plain\", json: \"application/json\", csv: \"text/csv\",\n};\n\nexport function attachmentMime(bytes: Uint8Array, path: string): string {\n const prefix = bytes.subarray(0, 512);\n const ascii = (offset: number, length: number) => String.fromCharCode(...prefix.subarray(offset, offset + length));\n if (prefix.length >= 7 && prefix[0] === 255 && (prefix[1]! & 246) === 240) return \"audio/aac\";\n if (ascii(0, 3) === \"ID3\" || (prefix[0] === 255 && (prefix[1]! & 224) === 224 && (prefix[1]! & 6) !== 0)) return \"audio/mpeg\";\n if (ascii(0, 4) === \"fLaC\") return \"audio/flac\";\n if (ascii(0, 4) === \"OggS\") return \"audio/ogg\";\n if (ascii(0, 4) === \"RIFF\") {\n if (ascii(8, 4) === \"WAVE\") return \"audio/wav\";\n if (ascii(8, 4) === \"AVI \") return \"video/x-msvideo\";\n }\n if (ascii(4, 4) === \"ftyp\") return ascii(8, 4) === \"M4A \" ? \"audio/mp4\" : ascii(8, 4) === \"qt \" ? \"video/quicktime\" : \"video/mp4\";\n const classified = classify(prefix, bytes.length <= prefix.length).mime;\n if (![\"application/octet-stream\", \"text/plain\", \"inode/x-empty\"].includes(classified)) return classified;\n const extension = path.slice(path.lastIndexOf(\".\") + 1).toLowerCase();\n return Object.hasOwn(extensions, extension) ? extensions[extension]! : classified === \"inode/x-empty\" ? \"application/octet-stream\" : classified;\n}\n", "export interface Classification {\n readonly description: string;\n readonly mime: string;\n readonly encoding: string;\n}\n\nexport const binary: Classification = { description: \"data\", mime: \"application/octet-stream\", encoding: \"binary\" };\n\nfunction result(description: string, mime: string, encoding = \"binary\"): Classification {\n return { description, mime, encoding };\n}\n\nfunction matches(bytes: Uint8Array, signature: readonly number[], offset = 0): boolean {\n return bytes.length >= offset + signature.length && signature.every((value, index) => bytes[offset + index] === value);\n}\n\nfunction ascii(bytes: Uint8Array, start: number, length: number): string {\n return String.fromCharCode(...bytes.subarray(start, start + length));\n}\n\nfunction magic(bytes: Uint8Array): Classification | undefined {\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n if (bytes.length >= 33 && matches(bytes, [137, 80, 78, 71, 13, 10, 26, 10]) && view.getUint32(8) === 13 && ascii(bytes, 12, 4) === \"IHDR\"\n && view.getUint32(16) > 0 && view.getUint32(20) > 0 && bytes[26] === 0 && bytes[27] === 0 && bytes[28]! <= 1) {\n const allowed: Record<number, readonly number[]> = { 0: [1, 2, 4, 8, 16], 2: [8, 16], 3: [1, 2, 4, 8], 4: [8, 16], 6: [8, 16] };\n if (allowed[bytes[25]!]?.includes(bytes[24]!)) return result(\"PNG image data\", \"image/png\");\n }\n if (bytes.length >= 13 && [\"GIF87a\", \"GIF89a\"].includes(ascii(bytes, 0, 6)) && view.getUint16(6, true) > 0 && view.getUint16(8, true) > 0) return result(\"GIF image data\", \"image/gif\");\n if (bytes.length >= 4 && matches(bytes, [255, 216, 255]) && bytes[3]! >= 192 && bytes[3]! <= 254) return result(\"JPEG image data\", \"image/jpeg\");\n if (bytes.length >= 20 && ascii(bytes, 0, 4) === \"RIFF\" && ascii(bytes, 8, 4) === \"WEBP\" && [\"VP8 \", \"VP8L\", \"VP8X\"].includes(ascii(bytes, 12, 4)) && view.getUint32(4, true) >= 12) return result(\"WebP image data\", \"image/webp\");\n if (bytes.length >= 8 && (matches(bytes, [73, 73, 42, 0]) || matches(bytes, [77, 77, 0, 42]))) return result(\"TIFF image data\", \"image/tiff\");\n if (bytes.length >= 26 && ascii(bytes, 0, 2) === \"BM\" && [12, 40, 52, 56, 108, 124].includes(view.getUint32(14, true))) return result(\"PC bitmap image data\", \"image/bmp\");\n if (bytes.length >= 22 && matches(bytes, [0, 0, 1, 0]) && view.getUint16(4, true) > 0) return result(\"MS Windows icon resource\", \"image/vnd.microsoft.icon\");\n if (/^%PDF-[12]\\.[0-9](?:\\r|\\n|\\s)/u.test(ascii(bytes, 0, 16))) return result(\"PDF document\", \"application/pdf\");\n if (bytes.length >= 10 && matches(bytes, [31, 139, 8]) && (bytes[3]! & 224) === 0) return result(\"gzip compressed data\", \"application/gzip\");\n if (bytes.length >= 10 && ascii(bytes, 0, 3) === \"BZh\" && bytes[3]! >= 49 && bytes[3]! <= 57 && (ascii(bytes, 4, 6) === \"1AY&SY\" || matches(bytes, [23, 114, 69, 56, 80, 144], 4))) return result(\"bzip2 compressed data\", \"application/x-bzip2\");\n if (bytes.length >= 12 && matches(bytes, [253, 55, 122, 88, 90, 0]) && bytes[6] === 0 && bytes[7]! <= 15) return result(\"XZ compressed data\", \"application/x-xz\");\n if (bytes.length >= 6 && matches(bytes, [40, 181, 47, 253]) && (bytes[4]! & 24) === 0) return result(\"Zstandard compressed data\", \"application/zstd\");\n if ((bytes.length >= 30 && matches(bytes, [80, 75, 3, 4])) || (bytes.length >= 22 && matches(bytes, [80, 75, 5, 6]))) return result(\"Zip archive data\", \"application/zip\");\n if (bytes.length >= 32 && matches(bytes, [55, 122, 188, 175, 39, 28])) return result(\"7-zip archive data\", \"application/x-7z-compressed\");\n if ((bytes.length >= 14 && matches(bytes, [82, 97, 114, 33, 26, 7, 0])) || (bytes.length >= 16 && matches(bytes, [82, 97, 114, 33, 26, 7, 1, 0]))) return result(\"RAR archive data\", \"application/x-rar\");\n if (bytes.length >= 512 && ascii(bytes, 257, 5) === \"ustar\") {\n const checksum = ascii(bytes, 148, 8).replace(/\\0.*$/u, \"\").trim();\n if (/^[0-7]+$/u.test(checksum)) {\n let total = 0;\n for (let index = 0; index < 512; index++) total += index >= 148 && index < 156 ? 32 : bytes[index]!;\n if (parseInt(checksum, 8) === total) return result(\"POSIX tar archive\", \"application/x-tar\");\n }\n }\n if (bytes.length >= 52 && matches(bytes, [127, 69, 76, 70]) && [1, 2].includes(bytes[4]!) && [1, 2].includes(bytes[5]!) && bytes[6] === 1 && (bytes[4] === 1 || bytes.length >= 64)) {\n const type = view.getUint16(16, bytes[5] === 1);\n const mime = type === 1 ? \"application/x-object\" : type === 2 ? \"application/x-executable\" : type === 3 ? \"application/x-sharedlib\" : \"application/octet-stream\";\n return result(`ELF ${bytes[4] === 1 ? \"32\" : \"64\"}-bit ${type === 2 ? \"executable\" : type === 3 ? \"shared object\" : \"object\"}`, mime);\n }\n if (bytes.length >= 64 && ascii(bytes, 0, 2) === \"MZ\") {\n const offset = view.getUint32(60, true);\n if (offset >= 64 && offset <= bytes.length - 24 && matches(bytes, [80, 69, 0, 0], offset)) return result(\"PE executable\", \"application/vnd.microsoft.portable-executable\");\n return result(\"DOS executable\", \"application/x-dosexec\");\n }\n if (bytes.length >= 8 && matches(bytes, [0, 97, 115, 109, 1, 0, 0, 0])) return result(\"WebAssembly binary module\", \"application/wasm\");\n if (bytes.length >= 100 && ascii(bytes, 0, 16) === \"SQLite format 3\\0\") {\n const size = view.getUint16(16);\n if ((size === 1 || (size >= 512 && size <= 32768 && (size & (size - 1)) === 0)) && [1, 2].includes(bytes[18]!) && [1, 2].includes(bytes[19]!) && matches(bytes, [64, 32, 32], 21)) return result(\"SQLite 3.x database\", \"application/vnd.sqlite3\");\n }\n if (bytes.length >= 512 && matches(bytes, [208, 207, 17, 224, 161, 177, 26, 225]) && matches(bytes, [254, 255], 28)) return result(\"OLE Compound Document\", \"application/x-ole-storage\");\n return undefined;\n}\n\nexport function classify(bytes: Uint8Array, complete: boolean): Classification {\n if (!bytes.length) return complete ? result(\"empty\", \"inode/x-empty\") : binary;\n const recognized = magic(bytes);\n if (recognized) return recognized;\n if (matches(bytes, [255, 254, 0, 0]) || matches(bytes, [0, 0, 254, 255])) return binary;\n let encoding = \"utf-8\";\n let bom = 0;\n if (matches(bytes, [239, 187, 191])) bom = 3;\n else if (matches(bytes, [255, 254])) { encoding = \"utf-16le\"; bom = 2; }\n else if (matches(bytes, [254, 255])) { encoding = \"utf-16be\"; bom = 2; }\n let text: string;\n try { text = new TextDecoder(encoding, { fatal: true }).decode(bytes, { stream: !complete }); }\n catch { return binary; }\n if (!text.length && bytes.length > bom) return binary;\n for (const character of text) {\n const code = character.codePointAt(0)!;\n if ((code < 32 && ![8, 9, 10, 12, 13, 27].includes(code)) || (code >= 127 && code <= 159)) return binary;\n }\n if (!bom && encoding === \"utf-8\" && bytes.every(value => value < 128)) encoding = \"us-ascii\";\n if (complete && /^[\\x20\\t\\r\\n]*(?:\\{|\\[)/u.test(text)) {\n try { JSON.parse(text); return result(\"JSON text data\", \"application/json\", encoding); } catch {}\n }\n const description = encoding === \"us-ascii\" ? \"ASCII text\" : encoding === \"utf-8\" ? \"Unicode text, UTF-8\" : `Unicode text, ${encoding === \"utf-16le\" ? \"UTF-16, little-endian\" : \"UTF-16, big-endian\"}`;\n return result(description, \"text/plain\", encoding);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;;;ACAA;;;ACAA;;;ACAA;AAMO,IAAM,SAAyB,EAAE,aAAa,QAAQ,MAAM,4BAA4B,UAAU,SAAS;AAElH,SAAS,OAAO,aAAqB,MAAc,WAAW,UAA0B;AACtF,SAAO,EAAE,aAAa,MAAM,SAAS;AACvC;AAEA,SAAS,QAAQ,OAAmB,WAA8B,SAAS,GAAY;AACrF,SAAO,MAAM,UAAU,SAAS,UAAU,UAAU,UAAU,MAAM,CAAC,OAAO,UAAU,MAAM,SAAS,KAAK,MAAM,KAAK;A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AM,OAAO,MAAM;AAAA,IAAG;AAAA,EACpC,EAAE;AACJ;;;ADjJO,SAAS,kBAAkB,SAA2D;AAC3F,SAAO,CAAC,cAAc,OAAO,CAAC;AAChC;AAEO,SAAS,YAAY,SAAiD;AAC3E,QAAM,WAAW,kBAAkB,OAAO;AAC1C,SAAO,EAAE,MAAM,gBAAgB,MAAM,MAAM;AACzC,eAAW,WAAW,SAAU,MAAK,SAAS,SAAS,SAAS,EAAE,SAAS,QAAQ,WAAW,MAAM,CAAC;AAAA,EACvG,EAAE;AACJ;",
|
|
6
|
-
"names": ["ascii", "binary"]
|
|
7
|
-
}
|
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TransformStream,
|
|
3
|
-
init_platform
|
|
4
|
-
} from "./chunk-2KL6W6NB.js";
|
|
5
|
-
|
|
6
|
-
// packages/safe-bash/src/contracts/errors.ts
|
|
7
|
-
init_platform();
|
|
8
|
-
import { isErrnoCode, isFsError, toFsError, FsError } from "poe-code/safe-fs/core";
|
|
9
|
-
|
|
10
|
-
// packages/safe-bash/src/contracts/io.ts
|
|
11
|
-
init_platform();
|
|
12
|
-
init_platform();
|
|
13
|
-
import { collectBytes, readBytes } from "poe-code/safe-fs/core";
|
|
14
|
-
import { collectBytes as collectBytes2, readBytes as readBytes2, toByteSource } from "poe-code/safe-fs/core";
|
|
15
|
-
var outputFailure = /* @__PURE__ */ Symbol("output failure");
|
|
16
|
-
function createBytePipe(options = {}) {
|
|
17
|
-
const highWaterMark = options.highWaterMark ?? 64 * 1024;
|
|
18
|
-
const signal = options.signal;
|
|
19
|
-
if (!Number.isSafeInteger(highWaterMark) || highWaterMark < 1) {
|
|
20
|
-
throw new RangeError("highWaterMark must be a positive safe integer");
|
|
21
|
-
}
|
|
22
|
-
const stream = new TransformStream(
|
|
23
|
-
void 0,
|
|
24
|
-
{ highWaterMark: 1 },
|
|
25
|
-
{ highWaterMark, size: (chunk) => chunk.byteLength }
|
|
26
|
-
);
|
|
27
|
-
const reader = stream.readable.getReader();
|
|
28
|
-
const writer = stream.writable.getWriter();
|
|
29
|
-
let ended = false;
|
|
30
|
-
let failed = false;
|
|
31
|
-
let failure;
|
|
32
|
-
let closePromise;
|
|
33
|
-
let abortPromise;
|
|
34
|
-
let finished = false;
|
|
35
|
-
const consumer = new AbortController();
|
|
36
|
-
const abort = (reason = new FsError("EPIPE", { syscall: "pipe" })) => {
|
|
37
|
-
if (abortPromise) return abortPromise;
|
|
38
|
-
if (finished) return Promise.resolve();
|
|
39
|
-
failed = true;
|
|
40
|
-
failure = reason;
|
|
41
|
-
ended = true;
|
|
42
|
-
consumer.abort(reason);
|
|
43
|
-
abortPromise = Promise.allSettled([reader.cancel(reason), writer.abort(reason)]).then(() => {
|
|
44
|
-
});
|
|
45
|
-
return abortPromise;
|
|
46
|
-
};
|
|
47
|
-
const onAbort = () => {
|
|
48
|
-
void abort(signal?.reason);
|
|
49
|
-
};
|
|
50
|
-
const cleanup = () => signal?.removeEventListener("abort", onAbort);
|
|
51
|
-
void writer.closed.catch(() => {
|
|
52
|
-
});
|
|
53
|
-
void reader.closed.then(cleanup, cleanup);
|
|
54
|
-
if (signal?.aborted) onAbort();
|
|
55
|
-
else signal?.addEventListener("abort", onAbort, { once: true });
|
|
56
|
-
const iterator = (async function* () {
|
|
57
|
-
try {
|
|
58
|
-
while (true) {
|
|
59
|
-
if (failed) throw failure;
|
|
60
|
-
const result = await reader.read();
|
|
61
|
-
if (failed) throw failure;
|
|
62
|
-
if (result.done) {
|
|
63
|
-
finished = true;
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
yield result.value;
|
|
67
|
-
}
|
|
68
|
-
} finally {
|
|
69
|
-
if (!finished) await abort();
|
|
70
|
-
reader.releaseLock();
|
|
71
|
-
}
|
|
72
|
-
})();
|
|
73
|
-
const readable = {
|
|
74
|
-
[Symbol.asyncIterator]() {
|
|
75
|
-
return this;
|
|
76
|
-
},
|
|
77
|
-
next() {
|
|
78
|
-
return iterator.next();
|
|
79
|
-
},
|
|
80
|
-
async return() {
|
|
81
|
-
if (!finished) await abort();
|
|
82
|
-
try {
|
|
83
|
-
return await iterator.return(void 0);
|
|
84
|
-
} finally {
|
|
85
|
-
reader.releaseLock();
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
async throw(reason) {
|
|
89
|
-
await abort(reason);
|
|
90
|
-
try {
|
|
91
|
-
return await iterator.throw(reason);
|
|
92
|
-
} finally {
|
|
93
|
-
reader.releaseLock();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
const write = async (chunk) => {
|
|
98
|
-
if (failed) throw failure;
|
|
99
|
-
if (ended) throw new FsError("EPIPE", { syscall: "write" });
|
|
100
|
-
if (!(chunk instanceof Uint8Array)) throw new TypeError("Byte sinks require Uint8Array chunks");
|
|
101
|
-
if (chunk.byteLength > 0) await writer.write(new Uint8Array(chunk));
|
|
102
|
-
};
|
|
103
|
-
return {
|
|
104
|
-
readable,
|
|
105
|
-
writable: {
|
|
106
|
-
write,
|
|
107
|
-
[outputFailure]: abort,
|
|
108
|
-
ownedOutput: { consumerClosed: consumer.signal, write }
|
|
109
|
-
},
|
|
110
|
-
close() {
|
|
111
|
-
if (failed) return Promise.reject(failure);
|
|
112
|
-
ended = true;
|
|
113
|
-
closePromise ??= writer.close();
|
|
114
|
-
return closePromise;
|
|
115
|
-
},
|
|
116
|
-
abort
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
async function writeText(sink, text) {
|
|
120
|
-
await sink.write(new TextEncoder().encode(text));
|
|
121
|
-
}
|
|
122
|
-
async function writeBytes(sink, chunk, signal) {
|
|
123
|
-
if (!(chunk instanceof Uint8Array)) throw new TypeError("Byte sinks require Uint8Array chunks");
|
|
124
|
-
await abortable(() => sink.write(chunk), signal);
|
|
125
|
-
}
|
|
126
|
-
async function pipeBytes(source, sink, signal) {
|
|
127
|
-
signal?.throwIfAborted();
|
|
128
|
-
for await (const chunk of readBytes(source, signal)) {
|
|
129
|
-
await writeBytes(sink, chunk, signal);
|
|
130
|
-
}
|
|
131
|
-
signal?.throwIfAborted();
|
|
132
|
-
}
|
|
133
|
-
async function collectText(source, options) {
|
|
134
|
-
return new TextDecoder().decode(await collectBytes(source, options));
|
|
135
|
-
}
|
|
136
|
-
async function abortable(operation, signal) {
|
|
137
|
-
signal?.throwIfAborted();
|
|
138
|
-
if (!signal) return operation();
|
|
139
|
-
return new Promise((resolve, reject) => {
|
|
140
|
-
const onAbort = () => {
|
|
141
|
-
signal.removeEventListener("abort", onAbort);
|
|
142
|
-
reject(signal.reason);
|
|
143
|
-
};
|
|
144
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
145
|
-
try {
|
|
146
|
-
Promise.resolve(operation()).then(
|
|
147
|
-
(result) => {
|
|
148
|
-
signal.removeEventListener("abort", onAbort);
|
|
149
|
-
resolve(result);
|
|
150
|
-
},
|
|
151
|
-
(error) => {
|
|
152
|
-
signal.removeEventListener("abort", onAbort);
|
|
153
|
-
reject(error);
|
|
154
|
-
}
|
|
155
|
-
);
|
|
156
|
-
} catch (error) {
|
|
157
|
-
signal.removeEventListener("abort", onAbort);
|
|
158
|
-
reject(error);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// packages/safe-bash/src/contracts/yield.ts
|
|
164
|
-
init_platform();
|
|
165
|
-
var checkpoints = /* @__PURE__ */ new WeakMap();
|
|
166
|
-
function monotonicNow() {
|
|
167
|
-
return globalThis.performance?.now() ?? Date.now();
|
|
168
|
-
}
|
|
169
|
-
function registerYieldCheckpoint(signal, checkpoint) {
|
|
170
|
-
checkpoints.set(signal, checkpoint);
|
|
171
|
-
}
|
|
172
|
-
function inheritYieldCheckpoint(parent, child) {
|
|
173
|
-
const checkpoint = checkpoints.get(parent);
|
|
174
|
-
if (checkpoint) checkpoints.set(child, checkpoint);
|
|
175
|
-
}
|
|
176
|
-
function scheduleTurn(callback) {
|
|
177
|
-
const host = globalThis;
|
|
178
|
-
return host.setImmediate ? { kind: "immediate", value: host.setImmediate(callback) } : { kind: "timeout", value: setTimeout(callback, 0) };
|
|
179
|
-
}
|
|
180
|
-
function cancelTurn(handle) {
|
|
181
|
-
if (handle?.kind === "immediate") globalThis.clearImmediate?.(handle.value);
|
|
182
|
-
else if (handle) clearTimeout(handle.value);
|
|
183
|
-
}
|
|
184
|
-
function yieldTurn(signal) {
|
|
185
|
-
signal?.throwIfAborted();
|
|
186
|
-
if (signal) checkpoints.get(signal)?.();
|
|
187
|
-
return new Promise((resolve, reject) => {
|
|
188
|
-
let handle;
|
|
189
|
-
const finish = () => {
|
|
190
|
-
signal?.removeEventListener("abort", abort);
|
|
191
|
-
resolve();
|
|
192
|
-
};
|
|
193
|
-
const abort = () => {
|
|
194
|
-
cancelTurn(handle);
|
|
195
|
-
reject(signal.reason);
|
|
196
|
-
};
|
|
197
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
198
|
-
if (signal?.aborted) abort();
|
|
199
|
-
else handle = scheduleTurn(finish);
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export {
|
|
204
|
-
isErrnoCode,
|
|
205
|
-
isFsError,
|
|
206
|
-
toFsError,
|
|
207
|
-
FsError,
|
|
208
|
-
outputFailure,
|
|
209
|
-
createBytePipe,
|
|
210
|
-
writeText,
|
|
211
|
-
writeBytes,
|
|
212
|
-
pipeBytes,
|
|
213
|
-
collectText,
|
|
214
|
-
collectBytes2 as collectBytes,
|
|
215
|
-
readBytes2 as readBytes,
|
|
216
|
-
toByteSource,
|
|
217
|
-
monotonicNow,
|
|
218
|
-
registerYieldCheckpoint,
|
|
219
|
-
inheritYieldCheckpoint,
|
|
220
|
-
scheduleTurn,
|
|
221
|
-
cancelTurn,
|
|
222
|
-
yieldTurn
|
|
223
|
-
};
|
|
224
|
-
//# sourceMappingURL=chunk-FDGESHPB.js.map
|