tenjin-cli 0.1.0-alpha.13 → 0.1.0-alpha.15
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/README.md +51 -3
- package/dist/buy-VIRNSYGN.js +47 -0
- package/dist/{chunk-OC3EIDCP.js → chunk-2MYQN7HM.js} +71 -26
- package/dist/chunk-2MYQN7HM.js.map +1 -0
- package/dist/{chunk-XXY77EZJ.js → chunk-2RF2GIJQ.js} +57 -226
- package/dist/chunk-2RF2GIJQ.js.map +1 -0
- package/dist/chunk-3GL2Z5QK.js +57 -0
- package/dist/chunk-3GL2Z5QK.js.map +1 -0
- package/dist/{chunk-OXUJ3FXU.js → chunk-4CQIDQOT.js} +41 -8
- package/dist/chunk-4CQIDQOT.js.map +1 -0
- package/dist/{chunk-YMUJZWHB.js → chunk-4KG27W2S.js} +10 -10
- package/dist/chunk-4KG27W2S.js.map +1 -0
- package/dist/{chunk-SPUORKD7.js → chunk-5QQTYWEU.js} +13 -13
- package/dist/chunk-5QQTYWEU.js.map +1 -0
- package/dist/chunk-65DTCCJ7.js +21 -0
- package/dist/chunk-65DTCCJ7.js.map +1 -0
- package/dist/{chunk-BRAVLUGI.js → chunk-A5DKHMUN.js} +28 -13
- package/dist/chunk-A5DKHMUN.js.map +1 -0
- package/dist/chunk-B63XPWQ4.js +246 -0
- package/dist/chunk-B63XPWQ4.js.map +1 -0
- package/dist/{chunk-47YKYDOF.js → chunk-CAR6FHK6.js} +5 -5
- package/dist/{chunk-JVBMPU5G.js → chunk-CPCX67TI.js} +22 -22
- package/dist/{chunk-TXVC46SA.js → chunk-CQBVCYI2.js} +40 -53
- package/dist/chunk-CQBVCYI2.js.map +1 -0
- package/dist/chunk-DBU5CXBV.js +4731 -0
- package/dist/chunk-DBU5CXBV.js.map +1 -0
- package/dist/chunk-DHJD77OW.js +81 -0
- package/dist/chunk-DHJD77OW.js.map +1 -0
- package/dist/{chunk-XGZ5EVMB.js → chunk-EDZSNPE5.js} +2 -2
- package/dist/{chunk-736DW4V3.js → chunk-EFWZPUTC.js} +2 -2
- package/dist/chunk-EPFL6CTE.js +448 -0
- package/dist/chunk-EPFL6CTE.js.map +1 -0
- package/dist/{chunk-3P3ES4XU.js → chunk-GHLVXVZD.js} +3 -5
- package/dist/{chunk-3P3ES4XU.js.map → chunk-GHLVXVZD.js.map} +1 -1
- package/dist/{chunk-UUARTUY2.js → chunk-H3SOOJ2I.js} +264 -33
- package/dist/chunk-H3SOOJ2I.js.map +1 -0
- package/dist/{chunk-OUJDDY5L.js → chunk-HPJGOLTN.js} +32 -32
- package/dist/chunk-HPJGOLTN.js.map +1 -0
- package/dist/{chunk-J6FUAIRR.js → chunk-HRGBS2PA.js} +4 -6
- package/dist/{chunk-J6FUAIRR.js.map → chunk-HRGBS2PA.js.map} +1 -1
- package/dist/{chunk-NKN4YC5C.js → chunk-ITUXPJIS.js} +55 -58
- package/dist/chunk-ITUXPJIS.js.map +1 -0
- package/dist/{chunk-CA3JV7FX.js → chunk-JBIKAAT3.js} +2 -2
- package/dist/{chunk-CA3JV7FX.js.map → chunk-JBIKAAT3.js.map} +1 -1
- package/dist/{chunk-6JKD46OJ.js → chunk-KAJZHIQ4.js} +13 -10
- package/dist/chunk-KAJZHIQ4.js.map +1 -0
- package/dist/{chunk-OWVVI4VQ.js → chunk-KINZ23CV.js} +107 -4535
- package/dist/chunk-KINZ23CV.js.map +1 -0
- package/dist/{chunk-WMFRCSNC.js → chunk-LRYV3SK7.js} +9 -7
- package/dist/{chunk-WMFRCSNC.js.map → chunk-LRYV3SK7.js.map} +1 -1
- package/dist/{chunk-T4UWMVKV.js → chunk-NIKXHWOL.js} +11 -13
- package/dist/{chunk-T4UWMVKV.js.map → chunk-NIKXHWOL.js.map} +1 -1
- package/dist/chunk-OKDRDT74.js +209 -0
- package/dist/chunk-OKDRDT74.js.map +1 -0
- package/dist/chunk-OKYSNAS3.js +2144 -0
- package/dist/chunk-OKYSNAS3.js.map +1 -0
- package/dist/{chunk-B676GPS2.js → chunk-OLWTRUTS.js} +7 -3
- package/dist/{chunk-B676GPS2.js.map → chunk-OLWTRUTS.js.map} +1 -1
- package/dist/{chunk-WU5CZPLD.js → chunk-QQ6ELLSA.js} +6 -8
- package/dist/{chunk-WU5CZPLD.js.map → chunk-QQ6ELLSA.js.map} +1 -1
- package/dist/{chunk-WVHPGQH5.js → chunk-QZ6ROAJU.js} +8 -4
- package/dist/chunk-QZ6ROAJU.js.map +1 -0
- package/dist/{chunk-L4XNT3UW.js → chunk-R7RSCBI7.js} +167 -52
- package/dist/chunk-R7RSCBI7.js.map +1 -0
- package/dist/{chunk-ELVDOTU7.js → chunk-U6VPKMGC.js} +128 -28
- package/dist/chunk-U6VPKMGC.js.map +1 -0
- package/dist/{chunk-FKSAUOJU.js → chunk-UO22YNY4.js} +1 -69
- package/dist/chunk-UO22YNY4.js.map +1 -0
- package/dist/{chunk-IAR25V2E.js → chunk-US456VUI.js} +6 -6
- package/dist/{chunk-IKAJSA7E.js → chunk-V44J2MXV.js} +80 -34
- package/dist/chunk-V44J2MXV.js.map +1 -0
- package/dist/{chunk-IFPKA32J.js → chunk-VJQKL3YH.js} +10 -7
- package/dist/{chunk-IFPKA32J.js.map → chunk-VJQKL3YH.js.map} +1 -1
- package/dist/{chunk-GCGMXA2O.js → chunk-VJSQSLBM.js} +52 -20
- package/dist/chunk-VJSQSLBM.js.map +1 -0
- package/dist/{chunk-IGHSLJUF.js → chunk-VYOJOX4Z.js} +9 -7
- package/dist/chunk-VYOJOX4Z.js.map +1 -0
- package/dist/chunk-WY2K35OL.js +269 -0
- package/dist/chunk-WY2K35OL.js.map +1 -0
- package/dist/{chunk-PAOVPSP6.js → chunk-ZFJJ3EXC.js} +53 -5
- package/dist/chunk-ZFJJ3EXC.js.map +1 -0
- package/dist/chunk-ZOBNS7CX.js +73 -0
- package/dist/chunk-ZOBNS7CX.js.map +1 -0
- package/dist/{cli-XK5JZWU6.js → cli-KKRKBU5T.js} +76 -47
- package/dist/{cli-XK5JZWU6.js.map → cli-KKRKBU5T.js.map} +1 -1
- package/dist/config-JMRUNYE6.js +37 -0
- package/dist/discover-B5HF6SHM.js +102 -0
- package/dist/discover-B5HF6SHM.js.map +1 -0
- package/dist/doctor-ZBG7X66D.js +32 -0
- package/dist/edit-PZJIILQE.js +40 -0
- package/dist/{fund-JF6A76YS.js → fund-EUDH5KPA.js} +19 -17
- package/dist/index.js +1 -1
- package/dist/inspect-QC6WEQPN.js +37 -0
- package/dist/{install-YQVM3SUW.js → install-GNK2W3PI.js} +286 -447
- package/dist/install-GNK2W3PI.js.map +1 -0
- package/dist/outcome-KSGWZHUS.js +24 -0
- package/dist/pay-BC4UICPA.js +361 -0
- package/dist/pay-BC4UICPA.js.map +1 -0
- package/dist/publish-LXWFDIKF.js +42 -0
- package/dist/{read-UF7QVQOU.js → read-JMNUQ56P.js} +22 -20
- package/dist/{read-UF7QVQOU.js.map → read-JMNUQ56P.js.map} +1 -1
- package/dist/{run-GDZWHNWZ.js → run-XYTQ5TWQ.js} +54 -45
- package/dist/{run-GDZWHNWZ.js.map → run-XYTQ5TWQ.js.map} +1 -1
- package/dist/search-TSQAB45E.js +25 -0
- package/dist/{send-SI254H3R.js → send-G746D7PQ.js} +14 -14
- package/dist/{session-GJZJEXLJ.js → session-JBKWMJ24.js} +18 -17
- package/dist/{session-GJZJEXLJ.js.map → session-JBKWMJ24.js.map} +1 -1
- package/dist/{skill-heal-BPFT22XS.js → skill-heal-WKD67SLJ.js} +17 -9
- package/dist/skill-heal-WKD67SLJ.js.map +1 -0
- package/dist/skill-placement-RIU4AMC2.js +20 -0
- package/dist/{uninstall-7ZZG6WQ5.js → uninstall-5E263VTS.js} +15 -9
- package/dist/uninstall-5E263VTS.js.map +1 -0
- package/dist/{update-FPSBITLB.js → update-R76LHOZW.js} +18 -16
- package/dist/update-R76LHOZW.js.map +1 -0
- package/dist/{wallet-NS7TYWNN.js → wallet-TQ7D5EQ7.js} +7 -7
- package/dist/{wallet-TZVD2M4I.js → wallet-ZAVXWLWP.js} +11 -11
- package/dist/wallet-ZAVXWLWP.js.map +1 -0
- package/docs/agent-permissions.md +117 -18
- package/docs/command-reference.md +102 -50
- package/docs/safety-model.md +9 -0
- package/package.json +1 -1
- package/skills/tenjin/SKILL.md +38 -29
- package/skills/tenjin-pay/SKILL.md +76 -0
- package/skills/tenjin-publish/SKILL.md +184 -205
- package/skills/tenjin-publish/references/maintain.md +39 -0
- package/skills/tenjin-search/SKILL.md +92 -280
- package/skills/tenjin-search/references/permissions.md +112 -0
- package/dist/buy-X4VPHFUA.js +0 -44
- package/dist/chunk-3NZCU6SD.js +0 -125
- package/dist/chunk-3NZCU6SD.js.map +0 -1
- package/dist/chunk-6JKD46OJ.js.map +0 -1
- package/dist/chunk-BRAVLUGI.js.map +0 -1
- package/dist/chunk-ELVDOTU7.js.map +0 -1
- package/dist/chunk-FKSAUOJU.js.map +0 -1
- package/dist/chunk-GCGMXA2O.js.map +0 -1
- package/dist/chunk-IGHSLJUF.js.map +0 -1
- package/dist/chunk-IKAJSA7E.js.map +0 -1
- package/dist/chunk-L4XNT3UW.js.map +0 -1
- package/dist/chunk-NKN4YC5C.js.map +0 -1
- package/dist/chunk-OC3EIDCP.js.map +0 -1
- package/dist/chunk-OE36HRWG.js +0 -939
- package/dist/chunk-OE36HRWG.js.map +0 -1
- package/dist/chunk-OUJDDY5L.js.map +0 -1
- package/dist/chunk-OWVVI4VQ.js.map +0 -1
- package/dist/chunk-OXUJ3FXU.js.map +0 -1
- package/dist/chunk-PAOVPSP6.js.map +0 -1
- package/dist/chunk-SPUORKD7.js.map +0 -1
- package/dist/chunk-TXVC46SA.js.map +0 -1
- package/dist/chunk-UUARTUY2.js.map +0 -1
- package/dist/chunk-WVHPGQH5.js.map +0 -1
- package/dist/chunk-XXY77EZJ.js.map +0 -1
- package/dist/chunk-YMUJZWHB.js.map +0 -1
- package/dist/chunk-ZQIQ55KK.js +0 -51
- package/dist/chunk-ZQIQ55KK.js.map +0 -1
- package/dist/config-CNK7MYUR.js +0 -26
- package/dist/doctor-R7N7FUX5.js +0 -27
- package/dist/edit-QSUEG7CL.js +0 -38
- package/dist/inspect-NFNAA4LA.js +0 -35
- package/dist/install-YQVM3SUW.js.map +0 -1
- package/dist/outcome-IUSYFJTN.js +0 -22
- package/dist/publish-O2I6IAEL.js +0 -40
- package/dist/search-JVOHEF3E.js +0 -23
- package/dist/skill-heal-BPFT22XS.js.map +0 -1
- package/dist/uninstall-7ZZG6WQ5.js.map +0 -1
- package/dist/update-FPSBITLB.js.map +0 -1
- /package/dist/{buy-X4VPHFUA.js.map → buy-VIRNSYGN.js.map} +0 -0
- /package/dist/{chunk-47YKYDOF.js.map → chunk-CAR6FHK6.js.map} +0 -0
- /package/dist/{chunk-JVBMPU5G.js.map → chunk-CPCX67TI.js.map} +0 -0
- /package/dist/{chunk-XGZ5EVMB.js.map → chunk-EDZSNPE5.js.map} +0 -0
- /package/dist/{chunk-736DW4V3.js.map → chunk-EFWZPUTC.js.map} +0 -0
- /package/dist/{chunk-IAR25V2E.js.map → chunk-US456VUI.js.map} +0 -0
- /package/dist/{config-CNK7MYUR.js.map → config-JMRUNYE6.js.map} +0 -0
- /package/dist/{doctor-R7N7FUX5.js.map → doctor-ZBG7X66D.js.map} +0 -0
- /package/dist/{edit-QSUEG7CL.js.map → edit-PZJIILQE.js.map} +0 -0
- /package/dist/{fund-JF6A76YS.js.map → fund-EUDH5KPA.js.map} +0 -0
- /package/dist/{inspect-NFNAA4LA.js.map → inspect-QC6WEQPN.js.map} +0 -0
- /package/dist/{outcome-IUSYFJTN.js.map → outcome-KSGWZHUS.js.map} +0 -0
- /package/dist/{publish-O2I6IAEL.js.map → publish-LXWFDIKF.js.map} +0 -0
- /package/dist/{search-JVOHEF3E.js.map → search-TSQAB45E.js.map} +0 -0
- /package/dist/{send-SI254H3R.js.map → send-G746D7PQ.js.map} +0 -0
- /package/dist/{wallet-NS7TYWNN.js.map → skill-placement-RIU4AMC2.js.map} +0 -0
- /package/dist/{wallet-TZVD2M4I.js.map → wallet-TQ7D5EQ7.js.map} +0 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
installSkill
|
|
4
|
+
} from "./chunk-QZ6ROAJU.js";
|
|
5
|
+
import {
|
|
6
|
+
emitWriteNotice
|
|
7
|
+
} from "./chunk-OLWTRUTS.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveHermesHomeLenient
|
|
10
|
+
} from "./chunk-OKYSNAS3.js";
|
|
11
|
+
import {
|
|
12
|
+
OPTIONAL_PAY_SKILL,
|
|
13
|
+
SKILL_NAMES,
|
|
14
|
+
readSkillFile,
|
|
15
|
+
resolveSkillsSource,
|
|
16
|
+
skillFrontmatterName,
|
|
17
|
+
skillsDirsFor
|
|
18
|
+
} from "./chunk-2MYQN7HM.js";
|
|
19
|
+
|
|
20
|
+
// src/lib/skill-placement.ts
|
|
21
|
+
import { lstatSync } from "fs";
|
|
22
|
+
import { readdir, rm, rmdir } from "fs/promises";
|
|
23
|
+
import { homedir } from "os";
|
|
24
|
+
import { isAbsolute, join } from "path";
|
|
25
|
+
import { fileURLToPath } from "url";
|
|
26
|
+
async function placeOptionalSkill(name, skillsDir, skillsSource, present) {
|
|
27
|
+
const skillDir = join(skillsDir, name);
|
|
28
|
+
if (present) {
|
|
29
|
+
const { status } = await installSkill(join(skillsSource, name), skillDir, false, name);
|
|
30
|
+
return { changed: status !== "up-to-date" };
|
|
31
|
+
}
|
|
32
|
+
if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) {
|
|
33
|
+
return { changed: false };
|
|
34
|
+
}
|
|
35
|
+
const path = join(skillDir, "SKILL.md");
|
|
36
|
+
const read = await readSkillFile(path);
|
|
37
|
+
if (read.kind === "absent") return { changed: false };
|
|
38
|
+
if (read.kind !== "ok" || skillFrontmatterName(read.bytes.toString("utf8")) !== name) {
|
|
39
|
+
return { changed: false };
|
|
40
|
+
}
|
|
41
|
+
await rm(path, { force: true });
|
|
42
|
+
const rest = await readdir(skillDir).catch(() => null);
|
|
43
|
+
if (rest !== null && rest.length === 0) await rmdir(skillDir).catch(() => void 0);
|
|
44
|
+
return { changed: true };
|
|
45
|
+
}
|
|
46
|
+
async function syncBazaarSkill(enabled, deps) {
|
|
47
|
+
const home = deps.homeDir ?? homedir();
|
|
48
|
+
if (!isAbsolute(home)) return;
|
|
49
|
+
let source;
|
|
50
|
+
try {
|
|
51
|
+
source = deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL(".", import.meta.url)));
|
|
52
|
+
} catch {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const env = deps.env ?? process.env;
|
|
56
|
+
const touched = [];
|
|
57
|
+
for (const dir of skillsDirsFor(home, resolveHermesHomeLenient(home, env).home)) {
|
|
58
|
+
try {
|
|
59
|
+
if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;
|
|
60
|
+
const consented = SKILL_NAMES.some(
|
|
61
|
+
(name) => lstatSync(join(dir, name, "SKILL.md"), { throwIfNoEntry: false })?.isFile() === true
|
|
62
|
+
);
|
|
63
|
+
if (!consented) continue;
|
|
64
|
+
const { changed } = await placeOptionalSkill(OPTIONAL_PAY_SKILL, dir, source, enabled);
|
|
65
|
+
if (changed) touched.push(join(dir, OPTIONAL_PAY_SKILL));
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (touched.length > 0) {
|
|
70
|
+
emitWriteNotice(
|
|
71
|
+
deps.io,
|
|
72
|
+
`${enabled ? "Installed" : "Removed"} ${touched.join(" and ")} to match bazaarPay.`
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
placeOptionalSkill,
|
|
79
|
+
syncBazaarSkill
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=chunk-DHJD77OW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/skill-placement.ts"],"sourcesContent":["import { lstatSync } from 'node:fs';\nimport { readdir, rm, rmdir } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { isAbsolute, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { emitWriteNotice } from './output';\nimport type { Io } from './output';\nimport { readSkillFile, skillFrontmatterName, skillsDirsFor } from './skill-wiring';\nimport { installSkill } from './skill-writer';\nimport { OPTIONAL_PAY_SKILL, SKILL_NAMES, resolveSkillsSource } from './skills-source';\nimport { resolveHermesHomeLenient } from './hermes';\n\n/**\n * Optional skills, where PRESENCE is the whole mechanism: the tenjin-pay skill\n * is on disk exactly while the `bazaarPay` toggle is on, so an agent is never\n * taught a lane the operator turned off, and turning the lane on is what makes\n * the teaching appear. No conditional content, no markers: the unit of\n * consent stays the one the whole pipeline already has, a skill directory.\n *\n * Removal follows `uninstall`'s rules exactly (lib/uninstall removeSkills):\n * only a SKILL.md whose frontmatter still claims our name is ours to delete,\n * and the directory goes only when our file was the only thing in it, so an\n * operator's own files beside it survive a toggle-off.\n */\n\n/** Ensure `name` is present or absent under one skills directory. */\nexport async function placeOptionalSkill(\n name: string,\n skillsDir: string,\n skillsSource: string,\n present: boolean,\n): Promise<{ changed: boolean }> {\n const skillDir = join(skillsDir, name);\n if (present) {\n const { status } = await installSkill(join(skillsSource, name), skillDir, false, name);\n return { changed: status !== 'up-to-date' };\n }\n if (lstatSync(skillDir, { throwIfNoEntry: false })?.isDirectory() !== true) {\n return { changed: false };\n }\n const path = join(skillDir, 'SKILL.md');\n const read = await readSkillFile(path);\n if (read.kind === 'absent') return { changed: false };\n if (read.kind !== 'ok' || skillFrontmatterName(read.bytes.toString('utf8')) !== name) {\n return { changed: false }; // not ours to delete for sitting at our path\n }\n await rm(path, { force: true });\n const rest = await readdir(skillDir).catch(() => null);\n if (rest !== null && rest.length === 0) await rmdir(skillDir).catch(() => undefined);\n return { changed: true };\n}\n\n/**\n * The `config set bazaarPay` twin of the heal: converge the tenjin-pay skill's\n * presence with the toggle across every skills directory a tenjin skill is\n * already wired into (presence of any shipped skill is the operator's consent\n * to a directory; an unwired directory is never created). Operator act, so\n * failures degrade per directory and doctor reports what remains.\n */\nexport async function syncBazaarSkill(\n enabled: boolean,\n deps: { io: Io; homeDir?: string; skillsSourceDir?: string; env?: NodeJS.ProcessEnv },\n): Promise<void> {\n const home = deps.homeDir ?? homedir();\n if (!isAbsolute(home)) return;\n let source: string;\n try {\n source =\n deps.skillsSourceDir ?? resolveSkillsSource(fileURLToPath(new URL('.', import.meta.url)));\n } catch {\n return; // no readable source: nothing safe to write, nothing to remove FROM\n }\n const env = deps.env ?? process.env;\n // Lenient, like `skill-heal` and `uninstall`: a stray relative HERMES_HOME must\n // not stop an operator's own `config set bazaarPay`. Resolving it at all is\n // what puts the Hermes skills directory in scope for the sync.\n const touched: string[] = [];\n for (const dir of skillsDirsFor(home, resolveHermesHomeLenient(home, env).home)) {\n try {\n if (lstatSync(dir, { throwIfNoEntry: false })?.isDirectory() !== true) continue;\n const consented = SKILL_NAMES.some(\n (name) =>\n lstatSync(join(dir, name, 'SKILL.md'), { throwIfNoEntry: false })?.isFile() === true,\n );\n if (!consented) continue;\n const { changed } = await placeOptionalSkill(OPTIONAL_PAY_SKILL, dir, source, enabled);\n if (changed) touched.push(join(dir, OPTIONAL_PAY_SKILL));\n } catch {\n // This directory keeps what it has; `tenjin doctor` reports the drift.\n }\n }\n if (touched.length > 0) {\n emitWriteNotice(\n deps.io,\n `${enabled ? 'Installed' : 'Removed'} ${touched.join(' and ')} to match bazaarPay.`,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,SAAS,IAAI,aAAa;AACnC,SAAS,eAAe;AACxB,SAAS,YAAY,YAAY;AACjC,SAAS,qBAAqB;AAsB9B,eAAsB,mBACpB,MACA,WACA,cACA,SAC+B;AAC/B,QAAM,WAAW,KAAK,WAAW,IAAI;AACrC,MAAI,SAAS;AACX,UAAM,EAAE,OAAO,IAAI,MAAM,aAAa,KAAK,cAAc,IAAI,GAAG,UAAU,OAAO,IAAI;AACrF,WAAO,EAAE,SAAS,WAAW,aAAa;AAAA,EAC5C;AACA,MAAI,UAAU,UAAU,EAAE,gBAAgB,MAAM,CAAC,GAAG,YAAY,MAAM,MAAM;AAC1E,WAAO,EAAE,SAAS,MAAM;AAAA,EAC1B;AACA,QAAM,OAAO,KAAK,UAAU,UAAU;AACtC,QAAM,OAAO,MAAM,cAAc,IAAI;AACrC,MAAI,KAAK,SAAS,SAAU,QAAO,EAAE,SAAS,MAAM;AACpD,MAAI,KAAK,SAAS,QAAQ,qBAAqB,KAAK,MAAM,SAAS,MAAM,CAAC,MAAM,MAAM;AACpF,WAAO,EAAE,SAAS,MAAM;AAAA,EAC1B;AACA,QAAM,GAAG,MAAM,EAAE,OAAO,KAAK,CAAC;AAC9B,QAAM,OAAO,MAAM,QAAQ,QAAQ,EAAE,MAAM,MAAM,IAAI;AACrD,MAAI,SAAS,QAAQ,KAAK,WAAW,EAAG,OAAM,MAAM,QAAQ,EAAE,MAAM,MAAM,MAAS;AACnF,SAAO,EAAE,SAAS,KAAK;AACzB;AASA,eAAsB,gBACpB,SACA,MACe;AACf,QAAM,OAAO,KAAK,WAAW,QAAQ;AACrC,MAAI,CAAC,WAAW,IAAI,EAAG;AACvB,MAAI;AACJ,MAAI;AACF,aACE,KAAK,mBAAmB,oBAAoB,cAAc,IAAI,IAAI,KAAK,YAAY,GAAG,CAAC,CAAC;AAAA,EAC5F,QAAQ;AACN;AAAA,EACF;AACA,QAAM,MAAM,KAAK,OAAO,QAAQ;AAIhC,QAAM,UAAoB,CAAC;AAC3B,aAAW,OAAO,cAAc,MAAM,yBAAyB,MAAM,GAAG,EAAE,IAAI,GAAG;AAC/E,QAAI;AACF,UAAI,UAAU,KAAK,EAAE,gBAAgB,MAAM,CAAC,GAAG,YAAY,MAAM,KAAM;AACvE,YAAM,YAAY,YAAY;AAAA,QAC5B,CAAC,SACC,UAAU,KAAK,KAAK,MAAM,UAAU,GAAG,EAAE,gBAAgB,MAAM,CAAC,GAAG,OAAO,MAAM;AAAA,MACpF;AACA,UAAI,CAAC,UAAW;AAChB,YAAM,EAAE,QAAQ,IAAI,MAAM,mBAAmB,oBAAoB,KAAK,QAAQ,OAAO;AACrF,UAAI,QAAS,SAAQ,KAAK,KAAK,KAAK,kBAAkB,CAAC;AAAA,IACzD,QAAQ;AAAA,IAER;AAAA,EACF;AACA,MAAI,QAAQ,SAAS,GAAG;AACtB;AAAA,MACE,KAAK;AAAA,MACL,GAAG,UAAU,cAAc,SAAS,IAAI,QAAQ,KAAK,OAAO,CAAC;AAAA,IAC/D;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
CliError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ZFJJ3EXC.js";
|
|
5
5
|
|
|
6
6
|
// src/lib/url.ts
|
|
7
7
|
function trimSlash(url) {
|
|
@@ -32,4 +32,4 @@ export {
|
|
|
32
32
|
tryOriginOf,
|
|
33
33
|
originOf
|
|
34
34
|
};
|
|
35
|
-
//# sourceMappingURL=chunk-
|
|
35
|
+
//# sourceMappingURL=chunk-EDZSNPE5.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
CliError
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-ZFJJ3EXC.js";
|
|
5
5
|
|
|
6
6
|
// src/lib/ids.ts
|
|
7
7
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
@@ -62,4 +62,4 @@ export {
|
|
|
62
62
|
toMoney,
|
|
63
63
|
formatUsdDisplay
|
|
64
64
|
};
|
|
65
|
-
//# sourceMappingURL=chunk-
|
|
65
|
+
//# sourceMappingURL=chunk-EFWZPUTC.js.map
|
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
HTTPFacilitatorClient
|
|
4
|
+
} from "./chunk-DBU5CXBV.js";
|
|
5
|
+
import {
|
|
6
|
+
writeFileAtomic
|
|
7
|
+
} from "./chunk-ZFJJ3EXC.js";
|
|
8
|
+
import {
|
|
9
|
+
getAddress
|
|
10
|
+
} from "./chunk-47PP7TAG.js";
|
|
11
|
+
|
|
12
|
+
// src/lib/bazaar.ts
|
|
13
|
+
import { readFile } from "fs/promises";
|
|
14
|
+
import { join } from "path";
|
|
15
|
+
|
|
16
|
+
// node_modules/.pnpm/@x402+extensions@2.17.0_typescript@6.0.3/node_modules/@x402/extensions/dist/esm/chunk-KKZBRP7D.mjs
|
|
17
|
+
var BAZAAR = { key: "bazaar" };
|
|
18
|
+
var BRACKET_PARAM_REGEX = /\[([^\]]+)\]/;
|
|
19
|
+
var BRACKET_PARAM_REGEX_ALL = /\[([^\]]+)\]/g;
|
|
20
|
+
var COLON_PARAM_REGEX = /:([a-zA-Z_][a-zA-Z0-9_]*)/;
|
|
21
|
+
function isHTTPRequestContext(ctx) {
|
|
22
|
+
return ctx !== null && typeof ctx === "object" && "method" in ctx && "adapter" in ctx;
|
|
23
|
+
}
|
|
24
|
+
function normalizeWildcardPattern(pattern) {
|
|
25
|
+
if (!pattern.includes("*")) {
|
|
26
|
+
return pattern;
|
|
27
|
+
}
|
|
28
|
+
let counter = 0;
|
|
29
|
+
return pattern.split("/").map((seg) => {
|
|
30
|
+
if (seg === "*") {
|
|
31
|
+
counter++;
|
|
32
|
+
return `:var${counter}`;
|
|
33
|
+
}
|
|
34
|
+
return seg;
|
|
35
|
+
}).join("/");
|
|
36
|
+
}
|
|
37
|
+
function extractDynamicRouteInfo(routePattern, urlPath) {
|
|
38
|
+
const hasBracket = BRACKET_PARAM_REGEX.test(routePattern);
|
|
39
|
+
const hasColon = COLON_PARAM_REGEX.test(routePattern);
|
|
40
|
+
if (!hasBracket && !hasColon) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const normalizedPattern = hasBracket ? routePattern.replace(BRACKET_PARAM_REGEX_ALL, ":$1") : routePattern;
|
|
44
|
+
const pathParams = extractPathParams(normalizedPattern, urlPath, false);
|
|
45
|
+
return { routeTemplate: normalizedPattern, pathParams };
|
|
46
|
+
}
|
|
47
|
+
function extractPathParams(routePattern, urlPath, isBracket) {
|
|
48
|
+
const paramNames = [];
|
|
49
|
+
const splitRegex = isBracket ? BRACKET_PARAM_REGEX : COLON_PARAM_REGEX;
|
|
50
|
+
const parts = routePattern.split(splitRegex);
|
|
51
|
+
const regexParts = [];
|
|
52
|
+
parts.forEach((part, i) => {
|
|
53
|
+
if (i % 2 === 0) {
|
|
54
|
+
regexParts.push(part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
|
|
55
|
+
} else {
|
|
56
|
+
paramNames.push(part);
|
|
57
|
+
regexParts.push("([^/]+)");
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const regex = new RegExp(`^${regexParts.join("")}$`);
|
|
61
|
+
const match = urlPath.match(regex);
|
|
62
|
+
if (!match) return {};
|
|
63
|
+
const result = {};
|
|
64
|
+
paramNames.forEach((name, idx) => {
|
|
65
|
+
result[name] = match[idx + 1];
|
|
66
|
+
});
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
var bazaarResourceServerExtension = {
|
|
70
|
+
key: BAZAAR.key,
|
|
71
|
+
enrichDeclaration: (declaration, transportContext) => {
|
|
72
|
+
if (!isHTTPRequestContext(transportContext)) {
|
|
73
|
+
return declaration;
|
|
74
|
+
}
|
|
75
|
+
const extension = declaration;
|
|
76
|
+
if (extension.info?.input?.type === "mcp") {
|
|
77
|
+
return declaration;
|
|
78
|
+
}
|
|
79
|
+
const method = transportContext.method;
|
|
80
|
+
const existingInputProps = extension.schema?.properties?.input?.properties || {};
|
|
81
|
+
const updatedInputProps = {
|
|
82
|
+
...existingInputProps,
|
|
83
|
+
method: {
|
|
84
|
+
type: "string",
|
|
85
|
+
enum: [method]
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
const enrichedResult = {
|
|
89
|
+
...extension,
|
|
90
|
+
info: {
|
|
91
|
+
...extension.info || {},
|
|
92
|
+
input: {
|
|
93
|
+
...extension.info?.input || {},
|
|
94
|
+
method
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
schema: {
|
|
98
|
+
...extension.schema || {},
|
|
99
|
+
properties: {
|
|
100
|
+
...extension.schema?.properties || {},
|
|
101
|
+
input: {
|
|
102
|
+
...extension.schema?.properties?.input || {},
|
|
103
|
+
properties: updatedInputProps,
|
|
104
|
+
required: [
|
|
105
|
+
...extension.schema?.properties?.input?.required || [],
|
|
106
|
+
...!(extension.schema?.properties?.input?.required || []).includes("method") ? ["method"] : []
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const rawRoutePattern = transportContext.routePattern;
|
|
113
|
+
const routePattern = rawRoutePattern ? normalizeWildcardPattern(rawRoutePattern) : void 0;
|
|
114
|
+
const dynamicRoute = routePattern ? extractDynamicRouteInfo(routePattern, transportContext.adapter.getPath()) : null;
|
|
115
|
+
if (dynamicRoute) {
|
|
116
|
+
const inputSchemaProps = enrichedResult.schema?.properties?.input?.properties || {};
|
|
117
|
+
const hasPathParamsInSchema = "pathParams" in inputSchemaProps;
|
|
118
|
+
return {
|
|
119
|
+
...enrichedResult,
|
|
120
|
+
routeTemplate: dynamicRoute.routeTemplate,
|
|
121
|
+
info: {
|
|
122
|
+
...enrichedResult.info,
|
|
123
|
+
input: { ...enrichedResult.info.input, pathParams: dynamicRoute.pathParams }
|
|
124
|
+
},
|
|
125
|
+
...!hasPathParamsInSchema ? {
|
|
126
|
+
schema: {
|
|
127
|
+
...enrichedResult.schema,
|
|
128
|
+
properties: {
|
|
129
|
+
...enrichedResult.schema?.properties,
|
|
130
|
+
input: {
|
|
131
|
+
...enrichedResult.schema?.properties?.input,
|
|
132
|
+
properties: {
|
|
133
|
+
...inputSchemaProps,
|
|
134
|
+
pathParams: { type: "object" }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} : {}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return enrichedResult;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
var UNICODE_CONTROL_REGEX = new RegExp("\\p{Cc}", "u");
|
|
146
|
+
var VALID_QUERY_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD", "DELETE"]);
|
|
147
|
+
var VALID_BODY_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH"]);
|
|
148
|
+
var VALID_METHODS = /* @__PURE__ */ new Set([...VALID_QUERY_METHODS, ...VALID_BODY_METHODS]);
|
|
149
|
+
function withBazaar(client2) {
|
|
150
|
+
const existingExtensions = client2.extensions ?? {};
|
|
151
|
+
const extended = client2;
|
|
152
|
+
extended.extensions = {
|
|
153
|
+
...existingExtensions,
|
|
154
|
+
bazaar: {
|
|
155
|
+
async listResources(params) {
|
|
156
|
+
let headers = {
|
|
157
|
+
"Content-Type": "application/json"
|
|
158
|
+
};
|
|
159
|
+
const authHeaders = await client2.createAuthHeaders("bazaar");
|
|
160
|
+
headers = { ...headers, ...authHeaders.headers };
|
|
161
|
+
const queryParams = new URLSearchParams();
|
|
162
|
+
if (params?.type !== void 0) {
|
|
163
|
+
queryParams.set("type", params.type);
|
|
164
|
+
}
|
|
165
|
+
if (params?.payTo !== void 0) {
|
|
166
|
+
queryParams.set("payTo", params.payTo);
|
|
167
|
+
}
|
|
168
|
+
if (params?.scheme !== void 0) {
|
|
169
|
+
queryParams.set("scheme", params.scheme);
|
|
170
|
+
}
|
|
171
|
+
if (params?.network !== void 0) {
|
|
172
|
+
queryParams.set("network", params.network);
|
|
173
|
+
}
|
|
174
|
+
if (params?.extensions !== void 0) {
|
|
175
|
+
queryParams.set("extensions", params.extensions);
|
|
176
|
+
}
|
|
177
|
+
if (params?.limit !== void 0) {
|
|
178
|
+
queryParams.set("limit", params.limit.toString());
|
|
179
|
+
}
|
|
180
|
+
if (params?.offset !== void 0) {
|
|
181
|
+
queryParams.set("offset", params.offset.toString());
|
|
182
|
+
}
|
|
183
|
+
const queryString = queryParams.toString();
|
|
184
|
+
const endpoint = `${client2.url}/discovery/resources${queryString ? `?${queryString}` : ""}`;
|
|
185
|
+
const response = await fetch(endpoint, {
|
|
186
|
+
method: "GET",
|
|
187
|
+
headers
|
|
188
|
+
});
|
|
189
|
+
if (!response.ok) {
|
|
190
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
191
|
+
throw new Error(
|
|
192
|
+
`Facilitator listDiscoveryResources failed (${response.status}): ${errorText}`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return await response.json();
|
|
196
|
+
},
|
|
197
|
+
async search(params) {
|
|
198
|
+
let headers = {
|
|
199
|
+
"Content-Type": "application/json"
|
|
200
|
+
};
|
|
201
|
+
const authHeaders = await client2.createAuthHeaders("bazaar");
|
|
202
|
+
headers = { ...headers, ...authHeaders.headers };
|
|
203
|
+
const queryParams = new URLSearchParams();
|
|
204
|
+
queryParams.set("query", params.query);
|
|
205
|
+
if (params.type !== void 0) {
|
|
206
|
+
queryParams.set("type", params.type);
|
|
207
|
+
}
|
|
208
|
+
if (params.payTo !== void 0) {
|
|
209
|
+
queryParams.set("payTo", params.payTo);
|
|
210
|
+
}
|
|
211
|
+
if (params.scheme !== void 0) {
|
|
212
|
+
queryParams.set("scheme", params.scheme);
|
|
213
|
+
}
|
|
214
|
+
if (params.network !== void 0) {
|
|
215
|
+
queryParams.set("network", params.network);
|
|
216
|
+
}
|
|
217
|
+
if (params.extensions !== void 0) {
|
|
218
|
+
queryParams.set("extensions", params.extensions);
|
|
219
|
+
}
|
|
220
|
+
if (params.limit !== void 0) {
|
|
221
|
+
queryParams.set("limit", params.limit.toString());
|
|
222
|
+
}
|
|
223
|
+
if (params.cursor !== void 0) {
|
|
224
|
+
queryParams.set("cursor", params.cursor);
|
|
225
|
+
}
|
|
226
|
+
const endpoint = `${client2.url}/discovery/search?${queryParams.toString()}`;
|
|
227
|
+
const response = await fetch(endpoint, {
|
|
228
|
+
method: "GET",
|
|
229
|
+
headers
|
|
230
|
+
});
|
|
231
|
+
if (!response.ok) {
|
|
232
|
+
const errorText = await response.text().catch(() => response.statusText);
|
|
233
|
+
throw new Error(
|
|
234
|
+
`Facilitator searchDiscoveryResources failed (${response.status}): ${errorText}`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
return await response.json();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
return extended;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// src/lib/bazaar.ts
|
|
245
|
+
var PAGE_LIMIT = 100;
|
|
246
|
+
var SEARCH_LIMIT = 20;
|
|
247
|
+
function client(registry) {
|
|
248
|
+
return withBazaar(new HTTPFacilitatorClient({ url: registry }));
|
|
249
|
+
}
|
|
250
|
+
async function withTimeout(work, timeoutMs, what) {
|
|
251
|
+
let timer;
|
|
252
|
+
try {
|
|
253
|
+
return await Promise.race([
|
|
254
|
+
work,
|
|
255
|
+
new Promise((_, reject) => {
|
|
256
|
+
timer = setTimeout(
|
|
257
|
+
() => reject(new Error(`${what} timed out after ${timeoutMs}ms`)),
|
|
258
|
+
timeoutMs
|
|
259
|
+
);
|
|
260
|
+
})
|
|
261
|
+
]);
|
|
262
|
+
} finally {
|
|
263
|
+
clearTimeout(timer);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
function toResource(item, registry) {
|
|
267
|
+
return {
|
|
268
|
+
url: item.resource,
|
|
269
|
+
registry,
|
|
270
|
+
...item.description !== void 0 ? { description: item.description } : {},
|
|
271
|
+
accepts: item.accepts,
|
|
272
|
+
...item.lastUpdated !== void 0 ? { lastUpdated: item.lastUpdated } : {}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
async function sweepRegistries(registries, opts) {
|
|
276
|
+
const resources = [];
|
|
277
|
+
const errors = [];
|
|
278
|
+
let skippedNonHttp = 0;
|
|
279
|
+
for (const registry of registries) {
|
|
280
|
+
try {
|
|
281
|
+
const bazaar = client(registry).extensions.bazaar;
|
|
282
|
+
const items = opts.query !== void 0 ? (await withTimeout(
|
|
283
|
+
bazaar.search({ query: opts.query, limit: SEARCH_LIMIT }),
|
|
284
|
+
opts.timeoutMs,
|
|
285
|
+
`search on ${registry}`
|
|
286
|
+
)).resources : (await withTimeout(
|
|
287
|
+
bazaar.listResources({ type: "http", limit: PAGE_LIMIT }),
|
|
288
|
+
opts.timeoutMs,
|
|
289
|
+
`listing ${registry}`
|
|
290
|
+
)).items;
|
|
291
|
+
for (const item of items) {
|
|
292
|
+
if (item.type !== "http") {
|
|
293
|
+
skippedNonHttp += 1;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
resources.push(toResource(item, registry));
|
|
297
|
+
}
|
|
298
|
+
} catch (err) {
|
|
299
|
+
errors.push({ registry, message: err instanceof Error ? err.message : String(err) });
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
return { resources, errors, skippedNonHttp };
|
|
303
|
+
}
|
|
304
|
+
var LISTING_STORE_FILE = "bazaar-listings.json";
|
|
305
|
+
var LISTING_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
306
|
+
var LISTING_STORE_CAP = 1e3;
|
|
307
|
+
function listingStorePath(dataDir) {
|
|
308
|
+
return join(dataDir, LISTING_STORE_FILE);
|
|
309
|
+
}
|
|
310
|
+
function isStoredListing(value) {
|
|
311
|
+
if (typeof value !== "object" || value === null) return false;
|
|
312
|
+
const listing = value;
|
|
313
|
+
return typeof listing.url === "string" && typeof listing.registry === "string" && typeof listing.fetchedAt === "string" && Array.isArray(listing.accepts);
|
|
314
|
+
}
|
|
315
|
+
async function loadListingStore(dataDir) {
|
|
316
|
+
try {
|
|
317
|
+
const raw = JSON.parse(await readFile(listingStorePath(dataDir), "utf8"));
|
|
318
|
+
const listings = raw?.listings;
|
|
319
|
+
return { listings: Array.isArray(listings) ? listings.filter(isStoredListing) : [] };
|
|
320
|
+
} catch {
|
|
321
|
+
return { listings: [] };
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
async function saveSweepListings(dataDir, resources, now = Date.now) {
|
|
325
|
+
const store = await loadListingStore(dataDir);
|
|
326
|
+
const fetchedAt = new Date(now()).toISOString();
|
|
327
|
+
const fresh = resources.map((r) => ({
|
|
328
|
+
url: r.url,
|
|
329
|
+
registry: r.registry,
|
|
330
|
+
accepts: r.accepts,
|
|
331
|
+
fetchedAt
|
|
332
|
+
}));
|
|
333
|
+
const seen = new Set(fresh.map((l) => `${l.registry} ${l.url}`));
|
|
334
|
+
const kept = store.listings.filter((l) => !seen.has(`${l.registry} ${l.url}`));
|
|
335
|
+
await writeFileAtomic(
|
|
336
|
+
listingStorePath(dataDir),
|
|
337
|
+
JSON.stringify({ listings: [...fresh, ...kept].slice(0, LISTING_STORE_CAP) }, null, 2)
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
async function storedListingsFor(dataDir, url, now) {
|
|
341
|
+
const store = await loadListingStore(dataDir);
|
|
342
|
+
return store.listings.filter((l) => {
|
|
343
|
+
if (!sameResourceUrl(l.url, url)) return false;
|
|
344
|
+
const age = now() - Date.parse(l.fetchedAt);
|
|
345
|
+
return age >= 0 && age < LISTING_TTL_MS;
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
function sameResourceUrl(listed, requested) {
|
|
349
|
+
const identity = (u) => {
|
|
350
|
+
try {
|
|
351
|
+
const parsed = new URL(u);
|
|
352
|
+
const path = parsed.pathname.endsWith("/") ? parsed.pathname.slice(0, -1) : parsed.pathname;
|
|
353
|
+
return `${parsed.origin}${path}`;
|
|
354
|
+
} catch {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
const a = identity(listed);
|
|
359
|
+
return a !== null && a === identity(requested);
|
|
360
|
+
}
|
|
361
|
+
async function verifyAgainstRegistries(registries, url, live, timeoutMs, opts = {}) {
|
|
362
|
+
const errors = [];
|
|
363
|
+
let mismatch;
|
|
364
|
+
if (opts.dataDir !== void 0) {
|
|
365
|
+
for (const listing of await storedListingsFor(opts.dataDir, url, opts.now ?? Date.now)) {
|
|
366
|
+
if (!registries.includes(listing.registry)) continue;
|
|
367
|
+
const detail = acceptsMismatch(listing.accepts, live);
|
|
368
|
+
if (detail === null) return { outcome: "verified", registry: listing.registry };
|
|
369
|
+
mismatch ??= { registry: listing.registry, detail };
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
for (const registry of registries) {
|
|
373
|
+
try {
|
|
374
|
+
const bazaar = client(registry).extensions.bazaar;
|
|
375
|
+
const listed = await withTimeout(
|
|
376
|
+
bazaar.listResources({ type: "http", payTo: live.payTo, limit: PAGE_LIMIT }),
|
|
377
|
+
timeoutMs,
|
|
378
|
+
`listing ${registry}`
|
|
379
|
+
);
|
|
380
|
+
const matches = listed.items.filter(
|
|
381
|
+
(item) => item.type === "http" && sameResourceUrl(item.resource, url)
|
|
382
|
+
);
|
|
383
|
+
if (matches.length === 0) continue;
|
|
384
|
+
for (const item of matches) {
|
|
385
|
+
const detail = acceptsMismatch(item.accepts, live);
|
|
386
|
+
if (detail === null) return { outcome: "verified", registry };
|
|
387
|
+
mismatch ??= { registry, detail };
|
|
388
|
+
}
|
|
389
|
+
} catch (err) {
|
|
390
|
+
errors.push({ registry, message: err instanceof Error ? err.message : String(err) });
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
if (mismatch !== void 0) return { outcome: "mismatch", ...mismatch };
|
|
394
|
+
if (errors.length === registries.length && registries.length > 0) {
|
|
395
|
+
return { outcome: "unavailable", errors };
|
|
396
|
+
}
|
|
397
|
+
return { outcome: "unlisted" };
|
|
398
|
+
}
|
|
399
|
+
function acceptsMismatch(advertised, live) {
|
|
400
|
+
let closest = "the listing advertises no payment terms";
|
|
401
|
+
for (const adv of advertised) {
|
|
402
|
+
if (adv.scheme !== live.scheme) {
|
|
403
|
+
closest = `advertised scheme ${adv.scheme}, live ${live.scheme}`;
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
if (adv.network !== live.network) {
|
|
407
|
+
closest = `advertised network ${adv.network}, live ${live.network}`;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (!sameAddress(adv.asset, live.asset)) {
|
|
411
|
+
closest = `advertised asset ${adv.asset}, live ${live.asset}`;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (!sameAddress(adv.payTo, live.payTo)) {
|
|
415
|
+
closest = `advertised payTo ${adv.payTo}, live ${live.payTo}`;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
let advertisedAmount;
|
|
419
|
+
let liveAmount;
|
|
420
|
+
try {
|
|
421
|
+
advertisedAmount = BigInt(adv.amount);
|
|
422
|
+
liveAmount = BigInt(live.amount);
|
|
423
|
+
} catch {
|
|
424
|
+
closest = "a non-integer amount in the listing or the live 402";
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (liveAmount > advertisedAmount) {
|
|
428
|
+
closest = `live amount ${live.amount} exceeds the advertised ${adv.amount}`;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
433
|
+
return closest;
|
|
434
|
+
}
|
|
435
|
+
function sameAddress(a, b) {
|
|
436
|
+
try {
|
|
437
|
+
return getAddress(a) === getAddress(b);
|
|
438
|
+
} catch {
|
|
439
|
+
return false;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export {
|
|
444
|
+
sweepRegistries,
|
|
445
|
+
saveSweepListings,
|
|
446
|
+
verifyAgainstRegistries
|
|
447
|
+
};
|
|
448
|
+
//# sourceMappingURL=chunk-EPFL6CTE.js.map
|