@langchain/google-common 0.2.18 → 1.0.1
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/CHANGELOG.md +23 -0
- package/LICENSE +6 -6
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/auth.cjs +82 -116
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +46 -0
- package/dist/auth.d.cts.map +1 -0
- package/dist/auth.d.ts +41 -36
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +80 -110
- package/dist/auth.js.map +1 -0
- package/dist/chat_models.cjs +264 -466
- package/dist/chat_models.cjs.map +1 -0
- package/dist/chat_models.d.cts +109 -0
- package/dist/chat_models.d.cts.map +1 -0
- package/dist/chat_models.d.ts +98 -73
- package/dist/chat_models.d.ts.map +1 -0
- package/dist/chat_models.js +258 -457
- package/dist/chat_models.js.map +1 -0
- package/dist/connection.cjs +321 -466
- package/dist/connection.cjs.map +1 -0
- package/dist/connection.d.cts +109 -0
- package/dist/connection.d.cts.map +1 -0
- package/dist/connection.d.ts +98 -91
- package/dist/connection.d.ts.map +1 -0
- package/dist/connection.js +317 -459
- package/dist/connection.js.map +1 -0
- package/dist/embeddings.cjs +135 -186
- package/dist/embeddings.cjs.map +1 -0
- package/dist/embeddings.d.cts +44 -0
- package/dist/embeddings.d.cts.map +1 -0
- package/dist/embeddings.d.ts +38 -32
- package/dist/embeddings.d.ts.map +1 -0
- package/dist/embeddings.js +133 -181
- package/dist/embeddings.js.map +1 -0
- package/dist/experimental/media.cjs +380 -482
- package/dist/experimental/media.cjs.map +1 -0
- package/dist/experimental/media.d.cts +198 -0
- package/dist/experimental/media.d.cts.map +1 -0
- package/dist/experimental/media.d.ts +190 -202
- package/dist/experimental/media.d.ts.map +1 -0
- package/dist/experimental/media.js +369 -468
- package/dist/experimental/media.js.map +1 -0
- package/dist/experimental/utils/media_core.cjs +403 -517
- package/dist/experimental/utils/media_core.cjs.map +1 -0
- package/dist/experimental/utils/media_core.d.cts +215 -0
- package/dist/experimental/utils/media_core.d.cts.map +1 -0
- package/dist/experimental/utils/media_core.d.ts +171 -165
- package/dist/experimental/utils/media_core.d.ts.map +1 -0
- package/dist/experimental/utils/media_core.js +395 -506
- package/dist/experimental/utils/media_core.js.map +1 -0
- package/dist/index.cjs +58 -27
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -11
- package/dist/index.js +13 -11
- package/dist/llms.cjs +157 -244
- package/dist/llms.cjs.map +1 -0
- package/dist/llms.d.cts +72 -0
- package/dist/llms.d.cts.map +1 -0
- package/dist/llms.d.ts +64 -54
- package/dist/llms.d.ts.map +1 -0
- package/dist/llms.js +154 -238
- package/dist/llms.js.map +1 -0
- package/dist/output_parsers.cjs +148 -173
- package/dist/output_parsers.cjs.map +1 -0
- package/dist/output_parsers.d.cts +53 -0
- package/dist/output_parsers.d.cts.map +1 -0
- package/dist/output_parsers.d.ts +46 -42
- package/dist/output_parsers.d.ts.map +1 -0
- package/dist/output_parsers.js +146 -168
- package/dist/output_parsers.js.map +1 -0
- package/dist/profiles.cjs +219 -0
- package/dist/profiles.cjs.map +1 -0
- package/dist/profiles.js +218 -0
- package/dist/profiles.js.map +1 -0
- package/dist/types-anthropic.d.cts +229 -0
- package/dist/types-anthropic.d.cts.map +1 -0
- package/dist/types-anthropic.d.ts +221 -215
- package/dist/types-anthropic.d.ts.map +1 -0
- package/dist/types.cjs +51 -62
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +748 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +669 -656
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +46 -45
- package/dist/types.js.map +1 -0
- package/dist/utils/anthropic.cjs +598 -821
- package/dist/utils/anthropic.cjs.map +1 -0
- package/dist/utils/anthropic.js +597 -818
- package/dist/utils/anthropic.js.map +1 -0
- package/dist/utils/common.cjs +130 -211
- package/dist/utils/common.cjs.map +1 -0
- package/dist/utils/common.d.cts +13 -0
- package/dist/utils/common.d.cts.map +1 -0
- package/dist/utils/common.d.ts +12 -7
- package/dist/utils/common.d.ts.map +1 -0
- package/dist/utils/common.js +128 -207
- package/dist/utils/common.js.map +1 -0
- package/dist/utils/failed_handler.cjs +28 -30
- package/dist/utils/failed_handler.cjs.map +1 -0
- package/dist/utils/failed_handler.d.cts +9 -0
- package/dist/utils/failed_handler.d.cts.map +1 -0
- package/dist/utils/failed_handler.d.ts +8 -2
- package/dist/utils/failed_handler.d.ts.map +1 -0
- package/dist/utils/failed_handler.js +28 -28
- package/dist/utils/failed_handler.js.map +1 -0
- package/dist/utils/gemini.cjs +1020 -1488
- package/dist/utils/gemini.cjs.map +1 -0
- package/dist/utils/gemini.d.cts +51 -0
- package/dist/utils/gemini.d.cts.map +1 -0
- package/dist/utils/gemini.d.ts +51 -48
- package/dist/utils/gemini.d.ts.map +1 -0
- package/dist/utils/gemini.js +1015 -1479
- package/dist/utils/gemini.js.map +1 -0
- package/dist/utils/index.cjs +38 -23
- package/dist/utils/index.d.cts +8 -0
- package/dist/utils/index.d.ts +8 -7
- package/dist/utils/index.js +8 -7
- package/dist/utils/palm.d.cts +11 -0
- package/dist/utils/palm.d.cts.map +1 -0
- package/dist/utils/palm.d.ts +9 -4
- package/dist/utils/palm.d.ts.map +1 -0
- package/dist/utils/safety.cjs +13 -22
- package/dist/utils/safety.cjs.map +1 -0
- package/dist/utils/safety.d.cts +12 -0
- package/dist/utils/safety.d.cts.map +1 -0
- package/dist/utils/safety.d.ts +10 -4
- package/dist/utils/safety.d.ts.map +1 -0
- package/dist/utils/safety.js +13 -19
- package/dist/utils/safety.js.map +1 -0
- package/dist/utils/stream.cjs +296 -475
- package/dist/utils/stream.cjs.map +1 -0
- package/dist/utils/stream.d.cts +165 -0
- package/dist/utils/stream.d.cts.map +1 -0
- package/dist/utils/stream.d.ts +156 -131
- package/dist/utils/stream.d.ts.map +1 -0
- package/dist/utils/stream.js +293 -469
- package/dist/utils/stream.js.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.cjs +43 -81
- package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts +22 -0
- package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.d.ts +21 -6
- package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -0
- package/dist/utils/zod_to_gemini_parameters.js +40 -76
- package/dist/utils/zod_to_gemini_parameters.js.map +1 -0
- package/package.json +72 -85
- package/dist/types-anthropic.cjs +0 -2
- package/dist/types-anthropic.js +0 -1
- package/dist/utils/anthropic.d.ts +0 -4
- package/dist/utils/palm.cjs +0 -2
- package/dist/utils/palm.js +0 -1
- package/experimental/media.cjs +0 -1
- package/experimental/media.d.cts +0 -1
- package/experimental/media.d.ts +0 -1
- package/experimental/media.js +0 -1
- package/experimental/utils/media_core.cjs +0 -1
- package/experimental/utils/media_core.d.cts +0 -1
- package/experimental/utils/media_core.d.ts +0 -1
- package/experimental/utils/media_core.js +0 -1
- package/index.cjs +0 -1
- package/index.d.cts +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -1
- package/types.cjs +0 -1
- package/types.d.cts +0 -1
- package/types.d.ts +0 -1
- package/types.js +0 -1
- package/utils.cjs +0 -1
- package/utils.d.cts +0 -1
- package/utils.d.ts +0 -1
- package/utils.js +0 -1
package/dist/utils/common.js
CHANGED
|
@@ -1,224 +1,145 @@
|
|
|
1
|
+
import { GeminiToolAttributes } from "../types.js";
|
|
2
|
+
import { jsonSchemaToGeminiParameters, schemaToGeminiParameters } from "./zod_to_gemini_parameters.js";
|
|
3
|
+
import { isModelGemini, isModelGemma, normalizeSpeechConfig, validateGeminiParams } from "./gemini.js";
|
|
4
|
+
import { isModelClaude, validateClaudeParams } from "./anthropic.js";
|
|
1
5
|
import { isOpenAITool } from "@langchain/core/language_models/base";
|
|
2
6
|
import { isLangChainTool } from "@langchain/core/utils/function_calling";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export function copyAIModelParams(params, options) {
|
|
8
|
-
return copyAIModelParamsInto(params, options, {});
|
|
7
|
+
|
|
8
|
+
//#region src/utils/common.ts
|
|
9
|
+
function copyAIModelParams(params, options) {
|
|
10
|
+
return copyAIModelParamsInto(params, options, {});
|
|
9
11
|
}
|
|
10
12
|
function processToolChoice(toolChoice, allowedFunctionNames) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (typeof toolChoice === "string") {
|
|
28
|
-
// String representing the function name.
|
|
29
|
-
// Return any to force the model to predict the specified function call.
|
|
30
|
-
return {
|
|
31
|
-
tool_choice: "any",
|
|
32
|
-
allowed_function_names: [...(allowedFunctionNames ?? []), toolChoice],
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
throw new Error("Object inputs for tool_choice not supported.");
|
|
13
|
+
if (!toolChoice) {
|
|
14
|
+
if (allowedFunctionNames) return {
|
|
15
|
+
tool_choice: "any",
|
|
16
|
+
allowed_function_names: allowedFunctionNames
|
|
17
|
+
};
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
if (toolChoice === "any" || toolChoice === "auto" || toolChoice === "none") return {
|
|
21
|
+
tool_choice: toolChoice,
|
|
22
|
+
allowed_function_names: allowedFunctionNames
|
|
23
|
+
};
|
|
24
|
+
if (typeof toolChoice === "string") return {
|
|
25
|
+
tool_choice: "any",
|
|
26
|
+
allowed_function_names: [...allowedFunctionNames ?? [], toolChoice]
|
|
27
|
+
};
|
|
28
|
+
throw new Error("Object inputs for tool_choice not supported.");
|
|
36
29
|
}
|
|
37
30
|
function isGeminiTool(tool) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
31
|
+
for (const toolAttribute of GeminiToolAttributes) if (toolAttribute in tool) return true;
|
|
32
|
+
return false;
|
|
44
33
|
}
|
|
45
34
|
function isGeminiNonFunctionTool(tool) {
|
|
46
|
-
|
|
35
|
+
return isGeminiTool(tool) && !("functionDeclaration" in tool);
|
|
47
36
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
name: tool.function.name,
|
|
78
|
-
description: tool.function.description ?? `A function available to call.`,
|
|
79
|
-
parameters: jsonSchemaToGeminiParameters(tool.function.parameters),
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
return geminiTools;
|
|
37
|
+
function convertToGeminiTools(tools) {
|
|
38
|
+
const geminiTools = [];
|
|
39
|
+
let functionDeclarationsIndex = -1;
|
|
40
|
+
tools.forEach((tool) => {
|
|
41
|
+
if (isGeminiNonFunctionTool(tool)) geminiTools.push(tool);
|
|
42
|
+
else {
|
|
43
|
+
if (functionDeclarationsIndex === -1) {
|
|
44
|
+
geminiTools.push({ functionDeclarations: [] });
|
|
45
|
+
functionDeclarationsIndex = geminiTools.length - 1;
|
|
46
|
+
}
|
|
47
|
+
if ("functionDeclarations" in tool && Array.isArray(tool.functionDeclarations)) {
|
|
48
|
+
const funcs = tool.functionDeclarations;
|
|
49
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
|
|
50
|
+
} else if (isLangChainTool(tool)) {
|
|
51
|
+
const jsonSchema = schemaToGeminiParameters(tool.schema);
|
|
52
|
+
geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
53
|
+
name: tool.name,
|
|
54
|
+
description: tool.description ?? `A function available to call.`,
|
|
55
|
+
parameters: jsonSchema
|
|
56
|
+
});
|
|
57
|
+
} else if (isOpenAITool(tool)) geminiTools[functionDeclarationsIndex].functionDeclarations.push({
|
|
58
|
+
name: tool.function.name,
|
|
59
|
+
description: tool.function.description ?? `A function available to call.`,
|
|
60
|
+
parameters: jsonSchemaToGeminiParameters(tool.function.parameters)
|
|
61
|
+
});
|
|
62
|
+
else throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return geminiTools;
|
|
88
66
|
}
|
|
89
67
|
function reasoningEffortToReasoningTokens(_modelName, effort) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
case "medium":
|
|
99
|
-
// Defined as 8k by https://ai.google.dev/gemini-api/docs/openai#thinking
|
|
100
|
-
return 8 * 1024;
|
|
101
|
-
case "high":
|
|
102
|
-
return maxEffort;
|
|
103
|
-
default:
|
|
104
|
-
return undefined;
|
|
105
|
-
}
|
|
68
|
+
if (effort === void 0) return void 0;
|
|
69
|
+
const maxEffort = 24 * 1024;
|
|
70
|
+
switch (effort) {
|
|
71
|
+
case "low": return 1024;
|
|
72
|
+
case "medium": return 8 * 1024;
|
|
73
|
+
case "high": return maxEffort;
|
|
74
|
+
default: return void 0;
|
|
75
|
+
}
|
|
106
76
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
target.frequencyPenalty;
|
|
140
|
-
ret.stopSequences =
|
|
141
|
-
options?.stopSequences ?? params?.stopSequences ?? target.stopSequences;
|
|
142
|
-
ret.safetySettings =
|
|
143
|
-
options?.safetySettings ?? params?.safetySettings ?? target.safetySettings;
|
|
144
|
-
ret.logprobs = options?.logprobs ?? params?.logprobs ?? target.logprobs;
|
|
145
|
-
ret.topLogprobs =
|
|
146
|
-
options?.topLogprobs ?? params?.topLogprobs ?? target.topLogprobs;
|
|
147
|
-
ret.convertSystemMessageToHumanContent =
|
|
148
|
-
options?.convertSystemMessageToHumanContent ??
|
|
149
|
-
params?.convertSystemMessageToHumanContent ??
|
|
150
|
-
target?.convertSystemMessageToHumanContent;
|
|
151
|
-
ret.responseMimeType =
|
|
152
|
-
options?.responseMimeType ??
|
|
153
|
-
params?.responseMimeType ??
|
|
154
|
-
target?.responseMimeType;
|
|
155
|
-
ret.responseModalities =
|
|
156
|
-
options?.responseModalities ??
|
|
157
|
-
params?.responseModalities ??
|
|
158
|
-
target?.responseModalities;
|
|
159
|
-
ret.speechConfig = normalizeSpeechConfig(options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig);
|
|
160
|
-
ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;
|
|
161
|
-
const toolChoice = processToolChoice(options?.tool_choice, options?.allowed_function_names);
|
|
162
|
-
if (toolChoice) {
|
|
163
|
-
ret.tool_choice = toolChoice.tool_choice;
|
|
164
|
-
ret.allowed_function_names = toolChoice.allowed_function_names;
|
|
165
|
-
}
|
|
166
|
-
const tools = options?.tools;
|
|
167
|
-
if (tools) {
|
|
168
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
169
|
-
ret.tools = convertToGeminiTools(tools);
|
|
170
|
-
}
|
|
171
|
-
if (options?.cachedContent) {
|
|
172
|
-
ret.cachedContent = options.cachedContent;
|
|
173
|
-
}
|
|
174
|
-
ret.labels = options?.labels ?? params?.labels ?? target?.labels;
|
|
175
|
-
return ret;
|
|
77
|
+
function copyAIModelParamsInto(params, options, target) {
|
|
78
|
+
const ret = target || {};
|
|
79
|
+
const model = options?.model ?? params?.model ?? target.model;
|
|
80
|
+
ret.modelName = model ?? options?.modelName ?? params?.modelName ?? target.modelName;
|
|
81
|
+
ret.model = model;
|
|
82
|
+
ret.temperature = options?.temperature ?? params?.temperature ?? target.temperature;
|
|
83
|
+
ret.maxOutputTokens = options?.maxOutputTokens ?? params?.maxOutputTokens ?? target.maxOutputTokens;
|
|
84
|
+
ret.maxReasoningTokens = options?.maxReasoningTokens ?? params?.maxReasoningTokens ?? target?.maxReasoningTokens ?? options?.thinkingBudget ?? params?.thinkingBudget ?? target?.thinkingBudget ?? reasoningEffortToReasoningTokens(ret.modelName, params?.reasoningEffort) ?? reasoningEffortToReasoningTokens(ret.modelName, target?.reasoningEffort) ?? reasoningEffortToReasoningTokens(ret.modelName, options?.reasoningEffort);
|
|
85
|
+
ret.topP = options?.topP ?? params?.topP ?? target.topP;
|
|
86
|
+
ret.topK = options?.topK ?? params?.topK ?? target.topK;
|
|
87
|
+
ret.seed = options?.seed ?? params?.seed ?? target.seed;
|
|
88
|
+
ret.presencePenalty = options?.presencePenalty ?? params?.presencePenalty ?? target.presencePenalty;
|
|
89
|
+
ret.frequencyPenalty = options?.frequencyPenalty ?? params?.frequencyPenalty ?? target.frequencyPenalty;
|
|
90
|
+
ret.stopSequences = options?.stopSequences ?? params?.stopSequences ?? target.stopSequences;
|
|
91
|
+
ret.safetySettings = options?.safetySettings ?? params?.safetySettings ?? target.safetySettings;
|
|
92
|
+
ret.logprobs = options?.logprobs ?? params?.logprobs ?? target.logprobs;
|
|
93
|
+
ret.topLogprobs = options?.topLogprobs ?? params?.topLogprobs ?? target.topLogprobs;
|
|
94
|
+
ret.convertSystemMessageToHumanContent = options?.convertSystemMessageToHumanContent ?? params?.convertSystemMessageToHumanContent ?? target?.convertSystemMessageToHumanContent;
|
|
95
|
+
ret.responseMimeType = options?.responseMimeType ?? params?.responseMimeType ?? target?.responseMimeType;
|
|
96
|
+
ret.responseModalities = options?.responseModalities ?? params?.responseModalities ?? target?.responseModalities;
|
|
97
|
+
ret.speechConfig = normalizeSpeechConfig(options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig);
|
|
98
|
+
ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;
|
|
99
|
+
const toolChoice = processToolChoice(options?.tool_choice, options?.allowed_function_names);
|
|
100
|
+
if (toolChoice) {
|
|
101
|
+
ret.tool_choice = toolChoice.tool_choice;
|
|
102
|
+
ret.allowed_function_names = toolChoice.allowed_function_names;
|
|
103
|
+
}
|
|
104
|
+
const tools = options?.tools;
|
|
105
|
+
if (tools) ret.tools = convertToGeminiTools(tools);
|
|
106
|
+
if (options?.cachedContent) ret.cachedContent = options.cachedContent;
|
|
107
|
+
ret.labels = options?.labels ?? params?.labels ?? target?.labels;
|
|
108
|
+
return ret;
|
|
176
109
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
else if (isModelGemma(modelName)) {
|
|
185
|
-
return "gemma";
|
|
186
|
-
}
|
|
187
|
-
else if (isModelClaude(modelName)) {
|
|
188
|
-
return "claude";
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
110
|
+
function modelToFamily(modelName) {
|
|
111
|
+
if (!modelName) return null;
|
|
112
|
+
else if (isModelGemini(modelName)) return "gemini";
|
|
113
|
+
else if (isModelGemma(modelName)) return "gemma";
|
|
114
|
+
else if (isModelClaude(modelName)) return "claude";
|
|
115
|
+
else return null;
|
|
193
116
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
default:
|
|
204
|
-
return "unknown";
|
|
205
|
-
}
|
|
117
|
+
function modelToPublisher(modelName) {
|
|
118
|
+
const family = modelToFamily(modelName);
|
|
119
|
+
switch (family) {
|
|
120
|
+
case "gemini":
|
|
121
|
+
case "gemma":
|
|
122
|
+
case "palm": return "google";
|
|
123
|
+
case "claude": return "anthropic";
|
|
124
|
+
default: return "unknown";
|
|
125
|
+
}
|
|
206
126
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
default:
|
|
217
|
-
throw new Error(`Unable to verify model params: ${JSON.stringify(params)}`);
|
|
218
|
-
}
|
|
127
|
+
function validateModelParams(params) {
|
|
128
|
+
const testParams = params ?? {};
|
|
129
|
+
const model = testParams.model ?? testParams.modelName;
|
|
130
|
+
switch (modelToFamily(model)) {
|
|
131
|
+
case "gemini":
|
|
132
|
+
case "gemma": return validateGeminiParams(testParams);
|
|
133
|
+
case "claude": return validateClaudeParams(testParams);
|
|
134
|
+
default: throw new Error(`Unable to verify model params: ${JSON.stringify(params)}`);
|
|
135
|
+
}
|
|
219
136
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
137
|
+
function copyAndValidateModelParamsInto(params, target) {
|
|
138
|
+
copyAIModelParamsInto(params, void 0, target);
|
|
139
|
+
validateModelParams(target);
|
|
140
|
+
return target;
|
|
224
141
|
}
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { convertToGeminiTools, copyAIModelParams, copyAIModelParamsInto, copyAndValidateModelParamsInto, modelToFamily, modelToPublisher, validateModelParams };
|
|
145
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","names":["params: GoogleAIModelParams | undefined","options: GoogleAIBaseLanguageModelCallOptions | undefined","toolChoice: GoogleAIBaseLanguageModelCallOptions[\"tool_choice\"]","allowedFunctionNames: GoogleAIBaseLanguageModelCallOptions[\"allowed_function_names\"]","tool: GoogleAIToolType","tools: GoogleAIToolType[]","geminiTools: GeminiTool[]","funcs: GeminiFunctionDeclaration[]","_modelName?: string","effort?: string","target: GoogleAIModelParams","ret: GoogleAIModelRequestParams","modelName: string | undefined","testParams: GoogleAIModelParams"],"sources":["../../src/utils/common.ts"],"sourcesContent":["import { isOpenAITool } from \"@langchain/core/language_models/base\";\nimport { isLangChainTool } from \"@langchain/core/utils/function_calling\";\nimport {\n isModelGemini,\n isModelGemma,\n normalizeSpeechConfig,\n validateGeminiParams,\n} from \"./gemini.js\";\nimport {\n GeminiFunctionDeclaration,\n GeminiFunctionSchema,\n GeminiTool,\n GeminiToolAttributes,\n GoogleAIBaseLanguageModelCallOptions,\n GoogleAIModelParams,\n GoogleAIModelRequestParams,\n GoogleAIToolType,\n VertexModelFamily,\n} from \"../types.js\";\nimport {\n jsonSchemaToGeminiParameters,\n schemaToGeminiParameters,\n} from \"./zod_to_gemini_parameters.js\";\nimport { isModelClaude, validateClaudeParams } from \"./anthropic.js\";\n\nexport function copyAIModelParams(\n params: GoogleAIModelParams | undefined,\n options: GoogleAIBaseLanguageModelCallOptions | undefined\n): GoogleAIModelRequestParams {\n return copyAIModelParamsInto(params, options, {});\n}\n\nfunction processToolChoice(\n toolChoice: GoogleAIBaseLanguageModelCallOptions[\"tool_choice\"],\n allowedFunctionNames: GoogleAIBaseLanguageModelCallOptions[\"allowed_function_names\"]\n):\n | {\n tool_choice: \"any\" | \"auto\" | \"none\";\n allowed_function_names?: string[];\n }\n | undefined {\n if (!toolChoice) {\n if (allowedFunctionNames) {\n // Allowed func names is passed, return 'any' so it forces the model to use a tool.\n return {\n tool_choice: \"any\",\n allowed_function_names: allowedFunctionNames,\n };\n }\n return undefined;\n }\n\n if (toolChoice === \"any\" || toolChoice === \"auto\" || toolChoice === \"none\") {\n return {\n tool_choice: toolChoice,\n allowed_function_names: allowedFunctionNames,\n };\n }\n if (typeof toolChoice === \"string\") {\n // String representing the function name.\n // Return any to force the model to predict the specified function call.\n return {\n tool_choice: \"any\",\n allowed_function_names: [...(allowedFunctionNames ?? []), toolChoice],\n };\n }\n throw new Error(\"Object inputs for tool_choice not supported.\");\n}\n\nfunction isGeminiTool(tool: GoogleAIToolType): tool is GeminiTool {\n for (const toolAttribute of GeminiToolAttributes) {\n if (toolAttribute in tool) {\n return true;\n }\n }\n return false;\n}\n\nfunction isGeminiNonFunctionTool(tool: GoogleAIToolType): tool is GeminiTool {\n return isGeminiTool(tool) && !(\"functionDeclaration\" in tool);\n}\n\nexport function convertToGeminiTools(tools: GoogleAIToolType[]): GeminiTool[] {\n const geminiTools: GeminiTool[] = [];\n let functionDeclarationsIndex = -1;\n tools.forEach((tool) => {\n if (isGeminiNonFunctionTool(tool)) {\n geminiTools.push(tool);\n } else {\n if (functionDeclarationsIndex === -1) {\n geminiTools.push({\n functionDeclarations: [],\n });\n functionDeclarationsIndex = geminiTools.length - 1;\n }\n if (\n \"functionDeclarations\" in tool &&\n Array.isArray(tool.functionDeclarations)\n ) {\n const funcs: GeminiFunctionDeclaration[] = tool.functionDeclarations;\n geminiTools[functionDeclarationsIndex].functionDeclarations!.push(\n ...funcs\n );\n } else if (isLangChainTool(tool)) {\n const jsonSchema = schemaToGeminiParameters(tool.schema);\n geminiTools[functionDeclarationsIndex].functionDeclarations!.push({\n name: tool.name,\n description: tool.description ?? `A function available to call.`,\n parameters: jsonSchema as GeminiFunctionSchema,\n });\n } else if (isOpenAITool(tool)) {\n geminiTools[functionDeclarationsIndex].functionDeclarations!.push({\n name: tool.function.name,\n description:\n tool.function.description ?? `A function available to call.`,\n parameters: jsonSchemaToGeminiParameters(tool.function.parameters),\n });\n } else {\n throw new Error(`Received invalid tool: ${JSON.stringify(tool)}`);\n }\n }\n });\n return geminiTools;\n}\n\nfunction reasoningEffortToReasoningTokens(\n _modelName?: string,\n effort?: string\n): number | undefined {\n if (effort === undefined) {\n return undefined;\n }\n const maxEffort = 24 * 1024; // Max for Gemini 2.5 Flash\n switch (effort) {\n case \"low\":\n // Defined as 1k by https://ai.google.dev/gemini-api/docs/openai#thinking\n return 1024;\n case \"medium\":\n // Defined as 8k by https://ai.google.dev/gemini-api/docs/openai#thinking\n return 8 * 1024;\n case \"high\":\n return maxEffort;\n default:\n return undefined;\n }\n}\n\nexport function copyAIModelParamsInto(\n params: GoogleAIModelParams | undefined,\n options: GoogleAIBaseLanguageModelCallOptions | undefined,\n target: GoogleAIModelParams\n): GoogleAIModelRequestParams {\n const ret: GoogleAIModelRequestParams = target || {};\n const model = options?.model ?? params?.model ?? target.model;\n ret.modelName =\n model ?? options?.modelName ?? params?.modelName ?? target.modelName;\n ret.model = model;\n ret.temperature =\n options?.temperature ?? params?.temperature ?? target.temperature;\n ret.maxOutputTokens =\n options?.maxOutputTokens ??\n params?.maxOutputTokens ??\n target.maxOutputTokens;\n ret.maxReasoningTokens =\n options?.maxReasoningTokens ??\n params?.maxReasoningTokens ??\n target?.maxReasoningTokens ??\n options?.thinkingBudget ??\n params?.thinkingBudget ??\n target?.thinkingBudget ??\n reasoningEffortToReasoningTokens(ret.modelName, params?.reasoningEffort) ??\n reasoningEffortToReasoningTokens(ret.modelName, target?.reasoningEffort) ??\n reasoningEffortToReasoningTokens(ret.modelName, options?.reasoningEffort);\n ret.topP = options?.topP ?? params?.topP ?? target.topP;\n ret.topK = options?.topK ?? params?.topK ?? target.topK;\n ret.seed = options?.seed ?? params?.seed ?? target.seed;\n ret.presencePenalty =\n options?.presencePenalty ??\n params?.presencePenalty ??\n target.presencePenalty;\n ret.frequencyPenalty =\n options?.frequencyPenalty ??\n params?.frequencyPenalty ??\n target.frequencyPenalty;\n ret.stopSequences =\n options?.stopSequences ?? params?.stopSequences ?? target.stopSequences;\n ret.safetySettings =\n options?.safetySettings ?? params?.safetySettings ?? target.safetySettings;\n ret.logprobs = options?.logprobs ?? params?.logprobs ?? target.logprobs;\n ret.topLogprobs =\n options?.topLogprobs ?? params?.topLogprobs ?? target.topLogprobs;\n ret.convertSystemMessageToHumanContent =\n options?.convertSystemMessageToHumanContent ??\n params?.convertSystemMessageToHumanContent ??\n target?.convertSystemMessageToHumanContent;\n ret.responseMimeType =\n options?.responseMimeType ??\n params?.responseMimeType ??\n target?.responseMimeType;\n ret.responseModalities =\n options?.responseModalities ??\n params?.responseModalities ??\n target?.responseModalities;\n ret.speechConfig = normalizeSpeechConfig(\n options?.speechConfig ?? params?.speechConfig ?? target?.speechConfig\n );\n ret.streaming = options?.streaming ?? params?.streaming ?? target?.streaming;\n const toolChoice = processToolChoice(\n options?.tool_choice,\n options?.allowed_function_names\n );\n if (toolChoice) {\n ret.tool_choice = toolChoice.tool_choice;\n ret.allowed_function_names = toolChoice.allowed_function_names;\n }\n\n const tools = options?.tools;\n if (tools) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ret.tools = convertToGeminiTools(tools as Record<string, any>[]);\n }\n\n if (options?.cachedContent) {\n ret.cachedContent = options.cachedContent;\n }\n\n ret.labels = options?.labels ?? params?.labels ?? target?.labels;\n\n return ret;\n}\n\nexport function modelToFamily(\n modelName: string | undefined\n): VertexModelFamily {\n if (!modelName) {\n return null;\n } else if (isModelGemini(modelName)) {\n return \"gemini\";\n } else if (isModelGemma(modelName)) {\n return \"gemma\";\n } else if (isModelClaude(modelName)) {\n return \"claude\";\n } else {\n return null;\n }\n}\n\nexport function modelToPublisher(modelName: string | undefined): string {\n const family = modelToFamily(modelName);\n switch (family) {\n case \"gemini\":\n case \"gemma\":\n case \"palm\":\n return \"google\";\n\n case \"claude\":\n return \"anthropic\";\n\n default:\n return \"unknown\";\n }\n}\n\nexport function validateModelParams(\n params: GoogleAIModelParams | undefined\n): void {\n const testParams: GoogleAIModelParams = params ?? {};\n const model = testParams.model ?? testParams.modelName;\n switch (modelToFamily(model)) {\n case \"gemini\":\n case \"gemma\": // TODO: Are we sure?\n return validateGeminiParams(testParams);\n\n case \"claude\":\n return validateClaudeParams(testParams);\n\n default:\n throw new Error(\n `Unable to verify model params: ${JSON.stringify(params)}`\n );\n }\n}\n\nexport function copyAndValidateModelParamsInto(\n params: GoogleAIModelParams | undefined,\n target: GoogleAIModelParams\n): GoogleAIModelParams {\n copyAIModelParamsInto(params, undefined, target);\n validateModelParams(target);\n return target;\n}\n"],"mappings":"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"}
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.failedAttemptHandler = failedAttemptHandler;
|
|
4
|
-
exports.ensureParams = ensureParams;
|
|
1
|
+
|
|
2
|
+
//#region src/utils/failed_handler.ts
|
|
5
3
|
const STATUS_NO_RETRY = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
400,
|
|
5
|
+
401,
|
|
6
|
+
402,
|
|
7
|
+
403,
|
|
8
|
+
404,
|
|
9
|
+
405,
|
|
10
|
+
406,
|
|
11
|
+
407,
|
|
12
|
+
408,
|
|
13
|
+
409
|
|
16
14
|
];
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
15
|
function failedAttemptHandler(error) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// What errors shouldn't be retried?
|
|
26
|
-
if (STATUS_NO_RETRY.includes(+status)) {
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
16
|
+
const status = error?.response?.status ?? 0;
|
|
17
|
+
if (status === 0) {
|
|
18
|
+
console.error("failedAttemptHandler", error);
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
if (STATUS_NO_RETRY.includes(+status)) throw error;
|
|
29
22
|
}
|
|
30
23
|
function ensureParams(params) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
const base = params ?? {};
|
|
25
|
+
return {
|
|
26
|
+
onFailedAttempt: failedAttemptHandler,
|
|
27
|
+
...base
|
|
28
|
+
};
|
|
36
29
|
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.ensureParams = ensureParams;
|
|
33
|
+
exports.failedAttemptHandler = failedAttemptHandler;
|
|
34
|
+
//# sourceMappingURL=failed_handler.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failed_handler.cjs","names":["error: any","params?: AsyncCallerParams","base: AsyncCallerParams"],"sources":["../../src/utils/failed_handler.ts"],"sourcesContent":["import { AsyncCallerParams } from \"@langchain/core/utils/async_caller\";\n\nconst STATUS_NO_RETRY = [\n 400,\n 401,\n 402,\n 403,\n 404,\n 405,\n 406,\n 407,\n 408,\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function failedAttemptHandler(error: any) {\n const status = error?.response?.status ?? 0;\n\n if (status === 0) {\n // What is this?\n console.error(\"failedAttemptHandler\", error);\n throw error;\n }\n\n // What errors shouldn't be retried?\n if (STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n}\n\nexport function ensureParams(params?: AsyncCallerParams): AsyncCallerParams {\n const base: AsyncCallerParams = params ?? {};\n return {\n onFailedAttempt: failedAttemptHandler,\n ...base,\n };\n}\n"],"mappings":";;AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAGD,SAAgB,qBAAqBA,OAAY;CAC/C,MAAM,SAAS,OAAO,UAAU,UAAU;AAE1C,KAAI,WAAW,GAAG;EAEhB,QAAQ,MAAM,wBAAwB,MAAM;AAC5C,QAAM;CACP;AAGD,KAAI,gBAAgB,SAAS,CAAC,OAAO,CACnC,OAAM;AAET;AAED,SAAgB,aAAaC,QAA+C;CAC1E,MAAMC,OAA0B,UAAU,CAAE;AAC5C,QAAO;EACL,iBAAiB;EACjB,GAAG;CACJ;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AsyncCallerParams } from "@langchain/core/utils/async_caller";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/failed_handler.d.ts
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
declare function failedAttemptHandler(error: any): void;
|
|
6
|
+
declare function ensureParams(params?: AsyncCallerParams): AsyncCallerParams;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ensureParams, failedAttemptHandler };
|
|
9
|
+
//# sourceMappingURL=failed_handler.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failed_handler.d.cts","names":["AsyncCallerParams","failedAttemptHandler","ensureParams"],"sources":["../../src/utils/failed_handler.d.ts"],"sourcesContent":["import { AsyncCallerParams } from \"@langchain/core/utils/async_caller\";\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare function failedAttemptHandler(error: any): void;\nexport declare function ensureParams(params?: AsyncCallerParams): AsyncCallerParams;\n"],"mappings":";;;;iBAEwBC,oBAAAA;AAAAA,iBACAC,YAAAA,CADoB,MAAA,CAAA,EACEF,iBADF,CAAA,EACsBA,iBADtB"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import { AsyncCallerParams } from "@langchain/core/utils/async_caller";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
|
|
3
|
+
//#region src/utils/failed_handler.d.ts
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
+
declare function failedAttemptHandler(error: any): void;
|
|
6
|
+
declare function ensureParams(params?: AsyncCallerParams): AsyncCallerParams;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ensureParams, failedAttemptHandler };
|
|
9
|
+
//# sourceMappingURL=failed_handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failed_handler.d.ts","names":["AsyncCallerParams","failedAttemptHandler","ensureParams"],"sources":["../../src/utils/failed_handler.d.ts"],"sourcesContent":["import { AsyncCallerParams } from \"@langchain/core/utils/async_caller\";\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport declare function failedAttemptHandler(error: any): void;\nexport declare function ensureParams(params?: AsyncCallerParams): AsyncCallerParams;\n"],"mappings":";;;;iBAEwBC,oBAAAA;AAAAA,iBACAC,YAAAA,CADoB,MAAA,CAAA,EACEF,iBADF,CAAA,EACsBA,iBADtB"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
+
//#region src/utils/failed_handler.ts
|
|
1
2
|
const STATUS_NO_RETRY = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
400,
|
|
4
|
+
401,
|
|
5
|
+
402,
|
|
6
|
+
403,
|
|
7
|
+
404,
|
|
8
|
+
405,
|
|
9
|
+
406,
|
|
10
|
+
407,
|
|
11
|
+
408,
|
|
12
|
+
409
|
|
12
13
|
];
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
// What errors shouldn't be retried?
|
|
22
|
-
if (STATUS_NO_RETRY.includes(+status)) {
|
|
23
|
-
throw error;
|
|
24
|
-
}
|
|
14
|
+
function failedAttemptHandler(error) {
|
|
15
|
+
const status = error?.response?.status ?? 0;
|
|
16
|
+
if (status === 0) {
|
|
17
|
+
console.error("failedAttemptHandler", error);
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
if (STATUS_NO_RETRY.includes(+status)) throw error;
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
function ensureParams(params) {
|
|
23
|
+
const base = params ?? {};
|
|
24
|
+
return {
|
|
25
|
+
onFailedAttempt: failedAttemptHandler,
|
|
26
|
+
...base
|
|
27
|
+
};
|
|
32
28
|
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { ensureParams, failedAttemptHandler };
|
|
32
|
+
//# sourceMappingURL=failed_handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"failed_handler.js","names":["error: any","params?: AsyncCallerParams","base: AsyncCallerParams"],"sources":["../../src/utils/failed_handler.ts"],"sourcesContent":["import { AsyncCallerParams } from \"@langchain/core/utils/async_caller\";\n\nconst STATUS_NO_RETRY = [\n 400,\n 401,\n 402,\n 403,\n 404,\n 405,\n 406,\n 407,\n 408,\n 409, // Conflict\n];\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function failedAttemptHandler(error: any) {\n const status = error?.response?.status ?? 0;\n\n if (status === 0) {\n // What is this?\n console.error(\"failedAttemptHandler\", error);\n throw error;\n }\n\n // What errors shouldn't be retried?\n if (STATUS_NO_RETRY.includes(+status)) {\n throw error;\n }\n}\n\nexport function ensureParams(params?: AsyncCallerParams): AsyncCallerParams {\n const base: AsyncCallerParams = params ?? {};\n return {\n onFailedAttempt: failedAttemptHandler,\n ...base,\n };\n}\n"],"mappings":";AAEA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AAGD,SAAgB,qBAAqBA,OAAY;CAC/C,MAAM,SAAS,OAAO,UAAU,UAAU;AAE1C,KAAI,WAAW,GAAG;EAEhB,QAAQ,MAAM,wBAAwB,MAAM;AAC5C,QAAM;CACP;AAGD,KAAI,gBAAgB,SAAS,CAAC,OAAO,CACnC,OAAM;AAET;AAED,SAAgB,aAAaC,QAA+C;CAC1E,MAAMC,OAA0B,UAAU,CAAE;AAC5C,QAAO;EACL,iBAAiB;EACjB,GAAG;CACJ;AACF"}
|