tenjin-cli 0.1.0-alpha.21 → 0.1.0-alpha.23

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.
Files changed (91) hide show
  1. package/README.md +17 -14
  2. package/dist/{chunk-PJEG2JIJ.js → chunk-2RMXTNLT.js} +4 -4
  3. package/dist/{chunk-2AQO4YDI.js → chunk-3IOS6YG6.js} +3 -3
  4. package/dist/{chunk-IOIHYOU4.js → chunk-6O6DFYF3.js} +2 -2
  5. package/dist/chunk-A2XMQSWI.js +140 -0
  6. package/dist/chunk-A2XMQSWI.js.map +1 -0
  7. package/dist/{chunk-YVODPFTL.js → chunk-DHCOGDJB.js} +4 -4
  8. package/dist/{chunk-AQRUD5GQ.js → chunk-F4IJQBGP.js} +4 -4
  9. package/dist/{chunk-SRVDXR6B.js → chunk-GONDQ27X.js} +5 -5
  10. package/dist/{chunk-JN7TMXVF.js → chunk-HJYI52HM.js} +2 -2
  11. package/dist/{chunk-UY2TOI3B.js → chunk-HTC4VJFT.js} +77 -7
  12. package/dist/chunk-HTC4VJFT.js.map +1 -0
  13. package/dist/{chunk-OTPEH3AH.js → chunk-I2GBBIDI.js} +5 -5
  14. package/dist/{chunk-GHTPYKDT.js → chunk-K63HPLYT.js} +4 -4
  15. package/dist/{chunk-3EUTWC2B.js → chunk-N7A5EXJZ.js} +4 -4
  16. package/dist/{chunk-N4DJEQAF.js → chunk-NYJCBQL5.js} +2 -2
  17. package/dist/{chunk-RCJQARZF.js → chunk-RA2J3TWG.js} +2 -2
  18. package/dist/{chunk-RCJQARZF.js.map → chunk-RA2J3TWG.js.map} +1 -1
  19. package/dist/{chunk-W3LVZ2EN.js → chunk-SAN5PFTL.js} +102 -5
  20. package/dist/chunk-SAN5PFTL.js.map +1 -0
  21. package/dist/{chunk-QRFONFRW.js → chunk-UGLTSPXQ.js} +2 -2
  22. package/dist/{chunk-IOB7URFH.js → chunk-UHEMZEGW.js} +2 -2
  23. package/dist/{chunk-U2ATFMKZ.js → chunk-WXFVJPZD.js} +2 -2
  24. package/dist/{chunk-C363JZN2.js → chunk-XBYTP4SP.js} +3 -3
  25. package/dist/{chunk-OSUD6YZZ.js → chunk-Y3LKUXZA.js} +8 -8
  26. package/dist/{chunk-ETW2ASBP.js → chunk-YT7A7DLY.js} +94 -29
  27. package/dist/chunk-YT7A7DLY.js.map +1 -0
  28. package/dist/{cli-7KJ4QLUU.js → cli-MUYFTWWB.js} +28 -28
  29. package/dist/{cli-7KJ4QLUU.js.map → cli-MUYFTWWB.js.map} +1 -1
  30. package/dist/{config-MSN6H4MD.js → config-IIRRO3XC.js} +7 -7
  31. package/dist/{doctor-ITUCKN6C.js → doctor-KGHM2CAC.js} +15 -15
  32. package/dist/{fund-XPB4IIG5.js → fund-DOWIT3JT.js} +9 -10
  33. package/dist/{fund-XPB4IIG5.js.map → fund-DOWIT3JT.js.map} +1 -1
  34. package/dist/{hook-command-VVV2Q23L.js → hook-command-RDT754KQ.js} +90 -12
  35. package/dist/hook-command-RDT754KQ.js.map +1 -0
  36. package/dist/index.js +3 -3
  37. package/dist/{install-OSJRM2ME.js → install-BYQUMYBN.js} +10 -10
  38. package/dist/{install-identity-YIWKQOUD.js → install-identity-KTQPYVAO.js} +6 -6
  39. package/dist/{install-wallet-BWJO2SUC.js → install-wallet-T737X74E.js} +8 -9
  40. package/dist/{install-wallet-BWJO2SUC.js.map → install-wallet-T737X74E.js.map} +1 -1
  41. package/dist/{mcp-KE5YKPS2.js → mcp-ZKOTURQN.js} +462 -69
  42. package/dist/mcp-ZKOTURQN.js.map +1 -0
  43. package/dist/{pay-MUV2U232.js → pay-LZPU2HUT.js} +11 -12
  44. package/dist/{payments-4D27K4L2.js → payments-26NVMFR2.js} +6 -7
  45. package/dist/{payments-4D27K4L2.js.map → payments-26NVMFR2.js.map} +1 -1
  46. package/dist/{send-BXHFKDBF.js → send-4RUBQQKP.js} +8 -9
  47. package/dist/{send-BXHFKDBF.js.map → send-4RUBQQKP.js.map} +1 -1
  48. package/dist/{status-3Z3YPRSE.js → status-CEHZKHBU.js} +5 -5
  49. package/dist/{status-line-CKRMGZ3Q.js → status-line-QRAO3Y2E.js} +4 -4
  50. package/dist/{status-line-wiring-GECLIIBT.js → status-line-wiring-7D2CSV3K.js} +4 -4
  51. package/dist/tenjin-daemon.mjs +5 -2
  52. package/dist/{uninstall-BZTVWJ7W.js → uninstall-VR44B4KD.js} +10 -10
  53. package/dist/{update-IQQTEOI5.js → update-SOYQLDBF.js} +5 -5
  54. package/dist/{wallet-UFXQ57TZ.js → wallet-IB2EFAUP.js} +8 -9
  55. package/docs/agent-permissions.md +8 -8
  56. package/docs/safety-model.md +2 -2
  57. package/package.json +1 -1
  58. package/dist/chunk-ETW2ASBP.js.map +0 -1
  59. package/dist/chunk-QHILSA6G.js +0 -82
  60. package/dist/chunk-QHILSA6G.js.map +0 -1
  61. package/dist/chunk-UY2TOI3B.js.map +0 -1
  62. package/dist/chunk-W3LVZ2EN.js.map +0 -1
  63. package/dist/hook-command-VVV2Q23L.js.map +0 -1
  64. package/dist/mcp-KE5YKPS2.js.map +0 -1
  65. /package/dist/{chunk-PJEG2JIJ.js.map → chunk-2RMXTNLT.js.map} +0 -0
  66. /package/dist/{chunk-2AQO4YDI.js.map → chunk-3IOS6YG6.js.map} +0 -0
  67. /package/dist/{chunk-IOIHYOU4.js.map → chunk-6O6DFYF3.js.map} +0 -0
  68. /package/dist/{chunk-YVODPFTL.js.map → chunk-DHCOGDJB.js.map} +0 -0
  69. /package/dist/{chunk-AQRUD5GQ.js.map → chunk-F4IJQBGP.js.map} +0 -0
  70. /package/dist/{chunk-SRVDXR6B.js.map → chunk-GONDQ27X.js.map} +0 -0
  71. /package/dist/{chunk-JN7TMXVF.js.map → chunk-HJYI52HM.js.map} +0 -0
  72. /package/dist/{chunk-OTPEH3AH.js.map → chunk-I2GBBIDI.js.map} +0 -0
  73. /package/dist/{chunk-GHTPYKDT.js.map → chunk-K63HPLYT.js.map} +0 -0
  74. /package/dist/{chunk-3EUTWC2B.js.map → chunk-N7A5EXJZ.js.map} +0 -0
  75. /package/dist/{chunk-N4DJEQAF.js.map → chunk-NYJCBQL5.js.map} +0 -0
  76. /package/dist/{chunk-QRFONFRW.js.map → chunk-UGLTSPXQ.js.map} +0 -0
  77. /package/dist/{chunk-IOB7URFH.js.map → chunk-UHEMZEGW.js.map} +0 -0
  78. /package/dist/{chunk-U2ATFMKZ.js.map → chunk-WXFVJPZD.js.map} +0 -0
  79. /package/dist/{chunk-C363JZN2.js.map → chunk-XBYTP4SP.js.map} +0 -0
  80. /package/dist/{chunk-OSUD6YZZ.js.map → chunk-Y3LKUXZA.js.map} +0 -0
  81. /package/dist/{config-MSN6H4MD.js.map → config-IIRRO3XC.js.map} +0 -0
  82. /package/dist/{doctor-ITUCKN6C.js.map → doctor-KGHM2CAC.js.map} +0 -0
  83. /package/dist/{install-OSJRM2ME.js.map → install-BYQUMYBN.js.map} +0 -0
  84. /package/dist/{install-identity-YIWKQOUD.js.map → install-identity-KTQPYVAO.js.map} +0 -0
  85. /package/dist/{pay-MUV2U232.js.map → pay-LZPU2HUT.js.map} +0 -0
  86. /package/dist/{status-3Z3YPRSE.js.map → status-CEHZKHBU.js.map} +0 -0
  87. /package/dist/{status-line-CKRMGZ3Q.js.map → status-line-QRAO3Y2E.js.map} +0 -0
  88. /package/dist/{status-line-wiring-GECLIIBT.js.map → status-line-wiring-7D2CSV3K.js.map} +0 -0
  89. /package/dist/{uninstall-BZTVWJ7W.js.map → uninstall-VR44B4KD.js.map} +0 -0
  90. /package/dist/{update-IQQTEOI5.js.map → update-SOYQLDBF.js.map} +0 -0
  91. /package/dist/{wallet-UFXQ57TZ.js.map → wallet-IB2EFAUP.js.map} +0 -0
