langchain 0.0.147 → 0.0.149
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/chat_models/googlevertexai/web.cjs +1 -0
- package/chat_models/googlevertexai/web.d.ts +1 -0
- package/chat_models/googlevertexai/web.js +1 -0
- package/chat_models/googlevertexai.cjs +1 -1
- package/chat_models/googlevertexai.d.ts +1 -1
- package/chat_models/googlevertexai.js +1 -1
- package/dist/chains/constitutional_ai/constitutional_principle.cjs +272 -1
- package/dist/chains/constitutional_ai/constitutional_principle.js +272 -1
- package/dist/chains/question_answering/load.cjs +12 -4
- package/dist/chains/question_answering/load.d.ts +2 -0
- package/dist/chains/question_answering/load.js +12 -4
- package/dist/chains/summarization/load.cjs +8 -4
- package/dist/chains/summarization/load.d.ts +2 -0
- package/dist/chains/summarization/load.js +8 -4
- package/dist/chat_models/{googlevertexai.cjs → googlevertexai/common.cjs} +14 -26
- package/dist/chat_models/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -22
- package/dist/chat_models/{googlevertexai.js → googlevertexai/common.js} +12 -24
- package/dist/chat_models/googlevertexai/index.cjs +36 -0
- package/dist/chat_models/googlevertexai/index.d.ts +21 -0
- package/dist/chat_models/googlevertexai/index.js +31 -0
- package/dist/chat_models/googlevertexai/web.cjs +33 -0
- package/dist/chat_models/googlevertexai/web.d.ts +19 -0
- package/dist/chat_models/googlevertexai/web.js +28 -0
- package/dist/document_loaders/web/notionapi.cjs +93 -70
- package/dist/document_loaders/web/notionapi.d.ts +33 -1
- package/dist/document_loaders/web/notionapi.js +89 -71
- package/dist/embeddings/googlevertexai.cjs +5 -1
- package/dist/embeddings/googlevertexai.d.ts +2 -1
- package/dist/embeddings/googlevertexai.js +5 -1
- package/dist/evaluation/agents/index.cjs +17 -0
- package/dist/evaluation/agents/index.d.ts +1 -0
- package/dist/evaluation/agents/index.js +1 -0
- package/dist/evaluation/agents/prompt.cjs +132 -0
- package/dist/evaluation/agents/prompt.d.ts +6 -0
- package/dist/evaluation/agents/prompt.js +129 -0
- package/dist/evaluation/agents/trajectory.cjs +189 -0
- package/dist/evaluation/agents/trajectory.d.ts +54 -0
- package/dist/evaluation/agents/trajectory.js +184 -0
- package/dist/evaluation/base.cjs +274 -0
- package/dist/evaluation/base.d.ts +232 -0
- package/dist/evaluation/base.js +263 -0
- package/dist/evaluation/comparison/index.cjs +17 -0
- package/dist/evaluation/comparison/index.d.ts +1 -0
- package/dist/evaluation/comparison/index.js +1 -0
- package/dist/evaluation/comparison/pairwise.cjs +244 -0
- package/dist/evaluation/comparison/pairwise.d.ts +50 -0
- package/dist/evaluation/comparison/pairwise.js +238 -0
- package/dist/evaluation/comparison/prompt.cjs +74 -0
- package/dist/evaluation/comparison/prompt.d.ts +21 -0
- package/dist/evaluation/comparison/prompt.js +71 -0
- package/dist/evaluation/criteria/criteria.cjs +259 -0
- package/dist/evaluation/criteria/criteria.d.ts +73 -0
- package/dist/evaluation/criteria/criteria.js +253 -0
- package/dist/evaluation/criteria/index.cjs +17 -0
- package/dist/evaluation/criteria/index.d.ts +1 -0
- package/dist/evaluation/criteria/index.js +1 -0
- package/dist/evaluation/criteria/prompt.cjs +36 -0
- package/dist/evaluation/criteria/prompt.d.ts +12 -0
- package/dist/evaluation/criteria/prompt.js +33 -0
- package/dist/evaluation/embedding_distance/base.cjs +163 -0
- package/dist/evaluation/embedding_distance/base.d.ts +78 -0
- package/dist/evaluation/embedding_distance/base.js +156 -0
- package/dist/evaluation/embedding_distance/index.cjs +17 -0
- package/dist/evaluation/embedding_distance/index.d.ts +1 -0
- package/dist/evaluation/embedding_distance/index.js +1 -0
- package/dist/evaluation/index.cjs +6 -0
- package/dist/evaluation/index.d.ts +6 -0
- package/dist/evaluation/index.js +6 -0
- package/dist/evaluation/loader.cjs +60 -0
- package/dist/evaluation/loader.d.ts +27 -0
- package/dist/evaluation/loader.js +56 -0
- package/dist/evaluation/types.cjs +2 -0
- package/dist/evaluation/types.d.ts +35 -0
- package/dist/evaluation/types.js +1 -0
- package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +5 -1
- package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -1
- package/dist/experimental/multimodal_embeddings/googlevertexai.js +5 -1
- package/dist/llms/bedrock.cjs +9 -1
- package/dist/llms/bedrock.d.ts +3 -0
- package/dist/llms/bedrock.js +9 -1
- package/dist/llms/{googlevertexai.js → googlevertexai/common.cjs} +21 -17
- package/dist/llms/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -23
- package/dist/llms/{googlevertexai.cjs → googlevertexai/common.js} +17 -21
- package/dist/llms/googlevertexai/index.cjs +34 -0
- package/dist/llms/googlevertexai/index.d.ts +26 -0
- package/dist/llms/googlevertexai/index.js +30 -0
- package/dist/llms/googlevertexai/web.cjs +31 -0
- package/dist/llms/googlevertexai/web.d.ts +24 -0
- package/dist/llms/googlevertexai/web.js +27 -0
- package/dist/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/load/serializable.cjs +23 -4
- package/dist/load/serializable.js +23 -4
- package/dist/retrievers/multi_query.cjs +140 -0
- package/dist/retrievers/multi_query.d.ts +33 -0
- package/dist/retrievers/multi_query.js +136 -0
- package/dist/retrievers/self_query/base.cjs +1 -1
- package/dist/retrievers/self_query/base.js +2 -2
- package/dist/retrievers/self_query/functional.cjs +1 -1
- package/dist/retrievers/self_query/functional.js +2 -2
- package/dist/retrievers/self_query/utils.cjs +46 -6
- package/dist/retrievers/self_query/utils.d.ts +7 -0
- package/dist/retrievers/self_query/utils.js +44 -5
- package/dist/schema/runnable/base.cjs +910 -0
- package/dist/schema/runnable/base.d.ts +300 -0
- package/dist/schema/runnable/base.js +896 -0
- package/dist/schema/runnable/index.cjs +19 -926
- package/dist/schema/runnable/index.d.ts +4 -298
- package/dist/schema/runnable/index.js +3 -914
- package/dist/schema/runnable/passthrough.cjs +31 -0
- package/dist/schema/runnable/passthrough.d.ts +11 -0
- package/dist/schema/runnable/passthrough.js +27 -0
- package/dist/schema/runnable/router.cjs +74 -0
- package/dist/schema/runnable/router.d.ts +29 -0
- package/dist/schema/runnable/router.js +70 -0
- package/dist/types/googlevertexai-types.d.ts +11 -4
- package/dist/util/googlevertexai-connection.cjs +14 -15
- package/dist/util/googlevertexai-connection.d.ts +7 -7
- package/dist/util/googlevertexai-connection.js +14 -15
- package/dist/util/googlevertexai-webauth.cjs +56 -0
- package/dist/util/googlevertexai-webauth.d.ts +25 -0
- package/dist/util/googlevertexai-webauth.js +52 -0
- package/dist/vectorstores/googlevertexai.cjs +9 -8
- package/dist/vectorstores/googlevertexai.d.ts +8 -7
- package/dist/vectorstores/googlevertexai.js +9 -8
- package/dist/vectorstores/opensearch.cjs +4 -2
- package/dist/vectorstores/opensearch.d.ts +4 -1
- package/dist/vectorstores/opensearch.js +4 -2
- package/llms/googlevertexai/web.cjs +1 -0
- package/llms/googlevertexai/web.d.ts +1 -0
- package/llms/googlevertexai/web.js +1 -0
- package/llms/googlevertexai.cjs +1 -1
- package/llms/googlevertexai.d.ts +1 -1
- package/llms/googlevertexai.js +1 -1
- package/package.json +32 -3
- package/retrievers/multi_query.cjs +1 -0
- package/retrievers/multi_query.d.ts +1 -0
- package/retrievers/multi_query.js +1 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NotionAPILoader = void 0;
|
|
3
|
+
exports.NotionAPILoader = exports.isDatabase = exports.isPage = exports.isErrorResponse = exports.isDatabaseResponse = exports.isPageResponse = void 0;
|
|
4
4
|
const client_1 = require("@notionhq/client");
|
|
5
5
|
const notion_to_md_1 = require("notion-to-md");
|
|
6
6
|
const notion_js_1 = require("notion-to-md/build/utils/notion.js");
|
|
@@ -8,18 +8,15 @@ const document_js_1 = require("../../document.cjs");
|
|
|
8
8
|
const base_js_1 = require("../base.cjs");
|
|
9
9
|
const async_caller_js_1 = require("../../util/async_caller.cjs");
|
|
10
10
|
const isPageResponse = (res) => !(0, client_1.isNotionClientError)(res) && res.object === "page";
|
|
11
|
+
exports.isPageResponse = isPageResponse;
|
|
11
12
|
const isDatabaseResponse = (res) => !(0, client_1.isNotionClientError)(res) && res.object === "database";
|
|
13
|
+
exports.isDatabaseResponse = isDatabaseResponse;
|
|
12
14
|
const isErrorResponse = (res) => (0, client_1.isNotionClientError)(res);
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
if (isDatabase(obj))
|
|
20
|
-
return obj.title[0]?.plain_text;
|
|
21
|
-
return null;
|
|
22
|
-
};
|
|
15
|
+
exports.isErrorResponse = isErrorResponse;
|
|
16
|
+
const isPage = (res) => (0, exports.isPageResponse)(res) && (0, client_1.isFullPage)(res);
|
|
17
|
+
exports.isPage = isPage;
|
|
18
|
+
const isDatabase = (res) => (0, exports.isDatabaseResponse)(res) && (0, client_1.isFullDatabase)(res);
|
|
19
|
+
exports.isDatabase = isDatabase;
|
|
23
20
|
/**
|
|
24
21
|
* A class that extends the BaseDocumentLoader class. It represents a
|
|
25
22
|
* document loader for loading documents from Notion using the Notion API.
|
|
@@ -107,11 +104,85 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
|
|
|
107
104
|
this.rootTitle = "";
|
|
108
105
|
this.onDocumentLoaded = options.onDocumentLoaded ?? ((_ti, _cu) => { });
|
|
109
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Adds a selection of page ids to the pageQueue and removes duplicates.
|
|
109
|
+
* @param items An array of string ids
|
|
110
|
+
*/
|
|
110
111
|
addToQueue(...items) {
|
|
111
112
|
const deDuped = items.filter((item) => !this.pageCompleted.concat(this.pageQueue).includes(item));
|
|
112
113
|
this.pageQueue.push(...deDuped);
|
|
113
114
|
this.pageQueueTotal += deDuped.length;
|
|
114
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Parses a Notion GetResponse object (page or database) and returns a string of the title.
|
|
118
|
+
* @param obj The Notion GetResponse object to parse.
|
|
119
|
+
* @returns The string of the title.
|
|
120
|
+
*/
|
|
121
|
+
getTitle(obj) {
|
|
122
|
+
if ((0, exports.isPage)(obj) && obj.properties.title.type === "title") {
|
|
123
|
+
return obj.properties.title.title[0]?.plain_text;
|
|
124
|
+
}
|
|
125
|
+
if ((0, exports.isDatabase)(obj))
|
|
126
|
+
return obj.title[0]?.plain_text;
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Parses the property type and returns a string
|
|
131
|
+
* @param page The Notion page property to parse.
|
|
132
|
+
* @returns A string of parsed property.
|
|
133
|
+
*/
|
|
134
|
+
getPropValue(prop) {
|
|
135
|
+
switch (prop.type) {
|
|
136
|
+
case "number": {
|
|
137
|
+
const propNumber = prop[prop.type];
|
|
138
|
+
return propNumber !== null ? propNumber.toString() : "";
|
|
139
|
+
}
|
|
140
|
+
case "url":
|
|
141
|
+
return prop[prop.type] || "";
|
|
142
|
+
case "select":
|
|
143
|
+
return prop[prop.type]?.name ?? "";
|
|
144
|
+
case "multi_select":
|
|
145
|
+
return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
|
|
146
|
+
case "status":
|
|
147
|
+
return prop[prop.type]?.name ?? "";
|
|
148
|
+
case "date":
|
|
149
|
+
return `${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? ` - ${prop[prop.type]?.end}` : ""}`;
|
|
150
|
+
case "email":
|
|
151
|
+
return prop[prop.type] || "";
|
|
152
|
+
case "phone_number":
|
|
153
|
+
return prop[prop.type] || "";
|
|
154
|
+
case "checkbox":
|
|
155
|
+
return prop[prop.type].toString();
|
|
156
|
+
case "files":
|
|
157
|
+
return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
|
|
158
|
+
case "created_by":
|
|
159
|
+
return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
|
|
160
|
+
case "created_time":
|
|
161
|
+
return prop[prop.type];
|
|
162
|
+
case "last_edited_by":
|
|
163
|
+
return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
|
|
164
|
+
case "last_edited_time":
|
|
165
|
+
return prop[prop.type];
|
|
166
|
+
case "title":
|
|
167
|
+
return prop[prop.type]
|
|
168
|
+
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
169
|
+
.join("");
|
|
170
|
+
case "rich_text":
|
|
171
|
+
return prop[prop.type]
|
|
172
|
+
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
173
|
+
.join("");
|
|
174
|
+
case "people":
|
|
175
|
+
return `[${prop[prop.type]
|
|
176
|
+
.map((v) => `["${v.object}", "${v.id}"]`)
|
|
177
|
+
.join(", ")}]`;
|
|
178
|
+
case "unique_id":
|
|
179
|
+
return `${prop[prop.type].prefix || ""}${prop[prop.type].number}`;
|
|
180
|
+
case "relation":
|
|
181
|
+
return `[${prop[prop.type].map((v) => `"${v.id}"`).join(", ")}]`;
|
|
182
|
+
default:
|
|
183
|
+
return `Unsupported type: ${prop.type}`;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
115
186
|
/**
|
|
116
187
|
* Parses the properties of a Notion page and returns them as key-value
|
|
117
188
|
* pairs.
|
|
@@ -119,60 +190,11 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
|
|
|
119
190
|
* @returns An object containing the parsed properties as key-value pairs.
|
|
120
191
|
*/
|
|
121
192
|
parsePageProperties(page) {
|
|
122
|
-
return Object.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return [prop.type, prop[prop.type]];
|
|
128
|
-
case "select":
|
|
129
|
-
return [prop.type, prop[prop.type]?.name ?? ""];
|
|
130
|
-
case "multi_select":
|
|
131
|
-
return [
|
|
132
|
-
prop.type,
|
|
133
|
-
prop[prop.type].map((select) => select.name).join(", "),
|
|
134
|
-
];
|
|
135
|
-
case "status":
|
|
136
|
-
return [prop.type, prop[prop.type]?.name ?? ""];
|
|
137
|
-
case "date":
|
|
138
|
-
return [
|
|
139
|
-
prop.type,
|
|
140
|
-
`${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? `- ${prop[prop.type]?.end}` : ""}`,
|
|
141
|
-
];
|
|
142
|
-
case "email":
|
|
143
|
-
return [prop.type, prop[prop.type]];
|
|
144
|
-
case "phone_number":
|
|
145
|
-
return [prop.type, prop[prop.type]];
|
|
146
|
-
case "checkbox":
|
|
147
|
-
return [prop.type, prop[prop.type].toString()];
|
|
148
|
-
// case "files":
|
|
149
|
-
case "created_by":
|
|
150
|
-
return [prop.type, prop[prop.type]];
|
|
151
|
-
case "created_time":
|
|
152
|
-
return [prop.type, prop[prop.type]];
|
|
153
|
-
case "last_edited_by":
|
|
154
|
-
return [prop.type, prop[prop.type]];
|
|
155
|
-
case "last_edited_time":
|
|
156
|
-
return [prop.type, prop[prop.type]];
|
|
157
|
-
// case "formula":
|
|
158
|
-
case "title":
|
|
159
|
-
return [
|
|
160
|
-
prop.type,
|
|
161
|
-
prop[prop.type].map((v) => v.plain_text).join(""),
|
|
162
|
-
];
|
|
163
|
-
case "rich_text":
|
|
164
|
-
return [
|
|
165
|
-
prop.type,
|
|
166
|
-
prop[prop.type].map((v) => v.plain_text).join(""),
|
|
167
|
-
];
|
|
168
|
-
case "people":
|
|
169
|
-
return [prop.type, prop[prop.type]];
|
|
170
|
-
// case "relation":
|
|
171
|
-
// case "rollup":
|
|
172
|
-
default:
|
|
173
|
-
return [prop.type, "Unsupported type"];
|
|
174
|
-
}
|
|
175
|
-
}));
|
|
193
|
+
return Object.entries(page.properties).reduce((accum, [propName, prop]) => {
|
|
194
|
+
const value = this.getPropValue(prop);
|
|
195
|
+
const props = { ...accum, [propName]: value };
|
|
196
|
+
return prop.type === "title" ? { ...props, _title: value } : props;
|
|
197
|
+
}, {});
|
|
176
198
|
}
|
|
177
199
|
/**
|
|
178
200
|
* Parses the details of a Notion page and returns them as an object.
|
|
@@ -180,10 +202,10 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
|
|
|
180
202
|
* @returns An object containing the parsed details of the page.
|
|
181
203
|
*/
|
|
182
204
|
parsePageDetails(page) {
|
|
183
|
-
const
|
|
205
|
+
const { id, ...rest } = page;
|
|
184
206
|
return {
|
|
185
|
-
...
|
|
186
|
-
notionId:
|
|
207
|
+
...rest,
|
|
208
|
+
notionId: id,
|
|
187
209
|
properties: this.parsePageProperties(page),
|
|
188
210
|
};
|
|
189
211
|
}
|
|
@@ -306,7 +328,7 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
|
|
|
306
328
|
resDatabasePromise,
|
|
307
329
|
]);
|
|
308
330
|
// Check if both resPage and resDatabase resulted in error responses
|
|
309
|
-
const errors = [resPage, resDatabase].filter(isErrorResponse);
|
|
331
|
+
const errors = [resPage, resDatabase].filter(exports.isErrorResponse);
|
|
310
332
|
if (errors.length === 2) {
|
|
311
333
|
if (errors.every((e) => e.code === client_1.APIErrorCode.ObjectNotFound)) {
|
|
312
334
|
throw new AggregateError([
|
|
@@ -316,7 +338,8 @@ class NotionAPILoader extends base_js_1.BaseDocumentLoader {
|
|
|
316
338
|
}
|
|
317
339
|
throw new AggregateError(errors);
|
|
318
340
|
}
|
|
319
|
-
this.rootTitle =
|
|
341
|
+
this.rootTitle =
|
|
342
|
+
this.getTitle(resPage) || this.getTitle(resDatabase) || this.id;
|
|
320
343
|
let pageId = this.pageQueue.shift();
|
|
321
344
|
while (pageId) {
|
|
322
345
|
await this.loadPage(pageId);
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
import { Client } from "@notionhq/client";
|
|
1
|
+
import { APIResponseError, Client, isFullBlock, isFullPage, isFullDatabase } from "@notionhq/client";
|
|
2
2
|
import { Document } from "../../document.js";
|
|
3
3
|
import { BaseDocumentLoader } from "../base.js";
|
|
4
4
|
import { AsyncCaller } from "../../util/async_caller.js";
|
|
5
|
+
type GuardType<T> = T extends (x: any, ...rest: any) => x is infer U ? U : never;
|
|
6
|
+
export type GetBlockResponse = Parameters<typeof isFullBlock>[0];
|
|
7
|
+
export type GetPageResponse = Parameters<typeof isFullPage>[0];
|
|
8
|
+
export type GetDatabaseResponse = Parameters<typeof isFullDatabase>[0];
|
|
9
|
+
export type BlockObjectResponse = GuardType<typeof isFullBlock>;
|
|
10
|
+
export type PageObjectResponse = GuardType<typeof isFullPage>;
|
|
11
|
+
export type DatabaseObjectResponse = GuardType<typeof isFullDatabase>;
|
|
12
|
+
export type GetResponse = GetBlockResponse | GetPageResponse | GetDatabaseResponse | APIResponseError;
|
|
13
|
+
export type PagePropertiesType = PageObjectResponse["properties"];
|
|
14
|
+
export type PagePropertiesValue = PagePropertiesType[keyof PagePropertiesType];
|
|
15
|
+
export declare const isPageResponse: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").PageObjectResponse | import("@notionhq/client/build/src/api-endpoints.js").PartialPageObjectResponse;
|
|
16
|
+
export declare const isDatabaseResponse: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").DatabaseObjectResponse | import("@notionhq/client/build/src/api-endpoints.js").PartialDatabaseObjectResponse;
|
|
17
|
+
export declare const isErrorResponse: (res: GetResponse) => res is APIResponseError;
|
|
18
|
+
export declare const isPage: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").PageObjectResponse;
|
|
19
|
+
export declare const isDatabase: (res: GetResponse) => res is import("@notionhq/client/build/src/api-endpoints.js").DatabaseObjectResponse;
|
|
5
20
|
/**
|
|
6
21
|
* Represents the type of Notion API to load documents from. The options
|
|
7
22
|
* are "database" or "page".
|
|
@@ -31,7 +46,23 @@ export declare class NotionAPILoader extends BaseDocumentLoader {
|
|
|
31
46
|
private rootTitle;
|
|
32
47
|
private onDocumentLoaded;
|
|
33
48
|
constructor(options: NotionAPILoaderOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Adds a selection of page ids to the pageQueue and removes duplicates.
|
|
51
|
+
* @param items An array of string ids
|
|
52
|
+
*/
|
|
34
53
|
private addToQueue;
|
|
54
|
+
/**
|
|
55
|
+
* Parses a Notion GetResponse object (page or database) and returns a string of the title.
|
|
56
|
+
* @param obj The Notion GetResponse object to parse.
|
|
57
|
+
* @returns The string of the title.
|
|
58
|
+
*/
|
|
59
|
+
private getTitle;
|
|
60
|
+
/**
|
|
61
|
+
* Parses the property type and returns a string
|
|
62
|
+
* @param page The Notion page property to parse.
|
|
63
|
+
* @returns A string of parsed property.
|
|
64
|
+
*/
|
|
65
|
+
private getPropValue;
|
|
35
66
|
/**
|
|
36
67
|
* Parses the properties of a Notion page and returns them as key-value
|
|
37
68
|
* pairs.
|
|
@@ -73,3 +104,4 @@ export declare class NotionAPILoader extends BaseDocumentLoader {
|
|
|
73
104
|
*/
|
|
74
105
|
load(): Promise<Document[]>;
|
|
75
106
|
}
|
|
107
|
+
export {};
|
|
@@ -4,19 +4,11 @@ import { getBlockChildren } from "notion-to-md/build/utils/notion.js";
|
|
|
4
4
|
import { Document } from "../../document.js";
|
|
5
5
|
import { BaseDocumentLoader } from "../base.js";
|
|
6
6
|
import { AsyncCaller } from "../../util/async_caller.js";
|
|
7
|
-
const isPageResponse = (res) => !isNotionClientError(res) && res.object === "page";
|
|
8
|
-
const isDatabaseResponse = (res) => !isNotionClientError(res) && res.object === "database";
|
|
9
|
-
const isErrorResponse = (res) => isNotionClientError(res);
|
|
10
|
-
const isPage = (res) => isPageResponse(res) && isFullPage(res);
|
|
11
|
-
const isDatabase = (res) => isDatabaseResponse(res) && isFullDatabase(res);
|
|
12
|
-
const getTitle = (obj) => {
|
|
13
|
-
if (isPage(obj) && obj.properties.title.type === "title") {
|
|
14
|
-
return obj.properties.title.title[0]?.plain_text;
|
|
15
|
-
}
|
|
16
|
-
if (isDatabase(obj))
|
|
17
|
-
return obj.title[0]?.plain_text;
|
|
18
|
-
return null;
|
|
19
|
-
};
|
|
7
|
+
export const isPageResponse = (res) => !isNotionClientError(res) && res.object === "page";
|
|
8
|
+
export const isDatabaseResponse = (res) => !isNotionClientError(res) && res.object === "database";
|
|
9
|
+
export const isErrorResponse = (res) => isNotionClientError(res);
|
|
10
|
+
export const isPage = (res) => isPageResponse(res) && isFullPage(res);
|
|
11
|
+
export const isDatabase = (res) => isDatabaseResponse(res) && isFullDatabase(res);
|
|
20
12
|
/**
|
|
21
13
|
* A class that extends the BaseDocumentLoader class. It represents a
|
|
22
14
|
* document loader for loading documents from Notion using the Notion API.
|
|
@@ -104,11 +96,85 @@ export class NotionAPILoader extends BaseDocumentLoader {
|
|
|
104
96
|
this.rootTitle = "";
|
|
105
97
|
this.onDocumentLoaded = options.onDocumentLoaded ?? ((_ti, _cu) => { });
|
|
106
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Adds a selection of page ids to the pageQueue and removes duplicates.
|
|
101
|
+
* @param items An array of string ids
|
|
102
|
+
*/
|
|
107
103
|
addToQueue(...items) {
|
|
108
104
|
const deDuped = items.filter((item) => !this.pageCompleted.concat(this.pageQueue).includes(item));
|
|
109
105
|
this.pageQueue.push(...deDuped);
|
|
110
106
|
this.pageQueueTotal += deDuped.length;
|
|
111
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Parses a Notion GetResponse object (page or database) and returns a string of the title.
|
|
110
|
+
* @param obj The Notion GetResponse object to parse.
|
|
111
|
+
* @returns The string of the title.
|
|
112
|
+
*/
|
|
113
|
+
getTitle(obj) {
|
|
114
|
+
if (isPage(obj) && obj.properties.title.type === "title") {
|
|
115
|
+
return obj.properties.title.title[0]?.plain_text;
|
|
116
|
+
}
|
|
117
|
+
if (isDatabase(obj))
|
|
118
|
+
return obj.title[0]?.plain_text;
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Parses the property type and returns a string
|
|
123
|
+
* @param page The Notion page property to parse.
|
|
124
|
+
* @returns A string of parsed property.
|
|
125
|
+
*/
|
|
126
|
+
getPropValue(prop) {
|
|
127
|
+
switch (prop.type) {
|
|
128
|
+
case "number": {
|
|
129
|
+
const propNumber = prop[prop.type];
|
|
130
|
+
return propNumber !== null ? propNumber.toString() : "";
|
|
131
|
+
}
|
|
132
|
+
case "url":
|
|
133
|
+
return prop[prop.type] || "";
|
|
134
|
+
case "select":
|
|
135
|
+
return prop[prop.type]?.name ?? "";
|
|
136
|
+
case "multi_select":
|
|
137
|
+
return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
|
|
138
|
+
case "status":
|
|
139
|
+
return prop[prop.type]?.name ?? "";
|
|
140
|
+
case "date":
|
|
141
|
+
return `${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? ` - ${prop[prop.type]?.end}` : ""}`;
|
|
142
|
+
case "email":
|
|
143
|
+
return prop[prop.type] || "";
|
|
144
|
+
case "phone_number":
|
|
145
|
+
return prop[prop.type] || "";
|
|
146
|
+
case "checkbox":
|
|
147
|
+
return prop[prop.type].toString();
|
|
148
|
+
case "files":
|
|
149
|
+
return `[${prop[prop.type].map((v) => `"${v.name}"`).join(", ")}]`;
|
|
150
|
+
case "created_by":
|
|
151
|
+
return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
|
|
152
|
+
case "created_time":
|
|
153
|
+
return prop[prop.type];
|
|
154
|
+
case "last_edited_by":
|
|
155
|
+
return `["${prop[prop.type].object}", "${prop[prop.type].id}"]`;
|
|
156
|
+
case "last_edited_time":
|
|
157
|
+
return prop[prop.type];
|
|
158
|
+
case "title":
|
|
159
|
+
return prop[prop.type]
|
|
160
|
+
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
161
|
+
.join("");
|
|
162
|
+
case "rich_text":
|
|
163
|
+
return prop[prop.type]
|
|
164
|
+
.map((v) => this.n2mClient.annotatePlainText(v.plain_text, v.annotations))
|
|
165
|
+
.join("");
|
|
166
|
+
case "people":
|
|
167
|
+
return `[${prop[prop.type]
|
|
168
|
+
.map((v) => `["${v.object}", "${v.id}"]`)
|
|
169
|
+
.join(", ")}]`;
|
|
170
|
+
case "unique_id":
|
|
171
|
+
return `${prop[prop.type].prefix || ""}${prop[prop.type].number}`;
|
|
172
|
+
case "relation":
|
|
173
|
+
return `[${prop[prop.type].map((v) => `"${v.id}"`).join(", ")}]`;
|
|
174
|
+
default:
|
|
175
|
+
return `Unsupported type: ${prop.type}`;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
112
178
|
/**
|
|
113
179
|
* Parses the properties of a Notion page and returns them as key-value
|
|
114
180
|
* pairs.
|
|
@@ -116,60 +182,11 @@ export class NotionAPILoader extends BaseDocumentLoader {
|
|
|
116
182
|
* @returns An object containing the parsed properties as key-value pairs.
|
|
117
183
|
*/
|
|
118
184
|
parsePageProperties(page) {
|
|
119
|
-
return Object.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return [prop.type, prop[prop.type]];
|
|
125
|
-
case "select":
|
|
126
|
-
return [prop.type, prop[prop.type]?.name ?? ""];
|
|
127
|
-
case "multi_select":
|
|
128
|
-
return [
|
|
129
|
-
prop.type,
|
|
130
|
-
prop[prop.type].map((select) => select.name).join(", "),
|
|
131
|
-
];
|
|
132
|
-
case "status":
|
|
133
|
-
return [prop.type, prop[prop.type]?.name ?? ""];
|
|
134
|
-
case "date":
|
|
135
|
-
return [
|
|
136
|
-
prop.type,
|
|
137
|
-
`${prop[prop.type]?.start ?? ""}${prop[prop.type]?.end ? `- ${prop[prop.type]?.end}` : ""}`,
|
|
138
|
-
];
|
|
139
|
-
case "email":
|
|
140
|
-
return [prop.type, prop[prop.type]];
|
|
141
|
-
case "phone_number":
|
|
142
|
-
return [prop.type, prop[prop.type]];
|
|
143
|
-
case "checkbox":
|
|
144
|
-
return [prop.type, prop[prop.type].toString()];
|
|
145
|
-
// case "files":
|
|
146
|
-
case "created_by":
|
|
147
|
-
return [prop.type, prop[prop.type]];
|
|
148
|
-
case "created_time":
|
|
149
|
-
return [prop.type, prop[prop.type]];
|
|
150
|
-
case "last_edited_by":
|
|
151
|
-
return [prop.type, prop[prop.type]];
|
|
152
|
-
case "last_edited_time":
|
|
153
|
-
return [prop.type, prop[prop.type]];
|
|
154
|
-
// case "formula":
|
|
155
|
-
case "title":
|
|
156
|
-
return [
|
|
157
|
-
prop.type,
|
|
158
|
-
prop[prop.type].map((v) => v.plain_text).join(""),
|
|
159
|
-
];
|
|
160
|
-
case "rich_text":
|
|
161
|
-
return [
|
|
162
|
-
prop.type,
|
|
163
|
-
prop[prop.type].map((v) => v.plain_text).join(""),
|
|
164
|
-
];
|
|
165
|
-
case "people":
|
|
166
|
-
return [prop.type, prop[prop.type]];
|
|
167
|
-
// case "relation":
|
|
168
|
-
// case "rollup":
|
|
169
|
-
default:
|
|
170
|
-
return [prop.type, "Unsupported type"];
|
|
171
|
-
}
|
|
172
|
-
}));
|
|
185
|
+
return Object.entries(page.properties).reduce((accum, [propName, prop]) => {
|
|
186
|
+
const value = this.getPropValue(prop);
|
|
187
|
+
const props = { ...accum, [propName]: value };
|
|
188
|
+
return prop.type === "title" ? { ...props, _title: value } : props;
|
|
189
|
+
}, {});
|
|
173
190
|
}
|
|
174
191
|
/**
|
|
175
192
|
* Parses the details of a Notion page and returns them as an object.
|
|
@@ -177,10 +194,10 @@ export class NotionAPILoader extends BaseDocumentLoader {
|
|
|
177
194
|
* @returns An object containing the parsed details of the page.
|
|
178
195
|
*/
|
|
179
196
|
parsePageDetails(page) {
|
|
180
|
-
const
|
|
197
|
+
const { id, ...rest } = page;
|
|
181
198
|
return {
|
|
182
|
-
...
|
|
183
|
-
notionId:
|
|
199
|
+
...rest,
|
|
200
|
+
notionId: id,
|
|
184
201
|
properties: this.parsePageProperties(page),
|
|
185
202
|
};
|
|
186
203
|
}
|
|
@@ -313,7 +330,8 @@ export class NotionAPILoader extends BaseDocumentLoader {
|
|
|
313
330
|
}
|
|
314
331
|
throw new AggregateError(errors);
|
|
315
332
|
}
|
|
316
|
-
this.rootTitle =
|
|
333
|
+
this.rootTitle =
|
|
334
|
+
this.getTitle(resPage) || this.getTitle(resDatabase) || this.id;
|
|
317
335
|
let pageId = this.pageQueue.shift();
|
|
318
336
|
while (pageId) {
|
|
319
337
|
await this.loadPage(pageId);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GoogleVertexAIEmbeddings = void 0;
|
|
4
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
4
5
|
const base_js_1 = require("./base.cjs");
|
|
5
6
|
const googlevertexai_connection_js_1 = require("../util/googlevertexai-connection.cjs");
|
|
6
7
|
const chunk_js_1 = require("../util/chunk.cjs");
|
|
@@ -34,7 +35,10 @@ class GoogleVertexAIEmbeddings extends base_js_1.Embeddings {
|
|
|
34
35
|
value: void 0
|
|
35
36
|
});
|
|
36
37
|
this.model = fields?.model ?? this.model;
|
|
37
|
-
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller
|
|
38
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, new google_auth_library_1.GoogleAuth({
|
|
39
|
+
scopes: "https://www.googleapis.com/auth/cloud-platform",
|
|
40
|
+
...fields?.authOptions,
|
|
41
|
+
}));
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
44
|
* Takes an array of documents as input and returns a promise that
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GoogleAuthOptions } from "google-auth-library";
|
|
1
2
|
import { Embeddings, EmbeddingsParams } from "./base.js";
|
|
2
3
|
import { GoogleVertexAIBaseLLMInput } from "../types/googlevertexai-types.js";
|
|
3
4
|
/**
|
|
@@ -5,7 +6,7 @@ import { GoogleVertexAIBaseLLMInput } from "../types/googlevertexai-types.js";
|
|
|
5
6
|
* GoogleVertexAIEmbeddings instance. It extends EmbeddingsParams and
|
|
6
7
|
* GoogleVertexAIConnectionParams.
|
|
7
8
|
*/
|
|
8
|
-
export interface GoogleVertexAIEmbeddingsParams extends EmbeddingsParams, GoogleVertexAIBaseLLMInput {
|
|
9
|
+
export interface GoogleVertexAIEmbeddingsParams extends EmbeddingsParams, GoogleVertexAIBaseLLMInput<GoogleAuthOptions> {
|
|
9
10
|
}
|
|
10
11
|
/**
|
|
11
12
|
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GoogleAuth } from "google-auth-library";
|
|
1
2
|
import { Embeddings } from "./base.js";
|
|
2
3
|
import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
|
|
3
4
|
import { chunkArray } from "../util/chunk.js";
|
|
@@ -31,7 +32,10 @@ export class GoogleVertexAIEmbeddings extends Embeddings {
|
|
|
31
32
|
value: void 0
|
|
32
33
|
});
|
|
33
34
|
this.model = fields?.model ?? this.model;
|
|
34
|
-
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller
|
|
35
|
+
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, new GoogleAuth({
|
|
36
|
+
scopes: "https://www.googleapis.com/auth/cloud-platform",
|
|
37
|
+
...fields?.authOptions,
|
|
38
|
+
}));
|
|
35
39
|
}
|
|
36
40
|
/**
|
|
37
41
|
* Takes an array of documents as input and returns a promise that
|
|
@@ -0,0 +1,17 @@
|
|
|
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("./trajectory.cjs"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./trajectory.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./trajectory.js";
|