@agentronics/sdk 0.7.0 → 0.7.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/dist/{chunk-BPDWJCPY.js → chunk-DYCRZCCT.js} +2 -2
- package/dist/chunk-DYCRZCCT.js.map +1 -0
- package/dist/chunk-JR5YRLTH.js +18 -0
- package/dist/chunk-JR5YRLTH.js.map +1 -0
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -4
- package/dist/index.d.ts +21 -4
- package/dist/index.global.js +4 -4
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{init-only-C80qhujz.d.ts → init-only-CRvqRvNI.d.ts} +8 -1
- package/dist/{init-only-s9E9bVC0.d.cts → init-only-Cif87Qbc.d.cts} +8 -1
- package/dist/init-only.cjs +4 -4
- 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 +4 -4
- package/dist/init-only.global.js.map +1 -1
- package/dist/init-only.js +1 -1
- package/dist/lite.d.cts +2 -2
- package/dist/lite.d.ts +2 -2
- package/dist/lite.js +1 -1
- package/dist/{webmcp-BgKzHeQ3.d.cts → webmcp-C5uwNbnJ.d.cts} +2 -1
- package/dist/{webmcp-BgKzHeQ3.d.ts → webmcp-C5uwNbnJ.d.ts} +2 -1
- package/package.json +3 -3
- package/dist/chunk-3WPDIMJP.js +0 -18
- package/dist/chunk-3WPDIMJP.js.map +0 -1
- package/dist/chunk-BPDWJCPY.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts","../src/tools/modelContext.ts","../src/detection/webmcp.ts"],"names":["SDK_VERSION","hasFn","value","key","resolveModelContext","host","h","fromDocument","fromNavigator","lastActivity","activityListeners","noteWebMcpActivity","type","toolName","listener","lastWebMcpActivity","onWebMcpActivity","readLegacyInjected","webMcpSupport","detectW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CACpB,CAAA,CAAA,CAEMwB,CAAAA,CAAgBD,CAAAA,GAA6C,CACjE,GAAGK,GAAK,CACR,MAAA,CAAQ,IAAA,CACR,OAAA,CAAS,CAAE,MAAA,CAAQ,IAAA,CAAM,MAAA,CAAQV,GAAc,CAAG,KAAA,CAAOK,CAAAA,CAAS,IAAA,CAAM,IAAA,CAAMA,CAAAA,CAAS,QAAS,CAClG,GAEMG,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","file":"chunk-BPDWJCPY.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","/**\n * The WebMCP `ModelContext` surface, per the W3C WebMCP draft (Oct 2026):\n *\n * await document.modelContext.registerTool(tool, { signal, exposedTo })\n *\n * - The getter lives on `document`. `navigator.modelContext` was the old name;\n * Chrome 150 kept it as an alias and Chrome 152 removed it, so it's read\n * only as a fallback.\n * - `registerTool()` is async. There is no `unregisterTool()`; aborting the\n * `signal` passed at registration unregisters the tool.\n * - `toolactivated` / `toolcancel` events fire on the ModelContext when an\n * agent starts or cancels a tool call — the only reliable \"an agent is here\"\n * signal, because the API itself exists for every visitor of a WebMCP browser.\n * - The declarative form API (`<form toolname>`) was removed from the spec\n * (Oct 8, 2026) and lives on only as an explainer; the SDK registers every\n * tool imperatively.\n */\n\nexport interface ToolAnnotations {\n /** The tool only reads; agents may call it without asking the user. */\n readOnlyHint?: boolean\n /** The tool's output includes content the site didn't author (reviews, messages, …). */\n untrustedContentHint?: boolean\n /** Payments, deletes, sends — the agent should confirm with the user first. */\n consequentialHint?: boolean\n /** Exposed only to agent debugging tools. */\n debugging?: boolean\n}\n\nexport interface ToolExecuteOptions {\n signal: AbortSignal\n}\n\nexport interface ModelContextTool {\n name: string\n title?: string\n description: string\n inputSchema?: Record<string, unknown>\n annotations?: ToolAnnotations\n execute: (input: Record<string, unknown>, options: ToolExecuteOptions) => Promise<unknown>\n}\n\nexport interface RegisterToolOptions {\n signal?: AbortSignal\n /** Origins (besides this one) whose agents may see the tool. */\n exposedTo?: string[]\n}\n\nexport interface ModelContextLike {\n registerTool(tool: ModelContextTool, options?: RegisterToolOptions): Promise<void> | void\n addEventListener?: (type: string, listener: (event: Event) => void) => void\n removeEventListener?: (type: string, listener: (event: Event) => void) => void\n}\n\n/** Very old polyfills exposed `provideContext({ tools })` instead of `registerTool`. */\nexport interface LegacyProvider {\n provideContext(payload: {\n tools: Array<{ name: string; description?: string; inputSchema?: Record<string, unknown>; invoke(input?: unknown): Promise<unknown> }>\n }): { revoke: () => void }\n}\n\nexport type ModelContextSource = 'document' | 'navigator' | 'legacy'\n\nexport interface ResolvedModelContext {\n source: ModelContextSource\n context: ModelContextLike | LegacyProvider\n}\n\ninterface HostLike {\n document?: { modelContext?: unknown } | null\n navigator?: { modelContext?: unknown } | null\n}\n\nconst hasFn = (value: unknown, key: string): boolean =>\n typeof value === 'object' && value !== null && typeof (value as Record<string, unknown>)[key] === 'function'\n\n/** Find the page's ModelContext: `document.modelContext`, then the legacy names. */\nexport const resolveModelContext = (host?: HostLike | null): ResolvedModelContext | null => {\n const h: HostLike | null = host ?? (typeof globalThis === 'undefined' ? null : (globalThis as HostLike))\n if (!h) return null\n const fromDocument = h.document?.modelContext\n if (hasFn(fromDocument, 'registerTool')) return { source: 'document', context: fromDocument as ModelContextLike }\n const fromNavigator = h.navigator?.modelContext\n if (hasFn(fromNavigator, 'registerTool')) return { source: 'navigator', context: fromNavigator as ModelContextLike }\n if (hasFn(fromNavigator, 'provideContext')) return { source: 'legacy', context: fromNavigator as LegacyProvider }\n return null\n}\n\n// ---- agent activity ------------------------------------------------------------\n// Shared by the adapter (which sees tool calls) and detection (which reports\n// a WebMCP agent once one has acted).\n\nexport interface WebMcpActivity {\n type: 'activated' | 'cancelled' | 'executed'\n toolName: string\n at: number\n}\n\nlet lastActivity: WebMcpActivity | null = null\nconst activityListeners = new Set<(activity: WebMcpActivity) => void>()\n\nexport const noteWebMcpActivity = (type: WebMcpActivity['type'], toolName: string) => {\n lastActivity = { type, toolName, at: Date.now() }\n activityListeners.forEach((listener) => listener(lastActivity!))\n}\n\nexport const lastWebMcpActivity = () => lastActivity\n\nexport const onWebMcpActivity = (listener: (activity: WebMcpActivity) => void) => {\n activityListeners.add(listener)\n return () => {\n activityListeners.delete(listener)\n }\n}\n\n/** @internal test helper */\nexport const __resetWebMcpActivity = () => {\n lastActivity = null\n activityListeners.clear()\n}\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"]}
|