utilitas 1998.2.45 → 1998.2.47

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
@@ -645,8 +645,9 @@ const buildClaudeMessage = (text, options) => {
645
645
  });
646
646
  return String.isString(text) ? {
647
647
  role: options?.role || user, content: [...attachments, {
648
- type: TEXT, text,
649
- cache_control: options?.cache_control ?? { type: 'ephemeral' }
648
+ type: TEXT, text, ...options.cache_control ? {
649
+ cache_control: { type: 'ephemeral' },
650
+ } : {},
650
651
  }],
651
652
  } : text;
652
653
  };
@@ -771,8 +772,8 @@ const buildPrompts = async (model, input, options = {}) => {
771
772
  options.reasoning && !model?.reasoning
772
773
  ), `This model does not support reasoning: ${options.model}`);
773
774
  let [systemPrompt, history, content, prompt, _system, _user, _assistant] = [
774
- null, null, input || ATTACHMENTS, null, [], null, // length hack: ATTACHMENTS
775
- { role: system }, { role: user }, { role: assistant }
775
+ null, null, input || ATTACHMENTS, null, // length hack: ATTACHMENTS
776
+ { role: system }, { role: user }, { role: assistant },
776
777
  ];
777
778
  options.systemPrompt = options.systemPrompt || INSTRUCTIONS;
778
779
  options.attachments = (
@@ -787,7 +788,7 @@ const buildPrompts = async (model, input, options = {}) => {
787
788
  break;
788
789
  case CLAUDE:
789
790
  systemPrompt = options.systemPrompt;
790
- prompt = buildClaudeMessage(content, options)
791
+ prompt = buildClaudeMessage(content, { ...options, cache_control: true });
791
792
  break;
792
793
  case OLLAMA:
793
794
  systemPrompt = buildOllamaMessage(options.systemPrompt, _system);
@@ -801,7 +802,7 @@ const buildPrompts = async (model, input, options = {}) => {
801
802
  }
802
803
  const msgBuilder = () => {
803
804
  history = [];
804
- (options.messages?.length ? options.messages : []).map(x => {
805
+ (options.messages?.length ? options.messages : []).map((x, i) => {
805
806
  switch (options.flavor) {
806
807
  case CHATGPT:
807
808
  history.push(buildGptMessage(x.request, _user));
@@ -812,8 +813,8 @@ const buildPrompts = async (model, input, options = {}) => {
812
813
  history.push(buildClaudeMessage(x.response, _assistant));
813
814
  break;
814
815
  case OLLAMA:
815
- history.push(buildClaudeMessage(x.request, _user));
816
- history.push(buildClaudeMessage(x.response, _assistant));
816
+ history.push(buildOllamaMessage(x.request, _user));
817
+ history.push(buildOllamaMessage(x.response, _assistant));
817
818
  break;
818
819
  case GEMINI:
819
820
  if (options.attachments?.length) { return; }
@@ -849,6 +850,7 @@ const buildPrompts = async (model, input, options = {}) => {
849
850
  content = trimTailing(trimTailing(content).slice(0, -1)) + '...';
850
851
  }
851
852
  }, model.maxInputTokens - options.attachments?.length * ATTACHMENT_TOKEN_COST);
853
+ print(JSON.stringify(history));
852
854
  return { systemPrompt, history, prompt };
853
855
  };
854
856
 
package/lib/bot.mjs CHANGED
@@ -1,24 +1,26 @@
1
1
  // @todo: New text of the message, 1-4096 characters after entities parsing
2
2
 
3
3
  import {
4
+ log as _log,
4
5
  base64Encode, countKeys, ensureArray, ensureString, getTimeIcon,
5
6
  humanReadableBoolean, ignoreErrFunc, insensitiveCompare, insensitiveHas,
6
- isSet, lastItem, log as _log, need, parseJson, prettyJson, splitArgs,
7
- timeout, trim, which, throwError,
7
+ isSet, lastItem,
8
+ need, parseJson, prettyJson, splitArgs,
9
+ throwError,
10
+ timeout, trim, which,
8
11
  } from './utilitas.mjs';
9
12
 
10
- import { BASE64, BUFFER, convert, FILE, isTextFile, tryRm } from './storage.mjs';
13
+ import { readdirSync } from 'fs';
14
+ import { parseArgs as _parseArgs } from 'node:util';
11
15
  import { basename, join } from 'path';
16
+ import { jpeg, ogg, wav } from './alan.mjs';
17
+ import { isPrimary, on, report } from './callosum.mjs';
18
+ import { cleanSql, encodeVector, MYSQL, POSTGRESQL } from './dbio.mjs';
12
19
  import { convertAudioTo16kNanoPcmWave } from './media.mjs';
13
- import { distill } from './web.mjs';
14
- import { fakeUuid } from './uoid.mjs';
15
20
  import { get } from './shot.mjs';
16
- import { isPrimary, on, report } from './callosum.mjs';
17
- import { jpeg, ogg, wav } from './alan.mjs';
18
- import { MYSQL, POSTGRESQL, cleanSql, encodeVector } from './dbio.mjs';
19
- import { parseArgs as _parseArgs } from 'node:util';
21
+ import { BASE64, BUFFER, convert, FILE, isTextFile, tryRm } from './storage.mjs';
22
+ import { fakeUuid } from './uoid.mjs';
20
23
  import { parseOfficeFile } from './vision.mjs';
21
- import { readdirSync } from 'fs';
22
24
 
23
25
  const _NEED = ['mime', 'telegraf'];
24
26
  // 👇 https://core.telegram.org/bots/faq#my-bot-is-hitting-limits-how-do-i-avoid-this
@@ -730,20 +732,20 @@ const subconscious = [{
730
732
  );
731
733
  await next();
732
734
  },
733
- }, {
734
- run: true, priority: -8870, name: 'web', func: async (ctx, next) => {
735
- if (ctx.entities.some(e => e.type === 'url')) {
736
- await ctx.ok(EMOJI_LOOK);
737
- for (let e of ctx.entities) {
738
- if (e.type !== 'url') { continue; }
739
- const content = await ignoreErrFunc(async () => (
740
- await distill(e.matched)
741
- )?.summary);
742
- content && ctx.collect(content, 'URL');
743
- }
744
- }
745
- await next();
746
- },
735
+ // }, {
736
+ // run: true, priority: -8870, name: 'web', func: async (ctx, next) => {
737
+ // if (ctx.entities.some(e => e.type === 'url')) {
738
+ // await ctx.ok(EMOJI_LOOK);
739
+ // for (let e of ctx.entities) {
740
+ // if (e.type !== 'url') { continue; }
741
+ // const content = await ignoreErrFunc(async () => (
742
+ // await distill(e.matched)
743
+ // )?.summary);
744
+ // content && ctx.collect(content, 'URL');
745
+ // }
746
+ // }
747
+ // await next();
748
+ // },
747
749
  }, {
748
750
  run: true, priority: -8860, name: 'vision', func: async (ctx, next) => {
749
751
  ctx.collect(ctx.m?.caption || '');
@@ -1146,21 +1148,14 @@ export {
1146
1148
  COMMAND_LIMIT,
1147
1149
  EMOJI_BOT,
1148
1150
  EMOJI_SPEECH,
1149
- EMOJI_THINKING,
1150
- GROUP_LIMIT,
1151
- HELLO,
1152
- MESSAGE_LENGTH_LIMIT,
1153
- MESSAGE_SOFT_LIMIT,
1154
- PRIVATE_LIMIT,
1155
- end,
1156
- init,
1151
+ EMOJI_THINKING, end, GROUP_LIMIT,
1152
+ HELLO, init,
1157
1153
  lines,
1158
1154
  lines2,
1159
- map,
1160
- newCommand,
1155
+ map, MESSAGE_LENGTH_LIMIT,
1156
+ MESSAGE_SOFT_LIMIT, newCommand,
1161
1157
  oList,
1162
- paging,
1163
- send,
1158
+ paging, PRIVATE_LIMIT, send,
1164
1159
  sendMd,
1165
- uList,
1160
+ uList
1166
1161
  };
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": "1998.2.45",
4
+ "version": "1998.2.47",
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": "1998.2.45",
4
+ "version": "1998.2.47",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",