@langchain/google-common 0.2.18 → 1.0.0

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.
Files changed (169) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +6 -6
  3. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  4. package/dist/auth.cjs +82 -116
  5. package/dist/auth.cjs.map +1 -0
  6. package/dist/auth.d.cts +46 -0
  7. package/dist/auth.d.cts.map +1 -0
  8. package/dist/auth.d.ts +41 -36
  9. package/dist/auth.d.ts.map +1 -0
  10. package/dist/auth.js +80 -110
  11. package/dist/auth.js.map +1 -0
  12. package/dist/chat_models.cjs +251 -466
  13. package/dist/chat_models.cjs.map +1 -0
  14. package/dist/chat_models.d.cts +98 -0
  15. package/dist/chat_models.d.cts.map +1 -0
  16. package/dist/chat_models.d.ts +87 -73
  17. package/dist/chat_models.d.ts.map +1 -0
  18. package/dist/chat_models.js +245 -457
  19. package/dist/chat_models.js.map +1 -0
  20. package/dist/connection.cjs +321 -466
  21. package/dist/connection.cjs.map +1 -0
  22. package/dist/connection.d.cts +109 -0
  23. package/dist/connection.d.cts.map +1 -0
  24. package/dist/connection.d.ts +98 -91
  25. package/dist/connection.d.ts.map +1 -0
  26. package/dist/connection.js +317 -459
  27. package/dist/connection.js.map +1 -0
  28. package/dist/embeddings.cjs +135 -186
  29. package/dist/embeddings.cjs.map +1 -0
  30. package/dist/embeddings.d.cts +44 -0
  31. package/dist/embeddings.d.cts.map +1 -0
  32. package/dist/embeddings.d.ts +38 -32
  33. package/dist/embeddings.d.ts.map +1 -0
  34. package/dist/embeddings.js +133 -181
  35. package/dist/embeddings.js.map +1 -0
  36. package/dist/experimental/media.cjs +380 -482
  37. package/dist/experimental/media.cjs.map +1 -0
  38. package/dist/experimental/media.d.cts +198 -0
  39. package/dist/experimental/media.d.cts.map +1 -0
  40. package/dist/experimental/media.d.ts +190 -202
  41. package/dist/experimental/media.d.ts.map +1 -0
  42. package/dist/experimental/media.js +369 -468
  43. package/dist/experimental/media.js.map +1 -0
  44. package/dist/experimental/utils/media_core.cjs +403 -517
  45. package/dist/experimental/utils/media_core.cjs.map +1 -0
  46. package/dist/experimental/utils/media_core.d.cts +215 -0
  47. package/dist/experimental/utils/media_core.d.cts.map +1 -0
  48. package/dist/experimental/utils/media_core.d.ts +171 -165
  49. package/dist/experimental/utils/media_core.d.ts.map +1 -0
  50. package/dist/experimental/utils/media_core.js +395 -506
  51. package/dist/experimental/utils/media_core.js.map +1 -0
  52. package/dist/index.cjs +58 -27
  53. package/dist/index.d.cts +13 -0
  54. package/dist/index.d.ts +13 -11
  55. package/dist/index.js +13 -11
  56. package/dist/llms.cjs +157 -244
  57. package/dist/llms.cjs.map +1 -0
  58. package/dist/llms.d.cts +72 -0
  59. package/dist/llms.d.cts.map +1 -0
  60. package/dist/llms.d.ts +64 -54
  61. package/dist/llms.d.ts.map +1 -0
  62. package/dist/llms.js +154 -238
  63. package/dist/llms.js.map +1 -0
  64. package/dist/output_parsers.cjs +148 -173
  65. package/dist/output_parsers.cjs.map +1 -0
  66. package/dist/output_parsers.d.cts +53 -0
  67. package/dist/output_parsers.d.cts.map +1 -0
  68. package/dist/output_parsers.d.ts +46 -42
  69. package/dist/output_parsers.d.ts.map +1 -0
  70. package/dist/output_parsers.js +146 -168
  71. package/dist/output_parsers.js.map +1 -0
  72. package/dist/types-anthropic.d.cts +229 -0
  73. package/dist/types-anthropic.d.cts.map +1 -0
  74. package/dist/types-anthropic.d.ts +221 -215
  75. package/dist/types-anthropic.d.ts.map +1 -0
  76. package/dist/types.cjs +51 -62
  77. package/dist/types.cjs.map +1 -0
  78. package/dist/types.d.cts +748 -0
  79. package/dist/types.d.cts.map +1 -0
  80. package/dist/types.d.ts +669 -656
  81. package/dist/types.d.ts.map +1 -0
  82. package/dist/types.js +46 -45
  83. package/dist/types.js.map +1 -0
  84. package/dist/utils/anthropic.cjs +598 -821
  85. package/dist/utils/anthropic.cjs.map +1 -0
  86. package/dist/utils/anthropic.js +597 -818
  87. package/dist/utils/anthropic.js.map +1 -0
  88. package/dist/utils/common.cjs +130 -211
  89. package/dist/utils/common.cjs.map +1 -0
  90. package/dist/utils/common.d.cts +13 -0
  91. package/dist/utils/common.d.cts.map +1 -0
  92. package/dist/utils/common.d.ts +12 -7
  93. package/dist/utils/common.d.ts.map +1 -0
  94. package/dist/utils/common.js +128 -207
  95. package/dist/utils/common.js.map +1 -0
  96. package/dist/utils/failed_handler.cjs +28 -30
  97. package/dist/utils/failed_handler.cjs.map +1 -0
  98. package/dist/utils/failed_handler.d.cts +9 -0
  99. package/dist/utils/failed_handler.d.cts.map +1 -0
  100. package/dist/utils/failed_handler.d.ts +8 -2
  101. package/dist/utils/failed_handler.d.ts.map +1 -0
  102. package/dist/utils/failed_handler.js +28 -28
  103. package/dist/utils/failed_handler.js.map +1 -0
  104. package/dist/utils/gemini.cjs +1020 -1488
  105. package/dist/utils/gemini.cjs.map +1 -0
  106. package/dist/utils/gemini.d.cts +51 -0
  107. package/dist/utils/gemini.d.cts.map +1 -0
  108. package/dist/utils/gemini.d.ts +51 -48
  109. package/dist/utils/gemini.d.ts.map +1 -0
  110. package/dist/utils/gemini.js +1015 -1479
  111. package/dist/utils/gemini.js.map +1 -0
  112. package/dist/utils/index.cjs +38 -23
  113. package/dist/utils/index.d.cts +8 -0
  114. package/dist/utils/index.d.ts +8 -7
  115. package/dist/utils/index.js +8 -7
  116. package/dist/utils/palm.d.cts +11 -0
  117. package/dist/utils/palm.d.cts.map +1 -0
  118. package/dist/utils/palm.d.ts +9 -4
  119. package/dist/utils/palm.d.ts.map +1 -0
  120. package/dist/utils/safety.cjs +13 -22
  121. package/dist/utils/safety.cjs.map +1 -0
  122. package/dist/utils/safety.d.cts +12 -0
  123. package/dist/utils/safety.d.cts.map +1 -0
  124. package/dist/utils/safety.d.ts +10 -4
  125. package/dist/utils/safety.d.ts.map +1 -0
  126. package/dist/utils/safety.js +13 -19
  127. package/dist/utils/safety.js.map +1 -0
  128. package/dist/utils/stream.cjs +296 -475
  129. package/dist/utils/stream.cjs.map +1 -0
  130. package/dist/utils/stream.d.cts +165 -0
  131. package/dist/utils/stream.d.cts.map +1 -0
  132. package/dist/utils/stream.d.ts +156 -131
  133. package/dist/utils/stream.d.ts.map +1 -0
  134. package/dist/utils/stream.js +293 -469
  135. package/dist/utils/stream.js.map +1 -0
  136. package/dist/utils/zod_to_gemini_parameters.cjs +43 -81
  137. package/dist/utils/zod_to_gemini_parameters.cjs.map +1 -0
  138. package/dist/utils/zod_to_gemini_parameters.d.cts +22 -0
  139. package/dist/utils/zod_to_gemini_parameters.d.cts.map +1 -0
  140. package/dist/utils/zod_to_gemini_parameters.d.ts +21 -6
  141. package/dist/utils/zod_to_gemini_parameters.d.ts.map +1 -0
  142. package/dist/utils/zod_to_gemini_parameters.js +40 -76
  143. package/dist/utils/zod_to_gemini_parameters.js.map +1 -0
  144. package/package.json +69 -85
  145. package/dist/types-anthropic.cjs +0 -2
  146. package/dist/types-anthropic.js +0 -1
  147. package/dist/utils/anthropic.d.ts +0 -4
  148. package/dist/utils/palm.cjs +0 -2
  149. package/dist/utils/palm.js +0 -1
  150. package/experimental/media.cjs +0 -1
  151. package/experimental/media.d.cts +0 -1
  152. package/experimental/media.d.ts +0 -1
  153. package/experimental/media.js +0 -1
  154. package/experimental/utils/media_core.cjs +0 -1
  155. package/experimental/utils/media_core.d.cts +0 -1
  156. package/experimental/utils/media_core.d.ts +0 -1
  157. package/experimental/utils/media_core.js +0 -1
  158. package/index.cjs +0 -1
  159. package/index.d.cts +0 -1
  160. package/index.d.ts +0 -1
  161. package/index.js +0 -1
  162. package/types.cjs +0 -1
  163. package/types.d.cts +0 -1
  164. package/types.d.ts +0 -1
  165. package/types.js +0 -1
  166. package/utils.cjs +0 -1
  167. package/utils.d.cts +0 -1
  168. package/utils.d.ts +0 -1
  169. package/utils.js +0 -1
