tenjin-cli 0.1.0-alpha.22 → 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.
- package/README.md +16 -13
- package/dist/{chunk-AG4DWNHO.js → chunk-3IOS6YG6.js} +2 -2
- package/dist/{chunk-3Q3UBMVB.js → chunk-6O6DFYF3.js} +2 -2
- package/dist/{chunk-UFCN7NCE.js → chunk-A2XMQSWI.js} +21 -11
- package/dist/chunk-A2XMQSWI.js.map +1 -0
- package/dist/{chunk-TU3IK7KK.js → chunk-HJYI52HM.js} +2 -2
- package/dist/{chunk-U5FFVIIF.js → chunk-HTC4VJFT.js} +6 -3
- package/dist/chunk-HTC4VJFT.js.map +1 -0
- package/dist/{chunk-UIOZRILX.js → chunk-I2GBBIDI.js} +2 -2
- package/dist/{chunk-DA53QKTD.js → chunk-K63HPLYT.js} +2 -2
- package/dist/{chunk-NZYVSZNF.js → chunk-N7A5EXJZ.js} +2 -2
- package/dist/{chunk-B4GA3HAK.js → chunk-RA2J3TWG.js} +2 -2
- package/dist/{chunk-B4GA3HAK.js.map → chunk-RA2J3TWG.js.map} +1 -1
- package/dist/{chunk-CYEUVU3F.js → chunk-Y3LKUXZA.js} +4 -4
- package/dist/{chunk-UAT3Q7VF.js → chunk-YT7A7DLY.js} +30 -17
- package/dist/{chunk-UAT3Q7VF.js.map → chunk-YT7A7DLY.js.map} +1 -1
- package/dist/{cli-5WM56Y7K.js → cli-MUYFTWWB.js} +17 -17
- package/dist/{config-JBF5BZNO.js → config-IIRRO3XC.js} +4 -4
- package/dist/{doctor-6KHBE77P.js → doctor-KGHM2CAC.js} +8 -8
- package/dist/{fund-GSFCXEF7.js → fund-DOWIT3JT.js} +3 -3
- package/dist/{hook-command-UQZ4DVDL.js → hook-command-RDT754KQ.js} +5 -5
- package/dist/index.js +2 -2
- package/dist/{install-TDYC22KI.js → install-BYQUMYBN.js} +6 -6
- package/dist/{install-identity-QS4UFF27.js → install-identity-KTQPYVAO.js} +4 -4
- package/dist/{mcp-JWOOSKLX.js → mcp-ZKOTURQN.js} +20 -8
- package/dist/{mcp-JWOOSKLX.js.map → mcp-ZKOTURQN.js.map} +1 -1
- package/dist/{pay-TDYQFSKY.js → pay-LZPU2HUT.js} +4 -4
- package/dist/{status-line-wiring-XKUVI5UW.js → status-line-wiring-7D2CSV3K.js} +4 -4
- package/dist/tenjin-daemon.mjs +1 -1
- package/dist/{uninstall-SJ6R2W2M.js → uninstall-VR44B4KD.js} +6 -6
- package/dist/{update-N2NZS3AA.js → update-SOYQLDBF.js} +3 -3
- package/docs/agent-permissions.md +1 -1
- package/package.json +1 -1
- package/dist/chunk-U5FFVIIF.js.map +0 -1
- package/dist/chunk-UFCN7NCE.js.map +0 -1
- /package/dist/{chunk-AG4DWNHO.js.map → chunk-3IOS6YG6.js.map} +0 -0
- /package/dist/{chunk-3Q3UBMVB.js.map → chunk-6O6DFYF3.js.map} +0 -0
- /package/dist/{chunk-TU3IK7KK.js.map → chunk-HJYI52HM.js.map} +0 -0
- /package/dist/{chunk-UIOZRILX.js.map → chunk-I2GBBIDI.js.map} +0 -0
- /package/dist/{chunk-DA53QKTD.js.map → chunk-K63HPLYT.js.map} +0 -0
- /package/dist/{chunk-NZYVSZNF.js.map → chunk-N7A5EXJZ.js.map} +0 -0
- /package/dist/{chunk-CYEUVU3F.js.map → chunk-Y3LKUXZA.js.map} +0 -0
- /package/dist/{cli-5WM56Y7K.js.map → cli-MUYFTWWB.js.map} +0 -0
- /package/dist/{config-JBF5BZNO.js.map → config-IIRRO3XC.js.map} +0 -0
- /package/dist/{doctor-6KHBE77P.js.map → doctor-KGHM2CAC.js.map} +0 -0
- /package/dist/{fund-GSFCXEF7.js.map → fund-DOWIT3JT.js.map} +0 -0
- /package/dist/{hook-command-UQZ4DVDL.js.map → hook-command-RDT754KQ.js.map} +0 -0
- /package/dist/{install-TDYC22KI.js.map → install-BYQUMYBN.js.map} +0 -0
- /package/dist/{install-identity-QS4UFF27.js.map → install-identity-KTQPYVAO.js.map} +0 -0
- /package/dist/{pay-TDYQFSKY.js.map → pay-LZPU2HUT.js.map} +0 -0
- /package/dist/{status-line-wiring-XKUVI5UW.js.map → status-line-wiring-7D2CSV3K.js.map} +0 -0
- /package/dist/{uninstall-SJ6R2W2M.js.map → uninstall-VR44B4KD.js.map} +0 -0
- /package/dist/{update-N2NZS3AA.js.map → update-SOYQLDBF.js.map} +0 -0
package/README.md
CHANGED
|
@@ -77,18 +77,21 @@ Each answer names the provider and the price. Your agent keeps its own tools, an
|
|
|
77
77
|
|
|
78
78
|
The router picks from a catalog we curate and maintain. When nothing in it fits, it can point your agent at a reviewed third-party pay-per-call service from the [Tenjin list](#tenjin-list-and-experimental-bazaar), and your agent decides whether to use it or to ask you first. Routing is free: you pay the provider's price and nothing else.
|
|
79
79
|
|
|
80
|
-
| Tool
|
|
81
|
-
|
|
|
82
|
-
| **Docs lookup** · [Context7](https://context7.com)
|
|
83
|
-
| **Web research** · [Exa](https://exa.ai)
|
|
84
|
-
| **Read a page** · [Firecrawl](https://firecrawl.dev)
|
|
85
|
-
| **Crypto prices** · [CoinMarketCap](https://coinmarketcap.com)
|
|
86
|
-
| **Compute** · [Wolfram Alpha](https://www.wolframalpha.com)
|
|
87
|
-
| **Email check** · [Hunter](https://hunter.io)
|
|
88
|
-
| **Person lookup** ·
|
|
89
|
-
| **Company profile** · [
|
|
90
|
-
|
|
91
|
-
|
|
80
|
+
| Tool | What your agent gets | Price per call |
|
|
81
|
+
| -------------------------------------------------------------- | ----------------------------------------------------------------------------------------- | -------------- |
|
|
82
|
+
| **Docs lookup** · [Context7](https://context7.com) | Current, version-specific docs for a library or API | **Free** |
|
|
83
|
+
| **Web research** · [Exa](https://exa.ai) | Search results with the page content, not just links | $0.007 |
|
|
84
|
+
| **Read a page** · [Firecrawl](https://firecrawl.dev) | One exact page as clean text, even when a plain fetch fails | $0.01 |
|
|
85
|
+
| **Crypto prices** · [CoinMarketCap](https://coinmarketcap.com) | Live quotes for any coin | $0.01 |
|
|
86
|
+
| **Compute** · [Wolfram Alpha](https://www.wolframalpha.com) | Math, unit conversions, science and data questions | $0.02 |
|
|
87
|
+
| **Email check** · [Hunter](https://hunter.io) | Whether an address is real and deliverable | $0.008 |
|
|
88
|
+
| **Person lookup** · [Apollo](https://www.apollo.io) | A professional profile and work email from a name and company, a LinkedIn URL or an email | $0.01 |
|
|
89
|
+
| **Company profile** · [Apollo](https://www.apollo.io) | Industry, headcount, revenue and funding from a domain | $0.01 |
|
|
90
|
+
| **Company match** · [CompanyEnrich](https://companyenrich.com) | The company behind a name or a social URL | $0.01225 |
|
|
91
|
+
| **X posts** · [glim](https://glim.sh) | Posts matching a search, or one post with its thread | $0.005 |
|
|
92
|
+
| **Reddit** · [glim](https://glim.sh) | Posts matching a search, or one thread with its comments | $0.01 / $0.005 |
|
|
93
|
+
|
|
94
|
+
Free tools run without a funded wallet. More are added by demand: [tell us what you want](#request-a-tool).
|
|
92
95
|
|
|
93
96
|
### Tenjin list and experimental Bazaar
|
|
94
97
|
|
|
@@ -164,7 +167,7 @@ tenjin uninstall # remove the Claude Code setup; your wallet stays
|
|
|
164
167
|
|
|
165
168
|
Use `tenjin install --project` to set it up for a single project. Add `--json` to any command for machine-readable output.
|
|
166
169
|
|
|
167
|
-
Every paid lookup is recorded on your machine in `~/.tenjin/paid/ledger.jsonl`: what was sent (masked), who was paid, how much, the settlement transaction, and any files saved. Files a paid lookup returns, and media files a paid third-party service links to, are saved under `~/.tenjin/downloads/`. When a seller never confirmed settlement, `tenjin payments reconcile` asks USDC on Base whether the payment was used once it has expired, and one that was never charged goes back to today's limit; the `request` tool does the same for up to three beside each lookup, without waiting for it.
|
|
170
|
+
Every paid lookup is recorded on your machine in `~/.tenjin/paid/ledger.jsonl`: what was sent (masked), who was paid, how much, the settlement transaction, and any files saved. Files a paid lookup returns, and media files a paid third-party service links to, are saved under `~/.tenjin/downloads/`. When a tool names the fields it returns, your agent gets those fields and the provider's whole response is saved under `~/.tenjin/results/` for a day, at the path the result names. When a seller never confirmed settlement, `tenjin payments reconcile` asks USDC on Base whether the payment was used once it has expired, and one that was never charged goes back to today's limit; the `request` tool does the same for up to three beside each lookup, without waiting for it.
|
|
168
171
|
|
|
169
172
|
<details>
|
|
170
173
|
<summary>Status line: keeping your own</summary>
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-SAN5PFTL.js";
|
|
5
5
|
import {
|
|
6
6
|
package_default
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-RA2J3TWG.js";
|
|
8
8
|
import {
|
|
9
9
|
CliError
|
|
10
10
|
} from "./chunk-JLEF5WHM.js";
|
|
@@ -288,4 +288,4 @@ export {
|
|
|
288
288
|
httpRequest,
|
|
289
289
|
fetchFailureToCliError
|
|
290
290
|
};
|
|
291
|
-
//# sourceMappingURL=chunk-
|
|
291
|
+
//# sourceMappingURL=chunk-3IOS6YG6.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
package_default
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RA2J3TWG.js";
|
|
5
5
|
import {
|
|
6
6
|
CliError,
|
|
7
7
|
HARNESSES,
|
|
@@ -1781,4 +1781,4 @@ export {
|
|
|
1781
1781
|
registeredHooks,
|
|
1782
1782
|
writeHooks
|
|
1783
1783
|
};
|
|
1784
|
-
//# sourceMappingURL=chunk-
|
|
1784
|
+
//# sourceMappingURL=chunk-6O6DFYF3.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
OfferSpecSchema
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HTC4VJFT.js";
|
|
5
5
|
import {
|
|
6
6
|
external_exports
|
|
7
7
|
} from "./chunk-SAN5PFTL.js";
|
|
@@ -16,9 +16,10 @@ import { constants } from "node:fs";
|
|
|
16
16
|
import { lstat, open, opendir, rm } from "node:fs/promises";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
var SPECS_DIR = join("progress", "specs");
|
|
19
|
+
var RESULTS_DIR = "results";
|
|
19
20
|
var MAX_SPEC_BYTES = 128 * 1024;
|
|
20
|
-
var MAX_SPECS = 512;
|
|
21
21
|
var SPEC_TTL_MS = 15 * 6e4;
|
|
22
|
+
var RESULT_TTL_MS = 24 * 60 * 6e4;
|
|
22
23
|
var digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
23
24
|
function specPath(dataDir, id) {
|
|
24
25
|
return join(dataDir, SPECS_DIR, `${digest(id)}.json`);
|
|
@@ -34,7 +35,7 @@ async function storeSpecs(dataDir, specs) {
|
|
|
34
35
|
} catch {
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
|
-
await
|
|
38
|
+
await prune(join(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());
|
|
38
39
|
}
|
|
39
40
|
async function readSpec(dataDir, id) {
|
|
40
41
|
const path = specPath(dataDir, id);
|
|
@@ -104,16 +105,24 @@ async function settleSpecPayment(dataDir, id, left, now = Date.now()) {
|
|
|
104
105
|
() => void 0
|
|
105
106
|
);
|
|
106
107
|
}
|
|
107
|
-
async function
|
|
108
|
+
async function storeFullResult(dataDir, id, body) {
|
|
109
|
+
const path = join(dataDir, RESULTS_DIR, `${digest(id)}.json`);
|
|
108
110
|
try {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
await writeFileAtomic(path, body, { mode: 384, dirMode: 448 });
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
void prune(join(dataDir, RESULTS_DIR), RESULT_TTL_MS, Date.now());
|
|
116
|
+
return path;
|
|
117
|
+
}
|
|
118
|
+
async function prune(dir, ttlMs, now) {
|
|
119
|
+
try {
|
|
120
|
+
const directory = await opendir(dir);
|
|
111
121
|
for await (const entry of directory) {
|
|
112
|
-
if (++count > MAX_SPECS) return;
|
|
113
122
|
if (!entry.isFile()) continue;
|
|
114
|
-
const path = join(
|
|
123
|
+
const path = join(dir, entry.name);
|
|
115
124
|
const stat = await lstat(path).catch(() => void 0);
|
|
116
|
-
if (stat === void 0 || now - stat.mtimeMs >
|
|
125
|
+
if (stat === void 0 || now - stat.mtimeMs > ttlMs) {
|
|
117
126
|
await rm(path, { force: true }).catch(() => void 0);
|
|
118
127
|
}
|
|
119
128
|
}
|
|
@@ -125,6 +134,7 @@ export {
|
|
|
125
134
|
storeSpecs,
|
|
126
135
|
readSpec,
|
|
127
136
|
claimSpecPayment,
|
|
128
|
-
settleSpecPayment
|
|
137
|
+
settleSpecPayment,
|
|
138
|
+
storeFullResult
|
|
129
139
|
};
|
|
130
|
-
//# sourceMappingURL=chunk-
|
|
140
|
+
//# sourceMappingURL=chunk-A2XMQSWI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/specs.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { constants } from 'node:fs';\nimport { lstat, open, opendir, rm } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { z } from 'zod';\nimport { writeFileAtomic, writeFileAtomicExclusive } from '../lib/atomic-json';\nimport { OfferSpecSchema, type OfferSpec } from './decision';\n\n/**\n * THE REQUEST SPECS AN OFFER CARRIED, kept on this machine by the offer's id. The\n * hook that shows a line stores the spec of every service the line names; the\n * `request` tool, which runs in the MCP server's own process and never sees\n * the hook, reads one back by the id the agent passes. One file per id, named\n * by the id's SHA-256, so a read is one open and needs no session.\n *\n * Best effort on the write, like every record the hooks keep: with no spec\n * stored, `request({id})` says none is kept and asks for the query its line\n * named. A spec is the server's own answer, re-parsed on the way back in, and\n * it lives as long as the server keeps the offer's id.\n */\n\nconst SPECS_DIR = join('progress', 'specs');\nconst RESULTS_DIR = 'results';\n/** A spec holds a service's whole input schema; far larger than any record. */\nconst MAX_SPEC_BYTES = 128 * 1024;\n/** The server's decision expiry: past it, the id's outcome report and an\n * `{id, query}` fallback find no row. */\nexport const SPEC_TTL_MS = 15 * 60_000;\n/** A saved result outlives its offer: the agent opens it later in the session,\n * or in the next step of a chain. A day covers a working session. */\nexport const RESULT_TTL_MS = 24 * 60 * 60_000;\n\nconst digest = (value: string): string => createHash('sha256').update(value).digest('hex');\n\nfunction specPath(dataDir: string, id: string): string {\n return join(dataDir, SPECS_DIR, `${digest(id)}.json`);\n}\n\n/**\n * Store each spec under its id, and drop expired ones. Never throws. Ages are\n * file mtimes, so they are read against the real clock, never a caller's.\n */\nexport async function storeSpecs(\n dataDir: string,\n specs: readonly OfferSpec[] | undefined,\n): Promise<void> {\n if (specs === undefined || specs.length === 0) return;\n for (const spec of specs) {\n try {\n await writeFileAtomic(specPath(dataDir, spec.id), JSON.stringify(spec), {\n mode: 0o600,\n dirMode: 0o700,\n });\n } catch {\n // The tool falls back to the server for this id.\n }\n }\n await prune(join(dataDir, SPECS_DIR), SPEC_TTL_MS, Date.now());\n}\n\n/** The spec stored for this id, or null: none, expired, damaged or not ours. */\nexport async function readSpec(dataDir: string, id: string): Promise<OfferSpec | null> {\n const path = specPath(dataDir, id);\n // O_NOFOLLOW: the directory is the user's, and a planted symlink must not\n // turn this read into a read of something else.\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return null;\n try {\n const stat = await file.stat();\n if (Date.now() - stat.mtimeMs > SPEC_TTL_MS || stat.size > MAX_SPEC_BYTES) return null;\n const parsed = OfferSpecSchema.safeParse(JSON.parse(await file.readFile('utf8')));\n return parsed.success && parsed.data.id === id ? parsed.data : null;\n } catch {\n return null;\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n\n/**\n * What an earlier call with a spec's id left. `paid`: money left for it.\n * `possibly_paid`: a payment was signed and may have left, but the call ended\n * without saying how much (a spend ledger that could not be written, say).\n * `running`: a call claimed it and has not ended, or its process died, so it\n * may have paid. `unrecorded`: this call could not record its claim.\n */\nexport type EarlierPayment =\n | { state: 'paid'; at: string; amountAtomic: string; txHash?: string }\n | { state: 'possibly_paid'; at: string }\n | { state: 'running'; at?: string }\n | { state: 'unrecorded' };\n\nconst PaymentSchema = z.discriminatedUnion('state', [\n z.strictObject({\n state: z.literal('paid'),\n at: z.string().max(40),\n amountAtomic: z.string().regex(/^\\d+$/),\n txHash: z.string().max(100).optional(),\n }),\n z.strictObject({ state: z.literal('possibly_paid'), at: z.string().max(40) }),\n z.strictObject({ state: z.literal('running'), at: z.string().max(40) }),\n]);\n\nfunction paymentPath(dataDir: string, id: string): string {\n return join(dataDir, SPECS_DIR, `${digest(id)}.paid.json`);\n}\n\n/**\n * CLAIM THE ONE PAYMENT A SPEC ALLOWS, before anything is signed: an exclusive\n * create beside the spec, so a retry or a second call with the same id cannot\n * pay again. Null when the claim is this call's; otherwise what an earlier call\n * left, and this one pays nothing. A claim that cannot be written refuses too:\n * the record is the only proof a payment has not already left.\n */\nexport async function claimSpecPayment(\n dataDir: string,\n id: string,\n now: number = Date.now(),\n): Promise<EarlierPayment | null> {\n const path = paymentPath(dataDir, id);\n try {\n await writeFileAtomicExclusive(\n path,\n JSON.stringify({ state: 'running', at: new Date(now).toISOString() }),\n { mode: 0o600, dirMode: 0o700 },\n );\n return null;\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'EEXIST') return { state: 'unrecorded' };\n }\n const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW).catch(() => undefined);\n if (file === undefined) return { state: 'running' };\n try {\n const parsed = PaymentSchema.safeParse(JSON.parse(await file.readFile('utf8')));\n return parsed.success ? parsed.data : { state: 'running' };\n } catch {\n return { state: 'running' };\n } finally {\n await file.close().catch(() => undefined);\n }\n}\n\n/**\n * How the claimed call ended. Money that left is recorded against the id. The\n * claim is dropped ONLY when nothing was signed, so a fixed input can still\n * run: a signed payment whose amount the call never learned (it failed after\n * the authorization left) stays claimed as possibly paid, and the id never\n * signs again. A record that cannot be written leaves the claim standing,\n * which refuses too.\n */\nexport async function settleSpecPayment(\n dataDir: string,\n id: string,\n left: { amountAtomic: bigint; txHash?: string; signed: boolean },\n now: number = Date.now(),\n): Promise<void> {\n const path = paymentPath(dataDir, id);\n if (!left.signed && left.amountAtomic === 0n) {\n await rm(path, { force: true }).catch(() => undefined);\n return;\n }\n const at = new Date(now).toISOString();\n const record =\n left.amountAtomic > 0n\n ? {\n state: 'paid',\n at,\n amountAtomic: left.amountAtomic.toString(),\n ...(left.txHash !== undefined ? { txHash: left.txHash } : {}),\n }\n : { state: 'possibly_paid', at };\n await writeFileAtomic(path, JSON.stringify(record), { mode: 0o600, dirMode: 0o700 }).catch(\n () => undefined,\n );\n}\n\n/**\n * THE WHOLE BODY A SPEC'S CALL RETURNED, kept by the offer's id while the\n * agent is handed only the fields the spec promises, so nothing it paid for is\n * out of reach. The caller passes only a body it could project, which is\n * bounded by the result cap. The path, or null when it could not be written,\n * and the caller then hands back the whole body instead. Never throws.\n */\nexport async function storeFullResult(\n dataDir: string,\n id: string,\n body: string,\n): Promise<string | null> {\n const path = join(dataDir, RESULTS_DIR, `${digest(id)}.json`);\n try {\n await writeFileAtomic(path, body, { mode: 0o600, dirMode: 0o700 });\n } catch {\n return null;\n }\n // Housekeeping never holds up a paid result: the prune runs after the path\n // is handed back, and it swallows its own errors.\n void prune(join(dataDir, RESULTS_DIR), RESULT_TTL_MS, Date.now());\n return path;\n}\n\nasync function prune(dir: string, ttlMs: number, now: number): Promise<void> {\n try {\n // Every entry: a directory with many files is the one that most needs its\n // expired files gone.\n const directory = await opendir(dir);\n for await (const entry of directory) {\n if (!entry.isFile()) continue;\n const path = join(dir, entry.name);\n const stat = await lstat(path).catch(() => undefined);\n if (stat === undefined || now - stat.mtimeMs > ttlMs) {\n await rm(path, { force: true }).catch(() => undefined);\n }\n }\n } catch {\n // Housekeeping only.\n }\n}\n"],"mappings":";;;;;;;;;;;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;AAC3E,MAAI;AAGF,UAAM,YAAY,MAAM,QAAQ,GAAG;AACnC,qBAAiB,SAAS,WAAW;AACnC,UAAI,CAAC,MAAM,OAAO,EAAG;AACrB,YAAM,OAAO,KAAK,KAAK,MAAM,IAAI;AACjC,YAAM,OAAO,MAAM,MAAM,IAAI,EAAE,MAAM,MAAM,MAAS;AACpD,UAAI,SAAS,UAAa,MAAM,KAAK,UAAU,OAAO;AACpD,cAAM,GAAG,MAAM,EAAE,OAAO,KAAK,CAAC,EAAE,MAAM,MAAM,MAAS;AAAA,MACvD;AAAA,IACF;AAAA,EACF,QAAQ;AAAA,EAER;AACF;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
inspectHooksFile
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6O6DFYF3.js";
|
|
5
5
|
import {
|
|
6
6
|
CliError,
|
|
7
7
|
writeFileAtomic
|
|
@@ -169,4 +169,4 @@ export {
|
|
|
169
169
|
removeStatusLine,
|
|
170
170
|
inspectStatusLine
|
|
171
171
|
};
|
|
172
|
-
//# sourceMappingURL=chunk-
|
|
172
|
+
//# sourceMappingURL=chunk-HJYI52HM.js.map
|
|
@@ -2,7 +2,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
2
2
|
import {
|
|
3
3
|
fetchFailureToCliError,
|
|
4
4
|
httpRequest
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3IOS6YG6.js";
|
|
6
6
|
import {
|
|
7
7
|
external_exports
|
|
8
8
|
} from "./chunk-SAN5PFTL.js";
|
|
@@ -95,7 +95,10 @@ var ToolSpecSchema = external_exports.strictObject({
|
|
|
95
95
|
example: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
96
96
|
returns: external_exports.string().min(1).max(200).optional(),
|
|
97
97
|
returnsExample: external_exports.unknown().optional(),
|
|
98
|
-
resultSchema: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
98
|
+
resultSchema: external_exports.record(external_exports.string(), external_exports.unknown()).optional(),
|
|
99
|
+
/** The fields the result promises (type, properties, items, required). The
|
|
100
|
+
* agent is handed only these; the whole body is saved to a file. */
|
|
101
|
+
outputSchema: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
99
102
|
});
|
|
100
103
|
var OfferSpecSchema = ToolSpecSchema.extend({ id: IdSchema });
|
|
101
104
|
var SpecsSchema = external_exports.array(OfferSpecSchema).min(1).max(4).optional();
|
|
@@ -272,4 +275,4 @@ export {
|
|
|
272
275
|
requestDecision,
|
|
273
276
|
reportSpecOutcome
|
|
274
277
|
};
|
|
275
|
-
//# sourceMappingURL=chunk-
|
|
278
|
+
//# sourceMappingURL=chunk-HTC4VJFT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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/**\n * A REQUEST SPEC: the offered service's real contract, sent beside the line only\n * because this build asks for it (`accepts: [\"spec\"]`). The hook stores it by\n * the offer's id; `request({id})` shows it and `request({id, input})` fills its\n * request and pays the provider directly, with no second decision. Every field\n * is the server's, and so is checked like the rest of the answer: the payee and\n * price still meet the live 402 and the spend policy in `runPay`.\n */\nexport const ToolSpecSchema = z.strictObject({\n capabilityId: z.string().min(1).max(200),\n provider: z.string().min(1).max(120),\n description: z.string().min(1).max(500),\n priceAtomic: z.string().regex(/^\\d+$/),\n priceVaries: z.boolean(),\n maxAmountAtomic: z.string().regex(/^\\d+$/),\n payTo: z.string().min(1).max(200),\n network: z.string().min(1).max(64),\n asset: z.string().min(1).max(200),\n request: z.strictObject({\n method: z.enum(['GET', 'POST']),\n url: z.string().min(1).max(2_048),\n fields: z.record(z.string(), z.enum(['path', 'query', 'body'])),\n location: z.enum(['query', 'body']),\n }),\n input: z.record(z.string(), z.unknown()),\n pinned: z.record(z.string(), z.unknown()),\n example: z.record(z.string(), z.unknown()).optional(),\n returns: z.string().min(1).max(200).optional(),\n returnsExample: z.unknown().optional(),\n resultSchema: z.record(z.string(), z.unknown()).optional(),\n /** The fields the result promises (type, properties, items, required). The\n * agent is handed only these; the whole body is saved to a file. */\n outputSchema: z.record(z.string(), z.unknown()).optional(),\n});\nexport type ToolSpec = z.infer<typeof ToolSpecSchema>;\n\nexport const OfferSpecSchema = ToolSpecSchema.extend({ id: IdSchema });\nexport type OfferSpec = z.infer<typeof OfferSpecSchema>;\n\n/** One spec per service the line names: the offer and any alternative. */\nconst SpecsSchema = z.array(OfferSpecSchema).min(1).max(4).optional();\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 specs: SpecsSchema,\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 specs: SpecsSchema,\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 /**\n * A query with no id, answered with the spec of the service the server\n * picked under a fresh `id`: kept like a hook's. `input` is there only when\n * the query, as written, was a valid value for the spec's query field (a\n * free-text field, or one whose format or pattern it satisfies), and the\n * tool then runs it in the same call, checked again like any input.\n * Otherwise the agent fills the skeleton. `hint` is the line, with the skeleton of the call:\n * `request({id, input: {...}})` with the required fields, or the bound one.\n */\n z\n .strictObject({\n action: z.literal('spec'),\n id: IdSchema,\n spec: ToolSpecSchema,\n hint: z.string().min(1).max(2_000),\n input: z.record(z.string(), z.unknown()).optional(),\n })\n .superRefine(checkHint),\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. `spec` asks for each offered\n * service's request spec beside its line, and for the picked service's spec in\n * place of a decision on a query with no id, which only a build that parses\n * them can take: the decision schemas are strict. `bazaar` widens discovery\n * to the open Bazaar and is sent only while `experimental.bazaar` is on.\n */\nexport const CLIENT_ACCEPTS: readonly string[] = ['discovered', 'spec'];\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\n/** How a call run from a request spec ended, for the server's offer-to-call\n * count. No text: the id, the outcome, the provider's status and the time. */\nexport interface SpecOutcome {\n id: string;\n status: 'fulfilled' | 'unverified' | 'failed' | 'needs_approval';\n httpStatus?: number;\n ms?: number;\n}\n\n/** The outcome report's own deadline: it is telemetry and never holds a result. */\nexport const OUTCOME_TIMEOUT_MS = 3_000;\n\n/**\n * TELL THE SERVER A SPEC WAS USED. The client called and paid the provider\n * itself, so this is the only word the server gets that its offer was taken.\n * Never throws and never waits on anything the caller needs: a lost report\n * costs one count.\n */\nexport async function reportSpecOutcome(\n outcome: SpecOutcome,\n deps: Pick<DecisionDeps, 'ctx' | 'baseUrl' | 'fetchImpl'>,\n): Promise<void> {\n try {\n await httpRequest(new URL(ROUTER_PATH, deps.baseUrl).toString(), {\n method: 'POST',\n timeoutMs: OUTCOME_TIMEOUT_MS,\n blockRedirects: true,\n jsonBody: buildOutcomeBody(outcome),\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n });\n } catch {\n // Telemetry only.\n }\n}\n\n/** The exact body of an outcome report, pinned to the shared fixtures. */\nexport function buildOutcomeBody(outcome: SpecOutcome): Record<string, unknown> {\n return {\n schemaVersion: 1,\n id: outcome.id,\n status: outcome.status,\n ...(outcome.httpStatus !== undefined ? { httpStatus: outcome.httpStatus } : {}),\n ...(outcome.ms !== undefined ? { ms: Math.max(0, Math.round(outcome.ms)) } : {}),\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,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,KAAM;AAAA,EACjC,QAAQ,iBAAE,KAAK,CAAC,OAAO,QAAQ,OAAO,SAAS,UAAU,QAAQ,SAAS,CAAC;AAAA,EAC3E,SAAS,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,OAAO,CAAC;AAAA,EACxC,MAAM,iBACH,OAAO,EACP,IAAI,MAAM,IAAI,EACd,SAAS;AACd,CAAC;AAED,IAAM,iBAAiB,iBAAE,OAAO;AAAA;AAAA;AAAA,EAG9B,WAAW,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACtD,cAAc,iBAAE,OAAO,iBAAE,OAAO,GAAG,iBAAE,QAAQ,CAAC,EAAE,SAAS;AAAA,EACzD,SAAS;AACX,CAAC;AAQD,IAAM,oB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AAC,OAAO,SAAS;AACnB,WAAO,EAAE,QAAQ,UAAU,QAAQ,yDAAyD;AAAA,EAC9F;AACA,SAAO,EAAE,QAAQ,WAAW,UAAU,OAAO,KAAmB;AAClE;AAIA,SAAS,QAAQ,MAAyD;AACxE,MAAI,SAAS,QAAQ,OAAO,SAAS,SAAU,QAAO;AACtD,QAAM,QAAS,KAA6B;AAC5C,MAAI,UAAU,QAAQ,OAAO,UAAU,SAAU,QAAO;AACxD,QAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,MAAI,OAAO,SAAS,YAAY,KAAK,WAAW,KAAK,KAAK,SAAS,GAAI,QAAO;AAC9E,QAAM,OAAO,OAAO,YAAY,WAAW,QAAQ,MAAM,GAAG,GAAG,IAAI;AACnE,SAAO,EAAE,MAAM,SAAS,KAAK;AAC/B;","names":[]}
|
|
@@ -56,7 +56,7 @@ import {
|
|
|
56
56
|
registeredHooks,
|
|
57
57
|
retractModeGatedRules,
|
|
58
58
|
wireFreeVerbAllowlist
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-6O6DFYF3.js";
|
|
60
60
|
import {
|
|
61
61
|
CliError,
|
|
62
62
|
writeFileAtomic
|
|
@@ -923,4 +923,4 @@ export {
|
|
|
923
923
|
persistInstallHarness,
|
|
924
924
|
persistGrantDeclined
|
|
925
925
|
};
|
|
926
|
-
//# sourceMappingURL=chunk-
|
|
926
|
+
//# sourceMappingURL=chunk-I2GBBIDI.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
3
|
setTenjinIdentity
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3IOS6YG6.js";
|
|
5
5
|
import {
|
|
6
6
|
hasCode
|
|
7
7
|
} from "./chunk-2I4QTOLB.js";
|
|
@@ -109,4 +109,4 @@ export {
|
|
|
109
109
|
enableCliIdentity,
|
|
110
110
|
enableDaemonIdentity
|
|
111
111
|
};
|
|
112
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-K63HPLYT.js.map
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "./chunk-SAN5PFTL.js";
|
|
9
9
|
import {
|
|
10
10
|
package_default
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-RA2J3TWG.js";
|
|
12
12
|
import {
|
|
13
13
|
writeFileAtomic
|
|
14
14
|
} from "./chunk-JLEF5WHM.js";
|
|
@@ -191,4 +191,4 @@ export {
|
|
|
191
191
|
fetchDistTags,
|
|
192
192
|
isNewer
|
|
193
193
|
};
|
|
194
|
-
//# sourceMappingURL=chunk-
|
|
194
|
+
//# sourceMappingURL=chunk-N7A5EXJZ.js.map
|
|
@@ -3,7 +3,7 @@ import { createRequire as __tenjinCreateRequire } from 'node:module'; const requ
|
|
|
3
3
|
// package.json
|
|
4
4
|
var package_default = {
|
|
5
5
|
name: "tenjin-cli",
|
|
6
|
-
version: "0.1.0-alpha.
|
|
6
|
+
version: "0.1.0-alpha.23",
|
|
7
7
|
mcpName: "blog.tenjin/tenjin",
|
|
8
8
|
type: "module",
|
|
9
9
|
description: "x402 router for coding agents: one paid decision per lookup, a local wallet that pays each provider per call in USDC on Base.",
|
|
@@ -80,4 +80,4 @@ var package_default = {
|
|
|
80
80
|
export {
|
|
81
81
|
package_default
|
|
82
82
|
};
|
|
83
|
-
//# sourceMappingURL=chunk-
|
|
83
|
+
//# sourceMappingURL=chunk-RA2J3TWG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.
|
|
1
|
+
{"version":3,"sources":["../package.json"],"sourcesContent":["{\n \"name\": \"tenjin-cli\",\n \"version\": \"0.1.0-alpha.23\",\n \"mcpName\": \"blog.tenjin/tenjin\",\n \"type\": \"module\",\n \"description\": \"x402 router for coding agents: one paid decision per lookup, a local wallet that pays each provider per call in USDC on Base.\",\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\": \">=24\"\n },\n \"files\": [\n \"dist\",\n \"docs\",\n \"NOTICE.md\"\n ],\n \"packageManager\": \"pnpm@11.11.0\",\n \"scripts\": {\n \"build\": \"rm -rf dist && 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 \"githooks\": \"git config core.hooksPath .githooks\"\n },\n \"devDependencies\": {\n \"@changesets/cli\": \"^2.31.1\",\n \"@clack/prompts\": \"^1.7.0\",\n \"@eslint/js\": \"^10\",\n \"@modelcontextprotocol/sdk\": \"1.29.0\",\n \"@types/node\": \"^25\",\n \"@x402/core\": \"2.17.0\",\n \"@x402/evm\": \"2.17.0\",\n \"@x402/extensions\": \"2.17.0\",\n \"ajv\": \"^8.20.0\",\n \"ajv-formats\": \"^3.0.1\",\n \"commander\": \"^14.0.1\",\n \"eslint\": \"^10\",\n \"eslint-config-prettier\": \"^10\",\n \"ox\": \"0.14.30\",\n \"prettier\": \"^3\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"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;AAAA,IACR,QAAU;AAAA,IACV,KAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
readSkillFile,
|
|
14
14
|
skillFrontmatterName,
|
|
15
15
|
skillsDirsFor
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-I2GBBIDI.js";
|
|
17
17
|
import {
|
|
18
18
|
hasCode
|
|
19
19
|
} from "./chunk-2I4QTOLB.js";
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
} from "./chunk-SAN5PFTL.js";
|
|
29
29
|
import {
|
|
30
30
|
ensureStatusLine
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-HJYI52HM.js";
|
|
32
32
|
import {
|
|
33
33
|
appendAllowlistRules,
|
|
34
34
|
claudeAdapter,
|
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
inspectHooksFile,
|
|
37
37
|
ownsHookEntry,
|
|
38
38
|
writeHooks
|
|
39
|
-
} from "./chunk-
|
|
39
|
+
} from "./chunk-6O6DFYF3.js";
|
|
40
40
|
import {
|
|
41
41
|
CliError
|
|
42
42
|
} from "./chunk-JLEF5WHM.js";
|
|
@@ -448,4 +448,4 @@ export {
|
|
|
448
448
|
readMcpEntry,
|
|
449
449
|
statusLineProblems
|
|
450
450
|
};
|
|
451
|
-
//# sourceMappingURL=chunk-
|
|
451
|
+
//# sourceMappingURL=chunk-Y3LKUXZA.js.map
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
import {
|
|
49
49
|
fetchFailureToCliError,
|
|
50
50
|
httpRequest
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-3IOS6YG6.js";
|
|
52
52
|
import {
|
|
53
53
|
resolveContextSettings
|
|
54
54
|
} from "./chunk-UHEMZEGW.js";
|
|
@@ -8586,7 +8586,7 @@ var import_ajv_formats = __toESM(require_dist(), 1);
|
|
|
8586
8586
|
import { createHash } from "node:crypto";
|
|
8587
8587
|
var MAX_SCHEMA_BYTES = 96 * 1024;
|
|
8588
8588
|
var MAX_VALUE_BYTES = 64 * 1024;
|
|
8589
|
-
var MAX_BODY_BYTES =
|
|
8589
|
+
var MAX_BODY_BYTES = 4 * 1024 * 1024;
|
|
8590
8590
|
var MAX_DEPTH = 24;
|
|
8591
8591
|
var VALIDATOR_CACHE_LIMIT = 128;
|
|
8592
8592
|
var DRAFT_07 = "http://json-schema.org/draft-07/schema#";
|
|
@@ -8622,11 +8622,11 @@ function walk(value, schemaMode, depth = 0) {
|
|
|
8622
8622
|
}
|
|
8623
8623
|
}
|
|
8624
8624
|
var validators = /* @__PURE__ */ new Map();
|
|
8625
|
-
function compile(schema, { allErrors = false, ignoreUnknown = false } = {}) {
|
|
8625
|
+
function compile(schema, { allErrors = false, ignoreUnknown = false, project = false } = {}) {
|
|
8626
8626
|
if (Buffer.byteLength(stable(schema)) > MAX_SCHEMA_BYTES) {
|
|
8627
8627
|
throw new Error("Schema exceeds its size limit.");
|
|
8628
8628
|
}
|
|
8629
|
-
const key = `${canonicalHash(schema)}${allErrors ? ":all" : ""}${ignoreUnknown ? ":lenient" : ""}`;
|
|
8629
|
+
const key = `${canonicalHash(schema)}${allErrors ? ":all" : ""}${ignoreUnknown ? ":lenient" : ""}${project ? ":project" : ""}`;
|
|
8630
8630
|
const cached = validators.get(key);
|
|
8631
8631
|
if (cached !== void 0) return cached;
|
|
8632
8632
|
walk(schema, true);
|
|
@@ -8640,7 +8640,7 @@ function compile(schema, { allErrors = false, ignoreUnknown = false } = {}) {
|
|
|
8640
8640
|
validateFormats: true,
|
|
8641
8641
|
coerceTypes: false,
|
|
8642
8642
|
useDefaults: false,
|
|
8643
|
-
removeAdditional: false,
|
|
8643
|
+
removeAdditional: project ? "all" : false,
|
|
8644
8644
|
allowUnionTypes: true
|
|
8645
8645
|
};
|
|
8646
8646
|
const ajv = schema.$schema === DRAFT_07 ? new import_ajv.default(options) : new import__.default(options);
|
|
@@ -8653,16 +8653,11 @@ function compile(schema, { allErrors = false, ignoreUnknown = false } = {}) {
|
|
|
8653
8653
|
validators.set(key, compiled);
|
|
8654
8654
|
return compiled;
|
|
8655
8655
|
}
|
|
8656
|
-
function
|
|
8656
|
+
function checkValue(schema, value) {
|
|
8657
8657
|
try {
|
|
8658
8658
|
if (schema === null || typeof schema !== "object" || Array.isArray(schema)) {
|
|
8659
8659
|
throw new Error("A schema must be a JSON Schema object.");
|
|
8660
8660
|
}
|
|
8661
|
-
const json = JSON.stringify(value);
|
|
8662
|
-
if (json === void 0 || Buffer.byteLength(json) > MAX_VALUE_BYTES) {
|
|
8663
|
-
throw new Error("The value is not JSON, or exceeds its size limit.");
|
|
8664
|
-
}
|
|
8665
|
-
walk(value, false);
|
|
8666
8661
|
const validate = compile(schema);
|
|
8667
8662
|
if (validate(value)) return { valid: true, errors: [] };
|
|
8668
8663
|
return {
|
|
@@ -8739,13 +8734,13 @@ function preview(body) {
|
|
|
8739
8734
|
}
|
|
8740
8735
|
function validateResultBody(schema, body) {
|
|
8741
8736
|
const bytes = Buffer.byteLength(body);
|
|
8742
|
-
const base = { json: false, bytes, maxBytes: MAX_BODY_BYTES, preview: preview(body) };
|
|
8737
|
+
const base = () => ({ json: false, bytes, maxBytes: MAX_BODY_BYTES, preview: preview(body) });
|
|
8743
8738
|
if (bytes > MAX_BODY_BYTES) {
|
|
8744
8739
|
return {
|
|
8745
8740
|
valid: false,
|
|
8746
8741
|
unvalidated: true,
|
|
8747
8742
|
reason: `The result is ${bytes} bytes, over the ${MAX_BODY_BYTES} byte validation limit, so its success schema was not checked.`,
|
|
8748
|
-
diagnosis: { ...base, failed: "too-large" }
|
|
8743
|
+
diagnosis: { ...base(), failed: "too-large" }
|
|
8749
8744
|
};
|
|
8750
8745
|
}
|
|
8751
8746
|
let value;
|
|
@@ -8756,18 +8751,35 @@ function validateResultBody(schema, body) {
|
|
|
8756
8751
|
return {
|
|
8757
8752
|
valid: false,
|
|
8758
8753
|
reason: `The result is not a supported bounded JSON document (${err instanceof Error ? err.message : String(err)}).`,
|
|
8759
|
-
diagnosis: { ...base, failed: "not-json" }
|
|
8754
|
+
diagnosis: { ...base(), failed: "not-json" }
|
|
8760
8755
|
};
|
|
8761
8756
|
}
|
|
8762
|
-
const check =
|
|
8757
|
+
const check = checkValue(schema, value);
|
|
8763
8758
|
if (check.valid) return { valid: true };
|
|
8764
8759
|
const failed = check.errors[0] ?? "the success rule";
|
|
8765
8760
|
return {
|
|
8766
8761
|
valid: false,
|
|
8767
8762
|
reason: `The result does not satisfy its success schema: ${failed}`,
|
|
8768
|
-
diagnosis: { ...base, json: true, failed }
|
|
8763
|
+
diagnosis: { ...base(), json: true, failed }
|
|
8769
8764
|
};
|
|
8770
8765
|
}
|
|
8766
|
+
function projectBody(schema, body) {
|
|
8767
|
+
if (schema === null || typeof schema !== "object" || Array.isArray(schema)) return void 0;
|
|
8768
|
+
if (Buffer.byteLength(body) > MAX_BODY_BYTES) return void 0;
|
|
8769
|
+
try {
|
|
8770
|
+
const value = JSON.parse(body);
|
|
8771
|
+
walk(value, false);
|
|
8772
|
+
const project = compile(withoutPatterns(schema), {
|
|
8773
|
+
allErrors: true,
|
|
8774
|
+
ignoreUnknown: true,
|
|
8775
|
+
project: true
|
|
8776
|
+
});
|
|
8777
|
+
project(value);
|
|
8778
|
+
return { value };
|
|
8779
|
+
} catch {
|
|
8780
|
+
return void 0;
|
|
8781
|
+
}
|
|
8782
|
+
}
|
|
8771
8783
|
|
|
8772
8784
|
// src/lib/spend-gate.ts
|
|
8773
8785
|
async function gateSpend(input) {
|
|
@@ -10606,9 +10618,10 @@ export {
|
|
|
10606
10618
|
canonicalHash,
|
|
10607
10619
|
inputProblems,
|
|
10608
10620
|
assertResultSchema,
|
|
10621
|
+
projectBody,
|
|
10609
10622
|
runPay,
|
|
10610
10623
|
MAX_PAID_LEG_TIMEOUT_MS,
|
|
10611
10624
|
paidLegTimeoutMs,
|
|
10612
10625
|
settlementTx
|
|
10613
10626
|
};
|
|
10614
|
-
//# sourceMappingURL=chunk-
|
|
10627
|
+
//# sourceMappingURL=chunk-YT7A7DLY.js.map
|