tenjin-cli 0.1.0-alpha.26 → 0.1.0-alpha.28
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 +9 -20
- package/dist/alive-3J3CHOQP.js +21 -0
- package/dist/{chunk-WT7DHJNJ.js → chunk-3QJREVMX.js} +5 -7
- package/dist/{chunk-WT7DHJNJ.js.map → chunk-3QJREVMX.js.map} +1 -1
- package/dist/{chunk-BOAI23CX.js → chunk-6KA4HFX5.js} +21 -15
- package/dist/chunk-6KA4HFX5.js.map +1 -0
- package/dist/chunk-6W5GYG3W.js +128 -0
- package/dist/chunk-6W5GYG3W.js.map +1 -0
- package/dist/{chunk-W36HL4TB.js → chunk-7H3RN4WJ.js} +7 -9
- package/dist/{chunk-W36HL4TB.js.map → chunk-7H3RN4WJ.js.map} +1 -1
- package/dist/{chunk-4HAV6IFE.js → chunk-7R37M6WV.js} +5 -7
- package/dist/{chunk-4HAV6IFE.js.map → chunk-7R37M6WV.js.map} +1 -1
- package/dist/{chunk-LAIZ2AQA.js → chunk-A5H3E5QA.js} +2 -2
- package/dist/{update-QXVH2DE7.js → chunk-AO54FM4H.js} +147 -35
- package/dist/chunk-AO54FM4H.js.map +1 -0
- package/dist/{chunk-XMIVHQ35.js → chunk-B2L53TMK.js} +17 -2
- package/dist/{chunk-XMIVHQ35.js.map → chunk-B2L53TMK.js.map} +1 -1
- package/dist/{chunk-YTM7OURD.js → chunk-BRHREK7E.js} +2 -2
- package/dist/{chunk-YLCWI6ZR.js → chunk-DJYAPACT.js} +79 -36
- package/dist/chunk-DJYAPACT.js.map +1 -0
- package/dist/{chunk-OBPZ36HG.js → chunk-DYSDQE7S.js} +92 -5
- package/dist/chunk-DYSDQE7S.js.map +1 -0
- package/dist/{chunk-EJXIK6WY.js → chunk-FQ6DHINU.js} +80 -48
- package/dist/chunk-FQ6DHINU.js.map +1 -0
- package/dist/chunk-FZTSGQVK.js +52 -0
- package/dist/chunk-FZTSGQVK.js.map +1 -0
- package/dist/{chunk-QF4SSCQV.js → chunk-KAMRYUK2.js} +5 -4
- package/dist/chunk-KAMRYUK2.js.map +1 -0
- package/dist/{chunk-ALJRB7NG.js → chunk-MNTQMZJB.js} +8 -8
- package/dist/{chunk-XICKN3CH.js → chunk-QTND6XWJ.js} +160 -80
- package/dist/chunk-QTND6XWJ.js.map +1 -0
- package/dist/chunk-RLPLYUME.js +115 -0
- package/dist/chunk-RLPLYUME.js.map +1 -0
- package/dist/{chunk-ZLD6MJVJ.js → chunk-S4SAZ7OD.js} +1 -1
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/{chunk-5HS54CLI.js → chunk-UEOWNDQG.js} +8 -10
- package/dist/{chunk-5HS54CLI.js.map → chunk-UEOWNDQG.js.map} +1 -1
- package/dist/{chunk-5INS5ZZF.js → chunk-UOW5JXYY.js} +5 -7
- package/dist/{chunk-5INS5ZZF.js.map → chunk-UOW5JXYY.js.map} +1 -1
- package/dist/chunk-VSUHGRVB.js +1455 -0
- package/dist/chunk-VSUHGRVB.js.map +1 -0
- package/dist/{chunk-Z7R2QDX2.js → chunk-W6JX4LYF.js} +50 -7
- package/dist/chunk-W6JX4LYF.js.map +1 -0
- package/dist/{chunk-UDWGT4FX.js → chunk-XVTD7UWR.js} +14 -8
- package/dist/chunk-XVTD7UWR.js.map +1 -0
- package/dist/{chunk-6JIYGYRB.js → chunk-YFJJYHVG.js} +2 -2
- package/dist/{chunk-DI7WHXOZ.js → chunk-ZG6ZZLO7.js} +898 -521
- package/dist/chunk-ZG6ZZLO7.js.map +1 -0
- package/dist/{chunk-OZ3LWLCI.js → chunk-ZO3X5NPG.js} +4 -6
- package/dist/{chunk-OZ3LWLCI.js.map → chunk-ZO3X5NPG.js.map} +1 -1
- package/dist/{chunk-5NUF4BHR.js → chunk-ZP5PV3JB.js} +4 -4
- package/dist/{chunk-HII5HOQV.js → chunk-ZP7AHN7Z.js} +6 -6
- package/dist/{cli-2U5JB7OQ.js → cli-234DNHN6.js} +53 -51
- package/dist/{cli-2U5JB7OQ.js.map → cli-234DNHN6.js.map} +1 -1
- package/dist/{config-44EGO636.js → config-IY2OJCAK.js} +11 -13
- package/dist/{doctor-BD42BBEG.js → doctor-2UZZF44A.js} +275 -250
- package/dist/doctor-2UZZF44A.js.map +1 -0
- package/dist/{env-proxy-KEGEMWKX.js → env-proxy-XL4P73MZ.js} +2 -2
- package/dist/{fund-WQOOUESE.js → fund-RZ2QFULK.js} +92 -36
- package/dist/{fund-WQOOUESE.js.map → fund-RZ2QFULK.js.map} +1 -1
- package/dist/hook-command-PZHKS7ES.js +31 -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 +11 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +206 -0
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/install-O5FJ5EP3.js +48 -0
- package/dist/{install-identity-4RDWTLJ2.js → install-identity-QM44IQ6Z.js} +7 -7
- package/dist/{install-wallet-USHWL7AX.js → install-wallet-Z52EDLPB.js} +14 -14
- package/dist/{mcp-T5SYCLP7.js → mcp-33HAADDF.js} +557 -118
- package/dist/mcp-33HAADDF.js.map +1 -0
- package/dist/package-RT24HTTP.js +37 -0
- package/dist/{pay-276DSSYG.js → pay-IR2V76FX.js} +16 -16
- package/dist/{payments-TZYLJXK3.js → payments-GFV4HU5R.js} +10 -10
- package/dist/{send-YHDKZPED.js → send-PI4NUA7I.js} +13 -13
- package/dist/{status-X2INT6VD.js → status-ZUHTJK46.js} +10 -9
- package/dist/{status-X2INT6VD.js.map → status-ZUHTJK46.js.map} +1 -1
- package/dist/{status-line-QKDJYZGV.js → status-line-2G5JPQAE.js} +6 -6
- package/dist/uninstall-THKUH5ZT.js +136 -0
- package/dist/uninstall-THKUH5ZT.js.map +1 -0
- package/dist/update-NPZDP24E.js +18 -0
- package/dist/update-NPZDP24E.js.map +1 -0
- package/dist/{wallet-CKKB23D5.js → wallet-53EFH4M5.js} +11 -11
- package/dist/wallet-53EFH4M5.js.map +1 -0
- package/docs/agent-permissions.md +32 -21
- package/package.json +3 -3
- package/dist/chunk-65EJJVT3.js +0 -172
- package/dist/chunk-65EJJVT3.js.map +0 -1
- package/dist/chunk-BOAI23CX.js.map +0 -1
- package/dist/chunk-DI7WHXOZ.js.map +0 -1
- package/dist/chunk-EJXIK6WY.js.map +0 -1
- package/dist/chunk-GHR4BTNJ.js +0 -87
- package/dist/chunk-GHR4BTNJ.js.map +0 -1
- package/dist/chunk-H4BOQLWW.js +0 -99
- package/dist/chunk-H4BOQLWW.js.map +0 -1
- package/dist/chunk-JLEF5WHM.js +0 -132
- package/dist/chunk-JLEF5WHM.js.map +0 -1
- package/dist/chunk-OBPZ36HG.js.map +0 -1
- package/dist/chunk-PM2MOXJ3.js +0 -66
- package/dist/chunk-PM2MOXJ3.js.map +0 -1
- package/dist/chunk-QF4SSCQV.js.map +0 -1
- package/dist/chunk-TGLKKLQG.js +0 -11
- package/dist/chunk-TGLKKLQG.js.map +0 -1
- package/dist/chunk-UDWGT4FX.js.map +0 -1
- package/dist/chunk-VNT3CQFV.js +0 -940
- package/dist/chunk-VNT3CQFV.js.map +0 -1
- package/dist/chunk-XICKN3CH.js.map +0 -1
- package/dist/chunk-YHWBDCGS.js +0 -753
- package/dist/chunk-YHWBDCGS.js.map +0 -1
- package/dist/chunk-YLCWI6ZR.js.map +0 -1
- package/dist/chunk-Z7R2QDX2.js.map +0 -1
- package/dist/chunk-ZLD6MJVJ.js.map +0 -1
- package/dist/doctor-BD42BBEG.js.map +0 -1
- package/dist/hook-command-23LC5NRN.js +0 -32
- package/dist/install-REPLHNU7.js +0 -72
- package/dist/mcp-T5SYCLP7.js.map +0 -1
- package/dist/status-line-wiring-LW4HFRHB.js +0 -31
- package/dist/uninstall-NVTGU7JD.js +0 -175
- package/dist/uninstall-NVTGU7JD.js.map +0 -1
- package/dist/update-QXVH2DE7.js.map +0 -1
- /package/dist/{config-44EGO636.js.map → alive-3J3CHOQP.js.map} +0 -0
- /package/dist/{chunk-LAIZ2AQA.js.map → chunk-A5H3E5QA.js.map} +0 -0
- /package/dist/{chunk-YTM7OURD.js.map → chunk-BRHREK7E.js.map} +0 -0
- /package/dist/{chunk-ALJRB7NG.js.map → chunk-MNTQMZJB.js.map} +0 -0
- /package/dist/{chunk-6JIYGYRB.js.map → chunk-YFJJYHVG.js.map} +0 -0
- /package/dist/{chunk-5NUF4BHR.js.map → chunk-ZP5PV3JB.js.map} +0 -0
- /package/dist/{chunk-HII5HOQV.js.map → chunk-ZP7AHN7Z.js.map} +0 -0
- /package/dist/{env-proxy-KEGEMWKX.js.map → config-IY2OJCAK.js.map} +0 -0
- /package/dist/{hook-command-23LC5NRN.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
- /package/dist/{install-REPLHNU7.js.map → hook-command-PZHKS7ES.js.map} +0 -0
- /package/dist/{install-identity-4RDWTLJ2.js.map → install-O5FJ5EP3.js.map} +0 -0
- /package/dist/{pay-276DSSYG.js.map → install-identity-QM44IQ6Z.js.map} +0 -0
- /package/dist/{install-wallet-USHWL7AX.js.map → install-wallet-Z52EDLPB.js.map} +0 -0
- /package/dist/{status-line-wiring-LW4HFRHB.js.map → package-RT24HTTP.js.map} +0 -0
- /package/dist/{wallet-CKKB23D5.js.map → pay-IR2V76FX.js.map} +0 -0
- /package/dist/{payments-TZYLJXK3.js.map → payments-GFV4HU5R.js.map} +0 -0
- /package/dist/{send-YHDKZPED.js.map → send-PI4NUA7I.js.map} +0 -0
- /package/dist/{status-line-QKDJYZGV.js.map → status-line-2G5JPQAE.js.map} +0 -0
|
@@ -1,13 +1,35 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
evaluateSpendPolicy
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-B2L53TMK.js";
|
|
5
5
|
import {
|
|
6
6
|
hasCode
|
|
7
7
|
} from "./chunk-2I4QTOLB.js";
|
|
8
8
|
import {
|
|
9
|
-
formatUsdDisplay
|
|
10
|
-
|
|
9
|
+
formatUsdDisplay,
|
|
10
|
+
toMoney
|
|
11
|
+
} from "./chunk-FZTSGQVK.js";
|
|
12
|
+
|
|
13
|
+
// src/router/names.ts
|
|
14
|
+
var PLUGIN_NAME = "tenjin";
|
|
15
|
+
var MCP_SERVER_NAME = "router";
|
|
16
|
+
var MARKETPLACE_NAME = "tenjin";
|
|
17
|
+
var PLUGIN_ID = `${PLUGIN_NAME}@${MARKETPLACE_NAME}`;
|
|
18
|
+
var SKILLS_DIR_PLUGIN_ID = `${PLUGIN_NAME}@skills-dir`;
|
|
19
|
+
var PLUGIN_SERVER = `plugin:${PLUGIN_NAME}:${MCP_SERVER_NAME}`;
|
|
20
|
+
var TOOL_PREFIX = `mcp__plugin_${PLUGIN_NAME}_${MCP_SERVER_NAME}`;
|
|
21
|
+
var REQUEST_TOOL = `${TOOL_PREFIX}__request`;
|
|
22
|
+
var PLUGIN_HOOK_TOOL = `${TOOL_PREFIX}__hook`;
|
|
23
|
+
var LEGACY_MCP_SERVER_NAME = "x402";
|
|
24
|
+
var LEGACY_REQUEST_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__request`;
|
|
25
|
+
var LEGACY_HOOK_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__hook`;
|
|
26
|
+
function launchedByPlugin(env = process.env) {
|
|
27
|
+
const root = env.CLAUDE_PLUGIN_ROOT;
|
|
28
|
+
return typeof root === "string" && root.length > 0;
|
|
29
|
+
}
|
|
30
|
+
function requestToolName(env = process.env) {
|
|
31
|
+
return launchedByPlugin(env) ? REQUEST_TOOL : LEGACY_REQUEST_TOOL;
|
|
32
|
+
}
|
|
11
33
|
|
|
12
34
|
// src/router/fee.ts
|
|
13
35
|
import { createHash } from "node:crypto";
|
|
@@ -127,7 +149,63 @@ async function createExclusive(path, body) {
|
|
|
127
149
|
}
|
|
128
150
|
}
|
|
129
151
|
|
|
152
|
+
// src/router/spend-question.ts
|
|
153
|
+
var ROUTER_DEFAULTS = {
|
|
154
|
+
maxAutoSpend: "250000",
|
|
155
|
+
sessionBudget: "5000000"
|
|
156
|
+
};
|
|
157
|
+
function shownLimits(config) {
|
|
158
|
+
return {
|
|
159
|
+
maxAutoSpend: config.maxAutoSpend ?? ROUTER_DEFAULTS.maxAutoSpend,
|
|
160
|
+
sessionBudget: config.sessionBudget ?? ROUTER_DEFAULTS.sessionBudget
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function limitsUsd(limits) {
|
|
164
|
+
return {
|
|
165
|
+
maxAutoSpend: toMoney(limits.maxAutoSpend).usd,
|
|
166
|
+
sessionBudget: limits.sessionBudget === "none" ? "none" : toMoney(limits.sessionBudget).usd
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function limitsPhrase(limits) {
|
|
170
|
+
const usdOf = limitsUsd(limits);
|
|
171
|
+
const daily = usdOf.sessionBudget === "none" ? "with no daily limit" : `and $${usdOf.sessionBudget} a day`;
|
|
172
|
+
return `up to $${usdOf.maxAutoSpend} a call ${daily}`;
|
|
173
|
+
}
|
|
174
|
+
var ROUTING_FEE_TERMS = `Routing costs $${usd(ROUTING_FEE_ATOMIC)} a call, paid from channel deposits of up to $${usd(CHANNEL_DEPOSIT_ATOMIC)} that stay yours until spent; each deposit counts against these limits.`;
|
|
175
|
+
var ACCEPT_COMMAND = `tenjin config set maxAutoSpend ${toMoney(ROUTER_DEFAULTS.maxAutoSpend).usd}`;
|
|
176
|
+
var OWN_LIMITS_COMMANDS = "`tenjin config set maxAutoSpend <usd>` and `tenjin config set sessionBudget <usd|none>`";
|
|
177
|
+
var FEE_APPROVAL = "Using these limits or choosing your own also approves the routing fee.";
|
|
178
|
+
function spendQuestion(limits) {
|
|
179
|
+
return `May Tenjin pay for tool calls without asking you each time, ${limitsPhrase(limits)}? ${ROUTING_FEE_TERMS} ${FEE_APPROVAL}`;
|
|
180
|
+
}
|
|
181
|
+
function unansweredNotice(limits, reader) {
|
|
182
|
+
const open2 = "Tenjin pays for nothing on its own yet: the spend limits are not answered.";
|
|
183
|
+
if (reader === "agent") {
|
|
184
|
+
return `${open2} Ask the user: ${spendQuestion(limits)} For a yes, run \`${ACCEPT_COMMAND}\`; for other amounts, run ${OWN_LIMITS_COMMANDS}.`;
|
|
185
|
+
}
|
|
186
|
+
return `${open2} It can pay for tool calls without asking you each time, ${limitsPhrase(limits)}. ${ROUTING_FEE_TERMS} ${FEE_APPROVAL} To use these limits, run \`${ACCEPT_COMMAND}\`; to choose your own, run ${OWN_LIMITS_COMMANDS}.`;
|
|
187
|
+
}
|
|
188
|
+
function unpaidNotice(why, config, reader) {
|
|
189
|
+
if (why === "limit_below_deposit" && config.maxAutoSpend === void 0) {
|
|
190
|
+
return unansweredNotice(shownLimits(config), reader);
|
|
191
|
+
}
|
|
192
|
+
return unpaidSentence(why);
|
|
193
|
+
}
|
|
194
|
+
|
|
130
195
|
export {
|
|
196
|
+
PLUGIN_NAME,
|
|
197
|
+
MCP_SERVER_NAME,
|
|
198
|
+
MARKETPLACE_NAME,
|
|
199
|
+
PLUGIN_ID,
|
|
200
|
+
SKILLS_DIR_PLUGIN_ID,
|
|
201
|
+
PLUGIN_SERVER,
|
|
202
|
+
REQUEST_TOOL,
|
|
203
|
+
PLUGIN_HOOK_TOOL,
|
|
204
|
+
LEGACY_MCP_SERVER_NAME,
|
|
205
|
+
LEGACY_REQUEST_TOOL,
|
|
206
|
+
LEGACY_HOOK_TOOL,
|
|
207
|
+
launchedByPlugin,
|
|
208
|
+
requestToolName,
|
|
131
209
|
ROUTE_PAID_PATH,
|
|
132
210
|
ROUTING_FEE_ATOMIC,
|
|
133
211
|
CHANNEL_DEPOSIT_ATOMIC,
|
|
@@ -140,6 +218,15 @@ export {
|
|
|
140
218
|
unpaidSentence,
|
|
141
219
|
payerDir,
|
|
142
220
|
usd,
|
|
143
|
-
firstNoticeFor
|
|
221
|
+
firstNoticeFor,
|
|
222
|
+
ROUTER_DEFAULTS,
|
|
223
|
+
shownLimits,
|
|
224
|
+
limitsUsd,
|
|
225
|
+
ROUTING_FEE_TERMS,
|
|
226
|
+
ACCEPT_COMMAND,
|
|
227
|
+
OWN_LIMITS_COMMANDS,
|
|
228
|
+
FEE_APPROVAL,
|
|
229
|
+
spendQuestion,
|
|
230
|
+
unpaidNotice
|
|
144
231
|
};
|
|
145
|
-
//# sourceMappingURL=chunk-
|
|
232
|
+
//# sourceMappingURL=chunk-DYSDQE7S.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/names.ts","../src/router/fee.ts","../src/router/spend-question.ts"],"sourcesContent":["/**\n * THE NAMES THE HARNESS KNOWS THE ROUTER BY, spelled once. `install` registers\n * the Claude Code plugin {@link PLUGIN_NAME}, whose MCP server is\n * {@link MCP_SERVER_NAME}, and Claude Code names a plugin's tools\n * `mcp__plugin_<plugin>_<server>__<tool>`. The plugin's hooks, the server's own\n * name and every hint line the hooks inject read these, so a rename moves them\n * together.\n *\n * A module of its own because the hooks need the tool name and must not load\n * `install` to get it: their chunk graph is the product's floor.\n */\nexport const PLUGIN_NAME = 'tenjin';\nexport const MCP_SERVER_NAME = 'router';\n/** The marketplace `install` adds from the package, so the plugin id is `tenjin@tenjin`. */\nexport const MARKETPLACE_NAME = 'tenjin';\nexport const PLUGIN_ID = `${PLUGIN_NAME}@${MARKETPLACE_NAME}`;\n/** The id Claude Code gives the same plugin loaded from a skills-directory folder. */\nexport const SKILLS_DIR_PLUGIN_ID = `${PLUGIN_NAME}@skills-dir`;\n/** How a plugin's `hooks.json` and `claude mcp` name the plugin's own server. */\nexport const PLUGIN_SERVER = `plugin:${PLUGIN_NAME}:${MCP_SERVER_NAME}`;\nconst TOOL_PREFIX = `mcp__plugin_${PLUGIN_NAME}_${MCP_SERVER_NAME}`;\nexport const REQUEST_TOOL = `${TOOL_PREFIX}__request`;\n/** The tool the plugin's hook legs call, which its own deny hook keeps from the model. */\nexport const PLUGIN_HOOK_TOOL = `${TOOL_PREFIX}__hook`;\n\n/**\n * THE SETTINGS-BASED INSTALL'S NAMES, for its migration and nothing else.\n * Releases up to alpha.26 registered the server as `x402` through `claude mcp\n * add` and wrote seven hook entries and two permission rules into settings.json.\n *\n * SHIM: remove on or after 2026-12-01, the first release cut 30 or more days\n * after the plugin PR 2 ships. Doctor keeps naming an unmigrated machine after.\n */\nexport const LEGACY_MCP_SERVER_NAME = 'x402';\nexport const LEGACY_REQUEST_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__request`;\nexport const LEGACY_HOOK_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__hook`;\n\n/**\n * Is this process one Claude Code launched from the plugin? Claude Code sets\n * `CLAUDE_PLUGIN_ROOT` for a plugin's MCP server and its command hooks\n * (checked on 2.1.296), and not for a server registered in `~/.claude.json`.\n */\nexport function launchedByPlugin(env: NodeJS.ProcessEnv = process.env): boolean {\n const root = env.CLAUDE_PLUGIN_ROOT;\n return typeof root === 'string' && root.length > 0;\n}\n\n/**\n * The request tool's name as THIS process's harness exposes it: the plugin's\n * tool for a server the plugin launched, and the `x402` server's tool for one a\n * settings install launched, so an offer line never names a tool the model\n * does not have.\n *\n * SHIM: the second branch goes on or after 2026-12-01 (see\n * {@link LEGACY_MCP_SERVER_NAME}); the name is then always {@link REQUEST_TOOL}.\n */\nexport function requestToolName(env: NodeJS.ProcessEnv = process.env): string {\n return launchedByPlugin(env) ? REQUEST_TOOL : LEGACY_REQUEST_TOOL;\n}\n","import { createHash } from 'node:crypto';\nimport { mkdir, open, readFile, readdir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { hasCode } from '../lib/errno';\nimport { formatUsdDisplay } from '../lib/money';\nimport { evaluateSpendPolicy, type PolicyReason, type SpendPolicy } from '../lib/policy';\nimport type { DecisionRoute } from './decision';\n\n/**\n * THE ROUTING FEE, WITHOUT ANYTHING THAT PAYS. Every routing call on the paid\n * path pays $0.003 over x402 `batch-settlement`, and the stock SDK client in\n * `tenjin mcp` does all of it (`routing-payer.ts`). Everything else, `tenjin\n * hook` included, is the free path exactly as before this fee existed.\n *\n * Hook-safe: `tenjin hook` loads this module, and its chunk graph stays free\n * of the wallet and the x402 SDK (`dist-chunks.test.ts`).\n */\n\nexport const ROUTE_PAID_PATH = '/api/x402-router/route';\n\n/** The flat fee per routing call, atomic USDC ($0.003). */\nexport const ROUTING_FEE_ATOMIC = 3_000n;\n/** The largest channel deposit, atomic USDC ($0.25), made inline by the SDK\n * on the first paid call of a channel that cannot cover the next fee. */\nexport const CHANNEL_DEPOSIT_ATOMIC = 250_000n;\n/**\n * The smallest deposit worth signing: ten fees ($0.03). A per-call limit under\n * $0.25 sizes the deposit down to the limit while it still covers this many.\n */\nexport const MIN_DEPOSIT_ATOMIC = 10n * ROUTING_FEE_ATOMIC;\n\n/** A spend refusal, as the reason the call was not paid. */\nconst REFUSED: Partial<Record<PolicyReason, string>> = {\n not_allowlisted: 'not_allowlisted',\n session_budget_exceeded: 'budget_reached',\n above_auto_spend: 'limit_below_deposit',\n};\n\n/** The reason a spend refusal leaves a routing call unpaid. */\nexport function refusedWhy(reason: PolicyReason): string {\n return REFUSED[reason] ?? reason;\n}\n\n/**\n * THE DEPOSIT IS THE SPEND. It meets the whole policy once, the day's budget\n * included, when the SDK's `depositStrategy` reserves it. Each fee paid from\n * it then gets only the per-payment checks: the per-call limit, the creator\n * allowlist (the router's host) and an explicit zero daily limit. It is never\n * refused for the day's running total, which the deposit already consumed.\n * Null when those checks allow the fee.\n */\nexport function feeRefusal(policy: SpendPolicy, host: string): string | null {\n const evaluation = evaluateSpendPolicy(\n { ...policy, sessionBudgetAtomic: policy.sessionBudgetAtomic === 0n ? 0n : null },\n { mode: 'automatic', amountAtomic: ROUTING_FEE_ATOMIC, creator: host, sessionSpentAtomic: 0n },\n );\n return evaluation.decision === 'allow' ? null : refusedWhy(evaluation.reason);\n}\n\n/** The paid path for this call, or null for the free path. `tenjin mcp` passes\n * its payer's; absent, every call is free. */\nexport type RouteFor = (baseUrl: string) => Promise<DecisionRoute | null>;\n\n/** The free path's reason code once the server routes only paid calls. */\nexport const FEE_REQUIRED = 'fee_required';\n\n/** Whether a decision is the free path's `fee_required` answer. */\nexport function isFeeRequired(response: unknown): boolean {\n const decision = (response as { decision?: { action?: unknown; diagnostics?: unknown } })\n ?.decision;\n const diagnostics = decision?.diagnostics as { reasonCode?: unknown } | undefined;\n return decision?.action === 'native' && diagnostics?.reasonCode === FEE_REQUIRED;\n}\n\n/**\n * WHY A CALL WAS NOT PAID, for the user: the reason and the fix, keyed by the\n * payer's skip reason (or `fee_required`, when the free path answered it and\n * nothing else explains why). Null for a reason that is no fault and needs no\n * fix: another session's call on the channel, a server with no paid path, or\n * a call queued past its own budget, or a payment still out when the call's\n * budget ran out (it finishes in the background).\n */\nconst UNPAID: Record<string, { reason: string; fix: string }> = {\n wallet_low: {\n reason: `the wallet holds less than the $${usd(CHANNEL_DEPOSIT_ATOMIC)} routing deposit`,\n fix: `Fund it with \\`tenjin wallet fund ${usd(CHANNEL_DEPOSIT_ATOMIC)}\\`.`,\n },\n wallet_locked: {\n reason: '`tenjin mcp` cannot unlock the wallet without a prompt',\n fix: 'Set TENJIN_WALLET_PASSPHRASE in the environment Claude Code starts from, then restart Claude Code.',\n },\n no_wallet: {\n reason: 'this machine has no wallet',\n fix: 'Run `tenjin doctor`.',\n },\n limit_below_deposit: {\n reason: `the per-call spend limit is below the smallest routing deposit ($${usd(MIN_DEPOSIT_ATOMIC)})`,\n fix: 'Run `tenjin doctor`.',\n },\n budget_reached: {\n reason: 'the daily spend limit has no room left for the routing fee or its deposit',\n fix: 'Run `tenjin doctor`.',\n },\n not_allowlisted: {\n reason: 'allowlistCreators does not include the router',\n fix: 'Run `tenjin doctor`.',\n },\n payment_failed: {\n reason: 'the routing payment failed',\n fix: 'Run `tenjin doctor`.',\n },\n [FEE_REQUIRED]: {\n reason: 'the router now charges it, and this session cannot pay it',\n fix: 'Run `tenjin doctor`.',\n },\n};\nconst NO_FAULT = new Set([\n 'channel_busy',\n 'paid_path_absent',\n 'busy',\n 'no_call',\n 'deadline_after_payment_sent',\n]);\n\n/** The reason and fix for an unpaid call, or null when it needs no word. */\nexport function unpaid(why: string): { reason: string; fix: string } | null {\n if (NO_FAULT.has(why)) return null;\n return UNPAID[why] ?? UNPAID['payment_failed']!;\n}\n\n/** The one line the user sees, once per session, when a call was not paid. */\nexport function unpaidSentence(why: string): string | null {\n const u = unpaid(why);\n if (u === null) return null;\n return `Tenjin routing could not pay its $${usd(ROUTING_FEE_ATOMIC)} fee (${u.reason}), so calls take the free path until that is fixed. ${u.fix}`;\n}\n\nconst ADDRESS_RE = /^0x[0-9a-f]{40}$/;\n\n/** One wallet's folder: the SDK's file storage for its routing channel\n * (`client/<channelId>.json`). */\nexport function payerDir(dataDir: string, payer: string): string {\n const name = payer.toLowerCase();\n if (!ADDRESS_RE.test(name)) throw new Error(`not a wallet address: ${payer}`);\n return join(dataDir, 'router', 'fee', name);\n}\n\n/** Atomic USDC as dollars with at least two decimals, never a float. */\nexport function usd(atomic: bigint): string {\n return formatUsdDisplay(atomic.toString());\n}\n\n/** How long a session's notice marker is kept. */\nconst NOTICE_KEEP_MS = 7 * 86_400_000;\n\n/**\n * TRUE ONCE PER SESSION: the first caller for a session id creates its marker\n * and gets true; every later one gets false. Each marker holds the time it was\n * made, and those older than a week go on the way past, so the directory does\n * not grow with every session ever run.\n */\nexport async function firstNoticeFor(\n dataDir: string,\n sessionId: string,\n now: number,\n): Promise<boolean> {\n const dir = join(dataDir, 'router', 'notices');\n const name = createHash('sha256').update(sessionId).digest('hex').slice(0, 32);\n const created = await createExclusive(join(dir, name), String(now));\n if (created) {\n for (const entry of await readdir(dir).catch(() => [] as string[])) {\n const path = join(dir, entry);\n const at = Number(await readFile(path, 'utf8').catch(() => 'NaN'));\n if (!Number.isFinite(at) || now - at > NOTICE_KEEP_MS) await rm(path, { force: true });\n }\n }\n return created;\n}\n\nasync function createExclusive(path: string, body: string): Promise<boolean> {\n try {\n await mkdir(join(path, '..'), { recursive: true, mode: 0o700 });\n const handle = await open(path, 'wx', 0o600);\n try {\n await handle.writeFile(body);\n } finally {\n await handle.close();\n }\n return true;\n } catch (err) {\n if (hasCode(err, 'EEXIST')) return false;\n throw err;\n }\n}\n","import { toMoney } from '../lib/money';\nimport { CHANNEL_DEPOSIT_ATOMIC, ROUTING_FEE_ATOMIC, unpaidSentence, usd } from './fee';\n\n/**\n * THE SPEND QUESTION, ONE TEXT FOR EVERY PLACE THAT ASKS IT. The selector in a\n * terminal, the question an install that could not ask hands to its agent,\n * doctor's warning and the routing notice all show the same limits, the same\n * routing-fee terms and the same one-step yes, so the agent can put to the\n * user exactly what the selector would have.\n */\n\n/** Absent-only automatic router defaults, in atomic USDC. */\nexport const ROUTER_DEFAULTS = {\n maxAutoSpend: '250000',\n sessionBudget: '5000000',\n} as const;\n\n/** The automatic limits a fresh install fills in, in atomic USDC; `sessionBudget` may be `none`. */\nexport interface RouterLimits {\n maxAutoSpend: string;\n sessionBudget: string;\n}\n\n/** What the question shows: the file's own value where it names one, else the default. */\nexport function shownLimits(config: {\n maxAutoSpend?: string | undefined;\n sessionBudget?: string | undefined;\n}): RouterLimits {\n return {\n maxAutoSpend: config.maxAutoSpend ?? ROUTER_DEFAULTS.maxAutoSpend,\n sessionBudget: config.sessionBudget ?? ROUTER_DEFAULTS.sessionBudget,\n };\n}\n\n/** The limits in USD, as the question shows them. */\nexport function limitsUsd(limits: RouterLimits): { maxAutoSpend: string; sessionBudget: string } {\n return {\n maxAutoSpend: toMoney(limits.maxAutoSpend).usd,\n sessionBudget: limits.sessionBudget === 'none' ? 'none' : toMoney(limits.sessionBudget).usd,\n };\n}\n\n/** \"up to $0.25 a call and $5 a day\" */\nexport function limitsPhrase(limits: RouterLimits): string {\n const usdOf = limitsUsd(limits);\n const daily =\n usdOf.sessionBudget === 'none' ? 'with no daily limit' : `and $${usdOf.sessionBudget} a day`;\n return `up to $${usdOf.maxAutoSpend} a call ${daily}`;\n}\n\n/** The routing fee's terms, as the selector names them. */\nexport const ROUTING_FEE_TERMS = `Routing costs $${usd(ROUTING_FEE_ATOMIC)} a call, paid from channel deposits of up to $${usd(CHANNEL_DEPOSIT_ATOMIC)} that stay yours until spent; each deposit counts against these limits.`;\n\n/**\n * The yes to the limits shown, where the command install ran is not known\n * (doctor, the routing notice, the request tool): the per-call limit only.\n * The daily limit already defaults to the one shown. A bare `install --yes`\n * here would undo a `--project` or `--no-wallet` install; install's own\n * output names that command with its flags instead.\n */\nexport const ACCEPT_COMMAND = `tenjin config set maxAutoSpend ${toMoney(ROUTER_DEFAULTS.maxAutoSpend).usd}`;\n\n/** The commands for limits of the user's own, each in backticks. */\nexport const OWN_LIMITS_COMMANDS =\n '`tenjin config set maxAutoSpend <usd>` and `tenjin config set sessionBudget <usd|none>`';\n\n/** The selector's own line: either answer approves the fee. */\nexport const FEE_APPROVAL =\n 'Using these limits or choosing your own also approves the routing fee.';\n\n/** The question, for the agent to put to the user as written. */\nexport function spendQuestion(limits: RouterLimits): string {\n return `May Tenjin pay for tool calls without asking you each time, ${limitsPhrase(limits)}? ${ROUTING_FEE_TERMS} ${FEE_APPROVAL}`;\n}\n\n/** Who reads a notice: the user, in the hook's `systemMessage`, or the agent,\n * in the request tool's answer. */\nexport type NoticeReader = 'user' | 'agent';\n\n/**\n * The routing notice for a machine whose limits nobody has answered: the\n * question and the one-step yes, put to the user directly, or handed to the\n * agent to ask.\n */\nexport function unansweredNotice(limits: RouterLimits, reader: NoticeReader): string {\n const open = 'Tenjin pays for nothing on its own yet: the spend limits are not answered.';\n if (reader === 'agent') {\n return `${open} Ask the user: ${spendQuestion(limits)} For a yes, run \\`${ACCEPT_COMMAND}\\`; for other amounts, run ${OWN_LIMITS_COMMANDS}.`;\n }\n return `${open} It can pay for tool calls without asking you each time, ${limitsPhrase(limits)}. ${ROUTING_FEE_TERMS} ${FEE_APPROVAL} To use these limits, run \\`${ACCEPT_COMMAND}\\`; to choose your own, run ${OWN_LIMITS_COMMANDS}.`;\n}\n\n/**\n * The routing notice for a call that was not paid: the limits question when\n * the per-call limit is the code default's zero because nobody has answered\n * it, else the reason and fix for `why`.\n */\nexport function unpaidNotice(\n why: string,\n config: { maxAutoSpend?: string | undefined; sessionBudget?: string | undefined },\n reader: NoticeReader,\n): string | null {\n if (why === 'limit_below_deposit' && config.maxAutoSpend === undefined) {\n return unansweredNotice(shownLimits(config), reader);\n }\n return unpaidSentence(why);\n}\n"],"mappings":";;;;;;;;;;;;;AAWO,IAAM,cAAc;AACpB,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AACzB,IAAM,YAAY,GAAG,WAAW,IAAI,gBAAgB;AAEpD,IAAM,uBAAuB,GAAG,WAAW;AAE3C,IAAM,gBAAgB,UAAU,WAAW,IAAI,eAAe;AACrE,IAAM,cAAc,eAAe,WAAW,IAAI,eAAe;AAC1D,IAAM,eAAe,GAAG,WAAW;AAEnC,IAAM,mBAAmB,GAAG,WAAW;AAUvC,IAAM,yBAAyB;AAC/B,IAAM,sBAAsB,QAAQ,sBAAsB;AAC1D,IAAM,mBAAmB,QAAQ,sBAAsB;AAOvD,SAAS,iBAAiB,MAAyB,QAAQ,KAAc;AAC9E,QAAM,OAAO,IAAI;AACjB,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS;AACnD;AAWO,SAAS,gBAAgB,MAAyB,QAAQ,KAAa;AAC5E,SAAO,iBAAiB,GAAG,IAAI,eAAe;AAChD;;;AC1DA,SAAS,kBAAkB;AAC3B,SAAS,OAAO,MAAM,UAAU,SAAS,UAAU;AACnD,SAAS,YAAY;AAgBd,IAAM,kBAAkB;AAGxB,IAAM,qBAAqB;AAG3B,IAAM,yBAAyB;AAK/B,IAAM,qBAAqB,MAAM;AAGxC,IAAM,UAAiD;AAAA,EACrD,iBAAiB;AAAA,EACjB,yBAAyB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AAW,SAAS;AACtB,WAAO,GAAGA,KAAI,kBAAkB,cAAc,MAAM,CAAC,qBAAqB,cAAc,8BAA8B,mBAAmB;AAAA,EAC3I;AACA,SAAO,GAAGA,KAAI,4DAA4D,aAAa,MAAM,CAAC,KAAK,iBAAiB,IAAI,YAAY,+BAA+B,cAAc,+BAA+B,mBAAmB;AACrO;AAOO,SAAS,aACd,KACA,QACA,QACe;AACf,MAAI,QAAQ,yBAAyB,OAAO,iBAAiB,QAAW;AACtE,WAAO,iBAAiB,YAAY,MAAM,GAAG,MAAM;AAAA,EACrD;AACA,SAAO,eAAe,GAAG;AAC3B;","names":["open"]}
|
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
ADDITIVE_ARRAY_INFO_FIELDS,
|
|
4
|
+
HTTPFacilitatorClient,
|
|
5
|
+
PaymentRequirementsV2Schema,
|
|
6
|
+
SIGN_IN_WITH_X,
|
|
7
|
+
SIWX_HEADER,
|
|
8
|
+
buildSiwxHeader,
|
|
9
|
+
convertToTokenAmount,
|
|
10
|
+
decodePaymentRequiredHeader,
|
|
11
|
+
decodePaymentResponseHeader,
|
|
12
|
+
deepEqual,
|
|
13
|
+
findByNetworkAndScheme,
|
|
14
|
+
findSchemesByNetwork,
|
|
15
|
+
networkMatchesPattern,
|
|
16
|
+
parseMoney,
|
|
17
|
+
toComparableArray,
|
|
18
|
+
x402HTTPClient,
|
|
19
|
+
x402Version
|
|
20
|
+
} from "./chunk-7EKYXMUO.js";
|
|
2
21
|
import {
|
|
3
22
|
promptYesNo
|
|
4
23
|
} from "./chunk-LHHMV4GU.js";
|
|
5
24
|
import {
|
|
6
25
|
assertPublicDestination
|
|
7
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-A5H3E5QA.js";
|
|
27
|
+
import {
|
|
28
|
+
USDC_ADDRESS
|
|
29
|
+
} from "./chunk-BRHREK7E.js";
|
|
8
30
|
import {
|
|
9
31
|
BATCH_SETTLEMENT_ADDRESS,
|
|
10
32
|
BATCH_SETTLEMENT_SCHEME,
|
|
@@ -25,30 +47,16 @@ import {
|
|
|
25
47
|
receiveAuthorizationTypes,
|
|
26
48
|
voucherTypes
|
|
27
49
|
} from "./chunk-LFZJM56J.js";
|
|
28
|
-
import {
|
|
29
|
-
ADDITIVE_ARRAY_INFO_FIELDS,
|
|
30
|
-
HTTPFacilitatorClient,
|
|
31
|
-
PaymentRequirementsV2Schema,
|
|
32
|
-
SIGN_IN_WITH_X,
|
|
33
|
-
SIWX_HEADER,
|
|
34
|
-
buildSiwxHeader,
|
|
35
|
-
convertToTokenAmount,
|
|
36
|
-
decodePaymentRequiredHeader,
|
|
37
|
-
decodePaymentResponseHeader,
|
|
38
|
-
deepEqual,
|
|
39
|
-
findByNetworkAndScheme,
|
|
40
|
-
findSchemesByNetwork,
|
|
41
|
-
networkMatchesPattern,
|
|
42
|
-
parseMoney,
|
|
43
|
-
toComparableArray,
|
|
44
|
-
x402HTTPClient,
|
|
45
|
-
x402Version
|
|
46
|
-
} from "./chunk-7EKYXMUO.js";
|
|
47
50
|
import {
|
|
48
51
|
createPublicClient,
|
|
49
52
|
http,
|
|
50
53
|
recoverTypedDataAddress
|
|
51
54
|
} from "./chunk-EL56RW2J.js";
|
|
55
|
+
import {
|
|
56
|
+
describeWallet,
|
|
57
|
+
resolveSpendAuthorizer,
|
|
58
|
+
resolveWalletProvider
|
|
59
|
+
} from "./chunk-7R37M6WV.js";
|
|
52
60
|
import {
|
|
53
61
|
encodeAbiParameters,
|
|
54
62
|
encodeFunctionData,
|
|
@@ -57,17 +65,9 @@ import {
|
|
|
57
65
|
maxUint256,
|
|
58
66
|
toBytes
|
|
59
67
|
} from "./chunk-TTNESUPQ.js";
|
|
60
|
-
import {
|
|
61
|
-
USDC_ADDRESS
|
|
62
|
-
} from "./chunk-YTM7OURD.js";
|
|
63
|
-
import {
|
|
64
|
-
describeWallet,
|
|
65
|
-
resolveSpendAuthorizer,
|
|
66
|
-
resolveWalletProvider
|
|
67
|
-
} from "./chunk-4HAV6IFE.js";
|
|
68
68
|
import {
|
|
69
69
|
sanitizeForTerminal
|
|
70
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-XVTD7UWR.js";
|
|
71
71
|
import {
|
|
72
72
|
getAddress
|
|
73
73
|
} from "./chunk-EGELTSPU.js";
|
|
@@ -77,20 +77,20 @@ import {
|
|
|
77
77
|
import {
|
|
78
78
|
fetchFailureToCliError,
|
|
79
79
|
httpRequest
|
|
80
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-UOW5JXYY.js";
|
|
81
81
|
import {
|
|
82
82
|
resolveContextSettings
|
|
83
|
-
} from "./chunk-
|
|
83
|
+
} from "./chunk-ZP7AHN7Z.js";
|
|
84
84
|
import {
|
|
85
|
-
external_exports,
|
|
86
|
-
isSameDeployment,
|
|
87
85
|
parseUsdToAtomic,
|
|
88
|
-
readUsdcBalanceWithFallback,
|
|
89
86
|
toMoney
|
|
90
|
-
} from "./chunk-
|
|
87
|
+
} from "./chunk-FZTSGQVK.js";
|
|
91
88
|
import {
|
|
92
|
-
CliError
|
|
93
|
-
|
|
89
|
+
CliError,
|
|
90
|
+
external_exports,
|
|
91
|
+
isSameDeployment,
|
|
92
|
+
readUsdcBalanceWithFallback
|
|
93
|
+
} from "./chunk-QTND6XWJ.js";
|
|
94
94
|
import {
|
|
95
95
|
__commonJS,
|
|
96
96
|
__toESM
|
|
@@ -11821,8 +11821,7 @@ async function executePay(args, ctx, deps, warnings) {
|
|
|
11821
11821
|
ctx,
|
|
11822
11822
|
deps.provider !== void 0 ? { provider: deps.provider } : {}
|
|
11823
11823
|
);
|
|
11824
|
-
await
|
|
11825
|
-
const signer = await provider.getSigner();
|
|
11824
|
+
const signer = await openWallet(provider);
|
|
11826
11825
|
openedSigner.current = signer;
|
|
11827
11826
|
let effectiveChallenge = paymentRequired;
|
|
11828
11827
|
let effectiveRequirement = requirement;
|
|
@@ -11995,17 +11994,19 @@ async function executePay(args, ctx, deps, warnings) {
|
|
|
11995
11994
|
printBody: args.printBody === true
|
|
11996
11995
|
});
|
|
11997
11996
|
}
|
|
11997
|
+
const refusal = settlementRefusal(paid);
|
|
11998
11998
|
throw new CliError(
|
|
11999
11999
|
"PAYMENT_FAILED",
|
|
12000
|
-
paid.status === 402 ? "Payment was not accepted by the endpoint." : `The endpoint answered ${paid.status} on the paid request; whether it settled is unknown.`,
|
|
12000
|
+
refusal !== void 0 ? `The endpoint did not settle the payment${refusal.reason !== void 0 ? `: ${refusal.reason.replace(/\.+$/, "")}` : ""}.` : paid.status === 402 ? "Payment was not accepted by the endpoint." : `The endpoint answered ${paid.status} on the paid request; whether it settled is unknown.`,
|
|
12001
12001
|
{
|
|
12002
|
-
fix: "The signed payment already left and is recorded as transmitted exposure; the endpoint may still settle it. Do not simply retry: each attempt signs a fresh authorization. Verify the endpoint (and this listing, if Bazaar) before paying again.",
|
|
12002
|
+
fix: refusal !== void 0 ? "The seller reported that nothing settled, but the signed authorization stays valid until it expires, so it is recorded as transmitted exposure. Do not simply retry: each attempt signs a fresh authorization. Use a different service for this." : "The signed payment already left and is recorded as transmitted exposure; the endpoint may still settle it. Do not simply retry: each attempt signs a fresh authorization. Verify the endpoint (and this listing, if Bazaar) before paying again.",
|
|
12003
12003
|
// The amount rides on the failure so a caller can report what is at risk
|
|
12004
12004
|
// rather than a zero. Settlement is unknown by construction here.
|
|
12005
12005
|
details: {
|
|
12006
12006
|
status: paid.status,
|
|
12007
12007
|
body: paid.json,
|
|
12008
12008
|
...providerError(paid.text),
|
|
12009
|
+
...refusal?.reason !== void 0 ? { settlementError: refusal.reason } : {},
|
|
12009
12010
|
amountAtomic: payment.amountAtomic.toString(),
|
|
12010
12011
|
settlement: "unknown",
|
|
12011
12012
|
...payment.authorization !== void 0 ? { authorization: payment.authorization } : {}
|
|
@@ -12138,14 +12139,15 @@ function providerMessage(body) {
|
|
|
12138
12139
|
}
|
|
12139
12140
|
var PROVIDER_ERROR_CHARS = 500;
|
|
12140
12141
|
function providerError(text) {
|
|
12142
|
+
const line = sellerLine(text);
|
|
12143
|
+
return line.length > 0 ? { providerError: line } : {};
|
|
12144
|
+
}
|
|
12145
|
+
function sellerLine(text) {
|
|
12141
12146
|
const flat = sanitizeForTerminal(
|
|
12142
12147
|
mask(text.slice(0, PROVIDER_ERROR_CHARS * 8)).replace(/\s+/g, " ")
|
|
12143
12148
|
).trim();
|
|
12144
|
-
if (flat.length === 0) return {};
|
|
12145
12149
|
const chars = Array.from(flat);
|
|
12146
|
-
return {
|
|
12147
|
-
providerError: chars.length <= PROVIDER_ERROR_CHARS ? flat : `${chars.slice(0, PROVIDER_ERROR_CHARS).join("")}\u2026`
|
|
12148
|
-
};
|
|
12150
|
+
return chars.length <= PROVIDER_ERROR_CHARS ? flat : `${chars.slice(0, PROVIDER_ERROR_CHARS).join("")}\u2026`;
|
|
12149
12151
|
}
|
|
12150
12152
|
function noMatchingEntry(challenge, terms) {
|
|
12151
12153
|
if (terms === void 0 || terms.network === void 0 && terms.asset === void 0) {
|
|
@@ -12271,16 +12273,45 @@ function deliver(url, lane, res, opts) {
|
|
|
12271
12273
|
};
|
|
12272
12274
|
}
|
|
12273
12275
|
function settlementTx(res) {
|
|
12276
|
+
const tx = paymentResponse(res)?.transaction;
|
|
12277
|
+
return typeof tx === "string" && /^0x[0-9a-fA-F]{64}$/.test(tx) ? tx : void 0;
|
|
12278
|
+
}
|
|
12279
|
+
function settlementRefusal(res) {
|
|
12280
|
+
const settle = paymentResponse(res);
|
|
12281
|
+
if (settle?.success !== false) return void 0;
|
|
12282
|
+
const said = [settle.errorReason, settle.errorMessage].find(
|
|
12283
|
+
(value) => typeof value === "string" && value.trim().length > 0
|
|
12284
|
+
);
|
|
12285
|
+
const reason = said !== void 0 ? sellerLine(said) : "";
|
|
12286
|
+
return reason.length > 0 ? { reason } : {};
|
|
12287
|
+
}
|
|
12288
|
+
function paymentResponse(res) {
|
|
12274
12289
|
const header = res.header(PAYMENT_RESPONSE_HEADER) ?? res.header(PAYMENT_RESPONSE_HEADER_V1);
|
|
12275
12290
|
if (header === void 0) return void 0;
|
|
12276
12291
|
try {
|
|
12277
12292
|
const settle = decodePaymentResponseHeader(header);
|
|
12278
|
-
|
|
12279
|
-
return typeof tx === "string" && /^0x[0-9a-fA-F]{64}$/.test(tx) ? tx : void 0;
|
|
12293
|
+
return typeof settle === "object" && settle !== null ? settle : void 0;
|
|
12280
12294
|
} catch {
|
|
12281
12295
|
return void 0;
|
|
12282
12296
|
}
|
|
12283
12297
|
}
|
|
12298
|
+
async function openWallet(provider) {
|
|
12299
|
+
try {
|
|
12300
|
+
await describeWallet(provider);
|
|
12301
|
+
return await provider.getSigner();
|
|
12302
|
+
} catch (err) {
|
|
12303
|
+
if (!(err instanceof CliError)) throw err;
|
|
12304
|
+
throw new CliError(err.code, err.message, {
|
|
12305
|
+
exitCode: err.exitCode,
|
|
12306
|
+
...err.fix !== void 0 ? { fix: err.fix } : {},
|
|
12307
|
+
details: {
|
|
12308
|
+
...typeof err.details === "object" && err.details !== null ? err.details : {},
|
|
12309
|
+
walletUnavailable: true
|
|
12310
|
+
},
|
|
12311
|
+
cause: err
|
|
12312
|
+
});
|
|
12313
|
+
}
|
|
12314
|
+
}
|
|
12284
12315
|
function signerOrThrow(held) {
|
|
12285
12316
|
if (held.current === void 0) {
|
|
12286
12317
|
throw new CliError("INTERNAL", "The payment was built before the wallet was opened.");
|
|
@@ -12295,6 +12326,7 @@ export {
|
|
|
12295
12326
|
inputProblems,
|
|
12296
12327
|
assertResultSchema,
|
|
12297
12328
|
projectBody,
|
|
12329
|
+
policyFix,
|
|
12298
12330
|
x402Client,
|
|
12299
12331
|
BatchSettlementEvmScheme,
|
|
12300
12332
|
toClientEvmSigner,
|
|
@@ -12304,4 +12336,4 @@ export {
|
|
|
12304
12336
|
paidLegTimeoutMs,
|
|
12305
12337
|
settlementTx
|
|
12306
12338
|
};
|
|
12307
|
-
//# sourceMappingURL=chunk-
|
|
12339
|
+
//# sourceMappingURL=chunk-FQ6DHINU.js.map
|