@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,58 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
importFrom
|
|
5
|
+
} from "./chunk-Y5E2WNWB.js";
|
|
6
|
+
import {
|
|
7
|
+
CliError
|
|
8
|
+
} from "./chunk-5RDNBG7D.js";
|
|
9
|
+
import {
|
|
10
|
+
__name
|
|
11
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
12
|
+
|
|
13
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.673.0_@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typ_d24fa0f4f3b37e009a0e8224eb6a2687/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
var musl = /* @__PURE__ */ __name(() => {
|
|
16
|
+
if (process.platform !== "linux")
|
|
17
|
+
return false;
|
|
18
|
+
try {
|
|
19
|
+
return readFileSync("/proc/self/maps", "utf8").includes("ld-musl");
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}, "musl");
|
|
24
|
+
var found;
|
|
25
|
+
var vectorExtension = /* @__PURE__ */ __name(() => {
|
|
26
|
+
found ??= locate();
|
|
27
|
+
return found;
|
|
28
|
+
}, "vectorExtension");
|
|
29
|
+
var locate = /* @__PURE__ */ __name(async () => {
|
|
30
|
+
const onMusl = musl();
|
|
31
|
+
const target = `${process.platform}-${process.arch}${onMusl ? "-musl" : ""}`;
|
|
32
|
+
let path;
|
|
33
|
+
try {
|
|
34
|
+
const { extensionFor } = await importFrom(new URL("store/vector-extension.js", import.meta.resolve("@wirecat/cli-core")).href, "@wirecat/cli-core-sqlite");
|
|
35
|
+
path = extensionFor({ musl: onMusl });
|
|
36
|
+
} catch {
|
|
37
|
+
path = void 0;
|
|
38
|
+
}
|
|
39
|
+
if (path === void 0) {
|
|
40
|
+
found = void 0;
|
|
41
|
+
throw new CliError("configuration_error", `the message store needs the sqlite-vec extension, and @wirecat/cli-core-sqlite has none for ${target} \u2014 reinstall the CLI so its dependencies install with it (an install that skips optional or native packages leaves it out)`, { reason: "store.vector-extension-missing", target });
|
|
42
|
+
}
|
|
43
|
+
return path;
|
|
44
|
+
}, "locate");
|
|
45
|
+
var loadVectorExtension = /* @__PURE__ */ __name((database, path) => {
|
|
46
|
+
try {
|
|
47
|
+
database.loadExtension(path);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
throw new CliError("configuration_error", `the sqlite-vec extension did not load on ${process.platform}-${process.arch} \u2014 reinstall the CLI; on macOS under Bun, @wirecat/cli-core-sqlite's SQLite must be installed, since the system's cannot load extensions`, { reason: "store.vector-extension-failed", cause: error instanceof Error ? error.message : String(error) });
|
|
50
|
+
} finally {
|
|
51
|
+
database.enableLoadExtension?.(false);
|
|
52
|
+
}
|
|
53
|
+
}, "loadVectorExtension");
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
vectorExtension,
|
|
57
|
+
loadVectorExtension
|
|
58
|
+
};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_RETRY,
|
|
5
|
+
backoffMs,
|
|
6
|
+
realSleep,
|
|
7
|
+
wallClock
|
|
8
|
+
} from "./chunk-3AL7QUS3.js";
|
|
9
|
+
import {
|
|
10
|
+
CliError,
|
|
11
|
+
isCliError
|
|
12
|
+
} from "./chunk-5RDNBG7D.js";
|
|
13
|
+
import {
|
|
14
|
+
__name
|
|
15
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
16
|
+
|
|
17
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/body.js
|
|
18
|
+
var interrupted = /* @__PURE__ */ __name((signal) => isCliError(signal.reason) ? signal.reason : new CliError(signal.reason instanceof Error && signal.reason.name === "TimeoutError" ? "timeout" : "cancelled", "HTTP response read was interrupted"), "interrupted");
|
|
19
|
+
var checked = /* @__PURE__ */ __name((signal) => {
|
|
20
|
+
if (signal?.aborted)
|
|
21
|
+
throw interrupted(signal);
|
|
22
|
+
}, "checked");
|
|
23
|
+
var abortable = /* @__PURE__ */ __name(async (pending, signal) => {
|
|
24
|
+
if (!signal)
|
|
25
|
+
return pending;
|
|
26
|
+
let abort = /* @__PURE__ */ __name(() => {
|
|
27
|
+
}, "abort");
|
|
28
|
+
const stopped = new Promise((_, reject) => {
|
|
29
|
+
abort = /* @__PURE__ */ __name(() => reject(interrupted(signal)), "abort");
|
|
30
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
31
|
+
if (signal.aborted)
|
|
32
|
+
abort();
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
return await Promise.race([pending, stopped]);
|
|
36
|
+
} finally {
|
|
37
|
+
signal.removeEventListener("abort", abort);
|
|
38
|
+
}
|
|
39
|
+
}, "abortable");
|
|
40
|
+
var readJsonResponse = /* @__PURE__ */ __name(async (response, options) => {
|
|
41
|
+
const { maxBytes, signal } = options ?? {};
|
|
42
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
43
|
+
throw new CliError("validation_error", "maxBytes must be a positive safe integer");
|
|
44
|
+
if (signal !== void 0 && !(signal instanceof AbortSignal))
|
|
45
|
+
throw new CliError("validation_error", "signal must be an AbortSignal");
|
|
46
|
+
if (signal?.aborted) {
|
|
47
|
+
void response.body?.cancel().catch(() => {
|
|
48
|
+
});
|
|
49
|
+
throw interrupted(signal);
|
|
50
|
+
}
|
|
51
|
+
const length = response.headers.get("content-length");
|
|
52
|
+
if (length !== null && (!/^\d+$/.test(length) || Number(length) > maxBytes)) {
|
|
53
|
+
void response.body?.cancel().catch(() => {
|
|
54
|
+
});
|
|
55
|
+
throw new CliError("invalid_response", "HTTP response exceeds the byte budget");
|
|
56
|
+
}
|
|
57
|
+
if (!response.body)
|
|
58
|
+
throw new CliError("invalid_response", "HTTP response has no body");
|
|
59
|
+
if (response.body.locked)
|
|
60
|
+
throw new CliError("invalid_response", "HTTP response body is already in use");
|
|
61
|
+
const reader = response.body.getReader();
|
|
62
|
+
const chunks = [];
|
|
63
|
+
let bytes = 0;
|
|
64
|
+
try {
|
|
65
|
+
for (; ; ) {
|
|
66
|
+
checked(signal);
|
|
67
|
+
const part = await abortable(reader.read(), signal);
|
|
68
|
+
checked(signal);
|
|
69
|
+
if (part.done)
|
|
70
|
+
break;
|
|
71
|
+
if (!(part.value instanceof Uint8Array))
|
|
72
|
+
throw new CliError("invalid_response", "HTTP response is not bytes");
|
|
73
|
+
bytes += part.value.byteLength;
|
|
74
|
+
if (bytes > maxBytes)
|
|
75
|
+
throw new CliError("invalid_response", "HTTP response exceeds the byte budget");
|
|
76
|
+
if (part.value.byteLength)
|
|
77
|
+
chunks.push(new Uint8Array(part.value));
|
|
78
|
+
}
|
|
79
|
+
const body = new Uint8Array(bytes);
|
|
80
|
+
let offset = 0;
|
|
81
|
+
for (const chunk of chunks) {
|
|
82
|
+
body.set(chunk, offset);
|
|
83
|
+
offset += chunk.byteLength;
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
|
|
87
|
+
} catch {
|
|
88
|
+
throw new CliError("invalid_response", "HTTP response is not valid UTF-8 JSON");
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
checked(signal);
|
|
92
|
+
if (isCliError(error))
|
|
93
|
+
throw error;
|
|
94
|
+
throw new CliError("network_error", "HTTP response could not be read");
|
|
95
|
+
} finally {
|
|
96
|
+
void reader.cancel().catch(() => {
|
|
97
|
+
});
|
|
98
|
+
reader.releaseLock();
|
|
99
|
+
}
|
|
100
|
+
}, "readJsonResponse");
|
|
101
|
+
|
|
102
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/hosts.js
|
|
103
|
+
var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
|
|
104
|
+
var HOST_PATTERN = new RegExp(`^(?:${LABEL}(?:\\.${LABEL})*|\\*\\.${LABEL}(?:\\.${LABEL})+)$`);
|
|
105
|
+
var hostProblems = /* @__PURE__ */ __name((hosts) => [
|
|
106
|
+
...hosts.filter((host) => !HOST_PATTERN.test(host) || host.length > 253).map((host) => `${JSON.stringify(host)} is not a host: a lower-case hostname with no scheme, port or path, or one leading *. before two labels or more`),
|
|
107
|
+
...hosts.filter((host, at) => hosts.indexOf(host) !== at).map((host) => `${JSON.stringify(host)} is listed twice`)
|
|
108
|
+
], "hostProblems");
|
|
109
|
+
var hostCovered = /* @__PURE__ */ __name((hostname, hosts) => {
|
|
110
|
+
const name = hostname.toLowerCase().replace(/\.$/, "");
|
|
111
|
+
return hosts.some((host) => host.startsWith("*.") ? name.endsWith(host.slice(1)) : name === host);
|
|
112
|
+
}, "hostCovered");
|
|
113
|
+
|
|
114
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/fetch.js
|
|
115
|
+
var HOST_FETCH_TIMEOUT_MS = 3e4;
|
|
116
|
+
var REDIRECTS = 5;
|
|
117
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
118
|
+
var CREDENTIAL_HEADERS = ["authorization", "cookie", "proxy-authorization"];
|
|
119
|
+
var NO_BODY = /* @__PURE__ */ new Set([204, 205, 304]);
|
|
120
|
+
var deadline = /* @__PURE__ */ __name((ms) => {
|
|
121
|
+
const controller = new AbortController();
|
|
122
|
+
const timer = setTimeout(() => controller.abort(new DOMException(`no answer within ${ms} ms`, "TimeoutError")), ms);
|
|
123
|
+
timer.unref?.();
|
|
124
|
+
return { signal: controller.signal, clear: /* @__PURE__ */ __name(() => clearTimeout(timer), "clear") };
|
|
125
|
+
}, "deadline");
|
|
126
|
+
var released = /* @__PURE__ */ __name((response, clear) => {
|
|
127
|
+
if (!response.body || NO_BODY.has(response.status) || response.status < 200 || response.status > 599) {
|
|
128
|
+
clear();
|
|
129
|
+
return response;
|
|
130
|
+
}
|
|
131
|
+
const { status, statusText, headers, url, redirected } = response;
|
|
132
|
+
const wrapped = new Response(response.body.pipeThrough(new TransformStream({ flush: clear })), {
|
|
133
|
+
status,
|
|
134
|
+
statusText,
|
|
135
|
+
headers
|
|
136
|
+
});
|
|
137
|
+
return Object.defineProperties(wrapped, { url: { value: url }, redirected: { value: redirected } });
|
|
138
|
+
}, "released");
|
|
139
|
+
var undeclared = /* @__PURE__ */ __name((url) => new CliError("configuration_error", `${url.hostname} is not a host this CLI declares: add "${url.hostname}" to \`hosts\` in its WCAT identity and run cli-dev manifest`, { reason: "network.host-undeclared", sent: false }), "undeclared");
|
|
140
|
+
var checked2 = /* @__PURE__ */ __name((url, hosts) => {
|
|
141
|
+
if (url.protocol !== "https:" && url.protocol !== "http:")
|
|
142
|
+
throw new CliError("validation_error", `only http and https are fetched, not ${url.protocol.replace(/:$/, "")}`, {
|
|
143
|
+
sent: false
|
|
144
|
+
});
|
|
145
|
+
if (!hostCovered(url.hostname, hosts))
|
|
146
|
+
throw undeclared(url);
|
|
147
|
+
return url;
|
|
148
|
+
}, "checked");
|
|
149
|
+
var hostFetch = /* @__PURE__ */ __name((options) => {
|
|
150
|
+
const problems = hostProblems(options.hosts);
|
|
151
|
+
if (problems.length > 0)
|
|
152
|
+
throw new CliError("configuration_error", problems.join("; "));
|
|
153
|
+
const { hosts, fetch: send = globalThis.fetch, timeoutMs = HOST_FETCH_TIMEOUT_MS, redirects = REDIRECTS } = options;
|
|
154
|
+
return async (input, init = {}) => {
|
|
155
|
+
const request = input instanceof Request ? input : void 0;
|
|
156
|
+
let url = checked2(new URL(request?.url ?? String(input)), hosts);
|
|
157
|
+
const caller = init.signal ?? request?.signal;
|
|
158
|
+
const timeout = deadline(timeoutMs);
|
|
159
|
+
const signal = caller ? AbortSignal.any([caller, timeout.signal]) : timeout.signal;
|
|
160
|
+
const follow = (init.redirect ?? request?.redirect ?? "follow") === "follow";
|
|
161
|
+
let method = (init.method ?? request?.method ?? "GET").toUpperCase();
|
|
162
|
+
let body = init.body ?? request?.body ?? void 0;
|
|
163
|
+
const headers = new Headers(init.headers ?? request?.headers);
|
|
164
|
+
try {
|
|
165
|
+
let response = await send(input, { ...init, signal, ...follow ? { redirect: "manual" } : {} });
|
|
166
|
+
for (let hop = 0; follow && REDIRECT_STATUSES.has(response.status); hop += 1) {
|
|
167
|
+
const location = response.headers.get("location");
|
|
168
|
+
if (!location)
|
|
169
|
+
return released(response, timeout.clear);
|
|
170
|
+
if (hop >= redirects)
|
|
171
|
+
throw new CliError("invalid_response", `more than ${redirects} redirects from ${url.hostname}`);
|
|
172
|
+
void response.body?.cancel().catch(() => {
|
|
173
|
+
});
|
|
174
|
+
const next = checked2(new URL(location, url), hosts);
|
|
175
|
+
if (response.status === 303 || (response.status === 301 || response.status === 302) && method === "POST") {
|
|
176
|
+
method = method === "HEAD" ? "HEAD" : "GET";
|
|
177
|
+
body = void 0;
|
|
178
|
+
headers.delete("content-type");
|
|
179
|
+
headers.delete("content-length");
|
|
180
|
+
} else if (body instanceof ReadableStream)
|
|
181
|
+
throw new CliError("invalid_response", `${url.hostname} redirected a streamed body, which cannot be sent again`);
|
|
182
|
+
if (next.origin !== url.origin)
|
|
183
|
+
for (const name of CREDENTIAL_HEADERS)
|
|
184
|
+
headers.delete(name);
|
|
185
|
+
url = next;
|
|
186
|
+
response = await send(url, { ...init, method, headers, body, signal, redirect: "manual" });
|
|
187
|
+
}
|
|
188
|
+
return released(response, timeout.clear);
|
|
189
|
+
} catch (error) {
|
|
190
|
+
timeout.clear();
|
|
191
|
+
if (isCliError(error))
|
|
192
|
+
throw error;
|
|
193
|
+
if (caller?.aborted)
|
|
194
|
+
throw isCliError(caller.reason) ? caller.reason : new CliError("cancelled", "request cancelled");
|
|
195
|
+
if (timeout.signal.aborted)
|
|
196
|
+
throw new CliError("timeout", `${url.hostname} did not answer within ${timeoutMs} ms`, { retryable: true });
|
|
197
|
+
throw new CliError("network_error", `${url.hostname} could not be reached`, { retryable: true });
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}, "hostFetch");
|
|
201
|
+
|
|
202
|
+
// node_modules/.pnpm/@wirecat+cli-base@0.102.1_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/index.js
|
|
203
|
+
var parseRetryAfter = /* @__PURE__ */ __name((header, now) => {
|
|
204
|
+
if (!header)
|
|
205
|
+
return void 0;
|
|
206
|
+
const trimmed = header.trim();
|
|
207
|
+
if (/^\d+$/.test(trimmed))
|
|
208
|
+
return Number(trimmed) * 1e3;
|
|
209
|
+
const at = Date.parse(trimmed);
|
|
210
|
+
if (Number.isNaN(at))
|
|
211
|
+
return void 0;
|
|
212
|
+
const delta = at - now().getTime();
|
|
213
|
+
return delta > 0 ? delta : void 0;
|
|
214
|
+
}, "parseRetryAfter");
|
|
215
|
+
var parseRateLimitReset = /* @__PURE__ */ __name((header, now) => {
|
|
216
|
+
if (!header)
|
|
217
|
+
return void 0;
|
|
218
|
+
const seconds = Number(header.trim());
|
|
219
|
+
if (!Number.isFinite(seconds))
|
|
220
|
+
return void 0;
|
|
221
|
+
const delta = seconds * 1e3 - now().getTime();
|
|
222
|
+
return delta > 0 ? delta : void 0;
|
|
223
|
+
}, "parseRateLimitReset");
|
|
224
|
+
var providerWaitMs = /* @__PURE__ */ __name((headers, now) => parseRetryAfter(headers.get("retry-after"), now) ?? parseRateLimitReset(headers.get("x-ratelimit-reset"), now), "providerWaitMs");
|
|
225
|
+
var retryableStatus = /* @__PURE__ */ __name((status) => status === 408 || status === 429 || status >= 500, "retryableStatus");
|
|
226
|
+
var statusToCode = /* @__PURE__ */ __name((status) => {
|
|
227
|
+
if (status === 400 || status === 422)
|
|
228
|
+
return "validation_error";
|
|
229
|
+
if (status === 401)
|
|
230
|
+
return "authentication_error";
|
|
231
|
+
if (status === 403)
|
|
232
|
+
return "permission_error";
|
|
233
|
+
if (status === 404)
|
|
234
|
+
return "not_found";
|
|
235
|
+
if (status === 408)
|
|
236
|
+
return "timeout";
|
|
237
|
+
if (status === 429)
|
|
238
|
+
return "rate_limited";
|
|
239
|
+
if (status === 502 || status === 503 || status === 504)
|
|
240
|
+
return "provider_unavailable";
|
|
241
|
+
return "provider_error";
|
|
242
|
+
}, "statusToCode");
|
|
243
|
+
var SAFE = /* @__PURE__ */ new Set(["GET", "HEAD", "OPTIONS"]);
|
|
244
|
+
var retrying = /* @__PURE__ */ __name((send, options = {}) => {
|
|
245
|
+
const { retry = DEFAULT_RETRY, reads = /* @__PURE__ */ __name((method) => SAFE.has(method), "reads"), pacer, budget = Number.POSITIVE_INFINITY, sleep = realSleep, now = wallClock, random = Math.random } = options;
|
|
246
|
+
return async (input, init = {}) => {
|
|
247
|
+
const request = input instanceof Request ? input : void 0;
|
|
248
|
+
const method = (init.method ?? request?.method ?? "GET").toUpperCase();
|
|
249
|
+
const read = reads(method, new URL(request?.url ?? String(input)));
|
|
250
|
+
const signal = init.signal ?? request?.signal ?? void 0;
|
|
251
|
+
const once = init.body instanceof ReadableStream;
|
|
252
|
+
let waited = 0;
|
|
253
|
+
const pause = /* @__PURE__ */ __name(async (ms) => {
|
|
254
|
+
waited += ms;
|
|
255
|
+
await sleep(ms, signal, "retry");
|
|
256
|
+
}, "pause");
|
|
257
|
+
for (let attempt = 1; ; attempt++) {
|
|
258
|
+
if (pacer) {
|
|
259
|
+
const wait = await pacer.reserve() - now().getTime();
|
|
260
|
+
if (wait > 0) {
|
|
261
|
+
if (waited + wait > budget)
|
|
262
|
+
throw new CliError("rate_limited", `the provider's pace needs a ${wait} ms wait, more than this run allows`, {
|
|
263
|
+
retry_after_ms: wait,
|
|
264
|
+
sent: false
|
|
265
|
+
});
|
|
266
|
+
await pause(wait);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const last = once || attempt > retry.retries;
|
|
270
|
+
try {
|
|
271
|
+
const response = await send(request && !last ? request.clone() : input, init);
|
|
272
|
+
if (last || !retryableStatus(response.status) || !(read || response.status === 429))
|
|
273
|
+
return response;
|
|
274
|
+
const wait = providerWaitMs(response.headers, now) ?? backoffMs(attempt, retry, random);
|
|
275
|
+
if (wait > retry.maxRetryAfterMs || waited + wait > budget)
|
|
276
|
+
return response;
|
|
277
|
+
await response.body?.cancel().catch(() => {
|
|
278
|
+
});
|
|
279
|
+
if (response.status === 429)
|
|
280
|
+
await pacer?.holdFor(wait);
|
|
281
|
+
await pause(wait);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (last || !read || signal?.aborted || !isCliError(error) || error.details.retryable !== true)
|
|
284
|
+
throw error;
|
|
285
|
+
const wait = backoffMs(attempt, retry, random);
|
|
286
|
+
if (waited + wait > budget)
|
|
287
|
+
throw error;
|
|
288
|
+
await pause(wait);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}, "retrying");
|
|
293
|
+
|
|
294
|
+
export {
|
|
295
|
+
readJsonResponse,
|
|
296
|
+
hostFetch,
|
|
297
|
+
providerWaitMs,
|
|
298
|
+
statusToCode,
|
|
299
|
+
retrying
|
|
300
|
+
};
|