langchain 0.0.154 → 0.0.155
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/dist/callbacks/base.d.ts +42 -28
- package/dist/callbacks/handlers/log_stream.cjs +283 -0
- package/dist/callbacks/handlers/log_stream.d.ts +99 -0
- package/dist/callbacks/handlers/log_stream.js +277 -0
- package/dist/callbacks/handlers/tracer.cjs +34 -18
- package/dist/callbacks/handlers/tracer.d.ts +18 -16
- package/dist/callbacks/handlers/tracer.js +34 -18
- package/dist/document_loaders/web/notionapi.cjs +8 -4
- package/dist/document_loaders/web/notionapi.js +8 -4
- package/dist/document_loaders/web/searchapi.cjs +134 -0
- package/dist/document_loaders/web/searchapi.d.ts +65 -0
- package/dist/document_loaders/web/searchapi.js +130 -0
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +3 -2
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/schema/runnable/base.cjs +64 -5
- package/dist/schema/runnable/base.d.ts +13 -0
- package/dist/schema/runnable/base.js +64 -5
- package/dist/tools/index.cjs +3 -1
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/searchapi.cjs +139 -0
- package/dist/tools/searchapi.d.ts +64 -0
- package/dist/tools/searchapi.js +135 -0
- package/dist/util/fast-json-patch/index.cjs +48 -0
- package/dist/util/fast-json-patch/index.d.ts +21 -0
- package/dist/util/fast-json-patch/index.js +15 -0
- package/dist/util/fast-json-patch/src/core.cjs +469 -0
- package/dist/util/fast-json-patch/src/core.d.ts +111 -0
- package/dist/util/fast-json-patch/src/core.js +459 -0
- package/dist/util/fast-json-patch/src/helpers.cjs +194 -0
- package/dist/util/fast-json-patch/src/helpers.d.ts +36 -0
- package/dist/util/fast-json-patch/src/helpers.js +181 -0
- package/dist/util/googlevertexai-webauth.cjs +6 -2
- package/dist/util/googlevertexai-webauth.d.ts +1 -0
- package/dist/util/googlevertexai-webauth.js +6 -2
- package/dist/util/stream.cjs +2 -40
- package/dist/util/stream.d.ts +1 -2
- package/dist/util/stream.js +1 -38
- package/dist/vectorstores/pgvector.cjs +1 -1
- package/dist/vectorstores/pgvector.js +1 -1
- package/dist/vectorstores/vercel_postgres.cjs +300 -0
- package/dist/vectorstores/vercel_postgres.d.ts +145 -0
- package/dist/vectorstores/vercel_postgres.js +296 -0
- package/document_loaders/web/searchapi.cjs +1 -0
- package/document_loaders/web/searchapi.d.ts +1 -0
- package/document_loaders/web/searchapi.js +1 -0
- package/package.json +22 -1
- package/vectorstores/vercel_postgres.cjs +1 -0
- package/vectorstores/vercel_postgres.d.ts +1 -0
- package/vectorstores/vercel_postgres.js +1 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// Inlined because of ESM import issues
|
|
3
|
+
/*!
|
|
4
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
5
|
+
* (c) 2017-2022 Joachim Wester
|
|
6
|
+
* MIT licensed
|
|
7
|
+
*/
|
|
8
|
+
const _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
9
|
+
export function hasOwnProperty(obj, key) {
|
|
10
|
+
return _hasOwnProperty.call(obj, key);
|
|
11
|
+
}
|
|
12
|
+
export function _objectKeys(obj) {
|
|
13
|
+
if (Array.isArray(obj)) {
|
|
14
|
+
const keys = new Array(obj.length);
|
|
15
|
+
for (let k = 0; k < keys.length; k++) {
|
|
16
|
+
keys[k] = "" + k;
|
|
17
|
+
}
|
|
18
|
+
return keys;
|
|
19
|
+
}
|
|
20
|
+
if (Object.keys) {
|
|
21
|
+
return Object.keys(obj);
|
|
22
|
+
}
|
|
23
|
+
let keys = [];
|
|
24
|
+
for (let i in obj) {
|
|
25
|
+
if (hasOwnProperty(obj, i)) {
|
|
26
|
+
keys.push(i);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return keys;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Deeply clone the object.
|
|
33
|
+
* https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 (recursiveDeepCopy)
|
|
34
|
+
* @param {any} obj value to clone
|
|
35
|
+
* @return {any} cloned obj
|
|
36
|
+
*/
|
|
37
|
+
export function _deepClone(obj) {
|
|
38
|
+
switch (typeof obj) {
|
|
39
|
+
case "object":
|
|
40
|
+
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5
|
|
41
|
+
case "undefined":
|
|
42
|
+
return null; //this is how JSON.stringify behaves for array items
|
|
43
|
+
default:
|
|
44
|
+
return obj; //no need to clone primitives
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
//3x faster than cached /^\d+$/.test(str)
|
|
48
|
+
export function isInteger(str) {
|
|
49
|
+
let i = 0;
|
|
50
|
+
const len = str.length;
|
|
51
|
+
let charCode;
|
|
52
|
+
while (i < len) {
|
|
53
|
+
charCode = str.charCodeAt(i);
|
|
54
|
+
if (charCode >= 48 && charCode <= 57) {
|
|
55
|
+
i++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Escapes a json pointer path
|
|
64
|
+
* @param path The raw pointer
|
|
65
|
+
* @return the Escaped path
|
|
66
|
+
*/
|
|
67
|
+
export function escapePathComponent(path) {
|
|
68
|
+
if (path.indexOf("/") === -1 && path.indexOf("~") === -1)
|
|
69
|
+
return path;
|
|
70
|
+
return path.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Unescapes a json pointer path
|
|
74
|
+
* @param path The escaped pointer
|
|
75
|
+
* @return The unescaped path
|
|
76
|
+
*/
|
|
77
|
+
export function unescapePathComponent(path) {
|
|
78
|
+
return path.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
79
|
+
}
|
|
80
|
+
export function _getPathRecursive(root, obj) {
|
|
81
|
+
let found;
|
|
82
|
+
for (let key in root) {
|
|
83
|
+
if (hasOwnProperty(root, key)) {
|
|
84
|
+
if (root[key] === obj) {
|
|
85
|
+
return escapePathComponent(key) + "/";
|
|
86
|
+
}
|
|
87
|
+
else if (typeof root[key] === "object") {
|
|
88
|
+
found = _getPathRecursive(root[key], obj);
|
|
89
|
+
if (found != "") {
|
|
90
|
+
return escapePathComponent(key) + "/" + found;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return "";
|
|
96
|
+
}
|
|
97
|
+
export function getPath(root, obj) {
|
|
98
|
+
if (root === obj) {
|
|
99
|
+
return "/";
|
|
100
|
+
}
|
|
101
|
+
const path = _getPathRecursive(root, obj);
|
|
102
|
+
if (path === "") {
|
|
103
|
+
throw new Error("Object not found in root");
|
|
104
|
+
}
|
|
105
|
+
return `/${path}`;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Recursively checks whether an object has any undefined values inside.
|
|
109
|
+
*/
|
|
110
|
+
export function hasUndefined(obj) {
|
|
111
|
+
if (obj === undefined) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
if (obj) {
|
|
115
|
+
if (Array.isArray(obj)) {
|
|
116
|
+
for (let i = 0, len = obj.length; i < len; i++) {
|
|
117
|
+
if (hasUndefined(obj[i])) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (typeof obj === "object") {
|
|
123
|
+
const objKeys = _objectKeys(obj);
|
|
124
|
+
const objKeysLength = objKeys.length;
|
|
125
|
+
for (var i = 0; i < objKeysLength; i++) {
|
|
126
|
+
if (hasUndefined(obj[objKeys[i]])) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
function patchErrorMessageFormatter(message, args) {
|
|
135
|
+
const messageParts = [message];
|
|
136
|
+
for (const key in args) {
|
|
137
|
+
const value = typeof args[key] === "object"
|
|
138
|
+
? JSON.stringify(args[key], null, 2)
|
|
139
|
+
: args[key]; // pretty print
|
|
140
|
+
if (typeof value !== "undefined") {
|
|
141
|
+
messageParts.push(`${key}: ${value}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return messageParts.join("\n");
|
|
145
|
+
}
|
|
146
|
+
export class PatchError extends Error {
|
|
147
|
+
constructor(message, name, index, operation, tree) {
|
|
148
|
+
super(patchErrorMessageFormatter(message, { name, index, operation, tree }));
|
|
149
|
+
Object.defineProperty(this, "name", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
configurable: true,
|
|
152
|
+
writable: true,
|
|
153
|
+
value: name
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(this, "index", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
configurable: true,
|
|
158
|
+
writable: true,
|
|
159
|
+
value: index
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(this, "operation", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
configurable: true,
|
|
164
|
+
writable: true,
|
|
165
|
+
value: operation
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(this, "tree", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
configurable: true,
|
|
170
|
+
writable: true,
|
|
171
|
+
value: tree
|
|
172
|
+
});
|
|
173
|
+
Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain, see https://stackoverflow.com/a/48342359
|
|
174
|
+
this.message = patchErrorMessageFormatter(message, {
|
|
175
|
+
name,
|
|
176
|
+
index,
|
|
177
|
+
operation,
|
|
178
|
+
tree,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -11,19 +11,23 @@ class WebGoogleAuth {
|
|
|
11
11
|
writable: true,
|
|
12
12
|
value: void 0
|
|
13
13
|
});
|
|
14
|
+
const accessToken = options?.accessToken;
|
|
14
15
|
const credentials = options?.credentials ??
|
|
15
16
|
(0, env_js_1.getEnvironmentVariable)("GOOGLE_VERTEX_AI_WEB_CREDENTIALS");
|
|
16
17
|
if (credentials === undefined)
|
|
17
18
|
throw new Error(`Credentials not found. Please set the GOOGLE_VERTEX_AI_WEB_CREDENTIALS or pass credentials into "authOptions.credentials".`);
|
|
18
19
|
const scope = options?.scope ?? "https://www.googleapis.com/auth/cloud-platform";
|
|
19
|
-
this.options = { ...options, credentials, scope };
|
|
20
|
+
this.options = { ...options, accessToken, credentials, scope };
|
|
20
21
|
}
|
|
21
22
|
async getProjectId() {
|
|
22
23
|
const credentials = (0, google_1.getCredentials)(this.options.credentials);
|
|
23
24
|
return credentials.project_id;
|
|
24
25
|
}
|
|
25
26
|
async request(opts) {
|
|
26
|
-
|
|
27
|
+
let { accessToken } = this.options;
|
|
28
|
+
if (accessToken === undefined) {
|
|
29
|
+
accessToken = await (0, google_1.getAccessToken)(this.options);
|
|
30
|
+
}
|
|
27
31
|
if (opts.url == null)
|
|
28
32
|
throw new Error("Missing URL");
|
|
29
33
|
const fetchOptions = {
|
|
@@ -3,6 +3,7 @@ import type { GoogleVertexAIAbstractedClient } from "../types/googlevertexai-typ
|
|
|
3
3
|
export type WebGoogleAuthOptions = {
|
|
4
4
|
credentials: string | Credentials;
|
|
5
5
|
scope?: string | string[];
|
|
6
|
+
accessToken?: string;
|
|
6
7
|
};
|
|
7
8
|
export declare class WebGoogleAuth implements GoogleVertexAIAbstractedClient {
|
|
8
9
|
options: WebGoogleAuthOptions;
|
|
@@ -8,19 +8,23 @@ export class WebGoogleAuth {
|
|
|
8
8
|
writable: true,
|
|
9
9
|
value: void 0
|
|
10
10
|
});
|
|
11
|
+
const accessToken = options?.accessToken;
|
|
11
12
|
const credentials = options?.credentials ??
|
|
12
13
|
getEnvironmentVariable("GOOGLE_VERTEX_AI_WEB_CREDENTIALS");
|
|
13
14
|
if (credentials === undefined)
|
|
14
15
|
throw new Error(`Credentials not found. Please set the GOOGLE_VERTEX_AI_WEB_CREDENTIALS or pass credentials into "authOptions.credentials".`);
|
|
15
16
|
const scope = options?.scope ?? "https://www.googleapis.com/auth/cloud-platform";
|
|
16
|
-
this.options = { ...options, credentials, scope };
|
|
17
|
+
this.options = { ...options, accessToken, credentials, scope };
|
|
17
18
|
}
|
|
18
19
|
async getProjectId() {
|
|
19
20
|
const credentials = getCredentials(this.options.credentials);
|
|
20
21
|
return credentials.project_id;
|
|
21
22
|
}
|
|
22
23
|
async request(opts) {
|
|
23
|
-
|
|
24
|
+
let { accessToken } = this.options;
|
|
25
|
+
if (accessToken === undefined) {
|
|
26
|
+
accessToken = await getAccessToken(this.options);
|
|
27
|
+
}
|
|
24
28
|
if (opts.url == null)
|
|
25
29
|
throw new Error("Missing URL");
|
|
26
30
|
const fetchOptions = {
|
package/dist/util/stream.cjs
CHANGED
|
@@ -1,47 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IterableReadableStream =
|
|
3
|
+
exports.IterableReadableStream = void 0;
|
|
4
4
|
/*
|
|
5
5
|
* Support async iterator syntax for ReadableStreams in all environments.
|
|
6
6
|
* Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
7
7
|
*/
|
|
8
|
-
function readableStreamToAsyncIterable(
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
stream, preventCancel = false) {
|
|
11
|
-
if (stream[Symbol.asyncIterator]) {
|
|
12
|
-
return stream[Symbol.asyncIterator]();
|
|
13
|
-
}
|
|
14
|
-
const reader = stream.getReader();
|
|
15
|
-
return {
|
|
16
|
-
async next() {
|
|
17
|
-
try {
|
|
18
|
-
const result = await reader.read();
|
|
19
|
-
if (result.done)
|
|
20
|
-
reader.releaseLock(); // release lock when stream becomes closed
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
reader.releaseLock(); // release lock when stream becomes errored
|
|
25
|
-
throw e;
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
async return() {
|
|
29
|
-
if (!preventCancel) {
|
|
30
|
-
const cancelPromise = reader.cancel(); // cancel first, but don't await yet
|
|
31
|
-
reader.releaseLock(); // release lock first
|
|
32
|
-
await cancelPromise; // now await it
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
reader.releaseLock();
|
|
36
|
-
}
|
|
37
|
-
return { done: true, value: undefined };
|
|
38
|
-
},
|
|
39
|
-
[Symbol.asyncIterator]() {
|
|
40
|
-
return this;
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
exports.readableStreamToAsyncIterable = readableStreamToAsyncIterable;
|
|
45
8
|
class IterableReadableStream extends ReadableStream {
|
|
46
9
|
constructor() {
|
|
47
10
|
super(...arguments);
|
|
@@ -75,7 +38,7 @@ class IterableReadableStream extends ReadableStream {
|
|
|
75
38
|
const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
|
|
76
39
|
this.reader.releaseLock(); // release lock first
|
|
77
40
|
await cancelPromise; // now await it
|
|
78
|
-
return { done: true, value: undefined };
|
|
41
|
+
return { done: true, value: undefined }; // This cast fixes TS typing, and convention is to ignore chunk value anyway
|
|
79
42
|
}
|
|
80
43
|
[Symbol.asyncIterator]() {
|
|
81
44
|
return this;
|
|
@@ -86,7 +49,6 @@ class IterableReadableStream extends ReadableStream {
|
|
|
86
49
|
return new IterableReadableStream({
|
|
87
50
|
start(controller) {
|
|
88
51
|
return pump();
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
90
52
|
function pump() {
|
|
91
53
|
return reader.read().then(({ done, value }) => {
|
|
92
54
|
// When no more data needs to be consumed, close the stream
|
package/dist/util/stream.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export declare function readableStreamToAsyncIterable(stream: any, preventCancel?: boolean): any;
|
|
2
1
|
export declare class IterableReadableStream<T> extends ReadableStream<T> {
|
|
3
2
|
reader: ReadableStreamDefaultReader<T>;
|
|
4
3
|
ensureReader(): void;
|
|
5
4
|
next(): Promise<ReadableStreamReadResult<T>>;
|
|
6
5
|
return(): Promise<{
|
|
7
6
|
done: boolean;
|
|
8
|
-
value:
|
|
7
|
+
value: T;
|
|
9
8
|
}>;
|
|
10
9
|
[Symbol.asyncIterator](): this;
|
|
11
10
|
static fromReadableStream<T>(stream: ReadableStream<T>): IterableReadableStream<T>;
|
package/dist/util/stream.js
CHANGED
|
@@ -2,42 +2,6 @@
|
|
|
2
2
|
* Support async iterator syntax for ReadableStreams in all environments.
|
|
3
3
|
* Source: https://github.com/MattiasBuelens/web-streams-polyfill/pull/122#issuecomment-1627354490
|
|
4
4
|
*/
|
|
5
|
-
export function readableStreamToAsyncIterable(
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
-
stream, preventCancel = false) {
|
|
8
|
-
if (stream[Symbol.asyncIterator]) {
|
|
9
|
-
return stream[Symbol.asyncIterator]();
|
|
10
|
-
}
|
|
11
|
-
const reader = stream.getReader();
|
|
12
|
-
return {
|
|
13
|
-
async next() {
|
|
14
|
-
try {
|
|
15
|
-
const result = await reader.read();
|
|
16
|
-
if (result.done)
|
|
17
|
-
reader.releaseLock(); // release lock when stream becomes closed
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
reader.releaseLock(); // release lock when stream becomes errored
|
|
22
|
-
throw e;
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
async return() {
|
|
26
|
-
if (!preventCancel) {
|
|
27
|
-
const cancelPromise = reader.cancel(); // cancel first, but don't await yet
|
|
28
|
-
reader.releaseLock(); // release lock first
|
|
29
|
-
await cancelPromise; // now await it
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
reader.releaseLock();
|
|
33
|
-
}
|
|
34
|
-
return { done: true, value: undefined };
|
|
35
|
-
},
|
|
36
|
-
[Symbol.asyncIterator]() {
|
|
37
|
-
return this;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
5
|
export class IterableReadableStream extends ReadableStream {
|
|
42
6
|
constructor() {
|
|
43
7
|
super(...arguments);
|
|
@@ -71,7 +35,7 @@ export class IterableReadableStream extends ReadableStream {
|
|
|
71
35
|
const cancelPromise = this.reader.cancel(); // cancel first, but don't await yet
|
|
72
36
|
this.reader.releaseLock(); // release lock first
|
|
73
37
|
await cancelPromise; // now await it
|
|
74
|
-
return { done: true, value: undefined };
|
|
38
|
+
return { done: true, value: undefined }; // This cast fixes TS typing, and convention is to ignore chunk value anyway
|
|
75
39
|
}
|
|
76
40
|
[Symbol.asyncIterator]() {
|
|
77
41
|
return this;
|
|
@@ -82,7 +46,6 @@ export class IterableReadableStream extends ReadableStream {
|
|
|
82
46
|
return new IterableReadableStream({
|
|
83
47
|
start(controller) {
|
|
84
48
|
return pump();
|
|
85
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
86
49
|
function pump() {
|
|
87
50
|
return reader.read().then(({ done, value }) => {
|
|
88
51
|
// When no more data needs to be consumed, close the stream
|