@ax-llm/ax 12.0.23 → 12.0.25
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 +96 -45
- package/index.cjs.map +1 -1
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/index.js +96 -45
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -379,7 +379,7 @@ type AxInternalEmbedRequest<TEmbedModel> = Omit<AxEmbedRequest, 'embedModel'> &
|
|
|
379
379
|
type AxRateLimiterFunction = <T = unknown>(reqFunc: () => Promise<T | ReadableStream$1<T>>, info: Readonly<{
|
|
380
380
|
modelUsage?: AxModelUsage;
|
|
381
381
|
}>) => Promise<T | ReadableStream$1<T>>;
|
|
382
|
-
type AxLoggerTag = 'error' | 'warning' | 'success' | 'functionName' | 'functionArg' | 'functionEnd' | 'firstFunction' | 'multipleFunctions' | 'responseStart' | 'responseContent' | 'responseEnd' | 'requestStart' | 'requestContent' | 'requestEnd' | 'systemStart' | 'systemContent' | 'systemEnd' | 'userStart' | 'userContent' | 'userEnd' | 'assistantStart' | 'assistantContent' | 'assistantEnd' | 'discovery' | 'optimizer' | 'start' | 'config' | 'phase' | 'progress' | 'result' | 'complete' | 'checkpoint';
|
|
382
|
+
type AxLoggerTag = 'error' | 'warning' | 'success' | 'functionName' | 'functionArg' | 'functionEnd' | 'functionResult' | 'functionError' | 'firstFunction' | 'multipleFunctions' | 'responseStart' | 'responseContent' | 'responseDelta' | 'responseEnd' | 'requestStart' | 'requestContent' | 'requestEnd' | 'systemStart' | 'systemContent' | 'systemEnd' | 'userStart' | 'userContent' | 'userEnd' | 'assistantStart' | 'assistantContent' | 'assistantEnd' | 'discovery' | 'optimizer' | 'start' | 'config' | 'phase' | 'progress' | 'result' | 'complete' | 'checkpoint';
|
|
383
383
|
type AxLoggerFunction = (message: string, options?: {
|
|
384
384
|
tags?: AxLoggerTag[];
|
|
385
385
|
}) => void;
|
|
@@ -1228,7 +1228,7 @@ type AxAIGoogleGeminiChatRequest = {
|
|
|
1228
1228
|
type AxAIGoogleGeminiChatResponse = {
|
|
1229
1229
|
candidates: {
|
|
1230
1230
|
content: AxAIGoogleGeminiContent;
|
|
1231
|
-
finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER' | 'MALFORMED_FUNCTION_CALL';
|
|
1231
|
+
finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER' | 'BLOCKLIST' | 'PROHIBITED_CONTENT' | 'SPII' | 'MALFORMED_FUNCTION_CALL' | 'UNEXPECTED_TOOL_CALL' | 'FINISH_REASON_UNSPECIFIED';
|
|
1232
1232
|
citationMetadata: {
|
|
1233
1233
|
citations: {
|
|
1234
1234
|
startIndex: number;
|
package/index.d.ts
CHANGED
|
@@ -379,7 +379,7 @@ type AxInternalEmbedRequest<TEmbedModel> = Omit<AxEmbedRequest, 'embedModel'> &
|
|
|
379
379
|
type AxRateLimiterFunction = <T = unknown>(reqFunc: () => Promise<T | ReadableStream$1<T>>, info: Readonly<{
|
|
380
380
|
modelUsage?: AxModelUsage;
|
|
381
381
|
}>) => Promise<T | ReadableStream$1<T>>;
|
|
382
|
-
type AxLoggerTag = 'error' | 'warning' | 'success' | 'functionName' | 'functionArg' | 'functionEnd' | 'firstFunction' | 'multipleFunctions' | 'responseStart' | 'responseContent' | 'responseEnd' | 'requestStart' | 'requestContent' | 'requestEnd' | 'systemStart' | 'systemContent' | 'systemEnd' | 'userStart' | 'userContent' | 'userEnd' | 'assistantStart' | 'assistantContent' | 'assistantEnd' | 'discovery' | 'optimizer' | 'start' | 'config' | 'phase' | 'progress' | 'result' | 'complete' | 'checkpoint';
|
|
382
|
+
type AxLoggerTag = 'error' | 'warning' | 'success' | 'functionName' | 'functionArg' | 'functionEnd' | 'functionResult' | 'functionError' | 'firstFunction' | 'multipleFunctions' | 'responseStart' | 'responseContent' | 'responseDelta' | 'responseEnd' | 'requestStart' | 'requestContent' | 'requestEnd' | 'systemStart' | 'systemContent' | 'systemEnd' | 'userStart' | 'userContent' | 'userEnd' | 'assistantStart' | 'assistantContent' | 'assistantEnd' | 'discovery' | 'optimizer' | 'start' | 'config' | 'phase' | 'progress' | 'result' | 'complete' | 'checkpoint';
|
|
383
383
|
type AxLoggerFunction = (message: string, options?: {
|
|
384
384
|
tags?: AxLoggerTag[];
|
|
385
385
|
}) => void;
|
|
@@ -1228,7 +1228,7 @@ type AxAIGoogleGeminiChatRequest = {
|
|
|
1228
1228
|
type AxAIGoogleGeminiChatResponse = {
|
|
1229
1229
|
candidates: {
|
|
1230
1230
|
content: AxAIGoogleGeminiContent;
|
|
1231
|
-
finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER' | 'MALFORMED_FUNCTION_CALL';
|
|
1231
|
+
finishReason: 'STOP' | 'MAX_TOKENS' | 'SAFETY' | 'RECITATION' | 'OTHER' | 'BLOCKLIST' | 'PROHIBITED_CONTENT' | 'SPII' | 'MALFORMED_FUNCTION_CALL' | 'UNEXPECTED_TOOL_CALL' | 'FINISH_REASON_UNSPECIFIED';
|
|
1232
1232
|
citationMetadata: {
|
|
1233
1233
|
citations: {
|
|
1234
1234
|
startIndex: number;
|
package/index.js
CHANGED
|
@@ -731,64 +731,42 @@ var axCreateDefaultLogger = (output = defaultOutput) => {
|
|
|
731
731
|
return (message, options) => {
|
|
732
732
|
const tags = options?.tags ?? [];
|
|
733
733
|
let formattedMessage = message;
|
|
734
|
-
|
|
735
|
-
|
|
734
|
+
let colorFunction = (text) => text;
|
|
735
|
+
if (tags.includes("warning") || tags.includes("discovery")) {
|
|
736
|
+
colorFunction = (text) => colorLog.yellow(text);
|
|
737
|
+
} else if (tags.includes("error")) {
|
|
738
|
+
colorFunction = (text) => colorLog.red(text);
|
|
736
739
|
} else if (tags.includes("success") || tags.includes("responseContent")) {
|
|
737
|
-
|
|
738
|
-
} else if (tags.includes("functionName")) {
|
|
739
|
-
if (tags.includes("firstFunction")) {
|
|
740
|
-
formattedMessage = `
|
|
741
|
-
${colorLog.whiteBright(formattedMessage)}`;
|
|
742
|
-
} else {
|
|
743
|
-
formattedMessage = `${colorLog.whiteBright(formattedMessage)}`;
|
|
744
|
-
}
|
|
740
|
+
colorFunction = (text) => colorLog.greenBright(text);
|
|
745
741
|
} else if (tags.includes("systemContent") || tags.includes("assistantContent")) {
|
|
746
|
-
|
|
747
|
-
} else if (tags.includes("
|
|
748
|
-
|
|
742
|
+
colorFunction = (text) => colorLog.blueBright(text);
|
|
743
|
+
} else if (tags.includes("functionName")) {
|
|
744
|
+
colorFunction = (text) => colorLog.whiteBright(text);
|
|
749
745
|
} else if (tags.includes("functionArg")) {
|
|
750
|
-
|
|
746
|
+
colorFunction = (text) => colorLog.blueBright(text);
|
|
747
|
+
} else if (tags.includes("functionResult")) {
|
|
748
|
+
colorFunction = (text) => colorLog.yellow(text);
|
|
751
749
|
}
|
|
752
|
-
if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart")) {
|
|
750
|
+
if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart") || tags.includes("assistantStart") || tags.includes("error") || tags.includes("functionName") || tags.includes("functionArg")) {
|
|
753
751
|
formattedMessage = `
|
|
754
752
|
${formattedMessage}`;
|
|
755
|
-
}
|
|
753
|
+
}
|
|
754
|
+
if (tags.includes("responseEnd") || tags.includes("systemEnd") || tags.includes("userEnd") || tags.includes("assistantStart") || tags.includes("error") || tags.includes("functionEnd")) {
|
|
756
755
|
formattedMessage = `${formattedMessage}
|
|
757
|
-
`;
|
|
758
|
-
} else if (tags.includes("assistantStart")) {
|
|
759
|
-
formattedMessage = `
|
|
760
|
-
${formattedMessage}
|
|
761
|
-
`;
|
|
762
|
-
} else if (tags.includes("error")) {
|
|
763
|
-
formattedMessage = `
|
|
764
|
-
${formattedMessage}
|
|
765
|
-
`;
|
|
766
|
-
} else if (tags.includes("functionEnd")) {
|
|
767
|
-
formattedMessage = `
|
|
768
756
|
`;
|
|
769
757
|
}
|
|
770
|
-
output(formattedMessage);
|
|
758
|
+
output(colorFunction(formattedMessage));
|
|
771
759
|
};
|
|
772
760
|
};
|
|
773
761
|
var axCreateDefaultTextLogger = (output = defaultOutput) => {
|
|
774
762
|
return (message, options) => {
|
|
775
763
|
const tags = options?.tags ?? [];
|
|
776
764
|
let formattedMessage = message;
|
|
777
|
-
if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart")) {
|
|
765
|
+
if (tags.includes("responseStart") || tags.includes("systemStart") || tags.includes("userStart") || tags.includes("assistantStart") || tags.includes("error") || tags.includes("functionName") || tags.includes("functionArg")) {
|
|
778
766
|
formattedMessage = `
|
|
779
767
|
${formattedMessage}`;
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
`;
|
|
783
|
-
} else if (tags.includes("assistantStart")) {
|
|
784
|
-
formattedMessage = `
|
|
785
|
-
${formattedMessage}
|
|
786
|
-
`;
|
|
787
|
-
} else if (tags.includes("error")) {
|
|
788
|
-
formattedMessage = `
|
|
789
|
-
${formattedMessage}
|
|
790
|
-
`;
|
|
791
|
-
} else if (tags.includes("functionEnd")) {
|
|
768
|
+
}
|
|
769
|
+
if (tags.includes("responseEnd") || tags.includes("systemEnd") || tags.includes("userEnd") || tags.includes("assistantStart") || tags.includes("error") || tags.includes("functionEnd")) {
|
|
792
770
|
formattedMessage = `${formattedMessage}
|
|
793
771
|
`;
|
|
794
772
|
}
|
|
@@ -999,9 +977,14 @@ var logResponseResult = (r, logger = defaultLogger) => {
|
|
|
999
977
|
if (r.content) {
|
|
1000
978
|
logger(r.content, { tags: ["responseContent"] });
|
|
1001
979
|
}
|
|
980
|
+
const loggedFunctionCalls = /* @__PURE__ */ new Set();
|
|
1002
981
|
if (r.functionCalls && r.functionCalls.length > 0) {
|
|
1003
982
|
for (const [i, f2] of r.functionCalls.entries()) {
|
|
1004
|
-
if (f2.
|
|
983
|
+
if (f2.id) {
|
|
984
|
+
if (loggedFunctionCalls.has(f2.id)) {
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
loggedFunctionCalls.add(f2.id);
|
|
1005
988
|
const tags = ["functionName"];
|
|
1006
989
|
if (i === 0) {
|
|
1007
990
|
tags.push("firstFunction");
|
|
@@ -1009,7 +992,7 @@ var logResponseResult = (r, logger = defaultLogger) => {
|
|
|
1009
992
|
if (r.functionCalls.length > 1) {
|
|
1010
993
|
tags.push("multipleFunctions");
|
|
1011
994
|
}
|
|
1012
|
-
logger(`[${i + 1}] ${f2.function.name}`, { tags });
|
|
995
|
+
logger(`[${i + 1}] ${f2.function.name}[${f2.id}]`, { tags });
|
|
1013
996
|
}
|
|
1014
997
|
if (f2.function.params) {
|
|
1015
998
|
const params = typeof f2.function.params === "string" ? f2.function.params : JSON.stringify(f2.function.params, null, 2);
|
|
@@ -1028,7 +1011,20 @@ var logResponse = (resp, logger = defaultLogger) => {
|
|
|
1028
1011
|
}
|
|
1029
1012
|
};
|
|
1030
1013
|
var logResponseDelta = (delta, logger = defaultLogger) => {
|
|
1031
|
-
logger(delta, { tags: ["responseContent"] });
|
|
1014
|
+
logger(delta, { tags: ["responseContent", "responseDelta"] });
|
|
1015
|
+
};
|
|
1016
|
+
var logFunctionResults = (results, logger = defaultLogger) => {
|
|
1017
|
+
for (const result of results) {
|
|
1018
|
+
logger(`Function Result [${result.functionId}]:`, {
|
|
1019
|
+
tags: ["functionName"]
|
|
1020
|
+
});
|
|
1021
|
+
if (result.isError) {
|
|
1022
|
+
logger(result.result, { tags: ["functionResult", "error"] });
|
|
1023
|
+
} else {
|
|
1024
|
+
logger(result.result, { tags: ["functionResult"] });
|
|
1025
|
+
}
|
|
1026
|
+
}
|
|
1027
|
+
logger("", { tags: ["functionEnd"] });
|
|
1032
1028
|
};
|
|
1033
1029
|
|
|
1034
1030
|
// ai/metrics.ts
|
|
@@ -4719,6 +4715,54 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
4719
4715
|
void 0
|
|
4720
4716
|
// requestId not available
|
|
4721
4717
|
);
|
|
4718
|
+
case "UNEXPECTED_TOOL_CALL":
|
|
4719
|
+
throw new AxAIRefusalError(
|
|
4720
|
+
"Unexpected tool call",
|
|
4721
|
+
void 0,
|
|
4722
|
+
// model not available in candidate
|
|
4723
|
+
void 0
|
|
4724
|
+
// requestId not available
|
|
4725
|
+
);
|
|
4726
|
+
case "FINISH_REASON_UNSPECIFIED":
|
|
4727
|
+
throw new AxAIRefusalError(
|
|
4728
|
+
"Finish reason unspecified",
|
|
4729
|
+
void 0,
|
|
4730
|
+
// model not available in candidate
|
|
4731
|
+
void 0
|
|
4732
|
+
// requestId not available
|
|
4733
|
+
);
|
|
4734
|
+
case "BLOCKLIST":
|
|
4735
|
+
throw new AxAIRefusalError(
|
|
4736
|
+
"Content was blocked due to blocklist",
|
|
4737
|
+
void 0,
|
|
4738
|
+
// model not available in candidate
|
|
4739
|
+
void 0
|
|
4740
|
+
// requestId not available
|
|
4741
|
+
);
|
|
4742
|
+
case "PROHIBITED_CONTENT":
|
|
4743
|
+
throw new AxAIRefusalError(
|
|
4744
|
+
"Content was blocked due to prohibited content",
|
|
4745
|
+
void 0,
|
|
4746
|
+
// model not available in candidate
|
|
4747
|
+
void 0
|
|
4748
|
+
// requestId not available
|
|
4749
|
+
);
|
|
4750
|
+
case "SPII":
|
|
4751
|
+
throw new AxAIRefusalError(
|
|
4752
|
+
"Content was blocked due to SPII",
|
|
4753
|
+
void 0,
|
|
4754
|
+
// model not available in candidate
|
|
4755
|
+
void 0
|
|
4756
|
+
// requestId not available
|
|
4757
|
+
);
|
|
4758
|
+
case "OTHER":
|
|
4759
|
+
throw new AxAIRefusalError(
|
|
4760
|
+
"Other finish reason",
|
|
4761
|
+
void 0,
|
|
4762
|
+
// model not available in candidate
|
|
4763
|
+
void 0
|
|
4764
|
+
// requestId not available
|
|
4765
|
+
);
|
|
4722
4766
|
}
|
|
4723
4767
|
if (!candidate.content || !candidate.content.parts) {
|
|
4724
4768
|
return result;
|
|
@@ -4798,7 +4842,8 @@ var AxAIGoogleGemini = class extends AxBaseAI {
|
|
|
4798
4842
|
} else {
|
|
4799
4843
|
path = "publishers/google";
|
|
4800
4844
|
}
|
|
4801
|
-
|
|
4845
|
+
const tld = region === "global" ? "aiplatform" : `${region}-aiplatform`;
|
|
4846
|
+
apiURL = `https://${tld}.googleapis.com/v1/projects/${projectId}/locations/${region}/${path}`;
|
|
4802
4847
|
if (apiKey) {
|
|
4803
4848
|
headers = async () => ({ Authorization: `Bearer ${apiKey}` });
|
|
4804
4849
|
} else {
|
|
@@ -7085,6 +7130,9 @@ var MemoryImpl = class {
|
|
|
7085
7130
|
} else {
|
|
7086
7131
|
this.data.push({ role: "function", chat });
|
|
7087
7132
|
}
|
|
7133
|
+
if (this.options?.debug) {
|
|
7134
|
+
debugFunctionResults(results);
|
|
7135
|
+
}
|
|
7088
7136
|
}
|
|
7089
7137
|
addResponse(results) {
|
|
7090
7138
|
const chat = results.map(({ index, ...value }) => ({
|
|
@@ -7273,6 +7321,9 @@ function debugResponse(value) {
|
|
|
7273
7321
|
function debugResponseDelta(delta) {
|
|
7274
7322
|
logResponseDelta(delta);
|
|
7275
7323
|
}
|
|
7324
|
+
function debugFunctionResults(results) {
|
|
7325
|
+
logFunctionResults(results);
|
|
7326
|
+
}
|
|
7276
7327
|
|
|
7277
7328
|
// dsp/asserts.ts
|
|
7278
7329
|
var AxAssertionError = class extends Error {
|