utilitas 1998.2.40 → 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
@@ -661,17 +661,13 @@ const getInfoEnd = text => Math.max(...[THINK_END, TOOLS_END].map(x => {
661
661
 
662
662
  const packResp = async (resp, options) => {
663
663
  if (options?.raw) { return resp; }
664
- let [
665
- txt, audio, references, markdown, simpleText, referencesMarkdown, end,
666
- json
667
- ] = [
668
- resp.text // ChatGPT / Claude / Gemini
669
- || resp?.message?.content || '', // Ollama @tudo: Need to be updated
670
- resp?.audio?.data, // ChatGPT audio mode
671
- resp?.references, // Gemini references
672
- '', '', '', null,
673
- ];
674
- 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;
675
671
  while ((end = getInfoEnd(simpleText))) {
676
672
  simpleText = simpleText.slice(end).trim();
677
673
  end = getInfoEnd(simpleText);
@@ -692,9 +688,7 @@ const packResp = async (resp, options) => {
692
688
  if (options?.simple && options?.audioMode) { return audio; }
693
689
  else if (options?.simple && options?.jsonMode) { return json; }
694
690
  else if (options?.simple) { return simpleText; }
695
- else if (options?.jsonMode) {
696
- markdown = `\`\`\`json\n${simpleText}\n\`\`\``;
697
- }
691
+ else if (options?.jsonMode) { txt = `\`\`\`json\n${simpleText}\n\`\`\``; }
698
692
  // references debug codes:
699
693
  // references = {
700
694
  // "segments": [
@@ -719,33 +713,30 @@ const packResp = async (resp, options) => {
719
713
  // };
720
714
  if (references?.segments?.length && references?.links?.length) {
721
715
  for (let i = references.segments.length - 1; i >= 0; i--) {
722
- let idx = markdown.indexOf(references.segments[i].text);
716
+ let idx = txt.indexOf(references.segments[i].text);
723
717
  if (idx < 0) { continue; }
724
718
  idx += references.segments[i].text.length;
725
- markdown = markdown.slice(0, idx)
719
+ txt = txt.slice(0, idx)
726
720
  + references.segments[i].indices.map(y => ` (${y + 1})`).join('')
727
- + markdown.slice(idx);
721
+ + txt.slice(idx);
728
722
  }
729
723
  referencesMarkdown = 'References:\n\n' + references.links.map(
730
724
  (x, i) => `${i + 1}. [${x.title}](${x.uri})`
731
725
  ).join('\n');
732
726
  }
733
- markdown = markdown.split('\n');
734
- for (let i in markdown) {
735
- switch (markdown[i]) {
736
- case THINK_STR: markdown[i] = MD_CODE + THINK; break;
737
- case TOOLS_STR: markdown[i] = MD_CODE + TOOLS; break;
738
- 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;
739
733
  }
740
734
  }
741
- markdown = markdown.join('\n');
742
- if (!options?.delta && !options?.processing) {
743
- txt = txt.trim();
744
- markdown = markdown.trim();
745
- }
735
+ txt = txt.join('\n');
736
+ !options?.delta && !options?.processing && (txt = txt.trim());
746
737
  return {
747
738
  ...text(txt), ...options?.jsonMode ? { json } : {},
748
- markdown, ...references ? { references } : {},
739
+ ...references ? { references } : {},
749
740
  ...referencesMarkdown ? { referencesMarkdown } : {},
750
741
  ...audio ? { audio, audioMimeType: options?.audioMimeType } : {},
751
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.40",
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.40",
4
+ "version": "1998.2.41",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",