@agentronics/sdk 0.6.0 → 0.7.0
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/chunk-3WPDIMJP.js +18 -0
- package/dist/chunk-3WPDIMJP.js.map +1 -0
- package/dist/{chunk-X7NFMFN6.js → chunk-6QQS26AP.js} +264 -69
- package/dist/chunk-6QQS26AP.js.map +1 -0
- package/dist/chunk-BPDWJCPY.js +2 -0
- package/dist/chunk-BPDWJCPY.js.map +1 -0
- package/dist/index.cjs +8 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -7
- package/dist/index.d.ts +39 -7
- package/dist/index.global.js +8 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/{init-only-7f8_LQAI.d.ts → init-only-C80qhujz.d.ts} +227 -30
- package/dist/{init-only-Cwll8MGz.d.cts → init-only-s9E9bVC0.d.cts} +227 -30
- package/dist/init-only.cjs +8 -7
- package/dist/init-only.cjs.map +1 -1
- package/dist/init-only.d.cts +2 -2
- package/dist/init-only.d.ts +2 -2
- package/dist/init-only.global.js +8 -7
- package/dist/init-only.global.js.map +1 -1
- package/dist/init-only.js +1 -1
- package/dist/lite.cjs +1 -1
- package/dist/lite.cjs.map +1 -1
- package/dist/lite.d.cts +2 -2
- package/dist/lite.d.ts +2 -2
- package/dist/lite.global.js +1 -1
- package/dist/lite.global.js.map +1 -1
- package/dist/lite.js +1 -1
- package/dist/middleware-Dd2T772u.d.cts +429 -0
- package/dist/middleware-Dd2T772u.d.ts +429 -0
- package/dist/next.cjs +239 -64
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +2 -2
- package/dist/next.d.ts +2 -2
- package/dist/next.js +2 -2
- package/dist/server.cjs +361 -66
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +103 -308
- package/dist/server.d.ts +103 -308
- package/dist/server.js +93 -1
- package/dist/server.js.map +1 -1
- package/dist/webmcp-BgKzHeQ3.d.cts +97 -0
- package/dist/webmcp-BgKzHeQ3.d.ts +97 -0
- package/package.json +4 -4
- package/dist/chunk-LLD3Y2LZ.js +0 -2
- package/dist/chunk-LLD3Y2LZ.js.map +0 -1
- package/dist/chunk-X7NFMFN6.js.map +0 -1
- package/dist/chunk-Y7JYD5RA.js +0 -17
- package/dist/chunk-Y7JYD5RA.js.map +0 -1
- package/dist/webmcp-C4ikhM4g.d.cts +0 -12
- package/dist/webmcp-C4ikhM4g.d.ts +0 -12
package/dist/init-only.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{
|
|
1
|
+
export{aa as init}from'./chunk-3WPDIMJP.js';import'./chunk-BPDWJCPY.js';//# sourceMappingURL=init-only.js.map
|
|
2
2
|
//# sourceMappingURL=init-only.js.map
|
package/dist/lite.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var s="0.1.2";var y=()=>{if(typeof navigator>"u")return null;let t=navigator.modelContext;return !t||typeof t!="object"?null:t.vendor||t.client?t:null},r=async(t={})=>{let{pollMs:e=500}=t,o=Date.now();for(;;){let c=y();if(c)return f(c);if(Date.now()-o>=e)return null;await new Promise(u=>setTimeout(u,50));}},p=()=>({class:"webmcp",trust:"detected",confidence:1,userAgent:typeof navigator>"u"?null:navigator.userAgent,detectionVersion:s}),f=t=>({...p(),vendor:t.vendor??t.client??null,signals:{webmcp:true,source:"legacy-extension",toolCount:Array.isArray(t.tools)?t.tools.length:0}});var d="agtx_pk_",m="agtx_sk_",L=({publishableKey:t,siteId:e="default",debug:o=false})=>{if(t.startsWith(m))throw new Error("A secret key was passed to Agentronics lite init(). Browser code must use a publishable key (agtx_pk_*).");if(!t.startsWith(d))throw new Error(`Agentronics lite init() expected a key starting with "${d}".`);return Object.freeze({publishableKey:t,siteId:e,debug:o,detectWebMcp:r})},W="0.1.0-lite";exports.VERSION=W;exports.detectWebMcp=r;exports.init=L;//# sourceMappingURL=lite.cjs.map
|
|
2
2
|
//# sourceMappingURL=lite.cjs.map
|
package/dist/lite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts","../src/detection/webmcp.ts","../src/lite.ts"],"names":["SDK_VERSION","
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/detection/webmcp.ts","../src/lite.ts"],"names":["SDK_VERSION","readLegacyInjected","value","detectWebMcp","options","pollMs","start","legacy","fromLegacy","resolve","base","ctx","PUBLISHABLE_KEY_PREFIX","SECRET_KEY_PREFIX","init","publishableKey","siteId","debug","VERSION"],"mappings":"aAKO,IAAMA,CAAAA,CAAc,OAAA,CCkB3B,IAAMC,CAAAA,CAAqB,IAAoC,CAC7D,GAAI,OAAO,SAAA,CAAc,IAAa,OAAO,IAAA,CAC7C,IAAMC,CAAAA,CAAS,SAAA,CAAkE,YAAA,CACjF,OAAI,CAACA,GAAS,OAAOA,CAAAA,EAAU,QAAA,CAAiB,IAAA,CACzCA,EAAM,MAAA,EAAUA,CAAAA,CAAM,MAAA,CAASA,CAAAA,CAAQ,IAChD,CAAA,CAaaC,CAAAA,CAAe,MAC1BC,CAAAA,CAA+B,EAAC,GACE,CAClC,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAS,GAAI,EAAID,CAAAA,CACnBE,CAAAA,CAAQ,IAAA,CAAK,GAAA,GAEnB,OAAa,CAGX,IAAMC,CAAAA,CAASN,GAAmB,CAClC,GAAIM,CAAAA,CAAQ,OAAOC,CAAAA,CAAWD,CAAM,CAAA,CACpC,GAAI,KAAK,GAAA,EAAI,CAAID,CAAAA,EAASD,CAAAA,CAAQ,OAAO,IAAA,CACzC,MAAM,IAAI,OAAA,CAASI,GAAY,UAAA,CAAWA,CAAAA,CAAS,EAAE,CAAC,EACxD,CACF,CAAA,CAEMC,CAAAA,CAAO,KAAkD,CAC7D,KAAA,CAAO,QAAA,CACP,KAAA,CAAO,WACP,UAAA,CAAY,CAAA,CACZ,SAAA,CAAW,OAAO,UAAc,GAAA,CAAc,IAAA,CAAO,SAAA,CAAU,SAAA,CAC/D,gBAAA,CAAkBV,CACpB,CAAA,CAAA,CAQMQ,CAAAA,CAAcG,CAAAA,GAA+C,CACjE,GAAGD,CAAAA,EAAK,CACR,MAAA,CAAQC,CAAAA,CAAI,QAAUA,CAAAA,CAAI,MAAA,EAAU,IAAA,CACpC,OAAA,CAAS,CACP,MAAA,CAAQ,IAAA,CACR,MAAA,CAAQ,mBACR,SAAA,CAAW,KAAA,CAAM,OAAA,CAAQA,CAAAA,CAAI,KAAK,CAAA,CAAIA,CAAAA,CAAI,KAAA,CAAM,MAAA,CAAS,CAC3D,CACF,CAAA,EC5EA,IAAMC,CAAAA,CAAyB,UAAA,CACzBC,CAAAA,CAAoB,UAAA,CAebC,CAAAA,CAAO,CAAC,CACnB,cAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,EAAS,SAAA,CACT,KAAA,CAAAC,CAAAA,CAAQ,KACV,IAA8C,CAC5C,GAAIF,CAAAA,CAAe,UAAA,CAAWF,CAAiB,CAAA,CAC7C,MAAM,IAAI,MACR,0GACF,CAAA,CAEF,GAAI,CAACE,EAAe,UAAA,CAAWH,CAAsB,CAAA,CACnD,MAAM,IAAI,KAAA,CAAM,CAAA,sDAAA,EAAyDA,CAAsB,CAAA,EAAA,CAAI,EAGrG,OAAO,MAAA,CAAO,MAAA,CAAO,CACnB,eAAAG,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,KAAA,CAAAC,EACA,YAAA,CAAAd,CACF,CAAC,CACH,EAKae,CAAAA,CAAU","file":"lite.cjs","sourcesContent":["// Single source of truth for the SDK build version, surfaced on every\n// AgentIdentity as `detectionVersion` so traces can be filtered by SDK\n// generation. tsup inlines a pkg-version replacement at build time;\n// the literal here is the dev/test fallback. Bump this when you cut a\n// new SDK release.\nexport const SDK_VERSION = '0.1.2'\n","import type { AgentIdentity } from '@agentronics/protocol'\nimport { SDK_VERSION } from '../version.js'\nimport { lastWebMcpActivity, resolveModelContext, type WebMcpActivity } from '../tools/modelContext.js'\n\n/**\n * WebMCP agent detection.\n *\n * `document.modelContext` exists for every visitor of a WebMCP-capable browser,\n * so its presence alone is NOT an agent — it only means the page can serve\n * tools. An agent is detected once it acts: a `toolactivated` event or a tool\n * call through the ModelContext (both recorded by the WebMCP adapter).\n *\n * Old browser-extension polyfills injected `navigator.modelContext` with a\n * `vendor`/`client` field only while an agent was attached; that is still\n * honoured as an agent signal.\n */\n\ninterface LegacyInjectedContext {\n client?: string\n vendor?: string\n tools?: unknown[]\n}\n\nconst readLegacyInjected = (): LegacyInjectedContext | null => {\n if (typeof navigator === 'undefined') return null\n const value = (navigator as unknown as { modelContext?: LegacyInjectedContext }).modelContext\n if (!value || typeof value !== 'object') return null\n return value.vendor || value.client ? value : null\n}\n\nexport interface DetectWebMcpOptions {\n /**\n * Wait up to this many milliseconds for an agent to act (or an extension to\n * inject itself). 0 reads once and returns immediately.\n */\n pollMs?: number\n}\n\n/** Whether this page can serve WebMCP tools, and through which surface. */\nexport const webMcpSupport = () => resolveModelContext()?.source ?? null\n\nexport const detectWebMcp = async (\n options: DetectWebMcpOptions = {}\n): Promise<AgentIdentity | null> => {\n const { pollMs = 500 } = options\n const start = Date.now()\n\n while (true) {\n const activity = lastWebMcpActivity()\n if (activity) return fromActivity(activity)\n const legacy = readLegacyInjected()\n if (legacy) return fromLegacy(legacy)\n if (Date.now() - start >= pollMs) return null\n await new Promise((resolve) => setTimeout(resolve, 50))\n }\n}\n\nconst base = (): Omit<AgentIdentity, 'vendor' | 'signals'> => ({\n class: 'webmcp',\n trust: 'detected',\n confidence: 1,\n userAgent: typeof navigator === 'undefined' ? null : navigator.userAgent,\n detectionVersion: SDK_VERSION,\n})\n\nconst fromActivity = (activity: WebMcpActivity): AgentIdentity => ({\n ...base(),\n vendor: null,\n signals: { webmcp: true, source: webMcpSupport(), event: activity.type, tool: activity.toolName },\n})\n\nconst fromLegacy = (ctx: LegacyInjectedContext): AgentIdentity => ({\n ...base(),\n vendor: ctx.vendor ?? ctx.client ?? null,\n signals: {\n webmcp: true,\n source: 'legacy-extension',\n toolCount: Array.isArray(ctx.tools) ? ctx.tools.length : 0,\n },\n})\n","import type { AgentIdentity } from '@agentronics/protocol'\nimport { detectWebMcp, type DetectWebMcpOptions } from './detection/webmcp.js'\n\nconst PUBLISHABLE_KEY_PREFIX = 'agtx_pk_'\nconst SECRET_KEY_PREFIX = 'agtx_sk_'\n\nexport interface LiteInitOptions {\n publishableKey: string\n siteId?: string\n debug?: boolean\n}\n\nexport interface LiteAgentronicsClient {\n readonly publishableKey: string\n readonly siteId: string\n readonly debug: boolean\n detectWebMcp(options?: DetectWebMcpOptions): Promise<AgentIdentity | null>\n}\n\nexport const init = ({\n publishableKey,\n siteId = 'default',\n debug = false,\n}: LiteInitOptions): LiteAgentronicsClient => {\n if (publishableKey.startsWith(SECRET_KEY_PREFIX)) {\n throw new Error(\n 'A secret key was passed to Agentronics lite init(). Browser code must use a publishable key (agtx_pk_*).'\n )\n }\n if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {\n throw new Error(`Agentronics lite init() expected a key starting with \"${PUBLISHABLE_KEY_PREFIX}\".`)\n }\n\n return Object.freeze({\n publishableKey,\n siteId,\n debug,\n detectWebMcp,\n })\n}\n\nexport { detectWebMcp } from './detection/webmcp.js'\nexport type { DetectWebMcpOptions } from './detection/webmcp.js'\n\nexport const VERSION = '0.1.0-lite'\n"]}
|
package/dist/lite.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentIdentity } from '@agentronics/protocol';
|
|
2
|
-
import { D as DetectWebMcpOptions } from './webmcp-
|
|
3
|
-
export { d as detectWebMcp } from './webmcp-
|
|
2
|
+
import { D as DetectWebMcpOptions } from './webmcp-BgKzHeQ3.cjs';
|
|
3
|
+
export { d as detectWebMcp } from './webmcp-BgKzHeQ3.cjs';
|
|
4
4
|
|
|
5
5
|
interface LiteInitOptions {
|
|
6
6
|
publishableKey: string;
|
package/dist/lite.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentIdentity } from '@agentronics/protocol';
|
|
2
|
-
import { D as DetectWebMcpOptions } from './webmcp-
|
|
3
|
-
export { d as detectWebMcp } from './webmcp-
|
|
2
|
+
import { D as DetectWebMcpOptions } from './webmcp-BgKzHeQ3.js';
|
|
3
|
+
export { d as detectWebMcp } from './webmcp-BgKzHeQ3.js';
|
|
4
4
|
|
|
5
5
|
interface LiteInitOptions {
|
|
6
6
|
publishableKey: string;
|
package/dist/lite.global.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Agentronics=(function(exports){'use strict';var
|
|
1
|
+
var Agentronics=(function(exports){'use strict';var s="0.1.2";var y=()=>{if(typeof navigator>"u")return null;let t=navigator.modelContext;return !t||typeof t!="object"?null:t.vendor||t.client?t:null},r=async(t={})=>{let{pollMs:e=500}=t,o=Date.now();for(;;){let c=y();if(c)return f(c);if(Date.now()-o>=e)return null;await new Promise(u=>setTimeout(u,50));}},p=()=>({class:"webmcp",trust:"detected",confidence:1,userAgent:typeof navigator>"u"?null:navigator.userAgent,detectionVersion:s}),f=t=>({...p(),vendor:t.vendor??t.client??null,signals:{webmcp:true,source:"legacy-extension",toolCount:Array.isArray(t.tools)?t.tools.length:0}});var d="agtx_pk_",m="agtx_sk_",L=({publishableKey:t,siteId:e="default",debug:o=false})=>{if(t.startsWith(m))throw new Error("A secret key was passed to Agentronics lite init(). Browser code must use a publishable key (agtx_pk_*).");if(!t.startsWith(d))throw new Error(`Agentronics lite init() expected a key starting with "${d}".`);return Object.freeze({publishableKey:t,siteId:e,debug:o,detectWebMcp:r})},W="0.1.0-lite";exports.VERSION=W;exports.detectWebMcp=r;exports.init=L;return exports;})({});//# sourceMappingURL=lite.global.js.map
|
|
2
2
|
//# sourceMappingURL=lite.global.js.map
|
package/dist/lite.global.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts","../src/detection/webmcp.ts","../src/lite.ts"],"names":["SDK_VERSION","
|
|
1
|
+
{"version":3,"sources":["../src/version.ts","../src/detection/webmcp.ts","../src/lite.ts"],"names":["SDK_VERSION","readLegacyInjected","value","detectWebMcp","options","pollMs","start","legacy","fromLegacy","resolve","base","ctx","PUBLISHABLE_KEY_PREFIX","SECRET_KEY_PREFIX","init","publishableKey","siteId","debug","VERSION"],"mappings":"gDAKO,IAAMA,CAAAA,CAAc,OAAA,CCkB3B,IAAMC,CAAAA,CAAqB,IAAoC,CAC7D,GAAI,OAAO,SAAA,CAAc,IAAa,OAAO,IAAA,CAC7C,IAAMC,CAAAA,CAAS,SAAA,CAAkE,YAAA,CACjF,OAAI,CAACA,GAAS,OAAOA,CAAAA,EAAU,QAAA,CAAiB,IAAA,CACzCA,EAAM,MAAA,EAAUA,CAAAA,CAAM,MAAA,CAASA,CAAAA,CAAQ,IAChD,CAAA,CAaaC,CAAAA,CAAe,MAC1BC,CAAAA,CAA+B,EAAC,GACE,CAClC,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAS,GAAI,EAAID,CAAAA,CACnBE,CAAAA,CAAQ,IAAA,CAAK,GAAA,GAEnB,OAAa,CAGX,IAAMC,CAAAA,CAASN,GAAmB,CAClC,GAAIM,CAAAA,CAAQ,OAAOC,CAAAA,CAAWD,CAAM,CAAA,CACpC,GAAI,KAAK,GAAA,EAAI,CAAID,CAAAA,EAASD,CAAAA,CAAQ,OAAO,IAAA,CACzC,MAAM,IAAI,OAAA,CAASI,GAAY,UAAA,CAAWA,CAAAA,CAAS,EAAE,CAAC,EACxD,CACF,CAAA,CAEMC,CAAAA,CAAO,KAAkD,CAC7D,KAAA,CAAO,QAAA,CACP,KAAA,CAAO,WACP,UAAA,CAAY,CAAA,CACZ,SAAA,CAAW,OAAO,UAAc,GAAA,CAAc,IAAA,CAAO,SAAA,CAAU,SAAA,CAC/D,gBAAA,CAAkBV,CACpB,CAAA,CAAA,CAQMQ,CAAAA,CAAcG,CAAAA,GAA+C,CACjE,GAAGD,CAAAA,EAAK,CACR,MAAA,CAAQC,CAAAA,CAAI,QAAUA,CAAAA,CAAI,MAAA,EAAU,IAAA,CACpC,OAAA,CAAS,CACP,MAAA,CAAQ,IAAA,CACR,MAAA,CAAQ,mBACR,SAAA,CAAW,KAAA,CAAM,OAAA,CAAQA,CAAAA,CAAI,KAAK,CAAA,CAAIA,CAAAA,CAAI,KAAA,CAAM,MAAA,CAAS,CAC3D,CACF,CAAA,EC5EA,IAAMC,CAAAA,CAAyB,UAAA,CACzBC,CAAAA,CAAoB,UAAA,CAebC,CAAAA,CAAO,CAAC,CACnB,cAAA,CAAAC,CAAAA,CACA,MAAA,CAAAC,EAAS,SAAA,CACT,KAAA,CAAAC,CAAAA,CAAQ,KACV,IAA8C,CAC5C,GAAIF,CAAAA,CAAe,UAAA,CAAWF,CAAiB,CAAA,CAC7C,MAAM,IAAI,MACR,0GACF,CAAA,CAEF,GAAI,CAACE,EAAe,UAAA,CAAWH,CAAsB,CAAA,CACnD,MAAM,IAAI,KAAA,CAAM,CAAA,sDAAA,EAAyDA,CAAsB,CAAA,EAAA,CAAI,EAGrG,OAAO,MAAA,CAAO,MAAA,CAAO,CACnB,eAAAG,CAAAA,CACA,MAAA,CAAAC,CAAAA,CACA,KAAA,CAAAC,EACA,YAAA,CAAAd,CACF,CAAC,CACH,EAKae,CAAAA,CAAU","file":"lite.global.js","sourcesContent":["// Single source of truth for the SDK build version, surfaced on every\n// AgentIdentity as `detectionVersion` so traces can be filtered by SDK\n// generation. tsup inlines a pkg-version replacement at build time;\n// the literal here is the dev/test fallback. Bump this when you cut a\n// new SDK release.\nexport const SDK_VERSION = '0.1.2'\n","import type { AgentIdentity } from '@agentronics/protocol'\nimport { SDK_VERSION } from '../version.js'\nimport { lastWebMcpActivity, resolveModelContext, type WebMcpActivity } from '../tools/modelContext.js'\n\n/**\n * WebMCP agent detection.\n *\n * `document.modelContext` exists for every visitor of a WebMCP-capable browser,\n * so its presence alone is NOT an agent — it only means the page can serve\n * tools. An agent is detected once it acts: a `toolactivated` event or a tool\n * call through the ModelContext (both recorded by the WebMCP adapter).\n *\n * Old browser-extension polyfills injected `navigator.modelContext` with a\n * `vendor`/`client` field only while an agent was attached; that is still\n * honoured as an agent signal.\n */\n\ninterface LegacyInjectedContext {\n client?: string\n vendor?: string\n tools?: unknown[]\n}\n\nconst readLegacyInjected = (): LegacyInjectedContext | null => {\n if (typeof navigator === 'undefined') return null\n const value = (navigator as unknown as { modelContext?: LegacyInjectedContext }).modelContext\n if (!value || typeof value !== 'object') return null\n return value.vendor || value.client ? value : null\n}\n\nexport interface DetectWebMcpOptions {\n /**\n * Wait up to this many milliseconds for an agent to act (or an extension to\n * inject itself). 0 reads once and returns immediately.\n */\n pollMs?: number\n}\n\n/** Whether this page can serve WebMCP tools, and through which surface. */\nexport const webMcpSupport = () => resolveModelContext()?.source ?? null\n\nexport const detectWebMcp = async (\n options: DetectWebMcpOptions = {}\n): Promise<AgentIdentity | null> => {\n const { pollMs = 500 } = options\n const start = Date.now()\n\n while (true) {\n const activity = lastWebMcpActivity()\n if (activity) return fromActivity(activity)\n const legacy = readLegacyInjected()\n if (legacy) return fromLegacy(legacy)\n if (Date.now() - start >= pollMs) return null\n await new Promise((resolve) => setTimeout(resolve, 50))\n }\n}\n\nconst base = (): Omit<AgentIdentity, 'vendor' | 'signals'> => ({\n class: 'webmcp',\n trust: 'detected',\n confidence: 1,\n userAgent: typeof navigator === 'undefined' ? null : navigator.userAgent,\n detectionVersion: SDK_VERSION,\n})\n\nconst fromActivity = (activity: WebMcpActivity): AgentIdentity => ({\n ...base(),\n vendor: null,\n signals: { webmcp: true, source: webMcpSupport(), event: activity.type, tool: activity.toolName },\n})\n\nconst fromLegacy = (ctx: LegacyInjectedContext): AgentIdentity => ({\n ...base(),\n vendor: ctx.vendor ?? ctx.client ?? null,\n signals: {\n webmcp: true,\n source: 'legacy-extension',\n toolCount: Array.isArray(ctx.tools) ? ctx.tools.length : 0,\n },\n})\n","import type { AgentIdentity } from '@agentronics/protocol'\nimport { detectWebMcp, type DetectWebMcpOptions } from './detection/webmcp.js'\n\nconst PUBLISHABLE_KEY_PREFIX = 'agtx_pk_'\nconst SECRET_KEY_PREFIX = 'agtx_sk_'\n\nexport interface LiteInitOptions {\n publishableKey: string\n siteId?: string\n debug?: boolean\n}\n\nexport interface LiteAgentronicsClient {\n readonly publishableKey: string\n readonly siteId: string\n readonly debug: boolean\n detectWebMcp(options?: DetectWebMcpOptions): Promise<AgentIdentity | null>\n}\n\nexport const init = ({\n publishableKey,\n siteId = 'default',\n debug = false,\n}: LiteInitOptions): LiteAgentronicsClient => {\n if (publishableKey.startsWith(SECRET_KEY_PREFIX)) {\n throw new Error(\n 'A secret key was passed to Agentronics lite init(). Browser code must use a publishable key (agtx_pk_*).'\n )\n }\n if (!publishableKey.startsWith(PUBLISHABLE_KEY_PREFIX)) {\n throw new Error(`Agentronics lite init() expected a key starting with \"${PUBLISHABLE_KEY_PREFIX}\".`)\n }\n\n return Object.freeze({\n publishableKey,\n siteId,\n debug,\n detectWebMcp,\n })\n}\n\nexport { detectWebMcp } from './detection/webmcp.js'\nexport type { DetectWebMcpOptions } from './detection/webmcp.js'\n\nexport const VERSION = '0.1.0-lite'\n"]}
|
package/dist/lite.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {f}from'./chunk-BPDWJCPY.js';export{f as detectWebMcp}from'./chunk-BPDWJCPY.js';var i="agtx_pk_",r="agtx_sk_",c=({publishableKey:t,siteId:n="default",debug:o=false})=>{if(t.startsWith(r))throw new Error("A secret key was passed to Agentronics lite init(). Browser code must use a publishable key (agtx_pk_*).");if(!t.startsWith(i))throw new Error(`Agentronics lite init() expected a key starting with "${i}".`);return Object.freeze({publishableKey:t,siteId:n,debug:o,detectWebMcp:f})},p="0.1.0-lite";export{p as VERSION,c as init};//# sourceMappingURL=lite.js.map
|
|
2
2
|
//# sourceMappingURL=lite.js.map
|
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
import { TraceEvent } from '@agentronics/protocol';
|
|
2
|
+
|
|
3
|
+
type CrawlerCategory = 'ai' | 'search';
|
|
4
|
+
interface CrawlerSignature {
|
|
5
|
+
/** Stable vendor id, reported as identity.vendor. */
|
|
6
|
+
name: string;
|
|
7
|
+
category: CrawlerCategory;
|
|
8
|
+
/** Tested against navigator.userAgent. */
|
|
9
|
+
pattern: RegExp;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Published crawler IP ranges.
|
|
14
|
+
*
|
|
15
|
+
* Most AI crawlers (GPTBot, ChatGPT-User, PerplexityBot, …) don't support
|
|
16
|
+
* reverse-DNS verification — instead the vendor publishes the CIDR blocks its
|
|
17
|
+
* crawler uses as JSON (`{ prefixes: [{ ipv4Prefix } | { ipv6Prefix }] }`).
|
|
18
|
+
* A User-Agent claim plus a client IP inside the vendor's published ranges is
|
|
19
|
+
* a verified crawler. Unlike rDNS this needs only `fetch`, so it also works on
|
|
20
|
+
* edge runtimes.
|
|
21
|
+
*/
|
|
22
|
+
/** Vendor range lists, keyed by crawler signature name. Fixed, vendor-owned URLs. */
|
|
23
|
+
declare const PUBLISHED_IP_RANGES: Record<string, string[]>;
|
|
24
|
+
interface IpRangeOptions {
|
|
25
|
+
/** Static CIDR lists per crawler name; replaces the fetched lists for those names. */
|
|
26
|
+
ipRanges?: Record<string, string[]>;
|
|
27
|
+
/** Test seam. */
|
|
28
|
+
fetcher?: typeof fetch;
|
|
29
|
+
}
|
|
30
|
+
/** The CIDR list for a crawler, or null when the vendor publishes none. */
|
|
31
|
+
declare function rangesFor(name: string, options?: IpRangeOptions): Promise<string[] | null>;
|
|
32
|
+
/** True when `ip` (v4 or v6) falls inside `cidr`. Mismatched families never match. */
|
|
33
|
+
declare function ipInCidr(ip: string, cidr: string): boolean;
|
|
34
|
+
declare const ipInRanges: (ip: string, cidrs: string[]) => boolean;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Server-side crawler identification + verification.
|
|
38
|
+
*
|
|
39
|
+
* A User-Agent claim is trivially spoofable, so on its own it only makes a
|
|
40
|
+
* request "claimed". A claim becomes verified in one of two ways the vendor
|
|
41
|
+
* documents:
|
|
42
|
+
*
|
|
43
|
+
* 1. **Published IP ranges** — the client IP is inside the CIDR list the vendor
|
|
44
|
+
* publishes as JSON (OpenAI, Perplexity, Google, Bing, DuckDuckGo, Common
|
|
45
|
+
* Crawl). Needs only `fetch`, so it works on edge runtimes too.
|
|
46
|
+
* 2. **Forward-confirmed reverse DNS** — the IP's PTR name sits under the
|
|
47
|
+
* vendor's domain AND resolves back to the same IP (Google, Microsoft,
|
|
48
|
+
* Apple, Yandex, Baidu, Amazon). Needs Node DNS; on edge runtimes it
|
|
49
|
+
* degrades to "unverified".
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/** Vendors that document reverse-DNS verification, keyed by signature name. */
|
|
53
|
+
declare const RDNS_DOMAINS: Record<string, string[]>;
|
|
54
|
+
interface CrawlerClaim {
|
|
55
|
+
name: string;
|
|
56
|
+
category: CrawlerSignature['category'];
|
|
57
|
+
}
|
|
58
|
+
declare function classifyUserAgent(ua: string | null, signatures?: CrawlerSignature[]): CrawlerClaim | null;
|
|
59
|
+
/**
|
|
60
|
+
* Where the real client IP comes from. Platform headers are set by the edge
|
|
61
|
+
* and can't be spoofed by the caller; the leftmost X-Forwarded-For entry CAN,
|
|
62
|
+
* so it's never used by default.
|
|
63
|
+
*/
|
|
64
|
+
type ClientIpSource = 'auto' | 'cloudflare' | 'vercel' | ((request: Request) => string | null);
|
|
65
|
+
declare function clientIp(request: Request, source?: ClientIpSource): string | null;
|
|
66
|
+
interface DnsResolver {
|
|
67
|
+
reverse(ip: string): Promise<string[]>;
|
|
68
|
+
lookup(host: string): Promise<string[]>;
|
|
69
|
+
}
|
|
70
|
+
type CrawlerVerification = {
|
|
71
|
+
status: 'verified';
|
|
72
|
+
name: string;
|
|
73
|
+
host: string;
|
|
74
|
+
ip: string;
|
|
75
|
+
via: 'ip-range' | 'rdns';
|
|
76
|
+
} | {
|
|
77
|
+
status: 'unverified';
|
|
78
|
+
name: string;
|
|
79
|
+
reason: string;
|
|
80
|
+
};
|
|
81
|
+
declare function verifyCrawler(claim: CrawlerClaim, ip: string | null, resolver?: DnsResolver, ranges?: IpRangeOptions): Promise<CrawlerVerification>;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Structured Field Values for HTTP (RFC 9651) — the subset HTTP Message
|
|
85
|
+
* Signatures (RFC 9421) and Web Bot Auth need: Dictionaries, Inner Lists,
|
|
86
|
+
* Items, Parameters; bare items of type Integer, Decimal, String, Token,
|
|
87
|
+
* Byte Sequence and Boolean. Parsing is strict (invalid input throws), and
|
|
88
|
+
* serialization is canonical, which RFC 9421 relies on for `@signature-params`.
|
|
89
|
+
*/
|
|
90
|
+
declare class SfToken {
|
|
91
|
+
readonly value: string;
|
|
92
|
+
constructor(value: string);
|
|
93
|
+
}
|
|
94
|
+
declare class SfDecimal {
|
|
95
|
+
readonly value: number;
|
|
96
|
+
constructor(value: number);
|
|
97
|
+
}
|
|
98
|
+
type BareItem = string | number | boolean | Uint8Array | SfToken | SfDecimal;
|
|
99
|
+
type Params = Array<[string, BareItem]>;
|
|
100
|
+
interface Item {
|
|
101
|
+
value: BareItem;
|
|
102
|
+
params: Params;
|
|
103
|
+
}
|
|
104
|
+
interface InnerList {
|
|
105
|
+
items: Item[];
|
|
106
|
+
params: Params;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* HTTP Message Signatures (RFC 9421) — request verification only.
|
|
111
|
+
* Runtime-neutral: WebCrypto + Fetch `Request`, so it runs on Node ≥ 20,
|
|
112
|
+
* Vercel/Next edge middleware, Cloudflare Workers, Deno and Bun.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
interface ComponentContext {
|
|
116
|
+
request: Request;
|
|
117
|
+
url: URL;
|
|
118
|
+
/** Override for `@authority` (e.g. when a proxy rewrites Host). */
|
|
119
|
+
authority?: string;
|
|
120
|
+
}
|
|
121
|
+
/** Build the signature base (RFC 9421 §2.5) for one Signature-Input member. */
|
|
122
|
+
declare function signatureBase(input: InnerList, ctx: ComponentContext): string;
|
|
123
|
+
interface PublicJwk {
|
|
124
|
+
kty: string;
|
|
125
|
+
crv?: string;
|
|
126
|
+
x?: string;
|
|
127
|
+
y?: string;
|
|
128
|
+
n?: string;
|
|
129
|
+
e?: string;
|
|
130
|
+
kid?: string;
|
|
131
|
+
alg?: string;
|
|
132
|
+
use?: string;
|
|
133
|
+
nbf?: number;
|
|
134
|
+
exp?: number;
|
|
135
|
+
}
|
|
136
|
+
type SignatureAlgorithm = 'ed25519' | 'rsa-pss-sha512' | 'rsa-v1_5-sha256' | 'ecdsa-p256-sha256' | 'ecdsa-p384-sha384';
|
|
137
|
+
/** JWK SHA-256 thumbprint, base64url (RFC 7638; RFC 8037 §A.3 for OKP). */
|
|
138
|
+
declare function jwkThumbprint(jwk: PublicJwk): Promise<string>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Web Bot Auth verifier — draft-meunier-webbotauth-httpsig-protocol-02.
|
|
142
|
+
*
|
|
143
|
+
* A signed agent request carries:
|
|
144
|
+
* Signature-Agent: agent2="https://signer.example" (dictionary form)
|
|
145
|
+
* Signature-Input: sig2=("@authority" "signature-agent";key="agent2");
|
|
146
|
+
* created=…;expires=…;keyid="<JWK thumbprint>";tag="web-bot-auth"
|
|
147
|
+
* Signature: sig2=:<base64>:
|
|
148
|
+
* The verifier resolves the signer's key directory
|
|
149
|
+
* (<origin>/.well-known/http-message-signatures-directory by default), picks
|
|
150
|
+
* the key whose JWK thumbprint equals `keyid`, rebuilds the RFC 9421 signature
|
|
151
|
+
* base, and verifies it. Cheap checks run before any network call.
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
declare const WEB_BOT_AUTH_TAG = "web-bot-auth";
|
|
155
|
+
declare const DIRECTORY_PATH = "/.well-known/http-message-signatures-directory";
|
|
156
|
+
interface ReplayCache {
|
|
157
|
+
has(key: string): boolean | Promise<boolean>;
|
|
158
|
+
add(key: string, ttlSeconds: number): void | Promise<void>;
|
|
159
|
+
}
|
|
160
|
+
/** Bounded in-memory replay cache. Use a shared store (Redis…) across instances. */
|
|
161
|
+
declare function memoryReplayCache(maxEntries?: number): ReplayCache;
|
|
162
|
+
interface WebBotAuthOptions {
|
|
163
|
+
/**
|
|
164
|
+
* Which signers may be resolved. `'any'` (default) accepts any public HTTPS
|
|
165
|
+
* signer behind SSRF guards; a list restricts to those origins/URLs.
|
|
166
|
+
*/
|
|
167
|
+
allowedDirectories?: 'any' | string[];
|
|
168
|
+
/** Accepted clock drift in seconds. Default 60. */
|
|
169
|
+
clockSkewSec?: number;
|
|
170
|
+
/** Max `expires - created`, seconds. Default 86400 (spec: ≤ 24 h recommended). */
|
|
171
|
+
maxValiditySec?: number;
|
|
172
|
+
/** Reject signatures without a `nonce`. Default false. */
|
|
173
|
+
requireNonce?: boolean;
|
|
174
|
+
replayCache?: ReplayCache;
|
|
175
|
+
/** Override `@authority` when a proxy rewrites Host. */
|
|
176
|
+
authority?: (request: Request, url: URL) => string;
|
|
177
|
+
/** Node only: DNS-check directory hosts for private addresses. Default true. */
|
|
178
|
+
resolveDns?: boolean;
|
|
179
|
+
/** Test seams. */
|
|
180
|
+
fetch?: typeof fetch;
|
|
181
|
+
now?: () => number;
|
|
182
|
+
}
|
|
183
|
+
type WebBotAuthResult = {
|
|
184
|
+
status: 'absent';
|
|
185
|
+
} | {
|
|
186
|
+
status: 'verified';
|
|
187
|
+
/** Stable identity: the signer URL (directory origin or JWKS URL). */
|
|
188
|
+
agentUrl: string;
|
|
189
|
+
keyid: string;
|
|
190
|
+
label: string;
|
|
191
|
+
alg: SignatureAlgorithm;
|
|
192
|
+
created: number;
|
|
193
|
+
expires: number;
|
|
194
|
+
} | {
|
|
195
|
+
status: 'invalid';
|
|
196
|
+
reason: string;
|
|
197
|
+
agentUrl?: string;
|
|
198
|
+
keyid?: string;
|
|
199
|
+
};
|
|
200
|
+
declare function verifyWebBotAuth(request: Request, opts?: WebBotAuthOptions): Promise<WebBotAuthResult>;
|
|
201
|
+
|
|
202
|
+
interface OAuth2Options {
|
|
203
|
+
issuer: string;
|
|
204
|
+
/** The audience / resource indicator this site accepts (RFC 8707). */
|
|
205
|
+
audience: string | string[];
|
|
206
|
+
/** Default `<issuer>/.well-known/jwks.json`. */
|
|
207
|
+
jwksUri?: string;
|
|
208
|
+
/** Static JWKS (tests / pinned keys) instead of fetching `jwksUri`. */
|
|
209
|
+
jwks?: {
|
|
210
|
+
keys: JsonWebKey[];
|
|
211
|
+
};
|
|
212
|
+
requiredScopes?: string[];
|
|
213
|
+
algorithms?: string[];
|
|
214
|
+
clockToleranceSec?: number;
|
|
215
|
+
/** Refuse tokens that aren't DPoP-bound. Default false (bound tokens are always checked). */
|
|
216
|
+
requireDpop?: boolean;
|
|
217
|
+
}
|
|
218
|
+
interface OAuthAgent {
|
|
219
|
+
id: string;
|
|
220
|
+
name: string;
|
|
221
|
+
vendor: string | null;
|
|
222
|
+
claims: Record<string, unknown>;
|
|
223
|
+
/** Present for delegated tokens: the user the agent acts for. */
|
|
224
|
+
onBehalfOf?: {
|
|
225
|
+
sub: string;
|
|
226
|
+
email?: string;
|
|
227
|
+
name?: string;
|
|
228
|
+
};
|
|
229
|
+
dpop: boolean;
|
|
230
|
+
}
|
|
231
|
+
declare function verifyOAuthToken(token: string, o: OAuth2Options, ctx: {
|
|
232
|
+
request: Request;
|
|
233
|
+
scheme: 'bearer' | 'dpop';
|
|
234
|
+
replayCache?: ReplayCache;
|
|
235
|
+
}): Promise<OAuthAgent | {
|
|
236
|
+
error: string;
|
|
237
|
+
}>;
|
|
238
|
+
declare const PROTECTED_RESOURCE_PATH = "/.well-known/oauth-protected-resource";
|
|
239
|
+
interface ProtectedResourceOptions {
|
|
240
|
+
/** This site's resource identifier, e.g. `https://shop.example`. */
|
|
241
|
+
resource: string;
|
|
242
|
+
/** Authorization servers agents should get tokens from. */
|
|
243
|
+
authorizationServers: string[];
|
|
244
|
+
scopesSupported?: string[];
|
|
245
|
+
resourceName?: string;
|
|
246
|
+
/** Advertise DPoP support. Default true. */
|
|
247
|
+
dpop?: boolean;
|
|
248
|
+
}
|
|
249
|
+
/** JSON for `GET /.well-known/oauth-protected-resource`. */
|
|
250
|
+
declare function protectedResourceMetadata(o: ProtectedResourceOptions): {
|
|
251
|
+
dpop_signing_alg_values_supported?: string[];
|
|
252
|
+
resource_name?: string;
|
|
253
|
+
scopes_supported?: string[];
|
|
254
|
+
resource: string;
|
|
255
|
+
authorization_servers: string[];
|
|
256
|
+
bearer_methods_supported: string[];
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* `WWW-Authenticate` value that tells an agent where to find the metadata
|
|
260
|
+
* (RFC 9728 §5.1). Send it with a 401 only on routes that *require* a token —
|
|
261
|
+
* Agentronics itself never blocks.
|
|
262
|
+
*/
|
|
263
|
+
declare function oauthChallenge(resource: string, opts?: {
|
|
264
|
+
error?: string;
|
|
265
|
+
scope?: string;
|
|
266
|
+
}): string;
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Agent authentication for any HTTP request — the server half of the SDK.
|
|
270
|
+
*
|
|
271
|
+
* const auth = createAgentAuth({ apiKey: { verify } })
|
|
272
|
+
* const result = await auth.authenticate(request) // Fetch API Request
|
|
273
|
+
*
|
|
274
|
+
* Authentication never blocks. A verified agent gets a stable identity your
|
|
275
|
+
* routes can read; an unverified agent (or a human) browses exactly as before.
|
|
276
|
+
*
|
|
277
|
+
* Methods, strongest first: Web Bot Auth (RFC 9421 signed agents), agent API
|
|
278
|
+
* keys, OAuth 2.1 access tokens (app-only or acting for a user, optionally
|
|
279
|
+
* DPoP-bound), and verified crawlers (published IP ranges or forward-confirmed
|
|
280
|
+
* reverse DNS). Everything runs on Node ≥ 20 and edge runtimes except crawler
|
|
281
|
+
* rDNS, which needs Node DNS (it degrades to "unverified", never "verified").
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
type AgentAuthMethod = 'web-bot-auth' | 'api-key' | 'oauth2' | 'verified-crawler';
|
|
285
|
+
interface VerifiedAgent {
|
|
286
|
+
/** Stable id: signer URL, API-key agent id, OAuth client id, or crawler name. */
|
|
287
|
+
id: string;
|
|
288
|
+
name: string;
|
|
289
|
+
vendor: string | null;
|
|
290
|
+
method: AgentAuthMethod;
|
|
291
|
+
claims?: Record<string, unknown>;
|
|
292
|
+
/** OAuth delegated tokens: the user this agent is acting for. */
|
|
293
|
+
onBehalfOf?: {
|
|
294
|
+
sub: string;
|
|
295
|
+
email?: string;
|
|
296
|
+
name?: string;
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
type AgentAuthResult = {
|
|
300
|
+
status: 'verified';
|
|
301
|
+
agent: VerifiedAgent;
|
|
302
|
+
} | {
|
|
303
|
+
status: 'unverified';
|
|
304
|
+
reason: string;
|
|
305
|
+
claimedName?: string;
|
|
306
|
+
attempted: AgentAuthMethod[];
|
|
307
|
+
} | {
|
|
308
|
+
status: 'none';
|
|
309
|
+
};
|
|
310
|
+
interface ApiKeyIdentity {
|
|
311
|
+
agentId: string;
|
|
312
|
+
name?: string;
|
|
313
|
+
vendor?: string;
|
|
314
|
+
scopes?: string[];
|
|
315
|
+
}
|
|
316
|
+
interface ApiKeyOptions {
|
|
317
|
+
/** Key prefix that marks a bearer token as an agent key. Default `agk_`. */
|
|
318
|
+
prefix?: string;
|
|
319
|
+
/** Look the key up. Return null for unknown/revoked keys. */
|
|
320
|
+
verify: (key: string) => ApiKeyIdentity | null | Promise<ApiKeyIdentity | null>;
|
|
321
|
+
}
|
|
322
|
+
interface CrawlerOptions extends IpRangeOptions {
|
|
323
|
+
/** Where to read the client IP. Default 'auto' (platform headers only). */
|
|
324
|
+
clientIp?: ClientIpSource;
|
|
325
|
+
/** Test seam / custom resolver. */
|
|
326
|
+
resolver?: DnsResolver;
|
|
327
|
+
}
|
|
328
|
+
interface AgentAuthOptions {
|
|
329
|
+
/** Web Bot Auth (on by default). `false` disables it. */
|
|
330
|
+
webBotAuth?: boolean | WebBotAuthOptions;
|
|
331
|
+
apiKey?: ApiKeyOptions;
|
|
332
|
+
/** One issuer, or several (e.g. your own auth server plus a partner's). */
|
|
333
|
+
oauth2?: OAuth2Options | OAuth2Options[];
|
|
334
|
+
/** Shared replay cache for Web Bot Auth nonces and DPoP proof ids. Default in-memory. */
|
|
335
|
+
replayCache?: ReplayCache;
|
|
336
|
+
/** Verified crawlers (on by default). `false` disables it. */
|
|
337
|
+
crawlers?: boolean | CrawlerOptions;
|
|
338
|
+
}
|
|
339
|
+
declare function createAgentAuth(options?: AgentAuthOptions): {
|
|
340
|
+
authenticate: (request: Request) => Promise<AgentAuthResult>;
|
|
341
|
+
};
|
|
342
|
+
/** SHA-256 hex of an agent key — store this, never the key. */
|
|
343
|
+
declare function hashAgentKey(key: string): Promise<string>;
|
|
344
|
+
/** Verifier over a static map of `sha256(key) → identity` (e.g. from env/config). */
|
|
345
|
+
declare function staticKeyVerifier(hashedKeys: Record<string, ApiKeyIdentity>): ApiKeyOptions['verify'];
|
|
346
|
+
/** Mint a new agent key (`agk_` + 32 random bytes, base64url). Show it once; store its hash. */
|
|
347
|
+
declare function generateAgentKey(prefix?: string): string;
|
|
348
|
+
declare const AGENT_HEADERS: {
|
|
349
|
+
readonly status: "x-agentronics-agent-status";
|
|
350
|
+
readonly id: "x-agentronics-agent-id";
|
|
351
|
+
readonly name: "x-agentronics-agent-name";
|
|
352
|
+
readonly vendor: "x-agentronics-agent-vendor";
|
|
353
|
+
readonly method: "x-agentronics-auth-method";
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Request headers to forward downstream, with the auth result attached.
|
|
357
|
+
* Any incoming `x-agentronics-*` header is stripped first so a caller can
|
|
358
|
+
* never forge a verified identity.
|
|
359
|
+
*/
|
|
360
|
+
declare function withAgentHeaders(request: Request, result: AgentAuthResult): Headers;
|
|
361
|
+
/**
|
|
362
|
+
* Read the forwarded result in a route handler (only trust it behind the
|
|
363
|
+
* middleware). Accepts anything with `get()` — `Headers`, Next's read-only
|
|
364
|
+
* `headers()`, or a plain adapter.
|
|
365
|
+
*/
|
|
366
|
+
declare function readAgentHeaders(headers: {
|
|
367
|
+
get(name: string): string | null;
|
|
368
|
+
}): {
|
|
369
|
+
status: "verified" | "unverified" | "none";
|
|
370
|
+
id: string | null;
|
|
371
|
+
name: string | null;
|
|
372
|
+
vendor: string | null;
|
|
373
|
+
method: AgentAuthMethod | null;
|
|
374
|
+
};
|
|
375
|
+
/**
|
|
376
|
+
* Map a result to an SDK trace event so server-side auth shows up in the
|
|
377
|
+
* console's Auth + Logs pages next to in-browser agents. Returns null for
|
|
378
|
+
* non-agent traffic. Server-side agents use class `crawler` (HTTP fetchers);
|
|
379
|
+
* the method is in `metadata.protocol`.
|
|
380
|
+
*/
|
|
381
|
+
declare function toTraceEvent(result: AgentAuthResult, ctx: {
|
|
382
|
+
siteId: string;
|
|
383
|
+
request: Request;
|
|
384
|
+
}): TraceEvent | null;
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Drop-in request handlers built on createAgentAuth().
|
|
388
|
+
*
|
|
389
|
+
* - createAgentAuthHandler(): framework-agnostic (Fetch Request in, identity out)
|
|
390
|
+
* - expressAgentAuth(): Express / Connect middleware
|
|
391
|
+
* - agentronicsMiddleware(): Next.js middleware — see '@agentronics/sdk/next'
|
|
392
|
+
*
|
|
393
|
+
* None of these ever block a request. They authenticate the agent (if any),
|
|
394
|
+
* attach the result as `x-agentronics-*` request headers, and pass every
|
|
395
|
+
* request through — verified agents, unverified agents and humans alike.
|
|
396
|
+
*/
|
|
397
|
+
|
|
398
|
+
interface AgentAuthHandlerOptions extends AgentAuthOptions {
|
|
399
|
+
/** Called for every agent request (not for plain human traffic). Never awaited on the hot path. */
|
|
400
|
+
onResult?: (event: {
|
|
401
|
+
result: AgentAuthResult;
|
|
402
|
+
request: Request;
|
|
403
|
+
}) => void | Promise<void>;
|
|
404
|
+
/** Return false to skip a path (e.g. static assets). */
|
|
405
|
+
matcher?: (url: URL) => boolean;
|
|
406
|
+
}
|
|
407
|
+
interface HandlerOutcome {
|
|
408
|
+
result: AgentAuthResult;
|
|
409
|
+
/** Request headers to forward downstream (spoofed x-agentronics-* stripped). */
|
|
410
|
+
headers: Headers;
|
|
411
|
+
}
|
|
412
|
+
declare function createAgentAuthHandler(options?: AgentAuthHandlerOptions): (request: Request) => Promise<HandlerOutcome>;
|
|
413
|
+
interface NodeReq {
|
|
414
|
+
method?: string;
|
|
415
|
+
url?: string;
|
|
416
|
+
originalUrl?: string;
|
|
417
|
+
protocol?: string;
|
|
418
|
+
headers: Record<string, string | string[] | undefined>;
|
|
419
|
+
agent?: AgentAuthResult;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Express middleware. Sets `req.agent` to the auth result and the
|
|
423
|
+
* `x-agentronics-*` request headers for downstream handlers, then always
|
|
424
|
+
* calls next(). For correct `@authority`/client IP behind a proxy, set
|
|
425
|
+
* Express `trust proxy`.
|
|
426
|
+
*/
|
|
427
|
+
declare function expressAgentAuth(options?: AgentAuthHandlerOptions): (req: NodeReq, _res: unknown, next: (err?: unknown) => void) => void;
|
|
428
|
+
|
|
429
|
+
export { AGENT_HEADERS as A, protectedResourceMetadata as B, type ClientIpSource as C, DIRECTORY_PATH as D, rangesFor as E, readAgentHeaders as F, signatureBase as G, type HandlerOutcome as H, type IpRangeOptions as I, staticKeyVerifier as J, toTraceEvent as K, verifyCrawler as L, verifyOAuthToken as M, verifyWebBotAuth as N, type OAuth2Options as O, PROTECTED_RESOURCE_PATH as P, withAgentHeaders as Q, RDNS_DOMAINS as R, type SignatureAlgorithm as S, type VerifiedAgent as V, WEB_BOT_AUTH_TAG as W, type AgentAuthHandlerOptions as a, type AgentAuthMethod as b, type AgentAuthOptions as c, type AgentAuthResult as d, type ApiKeyIdentity as e, type ApiKeyOptions as f, type CrawlerOptions as g, type OAuthAgent as h, PUBLISHED_IP_RANGES as i, type ProtectedResourceOptions as j, type PublicJwk as k, type ReplayCache as l, type WebBotAuthOptions as m, type WebBotAuthResult as n, classifyUserAgent as o, clientIp as p, createAgentAuth as q, createAgentAuthHandler as r, expressAgentAuth as s, generateAgentKey as t, hashAgentKey as u, ipInCidr as v, ipInRanges as w, jwkThumbprint as x, memoryReplayCache as y, oauthChallenge as z };
|