langchain 0.0.194 → 0.0.196
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/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/embeddings/hf.cjs +1 -2
- package/dist/embeddings/hf.js +1 -2
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/openai_assistant/index.cjs +2 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -1
- package/dist/experimental/openai_assistant/index.js +2 -1
- package/dist/experimental/openai_files/index.cjs +88 -0
- package/dist/experimental/openai_files/index.d.ts +79 -0
- package/dist/experimental/openai_files/index.js +84 -0
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/retrievers/chaindesk.cjs +9 -1
- package/dist/retrievers/chaindesk.d.ts +3 -1
- package/dist/retrievers/chaindesk.js +9 -1
- package/dist/retrievers/self_query/vectara.cjs +138 -0
- package/dist/retrievers/self_query/vectara.d.ts +41 -0
- package/dist/retrievers/self_query/vectara.js +134 -0
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/dist/vectorstores/vectara.cjs +77 -7
- package/dist/vectorstores/vectara.d.ts +9 -3
- package/dist/vectorstores/vectara.js +54 -7
- package/experimental/openai_files.cjs +1 -0
- package/experimental/openai_files.d.ts +1 -0
- package/experimental/openai_files.js +1 -0
- package/package.json +27 -5
- package/retrievers/self_query/vectara.cjs +1 -0
- package/retrievers/self_query/vectara.d.ts +1 -0
- package/retrievers/self_query/vectara.js +1 -0
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -1,124 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import PQueueMod from "p-queue";
|
|
3
|
-
const STATUS_NO_RETRY = [
|
|
4
|
-
400,
|
|
5
|
-
401,
|
|
6
|
-
402,
|
|
7
|
-
403,
|
|
8
|
-
404,
|
|
9
|
-
405,
|
|
10
|
-
406,
|
|
11
|
-
407,
|
|
12
|
-
408,
|
|
13
|
-
409, // Conflict
|
|
14
|
-
];
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
const defaultFailedAttemptHandler = (error) => {
|
|
17
|
-
if (error.message.startsWith("Cancel") ||
|
|
18
|
-
error.message.startsWith("TimeoutError") ||
|
|
19
|
-
error.name === "TimeoutError" ||
|
|
20
|
-
error.message.startsWith("AbortError") ||
|
|
21
|
-
error.name === "AbortError") {
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
-
if (error?.code === "ECONNABORTED") {
|
|
26
|
-
throw error;
|
|
27
|
-
}
|
|
28
|
-
const status =
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
error?.response?.status ?? error?.status;
|
|
31
|
-
if (status && STATUS_NO_RETRY.includes(+status)) {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
if (error?.error?.code === "insufficient_quota") {
|
|
36
|
-
const err = new Error(error?.message);
|
|
37
|
-
err.name = "InsufficientQuotaError";
|
|
38
|
-
throw err;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
43
|
-
*
|
|
44
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
45
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
46
|
-
*
|
|
47
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
48
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
49
|
-
*
|
|
50
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 6. This
|
|
51
|
-
* means that by default, each call will be retried up to 6 times, with an
|
|
52
|
-
* exponential backoff between each attempt.
|
|
53
|
-
*/
|
|
54
|
-
export class AsyncCaller {
|
|
55
|
-
constructor(params) {
|
|
56
|
-
Object.defineProperty(this, "maxConcurrency", {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
configurable: true,
|
|
59
|
-
writable: true,
|
|
60
|
-
value: void 0
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(this, "maxRetries", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(this, "onFailedAttempt", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: void 0
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(this, "queue", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: void 0
|
|
79
|
-
});
|
|
80
|
-
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
81
|
-
this.maxRetries = params.maxRetries ?? 6;
|
|
82
|
-
this.onFailedAttempt =
|
|
83
|
-
params.onFailedAttempt ?? defaultFailedAttemptHandler;
|
|
84
|
-
const PQueue = "default" in PQueueMod ? PQueueMod.default : PQueueMod;
|
|
85
|
-
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
86
|
-
}
|
|
87
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
-
call(callable, ...args) {
|
|
89
|
-
return this.queue.add(() => pRetry(() => callable(...args).catch((error) => {
|
|
90
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
91
|
-
if (error instanceof Error) {
|
|
92
|
-
throw error;
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
throw new Error(error);
|
|
96
|
-
}
|
|
97
|
-
}), {
|
|
98
|
-
onFailedAttempt: this.onFailedAttempt,
|
|
99
|
-
retries: this.maxRetries,
|
|
100
|
-
randomize: true,
|
|
101
|
-
// If needed we can change some of the defaults here,
|
|
102
|
-
// but they're quite sensible.
|
|
103
|
-
}), { throwOnTimeout: true });
|
|
104
|
-
}
|
|
105
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
|
-
callWithOptions(options, callable, ...args) {
|
|
107
|
-
// Note this doesn't cancel the underlying request,
|
|
108
|
-
// when available prefer to use the signal option of the underlying call
|
|
109
|
-
if (options.signal) {
|
|
110
|
-
return Promise.race([
|
|
111
|
-
this.call(callable, ...args),
|
|
112
|
-
new Promise((_, reject) => {
|
|
113
|
-
options.signal?.addEventListener("abort", () => {
|
|
114
|
-
reject(new Error("AbortError"));
|
|
115
|
-
});
|
|
116
|
-
}),
|
|
117
|
-
]);
|
|
118
|
-
}
|
|
119
|
-
return this.call(callable, ...args);
|
|
120
|
-
}
|
|
121
|
-
fetch(...args) {
|
|
122
|
-
return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
export * from "langchain-core/util/async_caller";
|
|
@@ -1,6 +1,30 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.VectaraStore = void 0;
|
|
27
|
+
const uuid = __importStar(require("uuid"));
|
|
4
28
|
const document_js_1 = require("../document.cjs");
|
|
5
29
|
const fake_js_1 = require("../embeddings/fake.cjs");
|
|
6
30
|
const env_js_1 = require("../util/env.cjs");
|
|
@@ -130,22 +154,64 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
130
154
|
async addVectors(_vectors, _documents) {
|
|
131
155
|
throw new Error("Method not implemented. Please call addDocuments instead.");
|
|
132
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Method to delete data from the Vectara corpus.
|
|
159
|
+
* @param params an array of document IDs to be deleted
|
|
160
|
+
* @returns Promise that resolves when the deletion is complete.
|
|
161
|
+
*/
|
|
162
|
+
async deleteDocuments(ids) {
|
|
163
|
+
if (ids && ids.length > 0) {
|
|
164
|
+
const headers = await this.getJsonHeader();
|
|
165
|
+
for (const id of ids) {
|
|
166
|
+
const data = {
|
|
167
|
+
customer_id: this.customerId,
|
|
168
|
+
corpus_id: this.corpusId[0],
|
|
169
|
+
document_id: id,
|
|
170
|
+
};
|
|
171
|
+
try {
|
|
172
|
+
const controller = new AbortController();
|
|
173
|
+
const timeout = setTimeout(() => controller.abort(), this.vectaraApiTimeoutSeconds * 1000);
|
|
174
|
+
const response = await fetch(`https://${this.apiEndpoint}/v1/delete-doc`, {
|
|
175
|
+
method: "POST",
|
|
176
|
+
headers: headers?.headers,
|
|
177
|
+
body: JSON.stringify(data),
|
|
178
|
+
signal: controller.signal,
|
|
179
|
+
});
|
|
180
|
+
clearTimeout(timeout);
|
|
181
|
+
if (response.status !== 200) {
|
|
182
|
+
throw new Error(`Vectara API returned status code ${response.status} when deleting document ${id}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (e) {
|
|
186
|
+
const error = new Error(`Error ${e.message}`);
|
|
187
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
188
|
+
error.code = 500;
|
|
189
|
+
throw error;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
throw new Error(`no "ids" specified for deletion`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
133
197
|
/**
|
|
134
198
|
* Adds documents to the Vectara store.
|
|
135
199
|
* @param documents An array of Document objects to add to the Vectara store.
|
|
136
|
-
* @returns A Promise that resolves
|
|
200
|
+
* @returns A Promise that resolves to an array of document IDs indexed in Vectara.
|
|
137
201
|
*/
|
|
138
202
|
async addDocuments(documents) {
|
|
139
203
|
if (this.corpusId.length > 1)
|
|
140
204
|
throw new Error("addDocuments does not support multiple corpus ids");
|
|
141
205
|
const headers = await this.getJsonHeader();
|
|
206
|
+
const doc_ids = [];
|
|
142
207
|
let countAdded = 0;
|
|
143
|
-
for (const
|
|
208
|
+
for (const document of documents) {
|
|
209
|
+
const doc_id = document.metadata?.document_id ?? uuid.v4();
|
|
144
210
|
const data = {
|
|
145
211
|
customer_id: this.customerId,
|
|
146
212
|
corpus_id: this.corpusId[0],
|
|
147
213
|
document: {
|
|
148
|
-
document_id:
|
|
214
|
+
document_id: doc_id,
|
|
149
215
|
title: document.metadata?.title ?? "",
|
|
150
216
|
metadata_json: JSON.stringify(document.metadata ?? {}),
|
|
151
217
|
section: [
|
|
@@ -175,6 +241,7 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
175
241
|
}
|
|
176
242
|
else {
|
|
177
243
|
countAdded += 1;
|
|
244
|
+
doc_ids.push(doc_id);
|
|
178
245
|
}
|
|
179
246
|
}
|
|
180
247
|
catch (e) {
|
|
@@ -187,6 +254,7 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
187
254
|
if (this.verbose) {
|
|
188
255
|
console.log(`Added ${countAdded} documents to Vectara`);
|
|
189
256
|
}
|
|
257
|
+
return doc_ids;
|
|
190
258
|
}
|
|
191
259
|
/**
|
|
192
260
|
* Vectara provides a way to add documents directly via their API. This API handles
|
|
@@ -200,13 +268,13 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
200
268
|
async addFiles(files, metadatas = undefined) {
|
|
201
269
|
if (this.corpusId.length > 1)
|
|
202
270
|
throw new Error("addFiles does not support multiple corpus ids");
|
|
203
|
-
|
|
271
|
+
const doc_ids = [];
|
|
204
272
|
for (const [index, file] of files.entries()) {
|
|
205
273
|
const md = metadatas ? metadatas[index] : {};
|
|
206
274
|
const data = new FormData();
|
|
207
275
|
data.append("file", file.blob, file.fileName);
|
|
208
276
|
data.append("doc-metadata", JSON.stringify(md));
|
|
209
|
-
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId[0]}`, {
|
|
277
|
+
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId[0]}&d=true`, {
|
|
210
278
|
method: "POST",
|
|
211
279
|
headers: {
|
|
212
280
|
"x-api-key": this.apiKey,
|
|
@@ -222,13 +290,15 @@ class VectaraStore extends base_js_1.VectorStore {
|
|
|
222
290
|
throw new Error(`Vectara API returned status code ${status}`);
|
|
223
291
|
}
|
|
224
292
|
else {
|
|
225
|
-
|
|
293
|
+
const result = await response.json();
|
|
294
|
+
const doc_id = result.document.documentId;
|
|
295
|
+
doc_ids.push(doc_id);
|
|
226
296
|
}
|
|
227
297
|
}
|
|
228
298
|
if (this.verbose) {
|
|
229
299
|
console.log(`Uploaded ${files.length} files to Vectara`);
|
|
230
300
|
}
|
|
231
|
-
return
|
|
301
|
+
return doc_ids;
|
|
232
302
|
}
|
|
233
303
|
/**
|
|
234
304
|
* Performs a similarity search and returns documents along with their
|
|
@@ -79,12 +79,18 @@ export declare class VectaraStore extends VectorStore {
|
|
|
79
79
|
* @returns Does not return a value.
|
|
80
80
|
*/
|
|
81
81
|
addVectors(_vectors: number[][], _documents: Document[]): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Method to delete data from the Vectara corpus.
|
|
84
|
+
* @param params an array of document IDs to be deleted
|
|
85
|
+
* @returns Promise that resolves when the deletion is complete.
|
|
86
|
+
*/
|
|
87
|
+
deleteDocuments(ids: string[]): Promise<void>;
|
|
82
88
|
/**
|
|
83
89
|
* Adds documents to the Vectara store.
|
|
84
90
|
* @param documents An array of Document objects to add to the Vectara store.
|
|
85
|
-
* @returns A Promise that resolves
|
|
91
|
+
* @returns A Promise that resolves to an array of document IDs indexed in Vectara.
|
|
86
92
|
*/
|
|
87
|
-
addDocuments(documents: Document[]): Promise<
|
|
93
|
+
addDocuments(documents: Document[]): Promise<string[]>;
|
|
88
94
|
/**
|
|
89
95
|
* Vectara provides a way to add documents directly via their API. This API handles
|
|
90
96
|
* pre-processing and chunking internally in an optimal manner. This method is a wrapper
|
|
@@ -94,7 +100,7 @@ export declare class VectaraStore extends VectorStore {
|
|
|
94
100
|
* @param metadata Optional. An array of metadata objects corresponding to each file in the `filePaths` array.
|
|
95
101
|
* @returns A Promise that resolves to the number of successfully uploaded files.
|
|
96
102
|
*/
|
|
97
|
-
addFiles(files: VectaraFile[], metadatas?: Record<string, unknown> | undefined): Promise<
|
|
103
|
+
addFiles(files: VectaraFile[], metadatas?: Record<string, unknown> | undefined): Promise<string[]>;
|
|
98
104
|
/**
|
|
99
105
|
* Performs a similarity search and returns documents along with their
|
|
100
106
|
* scores.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as uuid from "uuid";
|
|
1
2
|
import { Document } from "../document.js";
|
|
2
3
|
import { FakeEmbeddings } from "../embeddings/fake.js";
|
|
3
4
|
import { getEnvironmentVariable } from "../util/env.js";
|
|
@@ -127,22 +128,64 @@ export class VectaraStore extends VectorStore {
|
|
|
127
128
|
async addVectors(_vectors, _documents) {
|
|
128
129
|
throw new Error("Method not implemented. Please call addDocuments instead.");
|
|
129
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Method to delete data from the Vectara corpus.
|
|
133
|
+
* @param params an array of document IDs to be deleted
|
|
134
|
+
* @returns Promise that resolves when the deletion is complete.
|
|
135
|
+
*/
|
|
136
|
+
async deleteDocuments(ids) {
|
|
137
|
+
if (ids && ids.length > 0) {
|
|
138
|
+
const headers = await this.getJsonHeader();
|
|
139
|
+
for (const id of ids) {
|
|
140
|
+
const data = {
|
|
141
|
+
customer_id: this.customerId,
|
|
142
|
+
corpus_id: this.corpusId[0],
|
|
143
|
+
document_id: id,
|
|
144
|
+
};
|
|
145
|
+
try {
|
|
146
|
+
const controller = new AbortController();
|
|
147
|
+
const timeout = setTimeout(() => controller.abort(), this.vectaraApiTimeoutSeconds * 1000);
|
|
148
|
+
const response = await fetch(`https://${this.apiEndpoint}/v1/delete-doc`, {
|
|
149
|
+
method: "POST",
|
|
150
|
+
headers: headers?.headers,
|
|
151
|
+
body: JSON.stringify(data),
|
|
152
|
+
signal: controller.signal,
|
|
153
|
+
});
|
|
154
|
+
clearTimeout(timeout);
|
|
155
|
+
if (response.status !== 200) {
|
|
156
|
+
throw new Error(`Vectara API returned status code ${response.status} when deleting document ${id}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
catch (e) {
|
|
160
|
+
const error = new Error(`Error ${e.message}`);
|
|
161
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
162
|
+
error.code = 500;
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
throw new Error(`no "ids" specified for deletion`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
130
171
|
/**
|
|
131
172
|
* Adds documents to the Vectara store.
|
|
132
173
|
* @param documents An array of Document objects to add to the Vectara store.
|
|
133
|
-
* @returns A Promise that resolves
|
|
174
|
+
* @returns A Promise that resolves to an array of document IDs indexed in Vectara.
|
|
134
175
|
*/
|
|
135
176
|
async addDocuments(documents) {
|
|
136
177
|
if (this.corpusId.length > 1)
|
|
137
178
|
throw new Error("addDocuments does not support multiple corpus ids");
|
|
138
179
|
const headers = await this.getJsonHeader();
|
|
180
|
+
const doc_ids = [];
|
|
139
181
|
let countAdded = 0;
|
|
140
|
-
for (const
|
|
182
|
+
for (const document of documents) {
|
|
183
|
+
const doc_id = document.metadata?.document_id ?? uuid.v4();
|
|
141
184
|
const data = {
|
|
142
185
|
customer_id: this.customerId,
|
|
143
186
|
corpus_id: this.corpusId[0],
|
|
144
187
|
document: {
|
|
145
|
-
document_id:
|
|
188
|
+
document_id: doc_id,
|
|
146
189
|
title: document.metadata?.title ?? "",
|
|
147
190
|
metadata_json: JSON.stringify(document.metadata ?? {}),
|
|
148
191
|
section: [
|
|
@@ -172,6 +215,7 @@ export class VectaraStore extends VectorStore {
|
|
|
172
215
|
}
|
|
173
216
|
else {
|
|
174
217
|
countAdded += 1;
|
|
218
|
+
doc_ids.push(doc_id);
|
|
175
219
|
}
|
|
176
220
|
}
|
|
177
221
|
catch (e) {
|
|
@@ -184,6 +228,7 @@ export class VectaraStore extends VectorStore {
|
|
|
184
228
|
if (this.verbose) {
|
|
185
229
|
console.log(`Added ${countAdded} documents to Vectara`);
|
|
186
230
|
}
|
|
231
|
+
return doc_ids;
|
|
187
232
|
}
|
|
188
233
|
/**
|
|
189
234
|
* Vectara provides a way to add documents directly via their API. This API handles
|
|
@@ -197,13 +242,13 @@ export class VectaraStore extends VectorStore {
|
|
|
197
242
|
async addFiles(files, metadatas = undefined) {
|
|
198
243
|
if (this.corpusId.length > 1)
|
|
199
244
|
throw new Error("addFiles does not support multiple corpus ids");
|
|
200
|
-
|
|
245
|
+
const doc_ids = [];
|
|
201
246
|
for (const [index, file] of files.entries()) {
|
|
202
247
|
const md = metadatas ? metadatas[index] : {};
|
|
203
248
|
const data = new FormData();
|
|
204
249
|
data.append("file", file.blob, file.fileName);
|
|
205
250
|
data.append("doc-metadata", JSON.stringify(md));
|
|
206
|
-
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId[0]}`, {
|
|
251
|
+
const response = await fetch(`https://api.vectara.io/v1/upload?c=${this.customerId}&o=${this.corpusId[0]}&d=true`, {
|
|
207
252
|
method: "POST",
|
|
208
253
|
headers: {
|
|
209
254
|
"x-api-key": this.apiKey,
|
|
@@ -219,13 +264,15 @@ export class VectaraStore extends VectorStore {
|
|
|
219
264
|
throw new Error(`Vectara API returned status code ${status}`);
|
|
220
265
|
}
|
|
221
266
|
else {
|
|
222
|
-
|
|
267
|
+
const result = await response.json();
|
|
268
|
+
const doc_id = result.document.documentId;
|
|
269
|
+
doc_ids.push(doc_id);
|
|
223
270
|
}
|
|
224
271
|
}
|
|
225
272
|
if (this.verbose) {
|
|
226
273
|
console.log(`Uploaded ${files.length} files to Vectara`);
|
|
227
274
|
}
|
|
228
|
-
return
|
|
275
|
+
return doc_ids;
|
|
229
276
|
}
|
|
230
277
|
/**
|
|
231
278
|
* Performs a similarity search and returns documents along with their
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/experimental/openai_files/index.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/experimental/openai_files/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/experimental/openai_files/index.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.196",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -646,6 +646,9 @@
|
|
|
646
646
|
"retrievers/self_query/weaviate.cjs",
|
|
647
647
|
"retrievers/self_query/weaviate.js",
|
|
648
648
|
"retrievers/self_query/weaviate.d.ts",
|
|
649
|
+
"retrievers/self_query/vectara.cjs",
|
|
650
|
+
"retrievers/self_query/vectara.js",
|
|
651
|
+
"retrievers/self_query/vectara.d.ts",
|
|
649
652
|
"retrievers/vespa.cjs",
|
|
650
653
|
"retrievers/vespa.js",
|
|
651
654
|
"retrievers/vespa.d.ts",
|
|
@@ -766,6 +769,9 @@
|
|
|
766
769
|
"experimental/openai_assistant.cjs",
|
|
767
770
|
"experimental/openai_assistant.js",
|
|
768
771
|
"experimental/openai_assistant.d.ts",
|
|
772
|
+
"experimental/openai_files.cjs",
|
|
773
|
+
"experimental/openai_files.js",
|
|
774
|
+
"experimental/openai_files.d.ts",
|
|
769
775
|
"experimental/babyagi.cjs",
|
|
770
776
|
"experimental/babyagi.js",
|
|
771
777
|
"experimental/babyagi.d.ts",
|
|
@@ -799,6 +805,9 @@
|
|
|
799
805
|
"evaluation.cjs",
|
|
800
806
|
"evaluation.js",
|
|
801
807
|
"evaluation.d.ts",
|
|
808
|
+
"runnables.cjs",
|
|
809
|
+
"runnables.js",
|
|
810
|
+
"runnables.d.ts",
|
|
802
811
|
"runnables/remote.cjs",
|
|
803
812
|
"runnables/remote.js",
|
|
804
813
|
"runnables/remote.d.ts",
|
|
@@ -933,6 +942,7 @@
|
|
|
933
942
|
"jest": "^29.5.0",
|
|
934
943
|
"jest-environment-node": "^29.6.4",
|
|
935
944
|
"jsdom": "^22.1.0",
|
|
945
|
+
"langchain-core": "workspace:*",
|
|
936
946
|
"llmonitor": "^0.5.9",
|
|
937
947
|
"lodash": "^4.17.21",
|
|
938
948
|
"mammoth": "^1.5.1",
|
|
@@ -1369,21 +1379,18 @@
|
|
|
1369
1379
|
},
|
|
1370
1380
|
"dependencies": {
|
|
1371
1381
|
"@anthropic-ai/sdk": "^0.9.1",
|
|
1372
|
-
"ansi-styles": "^5.0.0",
|
|
1373
1382
|
"binary-extensions": "^2.2.0",
|
|
1374
|
-
"camelcase": "6",
|
|
1375
|
-
"decamelize": "^1.2.0",
|
|
1376
1383
|
"expr-eval": "^2.0.2",
|
|
1377
1384
|
"flat": "^5.0.2",
|
|
1378
1385
|
"js-tiktoken": "^1.0.7",
|
|
1379
1386
|
"js-yaml": "^4.1.0",
|
|
1380
1387
|
"jsonpointer": "^5.0.1",
|
|
1388
|
+
"langchain-core": "^0.0.1",
|
|
1381
1389
|
"langchainhub": "~0.0.6",
|
|
1382
1390
|
"langsmith": "~0.0.48",
|
|
1383
1391
|
"ml-distance": "^4.0.0",
|
|
1384
1392
|
"openai": "^4.19.0",
|
|
1385
1393
|
"openapi-types": "^12.1.3",
|
|
1386
|
-
"p-queue": "^6.6.2",
|
|
1387
1394
|
"p-retry": "4",
|
|
1388
1395
|
"uuid": "^9.0.0",
|
|
1389
1396
|
"yaml": "^2.2.1",
|
|
@@ -2468,6 +2475,11 @@
|
|
|
2468
2475
|
"import": "./retrievers/self_query/weaviate.js",
|
|
2469
2476
|
"require": "./retrievers/self_query/weaviate.cjs"
|
|
2470
2477
|
},
|
|
2478
|
+
"./retrievers/self_query/vectara": {
|
|
2479
|
+
"types": "./retrievers/self_query/vectara.d.ts",
|
|
2480
|
+
"import": "./retrievers/self_query/vectara.js",
|
|
2481
|
+
"require": "./retrievers/self_query/vectara.cjs"
|
|
2482
|
+
},
|
|
2471
2483
|
"./retrievers/vespa": {
|
|
2472
2484
|
"types": "./retrievers/vespa.d.ts",
|
|
2473
2485
|
"import": "./retrievers/vespa.js",
|
|
@@ -2668,6 +2680,11 @@
|
|
|
2668
2680
|
"import": "./experimental/openai_assistant.js",
|
|
2669
2681
|
"require": "./experimental/openai_assistant.cjs"
|
|
2670
2682
|
},
|
|
2683
|
+
"./experimental/openai_files": {
|
|
2684
|
+
"types": "./experimental/openai_files.d.ts",
|
|
2685
|
+
"import": "./experimental/openai_files.js",
|
|
2686
|
+
"require": "./experimental/openai_files.cjs"
|
|
2687
|
+
},
|
|
2671
2688
|
"./experimental/babyagi": {
|
|
2672
2689
|
"types": "./experimental/babyagi.d.ts",
|
|
2673
2690
|
"import": "./experimental/babyagi.js",
|
|
@@ -2723,6 +2740,11 @@
|
|
|
2723
2740
|
"import": "./evaluation.js",
|
|
2724
2741
|
"require": "./evaluation.cjs"
|
|
2725
2742
|
},
|
|
2743
|
+
"./runnables": {
|
|
2744
|
+
"types": "./runnables.d.ts",
|
|
2745
|
+
"import": "./runnables.js",
|
|
2746
|
+
"require": "./runnables.cjs"
|
|
2747
|
+
},
|
|
2726
2748
|
"./runnables/remote": {
|
|
2727
2749
|
"types": "./runnables/remote.d.ts",
|
|
2728
2750
|
"import": "./runnables/remote.js",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../../dist/retrievers/self_query/vectara.cjs');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/retrievers/self_query/vectara.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../../dist/retrievers/self_query/vectara.js'
|
package/runnables.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/runnables/index.cjs');
|
package/runnables.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/runnables/index.js'
|
package/runnables.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/runnables/index.js'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index.js";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index.js";
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deepCompareStrict = void 0;
|
|
4
|
-
function deepCompareStrict(a, b) {
|
|
5
|
-
const typeofa = typeof a;
|
|
6
|
-
if (typeofa !== typeof b) {
|
|
7
|
-
return false;
|
|
8
|
-
}
|
|
9
|
-
if (Array.isArray(a)) {
|
|
10
|
-
if (!Array.isArray(b)) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
const length = a.length;
|
|
14
|
-
if (length !== b.length) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
for (let i = 0; i < length; i++) {
|
|
18
|
-
if (!deepCompareStrict(a[i], b[i])) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
if (typeofa === "object") {
|
|
25
|
-
if (!a || !b) {
|
|
26
|
-
return a === b;
|
|
27
|
-
}
|
|
28
|
-
const aKeys = Object.keys(a);
|
|
29
|
-
const bKeys = Object.keys(b);
|
|
30
|
-
const length = aKeys.length;
|
|
31
|
-
if (length !== bKeys.length) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
for (const k of aKeys) {
|
|
35
|
-
if (!deepCompareStrict(a[k], b[k])) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return a === b;
|
|
42
|
-
}
|
|
43
|
-
exports.deepCompareStrict = deepCompareStrict;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function deepCompareStrict(a: any, b: any): boolean;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export function deepCompareStrict(a, b) {
|
|
2
|
-
const typeofa = typeof a;
|
|
3
|
-
if (typeofa !== typeof b) {
|
|
4
|
-
return false;
|
|
5
|
-
}
|
|
6
|
-
if (Array.isArray(a)) {
|
|
7
|
-
if (!Array.isArray(b)) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
const length = a.length;
|
|
11
|
-
if (length !== b.length) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
for (let i = 0; i < length; i++) {
|
|
15
|
-
if (!deepCompareStrict(a[i], b[i])) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
if (typeofa === "object") {
|
|
22
|
-
if (!a || !b) {
|
|
23
|
-
return a === b;
|
|
24
|
-
}
|
|
25
|
-
const aKeys = Object.keys(a);
|
|
26
|
-
const bKeys = Object.keys(b);
|
|
27
|
-
const length = aKeys.length;
|
|
28
|
-
if (length !== bKeys.length) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
for (const k of aKeys) {
|
|
32
|
-
if (!deepCompareStrict(a[k], b[k])) {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
return a === b;
|
|
39
|
-
}
|