@wirecat/notion-cli 0.0.0-stage → 0.2.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/CHANGELOG.md +73 -0
- package/LICENSE +204 -0
- package/README.md +42 -2
- package/contracts/wirecat.json +1964 -0
- package/dist/bin/notion.d.ts +3 -0
- package/dist/bin/notion.d.ts.map +1 -0
- package/dist/bin/notion.js +40 -0
- package/dist/bin/notion.js.map +1 -0
- package/dist/bundle/all-profiles-JGYLQZ5C.js +278 -0
- package/dist/bundle/anthropic-S2VSMIKQ.js +91 -0
- package/dist/bundle/app-server-SASYDBCA.js +240 -0
- package/dist/bundle/bun-LU5LP3JI.js +169 -0
- package/dist/bundle/bun-sqlite-JBSINB4O.js +76 -0
- package/dist/bundle/chunk-22QQUKWA.js +53 -0
- package/dist/bundle/chunk-2F4QQ7WB.js +73 -0
- package/dist/bundle/chunk-2F6VO5HA.js +73 -0
- package/dist/bundle/chunk-2LWO3PDX.js +726 -0
- package/dist/bundle/chunk-3AL7QUS3.js +2778 -0
- package/dist/bundle/chunk-3Z4YTSRY.js +731 -0
- package/dist/bundle/chunk-4HWJOU7N.js +38 -0
- package/dist/bundle/chunk-4IPURN72.js +1221 -0
- package/dist/bundle/chunk-4ZTVJHWU.js +206 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5IYKVRH2.js +44811 -0
- package/dist/bundle/chunk-5NFK5EM2.js +362 -0
- package/dist/bundle/chunk-5QIQEUOG.js +188 -0
- package/dist/bundle/chunk-5RDNBG7D.js +72 -0
- package/dist/bundle/chunk-5RSC54NA.js +1328 -0
- package/dist/bundle/chunk-6EVKHZKN.js +158 -0
- package/dist/bundle/chunk-6RA3EABS.js +4012 -0
- package/dist/bundle/chunk-AOCUKEAX.js +131 -0
- package/dist/bundle/chunk-B26TQZKZ.js +217 -0
- package/dist/bundle/chunk-B7ON6KPT.js +1197 -0
- package/dist/bundle/chunk-BNPTZ5ZB.js +161 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-D7QSEEYW.js +274 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DH5PRHT4.js +392 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EUIVXFLJ.js +259 -0
- package/dist/bundle/chunk-FPY6EJ7B.js +9568 -0
- package/dist/bundle/chunk-FT3LN3HP.js +6848 -0
- package/dist/bundle/chunk-FWVBPRL4.js +4436 -0
- package/dist/bundle/chunk-FXEJY4OL.js +12538 -0
- package/dist/bundle/chunk-G3EZFRSS.js +1297 -0
- package/dist/bundle/chunk-GZOUFX3C.js +230 -0
- package/dist/bundle/chunk-HL52XXZX.js +78 -0
- package/dist/bundle/chunk-KCLOUUYF.js +100 -0
- package/dist/bundle/chunk-KFVDL2QS.js +146 -0
- package/dist/bundle/chunk-KGERXYTV.js +24 -0
- package/dist/bundle/chunk-KM6WHPHI.js +288 -0
- package/dist/bundle/chunk-LAYPFBOM.js +95 -0
- package/dist/bundle/chunk-LLG2POQ7.js +170 -0
- package/dist/bundle/chunk-M3KB25D3.js +1392 -0
- package/dist/bundle/chunk-M7S2NDWB.js +76 -0
- package/dist/bundle/chunk-MGUEZYFA.js +5546 -0
- package/dist/bundle/chunk-MY742GAD.js +1977 -0
- package/dist/bundle/chunk-MZU2YFBZ.js +823 -0
- package/dist/bundle/chunk-NOQ7B5N7.js +58 -0
- package/dist/bundle/chunk-NQWV4WQO.js +300 -0
- package/dist/bundle/chunk-ODBZNSZ6.js +1028 -0
- package/dist/bundle/chunk-OTV53F34.js +370 -0
- package/dist/bundle/chunk-P7CUM5IB.js +18 -0
- package/dist/bundle/chunk-RV64YUQX.js +185 -0
- package/dist/bundle/chunk-SHJQ6JKG.js +106 -0
- package/dist/bundle/chunk-SWAOWNKW.js +52 -0
- package/dist/bundle/chunk-SZOVLP44.js +29 -0
- package/dist/bundle/chunk-TPX2M45D.js +385 -0
- package/dist/bundle/chunk-TSDBSIFM.js +66 -0
- package/dist/bundle/chunk-VBHETQVV.js +64146 -0
- package/dist/bundle/chunk-VCIALTEM.js +3139 -0
- package/dist/bundle/chunk-VKE77B3F.js +2 -0
- package/dist/bundle/chunk-WCSOH4JS.js +142 -0
- package/dist/bundle/chunk-WF4D56CA.js +54 -0
- package/dist/bundle/chunk-WJHZMR2W.js +335 -0
- package/dist/bundle/chunk-X4TIMMKJ.js +16 -0
- package/dist/bundle/chunk-XF26XKTS.js +82 -0
- package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
- package/dist/bundle/chunk-XQUUANA2.js +24600 -0
- package/dist/bundle/chunk-XYIT2XB3.js +1372 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-YMYUBZWT.js +1068 -0
- package/dist/bundle/chunk-YNTLT3Z3.js +2310 -0
- package/dist/bundle/chunk-YVI5SQPY.js +46 -0
- package/dist/bundle/chunk-Z56QFOBR.js +63 -0
- package/dist/bundle/chunk-ZKAEZXUP.js +787 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/chunk-ZZ32DXTH.js +23 -0
- package/dist/bundle/command-contract-JS5V27NX.js +38 -0
- package/dist/bundle/command-server-entry-UFSG7KRO.js +167 -0
- package/dist/bundle/decode-7LLWTSPT.js +297 -0
- package/dist/bundle/definitions-M3U4UYHN.js +45607 -0
- package/dist/bundle/dispatch-2GY6JIJH.js +411 -0
- package/dist/bundle/dist-ILNOLGYN.js +7577 -0
- package/dist/bundle/echarts-BXX4OQWC.js +42501 -0
- package/dist/bundle/embed-JXFNBTKH.js +38 -0
- package/dist/bundle/embedder-57YZ44KO.js +111 -0
- package/dist/bundle/failure-MYT4HPE3.js +25 -0
- package/dist/bundle/first-run-3PF7T74J.js +29 -0
- package/dist/bundle/first-screen-7BEROEQR.js +36 -0
- package/dist/bundle/instructions-2VECIDXF.js +11 -0
- package/dist/bundle/mcp-O6ACR2DX.js +167 -0
- package/dist/bundle/mdast-util-from-markdown-R66F4HZA.js +1958 -0
- package/dist/bundle/mdast-util-gfm-LN2ELINH.js +2699 -0
- package/dist/bundle/meeting-combined-PPUQ3KBR.js +24 -0
- package/dist/bundle/meeting-model-ZNMYKMCD.js +26 -0
- package/dist/bundle/meeting-semantic-ETN3A4BJ.js +22 -0
- package/dist/bundle/micromark-extension-gfm-5X7YT43T.js +1838 -0
- package/dist/bundle/node-KM3CUABH.js +2340 -0
- package/dist/bundle/node-MPEQSFI3.js +176 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-WA32MYSJ.js +74 -0
- package/dist/bundle/notion.js +185 -0
- package/dist/bundle/oauth-IAFZG3IR.js +20 -0
- package/dist/bundle/open-M3JQUC5G.js +23 -0
- package/dist/bundle/openai-HXUEHUSD.js +240 -0
- package/dist/bundle/process-F6TKXWWA.js +91 -0
- package/dist/bundle/program-Y7JAB6TG.js +33219 -0
- package/dist/bundle/prompt-IMUQLZD2.js +17 -0
- package/dist/bundle/recognize-2MZAYHAA.js +26 -0
- package/dist/bundle/remote-OV4LB6VR.js +32 -0
- package/dist/bundle/rerank-ZIULUS34.js +52 -0
- package/dist/bundle/schemas-DIVZS6TU.js +12214 -0
- package/dist/bundle/serve-YU7QBP6L.js +199 -0
- package/dist/bundle/server-FKQET4ZO.js +71 -0
- package/dist/bundle/server-LGMNONSB.js +202 -0
- package/dist/bundle/services-5WY4DCPJ.js +581 -0
- package/dist/bundle/sqlite-runtime-5MXZDETH.js +20 -0
- package/dist/bundle/state-LWMZH2KI.js +36 -0
- package/dist/bundle/store-EPZYV4VW.js +168 -0
- package/dist/bundle/store-QE6FEIZD.js +286 -0
- package/dist/bundle/store-maintenance-command-ZUUUFCHL.js +62 -0
- package/dist/commands/api.d.ts +4 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +140 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/databases.d.ts +3 -0
- package/dist/commands/databases.d.ts.map +1 -0
- package/dist/commands/databases.js +65 -0
- package/dist/commands/databases.js.map +1 -0
- package/dist/commands/documents.d.ts +4 -0
- package/dist/commands/documents.d.ts.map +1 -0
- package/dist/commands/documents.js +41 -0
- package/dist/commands/documents.js.map +1 -0
- package/dist/commands/library.d.ts +10 -0
- package/dist/commands/library.d.ts.map +1 -0
- package/dist/commands/library.js +468 -0
- package/dist/commands/library.js.map +1 -0
- package/dist/commands/session.d.ts +3 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +105 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +13 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +51 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +67 -0
- package/dist/context.js.map +1 -0
- package/dist/generated/definitions.d.ts +3 -0
- package/dist/generated/definitions.d.ts.map +1 -0
- package/dist/generated/definitions.js +45603 -0
- package/dist/generated/definitions.js.map +1 -0
- package/dist/generated/manifest.d.ts +3 -0
- package/dist/generated/manifest.d.ts.map +1 -0
- package/dist/generated/manifest.js +2089 -0
- package/dist/generated/manifest.js.map +1 -0
- package/dist/generated/metadata.d.ts +6 -0
- package/dist/generated/metadata.d.ts.map +1 -0
- package/dist/generated/metadata.js +24 -0
- package/dist/generated/metadata.js.map +1 -0
- package/dist/generated/schemas.d.ts +1223 -0
- package/dist/generated/schemas.d.ts.map +1 -0
- package/dist/generated/schemas.js +11557 -0
- package/dist/generated/schemas.js.map +1 -0
- package/dist/generated/types.d.ts +11120 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +30 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge.d.ts +27 -0
- package/dist/knowledge.d.ts.map +1 -0
- package/dist/knowledge.js +87 -0
- package/dist/knowledge.js.map +1 -0
- package/dist/library.d.ts +44 -0
- package/dist/library.d.ts.map +1 -0
- package/dist/library.js +149 -0
- package/dist/library.js.map +1 -0
- package/dist/notion/client.d.ts +45 -0
- package/dist/notion/client.d.ts.map +1 -0
- package/dist/notion/client.js +121 -0
- package/dist/notion/client.js.map +1 -0
- package/dist/notion/errors.d.ts +24 -0
- package/dist/notion/errors.d.ts.map +1 -0
- package/dist/notion/errors.js +127 -0
- package/dist/notion/errors.js.map +1 -0
- package/dist/notion/ids.d.ts +7 -0
- package/dist/notion/ids.d.ts.map +1 -0
- package/dist/notion/ids.js +37 -0
- package/dist/notion/ids.js.map +1 -0
- package/dist/notion/links.d.ts +6 -0
- package/dist/notion/links.d.ts.map +1 -0
- package/dist/notion/links.js +22 -0
- package/dist/notion/links.js.map +1 -0
- package/dist/notion/notion.d.ts +95 -0
- package/dist/notion/notion.d.ts.map +1 -0
- package/dist/notion/notion.js +269 -0
- package/dist/notion/notion.js.map +1 -0
- package/dist/notion/port.d.ts +13 -0
- package/dist/notion/port.d.ts.map +1 -0
- package/dist/notion/port.js +60 -0
- package/dist/notion/port.js.map +1 -0
- package/dist/notion/read-posts.d.ts +36 -0
- package/dist/notion/read-posts.d.ts.map +1 -0
- package/dist/notion/read-posts.js +24 -0
- package/dist/notion/read-posts.js.map +1 -0
- package/dist/notion/reads.d.ts +331 -0
- package/dist/notion/reads.d.ts.map +1 -0
- package/dist/notion/reads.js +18 -0
- package/dist/notion/reads.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +62 -0
- package/dist/program.js.map +1 -0
- package/dist/sync/cursor.d.ts +135 -0
- package/dist/sync/cursor.d.ts.map +1 -0
- package/dist/sync/cursor.js +113 -0
- package/dist/sync/cursor.js.map +1 -0
- package/dist/sync/files.d.ts +77 -0
- package/dist/sync/files.d.ts.map +1 -0
- package/dist/sync/files.js +12 -0
- package/dist/sync/files.js.map +1 -0
- package/dist/sync/front-matter.d.ts +10 -0
- package/dist/sync/front-matter.d.ts.map +1 -0
- package/dist/sync/front-matter.js +114 -0
- package/dist/sync/front-matter.js.map +1 -0
- package/dist/sync/markdown.d.ts +11 -0
- package/dist/sync/markdown.d.ts.map +1 -0
- package/dist/sync/markdown.js +42 -0
- package/dist/sync/markdown.js.map +1 -0
- package/dist/sync/source.d.ts +11 -0
- package/dist/sync/source.d.ts.map +1 -0
- package/dist/sync/source.js +995 -0
- package/dist/sync/source.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/package.json +85 -4
- package/skills/notion-cli/SKILL.md +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/generated/types.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,gEAAgE;AAChE,qBAAqB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ManifestIdentity } from "@wirecat/cli-base/wcat/manifest";
|
|
2
|
+
import type { AppIdentity } from "@wirecat/cli-core/cli";
|
|
3
|
+
export declare const PACKAGE = "@wirecat/notion-cli";
|
|
4
|
+
export declare const IDENTITY: AppIdentity;
|
|
5
|
+
export declare const DESKTOP: ManifestIdentity;
|
|
6
|
+
export declare const SKILL: import("url").URL;
|
|
7
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAIxD,eAAO,MAAM,OAAO,wBAAwB,CAAA;AAE5C,eAAO,MAAM,QAAQ,EAAE,WAUtB,CAAA;AAID,eAAO,MAAM,OAAO,EAAE,gBAWrB,CAAA;AAED,eAAO,MAAM,KAAK,mBAA4D,CAAA"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { DETAILS, REASONS } from "./notion/errors.js";
|
|
2
|
+
import { VERSION } from "./version.js";
|
|
3
|
+
export const PACKAGE = "@wirecat/notion-cli";
|
|
4
|
+
export const IDENTITY = {
|
|
5
|
+
command: "notion",
|
|
6
|
+
appName: "notion-cli",
|
|
7
|
+
envPrefix: "WCNOTION",
|
|
8
|
+
description: "Notion pages and databases for you and your agent, read live with your own token",
|
|
9
|
+
version: VERSION,
|
|
10
|
+
issues: "https://github.com/WireCatLabs/notion-cli/issues/new",
|
|
11
|
+
messenger: false,
|
|
12
|
+
contentLanguages: ["en", "ru", "es"],
|
|
13
|
+
errors: { reasons: REASONS, details: DETAILS },
|
|
14
|
+
};
|
|
15
|
+
// What `wcat` and WireCat Desktop show before the tool is installed. The bin passes it to wcatStart before anything
|
|
16
|
+
// else loads; src/wcat.ts adds the permission keys.
|
|
17
|
+
export const DESKTOP = {
|
|
18
|
+
...IDENTITY,
|
|
19
|
+
docs: "https://github.com/WireCatLabs/notion-cli#readme",
|
|
20
|
+
// Every host the CLI contacts (WC-CMD-32).
|
|
21
|
+
hosts: ["api.notion.com"],
|
|
22
|
+
tagline: "Notion pages and databases, searchable on your computer",
|
|
23
|
+
syncs: "Notion pages and database rows",
|
|
24
|
+
signIn: {
|
|
25
|
+
gives: "Lets your agent read the Notion pages and databases your token can see.",
|
|
26
|
+
asks: "A Notion personal access token, or the token of an internal connection you made in Notion.",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
export const SKILL = new URL("../skills/notion-cli/SKILL.md", import.meta.url);
|
|
30
|
+
//# sourceMappingURL=identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAA;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEtC,MAAM,CAAC,MAAM,OAAO,GAAG,qBAAqB,CAAA;AAE5C,MAAM,CAAC,MAAM,QAAQ,GAAgB;IACnC,OAAO,EAAE,QAAQ;IACjB,OAAO,EAAE,YAAY;IACrB,SAAS,EAAE,UAAU;IACrB,WAAW,EAAE,kFAAkF;IAC/F,OAAO,EAAE,OAAO;IAChB,MAAM,EAAE,sDAAsD;IAC9D,SAAS,EAAE,KAAK;IAChB,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;IACpC,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE;CAC/C,CAAA;AAED,oHAAoH;AACpH,oDAAoD;AACpD,MAAM,CAAC,MAAM,OAAO,GAAqB;IACvC,GAAG,QAAQ;IACX,IAAI,EAAE,kDAAkD;IACxD,2CAA2C;IAC3C,KAAK,EAAE,CAAC,gBAAgB,CAAC;IACzB,OAAO,EAAE,yDAAyD;IAClE,KAAK,EAAE,gCAAgC;IACvC,MAAM,EAAE;QACN,KAAK,EAAE,yEAAyE;QAChF,IAAI,EAAE,4FAA4F;KACnG;CACF,CAAA;AAED,MAAM,CAAC,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,+BAA+B,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type DocumentKnowledgePort } from "@wirecat/cli-core/documents/cli";
|
|
2
|
+
import type { MessageStore } from "@wirecat/cli-core/store";
|
|
3
|
+
import type { NotionFile } from "./sync/source.js";
|
|
4
|
+
export declare const ingestionOf: (store: MessageStore) => {
|
|
5
|
+
catalog: {
|
|
6
|
+
import: (principal: string, files: NotionFile[]) => Promise<{
|
|
7
|
+
entries: number;
|
|
8
|
+
retired: number;
|
|
9
|
+
}>;
|
|
10
|
+
get: (principal: string, id: string) => Promise<import("@wirecat/cli-core/store").CatalogEntry | undefined>;
|
|
11
|
+
list: (principal: string, query?: import("@wirecat/cli-core/store").CatalogQuery) => Promise<{
|
|
12
|
+
items: import("@wirecat/cli-core/store").CatalogEntry[];
|
|
13
|
+
hasMore: boolean;
|
|
14
|
+
} | {
|
|
15
|
+
items: never[];
|
|
16
|
+
hasMore: boolean;
|
|
17
|
+
}>;
|
|
18
|
+
};
|
|
19
|
+
collection: (principal: string, create: boolean) => Promise<import("@wirecat/cli-core/store").NoteFolder | undefined>;
|
|
20
|
+
settle: ({ until }: {
|
|
21
|
+
until: () => boolean;
|
|
22
|
+
}) => Promise<number>;
|
|
23
|
+
save: (principal: string, content: import("@wirecat/cli-core/documents").SourceContent<NotionFile>, hash: string) => Promise<string>;
|
|
24
|
+
remove: (principal: string, id: string) => Promise<void>;
|
|
25
|
+
};
|
|
26
|
+
export declare const knowledgeOf: (store: MessageStore, principal: string) => DocumentKnowledgePort;
|
|
27
|
+
//# sourceMappingURL=knowledge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge.d.ts","sourceRoot":"","sources":["../src/knowledge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAAwB,MAAM,iCAAiC,CAAA;AAClG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE3D,OAAO,KAAK,EAAE,UAAU,EAAkB,MAAM,kBAAkB,CAAA;AAIlE,eAAO,MAAM,WAAW,UAAW,YAAY;;;;;;;;;;;;;;;;;;;;;CA0B3C,CAAA;AAWJ,eAAO,MAAM,WAAW,UAAW,YAAY,aAAa,MAAM,KAAG,qBA2DpE,CAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { CliError } from "@wirecat/cli-base";
|
|
2
|
+
import { documentIngestion, documentKnowledge } from "@wirecat/cli-core/documents";
|
|
3
|
+
import { factItem, memoryItem } from "@wirecat/cli-core/documents/cli";
|
|
4
|
+
import { PROVIDER } from "./library.js";
|
|
5
|
+
const external = (id) => `${id}.md`;
|
|
6
|
+
export const ingestionOf = (store) => documentIngestion(store, {
|
|
7
|
+
provider: PROVIDER.name,
|
|
8
|
+
externalId: external,
|
|
9
|
+
catalogInput: (file) => ({
|
|
10
|
+
externalId: external(file.id),
|
|
11
|
+
// A page with sub-pages is a file too: its children name it as their parent, and the catalog nests them.
|
|
12
|
+
kind: file.providerMetadata.kind === "page" || file.providerMetadata.kind === "row" ? "file" : "folder",
|
|
13
|
+
name: file.name,
|
|
14
|
+
parents: file.parents.map(external),
|
|
15
|
+
...(file.url ? { url: file.url } : {}),
|
|
16
|
+
mime: file.mime,
|
|
17
|
+
...(file.createdAt ? { createdAt: file.createdAt } : {}),
|
|
18
|
+
...(file.modifiedAt ? { modifiedAt: file.modifiedAt } : {}),
|
|
19
|
+
metadata: { notion_kind: file.providerMetadata.kind },
|
|
20
|
+
}),
|
|
21
|
+
frontMatter: ({ metadata }) => ({
|
|
22
|
+
source: PROVIDER.name,
|
|
23
|
+
sourceUrl: metadata.url,
|
|
24
|
+
pageId: metadata.id,
|
|
25
|
+
kind: metadata.providerMetadata.kind,
|
|
26
|
+
modifiedAt: metadata.modifiedAt ?? null,
|
|
27
|
+
properties: metadata.providerMetadata.frontMatter ?? {},
|
|
28
|
+
people: metadata.providerMetadata.people ?? [],
|
|
29
|
+
...(metadata.providerMetadata.missingBlocks ? { missingBlocks: metadata.providerMetadata.missingBlocks } : {}),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
/** Notion's creator and last editor, in the shared roles; people properties are row data, not authorship. */
|
|
33
|
+
const ROLES = { author: "owner", editor: "last-editor" };
|
|
34
|
+
const contributors = (frontMatter) => (frontMatter?.people ?? []).flatMap((person) => {
|
|
35
|
+
const role = ROLES[person.role];
|
|
36
|
+
return role ? [{ ...person, role }] : [];
|
|
37
|
+
});
|
|
38
|
+
export const knowledgeOf = (store, principal) => {
|
|
39
|
+
const ingestion = ingestionOf(store);
|
|
40
|
+
const shared = documentKnowledge(store, async (account) => account === principal ? (await ingestion.collection(account, false))?.id : undefined);
|
|
41
|
+
const port = {
|
|
42
|
+
...shared,
|
|
43
|
+
context: async (account, ref) => ({
|
|
44
|
+
document: await shared.document(account, ref),
|
|
45
|
+
tags: await store.notes.noteTags(ref),
|
|
46
|
+
links: await store.notes.links({ from: ref }),
|
|
47
|
+
notes: await store.notes.notes({ source: "internal", about: ref, limit: 100 }),
|
|
48
|
+
memories: (await store.memories.list({ subject: ref, limit: 100 })).items.map(memoryItem),
|
|
49
|
+
facts: (await store.facts.list({ subject: ref, limit: 100 })).items.map(factItem),
|
|
50
|
+
people: await port.people(account, ref),
|
|
51
|
+
}),
|
|
52
|
+
people: async (account, ref, filter = {}) => {
|
|
53
|
+
const note = await shared.document(account, ref);
|
|
54
|
+
const found = contributors(note.frontMatter).filter((person) => (filter.role === undefined || person.role === filter.role) &&
|
|
55
|
+
(filter.remote_id === undefined || person.id === filter.remote_id));
|
|
56
|
+
return {
|
|
57
|
+
items: await Promise.all(found.map(async (person) => {
|
|
58
|
+
const linked = await store.people.personOf({ provider: PROVIDER.name, id: person.id });
|
|
59
|
+
return {
|
|
60
|
+
remote_id: person.id,
|
|
61
|
+
provider: PROVIDER.name,
|
|
62
|
+
role: person.role,
|
|
63
|
+
name: person.name ?? null,
|
|
64
|
+
person: linked ? { ref: `person:${linked.uid}`, ...linked } : null,
|
|
65
|
+
};
|
|
66
|
+
})),
|
|
67
|
+
coverage: "the page's creator and last editor, as Notion gives them; not every past editor",
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
linkPerson: async (account, ref, remoteId, personRef) => {
|
|
71
|
+
const note = await shared.document(account, ref);
|
|
72
|
+
if (!contributors(note.frontMatter).some((person) => person.id === remoteId))
|
|
73
|
+
throw new CliError("not_found", "this Notion user was not seen on the document", {
|
|
74
|
+
reason: "identity.not-seen",
|
|
75
|
+
});
|
|
76
|
+
if (!personRef.startsWith("person:"))
|
|
77
|
+
throw new CliError("validation_error", "the target must be a person: reference", { reason: "identity.target" });
|
|
78
|
+
const person = await store.people.personByUid(personRef.slice("person:".length));
|
|
79
|
+
const known = person?.identities[0];
|
|
80
|
+
if (!known)
|
|
81
|
+
throw new CliError("not_found", "the target person has no known identity", { reason: "identity.no-person" });
|
|
82
|
+
return store.people.linkIdentities(known, { provider: PROVIDER.name, id: remoteId }, { method: "manual", by: PROVIDER.name });
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
return port;
|
|
86
|
+
};
|
|
87
|
+
//# sourceMappingURL=knowledge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knowledge.js","sourceRoot":"","sources":["../src/knowledge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,EAAE,iBAAiB,EAAE,i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,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YAChD,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,KAAK,QAAQ,CAAC;gBAC1E,MAAM,IAAI,QAAQ,CAAC,WAAW,EAAE,+CAA+C,EAAE;oBAC/E,MAAM,EAAE,mBAAmB;iBAC5B,CAAC,CAAA;YACJ,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC;gBAClC,MAAM,IAAI,QAAQ,CAAC,kBAAkB,EAAE,wCAAwC,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,CAAC,CAAA;YACjH,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAA;YAChF,MAAM,KAAK,GAAG,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;YACnC,IAAI,CAAC,KAAK;gBACR,MAAM,IAAI,QAAQ,CAAC,WAAW,EAAE,yCAAyC,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,CAAC,CAAA;YAC9G,OAAO,KAAK,CAAC,MAAM,CAAC,cAAc,CAChC,KAAK,EACL,EAAE,QAAQ,EAAE,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,EACzC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,CAAC,IAAI,EAAE,CACxC,CAAA;QACH,CAAC;KACF,CAAA;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ProfileTokenStore } from "@wirecat/cli-core/cli";
|
|
2
|
+
import type { SourceContent, SourceState, SourceStatePort } from "@wirecat/cli-core/documents";
|
|
3
|
+
import type { MessageStore } from "@wirecat/cli-core/store";
|
|
4
|
+
import { type NotionFile } from "./sync/source.js";
|
|
5
|
+
export declare const PROVIDER: {
|
|
6
|
+
readonly name: "notion";
|
|
7
|
+
readonly kind: "documents";
|
|
8
|
+
readonly aliases: readonly [];
|
|
9
|
+
readonly command: string;
|
|
10
|
+
readonly opens: {
|
|
11
|
+
readonly document: "documents show";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** The most entries one sync walks under the chosen folders. */
|
|
15
|
+
export declare const MAX_ENTRIES = 10000;
|
|
16
|
+
/** The longest page text the store keeps; a longer page is kept by name only. */
|
|
17
|
+
export declare const TEXT_LIMIT = 1000000;
|
|
18
|
+
/** The shared store with notion's provider entry; a read, or any run under the read-only lock, opens it read-only. */
|
|
19
|
+
export declare const openStore: (env: NodeJS.ProcessEnv, write: boolean) => Promise<MessageStore>;
|
|
20
|
+
export declare const withStore: <T>(env: NodeJS.ProcessEnv, write: boolean, fn: (store: MessageStore) => Promise<T>) => Promise<T>;
|
|
21
|
+
export declare const chosenFolders: (env: NodeJS.ProcessEnv, profile: string) => string[];
|
|
22
|
+
export declare const foldersChangedAt: (env: NodeJS.ProcessEnv, profile: string) => string | undefined;
|
|
23
|
+
export declare const saveFolders: (env: NodeJS.ProcessEnv, profile: string, roots: string[]) => void;
|
|
24
|
+
export declare const rootsOf: (env: NodeJS.ProcessEnv, profile: string) => string[];
|
|
25
|
+
export declare const syncState: (env: NodeJS.ProcessEnv, profile: string, principal: string) => SourceStatePort<NotionFile>;
|
|
26
|
+
/** The engine's planning walk, when one is under way: it is saved between runs until the plan is made. */
|
|
27
|
+
export declare const walkUnderWay: (env: NodeJS.ProcessEnv, profile: string) => boolean;
|
|
28
|
+
export declare const readSnapshot: (env: NodeJS.ProcessEnv, profile: string, id: string) => SourceContent<NotionFile> | undefined;
|
|
29
|
+
/** What the sync holds, for the source to tell a page it missed from one Notion deleted. */
|
|
30
|
+
export declare const knownOf: (state: SourceState<NotionFile>) => NotionFile[];
|
|
31
|
+
/**
|
|
32
|
+
* The lock a sync and every write to the profile's local copy take, so a tag added during a sync is not lost. A
|
|
33
|
+
* second holder is refused at once: waiting would hold an agent's tool call for the length of a sync.
|
|
34
|
+
*/
|
|
35
|
+
export declare const withProfileLock: <T>(env: NodeJS.ProcessEnv, profile: string, fn: (assertHeld: () => void) => Promise<T>) => Promise<T>;
|
|
36
|
+
/** The account a profile has synced as: local reads never ask Notion, and a profile only signed in has no copy. */
|
|
37
|
+
export declare const principalOf: (env: NodeJS.ProcessEnv, profile: string) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Takes a Notion connection for a profile, before its token is kept or its copy written. One connection is one
|
|
40
|
+
* account in the shared store, so two profiles on it would each remove the other's pages; and a profile's local copy
|
|
41
|
+
* stays with the connection it was synced from.
|
|
42
|
+
*/
|
|
43
|
+
export declare const claimAccount: (env: NodeJS.ProcessEnv, profile: string, account: string, tokens: Pick<ProfileTokenStore, "read">) => void;
|
|
44
|
+
//# sourceMappingURL=library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,KAAK,iBAAiB,EAIvB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAc,MAAM,6BAA6B,CAAA;AAE1G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAE3D,OAAO,EAAE,KAAK,UAAU,EAAkB,MAAM,kBAAkB,CAAA;AAKlE,eAAO,MAAM,QAAQ;mBACb,QAAQ;mBACR,WAAW;;;;iBAGR,QAAQ,EAAE,gBAAgB;;CACH,CAAA;AAElC,gEAAgE;AAChE,eAAO,MAAM,WAAW,QAAS,CAAA;AACjC,iFAAiF;AACjF,eAAO,MAAM,UAAU,UAAY,CAAA;AAEnC,sHAAsH;AACtH,eAAO,MAAM,SAAS,QAAS,MAAM,CAAC,UAAU,SAAS,OAAO,KAAG,O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M,CAAC,UAAU,WACb,MAAM,WACN,MAAM,UACP,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC,SA4BxC,CAAA"}
|
package/dist/library.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { CliError, resolvePaths, writeSecurely } from "@wirecat/cli-base";
|
|
5
|
+
import { accountFileFor, openAppStore, profilesHere, readOnlyLockOf, rememberAccount, } from "@wirecat/cli-core/cli";
|
|
6
|
+
import { acquireLock } from "@wirecat/cli-core/files";
|
|
7
|
+
import { IDENTITY } from "./identity.js";
|
|
8
|
+
import { WORKSPACE_ROOT } from "./sync/source.js";
|
|
9
|
+
// What the shared documents commands keep for one profile, beside the shared store: the chosen folders, the sync's
|
|
10
|
+
// checkpoint, its walk and one snapshot per page, each a private file under the profile's state folder.
|
|
11
|
+
export const PROVIDER = {
|
|
12
|
+
name: "notion",
|
|
13
|
+
kind: "documents",
|
|
14
|
+
aliases: [],
|
|
15
|
+
command: IDENTITY.command,
|
|
16
|
+
opens: { document: "documents show" },
|
|
17
|
+
};
|
|
18
|
+
/** The most entries one sync walks under the chosen folders. */
|
|
19
|
+
export const MAX_ENTRIES = 10_000;
|
|
20
|
+
/** The longest page text the store keeps; a longer page is kept by name only. */
|
|
21
|
+
export const TEXT_LIMIT = 1_000_000;
|
|
22
|
+
/** The shared store with notion's provider entry; a read, or any run under the read-only lock, opens it read-only. */
|
|
23
|
+
export const openStore = (env, write) => openAppStore(env, {
|
|
24
|
+
app: IDENTITY,
|
|
25
|
+
provider: PROVIDER,
|
|
26
|
+
readOnly: !write || readOnlyLockOf(IDENTITY, env) !== undefined,
|
|
27
|
+
});
|
|
28
|
+
export const withStore = async (env, write, fn) => {
|
|
29
|
+
const store = await openStore(env, write);
|
|
30
|
+
try {
|
|
31
|
+
return await fn(store);
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await store.close();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const profileDir = (env, profile) => join(resolvePaths({ appName: IDENTITY.appName, prefix: IDENTITY.envPrefix, env }).state, "profiles", profile);
|
|
38
|
+
const readJson = (path) => {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error.code === "ENOENT")
|
|
44
|
+
return undefined;
|
|
45
|
+
throw new CliError("configuration_error", `${path} cannot be read; move it away and sync again`, {
|
|
46
|
+
reason: "state.unreadable",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const writeJson = (path, value) => writeSecurely(path, JSON.stringify(value), 0o600);
|
|
51
|
+
const foldersOf = (env, profile) => readJson(join(profileDir(env, profile), "folders.json"));
|
|
52
|
+
export const chosenFolders = (env, profile) => foldersOf(env, profile)?.roots ?? [];
|
|
53
|
+
export const foldersChangedAt = (env, profile) => foldersOf(env, profile)?.changed_at;
|
|
54
|
+
export const saveFolders = (env, profile, roots) => writeJson(join(profileDir(env, profile), "folders.json"), { roots, changed_at: new Date().toISOString() });
|
|
55
|
+
export const rootsOf = (env, profile) => {
|
|
56
|
+
const chosen = chosenFolders(env, profile);
|
|
57
|
+
return chosen.length ? chosen : [WORKSPACE_ROOT];
|
|
58
|
+
};
|
|
59
|
+
/** A Notion id is a file name as it is; anything else is hashed, so no id can reach outside the folder. */
|
|
60
|
+
const fileName = (id) => /^[0-9a-f-]{1,64}$/u.test(id) ? id : createHash("sha256").update(id).digest("hex").slice(0, 40);
|
|
61
|
+
export const syncState = (env, profile, principal) => {
|
|
62
|
+
const dir = join(profileDir(env, profile), "sync");
|
|
63
|
+
const snapshot = (id) => join(dir, "snapshots", `${fileName(id)}.json`);
|
|
64
|
+
return {
|
|
65
|
+
read: () => readJson(join(dir, "state.json")) ?? {
|
|
66
|
+
version: 1,
|
|
67
|
+
principal,
|
|
68
|
+
scope: "",
|
|
69
|
+
folders: {},
|
|
70
|
+
documents: {},
|
|
71
|
+
skipped: [],
|
|
72
|
+
},
|
|
73
|
+
save: (state) => writeJson(join(dir, "state.json"), state),
|
|
74
|
+
readWalk: (scope) => {
|
|
75
|
+
const walk = readJson(join(dir, "walk.json"));
|
|
76
|
+
return walk?.scope === scope ? walk : undefined;
|
|
77
|
+
},
|
|
78
|
+
saveWalk: (walk) => writeJson(join(dir, "walk.json"), walk),
|
|
79
|
+
removeWalk: () => rmSync(join(dir, "walk.json"), { force: true }),
|
|
80
|
+
saveSnapshot: (content) => writeJson(snapshot(content.metadata.id), content),
|
|
81
|
+
removeSnapshot: (id) => rmSync(snapshot(id), { force: true }),
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
/** The engine's planning walk, when one is under way: it is saved between runs until the plan is made. */
|
|
85
|
+
export const walkUnderWay = (env, profile) => existsSync(join(profileDir(env, profile), "sync", "walk.json"));
|
|
86
|
+
export const readSnapshot = (env, profile, id) => readJson(join(profileDir(env, profile), "sync", "snapshots", `${fileName(id)}.json`));
|
|
87
|
+
/** What the sync holds, for the source to tell a page it missed from one Notion deleted. */
|
|
88
|
+
export const knownOf = (state) => [
|
|
89
|
+
...Object.values(state.documents).map((doc) => doc.metadata),
|
|
90
|
+
...Object.values(state.folders).filter((folder) => !state.documents[folder.id]),
|
|
91
|
+
];
|
|
92
|
+
/**
|
|
93
|
+
* The lock a sync and every write to the profile's local copy take, so a tag added during a sync is not lost. A
|
|
94
|
+
* second holder is refused at once: waiting would hold an agent's tool call for the length of a sync.
|
|
95
|
+
*/
|
|
96
|
+
export const withProfileLock = async (env, profile, fn) => {
|
|
97
|
+
const lock = await acquireLock(join(profileDir(env, profile), "sync.lock")).catch((error) => {
|
|
98
|
+
throw new CliError("provider_unavailable", "another sync or write holds this profile's local copy; retry later", {
|
|
99
|
+
reason: "profile.busy",
|
|
100
|
+
...(error instanceof CliError ? { holders: error.details.holders } : {}),
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
let held = true;
|
|
104
|
+
try {
|
|
105
|
+
return await fn(() => {
|
|
106
|
+
if (!held)
|
|
107
|
+
throw new CliError("provider_unavailable", "the profile's lock was released", { reason: "profile.busy" });
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
held = false;
|
|
112
|
+
await lock.release();
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const recalled = (env, profile) => readJson(accountFileFor(IDENTITY, profile, env))?.account;
|
|
116
|
+
/** The account a profile has synced as: local reads never ask Notion, and a profile only signed in has no copy. */
|
|
117
|
+
export const principalOf = (env, profile) => {
|
|
118
|
+
const account = recalled(env, profile);
|
|
119
|
+
if (typeof account !== "string" || !existsSync(join(profileDir(env, profile), "sync", "state.json")))
|
|
120
|
+
throw new CliError("not_found", `profile ${profile} has no local copy yet — ${IDENTITY.command} ${profile} sync`, {
|
|
121
|
+
reason: "profile.not-synced",
|
|
122
|
+
});
|
|
123
|
+
return account;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Takes a Notion connection for a profile, before its token is kept or its copy written. One connection is one
|
|
127
|
+
* account in the shared store, so two profiles on it would each remove the other's pages; and a profile's local copy
|
|
128
|
+
* stays with the connection it was synced from.
|
|
129
|
+
*/
|
|
130
|
+
export const claimAccount = (env, profile, account, tokens) => {
|
|
131
|
+
// A token from the environment variable signs every profile in, so each profile synced under it holds its account.
|
|
132
|
+
const signedIn = (name) => tokens.read(name) !== undefined;
|
|
133
|
+
const other = profilesHere(IDENTITY, [], env).find((name) => name !== profile && recalled(env, name) === account && signedIn(name));
|
|
134
|
+
const cli = IDENTITY.command;
|
|
135
|
+
if (other) {
|
|
136
|
+
const fromVariable = tokens.read(other)?.source === "environment";
|
|
137
|
+
throw new CliError("conflict", `profile ${other} already uses this Notion connection; use \`${cli} ${other} …\`, or ` +
|
|
138
|
+
(fromVariable
|
|
139
|
+
? `give this profile its own token instead of ${IDENTITY.envPrefix}_TOKEN`
|
|
140
|
+
: `run \`${cli} ${other} session end\` first`), { reason: "profile.account-taken", profile: other });
|
|
141
|
+
}
|
|
142
|
+
const synced = syncState(env, profile, "").read().principal;
|
|
143
|
+
if (synced && synced !== account)
|
|
144
|
+
throw new CliError("conflict", `profile ${profile} holds a copy synced from another Notion connection; sign this token in under a new ` +
|
|
145
|
+
`profile (\`${cli} <new profile> session start\`), or keep this profile's own token`, { reason: "profile.other-account" });
|
|
146
|
+
if (recalled(env, profile) !== account)
|
|
147
|
+
rememberAccount(IDENTITY, profile, account, env);
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=library.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library.js","sourceRoot":"","sources":["../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEzE,OAAO,EACL,cAAc,EACd,YAAY,EAEZ,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxC,OAAO,EAAmB,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAElE,mHAAmH;AACnH,wGAAwG;AAExG,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,WAAW;IACjB,OAAO,EAAE,EAAE;IACX,OAAO,EAAE,QAAQ,CAAC,OAAO;IACzB,KAAK,EAAE,EAAE,QAAQ,EAAE,gBAAgB,EAA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AQ,CAAC,SAAS,QAAQ;gBAC1E,CAAC,CAAC,SAAS,GAAG,IAAI,KAAK,sBAAsB,CAAC,EAClD,EAAE,MAAM,EAAE,uBAAuB,EAAE,OAAO,EAAE,KAAK,EAAE,CACpD,CAAA;IACH,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,SAAS,CAAA;IAC3D,IAAI,MAAM,IAAI,MAAM,KAAK,OAAO;QAC9B,MAAM,IAAI,QAAQ,CAChB,UAAU,EACV,WAAW,OAAO,sFAAsF;YACtG,cAAc,GAAG,mEAAmE,EACtF,EAAE,MAAM,EAAE,uBAAuB,EAAE,CACpC,CAAA;IACH,IAAI,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,KAAK,OAAO;QAAE,eAAe,CAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,CAAA;AAC1F,CAAC,CAAA"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Client } from "@notionhq/client";
|
|
2
|
+
import { type SleepLike } from "@wirecat/cli-base";
|
|
3
|
+
import { type FetchLike, type PacerLike } from "@wirecat/cli-base/http";
|
|
4
|
+
import { type EventSink } from "@wirecat/cli-core/cli";
|
|
5
|
+
export declare const API_HOST = "api.notion.com";
|
|
6
|
+
/** The API version every request names ([versioning](https://developers.notion.com/reference/versioning)). */
|
|
7
|
+
export declare const NOTION_VERSION = "2026-03-11";
|
|
8
|
+
/**
|
|
9
|
+
* 180 a minute per connection, the lower plan's limit; data source queries have a limit of their own, "about 3
|
|
10
|
+
* requests per second per connection" ([request limits](https://developers.notion.com/reference/request-limits)).
|
|
11
|
+
*/
|
|
12
|
+
export declare const PACE: {
|
|
13
|
+
perMinute: number;
|
|
14
|
+
burst: number;
|
|
15
|
+
};
|
|
16
|
+
export declare const QUERY_PACE: {
|
|
17
|
+
perMinute: number;
|
|
18
|
+
burst: number;
|
|
19
|
+
};
|
|
20
|
+
/** The run record keeps the path's shape, never a page id (WC-LIFE-15). */
|
|
21
|
+
export declare const operationOf: (method: string, url: URL) => string;
|
|
22
|
+
/** Search, queries and the other POSTs in READ_POSTS change nothing: they may be sent again. */
|
|
23
|
+
export declare const isRead: (method: string, url: URL) => boolean;
|
|
24
|
+
export interface NotionClientOptions {
|
|
25
|
+
token: string;
|
|
26
|
+
fetch?: FetchLike | undefined;
|
|
27
|
+
signal?: AbortSignal | undefined;
|
|
28
|
+
events?: EventSink | undefined;
|
|
29
|
+
pacer?: PacerLike | undefined;
|
|
30
|
+
/** The data source queries' own pace, taken on top of `pacer`. */
|
|
31
|
+
queryPacer?: PacerLike | undefined;
|
|
32
|
+
sleep?: SleepLike;
|
|
33
|
+
now?: () => Date;
|
|
34
|
+
/** Sees every answer Notion gives, as `notionClock` does for its Date header. */
|
|
35
|
+
onAnswer?: (response: Response) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Every request's one path to Notion: paced per profile, retried by cli-base, data source queries on a pace of their own. */
|
|
38
|
+
export declare const notionFetch: (options: Omit<NotionClientOptions, "token">) => FetchLike;
|
|
39
|
+
/**
|
|
40
|
+
* The SDK puts the token in the Authorization header, as the `api` commands' executor does. The SDK's own retries and console
|
|
41
|
+
* logger are off: retries are cli-base's, paced by cli-core's Pacer, and the logger would print Notion's messages and
|
|
42
|
+
* answer bodies (WC-SECR-6, WC-OUT-20).
|
|
43
|
+
*/
|
|
44
|
+
export declare const notionClient: (options: NotionClientOptions) => Client;
|
|
45
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAE,KAAK,SAAS,EAAa,KAAK,SAAS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|
+
import { hostFetch, retrying, statusToCode } from "@wirecat/cli-base/http";
|
|
4
|
+
import { providerRequest } from "@wirecat/cli-core/cli";
|
|
5
|
+
import { BLOCKED, blocked, NOTION } from "./errors.js";
|
|
6
|
+
import { READ_POST_PATHS } from "./read-posts.js";
|
|
7
|
+
export const API_HOST = "api.notion.com";
|
|
8
|
+
/** The API version every request names ([versioning](https://developers.notion.com/reference/versioning)). */
|
|
9
|
+
export const NOTION_VERSION = "2026-03-11";
|
|
10
|
+
/** Notion ends a request after 60 s ([status codes](https://developers.notion.com/reference/status-codes), 503). */
|
|
11
|
+
const EXCHANGE_MS = 70_000;
|
|
12
|
+
const LARGEST_ANSWER = 16 * 1024 * 1024;
|
|
13
|
+
/** A pace or retry wait longer than this ends the run with `rate_limited` instead of sitting in it. */
|
|
14
|
+
const LONGEST_WAIT_MS = 60_000;
|
|
15
|
+
/** Notion's guide retries 429 and 529 with `Retry-After`, then backs off ([request limits](https://developers.notion.com/reference/request-limits)). */
|
|
16
|
+
const RETRY = { retries: 3, baseDelayMs: 500, maxDelayMs: 10_000, maxRetryAfterMs: LONGEST_WAIT_MS };
|
|
17
|
+
/**
|
|
18
|
+
* 180 a minute per connection, the lower plan's limit; data source queries have a limit of their own, "about 3
|
|
19
|
+
* requests per second per connection" ([request limits](https://developers.notion.com/reference/request-limits)).
|
|
20
|
+
*/
|
|
21
|
+
export const PACE = { perMinute: 170, burst: 10 };
|
|
22
|
+
export const QUERY_PACE = { perMinute: 170, burst: 3 };
|
|
23
|
+
const ID = /[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}/giu;
|
|
24
|
+
const QUERY = /^\/v1\/data_sources\/[^/]+\/query$/u;
|
|
25
|
+
/** The run record keeps the path's shape, never a page id (WC-LIFE-15). */
|
|
26
|
+
export const operationOf = (method, url) => `${method} ${url.pathname.replace(ID, ":id")}`;
|
|
27
|
+
/** Search, queries and the other POSTs in READ_POSTS change nothing: they may be sent again. */
|
|
28
|
+
export const isRead = (method, url) => method === "GET" || (method === "POST" && READ_POST_PATHS.some((path) => path.test(url.pathname)));
|
|
29
|
+
const both = (first, second) => ({
|
|
30
|
+
reserve: async () => Math.max(await first.reserve(), await second.reserve()),
|
|
31
|
+
holdFor: async (ms) => {
|
|
32
|
+
await Promise.all([first.holdFor(ms), second.holdFor(ms)]);
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
/** The SDK reads the whole body as text; past the cap the stream fails, and the SDK passes that error on as it is. */
|
|
36
|
+
const bounded = (response) => {
|
|
37
|
+
if (!response.body)
|
|
38
|
+
return response;
|
|
39
|
+
let bytes = 0;
|
|
40
|
+
const capped = response.body.pipeThrough(new TransformStream({
|
|
41
|
+
transform(chunk, controller) {
|
|
42
|
+
bytes += chunk.byteLength;
|
|
43
|
+
if (bytes > LARGEST_ANSWER)
|
|
44
|
+
controller.error(new CliError("invalid_response", `${NOTION}'s answer is over ${LARGEST_ANSWER} bytes`));
|
|
45
|
+
else
|
|
46
|
+
controller.enqueue(chunk);
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
return new Response(capped, { status: response.status, statusText: response.statusText, headers: response.headers });
|
|
50
|
+
};
|
|
51
|
+
/** Notion's 429 body names why; a blocked connection must reach cli-base's retry as a failure, not a 429. */
|
|
52
|
+
const blockedAnswer = async (response) => {
|
|
53
|
+
try {
|
|
54
|
+
const body = (await response.clone().json());
|
|
55
|
+
return body.additional_data?.rate_limit_reason === BLOCKED;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* One attempt: only api.notion.com, no redirect (it would carry the token elsewhere), the run's signal, and a record
|
|
63
|
+
* of the call under its path template. A failure to reach Notion is already a retryable CliError from `hostFetch`.
|
|
64
|
+
*/
|
|
65
|
+
const attempt = (send, options) => async (input, init = {}) => {
|
|
66
|
+
const url = new URL(String(input));
|
|
67
|
+
const method = (init.method ?? "GET").toUpperCase();
|
|
68
|
+
const end = providerRequest(operationOf(method, url), options.events, { method, transport: "http" });
|
|
69
|
+
try {
|
|
70
|
+
const response = await send(url, {
|
|
71
|
+
...init,
|
|
72
|
+
redirect: "error",
|
|
73
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
74
|
+
});
|
|
75
|
+
options.onAnswer?.(response);
|
|
76
|
+
if (response.status === 429 && (await blockedAnswer(response))) {
|
|
77
|
+
await response.body?.cancel().catch(() => { });
|
|
78
|
+
throw blocked({ status: 429, notion_code: "rate_limited", sent: false });
|
|
79
|
+
}
|
|
80
|
+
end({ status: response.status, ...(response.ok ? {} : { errorCode: statusToCode(response.status) }) });
|
|
81
|
+
return bounded(response);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
end({ error, errorCode: error instanceof CliError ? error.code : "network_error" });
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/** Every request's one path to Notion: paced per profile, retried by cli-base, data source queries on a pace of their own. */
|
|
89
|
+
export const notionFetch = (options) => {
|
|
90
|
+
const once = attempt(hostFetch({ hosts: [API_HOST], timeoutMs: EXCHANGE_MS, ...(options.fetch ? { fetch: options.fetch } : {}) }), options);
|
|
91
|
+
const common = {
|
|
92
|
+
retry: RETRY,
|
|
93
|
+
budget: LONGEST_WAIT_MS,
|
|
94
|
+
reads: (method, url) => isRead(method, url),
|
|
95
|
+
...(options.sleep ? { sleep: options.sleep } : {}),
|
|
96
|
+
...(options.now ? { now: options.now } : {}),
|
|
97
|
+
};
|
|
98
|
+
const general = retrying(once, { ...common, ...(options.pacer ? { pacer: options.pacer } : {}) });
|
|
99
|
+
const queryPacer = options.pacer && options.queryPacer
|
|
100
|
+
? both(options.pacer, options.queryPacer)
|
|
101
|
+
: (options.queryPacer ?? options.pacer);
|
|
102
|
+
const queries = retrying(once, { ...common, ...(queryPacer ? { pacer: queryPacer } : {}) });
|
|
103
|
+
return (input, init) => (QUERY.test(new URL(String(input)).pathname) ? queries : general)(input, init);
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* The SDK puts the token in the Authorization header, as the `api` commands' executor does. The SDK's own retries and console
|
|
107
|
+
* logger are off: retries are cli-base's, paced by cli-core's Pacer, and the logger would print Notion's messages and
|
|
108
|
+
* answer bodies (WC-SECR-6, WC-OUT-20).
|
|
109
|
+
*/
|
|
110
|
+
export const notionClient = (options) => {
|
|
111
|
+
const fetch = notionFetch(options);
|
|
112
|
+
return new Client({
|
|
113
|
+
auth: options.token,
|
|
114
|
+
notionVersion: NOTION_VERSION,
|
|
115
|
+
fetch: fetch,
|
|
116
|
+
retry: false,
|
|
117
|
+
timeoutMs: EXCHANGE_MS + LONGEST_WAIT_MS + 10_000,
|
|
118
|
+
logger: () => { },
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/notion/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAkB,MAAM,mBAAmB,CAAA;AAC5D,OAAO,EAAkB,SAAS,EAAkB,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAC1G,OAAO,EAAkB,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,CAAC,MAAM,QAAQ,GAAG,gBAAgB,CAAA;AACxC,8GAA8G;AAC9G,MAAM,CAAC,MAAM,cAAc,GAAG,YAAY,CAAA;AAE1C,oHAAoH;AACpH,MAAM,WAAW,GAAG,MAAM,CAAA;AAC1B,MAAM,cAAc,GAAG,EAAE,GAAG,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