@agentcash/telemetry 0.0.0-pr-16-20260520161400

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/dist/siwx.js ADDED
@@ -0,0 +1,99 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
2
+
3
+ var _chunk47QZYT7Qjs = require('./chunk-47QZYT7Q.js');
4
+ require('./chunk-MBH3LCBQ.js');
5
+ require('./chunk-QEJ7ZGGH.js');
6
+
7
+ // src/siwx.ts
8
+ var _server = require('next/server');
9
+ var _crypto = require('crypto');
10
+
11
+
12
+
13
+
14
+
15
+ var _signinwithx = require('@x402/extensions/sign-in-with-x');
16
+ var _http = require('@x402/core/http');
17
+ function withSiwxTelemetry(handler) {
18
+ return _chunk47QZYT7Qjs.withTelemetry.call(void 0, async (request, ctx) => {
19
+ const header = _nullishCoalesce(request.headers.get("SIGN-IN-WITH-X"), () => ( request.headers.get("sign-in-with-x")));
20
+ if (!header) {
21
+ return buildSiwxChallengeResponse(request);
22
+ }
23
+ const payload = _signinwithx.parseSIWxHeader.call(void 0, header);
24
+ const validation = await _signinwithx.validateSIWxMessage.call(void 0, payload, request.url);
25
+ if (!validation.valid) {
26
+ return _server.NextResponse.json(
27
+ { success: false, error: `SIWX validation failed: ${validation.error}` },
28
+ { status: 402 }
29
+ );
30
+ }
31
+ const verification = await _signinwithx.verifySIWxSignature.call(void 0, payload);
32
+ if (!verification.valid || !verification.address) {
33
+ return _server.NextResponse.json(
34
+ { success: false, error: "SIWX signature verification failed" },
35
+ { status: 402 }
36
+ );
37
+ }
38
+ const walletAddress = verification.address.toLowerCase();
39
+ ctx.setVerifiedWallet(walletAddress);
40
+ return handler(request, {
41
+ ...ctx,
42
+ verifiedWallet: walletAddress
43
+ });
44
+ });
45
+ }
46
+ function buildSiwxChallengeResponse(request) {
47
+ const url = new URL(request.url);
48
+ const nonce = _crypto.randomBytes.call(void 0, 16).toString("hex");
49
+ const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
50
+ const expirationTime = new Date(Date.now() + 3e5).toISOString();
51
+ const paymentRequired = {
52
+ x402Version: 2,
53
+ error: "SIWX authentication required",
54
+ resource: {
55
+ url: request.url,
56
+ description: "SIWX-protected endpoint",
57
+ mimeType: "application/json"
58
+ },
59
+ accepts: [
60
+ {
61
+ scheme: "exact",
62
+ network: "eip155:8453",
63
+ asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
64
+ amount: "0",
65
+ payTo: "0x0000000000000000000000000000000000000000",
66
+ maxTimeoutSeconds: 300,
67
+ extra: {}
68
+ }
69
+ ],
70
+ extensions: {
71
+ "sign-in-with-x": {
72
+ info: {
73
+ domain: url.hostname,
74
+ uri: request.url,
75
+ version: "1",
76
+ nonce,
77
+ issuedAt,
78
+ expirationTime,
79
+ statement: "Sign in to verify your wallet identity",
80
+ resources: [request.url]
81
+ },
82
+ supportedChains: [{ chainId: "eip155:8453", type: "eip191" }],
83
+ schema: _signinwithx.buildSIWxSchema.call(void 0, )
84
+ }
85
+ }
86
+ };
87
+ const encoded = _http.encodePaymentRequiredHeader.call(void 0, paymentRequired);
88
+ return new (0, _server.NextResponse)(JSON.stringify(paymentRequired), {
89
+ status: 402,
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ "PAYMENT-REQUIRED": encoded
93
+ }
94
+ });
95
+ }
96
+
97
+
98
+ exports.withSiwxTelemetry = withSiwxTelemetry;
99
+ //# sourceMappingURL=siwx.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/agentcash-telemetry/agentcash-telemetry/dist/siwx.js","../src/siwx.ts"],"names":[],"mappings":"AAAA;AACE;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B,+BAA4B;AAC5B;AACA;ACKA,qCAA+C;AAC/C,gCAA4B;AAC5B;AACE;AACA;AACA;AACA;AAAA,8DACK;AACP,uCAA4C;AAoBrC,SAAS,iBAAA,CAAkB,OAAA,EAAsB;AACtD,EAAA,OAAO,4CAAA,MAAc,CAAO,OAAA,EAAsB,GAAA,EAAA,GAA0B;AAC1E,IAAA,MAAM,OAAA,mBAAS,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,gBAAgB,CAAA,UAAK,OAAA,CAAQ,OAAA,CAAQ,GAAA,CAAI,gBAAgB,GAAA;AAE5F,IAAA,GAAA,CAAI,CAAC,MAAA,EAAQ;AACX,MAAA,OAAO,0BAAA,CAA2B,OAAO,CAAA;AAAA,IAC3C;AAEA,IAAA,MAAM,QAAA,EAAU,0CAAA,MAAsB,CAAA;AAEtC,IAAA,MAAM,WAAA,EAAa,MAAM,8CAAA,OAAoB,EAAS,OAAA,CAAQ,GAAG,CAAA;AACjE,IAAA,GAAA,CAAI,CAAC,UAAA,CAAW,KAAA,EAAO;AACrB,MAAA,OAAO,oBAAA,CAAa,IAAA;AAAA,QAClB,EAAE,OAAA,EAAS,KAAA,EAAO,KAAA,EAAO,CAAA,wBAAA,EAA2B,UAAA,CAAW,KAAK,CAAA,EAAA;AACtD,QAAA;AAChB,MAAA;AACF,IAAA;AAEsD,IAAA;AACJ,IAAA;AAC5B,MAAA;AAC4C,QAAA;AAChD,QAAA;AAChB,MAAA;AACF,IAAA;AAEuD,IAAA;AACpB,IAAA;AAEX,IAAA;AACnB,MAAA;AACa,MAAA;AACO,IAAA;AAC1B,EAAA;AACH;AAKwE;AACvC,EAAA;AACa,EAAA;AACJ,EAAA;AAC0B,EAAA;AAE1C,EAAA;AACT,IAAA;AACN,IAAA;AACG,IAAA;AACK,MAAA;AACA,MAAA;AACH,MAAA;AACZ,IAAA;AACS,IAAA;AACP,MAAA;AACU,QAAA;AACC,QAAA;AACF,QAAA;AACC,QAAA;AACD,QAAA;AACY,QAAA;AACX,QAAA;AACV,MAAA;AACF,IAAA;AACY,IAAA;AACQ,MAAA;AACV,QAAA;AACQ,UAAA;AACC,UAAA;AACJ,UAAA;AACT,UAAA;AACA,UAAA;AACA,UAAA;AACW,UAAA;AACY,UAAA;AACzB,QAAA;AAC4D,QAAA;AACpC,QAAA;AAC1B,MAAA;AACF,IAAA;AACF,EAAA;AAE2D,EAAA;AAEF,EAAA;AAC/C,IAAA;AACC,IAAA;AACS,MAAA;AACI,MAAA;AACtB,IAAA;AACD,EAAA;AACH;ADnC6E;AACA;AACA","file":"/home/runner/work/agentcash-telemetry/agentcash-telemetry/dist/siwx.js","sourcesContent":[null,"/**\n * SIWX telemetry wrapper — composes SIWX verification with telemetry.\n * One-liner for routes that need wallet auth + telemetry.\n *\n * Delegates SIWX verification to @x402/extensions/sign-in-with-x.\n * This package does NOT implement SIWX itself.\n *\n * Import from '@agentcash/telemetry/siwx'.\n * Requires peer dep: @x402/extensions\n */\n\nimport { type NextRequest, NextResponse } from 'next/server';\nimport { randomBytes } from 'crypto';\nimport {\n parseSIWxHeader,\n validateSIWxMessage,\n verifySIWxSignature,\n buildSIWxSchema,\n} from '@x402/extensions/sign-in-with-x';\nimport { encodePaymentRequiredHeader } from '@x402/core/http';\nimport type { TelemetryContext } from './types';\nimport { withTelemetry } from './telemetry';\n\nexport type { SiwxTelemetryContext };\n\ninterface SiwxTelemetryContext extends Omit<TelemetryContext, 'verifiedWallet'> {\n /** Verified wallet address from SIWX authentication */\n verifiedWallet: string;\n}\n\ntype SiwxHandler = (request: NextRequest, ctx: SiwxTelemetryContext) => Promise<NextResponse>;\n\n/**\n * Wrap a Next.js route handler with SIWX verification + telemetry.\n *\n * Verifies the SIGN-IN-WITH-X header and sets the verified wallet automatically.\n * If no SIWX header is present, returns a 402 with SIWX challenge.\n * If verification fails, returns a 402 (matching x402 protocol convention).\n */\nexport function withSiwxTelemetry(handler: SiwxHandler) {\n return withTelemetry(async (request: NextRequest, ctx: TelemetryContext) => {\n const header = request.headers.get('SIGN-IN-WITH-X') ?? request.headers.get('sign-in-with-x');\n\n if (!header) {\n return buildSiwxChallengeResponse(request);\n }\n\n const payload = parseSIWxHeader(header);\n\n const validation = await validateSIWxMessage(payload, request.url);\n if (!validation.valid) {\n return NextResponse.json(\n { success: false, error: `SIWX validation failed: ${validation.error}` },\n { status: 402 },\n );\n }\n\n const verification = await verifySIWxSignature(payload);\n if (!verification.valid || !verification.address) {\n return NextResponse.json(\n { success: false, error: 'SIWX signature verification failed' },\n { status: 402 },\n );\n }\n\n const walletAddress = verification.address.toLowerCase();\n ctx.setVerifiedWallet(walletAddress);\n\n return handler(request, {\n ...ctx,\n verifiedWallet: walletAddress,\n } as SiwxTelemetryContext);\n });\n}\n\n/**\n * Build a 402 response with SIWX challenge.\n */\nfunction buildSiwxChallengeResponse(request: NextRequest): NextResponse {\n const url = new URL(request.url);\n const nonce = randomBytes(16).toString('hex');\n const issuedAt = new Date().toISOString();\n const expirationTime = new Date(Date.now() + 300_000).toISOString();\n\n const paymentRequired = {\n x402Version: 2,\n error: 'SIWX authentication required',\n resource: {\n url: request.url,\n description: 'SIWX-protected endpoint',\n mimeType: 'application/json',\n },\n accepts: [\n {\n scheme: 'exact' as const,\n network: 'eip155:8453' as const,\n asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n amount: '0',\n payTo: '0x0000000000000000000000000000000000000000',\n maxTimeoutSeconds: 300,\n extra: {},\n },\n ],\n extensions: {\n 'sign-in-with-x': {\n info: {\n domain: url.hostname,\n uri: request.url,\n version: '1',\n nonce,\n issuedAt,\n expirationTime,\n statement: 'Sign in to verify your wallet identity',\n resources: [request.url],\n },\n supportedChains: [{ chainId: 'eip155:8453', type: 'eip191' }],\n schema: buildSIWxSchema(),\n },\n },\n };\n\n const encoded = encodePaymentRequiredHeader(paymentRequired);\n\n return new NextResponse(JSON.stringify(paymentRequired), {\n status: 402,\n headers: {\n 'Content-Type': 'application/json',\n 'PAYMENT-REQUIRED': encoded,\n },\n });\n}\n"]}
package/dist/siwx.mjs ADDED
@@ -0,0 +1,99 @@
1
+ import {
2
+ withTelemetry
3
+ } from "./chunk-5JJYROO4.mjs";
4
+ import "./chunk-MJIU4ZVL.mjs";
5
+ import "./chunk-V553T6WE.mjs";
6
+
7
+ // src/siwx.ts
8
+ import { NextResponse } from "next/server";
9
+ import { randomBytes } from "crypto";
10
+ import {
11
+ parseSIWxHeader,
12
+ validateSIWxMessage,
13
+ verifySIWxSignature,
14
+ buildSIWxSchema
15
+ } from "@x402/extensions/sign-in-with-x";
16
+ import { encodePaymentRequiredHeader } from "@x402/core/http";
17
+ function withSiwxTelemetry(handler) {
18
+ return withTelemetry(async (request, ctx) => {
19
+ const header = request.headers.get("SIGN-IN-WITH-X") ?? request.headers.get("sign-in-with-x");
20
+ if (!header) {
21
+ return buildSiwxChallengeResponse(request);
22
+ }
23
+ const payload = parseSIWxHeader(header);
24
+ const validation = await validateSIWxMessage(payload, request.url);
25
+ if (!validation.valid) {
26
+ return NextResponse.json(
27
+ { success: false, error: `SIWX validation failed: ${validation.error}` },
28
+ { status: 402 }
29
+ );
30
+ }
31
+ const verification = await verifySIWxSignature(payload);
32
+ if (!verification.valid || !verification.address) {
33
+ return NextResponse.json(
34
+ { success: false, error: "SIWX signature verification failed" },
35
+ { status: 402 }
36
+ );
37
+ }
38
+ const walletAddress = verification.address.toLowerCase();
39
+ ctx.setVerifiedWallet(walletAddress);
40
+ return handler(request, {
41
+ ...ctx,
42
+ verifiedWallet: walletAddress
43
+ });
44
+ });
45
+ }
46
+ function buildSiwxChallengeResponse(request) {
47
+ const url = new URL(request.url);
48
+ const nonce = randomBytes(16).toString("hex");
49
+ const issuedAt = (/* @__PURE__ */ new Date()).toISOString();
50
+ const expirationTime = new Date(Date.now() + 3e5).toISOString();
51
+ const paymentRequired = {
52
+ x402Version: 2,
53
+ error: "SIWX authentication required",
54
+ resource: {
55
+ url: request.url,
56
+ description: "SIWX-protected endpoint",
57
+ mimeType: "application/json"
58
+ },
59
+ accepts: [
60
+ {
61
+ scheme: "exact",
62
+ network: "eip155:8453",
63
+ asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
64
+ amount: "0",
65
+ payTo: "0x0000000000000000000000000000000000000000",
66
+ maxTimeoutSeconds: 300,
67
+ extra: {}
68
+ }
69
+ ],
70
+ extensions: {
71
+ "sign-in-with-x": {
72
+ info: {
73
+ domain: url.hostname,
74
+ uri: request.url,
75
+ version: "1",
76
+ nonce,
77
+ issuedAt,
78
+ expirationTime,
79
+ statement: "Sign in to verify your wallet identity",
80
+ resources: [request.url]
81
+ },
82
+ supportedChains: [{ chainId: "eip155:8453", type: "eip191" }],
83
+ schema: buildSIWxSchema()
84
+ }
85
+ }
86
+ };
87
+ const encoded = encodePaymentRequiredHeader(paymentRequired);
88
+ return new NextResponse(JSON.stringify(paymentRequired), {
89
+ status: 402,
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ "PAYMENT-REQUIRED": encoded
93
+ }
94
+ });
95
+ }
96
+ export {
97
+ withSiwxTelemetry
98
+ };
99
+ //# sourceMappingURL=siwx.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/siwx.ts"],"sourcesContent":["/**\n * SIWX telemetry wrapper — composes SIWX verification with telemetry.\n * One-liner for routes that need wallet auth + telemetry.\n *\n * Delegates SIWX verification to @x402/extensions/sign-in-with-x.\n * This package does NOT implement SIWX itself.\n *\n * Import from '@agentcash/telemetry/siwx'.\n * Requires peer dep: @x402/extensions\n */\n\nimport { type NextRequest, NextResponse } from 'next/server';\nimport { randomBytes } from 'crypto';\nimport {\n parseSIWxHeader,\n validateSIWxMessage,\n verifySIWxSignature,\n buildSIWxSchema,\n} from '@x402/extensions/sign-in-with-x';\nimport { encodePaymentRequiredHeader } from '@x402/core/http';\nimport type { TelemetryContext } from './types';\nimport { withTelemetry } from './telemetry';\n\nexport type { SiwxTelemetryContext };\n\ninterface SiwxTelemetryContext extends Omit<TelemetryContext, 'verifiedWallet'> {\n /** Verified wallet address from SIWX authentication */\n verifiedWallet: string;\n}\n\ntype SiwxHandler = (request: NextRequest, ctx: SiwxTelemetryContext) => Promise<NextResponse>;\n\n/**\n * Wrap a Next.js route handler with SIWX verification + telemetry.\n *\n * Verifies the SIGN-IN-WITH-X header and sets the verified wallet automatically.\n * If no SIWX header is present, returns a 402 with SIWX challenge.\n * If verification fails, returns a 402 (matching x402 protocol convention).\n */\nexport function withSiwxTelemetry(handler: SiwxHandler) {\n return withTelemetry(async (request: NextRequest, ctx: TelemetryContext) => {\n const header = request.headers.get('SIGN-IN-WITH-X') ?? request.headers.get('sign-in-with-x');\n\n if (!header) {\n return buildSiwxChallengeResponse(request);\n }\n\n const payload = parseSIWxHeader(header);\n\n const validation = await validateSIWxMessage(payload, request.url);\n if (!validation.valid) {\n return NextResponse.json(\n { success: false, error: `SIWX validation failed: ${validation.error}` },\n { status: 402 },\n );\n }\n\n const verification = await verifySIWxSignature(payload);\n if (!verification.valid || !verification.address) {\n return NextResponse.json(\n { success: false, error: 'SIWX signature verification failed' },\n { status: 402 },\n );\n }\n\n const walletAddress = verification.address.toLowerCase();\n ctx.setVerifiedWallet(walletAddress);\n\n return handler(request, {\n ...ctx,\n verifiedWallet: walletAddress,\n } as SiwxTelemetryContext);\n });\n}\n\n/**\n * Build a 402 response with SIWX challenge.\n */\nfunction buildSiwxChallengeResponse(request: NextRequest): NextResponse {\n const url = new URL(request.url);\n const nonce = randomBytes(16).toString('hex');\n const issuedAt = new Date().toISOString();\n const expirationTime = new Date(Date.now() + 300_000).toISOString();\n\n const paymentRequired = {\n x402Version: 2,\n error: 'SIWX authentication required',\n resource: {\n url: request.url,\n description: 'SIWX-protected endpoint',\n mimeType: 'application/json',\n },\n accepts: [\n {\n scheme: 'exact' as const,\n network: 'eip155:8453' as const,\n asset: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',\n amount: '0',\n payTo: '0x0000000000000000000000000000000000000000',\n maxTimeoutSeconds: 300,\n extra: {},\n },\n ],\n extensions: {\n 'sign-in-with-x': {\n info: {\n domain: url.hostname,\n uri: request.url,\n version: '1',\n nonce,\n issuedAt,\n expirationTime,\n statement: 'Sign in to verify your wallet identity',\n resources: [request.url],\n },\n supportedChains: [{ chainId: 'eip155:8453', type: 'eip191' }],\n schema: buildSIWxSchema(),\n },\n },\n };\n\n const encoded = encodePaymentRequiredHeader(paymentRequired);\n\n return new NextResponse(JSON.stringify(paymentRequired), {\n status: 402,\n headers: {\n 'Content-Type': 'application/json',\n 'PAYMENT-REQUIRED': encoded,\n },\n });\n}\n"],"mappings":";;;;;;;AAWA,SAA2B,oBAAoB;AAC/C,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mCAAmC;AAoBrC,SAAS,kBAAkB,SAAsB;AACtD,SAAO,cAAc,OAAO,SAAsB,QAA0B;AAC1E,UAAM,SAAS,QAAQ,QAAQ,IAAI,gBAAgB,KAAK,QAAQ,QAAQ,IAAI,gBAAgB;AAE5F,QAAI,CAAC,QAAQ;AACX,aAAO,2BAA2B,OAAO;AAAA,IAC3C;AAEA,UAAM,UAAU,gBAAgB,MAAM;AAEtC,UAAM,aAAa,MAAM,oBAAoB,SAAS,QAAQ,GAAG;AACjE,QAAI,CAAC,WAAW,OAAO;AACrB,aAAO,aAAa;AAAA,QAClB,EAAE,SAAS,OAAO,OAAO,2BAA2B,WAAW,KAAK,GAAG;AAAA,QACvE,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,UAAM,eAAe,MAAM,oBAAoB,OAAO;AACtD,QAAI,CAAC,aAAa,SAAS,CAAC,aAAa,SAAS;AAChD,aAAO,aAAa;AAAA,QAClB,EAAE,SAAS,OAAO,OAAO,qCAAqC;AAAA,QAC9D,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAEA,UAAM,gBAAgB,aAAa,QAAQ,YAAY;AACvD,QAAI,kBAAkB,aAAa;AAEnC,WAAO,QAAQ,SAAS;AAAA,MACtB,GAAG;AAAA,MACH,gBAAgB;AAAA,IAClB,CAAyB;AAAA,EAC3B,CAAC;AACH;AAKA,SAAS,2BAA2B,SAAoC;AACtE,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAC/B,QAAM,QAAQ,YAAY,EAAE,EAAE,SAAS,KAAK;AAC5C,QAAM,YAAW,oBAAI,KAAK,GAAE,YAAY;AACxC,QAAM,iBAAiB,IAAI,KAAK,KAAK,IAAI,IAAI,GAAO,EAAE,YAAY;AAElE,QAAM,kBAAkB;AAAA,IACtB,aAAa;AAAA,IACb,OAAO;AAAA,IACP,UAAU;AAAA,MACR,KAAK,QAAQ;AAAA,MACb,aAAa;AAAA,MACb,UAAU;AAAA,IACZ;AAAA,IACA,SAAS;AAAA,MACP;AAAA,QACE,QAAQ;AAAA,QACR,SAAS;AAAA,QACT,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,mBAAmB;AAAA,QACnB,OAAO,CAAC;AAAA,MACV;AAAA,IACF;AAAA,IACA,YAAY;AAAA,MACV,kBAAkB;AAAA,QAChB,MAAM;AAAA,UACJ,QAAQ,IAAI;AAAA,UACZ,KAAK,QAAQ;AAAA,UACb,SAAS;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,WAAW;AAAA,UACX,WAAW,CAAC,QAAQ,GAAG;AAAA,QACzB;AAAA,QACA,iBAAiB,CAAC,EAAE,SAAS,eAAe,MAAM,SAAS,CAAC;AAAA,QAC5D,QAAQ,gBAAgB;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,4BAA4B,eAAe;AAE3D,SAAO,IAAI,aAAa,KAAK,UAAU,eAAe,GAAG;AAAA,IACvD,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,oBAAoB;AAAA,IACtB;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * ClickHouse row type for mcp_resource_invocations table.
3
+ * This is the real contract — not the DDL.
4
+ */
5
+ interface McpResourceInvocation {
6
+ id: string;
7
+ x_wallet_address: string | null;
8
+ x_client_id: string | null;
9
+ session_id: string | null;
10
+ verified_wallet_address: string | null;
11
+ method: string;
12
+ route: string;
13
+ origin: string;
14
+ referer: string | null;
15
+ request_content_type: string | null;
16
+ request_headers: string | null;
17
+ request_body: string | null;
18
+ status_code: number;
19
+ status_text: string;
20
+ duration: number;
21
+ response_content_type: string | null;
22
+ response_headers: string | null;
23
+ response_body: string | null;
24
+ payment_protocol: string | null;
25
+ payment_amount: string | null;
26
+ payment_network: string | null;
27
+ payment_tx_hash: string | null;
28
+ created_at: Date;
29
+ }
30
+ /**
31
+ * Telemetry context passed to handler functions.
32
+ */
33
+ interface TelemetryContext {
34
+ /** Wallet address from X-Wallet-Address header (lowercased) */
35
+ walletAddress: string | null;
36
+ /** Client ID from X-Client-ID header */
37
+ clientId: string | null;
38
+ /** Session ID from X-Session-ID header */
39
+ sessionId: string | null;
40
+ /** Verified wallet address (auto-extracted from x402 payment, or set manually) */
41
+ verifiedWallet: string | null;
42
+ /** Manually set the verified wallet address (for SIWX, API-key, or other auth) */
43
+ setVerifiedWallet: (address: string) => void;
44
+ }
45
+ /**
46
+ * ClickHouse connection config for initTelemetry.
47
+ */
48
+ interface TelemetryConfig {
49
+ clickhouse: {
50
+ url: string;
51
+ database?: string;
52
+ username?: string;
53
+ password?: string;
54
+ };
55
+ /** Server's own origin URL (e.g., 'https://enrichx402.com'). Auto-detected from request if not set. */
56
+ origin?: string;
57
+ /** If true, pings ClickHouse on init and logs the result. Never throws or blocks. */
58
+ verify?: boolean;
59
+ }
60
+
61
+ export type { McpResourceInvocation as M, TelemetryConfig as T, TelemetryContext as a };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * ClickHouse row type for mcp_resource_invocations table.
3
+ * This is the real contract — not the DDL.
4
+ */
5
+ interface McpResourceInvocation {
6
+ id: string;
7
+ x_wallet_address: string | null;
8
+ x_client_id: string | null;
9
+ session_id: string | null;
10
+ verified_wallet_address: string | null;
11
+ method: string;
12
+ route: string;
13
+ origin: string;
14
+ referer: string | null;
15
+ request_content_type: string | null;
16
+ request_headers: string | null;
17
+ request_body: string | null;
18
+ status_code: number;
19
+ status_text: string;
20
+ duration: number;
21
+ response_content_type: string | null;
22
+ response_headers: string | null;
23
+ response_body: string | null;
24
+ payment_protocol: string | null;
25
+ payment_amount: string | null;
26
+ payment_network: string | null;
27
+ payment_tx_hash: string | null;
28
+ created_at: Date;
29
+ }
30
+ /**
31
+ * Telemetry context passed to handler functions.
32
+ */
33
+ interface TelemetryContext {
34
+ /** Wallet address from X-Wallet-Address header (lowercased) */
35
+ walletAddress: string | null;
36
+ /** Client ID from X-Client-ID header */
37
+ clientId: string | null;
38
+ /** Session ID from X-Session-ID header */
39
+ sessionId: string | null;
40
+ /** Verified wallet address (auto-extracted from x402 payment, or set manually) */
41
+ verifiedWallet: string | null;
42
+ /** Manually set the verified wallet address (for SIWX, API-key, or other auth) */
43
+ setVerifiedWallet: (address: string) => void;
44
+ }
45
+ /**
46
+ * ClickHouse connection config for initTelemetry.
47
+ */
48
+ interface TelemetryConfig {
49
+ clickhouse: {
50
+ url: string;
51
+ database?: string;
52
+ username?: string;
53
+ password?: string;
54
+ };
55
+ /** Server's own origin URL (e.g., 'https://enrichx402.com'). Auto-detected from request if not set. */
56
+ origin?: string;
57
+ /** If true, pings ClickHouse on init and logs the result. Never throws or blocks. */
58
+ verify?: boolean;
59
+ }
60
+
61
+ export type { McpResourceInvocation as M, TelemetryConfig as T, TelemetryContext as a };
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@agentcash/telemetry",
3
+ "version": "0.0.0-pr-16-20260520161400",
4
+ "description": "ClickHouse telemetry plugin for @agentcash/router. Logs request lifecycle, payments, settlements, and provider quota to ClickHouse.",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./siwx": {
15
+ "types": "./dist/siwx.d.ts",
16
+ "import": "./dist/siwx.mjs",
17
+ "require": "./dist/siwx.js"
18
+ },
19
+ "./builder": {
20
+ "types": "./dist/builder.d.ts",
21
+ "import": "./dist/builder.mjs",
22
+ "require": "./dist/builder.js"
23
+ },
24
+ "./plugin": {
25
+ "types": "./dist/router-plugin.d.ts",
26
+ "import": "./dist/router-plugin.mjs",
27
+ "require": "./dist/router-plugin.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "keywords": [
34
+ "x402",
35
+ "agentcash",
36
+ "telemetry",
37
+ "clickhouse",
38
+ "payments"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/Merit-Systems/agentcash-telemetry"
43
+ },
44
+ "license": "MIT",
45
+ "publishConfig": {
46
+ "access": "public"
47
+ },
48
+ "peerDependencies": {
49
+ "@clickhouse/client": "^1.12.0",
50
+ "@x402/core": "^2.2.0",
51
+ "@x402/extensions": "^2.3.0",
52
+ "@x402/next": "^2.2.0",
53
+ "next": ">=15.0.0",
54
+ "zod": "^4.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "@x402/next": {
58
+ "optional": true
59
+ },
60
+ "@x402/extensions": {
61
+ "optional": true
62
+ },
63
+ "zod": {
64
+ "optional": true
65
+ }
66
+ },
67
+ "devDependencies": {
68
+ "@changesets/cli": "^2.29.8",
69
+ "@clickhouse/client": "^1.16.0",
70
+ "@eslint/js": "^9.0.0",
71
+ "@x402/core": "^2.2.0",
72
+ "@x402/extensions": "^2.3.0",
73
+ "@x402/next": "^2.2.0",
74
+ "eslint": "^9.0.0",
75
+ "next": "16.0.10",
76
+ "prettier": "^3.8.1",
77
+ "tsup": "^8.0.0",
78
+ "typescript": "^5.7.0",
79
+ "typescript-eslint": "^8.55.0",
80
+ "vitest": "^4.0.18",
81
+ "zod": "^4.1.13"
82
+ },
83
+ "scripts": {
84
+ "build": "tsup",
85
+ "lint": "eslint src/",
86
+ "lint:fix": "eslint src/ --fix",
87
+ "format": "prettier --write 'src/**/*.ts' '*.json' '*.mjs'",
88
+ "format:check": "prettier --check 'src/**/*.ts' '*.json' '*.mjs'",
89
+ "typecheck": "tsc --noEmit",
90
+ "test": "vitest run",
91
+ "check": "npm run format:check && npm run lint && npm run typecheck && npm run build && npm test",
92
+ "changeset": "changeset"
93
+ }
94
+ }