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