@ax-llm/ax 11.0.56 → 11.0.58
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/index.cjs +238 -102
- package/index.cjs.map +1 -1
- package/index.d.cts +27 -1
- package/index.d.ts +27 -1
- package/index.js +238 -102
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -835,6 +835,46 @@ var ColorLog = class {
|
|
|
835
835
|
|
|
836
836
|
// ai/debug.ts
|
|
837
837
|
var colorLog = new ColorLog();
|
|
838
|
+
var defaultOutput = (message) => {
|
|
839
|
+
process.stdout.write(message);
|
|
840
|
+
};
|
|
841
|
+
var createDefaultLogger = (output = defaultOutput) => {
|
|
842
|
+
return (message, options) => {
|
|
843
|
+
const tags = options?.tags ?? [];
|
|
844
|
+
let formattedMessage = message;
|
|
845
|
+
if (tags.includes("error")) {
|
|
846
|
+
formattedMessage = colorLog.red(formattedMessage);
|
|
847
|
+
} else if (tags.includes("success") || tags.includes("responseContent")) {
|
|
848
|
+
formattedMessage = colorLog.greenBright(formattedMessage);
|
|
849
|
+
} else if (tags.includes("functionName")) {
|
|
850
|
+
formattedMessage = colorLog.whiteBright(formattedMessage);
|
|
851
|
+
} else if (tags.includes("functionArg") || tags.includes("systemContent") || tags.includes("assistantContent")) {
|
|
852
|
+
formattedMessage = colorLog.blueBright(formattedMessage);
|
|
853
|
+
} else if (tags.includes("warning") || tags.includes("discovery")) {
|
|
854
|
+
formattedMessage = colorLog.yellow(formattedMessage);
|
|
855
|
+
}
|
|
856
|
+
if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart")) {
|
|
857
|
+
formattedMessage = `
|
|
858
|
+
${formattedMessage}`;
|
|
859
|
+
} else if (tags.includes("responseEnd") || tags.includes("systemEnd") || tags.includes("userEnd")) {
|
|
860
|
+
formattedMessage = `${formattedMessage}
|
|
861
|
+
`;
|
|
862
|
+
} else if (tags.includes("assistantStart")) {
|
|
863
|
+
formattedMessage = `
|
|
864
|
+
${formattedMessage}
|
|
865
|
+
`;
|
|
866
|
+
} else if (tags.includes("error")) {
|
|
867
|
+
formattedMessage = `
|
|
868
|
+
${formattedMessage}
|
|
869
|
+
`;
|
|
870
|
+
} else if (tags.includes("functionEnd")) {
|
|
871
|
+
formattedMessage = `${formattedMessage}
|
|
872
|
+
`;
|
|
873
|
+
}
|
|
874
|
+
output(formattedMessage);
|
|
875
|
+
};
|
|
876
|
+
};
|
|
877
|
+
var defaultLogger = createDefaultLogger();
|
|
838
878
|
var formatChatMessage = (msg, hideContent, hideSystemPrompt) => {
|
|
839
879
|
switch (msg.role) {
|
|
840
880
|
case "system":
|
|
@@ -842,30 +882,30 @@ var formatChatMessage = (msg, hideContent, hideSystemPrompt) => {
|
|
|
842
882
|
return "";
|
|
843
883
|
}
|
|
844
884
|
return `
|
|
845
|
-
|
|
846
|
-
${
|
|
885
|
+
System:
|
|
886
|
+
${msg.content}`;
|
|
847
887
|
case "function":
|
|
848
888
|
return `
|
|
849
|
-
|
|
850
|
-
${
|
|
889
|
+
Function Result:
|
|
890
|
+
${msg.result}`;
|
|
851
891
|
case "user": {
|
|
852
892
|
if (typeof msg.content === "string") {
|
|
853
893
|
return `
|
|
854
|
-
|
|
855
|
-
${
|
|
894
|
+
User:
|
|
895
|
+
${msg.content}`;
|
|
856
896
|
}
|
|
857
897
|
const items = msg.content.map((v) => {
|
|
858
898
|
switch (v.type) {
|
|
859
899
|
case "text":
|
|
860
|
-
return
|
|
900
|
+
return v.text;
|
|
861
901
|
case "image":
|
|
862
|
-
return `(Image, ${v.mimeType}) ${
|
|
902
|
+
return `(Image, ${v.mimeType}) ${v.image.substring(0, 10)}`;
|
|
863
903
|
default:
|
|
864
904
|
throw new Error("Invalid content type");
|
|
865
905
|
}
|
|
866
906
|
});
|
|
867
907
|
return `
|
|
868
|
-
|
|
908
|
+
User:
|
|
869
909
|
${items.join("\n")}`;
|
|
870
910
|
}
|
|
871
911
|
case "assistant": {
|
|
@@ -875,62 +915,64 @@ ${items.join("\n")}`;
|
|
|
875
915
|
return `${fn.name}(${args})`;
|
|
876
916
|
});
|
|
877
917
|
return `
|
|
878
|
-
|
|
879
|
-
${
|
|
918
|
+
Functions:
|
|
919
|
+
${fns.join("\n")}`;
|
|
880
920
|
}
|
|
881
921
|
return `
|
|
882
|
-
|
|
883
|
-
${hideContent ? "" :
|
|
922
|
+
Assistant:
|
|
923
|
+
${hideContent ? "" : msg.content ?? "<empty>"}`;
|
|
884
924
|
}
|
|
885
925
|
default:
|
|
886
926
|
throw new Error("Invalid role");
|
|
887
927
|
}
|
|
888
928
|
};
|
|
889
|
-
var logChatRequestMessage = (msg, hideSystemPrompt) => {
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
929
|
+
var logChatRequestMessage = (msg, hideSystemPrompt, logger = defaultLogger) => {
|
|
930
|
+
const formattedMessage = formatChatMessage(msg, false, hideSystemPrompt);
|
|
931
|
+
if (formattedMessage) {
|
|
932
|
+
const tags = msg.role === "system" ? ["systemStart", "systemContent"] : msg.role === "function" ? ["functionName"] : msg.role === "user" ? ["userStart", "userContent"] : [];
|
|
933
|
+
logger(formattedMessage, { tags });
|
|
934
|
+
}
|
|
935
|
+
logger("Assistant:", { tags: ["assistantStart"] });
|
|
893
936
|
};
|
|
894
|
-
var logChatRequest = (chatPrompt, hideSystemPrompt) => {
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
937
|
+
var logChatRequest = (chatPrompt, hideSystemPrompt, logger = defaultLogger) => {
|
|
938
|
+
for (const msg of chatPrompt ?? []) {
|
|
939
|
+
const formattedMessage = formatChatMessage(msg, false, hideSystemPrompt);
|
|
940
|
+
if (formattedMessage) {
|
|
941
|
+
const tags = msg.role === "system" ? ["systemContent"] : msg.role === "function" ? ["functionName"] : msg.role === "user" ? ["userContent"] : [];
|
|
942
|
+
logger(formattedMessage, { tags });
|
|
943
|
+
}
|
|
901
944
|
}
|
|
945
|
+
logger("Assistant:", { tags: ["assistantStart"] });
|
|
902
946
|
};
|
|
903
|
-
var logResponseResult = (r) => {
|
|
947
|
+
var logResponseResult = (r, logger = defaultLogger) => {
|
|
904
948
|
if (r.content) {
|
|
905
|
-
|
|
949
|
+
logger(r.content, { tags: ["responseContent"] });
|
|
906
950
|
}
|
|
907
|
-
if (r.functionCalls) {
|
|
951
|
+
if (r.functionCalls && r.functionCalls.length > 0) {
|
|
908
952
|
for (const [i, f] of r.functionCalls.entries()) {
|
|
909
953
|
if (f.function.name) {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
}
|
|
913
|
-
process.stdout.write(
|
|
914
|
-
`Function ${i + 1} -> ${colorLog.greenBright(f.function.name)}`
|
|
915
|
-
);
|
|
954
|
+
logger(`[${i + 1}] ${f.function.name}`, {
|
|
955
|
+
tags: ["functionName"]
|
|
956
|
+
});
|
|
916
957
|
}
|
|
917
958
|
if (f.function.params) {
|
|
918
959
|
const params = typeof f.function.params === "string" ? f.function.params : JSON.stringify(f.function.params, null, 2);
|
|
919
|
-
|
|
960
|
+
logger(params, { tags: ["functionArg"] });
|
|
920
961
|
}
|
|
921
962
|
}
|
|
963
|
+
logger("", { tags: ["functionEnd"] });
|
|
922
964
|
}
|
|
923
965
|
};
|
|
924
|
-
var logResponse = (resp) => {
|
|
966
|
+
var logResponse = (resp, logger = defaultLogger) => {
|
|
925
967
|
if (!resp.results) {
|
|
926
968
|
return;
|
|
927
969
|
}
|
|
928
970
|
for (const r of resp.results) {
|
|
929
|
-
logResponseResult(r);
|
|
971
|
+
logResponseResult(r, logger);
|
|
930
972
|
}
|
|
931
973
|
};
|
|
932
|
-
var logResponseDelta = (delta) => {
|
|
933
|
-
|
|
974
|
+
var logResponseDelta = (delta, logger = defaultLogger) => {
|
|
975
|
+
logger(delta, { tags: ["responseContent"] });
|
|
934
976
|
};
|
|
935
977
|
|
|
936
978
|
// ai/base.ts
|
|
@@ -944,6 +986,9 @@ var axBaseAIDefaultCreativeConfig = () => structuredClone({
|
|
|
944
986
|
topP: 0.7,
|
|
945
987
|
frequencyPenalty: 0.2
|
|
946
988
|
});
|
|
989
|
+
var defaultLogger2 = (message, _options) => {
|
|
990
|
+
process.stdout.write(message);
|
|
991
|
+
};
|
|
947
992
|
var AxBaseAI = class {
|
|
948
993
|
constructor(aiImpl, {
|
|
949
994
|
name,
|
|
@@ -983,6 +1028,7 @@ var AxBaseAI = class {
|
|
|
983
1028
|
excludeContentFromTrace;
|
|
984
1029
|
models;
|
|
985
1030
|
abortSignal;
|
|
1031
|
+
logger = defaultLogger2;
|
|
986
1032
|
modelInfo;
|
|
987
1033
|
modelUsage;
|
|
988
1034
|
embedModelUsage;
|
|
@@ -1044,6 +1090,7 @@ var AxBaseAI = class {
|
|
|
1044
1090
|
this.tracer = options.tracer;
|
|
1045
1091
|
this.excludeContentFromTrace = options.excludeContentFromTrace;
|
|
1046
1092
|
this.abortSignal = options.abortSignal;
|
|
1093
|
+
this.logger = options.logger ?? defaultLogger2;
|
|
1047
1094
|
}
|
|
1048
1095
|
getOptions() {
|
|
1049
1096
|
return {
|
|
@@ -1053,9 +1100,13 @@ var AxBaseAI = class {
|
|
|
1053
1100
|
tracer: this.tracer,
|
|
1054
1101
|
timeout: this.timeout,
|
|
1055
1102
|
excludeContentFromTrace: this.excludeContentFromTrace,
|
|
1056
|
-
abortSignal: this.abortSignal
|
|
1103
|
+
abortSignal: this.abortSignal,
|
|
1104
|
+
logger: this.logger
|
|
1057
1105
|
};
|
|
1058
1106
|
}
|
|
1107
|
+
getLogger() {
|
|
1108
|
+
return this.logger;
|
|
1109
|
+
}
|
|
1059
1110
|
getModelList() {
|
|
1060
1111
|
const models = [];
|
|
1061
1112
|
for (const model of this.models ?? []) {
|
|
@@ -1243,7 +1294,11 @@ var AxBaseAI = class {
|
|
|
1243
1294
|
return res2;
|
|
1244
1295
|
};
|
|
1245
1296
|
if (debug) {
|
|
1246
|
-
logChatRequest(
|
|
1297
|
+
logChatRequest(
|
|
1298
|
+
req.chatPrompt,
|
|
1299
|
+
options?.debugHideSystemPrompt,
|
|
1300
|
+
options?.logger ?? this.logger
|
|
1301
|
+
);
|
|
1247
1302
|
}
|
|
1248
1303
|
const rt = options?.rateLimiter ?? this.rt;
|
|
1249
1304
|
const rv = rt ? await rt(fn, { modelUsage: this.modelUsage }) : await fn();
|
|
@@ -1274,13 +1329,14 @@ var AxBaseAI = class {
|
|
|
1274
1329
|
setChatResponseEvents(res2, span, this.excludeContentFromTrace);
|
|
1275
1330
|
}
|
|
1276
1331
|
if (debug) {
|
|
1277
|
-
logResponse(res2);
|
|
1332
|
+
logResponse(res2, options?.logger ?? this.logger);
|
|
1278
1333
|
}
|
|
1279
1334
|
return res2;
|
|
1280
1335
|
};
|
|
1281
1336
|
const doneCb = async (_values) => {
|
|
1282
1337
|
if (debug) {
|
|
1283
|
-
|
|
1338
|
+
const logger = options?.logger ?? this.logger;
|
|
1339
|
+
logger("", { tags: ["responseEnd"] });
|
|
1284
1340
|
}
|
|
1285
1341
|
if (span?.isRecording()) {
|
|
1286
1342
|
span.end();
|
|
@@ -1324,7 +1380,10 @@ var AxBaseAI = class {
|
|
|
1324
1380
|
span.end();
|
|
1325
1381
|
}
|
|
1326
1382
|
if (debug) {
|
|
1327
|
-
logResponse(res);
|
|
1383
|
+
logResponse(res, options?.logger ?? this.logger);
|
|
1384
|
+
}
|
|
1385
|
+
if (debug) {
|
|
1386
|
+
this.logger("", { tags: ["responseEnd"] });
|
|
1328
1387
|
}
|
|
1329
1388
|
return res;
|
|
1330
1389
|
}
|
|
@@ -1591,6 +1650,8 @@ var GoogleVertexAuth = class {
|
|
|
1591
1650
|
|
|
1592
1651
|
// ai/anthropic/types.ts
|
|
1593
1652
|
var AxAIAnthropicModel = /* @__PURE__ */ ((AxAIAnthropicModel2) => {
|
|
1653
|
+
AxAIAnthropicModel2["Claude4Opus"] = "claude-opus-4-20250514";
|
|
1654
|
+
AxAIAnthropicModel2["Claude4Sonnet"] = "claude-sonnet-4-20250514";
|
|
1594
1655
|
AxAIAnthropicModel2["Claude37Sonnet"] = "claude-3-7-sonnet-latest";
|
|
1595
1656
|
AxAIAnthropicModel2["Claude35Sonnet"] = "claude-3-5-sonnet-latest";
|
|
1596
1657
|
AxAIAnthropicModel2["Claude35Haiku"] = "claude-3-5-haiku-latest";
|
|
@@ -1613,50 +1674,80 @@ var AxAIAnthropicVertexModel = /* @__PURE__ */ ((AxAIAnthropicVertexModel2) => {
|
|
|
1613
1674
|
|
|
1614
1675
|
// ai/anthropic/info.ts
|
|
1615
1676
|
var axModelInfoAnthropic = [
|
|
1616
|
-
//
|
|
1677
|
+
// 4
|
|
1678
|
+
{
|
|
1679
|
+
name: "claude-opus-4-20250514" /* Claude4Opus */,
|
|
1680
|
+
currency: "usd",
|
|
1681
|
+
promptTokenCostPer1M: 15,
|
|
1682
|
+
completionTokenCostPer1M: 75,
|
|
1683
|
+
maxTokens: 32e3
|
|
1684
|
+
},
|
|
1685
|
+
{
|
|
1686
|
+
name: "claude-sonnet-4-20250514" /* Claude4Sonnet */,
|
|
1687
|
+
currency: "usd",
|
|
1688
|
+
promptTokenCostPer1M: 3,
|
|
1689
|
+
completionTokenCostPer1M: 15,
|
|
1690
|
+
maxTokens: 64e3
|
|
1691
|
+
},
|
|
1692
|
+
// 3.7
|
|
1693
|
+
{
|
|
1694
|
+
name: "claude-3-7-sonnet-latest" /* Claude37Sonnet */,
|
|
1695
|
+
currency: "usd",
|
|
1696
|
+
promptTokenCostPer1M: 3,
|
|
1697
|
+
completionTokenCostPer1M: 15,
|
|
1698
|
+
maxTokens: 64e3
|
|
1699
|
+
},
|
|
1700
|
+
// 3.5
|
|
1617
1701
|
{
|
|
1618
1702
|
name: "claude-3-5-sonnet-latest" /* Claude35Sonnet */,
|
|
1619
1703
|
currency: "usd",
|
|
1620
1704
|
promptTokenCostPer1M: 3,
|
|
1621
|
-
completionTokenCostPer1M: 15
|
|
1705
|
+
completionTokenCostPer1M: 15,
|
|
1706
|
+
maxTokens: 8192
|
|
1622
1707
|
},
|
|
1623
1708
|
{
|
|
1624
1709
|
name: "claude-3-5-haiku-latest" /* Claude35Haiku */,
|
|
1625
1710
|
currency: "usd",
|
|
1626
1711
|
promptTokenCostPer1M: 0.8,
|
|
1627
|
-
completionTokenCostPer1M: 4
|
|
1712
|
+
completionTokenCostPer1M: 4,
|
|
1713
|
+
maxTokens: 8192
|
|
1628
1714
|
},
|
|
1629
1715
|
// 3
|
|
1630
1716
|
{
|
|
1631
1717
|
name: "claude-3-opus-latest" /* Claude3Opus */,
|
|
1632
1718
|
currency: "usd",
|
|
1633
1719
|
promptTokenCostPer1M: 15,
|
|
1634
|
-
completionTokenCostPer1M: 75
|
|
1720
|
+
completionTokenCostPer1M: 75,
|
|
1721
|
+
maxTokens: 4096
|
|
1635
1722
|
},
|
|
1636
1723
|
{
|
|
1637
1724
|
name: "claude-3-sonnet-20240229" /* Claude3Sonnet */,
|
|
1638
1725
|
currency: "usd",
|
|
1639
1726
|
promptTokenCostPer1M: 3,
|
|
1640
|
-
completionTokenCostPer1M: 15
|
|
1727
|
+
completionTokenCostPer1M: 15,
|
|
1728
|
+
maxTokens: 4096
|
|
1641
1729
|
},
|
|
1642
1730
|
{
|
|
1643
1731
|
name: "claude-3-haiku-20240307" /* Claude3Haiku */,
|
|
1644
1732
|
currency: "usd",
|
|
1645
1733
|
promptTokenCostPer1M: 0.25,
|
|
1646
|
-
completionTokenCostPer1M: 1.25
|
|
1734
|
+
completionTokenCostPer1M: 1.25,
|
|
1735
|
+
maxTokens: 4096
|
|
1647
1736
|
},
|
|
1648
|
-
//
|
|
1737
|
+
// 2.1
|
|
1649
1738
|
{
|
|
1650
1739
|
name: "claude-2.1" /* Claude21 */,
|
|
1651
1740
|
currency: "usd",
|
|
1652
1741
|
promptTokenCostPer1M: 8,
|
|
1653
|
-
completionTokenCostPer1M: 25
|
|
1742
|
+
completionTokenCostPer1M: 25,
|
|
1743
|
+
maxTokens: 4096
|
|
1654
1744
|
},
|
|
1655
1745
|
{
|
|
1656
1746
|
name: "claude-instant-1.2" /* ClaudeInstant12 */,
|
|
1657
1747
|
currency: "usd",
|
|
1658
1748
|
promptTokenCostPer1M: 0.8,
|
|
1659
|
-
completionTokenCostPer1M: 2.24
|
|
1749
|
+
completionTokenCostPer1M: 2.24,
|
|
1750
|
+
maxTokens: 4096
|
|
1660
1751
|
}
|
|
1661
1752
|
];
|
|
1662
1753
|
|
|
@@ -1681,7 +1772,7 @@ var AxAIAnthropicImpl = class {
|
|
|
1681
1772
|
getModelConfig() {
|
|
1682
1773
|
const { config } = this;
|
|
1683
1774
|
return {
|
|
1684
|
-
maxTokens: config.maxTokens,
|
|
1775
|
+
maxTokens: config.maxTokens ?? 4096,
|
|
1685
1776
|
temperature: config.temperature,
|
|
1686
1777
|
topP: config.topP,
|
|
1687
1778
|
topK: config.topK,
|
|
@@ -1744,13 +1835,18 @@ var AxAIAnthropicImpl = class {
|
|
|
1744
1835
|
input_schema: v.parameters
|
|
1745
1836
|
})
|
|
1746
1837
|
);
|
|
1838
|
+
const maxTokens = req.modelConfig?.maxTokens ?? this.config.maxTokens;
|
|
1839
|
+
const stopSequences = req.modelConfig?.stopSequences ?? this.config.stopSequences;
|
|
1840
|
+
const temperature = req.modelConfig?.temperature ?? this.config.temperature;
|
|
1841
|
+
const topP = req.modelConfig?.topP ?? this.config.topP;
|
|
1842
|
+
const topK = req.modelConfig?.topK ?? this.config.topK;
|
|
1747
1843
|
const reqValue = {
|
|
1748
1844
|
...this.isVertex ? { anthropic_version: "vertex-2023-10-16" } : { model },
|
|
1749
|
-
max_tokens:
|
|
1750
|
-
stop_sequences:
|
|
1751
|
-
temperature
|
|
1752
|
-
top_p:
|
|
1753
|
-
top_k:
|
|
1845
|
+
...maxTokens ? { max_tokens: maxTokens } : {},
|
|
1846
|
+
...stopSequences && stopSequences.length > 0 ? { stop_sequences: stopSequences } : {},
|
|
1847
|
+
...temperature ? { temperature } : {},
|
|
1848
|
+
...topP ? { top_p: topP } : {},
|
|
1849
|
+
...topK ? { top_k: topK } : {},
|
|
1754
1850
|
...toolsChoice,
|
|
1755
1851
|
...tools && tools.length > 0 ? { tools } : {},
|
|
1756
1852
|
...stream ? { stream: true } : {},
|
|
@@ -5272,6 +5368,9 @@ var AxAI = class {
|
|
|
5272
5368
|
getOptions() {
|
|
5273
5369
|
return this.ai.getOptions();
|
|
5274
5370
|
}
|
|
5371
|
+
getLogger() {
|
|
5372
|
+
return this.ai.getLogger();
|
|
5373
|
+
}
|
|
5275
5374
|
};
|
|
5276
5375
|
|
|
5277
5376
|
// ai/x-grok/types.ts
|
|
@@ -5491,7 +5590,7 @@ var MemoryImpl = class {
|
|
|
5491
5590
|
if (this.options?.debug) {
|
|
5492
5591
|
if (delta && typeof delta === "string") {
|
|
5493
5592
|
debugResponseDelta(delta);
|
|
5494
|
-
} else if (
|
|
5593
|
+
} else if (!delta && (content || functionCalls)) {
|
|
5495
5594
|
debugResponse({ content, name, functionCalls });
|
|
5496
5595
|
}
|
|
5497
5596
|
}
|
|
@@ -6433,7 +6532,6 @@ function formatDescription(str) {
|
|
|
6433
6532
|
}
|
|
6434
6533
|
|
|
6435
6534
|
// dsp/validate.ts
|
|
6436
|
-
var colorLog4 = new ColorLog();
|
|
6437
6535
|
var ValidationError = class extends Error {
|
|
6438
6536
|
fields;
|
|
6439
6537
|
constructor({
|
|
@@ -6474,10 +6572,11 @@ function handleValidationError(mem, errorFields, ai, promptTemplate, sessionId)
|
|
|
6474
6572
|
mem.addTag("error");
|
|
6475
6573
|
if (ai.getOptions().debug) {
|
|
6476
6574
|
const errors = errorFields.map((field) => `- ${field.title}: ${field.description}`).join("\n");
|
|
6477
|
-
|
|
6478
|
-
|
|
6479
|
-
${errors}
|
|
6480
|
-
|
|
6575
|
+
const logger = ai.getLogger();
|
|
6576
|
+
logger(`\u274C Error Correction:
|
|
6577
|
+
${errors}`, {
|
|
6578
|
+
tags: ["error"]
|
|
6579
|
+
});
|
|
6481
6580
|
}
|
|
6482
6581
|
}
|
|
6483
6582
|
|
|
@@ -7057,7 +7156,6 @@ var validateJSONSchema = (schema) => {
|
|
|
7057
7156
|
};
|
|
7058
7157
|
|
|
7059
7158
|
// dsp/functions.ts
|
|
7060
|
-
var colorLog5 = new ColorLog();
|
|
7061
7159
|
var AxFunctionError = class extends Error {
|
|
7062
7160
|
constructor(fields) {
|
|
7063
7161
|
super();
|
|
@@ -7226,12 +7324,11 @@ var processFunctions = async (ai, functionList, functionCalls, mem, sessionId, t
|
|
|
7226
7324
|
);
|
|
7227
7325
|
mem.addTag("error");
|
|
7228
7326
|
if (ai.getOptions().debug) {
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
|
|
7232
|
-
|
|
7233
|
-
|
|
7234
|
-
);
|
|
7327
|
+
const logger = ai.getLogger();
|
|
7328
|
+
logger(`\u274C Function Error Correction:
|
|
7329
|
+
${result}`, {
|
|
7330
|
+
tags: ["error"]
|
|
7331
|
+
});
|
|
7235
7332
|
}
|
|
7236
7333
|
} else {
|
|
7237
7334
|
throw e;
|
|
@@ -7997,9 +8094,11 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7997
8094
|
values = {};
|
|
7998
8095
|
excludeContentFromTrace = false;
|
|
7999
8096
|
thoughtFieldName;
|
|
8097
|
+
logger;
|
|
8000
8098
|
constructor(signature, options) {
|
|
8001
8099
|
super(signature, { description: options?.description });
|
|
8002
8100
|
this.options = options;
|
|
8101
|
+
this.logger = options?.logger;
|
|
8003
8102
|
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
8004
8103
|
const promptTemplateOptions = {
|
|
8005
8104
|
functions: options?.functions,
|
|
@@ -8287,6 +8386,10 @@ Content: ${content}`
|
|
|
8287
8386
|
xstate
|
|
8288
8387
|
);
|
|
8289
8388
|
}
|
|
8389
|
+
if (ai.getOptions().debug) {
|
|
8390
|
+
const logger = ai.getLogger();
|
|
8391
|
+
logger("", { tags: ["responseEnd"] });
|
|
8392
|
+
}
|
|
8290
8393
|
}
|
|
8291
8394
|
async processResponse({
|
|
8292
8395
|
ai,
|
|
@@ -8414,7 +8517,8 @@ Content: ${result.content}`
|
|
|
8414
8517
|
continue multiStepLoop;
|
|
8415
8518
|
}
|
|
8416
8519
|
if (debug) {
|
|
8417
|
-
|
|
8520
|
+
const logger = options.logger ?? this.logger ?? ai.getLogger();
|
|
8521
|
+
logger("", { tags: ["responseEnd"] });
|
|
8418
8522
|
}
|
|
8419
8523
|
return;
|
|
8420
8524
|
} catch (e) {
|
|
@@ -8605,10 +8709,14 @@ function processChildAgentFunction(childFunction, parentValues, parentInputKeys,
|
|
|
8605
8709
|
...pick(parentValues, injectionKeys)
|
|
8606
8710
|
};
|
|
8607
8711
|
if (options.debug && injectionKeys.length > 0) {
|
|
8608
|
-
|
|
8609
|
-
|
|
8610
|
-
|
|
8611
|
-
|
|
8712
|
+
const ai = funcOptions?.ai;
|
|
8713
|
+
if (ai) {
|
|
8714
|
+
const logger = ai.getLogger();
|
|
8715
|
+
logger(
|
|
8716
|
+
`Function Params: ${JSON.stringify(updatedChildArgs, null, 2)}`,
|
|
8717
|
+
{ tags: ["functionArg"] }
|
|
8718
|
+
);
|
|
8719
|
+
}
|
|
8612
8720
|
}
|
|
8613
8721
|
return await originalFunc(updatedChildArgs, funcOptions);
|
|
8614
8722
|
};
|
|
@@ -8717,18 +8825,18 @@ var AxAgent = class {
|
|
|
8717
8825
|
}
|
|
8718
8826
|
const debug = this.getDebug(ai, options);
|
|
8719
8827
|
if (debug) {
|
|
8720
|
-
|
|
8721
|
-
|
|
8722
|
-
|
|
8828
|
+
const logger = ai.getLogger();
|
|
8829
|
+
logger(`\u{1F916} Agent ${this.name} starting...`, {
|
|
8830
|
+
tags: ["assistantStart"]
|
|
8831
|
+
});
|
|
8723
8832
|
}
|
|
8724
8833
|
const ret = await boundFunc(ai, values, {
|
|
8725
8834
|
...options,
|
|
8726
8835
|
model
|
|
8727
8836
|
});
|
|
8728
8837
|
if (debug) {
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
`);
|
|
8838
|
+
const logger = ai.getLogger();
|
|
8839
|
+
logger(`\u{1F916} Agent ${this.name} completed.`, { tags: ["assistantEnd"] });
|
|
8732
8840
|
}
|
|
8733
8841
|
const sig = this.program.getSignature();
|
|
8734
8842
|
const outFields = sig.getOutputFields();
|
|
@@ -9131,6 +9239,9 @@ var AxBalancer = class _AxBalancer {
|
|
|
9131
9239
|
getOptions() {
|
|
9132
9240
|
return this.currentService.getOptions();
|
|
9133
9241
|
}
|
|
9242
|
+
getLogger() {
|
|
9243
|
+
return this.currentService.getLogger();
|
|
9244
|
+
}
|
|
9134
9245
|
};
|
|
9135
9246
|
function validateModels2(services) {
|
|
9136
9247
|
const serviceWithModel = services.find(
|
|
@@ -11566,6 +11677,11 @@ var AxMockAIService = class {
|
|
|
11566
11677
|
getOptions() {
|
|
11567
11678
|
return this.config.options ?? {};
|
|
11568
11679
|
}
|
|
11680
|
+
getLogger() {
|
|
11681
|
+
return this.config.options?.logger ?? ((message) => {
|
|
11682
|
+
process.stdout.write(message);
|
|
11683
|
+
});
|
|
11684
|
+
}
|
|
11569
11685
|
updateMetrics(type) {
|
|
11570
11686
|
const latency = this.config.latencyMs ?? 0;
|
|
11571
11687
|
this.metrics.latency[type].samples.push(latency);
|
|
@@ -11588,7 +11704,7 @@ var AxMockAIService = class {
|
|
|
11588
11704
|
};
|
|
11589
11705
|
|
|
11590
11706
|
// dsp/classifier.ts
|
|
11591
|
-
var
|
|
11707
|
+
var colorLog4 = new ColorLog();
|
|
11592
11708
|
var AxSimpleClassifierClass = class {
|
|
11593
11709
|
name;
|
|
11594
11710
|
context;
|
|
@@ -11650,7 +11766,7 @@ var AxSimpleClassifier = class {
|
|
|
11650
11766
|
}
|
|
11651
11767
|
if (this.debug) {
|
|
11652
11768
|
console.log(
|
|
11653
|
-
|
|
11769
|
+
colorLog4.whiteBright(`query: ${text}`) + "\n" + colorLog4.greenBright(
|
|
11654
11770
|
JSON.stringify(m.map((m2) => `${m2.id}, ${m2.score}`))
|
|
11655
11771
|
)
|
|
11656
11772
|
);
|
|
@@ -13141,15 +13257,16 @@ function v4(options, buf, offset) {
|
|
|
13141
13257
|
var v4_default = v4;
|
|
13142
13258
|
|
|
13143
13259
|
// mcp/client.ts
|
|
13144
|
-
var colorLog7 = new ColorLog();
|
|
13145
13260
|
var AxMCPClient = class {
|
|
13146
13261
|
constructor(transport, options = {}) {
|
|
13147
13262
|
this.transport = transport;
|
|
13148
13263
|
this.options = options;
|
|
13264
|
+
this.logger = options.logger ?? ((message) => console.log(message));
|
|
13149
13265
|
}
|
|
13150
13266
|
functions = [];
|
|
13151
13267
|
activeRequests = /* @__PURE__ */ new Map();
|
|
13152
13268
|
capabilities = {};
|
|
13269
|
+
logger;
|
|
13153
13270
|
async init() {
|
|
13154
13271
|
if ("connect" in this.transport) {
|
|
13155
13272
|
await this.transport.connect?.();
|
|
@@ -13208,11 +13325,13 @@ var AxMCPClient = class {
|
|
|
13208
13325
|
};
|
|
13209
13326
|
});
|
|
13210
13327
|
if (this.options.debug) {
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
);
|
|
13328
|
+
this.logger(`> Discovered ${this.functions.length} functions:`, {
|
|
13329
|
+
tags: ["discovery"]
|
|
13330
|
+
});
|
|
13214
13331
|
for (const fn of this.functions) {
|
|
13215
|
-
|
|
13332
|
+
this.logger(` - ${fn.name}: ${fn.description}`, {
|
|
13333
|
+
tags: ["discovery"]
|
|
13334
|
+
});
|
|
13216
13335
|
}
|
|
13217
13336
|
}
|
|
13218
13337
|
}
|
|
@@ -13255,11 +13374,10 @@ var AxMCPClient = class {
|
|
|
13255
13374
|
params
|
|
13256
13375
|
};
|
|
13257
13376
|
if (this.options.debug) {
|
|
13258
|
-
|
|
13259
|
-
|
|
13260
|
-
|
|
13261
|
-
|
|
13262
|
-
)
|
|
13377
|
+
this.logger(
|
|
13378
|
+
`> Sending request ${requestId}:
|
|
13379
|
+
${JSON.stringify(request, null, 2)}`,
|
|
13380
|
+
{ tags: ["requestStart"] }
|
|
13263
13381
|
);
|
|
13264
13382
|
}
|
|
13265
13383
|
const responsePromise = new Promise((resolve, reject) => {
|
|
@@ -13267,11 +13385,10 @@ ${JSON.stringify(request, null, 2)}`
|
|
|
13267
13385
|
this.transport.send(request).then((res) => {
|
|
13268
13386
|
this.activeRequests.delete(requestId);
|
|
13269
13387
|
if (this.options.debug) {
|
|
13270
|
-
|
|
13271
|
-
|
|
13272
|
-
|
|
13273
|
-
|
|
13274
|
-
)
|
|
13388
|
+
this.logger(
|
|
13389
|
+
`> Received response for request ${requestId}:
|
|
13390
|
+
${JSON.stringify(res, null, 2)}`,
|
|
13391
|
+
{ tags: ["responseContent"] }
|
|
13275
13392
|
);
|
|
13276
13393
|
}
|
|
13277
13394
|
if (res !== null && typeof res === "object" && "error" in res) {
|
|
@@ -13301,9 +13418,9 @@ ${JSON.stringify(res, null, 2)}`
|
|
|
13301
13418
|
params
|
|
13302
13419
|
};
|
|
13303
13420
|
if (this.options.debug) {
|
|
13304
|
-
|
|
13305
|
-
|
|
13306
|
-
|
|
13421
|
+
this.logger(
|
|
13422
|
+
`\u27A1\uFE0F Sending notification: ${JSON.stringify(notification, null, 2)}`,
|
|
13423
|
+
{ tags: ["requestStart"] }
|
|
13307
13424
|
);
|
|
13308
13425
|
}
|
|
13309
13426
|
await this.transport.sendNotification(notification);
|
|
@@ -13533,6 +13650,25 @@ var AxMultiServiceRouter = class {
|
|
|
13533
13650
|
getOptions() {
|
|
13534
13651
|
return this.options ?? {};
|
|
13535
13652
|
}
|
|
13653
|
+
/**
|
|
13654
|
+
* Returns the logger from the last used service,
|
|
13655
|
+
* or falls back to the first service if none has been used.
|
|
13656
|
+
*/
|
|
13657
|
+
getLogger() {
|
|
13658
|
+
let serviceInstance = this.lastUsedService;
|
|
13659
|
+
if (!serviceInstance) {
|
|
13660
|
+
const firstServiceEntry = this.services.values().next().value;
|
|
13661
|
+
if (firstServiceEntry) {
|
|
13662
|
+
serviceInstance = firstServiceEntry.service;
|
|
13663
|
+
}
|
|
13664
|
+
}
|
|
13665
|
+
if (!serviceInstance) {
|
|
13666
|
+
return (message) => {
|
|
13667
|
+
process.stdout.write(message);
|
|
13668
|
+
};
|
|
13669
|
+
}
|
|
13670
|
+
return serviceInstance.getLogger();
|
|
13671
|
+
}
|
|
13536
13672
|
};
|
|
13537
13673
|
|
|
13538
13674
|
// prompts/rag.ts
|