utilitas 2001.1.67 → 2001.1.69

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
@@ -54,7 +54,7 @@ const [
54
54
  GEMINI_30_PRO, GEMINI_25_FLASH, IMAGEN_4_ULTRA, VEO_31, IMAGEN_4_UPSCALE,
55
55
  ERROR_GENERATING, GEMINI_25_FLASH_TTS, GEMINI_25_PRO_TTS, wav,
56
56
  GPT_4O_MIMI_TTS, GPT_4O_TRANSCRIBE, INVALID_AUDIO, OGG_EXT, ELLIPSIS,
57
- TOP_LIMIT, ATTACHMENT, PROCESSING, CURSOR, LN
57
+ TOP_LIMIT, ATTACHMENT, PROCESSING, CURSOR, LN, TOP
58
58
  ] = [
59
59
  'OpenAI', 'Google', 'Ollama', 'nova', 'deepseek-3.2-speciale', '```',
60
60
  'claude-opus-4.5', 'audio', 'wav', 'OPENAI_VOICE', 'medium', 'think',
@@ -72,7 +72,7 @@ const [
72
72
  'imagen-4.0-upscale-preview', 'Error generating content.',
73
73
  'gemini-2.5-flash-preview-tts', 'gemini-2.5-pro-tts', 'wav',
74
74
  'gpt-4o-mini-tts', 'gpt-4o-transcribe', 'Invalid audio data.', 'ogg',
75
- '...', 3, 'ATTACHMENT', { processing: true }, ' █', '\n',
75
+ '...', 3, 'ATTACHMENT', { processing: true }, ' █', '\n', 'top',
76
76
  ];
77
77
 
78
78
  const LN2 = `${LN}${LN}`;
@@ -1235,7 +1235,7 @@ const collectAttachments = async (options = {}) => {
1235
1235
  const selectAi = async (options = {}) => {
1236
1236
  options.aiId = ensureArray(options?.aiId).filter(x => x);
1237
1237
  const ais = await getAi(null, { all: true });
1238
- if (options.aiId.includes('top')) { // Use top AIs
1238
+ if (options.aiId.includes(TOP)) { // Use top AIs
1239
1239
  options.aiId = ais.slice(0, TOP_LIMIT).map(x => x.id);
1240
1240
  } else if (options.collected?.length) { // Select by attachments
1241
1241
  const supported = {};
@@ -1259,15 +1259,11 @@ const selectAi = async (options = {}) => {
1259
1259
  };
1260
1260
 
1261
1261
  const talk = async (request, options = {}) => {
1262
- const SOUND_ICON = '🔊';
1263
- let [sessionId, msgs] = [options.sessionId || newSessionId(), {}];
1262
+ // init
1263
+ const [sessionId, msgs, stream, SOUND_ICON]
1264
+ = [options.sessionId || newSessionId(), {}, options.stream, '🔊'];
1264
1265
  await selectAi(options);
1265
- await collectAttachments(options);
1266
- request = joinL2([ensureString(request), ...(options.collected || []).filter(
1267
- x => x.type !== ATTACHMENT && String.isString(x.content)
1268
- ).map(x => x.content)]);
1269
- const session = await getSession(sessionId, { ...options, prompt: request });
1270
- const stream = options.stream;
1266
+ // init functions
1271
1267
  const packMsg = (opts) => ({
1272
1268
  text: Object.values(msgs).find(x => x.text) ? joinL2(options.aiId.map(n => {
1273
1269
  if (msgs[n]?.ignored) { return null };
@@ -1290,7 +1286,16 @@ const talk = async (request, options = {}) => {
1290
1286
  ai && r && (msgs[ai] = r);
1291
1287
  stream && await stream(packMsg(opts));
1292
1288
  };
1289
+ // first response
1293
1290
  await multiStream(null, null, PROCESSING);
1291
+ // build prompt
1292
+ await collectAttachments(options);
1293
+ request = joinL2([ensureString(request), ...(options.collected || []).filter(
1294
+ x => x.type !== ATTACHMENT && String.isString(x.content)
1295
+ ).map(x => x.content)]);
1296
+ // get session
1297
+ const session = await getSession(sessionId, { ...options, prompt: request });
1298
+ // prompt
1294
1299
  await Promise.all(options.aiId.map(async ai => {
1295
1300
  try {
1296
1301
  return await prompt(request, {
@@ -1304,10 +1309,13 @@ const talk = async (request, options = {}) => {
1304
1309
  log(e);
1305
1310
  }
1306
1311
  }));
1312
+ // pack response
1307
1313
  const response = joinL2(Object.values(msgs).map(x => x.text));
1314
+ // save session
1308
1315
  const chat = { request, response };
1309
1316
  request && response && session.messages.push(chat);
1310
1317
  await setSession(sessionId, session, options);
1318
+ // tts
1311
1319
  if ((options?.tts || session?.config?.tts)
1312
1320
  && Object.values(msgs).find(x => !x.audio?.length)) {
1313
1321
  await ignoreErrFunc(async () => {
@@ -1318,6 +1326,7 @@ const talk = async (request, options = {}) => {
1318
1326
  }, { processing: true });
1319
1327
  }, LOG);
1320
1328
  }
1329
+ // return
1321
1330
  return { sessionId, ...chat, ...packMsg({ processing: false }) };
1322
1331
  };
1323
1332
 
@@ -1504,6 +1513,7 @@ export {
1504
1513
  MODELS,
1505
1514
  OPENAI_VOICE,
1506
1515
  RETRIEVAL,
1516
+ TOP,
1507
1517
  VEO_31,
1508
1518
  analyzeSessions,
1509
1519
  countTokens,
package/lib/bot.mjs CHANGED
@@ -9,10 +9,10 @@ const sendMd = (cId, cnt, opt) => send(cId, cnt, { parse_mode, ...opt || {} });
9
9
 
10
10
  const [ // https://limits.tginfo.me/en
11
11
  BOT_SEND, provider, signals, MESSAGE_LENGTH_LIMIT, EMOJI_THINKING,
12
- PARSE_MODE_MD, PARSE_MODE_MD_V2,
12
+ PARSE_MODE_MD, BOT
13
13
  ] = [
14
14
  'BOT_SEND', 'TELEGRAM', ['SIGINT', 'SIGTERM'], parseInt(4096 * 0.95),
15
- '💬', 'Markdown', 'MarkdownV2',
15
+ '💬', 'Markdown', '🤖',
16
16
  ];
17
17
 
18
18
  const parse_mode = PARSE_MODE_MD;
@@ -76,6 +76,8 @@ const init = async (options) => {
76
76
  bot.use(useNewReplies());
77
77
  bot.catch(console.error);
78
78
  bot.launch();
79
+ bot.botInfo = await bot.telegram.getMe();
80
+ log(`Initialized: ${BOT}${bot.botInfo.first_name} @${bot.botInfo.username} #${bot.botInfo.id}`);
79
81
  on(BOT_SEND, data => send(...data || []));
80
82
  // Graceful stop
81
83
  signals.map(signal => process.once(signal, () => end({ signal })));
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.67",
4
+ "version": "2001.1.69",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
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.67",
4
+ "version": "2001.1.69",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",