@@ -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
- import { isModelGemini, isModelGemma, normalizeSpeechConfig, validateGeminiParams, } from "./gemini.js";
4
- import { GeminiToolAttributes, } from "../types.js";
5
- import { jsonSchemaToGeminiParameters, schemaToGeminiParameters, } from "./zod_to_gemini_parameters.js";
6
- import { isModelClaude, validateClaudeParams } from "./anthropic.js";
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
- if (!toolChoice) {
12
- if (allowedFunctionNames) {
13
- // Allowed func names is passed, return 'any' so it forces the model to use a tool.
14
- return {
15
- tool_choice: "any",
16
- allowed_function_names: allowedFunctionNames,
17
- };
18
- }
19
- return undefined;
20
- }
21
- if (toolChoice === "any" || toolChoice === "auto" || toolChoice === "none") {
22
- return {
23
- tool_choice: toolChoice,
24
- allowed_function_names: allowedFunctionNames,
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
- for (const toolAttribute of GeminiToolAttributes) {
39
- if (toolAttribute in tool) {
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
- return isGeminiTool(tool) && !("functionDeclaration" in tool);
35
+ return isGeminiTool(tool) && !("functionDeclaration" in tool);
47
36
  }
48
- export function convertToGeminiTools(tools) {
49
- const geminiTools = [];
50
- let functionDeclarationsIndex = -1;
51
- tools.forEach((tool) => {
52
- if (isGeminiNonFunctionTool(tool)) {
53
- geminiTools.push(tool);
54
- }
55
- else {
56
- if (functionDeclarationsIndex === -1) {
57
- geminiTools.push({
58
- functionDeclarations: [],
59
- });
60
- functionDeclarationsIndex = geminiTools.length - 1;
61
- }
62
- if ("functionDeclarations" in tool &&
63
- Array.isArray(tool.functionDeclarations)) {
64
- const funcs = tool.functionDeclarations;
65
- geminiTools[functionDeclarationsIndex].functionDeclarations.push(...funcs);
66
- }
67
- else if (isLangChainTool(tool)) {
68
- const jsonSchema = schemaToGeminiParameters(tool.schema);
69
- geminiTools[functionDeclarationsIndex].functionDeclarations.push({
70
- name: tool.name,
71
- description: tool.description ?? `A function available to call.`,
72
- parameters: jsonSchema,
73
- });
74
- }
75
- else if (isOpenAITool(tool)) {
76
- geminiTools[functionDeclarationsIndex].functionDeclarations.push({
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
- if (effort === undefined) {
91
- return undefined;
92
- }
93
- const maxEffort = 24 * 1024; // Max for Gemini 2.5 Flash
94
- switch (effort) {
95
- case "low":
96
- // Defined as 1k by https://ai.google.dev/gemini-api/docs/openai#thinking
97
- return 1024;
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
- export function copyAIModelParamsInto(params, options, target) {
108
- const ret = target || {};
109
- const model = options?.model ?? params?.model ?? target.model;
110
- ret.modelName =
111
- model ?? options?.modelName ?? params?.modelName ?? target.modelName;
112
- ret.model = model;
113
- ret.temperature =
114
- options?.temperature ?? params?.temperature ?? target.temperature;
115
- ret.maxOutputTokens =
116
- options?.maxOutputTokens ??
117
- params?.maxOutputTokens ??
118
- target.maxOutputTokens;
119
- ret.maxReasoningTokens =
120
- options?.maxReasoningTokens ??
121
- params?.maxReasoningTokens ??
122
- target?.maxReasoningTokens ??
123
- options?.thinkingBudget ??
124
- params?.thinkingBudget ??
125
- target?.thinkingBudget ??
126
- reasoningEffortToReasoningTokens(ret.modelName, params?.reasoningEffort) ??
127
- reasoningEffortToReasoningTokens(ret.modelName, target?.reasoningEffort) ??
128
- reasoningEffortToReasoningTokens(ret.modelName, options?.reasoningEffort);
129
- ret.topP = options?.topP ?? params?.topP ?? target.topP;
130
- ret.topK = options?.topK ?? params?.topK ?? target.topK;
131
- ret.seed = options?.seed ?? params?.seed ?? target.seed;
132
- ret.presencePenalty =
133
- options?.presencePenalty ??
134
- params?.presencePenalty ??
135
- target.presencePenalty;
136
- ret.frequencyPenalty =
137
- options?.frequencyPenalty ??
138
- params?.frequencyPenalty ??
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
- export function modelToFamily(modelName) {
178
- if (!modelName) {
179
- return null;
180
- }
181
- else if (isModelGemini(modelName)) {
182
- return "gemini";
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
- export function modelToPublisher(modelName) {
195
- const family = modelToFamily(modelName);
196
- switch (family) {
197
- case "gemini":
198
- case "gemma":
199
- case "palm":
200
- return "google";
201
- case "claude":
202
- return "anthropic";
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
- export function validateModelParams(params) {
208
- const testParams = params ?? {};
209
- const model = testParams.model ?? testParams.modelName;
210
- switch (modelToFamily(model)) {
211
- case "gemini":
212
- case "gemma": // TODO: Are we sure?
213
- return validateGeminiParams(testParams);
214
- case "claude":
215
- return validateClaudeParams(testParams);
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
- export function copyAndValidateModelParamsInto(params, target) {
221
- copyAIModelParamsInto(params, undefined, target);
222
- validateModelParams(target);
223
- return target;
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
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.failedAttemptHandler = failedAttemptHandler;
4
- exports.ensureParams = ensureParams;
1
+
2
+ //#region src/utils/failed_handler.ts
5
3
  const STATUS_NO_RETRY = [
6
- 400,
7
- 401,
8
- 402,
9
- 403,
10
- 404,
11
- 405,
12
- 406,
13
- 407,
14
- 408,
15
- 409, // Conflict
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
- const status = error?.response?.status ?? 0;
20
- if (status === 0) {
21
- // What is this?
22
- console.error("failedAttemptHandler", error);
23
- throw error;
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
- const base = params ?? {};
32
- return {
33
- onFailedAttempt: failedAttemptHandler,
34
- ...base,
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
- export declare function failedAttemptHandler(error: any): void;
3
- export declare function ensureParams(params?: AsyncCallerParams): AsyncCallerParams;
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
- 400,
3
- 401,
4
- 402,
5
- 403,
6
- 404,
7
- 405,
8
- 406,
9
- 407,
10
- 408,
11
- 409, // Conflict
3
+ 400,
4
+ 401,
5
+ 402,
6
+ 403,
7
+ 404,
8
+ 405,
9
+ 406,
10
+ 407,
11
+ 408,
12
+ 409
12
13
  ];
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- export function failedAttemptHandler(error) {
15
- const status = error?.response?.status ?? 0;
16
- if (status === 0) {
17
- // What is this?
18
- console.error("failedAttemptHandler", error);
19
- throw error;
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
- export function ensureParams(params) {
27
- const base = params ?? {};
28
- return {
29
- onFailedAttempt: failedAttemptHandler,
30
- ...base,
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"}