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/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
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.94",
4
+ "version": "2001.1.98",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/shell.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { exec as _exec } from 'child_process';
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 = (_exec || vF)(command, (error, stdout, stderr) => {
13
- if (error && !options?.acceptError) { return reject(error); }
14
- try {
15
- assert(options?.acceptError || !stderr, stderr, 500);
16
- } catch (e) {
17
- return reject(e);
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
- resolve(options?.acceptError
20
- ? [stdout, stderr].map(x => x.trim()).filter(x => x).join('\n')
21
- : stdout.trim());
22
- });
23
- if (options?.stream && child?.stdout) {
24
- child.stdout.on('data', options.stream);
25
- child.stderr.on('data', options.stream);
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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "2001.1.94",
4
+ "version": "2001.1.98",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",