utilitas 2001.1.102 → 2001.1.104

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
@@ -1360,9 +1360,10 @@ const talk = async (request, options = {}) => {
1360
1360
  // init
1361
1361
  const [sessionId, msgs, stream]
1362
1362
  = [options.sessionId || newSessionId(), {}, options.stream];
1363
+ let result;
1363
1364
  await selectAi(options);
1364
1365
  // init functions
1365
- const packMsg = (opts) => ({
1366
+ const packMsg = (opts) => result = {
1366
1367
  text: Object.values(msgs).find(x => x.text) ? joinL2(options.aiId.map(n => {
1367
1368
  if (msgs[n]?.ignored) { return null };
1368
1369
  const ai = ais.find(x => x.id === n);
@@ -1379,7 +1380,7 @@ const talk = async (request, options = {}) => {
1379
1380
  videos: Object.values(msgs).map(x => (x.videos || []).map(y => caption(y, FEATURE_ICONS.video, x.model))).flat(),
1380
1381
  annotations: Object.values(msgs).map(x => x.annotations || []).flat(),
1381
1382
  models: Object.values(msgs).map(x => x.model),
1382
- });
1383
+ };
1383
1384
  const multiStream = async (ai, r, opts) => {
1384
1385
  ai && r && (msgs[ai] = r);
1385
1386
  stream && await stream(packMsg(opts));
@@ -1414,12 +1415,12 @@ const talk = async (request, options = {}) => {
1414
1415
  request && response && session.messages.push(chat);
1415
1416
  await setSession(sessionId, session, options);
1416
1417
  // tts
1417
- if ((options?.tts || session?.config?.tts) && response
1418
+ if ((options?.tts || session?.config?.tts) && result?.spoken
1418
1419
  && Object.values(msgs).find(x => !x.audio?.length)) {
1419
1420
  await ignoreErrFunc(async () => {
1420
1421
  const ttsAi = await getAi(null, { select: { audio: true, fast: true } });
1421
1422
  await multiStream(ttsAi.id, {
1422
- ...await tts(response, { aiId: ttsAi.id, raw: true }),
1423
+ ...await tts(result?.spoken, { aiId: ttsAi.id, raw: true }),
1423
1424
  text: FEATURE_ICONS.audio, hidden: true,
1424
1425
  }, { processing: true });
1425
1426
  }, LOG);
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.102",
4
+ "version": "2001.1.104",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
package/lib/utilitas.mjs CHANGED
@@ -850,12 +850,14 @@ const getLockKey = key => {
850
850
  };
851
851
 
852
852
  const lock = async (key, options) => {
853
- key = getLockKey(key);
854
- while (new Date().getTime() - parseInt(LOCKS?.[key] || 0)
855
- < (options?.timeout || 1000)) {
853
+ const stdKey = getLockKey(key);
854
+ while (new Date().getTime() < parseInt(LOCKS?.[stdKey] || 0)) {
856
855
  await timeout(options?.checkInterval || 1000);
857
856
  }
858
- return (LOCKS[key] = new Date().getTime());
857
+ return {
858
+ time: LOCKS[stdKey] = new Date().getTime() + (options?.timeout || 1000),
859
+ unlock: () => unlock(key),
860
+ };
859
861
  };
860
862
 
861
863
  export {
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.102",
4
+ "version": "2001.1.104",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",