@absol-labs/agent 0.11.0 → 0.12.0-rc.2
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 +43 -51
- package/dist/capability/invocation-capability.d.ts +2 -2
- package/dist/capability/probe-capability.d.ts +225 -0
- package/dist/capability/probe-capability.d.ts.map +1 -0
- package/dist/capability/probe-capability.js +248 -0
- package/dist/capability/probe-capability.js.map +1 -0
- package/dist/cli/args.d.ts +11 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +23 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/commands/claim.d.ts +32 -0
- package/dist/cli/commands/claim.d.ts.map +1 -1
- package/dist/cli/commands/claim.js +116 -28
- package/dist/cli/commands/claim.js.map +1 -1
- package/dist/cli/commands/close.d.ts.map +1 -1
- package/dist/cli/commands/close.js +35 -3
- package/dist/cli/commands/close.js.map +1 -1
- package/dist/cli/commands/invoke.d.ts +2 -0
- package/dist/cli/commands/invoke.d.ts.map +1 -1
- package/dist/cli/commands/invoke.js +2 -2
- package/dist/cli/commands/invoke.js.map +1 -1
- package/dist/cli/commands/mcp.d.ts.map +1 -1
- package/dist/cli/commands/mcp.js +15 -2
- package/dist/cli/commands/mcp.js.map +1 -1
- package/dist/cli/commands/open.d.ts.map +1 -1
- package/dist/cli/commands/open.js +58 -4
- package/dist/cli/commands/open.js.map +1 -1
- package/dist/cli/commands/pay.d.ts +34 -0
- package/dist/cli/commands/pay.d.ts.map +1 -0
- package/dist/cli/commands/pay.js +479 -0
- package/dist/cli/commands/pay.js.map +1 -0
- package/dist/cli/commands/reclaim-unverified.d.ts.map +1 -1
- package/dist/cli/commands/reclaim-unverified.js +3 -2
- package/dist/cli/commands/reclaim-unverified.js.map +1 -1
- package/dist/cli/commands/reclaim.d.ts +23 -2
- package/dist/cli/commands/reclaim.d.ts.map +1 -1
- package/dist/cli/commands/reclaim.js +204 -20
- package/dist/cli/commands/reclaim.js.map +1 -1
- package/dist/cli/commands/refund.d.ts +31 -0
- package/dist/cli/commands/refund.d.ts.map +1 -0
- package/dist/cli/commands/refund.js +397 -0
- package/dist/cli/commands/refund.js.map +1 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +21 -2
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/streams.js +8 -12
- package/dist/cli/commands/streams.js.map +1 -1
- package/dist/cli/commands/watch.d.ts.map +1 -1
- package/dist/cli/commands/watch.js +4 -1
- package/dist/cli/commands/watch.js.map +1 -1
- package/dist/cli/config.d.ts +44 -26
- package/dist/cli/config.d.ts.map +1 -1
- package/dist/cli/config.js +88 -38
- package/dist/cli/config.js.map +1 -1
- package/dist/cli/context.d.ts +19 -0
- package/dist/cli/context.d.ts.map +1 -1
- package/dist/cli/deps.d.ts +53 -0
- package/dist/cli/deps.d.ts.map +1 -1
- package/dist/cli/deps.js +51 -1
- package/dist/cli/deps.js.map +1 -1
- package/dist/cli/errors.d.ts.map +1 -1
- package/dist/cli/errors.js +21 -1
- package/dist/cli/errors.js.map +1 -1
- package/dist/cli/escape-hatch.d.ts +6 -4
- package/dist/cli/escape-hatch.d.ts.map +1 -1
- package/dist/cli/escape-hatch.js +6 -2
- package/dist/cli/escape-hatch.js.map +1 -1
- package/dist/cli/listings.d.ts +18 -0
- package/dist/cli/listings.d.ts.map +1 -1
- package/dist/cli/listings.js +22 -12
- package/dist/cli/listings.js.map +1 -1
- package/dist/cli/preflight.d.ts +20 -14
- package/dist/cli/preflight.d.ts.map +1 -1
- package/dist/cli/preflight.js +34 -20
- package/dist/cli/preflight.js.map +1 -1
- package/dist/cli/privy.d.ts.map +1 -1
- package/dist/cli/privy.js +4 -2
- package/dist/cli/privy.js.map +1 -1
- package/dist/cli/progress.d.ts +13 -1
- package/dist/cli/progress.d.ts.map +1 -1
- package/dist/cli/progress.js +7 -1
- package/dist/cli/progress.js.map +1 -1
- package/dist/cli/reclaimability.d.ts +82 -0
- package/dist/cli/reclaimability.d.ts.map +1 -0
- package/dist/cli/reclaimability.js +80 -0
- package/dist/cli/reclaimability.js.map +1 -0
- package/dist/cli/run.d.ts +2 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +62 -21
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/scan-range.d.ts +2 -2
- package/dist/cli/scan-range.js +2 -2
- package/dist/cli/status.d.ts +106 -1
- package/dist/cli/status.d.ts.map +1 -1
- package/dist/cli/status.js +325 -44
- package/dist/cli/status.js.map +1 -1
- package/dist/cli/wallet.d.ts +2 -2
- package/dist/cli/wallet.d.ts.map +1 -1
- package/dist/cli/wallet.js +29 -5
- package/dist/cli/wallet.js.map +1 -1
- package/dist/discovery/rate-band.d.ts +74 -0
- package/dist/discovery/rate-band.d.ts.map +1 -0
- package/dist/discovery/rate-band.js +114 -0
- package/dist/discovery/rate-band.js.map +1 -0
- package/dist/escrow-generation.d.ts +81 -0
- package/dist/escrow-generation.d.ts.map +1 -0
- package/dist/escrow-generation.js +76 -0
- package/dist/escrow-generation.js.map +1 -0
- package/dist/frameworks/agentkit.d.ts +8 -4
- package/dist/frameworks/agentkit.d.ts.map +1 -1
- package/dist/frameworks/agentkit.js +27 -10
- package/dist/frameworks/agentkit.js.map +1 -1
- package/dist/frameworks/eliza.d.ts +3 -3
- package/dist/frameworks/eliza.d.ts.map +1 -1
- package/dist/frameworks/eliza.js +15 -6
- package/dist/frameworks/eliza.js.map +1 -1
- package/dist/frameworks/langchain.d.ts.map +1 -1
- package/dist/frameworks/langchain.js +8 -0
- package/dist/frameworks/langchain.js.map +1 -1
- package/dist/gateway/caller-auth-gateway.d.ts +83 -31
- package/dist/gateway/caller-auth-gateway.d.ts.map +1 -1
- package/dist/gateway/caller-auth-gateway.js +180 -27
- package/dist/gateway/caller-auth-gateway.js.map +1 -1
- package/dist/gateway/http-server.d.ts +128 -44
- package/dist/gateway/http-server.d.ts.map +1 -1
- package/dist/gateway/http-server.js +506 -155
- package/dist/gateway/http-server.js.map +1 -1
- package/dist/gateway/probe-auth.d.ts +112 -0
- package/dist/gateway/probe-auth.d.ts.map +1 -0
- package/dist/gateway/probe-auth.js +127 -0
- package/dist/gateway/probe-auth.js.map +1 -0
- package/dist/gateway/signed-rate-bounds.d.ts +51 -0
- package/dist/gateway/signed-rate-bounds.d.ts.map +1 -0
- package/dist/gateway/signed-rate-bounds.js +94 -0
- package/dist/gateway/signed-rate-bounds.js.map +1 -0
- package/dist/gateway/x402-opener-mode.d.ts +252 -0
- package/dist/gateway/x402-opener-mode.d.ts.map +1 -0
- package/dist/gateway/x402-opener-mode.js +772 -0
- package/dist/gateway/x402-opener-mode.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.d.ts +64 -1
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +247 -37
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/x402-tools.d.ts +109 -0
- package/dist/mcp/x402-tools.d.ts.map +1 -0
- package/dist/mcp/x402-tools.js +554 -0
- package/dist/mcp/x402-tools.js.map +1 -0
- package/dist/network.d.ts +119 -0
- package/dist/network.d.ts.map +1 -0
- package/dist/network.js +199 -0
- package/dist/network.js.map +1 -0
- package/dist/sdk/client.d.ts +13 -0
- package/dist/sdk/client.d.ts.map +1 -1
- package/dist/sdk/client.js +15 -0
- package/dist/sdk/client.js.map +1 -1
- package/dist/sdk/invoke.d.ts +4 -0
- package/dist/sdk/invoke.d.ts.map +1 -1
- package/dist/sdk/invoke.js +2 -5
- package/dist/sdk/invoke.js.map +1 -1
- package/dist/wallet/autonomous-wallet-broker.d.ts +3 -0
- package/dist/wallet/autonomous-wallet-broker.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet-broker.js +27 -23
- package/dist/wallet/autonomous-wallet-broker.js.map +1 -1
- package/dist/wallet/autonomous-wallet-protocol.d.ts +8 -2
- package/dist/wallet/autonomous-wallet-protocol.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet-protocol.js +9 -2
- package/dist/wallet/autonomous-wallet-protocol.js.map +1 -1
- package/dist/wallet/autonomous-wallet.d.ts.map +1 -1
- package/dist/wallet/autonomous-wallet.js +3 -2
- package/dist/wallet/autonomous-wallet.js.map +1 -1
- package/dist/wallet/broker-escrows.d.ts +222 -0
- package/dist/wallet/broker-escrows.d.ts.map +1 -0
- package/dist/wallet/broker-escrows.js +36 -0
- package/dist/wallet/broker-escrows.js.map +1 -0
- package/dist/wallet/lifecycle.d.ts +21 -5
- package/dist/wallet/lifecycle.d.ts.map +1 -1
- package/dist/wallet/lifecycle.js +32 -12
- package/dist/wallet/lifecycle.js.map +1 -1
- package/dist/wallet/privy-broker-server.d.ts.map +1 -1
- package/dist/wallet/privy-broker-server.js +31 -26
- package/dist/wallet/privy-broker-server.js.map +1 -1
- package/dist/wallet/privy-session-broker.d.ts +14 -5
- package/dist/wallet/privy-session-broker.d.ts.map +1 -1
- package/dist/wallet/privy-session-broker.js +29 -17
- package/dist/wallet/privy-session-broker.js.map +1 -1
- package/dist/wallet/privy-session-provider.d.ts +3 -1
- package/dist/wallet/privy-session-provider.d.ts.map +1 -1
- package/dist/wallet/privy-session-provider.js +5 -3
- package/dist/wallet/privy-session-provider.js.map +1 -1
- package/dist/wallet/provider.d.ts.map +1 -1
- package/dist/wallet/provider.js +15 -8
- package/dist/wallet/provider.js.map +1 -1
- package/dist/x402/facilitator.d.ts +3 -30
- package/dist/x402/facilitator.d.ts.map +1 -1
- package/dist/x402/facilitator.js +0 -27
- package/dist/x402/facilitator.js.map +1 -1
- package/dist/x402-buyer/guarded-fetch.d.ts +51 -0
- package/dist/x402-buyer/guarded-fetch.d.ts.map +1 -0
- package/dist/x402-buyer/guarded-fetch.js +147 -0
- package/dist/x402-buyer/guarded-fetch.js.map +1 -0
- package/dist/x402-buyer/index.d.ts +10 -0
- package/dist/x402-buyer/index.d.ts.map +1 -0
- package/dist/x402-buyer/index.js +10 -0
- package/dist/x402-buyer/index.js.map +1 -0
- package/dist/x402-buyer/pay.d.ts +157 -0
- package/dist/x402-buyer/pay.d.ts.map +1 -0
- package/dist/x402-buyer/pay.js +366 -0
- package/dist/x402-buyer/pay.js.map +1 -0
- package/dist/x402-opener/abi.d.ts +684 -0
- package/dist/x402-opener/abi.d.ts.map +1 -0
- package/dist/x402-opener/abi.js +880 -0
- package/dist/x402-opener/abi.js.map +1 -0
- package/dist/x402-opener/facilitator-entry.d.ts +3 -0
- package/dist/x402-opener/facilitator-entry.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-entry.js +40 -0
- package/dist/x402-opener/facilitator-entry.js.map +1 -0
- package/dist/x402-opener/facilitator-server.d.ts +209 -0
- package/dist/x402-opener/facilitator-server.d.ts.map +1 -0
- package/dist/x402-opener/facilitator-server.js +762 -0
- package/dist/x402-opener/facilitator-server.js.map +1 -0
- package/dist/x402-opener/index.d.ts +14 -0
- package/dist/x402-opener/index.d.ts.map +1 -0
- package/dist/x402-opener/index.js +14 -0
- package/dist/x402-opener/index.js.map +1 -0
- package/dist/x402-opener/listing-resolver.d.ts +55 -0
- package/dist/x402-opener/listing-resolver.d.ts.map +1 -0
- package/dist/x402-opener/listing-resolver.js +125 -0
- package/dist/x402-opener/listing-resolver.js.map +1 -0
- package/dist/x402-opener/refund-relay.d.ts +266 -0
- package/dist/x402-opener/refund-relay.d.ts.map +1 -0
- package/dist/x402-opener/refund-relay.js +1341 -0
- package/dist/x402-opener/refund-relay.js.map +1 -0
- package/dist/x402-opener/relayer-queue.d.ts +14 -0
- package/dist/x402-opener/relayer-queue.d.ts.map +1 -0
- package/dist/x402-opener/relayer-queue.js +18 -0
- package/dist/x402-opener/relayer-queue.js.map +1 -0
- package/dist/x402-opener/scheme.d.ts +296 -0
- package/dist/x402-opener/scheme.d.ts.map +1 -0
- package/dist/x402-opener/scheme.js +1035 -0
- package/dist/x402-opener/scheme.js.map +1 -0
- package/dist/x402-opener/terms.d.ts +165 -0
- package/dist/x402-opener/terms.d.ts.map +1 -0
- package/dist/x402-opener/terms.js +304 -0
- package/dist/x402-opener/terms.js.map +1 -0
- package/dist/zktls/reclaim.d.ts +2 -2
- package/dist/zktls/t2-delivery-proof.d.ts +6 -6
- package/docs/agent-layer.md +3 -2
- package/docs/autonomous-privy-wallet.md +188 -0
- package/docs/cli.md +265 -34
- package/docs/langchain.md +5 -0
- package/docs/mcp-reference.md +91 -5
- package/docs/probe-capability.md +191 -0
- package/docs/quickstart.md +39 -4
- package/docs/threat-model.md +20 -0
- package/docs/x402.md +766 -593
- package/package.json +19 -17
- package/src/capability/probe-capability.ts +355 -0
- package/src/cli/args.ts +29 -0
- package/src/cli/commands/claim.ts +168 -33
- package/src/cli/commands/close.ts +36 -3
- package/src/cli/commands/invoke.ts +5 -2
- package/src/cli/commands/mcp.ts +18 -2
- package/src/cli/commands/open.ts +75 -4
- package/src/cli/commands/pay.ts +584 -0
- package/src/cli/commands/reclaim-unverified.ts +8 -2
- package/src/cli/commands/reclaim.ts +277 -19
- package/src/cli/commands/refund.ts +475 -0
- package/src/cli/commands/status.ts +28 -2
- package/src/cli/commands/streams.ts +10 -14
- package/src/cli/commands/watch.ts +11 -1
- package/src/cli/config.ts +139 -52
- package/src/cli/context.ts +16 -0
- package/src/cli/deps.ts +111 -1
- package/src/cli/errors.ts +24 -1
- package/src/cli/escape-hatch.ts +19 -5
- package/src/cli/listings.ts +43 -10
- package/src/cli/preflight.ts +36 -21
- package/src/cli/privy.ts +4 -2
- package/src/cli/progress.ts +21 -2
- package/src/cli/reclaimability.ts +154 -0
- package/src/cli/run.ts +77 -21
- package/src/cli/scan-range.ts +2 -2
- package/src/cli/status.ts +454 -44
- package/src/cli/wallet.ts +45 -8
- package/src/discovery/rate-band.ts +172 -0
- package/src/escrow-generation.ts +135 -0
- package/src/frameworks/agentkit.ts +45 -11
- package/src/frameworks/eliza.ts +27 -5
- package/src/frameworks/langchain.ts +14 -0
- package/src/gateway/caller-auth-gateway.ts +320 -68
- package/src/gateway/http-server.ts +717 -220
- package/src/gateway/probe-auth.ts +191 -0
- package/src/gateway/signed-rate-bounds.ts +164 -0
- package/src/gateway/x402-opener-mode.ts +1171 -0
- package/src/index.ts +82 -19
- package/src/mcp/server.ts +351 -42
- package/src/mcp/x402-tools.ts +785 -0
- package/src/network.ts +302 -0
- package/src/sdk/client.ts +25 -0
- package/src/sdk/invoke.ts +6 -5
- package/src/wallet/autonomous-wallet-broker.ts +46 -20
- package/src/wallet/autonomous-wallet-protocol.ts +11 -2
- package/src/wallet/autonomous-wallet.ts +4 -2
- package/src/wallet/broker-escrows.ts +66 -0
- package/src/wallet/lifecycle.ts +53 -18
- package/src/wallet/privy-broker-server.ts +35 -25
- package/src/wallet/privy-session-broker.ts +58 -25
- package/src/wallet/privy-session-provider.ts +7 -3
- package/src/wallet/provider.ts +20 -15
- package/src/x402/facilitator.ts +3 -43
- package/src/x402-buyer/guarded-fetch.ts +213 -0
- package/src/x402-buyer/index.ts +9 -0
- package/src/x402-buyer/pay.ts +555 -0
- package/src/x402-opener/abi.ts +881 -0
- package/src/x402-opener/facilitator-entry.ts +48 -0
- package/src/x402-opener/facilitator-server.ts +1114 -0
- package/src/x402-opener/index.ts +13 -0
- package/src/x402-opener/listing-resolver.ts +202 -0
- package/src/x402-opener/refund-relay.ts +1873 -0
- package/src/x402-opener/relayer-queue.ts +18 -0
- package/src/x402-opener/scheme.ts +1551 -0
- package/src/x402-opener/terms.ts +453 -0
- package/dist/gateway/x402-mode.d.ts +0 -123
- package/dist/gateway/x402-mode.d.ts.map +0 -1
- package/dist/gateway/x402-mode.js +0 -212
- package/dist/gateway/x402-mode.js.map +0 -1
- package/dist/x402/delivery-oracle.d.ts +0 -108
- package/dist/x402/delivery-oracle.d.ts.map +0 -1
- package/dist/x402/delivery-oracle.js +0 -174
- package/dist/x402/delivery-oracle.js.map +0 -1
- package/dist/x402/facilitator-server-entry.d.ts +0 -3
- package/dist/x402/facilitator-server-entry.d.ts.map +0 -1
- package/dist/x402/facilitator-server-entry.js +0 -27
- package/dist/x402/facilitator-server-entry.js.map +0 -1
- package/dist/x402/facilitator-server.d.ts +0 -73
- package/dist/x402/facilitator-server.d.ts.map +0 -1
- package/dist/x402/facilitator-server.js +0 -305
- package/dist/x402/facilitator-server.js.map +0 -1
- package/dist/x402/payment-requirements.d.ts +0 -106
- package/dist/x402/payment-requirements.d.ts.map +0 -1
- package/dist/x402/payment-requirements.js +0 -138
- package/dist/x402/payment-requirements.js.map +0 -1
- package/dist/x402/relayer.d.ts +0 -41
- package/dist/x402/relayer.d.ts.map +0 -1
- package/dist/x402/relayer.js +0 -64
- package/dist/x402/relayer.js.map +0 -1
- package/dist/x402/resource-index.d.ts +0 -75
- package/dist/x402/resource-index.d.ts.map +0 -1
- package/dist/x402/resource-index.js +0 -126
- package/dist/x402/resource-index.js.map +0 -1
- package/dist/x402/verified-delivery-facilitator.d.ts +0 -285
- package/dist/x402/verified-delivery-facilitator.d.ts.map +0 -1
- package/dist/x402/verified-delivery-facilitator.js +0 -423
- package/dist/x402/verified-delivery-facilitator.js.map +0 -1
- package/src/gateway/x402-mode.ts +0 -350
- package/src/x402/delivery-oracle.ts +0 -285
- package/src/x402/facilitator-server-entry.ts +0 -35
- package/src/x402/facilitator-server.ts +0 -445
- package/src/x402/payment-requirements.ts +0 -231
- package/src/x402/relayer.ts +0 -122
- package/src/x402/resource-index.ts +0 -228
- package/src/x402/verified-delivery-facilitator.ts +0 -744
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absol-labs/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-rc.2",
|
|
4
4
|
"description": "Metrik agent layer: verified-streaming USDC payments metered by delivery, an MCP server, framework tools, and spend mandates so AI agents can hire and pay verified services safely.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Absol Labs",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"metrik-mcp": "dist/mcp/stdio.js",
|
|
22
22
|
"metrik-mcp-http": "dist/mcp/http-server.js",
|
|
23
23
|
"metrik-gateway": "dist/gateway/server-entry.js",
|
|
24
|
-
"metrik-x402-facilitator": "dist/x402/facilitator-
|
|
24
|
+
"metrik-x402-opener-facilitator": "dist/x402-opener/facilitator-entry.js"
|
|
25
25
|
},
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
@@ -48,9 +48,13 @@
|
|
|
48
48
|
"types": "./dist/frameworks/crewai.d.ts",
|
|
49
49
|
"import": "./dist/frameworks/crewai.js"
|
|
50
50
|
},
|
|
51
|
-
"./x402-
|
|
52
|
-
"types": "./dist/x402/
|
|
53
|
-
"import": "./dist/x402/
|
|
51
|
+
"./x402-opener": {
|
|
52
|
+
"types": "./dist/x402-opener/index.d.ts",
|
|
53
|
+
"import": "./dist/x402-opener/index.js"
|
|
54
|
+
},
|
|
55
|
+
"./x402-buyer": {
|
|
56
|
+
"types": "./dist/x402-buyer/index.d.ts",
|
|
57
|
+
"import": "./dist/x402-buyer/index.js"
|
|
54
58
|
},
|
|
55
59
|
"./package.json": "./package.json",
|
|
56
60
|
"./*": {
|
|
@@ -81,11 +85,13 @@
|
|
|
81
85
|
"pnpm": "9.15.x"
|
|
82
86
|
},
|
|
83
87
|
"dependencies": {
|
|
84
|
-
"@absol-labs/sdk": "
|
|
85
|
-
"@absol-labs/shared": "
|
|
88
|
+
"@absol-labs/sdk": "0.10.0-rc.3",
|
|
89
|
+
"@absol-labs/shared": "0.14.0-rc.2",
|
|
86
90
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
87
91
|
"@napi-rs/keyring": "1.3.0",
|
|
88
92
|
"@privy-io/node": "0.33.0",
|
|
93
|
+
"@x402/core": "2.27.0",
|
|
94
|
+
"@x402/evm": "2.27.0",
|
|
89
95
|
"reflect-metadata": "^0.2.2",
|
|
90
96
|
"viem": "^2.21.0",
|
|
91
97
|
"zod": "^3.24.0"
|
|
@@ -96,8 +102,7 @@
|
|
|
96
102
|
"@elizaos/core": "^1.7.2",
|
|
97
103
|
"@langchain/core": "^1.2.0",
|
|
98
104
|
"@reclaimprotocol/js-sdk": "^5.6.0",
|
|
99
|
-
"@reclaimprotocol/zk-fetch": "^1.0.0"
|
|
100
|
-
"x402": "^1.2.0"
|
|
105
|
+
"@reclaimprotocol/zk-fetch": "^1.0.0"
|
|
101
106
|
},
|
|
102
107
|
"peerDependenciesMeta": {
|
|
103
108
|
"@coinbase/agentkit": {
|
|
@@ -117,9 +122,6 @@
|
|
|
117
122
|
},
|
|
118
123
|
"@reclaimprotocol/zk-fetch": {
|
|
119
124
|
"optional": true
|
|
120
|
-
},
|
|
121
|
-
"x402": {
|
|
122
|
-
"optional": true
|
|
123
125
|
}
|
|
124
126
|
},
|
|
125
127
|
"devDependencies": {
|
|
@@ -131,12 +133,11 @@
|
|
|
131
133
|
"@reclaimprotocol/zk-fetch": "^1.0.0",
|
|
132
134
|
"@swc/core": "^1.10.0",
|
|
133
135
|
"@types/node": "^20.17.0",
|
|
136
|
+
"@x402/fetch": "2.27.0",
|
|
134
137
|
"prettier": "^3.4.0",
|
|
135
138
|
"tsx": "^4.19.0",
|
|
136
139
|
"typescript": "^5.7.0",
|
|
137
|
-
"vitest": "^2.1.0"
|
|
138
|
-
"x402": "1.2.0",
|
|
139
|
-
"x402-fetch": "1.2.0"
|
|
140
|
+
"vitest": "^2.1.0"
|
|
140
141
|
},
|
|
141
142
|
"scripts": {
|
|
142
143
|
"build": "tsc -p tsconfig.json",
|
|
@@ -145,7 +146,9 @@
|
|
|
145
146
|
"mcp:stdio": "tsx src/mcp/stdio.ts",
|
|
146
147
|
"mcp:http": "tsx src/mcp/http-server.ts",
|
|
147
148
|
"gateway": "tsx src/gateway/server-entry.ts",
|
|
149
|
+
"x402-opener:facilitator": "tsx src/x402-opener/facilitator-entry.ts",
|
|
148
150
|
"e2e:cdp": "node dist-e2e/scripts/e2e-cdp.js",
|
|
151
|
+
"e2e:x402": "node dist-e2e/scripts/e2e-x402.js",
|
|
149
152
|
"e2e:hire": "tsx scripts/e2e-hire.ts",
|
|
150
153
|
"l2:proof": "node scripts/l2-proof.mjs",
|
|
151
154
|
"test": "vitest run",
|
|
@@ -154,7 +157,6 @@
|
|
|
154
157
|
"typecheck:examples": "tsc -p tsconfig.examples.json --noEmit",
|
|
155
158
|
"typecheck:e2e": "tsc -p tsconfig.e2e.json --noEmit",
|
|
156
159
|
"lint": "tsc -p tsconfig.json --noEmit",
|
|
157
|
-
"format": "prettier --write ."
|
|
158
|
-
"x402:facilitator": "tsx src/x402/facilitator-server-entry.ts"
|
|
160
|
+
"format": "prettier --write ."
|
|
159
161
|
}
|
|
160
162
|
}
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
getAddress,
|
|
5
|
+
isAddress,
|
|
6
|
+
isHex,
|
|
7
|
+
recoverTypedDataAddress,
|
|
8
|
+
type Address,
|
|
9
|
+
type Hex,
|
|
10
|
+
type LocalAccount,
|
|
11
|
+
} from "viem";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
hashInvocationPath,
|
|
16
|
+
httpMethodSchema,
|
|
17
|
+
normalizeInvocationPath,
|
|
18
|
+
} from "./invocation-capability.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `ProbeCapability` — the ORACLE-signed EIP-712 credential that lets the
|
|
22
|
+
* neutral verifier exercise the PAID route of a `gated` listing.
|
|
23
|
+
*
|
|
24
|
+
* ## The gap this closes
|
|
25
|
+
*
|
|
26
|
+
* A gated listing's paid route requires an `InvocationCapability` signed by the
|
|
27
|
+
* stream's BUYER (see `./invocation-capability.ts`). The oracle is not a buyer
|
|
28
|
+
* and holds no buyer key, so before this type existed the oracle could only
|
|
29
|
+
* probe a gated service's HEALTH route. "The seller earns only for intervals
|
|
30
|
+
* that verified" therefore meant "the health endpoint answered" — not "the paid
|
|
31
|
+
* route delivered". This capability is the missing credential.
|
|
32
|
+
*
|
|
33
|
+
* ## Why this is not just "give the workers a credential"
|
|
34
|
+
*
|
|
35
|
+
* Three properties, all load-bearing:
|
|
36
|
+
*
|
|
37
|
+
* 1. **No shared secret.** Authority is an EIP-712 signature by an address in
|
|
38
|
+
* the escrow's `getOracleSigners()`. That list is PUBLICLY READABLE on-chain,
|
|
39
|
+
* so a third-party seller performs the identical check with no credential
|
|
40
|
+
* distribution, no registration, and nothing for either side to leak.
|
|
41
|
+
* 2. **No signing key leaves the coordinator.** The oracle coordinator mints one
|
|
42
|
+
* fresh capability per probe and hands the encoded header to the regional
|
|
43
|
+
* worker. A worker holds a bearer token for the coordinator and nothing else;
|
|
44
|
+
* compromising every worker yields no ability to mint a capability.
|
|
45
|
+
* 3. **Not stream-bound.** Deliberately carries NO `streamId` and NO `buyer`.
|
|
46
|
+
* That is what makes the same mechanism usable to probe a listing that has no
|
|
47
|
+
* stream at all — and it is also the structural guarantee that a probe can
|
|
48
|
+
* never consume a buyer's budget: there is no stream for it to be billed
|
|
49
|
+
* against. Accrual is only ever produced by an oracle checkpoint keyed to a
|
|
50
|
+
* stream; a gateway call produces none.
|
|
51
|
+
*
|
|
52
|
+
* ## What a probe is NOT
|
|
53
|
+
*
|
|
54
|
+
* A probe is verification, not delivery to a buyer. A gateway authorizing one
|
|
55
|
+
* MUST NOT meter it, settle any payment for it, or count it as a paid call.
|
|
56
|
+
* The reference gateway enforces this structurally (see
|
|
57
|
+
* `../gateway/caller-auth-gateway.ts`) and marks the upstream request with
|
|
58
|
+
* {@link PROBE_MARKER_HEADER_NAME} so a seller's own metering can exclude it.
|
|
59
|
+
*
|
|
60
|
+
* ## Honest note for third-party sellers
|
|
61
|
+
*
|
|
62
|
+
* This CHANGES what a seller's gateway must implement to get paid-route
|
|
63
|
+
* verification. A gated listing fronted by a gateway that has not adopted
|
|
64
|
+
* `ProbeCapability` stays HEALTH-ROUTE-ONLY, and the oracle reports it as
|
|
65
|
+
* unverifiable rather than passing. Adoption is the seller's choice; silence
|
|
66
|
+
* about it is not the oracle's.
|
|
67
|
+
*
|
|
68
|
+
* Kept LOCAL to `@absol-labs/agent` for the same reason as
|
|
69
|
+
* `InvocationCapability`: no contract parses it, so there is no on-chain byte
|
|
70
|
+
* compatibility requirement. Cross-repo compatibility with the oracle's minter
|
|
71
|
+
* is pinned by a shared digest test vector — see
|
|
72
|
+
* `test/probe-capability.test.ts` and the oracle's mirror of the same constant.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
const addressSchema = z
|
|
76
|
+
.string()
|
|
77
|
+
.refine((value) => isAddress(value), "must be an EVM address");
|
|
78
|
+
const bytes32Schema = z
|
|
79
|
+
.string()
|
|
80
|
+
.refine(
|
|
81
|
+
(value) => isHex(value, { strict: true }) && value.length === 66,
|
|
82
|
+
"must be bytes32 hex",
|
|
83
|
+
);
|
|
84
|
+
const signatureSchema = z
|
|
85
|
+
.string()
|
|
86
|
+
.refine(
|
|
87
|
+
(value) => isHex(value, { strict: true }) && value.length === 132,
|
|
88
|
+
"must be a 65-byte signature",
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
export const probeCapabilitySchema = z.object({
|
|
92
|
+
/**
|
|
93
|
+
* The service being probed. Must match the target gateway's configured
|
|
94
|
+
* `serviceRef`. There is deliberately no `streamId` field — see the class
|
|
95
|
+
* docs.
|
|
96
|
+
*/
|
|
97
|
+
serviceRef: bytes32Schema,
|
|
98
|
+
/**
|
|
99
|
+
* The minting oracle signer. Must equal the EIP-712 signer AND be a member of
|
|
100
|
+
* the escrow's on-chain `getOracleSigners()` set at verification time.
|
|
101
|
+
*/
|
|
102
|
+
oracle: addressSchema,
|
|
103
|
+
/** The single HTTP method this capability authorizes. */
|
|
104
|
+
method: httpMethodSchema,
|
|
105
|
+
/** `keccak256` of the exact request path this capability authorizes. */
|
|
106
|
+
pathHash: bytes32Schema,
|
|
107
|
+
/** Single-use anti-replay nonce. */
|
|
108
|
+
nonce: bytes32Schema,
|
|
109
|
+
/** Unix seconds after which the capability is no longer valid. */
|
|
110
|
+
expiry: z.number().int().positive(),
|
|
111
|
+
});
|
|
112
|
+
export type ProbeCapability = z.infer<typeof probeCapabilitySchema>;
|
|
113
|
+
|
|
114
|
+
export const signedProbeCapabilitySchema = probeCapabilitySchema.extend({
|
|
115
|
+
signature: signatureSchema,
|
|
116
|
+
});
|
|
117
|
+
export type SignedProbeCapability = z.infer<typeof signedProbeCapabilitySchema>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Chain-bound domain. `verifyingContract` is the `StreamEscrowV2` whose
|
|
121
|
+
* `getOracleSigners()` defines who may mint — so a capability minted for one
|
|
122
|
+
* escrow can never authorize a probe against a gateway fronting another.
|
|
123
|
+
*/
|
|
124
|
+
export interface ProbeCapabilityDomainInput {
|
|
125
|
+
readonly chainId: number;
|
|
126
|
+
readonly verifyingContract: Address;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Distinct from `Metrik Invocation Capability`, so a buyer's invocation
|
|
131
|
+
* signature can never be replayed as a probe (or the reverse) even though both
|
|
132
|
+
* share a chainId and verifying contract.
|
|
133
|
+
*/
|
|
134
|
+
export const probeCapabilityDomainName = "Metrik Probe Capability" as const;
|
|
135
|
+
export const probeCapabilityDomainVersion = "1" as const;
|
|
136
|
+
|
|
137
|
+
export const probeCapabilityTypedData = {
|
|
138
|
+
ProbeCapability: [
|
|
139
|
+
{ name: "serviceRef", type: "bytes32" },
|
|
140
|
+
{ name: "oracle", type: "address" },
|
|
141
|
+
{ name: "method", type: "string" },
|
|
142
|
+
{ name: "pathHash", type: "bytes32" },
|
|
143
|
+
{ name: "nonce", type: "bytes32" },
|
|
144
|
+
{ name: "expiry", type: "uint64" },
|
|
145
|
+
],
|
|
146
|
+
} as const;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Default lifetime of a freshly-minted probe capability, in seconds.
|
|
150
|
+
*
|
|
151
|
+
* Shorter than the ~15-22s checkpoint cadence would race a slow upstream; much
|
|
152
|
+
* longer would widen the window in which a captured capability is replayable
|
|
153
|
+
* against a gateway with no nonce cache. 30s is one to two probe intervals.
|
|
154
|
+
*/
|
|
155
|
+
export const DEFAULT_PROBE_CAPABILITY_TTL_SECONDS = 30;
|
|
156
|
+
|
|
157
|
+
/** Header a probe request carries the signed capability in. */
|
|
158
|
+
export const PROBE_CAPABILITY_HEADER_NAME = "x-metrik-probe-capability";
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Header the gateway adds to the UPSTREAM request when it authorized a probe.
|
|
162
|
+
* Advisory: it exists so a seller's own metering/analytics can exclude
|
|
163
|
+
* verification traffic from billable usage.
|
|
164
|
+
*/
|
|
165
|
+
export const PROBE_MARKER_HEADER_NAME = "x-metrik-probe";
|
|
166
|
+
|
|
167
|
+
export function createProbeCapabilityEip712Domain(
|
|
168
|
+
domain: ProbeCapabilityDomainInput,
|
|
169
|
+
) {
|
|
170
|
+
return {
|
|
171
|
+
name: probeCapabilityDomainName,
|
|
172
|
+
version: probeCapabilityDomainVersion,
|
|
173
|
+
chainId: domain.chainId,
|
|
174
|
+
verifyingContract: getAddress(domain.verifyingContract),
|
|
175
|
+
} as const;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* `keccak256` of the exact request path this capability authorizes. Shares the
|
|
180
|
+
* canonical form with `InvocationCapability` so both sides of a gateway hash
|
|
181
|
+
* paths identically.
|
|
182
|
+
*/
|
|
183
|
+
export function hashProbePath(path: string): Hex {
|
|
184
|
+
return hashInvocationPath(path);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Re-exported for symmetry; identical canonicalization to the invocation path. */
|
|
188
|
+
export function normalizeProbePath(path: string): string {
|
|
189
|
+
return normalizeInvocationPath(path);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function probeCapabilityMessage(capability: ProbeCapability) {
|
|
193
|
+
const parsed = probeCapabilitySchema.parse(capability);
|
|
194
|
+
return {
|
|
195
|
+
serviceRef: parsed.serviceRef as Hex,
|
|
196
|
+
oracle: getAddress(parsed.oracle),
|
|
197
|
+
method: parsed.method,
|
|
198
|
+
pathHash: parsed.pathHash as Hex,
|
|
199
|
+
nonce: parsed.nonce as Hex,
|
|
200
|
+
expiry: BigInt(parsed.expiry),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function buildProbeCapabilityTypedData(
|
|
205
|
+
capability: ProbeCapability,
|
|
206
|
+
domain: ProbeCapabilityDomainInput,
|
|
207
|
+
) {
|
|
208
|
+
return {
|
|
209
|
+
domain: createProbeCapabilityEip712Domain(domain),
|
|
210
|
+
types: probeCapabilityTypedData,
|
|
211
|
+
primaryType: "ProbeCapability" as const,
|
|
212
|
+
message: probeCapabilityMessage(capability),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** The minimum an oracle signer must expose to mint a probe capability. */
|
|
217
|
+
export type ProbeCapabilitySigner = Pick<
|
|
218
|
+
LocalAccount,
|
|
219
|
+
"address" | "signTypedData"
|
|
220
|
+
>;
|
|
221
|
+
|
|
222
|
+
/** Signs a `ProbeCapability` with an oracle signer's own key. */
|
|
223
|
+
export async function signProbeCapability(
|
|
224
|
+
capability: ProbeCapability,
|
|
225
|
+
domain: ProbeCapabilityDomainInput,
|
|
226
|
+
account: ProbeCapabilitySigner,
|
|
227
|
+
): Promise<Hex> {
|
|
228
|
+
const typedData = buildProbeCapabilityTypedData(capability, domain);
|
|
229
|
+
return account.signTypedData(typedData);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Recovers the EIP-712 signer of a probe capability. Throws on a malformed signature. */
|
|
233
|
+
export async function recoverProbeCapabilitySigner(
|
|
234
|
+
capability: ProbeCapability,
|
|
235
|
+
domain: ProbeCapabilityDomainInput,
|
|
236
|
+
signature: Hex,
|
|
237
|
+
): Promise<Address> {
|
|
238
|
+
const typedData = buildProbeCapabilityTypedData(capability, domain);
|
|
239
|
+
return recoverTypedDataAddress({ ...typedData, signature });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Cryptographically random 32-byte single-use nonce. */
|
|
243
|
+
export function generateProbeNonce(): Hex {
|
|
244
|
+
return `0x${randomBytes(32).toString("hex")}` as Hex;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export class InvalidProbeCapabilityHeaderError extends Error {
|
|
248
|
+
constructor(message: string, options?: { readonly cause?: unknown }) {
|
|
249
|
+
super(message, options);
|
|
250
|
+
this.name = "InvalidProbeCapabilityHeaderError";
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Encodes a signed probe capability as an opaque, header-safe (base64url) string. */
|
|
255
|
+
export function encodeProbeCapabilityHeader(
|
|
256
|
+
signed: SignedProbeCapability,
|
|
257
|
+
): string {
|
|
258
|
+
const parsed = signedProbeCapabilitySchema.parse(signed);
|
|
259
|
+
const json = JSON.stringify({
|
|
260
|
+
serviceRef: parsed.serviceRef,
|
|
261
|
+
oracle: parsed.oracle,
|
|
262
|
+
method: parsed.method,
|
|
263
|
+
pathHash: parsed.pathHash,
|
|
264
|
+
nonce: parsed.nonce,
|
|
265
|
+
expiry: parsed.expiry,
|
|
266
|
+
signature: parsed.signature,
|
|
267
|
+
});
|
|
268
|
+
return Buffer.from(json, "utf8").toString("base64url");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Decodes and schema-validates a probe capability header. Fails closed on any malformation. */
|
|
272
|
+
export function decodeProbeCapabilityHeader(
|
|
273
|
+
headerValue: string,
|
|
274
|
+
): SignedProbeCapability {
|
|
275
|
+
let json: string;
|
|
276
|
+
try {
|
|
277
|
+
json = Buffer.from(headerValue, "base64url").toString("utf8");
|
|
278
|
+
} catch (cause) {
|
|
279
|
+
throw new InvalidProbeCapabilityHeaderError(
|
|
280
|
+
"malformed base64 probe capability header",
|
|
281
|
+
{ cause },
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let raw: unknown;
|
|
286
|
+
try {
|
|
287
|
+
raw = JSON.parse(json);
|
|
288
|
+
} catch (cause) {
|
|
289
|
+
throw new InvalidProbeCapabilityHeaderError(
|
|
290
|
+
"malformed JSON probe capability header",
|
|
291
|
+
{ cause },
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const result = signedProbeCapabilitySchema.safeParse(raw);
|
|
296
|
+
if (!result.success) {
|
|
297
|
+
throw new InvalidProbeCapabilityHeaderError(
|
|
298
|
+
`invalid probe capability shape: ${result.error.message}`,
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
return result.data;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface MintProbeCapabilityOptions {
|
|
305
|
+
readonly serviceRef: Hex;
|
|
306
|
+
readonly method: ProbeCapability["method"];
|
|
307
|
+
/** The exact request path to be probed (query/fragment are stripped). */
|
|
308
|
+
readonly path: string;
|
|
309
|
+
readonly domain: ProbeCapabilityDomainInput;
|
|
310
|
+
readonly account: ProbeCapabilitySigner;
|
|
311
|
+
readonly ttlSeconds?: number;
|
|
312
|
+
/** Injectable clock (unix seconds), for tests. */
|
|
313
|
+
readonly now?: () => number;
|
|
314
|
+
/** Injectable nonce source, for tests. */
|
|
315
|
+
readonly nonce?: () => Hex;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Mint one fresh, single-use, short-lived probe capability and return its
|
|
320
|
+
* encoded header value. Called once PER PROBE PER VANTAGE by the coordinator:
|
|
321
|
+
* the gateway's replay cache is single-use, so two vantages sharing one
|
|
322
|
+
* capability would see the second rejected as a replay.
|
|
323
|
+
*/
|
|
324
|
+
export async function mintProbeCapabilityHeader(
|
|
325
|
+
options: MintProbeCapabilityOptions,
|
|
326
|
+
): Promise<{
|
|
327
|
+
readonly headerName: string;
|
|
328
|
+
readonly headerValue: string;
|
|
329
|
+
readonly capability: SignedProbeCapability;
|
|
330
|
+
}> {
|
|
331
|
+
const nowSeconds = (options.now ?? (() => Math.floor(Date.now() / 1000)))();
|
|
332
|
+
const ttl = options.ttlSeconds ?? DEFAULT_PROBE_CAPABILITY_TTL_SECONDS;
|
|
333
|
+
if (!Number.isInteger(ttl) || ttl <= 0) {
|
|
334
|
+
throw new Error("probe capability ttlSeconds must be a positive integer");
|
|
335
|
+
}
|
|
336
|
+
const capability: ProbeCapability = {
|
|
337
|
+
serviceRef: options.serviceRef,
|
|
338
|
+
oracle: getAddress(options.account.address),
|
|
339
|
+
method: options.method,
|
|
340
|
+
pathHash: hashProbePath(options.path),
|
|
341
|
+
nonce: (options.nonce ?? generateProbeNonce)(),
|
|
342
|
+
expiry: nowSeconds + ttl,
|
|
343
|
+
};
|
|
344
|
+
const signature = await signProbeCapability(
|
|
345
|
+
capability,
|
|
346
|
+
options.domain,
|
|
347
|
+
options.account,
|
|
348
|
+
);
|
|
349
|
+
const signed: SignedProbeCapability = { ...capability, signature };
|
|
350
|
+
return {
|
|
351
|
+
headerName: PROBE_CAPABILITY_HEADER_NAME,
|
|
352
|
+
headerValue: encodeProbeCapabilityHeader(signed),
|
|
353
|
+
capability: signed,
|
|
354
|
+
};
|
|
355
|
+
}
|
package/src/cli/args.ts
CHANGED
|
@@ -117,6 +117,35 @@ export function booleanFlag(args: ParsedArgs, name: string): boolean {
|
|
|
117
117
|
throw usageError(`--${name} takes no value (got "${value}")`);
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Commands whose `--json` may ALSO carry a value: a JSON request body, as in
|
|
122
|
+
* curl's `--json '<body>'`. For them a bare `--json` (or `--json=true`) still
|
|
123
|
+
* selects JSON output, and the two can be combined
|
|
124
|
+
* (`--json '{"a":1}' --json`). Every other command keeps `--json` boolean.
|
|
125
|
+
*/
|
|
126
|
+
export const JSON_BODY_COMMANDS: ReadonlySet<string> = new Set(["pay"]);
|
|
127
|
+
|
|
128
|
+
/** Whether `--json` OUTPUT was requested (see {@link JSON_BODY_COMMANDS}). */
|
|
129
|
+
export function jsonOutputRequested(args: ParsedArgs): boolean {
|
|
130
|
+
if (args.command === null || !JSON_BODY_COMMANDS.has(args.command)) {
|
|
131
|
+
return booleanFlag(args, "json");
|
|
132
|
+
}
|
|
133
|
+
const values = args.flags.get("json") ?? [];
|
|
134
|
+
return values.some((value) => value === true || value === "true");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The `--json <body>` value(s) of a JSON-body command, if any. */
|
|
138
|
+
export function jsonBodyFlag(args: ParsedArgs): string | undefined {
|
|
139
|
+
const values = (args.flags.get("json") ?? []).filter(
|
|
140
|
+
(value): value is string =>
|
|
141
|
+
typeof value === "string" && value !== "true" && value !== "false",
|
|
142
|
+
);
|
|
143
|
+
if (values.length > 1) {
|
|
144
|
+
throw usageError("--json <body> may be given only once");
|
|
145
|
+
}
|
|
146
|
+
return values[0];
|
|
147
|
+
}
|
|
148
|
+
|
|
120
149
|
export function integerFlag(
|
|
121
150
|
args: ParsedArgs,
|
|
122
151
|
name: string,
|