utilitas 2001.1.94 → 2001.1.98
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/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/alan.mjs +1 -1
- package/lib/manifest.mjs +1 -1
- package/lib/shell.mjs +37 -14
- package/package.json +1 -1
package/lib/alan.mjs
CHANGED
|
@@ -938,7 +938,7 @@ const promptOpenRouter = async (aiId, content, options = {}) => {
|
|
|
938
938
|
delteReasoning && delteReasoning === resultReasoning
|
|
939
939
|
&& (delteReasoning = `${result ? '\n\n' : ''}${THINK_STR}\n${delteReasoning}`);
|
|
940
940
|
resultReasoning && (deltaText || delta.tool_calls?.length) && !reasoningEnd && (
|
|
941
|
-
reasoningEnd = delteReasoning = `${delteReasoning}${THINK_END}\n\n`
|
|
941
|
+
reasoningEnd = delteReasoning = `${delteReasoning}\n${THINK_END}\n\n`
|
|
942
942
|
);
|
|
943
943
|
deltaText = delteReasoning + deltaText;
|
|
944
944
|
result += deltaText;
|
package/lib/manifest.mjs
CHANGED
package/lib/shell.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
2
|
import { log as _log } from './utilitas.mjs';
|
|
3
3
|
|
|
4
4
|
const log = (content) => _log(content, import.meta.url);
|
|
@@ -8,21 +8,44 @@ const exist = (bin) => { assertCommand(bin); return which(bin); };
|
|
|
8
8
|
|
|
9
9
|
const exec = async (command, options = {}) => {
|
|
10
10
|
assertCommand(command);
|
|
11
|
+
const limit = options?.limit || 3000;
|
|
11
12
|
return new Promise((resolve, reject) => {
|
|
12
|
-
const child = (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const child = (spawn || vF)(command, { ...options || {}, shell: true });
|
|
14
|
+
const buf = { stdout: { lines: [], p: '' }, stderr: { lines: [], p: '' } };
|
|
15
|
+
const collect = (k, d) => {
|
|
16
|
+
if (options?.stream) { options.stream(d); }
|
|
17
|
+
const p = (buf[k].p + d).split(/\r?\n/);
|
|
18
|
+
buf[k].p = p.pop();
|
|
19
|
+
buf[k].lines = buf[k].lines.concat(p);
|
|
20
|
+
if (buf[k].lines.length > limit) {
|
|
21
|
+
buf[k].lines = buf[k].lines.slice(-limit);
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
child.
|
|
23
|
+
};
|
|
24
|
+
const getBuf = (k) => {
|
|
25
|
+
const c = buf[k].lines.join('\n');
|
|
26
|
+
return c + (c && buf[k].p ? '\n' : '') + buf[k].p;
|
|
27
|
+
};
|
|
28
|
+
if (child?.stdout) {
|
|
29
|
+
child.stdout.on('data', d => collect('stdout', d));
|
|
30
|
+
child.stderr.on('data', d => collect('stderr', d));
|
|
31
|
+
child.on('close', code => {
|
|
32
|
+
const stdout = getBuf('stdout');
|
|
33
|
+
const stderr = getBuf('stderr');
|
|
34
|
+
if (code && !options?.acceptError) {
|
|
35
|
+
const err = new Error(stderr || `Command failed: ${command}\n${stdout}`);
|
|
36
|
+
err.code = code;
|
|
37
|
+
return reject(err);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
assert(options?.acceptError || !stderr, stderr, 500);
|
|
41
|
+
} catch (e) { return reject(e); }
|
|
42
|
+
resolve(options?.acceptError
|
|
43
|
+
? [stdout, stderr].map(x => x.trim()).filter(x => x).join('\n')
|
|
44
|
+
: stdout.trim());
|
|
45
|
+
});
|
|
46
|
+
child.on('error', reject);
|
|
47
|
+
} else {
|
|
48
|
+
vF(command, resolve);
|
|
26
49
|
}
|
|
27
50
|
});
|
|
28
51
|
};
|