@langchain/google-gauth 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2023 LangChain
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # LangChain google-gauth
2
+
3
+ This package contains resources to access Google AI/ML models
4
+ and other Google services. Authorization to these services use
5
+ either an API Key or service account credentials that are either
6
+ stored on the local file system or are provided through the
7
+ Google Cloud Platform environment it is running on.
8
+
9
+ If you are running this on a platform where the credentials cannot
10
+ be provided this way, consider using the @langchain/google-webauth
11
+ package *instead*. You do not need to use both packages. See the
12
+ section on **Authorization** below.
13
+
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ $ yarn add @langchain/google-gauth
19
+ ```
20
+
21
+
22
+ ## Authorization
23
+
24
+ Authorization is either done through the use of an API Key, if it is
25
+ supported for the service you're using, or a Google Cloud Service
26
+ Account.
27
+
28
+ To handle service accounts, this package uses the `google-auth-library`
29
+ package, and you may wish to consult the documentation for that library
30
+ about how it does so. But in short, classes in this package will use
31
+ credentials from the first of the following that apply:
32
+
33
+ 1. An API Key that is passed to the constructor using the `apiKey` attribute
34
+ 2. Credentials that are passed to the constructor using the `authInfo` attribute
35
+ 3. An API Key that is set in the environment variable `API_KEY`
36
+ 4. The Service Account credentials that are saved in a file. The path to
37
+ this file is set in the `GOOGLE_APPLICATION_CREDENTIALS` environment
38
+ variable.
39
+ 5. If you are running on a Google Cloud Platform resource, or if you have
40
+ logged in using `gcloud auth application-default login`, then the
41
+ default credentials.
42
+
package/dist/auth.cjs ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GAuthClient = void 0;
4
+ const google_common_1 = require("@langchain/google-common");
5
+ const google_auth_library_1 = require("google-auth-library");
6
+ class NodeJsonStream extends google_common_1.JsonStream {
7
+ constructor(data) {
8
+ super();
9
+ data.on("data", (data) => this.appendBuffer(data.toString()));
10
+ data.on("end", () => this.closeBuffer());
11
+ }
12
+ }
13
+ class GAuthClient {
14
+ constructor(fields) {
15
+ Object.defineProperty(this, "gauth", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ const options = (0, google_common_1.ensureAuthOptionScopes)(fields?.authOptions, "scopes", fields?.platformType);
22
+ this.gauth = new google_auth_library_1.GoogleAuth(options);
23
+ }
24
+ get clientType() {
25
+ return "gauth";
26
+ }
27
+ async getProjectId() {
28
+ return this.gauth.getProjectId();
29
+ }
30
+ async request(opts) {
31
+ try {
32
+ const ret = await this.gauth.request(opts);
33
+ return opts.responseType !== "stream"
34
+ ? ret
35
+ : {
36
+ ...ret,
37
+ data: new NodeJsonStream(ret.data),
38
+ };
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ }
41
+ catch (xx) {
42
+ console.error("call to gauth.request", JSON.stringify(xx, null, 2));
43
+ console.error("call to gauth.request opts=", JSON.stringify(opts, null, 2));
44
+ console.error("call to gauth.request message:", xx?.message);
45
+ throw xx;
46
+ }
47
+ }
48
+ }
49
+ exports.GAuthClient = GAuthClient;
package/dist/auth.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import { GoogleAbstractedClient, GoogleAbstractedClientOps, GoogleBaseLLMInput } from "@langchain/google-common";
2
+ import { GoogleAuth, GoogleAuthOptions } from "google-auth-library";
3
+ export declare class GAuthClient implements GoogleAbstractedClient {
4
+ gauth: GoogleAuth;
5
+ constructor(fields?: GoogleBaseLLMInput<GoogleAuthOptions>);
6
+ get clientType(): string;
7
+ getProjectId(): Promise<string>;
8
+ request(opts: GoogleAbstractedClientOps): Promise<unknown>;
9
+ }
package/dist/auth.js ADDED
@@ -0,0 +1,45 @@
1
+ import { ensureAuthOptionScopes, JsonStream, } from "@langchain/google-common";
2
+ import { GoogleAuth } from "google-auth-library";
3
+ class NodeJsonStream extends JsonStream {
4
+ constructor(data) {
5
+ super();
6
+ data.on("data", (data) => this.appendBuffer(data.toString()));
7
+ data.on("end", () => this.closeBuffer());
8
+ }
9
+ }
10
+ export class GAuthClient {
11
+ constructor(fields) {
12
+ Object.defineProperty(this, "gauth", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ const options = ensureAuthOptionScopes(fields?.authOptions, "scopes", fields?.platformType);
19
+ this.gauth = new GoogleAuth(options);
20
+ }
21
+ get clientType() {
22
+ return "gauth";
23
+ }
24
+ async getProjectId() {
25
+ return this.gauth.getProjectId();
26
+ }
27
+ async request(opts) {
28
+ try {
29
+ const ret = await this.gauth.request(opts);
30
+ return opts.responseType !== "stream"
31
+ ? ret
32
+ : {
33
+ ...ret,
34
+ data: new NodeJsonStream(ret.data),
35
+ };
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ }
38
+ catch (xx) {
39
+ console.error("call to gauth.request", JSON.stringify(xx, null, 2));
40
+ console.error("call to gauth.request opts=", JSON.stringify(opts, null, 2));
41
+ console.error("call to gauth.request message:", xx?.message);
42
+ throw xx;
43
+ }
44
+ }
45
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChatGoogle = void 0;
4
+ const google_common_1 = require("@langchain/google-common");
5
+ const auth_js_1 = require("./auth.cjs");
6
+ /**
7
+ * Integration with a chat model.
8
+ */
9
+ class ChatGoogle extends google_common_1.ChatGoogleBase {
10
+ // Used for tracing, replace with the same name as your class
11
+ static lc_name() {
12
+ return "ChatGoogle";
13
+ }
14
+ constructor(fields) {
15
+ super(fields);
16
+ }
17
+ buildAbstractedClient(fields) {
18
+ return new auth_js_1.GAuthClient(fields);
19
+ }
20
+ }
21
+ exports.ChatGoogle = ChatGoogle;
@@ -0,0 +1,15 @@
1
+ import { ChatGoogleBase, ChatGoogleBaseInput, GoogleAbstractedClient, GoogleBaseLLMInput } from "@langchain/google-common";
2
+ import { GoogleAuthOptions } from "google-auth-library";
3
+ /**
4
+ * Input to chat model class.
5
+ */
6
+ export interface ChatGoogleInput extends ChatGoogleBaseInput<GoogleAuthOptions> {
7
+ }
8
+ /**
9
+ * Integration with a chat model.
10
+ */
11
+ export declare class ChatGoogle extends ChatGoogleBase<GoogleAuthOptions> implements ChatGoogleInput {
12
+ static lc_name(): string;
13
+ constructor(fields?: ChatGoogleInput);
14
+ buildAbstractedClient(fields: GoogleBaseLLMInput<GoogleAuthOptions> | undefined): GoogleAbstractedClient;
15
+ }
@@ -0,0 +1,17 @@
1
+ import { ChatGoogleBase, } from "@langchain/google-common";
2
+ import { GAuthClient } from "./auth.js";
3
+ /**
4
+ * Integration with a chat model.
5
+ */
6
+ export class ChatGoogle extends ChatGoogleBase {
7
+ // Used for tracing, replace with the same name as your class
8
+ static lc_name() {
9
+ return "ChatGoogle";
10
+ }
11
+ constructor(fields) {
12
+ super(fields);
13
+ }
14
+ buildAbstractedClient(fields) {
15
+ return new GAuthClient(fields);
16
+ }
17
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./chat_models.cjs"), exports);
18
+ __exportStar(require("./llms.cjs"), exports);
@@ -0,0 +1,2 @@
1
+ export * from "./chat_models.js";
2
+ export * from "./llms.js";
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./chat_models.js";
2
+ export * from "./llms.js";
package/dist/llms.cjs ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GoogleLLM = void 0;
4
+ const google_common_1 = require("@langchain/google-common");
5
+ const auth_js_1 = require("./auth.cjs");
6
+ /**
7
+ * Integration with an LLM.
8
+ */
9
+ class GoogleLLM extends google_common_1.GoogleBaseLLM {
10
+ // Used for tracing, replace with the same name as your class
11
+ static lc_name() {
12
+ return "GoogleLLM";
13
+ }
14
+ constructor(fields) {
15
+ super(fields);
16
+ Object.defineProperty(this, "lc_serializable", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: true
21
+ });
22
+ }
23
+ buildAbstractedClient(fields) {
24
+ return new auth_js_1.GAuthClient(fields);
25
+ }
26
+ }
27
+ exports.GoogleLLM = GoogleLLM;
package/dist/llms.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import { GoogleAbstractedClient, GoogleBaseLLM, GoogleBaseLLMInput } from "@langchain/google-common";
2
+ import { GoogleAuthOptions } from "google-auth-library";
3
+ /**
4
+ * Input to LLM class.
5
+ */
6
+ export interface GoogleLLMInput extends GoogleBaseLLMInput<GoogleAuthOptions> {
7
+ }
8
+ /**
9
+ * Integration with an LLM.
10
+ */
11
+ export declare class GoogleLLM extends GoogleBaseLLM<GoogleAuthOptions> implements GoogleLLMInput {
12
+ static lc_name(): string;
13
+ lc_serializable: boolean;
14
+ constructor(fields?: GoogleLLMInput);
15
+ buildAbstractedClient(fields: GoogleBaseLLMInput<GoogleAuthOptions> | undefined): GoogleAbstractedClient;
16
+ }
package/dist/llms.js ADDED
@@ -0,0 +1,23 @@
1
+ import { GoogleBaseLLM, } from "@langchain/google-common";
2
+ import { GAuthClient } from "./auth.js";
3
+ /**
4
+ * Integration with an LLM.
5
+ */
6
+ export class GoogleLLM extends GoogleBaseLLM {
7
+ // Used for tracing, replace with the same name as your class
8
+ static lc_name() {
9
+ return "GoogleLLM";
10
+ }
11
+ constructor(fields) {
12
+ super(fields);
13
+ Object.defineProperty(this, "lc_serializable", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: true
18
+ });
19
+ }
20
+ buildAbstractedClient(fields) {
21
+ return new GAuthClient(fields);
22
+ }
23
+ }
package/index.cjs ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/index.cjs');
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/index.js'
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './dist/index.js'
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@langchain/google-gauth",
3
+ "version": "0.0.0",
4
+ "description": "Google auth based authentication support for Google services",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=18"
8
+ },
9
+ "main": "./index.js",
10
+ "types": "./index.d.ts",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git@github.com:langchain-ai/langchainjs.git"
14
+ },
15
+ "scripts": {
16
+ "build": "yarn run build:deps && yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts",
17
+ "build:deps": "yarn run turbo:command build --filter=@langchain/core --filter=@langchain/google-common",
18
+ "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests",
19
+ "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs",
20
+ "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch",
21
+ "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking",
22
+ "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
23
+ "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
24
+ "lint": "yarn lint:eslint && yarn lint:dpdm",
25
+ "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
26
+ "clean": "rm -rf dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn create-entrypoints -- --pre",
27
+ "prepack": "yarn build",
28
+ "test": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%",
29
+ "test:watch": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts",
30
+ "test:single": "yarn run build:deps && NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000",
31
+ "test:integration": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
32
+ "format": "prettier --config .prettierrc --write \"src\"",
33
+ "format:check": "prettier --config .prettierrc --check \"src\"",
34
+ "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist",
35
+ "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints",
36
+ "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking"
37
+ },
38
+ "author": "LangChain",
39
+ "license": "MIT",
40
+ "dependencies": {
41
+ "@langchain/core": "~0.1.1",
42
+ "@langchain/google-common": "~0.0.0",
43
+ "google-auth-library": "^8.9.0"
44
+ },
45
+ "devDependencies": {
46
+ "@jest/globals": "^29.5.0",
47
+ "@langchain/scripts": "^0.0.2",
48
+ "@swc/core": "^1.3.90",
49
+ "@swc/jest": "^0.2.29",
50
+ "@tsconfig/recommended": "^1.0.3",
51
+ "@typescript-eslint/eslint-plugin": "^6.12.0",
52
+ "@typescript-eslint/parser": "^6.12.0",
53
+ "dotenv": "^16.3.1",
54
+ "dpdm": "^3.12.0",
55
+ "eslint": "^8.33.0",
56
+ "eslint-config-airbnb-base": "^15.0.0",
57
+ "eslint-config-prettier": "^8.6.0",
58
+ "eslint-plugin-import": "^2.27.5",
59
+ "eslint-plugin-no-instanceof": "^1.0.1",
60
+ "eslint-plugin-prettier": "^4.2.1",
61
+ "jest": "^29.5.0",
62
+ "jest-environment-node": "^29.6.4",
63
+ "prettier": "^2.8.3",
64
+ "rollup": "^4.5.2",
65
+ "ts-jest": "^29.1.0",
66
+ "typescript": "<5.2.0"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public"
70
+ },
71
+ "exports": {
72
+ ".": {
73
+ "types": "./index.d.ts",
74
+ "import": "./index.js",
75
+ "require": "./index.cjs"
76
+ },
77
+ "./package.json": "./package.json"
78
+ },
79
+ "files": [
80
+ "dist/",
81
+ "index.cjs",
82
+ "index.js",
83
+ "index.d.ts"
84
+ ]
85
+ }