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/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/alan.mjs +20 -29
- package/lib/manifest.mjs +1 -1
- package/package.json +1 -1
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
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
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 =
|
|
716
|
+
let idx = txt.indexOf(references.segments[i].text);
|
|
723
717
|
if (idx < 0) { continue; }
|
|
724
718
|
idx += references.segments[i].text.length;
|
|
725
|
-
|
|
719
|
+
txt = txt.slice(0, idx)
|
|
726
720
|
+ references.segments[i].indices.map(y => ` (${y + 1})`).join('')
|
|
727
|
-
+
|
|
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
|
-
|
|
734
|
-
for (let i in
|
|
735
|
-
switch (
|
|
736
|
-
case THINK_STR:
|
|
737
|
-
case TOOLS_STR:
|
|
738
|
-
case THINK_END: case TOOLS_END:
|
|
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
|
-
|
|
742
|
-
|
|
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
|
-
|
|
739
|
+
...references ? { references } : {},
|
|
749
740
|
...referencesMarkdown ? { referencesMarkdown } : {},
|
|
750
741
|
...audio ? { audio, audioMimeType: options?.audioMimeType } : {},
|
|
751
742
|
processing: options?.processing,
|
package/lib/manifest.mjs
CHANGED