tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.30
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/NOTICE.md +54 -7
- package/README.md +149 -264
- package/dist/{_esm-FEASBWRP.js → _esm-CE7KNONL.js} +9 -10
- package/dist/alive-3J3CHOQP.js +21 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/chunk-3O2BQIF6.js +2227 -0
- package/dist/chunk-3O2BQIF6.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5LJCEMFD.js +12700 -0
- package/dist/chunk-5LJCEMFD.js.map +1 -0
- package/dist/chunk-6W5GYG3W.js +128 -0
- package/dist/chunk-6W5GYG3W.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AEG2PXBP.js +192 -0
- package/dist/chunk-AEG2PXBP.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-AWFUPKTM.js +238 -0
- package/dist/chunk-AWFUPKTM.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-AWQPGIR6.js} +7 -9
- package/dist/{chunk-UGX7YPX2.js.map → chunk-AWQPGIR6.js.map} +1 -1
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-EBVIKMCH.js +108 -0
- package/dist/chunk-EBVIKMCH.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/{chunk-S3IGX57D.js → chunk-EL56RW2J.js} +166 -7237
- package/dist/chunk-EL56RW2J.js.map +1 -0
- package/dist/chunk-HE2MS4QO.js +256 -0
- package/dist/chunk-HE2MS4QO.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-HPWO4O6S.js} +3 -3
- package/dist/chunk-IOODYAXL.js +324 -0
- package/dist/chunk-IOODYAXL.js.map +1 -0
- package/dist/chunk-JMM6YE7J.js +2174 -0
- package/dist/chunk-JMM6YE7J.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KHE6L6TD.js +416 -0
- package/dist/chunk-KHE6L6TD.js.map +1 -0
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KYFZTGMC.js +237 -0
- package/dist/chunk-KYFZTGMC.js.map +1 -0
- package/dist/chunk-LFZJM56J.js +159 -0
- package/dist/chunk-LFZJM56J.js.map +1 -0
- package/dist/chunk-LHHMV4GU.js +27 -0
- package/dist/chunk-LHHMV4GU.js.map +1 -0
- package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/{chunk-NCE5NSN6.js → chunk-N35E6CM2.js} +140 -10
- package/dist/chunk-N35E6CM2.js.map +1 -0
- package/dist/chunk-NZIP4PA2.js +114 -0
- package/dist/chunk-NZIP4PA2.js.map +1 -0
- package/dist/chunk-O2FRQ2L2.js +168 -0
- package/dist/chunk-O2FRQ2L2.js.map +1 -0
- package/dist/chunk-OK2TDZQU.js +404 -0
- package/dist/chunk-OK2TDZQU.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-OSYTBCUC.js} +850 -499
- package/dist/chunk-OSYTBCUC.js.map +1 -0
- package/dist/chunk-P7LABKCW.js +90 -0
- package/dist/chunk-P7LABKCW.js.map +1 -0
- package/dist/chunk-PAYV4XUA.js +151 -0
- package/dist/chunk-PAYV4XUA.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QUVVWYJW.js +112 -0
- package/dist/chunk-QUVVWYJW.js.map +1 -0
- package/dist/chunk-RAULEAZ6.js +228 -0
- package/dist/chunk-RAULEAZ6.js.map +1 -0
- package/dist/chunk-S4SAZ7OD.js +30 -0
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/chunk-SJLTEINJ.js +117 -0
- package/dist/chunk-SJLTEINJ.js.map +1 -0
- package/dist/chunk-SPAVAYSW.js +125 -0
- package/dist/chunk-SPAVAYSW.js.map +1 -0
- package/dist/chunk-TTBKWWTV.js +1605 -0
- package/dist/chunk-TTBKWWTV.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-U6YQ6FRI.js +378 -0
- package/dist/chunk-U6YQ6FRI.js.map +1 -0
- package/dist/chunk-VFMQTSXG.js +29 -0
- package/dist/chunk-VFMQTSXG.js.map +1 -0
- package/dist/chunk-VUFAK2LW.js +115 -0
- package/dist/chunk-VUFAK2LW.js.map +1 -0
- package/dist/chunk-VZGAONSJ.js +194 -0
- package/dist/chunk-VZGAONSJ.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-WO5BJNIB.js} +682 -53
- package/dist/chunk-WO5BJNIB.js.map +1 -0
- package/dist/chunk-WVUSXNIE.js +39 -0
- package/dist/chunk-WVUSXNIE.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/{chunk-XJIW7USF.js → chunk-YFQOA5AU.js} +118 -9
- package/dist/chunk-YFQOA5AU.js.map +1 -0
- package/dist/chunk-YHKXNYTB.js +105 -0
- package/dist/chunk-YHKXNYTB.js.map +1 -0
- package/dist/{cli-SBXI5AMS.js → cli-O5SN7ZJ4.js} +382 -214
- package/dist/cli-O5SN7ZJ4.js.map +1 -0
- package/dist/config-OJQI27LT.js +45 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-IQQJHGGM.js +590 -0
- package/dist/doctor-IQQJHGGM.js.map +1 -0
- package/dist/env-proxy-XL4P73MZ.js +15 -0
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/fund-WEV6DMTD.js +365 -0
- package/dist/fund-WEV6DMTD.js.map +1 -0
- package/dist/hook-command-D2P3ILRV.js +32 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +14 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +221 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-TUCRF32I.js +60 -0
- package/dist/install-identity-WHPNMNMQ.js +26 -0
- package/dist/install-wallet-MA27FTQ5.js +113 -0
- package/dist/install-wallet-MA27FTQ5.js.map +1 -0
- package/dist/mcp-QML7ZMPH.js +13427 -0
- package/dist/mcp-QML7ZMPH.js.map +1 -0
- package/dist/package-LGKYOEPV.js +37 -0
- package/dist/package-LGKYOEPV.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-2C2UBBXJ.js +51 -0
- package/dist/pay-2C2UBBXJ.js.map +1 -0
- package/dist/payments-C44QUFXU.js +106 -0
- package/dist/payments-C44QUFXU.js.map +1 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/redact-6W23GGJC.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
- package/dist/send-KVJX4XIR.js +222 -0
- package/dist/send-KVJX4XIR.js.map +1 -0
- package/dist/status-S7C3WMSH.js +115 -0
- package/dist/status-S7C3WMSH.js.map +1 -0
- package/dist/status-line-YR2T5HC4.js +86 -0
- package/dist/status-line-YR2T5HC4.js.map +1 -0
- package/dist/uninstall-HY6LKIIT.js +149 -0
- package/dist/uninstall-HY6LKIIT.js.map +1 -0
- package/dist/update-OJV22LR3.js +36 -0
- package/dist/update-OJV22LR3.js.map +1 -0
- package/dist/usdc-JK4RRFFQ.js +39 -0
- package/dist/usdc-JK4RRFFQ.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
- package/dist/viemAdapter-By13KInL-X2VY6CY3.js.map +1 -0
- package/dist/wallet-PD2IMZDU.js +39 -0
- package/dist/wallet-PD2IMZDU.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +180 -0
- package/docs/safety-model.md +59 -0
- package/docs/troubleshooting.md +13 -0
- package/package.json +28 -19
- package/LICENSE +0 -21
- package/dist/buy-EE6SEXP6.js +0 -1598
- package/dist/buy-EE6SEXP6.js.map +0 -1
- package/dist/candidate-ERMSYYQZ.js +0 -127
- package/dist/candidate-ERMSYYQZ.js.map +0 -1
- package/dist/chunk-3OV7E5G5.js +0 -18
- package/dist/chunk-3OV7E5G5.js.map +0 -1
- package/dist/chunk-4ONXEEQL.js +0 -152
- package/dist/chunk-4ONXEEQL.js.map +0 -1
- package/dist/chunk-662MSGZB.js +0 -286
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-7KUW4MJD.js +0 -59
- package/dist/chunk-7KUW4MJD.js.map +0 -1
- package/dist/chunk-AWPAWHNX.js +0 -333
- package/dist/chunk-AWPAWHNX.js.map +0 -1
- package/dist/chunk-DXTQ3CSI.js +0 -171
- package/dist/chunk-DXTQ3CSI.js.map +0 -1
- package/dist/chunk-ESPNTPQ2.js +0 -207
- package/dist/chunk-ESPNTPQ2.js.map +0 -1
- package/dist/chunk-FJPLRISB.js +0 -79
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-GO75V3NZ.js +0 -160
- package/dist/chunk-GO75V3NZ.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js +0 -96
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-MUBUQVC3.js +0 -67
- package/dist/chunk-MUBUQVC3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-OYMYCW7J.js.map +0 -1
- package/dist/chunk-RY4XKNV3.js +0 -140
- package/dist/chunk-RY4XKNV3.js.map +0 -1
- package/dist/chunk-S3IGX57D.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js +0 -126
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-UO22YNY4.js +0 -69
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-XHC6FCGZ.js +0 -261
- package/dist/chunk-XHC6FCGZ.js.map +0 -1
- package/dist/chunk-XJIW7USF.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YN5SHIXQ.js +0 -126
- package/dist/chunk-YN5SHIXQ.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js +0 -137
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/chunk-Z6MFJV5Z.js.map +0 -1
- package/dist/cli-SBXI5AMS.js.map +0 -1
- package/dist/config-VELDKLHY.js +0 -21
- package/dist/doctor-T3KWNNP2.js +0 -20
- package/dist/inspect-LMKOXE4Y.js +0 -96
- package/dist/inspect-LMKOXE4Y.js.map +0 -1
- package/dist/install-LEX3ENQ6.js +0 -387
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js +0 -129
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/publish-BKBQQAW4.js +0 -1478
- package/dist/publish-BKBQQAW4.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- package/dist/wallet-CWEMYVIH.js +0 -179
- package/dist/wallet-CWEMYVIH.js.map +0 -1
- package/dist/wallet-PA54CRBL.js +0 -30
- package/skills/tenjin/SKILL.md +0 -199
- package/skills/tenjin-publish/SKILL.md +0 -111
- package/skills/tenjin-search/SKILL.md +0 -133
- /package/dist/{_esm-FEASBWRP.js.map → _esm-CE7KNONL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-3J3CHOQP.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-HPWO4O6S.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → config-OJQI27LT.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → hook-command-D2P3ILRV.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → install-TUCRF32I.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → install-identity-WHPNMNMQ.js.map} +0 -0
package/dist/chunk-DXTQ3CSI.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
SIWX_HEADER,
|
|
4
|
-
decodePaymentRequiredHeader,
|
|
5
|
-
decodePaymentResponseHeader
|
|
6
|
-
} from "./chunk-S3IGX57D.js";
|
|
7
|
-
import {
|
|
8
|
-
rateLimitError
|
|
9
|
-
} from "./chunk-662MSGZB.js";
|
|
10
|
-
import {
|
|
11
|
-
SLUG_RE,
|
|
12
|
-
UUID_RE
|
|
13
|
-
} from "./chunk-3OV7E5G5.js";
|
|
14
|
-
import {
|
|
15
|
-
CLIENT_HEADER,
|
|
16
|
-
httpRequest
|
|
17
|
-
} from "./chunk-4ONXEEQL.js";
|
|
18
|
-
import {
|
|
19
|
-
CliError,
|
|
20
|
-
external_exports
|
|
21
|
-
} from "./chunk-OYMYCW7J.js";
|
|
22
|
-
|
|
23
|
-
// src/lib/read-client.ts
|
|
24
|
-
var PAYMENT_REQUIRED_HEADER = "PAYMENT-REQUIRED";
|
|
25
|
-
var PAYMENT_RESPONSE_HEADER = "PAYMENT-RESPONSE";
|
|
26
|
-
var readBodySchema = external_exports.object({
|
|
27
|
-
id: external_exports.string().regex(UUID_RE, "resource id must be a uuid"),
|
|
28
|
-
slug: external_exports.string().regex(SLUG_RE, "unsafe slug").max(80),
|
|
29
|
-
title: external_exports.string(),
|
|
30
|
-
bodyMd: external_exports.string(),
|
|
31
|
-
price: external_exports.string(),
|
|
32
|
-
creator: external_exports.object({
|
|
33
|
-
handle: external_exports.string().nullish(),
|
|
34
|
-
walletAddress: external_exports.string().nullish()
|
|
35
|
-
}).passthrough()
|
|
36
|
-
}).passthrough();
|
|
37
|
-
var previewSchema = external_exports.object({
|
|
38
|
-
id: external_exports.string().optional(),
|
|
39
|
-
title: external_exports.string().optional(),
|
|
40
|
-
price: external_exports.string().optional(),
|
|
41
|
-
creator: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
42
|
-
}).passthrough();
|
|
43
|
-
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
44
|
-
var paymentRequiredSchema = external_exports.object({
|
|
45
|
-
x402Version: external_exports.literal(2),
|
|
46
|
-
accepts: external_exports.array(
|
|
47
|
-
external_exports.object({
|
|
48
|
-
scheme: external_exports.string(),
|
|
49
|
-
network: external_exports.string().regex(/^eip155:\d+$/, "network must be CAIP-2 eip155"),
|
|
50
|
-
asset: external_exports.string().regex(ADDRESS_RE, "asset must be a 0x address"),
|
|
51
|
-
amount: external_exports.string().regex(/^\d{1,39}$/, "amount must be an atomic integer string"),
|
|
52
|
-
payTo: external_exports.string().regex(ADDRESS_RE, "payTo must be a 0x address")
|
|
53
|
-
}).passthrough()
|
|
54
|
-
)
|
|
55
|
-
}).passthrough();
|
|
56
|
-
async function fetchRead(url, opts) {
|
|
57
|
-
const headers = {
|
|
58
|
-
accept: "application/json",
|
|
59
|
-
"x-tenjin-client": CLIENT_HEADER
|
|
60
|
-
};
|
|
61
|
-
if (opts.lookupId !== void 0) headers["x-tenjin-lookup-id"] = opts.lookupId;
|
|
62
|
-
if (opts.siwxHeader !== void 0) headers[SIWX_HEADER] = opts.siwxHeader;
|
|
63
|
-
if (opts.paymentHeaders !== void 0) Object.assign(headers, opts.paymentHeaders);
|
|
64
|
-
const res = await httpRequest(url, {
|
|
65
|
-
method: "GET",
|
|
66
|
-
timeoutMs: opts.timeoutMs,
|
|
67
|
-
headers,
|
|
68
|
-
fetchImpl: opts.fetchImpl
|
|
69
|
-
});
|
|
70
|
-
if (!res.ok) {
|
|
71
|
-
const code = res.kind === "network" || res.kind === "timeout" ? "NETWORK_ERROR" : "API_UNREACHABLE";
|
|
72
|
-
throw new CliError(code, `${url}: ${res.message}`, {
|
|
73
|
-
fix: "Check the resource URL and your network, then retry."
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (res.status === 200) {
|
|
77
|
-
const parsed = readBodySchema.safeParse(res.json);
|
|
78
|
-
if (!parsed.success) {
|
|
79
|
-
throw new CliError(
|
|
80
|
-
"CONTRACT_MISMATCH",
|
|
81
|
-
"The read response did not match the expected contract",
|
|
82
|
-
{
|
|
83
|
-
fix: "Update tenjin-cli; the read contract may have changed.",
|
|
84
|
-
details: parsed.error.issues
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
const settlement = decodeSettlement(res.header(PAYMENT_RESPONSE_HEADER));
|
|
89
|
-
return {
|
|
90
|
-
kind: "entitled",
|
|
91
|
-
body: parsed.data,
|
|
92
|
-
...settlement !== void 0 ? { settlementTxHash: settlement } : {}
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
if (res.status === 402) {
|
|
96
|
-
const encoded = res.header(PAYMENT_REQUIRED_HEADER);
|
|
97
|
-
if (encoded === void 0) {
|
|
98
|
-
throw new CliError("CONTRACT_MISMATCH", "The 402 carried no PAYMENT-REQUIRED header", {
|
|
99
|
-
fix: "The server may be misconfigured; try another resource or update tenjin-cli."
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
let decoded;
|
|
103
|
-
try {
|
|
104
|
-
decoded = decodePaymentRequiredHeader(encoded);
|
|
105
|
-
} catch (err) {
|
|
106
|
-
throw new CliError("CONTRACT_MISMATCH", "Could not decode the PAYMENT-REQUIRED header", {
|
|
107
|
-
fix: "Update tenjin-cli; the x402 header format may have changed.",
|
|
108
|
-
cause: err
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
const validated = paymentRequiredSchema.safeParse(decoded);
|
|
112
|
-
if (!validated.success) {
|
|
113
|
-
throw new CliError(
|
|
114
|
-
"CONTRACT_MISMATCH",
|
|
115
|
-
"The 402 challenge is not a valid x402 v2 payment declaration.",
|
|
116
|
-
{
|
|
117
|
-
fix: "Update tenjin-cli, or check --base-url points at a Tenjin deployment.",
|
|
118
|
-
details: validated.error.issues
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
const paymentRequired = decoded;
|
|
123
|
-
const preview = previewSchema.safeParse(res.json);
|
|
124
|
-
return {
|
|
125
|
-
kind: "payment_required",
|
|
126
|
-
paymentRequired,
|
|
127
|
-
preview: preview.success ? preview.data : {}
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
if (res.status === 409) {
|
|
131
|
-
return { kind: "already_purchased", message: readMessage(res.json) ?? "Already purchased." };
|
|
132
|
-
}
|
|
133
|
-
if (res.status === 404) {
|
|
134
|
-
throw new CliError("RESOURCE_NOT_FOUND", `No resource at ${url}`, {
|
|
135
|
-
fix: "Check the handle/slug or resource id."
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));
|
|
139
|
-
throw new CliError(
|
|
140
|
-
"API_UNREACHABLE",
|
|
141
|
-
readMessage(res.json) ?? `Unexpected status ${res.status} from ${url}`,
|
|
142
|
-
{
|
|
143
|
-
fix: "Retry; if it persists the resource may be unavailable.",
|
|
144
|
-
details: res.json
|
|
145
|
-
}
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
function decodeSettlement(header) {
|
|
149
|
-
if (header === void 0) return void 0;
|
|
150
|
-
try {
|
|
151
|
-
const settle = decodePaymentResponseHeader(header);
|
|
152
|
-
const tx = settle.transaction;
|
|
153
|
-
return typeof tx === "string" ? tx : void 0;
|
|
154
|
-
} catch {
|
|
155
|
-
return void 0;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function readMessage(json) {
|
|
159
|
-
if (typeof json === "object" && json !== null) {
|
|
160
|
-
const rec = json;
|
|
161
|
-
if (typeof rec.message === "string") return rec.message;
|
|
162
|
-
if (typeof rec.error === "string") return rec.error;
|
|
163
|
-
if (typeof rec.code === "string") return rec.code;
|
|
164
|
-
}
|
|
165
|
-
return void 0;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export {
|
|
169
|
-
fetchRead
|
|
170
|
-
};
|
|
171
|
-
//# sourceMappingURL=chunk-DXTQ3CSI.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/read-client.ts"],"sourcesContent":["import { z } from 'zod';\nimport { decodePaymentRequiredHeader, decodePaymentResponseHeader } from '@x402/core/http';\nimport type { PaymentRequired } from '@x402/core/types';\nimport { CliError } from './errors';\nimport { rateLimitError } from './agent-api';\nimport { httpRequest } from './http';\nimport { CLIENT_HEADER } from './client-meta';\nimport { SIWX_HEADER } from './siwx';\n\n/**\n * The read-route (`GET /api/read/<handle>/<slug>`) client, always JSON/x402, so\n * it is the robust agent target (llms-full). It surfaces the three outcomes the\n * buy flow branches on: `entitled` (200 with the full body, free post, SIWX\n * re-read, or freshly paid), `payment_required` (402 with the decoded\n * PAYMENT-REQUIRED header + the leak-safe preview body), and `already_purchased`\n * (409 owned-re-pay gate, nothing charged). Purchase attribution rides\n * `X-Tenjin-Client` always and `X-Tenjin-Lookup-Id` when a lookup preceded the buy.\n */\n\nconst PAYMENT_REQUIRED_HEADER = 'PAYMENT-REQUIRED';\nconst PAYMENT_RESPONSE_HEADER = 'PAYMENT-RESPONSE';\n\n// id/slug become filesystem path segments (the local library), so they are\n// validated as a uuid + the server's slug charset HERE, at the trust boundary, so\n// a hostile id='../../evil' or slug fails as CONTRACT_MISMATCH before delivery.\nimport { SLUG_RE, UUID_RE as RESOURCE_ID_RE } from './ids';\n\n/** The full essay body a 200 returns (loose: require what the CLI reads, keep the rest). */\nconst readBodySchema = z\n .object({\n id: z.string().regex(RESOURCE_ID_RE, 'resource id must be a uuid'),\n slug: z.string().regex(SLUG_RE, 'unsafe slug').max(80),\n title: z.string(),\n bodyMd: z.string(),\n price: z.string(),\n creator: z\n .object({\n handle: z.string().nullish(),\n walletAddress: z.string().nullish(),\n })\n .passthrough(),\n })\n .passthrough();\n\nexport type ReadBody = z.infer<typeof readBodySchema>;\n\n/** The leak-safe 402 preview body, never the paid content. */\nconst previewSchema = z\n .object({\n id: z.string().optional(),\n title: z.string().optional(),\n price: z.string().optional(),\n creator: z.record(z.string(), z.unknown()).optional(),\n })\n .passthrough();\n\nexport type Preview = z.infer<typeof previewSchema>;\n\n// The decoded PAYMENT-REQUIRED is money-path input: validate the fields the pay\n// path consumes (amount as an atomic integer, CAIP-2 network, 0x asset/payTo)\n// at THIS boundary instead of trusting raw base64 JSON. Loose otherwise so new\n// server fields never break an older CLI.\nconst ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\nconst paymentRequiredSchema = z\n .object({\n x402Version: z.literal(2),\n accepts: z.array(\n z\n .object({\n scheme: z.string(),\n network: z.string().regex(/^eip155:\\d+$/, 'network must be CAIP-2 eip155'),\n asset: z.string().regex(ADDRESS_RE, 'asset must be a 0x address'),\n amount: z.string().regex(/^\\d{1,39}$/, 'amount must be an atomic integer string'),\n payTo: z.string().regex(ADDRESS_RE, 'payTo must be a 0x address'),\n })\n .passthrough(),\n ),\n })\n .passthrough();\n\nexport type ReadResult =\n | { kind: 'entitled'; body: ReadBody; settlementTxHash?: string }\n | { kind: 'payment_required'; paymentRequired: PaymentRequired; preview: Preview }\n | { kind: 'already_purchased'; message: string };\n\nexport interface ReadRequestOptions {\n timeoutMs: number;\n fetchImpl?: typeof fetch;\n /** A `SIGN-IN-WITH-X` header for the entitled free re-read. */\n siwxHeader?: string;\n /** The `PAYMENT-SIGNATURE` header(s) for a paid request. */\n paymentHeaders?: Record<string, string>;\n /** Attribute a following purchase to the lookup that surfaced it. */\n lookupId?: string;\n}\n\nexport async function fetchRead(url: string, opts: ReadRequestOptions): Promise<ReadResult> {\n const headers: Record<string, string> = {\n accept: 'application/json',\n 'x-tenjin-client': CLIENT_HEADER,\n };\n if (opts.lookupId !== undefined) headers['x-tenjin-lookup-id'] = opts.lookupId;\n if (opts.siwxHeader !== undefined) headers[SIWX_HEADER] = opts.siwxHeader;\n if (opts.paymentHeaders !== undefined) Object.assign(headers, opts.paymentHeaders);\n\n const res = await httpRequest(url, {\n method: 'GET',\n timeoutMs: opts.timeoutMs,\n headers,\n fetchImpl: opts.fetchImpl,\n });\n if (!res.ok) {\n const code =\n res.kind === 'network' || res.kind === 'timeout' ? 'NETWORK_ERROR' : 'API_UNREACHABLE';\n throw new CliError(code, `${url}: ${res.message}`, {\n fix: 'Check the resource URL and your network, then retry.',\n });\n }\n\n if (res.status === 200) {\n const parsed = readBodySchema.safeParse(res.json);\n if (!parsed.success) {\n throw new CliError(\n 'CONTRACT_MISMATCH',\n 'The read response did not match the expected contract',\n {\n fix: 'Update tenjin-cli; the read contract may have changed.',\n details: parsed.error.issues,\n },\n );\n }\n const settlement = decodeSettlement(res.header(PAYMENT_RESPONSE_HEADER));\n return {\n kind: 'entitled',\n body: parsed.data,\n ...(settlement !== undefined ? { settlementTxHash: settlement } : {}),\n };\n }\n\n if (res.status === 402) {\n const encoded = res.header(PAYMENT_REQUIRED_HEADER);\n if (encoded === undefined) {\n throw new CliError('CONTRACT_MISMATCH', 'The 402 carried no PAYMENT-REQUIRED header', {\n fix: 'The server may be misconfigured; try another resource or update tenjin-cli.',\n });\n }\n let decoded: PaymentRequired;\n try {\n decoded = decodePaymentRequiredHeader(encoded);\n } catch (err) {\n throw new CliError('CONTRACT_MISMATCH', 'Could not decode the PAYMENT-REQUIRED header', {\n fix: 'Update tenjin-cli; the x402 header format may have changed.',\n cause: err,\n });\n }\n const validated = paymentRequiredSchema.safeParse(decoded);\n if (!validated.success) {\n throw new CliError(\n 'CONTRACT_MISMATCH',\n 'The 402 challenge is not a valid x402 v2 payment declaration.',\n {\n fix: 'Update tenjin-cli, or check --base-url points at a Tenjin deployment.',\n details: validated.error.issues,\n },\n );\n }\n const paymentRequired = decoded;\n const preview = previewSchema.safeParse(res.json);\n return {\n kind: 'payment_required',\n paymentRequired,\n preview: preview.success ? preview.data : {},\n };\n }\n\n if (res.status === 409) {\n // The owned-re-pay gate: a payment for a post this wallet already bought is\n // refused, nothing charged. The caller falls back to a SIWX free re-read.\n return { kind: 'already_purchased', message: readMessage(res.json) ?? 'Already purchased.' };\n }\n\n if (res.status === 404) {\n throw new CliError('RESOURCE_NOT_FOUND', `No resource at ${url}`, {\n fix: 'Check the handle/slug or resource id.',\n });\n }\n\n // 429 on the paid-read path is a recoverable pause, not an outage: surface\n // RATE_LIMITED + retryAfterSeconds like postLookup/postOutcomes do, so a looping\n // agent (the caller most likely to hit this) can back off instead of treating it\n // as API_UNREACHABLE.\n if (res.status === 429) throw rateLimitError(url, (n) => res.header(n));\n\n throw new CliError(\n 'API_UNREACHABLE',\n readMessage(res.json) ?? `Unexpected status ${res.status} from ${url}`,\n {\n fix: 'Retry; if it persists the resource may be unavailable.',\n details: res.json,\n },\n );\n}\n\nfunction decodeSettlement(header: string | undefined): string | undefined {\n if (header === undefined) return undefined;\n try {\n const settle = decodePaymentResponseHeader(header);\n const tx = (settle as { transaction?: unknown }).transaction;\n return typeof tx === 'string' ? tx : undefined;\n } catch {\n return undefined;\n }\n}\n\nfunction readMessage(json: unknown): string | undefined {\n if (typeof json === 'object' && json !== null) {\n const rec = json as Record<string, unknown>;\n if (typeof rec.message === 'string') return rec.message;\n if (typeof rec.error === 'string') return rec.error;\n if (typeof rec.code === 'string') return rec.code;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;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F;AAEA,SAAS,YAAY,MAAmC;AACtD,MAAI,OAAO,SAAS,YAAY,SAAS,MAAM;AAC7C,UAAM,MAAM;AACZ,QAAI,OAAO,IAAI,YAAY,SAAU,QAAO,IAAI;AAChD,QAAI,OAAO,IAAI,UAAU,SAAU,QAAO,IAAI;AAC9C,QAAI,OAAO,IAAI,SAAS,SAAU,QAAO,IAAI;AAAA,EAC/C;AACA,SAAO;AACT;","names":[]}
|
package/dist/chunk-ESPNTPQ2.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
CliError,
|
|
4
|
-
configPath,
|
|
5
|
-
external_exports
|
|
6
|
-
} from "./chunk-OYMYCW7J.js";
|
|
7
|
-
|
|
8
|
-
// src/lib/config.ts
|
|
9
|
-
import { readFile } from "fs/promises";
|
|
10
|
-
var atomicString = external_exports.string().regex(/^\d+$/, "expected an atomic USDC integer string");
|
|
11
|
-
var PublishModeSchema = external_exports.enum(["review", "auto", "full-auto"]);
|
|
12
|
-
function parsePublishModeFlag(value, flagName) {
|
|
13
|
-
const parsed = PublishModeSchema.safeParse(value);
|
|
14
|
-
if (parsed.success) return parsed.data;
|
|
15
|
-
throw new CliError("USAGE", `Invalid ${flagName} ${JSON.stringify(value)}`, {
|
|
16
|
-
fix: 'Use "review", "auto", or "full-auto".'
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
var PublishConfigSchema = external_exports.object({
|
|
20
|
-
mode: PublishModeSchema,
|
|
21
|
-
defaultPrice: atomicString
|
|
22
|
-
});
|
|
23
|
-
var ConfigSchema = external_exports.object({
|
|
24
|
-
maxAutoSpend: atomicString,
|
|
25
|
-
sessionBudget: atomicString,
|
|
26
|
-
confirm: external_exports.union([external_exports.literal("always"), external_exports.string().regex(/^above:\d+$/)]),
|
|
27
|
-
allowlistCreators: external_exports.array(external_exports.string()),
|
|
28
|
-
baseUrl: external_exports.url(),
|
|
29
|
-
rpcUrl: external_exports.url(),
|
|
30
|
-
/**
|
|
31
|
-
* Evaluation-cohort opt-in (spec 09 §3): when true, lookup sends
|
|
32
|
-
* X-Tenjin-Eval-Cohort: 1 and the server stores the generalized question for
|
|
33
|
-
* 90 days. Off by default; no query text is retained server-side without it.
|
|
34
|
-
*/
|
|
35
|
-
evalCohort: external_exports.boolean(),
|
|
36
|
-
publish: PublishConfigSchema
|
|
37
|
-
});
|
|
38
|
-
var RawConfigSchema = ConfigSchema.partial().extend({ publish: PublishConfigSchema.partial().passthrough().optional() }).passthrough();
|
|
39
|
-
var CONFIG_DEFAULTS = {
|
|
40
|
-
maxAutoSpend: "0",
|
|
41
|
-
sessionBudget: "0",
|
|
42
|
-
confirm: "always",
|
|
43
|
-
allowlistCreators: [],
|
|
44
|
-
baseUrl: "https://tenjin.blog",
|
|
45
|
-
rpcUrl: "https://mainnet.base.org",
|
|
46
|
-
evalCohort: false,
|
|
47
|
-
publish: { mode: "review", defaultPrice: "100000" }
|
|
48
|
-
};
|
|
49
|
-
var CONFIG_KEYS = Object.keys(CONFIG_DEFAULTS).filter(
|
|
50
|
-
(key) => key !== "publish"
|
|
51
|
-
);
|
|
52
|
-
var PUBLISH_CONFIG_KEYS = ["publish.mode", "publish.defaultPrice"];
|
|
53
|
-
async function loadRawConfig(dir) {
|
|
54
|
-
const path = configPath(dir);
|
|
55
|
-
let raw;
|
|
56
|
-
try {
|
|
57
|
-
raw = await readFile(path, "utf8");
|
|
58
|
-
} catch (err) {
|
|
59
|
-
if (isNotFound(err)) return {};
|
|
60
|
-
throw new CliError("CONFIG_INVALID", `Could not read config at ${path}`, {
|
|
61
|
-
fix: `Check file permissions on ${path}.`,
|
|
62
|
-
cause: err
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
let json;
|
|
66
|
-
try {
|
|
67
|
-
json = JSON.parse(raw);
|
|
68
|
-
} catch (err) {
|
|
69
|
-
throw new CliError("CONFIG_INVALID", `Config at ${path} is not valid JSON`, {
|
|
70
|
-
fix: `Fix the JSON syntax in ${path}, or delete it to restore defaults.`,
|
|
71
|
-
cause: err
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const parsed = RawConfigSchema.safeParse(json);
|
|
75
|
-
if (!parsed.success) {
|
|
76
|
-
throw new CliError("CONFIG_INVALID", `Config at ${path} is invalid`, {
|
|
77
|
-
fix: `Correct the reported keys in ${path}, or delete it to restore defaults.`,
|
|
78
|
-
details: parsed.error.issues
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return parsed.data;
|
|
82
|
-
}
|
|
83
|
-
function resolveSettings(input) {
|
|
84
|
-
const { config, flags, env, project } = input;
|
|
85
|
-
return {
|
|
86
|
-
maxAutoSpend: fileOrDefault("maxAutoSpend", config),
|
|
87
|
-
sessionBudget: fileOrDefault("sessionBudget", config),
|
|
88
|
-
confirm: fileOrDefault("confirm", config),
|
|
89
|
-
allowlistCreators: fileOrDefault("allowlistCreators", config),
|
|
90
|
-
baseUrl: resolveBaseUrl(config, flags, env),
|
|
91
|
-
rpcUrl: fileOrDefault("rpcUrl", config),
|
|
92
|
-
evalCohort: fileOrDefault("evalCohort", config),
|
|
93
|
-
publishMode: resolvePublishMode({ config, project, env }),
|
|
94
|
-
publishDefaultPrice: resolvePublishDefaultPrice({ config, project })
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
var FULL_AUTO_DOWNGRADE_WARNING = 'Ignoring publish.mode "full-auto" from a committed .tenjin.json (cloning a repo must not enable auto-publish); using "auto". Add .tenjin.json to .gitignore to opt in.';
|
|
98
|
-
function coercePublishMode(raw) {
|
|
99
|
-
if (raw === void 0 || raw.length === 0) return void 0;
|
|
100
|
-
const parsed = PublishModeSchema.safeParse(raw);
|
|
101
|
-
return parsed.success ? parsed.data : void 0;
|
|
102
|
-
}
|
|
103
|
-
function resolvePublishMode(input) {
|
|
104
|
-
const { config, project, env, flag } = input;
|
|
105
|
-
let winner = { value: CONFIG_DEFAULTS.publish.mode, source: "default" };
|
|
106
|
-
const fromFile = config.publish?.mode;
|
|
107
|
-
if (fromFile !== void 0) winner = { value: fromFile, source: "file" };
|
|
108
|
-
if (project !== void 0 && project.publish?.mode !== void 0) {
|
|
109
|
-
const fromProject = project.publish.mode;
|
|
110
|
-
if (fromProject === "full-auto" && !project.gitignored) {
|
|
111
|
-
winner = { value: "auto", source: "project", downgradedWarning: FULL_AUTO_DOWNGRADE_WARNING };
|
|
112
|
-
} else {
|
|
113
|
-
winner = { value: fromProject, source: "project" };
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const fromEnv = coercePublishMode(env.TENJIN_PUBLISH_MODE);
|
|
117
|
-
if (fromEnv !== void 0) winner = { value: fromEnv, source: "env" };
|
|
118
|
-
const fromFlag = coercePublishMode(flag);
|
|
119
|
-
if (fromFlag !== void 0) winner = { value: fromFlag, source: "flag" };
|
|
120
|
-
return winner;
|
|
121
|
-
}
|
|
122
|
-
function resolvePublishDefaultPrice(input) {
|
|
123
|
-
const { config, project } = input;
|
|
124
|
-
let result = {
|
|
125
|
-
value: CONFIG_DEFAULTS.publish.defaultPrice,
|
|
126
|
-
source: "default"
|
|
127
|
-
};
|
|
128
|
-
if (config.publish?.defaultPrice !== void 0) {
|
|
129
|
-
result = { value: config.publish.defaultPrice, source: "file" };
|
|
130
|
-
}
|
|
131
|
-
if (project?.publish?.defaultPrice !== void 0) {
|
|
132
|
-
result = { value: project.publish.defaultPrice, source: "project" };
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
}
|
|
136
|
-
function fileOrDefault(key, config) {
|
|
137
|
-
const fromFile = config[key];
|
|
138
|
-
if (fromFile !== void 0) return { value: fromFile, source: "file" };
|
|
139
|
-
return { value: CONFIG_DEFAULTS[key], source: "default" };
|
|
140
|
-
}
|
|
141
|
-
function resolveBaseUrl(config, flags, env) {
|
|
142
|
-
if (flags.baseUrl !== void 0 && flags.baseUrl.length > 0) {
|
|
143
|
-
return { value: flags.baseUrl, source: "flag" };
|
|
144
|
-
}
|
|
145
|
-
const fromEnv = env.TENJIN_BASE_URL;
|
|
146
|
-
if (fromEnv !== void 0 && fromEnv.length > 0) {
|
|
147
|
-
return { value: fromEnv, source: "env" };
|
|
148
|
-
}
|
|
149
|
-
if (config.baseUrl !== void 0) return { value: config.baseUrl, source: "file" };
|
|
150
|
-
return { value: CONFIG_DEFAULTS.baseUrl, source: "default" };
|
|
151
|
-
}
|
|
152
|
-
function isNotFound(err) {
|
|
153
|
-
return typeof err === "object" && err !== null && "code" in err && err.code === "ENOENT";
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// src/lib/money.ts
|
|
157
|
-
var USDC_DECIMALS = 6;
|
|
158
|
-
function parseUsdToAtomic(input) {
|
|
159
|
-
const trimmed = input.trim();
|
|
160
|
-
if (!/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
161
|
-
throw new CliError("USAGE", `Invalid USD amount: ${JSON.stringify(input)}`, {
|
|
162
|
-
fix: "Pass a non-negative decimal like 0.25 or 5."
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
const [whole, frac = ""] = trimmed.split(".");
|
|
166
|
-
if (frac.length > USDC_DECIMALS) {
|
|
167
|
-
throw new CliError(
|
|
168
|
-
"USAGE",
|
|
169
|
-
`USD amount ${JSON.stringify(input)} has more than 6 decimal places`,
|
|
170
|
-
{
|
|
171
|
-
fix: "USDC supports at most 6 decimal places (micro-dollars)."
|
|
172
|
-
}
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
const atomic = BigInt(`${whole}${frac.padEnd(USDC_DECIMALS, "0")}`);
|
|
176
|
-
return atomic.toString();
|
|
177
|
-
}
|
|
178
|
-
function atomicToUsd(atomic) {
|
|
179
|
-
const trimmed = atomic.trim();
|
|
180
|
-
if (!/^\d+$/.test(trimmed)) {
|
|
181
|
-
throw new CliError("INTERNAL", `Malformed atomic amount: ${JSON.stringify(atomic)}`);
|
|
182
|
-
}
|
|
183
|
-
const value = BigInt(trimmed);
|
|
184
|
-
const base = 10n ** BigInt(USDC_DECIMALS);
|
|
185
|
-
const whole = value / base;
|
|
186
|
-
const frac = (value % base).toString().padStart(USDC_DECIMALS, "0").replace(/0+$/, "");
|
|
187
|
-
return frac.length > 0 ? `${whole}.${frac}` : whole.toString();
|
|
188
|
-
}
|
|
189
|
-
function toMoney(atomic) {
|
|
190
|
-
return { atomic, usd: atomicToUsd(atomic) };
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export {
|
|
194
|
-
PublishModeSchema,
|
|
195
|
-
parsePublishModeFlag,
|
|
196
|
-
RawConfigSchema,
|
|
197
|
-
CONFIG_DEFAULTS,
|
|
198
|
-
CONFIG_KEYS,
|
|
199
|
-
PUBLISH_CONFIG_KEYS,
|
|
200
|
-
loadRawConfig,
|
|
201
|
-
resolveSettings,
|
|
202
|
-
resolvePublishMode,
|
|
203
|
-
resolvePublishDefaultPrice,
|
|
204
|
-
parseUsdToAtomic,
|
|
205
|
-
toMoney
|
|
206
|
-
};
|
|
207
|
-
//# sourceMappingURL=chunk-ESPNTPQ2.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/config.ts","../src/lib/money.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport { CliError } from './errors';\nimport { configPath } from './paths';\nimport { writeFileAtomic } from './atomic-json';\n\n/** A non-negative integer string in USDC atomic units (6-decimal base). */\nconst atomicString = z.string().regex(/^\\d+$/, 'expected an atomic USDC integer string');\n\n/** The publish consent mode (B3, D38). `full-auto` is loosening-gated, below. */\nexport const PublishModeSchema = z.enum(['review', 'auto', 'full-auto']);\nexport type PublishMode = z.infer<typeof PublishModeSchema>;\n\n/**\n * Validate a publish-mode value at a command edge (`--mode`, `--publish-mode`):\n * an unrecognized value is USAGE (exit 2), never silently dropped. `flagName` is\n * woven into the message so the failing flag is named.\n */\nexport function parsePublishModeFlag(value: string, flagName: string): PublishMode {\n const parsed = PublishModeSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n throw new CliError('USAGE', `Invalid ${flagName} ${JSON.stringify(value)}`, {\n fix: 'Use \"review\", \"auto\", or \"full-auto\".',\n });\n}\n\n/**\n * The publish block (B3): `mode` governs the confirm cascade a `publish` runs,\n * `defaultPrice` is the atomic USDC price a card is published at when no\n * per-publish price is given. Stored atomic like the spend keys.\n */\nconst PublishConfigSchema = z.object({\n mode: PublishModeSchema,\n defaultPrice: atomicString,\n});\n\n/**\n * The persisted config shape. Spend keys are stored atomic (accepted as decimal\n * USD at the command edge, see lib/money); `confirm` is the stored form\n * \"always\" | \"above:<atomic>\". These are client-enforced guardrails, not a\n * security boundary — any process that runs the CLI can also edit this file.\n */\nexport const ConfigSchema = z.object({\n maxAutoSpend: atomicString,\n sessionBudget: atomicString,\n confirm: z.union([z.literal('always'), z.string().regex(/^above:\\d+$/)]),\n allowlistCreators: z.array(z.string()),\n baseUrl: z.url(),\n rpcUrl: z.url(),\n /**\n * Evaluation-cohort opt-in (spec 09 §3): when true, lookup sends\n * X-Tenjin-Eval-Cohort: 1 and the server stores the generalized question for\n * 90 days. Off by default; no query text is retained server-side without it.\n */\n evalCohort: z.boolean(),\n publish: PublishConfigSchema,\n});\nexport type Config = z.infer<typeof ConfigSchema>;\n\n/**\n * Values as they may appear in config.json — every known key optional; absent =\n * default. `.passthrough()` PRESERVES unknown keys through load + persist: without\n * it an older binary's `config set` would strip (and re-serialize away) any newer\n * block a later CLI wrote, e.g. B3's `publish.*`. Known keys are still validated;\n * unknown keys ride along untouched.\n */\nexport const RawConfigSchema = ConfigSchema.partial()\n // The publish block is itself partial + passthrough: `config set publish.mode`\n // writes only the one subkey, and a subkey a newer CLI adds (e.g. publish.*\n // beyond mode/defaultPrice) survives an older binary's set, same reason the\n // outer object passes unknown keys through.\n .extend({ publish: PublishConfigSchema.partial().passthrough().optional() })\n .passthrough();\nexport type PartialConfig = z.infer<typeof RawConfigSchema>;\n\nexport const CONFIG_DEFAULTS: Config = {\n maxAutoSpend: '0',\n sessionBudget: '0',\n confirm: 'always',\n allowlistCreators: [],\n baseUrl: 'https://tenjin.blog',\n rpcUrl: 'https://mainnet.base.org',\n evalCohort: false,\n publish: { mode: 'review', defaultPrice: '100000' },\n};\n\n/**\n * Scalar keys `config get/set/list` render one line each. `publish` is excluded:\n * it is a nested block addressed by the dotted `publish.mode`/`publish.defaultPrice`\n * keys (see PUBLISH_CONFIG_KEYS), so it is never rendered as a bare scalar.\n */\nexport type ScalarConfigKey = Exclude<keyof Config, 'publish'>;\nexport const CONFIG_KEYS = (Object.keys(CONFIG_DEFAULTS) as Array<keyof Config>).filter(\n (key): key is ScalarConfigKey => key !== 'publish',\n);\n\n/** The dotted keys `config get/set` accept for the nested publish block. */\nexport const PUBLISH_CONFIG_KEYS = ['publish.mode', 'publish.defaultPrice'] as const;\nexport type PublishConfigKey = (typeof PUBLISH_CONFIG_KEYS)[number];\n\n/**\n * Read and validate config.json WITHOUT applying defaults, so provenance can\n * distinguish \"present in file\" from \"absent\". Missing file is fine (returns\n * {}); malformed JSON or a failed schema is CONFIG_INVALID with a fix.\n */\nexport async function loadRawConfig(dir: string): Promise<PartialConfig> {\n const path = configPath(dir);\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n if (isNotFound(err)) return {};\n throw new CliError('CONFIG_INVALID', `Could not read config at ${path}`, {\n fix: `Check file permissions on ${path}.`,\n cause: err,\n });\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch (err) {\n throw new CliError('CONFIG_INVALID', `Config at ${path} is not valid JSON`, {\n fix: `Fix the JSON syntax in ${path}, or delete it to restore defaults.`,\n cause: err,\n });\n }\n const parsed = RawConfigSchema.safeParse(json);\n if (!parsed.success) {\n throw new CliError('CONFIG_INVALID', `Config at ${path} is invalid`, {\n fix: `Correct the reported keys in ${path}, or delete it to restore defaults.`,\n details: parsed.error.issues,\n });\n }\n return parsed.data;\n}\n\n/** File values merged over defaults — the effective persisted config. The nested\n * publish block is merged per-subkey so a file that sets only publish.mode keeps\n * the default defaultPrice (a shallow spread would drop it). */\nexport async function loadConfig(dir: string): Promise<Config> {\n const raw = await loadRawConfig(dir);\n return {\n ...CONFIG_DEFAULTS,\n ...raw,\n publish: {\n mode: raw.publish?.mode ?? CONFIG_DEFAULTS.publish.mode,\n defaultPrice: raw.publish?.defaultPrice ?? CONFIG_DEFAULTS.publish.defaultPrice,\n },\n };\n}\n\nexport type Provenance = 'default' | 'file' | 'project' | 'env' | 'flag';\n\nexport interface ResolvedSetting<T> {\n value: T;\n source: Provenance;\n}\n\n/**\n * The per-project `.tenjin.json` layer (B3, D38): publish overrides discovered by\n * walking up from cwd, plus whether that file is gitignored. `gitignored` gates\n * `full-auto` — a committed file requesting it is downgraded (loosening gate).\n */\nexport interface ProjectPublishLayer {\n publish?: { mode?: PublishMode; defaultPrice?: string };\n gitignored: boolean;\n}\n\n/** publish.mode resolution: value, source, and the downgrade warning (if any). */\nexport interface PublishModeResolution {\n value: PublishMode;\n source: Provenance;\n /** Set when a committed `.tenjin.json`'s `full-auto` was downgraded to `auto`. */\n downgradedWarning?: string;\n}\n\n/** Effective value + where it came from, per key. What `config` (bare) renders. */\nexport interface EffectiveSettings {\n maxAutoSpend: ResolvedSetting<string>;\n sessionBudget: ResolvedSetting<string>;\n confirm: ResolvedSetting<string>;\n allowlistCreators: ResolvedSetting<string[]>;\n baseUrl: ResolvedSetting<string>;\n rpcUrl: ResolvedSetting<string>;\n evalCohort: ResolvedSetting<boolean>;\n publishMode: PublishModeResolution;\n publishDefaultPrice: ResolvedSetting<string>;\n}\n\n/** CLI flags that participate in settings precedence (`--base-url`). */\nexport interface SettingsFlags {\n baseUrl?: string;\n}\n\nexport interface ResolveSettingsInput {\n /** Raw file values (present keys only) — from loadRawConfig, not loadConfig. */\n config: PartialConfig;\n flags: SettingsFlags;\n env: NodeJS.ProcessEnv;\n /** The nearest `.tenjin.json` layer, when one was found (see publish-settings). */\n project?: ProjectPublishLayer;\n}\n\n/**\n * Apply precedence flag > env > file > default per key, returning each effective\n * value with its source. In B1 only baseUrl has flag/env overrides\n * (`--base-url`, TENJIN_BASE_URL); the rest resolve file-or-default. B3 adds the\n * publish keys, which additionally fold in the per-project `.tenjin.json` layer.\n */\nexport function resolveSettings(input: ResolveSettingsInput): EffectiveSettings {\n const { config, flags, env, project } = input;\n return {\n maxAutoSpend: fileOrDefault('maxAutoSpend', config),\n sessionBudget: fileOrDefault('sessionBudget', config),\n confirm: fileOrDefault('confirm', config),\n allowlistCreators: fileOrDefault('allowlistCreators', config),\n baseUrl: resolveBaseUrl(config, flags, env),\n rpcUrl: fileOrDefault('rpcUrl', config),\n evalCohort: fileOrDefault('evalCohort', config),\n publishMode: resolvePublishMode({ config, project, env }),\n publishDefaultPrice: resolvePublishDefaultPrice({ config, project }),\n };\n}\n\n/**\n * The loosening gate (D38): a committed (not-gitignored) `.tenjin.json` requesting\n * `full-auto` is downgraded to `auto`, never silently honored — cloning a repo\n * must not enable auto-publish. `full-auto` from global config / env / flag (all\n * inherently local, not cloned) is always honored.\n */\nconst FULL_AUTO_DOWNGRADE_WARNING =\n 'Ignoring publish.mode \"full-auto\" from a committed .tenjin.json (cloning a repo must not enable auto-publish); using \"auto\". Add .tenjin.json to .gitignore to opt in.';\n\nfunction coercePublishMode(raw: string | undefined): PublishMode | undefined {\n if (raw === undefined || raw.length === 0) return undefined;\n const parsed = PublishModeSchema.safeParse(raw);\n return parsed.success ? parsed.data : undefined;\n}\n\n/**\n * Resolve publish.mode through global file < project `.tenjin.json` < env\n * (TENJIN_PUBLISH_MODE) < flag (`--mode`). Total: an invalid env/flag value is\n * ignored (validation lives at the command edge, like baseUrl). The project\n * layer's `full-auto` is gated on that file being gitignored.\n */\nexport function resolvePublishMode(input: {\n config: PartialConfig;\n project?: ProjectPublishLayer;\n env: NodeJS.ProcessEnv;\n flag?: string;\n}): PublishModeResolution {\n const { config, project, env, flag } = input;\n let winner: PublishModeResolution = { value: CONFIG_DEFAULTS.publish.mode, source: 'default' };\n\n const fromFile = config.publish?.mode;\n if (fromFile !== undefined) winner = { value: fromFile, source: 'file' };\n\n if (project !== undefined && project.publish?.mode !== undefined) {\n const fromProject = project.publish.mode;\n if (fromProject === 'full-auto' && !project.gitignored) {\n winner = { value: 'auto', source: 'project', downgradedWarning: FULL_AUTO_DOWNGRADE_WARNING };\n } else {\n winner = { value: fromProject, source: 'project' };\n }\n }\n\n const fromEnv = coercePublishMode(env.TENJIN_PUBLISH_MODE);\n if (fromEnv !== undefined) winner = { value: fromEnv, source: 'env' };\n\n const fromFlag = coercePublishMode(flag);\n if (fromFlag !== undefined) winner = { value: fromFlag, source: 'flag' };\n\n return winner;\n}\n\n/** Resolve publish.defaultPrice (atomic) through global file < project < default. */\nexport function resolvePublishDefaultPrice(input: {\n config: PartialConfig;\n project?: ProjectPublishLayer;\n}): ResolvedSetting<string> {\n const { config, project } = input;\n let result: ResolvedSetting<string> = {\n value: CONFIG_DEFAULTS.publish.defaultPrice,\n source: 'default',\n };\n if (config.publish?.defaultPrice !== undefined) {\n result = { value: config.publish.defaultPrice, source: 'file' };\n }\n if (project?.publish?.defaultPrice !== undefined) {\n result = { value: project.publish.defaultPrice, source: 'project' };\n }\n return result;\n}\n\n/** Persist a full, validated config via the atomic writer (0700 dir, 0644 file). */\nexport async function writeConfig(dir: string, config: Config): Promise<void> {\n const validated = ConfigSchema.parse(config);\n await writeFileAtomic(configPath(dir), `${JSON.stringify(validated, null, 2)}\\n`, {\n mode: 0o644,\n dirMode: 0o700,\n });\n}\n\nfunction fileOrDefault<K extends keyof Config>(\n key: K,\n config: PartialConfig,\n): ResolvedSetting<Config[K]> {\n const fromFile = config[key];\n // PartialConfig[K] is Config[K] | undefined; narrowing an indexed access of a\n // type parameter doesn't refine K, so assert the excluded-undefined type.\n if (fromFile !== undefined) return { value: fromFile as Config[K], source: 'file' };\n return { value: CONFIG_DEFAULTS[key], source: 'default' };\n}\n\nfunction resolveBaseUrl(\n config: PartialConfig,\n flags: SettingsFlags,\n env: NodeJS.ProcessEnv,\n): ResolvedSetting<string> {\n if (flags.baseUrl !== undefined && flags.baseUrl.length > 0) {\n return { value: flags.baseUrl, source: 'flag' };\n }\n const fromEnv = env.TENJIN_BASE_URL;\n if (fromEnv !== undefined && fromEnv.length > 0) {\n return { value: fromEnv, source: 'env' };\n }\n if (config.baseUrl !== undefined) return { value: config.baseUrl, source: 'file' };\n return { value: CONFIG_DEFAULTS.baseUrl, source: 'default' };\n}\n\nfunction isNotFound(err: unknown): boolean {\n return (\n typeof err === 'object' &&\n err !== null &&\n 'code' in err &&\n (err as { code?: unknown }).code === 'ENOENT'\n );\n}\n","import { CliError } from './errors';\nimport type { Money } from '../schemas';\n\n/** USDC is a 6-decimal token; one dollar is 1_000_000 atomic units. */\nconst USDC_DECIMALS = 6;\n\n/**\n * Decimal USD at the CLI edge -> atomic USDC string (O1). Accepts \"0\", \"0.25\",\n * \"5\"; rejects negatives, non-numeric input, and more than 6 decimal places as\n * USAGE so a fat-fingered amount fails loudly instead of truncating money.\n * String math throughout — a float would lose precision at the 6th decimal.\n */\nexport function parseUsdToAtomic(input: string): string {\n const trimmed = input.trim();\n if (!/^\\d+(\\.\\d+)?$/.test(trimmed)) {\n throw new CliError('USAGE', `Invalid USD amount: ${JSON.stringify(input)}`, {\n fix: 'Pass a non-negative decimal like 0.25 or 5.',\n });\n }\n const [whole, frac = ''] = trimmed.split('.');\n if (frac.length > USDC_DECIMALS) {\n throw new CliError(\n 'USAGE',\n `USD amount ${JSON.stringify(input)} has more than 6 decimal places`,\n {\n fix: 'USDC supports at most 6 decimal places (micro-dollars).',\n },\n );\n }\n const atomic = BigInt(`${whole}${frac.padEnd(USDC_DECIMALS, '0')}`);\n return atomic.toString();\n}\n\n/**\n * Atomic USDC string -> decimal USD string, trailing zeros trimmed (\"250000\" ->\n * \"0.25\", \"5000000\" -> \"5\", \"0\" -> \"0\"). Throws INTERNAL on a malformed atomic\n * value: atomic strings come from validated config or on-chain reads, so a bad\n * one is a bug, not user input.\n */\nexport function atomicToUsd(atomic: string): string {\n const trimmed = atomic.trim();\n if (!/^\\d+$/.test(trimmed)) {\n throw new CliError('INTERNAL', `Malformed atomic amount: ${JSON.stringify(atomic)}`);\n }\n const value = BigInt(trimmed);\n const base = 10n ** BigInt(USDC_DECIMALS);\n const whole = value / base;\n const frac = (value % base).toString().padStart(USDC_DECIMALS, '0').replace(/0+$/, '');\n return frac.length > 0 ? `${whole}.${frac}` : whole.toString();\n}\n\n/** Dual-form money object for machine output. */\nexport function toMoney(atomic: string): Money {\n return { atomic, usd: atomicToUsd(atomic) };\n}\n\n/**\n * Canonical USD for human COPY (a price a person reads): always at least two\n * decimals (\"0.10\", \"5.00\"), keeping any finer precision below a cent\n * (\"0.000001\"). Distinct from `atomicToUsd`, which trims to the shortest exact\n * form for machine output; use this only where a dollar amount is shown to a human.\n */\nexport function formatUsdDisplay(atomic: string): string {\n const [whole, frac = ''] = atomicToUsd(atomic).split('.');\n return `${whole}.${frac.padEnd(2, '0')}`;\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AAOzB,IAAM,eAAe,iBAAE,OAAO,EAAE,MAAM,SAAS,wCAAwC;AAGhF,IAAM,oBAAoB,iBAAE,KAAK,CAAC,UAAU,QAAQ,WAAW,CAAC;AAQhE,SAAS,qBAAqB,OAAe,UAA+B;AACjF,QAAM,SAAS,kBAAkB,UAAU,KAAK;AAChD,MAAI,OAAO,QAAS,QAAO,OAAO;AAClC,QAAM,IAAI,SAAS,SAAS,WAAW,QAAQ,IAAI,KAAK,UAAU,KAAK,CAAC,IAAI;AAAA,IAC1E,KAAK;AAAA,EACP,CAAC;AACH;AAOA,IAAM,sBAAsB,iBAAE,OAAO;AAAA,EACnC,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAQM,IAAM,eAAe,iBAAE,OAAO;AAAA,EACnC,cAAc;AAAA,EACd,eAAe;AAAA,EACf,SAAS,iBAAE,MAAM,CAA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IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,MAAM,SAAS;AAC/D;AAGO,SAAS,QAAQ,QAAuB;AAC7C,SAAO,EAAE,QAAQ,KAAK,YAAY,MAAM,EAAE;AAC5C;","names":[]}
|
package/dist/chunk-FJPLRISB.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// package.json
|
|
4
|
-
var package_default = {
|
|
5
|
-
name: "tenjin-cli",
|
|
6
|
-
version: "0.1.0-alpha.3",
|
|
7
|
-
type: "module",
|
|
8
|
-
description: "Tenjin agent CLI for the x402 knowledge marketplace.",
|
|
9
|
-
license: "MIT",
|
|
10
|
-
repository: {
|
|
11
|
-
type: "git",
|
|
12
|
-
url: "git+https://github.com/BackTrackCo/tenjin-agent.git"
|
|
13
|
-
},
|
|
14
|
-
homepage: "https://tenjin.blog/agents",
|
|
15
|
-
bugs: "https://github.com/BackTrackCo/tenjin-agent/issues",
|
|
16
|
-
keywords: [
|
|
17
|
-
"x402",
|
|
18
|
-
"usdc",
|
|
19
|
-
"base",
|
|
20
|
-
"ai-agents",
|
|
21
|
-
"agent-payments",
|
|
22
|
-
"mcp",
|
|
23
|
-
"knowledge-marketplace",
|
|
24
|
-
"micropayments",
|
|
25
|
-
"claude",
|
|
26
|
-
"codex",
|
|
27
|
-
"cli"
|
|
28
|
-
],
|
|
29
|
-
bin: {
|
|
30
|
-
tenjin: "dist/index.js"
|
|
31
|
-
},
|
|
32
|
-
engines: {
|
|
33
|
-
node: ">=22"
|
|
34
|
-
},
|
|
35
|
-
files: [
|
|
36
|
-
"dist",
|
|
37
|
-
"skills",
|
|
38
|
-
"NOTICE.md"
|
|
39
|
-
],
|
|
40
|
-
packageManager: "pnpm@11.11.0",
|
|
41
|
-
scripts: {
|
|
42
|
-
build: "tsup",
|
|
43
|
-
test: "vitest run",
|
|
44
|
-
typecheck: "tsc --noEmit",
|
|
45
|
-
lint: "eslint .",
|
|
46
|
-
format: "prettier --write .",
|
|
47
|
-
"format:check": "prettier --check .",
|
|
48
|
-
check: "pnpm run build && pnpm run test",
|
|
49
|
-
"sync:skill": "node scripts/sync-skill.mjs",
|
|
50
|
-
"pack-smoke": "bash scripts/pack-smoke.sh",
|
|
51
|
-
changeset: "changeset",
|
|
52
|
-
prepublishOnly: "pnpm run build",
|
|
53
|
-
prepare: "git config core.hooksPath .githooks || true"
|
|
54
|
-
},
|
|
55
|
-
devDependencies: {
|
|
56
|
-
"@changesets/cli": "^2.31.1",
|
|
57
|
-
"@eslint/js": "^9",
|
|
58
|
-
"@types/node": "^25",
|
|
59
|
-
"@x402/core": "2.17.0",
|
|
60
|
-
"@x402/evm": "2.17.0",
|
|
61
|
-
"@x402/extensions": "2.17.0",
|
|
62
|
-
commander: "^14.0.1",
|
|
63
|
-
eslint: "^9",
|
|
64
|
-
"eslint-config-prettier": "^10",
|
|
65
|
-
ox: "0.14.30",
|
|
66
|
-
prettier: "^3",
|
|
67
|
-
tsup: "^8.5.0",
|
|
68
|
-
typescript: "^6",
|
|
69
|
-
"typescript-eslint": "^8",
|
|
70
|
-
viem: "^2.53.1",
|
|
71
|
-
vitest: "^4.1.9",
|
|
72
|
-
zod: "^4.4.3"
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export {
|
|
77
|
-
package_default
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=chunk-FJPLRISB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.3\",\n \"type\": \"module\",\n \"description\": \"Tenjin agent CLI for the x402 knowledge marketplace.\",\n \"license\": \"MIT\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/BackTrackCo/tenjin-agent.git\"\n },\n \"homepage\": \"https://tenjin.blog/agents\",\n \"bugs\": \"https://github.com/BackTrackCo/tenjin-agent/issues\",\n \"keywords\": [\n \"x402\",\n \"usdc\",\n \"base\",\n \"ai-agents\",\n \"agent-payments\",\n \"mcp\",\n \"knowledge-marketplace\",\n \"micropayments\",\n \"claude\",\n \"codex\",\n \"cli\"\n ],\n \"bin\": {\n \"tenjin\": \"dist/index.js\"\n },\n \"engines\": {\n \"node\": \">=22\"\n },\n \"files\": [\n \"dist\",\n \"skills\",\n \"NOTICE.md\"\n ],\n \"packageManager\": \"pnpm@11.11.0\",\n \"scripts\": {\n \"build\": \"tsup\",\n \"test\": \"vitest run\",\n \"typecheck\": \"tsc --noEmit\",\n \"lint\": \"eslint .\",\n \"format\": \"prettier --write .\",\n \"format:check\": \"prettier --check .\",\n \"check\": \"pnpm run build && pnpm run test\",\n \"sync:skill\": \"node scripts/sync-skill.mjs\",\n \"pack-smoke\": \"bash scripts/pack-smoke.sh\",\n \"changeset\": \"changeset\",\n \"prepublishOnly\": \"pnpm run build\",\n \"prepare\": \"git config core.hooksPath .githooks || true\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.31.1\",\n \"@eslint/js\": \"^9\",\n \"@types/node\": \"^25\",\n \"@x402/core\": \"2.17.0\",\n \"@x402/evm\": \"2.17.0\",\n \"@x402/extensions\": \"2.17.0\",\n \"commander\": \"^14.0.1\",\n \"eslint\": \"^9\",\n \"eslint-config-prettier\": \"^10\",\n \"ox\": \"0.14.30\",\n \"prettier\": \"^3\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^6\",\n \"typescript-eslint\": \"^8\",\n \"viem\": \"^2.53.1\",\n \"vitest\": \"^4.1.9\",\n \"zod\": \"^4.4.3\"\n }\n}\n"],"mappings":";;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,aAAe;AAAA,EACf,SAAW;AAAA,EACX,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,EACR,UAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,KAAO;AAAA,IACL,QAAU;AAAA,EACZ;AAAA,EACA,SAAW;AAAA,IACT,MAAQ;AAAA,EACV;AAAA,EACA,OAAS;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAAA,EACA,gBAAkB;AAAA,EAClB,SAAW;AAAA,IACT,OAAS;AAAA,IACT,MAAQ;AAAA,IACR,WAAa;AAAA,IACb,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,gBAAgB;AAAA,IAChB,OAAS;AAAA,IACT,cAAc;AAAA,IACd,cAAc;AAAA,IACd,WAAa;AAAA,IACb,gBAAkB;AAAA,IAClB,SAAW;AAAA,EACb;AAAA,EACA,iBAAmB;AAAA,IACjB,mBAAmB;AAAA,IACnB,cAAc;AAAA,IACd,eAAe;AAAA,IACf,cAAc;AAAA,IACd,aAAa;AAAA,IACb,oBAAoB;AAAA,IACpB,WAAa;AAAA,IACb,QAAU;AAAA,IACV,0BAA0B;AAAA,IAC1B,IAAM;AAAA,IACN,UAAY;AAAA,IACZ,MAAQ;AAAA,IACR,YAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,MAAQ;AAAA,IACR,QAAU;AAAA,IACV,KAAO;AAAA,EACT;AACF;","names":[]}
|