feat: vertex ai openai adapter (#6736)
* feat: vertex ai openai adapter * fix: vertex ai - missing mistral key * feat: support tools for vertexAI gemini and anthropic * feat: vertex openai adapter working for gemini * fix: show errors in vertex ai * fix: filter out model from vertexai anthropic body * feat: vertexai toolSupport update * chore: remove force openai adapter usage for vertex * fix: prettier
This commit is contained in:
parent
70302e2f2b
commit
f0d35e2099
12 changed files with 980 additions and 238 deletions
|
|
@ -172,52 +172,10 @@ class Anthropic extends BaseLLM {
|
|||
}
|
||||
}
|
||||
|
||||
protected async *_streamChat(
|
||||
messages: ChatMessage[],
|
||||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
async *handleResponse(
|
||||
response: any,
|
||||
stream: boolean | undefined,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
if (!this.apiKey || this.apiKey === "") {
|
||||
throw new Error(
|
||||
"Request not sent. You have an Anthropic model configured in your config.json, but the API key is not set.",
|
||||
);
|
||||
}
|
||||
|
||||
const systemMessage = stripImages(
|
||||
messages.filter((m) => m.role === "system")[0]?.content ?? "",
|
||||
);
|
||||
const shouldCacheSystemMessage = !!(
|
||||
this.cacheBehavior?.cacheSystemMessage && systemMessage
|
||||
);
|
||||
|
||||
const msgs = this.convertMessages(messages);
|
||||
const response = await this.fetch(new URL("messages", this.apiBase), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"anthropic-version": "2023-06-01",
|
||||
"x-api-key": this.apiKey as string,
|
||||
...(shouldCacheSystemMessage || this.cacheBehavior?.cacheConversation
|
||||
? { "anthropic-beta": "prompt-caching-2024-07-31" }
|
||||
: {}),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...this.convertArgs(options),
|
||||
messages: msgs,
|
||||
system: shouldCacheSystemMessage
|
||||
? [
|
||||
{
|
||||
type: "text",
|
||||
text: systemMessage,
|
||||
cache_control: { type: "ephemeral" },
|
||||
},
|
||||
]
|
||||
: systemMessage,
|
||||
}),
|
||||
signal,
|
||||
});
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
|
@ -237,7 +195,7 @@ class Anthropic extends BaseLLM {
|
|||
);
|
||||
}
|
||||
|
||||
if (options.stream === false) {
|
||||
if (stream === false) {
|
||||
const data = await response.json();
|
||||
const cost = data.usage
|
||||
? {
|
||||
|
|
@ -348,6 +306,55 @@ class Anthropic extends BaseLLM {
|
|||
usage,
|
||||
};
|
||||
}
|
||||
|
||||
protected async *_streamChat(
|
||||
messages: ChatMessage[],
|
||||
signal: AbortSignal,
|
||||
options: CompletionOptions,
|
||||
): AsyncGenerator<ChatMessage> {
|
||||
if (!this.apiKey || this.apiKey === "") {
|
||||
throw new Error(
|
||||
"Request not sent. You have an Anthropic model configured in your config.json, but the API key is not set.",
|
||||
);
|
||||
}
|
||||
|
||||
const systemMessage = stripImages(
|
||||
messages.filter((m) => m.role === "system")[0]?.content ?? "",
|
||||
);
|
||||
const shouldCacheSystemMessage = !!(
|
||||
this.cacheBehavior?.cacheSystemMessage && systemMessage
|
||||
);
|
||||
|
||||
const msgs = this.convertMessages(messages);
|
||||
const response = await this.fetch(new URL("messages", this.apiBase), {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"anthropic-version": "2023-06-01",
|
||||
"x-api-key": this.apiKey as string,
|
||||
...(shouldCacheSystemMessage || this.cacheBehavior?.cacheConversation
|
||||
? { "anthropic-beta": "prompt-caching-2024-07-31" }
|
||||
: {}),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
...this.convertArgs(options),
|
||||
messages: msgs,
|
||||
system: shouldCacheSystemMessage
|
||||
? [
|
||||
{
|
||||
type: "text",
|
||||
text: systemMessage,
|
||||
cache_control: { type: "ephemeral" },
|
||||
},
|
||||
]
|
||||
: systemMessage,
|
||||
}),
|
||||
signal,
|
||||
});
|
||||
|
||||
yield* this.handleResponse(response, options.stream);
|
||||
}
|
||||
}
|
||||
|
||||
export default Anthropic;
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ class Gemini extends BaseLLM {
|
|||
messages: ChatMessage[],
|
||||
options: CompletionOptions,
|
||||
isV1API: boolean,
|
||||
includeToolIds: boolean,
|
||||
): GeminiChatRequestBody {
|
||||
const toolCallIdToNameMap = new Map<string, string>();
|
||||
messages.forEach((msg) => {
|
||||
|
|
@ -231,7 +232,7 @@ class Gemini extends BaseLLM {
|
|||
parts: [
|
||||
{
|
||||
functionResponse: {
|
||||
id: msg.toolCallId,
|
||||
id: includeToolIds ? msg.toolCallId : undefined,
|
||||
name: functionName || "unknown",
|
||||
response: {
|
||||
output: msg.content, // "output" key is opinionated - not all functions will output objects
|
||||
|
|
@ -406,7 +407,7 @@ class Gemini extends BaseLLM {
|
|||
const isV1API = !!this.apiBase?.includes("/v1/");
|
||||
|
||||
// Convert chat messages to contents
|
||||
const body = this.prepareBody(messages, options, isV1API);
|
||||
const body = this.prepareBody(messages, options, isV1API, true);
|
||||
|
||||
const response = await this.fetch(apiURL, {
|
||||
method: "POST",
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ class Mistral extends OpenAI {
|
|||
return Mistral.modelConversion[model] ?? model;
|
||||
}
|
||||
|
||||
protected _convertArgs(options: any, messages: ChatMessage[]) {
|
||||
_convertArgs(options: any, messages: ChatMessage[]) {
|
||||
const finalOptions = super._convertArgs(options, messages);
|
||||
|
||||
const lastMessage = finalOptions.messages[finalOptions.messages.length - 1];
|
||||
|
|
|
|||
|
|
@ -254,24 +254,7 @@ class VertexAI extends BaseLLM {
|
|||
signal,
|
||||
});
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
|
||||
if (options.stream === false) {
|
||||
const data = await response.json();
|
||||
yield { role: "assistant", content: data.content[0].text };
|
||||
return;
|
||||
}
|
||||
|
||||
for await (const value of streamSse(response)) {
|
||||
if (value.type === "message_start") {
|
||||
console.log(value);
|
||||
}
|
||||
if (value.delta?.text) {
|
||||
yield { role: "assistant", content: value.delta.text };
|
||||
}
|
||||
}
|
||||
yield* this.anthropicInstance.handleResponse(response, options.stream);
|
||||
}
|
||||
|
||||
// Gemini
|
||||
|
|
@ -285,17 +268,19 @@ class VertexAI extends BaseLLM {
|
|||
this.apiBase,
|
||||
);
|
||||
|
||||
const body = this.geminiInstance.prepareBody(messages, options, false);
|
||||
// For some reason gemini through vertex does not support ids in functionResponses yet
|
||||
const body = this.geminiInstance.prepareBody(
|
||||
messages,
|
||||
options,
|
||||
false,
|
||||
false,
|
||||
);
|
||||
const response = await this.fetch(apiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
signal,
|
||||
});
|
||||
for await (const message of this.geminiInstance.processGeminiResponse(
|
||||
streamResponse(response),
|
||||
)) {
|
||||
yield message;
|
||||
}
|
||||
yield* this.geminiInstance.processGeminiResponse(streamResponse(response));
|
||||
}
|
||||
|
||||
private async *streamChatBison(
|
||||
|
|
|
|||
|
|
@ -83,11 +83,12 @@ export const PROVIDER_TOOL_SUPPORT: Record<string, (model: string) => boolean> =
|
|||
return model.toLowerCase().includes("gemini");
|
||||
},
|
||||
vertexai: (model) => {
|
||||
const lowerCaseModel = model.toLowerCase();
|
||||
// All gemini models except flash 2.0 lite support function calling
|
||||
return (
|
||||
model.toLowerCase().includes("gemini") &&
|
||||
!model.toLowerCase().includes("lite")
|
||||
);
|
||||
if (lowerCaseModel.includes("lite")) {
|
||||
return false;
|
||||
}
|
||||
return ["claude", "gemini"].some((val) => lowerCaseModel.includes(val));
|
||||
},
|
||||
bedrock: (model) => {
|
||||
if (
|
||||
|
|
|
|||
378
packages/openai-adapters/package-lock.json
generated
378
packages/openai-adapters/package-lock.json
generated
|
|
@ -15,6 +15,7 @@
|
|||
"@continuedev/config-yaml": "^1.0.51",
|
||||
"@continuedev/fetch": "^1.0.15",
|
||||
"dotenv": "^16.5.0",
|
||||
"google-auth-library": "^10.1.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"openai": "^4.104.0",
|
||||
|
|
@ -1386,9 +1387,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/aix-ppc64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.6.tgz",
|
||||
"integrity": "sha512-ShbM/3XxwuxjFiuVBHA+d3j5dyac0aEVVq1oluIDf71hUw0aRF59dV/efUsIwFnR6m8JNM2FjZOzmaZ8yG61kw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.8.tgz",
|
||||
"integrity": "sha512-urAvrUedIqEiFR3FYSLTWQgLu5tb+m0qZw0NBEasUeo6wuqatkMDaRT+1uABiGXEu5vqgPd7FGE1BhsAIy9QVA==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
|
|
@ -1403,9 +1404,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.6.tgz",
|
||||
"integrity": "sha512-S8ToEOVfg++AU/bHwdksHNnyLyVM+eMVAOf6yRKFitnwnbwwPNqKr3srzFRe7nzV69RQKb5DgchIX5pt3L53xg==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.8.tgz",
|
||||
"integrity": "sha512-RONsAvGCz5oWyePVnLdZY/HHwA++nxYWIX1atInlaW6SEkwq6XkP3+cb825EUcRs5Vss/lGh/2YxAb5xqc07Uw==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
|
|
@ -1420,9 +1421,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-hd5zdUarsK6strW+3Wxi5qWws+rJhCCbMiC9QZyzoxfk5uHRIE8T287giQxzVpEvCwuJ9Qjg6bEjcRJcgfLqoA==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-OD3p7LYzWpLhZEyATcTSJ67qB5D+20vbtr6vHlHWSQYhKtzUYrETuWThmzFpZtFsBIxRvhO07+UgVA9m0i/O1w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1437,9 +1438,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-0Z7KpHSr3VBIO9A/1wcT3NTy7EB4oNC4upJ5ye3R7taCc2GUdeynSLArnon5G8scPwaU866d3H4BCrE5xLW25A==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-yJAVPklM5+4+9dTeKwHOaA+LQkmrKFX96BM0A/2zQrbS6ENCmxc4OVoBs5dPkCCak2roAD+jKCdnmOqKszPkjA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1454,9 +1455,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/darwin-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-FFCssz3XBavjxcFxKsGy2DYK5VSvJqa6y5HXljKzhRZ87LvEi13brPrf/wdyl/BbpbMKJNOr1Sd0jtW4Ge1pAA==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-Jw0mxgIaYX6R8ODrdkLLPwBqHTtYHJSmzzd+QeytSugzQ0Vg4c5rDky5VgkoowbZQahCbsv1rT1KW72MPIkevw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1471,9 +1472,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/darwin-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-GfXs5kry/TkGM2vKqK2oyiLFygJRqKVhawu3+DOCk7OxLy/6jYkWXhlHwOoTb0WqGnWGAS7sooxbZowy+pK9Yg==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-Vh2gLxxHnuoQ+GjPNvDSDRpoBCUzY4Pu0kBqMBDlK4fuWbKgGtmDIeEC081xi26PPjn+1tct+Bh8FjyLlw1Zlg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1488,9 +1489,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/freebsd-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-aoLF2c3OvDn2XDTRvn8hN6DRzVVpDlj2B/F66clWd/FHLiHaG3aVZjxQX2DYphA5y/evbdGvC6Us13tvyt4pWg==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-YPJ7hDQ9DnNe5vxOm6jaie9QsTwcKedPvizTVlqWG9GBSq+BuyWEDazlGaDTC5NGU4QJd666V0yqCBL2oWKPfA==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1505,9 +1506,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/freebsd-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-2SkqTjTSo2dYi/jzFbU9Plt1vk0+nNg8YC8rOXXea+iA3hfNJWebKYPs3xnOUf9+ZWhKAaxnQNUf2X9LOpeiMQ==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-MmaEXxQRdXNFsRN/KcIimLnSJrk2r5H8v+WVafRWz5xdSVmWLoITZQXcgehI2ZE6gioE6HirAEToM/RvFBeuhw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1522,9 +1523,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-arm": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.6.tgz",
|
||||
"integrity": "sha512-SZHQlzvqv4Du5PrKE2faN0qlbsaW/3QQfUUc6yO2EjFcA83xnwm91UbEEVx4ApZ9Z5oG8Bxz4qPE+HFwtVcfyw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.8.tgz",
|
||||
"integrity": "sha512-FuzEP9BixzZohl1kLf76KEVOsxtIBFwCaLupVuk4eFVnOZfU+Wsn+x5Ryam7nILV2pkq2TqQM9EZPsOBuMC+kg==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
|
|
@ -1539,9 +1540,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-b967hU0gqKd9Drsh/UuAm21Khpoh6mPBSgz8mKRq4P5mVK8bpA+hQzmm/ZwGVULSNBzKdZPQBRT3+WuVavcWsQ==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-WIgg00ARWv/uYLU7lsuDK00d/hHSfES5BzdWAdAig1ioV5kaFNrtK8EqGcUBJhYqotlUByUKz5Qo6u8tt7iD/w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1556,9 +1557,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-ia32": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.6.tgz",
|
||||
"integrity": "sha512-aHWdQ2AAltRkLPOsKdi3xv0mZ8fUGPdlKEjIEhxCPm5yKEThcUjHpWB1idN74lfXGnZ5SULQSgtr5Qos5B0bPw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.8.tgz",
|
||||
"integrity": "sha512-A1D9YzRX1i+1AJZuFFUMP1E9fMaYY+GnSQil9Tlw05utlE86EKTUA7RjwHDkEitmLYiFsRd9HwKBPEftNdBfjg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
|
|
@ -1573,9 +1574,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-loong64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.6.tgz",
|
||||
"integrity": "sha512-VgKCsHdXRSQ7E1+QXGdRPlQ/e08bN6WMQb27/TMfV+vPjjTImuT9PmLXupRlC90S1JeNNW5lzkAEO/McKeJ2yg==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.8.tgz",
|
||||
"integrity": "sha512-O7k1J/dwHkY1RMVvglFHl1HzutGEFFZ3kNiDMSOyUrB7WcoHGf96Sh+64nTRT26l3GMbCW01Ekh/ThKM5iI7hQ==",
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
|
|
@ -1590,9 +1591,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-mips64el": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.6.tgz",
|
||||
"integrity": "sha512-WViNlpivRKT9/py3kCmkHnn44GkGXVdXfdc4drNmRl15zVQ2+D2uFwdlGh6IuK5AAnGTo2qPB1Djppj+t78rzw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.8.tgz",
|
||||
"integrity": "sha512-uv+dqfRazte3BzfMp8PAQXmdGHQt2oC/y2ovwpTteqrMx2lwaksiFZ/bdkXJC19ttTvNXBuWH53zy/aTj1FgGw==",
|
||||
"cpu": [
|
||||
"mips64el"
|
||||
],
|
||||
|
|
@ -1607,9 +1608,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-ppc64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.6.tgz",
|
||||
"integrity": "sha512-wyYKZ9NTdmAMb5730I38lBqVu6cKl4ZfYXIs31Baf8aoOtB4xSGi3THmDYt4BTFHk7/EcVixkOV2uZfwU3Q2Jw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.8.tgz",
|
||||
"integrity": "sha512-GyG0KcMi1GBavP5JgAkkstMGyMholMDybAf8wF5A70CALlDM2p/f7YFE7H92eDeH/VBtFJA5MT4nRPDGg4JuzQ==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
|
|
@ -1624,9 +1625,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-riscv64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.6.tgz",
|
||||
"integrity": "sha512-KZh7bAGGcrinEj4qzilJ4hqTY3Dg2U82c8bv+e1xqNqZCrCyc+TL9AUEn5WGKDzm3CfC5RODE/qc96OcbIe33w==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.8.tgz",
|
||||
"integrity": "sha512-rAqDYFv3yzMrq7GIcen3XP7TUEG/4LK86LUPMIz6RT8A6pRIDn0sDcvjudVZBiiTcZCY9y2SgYX2lgK3AF+1eg==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
|
|
@ -1641,9 +1642,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-s390x": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.6.tgz",
|
||||
"integrity": "sha512-9N1LsTwAuE9oj6lHMyyAM+ucxGiVnEqUdp4v7IaMmrwb06ZTEVCIs3oPPplVsnjPfyjmxwHxHMF8b6vzUVAUGw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.8.tgz",
|
||||
"integrity": "sha512-Xutvh6VjlbcHpsIIbwY8GVRbwoviWT19tFhgdA7DlenLGC/mbc3lBoVb7jxj9Z+eyGqvcnSyIltYUrkKzWqSvg==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
|
|
@ -1658,9 +1659,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-A6bJB41b4lKFWRKNrWoP2LHsjVzNiaurf7wyj/XtFNTsnPuxwEBWHLty+ZE0dWBKuSK1fvKgrKaNjBS7qbFKig==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-ASFQhgY4ElXh3nDcOMTkQero4b1lgubskNlhIfJrsH5OKZXDpUAKBlNS0Kx81jwOBp+HCeZqmoJuihTv57/jvQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1675,9 +1676,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/netbsd-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-IjA+DcwoVpjEvyxZddDqBY+uJ2Snc6duLpjmkXm/v4xuS3H+3FkLZlDm9ZsAbF9rsfP3zeA0/ArNDORZgrxR/Q==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-d1KfruIeohqAi6SA+gENMuObDbEjn22olAR7egqnkCD9DGBG0wsEARotkLgXDu6c4ncgWTZJtN5vcgxzWRMzcw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1692,9 +1693,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/netbsd-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-dUXuZr5WenIDlMHdMkvDc1FAu4xdWixTCRgP7RQLBOkkGgwuuzaGSYcOpW4jFxzpzL1ejb8yF620UxAqnBrR9g==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-nVDCkrvx2ua+XQNyfrujIG38+YGyuy2Ru9kKVNyh5jAys6n+l44tTtToqHjino2My8VAY6Lw9H7RI73XFi66Cg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1709,9 +1710,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/openbsd-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-l8ZCvXP0tbTJ3iaqdNf3pjaOSd5ex/e6/omLIQCVBLmHTlfXW3zAxQ4fnDmPLOB1x9xrcSi/xtCWFwCZRIaEwg==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-j8HgrDuSJFAujkivSMSfPQSAa5Fxbvk4rgNAS5i3K+r8s1X0p1uOO2Hl2xNsGFppOeHOLAVgYwDVlmxhq5h+SQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1726,9 +1727,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/openbsd-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-hKrmDa0aOFOr71KQ/19JC7az1P0GWtCN1t2ahYAf4O007DHZt/dW8ym5+CUdJhQ/qkZmI1HAF8KkJbEFtCL7gw==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-1h8MUAwa0VhNCDp6Af0HToI2TJFAn1uqT9Al6DJVzdIBAd21m/G0Yfc77KDM3uF3T/YaOgQq3qTJHPbTOInaIQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1743,9 +1744,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/openharmony-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-+SqBcAWoB1fYKmpWoQP4pGtx+pUUC//RNYhFdbcSA16617cchuryuhOCRpPsjCblKukAckWsV+aQ3UKT/RMPcA==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-r2nVa5SIK9tSWd0kJd9HCffnDHKchTGikb//9c7HX+r+wHYCpQrSgxhlY6KWV1nFo1l4KFbsMlHk+L6fekLsUg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1760,9 +1761,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/sunos-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-dyCGxv1/Br7MiSC42qinGL8KkG4kX0pEsdb0+TKhmJZgCUDBGmyo1/ArCjNGiOLiIAgdbWgmWgib4HoCi5t7kA==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-zUlaP2S12YhQ2UzUfcCuMDHQFJyKABkAjvO5YSndMiIkMimPmxA+BYSBikWgsRpvyxuRnow4nS5NPnf9fpv41w==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -1777,9 +1778,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-arm64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.6.tgz",
|
||||
"integrity": "sha512-42QOgcZeZOvXfsCBJF5Afw73t4veOId//XD3i+/9gSkhSV6Gk3VPlWncctI+JcOyERv85FUo7RxuxGy+z8A43Q==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.8.tgz",
|
||||
"integrity": "sha512-YEGFFWESlPva8hGL+zvj2z/SaK+pH0SwOM0Nc/d+rVnW7GSTFlLBGzZkuSU9kFIGIo8q9X3ucpZhu8PDN5A2sQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
|
|
@ -1794,9 +1795,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-ia32": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.6.tgz",
|
||||
"integrity": "sha512-4AWhgXmDuYN7rJI6ORB+uU9DHLq/erBbuMoAuB4VWJTu5KtCgcKYPynF0YI1VkBNuEfjNlLrFr9KZPJzrtLkrQ==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.8.tgz",
|
||||
"integrity": "sha512-hiGgGC6KZ5LZz58OL/+qVVoZiuZlUYlYHNAmczOm7bs2oE1XriPFi5ZHHrS8ACpV5EjySrnoCKmcbQMN+ojnHg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
|
|
@ -1811,9 +1812,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-x64": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.6.tgz",
|
||||
"integrity": "sha512-NgJPHHbEpLQgDH2MjQu90pzW/5vvXIZ7KOnPyNBm92A6WgZ/7b6fJyUBjoumLqeOQQGqY2QjQxRo97ah4Sj0cA==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.8.tgz",
|
||||
"integrity": "sha512-cn3Yr7+OaaZq1c+2pe+8yxC8E144SReCQjN6/2ynubzYjvyqZjTXfQJpAcQpsdJq3My7XADANiYGHoFC69pLQw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
|
|
@ -3994,9 +3995,9 @@
|
|||
"dev": true
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "24.0.14",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.0.14.tgz",
|
||||
"integrity": "sha512-4zXMWD91vBLGRtHK3YbIoFMia+1nqEz72coM42C5ETjnNCa/heoj7NT1G67iAfOqMmcfhuCZ4uNpyz8EjlAejw==",
|
||||
"version": "24.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-24.1.0.tgz",
|
||||
"integrity": "sha512-ut5FthK5moxFKH2T1CUOC6ctR67rQRvvHdFLCD2Ql6KXmMuCrjsSsRI9UsLCm9M18BMwClv4pn327UvB7eeO1w==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~7.8.0"
|
||||
|
|
@ -4458,12 +4459,41 @@
|
|||
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/before-after-hook": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-4.0.0.tgz",
|
||||
"integrity": "sha512-q6tR3RPqIB1pMiTRMFcZwuG5T8vwp+vUvEG0vuI6B+Rikh5BfPp2fQ82c925FOs+b0lcFQ8CFrL+KbilfZFhOQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/bignumber.js": {
|
||||
"version": "9.3.1",
|
||||
"resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.3.1.tgz",
|
||||
"integrity": "sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/bottleneck": {
|
||||
"version": "2.19.5",
|
||||
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
|
||||
|
|
@ -4553,6 +4583,12 @@
|
|||
"node-int64": "^0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
||||
"integrity": "sha512-zRpUiDwd/xk6ADqPMATG8vc9VPrkck7T07OIx0gnjmJAnHnTVXNQG3vfvWNuiZIkwu9KrKdA1iJKfsfTVxE6NA==",
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/buffer-from": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
|
||||
|
|
@ -5225,6 +5261,15 @@
|
|||
"readable-stream": "^2.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/ecdsa-sig-formatter": {
|
||||
"version": "1.0.11",
|
||||
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
|
||||
"integrity": "sha512-nagl3RYrbNv6kQkeJIpt6NJZy8twLB/2vtz6yN9Z4vRKHN4/QZJIEbqohALSgwKdnksuY3k5Addp5lg8sVoVcQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/ejs": {
|
||||
"version": "3.1.10",
|
||||
"resolved": "https://registry.npmjs.org/ejs/-/ejs-3.1.10.tgz",
|
||||
|
|
@ -5457,9 +5502,9 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.25.6",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.6.tgz",
|
||||
"integrity": "sha512-GVuzuUwtdsghE3ocJ9Bs8PNoF13HNQ5TXbEi2AhvVb8xU1Iwt9Fos9FEamfoee+u/TOsn7GUWc04lz46n2bbTg==",
|
||||
"version": "0.25.8",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.8.tgz",
|
||||
"integrity": "sha512-vVC0USHGtMi8+R4Kz8rt6JhEWLxsv9Rnu/lGYbPR8u47B+DCBksq9JarW0zOO7bs37hyOK1l2/oqtbciutL5+Q==",
|
||||
"dev": true,
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
|
|
@ -5470,32 +5515,32 @@
|
|||
"node": ">=18"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@esbuild/aix-ppc64": "0.25.6",
|
||||
"@esbuild/android-arm": "0.25.6",
|
||||
"@esbuild/android-arm64": "0.25.6",
|
||||
"@esbuild/android-x64": "0.25.6",
|
||||
"@esbuild/darwin-arm64": "0.25.6",
|
||||
"@esbuild/darwin-x64": "0.25.6",
|
||||
"@esbuild/freebsd-arm64": "0.25.6",
|
||||
"@esbuild/freebsd-x64": "0.25.6",
|
||||
"@esbuild/linux-arm": "0.25.6",
|
||||
"@esbuild/linux-arm64": "0.25.6",
|
||||
"@esbuild/linux-ia32": "0.25.6",
|
||||
"@esbuild/linux-loong64": "0.25.6",
|
||||
"@esbuild/linux-mips64el": "0.25.6",
|
||||
"@esbuild/linux-ppc64": "0.25.6",
|
||||
"@esbuild/linux-riscv64": "0.25.6",
|
||||
"@esbuild/linux-s390x": "0.25.6",
|
||||
"@esbuild/linux-x64": "0.25.6",
|
||||
"@esbuild/netbsd-arm64": "0.25.6",
|
||||
"@esbuild/netbsd-x64": "0.25.6",
|
||||
"@esbuild/openbsd-arm64": "0.25.6",
|
||||
"@esbuild/openbsd-x64": "0.25.6",
|
||||
"@esbuild/openharmony-arm64": "0.25.6",
|
||||
"@esbuild/sunos-x64": "0.25.6",
|
||||
"@esbuild/win32-arm64": "0.25.6",
|
||||
"@esbuild/win32-ia32": "0.25.6",
|
||||
"@esbuild/win32-x64": "0.25.6"
|
||||
"@esbuild/aix-ppc64": "0.25.8",
|
||||
"@esbuild/android-arm": "0.25.8",
|
||||
"@esbuild/android-arm64": "0.25.8",
|
||||
"@esbuild/android-x64": "0.25.8",
|
||||
"@esbuild/darwin-arm64": "0.25.8",
|
||||
"@esbuild/darwin-x64": "0.25.8",
|
||||
"@esbuild/freebsd-arm64": "0.25.8",
|
||||
"@esbuild/freebsd-x64": "0.25.8",
|
||||
"@esbuild/linux-arm": "0.25.8",
|
||||
"@esbuild/linux-arm64": "0.25.8",
|
||||
"@esbuild/linux-ia32": "0.25.8",
|
||||
"@esbuild/linux-loong64": "0.25.8",
|
||||
"@esbuild/linux-mips64el": "0.25.8",
|
||||
"@esbuild/linux-ppc64": "0.25.8",
|
||||
"@esbuild/linux-riscv64": "0.25.8",
|
||||
"@esbuild/linux-s390x": "0.25.8",
|
||||
"@esbuild/linux-x64": "0.25.8",
|
||||
"@esbuild/netbsd-arm64": "0.25.8",
|
||||
"@esbuild/netbsd-x64": "0.25.8",
|
||||
"@esbuild/openbsd-arm64": "0.25.8",
|
||||
"@esbuild/openbsd-x64": "0.25.8",
|
||||
"@esbuild/openharmony-arm64": "0.25.8",
|
||||
"@esbuild/sunos-x64": "0.25.8",
|
||||
"@esbuild/win32-arm64": "0.25.8",
|
||||
"@esbuild/win32-ia32": "0.25.8",
|
||||
"@esbuild/win32-x64": "0.25.8"
|
||||
}
|
||||
},
|
||||
"node_modules/escalade": {
|
||||
|
|
@ -5607,6 +5652,12 @@
|
|||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/extend": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
|
||||
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/fast-content-type-parse": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fast-content-type-parse/-/fast-content-type-parse-3.0.0.tgz",
|
||||
|
|
@ -5942,6 +5993,34 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/gaxios": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/gaxios/-/gaxios-7.1.1.tgz",
|
||||
"integrity": "sha512-Odju3uBUJyVCkW64nLD4wKLhbh93bh6vIg/ZIXkWiLPBrdgtc65+tls/qml+un3pr6JqYVFDZbbmLDQT68rTOQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"extend": "^3.0.2",
|
||||
"https-proxy-agent": "^7.0.1",
|
||||
"node-fetch": "^3.3.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/gcp-metadata": {
|
||||
"version": "7.0.1",
|
||||
"resolved": "https://registry.npmjs.org/gcp-metadata/-/gcp-metadata-7.0.1.tgz",
|
||||
"integrity": "sha512-UcO3kefx6dCcZkgcTGgVOTFb7b1LlQ02hY1omMjjrrBzkajRMCFgYOjs7J71WqnuG1k2b+9ppGL7FsOfhZMQKQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"gaxios": "^7.0.0",
|
||||
"google-logging-utils": "^1.0.0",
|
||||
"json-bigint": "^1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/gensync": {
|
||||
"version": "1.0.0-beta.2",
|
||||
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
|
|
@ -6085,12 +6164,52 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/google-auth-library": {
|
||||
"version": "10.1.0",
|
||||
"resolved": "https://registry.npmjs.org/google-auth-library/-/google-auth-library-10.1.0.tgz",
|
||||
"integrity": "sha512-GspVjZj1RbyRWpQ9FbAXMKjFGzZwDKnUHi66JJ+tcjcu5/xYAP1pdlWotCuIkMwjfVsxxDvsGZXGLzRt72D0sQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.0",
|
||||
"ecdsa-sig-formatter": "^1.0.11",
|
||||
"gaxios": "^7.0.0",
|
||||
"gcp-metadata": "^7.0.0",
|
||||
"google-logging-utils": "^1.0.0",
|
||||
"gtoken": "^8.0.0",
|
||||
"jws": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/google-logging-utils": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/google-logging-utils/-/google-logging-utils-1.1.1.tgz",
|
||||
"integrity": "sha512-rcX58I7nqpu4mbKztFeOAObbomBbHU2oIb/d3tJfF3dizGSApqtSwYJigGCooHdnMyQBIw8BrWyK96w3YXgr6A==",
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/gtoken": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-8.0.0.tgz",
|
||||
"integrity": "sha512-+CqsMbHPiSTdtSO14O51eMNlrp9N79gmeqmXeouJOhfucAedHw9noVe/n5uJk3tbKE6a+6ZCQg3RPhVhHByAIw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"gaxios": "^7.0.0",
|
||||
"jws": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/handlebars": {
|
||||
"version": "4.7.8",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz",
|
||||
|
|
@ -7248,6 +7367,15 @@
|
|||
"node": ">=4"
|
||||
}
|
||||
},
|
||||
"node_modules/json-bigint": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz",
|
||||
"integrity": "sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"bignumber.js": "^9.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/json-parse-better-errors": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz",
|
||||
|
|
@ -7289,6 +7417,27 @@
|
|||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/jwa": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/jwa/-/jwa-2.0.1.tgz",
|
||||
"integrity": "sha512-hRF04fqJIP8Abbkq5NKGN0Bbr3JxlQ+qhZufXVr0DvujKy93ZCbXZMHDL4EOtodSbCWxOqR8MS1tXA5hwqCXDg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"buffer-equal-constant-time": "^1.0.1",
|
||||
"ecdsa-sig-formatter": "1.0.11",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/jws": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jws/-/jws-4.0.0.tgz",
|
||||
"integrity": "sha512-KDncfTmOZoOMTFG4mBlG0qUIOlc03fmzH+ru6RgYVZhPkyiy/92Owlt/8UEN+a4TXR1FQetfIpJE8ApdvdVxTg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"jwa": "^2.0.0",
|
||||
"safe-buffer": "^5.0.1"
|
||||
}
|
||||
},
|
||||
"node_modules/kleur": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
|
||||
|
|
@ -10596,9 +10745,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/openai/node_modules/@types/node": {
|
||||
"version": "18.19.119",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.119.tgz",
|
||||
"integrity": "sha512-d0F6m9itIPaKnrvEMlzE48UjwZaAnFW7Jwibacw9MNdqadjKNpUm9tfJYDwmShJmgqcoqYUX3EMKO1+RWiuuNg==",
|
||||
"version": "18.19.120",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.120.tgz",
|
||||
"integrity": "sha512-WtCGHFXnVI8WHLxDAt5TbnCM4eSE+nI0QN2NJtwzcgMhht2eNz6V9evJrk+lwC8bCY8OWV5Ym8Jz7ZEyGnKnMA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~5.26.4"
|
||||
|
|
@ -11414,8 +11563,7 @@
|
|||
"node_modules/safe-buffer": {
|
||||
"version": "5.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==",
|
||||
"dev": true
|
||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
||||
},
|
||||
"node_modules/semantic-release": {
|
||||
"version": "24.2.7",
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
"@continuedev/config-yaml": "^1.0.51",
|
||||
"@continuedev/fetch": "^1.0.15",
|
||||
"dotenv": "^16.5.0",
|
||||
"google-auth-library": "^10.1.0",
|
||||
"json-schema": "^0.4.0",
|
||||
"node-fetch": "^3.3.2",
|
||||
"openai": "^4.104.0",
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ export class AnthropicApi implements BaseLlmApi {
|
|||
return cachingStrategy(cleanBody);
|
||||
}
|
||||
|
||||
private _convertToCleanAnthropicBody(oaiBody: ChatCompletionCreateParams) {
|
||||
public _convertToCleanAnthropicBody(oaiBody: ChatCompletionCreateParams) {
|
||||
let stop = undefined;
|
||||
if (oaiBody.stop && Array.isArray(oaiBody.stop)) {
|
||||
stop = oaiBody.stop.filter((x) => x.trim() !== "");
|
||||
|
|
@ -219,27 +219,9 @@ export class AnthropicApi implements BaseLlmApi {
|
|||
],
|
||||
};
|
||||
}
|
||||
async *chatCompletionStream(
|
||||
body: ChatCompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk, any, unknown> {
|
||||
body.messages;
|
||||
const response = await customFetch(this.config.requestOptions)(
|
||||
new URL("messages", this.apiBase),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"anthropic-version": "2023-06-01",
|
||||
"anthropic-beta": "prompt-caching-2024-07-31",
|
||||
"x-api-key": this.config.apiKey,
|
||||
},
|
||||
body: JSON.stringify(this._convertBody(body)),
|
||||
signal,
|
||||
},
|
||||
);
|
||||
|
||||
// This is split off so e.g. VertexAI can use it
|
||||
async *handleStreamResponse(response: any, model: string) {
|
||||
let lastToolUseId: string | undefined;
|
||||
let lastToolUseName: string | undefined;
|
||||
|
||||
|
|
@ -272,7 +254,7 @@ export class AnthropicApi implements BaseLlmApi {
|
|||
case "text_delta":
|
||||
yield chatChunk({
|
||||
content: value.delta.text,
|
||||
model: body.model,
|
||||
model,
|
||||
});
|
||||
break;
|
||||
case "input_json_delta":
|
||||
|
|
@ -280,7 +262,7 @@ export class AnthropicApi implements BaseLlmApi {
|
|||
throw new Error("No tool use found");
|
||||
}
|
||||
yield chatChunkFromDelta({
|
||||
model: body.model,
|
||||
model,
|
||||
delta: {
|
||||
tool_calls: [
|
||||
{
|
||||
|
|
@ -308,13 +290,36 @@ export class AnthropicApi implements BaseLlmApi {
|
|||
}
|
||||
|
||||
yield usageChatChunk({
|
||||
model: body.model,
|
||||
model,
|
||||
usage: {
|
||||
...usage,
|
||||
total_tokens: usage.completion_tokens + usage.prompt_tokens,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async *chatCompletionStream(
|
||||
body: ChatCompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk, any, unknown> {
|
||||
body.messages;
|
||||
const response = await customFetch(this.config.requestOptions)(
|
||||
new URL("messages", this.apiBase),
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"anthropic-version": "2023-06-01",
|
||||
"anthropic-beta": "prompt-caching-2024-07-31",
|
||||
"x-api-key": this.config.apiKey,
|
||||
},
|
||||
body: JSON.stringify(this._convertBody(body)),
|
||||
signal,
|
||||
},
|
||||
);
|
||||
yield* this.handleStreamResponse(response, body.model);
|
||||
}
|
||||
async completionNonStream(
|
||||
body: CompletionCreateParamsNonStreaming,
|
||||
signal: AbortSignal,
|
||||
|
|
|
|||
|
|
@ -84,7 +84,12 @@ export class GeminiApi implements BaseLlmApi {
|
|||
}
|
||||
}
|
||||
|
||||
private _convertBody(oaiBody: ChatCompletionCreateParams, url: string) {
|
||||
public _convertBody(
|
||||
oaiBody: ChatCompletionCreateParams,
|
||||
url: string,
|
||||
includeToolCallIds: boolean,
|
||||
overrideIsV1?: boolean,
|
||||
) {
|
||||
const generationConfig: any = {};
|
||||
|
||||
if (oaiBody.top_p) {
|
||||
|
|
@ -101,7 +106,7 @@ export class GeminiApi implements BaseLlmApi {
|
|||
generationConfig.stopSequences = stop.filter((x) => x.trim() !== "");
|
||||
}
|
||||
|
||||
const isV1API = url.includes("/v1/");
|
||||
const isV1API = overrideIsV1 ?? url.includes("/v1/");
|
||||
|
||||
const toolCallIdToNameMap = new Map<string, string>();
|
||||
oaiBody.messages.forEach((msg) => {
|
||||
|
|
@ -127,7 +132,7 @@ export class GeminiApi implements BaseLlmApi {
|
|||
role: "model" as const,
|
||||
parts: msg.tool_calls.map((toolCall) => ({
|
||||
functionCall: {
|
||||
id: toolCall.id,
|
||||
id: includeToolCallIds ? toolCall.id : undefined,
|
||||
name: toolCall.function.name,
|
||||
args: safeParseArgs(
|
||||
toolCall.function.arguments,
|
||||
|
|
@ -145,7 +150,7 @@ export class GeminiApi implements BaseLlmApi {
|
|||
parts: [
|
||||
{
|
||||
functionResponse: {
|
||||
id: msg.tool_call_id,
|
||||
id: includeToolCallIds ? msg.tool_call_id : undefined,
|
||||
name: functionName ?? "unknown",
|
||||
response: {
|
||||
content:
|
||||
|
|
@ -250,23 +255,9 @@ export class GeminiApi implements BaseLlmApi {
|
|||
};
|
||||
}
|
||||
|
||||
async *chatCompletionStream(
|
||||
body: ChatCompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk> {
|
||||
const apiURL = new URL(
|
||||
`models/${body.model}:streamGenerateContent?key=${this.config.apiKey}`,
|
||||
this.apiBase,
|
||||
).toString();
|
||||
const convertedBody = this._convertBody(body, apiURL);
|
||||
const resp = await customFetch(this.config.requestOptions)(apiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(convertedBody),
|
||||
signal,
|
||||
});
|
||||
|
||||
async *handleStreamResponse(response: any, model: string) {
|
||||
let buffer = "";
|
||||
for await (const chunk of streamResponse(resp as any)) {
|
||||
for await (const chunk of streamResponse(response as any)) {
|
||||
buffer += chunk;
|
||||
if (buffer.startsWith("[")) {
|
||||
buffer = buffer.slice(1);
|
||||
|
|
@ -301,11 +292,11 @@ export class GeminiApi implements BaseLlmApi {
|
|||
if ("text" in part) {
|
||||
yield chatChunk({
|
||||
content: part.text,
|
||||
model: body.model,
|
||||
model,
|
||||
});
|
||||
} else if ("functionCall" in part) {
|
||||
yield chatChunkFromDelta({
|
||||
model: body.model,
|
||||
model,
|
||||
delta: {
|
||||
tool_calls: [
|
||||
{
|
||||
|
|
@ -333,6 +324,23 @@ export class GeminiApi implements BaseLlmApi {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async *chatCompletionStream(
|
||||
body: ChatCompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk> {
|
||||
const apiURL = new URL(
|
||||
`models/${body.model}:streamGenerateContent?key=${this.config.apiKey}`,
|
||||
this.apiBase,
|
||||
).toString();
|
||||
const convertedBody = this._convertBody(body, apiURL, true);
|
||||
const resp = await customFetch(this.config.requestOptions)(apiURL, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(convertedBody),
|
||||
signal,
|
||||
});
|
||||
yield* this.handleStreamResponse(resp, body.model);
|
||||
}
|
||||
completionNonStream(
|
||||
body: CompletionCreateParamsNonStreaming,
|
||||
): Promise<Completion> {
|
||||
|
|
|
|||
569
packages/openai-adapters/src/apis/VertexAI.ts
Normal file
569
packages/openai-adapters/src/apis/VertexAI.ts
Normal file
|
|
@ -0,0 +1,569 @@
|
|||
import { streamSse } from "@continuedev/fetch";
|
||||
import { AuthClient, GoogleAuth, JWT, auth } from "google-auth-library";
|
||||
import {
|
||||
ChatCompletion,
|
||||
ChatCompletionChunk,
|
||||
ChatCompletionCreateParams,
|
||||
ChatCompletionCreateParamsNonStreaming,
|
||||
ChatCompletionCreateParamsStreaming,
|
||||
Completion,
|
||||
CompletionCreateParamsNonStreaming,
|
||||
CompletionCreateParamsStreaming,
|
||||
CreateEmbeddingResponse,
|
||||
EmbeddingCreateParams,
|
||||
Model,
|
||||
} from "openai/resources/index";
|
||||
import { VertexAIConfig } from "../types.js";
|
||||
import { chatChunk, chatCompletion, customFetch, embedding } from "../util.js";
|
||||
import { AnthropicApi } from "./Anthropic.js";
|
||||
import {
|
||||
BaseLlmApi,
|
||||
CreateRerankResponse,
|
||||
FimCreateParamsStreaming,
|
||||
RerankCreateParams,
|
||||
} from "./base.js";
|
||||
import { GeminiApi } from "./Gemini.js";
|
||||
import { OpenAIApi } from "./OpenAI.js";
|
||||
|
||||
export class VertexAIApi implements BaseLlmApi {
|
||||
anthropicInstance: AnthropicApi;
|
||||
geminiInstance: GeminiApi;
|
||||
mistralInstance: OpenAIApi;
|
||||
private clientPromise?: Promise<AuthClient | void>;
|
||||
static AUTH_SCOPES = "https://www.googleapis.com/auth/cloud-platform";
|
||||
|
||||
constructor(protected config: VertexAIConfig) {
|
||||
this.setupAuthentication();
|
||||
|
||||
// These sub-instances are only used to convert and handle responses,
|
||||
// So do not need apiKey, etc
|
||||
this.anthropicInstance = new AnthropicApi({
|
||||
provider: "anthropic",
|
||||
apiKey: "dud",
|
||||
});
|
||||
this.geminiInstance = new GeminiApi({
|
||||
provider: "gemini",
|
||||
apiKey: "dud",
|
||||
});
|
||||
this.mistralInstance = new OpenAIApi({
|
||||
provider: "mistral",
|
||||
apiKey: "dud",
|
||||
});
|
||||
}
|
||||
|
||||
private setupAuthentication(): void {
|
||||
const { apiKey, env } = this.config;
|
||||
const { region, projectId, keyFile, keyJson } = env || {};
|
||||
|
||||
// Validate authentication configuration
|
||||
if (apiKey) {
|
||||
// Express mode validation
|
||||
if (region || projectId || keyFile || keyJson) {
|
||||
throw new Error(
|
||||
"VertexAI in express mode (apiKey only) cannot be configured with region, projectId, keyFile, or keyJson",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Standard mode validation
|
||||
if (!region || !projectId) {
|
||||
throw new Error(
|
||||
"region and projectId are required for VertexAI (when not using express/apiKey mode)",
|
||||
);
|
||||
}
|
||||
if (keyFile && keyJson) {
|
||||
throw new Error(
|
||||
"VertexAI credentials can be configured with either keyFile or keyJson but not both",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Set up authentication client
|
||||
if (keyJson) {
|
||||
try {
|
||||
const parsed = JSON.parse(keyJson);
|
||||
if (!parsed?.private_key) {
|
||||
throw new Error("VertexAI: keyJson must contain a valid private key");
|
||||
}
|
||||
parsed.private_key = parsed.private_key.replace(/\\n/g, "\n");
|
||||
const jsonClient = auth.fromJSON(parsed);
|
||||
if (jsonClient instanceof JWT) {
|
||||
jsonClient.scopes = [VertexAIApi.AUTH_SCOPES];
|
||||
} else {
|
||||
throw new Error("VertexAI: keyJson must be a valid JWT");
|
||||
}
|
||||
this.clientPromise = Promise.resolve(jsonClient);
|
||||
} catch (e) {
|
||||
throw new Error("VertexAI: Failed to parse keyJson");
|
||||
}
|
||||
} else if (keyFile) {
|
||||
if (typeof keyFile !== "string") {
|
||||
throw new Error("VertexAI: keyFile must be a string");
|
||||
}
|
||||
this.clientPromise = new GoogleAuth({
|
||||
scopes: VertexAIApi.AUTH_SCOPES,
|
||||
keyFile,
|
||||
})
|
||||
.getClient()
|
||||
.catch((e: Error) => {
|
||||
console.warn(
|
||||
`Failed to load credentials for Vertex AI: ${e.message}`,
|
||||
);
|
||||
});
|
||||
} else if (!apiKey) {
|
||||
// Application Default Credentials
|
||||
this.clientPromise = new GoogleAuth({
|
||||
scopes: VertexAIApi.AUTH_SCOPES,
|
||||
})
|
||||
.getClient()
|
||||
.catch((e: Error) => {
|
||||
console.warn(
|
||||
`Failed to load credentials for Vertex AI: ${e.message}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private getApiBase(): string {
|
||||
const { apiKey, env } = this.config;
|
||||
|
||||
if (this.config.apiBase) {
|
||||
return this.config.apiBase;
|
||||
}
|
||||
|
||||
if (apiKey) {
|
||||
// Express mode
|
||||
return "https://aiplatform.googleapis.com/v1/";
|
||||
} else {
|
||||
// Standard mode
|
||||
const { region, projectId } = env!;
|
||||
return `https://${region}-aiplatform.googleapis.com/v1/projects/${projectId}/locations/${region}/`;
|
||||
}
|
||||
}
|
||||
|
||||
private determineVertexProvider(
|
||||
model: string,
|
||||
): "mistral" | "anthropic" | "gemini" | "unknown" {
|
||||
if (
|
||||
model.includes("mistral") ||
|
||||
model.includes("codestral") ||
|
||||
model.includes("mixtral")
|
||||
) {
|
||||
return "mistral";
|
||||
} else if (model.includes("claude")) {
|
||||
return "anthropic";
|
||||
} else if (model.includes("gemini")) {
|
||||
return "gemini";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
private async getAuthHeaders(): Promise<Record<string, string>> {
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
// Accept: "application/json"
|
||||
};
|
||||
|
||||
// TODO - support anthropic prompt caching with "anthropic-beta" header
|
||||
|
||||
if (this.config.apiKey) {
|
||||
// Express mode - no Authorization header needed, API key is in URL
|
||||
return headers;
|
||||
} else {
|
||||
// Standard mode - use OAuth token
|
||||
const client = await this.clientPromise;
|
||||
const result = await client?.getAccessToken();
|
||||
if (!result?.token) {
|
||||
throw new Error(
|
||||
"Could not get an access token. Set up your Google Application Default Credentials.",
|
||||
);
|
||||
}
|
||||
headers.Authorization = `Bearer ${result.token}`;
|
||||
return headers;
|
||||
}
|
||||
}
|
||||
|
||||
private buildUrl(endpoint: string, model?: string): URL {
|
||||
const apiBase = this.getApiBase();
|
||||
const url = new URL(endpoint, apiBase);
|
||||
|
||||
if (this.config.apiKey) {
|
||||
url.searchParams.set("key", this.config.apiKey);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
private convertAnthropicBody(oaiBody: ChatCompletionCreateParams): object {
|
||||
const body = this.anthropicInstance._convertToCleanAnthropicBody(oaiBody);
|
||||
const { model, ...exceptModel } = body;
|
||||
return {
|
||||
...exceptModel,
|
||||
anthropic_version: "vertex-2023-10-16",
|
||||
};
|
||||
}
|
||||
|
||||
private convertGeminiBody(
|
||||
oaiBody: ChatCompletionCreateParams,
|
||||
url: URL,
|
||||
): object {
|
||||
return this.geminiInstance._convertBody(
|
||||
oaiBody,
|
||||
url.toString(),
|
||||
false,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
async chatCompletionNonStream(
|
||||
body: ChatCompletionCreateParamsNonStreaming,
|
||||
signal: AbortSignal,
|
||||
): Promise<ChatCompletion> {
|
||||
const vertexProvider = this.determineVertexProvider(body.model);
|
||||
|
||||
if (this.config.apiKey && vertexProvider !== "gemini") {
|
||||
throw new Error(
|
||||
"VertexAI: only gemini models are supported in express (apiKey) mode",
|
||||
);
|
||||
}
|
||||
|
||||
const headers = await this.getAuthHeaders();
|
||||
let url: URL;
|
||||
let requestBody: any;
|
||||
|
||||
switch (vertexProvider) {
|
||||
case "anthropic":
|
||||
url = this.buildUrl(
|
||||
`publishers/anthropic/models/${body.model}:rawPredict`,
|
||||
);
|
||||
requestBody = this.convertAnthropicBody(body);
|
||||
break;
|
||||
case "gemini":
|
||||
url = this.buildUrl(
|
||||
`publishers/google/models/${body.model}:generateContent`,
|
||||
);
|
||||
requestBody = this.convertGeminiBody(body, url);
|
||||
break;
|
||||
case "mistral":
|
||||
url = this.buildUrl(
|
||||
`publishers/mistralai/models/${body.model}:rawPredict`,
|
||||
);
|
||||
requestBody = body;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported model: ${body.model}`);
|
||||
}
|
||||
|
||||
const response = await customFetch(this.config.requestOptions)(
|
||||
url.toString(),
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(requestBody),
|
||||
signal,
|
||||
},
|
||||
);
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`VertexAI API error: ${response.status} ${response.statusText}\n${JSON.stringify(data)}`,
|
||||
);
|
||||
}
|
||||
|
||||
// Convert response to OpenAI format
|
||||
switch (vertexProvider) {
|
||||
case "anthropic":
|
||||
return chatCompletion({
|
||||
content: data.content?.[0]?.text || "",
|
||||
model: body.model,
|
||||
});
|
||||
case "gemini":
|
||||
return chatCompletion({
|
||||
content: data.candidates?.[0]?.content?.parts?.[0]?.text || "",
|
||||
model: body.model,
|
||||
});
|
||||
case "mistral":
|
||||
return chatCompletion({
|
||||
content: data.choices?.[0]?.message?.content || "",
|
||||
model: body.model,
|
||||
});
|
||||
default:
|
||||
throw new Error(`Unsupported provider: ${vertexProvider}`);
|
||||
}
|
||||
}
|
||||
|
||||
async *chatCompletionStream(
|
||||
body: ChatCompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk> {
|
||||
const vertexProvider = this.determineVertexProvider(body.model);
|
||||
|
||||
if (this.config.apiKey && vertexProvider !== "gemini") {
|
||||
throw new Error(
|
||||
"VertexAI: only gemini models are supported in express (apiKey) mode",
|
||||
);
|
||||
}
|
||||
|
||||
const headers = await this.getAuthHeaders();
|
||||
let url: URL;
|
||||
let requestBody: any;
|
||||
|
||||
switch (vertexProvider) {
|
||||
case "anthropic":
|
||||
url = this.buildUrl(
|
||||
`publishers/anthropic/models/${body.model}:streamRawPredict`,
|
||||
);
|
||||
requestBody = this.convertAnthropicBody(body);
|
||||
break;
|
||||
case "gemini":
|
||||
url = this.buildUrl(
|
||||
`publishers/google/models/${body.model}:streamGenerateContent`,
|
||||
);
|
||||
requestBody = this.convertGeminiBody(body, url);
|
||||
break;
|
||||
case "mistral":
|
||||
url = this.buildUrl(
|
||||
`publishers/mistralai/models/${body.model}:streamRawPredict`,
|
||||
);
|
||||
requestBody = body;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unsupported model: ${body.model}`);
|
||||
}
|
||||
|
||||
switch (vertexProvider) {
|
||||
case "mistral":
|
||||
const mistralResponse =
|
||||
await this.mistralInstance.openai.chat.completions.create(
|
||||
this.mistralInstance.modifyChatBody(body),
|
||||
{
|
||||
signal,
|
||||
headers,
|
||||
},
|
||||
);
|
||||
for await (const result of mistralResponse) {
|
||||
yield result;
|
||||
}
|
||||
break;
|
||||
case "anthropic":
|
||||
case "gemini":
|
||||
const response = await customFetch(this.config.requestOptions)(
|
||||
url.toString(),
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(requestBody),
|
||||
signal,
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const data = await response.json();
|
||||
throw new Error(
|
||||
`VertexAI API error: ${response.status} ${response.statusText}\n${JSON.stringify(data)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (response.status === 499) {
|
||||
return; // Aborted by user
|
||||
}
|
||||
if (vertexProvider === "gemini") {
|
||||
yield* this.geminiInstance.handleStreamResponse(response, body.model);
|
||||
} else {
|
||||
yield* this.anthropicInstance.handleStreamResponse(
|
||||
response,
|
||||
body.model,
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
async completionNonStream(
|
||||
body: CompletionCreateParamsNonStreaming,
|
||||
signal: AbortSignal,
|
||||
): Promise<Completion> {
|
||||
// Convert completion to chat completion and back
|
||||
const promptText =
|
||||
typeof body.prompt === "string"
|
||||
? body.prompt
|
||||
: Array.isArray(body.prompt)
|
||||
? body.prompt.join("")
|
||||
: "";
|
||||
|
||||
const chatBody: ChatCompletionCreateParamsNonStreaming = {
|
||||
model: body.model,
|
||||
messages: [{ role: "user", content: promptText }],
|
||||
max_tokens: body.max_tokens,
|
||||
temperature: body.temperature,
|
||||
top_p: body.top_p,
|
||||
stop: body.stop,
|
||||
stream: false,
|
||||
};
|
||||
|
||||
const chatResponse = await this.chatCompletionNonStream(chatBody, signal);
|
||||
|
||||
return {
|
||||
id: chatResponse.id,
|
||||
object: "text_completion",
|
||||
created: chatResponse.created,
|
||||
model: chatResponse.model,
|
||||
choices: [
|
||||
{
|
||||
text: chatResponse.choices[0]?.message?.content || "",
|
||||
index: 0,
|
||||
logprobs: null,
|
||||
finish_reason: chatResponse.choices[0]?.finish_reason || null,
|
||||
},
|
||||
],
|
||||
usage: chatResponse.usage,
|
||||
} as Completion;
|
||||
}
|
||||
|
||||
async *completionStream(
|
||||
body: CompletionCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<Completion> {
|
||||
// Convert completion to chat completion and back
|
||||
const promptText =
|
||||
typeof body.prompt === "string"
|
||||
? body.prompt
|
||||
: Array.isArray(body.prompt)
|
||||
? body.prompt.join("")
|
||||
: "";
|
||||
|
||||
const chatBody: ChatCompletionCreateParamsStreaming = {
|
||||
model: body.model,
|
||||
messages: [{ role: "user", content: promptText }],
|
||||
max_tokens: body.max_tokens,
|
||||
temperature: body.temperature,
|
||||
top_p: body.top_p,
|
||||
stop: body.stop,
|
||||
stream: true,
|
||||
};
|
||||
|
||||
for await (const chatChunk of this.chatCompletionStream(chatBody, signal)) {
|
||||
yield {
|
||||
id: chatChunk.id,
|
||||
object: "text_completion",
|
||||
created: chatChunk.created,
|
||||
model: chatChunk.model,
|
||||
choices: [
|
||||
{
|
||||
text: chatChunk.choices[0]?.delta?.content || "",
|
||||
index: 0,
|
||||
logprobs: null,
|
||||
finish_reason: chatChunk.choices[0]?.finish_reason || null,
|
||||
},
|
||||
],
|
||||
} as Completion;
|
||||
}
|
||||
}
|
||||
|
||||
async *fimStream(
|
||||
body: FimCreateParamsStreaming,
|
||||
signal: AbortSignal,
|
||||
): AsyncGenerator<ChatCompletionChunk> {
|
||||
// Only Codestral (Mistral) supports FIM in VertexAI
|
||||
if (!body.model.includes("codestral")) {
|
||||
throw new Error(
|
||||
`FIM is only supported for Codestral models, got: ${body.model}`,
|
||||
);
|
||||
}
|
||||
|
||||
const headers = await this.getAuthHeaders();
|
||||
const url = this.buildUrl(
|
||||
`publishers/mistralai/models/${body.model}:streamRawPredict`,
|
||||
);
|
||||
|
||||
const requestBody = {
|
||||
model: body.model,
|
||||
max_tokens: body.max_tokens,
|
||||
temperature: body.temperature,
|
||||
top_p: body.top_p,
|
||||
stream: body.stream ?? true,
|
||||
stop: body.stop,
|
||||
prompt: body.prompt,
|
||||
suffix: body.suffix,
|
||||
};
|
||||
|
||||
const response = await customFetch(this.config.requestOptions)(
|
||||
url.toString(),
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(requestBody),
|
||||
signal,
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`VertexAI API error: ${response.status} ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
for await (const chunk of streamSse(response)) {
|
||||
if (chunk.choices?.[0]?.delta?.content) {
|
||||
yield chatChunk({
|
||||
content: chunk.choices[0].delta.content,
|
||||
model: body.model,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async embed(body: EmbeddingCreateParams): Promise<CreateEmbeddingResponse> {
|
||||
const headers = await this.getAuthHeaders();
|
||||
const url = this.buildUrl(`publishers/google/models/${body.model}:predict`);
|
||||
|
||||
// Convert input to text strings
|
||||
const textInputs = Array.isArray(body.input)
|
||||
? body.input.map((item) =>
|
||||
typeof item === "string" ? item : JSON.stringify(item),
|
||||
)
|
||||
: [
|
||||
typeof body.input === "string"
|
||||
? body.input
|
||||
: JSON.stringify(body.input),
|
||||
];
|
||||
|
||||
const requestBody = {
|
||||
instances: textInputs.map((text) => ({ content: text })),
|
||||
};
|
||||
|
||||
const response = await customFetch(this.config.requestOptions)(
|
||||
url.toString(),
|
||||
{
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify(requestBody),
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`VertexAI API error: ${response.status} ${response.statusText}`,
|
||||
);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
const embeddings = data.predictions.map(
|
||||
(prediction: any) => prediction.embeddings.values,
|
||||
);
|
||||
|
||||
return embedding({
|
||||
data: embeddings,
|
||||
model: body.model,
|
||||
});
|
||||
}
|
||||
|
||||
async rerank(body: RerankCreateParams): Promise<CreateRerankResponse> {
|
||||
throw new Error("Reranking is not supported by VertexAI");
|
||||
}
|
||||
|
||||
async list(): Promise<Model[]> {
|
||||
throw new Error("VertexAI provider does not support model listing.");
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import { MockApi } from "./apis/Mock.js";
|
|||
import { MoonshotApi } from "./apis/Moonshot.js";
|
||||
import { OpenAIApi } from "./apis/OpenAI.js";
|
||||
import { RelaceApi } from "./apis/Relace.js";
|
||||
import { VertexAIApi } from "./apis/VertexAI.js";
|
||||
import { WatsonXApi } from "./apis/WatsonX.js";
|
||||
import { BaseLlmApi } from "./apis/base.js";
|
||||
import { LLMConfig, OpenAIConfigSchema } from "./types.js";
|
||||
|
|
@ -56,6 +57,8 @@ export function constructLlmApi(config: LLMConfig): BaseLlmApi | undefined {
|
|||
return new InceptionApi(config);
|
||||
case "watsonx":
|
||||
return new WatsonXApi(config);
|
||||
case "vertexai":
|
||||
return new VertexAIApi(config);
|
||||
case "llamastack":
|
||||
return new LlamastackApi(config);
|
||||
case "continue-proxy":
|
||||
|
|
|
|||
|
|
@ -165,6 +165,19 @@ export const InceptionConfigSchema = OpenAIConfigSchema.extend({
|
|||
});
|
||||
export type InceptionConfig = z.infer<typeof InceptionConfigSchema>;
|
||||
|
||||
export const VertexAIConfigSchema = BasePlusConfig.extend({
|
||||
provider: z.literal("vertexai"),
|
||||
env: z
|
||||
.object({
|
||||
region: z.string().optional(),
|
||||
projectId: z.string().optional(),
|
||||
keyFile: z.string().optional(),
|
||||
keyJson: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
});
|
||||
export type VertexAIConfig = z.infer<typeof VertexAIConfigSchema>;
|
||||
|
||||
// Discriminated union
|
||||
export const LLMConfigSchema = z.discriminatedUnion("provider", [
|
||||
OpenAIConfigSchema,
|
||||
|
|
@ -179,6 +192,7 @@ export const LLMConfigSchema = z.discriminatedUnion("provider", [
|
|||
JinaConfigSchema,
|
||||
MockConfigSchema,
|
||||
InceptionConfigSchema,
|
||||
VertexAIConfigSchema,
|
||||
LlamastackConfigSchema,
|
||||
ContinueProxyConfigSchema,
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue