@langchain/google 0.1.1-dev-1771365493298 → 0.1.2
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 +34 -0
- package/dist/chat_models/profiles.cjs +93 -93
- package/dist/chat_models/profiles.cjs.map +1 -1
- package/dist/chat_models/profiles.js +93 -93
- package/dist/chat_models/profiles.js.map +1 -1
- package/dist/converters/params.cjs +2 -0
- package/dist/converters/params.cjs.map +1 -1
- package/dist/converters/params.js +2 -0
- package/dist/converters/params.js.map +1 -1
- package/dist/utils/errors.cjs +32 -26
- package/dist/utils/errors.cjs.map +1 -1
- package/dist/utils/errors.js +32 -26
- package/dist/utils/errors.js.map +1 -1
- package/package.json +5 -5
package/dist/utils/errors.cjs
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
const require_misc = require('./misc.cjs');
|
|
2
|
+
let _langchain_core_errors = require("@langchain/core/errors");
|
|
2
3
|
|
|
3
4
|
//#region src/utils/errors.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
5
|
+
const ns = _langchain_core_errors.ns.sub("google");
|
|
6
|
+
/**
|
|
7
|
+
* Base error class for all Google provider errors.
|
|
8
|
+
*
|
|
9
|
+
* All Google-specific error classes extend this class. Use
|
|
10
|
+
* `GoogleError.isInstance(obj)` to check if an object is any
|
|
11
|
+
* Google provider error.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* try {
|
|
16
|
+
* await model.invoke("hello");
|
|
17
|
+
* } catch (error) {
|
|
18
|
+
* if (GoogleError.isInstance(error)) {
|
|
19
|
+
* console.log("Got a Google error:", error.message);
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var GoogleError = class extends ns.brand(_langchain_core_errors.LangChainError) {
|
|
25
|
+
name = "GoogleError";
|
|
26
|
+
};
|
|
17
27
|
/**
|
|
18
28
|
* Error thrown when there is a configuration issue with the Google provider.
|
|
19
29
|
*
|
|
@@ -31,7 +41,7 @@ function GoogleError(marker) {
|
|
|
31
41
|
* }
|
|
32
42
|
* ```
|
|
33
43
|
*/
|
|
34
|
-
var ConfigurationError = class extends GoogleError
|
|
44
|
+
var ConfigurationError = class extends ns.brand(GoogleError, "configuration") {
|
|
35
45
|
name = "ConfigurationError";
|
|
36
46
|
};
|
|
37
47
|
/**
|
|
@@ -53,11 +63,7 @@ var ConfigurationError = class extends GoogleError("configuration") {
|
|
|
53
63
|
* }
|
|
54
64
|
* ```
|
|
55
65
|
*/
|
|
56
|
-
var PromptBlockedError = class PromptBlockedError extends GoogleError
|
|
57
|
-
/**
|
|
58
|
-
* The name of the error class.
|
|
59
|
-
* @readonly
|
|
60
|
-
*/
|
|
66
|
+
var PromptBlockedError = class PromptBlockedError extends ns.brand(GoogleError, "prompt-blocked") {
|
|
61
67
|
name = "PromptBlockedError";
|
|
62
68
|
/**
|
|
63
69
|
* The reason why the prompt was blocked.
|
|
@@ -138,7 +144,7 @@ var PromptBlockedError = class PromptBlockedError extends GoogleError("prompt-bl
|
|
|
138
144
|
* }
|
|
139
145
|
* ```
|
|
140
146
|
*/
|
|
141
|
-
var AuthError = class AuthError extends GoogleError
|
|
147
|
+
var AuthError = class AuthError extends ns.brand(GoogleError, "auth") {
|
|
142
148
|
name = "AuthError";
|
|
143
149
|
/**
|
|
144
150
|
* The HTTP status code of the failed response.
|
|
@@ -256,7 +262,7 @@ const RETRYABLE_STATUS_CODES = [
|
|
|
256
262
|
* }
|
|
257
263
|
* ```
|
|
258
264
|
*/
|
|
259
|
-
var RequestError = class RequestError extends GoogleError
|
|
265
|
+
var RequestError = class RequestError extends ns.brand(GoogleError, "request") {
|
|
260
266
|
name = "RequestError";
|
|
261
267
|
/**
|
|
262
268
|
* The URL of the failed request.
|
|
@@ -391,7 +397,7 @@ var RequestError = class RequestError extends GoogleError("request") {
|
|
|
391
397
|
* }
|
|
392
398
|
* ```
|
|
393
399
|
*/
|
|
394
|
-
var NoCandidatesError = class extends GoogleError
|
|
400
|
+
var NoCandidatesError = class extends ns.brand(GoogleError, "no-candidates") {
|
|
395
401
|
name = "NoCandidatesError";
|
|
396
402
|
constructor() {
|
|
397
403
|
super("No candidates returned from API. This may indicate the prompt was blocked or an error occurred.");
|
|
@@ -419,7 +425,7 @@ var NoCandidatesError = class extends GoogleError("no-candidates") {
|
|
|
419
425
|
* }
|
|
420
426
|
* ```
|
|
421
427
|
*/
|
|
422
|
-
var InvalidToolError = class extends GoogleError
|
|
428
|
+
var InvalidToolError = class extends ns.brand(GoogleError, "invalid-tool") {
|
|
423
429
|
name = "InvalidToolError";
|
|
424
430
|
/**
|
|
425
431
|
* The invalid tool that was provided.
|
|
@@ -454,7 +460,7 @@ var InvalidToolError = class extends GoogleError("invalid-tool") {
|
|
|
454
460
|
* }
|
|
455
461
|
* ```
|
|
456
462
|
*/
|
|
457
|
-
var ToolCallNotFoundError = class extends GoogleError
|
|
463
|
+
var ToolCallNotFoundError = class extends ns.brand(GoogleError, "tool-call-not-found") {
|
|
458
464
|
name = "ToolCallNotFoundError";
|
|
459
465
|
/**
|
|
460
466
|
* The tool call ID that could not be found in the conversation history.
|
|
@@ -490,7 +496,7 @@ var ToolCallNotFoundError = class extends GoogleError("tool-call-not-found") {
|
|
|
490
496
|
* }
|
|
491
497
|
* ```
|
|
492
498
|
*/
|
|
493
|
-
var MalformedOutputError = class extends GoogleError
|
|
499
|
+
var MalformedOutputError = class extends ns.brand(GoogleError, "malformed-output") {
|
|
494
500
|
name = "MalformedOutputError";
|
|
495
501
|
/**
|
|
496
502
|
* Optional cause of the parsing error.
|
|
@@ -524,7 +530,7 @@ var MalformedOutputError = class extends GoogleError("malformed-output") {
|
|
|
524
530
|
* }
|
|
525
531
|
* ```
|
|
526
532
|
*/
|
|
527
|
-
var InvalidInputError = class extends GoogleError
|
|
533
|
+
var InvalidInputError = class extends ns.brand(GoogleError, "invalid-input") {
|
|
528
534
|
name = "InvalidInputError";
|
|
529
535
|
};
|
|
530
536
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":["iife"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["import type { Gemini } from \"../chat_models/types.js\";\nimport { iife } from \"./misc.js\";\n\nfunction GoogleError<TMarker extends string>(marker: TMarker) {\n const symbol: symbol = Symbol.for(`langchain.google.error.${marker}`);\n\n return class extends Error {\n readonly [symbol] = true as const;\n\n constructor(message: string) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n isInstance(obj: unknown): obj is this {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n symbol in obj &&\n obj[symbol as keyof typeof obj] === true\n );\n }\n };\n}\n\n/**\n * Error thrown when there is a configuration issue with the Google provider.\n *\n * This error is thrown when the Google provider encounters invalid configuration\n * parameters or settings that prevent it from functioning correctly.\n *\n * @example\n * ```typescript\n * try {\n * const model = new ChatGoogle({ invalidOption: true });\n * } catch (error) {\n * if (ConfigurationError.isInstance(error)) {\n * console.log(`Configuration error: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class ConfigurationError extends GoogleError(\"configuration\") {\n readonly name = \"ConfigurationError\" as const;\n}\n\n/**\n * Parameters for constructing a PromptBlockedError\n */\ntype PromptBlockedErrorParams = {\n /**\n * The reason why the prompt was blocked (e.g., \"SAFETY\", \"OTHER\", \"UNKNOWN\")\n */\n blockReason: string;\n /**\n * Optional array of safety ratings that contributed to the block decision\n */\n safetyRatings?: Gemini.SafetyRating[];\n /**\n * Optional custom error message. If not provided, a default message will be generated\n */\n message?: string;\n};\n\n/**\n * Error thrown when a prompt is blocked by Google's safety filters.\n *\n * This error is thrown when the Gemini API blocks a prompt due to safety concerns.\n * It contains information about why the prompt was blocked and the safety ratings\n * that triggered the block.\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some potentially unsafe prompt\");\n * } catch (error) {\n * if (PromptBlockedError.isInstance(error)) {\n * console.log(`Blocked due to: ${error.blockReason}`);\n * console.log(`Safety ratings:`, error.safetyRatings);\n * }\n * }\n * ```\n */\nexport class PromptBlockedError extends GoogleError(\"prompt-blocked\") {\n /**\n * The name of the error class.\n * @readonly\n */\n readonly name = \"PromptBlockedError\" as const;\n\n /**\n * The reason why the prompt was blocked.\n *\n * Common values include:\n * - \"SAFETY\" - Blocked due to safety concerns\n * - \"OTHER\" - Blocked for other reasons\n * - \"UNKNOWN\" - Reason is unknown\n *\n * @readonly\n */\n readonly blockReason: string;\n\n /**\n * Optional array of safety ratings that contributed to the block decision.\n *\n * Each rating contains information about different safety categories\n * (e.g., hate speech, sexually explicit content, dangerous content)\n * and their probability levels.\n *\n * @readonly\n */\n readonly safetyRatings?: Gemini.SafetyRating[];\n\n constructor(params: PromptBlockedErrorParams) {\n const message =\n params.message ??\n `Prompt was blocked: ${params.blockReason}.${\n params.safetyRatings && params.safetyRatings.length > 0\n ? ` Safety ratings: ${JSON.stringify(params.safetyRatings)}`\n : \"\"\n }`;\n\n super(message);\n this.blockReason = params.blockReason;\n this.safetyRatings = params.safetyRatings;\n }\n\n /**\n * Creates a PromptBlockedError from a Gemini API prompt feedback object.\n *\n * This is a convenience factory method for creating errors from the API response\n * when a prompt is blocked. It extracts the relevant information from the\n * promptFeedback object returned by the Gemini API.\n *\n * @param promptFeedback - The prompt feedback object from the Gemini API response\n * @returns A new PromptBlockedError instance with information from the feedback\n *\n * @example\n * ```typescript\n * const response = await geminiApi.generateContent(request);\n * if (response.promptFeedback?.blockReason) {\n * throw PromptBlockedError.fromPromptFeedback(response.promptFeedback);\n * }\n * ```\n */\n static fromPromptFeedback(\n promptFeedback: Gemini.PromptFeedback\n ): PromptBlockedError {\n return new PromptBlockedError({\n blockReason: promptFeedback.blockReason ?? \"UNKNOWN\",\n safetyRatings: promptFeedback.safetyRatings,\n });\n }\n}\n\n/**\n * Parameters for constructing an AuthError\n */\ntype AuthErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for authentication failures when communicating with Google APIs.\n *\n * This error is thrown when authentication with a Google API fails, typically\n * during the OAuth token exchange process or when using service account credentials.\n * It captures detailed information about the failed authentication attempt including\n * the status code, headers, and response body to aid in debugging and error handling.\n *\n * Common authentication failure scenarios include:\n * - Invalid or expired credentials\n * - Incorrect service account configuration\n * - Missing or invalid API keys\n * - Insufficient permissions or scopes\n * - Token exchange failures\n *\n * @example\n * ```typescript\n * try {\n * const token = await getAccessToken(credentials);\n * } catch (error) {\n * if (AuthError.isInstance(error)) {\n * console.error(`Auth failed with status ${error.statusCode}: ${error.message}`);\n * console.error('Response data:', error.data);\n * }\n * }\n * ```\n */\nexport class AuthError extends GoogleError(\"auth\") {\n readonly name = \"AuthError\" as const;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: AuthErrorParams) {\n super(params.message);\n\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Creates an AuthError from a failed HTTP response.\n *\n * This is a convenience factory method for creating authentication errors from\n * HTTP responses. It automatically extracts the error message, status code,\n * headers, and response body from the Response object.\n *\n * The method attempts to parse the response body as JSON to extract an\n * `error_description` field if available. If JSON parsing fails or the\n * content type is not JSON, it falls back to reading the response as text.\n * If both fail, the error body will be null.\n *\n * @param response - The failed HTTP Response object from the authentication request\n * @returns A Promise that resolves to a new AuthError instance with information from the response\n *\n * @example\n * ```typescript\n * const response = await fetch(tokenUrl, {\n * method: 'POST',\n * body: authRequestBody\n * });\n *\n * if (!response.ok) {\n * throw await AuthError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<AuthError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error_description ??\n `Authentication failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new AuthError({\n message,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\nconst RETRYABLE_STATUS_CODES = [\n 408, // Request Timeout\n 429, // Too Many Requests\n 500, // Internal Server Error\n 502, // Bad Gateway\n 503, // Service Unavailable\n 504, // Gateway Timeout\n];\n\n/**\n * Parameters for constructing a RequestError\n */\ntype RequestErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for HTTP request failures when communicating with Google APIs.\n *\n * This error is thrown when an HTTP request to a Google API endpoint fails.\n * It captures detailed information about the failed request including the URL,\n * status code, headers, and response body to aid in debugging and error handling.\n *\n * The error includes a `isRetryable()` method to determine if the request should\n * be retried based on the HTTP status code (e.g., 429 Too Many Requests, 503 Service Unavailable).\n *\n * @example\n * ```typescript\n * try {\n * const response = await apiClient.fetch(request);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * } catch (error) {\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * // Retry the request\n * }\n * }\n * ```\n */\nexport class RequestError extends GoogleError(\"request\") {\n readonly name = \"RequestError\" as const;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n readonly url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: RequestErrorParams) {\n super(params.message);\n\n this.url = params.url;\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Determines if this error represents a retryable request failure.\n *\n * A request is considered retryable if it failed with a status code that\n * indicates a temporary issue that might succeed on retry. This includes:\n * - 408 (Request Timeout)\n * - 429 (Too Many Requests / Rate Limiting)\n * - 500 (Internal Server Error)\n * - 502 (Bad Gateway)\n * - 503 (Service Unavailable)\n * - 504 (Gateway Timeout)\n *\n * @returns `true` if the request should be retried, `false` otherwise\n *\n * @example\n * ```typescript\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * await sleep(1000);\n * return retry(request);\n * }\n * ```\n */\n isRetryable(): boolean {\n if (!this.statusCode) return false;\n return RETRYABLE_STATUS_CODES.includes(this.statusCode);\n }\n\n /**\n * Creates a RequestError from a failed HTTP Response object.\n *\n * This is a factory method that extracts all relevant information from a\n * Response object and constructs a RequestError with appropriate details.\n * It attempts to parse the response body as JSON first, falling back to\n * text if that fails, and finally to null if the body cannot be read.\n *\n * The error message is extracted from the response body if available\n * (looking for `message` or `error` fields), otherwise a generic message\n * is constructed using the status code.\n *\n * @param response - The failed HTTP Response object to convert into an error\n * @returns A Promise that resolves to a new RequestError instance\n *\n * @example\n * ```typescript\n * const response = await fetch(url);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<RequestError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error?.message ??\n errorBody?.message ??\n errorBody?.error ??\n `Request failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new RequestError({\n message,\n url: response.url,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\n/**\n * Error thrown when the Gemini API returns no candidates in the response.\n *\n * This error is thrown when the API successfully processes a request but returns\n * an empty candidates array. This can occur when:\n * - The prompt was blocked by safety filters (but no explicit block reason was provided)\n * - An internal error occurred during generation\n * - The model was unable to generate a valid response\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some prompt\");\n * } catch (error) {\n * if (NoCandidatesError.isInstance(error)) {\n * console.log(\"No response candidates were generated\");\n * }\n * }\n * ```\n */\nexport class NoCandidatesError extends GoogleError(\"no-candidates\") {\n readonly name = \"NoCandidatesError\" as const;\n\n constructor() {\n super(\n \"No candidates returned from API. This may indicate the prompt was blocked or an error occurred.\"\n );\n }\n}\n\n/**\n * Error thrown when an invalid tool is provided to the tool converter.\n *\n * This error is thrown when a tool cannot be converted to Gemini's function\n * declaration format. Tools must be one of:\n * - LangChain structured tools (with Zod schemas)\n * - OpenAI format tools (with JSON Schema)\n * - Gemini-native function declarations\n * - Gemini-native tools (codeExecution, googleSearchRetrieval)\n *\n * @example\n * ```typescript\n * try {\n * convertToolsToGeminiFunctionDeclarations([invalidTool]);\n * } catch (error) {\n * if (InvalidToolError.isInstance(error)) {\n * console.log(`Invalid tool: ${error.tool}`);\n * console.log(`Expected formats: LangChain tools, OpenAI tools, or Gemini function declarations`);\n * }\n * }\n * ```\n */\nexport class InvalidToolError extends GoogleError(\"invalid-tool\") {\n readonly name = \"InvalidToolError\" as const;\n\n /**\n * The invalid tool that was provided.\n */\n readonly tool: unknown;\n\n constructor(tool: unknown, message?: string) {\n const defaultMessage = `Received invalid tool: ${JSON.stringify(\n tool\n )}. Tools must be LangChain tools, OpenAI tools, or Gemini function declarations.`;\n\n super(message ?? defaultMessage);\n this.tool = tool;\n }\n}\n\n/**\n * Error thrown when a ToolMessage references a tool call that cannot be found.\n *\n * This error is thrown when a ToolMessage is passed to ChatGoogle but there is no\n * corresponding AIMessage with a matching toolCallId in the conversation history.\n * This typically indicates that:\n * - The tool call ID in the ToolMessage doesn't match any previous tool calls\n * - The AIMessage containing the tool call was not included in the message history\n * - The tool call ID was incorrectly set or modified\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke([\n * new ToolMessage({ content: \"result\", tool_call_id: \"nonexistent-id\" })\n * ]);\n * } catch (error) {\n * if (ToolCallNotFoundError.isInstance(error)) {\n * console.log(`Tool call not found: ${error.toolCallId}`);\n * }\n * }\n * ```\n */\nexport class ToolCallNotFoundError extends GoogleError(\"tool-call-not-found\") {\n readonly name = \"ToolCallNotFoundError\" as const;\n\n /**\n * The tool call ID that could not be found in the conversation history.\n */\n readonly toolCallId: string;\n\n constructor(toolCallId: string, message?: string) {\n const defaultMessage = `Tool call with ID \"${toolCallId}\" not found in conversation history. Ensure the corresponding AIMessage with this tool call ID is included in the input.`;\n\n super(message ?? defaultMessage);\n this.toolCallId = toolCallId;\n }\n}\n\n/**\n * Parameters for constructing a MalformedOutputError\n */\ntype MalformedOutputErrorParams = {\n /**\n * The error message describing what went wrong during parsing\n */\n message: string;\n /**\n * Optional cause of the parsing error (e.g., the original error that occurred)\n */\n cause?: unknown;\n};\n\n/**\n * Error thrown when output parsing fails in structured output methods.\n *\n * This error is thrown when the model's response cannot be parsed according to\n * the expected schema or format. Common causes include:\n * - Invalid message type (not an AIMessage or AIMessageChunk)\n * - Missing or empty content in the response\n * - Malformed JSON that cannot be parsed\n * - Schema validation failures\n *\n * @example\n * ```typescript\n * try {\n * const result = await model.withStructuredOutput(schema).invoke(\"extract data\");\n * } catch (error) {\n * if (MalformedOutputError.isInstance(error)) {\n * console.log(`Failed to parse output: ${error.message}`);\n * if (error.cause) {\n * console.log(`Cause:`, error.cause);\n * }\n * }\n * }\n * ```\n */\nexport class MalformedOutputError extends GoogleError(\"malformed-output\") {\n readonly name = \"MalformedOutputError\" as const;\n\n /**\n * Optional cause of the parsing error.\n * This may be the original error that occurred during parsing,\n * or additional context about what went wrong.\n */\n readonly cause?: unknown;\n\n constructor(params: MalformedOutputErrorParams) {\n super(params.message);\n this.cause = params.cause;\n }\n}\n\n/**\n * Error thrown when input provided to the Google provider is invalid.\n *\n * This error is thrown when the user provides input that cannot be\n * processed by Gemini, such as:\n * - Union types in tool/function schemas\n * - Null-only types in schemas\n * - Unsupported content block source types\n * - Missing required fields in content blocks\n *\n * @example\n * ```typescript\n * try {\n * const result = schemaToGeminiParameters(unionTypeSchema);\n * } catch (error) {\n * if (InvalidInputError.isInstance(error)) {\n * console.log(`Invalid input: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class InvalidInputError extends GoogleError(\"invalid-input\") {\n readonly name = \"InvalidInputError\" as const;\n}\n"],"mappings":";;;AAGA,SAAS,YAAoC,QAAiB;CAC5D,MAAM,SAAiB,OAAO,IAAI,0BAA0B,SAAS;AAErE,QAAO,cAAc,MAAM;EACzB,CAAU,UAAU;EAEpB,YAAY,SAAiB;AAC3B,SAAM,QAAQ;AACd,OAAI,MAAM,kBACR,OAAM,kBAAkB,MAAM,KAAK,YAAY;;EAInD,WAAW,KAA2B;AACpC,UACE,OAAO,QAAQ,YACf,QAAQ,QACR,UAAU,OACV,IAAI,YAAgC;;;;;;;;;;;;;;;;;;;;;AAuB5C,IAAa,qBAAb,cAAwC,YAAY,gBAAgB,CAAC;CACnE,AAAS,OAAO;;;;;;;;;;;;;;;;;;;;;AAwClB,IAAa,qBAAb,MAAa,2BAA2B,YAAY,iBAAiB,CAAC;;;;;CAKpE,AAAS,OAAO;;;;;;;;;;;CAYhB,AAAS;;;;;;;;;;CAWT,AAAS;CAET,YAAY,QAAkC;EAC5C,MAAM,UACJ,OAAO,WACP,uBAAuB,OAAO,YAAY,GACxC,OAAO,iBAAiB,OAAO,cAAc,SAAS,IAClD,oBAAoB,KAAK,UAAU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D,KACD,CAAC;AAEF,QAAM,WAAW,eAAe;AAChC,OAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BhB,IAAa,wBAAb,cAA2C,YAAY,sBAAsB,CAAC;CAC5E,AAAS,OAAO;;;;CAKhB,AAAS;CAET,YAAY,YAAoB,SAAkB;EAChD,MAAM,iBAAiB,sBAAsB,WAAW;AAExD,QAAM,WAAW,eAAe;AAChC,OAAK,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CtB,IAAa,uBAAb,cAA0C,YAAY,mBAAmB,CAAC;CACxE,AAAS,OAAO;;;;;;CAOhB,AAAS;CAET,YAAY,QAAoC;AAC9C,QAAM,OAAO,QAAQ;AACrB,OAAK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyBxB,IAAa,oBAAb,cAAuC,YAAY,gBAAgB,CAAC;CAClE,AAAS,OAAO"}
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":["baseNs","LangChainError","iife"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["import { ns as baseNs, LangChainError } from \"@langchain/core/errors\";\nimport type { Gemini } from \"../chat_models/types.js\";\nimport { iife } from \"./misc.js\";\n\n// Internal namespace for all Google provider errors\nconst ns = baseNs.sub(\"google\");\n\n/**\n * Base error class for all Google provider errors.\n *\n * All Google-specific error classes extend this class. Use\n * `GoogleError.isInstance(obj)` to check if an object is any\n * Google provider error.\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"hello\");\n * } catch (error) {\n * if (GoogleError.isInstance(error)) {\n * console.log(\"Got a Google error:\", error.message);\n * }\n * }\n * ```\n */\nexport class GoogleError extends ns.brand(LangChainError) {\n readonly name: string = \"GoogleError\";\n}\n\n/**\n * Error thrown when there is a configuration issue with the Google provider.\n *\n * This error is thrown when the Google provider encounters invalid configuration\n * parameters or settings that prevent it from functioning correctly.\n *\n * @example\n * ```typescript\n * try {\n * const model = new ChatGoogle({ invalidOption: true });\n * } catch (error) {\n * if (ConfigurationError.isInstance(error)) {\n * console.log(`Configuration error: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class ConfigurationError extends ns.brand(GoogleError, \"configuration\") {\n readonly name = \"ConfigurationError\";\n}\n\n/**\n * Parameters for constructing a PromptBlockedError\n */\ntype PromptBlockedErrorParams = {\n /**\n * The reason why the prompt was blocked (e.g., \"SAFETY\", \"OTHER\", \"UNKNOWN\")\n */\n blockReason: string;\n /**\n * Optional array of safety ratings that contributed to the block decision\n */\n safetyRatings?: Gemini.SafetyRating[];\n /**\n * Optional custom error message. If not provided, a default message will be generated\n */\n message?: string;\n};\n\n/**\n * Error thrown when a prompt is blocked by Google's safety filters.\n *\n * This error is thrown when the Gemini API blocks a prompt due to safety concerns.\n * It contains information about why the prompt was blocked and the safety ratings\n * that triggered the block.\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some potentially unsafe prompt\");\n * } catch (error) {\n * if (PromptBlockedError.isInstance(error)) {\n * console.log(`Blocked due to: ${error.blockReason}`);\n * console.log(`Safety ratings:`, error.safetyRatings);\n * }\n * }\n * ```\n */\nexport class PromptBlockedError extends ns.brand(\n GoogleError,\n \"prompt-blocked\"\n) {\n readonly name = \"PromptBlockedError\";\n\n /**\n * The reason why the prompt was blocked.\n *\n * Common values include:\n * - \"SAFETY\" - Blocked due to safety concerns\n * - \"OTHER\" - Blocked for other reasons\n * - \"UNKNOWN\" - Reason is unknown\n *\n * @readonly\n */\n readonly blockReason: string;\n\n /**\n * Optional array of safety ratings that contributed to the block decision.\n *\n * Each rating contains information about different safety categories\n * (e.g., hate speech, sexually explicit content, dangerous content)\n * and their probability levels.\n *\n * @readonly\n */\n readonly safetyRatings?: Gemini.SafetyRating[];\n\n constructor(params: PromptBlockedErrorParams) {\n const message =\n params.message ??\n `Prompt was blocked: ${params.blockReason}.${\n params.safetyRatings && params.safetyRatings.length > 0\n ? ` Safety ratings: ${JSON.stringify(params.safetyRatings)}`\n : \"\"\n }`;\n\n super(message);\n this.blockReason = params.blockReason;\n this.safetyRatings = params.safetyRatings;\n }\n\n /**\n * Creates a PromptBlockedError from a Gemini API prompt feedback object.\n *\n * This is a convenience factory method for creating errors from the API response\n * when a prompt is blocked. It extracts the relevant information from the\n * promptFeedback object returned by the Gemini API.\n *\n * @param promptFeedback - The prompt feedback object from the Gemini API response\n * @returns A new PromptBlockedError instance with information from the feedback\n *\n * @example\n * ```typescript\n * const response = await geminiApi.generateContent(request);\n * if (response.promptFeedback?.blockReason) {\n * throw PromptBlockedError.fromPromptFeedback(response.promptFeedback);\n * }\n * ```\n */\n static fromPromptFeedback(\n promptFeedback: Gemini.PromptFeedback\n ): PromptBlockedError {\n return new PromptBlockedError({\n blockReason: promptFeedback.blockReason ?? \"UNKNOWN\",\n safetyRatings: promptFeedback.safetyRatings,\n });\n }\n}\n\n/**\n * Parameters for constructing an AuthError\n */\ntype AuthErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for authentication failures when communicating with Google APIs.\n *\n * This error is thrown when authentication with a Google API fails, typically\n * during the OAuth token exchange process or when using service account credentials.\n * It captures detailed information about the failed authentication attempt including\n * the status code, headers, and response body to aid in debugging and error handling.\n *\n * Common authentication failure scenarios include:\n * - Invalid or expired credentials\n * - Incorrect service account configuration\n * - Missing or invalid API keys\n * - Insufficient permissions or scopes\n * - Token exchange failures\n *\n * @example\n * ```typescript\n * try {\n * const token = await getAccessToken(credentials);\n * } catch (error) {\n * if (AuthError.isInstance(error)) {\n * console.error(`Auth failed with status ${error.statusCode}: ${error.message}`);\n * console.error('Response data:', error.data);\n * }\n * }\n * ```\n */\nexport class AuthError extends ns.brand(GoogleError, \"auth\") {\n readonly name = \"AuthError\" as const;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: AuthErrorParams) {\n super(params.message);\n\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Creates an AuthError from a failed HTTP response.\n *\n * This is a convenience factory method for creating authentication errors from\n * HTTP responses. It automatically extracts the error message, status code,\n * headers, and response body from the Response object.\n *\n * The method attempts to parse the response body as JSON to extract an\n * `error_description` field if available. If JSON parsing fails or the\n * content type is not JSON, it falls back to reading the response as text.\n * If both fail, the error body will be null.\n *\n * @param response - The failed HTTP Response object from the authentication request\n * @returns A Promise that resolves to a new AuthError instance with information from the response\n *\n * @example\n * ```typescript\n * const response = await fetch(tokenUrl, {\n * method: 'POST',\n * body: authRequestBody\n * });\n *\n * if (!response.ok) {\n * throw await AuthError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<AuthError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error_description ??\n `Authentication failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new AuthError({\n message,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\nconst RETRYABLE_STATUS_CODES = [\n 408, // Request Timeout\n 429, // Too Many Requests\n 500, // Internal Server Error\n 502, // Bad Gateway\n 503, // Service Unavailable\n 504, // Gateway Timeout\n];\n\n/**\n * Parameters for constructing a RequestError\n */\ntype RequestErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for HTTP request failures when communicating with Google APIs.\n *\n * This error is thrown when an HTTP request to a Google API endpoint fails.\n * It captures detailed information about the failed request including the URL,\n * status code, headers, and response body to aid in debugging and error handling.\n *\n * The error includes a `isRetryable()` method to determine if the request should\n * be retried based on the HTTP status code (e.g., 429 Too Many Requests, 503 Service Unavailable).\n *\n * @example\n * ```typescript\n * try {\n * const response = await apiClient.fetch(request);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * } catch (error) {\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * // Retry the request\n * }\n * }\n * ```\n */\nexport class RequestError extends ns.brand(GoogleError, \"request\") {\n readonly name = \"RequestError\" as const;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n readonly url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: RequestErrorParams) {\n super(params.message);\n\n this.url = params.url;\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Determines if this error represents a retryable request failure.\n *\n * A request is considered retryable if it failed with a status code that\n * indicates a temporary issue that might succeed on retry. This includes:\n * - 408 (Request Timeout)\n * - 429 (Too Many Requests / Rate Limiting)\n * - 500 (Internal Server Error)\n * - 502 (Bad Gateway)\n * - 503 (Service Unavailable)\n * - 504 (Gateway Timeout)\n *\n * @returns `true` if the request should be retried, `false` otherwise\n *\n * @example\n * ```typescript\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * await sleep(1000);\n * return retry(request);\n * }\n * ```\n */\n isRetryable(): boolean {\n if (!this.statusCode) return false;\n return RETRYABLE_STATUS_CODES.includes(this.statusCode);\n }\n\n /**\n * Creates a RequestError from a failed HTTP Response object.\n *\n * This is a factory method that extracts all relevant information from a\n * Response object and constructs a RequestError with appropriate details.\n * It attempts to parse the response body as JSON first, falling back to\n * text if that fails, and finally to null if the body cannot be read.\n *\n * The error message is extracted from the response body if available\n * (looking for `message` or `error` fields), otherwise a generic message\n * is constructed using the status code.\n *\n * @param response - The failed HTTP Response object to convert into an error\n * @returns A Promise that resolves to a new RequestError instance\n *\n * @example\n * ```typescript\n * const response = await fetch(url);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<RequestError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error?.message ??\n errorBody?.message ??\n errorBody?.error ??\n `Request failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new RequestError({\n message,\n url: response.url,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\n/**\n * Error thrown when the Gemini API returns no candidates in the response.\n *\n * This error is thrown when the API successfully processes a request but returns\n * an empty candidates array. This can occur when:\n * - The prompt was blocked by safety filters (but no explicit block reason was provided)\n * - An internal error occurred during generation\n * - The model was unable to generate a valid response\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some prompt\");\n * } catch (error) {\n * if (NoCandidatesError.isInstance(error)) {\n * console.log(\"No response candidates were generated\");\n * }\n * }\n * ```\n */\nexport class NoCandidatesError extends ns.brand(GoogleError, \"no-candidates\") {\n readonly name = \"NoCandidatesError\";\n\n constructor() {\n super(\n \"No candidates returned from API. This may indicate the prompt was blocked or an error occurred.\"\n );\n }\n}\n\n/**\n * Error thrown when an invalid tool is provided to the tool converter.\n *\n * This error is thrown when a tool cannot be converted to Gemini's function\n * declaration format. Tools must be one of:\n * - LangChain structured tools (with Zod schemas)\n * - OpenAI format tools (with JSON Schema)\n * - Gemini-native function declarations\n * - Gemini-native tools (codeExecution, googleSearchRetrieval)\n *\n * @example\n * ```typescript\n * try {\n * convertToolsToGeminiFunctionDeclarations([invalidTool]);\n * } catch (error) {\n * if (InvalidToolError.isInstance(error)) {\n * console.log(`Invalid tool: ${error.tool}`);\n * console.log(`Expected formats: LangChain tools, OpenAI tools, or Gemini function declarations`);\n * }\n * }\n * ```\n */\nexport class InvalidToolError extends ns.brand(GoogleError, \"invalid-tool\") {\n readonly name = \"InvalidToolError\";\n\n /**\n * The invalid tool that was provided.\n */\n readonly tool: unknown;\n\n constructor(tool: unknown, message?: string) {\n const defaultMessage = `Received invalid tool: ${JSON.stringify(\n tool\n )}. Tools must be LangChain tools, OpenAI tools, or Gemini function declarations.`;\n\n super(message ?? defaultMessage);\n this.tool = tool;\n }\n}\n\n/**\n * Error thrown when a ToolMessage references a tool call that cannot be found.\n *\n * This error is thrown when a ToolMessage is passed to ChatGoogle but there is no\n * corresponding AIMessage with a matching toolCallId in the conversation history.\n * This typically indicates that:\n * - The tool call ID in the ToolMessage doesn't match any previous tool calls\n * - The AIMessage containing the tool call was not included in the message history\n * - The tool call ID was incorrectly set or modified\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke([\n * new ToolMessage({ content: \"result\", tool_call_id: \"nonexistent-id\" })\n * ]);\n * } catch (error) {\n * if (ToolCallNotFoundError.isInstance(error)) {\n * console.log(`Tool call not found: ${error.toolCallId}`);\n * }\n * }\n * ```\n */\nexport class ToolCallNotFoundError extends ns.brand(\n GoogleError,\n \"tool-call-not-found\"\n) {\n readonly name = \"ToolCallNotFoundError\";\n\n /**\n * The tool call ID that could not be found in the conversation history.\n */\n readonly toolCallId: string;\n\n constructor(toolCallId: string, message?: string) {\n const defaultMessage = `Tool call with ID \"${toolCallId}\" not found in conversation history. Ensure the corresponding AIMessage with this tool call ID is included in the input.`;\n\n super(message ?? defaultMessage);\n this.toolCallId = toolCallId;\n }\n}\n\n/**\n * Parameters for constructing a MalformedOutputError\n */\ntype MalformedOutputErrorParams = {\n /**\n * The error message describing what went wrong during parsing\n */\n message: string;\n /**\n * Optional cause of the parsing error (e.g., the original error that occurred)\n */\n cause?: unknown;\n};\n\n/**\n * Error thrown when output parsing fails in structured output methods.\n *\n * This error is thrown when the model's response cannot be parsed according to\n * the expected schema or format. Common causes include:\n * - Invalid message type (not an AIMessage or AIMessageChunk)\n * - Missing or empty content in the response\n * - Malformed JSON that cannot be parsed\n * - Schema validation failures\n *\n * @example\n * ```typescript\n * try {\n * const result = await model.withStructuredOutput(schema).invoke(\"extract data\");\n * } catch (error) {\n * if (MalformedOutputError.isInstance(error)) {\n * console.log(`Failed to parse output: ${error.message}`);\n * if (error.cause) {\n * console.log(`Cause:`, error.cause);\n * }\n * }\n * }\n * ```\n */\nexport class MalformedOutputError extends ns.brand(\n GoogleError,\n \"malformed-output\"\n) {\n readonly name = \"MalformedOutputError\";\n\n /**\n * Optional cause of the parsing error.\n * This may be the original error that occurred during parsing,\n * or additional context about what went wrong.\n */\n readonly cause?: unknown;\n\n constructor(params: MalformedOutputErrorParams) {\n super(params.message);\n this.cause = params.cause;\n }\n}\n\n/**\n * Error thrown when input provided to the Google provider is invalid.\n *\n * This error is thrown when the user provides input that cannot be\n * processed by Gemini, such as:\n * - Union types in tool/function schemas\n * - Null-only types in schemas\n * - Unsupported content block source types\n * - Missing required fields in content blocks\n *\n * @example\n * ```typescript\n * try {\n * const result = schemaToGeminiParameters(unionTypeSchema);\n * } catch (error) {\n * if (InvalidInputError.isInstance(error)) {\n * console.log(`Invalid input: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class InvalidInputError extends ns.brand(GoogleError, \"invalid-input\") {\n readonly name = \"InvalidInputError\";\n}\n"],"mappings":";;;;AAKA,MAAM,KAAKA,0BAAO,IAAI,SAAS;;;;;;;;;;;;;;;;;;;AAoB/B,IAAa,cAAb,cAAiC,GAAG,MAAMC,sCAAe,CAAC;CACxD,AAAS,OAAe;;;;;;;;;;;;;;;;;;;AAoB1B,IAAa,qBAAb,cAAw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SAAS;GACd,YAAY,SAAS;GACrB,YAAY,SAAS;GACrB;GACA,MAAM;GACP,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAwBN,IAAa,oBAAb,cAAuC,GAAG,MAAM,aAAa,gBAAgB,CAAC;CAC5E,AAAS,OAAO;CAEhB,cAAc;AACZ,QACE,kGACD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BL,IAAa,mBAAb,cAAsC,GAAG,MAAM,aAAa,eAAe,CAAC;CAC1E,AAAS,OAAO;;;;CAKhB,AAAS;CAET,YAAY,MAAe,SAAkB;EAC3C,MAAM,iBAAiB,0BAA0B,KAAK,UACpD,KACD,CAAC;AAEF,QAAM,WAAW,eAAe;AAChC,OAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BhB,IAAa,wBAAb,cAA2C,GAAG,MAC5C,aACA,sBACD,CAAC;CACA,AAAS,OAAO;;;;CAKhB,AAAS;CAET,YAAY,YAAoB,SAAkB;EAChD,MAAM,iBAAiB,sBAAsB,WAAW;AAExD,QAAM,WAAW,eAAe;AAChC,OAAK,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CtB,IAAa,uBAAb,cAA0C,GAAG,MAC3C,aACA,mBACD,CAAC;CACA,AAAS,OAAO;;;;;;CAOhB,AAAS;CAET,YAAY,QAAoC;AAC9C,QAAM,OAAO,QAAQ;AACrB,OAAK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyBxB,IAAa,oBAAb,cAAuC,GAAG,MAAM,aAAa,gBAAgB,CAAC;CAC5E,AAAS,OAAO"}
|
package/dist/utils/errors.js
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import { iife } from "./misc.js";
|
|
2
|
+
import { LangChainError, ns } from "@langchain/core/errors";
|
|
2
3
|
|
|
3
4
|
//#region src/utils/errors.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
5
|
+
const ns$1 = ns.sub("google");
|
|
6
|
+
/**
|
|
7
|
+
* Base error class for all Google provider errors.
|
|
8
|
+
*
|
|
9
|
+
* All Google-specific error classes extend this class. Use
|
|
10
|
+
* `GoogleError.isInstance(obj)` to check if an object is any
|
|
11
|
+
* Google provider error.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* try {
|
|
16
|
+
* await model.invoke("hello");
|
|
17
|
+
* } catch (error) {
|
|
18
|
+
* if (GoogleError.isInstance(error)) {
|
|
19
|
+
* console.log("Got a Google error:", error.message);
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
var GoogleError = class extends ns$1.brand(LangChainError) {
|
|
25
|
+
name = "GoogleError";
|
|
26
|
+
};
|
|
17
27
|
/**
|
|
18
28
|
* Error thrown when there is a configuration issue with the Google provider.
|
|
19
29
|
*
|
|
@@ -31,7 +41,7 @@ function GoogleError(marker) {
|
|
|
31
41
|
* }
|
|
32
42
|
* ```
|
|
33
43
|
*/
|
|
34
|
-
var ConfigurationError = class extends GoogleError
|
|
44
|
+
var ConfigurationError = class extends ns$1.brand(GoogleError, "configuration") {
|
|
35
45
|
name = "ConfigurationError";
|
|
36
46
|
};
|
|
37
47
|
/**
|
|
@@ -53,11 +63,7 @@ var ConfigurationError = class extends GoogleError("configuration") {
|
|
|
53
63
|
* }
|
|
54
64
|
* ```
|
|
55
65
|
*/
|
|
56
|
-
var PromptBlockedError = class PromptBlockedError extends GoogleError
|
|
57
|
-
/**
|
|
58
|
-
* The name of the error class.
|
|
59
|
-
* @readonly
|
|
60
|
-
*/
|
|
66
|
+
var PromptBlockedError = class PromptBlockedError extends ns$1.brand(GoogleError, "prompt-blocked") {
|
|
61
67
|
name = "PromptBlockedError";
|
|
62
68
|
/**
|
|
63
69
|
* The reason why the prompt was blocked.
|
|
@@ -138,7 +144,7 @@ var PromptBlockedError = class PromptBlockedError extends GoogleError("prompt-bl
|
|
|
138
144
|
* }
|
|
139
145
|
* ```
|
|
140
146
|
*/
|
|
141
|
-
var AuthError = class AuthError extends GoogleError
|
|
147
|
+
var AuthError = class AuthError extends ns$1.brand(GoogleError, "auth") {
|
|
142
148
|
name = "AuthError";
|
|
143
149
|
/**
|
|
144
150
|
* The HTTP status code of the failed response.
|
|
@@ -256,7 +262,7 @@ const RETRYABLE_STATUS_CODES = [
|
|
|
256
262
|
* }
|
|
257
263
|
* ```
|
|
258
264
|
*/
|
|
259
|
-
var RequestError = class RequestError extends GoogleError
|
|
265
|
+
var RequestError = class RequestError extends ns$1.brand(GoogleError, "request") {
|
|
260
266
|
name = "RequestError";
|
|
261
267
|
/**
|
|
262
268
|
* The URL of the failed request.
|
|
@@ -391,7 +397,7 @@ var RequestError = class RequestError extends GoogleError("request") {
|
|
|
391
397
|
* }
|
|
392
398
|
* ```
|
|
393
399
|
*/
|
|
394
|
-
var NoCandidatesError = class extends GoogleError
|
|
400
|
+
var NoCandidatesError = class extends ns$1.brand(GoogleError, "no-candidates") {
|
|
395
401
|
name = "NoCandidatesError";
|
|
396
402
|
constructor() {
|
|
397
403
|
super("No candidates returned from API. This may indicate the prompt was blocked or an error occurred.");
|
|
@@ -419,7 +425,7 @@ var NoCandidatesError = class extends GoogleError("no-candidates") {
|
|
|
419
425
|
* }
|
|
420
426
|
* ```
|
|
421
427
|
*/
|
|
422
|
-
var InvalidToolError = class extends GoogleError
|
|
428
|
+
var InvalidToolError = class extends ns$1.brand(GoogleError, "invalid-tool") {
|
|
423
429
|
name = "InvalidToolError";
|
|
424
430
|
/**
|
|
425
431
|
* The invalid tool that was provided.
|
|
@@ -454,7 +460,7 @@ var InvalidToolError = class extends GoogleError("invalid-tool") {
|
|
|
454
460
|
* }
|
|
455
461
|
* ```
|
|
456
462
|
*/
|
|
457
|
-
var ToolCallNotFoundError = class extends GoogleError
|
|
463
|
+
var ToolCallNotFoundError = class extends ns$1.brand(GoogleError, "tool-call-not-found") {
|
|
458
464
|
name = "ToolCallNotFoundError";
|
|
459
465
|
/**
|
|
460
466
|
* The tool call ID that could not be found in the conversation history.
|
|
@@ -490,7 +496,7 @@ var ToolCallNotFoundError = class extends GoogleError("tool-call-not-found") {
|
|
|
490
496
|
* }
|
|
491
497
|
* ```
|
|
492
498
|
*/
|
|
493
|
-
var MalformedOutputError = class extends GoogleError
|
|
499
|
+
var MalformedOutputError = class extends ns$1.brand(GoogleError, "malformed-output") {
|
|
494
500
|
name = "MalformedOutputError";
|
|
495
501
|
/**
|
|
496
502
|
* Optional cause of the parsing error.
|
|
@@ -524,7 +530,7 @@ var MalformedOutputError = class extends GoogleError("malformed-output") {
|
|
|
524
530
|
* }
|
|
525
531
|
* ```
|
|
526
532
|
*/
|
|
527
|
-
var InvalidInputError = class extends GoogleError
|
|
533
|
+
var InvalidInputError = class extends ns$1.brand(GoogleError, "invalid-input") {
|
|
528
534
|
name = "InvalidInputError";
|
|
529
535
|
};
|
|
530
536
|
|
package/dist/utils/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/utils/errors.ts"],"sourcesContent":["import type { Gemini } from \"../chat_models/types.js\";\nimport { iife } from \"./misc.js\";\n\nfunction GoogleError<TMarker extends string>(marker: TMarker) {\n const symbol: symbol = Symbol.for(`langchain.google.error.${marker}`);\n\n return class extends Error {\n readonly [symbol] = true as const;\n\n constructor(message: string) {\n super(message);\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n }\n\n isInstance(obj: unknown): obj is this {\n return (\n typeof obj === \"object\" &&\n obj !== null &&\n symbol in obj &&\n obj[symbol as keyof typeof obj] === true\n );\n }\n };\n}\n\n/**\n * Error thrown when there is a configuration issue with the Google provider.\n *\n * This error is thrown when the Google provider encounters invalid configuration\n * parameters or settings that prevent it from functioning correctly.\n *\n * @example\n * ```typescript\n * try {\n * const model = new ChatGoogle({ invalidOption: true });\n * } catch (error) {\n * if (ConfigurationError.isInstance(error)) {\n * console.log(`Configuration error: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class ConfigurationError extends GoogleError(\"configuration\") {\n readonly name = \"ConfigurationError\" as const;\n}\n\n/**\n * Parameters for constructing a PromptBlockedError\n */\ntype PromptBlockedErrorParams = {\n /**\n * The reason why the prompt was blocked (e.g., \"SAFETY\", \"OTHER\", \"UNKNOWN\")\n */\n blockReason: string;\n /**\n * Optional array of safety ratings that contributed to the block decision\n */\n safetyRatings?: Gemini.SafetyRating[];\n /**\n * Optional custom error message. If not provided, a default message will be generated\n */\n message?: string;\n};\n\n/**\n * Error thrown when a prompt is blocked by Google's safety filters.\n *\n * This error is thrown when the Gemini API blocks a prompt due to safety concerns.\n * It contains information about why the prompt was blocked and the safety ratings\n * that triggered the block.\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some potentially unsafe prompt\");\n * } catch (error) {\n * if (PromptBlockedError.isInstance(error)) {\n * console.log(`Blocked due to: ${error.blockReason}`);\n * console.log(`Safety ratings:`, error.safetyRatings);\n * }\n * }\n * ```\n */\nexport class PromptBlockedError extends GoogleError(\"prompt-blocked\") {\n /**\n * The name of the error class.\n * @readonly\n */\n readonly name = \"PromptBlockedError\" as const;\n\n /**\n * The reason why the prompt was blocked.\n *\n * Common values include:\n * - \"SAFETY\" - Blocked due to safety concerns\n * - \"OTHER\" - Blocked for other reasons\n * - \"UNKNOWN\" - Reason is unknown\n *\n * @readonly\n */\n readonly blockReason: string;\n\n /**\n * Optional array of safety ratings that contributed to the block decision.\n *\n * Each rating contains information about different safety categories\n * (e.g., hate speech, sexually explicit content, dangerous content)\n * and their probability levels.\n *\n * @readonly\n */\n readonly safetyRatings?: Gemini.SafetyRating[];\n\n constructor(params: PromptBlockedErrorParams) {\n const message =\n params.message ??\n `Prompt was blocked: ${params.blockReason}.${\n params.safetyRatings && params.safetyRatings.length > 0\n ? ` Safety ratings: ${JSON.stringify(params.safetyRatings)}`\n : \"\"\n }`;\n\n super(message);\n this.blockReason = params.blockReason;\n this.safetyRatings = params.safetyRatings;\n }\n\n /**\n * Creates a PromptBlockedError from a Gemini API prompt feedback object.\n *\n * This is a convenience factory method for creating errors from the API response\n * when a prompt is blocked. It extracts the relevant information from the\n * promptFeedback object returned by the Gemini API.\n *\n * @param promptFeedback - The prompt feedback object from the Gemini API response\n * @returns A new PromptBlockedError instance with information from the feedback\n *\n * @example\n * ```typescript\n * const response = await geminiApi.generateContent(request);\n * if (response.promptFeedback?.blockReason) {\n * throw PromptBlockedError.fromPromptFeedback(response.promptFeedback);\n * }\n * ```\n */\n static fromPromptFeedback(\n promptFeedback: Gemini.PromptFeedback\n ): PromptBlockedError {\n return new PromptBlockedError({\n blockReason: promptFeedback.blockReason ?? \"UNKNOWN\",\n safetyRatings: promptFeedback.safetyRatings,\n });\n }\n}\n\n/**\n * Parameters for constructing an AuthError\n */\ntype AuthErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for authentication failures when communicating with Google APIs.\n *\n * This error is thrown when authentication with a Google API fails, typically\n * during the OAuth token exchange process or when using service account credentials.\n * It captures detailed information about the failed authentication attempt including\n * the status code, headers, and response body to aid in debugging and error handling.\n *\n * Common authentication failure scenarios include:\n * - Invalid or expired credentials\n * - Incorrect service account configuration\n * - Missing or invalid API keys\n * - Insufficient permissions or scopes\n * - Token exchange failures\n *\n * @example\n * ```typescript\n * try {\n * const token = await getAccessToken(credentials);\n * } catch (error) {\n * if (AuthError.isInstance(error)) {\n * console.error(`Auth failed with status ${error.statusCode}: ${error.message}`);\n * console.error('Response data:', error.data);\n * }\n * }\n * ```\n */\nexport class AuthError extends GoogleError(\"auth\") {\n readonly name = \"AuthError\" as const;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: AuthErrorParams) {\n super(params.message);\n\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Creates an AuthError from a failed HTTP response.\n *\n * This is a convenience factory method for creating authentication errors from\n * HTTP responses. It automatically extracts the error message, status code,\n * headers, and response body from the Response object.\n *\n * The method attempts to parse the response body as JSON to extract an\n * `error_description` field if available. If JSON parsing fails or the\n * content type is not JSON, it falls back to reading the response as text.\n * If both fail, the error body will be null.\n *\n * @param response - The failed HTTP Response object from the authentication request\n * @returns A Promise that resolves to a new AuthError instance with information from the response\n *\n * @example\n * ```typescript\n * const response = await fetch(tokenUrl, {\n * method: 'POST',\n * body: authRequestBody\n * });\n *\n * if (!response.ok) {\n * throw await AuthError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<AuthError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error_description ??\n `Authentication failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new AuthError({\n message,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\nconst RETRYABLE_STATUS_CODES = [\n 408, // Request Timeout\n 429, // Too Many Requests\n 500, // Internal Server Error\n 502, // Bad Gateway\n 503, // Service Unavailable\n 504, // Gateway Timeout\n];\n\n/**\n * Parameters for constructing a RequestError\n */\ntype RequestErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for HTTP request failures when communicating with Google APIs.\n *\n * This error is thrown when an HTTP request to a Google API endpoint fails.\n * It captures detailed information about the failed request including the URL,\n * status code, headers, and response body to aid in debugging and error handling.\n *\n * The error includes a `isRetryable()` method to determine if the request should\n * be retried based on the HTTP status code (e.g., 429 Too Many Requests, 503 Service Unavailable).\n *\n * @example\n * ```typescript\n * try {\n * const response = await apiClient.fetch(request);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * } catch (error) {\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * // Retry the request\n * }\n * }\n * ```\n */\nexport class RequestError extends GoogleError(\"request\") {\n readonly name = \"RequestError\" as const;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n readonly url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: RequestErrorParams) {\n super(params.message);\n\n this.url = params.url;\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Determines if this error represents a retryable request failure.\n *\n * A request is considered retryable if it failed with a status code that\n * indicates a temporary issue that might succeed on retry. This includes:\n * - 408 (Request Timeout)\n * - 429 (Too Many Requests / Rate Limiting)\n * - 500 (Internal Server Error)\n * - 502 (Bad Gateway)\n * - 503 (Service Unavailable)\n * - 504 (Gateway Timeout)\n *\n * @returns `true` if the request should be retried, `false` otherwise\n *\n * @example\n * ```typescript\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * await sleep(1000);\n * return retry(request);\n * }\n * ```\n */\n isRetryable(): boolean {\n if (!this.statusCode) return false;\n return RETRYABLE_STATUS_CODES.includes(this.statusCode);\n }\n\n /**\n * Creates a RequestError from a failed HTTP Response object.\n *\n * This is a factory method that extracts all relevant information from a\n * Response object and constructs a RequestError with appropriate details.\n * It attempts to parse the response body as JSON first, falling back to\n * text if that fails, and finally to null if the body cannot be read.\n *\n * The error message is extracted from the response body if available\n * (looking for `message` or `error` fields), otherwise a generic message\n * is constructed using the status code.\n *\n * @param response - The failed HTTP Response object to convert into an error\n * @returns A Promise that resolves to a new RequestError instance\n *\n * @example\n * ```typescript\n * const response = await fetch(url);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<RequestError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error?.message ??\n errorBody?.message ??\n errorBody?.error ??\n `Request failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new RequestError({\n message,\n url: response.url,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\n/**\n * Error thrown when the Gemini API returns no candidates in the response.\n *\n * This error is thrown when the API successfully processes a request but returns\n * an empty candidates array. This can occur when:\n * - The prompt was blocked by safety filters (but no explicit block reason was provided)\n * - An internal error occurred during generation\n * - The model was unable to generate a valid response\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some prompt\");\n * } catch (error) {\n * if (NoCandidatesError.isInstance(error)) {\n * console.log(\"No response candidates were generated\");\n * }\n * }\n * ```\n */\nexport class NoCandidatesError extends GoogleError(\"no-candidates\") {\n readonly name = \"NoCandidatesError\" as const;\n\n constructor() {\n super(\n \"No candidates returned from API. This may indicate the prompt was blocked or an error occurred.\"\n );\n }\n}\n\n/**\n * Error thrown when an invalid tool is provided to the tool converter.\n *\n * This error is thrown when a tool cannot be converted to Gemini's function\n * declaration format. Tools must be one of:\n * - LangChain structured tools (with Zod schemas)\n * - OpenAI format tools (with JSON Schema)\n * - Gemini-native function declarations\n * - Gemini-native tools (codeExecution, googleSearchRetrieval)\n *\n * @example\n * ```typescript\n * try {\n * convertToolsToGeminiFunctionDeclarations([invalidTool]);\n * } catch (error) {\n * if (InvalidToolError.isInstance(error)) {\n * console.log(`Invalid tool: ${error.tool}`);\n * console.log(`Expected formats: LangChain tools, OpenAI tools, or Gemini function declarations`);\n * }\n * }\n * ```\n */\nexport class InvalidToolError extends GoogleError(\"invalid-tool\") {\n readonly name = \"InvalidToolError\" as const;\n\n /**\n * The invalid tool that was provided.\n */\n readonly tool: unknown;\n\n constructor(tool: unknown, message?: string) {\n const defaultMessage = `Received invalid tool: ${JSON.stringify(\n tool\n )}. Tools must be LangChain tools, OpenAI tools, or Gemini function declarations.`;\n\n super(message ?? defaultMessage);\n this.tool = tool;\n }\n}\n\n/**\n * Error thrown when a ToolMessage references a tool call that cannot be found.\n *\n * This error is thrown when a ToolMessage is passed to ChatGoogle but there is no\n * corresponding AIMessage with a matching toolCallId in the conversation history.\n * This typically indicates that:\n * - The tool call ID in the ToolMessage doesn't match any previous tool calls\n * - The AIMessage containing the tool call was not included in the message history\n * - The tool call ID was incorrectly set or modified\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke([\n * new ToolMessage({ content: \"result\", tool_call_id: \"nonexistent-id\" })\n * ]);\n * } catch (error) {\n * if (ToolCallNotFoundError.isInstance(error)) {\n * console.log(`Tool call not found: ${error.toolCallId}`);\n * }\n * }\n * ```\n */\nexport class ToolCallNotFoundError extends GoogleError(\"tool-call-not-found\") {\n readonly name = \"ToolCallNotFoundError\" as const;\n\n /**\n * The tool call ID that could not be found in the conversation history.\n */\n readonly toolCallId: string;\n\n constructor(toolCallId: string, message?: string) {\n const defaultMessage = `Tool call with ID \"${toolCallId}\" not found in conversation history. Ensure the corresponding AIMessage with this tool call ID is included in the input.`;\n\n super(message ?? defaultMessage);\n this.toolCallId = toolCallId;\n }\n}\n\n/**\n * Parameters for constructing a MalformedOutputError\n */\ntype MalformedOutputErrorParams = {\n /**\n * The error message describing what went wrong during parsing\n */\n message: string;\n /**\n * Optional cause of the parsing error (e.g., the original error that occurred)\n */\n cause?: unknown;\n};\n\n/**\n * Error thrown when output parsing fails in structured output methods.\n *\n * This error is thrown when the model's response cannot be parsed according to\n * the expected schema or format. Common causes include:\n * - Invalid message type (not an AIMessage or AIMessageChunk)\n * - Missing or empty content in the response\n * - Malformed JSON that cannot be parsed\n * - Schema validation failures\n *\n * @example\n * ```typescript\n * try {\n * const result = await model.withStructuredOutput(schema).invoke(\"extract data\");\n * } catch (error) {\n * if (MalformedOutputError.isInstance(error)) {\n * console.log(`Failed to parse output: ${error.message}`);\n * if (error.cause) {\n * console.log(`Cause:`, error.cause);\n * }\n * }\n * }\n * ```\n */\nexport class MalformedOutputError extends GoogleError(\"malformed-output\") {\n readonly name = \"MalformedOutputError\" as const;\n\n /**\n * Optional cause of the parsing error.\n * This may be the original error that occurred during parsing,\n * or additional context about what went wrong.\n */\n readonly cause?: unknown;\n\n constructor(params: MalformedOutputErrorParams) {\n super(params.message);\n this.cause = params.cause;\n }\n}\n\n/**\n * Error thrown when input provided to the Google provider is invalid.\n *\n * This error is thrown when the user provides input that cannot be\n * processed by Gemini, such as:\n * - Union types in tool/function schemas\n * - Null-only types in schemas\n * - Unsupported content block source types\n * - Missing required fields in content blocks\n *\n * @example\n * ```typescript\n * try {\n * const result = schemaToGeminiParameters(unionTypeSchema);\n * } catch (error) {\n * if (InvalidInputError.isInstance(error)) {\n * console.log(`Invalid input: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class InvalidInputError extends GoogleError(\"invalid-input\") {\n readonly name = \"InvalidInputError\" as const;\n}\n"],"mappings":";;;AAGA,SAAS,YAAoC,QAAiB;CAC5D,MAAM,SAAiB,OAAO,IAAI,0BAA0B,SAAS;AAErE,QAAO,cAAc,MAAM;EACzB,CAAU,UAAU;EAEpB,YAAY,SAAiB;AAC3B,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UAAU,WAAW;GACzB,MAAM,SAAiC,EAAE;AACzC,YAAS,QAAQ,SAAS,OAAO,SAAS;AACxC,WAAO,QAAQ;KACf;AACF,UAAO;IACP;AAEF,SAAO,IAAI,aAAa;GACtB;GACA,KAAK,SAAS;GACd,YAAY,SAAS;GACrB,YAAY,SAAS;GACrB;GACA,MAAM;GACP,CAAC;;;;;;;;;;;;;;;;;;;;;;;AAwBN,IAAa,oBAAb,cAAuC,YAAY,gBAAgB,CAAC;CAClE,AAAS,OAAO;CAEhB,cAAc;AACZ,QACE,kGACD;;;;;;;;;;;;;;;;;;;;;;;;;AA0BL,IAAa,mBAAb,cAAsC,YAAY,eAAe,CAAC;CAChE,AAAS,OAAO;;;;CAKhB,AAAS;CAET,YAAY,MAAe,SAAkB;EAC3C,MAAM,iBAAiB,0BAA0B,KAAK,UACpD,KACD,CAAC;AAEF,QAAM,WAAW,eAAe;AAChC,OAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BhB,IAAa,wBAAb,cAA2C,YAAY,sBAAsB,CAAC;CAC5E,AAAS,OAAO;;;;CAKhB,AAAS;CAET,YAAY,YAAoB,SAAkB;EAChD,MAAM,iBAAiB,sBAAsB,WAAW;AAExD,QAAM,WAAW,eAAe;AAChC,OAAK,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CtB,IAAa,uBAAb,cAA0C,YAAY,mBAAmB,CAAC;CACxE,AAAS,OAAO;;;;;;CAOhB,AAAS;CAET,YAAY,QAAoC;AAC9C,QAAM,OAAO,QAAQ;AACrB,OAAK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyBxB,IAAa,oBAAb,cAAuC,YAAY,gBAAgB,CAAC;CAClE,AAAS,OAAO"}
|
|
1
|
+
{"version":3,"file":"errors.js","names":["ns","baseNs"],"sources":["../../src/utils/errors.ts"],"sourcesContent":["import { ns as baseNs, LangChainError } from \"@langchain/core/errors\";\nimport type { Gemini } from \"../chat_models/types.js\";\nimport { iife } from \"./misc.js\";\n\n// Internal namespace for all Google provider errors\nconst ns = baseNs.sub(\"google\");\n\n/**\n * Base error class for all Google provider errors.\n *\n * All Google-specific error classes extend this class. Use\n * `GoogleError.isInstance(obj)` to check if an object is any\n * Google provider error.\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"hello\");\n * } catch (error) {\n * if (GoogleError.isInstance(error)) {\n * console.log(\"Got a Google error:\", error.message);\n * }\n * }\n * ```\n */\nexport class GoogleError extends ns.brand(LangChainError) {\n readonly name: string = \"GoogleError\";\n}\n\n/**\n * Error thrown when there is a configuration issue with the Google provider.\n *\n * This error is thrown when the Google provider encounters invalid configuration\n * parameters or settings that prevent it from functioning correctly.\n *\n * @example\n * ```typescript\n * try {\n * const model = new ChatGoogle({ invalidOption: true });\n * } catch (error) {\n * if (ConfigurationError.isInstance(error)) {\n * console.log(`Configuration error: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class ConfigurationError extends ns.brand(GoogleError, \"configuration\") {\n readonly name = \"ConfigurationError\";\n}\n\n/**\n * Parameters for constructing a PromptBlockedError\n */\ntype PromptBlockedErrorParams = {\n /**\n * The reason why the prompt was blocked (e.g., \"SAFETY\", \"OTHER\", \"UNKNOWN\")\n */\n blockReason: string;\n /**\n * Optional array of safety ratings that contributed to the block decision\n */\n safetyRatings?: Gemini.SafetyRating[];\n /**\n * Optional custom error message. If not provided, a default message will be generated\n */\n message?: string;\n};\n\n/**\n * Error thrown when a prompt is blocked by Google's safety filters.\n *\n * This error is thrown when the Gemini API blocks a prompt due to safety concerns.\n * It contains information about why the prompt was blocked and the safety ratings\n * that triggered the block.\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some potentially unsafe prompt\");\n * } catch (error) {\n * if (PromptBlockedError.isInstance(error)) {\n * console.log(`Blocked due to: ${error.blockReason}`);\n * console.log(`Safety ratings:`, error.safetyRatings);\n * }\n * }\n * ```\n */\nexport class PromptBlockedError extends ns.brand(\n GoogleError,\n \"prompt-blocked\"\n) {\n readonly name = \"PromptBlockedError\";\n\n /**\n * The reason why the prompt was blocked.\n *\n * Common values include:\n * - \"SAFETY\" - Blocked due to safety concerns\n * - \"OTHER\" - Blocked for other reasons\n * - \"UNKNOWN\" - Reason is unknown\n *\n * @readonly\n */\n readonly blockReason: string;\n\n /**\n * Optional array of safety ratings that contributed to the block decision.\n *\n * Each rating contains information about different safety categories\n * (e.g., hate speech, sexually explicit content, dangerous content)\n * and their probability levels.\n *\n * @readonly\n */\n readonly safetyRatings?: Gemini.SafetyRating[];\n\n constructor(params: PromptBlockedErrorParams) {\n const message =\n params.message ??\n `Prompt was blocked: ${params.blockReason}.${\n params.safetyRatings && params.safetyRatings.length > 0\n ? ` Safety ratings: ${JSON.stringify(params.safetyRatings)}`\n : \"\"\n }`;\n\n super(message);\n this.blockReason = params.blockReason;\n this.safetyRatings = params.safetyRatings;\n }\n\n /**\n * Creates a PromptBlockedError from a Gemini API prompt feedback object.\n *\n * This is a convenience factory method for creating errors from the API response\n * when a prompt is blocked. It extracts the relevant information from the\n * promptFeedback object returned by the Gemini API.\n *\n * @param promptFeedback - The prompt feedback object from the Gemini API response\n * @returns A new PromptBlockedError instance with information from the feedback\n *\n * @example\n * ```typescript\n * const response = await geminiApi.generateContent(request);\n * if (response.promptFeedback?.blockReason) {\n * throw PromptBlockedError.fromPromptFeedback(response.promptFeedback);\n * }\n * ```\n */\n static fromPromptFeedback(\n promptFeedback: Gemini.PromptFeedback\n ): PromptBlockedError {\n return new PromptBlockedError({\n blockReason: promptFeedback.blockReason ?? \"UNKNOWN\",\n safetyRatings: promptFeedback.safetyRatings,\n });\n }\n}\n\n/**\n * Parameters for constructing an AuthError\n */\ntype AuthErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for authentication failures when communicating with Google APIs.\n *\n * This error is thrown when authentication with a Google API fails, typically\n * during the OAuth token exchange process or when using service account credentials.\n * It captures detailed information about the failed authentication attempt including\n * the status code, headers, and response body to aid in debugging and error handling.\n *\n * Common authentication failure scenarios include:\n * - Invalid or expired credentials\n * - Incorrect service account configuration\n * - Missing or invalid API keys\n * - Insufficient permissions or scopes\n * - Token exchange failures\n *\n * @example\n * ```typescript\n * try {\n * const token = await getAccessToken(credentials);\n * } catch (error) {\n * if (AuthError.isInstance(error)) {\n * console.error(`Auth failed with status ${error.statusCode}: ${error.message}`);\n * console.error('Response data:', error.data);\n * }\n * }\n * ```\n */\nexport class AuthError extends ns.brand(GoogleError, \"auth\") {\n readonly name = \"AuthError\" as const;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: AuthErrorParams) {\n super(params.message);\n\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Creates an AuthError from a failed HTTP response.\n *\n * This is a convenience factory method for creating authentication errors from\n * HTTP responses. It automatically extracts the error message, status code,\n * headers, and response body from the Response object.\n *\n * The method attempts to parse the response body as JSON to extract an\n * `error_description` field if available. If JSON parsing fails or the\n * content type is not JSON, it falls back to reading the response as text.\n * If both fail, the error body will be null.\n *\n * @param response - The failed HTTP Response object from the authentication request\n * @returns A Promise that resolves to a new AuthError instance with information from the response\n *\n * @example\n * ```typescript\n * const response = await fetch(tokenUrl, {\n * method: 'POST',\n * body: authRequestBody\n * });\n *\n * if (!response.ok) {\n * throw await AuthError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<AuthError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error_description ??\n `Authentication failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new AuthError({\n message,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\nconst RETRYABLE_STATUS_CODES = [\n 408, // Request Timeout\n 429, // Too Many Requests\n 500, // Internal Server Error\n 502, // Bad Gateway\n 503, // Service Unavailable\n 504, // Gateway Timeout\n];\n\n/**\n * Parameters for constructing a RequestError\n */\ntype RequestErrorParams = {\n /**\n * The error message describing what went wrong\n */\n message: string;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n data?: unknown;\n};\n\n/**\n * Error class for HTTP request failures when communicating with Google APIs.\n *\n * This error is thrown when an HTTP request to a Google API endpoint fails.\n * It captures detailed information about the failed request including the URL,\n * status code, headers, and response body to aid in debugging and error handling.\n *\n * The error includes a `isRetryable()` method to determine if the request should\n * be retried based on the HTTP status code (e.g., 429 Too Many Requests, 503 Service Unavailable).\n *\n * @example\n * ```typescript\n * try {\n * const response = await apiClient.fetch(request);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * } catch (error) {\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * // Retry the request\n * }\n * }\n * ```\n */\nexport class RequestError extends ns.brand(GoogleError, \"request\") {\n readonly name = \"RequestError\" as const;\n\n /**\n * The URL of the failed request.\n * This is the full URL that was being accessed when the error occurred.\n */\n readonly url: string;\n\n /**\n * The HTTP status code of the failed response.\n * Common values include 400 (Bad Request), 401 (Unauthorized),\n * 403 (Forbidden), 404 (Not Found), 429 (Too Many Requests),\n * 500 (Internal Server Error), etc.\n */\n readonly statusCode?: number;\n\n /**\n * The HTTP status text of the failed response.\n * This is the human-readable status message that accompanies the status code\n * (e.g., \"Bad Request\", \"Internal Server Error\").\n */\n readonly statusText?: string;\n\n /**\n * The HTTP response headers from the failed request.\n * Stored as a key-value record for easy access to header information.\n */\n readonly headers?: Record<string, string>;\n\n /**\n * The response body data from the failed request.\n * This may be a parsed JSON object, a text string, or null if the body\n * could not be read. Often contains additional error details from the API.\n */\n readonly data?: unknown;\n\n constructor(params: RequestErrorParams) {\n super(params.message);\n\n this.url = params.url;\n this.statusCode = params.statusCode;\n this.statusText = params.statusText;\n this.headers = params.headers;\n this.data = params.data;\n }\n\n /**\n * Determines if this error represents a retryable request failure.\n *\n * A request is considered retryable if it failed with a status code that\n * indicates a temporary issue that might succeed on retry. This includes:\n * - 408 (Request Timeout)\n * - 429 (Too Many Requests / Rate Limiting)\n * - 500 (Internal Server Error)\n * - 502 (Bad Gateway)\n * - 503 (Service Unavailable)\n * - 504 (Gateway Timeout)\n *\n * @returns `true` if the request should be retried, `false` otherwise\n *\n * @example\n * ```typescript\n * if (RequestError.isInstance(error) && error.isRetryable()) {\n * await sleep(1000);\n * return retry(request);\n * }\n * ```\n */\n isRetryable(): boolean {\n if (!this.statusCode) return false;\n return RETRYABLE_STATUS_CODES.includes(this.statusCode);\n }\n\n /**\n * Creates a RequestError from a failed HTTP Response object.\n *\n * This is a factory method that extracts all relevant information from a\n * Response object and constructs a RequestError with appropriate details.\n * It attempts to parse the response body as JSON first, falling back to\n * text if that fails, and finally to null if the body cannot be read.\n *\n * The error message is extracted from the response body if available\n * (looking for `message` or `error` fields), otherwise a generic message\n * is constructed using the status code.\n *\n * @param response - The failed HTTP Response object to convert into an error\n * @returns A Promise that resolves to a new RequestError instance\n *\n * @example\n * ```typescript\n * const response = await fetch(url);\n * if (!response.ok) {\n * throw await RequestError.fromResponse(response);\n * }\n * ```\n */\n static async fromResponse(response: Response): Promise<RequestError> {\n const errorBody = await iife(async () => {\n try {\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (contentType.includes(\"application/json\")) {\n return await response.json();\n }\n return await response.text();\n } catch {\n return null;\n }\n });\n\n const message =\n errorBody?.error?.message ??\n errorBody?.message ??\n errorBody?.error ??\n `Request failed with status code ${response.status}`;\n\n const headers = iife(() => {\n const object: Record<string, string> = {};\n response.headers.forEach((value, name) => {\n object[name] = value;\n });\n return object;\n });\n\n return new RequestError({\n message,\n url: response.url,\n statusCode: response.status,\n statusText: response.statusText,\n headers,\n data: errorBody,\n });\n }\n}\n\n/**\n * Error thrown when the Gemini API returns no candidates in the response.\n *\n * This error is thrown when the API successfully processes a request but returns\n * an empty candidates array. This can occur when:\n * - The prompt was blocked by safety filters (but no explicit block reason was provided)\n * - An internal error occurred during generation\n * - The model was unable to generate a valid response\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke(\"some prompt\");\n * } catch (error) {\n * if (NoCandidatesError.isInstance(error)) {\n * console.log(\"No response candidates were generated\");\n * }\n * }\n * ```\n */\nexport class NoCandidatesError extends ns.brand(GoogleError, \"no-candidates\") {\n readonly name = \"NoCandidatesError\";\n\n constructor() {\n super(\n \"No candidates returned from API. This may indicate the prompt was blocked or an error occurred.\"\n );\n }\n}\n\n/**\n * Error thrown when an invalid tool is provided to the tool converter.\n *\n * This error is thrown when a tool cannot be converted to Gemini's function\n * declaration format. Tools must be one of:\n * - LangChain structured tools (with Zod schemas)\n * - OpenAI format tools (with JSON Schema)\n * - Gemini-native function declarations\n * - Gemini-native tools (codeExecution, googleSearchRetrieval)\n *\n * @example\n * ```typescript\n * try {\n * convertToolsToGeminiFunctionDeclarations([invalidTool]);\n * } catch (error) {\n * if (InvalidToolError.isInstance(error)) {\n * console.log(`Invalid tool: ${error.tool}`);\n * console.log(`Expected formats: LangChain tools, OpenAI tools, or Gemini function declarations`);\n * }\n * }\n * ```\n */\nexport class InvalidToolError extends ns.brand(GoogleError, \"invalid-tool\") {\n readonly name = \"InvalidToolError\";\n\n /**\n * The invalid tool that was provided.\n */\n readonly tool: unknown;\n\n constructor(tool: unknown, message?: string) {\n const defaultMessage = `Received invalid tool: ${JSON.stringify(\n tool\n )}. Tools must be LangChain tools, OpenAI tools, or Gemini function declarations.`;\n\n super(message ?? defaultMessage);\n this.tool = tool;\n }\n}\n\n/**\n * Error thrown when a ToolMessage references a tool call that cannot be found.\n *\n * This error is thrown when a ToolMessage is passed to ChatGoogle but there is no\n * corresponding AIMessage with a matching toolCallId in the conversation history.\n * This typically indicates that:\n * - The tool call ID in the ToolMessage doesn't match any previous tool calls\n * - The AIMessage containing the tool call was not included in the message history\n * - The tool call ID was incorrectly set or modified\n *\n * @example\n * ```typescript\n * try {\n * await model.invoke([\n * new ToolMessage({ content: \"result\", tool_call_id: \"nonexistent-id\" })\n * ]);\n * } catch (error) {\n * if (ToolCallNotFoundError.isInstance(error)) {\n * console.log(`Tool call not found: ${error.toolCallId}`);\n * }\n * }\n * ```\n */\nexport class ToolCallNotFoundError extends ns.brand(\n GoogleError,\n \"tool-call-not-found\"\n) {\n readonly name = \"ToolCallNotFoundError\";\n\n /**\n * The tool call ID that could not be found in the conversation history.\n */\n readonly toolCallId: string;\n\n constructor(toolCallId: string, message?: string) {\n const defaultMessage = `Tool call with ID \"${toolCallId}\" not found in conversation history. Ensure the corresponding AIMessage with this tool call ID is included in the input.`;\n\n super(message ?? defaultMessage);\n this.toolCallId = toolCallId;\n }\n}\n\n/**\n * Parameters for constructing a MalformedOutputError\n */\ntype MalformedOutputErrorParams = {\n /**\n * The error message describing what went wrong during parsing\n */\n message: string;\n /**\n * Optional cause of the parsing error (e.g., the original error that occurred)\n */\n cause?: unknown;\n};\n\n/**\n * Error thrown when output parsing fails in structured output methods.\n *\n * This error is thrown when the model's response cannot be parsed according to\n * the expected schema or format. Common causes include:\n * - Invalid message type (not an AIMessage or AIMessageChunk)\n * - Missing or empty content in the response\n * - Malformed JSON that cannot be parsed\n * - Schema validation failures\n *\n * @example\n * ```typescript\n * try {\n * const result = await model.withStructuredOutput(schema).invoke(\"extract data\");\n * } catch (error) {\n * if (MalformedOutputError.isInstance(error)) {\n * console.log(`Failed to parse output: ${error.message}`);\n * if (error.cause) {\n * console.log(`Cause:`, error.cause);\n * }\n * }\n * }\n * ```\n */\nexport class MalformedOutputError extends ns.brand(\n GoogleError,\n \"malformed-output\"\n) {\n readonly name = \"MalformedOutputError\";\n\n /**\n * Optional cause of the parsing error.\n * This may be the original error that occurred during parsing,\n * or additional context about what went wrong.\n */\n readonly cause?: unknown;\n\n constructor(params: MalformedOutputErrorParams) {\n super(params.message);\n this.cause = params.cause;\n }\n}\n\n/**\n * Error thrown when input provided to the Google provider is invalid.\n *\n * This error is thrown when the user provides input that cannot be\n * processed by Gemini, such as:\n * - Union types in tool/function schemas\n * - Null-only types in schemas\n * - Unsupported content block source types\n * - Missing required fields in content blocks\n *\n * @example\n * ```typescript\n * try {\n * const result = schemaToGeminiParameters(unionTypeSchema);\n * } catch (error) {\n * if (InvalidInputError.isInstance(error)) {\n * console.log(`Invalid input: ${error.message}`);\n * }\n * }\n * ```\n */\nexport class InvalidInputError extends ns.brand(GoogleError, \"invalid-input\") {\n readonly name = \"InvalidInputError\";\n}\n"],"mappings":";;;;AAKA,MAAMA,OAAKC,GAAO,IAAI,SAAS;;;;;;;;;;;;;;;;;;;AAoB/B,IAAa,cAAb,cAAiCD,KAAG,MAAM,eAAe,CAAC;CACxD,AAAS,OAAe;;;;;;;;;;;;;;;;;;;AAoB1B,IAAa,qBAAb,cAAwCA,KAAG,MAAM,aAAa,gBAAgB,CAAC;CAC7E,AAAS,OAAO;;;;;;;;;;;;;;;;;;;;;AAwClB,IAAa,qBAAb,MAAa,2BAA2BA,KAAG,MACzC,aACA,iBACD,CAAC;CACA,AAAS,OAAO;;;;;;;;;;;CAYhB,AAAS;;;;;;;;;;CAWT,AAAS;CAET,YAAY,QAAkC;EAC5C,MAAM,UACJ,OAAO,WACP,uBAAuB,OAAO,YAAY,GACxC,OAAO,iBAAiB,OAAO,cAAc,SAAS,IAClD,oBAAoB,KAAK,UAAU,OAAO,cAAc,KACxD;AAGR,QAAM,QAAQ;AACd,OAAK,cAAc,OAAO;AAC1B,OAAK,gBAAgB,OAAO;;;;;;;;;;;;;;;;;;;;CAqB9B,OAAO,mBACL,gBACoB;AACpB,SAAO,IAAI,mBAAmB;GAC5B,aAAa,eAAe,eAAe;GAC3C,eAAe,eAAe;GAC/B,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEN,IAAa,YAAb,MAAa,kBAAkBA,KAAG,MAAM,aAAa,OAAO,CAAC;CAC3D,AAAS,OAAO;;;;;;;CAQhB,AAAS;;;;;;CAOT,AAAS;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cAA0CA,KAAG,MAC3C,aACA,mBACD,CAAC;CACA,AAAS,OAAO;;;;;;CAOhB,AAAS;CAET,YAAY,QAAoC;AAC9C,QAAM,OAAO,QAAQ;AACrB,OAAK,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;;;;;;AAyBxB,IAAa,oBAAb,cAAuCA,KAAG,MAAM,aAAa,gBAAgB,CAAC;CAC5E,AAAS,OAAO"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Google integrations for LangChain.js",
|
|
5
5
|
"author": "LangChain",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"jose": "^6.1.3"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@langchain/core": "1.
|
|
22
|
+
"@langchain/core": "^1.0.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@tsconfig/recommended": "^1.0.10",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"vitest": "^3.2.4",
|
|
32
32
|
"zod": "^3.25.76 || ^4",
|
|
33
33
|
"zod-to-json-schema": "^3.24.6",
|
|
34
|
-
"@langchain/core": "^1.1.
|
|
35
|
-
"@langchain/
|
|
36
|
-
"@langchain/
|
|
34
|
+
"@langchain/core": "^1.1.27",
|
|
35
|
+
"@langchain/eslint": "0.1.1",
|
|
36
|
+
"@langchain/standard-tests": "0.0.23"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|