@providerprotocol/ai 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/anthropic/index.d.ts +184 -14
- package/dist/anthropic/index.js +306 -107
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-P5IRTEM5.js → chunk-7WYBJPJJ.js} +2 -2
- package/dist/chunk-I2VHCGQE.js +49 -0
- package/dist/chunk-I2VHCGQE.js.map +1 -0
- package/dist/{chunk-UMKWXGO3.js → chunk-M4BMM5IB.js} +86 -2
- package/dist/chunk-M4BMM5IB.js.map +1 -0
- package/dist/{chunk-SKY2JLA7.js → chunk-MKDLXV4O.js} +1 -1
- package/dist/chunk-MKDLXV4O.js.map +1 -0
- package/dist/{chunk-Z7RBRCRN.js → chunk-NWS5IKNR.js} +37 -11
- package/dist/chunk-NWS5IKNR.js.map +1 -0
- package/dist/{chunk-U3FZWV4U.js → chunk-RFWLEFAB.js} +100 -43
- package/dist/chunk-RFWLEFAB.js.map +1 -0
- package/dist/{chunk-U4JJC2YX.js → chunk-RS7C25LS.js} +36 -11
- package/dist/chunk-RS7C25LS.js.map +1 -0
- package/dist/google/index.d.ts +35 -24
- package/dist/google/index.js +273 -99
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +3 -3
- package/dist/http/index.js +4 -4
- package/dist/index.d.ts +103 -38
- package/dist/index.js +346 -153
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +14 -16
- package/dist/ollama/index.js +68 -16
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +25 -133
- package/dist/openai/index.js +208 -122
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +28 -53
- package/dist/openrouter/index.js +179 -72
- package/dist/openrouter/index.js.map +1 -1
- package/dist/provider-DWEAzeM5.d.ts +1329 -0
- package/dist/proxy/index.d.ts +2 -3
- package/dist/proxy/index.js +174 -17
- package/dist/proxy/index.js.map +1 -1
- package/dist/{retry-DR7YRJDz.d.ts → retry-DmPmqZL6.d.ts} +12 -3
- package/dist/{stream-DRHy6q1a.d.ts → stream-DbkLOIbJ.d.ts} +15 -5
- package/dist/xai/index.d.ts +16 -88
- package/dist/xai/index.js +167 -86
- package/dist/xai/index.js.map +1 -1
- package/package.json +4 -1
- package/dist/chunk-MSR5P65T.js +0 -39
- package/dist/chunk-MSR5P65T.js.map +0 -1
- package/dist/chunk-SKY2JLA7.js.map +0 -1
- package/dist/chunk-U3FZWV4U.js.map +0 -1
- package/dist/chunk-U4JJC2YX.js.map +0 -1
- package/dist/chunk-UMKWXGO3.js.map +0 -1
- package/dist/chunk-Z7RBRCRN.js.map +0 -1
- package/dist/content-DEl3z_W2.d.ts +0 -276
- package/dist/image-Dhq-Yuq4.d.ts +0 -456
- package/dist/provider-BBMBZuGn.d.ts +0 -570
- /package/dist/{chunk-P5IRTEM5.js.map → chunk-7WYBJPJJ.js.map} +0 -0
package/dist/google/index.js
CHANGED
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createProvider
|
|
3
|
-
} from "../chunk-MSR5P65T.js";
|
|
4
1
|
import {
|
|
5
2
|
Image
|
|
6
3
|
} from "../chunk-WAKD3OO5.js";
|
|
4
|
+
import {
|
|
5
|
+
parseJsonResponse
|
|
6
|
+
} from "../chunk-I2VHCGQE.js";
|
|
7
7
|
import {
|
|
8
8
|
AssistantMessage,
|
|
9
|
+
createProvider,
|
|
9
10
|
isAssistantMessage,
|
|
10
11
|
isToolResultMessage,
|
|
11
12
|
isUserMessage
|
|
12
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-M4BMM5IB.js";
|
|
13
14
|
import {
|
|
14
15
|
parseSSEStream
|
|
15
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-NWS5IKNR.js";
|
|
16
17
|
import {
|
|
17
18
|
resolveApiKey
|
|
18
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-7WYBJPJJ.js";
|
|
19
20
|
import {
|
|
20
21
|
UPPError,
|
|
21
22
|
doFetch,
|
|
22
23
|
doStreamFetch,
|
|
23
|
-
normalizeHttpError
|
|
24
|
-
|
|
24
|
+
normalizeHttpError,
|
|
25
|
+
toError
|
|
26
|
+
} from "../chunk-RFWLEFAB.js";
|
|
25
27
|
|
|
26
28
|
// src/providers/google/transform.ts
|
|
27
29
|
function transformRequest(request, modelId) {
|
|
28
30
|
const params = request.params ?? {};
|
|
29
|
-
const { cachedContent, builtInTools, toolConfig, ...generationParams } = params;
|
|
31
|
+
const { cachedContent, tools: builtInTools, toolConfig, ...generationParams } = params;
|
|
30
32
|
const googleRequest = {
|
|
31
33
|
contents: transformMessages(request.messages)
|
|
32
34
|
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
const normalizedSystem = normalizeSystem(request.system);
|
|
36
|
+
if (normalizedSystem !== void 0) {
|
|
37
|
+
if (typeof normalizedSystem === "string") {
|
|
35
38
|
googleRequest.systemInstruction = {
|
|
36
|
-
parts: [{ text:
|
|
39
|
+
parts: [{ text: normalizedSystem }]
|
|
37
40
|
};
|
|
38
|
-
} else {
|
|
41
|
+
} else if (normalizedSystem.length > 0) {
|
|
39
42
|
googleRequest.systemInstruction = {
|
|
40
|
-
parts:
|
|
43
|
+
parts: normalizedSystem
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -51,17 +54,17 @@ function transformRequest(request, modelId) {
|
|
|
51
54
|
if (Object.keys(generationConfig).length > 0) {
|
|
52
55
|
googleRequest.generationConfig = generationConfig;
|
|
53
56
|
}
|
|
54
|
-
const
|
|
57
|
+
const requestTools = [];
|
|
55
58
|
if (request.tools && request.tools.length > 0) {
|
|
56
|
-
|
|
59
|
+
requestTools.push({
|
|
57
60
|
functionDeclarations: request.tools.map(transformTool)
|
|
58
61
|
});
|
|
59
62
|
}
|
|
60
63
|
if (builtInTools && builtInTools.length > 0) {
|
|
61
|
-
|
|
64
|
+
requestTools.push(...builtInTools);
|
|
62
65
|
}
|
|
63
|
-
if (
|
|
64
|
-
googleRequest.tools =
|
|
66
|
+
if (requestTools.length > 0) {
|
|
67
|
+
googleRequest.tools = requestTools;
|
|
65
68
|
}
|
|
66
69
|
if (toolConfig) {
|
|
67
70
|
googleRequest.toolConfig = toolConfig;
|
|
@@ -71,6 +74,56 @@ function transformRequest(request, modelId) {
|
|
|
71
74
|
}
|
|
72
75
|
return googleRequest;
|
|
73
76
|
}
|
|
77
|
+
function normalizeSystem(system) {
|
|
78
|
+
if (system === void 0 || system === null) return void 0;
|
|
79
|
+
if (typeof system === "string") return system;
|
|
80
|
+
if (!Array.isArray(system)) {
|
|
81
|
+
throw new UPPError(
|
|
82
|
+
"System prompt must be a string or an array of text parts",
|
|
83
|
+
"INVALID_REQUEST",
|
|
84
|
+
"google",
|
|
85
|
+
"llm"
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const parts = [];
|
|
89
|
+
for (const part of system) {
|
|
90
|
+
if (!part || typeof part !== "object" || !("text" in part)) {
|
|
91
|
+
throw new UPPError(
|
|
92
|
+
"Google system prompt array must contain text parts",
|
|
93
|
+
"INVALID_REQUEST",
|
|
94
|
+
"google",
|
|
95
|
+
"llm"
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
const textValue = part.text;
|
|
99
|
+
if (typeof textValue !== "string") {
|
|
100
|
+
throw new UPPError(
|
|
101
|
+
"Google system prompt text must be a string",
|
|
102
|
+
"INVALID_REQUEST",
|
|
103
|
+
"google",
|
|
104
|
+
"llm"
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
parts.push(part);
|
|
108
|
+
}
|
|
109
|
+
return parts.length > 0 ? parts : void 0;
|
|
110
|
+
}
|
|
111
|
+
var GOOGLE_TOOLCALL_PREFIX = "google_toolcall";
|
|
112
|
+
function createGoogleToolCallId(name, index) {
|
|
113
|
+
return `${GOOGLE_TOOLCALL_PREFIX}:${index}:${name}`;
|
|
114
|
+
}
|
|
115
|
+
function extractGoogleToolName(toolCallId) {
|
|
116
|
+
const prefix = `${GOOGLE_TOOLCALL_PREFIX}:`;
|
|
117
|
+
if (!toolCallId.startsWith(prefix)) {
|
|
118
|
+
return toolCallId;
|
|
119
|
+
}
|
|
120
|
+
const rest = toolCallId.slice(prefix.length);
|
|
121
|
+
const separatorIndex = rest.indexOf(":");
|
|
122
|
+
if (separatorIndex === -1) {
|
|
123
|
+
return toolCallId;
|
|
124
|
+
}
|
|
125
|
+
return rest.slice(separatorIndex + 1);
|
|
126
|
+
}
|
|
74
127
|
function filterValidContent(content) {
|
|
75
128
|
return content.filter((c) => c && typeof c.type === "string");
|
|
76
129
|
}
|
|
@@ -126,7 +179,7 @@ function transformMessages(messages) {
|
|
|
126
179
|
role: "user",
|
|
127
180
|
parts: msg.results.map((result) => ({
|
|
128
181
|
functionResponse: {
|
|
129
|
-
name: result.toolCallId,
|
|
182
|
+
name: extractGoogleToolName(result.toolCallId),
|
|
130
183
|
response: typeof result.result === "object" ? result.result : { result: result.result }
|
|
131
184
|
}
|
|
132
185
|
}))
|
|
@@ -193,8 +246,9 @@ function transformResponse(data) {
|
|
|
193
246
|
}
|
|
194
247
|
} else if ("functionCall" in part) {
|
|
195
248
|
const fc = part;
|
|
249
|
+
const toolCallId = createGoogleToolCallId(fc.functionCall.name, toolCalls.length);
|
|
196
250
|
toolCalls.push({
|
|
197
|
-
toolCallId
|
|
251
|
+
toolCallId,
|
|
198
252
|
toolName: fc.functionCall.name,
|
|
199
253
|
arguments: fc.functionCall.args
|
|
200
254
|
});
|
|
@@ -236,7 +290,7 @@ ${codeResult.codeExecutionResult.output}\`\`\`
|
|
|
236
290
|
return {
|
|
237
291
|
message,
|
|
238
292
|
usage,
|
|
239
|
-
stopReason: candidate.finishReason
|
|
293
|
+
stopReason: normalizeStopReason(candidate.finishReason),
|
|
240
294
|
data: structuredData
|
|
241
295
|
};
|
|
242
296
|
}
|
|
@@ -276,7 +330,9 @@ function transformStreamChunk(chunk, state) {
|
|
|
276
330
|
});
|
|
277
331
|
} else if ("functionCall" in part) {
|
|
278
332
|
const fc = part;
|
|
333
|
+
const toolCallId = createGoogleToolCallId(fc.functionCall.name, state.toolCalls.length);
|
|
279
334
|
state.toolCalls.push({
|
|
335
|
+
id: toolCallId,
|
|
280
336
|
name: fc.functionCall.name,
|
|
281
337
|
args: fc.functionCall.args,
|
|
282
338
|
thoughtSignature: fc.thoughtSignature
|
|
@@ -285,7 +341,7 @@ function transformStreamChunk(chunk, state) {
|
|
|
285
341
|
type: "tool_call_delta",
|
|
286
342
|
index: state.toolCalls.length - 1,
|
|
287
343
|
delta: {
|
|
288
|
-
toolCallId
|
|
344
|
+
toolCallId,
|
|
289
345
|
toolName: fc.functionCall.name,
|
|
290
346
|
argumentsJson: JSON.stringify(fc.functionCall.args)
|
|
291
347
|
}
|
|
@@ -325,8 +381,9 @@ function buildResponseFromState(state) {
|
|
|
325
381
|
}
|
|
326
382
|
}
|
|
327
383
|
for (const tc of state.toolCalls) {
|
|
384
|
+
const toolCallId = tc.id || createGoogleToolCallId(tc.name, toolCalls.length);
|
|
328
385
|
toolCalls.push({
|
|
329
|
-
toolCallId
|
|
386
|
+
toolCallId,
|
|
330
387
|
toolName: tc.name,
|
|
331
388
|
arguments: tc.args
|
|
332
389
|
});
|
|
@@ -358,10 +415,25 @@ function buildResponseFromState(state) {
|
|
|
358
415
|
return {
|
|
359
416
|
message,
|
|
360
417
|
usage,
|
|
361
|
-
stopReason: state.finishReason
|
|
418
|
+
stopReason: normalizeStopReason(state.finishReason),
|
|
362
419
|
data: structuredData
|
|
363
420
|
};
|
|
364
421
|
}
|
|
422
|
+
function normalizeStopReason(reason) {
|
|
423
|
+
switch (reason) {
|
|
424
|
+
case "STOP":
|
|
425
|
+
return "end_turn";
|
|
426
|
+
case "MAX_TOKENS":
|
|
427
|
+
return "max_tokens";
|
|
428
|
+
case "SAFETY":
|
|
429
|
+
case "RECITATION":
|
|
430
|
+
return "content_filter";
|
|
431
|
+
case "OTHER":
|
|
432
|
+
return "end_turn";
|
|
433
|
+
default:
|
|
434
|
+
return "end_turn";
|
|
435
|
+
}
|
|
436
|
+
}
|
|
365
437
|
|
|
366
438
|
// src/providers/google/llm.ts
|
|
367
439
|
var GOOGLE_API_BASE = "https://generativelanguage.googleapis.com/v1beta";
|
|
@@ -373,9 +445,8 @@ var GOOGLE_CAPABILITIES = {
|
|
|
373
445
|
videoInput: true,
|
|
374
446
|
audioInput: true
|
|
375
447
|
};
|
|
376
|
-
function buildUrl(modelId, action
|
|
377
|
-
|
|
378
|
-
return `${base}?key=${apiKey}`;
|
|
448
|
+
function buildUrl(modelId, action) {
|
|
449
|
+
return `${GOOGLE_API_BASE}/models/${modelId}:${action}`;
|
|
379
450
|
}
|
|
380
451
|
function createLLMHandler() {
|
|
381
452
|
let providerRef = null;
|
|
@@ -405,10 +476,11 @@ function createLLMHandler() {
|
|
|
405
476
|
"google",
|
|
406
477
|
"llm"
|
|
407
478
|
);
|
|
408
|
-
const url = request.config.baseUrl ? `${request.config.baseUrl}/models/${modelId}:generateContent
|
|
479
|
+
const url = request.config.baseUrl ? `${request.config.baseUrl}/models/${modelId}:generateContent` : buildUrl(modelId, "generateContent");
|
|
409
480
|
const body = transformRequest(request, modelId);
|
|
410
481
|
const headers = {
|
|
411
|
-
"Content-Type": "application/json"
|
|
482
|
+
"Content-Type": "application/json",
|
|
483
|
+
"x-goog-api-key": apiKey
|
|
412
484
|
};
|
|
413
485
|
if (request.config.headers) {
|
|
414
486
|
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
@@ -429,7 +501,7 @@ function createLLMHandler() {
|
|
|
429
501
|
"google",
|
|
430
502
|
"llm"
|
|
431
503
|
);
|
|
432
|
-
const data = await response
|
|
504
|
+
const data = await parseJsonResponse(response, "google", "llm");
|
|
433
505
|
return transformResponse(data);
|
|
434
506
|
},
|
|
435
507
|
stream(request) {
|
|
@@ -448,10 +520,12 @@ function createLLMHandler() {
|
|
|
448
520
|
"google",
|
|
449
521
|
"llm"
|
|
450
522
|
);
|
|
451
|
-
const url = request.config.baseUrl ? `${request.config.baseUrl}/models/${modelId}:streamGenerateContent?alt=sse
|
|
523
|
+
const url = request.config.baseUrl ? `${request.config.baseUrl}/models/${modelId}:streamGenerateContent?alt=sse` : `${buildUrl(modelId, "streamGenerateContent")}?alt=sse`;
|
|
452
524
|
const body = transformRequest(request, modelId);
|
|
453
525
|
const headers = {
|
|
454
|
-
"Content-Type": "application/json"
|
|
526
|
+
"Content-Type": "application/json",
|
|
527
|
+
Accept: "text/event-stream",
|
|
528
|
+
"x-goog-api-key": apiKey
|
|
455
529
|
};
|
|
456
530
|
if (request.config.headers) {
|
|
457
531
|
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
@@ -490,7 +564,7 @@ function createLLMHandler() {
|
|
|
490
564
|
for await (const data of parseSSEStream(response.body)) {
|
|
491
565
|
if (typeof data === "object" && data !== null) {
|
|
492
566
|
const chunk = data;
|
|
493
|
-
if (
|
|
567
|
+
if (chunk.error) {
|
|
494
568
|
const error = new UPPError(
|
|
495
569
|
chunk.error.message,
|
|
496
570
|
"PROVIDER_ERROR",
|
|
@@ -508,8 +582,9 @@ function createLLMHandler() {
|
|
|
508
582
|
}
|
|
509
583
|
responseResolve(buildResponseFromState(state));
|
|
510
584
|
} catch (error) {
|
|
511
|
-
|
|
512
|
-
|
|
585
|
+
const err = toError(error);
|
|
586
|
+
responseReject(err);
|
|
587
|
+
throw err;
|
|
513
588
|
}
|
|
514
589
|
}
|
|
515
590
|
return {
|
|
@@ -570,26 +645,16 @@ function createEmbeddingHandler() {
|
|
|
570
645
|
);
|
|
571
646
|
}
|
|
572
647
|
const embedRequest = {
|
|
648
|
+
...request.params,
|
|
573
649
|
model: `models/${modelId}`,
|
|
574
650
|
content: { parts: [{ text }] }
|
|
575
651
|
};
|
|
576
|
-
if (request.params?.taskType !== void 0) {
|
|
577
|
-
embedRequest.taskType = request.params.taskType;
|
|
578
|
-
}
|
|
579
|
-
if (request.params?.title !== void 0) {
|
|
580
|
-
embedRequest.title = request.params.title;
|
|
581
|
-
}
|
|
582
|
-
if (request.params?.outputDimensionality !== void 0) {
|
|
583
|
-
embedRequest.outputDimensionality = request.params.outputDimensionality;
|
|
584
|
-
}
|
|
585
|
-
if (request.params?.autoTruncate !== void 0) {
|
|
586
|
-
embedRequest.autoTruncate = request.params.autoTruncate;
|
|
587
|
-
}
|
|
588
652
|
return embedRequest;
|
|
589
653
|
});
|
|
590
|
-
const url = `${baseUrl}/models/${modelId}:batchEmbedContents
|
|
654
|
+
const url = `${baseUrl}/models/${modelId}:batchEmbedContents`;
|
|
591
655
|
const headers = {
|
|
592
|
-
"Content-Type": "application/json"
|
|
656
|
+
"Content-Type": "application/json",
|
|
657
|
+
"x-goog-api-key": apiKey
|
|
593
658
|
};
|
|
594
659
|
if (request.config.headers) {
|
|
595
660
|
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
@@ -604,7 +669,7 @@ function createEmbeddingHandler() {
|
|
|
604
669
|
body: JSON.stringify({ requests }),
|
|
605
670
|
signal: request.signal
|
|
606
671
|
}, request.config, "google", "embedding");
|
|
607
|
-
const data = await response
|
|
672
|
+
const data = await parseJsonResponse(response, "google", "embedding");
|
|
608
673
|
let totalTokens = 0;
|
|
609
674
|
for (const emb of data.embeddings) {
|
|
610
675
|
totalTokens += emb.statistics?.tokenCount ?? 0;
|
|
@@ -700,20 +765,11 @@ async function executeGenerate(modelId, request) {
|
|
|
700
765
|
body: JSON.stringify(body),
|
|
701
766
|
signal: request.signal
|
|
702
767
|
}, request.config, "google", "image");
|
|
703
|
-
const data = await response
|
|
768
|
+
const data = await parseJsonResponse(response, "google", "image");
|
|
704
769
|
return transformResponse2(data);
|
|
705
770
|
}
|
|
706
771
|
function buildParameters(params) {
|
|
707
|
-
|
|
708
|
-
if (!params) return parameters;
|
|
709
|
-
if (params.sampleCount !== void 0) parameters.sampleCount = params.sampleCount;
|
|
710
|
-
if (params.imageSize !== void 0) parameters.imageSize = params.imageSize;
|
|
711
|
-
if (params.aspectRatio !== void 0) parameters.aspectRatio = params.aspectRatio;
|
|
712
|
-
if (params.personGeneration !== void 0) parameters.personGeneration = params.personGeneration;
|
|
713
|
-
if (params.safetyFilterLevel !== void 0) parameters.safetyFilterLevel = params.safetyFilterLevel;
|
|
714
|
-
if (params.addWatermark !== void 0) parameters.addWatermark = params.addWatermark;
|
|
715
|
-
if (params.negativePrompt !== void 0) parameters.negativePrompt = params.negativePrompt;
|
|
716
|
-
return parameters;
|
|
772
|
+
return params ? { ...params } : {};
|
|
717
773
|
}
|
|
718
774
|
function transformResponse2(data) {
|
|
719
775
|
if (!data.predictions || data.predictions.length === 0) {
|
|
@@ -738,10 +794,19 @@ function transformResponse2(data) {
|
|
|
738
794
|
}
|
|
739
795
|
|
|
740
796
|
// src/providers/google/cache.ts
|
|
741
|
-
var
|
|
797
|
+
var DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
798
|
+
function resolveBaseUrl(config) {
|
|
799
|
+
if (config?.baseUrl) {
|
|
800
|
+
const trimmed = config.baseUrl.replace(/\/$/, "");
|
|
801
|
+
return trimmed.endsWith("/v1beta") ? trimmed : `${trimmed}/v1beta`;
|
|
802
|
+
}
|
|
803
|
+
return DEFAULT_BASE_URL;
|
|
804
|
+
}
|
|
742
805
|
async function create(options) {
|
|
743
806
|
const {
|
|
744
807
|
apiKey,
|
|
808
|
+
config,
|
|
809
|
+
signal,
|
|
745
810
|
model,
|
|
746
811
|
displayName,
|
|
747
812
|
contents,
|
|
@@ -750,6 +815,8 @@ async function create(options) {
|
|
|
750
815
|
ttl,
|
|
751
816
|
expireTime
|
|
752
817
|
} = options;
|
|
818
|
+
const baseUrl = resolveBaseUrl(config);
|
|
819
|
+
const requestConfig = { ...config, apiKey };
|
|
753
820
|
const requestBody = {
|
|
754
821
|
model: model.startsWith("models/") ? model : `models/${model}`
|
|
755
822
|
};
|
|
@@ -772,56 +839,163 @@ async function create(options) {
|
|
|
772
839
|
} else if (expireTime) {
|
|
773
840
|
requestBody.expireTime = expireTime;
|
|
774
841
|
}
|
|
775
|
-
const
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
842
|
+
const headers = {
|
|
843
|
+
"Content-Type": "application/json",
|
|
844
|
+
"x-goog-api-key": apiKey
|
|
845
|
+
};
|
|
846
|
+
if (config?.headers) {
|
|
847
|
+
for (const [key, value] of Object.entries(config.headers)) {
|
|
848
|
+
if (value !== void 0) {
|
|
849
|
+
headers[key] = value;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
782
852
|
}
|
|
783
|
-
|
|
853
|
+
const response = await doFetch(
|
|
854
|
+
`${baseUrl}/cachedContents`,
|
|
855
|
+
{
|
|
856
|
+
method: "POST",
|
|
857
|
+
headers,
|
|
858
|
+
body: JSON.stringify(requestBody),
|
|
859
|
+
signal
|
|
860
|
+
},
|
|
861
|
+
requestConfig,
|
|
862
|
+
"google",
|
|
863
|
+
"llm"
|
|
864
|
+
);
|
|
865
|
+
return parseJsonResponse(response, "google", "llm");
|
|
784
866
|
}
|
|
785
|
-
async function get(name, apiKey) {
|
|
867
|
+
async function get(name, apiKey, config, signal) {
|
|
786
868
|
const cacheName = name.startsWith("cachedContents/") ? name : `cachedContents/${name}`;
|
|
787
|
-
const
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
869
|
+
const baseUrl = resolveBaseUrl(config);
|
|
870
|
+
const url = `${baseUrl}/${cacheName}`;
|
|
871
|
+
const requestConfig = { ...config, apiKey };
|
|
872
|
+
const headers = { "x-goog-api-key": apiKey };
|
|
873
|
+
if (config?.headers) {
|
|
874
|
+
for (const [key, value] of Object.entries(config.headers)) {
|
|
875
|
+
if (value !== void 0) {
|
|
876
|
+
headers[key] = value;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
791
879
|
}
|
|
792
|
-
|
|
880
|
+
const response = await doFetch(
|
|
881
|
+
url,
|
|
882
|
+
{
|
|
883
|
+
method: "GET",
|
|
884
|
+
headers,
|
|
885
|
+
signal
|
|
886
|
+
},
|
|
887
|
+
requestConfig,
|
|
888
|
+
"google",
|
|
889
|
+
"llm"
|
|
890
|
+
);
|
|
891
|
+
return parseJsonResponse(response, "google", "llm");
|
|
793
892
|
}
|
|
794
893
|
async function list(options) {
|
|
795
|
-
const { apiKey, pageSize, pageToken } = options;
|
|
796
|
-
const
|
|
894
|
+
const { apiKey, config, signal, pageSize, pageToken } = options;
|
|
895
|
+
const baseUrl = resolveBaseUrl(config);
|
|
896
|
+
const requestConfig = { ...config, apiKey };
|
|
897
|
+
const params = new URLSearchParams();
|
|
797
898
|
if (pageSize) params.set("pageSize", String(pageSize));
|
|
798
899
|
if (pageToken) params.set("pageToken", pageToken);
|
|
799
|
-
const
|
|
800
|
-
if (
|
|
801
|
-
|
|
900
|
+
const headers = { "x-goog-api-key": apiKey };
|
|
901
|
+
if (config?.headers) {
|
|
902
|
+
for (const [key, value] of Object.entries(config.headers)) {
|
|
903
|
+
if (value !== void 0) {
|
|
904
|
+
headers[key] = value;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
802
907
|
}
|
|
803
|
-
|
|
908
|
+
const response = await doFetch(
|
|
909
|
+
`${baseUrl}/cachedContents?${params}`,
|
|
910
|
+
{
|
|
911
|
+
method: "GET",
|
|
912
|
+
headers,
|
|
913
|
+
signal
|
|
914
|
+
},
|
|
915
|
+
requestConfig,
|
|
916
|
+
"google",
|
|
917
|
+
"llm"
|
|
918
|
+
);
|
|
919
|
+
return parseJsonResponse(response, "google", "llm");
|
|
804
920
|
}
|
|
805
|
-
async function update(name, updateRequest, apiKey) {
|
|
921
|
+
async function update(name, updateRequest, apiKey, config, signal) {
|
|
922
|
+
if (updateRequest.expireTime && updateRequest.ttl) {
|
|
923
|
+
throw new UPPError(
|
|
924
|
+
"Provide either expireTime or ttl (not both)",
|
|
925
|
+
"INVALID_REQUEST",
|
|
926
|
+
"google",
|
|
927
|
+
"llm"
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
const updateMaskParts = [];
|
|
931
|
+
if (updateRequest.expireTime) {
|
|
932
|
+
updateMaskParts.push("expireTime");
|
|
933
|
+
}
|
|
934
|
+
if (updateRequest.ttl) {
|
|
935
|
+
updateMaskParts.push("ttl");
|
|
936
|
+
}
|
|
937
|
+
if (updateMaskParts.length === 0) {
|
|
938
|
+
throw new UPPError(
|
|
939
|
+
"Update request must include expireTime or ttl",
|
|
940
|
+
"INVALID_REQUEST",
|
|
941
|
+
"google",
|
|
942
|
+
"llm"
|
|
943
|
+
);
|
|
944
|
+
}
|
|
806
945
|
const cacheName = name.startsWith("cachedContents/") ? name : `cachedContents/${name}`;
|
|
807
|
-
const
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
946
|
+
const baseUrl = resolveBaseUrl(config);
|
|
947
|
+
const params = new URLSearchParams({ updateMask: updateMaskParts.join(",") });
|
|
948
|
+
const url = `${baseUrl}/${cacheName}?${params.toString()}`;
|
|
949
|
+
const requestConfig = { ...config, apiKey };
|
|
950
|
+
const headers = {
|
|
951
|
+
"Content-Type": "application/json",
|
|
952
|
+
"x-goog-api-key": apiKey
|
|
953
|
+
};
|
|
954
|
+
if (config?.headers) {
|
|
955
|
+
for (const [key, value] of Object.entries(config.headers)) {
|
|
956
|
+
if (value !== void 0) {
|
|
957
|
+
headers[key] = value;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
815
960
|
}
|
|
816
|
-
|
|
961
|
+
const response = await doFetch(
|
|
962
|
+
url,
|
|
963
|
+
{
|
|
964
|
+
method: "PATCH",
|
|
965
|
+
headers,
|
|
966
|
+
body: JSON.stringify(updateRequest),
|
|
967
|
+
signal
|
|
968
|
+
},
|
|
969
|
+
requestConfig,
|
|
970
|
+
"google",
|
|
971
|
+
"llm"
|
|
972
|
+
);
|
|
973
|
+
return parseJsonResponse(response, "google", "llm");
|
|
817
974
|
}
|
|
818
|
-
async function deleteCache(name, apiKey) {
|
|
975
|
+
async function deleteCache(name, apiKey, config, signal) {
|
|
819
976
|
const cacheName = name.startsWith("cachedContents/") ? name : `cachedContents/${name}`;
|
|
820
|
-
const
|
|
821
|
-
const
|
|
822
|
-
|
|
823
|
-
|
|
977
|
+
const baseUrl = resolveBaseUrl(config);
|
|
978
|
+
const url = `${baseUrl}/${cacheName}`;
|
|
979
|
+
const requestConfig = { ...config, apiKey };
|
|
980
|
+
const headers = { "x-goog-api-key": apiKey };
|
|
981
|
+
if (config?.headers) {
|
|
982
|
+
for (const [key, value] of Object.entries(config.headers)) {
|
|
983
|
+
if (value !== void 0) {
|
|
984
|
+
headers[key] = value;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
824
987
|
}
|
|
988
|
+
const response = await doFetch(
|
|
989
|
+
url,
|
|
990
|
+
{
|
|
991
|
+
method: "DELETE",
|
|
992
|
+
headers,
|
|
993
|
+
signal
|
|
994
|
+
},
|
|
995
|
+
requestConfig,
|
|
996
|
+
"google",
|
|
997
|
+
"llm"
|
|
998
|
+
);
|
|
825
999
|
}
|
|
826
1000
|
var cache = {
|
|
827
1001
|
create,
|
|
@@ -870,7 +1044,7 @@ var tools = {
|
|
|
870
1044
|
var baseProvider = createProvider({
|
|
871
1045
|
name: "google",
|
|
872
1046
|
version: "1.0.0",
|
|
873
|
-
|
|
1047
|
+
handlers: {
|
|
874
1048
|
llm: createLLMHandler(),
|
|
875
1049
|
embedding: createEmbeddingHandler(),
|
|
876
1050
|
image: createImageHandler()
|