utilitas 1998.2.39 → 1998.2.41

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
@@ -101,7 +101,6 @@ const clients = {};
101
101
  const size8k = 7680 * 4320;
102
102
  const MAX_TOOL_RECURSION = 10;
103
103
  const LOG = { log: true };
104
- const OPENAI_BASE_URL = 'https://api.openai.com/v1';
105
104
  const sessionType = `${name.toUpperCase()}-SESSION`;
106
105
  const unifyProvider = options => unifyType(options?.provider, 'AI provider');
107
106
  const unifyEngine = options => unifyType(options?.engine, 'AI engine');
@@ -111,7 +110,6 @@ const renderText = (t, o) => _renderText(t, { extraCodeBlock: 0, ...o || {} });
111
110
  const log = (cnt, opt) => _log(cnt, import.meta.url, { time: 1, ...opt || {} });
112
111
  const CONTENT_IS_REQUIRED = 'Content is required.';
113
112
  const assertContent = content => assert(content.length, CONTENT_IS_REQUIRED);
114
- const packThink = thk => thk ? [`${THINK_STR}\n${thk}\n${THINK_END}`] : [];
115
113
  const countToolCalls = r => r?.split('\n').filter(x => x === TOOLS_STR).length;
116
114
 
117
115
  const DEFAULT_MODELS = {
@@ -663,17 +661,13 @@ const getInfoEnd = text => Math.max(...[THINK_END, TOOLS_END].map(x => {
663
661
 
664
662
  const packResp = async (resp, options) => {
665
663
  if (options?.raw) { return resp; }
666
- let [
667
- txt, audio, references, markdown, simpleText, referencesMarkdown, end,
668
- json
669
- ] = [
670
- resp.text // ChatGPT / Claude / Gemini
671
- || resp?.message?.content || '', // Ollama @tudo: Need to be updated
672
- resp?.audio?.data, // ChatGPT audio mode
673
- resp?.references, // Gemini references
674
- '', '', '', null,
675
- ];
676
- markdown = simpleText = txt;
664
+ let [txt, audio, references, simpleText, referencesMarkdown, end, json] = [
665
+ resp.text || '', // ChatGPT / Claude / Gemini / Ollama
666
+ resp?.audio?.data, // ChatGPT audio mode
667
+ resp?.references, // Gemini references
668
+ '', '', '', null,
669
+ ];
670
+ simpleText = txt;
677
671
  while ((end = getInfoEnd(simpleText))) {
678
672
  simpleText = simpleText.slice(end).trim();
679
673
  end = getInfoEnd(simpleText);
@@ -694,9 +688,7 @@ const packResp = async (resp, options) => {
694
688
  if (options?.simple && options?.audioMode) { return audio; }
695
689
  else if (options?.simple && options?.jsonMode) { return json; }
696
690
  else if (options?.simple) { return simpleText; }
697
- else if (options?.jsonMode) {
698
- markdown = `\`\`\`json\n${simpleText}\n\`\`\``;
699
- }
691
+ else if (options?.jsonMode) { txt = `\`\`\`json\n${simpleText}\n\`\`\``; }
700
692
  // references debug codes:
701
693
  // references = {
702
694
  // "segments": [
@@ -721,33 +713,30 @@ const packResp = async (resp, options) => {
721
713
  // };
722
714
  if (references?.segments?.length && references?.links?.length) {
723
715
  for (let i = references.segments.length - 1; i >= 0; i--) {
724
- let idx = markdown.indexOf(references.segments[i].text);
716
+ let idx = txt.indexOf(references.segments[i].text);
725
717
  if (idx < 0) { continue; }
726
718
  idx += references.segments[i].text.length;
727
- markdown = markdown.slice(0, idx)
719
+ txt = txt.slice(0, idx)
728
720
  + references.segments[i].indices.map(y => ` (${y + 1})`).join('')
729
- + markdown.slice(idx);
721
+ + txt.slice(idx);
730
722
  }
731
723
  referencesMarkdown = 'References:\n\n' + references.links.map(
732
724
  (x, i) => `${i + 1}. [${x.title}](${x.uri})`
733
725
  ).join('\n');
734
726
  }
735
- markdown = markdown.split('\n');
736
- for (let i in markdown) {
737
- switch (markdown[i]) {
738
- case THINK_STR: markdown[i] = MD_CODE + THINK; break;
739
- case TOOLS_STR: markdown[i] = MD_CODE + TOOLS; break;
740
- case THINK_END: case TOOLS_END: markdown[i] = MD_CODE;
727
+ txt = txt.split('\n');
728
+ for (let i in txt) {
729
+ switch (txt[i]) {
730
+ case THINK_STR: txt[i] = MD_CODE + THINK; break;
731
+ case TOOLS_STR: txt[i] = MD_CODE + TOOLS; break;
732
+ case THINK_END: case TOOLS_END: txt[i] = MD_CODE;
741
733
  }
742
734
  }
743
- markdown = markdown.join('\n');
744
- if (!options?.delta && !options?.processing) {
745
- txt = txt.trim();
746
- markdown = markdown.trim();
747
- }
735
+ txt = txt.join('\n');
736
+ !options?.delta && !options?.processing && (txt = txt.trim());
748
737
  return {
749
738
  ...text(txt), ...options?.jsonMode ? { json } : {},
750
- markdown, ...references ? { references } : {},
739
+ ...references ? { references } : {},
751
740
  ...referencesMarkdown ? { referencesMarkdown } : {},
752
741
  ...audio ? { audio, audioMimeType: options?.audioMimeType } : {},
753
742
  processing: options?.processing,
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.39",
4
+ "version": "1998.2.41",
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.39",
4
+ "version": "1998.2.41",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",