ai-cli 0.1.1 → 0.2.1
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/README.md +30 -3
- package/dist/index.js +30027 -0
- package/{src/lib/openh264.wasm → dist/openh264-d6yed0d8.wasm} +0 -0
- package/package.json +9 -5
- package/src/cli.test.ts +0 -95
- package/src/commands/completions.ts +0 -296
- package/src/commands/image.ts +0 -136
- package/src/commands/models.ts +0 -117
- package/src/commands/text.ts +0 -117
- package/src/commands/video.ts +0 -113
- package/src/index.ts +0 -30
- package/src/lib/color.ts +0 -5
- package/src/lib/h264-wasm.ts +0 -164
- package/src/lib/h264.test.ts +0 -48
- package/src/lib/jobs.ts +0 -192
- package/src/lib/kitty.ts +0 -55
- package/src/lib/models.test.ts +0 -197
- package/src/lib/models.ts +0 -163
- package/src/lib/mp4.test.ts +0 -231
- package/src/lib/mp4.ts +0 -560
- package/src/lib/openh264.d.mts +0 -28
- package/src/lib/openh264.mjs +0 -423
- package/src/lib/openh264.wasm.d.ts +0 -2
- package/src/lib/output.ts +0 -97
- package/src/lib/p-map.test.ts +0 -63
- package/src/lib/p-map.ts +0 -30
- package/src/lib/parse.test.ts +0 -114
- package/src/lib/parse.ts +0 -44
- package/src/lib/png.test.ts +0 -104
- package/src/lib/png.ts +0 -90
- package/src/lib/progress.ts +0 -214
- package/src/lib/shimmer.test.ts +0 -39
- package/src/lib/shimmer.ts +0 -42
- package/src/lib/stdin.ts +0 -31
package/src/lib/openh264.mjs
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
async function Module(moduleArg = {}) {
|
|
2
|
-
var moduleRtn;
|
|
3
|
-
var Module = moduleArg;
|
|
4
|
-
var ENVIRONMENT_IS_NODE = true;
|
|
5
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
6
|
-
const { createRequire } = await import("node:module");
|
|
7
|
-
var require = createRequire(import.meta.url);
|
|
8
|
-
}
|
|
9
|
-
var arguments_ = [];
|
|
10
|
-
var thisProgram = "./this.program";
|
|
11
|
-
var quit_ = (status, toThrow) => {
|
|
12
|
-
throw toThrow;
|
|
13
|
-
};
|
|
14
|
-
var _scriptName = import.meta.url;
|
|
15
|
-
var scriptDirectory = "";
|
|
16
|
-
function locateFile(path) {
|
|
17
|
-
if (Module["locateFile"]) {
|
|
18
|
-
return Module["locateFile"](path, scriptDirectory);
|
|
19
|
-
}
|
|
20
|
-
return scriptDirectory + path;
|
|
21
|
-
}
|
|
22
|
-
var readAsync, readBinary;
|
|
23
|
-
if (ENVIRONMENT_IS_NODE) {
|
|
24
|
-
var fs = require("node:fs");
|
|
25
|
-
if (_scriptName.startsWith("file:")) {
|
|
26
|
-
scriptDirectory =
|
|
27
|
-
require("node:path").dirname(
|
|
28
|
-
require("node:url").fileURLToPath(_scriptName)
|
|
29
|
-
) + "/";
|
|
30
|
-
}
|
|
31
|
-
readBinary = (filename) => {
|
|
32
|
-
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
33
|
-
var ret = fs.readFileSync(filename);
|
|
34
|
-
return ret;
|
|
35
|
-
};
|
|
36
|
-
readAsync = async (filename, binary = true) => {
|
|
37
|
-
filename = isFileURI(filename) ? new URL(filename) : filename;
|
|
38
|
-
var ret = fs.readFileSync(filename, binary ? undefined : "utf8");
|
|
39
|
-
return ret;
|
|
40
|
-
};
|
|
41
|
-
if (process.argv.length > 1) {
|
|
42
|
-
thisProgram = process.argv[1].replace(/\\/g, "/");
|
|
43
|
-
}
|
|
44
|
-
arguments_ = process.argv.slice(2);
|
|
45
|
-
quit_ = (status, toThrow) => {
|
|
46
|
-
process.exitCode = status;
|
|
47
|
-
throw toThrow;
|
|
48
|
-
};
|
|
49
|
-
} else {
|
|
50
|
-
}
|
|
51
|
-
var out = console.log.bind(console);
|
|
52
|
-
var err = console.error.bind(console);
|
|
53
|
-
var wasmBinary;
|
|
54
|
-
var ABORT = false;
|
|
55
|
-
var isFileURI = (filename) => filename.startsWith("file://");
|
|
56
|
-
class EmscriptenEH {}
|
|
57
|
-
class EmscriptenSjLj extends EmscriptenEH {}
|
|
58
|
-
var readyPromiseResolve, readyPromiseReject;
|
|
59
|
-
var runtimeInitialized = false;
|
|
60
|
-
function updateMemoryViews() {
|
|
61
|
-
var b = wasmMemory.buffer;
|
|
62
|
-
HEAP8 = new Int8Array(b);
|
|
63
|
-
HEAP16 = new Int16Array(b);
|
|
64
|
-
Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
|
|
65
|
-
HEAPU16 = new Uint16Array(b);
|
|
66
|
-
HEAP32 = new Int32Array(b);
|
|
67
|
-
HEAPU32 = new Uint32Array(b);
|
|
68
|
-
HEAPF32 = new Float32Array(b);
|
|
69
|
-
HEAPF64 = new Float64Array(b);
|
|
70
|
-
HEAP64 = new BigInt64Array(b);
|
|
71
|
-
HEAPU64 = new BigUint64Array(b);
|
|
72
|
-
}
|
|
73
|
-
function preRun() {
|
|
74
|
-
if (Module["preRun"]) {
|
|
75
|
-
if (typeof Module["preRun"] == "function")
|
|
76
|
-
Module["preRun"] = [Module["preRun"]];
|
|
77
|
-
while (Module["preRun"].length) {
|
|
78
|
-
addOnPreRun(Module["preRun"].shift());
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
callRuntimeCallbacks(onPreRuns);
|
|
82
|
-
}
|
|
83
|
-
function initRuntime() {
|
|
84
|
-
runtimeInitialized = true;
|
|
85
|
-
wasmExports["__wasm_call_ctors"]();
|
|
86
|
-
}
|
|
87
|
-
function postRun() {
|
|
88
|
-
if (Module["postRun"]) {
|
|
89
|
-
if (typeof Module["postRun"] == "function")
|
|
90
|
-
Module["postRun"] = [Module["postRun"]];
|
|
91
|
-
while (Module["postRun"].length) {
|
|
92
|
-
addOnPostRun(Module["postRun"].shift());
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
callRuntimeCallbacks(onPostRuns);
|
|
96
|
-
}
|
|
97
|
-
function abort(what) {
|
|
98
|
-
Module["onAbort"]?.(what);
|
|
99
|
-
what = `Aborted(${what})`;
|
|
100
|
-
err(what);
|
|
101
|
-
ABORT = true;
|
|
102
|
-
what += ". Build with -sASSERTIONS for more info.";
|
|
103
|
-
var e = new WebAssembly.RuntimeError(what);
|
|
104
|
-
readyPromiseReject?.(e);
|
|
105
|
-
throw e;
|
|
106
|
-
}
|
|
107
|
-
var wasmBinaryFile;
|
|
108
|
-
function findWasmBinary() {
|
|
109
|
-
if (Module["locateFile"]) {
|
|
110
|
-
return locateFile("openh264.wasm");
|
|
111
|
-
}
|
|
112
|
-
return new URL("openh264.wasm", import.meta.url).href;
|
|
113
|
-
}
|
|
114
|
-
function getBinarySync(file) {
|
|
115
|
-
if (file == wasmBinaryFile && wasmBinary) {
|
|
116
|
-
return new Uint8Array(wasmBinary);
|
|
117
|
-
}
|
|
118
|
-
if (readBinary) {
|
|
119
|
-
return readBinary(file);
|
|
120
|
-
}
|
|
121
|
-
throw "both async and sync fetching of the wasm failed";
|
|
122
|
-
}
|
|
123
|
-
async function getWasmBinary(binaryFile) {
|
|
124
|
-
if (!wasmBinary) {
|
|
125
|
-
try {
|
|
126
|
-
var response = await readAsync(binaryFile);
|
|
127
|
-
return new Uint8Array(response);
|
|
128
|
-
} catch {}
|
|
129
|
-
}
|
|
130
|
-
return getBinarySync(binaryFile);
|
|
131
|
-
}
|
|
132
|
-
async function instantiateArrayBuffer(binaryFile, imports) {
|
|
133
|
-
try {
|
|
134
|
-
var binary = await getWasmBinary(binaryFile);
|
|
135
|
-
var instance = await WebAssembly.instantiate(binary, imports);
|
|
136
|
-
return instance;
|
|
137
|
-
} catch (reason) {
|
|
138
|
-
err(`failed to asynchronously prepare wasm: ${reason}`);
|
|
139
|
-
abort(reason);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async function instantiateAsync(binary, binaryFile, imports) {
|
|
143
|
-
if (!binary && !ENVIRONMENT_IS_NODE) {
|
|
144
|
-
try {
|
|
145
|
-
var response = fetch(binaryFile, { credentials: "same-origin" });
|
|
146
|
-
var instantiationResult = await WebAssembly.instantiateStreaming(
|
|
147
|
-
response,
|
|
148
|
-
imports
|
|
149
|
-
);
|
|
150
|
-
return instantiationResult;
|
|
151
|
-
} catch (reason) {
|
|
152
|
-
err(`wasm streaming compile failed: ${reason}`);
|
|
153
|
-
err("falling back to ArrayBuffer instantiation");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return instantiateArrayBuffer(binaryFile, imports);
|
|
157
|
-
}
|
|
158
|
-
function getWasmImports() {
|
|
159
|
-
var imports = { env: wasmImports, wasi_snapshot_preview1: wasmImports };
|
|
160
|
-
return imports;
|
|
161
|
-
}
|
|
162
|
-
async function createWasm() {
|
|
163
|
-
function receiveInstance(instance, module) {
|
|
164
|
-
wasmExports = instance.exports;
|
|
165
|
-
assignWasmExports(wasmExports);
|
|
166
|
-
updateMemoryViews();
|
|
167
|
-
return wasmExports;
|
|
168
|
-
}
|
|
169
|
-
function receiveInstantiationResult(result) {
|
|
170
|
-
return receiveInstance(result["instance"]);
|
|
171
|
-
}
|
|
172
|
-
var info = getWasmImports();
|
|
173
|
-
if (Module["instantiateWasm"]) {
|
|
174
|
-
return new Promise((resolve, reject) => {
|
|
175
|
-
Module["instantiateWasm"](info, (inst, mod) => {
|
|
176
|
-
resolve(receiveInstance(inst, mod));
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
wasmBinaryFile ??= findWasmBinary();
|
|
181
|
-
var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
|
|
182
|
-
var exports = receiveInstantiationResult(result);
|
|
183
|
-
return exports;
|
|
184
|
-
}
|
|
185
|
-
class ExitStatus {
|
|
186
|
-
name = "ExitStatus";
|
|
187
|
-
constructor(status) {
|
|
188
|
-
this.message = `Program terminated with exit(${status})`;
|
|
189
|
-
this.status = status;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
var HEAP16;
|
|
193
|
-
var HEAP32;
|
|
194
|
-
var HEAP64;
|
|
195
|
-
var HEAP8;
|
|
196
|
-
var HEAPF32;
|
|
197
|
-
var HEAPF64;
|
|
198
|
-
var HEAPU16;
|
|
199
|
-
var HEAPU32;
|
|
200
|
-
var HEAPU64;
|
|
201
|
-
var HEAPU8;
|
|
202
|
-
var callRuntimeCallbacks = (callbacks) => {
|
|
203
|
-
while (callbacks.length > 0) {
|
|
204
|
-
callbacks.shift()(Module);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
207
|
-
var onPostRuns = [];
|
|
208
|
-
var addOnPostRun = (cb) => onPostRuns.push(cb);
|
|
209
|
-
var onPreRuns = [];
|
|
210
|
-
var addOnPreRun = (cb) => onPreRuns.push(cb);
|
|
211
|
-
var noExitRuntime = true;
|
|
212
|
-
var __abort_js = () => abort("");
|
|
213
|
-
var _emscripten_date_now = () => Date.now();
|
|
214
|
-
var getHeapMax = () => 2147483648;
|
|
215
|
-
var alignMemory = (size, alignment) =>
|
|
216
|
-
Math.ceil(size / alignment) * alignment;
|
|
217
|
-
var growMemory = (size) => {
|
|
218
|
-
var oldHeapSize = wasmMemory.buffer.byteLength;
|
|
219
|
-
var pages = ((size - oldHeapSize + 65535) / 65536) | 0;
|
|
220
|
-
try {
|
|
221
|
-
wasmMemory.grow(pages);
|
|
222
|
-
updateMemoryViews();
|
|
223
|
-
return 1;
|
|
224
|
-
} catch (e) {}
|
|
225
|
-
};
|
|
226
|
-
var _emscripten_resize_heap = (requestedSize) => {
|
|
227
|
-
var oldSize = HEAPU8.length;
|
|
228
|
-
requestedSize >>>= 0;
|
|
229
|
-
var maxHeapSize = getHeapMax();
|
|
230
|
-
if (requestedSize > maxHeapSize) {
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
|
|
234
|
-
var overGrownHeapSize = oldSize * (1 + 0.2 / cutDown);
|
|
235
|
-
overGrownHeapSize = Math.min(
|
|
236
|
-
overGrownHeapSize,
|
|
237
|
-
requestedSize + 100663296
|
|
238
|
-
);
|
|
239
|
-
var newSize = Math.min(
|
|
240
|
-
maxHeapSize,
|
|
241
|
-
alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536)
|
|
242
|
-
);
|
|
243
|
-
var replacement = growMemory(newSize);
|
|
244
|
-
if (replacement) {
|
|
245
|
-
return true;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return false;
|
|
249
|
-
};
|
|
250
|
-
var _fd_close = (fd) => 52;
|
|
251
|
-
var INT53_MAX = 9007199254740992;
|
|
252
|
-
var INT53_MIN = -9007199254740992;
|
|
253
|
-
var bigintToI53Checked = (num) =>
|
|
254
|
-
num < INT53_MIN || num > INT53_MAX ? NaN : Number(num);
|
|
255
|
-
function _fd_seek(fd, offset, whence, newOffset) {
|
|
256
|
-
offset = bigintToI53Checked(offset);
|
|
257
|
-
return 70;
|
|
258
|
-
}
|
|
259
|
-
var printCharBuffers = [null, [], []];
|
|
260
|
-
var UTF8Decoder = globalThis.TextDecoder && new TextDecoder();
|
|
261
|
-
var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
|
|
262
|
-
var maxIdx = idx + maxBytesToRead;
|
|
263
|
-
if (ignoreNul) return maxIdx;
|
|
264
|
-
while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
|
|
265
|
-
return idx;
|
|
266
|
-
};
|
|
267
|
-
var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
|
|
268
|
-
var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
|
|
269
|
-
if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
|
|
270
|
-
return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr));
|
|
271
|
-
}
|
|
272
|
-
var str = "";
|
|
273
|
-
while (idx < endPtr) {
|
|
274
|
-
var u0 = heapOrArray[idx++];
|
|
275
|
-
if (!(u0 & 128)) {
|
|
276
|
-
str += String.fromCharCode(u0);
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
var u1 = heapOrArray[idx++] & 63;
|
|
280
|
-
if ((u0 & 224) == 192) {
|
|
281
|
-
str += String.fromCharCode(((u0 & 31) << 6) | u1);
|
|
282
|
-
continue;
|
|
283
|
-
}
|
|
284
|
-
var u2 = heapOrArray[idx++] & 63;
|
|
285
|
-
if ((u0 & 240) == 224) {
|
|
286
|
-
u0 = ((u0 & 15) << 12) | (u1 << 6) | u2;
|
|
287
|
-
} else {
|
|
288
|
-
u0 =
|
|
289
|
-
((u0 & 7) << 18) | (u1 << 12) | (u2 << 6) | (heapOrArray[idx++] & 63);
|
|
290
|
-
}
|
|
291
|
-
if (u0 < 65536) {
|
|
292
|
-
str += String.fromCharCode(u0);
|
|
293
|
-
} else {
|
|
294
|
-
var ch = u0 - 65536;
|
|
295
|
-
str += String.fromCharCode(55296 | (ch >> 10), 56320 | (ch & 1023));
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return str;
|
|
299
|
-
};
|
|
300
|
-
var printChar = (stream, curr) => {
|
|
301
|
-
var buffer = printCharBuffers[stream];
|
|
302
|
-
if (curr === 0 || curr === 10) {
|
|
303
|
-
(stream === 1 ? out : err)(UTF8ArrayToString(buffer));
|
|
304
|
-
buffer.length = 0;
|
|
305
|
-
} else {
|
|
306
|
-
buffer.push(curr);
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) =>
|
|
310
|
-
ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : "";
|
|
311
|
-
var _fd_write = (fd, iov, iovcnt, pnum) => {
|
|
312
|
-
var num = 0;
|
|
313
|
-
for (var i = 0; i < iovcnt; i++) {
|
|
314
|
-
var ptr = HEAPU32[iov >> 2];
|
|
315
|
-
var len = HEAPU32[(iov + 4) >> 2];
|
|
316
|
-
iov += 8;
|
|
317
|
-
for (var j = 0; j < len; j++) {
|
|
318
|
-
printChar(fd, HEAPU8[ptr + j]);
|
|
319
|
-
}
|
|
320
|
-
num += len;
|
|
321
|
-
}
|
|
322
|
-
HEAPU32[pnum >> 2] = num;
|
|
323
|
-
return 0;
|
|
324
|
-
};
|
|
325
|
-
{
|
|
326
|
-
if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
|
|
327
|
-
if (Module["print"]) out = Module["print"];
|
|
328
|
-
if (Module["printErr"]) err = Module["printErr"];
|
|
329
|
-
if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
|
|
330
|
-
if (Module["arguments"]) arguments_ = Module["arguments"];
|
|
331
|
-
if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
|
|
332
|
-
if (Module["preInit"]) {
|
|
333
|
-
if (typeof Module["preInit"] == "function")
|
|
334
|
-
Module["preInit"] = [Module["preInit"]];
|
|
335
|
-
while (Module["preInit"].length > 0) {
|
|
336
|
-
Module["preInit"].shift()();
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
var _decoder_init,
|
|
341
|
-
_decoder_feed,
|
|
342
|
-
_decoder_flush,
|
|
343
|
-
_get_has_frame,
|
|
344
|
-
_get_width,
|
|
345
|
-
_get_height,
|
|
346
|
-
_get_y_stride,
|
|
347
|
-
_get_uv_stride,
|
|
348
|
-
_get_y_ptr,
|
|
349
|
-
_get_u_ptr,
|
|
350
|
-
_get_v_ptr,
|
|
351
|
-
_decoder_destroy,
|
|
352
|
-
_malloc,
|
|
353
|
-
_free,
|
|
354
|
-
__emscripten_stack_restore,
|
|
355
|
-
__emscripten_stack_alloc,
|
|
356
|
-
_emscripten_stack_get_current,
|
|
357
|
-
memory,
|
|
358
|
-
__indirect_function_table,
|
|
359
|
-
wasmMemory;
|
|
360
|
-
function assignWasmExports(wasmExports) {
|
|
361
|
-
_decoder_init = Module["_decoder_init"] = wasmExports["decoder_init"];
|
|
362
|
-
_decoder_feed = Module["_decoder_feed"] = wasmExports["decoder_feed"];
|
|
363
|
-
_decoder_flush = Module["_decoder_flush"] = wasmExports["decoder_flush"];
|
|
364
|
-
_get_has_frame = Module["_get_has_frame"] = wasmExports["get_has_frame"];
|
|
365
|
-
_get_width = Module["_get_width"] = wasmExports["get_width"];
|
|
366
|
-
_get_height = Module["_get_height"] = wasmExports["get_height"];
|
|
367
|
-
_get_y_stride = Module["_get_y_stride"] = wasmExports["get_y_stride"];
|
|
368
|
-
_get_uv_stride = Module["_get_uv_stride"] = wasmExports["get_uv_stride"];
|
|
369
|
-
_get_y_ptr = Module["_get_y_ptr"] = wasmExports["get_y_ptr"];
|
|
370
|
-
_get_u_ptr = Module["_get_u_ptr"] = wasmExports["get_u_ptr"];
|
|
371
|
-
_get_v_ptr = Module["_get_v_ptr"] = wasmExports["get_v_ptr"];
|
|
372
|
-
_decoder_destroy = Module["_decoder_destroy"] =
|
|
373
|
-
wasmExports["decoder_destroy"];
|
|
374
|
-
_malloc = Module["_malloc"] = wasmExports["malloc"];
|
|
375
|
-
_free = Module["_free"] = wasmExports["free"];
|
|
376
|
-
__emscripten_stack_restore = wasmExports["_emscripten_stack_restore"];
|
|
377
|
-
__emscripten_stack_alloc = wasmExports["_emscripten_stack_alloc"];
|
|
378
|
-
_emscripten_stack_get_current = wasmExports["emscripten_stack_get_current"];
|
|
379
|
-
memory = wasmMemory = wasmExports["memory"];
|
|
380
|
-
__indirect_function_table = wasmExports["__indirect_function_table"];
|
|
381
|
-
}
|
|
382
|
-
var wasmImports = {
|
|
383
|
-
_abort_js: __abort_js,
|
|
384
|
-
emscripten_date_now: _emscripten_date_now,
|
|
385
|
-
emscripten_resize_heap: _emscripten_resize_heap,
|
|
386
|
-
fd_close: _fd_close,
|
|
387
|
-
fd_seek: _fd_seek,
|
|
388
|
-
fd_write: _fd_write,
|
|
389
|
-
};
|
|
390
|
-
function run() {
|
|
391
|
-
preRun();
|
|
392
|
-
function doRun() {
|
|
393
|
-
Module["calledRun"] = true;
|
|
394
|
-
if (ABORT) return;
|
|
395
|
-
initRuntime();
|
|
396
|
-
readyPromiseResolve?.(Module);
|
|
397
|
-
Module["onRuntimeInitialized"]?.();
|
|
398
|
-
postRun();
|
|
399
|
-
}
|
|
400
|
-
if (Module["setStatus"]) {
|
|
401
|
-
Module["setStatus"]("Running...");
|
|
402
|
-
setTimeout(() => {
|
|
403
|
-
setTimeout(() => Module["setStatus"](""), 1);
|
|
404
|
-
doRun();
|
|
405
|
-
}, 1);
|
|
406
|
-
} else {
|
|
407
|
-
doRun();
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
var wasmExports;
|
|
411
|
-
wasmExports = await createWasm();
|
|
412
|
-
run();
|
|
413
|
-
if (runtimeInitialized) {
|
|
414
|
-
moduleRtn = Module;
|
|
415
|
-
} else {
|
|
416
|
-
moduleRtn = new Promise((resolve, reject) => {
|
|
417
|
-
readyPromiseResolve = resolve;
|
|
418
|
-
readyPromiseReject = reject;
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
return moduleRtn;
|
|
422
|
-
}
|
|
423
|
-
export default Module;
|
package/src/lib/output.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { writeFileSync, mkdirSync, statSync } from "fs";
|
|
2
|
-
import { resolve, join, dirname } from "path";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
supportsKittyGraphics,
|
|
6
|
-
displayImage,
|
|
7
|
-
displayVideoFrame,
|
|
8
|
-
} from "./kitty.js";
|
|
9
|
-
|
|
10
|
-
export type OutputFormat = "md" | "txt" | "image" | "video";
|
|
11
|
-
|
|
12
|
-
const DEFAULT_EXTENSIONS: Record<OutputFormat, string> = {
|
|
13
|
-
md: ".md",
|
|
14
|
-
txt: ".txt",
|
|
15
|
-
image: ".png",
|
|
16
|
-
video: ".mp4",
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export interface WriteOutputOptions {
|
|
20
|
-
data: Buffer | string;
|
|
21
|
-
format: OutputFormat;
|
|
22
|
-
outputPath?: string;
|
|
23
|
-
suffix?: string;
|
|
24
|
-
quiet?: boolean;
|
|
25
|
-
display?: boolean;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function defaultFilename(format: OutputFormat): string {
|
|
29
|
-
return `output${DEFAULT_EXTENSIONS[format]}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function isDirectory(p: string): boolean {
|
|
33
|
-
try {
|
|
34
|
-
return statSync(p).isDirectory();
|
|
35
|
-
} catch {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function writeOutput(
|
|
41
|
-
opts: WriteOutputOptions
|
|
42
|
-
): Promise<string | null> {
|
|
43
|
-
const { data, format, suffix, quiet, display } = opts;
|
|
44
|
-
const effectiveOutput = opts.outputPath ?? process.env.AI_CLI_OUTPUT_DIR;
|
|
45
|
-
const buf = typeof data === "string" ? Buffer.from(data, "utf-8") : data;
|
|
46
|
-
const shouldDisplay =
|
|
47
|
-
display !== false &&
|
|
48
|
-
(format === "image" || format === "video") &&
|
|
49
|
-
process.stdout.isTTY &&
|
|
50
|
-
supportsKittyGraphics();
|
|
51
|
-
|
|
52
|
-
if (effectiveOutput) {
|
|
53
|
-
let filePath: string;
|
|
54
|
-
if (isDirectory(effectiveOutput)) {
|
|
55
|
-
filePath = join(
|
|
56
|
-
effectiveOutput,
|
|
57
|
-
addSuffix(defaultFilename(format), suffix)
|
|
58
|
-
);
|
|
59
|
-
} else {
|
|
60
|
-
filePath = addSuffix(effectiveOutput, suffix);
|
|
61
|
-
}
|
|
62
|
-
filePath = resolve(filePath);
|
|
63
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
64
|
-
writeFileSync(filePath, buf);
|
|
65
|
-
if (!quiet) process.stderr.write(`Saved to ${filePath}\n`);
|
|
66
|
-
if (shouldDisplay) await showPreview(format, buf);
|
|
67
|
-
return filePath;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!process.stdout.isTTY) {
|
|
71
|
-
process.stdout.write(buf);
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const filename = addSuffix(defaultFilename(format), suffix);
|
|
76
|
-
const path = resolve(filename);
|
|
77
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
78
|
-
writeFileSync(path, buf);
|
|
79
|
-
if (!quiet) process.stderr.write(`Saved to ${path}\n`);
|
|
80
|
-
if (shouldDisplay) await showPreview(format, buf);
|
|
81
|
-
return path;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function showPreview(format: OutputFormat, buf: Buffer): Promise<void> {
|
|
85
|
-
if (format === "video") {
|
|
86
|
-
await displayVideoFrame(buf);
|
|
87
|
-
} else {
|
|
88
|
-
displayImage(buf);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function addSuffix(filename: string, suffix?: string): string {
|
|
93
|
-
if (!suffix) return filename;
|
|
94
|
-
const dot = filename.lastIndexOf(".");
|
|
95
|
-
if (dot === -1) return `${filename}-${suffix}`;
|
|
96
|
-
return `${filename.slice(0, dot)}-${suffix}${filename.slice(dot)}`;
|
|
97
|
-
}
|
package/src/lib/p-map.test.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
import { pMap } from "./p-map.js";
|
|
4
|
-
|
|
5
|
-
describe("pMap", () => {
|
|
6
|
-
test("maps items with fulfilled results", async () => {
|
|
7
|
-
const results = await pMap([1, 2, 3], async (x) => x * 2, 2);
|
|
8
|
-
expect(results).toEqual([
|
|
9
|
-
{ status: "fulfilled", value: 2 },
|
|
10
|
-
{ status: "fulfilled", value: 4 },
|
|
11
|
-
{ status: "fulfilled", value: 6 },
|
|
12
|
-
]);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test("captures rejections without stopping others", async () => {
|
|
16
|
-
const results = await pMap(
|
|
17
|
-
[1, 2, 3],
|
|
18
|
-
async (x) => {
|
|
19
|
-
if (x === 2) throw new Error("fail");
|
|
20
|
-
return x;
|
|
21
|
-
},
|
|
22
|
-
3
|
|
23
|
-
);
|
|
24
|
-
expect(results[0]).toEqual({ status: "fulfilled", value: 1 });
|
|
25
|
-
expect(results[1].status).toBe("rejected");
|
|
26
|
-
expect(results[2]).toEqual({ status: "fulfilled", value: 3 });
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test("handles empty input", async () => {
|
|
30
|
-
const results = await pMap([], async (x: number) => x, 4);
|
|
31
|
-
expect(results).toEqual([]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
test("respects concurrency limit", async () => {
|
|
35
|
-
let active = 0;
|
|
36
|
-
let maxActive = 0;
|
|
37
|
-
|
|
38
|
-
await pMap(
|
|
39
|
-
[1, 2, 3, 4, 5, 6],
|
|
40
|
-
async () => {
|
|
41
|
-
active++;
|
|
42
|
-
maxActive = Math.max(maxActive, active);
|
|
43
|
-
await new Promise((r) => setTimeout(r, 10));
|
|
44
|
-
active--;
|
|
45
|
-
},
|
|
46
|
-
2
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
expect(maxActive).toBeLessThanOrEqual(2);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("passes correct indices to callback", async () => {
|
|
53
|
-
const indices: number[] = [];
|
|
54
|
-
await pMap(
|
|
55
|
-
["a", "b", "c"],
|
|
56
|
-
async (_, i) => {
|
|
57
|
-
indices.push(i);
|
|
58
|
-
},
|
|
59
|
-
1
|
|
60
|
-
);
|
|
61
|
-
expect(indices).toEqual([0, 1, 2]);
|
|
62
|
-
});
|
|
63
|
-
});
|
package/src/lib/p-map.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export async function pMap<T, R>(
|
|
2
|
-
items: T[],
|
|
3
|
-
fn: (item: T, index: number) => Promise<R>,
|
|
4
|
-
concurrency: number
|
|
5
|
-
): Promise<PromiseSettledResult<R>[]> {
|
|
6
|
-
concurrency = Math.max(1, concurrency);
|
|
7
|
-
const results = Array.from<PromiseSettledResult<R>>({ length: items.length });
|
|
8
|
-
let nextIdx = 0;
|
|
9
|
-
|
|
10
|
-
async function worker() {
|
|
11
|
-
while (nextIdx < items.length) {
|
|
12
|
-
const idx = nextIdx++;
|
|
13
|
-
try {
|
|
14
|
-
results[idx] = {
|
|
15
|
-
status: "fulfilled",
|
|
16
|
-
value: await fn(items[idx], idx),
|
|
17
|
-
};
|
|
18
|
-
} catch (reason) {
|
|
19
|
-
results[idx] = { status: "rejected", reason };
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const workers = Array.from(
|
|
25
|
-
{ length: Math.min(concurrency, items.length) },
|
|
26
|
-
() => worker()
|
|
27
|
-
);
|
|
28
|
-
await Promise.all(workers);
|
|
29
|
-
return results;
|
|
30
|
-
}
|