@langchain/google 0.1.9 → 0.1.10
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 +6 -0
- package/dist/chat_models/base.cjs +11 -2
- package/dist/chat_models/base.cjs.map +1 -1
- package/dist/chat_models/base.d.cts +3 -56
- package/dist/chat_models/base.d.ts +3 -56
- package/dist/chat_models/base.js +11 -2
- package/dist/chat_models/base.js.map +1 -1
- package/dist/chat_models/types.d.cts +15 -1
- package/dist/chat_models/types.d.ts +15 -1
- package/dist/converters/messages.cjs.map +1 -1
- package/dist/converters/messages.js.map +1 -1
- package/dist/converters/tools.cjs.map +1 -1
- package/dist/converters/tools.js.map +1 -1
- package/dist/utils/gcp-auth.cjs.map +1 -1
- package/dist/utils/gcp-auth.js.map +1 -1
- package/dist/utils/handler.cjs.map +1 -1
- package/dist/utils/handler.js.map +1 -1
- package/package.json +5 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gcp-auth.js","names":[],"sources":["../../src/utils/gcp-auth.ts"],"sourcesContent":["/**\n * GCP authentication utilities.\n *\n * Adapted from: https://github.com/kriasoft/web-auth-library\n * Original source: web-auth-library by Kriasoft\n * License: MIT (https://github.com/kriasoft/web-auth-library/blob/main/LICENSE)\n */\n\nimport { AuthError } from \"../utils/errors.js\";\nimport { iife } from \"../utils/misc.js\";\n\ntype JoseModule = typeof import(\"jose\");\n\nlet joseModulePromise: Promise<JoseModule> | undefined;\n\nasync function getJose(): Promise<JoseModule> {\n joseModulePromise ??= import(\"jose\");\n return joseModulePromise;\n}\n\n/**\n * Google Cloud Platform service account credentials interface.\n *\n * This interface represents the structure of a GCP service account key file,\n * which is used for authenticating with Google Cloud APIs. Service account\n * keys can be downloaded from the Google Cloud Console and contain all the\n * information needed to authenticate as a service account.\n *\n * @see https://cloud.google.com/iam/docs/creating-managing-service-account-keys\n */\nexport interface GCPCredentials {\n /** The type of credential, typically \"service_account\" */\n type: string;\n /** The GCP project ID associated with this service account */\n project_id: string;\n /** The unique identifier for the private key */\n private_key_id: string;\n /** The RSA private key in PEM format used for signing JWTs */\n private_key: string;\n /** The unique client ID for this service account */\n client_id: string;\n /** The email address of the service account */\n client_email: string;\n /** The OAuth2 authorization endpoint URI */\n auth_uri: string;\n /** The OAuth2 token endpoint URI where access tokens are requested */\n token_uri: string;\n /** The URL for the OAuth2 provider's x509 certificate */\n auth_provider_x509_cert_url: string;\n /** The URL for this service account's x509 certificate */\n client_x509_cert_url: string;\n}\n\ninterface CacheValue {\n /** Unix timestamp (in seconds) when this cache entry was created */\n created: number;\n /** Promise that resolves to the token and its expiration time */\n promise: Promise<{ token: string; expires: number }>;\n}\n\nconst cache = new Map<string, CacheValue>();\nconst CACHE_MAX_AGE = 60 * 60; // 1 hour\n\n/**\n * Normalizes GCP credentials to a frozen GCPCredentials object.\n *\n * This function accepts credentials in either string (JSON) or object format\n * and ensures the returned value is a frozen (immutable) GCPCredentials object.\n * Freezing the credentials prevents accidental modification and ensures\n * consistency throughout the application lifecycle.\n *\n * @param credentials - The GCP service account credentials, either as a JSON string\n * or as a GCPCredentials object\n * @returns A frozen GCPCredentials object that cannot be modified\n *\n * @example\n * ```typescript\n * // From JSON string\n * const creds = normalizeGCPCredentials('{\"type\":\"service_account\",...}');\n *\n * // From object\n * const creds = normalizeGCPCredentials({\n * type: \"service_account\",\n * project_id: \"my-project\",\n * // ... other fields\n * });\n * ```\n */\nexport function normalizeGCPCredentials(\n credentials: string | GCPCredentials\n): GCPCredentials {\n return typeof credentials === \"string\"\n ? Object.freeze(JSON.parse(credentials))\n : Object.isFrozen(credentials)\n ? credentials\n : Object.freeze(credentials);\n}\n\n/**\n * Imports and returns the private key from GCP credentials for JWT signing.\n *\n * This function extracts the RSA private key from the service account credentials\n * and imports it using the PKCS#8 format with the RS256 algorithm. The returned\n * key can be used to sign JWTs for authentication with Google Cloud services.\n *\n * @param credentials - The GCP service account credentials containing the private key\n * @returns A Promise that resolves to the imported private key suitable for JWT signing\n *\n * @throws {Error} If the private key format is invalid or cannot be imported\n *\n * @example\n * ```typescript\n * const credentials = normalizeGCPCredentials(credentialsJson);\n * const privateKey = await getGCPPrivateKey(credentials);\n * // Use privateKey for signing operations\n * ```\n */\nexport async function getGCPPrivateKey(credentials: GCPCredentials) {\n const { importPKCS8 } = await getJose();\n return importPKCS8(credentials.private_key, \"RS256\");\n}\n\n/**\n * Generates a custom JWT token for authenticating with Google Cloud services.\n *\n * This function creates a signed JWT (JSON Web Token) using the service account's\n * private key. The token includes standard claims such as issuer, audience, subject,\n * issued-at time, and expiration time. This custom token can be exchanged for an\n * access token or ID token through Google's OAuth2 token endpoint.\n *\n * The generated JWT is valid for 1 hour and follows the OAuth 2.0 JWT Bearer\n * Token flow as specified by RFC 7523.\n *\n * @param credentials - The GCP service account credentials used to sign the JWT\n * @returns A Promise that resolves to the signed JWT string\n *\n * @throws {Error} If the private key cannot be imported or the JWT cannot be signed\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7523\n * @see https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials\n *\n * @example\n * ```typescript\n * const credentials = normalizeGCPCredentials(credentialsJson);\n * const customToken = await getGCPCustomToken(credentials);\n * // Use customToken to request an access token\n * ```\n */\nexport async function getGCPCustomToken(credentials: GCPCredentials) {\n const { SignJWT } = await getJose();\n const privateKey = await getGCPPrivateKey(credentials);\n const customToken = await new SignJWT()\n .setIssuer(credentials.client_email)\n .setAudience(credentials.token_uri)\n .setSubject(credentials.client_email)\n .setProtectedHeader({ alg: \"RS256\" })\n .setIssuedAt()\n .setExpirationTime(\"1h\")\n .sign(privateKey);\n return customToken;\n}\n\n/**\n * Retrieves an access token for authenticating with Google Cloud APIs.\n *\n * - Tokens are cached based on the token URI and private key ID\n * - Cache entries are valid for up to 1 hour\n * - Expired tokens trigger automatic refresh\n * - Multiple concurrent requests for the same token are deduplicated\n *\n * The function handles both access tokens and ID tokens, automatically detecting\n * which type is returned by the token endpoint and extracting the appropriate\n * expiration time.\n *\n * @param credentials - The GCP service account credentials used to request the token\n * @returns A Promise that resolves to the access token string\n *\n * @throws {AuthError} If the token request fails (e.g., invalid credentials,\n * network error, or API error)\n *\n * @see https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials\n * @see https://datatracker.ietf.org/doc/html/rfc7523\n *\n * @example\n * ```typescript\n * const credentials = normalizeGCPCredentials(credentialsJson);\n * const accessToken = await getGCPCredentialsAccessToken(credentials);\n *\n * // Use the access token in API requests\n * const response = await fetch('https://api.google.com/...', {\n * headers: {\n * 'Authorization': `Bearer ${accessToken}`\n * }\n * });\n * ```\n *\n * @remarks\n * The caching mechanism uses a two-level validation:\n * 1. Cache entry age (must be less than CACHE_MAX_AGE)\n * 2. Token expiration time (must not be expired)\n *\n * This ensures that even if a cache entry is fresh, an expired token\n * will trigger a refresh request.\n */\nexport async function getGCPCredentialsAccessToken(\n credentials: GCPCredentials\n): Promise<string> {\n const tokenUrl = credentials.token_uri;\n\n const cacheKeyUrl = new URL(tokenUrl);\n cacheKeyUrl.searchParams.set(\"key\", credentials.private_key_id);\n const cacheKey = cacheKeyUrl.toString();\n\n // Attempt to retrieve the token from the cache\n const cacheValue = cache.get(cacheKey);\n let now = Math.floor(Date.now() / 1000);\n\n if (cacheValue) {\n if (cacheValue.created > now - CACHE_MAX_AGE) {\n let token = await cacheValue.promise;\n\n if (token.expires > now) {\n return token.token;\n } else {\n const nextValue = cache.get(cacheKey);\n\n if (nextValue && nextValue !== cacheValue) {\n token = await nextValue.promise;\n if (token.expires > now) {\n return token.token;\n } else {\n cache.delete(cacheKey);\n }\n }\n }\n } else {\n cache.delete(cacheKey);\n }\n }\n\n const promise = iife(async () => {\n now = Math.floor(Date.now() / 1000);\n\n // Request a new token from the Google Cloud API\n const jwt = await getGCPCustomToken(credentials);\n const body = new URLSearchParams();\n body.append(\"grant_type\", \"urn:ietf:params:oauth:grant-type:jwt-bearer\");\n body.append(\"assertion\", jwt);\n const res = await fetch(tokenUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body,\n });\n\n if (!res.ok) {\n throw await AuthError.fromResponse(res);\n }\n\n const data = await res.json();\n\n if (\"id_token\" in data) {\n const { decodeJwt } = await getJose();\n const claims = decodeJwt(data.id_token);\n return { token: data.id_token, expires: claims.exp as number };\n }\n\n const lastModified = res.headers.get(\"last-modified\");\n const expires = lastModified\n ? Math.floor(new Date(lastModified).valueOf() / 1000) + data.expires_in\n : now + data.expires_in;\n\n return { expires, token: data.access_token };\n });\n\n cache.set(cacheKey, { created: now, promise });\n return await promise.then((data) => data.token);\n}\n"],"mappings":";;;;;;;;;;AAaA,IAAI;AAEJ,eAAe,UAA+B;AAC5C,uBAAsB,OAAO;AAC7B,QAAO;;AA2CT,MAAM,wBAAQ,IAAI,KAAyB;AAC3C,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BtB,SAAgB,wBACd,aACgB;AAChB,QAAO,OAAO,gBAAgB,WAC1B,OAAO,OAAO,KAAK,MAAM,YAAY,CAAC,GACtC,OAAO,SAAS,YAAY,GAC5B,cACA,OAAO,OAAO,YAAY;;;;;;;;;;;;;;;;;;;;;AAsBhC,eAAsB,iBAAiB,aAA6B;CAClE,MAAM,EAAE,gBAAgB,MAAM,SAAS;AACvC,QAAO,YAAY,YAAY,aAAa,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BtD,eAAsB,kBAAkB,aAA6B;CACnE,MAAM,EAAE,YAAY,MAAM,SAAS;CACnC,MAAM,aAAa,MAAM,iBAAiB,YAAY;AAStD,QARoB,MAAM,IAAI,SAAS,CACpC,UAAU,YAAY,aAAa,CACnC,YAAY,YAAY,UAAU,CAClC,WAAW,YAAY,aAAa,CACpC,mBAAmB,EAAE,KAAK,SAAS,CAAC,CACpC,aAAa,CACb,kBAAkB,KAAK,CACvB,KAAK,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8Cr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Aa,CAAC,SAAS,GAAG,IAAK,GAAG,KAAK,aAC3D,MAAM,KAAK;GAEG,OAAO,KAAK;GAAc;GAC5C;AAEF,OAAM,IAAI,UAAU;EAAE,SAAS;EAAK;EAAS,CAAC;AAC9C,QAAO,MAAM,QAAQ,MAAM,SAAS,KAAK,MAAM"}
|
|
1
|
+
{"version":3,"file":"gcp-auth.js","names":[],"sources":["../../src/utils/gcp-auth.ts"],"sourcesContent":["/**\n * GCP authentication utilities.\n *\n * Adapted from: https://github.com/kriasoft/web-auth-library\n * Original source: web-auth-library by Kriasoft\n * License: MIT (https://github.com/kriasoft/web-auth-library/blob/main/LICENSE)\n */\n\nimport { AuthError } from \"../utils/errors.js\";\nimport { iife } from \"../utils/misc.js\";\n\ntype JoseModule = typeof import(\"jose\");\n\nlet joseModulePromise: Promise<JoseModule> | undefined;\n\nasync function getJose(): Promise<JoseModule> {\n joseModulePromise ??= import(\"jose\");\n return joseModulePromise;\n}\n\n/**\n * Google Cloud Platform service account credentials interface.\n *\n * This interface represents the structure of a GCP service account key file,\n * which is used for authenticating with Google Cloud APIs. Service account\n * keys can be downloaded from the Google Cloud Console and contain all the\n * information needed to authenticate as a service account.\n *\n * @see https://cloud.google.com/iam/docs/creating-managing-service-account-keys\n */\nexport interface GCPCredentials {\n /** The type of credential, typically \"service_account\" */\n type: string;\n /** The GCP project ID associated with this service account */\n project_id: string;\n /** The unique identifier for the private key */\n private_key_id: string;\n /** The RSA private key in PEM format used for signing JWTs */\n private_key: string;\n /** The unique client ID for this service account */\n client_id: string;\n /** The email address of the service account */\n client_email: string;\n /** The OAuth2 authorization endpoint URI */\n auth_uri: string;\n /** The OAuth2 token endpoint URI where access tokens are requested */\n token_uri: string;\n /** The URL for the OAuth2 provider's x509 certificate */\n auth_provider_x509_cert_url: string;\n /** The URL for this service account's x509 certificate */\n client_x509_cert_url: string;\n}\n\ninterface CacheValue {\n /** Unix timestamp (in seconds) when this cache entry was created */\n created: number;\n /** Promise that resolves to the token and its expiration time */\n promise: Promise<{ token: string; expires: number }>;\n}\n\nconst cache = new Map<string, CacheValue>();\nconst CACHE_MAX_AGE = 60 * 60; // 1 hour\n\n/**\n * Normalizes GCP credentials to a frozen GCPCredentials object.\n *\n * This function accepts credentials in either string (JSON) or object format\n * and ensures the returned value is a frozen (immutable) GCPCredentials object.\n * Freezing the credentials prevents accidental modification and ensures\n * consistency throughout the application lifecycle.\n *\n * @param credentials - The GCP service account credentials, either as a JSON string\n * or as a GCPCredentials object\n * @returns A frozen GCPCredentials object that cannot be modified\n *\n * @example\n * ```typescript\n * // From JSON string\n * const creds = normalizeGCPCredentials('{\"type\":\"service_account\",...}');\n *\n * // From object\n * const creds = normalizeGCPCredentials({\n * type: \"service_account\",\n * project_id: \"my-project\",\n * // ... other fields\n * });\n * ```\n */\nexport function normalizeGCPCredentials(\n credentials: string | GCPCredentials\n): GCPCredentials {\n return typeof credentials === \"string\"\n ? Object.freeze(JSON.parse(credentials))\n : Object.isFrozen(credentials)\n ? credentials\n : Object.freeze(credentials);\n}\n\n/**\n * Imports and returns the private key from GCP credentials for JWT signing.\n *\n * This function extracts the RSA private key from the service account credentials\n * and imports it using the PKCS#8 format with the RS256 algorithm. The returned\n * key can be used to sign JWTs for authentication with Google Cloud services.\n *\n * @param credentials - The GCP service account credentials containing the private key\n * @returns A Promise that resolves to the imported private key suitable for JWT signing\n *\n * @throws {Error} If the private key format is invalid or cannot be imported\n *\n * @example\n * ```typescript\n * const credentials = normalizeGCPCredentials(credentialsJson);\n * const privateKey = await getGCPPrivateKey(credentials);\n * // Use privateKey for signing operations\n * ```\n */\nexport async function getGCPPrivateKey(credentials: GCPCredentials) {\n const { importPKCS8 } = await getJose();\n return importPKCS8(credentials.private_key, \"RS256\");\n}\n\n/**\n * Generates a custom JWT token for authenticating with Google Cloud services.\n *\n * This function creates a signed JWT (JSON Web Token) using the service account's\n * private key. The token includes standard claims such as issuer, audience, subject,\n * issued-at time, and expiration time. This custom token can be exchanged for an\n * access token or ID token through Google's OAuth2 token endpoint.\n *\n * The generated JWT is valid for 1 hour and follows the OAuth 2.0 JWT Bearer\n * Token flow as specified by RFC 7523.\n *\n * @param credentials - The GCP service account credentials used to sign the JWT\n * @returns A Promise that resolves to the signed JWT string\n *\n * @throws {Error} If the private key cannot be imported or the JWT cannot be signed\n *\n * @see https://datatracker.ietf.org/doc/html/rfc7523\n * @see https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials\n *\n * @example\n * ```typescript\n * const credentials = normalizeGCPCredentials(credentialsJson);\n * const customToken = await getGCPCustomToken(credentials);\n * // Use customToken to request an access token\n * ```\n */\nexport async function getGCPCustomToken(credentials: GCPCredentials) {\n const { SignJWT } = await getJose();\n const privateKey = await getGCPPrivateKey(credentials);\n const customToken = await new SignJWT()\n .setIssuer(credentials.client_email)\n .setAudience(credentials.token_uri)\n .setSubject(credentials.client_email)\n .setProtectedHeader({ alg: \"RS256\" })\n .setIssuedAt()\n .setExpirationTime(\"1h\")\n .sign(privateKey);\n return customToken;\n}\n\n/**\n * Retrieves an access token for authenticating with Google Cloud APIs.\n *\n * - Tokens are cached based on the token URI and private key ID\n * - Cache entries are valid for up to 1 hour\n * - Expired tokens trigger automatic refresh\n * - Multiple concurrent requests for the same token are deduplicated\n *\n * The function handles both access tokens and ID tokens, automatically detecting\n * which type is returned by the token endpoint and extracting the appropriate\n * expiration time.\n *\n * @param credentials - The GCP service account credentials used to request the token\n * @returns A Promise that resolves to the access token string\n *\n * @throws {AuthError} If the token request fails (e.g., invalid credentials,\n * network error, or API error)\n *\n * @see https://cloud.google.com/iam/docs/creating-short-lived-service-account-credentials\n * @see https://datatracker.ietf.org/doc/html/rfc7523\n *\n * @example\n * ```typescript\n * const credentials = normalizeGCPCredentials(credentialsJson);\n * const accessToken = await getGCPCredentialsAccessToken(credentials);\n *\n * // Use the access token in API requests\n * const response = await fetch('https://api.google.com/...', {\n * headers: {\n * 'Authorization': `Bearer ${accessToken}`\n * }\n * });\n * ```\n *\n * @remarks\n * The caching mechanism uses a two-level validation:\n * 1. Cache entry age (must be less than CACHE_MAX_AGE)\n * 2. Token expiration time (must not be expired)\n *\n * This ensures that even if a cache entry is fresh, an expired token\n * will trigger a refresh request.\n */\nexport async function getGCPCredentialsAccessToken(\n credentials: GCPCredentials\n): Promise<string> {\n const tokenUrl = credentials.token_uri;\n\n const cacheKeyUrl = new URL(tokenUrl);\n cacheKeyUrl.searchParams.set(\"key\", credentials.private_key_id);\n const cacheKey = cacheKeyUrl.toString();\n\n // Attempt to retrieve the token from the cache\n const cacheValue = cache.get(cacheKey);\n let now = Math.floor(Date.now() / 1000);\n\n if (cacheValue) {\n if (cacheValue.created > now - CACHE_MAX_AGE) {\n let token = await cacheValue.promise;\n\n if (token.expires > now) {\n return token.token;\n } else {\n const nextValue = cache.get(cacheKey);\n\n if (nextValue && nextValue !== cacheValue) {\n token = await nextValue.promise;\n if (token.expires > now) {\n return token.token;\n } else {\n cache.delete(cacheKey);\n }\n }\n }\n } else {\n cache.delete(cacheKey);\n }\n }\n\n const promise = iife(async () => {\n now = Math.floor(Date.now() / 1000);\n\n // Request a new token from the Google Cloud API\n const jwt = await getGCPCustomToken(credentials);\n const body = new URLSearchParams();\n body.append(\"grant_type\", \"urn:ietf:params:oauth:grant-type:jwt-bearer\");\n body.append(\"assertion\", jwt);\n const res = await fetch(tokenUrl, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/x-www-form-urlencoded\" },\n body,\n });\n\n if (!res.ok) {\n throw await AuthError.fromResponse(res);\n }\n\n const data = await res.json();\n\n if (\"id_token\" in data) {\n const { decodeJwt } = await getJose();\n const claims = decodeJwt(data.id_token);\n return { token: data.id_token, expires: claims.exp as number };\n }\n\n const lastModified = res.headers.get(\"last-modified\");\n const expires = lastModified\n ? Math.floor(new Date(lastModified).valueOf() / 1000) + data.expires_in\n : now + data.expires_in;\n\n return { expires, token: data.access_token };\n });\n\n cache.set(cacheKey, { created: now, promise });\n return await promise.then((data) => data.token);\n}\n"],"mappings":";;;;;;;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I,SAAS;AAErC,OAAI,aAAa,cAAc,YAAY;AACzC,YAAQ,MAAM,UAAU;AACxB,QAAI,MAAM,UAAU,IAClB,QAAO,MAAM;QAEb,OAAM,OAAO,SAAS;;;OAK5B,OAAM,OAAO,SAAS;CAI1B,MAAM,UAAU,KAAK,YAAY;AAC/B,QAAM,KAAK,MAAM,KAAK,KAAK,GAAG,IAAK;EAGnC,MAAM,MAAM,MAAM,kBAAkB,YAAY;EAChD,MAAM,OAAO,IAAI,iBAAiB;AAClC,OAAK,OAAO,cAAc,8CAA8C;AACxE,OAAK,OAAO,aAAa,IAAI;EAC7B,MAAM,MAAM,MAAM,MAAM,UAAU;GAChC,QAAQ;GACR,SAAS,EAAE,gBAAgB,qCAAqC;GAChE;GACD,CAAC;AAEF,MAAI,CAAC,IAAI,GACP,OAAM,MAAM,UAAU,aAAa,IAAI;EAGzC,MAAM,OAAO,MAAM,IAAI,MAAM;AAE7B,MAAI,cAAc,MAAM;GACtB,MAAM,EAAE,cAAc,MAAM,SAAS;GACrC,MAAM,SAAS,UAAU,KAAK,SAAS;AACvC,UAAO;IAAE,OAAO,KAAK;IAAU,SAAS,OAAO;IAAe;;EAGhE,MAAM,eAAe,IAAI,QAAQ,IAAI,gBAAgB;AAKrD,SAAO;GAAE,SAJO,eACZ,KAAK,MAAM,IAAI,KAAK,aAAa,CAAC,SAAS,GAAG,IAAK,GAAG,KAAK,aAC3D,MAAM,KAAK;GAEG,OAAO,KAAK;GAAc;GAC5C;AAEF,OAAM,IAAI,UAAU;EAAE,SAAS;EAAK;EAAS,CAAC;AAC9C,QAAO,MAAM,QAAQ,MAAM,SAAS,KAAK,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.cjs","names":["BaseCallbackHandler"],"sources":["../../src/utils/handler.ts"],"sourcesContent":["/*
|
|
1
|
+
{"version":3,"file":"handler.cjs","names":["BaseCallbackHandler"],"sources":["../../src/utils/handler.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport { BaseCallbackHandler } from \"@langchain/core/callbacks/base\";\n\nexport interface GoogleCustomEventInfo {\n subEvent: string;\n module: string;\n}\n\nexport abstract class GoogleRequestCallbackHandler extends BaseCallbackHandler {\n customEventInfo(eventName: string): GoogleCustomEventInfo {\n const names = eventName.split(\"-\");\n return {\n subEvent: names[1],\n module: names[2],\n };\n }\n\n abstract handleCustomRequestEvent(\n eventName: string,\n eventInfo: GoogleCustomEventInfo,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any;\n\n abstract handleCustomResponseEvent(\n eventName: string,\n eventInfo: GoogleCustomEventInfo,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any;\n\n abstract handleCustomChunkEvent(\n eventName: string,\n eventInfo: GoogleCustomEventInfo,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any;\n\n handleCustomEvent(\n eventName: string,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any {\n if (!eventName) {\n return undefined;\n }\n const eventInfo = this.customEventInfo(eventName);\n switch (eventInfo.subEvent) {\n case \"request\":\n return this.handleCustomRequestEvent(\n eventName,\n eventInfo,\n data,\n runId,\n tags,\n metadata\n );\n case \"response\":\n return this.handleCustomResponseEvent(\n eventName,\n eventInfo,\n data,\n runId,\n tags,\n metadata\n );\n case \"chunk\":\n return this.handleCustomChunkEvent(\n eventName,\n eventInfo,\n data,\n runId,\n tags,\n metadata\n );\n default:\n console.error(\n `Unexpected eventInfo for ${eventName} ${JSON.stringify(\n eventInfo,\n null,\n 1\n )}`\n );\n }\n }\n}\n\nexport class GoogleRequestLogger extends GoogleRequestCallbackHandler {\n name: string = \"GoogleRequestLogger\";\n\n shortenStringLength = 40;\n\n log(eventName: string, data: any, tags?: string[]): undefined {\n const splitLen = this.shortenStringLength;\n const half = splitLen / 2;\n const replacer = (_key: string, value: any) => {\n if (\n typeof value === \"string\" &&\n splitLen > 0 &&\n value.length > splitLen\n ) {\n return `${value.substring(0, half)}...${value.substring(\n value.length - half\n )}`;\n }\n return value;\n };\n const tagStr = tags ? `[${tags}]` : \"[]\";\n console.log(`${eventName} ${tagStr} ${JSON.stringify(data, replacer, 1)}`);\n }\n\n handleCustomRequestEvent(\n eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.log(eventName, data, tags);\n }\n\n handleCustomResponseEvent(\n eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.log(eventName, data, tags);\n }\n\n handleCustomChunkEvent(\n eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.log(eventName, data, tags);\n }\n}\n\nexport class GoogleRequestRecorder extends GoogleRequestCallbackHandler {\n name = \"GoogleRequestRecorder\";\n\n request: any = {};\n\n response: any = {};\n\n chunk: any[] = [];\n\n handleCustomRequestEvent(\n _eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n _tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.request = data;\n }\n\n handleCustomResponseEvent(\n _eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n _tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.response = data;\n }\n\n handleCustomChunkEvent(\n _eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n _tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.chunk.push(data);\n }\n}\n"],"mappings":";;AAQA,IAAsB,+BAAtB,cAA2DA,+BAAAA,oBAAoB;CAC7E,gBAAgB,WAA0C;EACxD,MAAM,QAAQ,UAAU,MAAM,IAAI;AAClC,SAAO;GACL,UAAU,MAAM;GAChB,QAAQ,MAAM;GACf;;CA8BH,kBACE,WACA,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0BACE,YACA,YACA,MACA,QACA,OACA,WACK;AACL,OAAK,WAAW;;CAGlB,uBACE,YACA,YACA,MACA,QACA,OACA,WACK;AACL,OAAK,MAAM,KAAK,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","names":[],"sources":["../../src/utils/handler.ts"],"sourcesContent":["/*
|
|
1
|
+
{"version":3,"file":"handler.js","names":[],"sources":["../../src/utils/handler.ts"],"sourcesContent":["/* oxlint-disable @typescript-eslint/no-explicit-any */\nimport { BaseCallbackHandler } from \"@langchain/core/callbacks/base\";\n\nexport interface GoogleCustomEventInfo {\n subEvent: string;\n module: string;\n}\n\nexport abstract class GoogleRequestCallbackHandler extends BaseCallbackHandler {\n customEventInfo(eventName: string): GoogleCustomEventInfo {\n const names = eventName.split(\"-\");\n return {\n subEvent: names[1],\n module: names[2],\n };\n }\n\n abstract handleCustomRequestEvent(\n eventName: string,\n eventInfo: GoogleCustomEventInfo,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any;\n\n abstract handleCustomResponseEvent(\n eventName: string,\n eventInfo: GoogleCustomEventInfo,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any;\n\n abstract handleCustomChunkEvent(\n eventName: string,\n eventInfo: GoogleCustomEventInfo,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any;\n\n handleCustomEvent(\n eventName: string,\n data: any,\n runId: string,\n tags?: string[],\n metadata?: Record<string, any>\n ): any {\n if (!eventName) {\n return undefined;\n }\n const eventInfo = this.customEventInfo(eventName);\n switch (eventInfo.subEvent) {\n case \"request\":\n return this.handleCustomRequestEvent(\n eventName,\n eventInfo,\n data,\n runId,\n tags,\n metadata\n );\n case \"response\":\n return this.handleCustomResponseEvent(\n eventName,\n eventInfo,\n data,\n runId,\n tags,\n metadata\n );\n case \"chunk\":\n return this.handleCustomChunkEvent(\n eventName,\n eventInfo,\n data,\n runId,\n tags,\n metadata\n );\n default:\n console.error(\n `Unexpected eventInfo for ${eventName} ${JSON.stringify(\n eventInfo,\n null,\n 1\n )}`\n );\n }\n }\n}\n\nexport class GoogleRequestLogger extends GoogleRequestCallbackHandler {\n name: string = \"GoogleRequestLogger\";\n\n shortenStringLength = 40;\n\n log(eventName: string, data: any, tags?: string[]): undefined {\n const splitLen = this.shortenStringLength;\n const half = splitLen / 2;\n const replacer = (_key: string, value: any) => {\n if (\n typeof value === \"string\" &&\n splitLen > 0 &&\n value.length > splitLen\n ) {\n return `${value.substring(0, half)}...${value.substring(\n value.length - half\n )}`;\n }\n return value;\n };\n const tagStr = tags ? `[${tags}]` : \"[]\";\n console.log(`${eventName} ${tagStr} ${JSON.stringify(data, replacer, 1)}`);\n }\n\n handleCustomRequestEvent(\n eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.log(eventName, data, tags);\n }\n\n handleCustomResponseEvent(\n eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.log(eventName, data, tags);\n }\n\n handleCustomChunkEvent(\n eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.log(eventName, data, tags);\n }\n}\n\nexport class GoogleRequestRecorder extends GoogleRequestCallbackHandler {\n name = \"GoogleRequestRecorder\";\n\n request: any = {};\n\n response: any = {};\n\n chunk: any[] = [];\n\n handleCustomRequestEvent(\n _eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n _tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.request = data;\n }\n\n handleCustomResponseEvent(\n _eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n _tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.response = data;\n }\n\n handleCustomChunkEvent(\n _eventName: string,\n _eventInfo: GoogleCustomEventInfo,\n data: any,\n _runId: string,\n _tags?: string[],\n _metadata?: Record<string, any>\n ): any {\n this.chunk.push(data);\n }\n}\n"],"mappings":";;AAQA,IAAsB,+BAAtB,cAA2D,oBAAoB;CAC7E,gBAAgB,WAA0C;EACxD,MAAM,QAAQ,UAAU,MAAM,IAAI;AAClC,SAAO;GACL,UAAU,MAAM;GAChB,QAAQ,MAAM;GACf;;CA8BH,kBACE,WACA,MACA,OACA,MACA,UACK;AACL,MAAI,CAAC,UACH;EAEF,MAAM,YAAY,KAAK,gBAAgB,UAAU;AACjD,UAAQ,UAAU,UAAlB;GACE,KAAK,UACH,QAAO,KAAK,yBACV,WACA,WACA,MACA,OACA,MACA,SACD;GACH,KAAK,WACH,QAAO,KAAK,0BACV,WACA,WACA,MACA,OACA,MACA,SACD;GACH,KAAK,QACH,QAAO,KAAK,uBACV,WACA,WACA,MACA,OACA,MACA,SACD;GACH,QACE,SAAQ,MACN,4BAA4B,UAAU,GAAG,KAAK,UAC5C,WACA,MACA,EACD,GACF;;;;AAKT,IAAa,sBAAb,cAAyC,6BAA6B;CACpE,OAAe;CAEf,sBAAsB;CAEtB,IAAI,WAAmB,MAAW,MAA4B;EAC5D,MAAM,WAAW,KAAK;EACtB,MAAM,OAAO,WAAW;EACxB,MAAM,YAAY,MAAc,UAAe;AAC7C,OACE,OAAO,UAAU,YACjB,WAAW,KACX,MAAM,SAAS,SAEf,QAAO,GAAG,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,MAAM,UAC5C,MAAM,SAAS,KAChB;AAEH,UAAO;;EAET,MAAM,SAAS,OAAO,IAAI,KAAK,KAAK;AACpC,UAAQ,IAAI,GAAG,UAAU,GAAG,OAAO,GAAG,KAAK,UAAU,MAAM,UAAU,EAAE,GAAG;;CAG5E,yBACE,WACA,YACA,MACA,QACA,MACA,WACK;AACL,OAAK,IAAI,WAAW,MAAM,KAAK;;CAGjC,0BACE,WACA,YACA,MACA,QACA,MACA,WACK;AACL,OAAK,IAAI,WAAW,MAAM,KAAK;;CAGjC,uBACE,WACA,YACA,MACA,QACA,MACA,WACK;AACL,OAAK,IAAI,WAAW,MAAM,KAAK;;;AAInC,IAAa,wBAAb,cAA2C,6BAA6B;CACtE,OAAO;CAEP,UAAe,EAAE;CAEjB,WAAgB,EAAE;CAElB,QAAe,EAAE;CAEjB,yBACE,YACA,YACA,MACA,QACA,OACA,WACK;AACL,OAAK,UAAU;;CAGjB,0BACE,YACA,YACA,MACA,QACA,OACA,WACK;AACL,OAAK,WAAW;;CAGlB,uBACE,YACA,YACA,MACA,QACA,OACA,WACK;AACL,OAAK,MAAM,KAAK,KAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/google",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "Google integrations for LangChain.js",
|
|
5
5
|
"author": "LangChain",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"eventsource-parser": "^3.0.6",
|
|
18
|
-
"google-auth-library": "^10.
|
|
18
|
+
"google-auth-library": "^10.6.2",
|
|
19
19
|
"jose": "^6.1.3",
|
|
20
20
|
"uuid": "^10.0.0"
|
|
21
21
|
},
|
|
@@ -25,15 +25,12 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@tsconfig/recommended": "^1.0.10",
|
|
27
27
|
"dpdm": "^3.14.0",
|
|
28
|
-
"eslint": "^9.34.0",
|
|
29
|
-
"prettier": "^2.8.3",
|
|
30
28
|
"sparktype": "^0.1.3",
|
|
31
29
|
"typescript": "~5.8.3",
|
|
32
|
-
"vitest": "^
|
|
30
|
+
"vitest": "^4.1.2",
|
|
33
31
|
"zod": "^3.25.76 || ^4",
|
|
34
|
-
"zod-to-json-schema": "^3.
|
|
35
|
-
"@langchain/core": "^1.1.
|
|
36
|
-
"@langchain/eslint": "0.1.1",
|
|
32
|
+
"zod-to-json-schema": "^3.25.2",
|
|
33
|
+
"@langchain/core": "^1.1.39",
|
|
37
34
|
"@langchain/standard-tests": "0.0.23"
|
|
38
35
|
},
|
|
39
36
|
"publishConfig": {
|
|
@@ -76,10 +73,6 @@
|
|
|
76
73
|
"scripts": {
|
|
77
74
|
"build": "turbo build:compile --filter @langchain/google --output-logs new-only",
|
|
78
75
|
"build:compile": "tsdown",
|
|
79
|
-
"lint:eslint": "eslint --cache src/",
|
|
80
|
-
"lint:dpdm": "dpdm --skip-dynamic-imports circular --exit-code circular:1 --no-warning --no-tree src/**/*.ts",
|
|
81
|
-
"lint": "pnpm lint:eslint && pnpm lint:dpdm",
|
|
82
|
-
"lint:fix": "pnpm lint:eslint --fix && pnpm lint:dpdm",
|
|
83
76
|
"clean": "rm -rf .turbo dist/",
|
|
84
77
|
"test": "vitest run",
|
|
85
78
|
"test:watch": "vitest",
|
|
@@ -87,8 +80,6 @@
|
|
|
87
80
|
"test:standard:unit": "vitest run --mode standard-unit",
|
|
88
81
|
"test:standard:int": "vitest run --mode standard-int",
|
|
89
82
|
"test:standard": "pnpm test:standard:unit && pnpm test:standard:int",
|
|
90
|
-
"format": "prettier --config .prettierrc --write \"src\"",
|
|
91
|
-
"format:check": "prettier --config .prettierrc --check \"src\"",
|
|
92
83
|
"typegen": "pnpm run typegen:sparktype && pnpm run typegen:profiles",
|
|
93
84
|
"typegen:sparktype": "sparktype generate",
|
|
94
85
|
"typegen:profiles": "pnpm --filter @langchain/model-profiles make --config profiles.toml",
|