utilitas 2000.3.49 → 2000.3.52

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
@@ -1220,7 +1220,7 @@ const initChat = async (options = {}) => {
1220
1220
  'Invalid session storage provider.'
1221
1221
  );
1222
1222
  chatConfig.sessions = options.sessions;
1223
- }
1223
+ } else { log(`WARNING: Sessions persistence is not enabled.`); }
1224
1224
  options.instructions && (chatConfig.systemPrompt = options.instructions);
1225
1225
  // Use Gemini instead of ChatGPT because of the longer package.
1226
1226
  const [spTokens, ais] = await Promise.all([countTokens([await buildMessage(
@@ -1446,6 +1446,7 @@ export {
1446
1446
  prompt,
1447
1447
  promptOpenRouter,
1448
1448
  resetSession,
1449
+ setSession,
1449
1450
  stt,
1450
1451
  talk,
1451
1452
  trimPrompt,
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": "2000.3.49",
4
+ "version": "2000.3.52",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/storage.mjs CHANGED
@@ -119,18 +119,20 @@ const assertPath = async (path, type, mode, msg, code, options) => {
119
119
  };
120
120
 
121
121
  const isTextFile = async (file, options) => {
122
- const isBuf = Buffer.isBuffer(file);
123
- let [f, bytes, res] = [isBuf ? file : await fs.open(file, 'r'), null, true];
124
- for (let i = 0; i < (~~options?.length || 1000); i++) {
125
- let buf = Buffer.alloc(1);
126
- if (isBuf) { buf[0] = f[i]; bytes = i < f.length ? 1 : 0; }
127
- else { bytes = readSync(f.fd, buf, 0, 1, i); }
128
- if (bytes === 0) { break; } else if (
129
- bytes === 1 && buf.toString().charCodeAt() === 0
130
- ) { res = false; break; }
122
+ const maxBytes = options?.length ?? 1000;
123
+ let buf;
124
+ if (Buffer.isBuffer(file)) {
125
+ buf = file.subarray(0, maxBytes);
126
+ } else {
127
+ const fd = await fs.promises.open(file, 'r');
128
+ buf = Buffer.alloc(maxBytes);
129
+ await fd.read(buf, 0, maxBytes, 0);
130
+ await fd.close();
131
+ }
132
+ for (let i = 0; i < buf.length; i++) {
133
+ if (buf[i] === 0) return false;
131
134
  }
132
- isBuf || f?.close()
133
- return res;
135
+ return true;
134
136
  };
135
137
 
136
138
  const getConfigFilename = async (options) => {
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": "2000.3.49",
4
+ "version": "2000.3.52",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",