@@ -1,82 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- writeFileAtomic
4
- } from "./chunk-JLEF5WHM.js";
5
- import {
6
- balanceCachePath
7
- } from "./chunk-K6AXXYCG.js";
8
-
9
- // src/lib/usdc-balance.ts
10
- import { readFile } from "node:fs/promises";
11
- var USDC_ADDRESS = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
12
- var BALANCE_OF_SELECTOR = "0x70a08231";
13
- var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
14
- var WORD_RE = /^0x[0-9a-fA-F]{64}$/;
15
- async function readUsdcBalance(address, rpcUrl, opts) {
16
- if (!ADDRESS_RE.test(address) || opts.timeoutMs <= 0) return null;
17
- try {
18
- const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {
19
- method: "POST",
20
- headers: { "content-type": "application/json" },
21
- body: JSON.stringify({
22
- jsonrpc: "2.0",
23
- id: 1,
24
- method: "eth_call",
25
- params: [
26
- {
27
- to: USDC_ADDRESS,
28
- data: `${BALANCE_OF_SELECTOR}${address.slice(2).toLowerCase().padStart(64, "0")}`
29
- },
30
- "latest"
31
- ]
32
- }),
33
- signal: AbortSignal.timeout(opts.timeoutMs)
34
- });
35
- if (!res.ok) return null;
36
- const result = (await res.json())?.result;
37
- return typeof result === "string" && WORD_RE.test(result) ? BigInt(result) : null;
38
- } catch {
39
- return null;
40
- }
41
- }
42
- var LAST_KNOWN_BALANCE_MS = 6e4;
43
- function rememberingBalanceReader(dataDir, opts = {}) {
44
- const read = opts.read ?? readUsdcBalance;
45
- const now = opts.now ?? Date.now;
46
- const path = balanceCachePath(dataDir);
47
- return async (address, rpcUrl, readOpts) => {
48
- const remembered = await recallBalance(path, address, now());
49
- if (remembered !== null) return remembered;
50
- const live = await read(address, rpcUrl, readOpts);
51
- if (live === null) return null;
52
- const record = {
53
- version: 1,
54
- address: address.toLowerCase(),
55
- atomic: live.toString(),
56
- at: now()
57
- };
58
- try {
59
- await writeFileAtomic(path, JSON.stringify(record), { mode: 384, dirMode: 448 });
60
- } catch {
61
- }
62
- return live;
63
- };
64
- }
65
- async function recallBalance(path, address, now) {
66
- try {
67
- const row = JSON.parse(await readFile(path, "utf8"));
68
- if (row?.version !== 1 || row.address !== address.toLowerCase() || typeof row.atomic !== "string" || !/^\d{1,40}$/.test(row.atomic) || typeof row.at !== "number" || now - row.at < 0 || now - row.at > LAST_KNOWN_BALANCE_MS) {
69
- return null;
70
- }
71
- return BigInt(row.atomic);
72
- } catch {
73
- return null;
74
- }
75
- }
76
-
77
- export {
78
- USDC_ADDRESS,
79
- readUsdcBalance,
80
- rememberingBalanceReader
81
- };
82
- //# sourceMappingURL=chunk-QHILSA6G.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/lib/usdc-balance.ts"],"sourcesContent":["/**\n * Base USDC's address and one `balanceOf` over plain JSON-RPC. No viem on\n * purpose: the router hooks read a balance before they redirect a call, and\n * their chunk graph must stay free of it (`src/router/dist-chunks.test.ts`).\n * One `eth_call` needs nothing viem adds. `usdc.ts` keeps the viem client for\n * the send path and re-exports the address from here.\n */\n\nimport { readFile } from 'node:fs/promises';\nimport { writeFileAtomic } from './atomic-json';\nimport { balanceCachePath } from './paths';\n\n// Values mirror the app's lib/chain.ts Base mainnet entry (chain 8453).\nexport const USDC_ADDRESS = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';\n\n/** `balanceOf(address)`: the first four bytes of its keccak-256. */\nconst BALANCE_OF_SELECTOR = '0x70a08231';\nconst ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;\n/** One ABI word: what `balanceOf` returns. */\nconst WORD_RE = /^0x[0-9a-fA-F]{64}$/;\n\n/**\n * The address's USDC balance in atomic units, or null when it could not be\n * read inside `timeoutMs`: a transport failure, a non-2xx, an RPC error, or an\n * answer that is not one word. Never throws, so the caller picks which way an\n * unreadable balance falls.\n */\nexport async function readUsdcBalance(\n address: string,\n rpcUrl: string,\n opts: { timeoutMs: number; fetchImpl?: typeof fetch },\n): Promise<bigint | null> {\n if (!ADDRESS_RE.test(address) || opts.timeoutMs <= 0) return null;\n try {\n const res = await (opts.fetchImpl ?? fetch)(rpcUrl, {\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({\n jsonrpc: '2.0',\n id: 1,\n method: 'eth_call',\n params: [\n {\n to: USDC_ADDRESS,\n data: `${BALANCE_OF_SELECTOR}${address.slice(2).toLowerCase().padStart(64, '0')}`,\n },\n 'latest',\n ],\n }),\n signal: AbortSignal.timeout(opts.timeoutMs),\n });\n if (!res.ok) return null;\n const result = ((await res.json()) as { result?: unknown } | null)?.result;\n return typeof result === 'string' && WORD_RE.test(result) ? BigInt(result) : null;\n } catch {\n return null;\n }\n}\n\n/**\n * How long the hooks remember a balance read. Base's public RPC refuses the\n * sixth `eth_call` in a second, which a burst of parallel lookups reaches, and\n * each hook then waited on a failed read. A minute carries a burst past that;\n * the hooks' read only decides whether to offer.\n */\nexport const LAST_KNOWN_BALANCE_MS = 60_000;\n\n/**\n * {@link readUsdcBalance} for the router hooks, which returns the last read it\n * made for this address while it is under {@link LAST_KNOWN_BALANCE_MS} old,\n * without asking the RPC, and reads the chain otherwise. A read that fails is\n * null, never the remembered balance. The RPC URL is never stored, since it\n * can embed a key.\n *\n * NEVER FOR A PAYMENT. `tenjin pay` reads the signer's balance live\n * immediately before signing (docs/agent-permissions.md): a minute-old balance\n * can be one the wallet has since spent.\n */\nexport function rememberingBalanceReader(\n dataDir: string,\n opts: { now?: () => number; read?: typeof readUsdcBalance } = {},\n): typeof readUsdcBalance {\n const read = opts.read ?? readUsdcBalance;\n const now = opts.now ?? Date.now;\n const path = balanceCachePath(dataDir);\n return async (address, rpcUrl, readOpts) => {\n const remembered = await recallBalance(path, address, now());\n if (remembered !== null) return remembered;\n const live = await read(address, rpcUrl, readOpts);\n if (live === null) return null;\n const record = {\n version: 1,\n address: address.toLowerCase(),\n atomic: live.toString(),\n at: now(),\n };\n try {\n await writeFileAtomic(path, JSON.stringify(record), { mode: 0o600, dirMode: 0o700 });\n } catch {\n // A cache that cannot be written is a cache that is not used.\n }\n return live;\n };\n}\n\n/** The remembered balance for this address while it is fresh, else null. */\nasync function recallBalance(path: string, address: string, now: number): Promise<bigint | null> {\n try {\n const row = JSON.parse(await readFile(path, 'utf8')) as Record<string, unknown> | null;\n if (\n row?.version !== 1 ||\n row.address !== address.toLowerCase() ||\n typeof row.atomic !== 'string' ||\n !/^\\d{1,40}$/.test(row.atomic) ||\n typeof row.at !== 'number' ||\n now - row.at < 0 ||\n now - row.at > LAST_KNOWN_BALANCE_MS\n ) {\n return null;\n }\n return BigInt(row.atomic);\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;AAQA,SAAS,gBAAgB;AAKlB,IAAM,eAAe;AAG5B,IAAM,sBAAsB;AAC5B,IAAM,aAAa;AAEnB,IAAM,UAAU;AAQhB,eAAsB,gBACpB,SACA,QACA,MACwB;AACxB,MAAI,CAAC,WAAW,KAAK,OAAO,KAAK,KAAK,aAAa,EAAG,QAAO;AAC7D,MAAI;AACF,UAAM,MAAM,OAAO,KAAK,aAAa,OAAO,QAAQ;AAAA,MAClD,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU;AAAA,QACnB,SAAS;AAAA,QACT,IAAI;AAAA,QACJ,QAAQ;AAAA,QACR,QAAQ;AAAA,UACN;AAAA,YACE,IAAI;AAAA,YACJ,MAAM,GAAG,mBAAmB,GAAG,QAAQ,MAAM,CAAC,EAAE,YAAY,EAAE,SAAS,IAAI,GAAG,CAAC;AAAA,UACjF;AAAA,UACA;AAAA,QACF;AAAA,MACF,CAAC;AAAA,MACD,QAAQ,YAAY,QAAQ,KAAK,SAAS;AAAA,IAC5C,CAAC;AACD,QAAI,CAAC,IAAI,GAAI,QAAO;AACpB,UAAM,UAAW,MAAM,IAAI,KAAK,IAAoC;AACpE,WAAO,OAAO,WAAW,YAAY,QAAQ,KAAK,MAAM,IAAI,OAAO,MAAM,IAAI;AAAA,EAC/E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQO,IAAM,wBAAwB;AAa9B,SAAS,yBACd,SACA,OAA8D,CAAC,GACvC;AACxB,QAAM,OAAO,KAAK,QAAQ;AAC1B,QAAM,MAAM,KAAK,OAAO,KAAK;AAC7B,QAAM,OAAO,iBAAiB,OAAO;AACrC,SAAO,OAAO,SAAS,QAAQ,aAAa;AAC1C,UAAM,aAAa,MAAM,cAAc,MAAM,SAAS,IAAI,CAAC;AAC3D,QAAI,eAAe,KAAM,QAAO;AAChC,UAAM,OAAO,MAAM,KAAK,SAAS,QAAQ,QAAQ;AACjD,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,SAAS;AAAA,MACb,SAAS;AAAA,MACT,SAAS,QAAQ,YAAY;AAAA,MAC7B,QAAQ,KAAK,SAAS;AAAA,MACtB,IAAI,IAAI;AAAA,IACV;AACA,QAAI;AACF,YAAM,gBAAgB,MAAM,KAAK,UAAU,MAAM,GAAG,EAAE,MAAM,KAAO,SAAS,IAAM,CAAC;AAAA,IACrF,QAAQ;AAAA,IAER;AACA,WAAO;AAAA,EACT;AACF;AAGA,eAAe,cAAc,MAAc,SAAiB,KAAqC;AAC/F,MAAI;AACF,UAAM,MAAM,KAAK,MAAM,MAAM,SAAS,MAAM,MAAM,CAAC;AACnD,QACE,KAAK,YAAY,KACjB,IAAI,YAAY,QAAQ,YAAY,KACpC,OAAO,IAAI,WAAW,YACtB,CAAC,aAAa,KAAK,IAAI,MAAM,KAC7B,OAAO,IAAI,OAAO,YAClB,MAAM,IAAI,KAAK,KACf,MAAM,IAAI,KAAK,uBACf;AACA,aAAO;AAAA,IACT;AACA,WAAO,OAAO,IAAI,MAAM;AAAA,EAC1B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/router/decision.ts"],"sourcesContent":["import { z } from 'zod';\nimport { fetchFailureToCliError, httpRequest } from '../lib/http';\nimport type { HttpRequestOptions, HttpResult } from '../lib/http';\nimport type { CommandContext } from '../context';\nimport type { Packet } from './context';\n\n/**\n * `POST /api/x402-router`: ONE FREE DECISION PER LOOKUP.\n *\n * The routing decision costs nothing and nobody signs for it. The hook asks for\n * it from the user's own words, the backend answers with what it would do and\n * what the provider charges, and the only payment on the wire is the one\n * `runPay` makes to that provider. That deletes the router fee and everything\n * built to carry it: the 402 probe, the requirements cache, the stale-quote\n * retry, the settlement accounting and one Base settlement of about 1.5 s from\n * every paid lookup.\n *\n * NOTHING IS STORED LOCALLY. The bounded packet travels with the request and\n * the backend keeps it against the decision id until that id expires, which is\n * how `request({query})` reaches the same calibrated input with no session\n * file, no timestamp latch and no guess about which window this process serves.\n */\n\nexport const ROUTER_PATH = '/api/x402-router';\n\n/**\n * The request the server builds and this client sends verbatim. Query assembly,\n * body encoding and header choice are the server's; what stays here is every\n * check that decides whether to send it at all.\n */\nconst RequestSchema = z.object({\n url: z.string().min(1).max(16_384),\n method: z.enum(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']),\n headers: z.record(z.string(), z.string()),\n body: z\n .string()\n .max(256 * 1024)\n .optional(),\n});\n\nconst ContractSchema = z.object({\n /** Flat, for display and for the result check; never re-encoded into a call:\n * the server built `request` from them and this client sends that verbatim. */\n arguments: z.record(z.string(), z.unknown()).optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n request: RequestSchema,\n});\nexport type DecisionContract = z.infer<typeof ContractSchema>;\n\n/**\n * What stopped an outcome this client cannot execute, in terms the host can act\n * on: a stable reason code, the stage that stopped, the fields or scope choices\n * the user can supply, and one concrete next action.\n */\nconst DiagnosticsSchema = z.object({\n reasonCode: z.string().min(1).max(64),\n stage: z.string().min(1).max(32),\n missing: z.array(z.string().max(200)).max(60),\n nextAction: z.string().max(500),\n});\nexport type DecisionDiagnostics = z.infer<typeof DiagnosticsSchema>;\n\n/**\n * ONE VARIANT PER ANSWER, DISCRIMINATED ON THE ACTION. Optional fields made\n * every shape legal: an `execute` with no contract parsed and came back to the\n * host as a routine `needs_input`, a non-execute with no diagnostics parsed\n * with nothing to act on, and a hook answer carrying a contract parsed as\n * though the hook had quoted a price. Each of those is drift the shared\n * fixtures exist to catch, so each is now a parse failure that names itself.\n *\n * The two calls ask different questions and get different answers, so they get\n * different parsers. The HOOK asks whether a paid lookup is worth offering: an\n * id, or a reason it is not. The TOOL asks for the decision: the capability,\n * its price and the contract together, so a caller cannot approve one offer and\n * receive another.\n */\nconst IdSchema = z\n .string()\n .regex(/^[A-Za-z0-9_-]{8,64}$/)\n .describe(\n 'The turn id, an OPAQUE HANDLE: it is the one piece of server text this ' +\n 'client puts in a model-facing line, so the alphabet is pinned here ' +\n 'rather than escaped later.',\n );\n\n/** Every non-execute answer carries these, beside the action they explain. */\nconst RefusedSchema = z.strictObject({\n reason: z.string().max(2_000).optional(),\n diagnostics: DiagnosticsSchema,\n});\n\n/**\n * WHAT THE SERVICE IS, AND WHAT IT DOES. The hook answer used to be an id and\n * nothing else, so the line the host injected could only say \"a paid lookup is\n * available\", which a model follows 8 to 20 times in 40 where a line naming the\n * task and the service is followed 40 in 40. The gate knows which capability\n * serves the category it chose, so it now says so; the CONTRACT is still not\n * here, because the task the host will run does not exist yet.\n */\nconst CapabilityFields = {\n capabilityId: z.string().min(1).max(200),\n category: z.string().min(1).max(64),\n /** The service's own name, not the x402 reseller in front of it. */\n provider: z.string().min(1).max(120),\n capabilityDescription: z.string().min(1).max(500),\n /** What the provider charges, atomic USDC. The `request` tool refuses a live\n * 402 above it; `gateSpend` still caps the amount actually signed. */\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n};\n\n/**\n * STRUCTURE, NEVER WORDING. A hint lands in the model's context verbatim, so\n * its shape is checked the way the id's alphabet is: one line, no control\n * characters, and it has to be the call it claims to be, naming the id this\n * same answer carries. A hint that fails any of these is a protocol error and\n * the turn falls back to the generic line; nothing here rewrites a word of a\n * hint that passes. Both offering arms, `execute` and `discovered`, hold it.\n */\nfunction checkHint(decision: { id: string; hint: string }, ctx: z.RefinementCtx): void {\n if (/[\\p{Cc}\\p{Cf}]/u.test(decision.hint)) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint is one plain line' });\n }\n if (!decision.hint.includes('request({')) {\n ctx.addIssue({ code: 'custom', path: ['hint'], message: 'a hint names the call to make' });\n }\n if (!decision.hint.includes(decision.id)) {\n ctx.addIssue({\n code: 'custom',\n path: ['hint'],\n message: \"a hint carries this answer's own id\",\n });\n }\n}\n\n/**\n * A PAY-PER-CALL SERVICE NOBODY CURATED. When no capability in the catalog fits\n * but a listed x402 service could do the step, the server names that one\n * service: who sells it, where, for how much, and the input it takes. The\n * candidate is the seller's own listing, so every field is data for the host\n * to judge, never an instruction; the host builds the `input` and the tool\n * call pays through the same `runPay` path and caps as a curated lookup.\n */\nconst DiscoveredCandidateSchema = z.strictObject({\n source: z.string().min(1).max(64),\n provider: z.string().min(1).max(120),\n url: z.string().min(1).max(2_048),\n method: z.enum(['GET', 'POST']),\n description: z.string().max(500),\n providerPriceAtomic: z.string().regex(/^\\d+$/),\n network: z.string().min(1).max(64),\n payTo: z.string().min(1).max(200),\n input: z.strictObject({\n location: z.enum(['body', 'query']),\n schema: z.record(z.string(), z.unknown()),\n }),\n});\n\n/** The same answer on both calls: the hook's offer, and the tool's fallback\n * when a query with no id found no curated capability. */\nconst DiscoveredSchema = z\n .strictObject({\n action: z.literal('discovered'),\n id: IdSchema,\n candidate: DiscoveredCandidateSchema,\n /** THE LINE, FINISHED, as on `execute`: it carries the seller's\n * description and the input it takes. */\n hint: z.string().min(1).max(2_000),\n })\n .superRefine(checkHint);\n\nconst HookDecisionSchema = z.discriminatedUnion('action', [\n z\n .strictObject({\n action: z.literal('execute'),\n id: IdSchema,\n ...CapabilityFields,\n /** The x402 URL a lookup would pay, for the line the server writes. */\n endpoint: z.string().min(1).max(2_048),\n /** What to pass in `query`, in the service's own terms. */\n usage: z.string().min(1).max(300),\n /**\n * THE LINE, FINISHED. The server writes it with the real id in it and, on a\n * native call, the exact search or URL that was denied. The client injects\n * it and composes nothing, which is why there is no hint builder here any\n * more: two sides writing the same sentence is how they drift. The same\n * bound as a discovered line's.\n */\n hint: z.string().min(1).max(2_000),\n })\n .superRefine(checkHint),\n DiscoveredSchema,\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nconst ToolDecisionSchema = z.discriminatedUnion('action', [\n z.strictObject({\n action: z.literal('execute'),\n ...CapabilityFields,\n contract: ContractSchema,\n }),\n DiscoveredSchema,\n RefusedSchema.extend({ action: z.literal('native') }),\n RefusedSchema.extend({ action: z.literal('needs_input') }),\n]);\n\nfunction envelope<T extends z.ZodTypeAny>(decision: T) {\n return z.strictObject({\n schemaVersion: z.literal(1),\n routerVersion: z.string().min(1).max(64),\n decision,\n /** A plain sentence about the CALL, such as an id that had expired. Never a\n * failure: the decision beside it ran anyway. */\n note: z.string().max(500).optional(),\n jev: z.object({ calls: z.number(), latencyMs: z.number() }).optional(),\n });\n}\n\nconst HookResponseSchema = envelope(HookDecisionSchema);\nconst ToolResponseSchema = envelope(ToolDecisionSchema);\n\nexport type HookResponse = z.infer<typeof HookResponseSchema>;\nexport type ToolResponse = z.infer<typeof ToolResponseSchema>;\nexport type HookDecision = HookResponse['decision'];\nexport type ToolDecision = ToolResponse['decision'];\n\n/** Which call this is, and therefore which answer is legal for it. */\nexport type CallKind = 'hook' | 'tool';\n\n/**\n * What this client can act on beyond the curated answers, sent on both calls.\n * `discovered` is Tenjin's reviewed list of third-party services, on for every\n * build that parses it; the server answers that arm only to a request that\n * lists it, so an older build never sees one. `bazaar` widens it to the open\n * Bazaar and is sent only while `experimental.bazaar` is on.\n */\nexport const CLIENT_ACCEPTS: readonly string[] = ['discovered'];\nexport const BAZAAR_ACCEPT = 'bazaar';\n\n/** The `accepts` this build sends, with the open Bazaar or without it. */\nexport function acceptsFor(bazaar: boolean): string[] {\n return bazaar ? [...CLIENT_ACCEPTS, BAZAAR_ACCEPT] : [...CLIENT_ACCEPTS];\n}\n\n/**\n * The exact body the hook call sends, spelled once and pinned to the shared\n * fixtures. The route reads it with a strict object, so an extra field is a\n * 400, and a 400 is a turn with no hint.\n *\n * ONE BODY FOR BOTH HOOKS. Which hook is asking is not a field: the route reads\n * it from `packet.pendingCall`, which the native hook sets and the prompt hook\n * does not. A `source` beside the packet was the `/prepare` route's shape, and\n * that route is gone. `sessionId` is the harness's own session id, which the\n * server uses only so one session is not offered the same discovered service\n * twice.\n */\nexport function buildHookBody(\n packet: Packet,\n extras: { sessionId?: string; accepts?: readonly string[] } = {},\n): Record<string, unknown> {\n return {\n schemaVersion: 1,\n ...(extras.sessionId !== undefined ? { sessionId: extras.sessionId } : {}),\n ...(extras.accepts !== undefined ? { accepts: [...extras.accepts] } : {}),\n packet,\n };\n}\n\n/** The exact body the tool call sends. `id` is the turn whose packet decides\n * with this query; `gateHint` is evidence, never authority. `input` is the\n * host's own input for a discovered service, and stands in for `query`. */\nexport function buildToolBody(request: {\n query?: string;\n id?: string;\n input?: Record<string, unknown>;\n gateHint?: GateHint;\n accepts?: readonly string[];\n}): Record<string, unknown> {\n return {\n schemaVersion: 1,\n ...(request.query !== undefined ? { query: request.query } : {}),\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.input !== undefined ? { input: request.input } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n ...(request.accepts !== undefined ? { accepts: [...request.accepts] } : {}),\n };\n}\n\n/** The parsers, exposed so the shared wire fixtures are checked against the\n * same schemas production parses with rather than against a copy of them. */\nexport function parseForTests(kind: CallKind, value: unknown): { success: boolean } {\n const schema = kind === 'hook' ? HookResponseSchema : ToolResponseSchema;\n return { success: schema.safeParse(value).success };\n}\n\n/**\n * The gate's own reading of this turn, travelling as EVIDENCE for the lookup it\n * was produced for. The backend may refine or reject it, and it authorizes no\n * money: the local spend policy does that. Optional on both call forms.\n */\nexport interface GateHint {\n category: string;\n turnId: string;\n lookupId: string;\n}\n\nexport interface DecisionDeps {\n ctx: CommandContext;\n baseUrl: string;\n /** `experimental.bazaar`: add {@link BAZAAR_ACCEPT}, so a service from the\n * open Bazaar may come back. Off by default: curated and the Tenjin list. */\n acceptsBazaar?: boolean;\n fetchImpl?: typeof fetch;\n /** Overrides the per-call deadline; the hook passes its own, smaller one. */\n timeoutMs?: number;\n}\n\nexport type DecisionOutcome<T> =\n | { status: 'decided'; decision: T }\n /** Nothing was paid and nothing could be: the endpoint is free, so a failure\n * here costs the turn a routing answer and nothing else. */\n | { status: 'failed'; reason: string; errorCode?: string };\n\n/**\n * ONE FREE CALL, IN TWO FORMS. The hook sends `{ packet }`: the backend runs\n * the gate, and on `execute` stores that packet under an id. The tool sends\n * `{ query, id? }`: the backend makes THE decision from that query plus the\n * packet it stored, and answers with the contract to run. A discovered\n * service's id is sent with the host's own `{ input }` instead of a query.\n *\n * The tool never sends a packet of its own. The turn's context lives on the\n * backend against the id, and the query the model wrote is what the routing\n * corpus is calibrated against: 55 of 56 for query plus packet, 53 of 56 for\n * the raw prompt, measured on jev-1.13.0.\n */\nexport async function requestDecision(\n kind: 'hook',\n request: { packet: Packet; sessionId?: string },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse>>;\nexport async function requestDecision(\n kind: 'tool',\n request: { query?: string; id?: string; input?: Record<string, unknown>; gateHint?: GateHint },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<ToolResponse>>;\nexport async function requestDecision(\n kind: CallKind,\n request: {\n query?: string;\n packet?: Packet;\n sessionId?: string;\n id?: string;\n input?: Record<string, unknown>;\n gateHint?: GateHint;\n },\n deps: DecisionDeps,\n): Promise<DecisionOutcome<HookResponse | ToolResponse>> {\n const url = new URL(ROUTER_PATH, deps.baseUrl).toString();\n const options: HttpRequestOptions = {\n method: 'POST',\n timeoutMs: deps.timeoutMs ?? deps.ctx.flags.timeout,\n blockRedirects: true,\n jsonBody:\n kind === 'hook'\n ? buildHookBody(request.packet as Packet, {\n ...(request.sessionId !== undefined ? { sessionId: request.sessionId } : {}),\n accepts: acceptsFor(deps.acceptsBazaar === true),\n })\n : buildToolBody({\n ...(request.query !== undefined ? { query: request.query } : {}),\n ...(request.id !== undefined ? { id: request.id } : {}),\n ...(request.input !== undefined ? { input: request.input } : {}),\n ...(request.gateHint !== undefined ? { gateHint: request.gateHint } : {}),\n accepts: acceptsFor(deps.acceptsBazaar === true),\n }),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n };\n return readDecision(\n await httpRequest(url, options),\n kind === 'hook' ? HookResponseSchema : ToolResponseSchema,\n );\n}\n\nfunction readDecision<T extends z.ZodTypeAny>(\n response: HttpResult,\n schema: T,\n): DecisionOutcome<z.infer<T>> {\n // A transport failure says its own reason; nothing was paid either way,\n // because there is nothing to pay for on this route.\n if (!response.ok) return { status: 'failed', reason: fetchFailureToCliError(response).message };\n if (response.status < 200 || response.status >= 300) {\n const named = errorOf(response.json);\n return {\n status: 'failed',\n // The backend's own code and message, never a bare status line: a typed\n // refusal the host could act on was arriving as \"answered 400\".\n reason:\n named === null\n ? `The router endpoint answered ${response.status}.`\n : `The router endpoint answered ${response.status} (${named.code}): ${named.message}`,\n ...(named !== null ? { errorCode: named.code } : {}),\n };\n }\n const parsed = schema.safeParse(response.json);\n if (!parsed.success) {\n return { status: 'failed', reason: 'The router returned a decision this build cannot read.' };\n }\n return { status: 'decided', decision: parsed.data as z.infer<T> };\n}\n\n/** `{ error: { code, message } }`, the envelope every Tenjin route answers a\n * refusal with. Anything else reads as no code rather than as a guess. */\nfunction errorOf(body: unknown): { code: string; message: string } | null {\n if (body === null || typeof body !== 'object') return null;\n const error = (body as { error?: unknown }).error;\n if (error === null || typeof error !== 'object') return null;\n const { code, message } = error as { code?: unknown; message?: unknown };\n if (typeof code !== 'string' || code.length === 0 || code.length > 64) return null;\n const text = typeof message === 'string' ? message.slice(0, 500) : '';\n return { code, message: text };\n}\n"],"mappings":";;;;;;;;;;AAuBO,IAAM,cAAc;AAO3B,IAAM,gBAAgB,iBAAE,OAAO;AAAA,EAC7B,KAAK,iBAAE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