diff --git a/prototypes/runtime-availability/DESIGN.md b/prototypes/runtime-availability/DESIGN.md new file mode 100644 index 0000000..e34c1f0 --- /dev/null +++ b/prototypes/runtime-availability/DESIGN.md @@ -0,0 +1,37 @@ +# Per-capability runtime availability + +## User problem + +A host picker currently joins several exports to label the capabilities it can use. A service can have several capabilities, each with different library support. + +## Contract + +Each entry retains its ID and discovery capability order. A capability carries a descriptor for a reference-only entry, a runtime definition, or protocol helpers. Definitions identify the relevant export and key. Helper descriptors identify helper names and include the native webhook event subset when available. + +Library availability describes static implementation coverage. The host owns configuration, credential validation, account permissions, routing, scheduling, and health checks. + +## Examples + +| Capability | Runtime | +| --- | --- | +| Linear MCP | Definition in `connectors` | +| Linear webhook | Native verification for the events in `webhooks.linear.events` | +| Linear API and GitHub CLI | Reference only | +| Generic signed webhook | Verification in `triggers` | +| Schedule | Host-owned scheduling | +| Discord channel | Interaction verification and reply helpers | +| Discord webhook listing | Reference only | + +Discord's interaction implementation belongs to its channel. A host may cross-link that channel when it displays the webhook listing. + +## Compatibility + +The prototype preserves every discovery tuple, including unrecognized future capabilities. Consumers can handle such descriptors as reference only. Existing runtime maps keep their declarations and package subpaths. Native event subsets track the public definitions, so behavior changes remain reviewable in the export that owns them. + +## Alternatives + +A separate export keeps the discovery entry compact and lets hosts opt into the additional import cost. Embedding descriptors in generated entries makes lookups simpler but adds bytes and declaration changes to every catalog consumer. A pure helper with supplied maps keeps imports explicit at the cost of extra host wiring. A generated companion can avoid loading runtime modules while deriving membership from the same projections. + +## Recommendation + +Prototype a separate lightweight export against a real host picker and measure its bundle cost. A production follow-up should derive descriptors from generation, cover the public declaration and event-subset behavior, and handle unknown capabilities conservatively. diff --git a/prototypes/runtime-availability/contract.ts b/prototypes/runtime-availability/contract.ts new file mode 100644 index 0000000..77aba83 --- /dev/null +++ b/prototypes/runtime-availability/contract.ts @@ -0,0 +1,37 @@ +type ReferenceOnly = { readonly type: "reference-only" } +type Definition = { + readonly type: "definition" + readonly export: Name + readonly key: string +} +type ProtocolHelper = { + readonly type: "protocol-helper" + readonly export: Name + readonly key: string + readonly helpers: readonly string[] +} & (Name extends "webhooks" ? { readonly events: readonly string[] } : { readonly events?: never }) + +export type CapabilityRuntime = + | { readonly kind: "provider"; readonly surface: "inference"; readonly runtime: ReferenceOnly | Definition<"providers"> } + | { readonly kind: "connector"; readonly surface: "mcp"; readonly runtime: ReferenceOnly | Definition<"connectors"> } + | { readonly kind: "connector"; readonly surface: "api" | "cli"; readonly runtime: ReferenceOnly } + | { readonly kind: "trigger"; readonly surface: "schedule"; readonly runtime: ReferenceOnly } + | { readonly kind: "trigger"; readonly surface: "webhook"; readonly runtime: ReferenceOnly | ProtocolHelper<"triggers"> | ProtocolHelper<"webhooks"> } + | { readonly kind: "channel"; readonly surface: "channel"; readonly runtime: ReferenceOnly | ProtocolHelper<"channels"> } + +export type EntryRuntime = { + readonly id: string + readonly capabilities: readonly CapabilityRuntime[] +} + +export const examples = { + id: "linear", + capabilities: [ + { kind: "connector", surface: "mcp", runtime: { type: "definition", export: "connectors", key: "linear" } }, + { kind: "connector", surface: "api", runtime: { type: "reference-only" } }, + { kind: "trigger", surface: "webhook", runtime: { + type: "protocol-helper", export: "webhooks", key: "linear", helpers: ["verifyNativeWebhook"], + events: ["Issue.create", "Issue.update"], + } }, + ], +} as const satisfies EntryRuntime diff --git a/prototypes/runtime-availability/decision.json b/prototypes/runtime-availability/decision.json new file mode 100644 index 0000000..597803f --- /dev/null +++ b/prototypes/runtime-availability/decision.json @@ -0,0 +1,9 @@ +{ + "outcome": "propose-production-plan", + "reason": "A host picker can label definition and helper coverage without repeating the mapping between discovery capabilities and runtime exports.", + "openQuestions": [ + "Should runtime membership be generated in a separate lightweight export?", + "How should a future channel advertise helper names for its own protocol?", + "Should hosts request a single descriptor by ID to limit bundle costs?" + ] +} diff --git a/prototypes/runtime-availability/prototype.mjs b/prototypes/runtime-availability/prototype.mjs new file mode 100644 index 0000000..106f7fb --- /dev/null +++ b/prototypes/runtime-availability/prototype.mjs @@ -0,0 +1,56 @@ +import { realpathSync } from "node:fs" +import { pathToFileURL } from "node:url" +import { catalog } from "@checkfu/integrations/catalog" +import { channels } from "@checkfu/integrations/channels" +import { connectors } from "@checkfu/integrations/connectors" +import { providers } from "@checkfu/integrations/providers" +import { triggers } from "@checkfu/integrations/triggers" +import { webhooks } from "@checkfu/integrations/webhooks" + +export const publicMaps = { channels, connectors, providers, triggers, webhooks } + +const own = (map, key) => Object.hasOwn(map, key) ? map[key] : undefined +const definition = (name, key) => ({ type: "definition", export: name, key }) +const helpers = (name, key, names) => ({ type: "protocol-helper", export: name, key, helpers: names }) +const channelHelpers = { + "discord-interactions": ["verifyDiscordInteraction", "discordReplyRequest"], +} + +function runtimeFor(id, { kind, surface }, maps) { + if (kind === "provider" && surface === "inference" && own(maps.providers, id)) { + return definition("providers", id) + } + if (kind === "connector" && surface === "mcp" && own(maps.connectors, id)) { + return definition("connectors", id) + } + if (kind === "trigger" && surface === "webhook") { + const native = own(maps.webhooks, id) + if (native !== undefined) { + const names = native.setup === "challenge" + ? ["verifyNativeWebhook", "readNotionChallenge"] + : ["verifyNativeWebhook"] + return { ...helpers("webhooks", id, names), events: [...native.events] } + } + if (own(maps.triggers, id)) return helpers("triggers", id, ["verifyWebhookDelivery"]) + } + if (kind === "channel" && surface === "channel") { + const configured = own(maps.channels, id) + const names = own(channelHelpers, configured?.channel.protocol) + if (names !== undefined) return helpers("channels", id, [...names]) + } + return { type: "reference-only" } +} + +export function availabilityFor(entry, runtimeMaps) { + return { + id: entry.id, + capabilities: entry.capabilities.map(capability => ({ + ...capability, + runtime: runtimeFor(entry.id, capability, runtimeMaps), + })), + } +} + +if (process.argv[1] && pathToFileURL(realpathSync(process.argv[1])).href === import.meta.url) { + console.log(JSON.stringify(catalog.map(entry => availabilityFor(entry, publicMaps)), null, 2)) +} diff --git a/prototypes/runtime-availability/prototype.test.mjs b/prototypes/runtime-availability/prototype.test.mjs new file mode 100644 index 0000000..eff465a --- /dev/null +++ b/prototypes/runtime-availability/prototype.test.mjs @@ -0,0 +1,66 @@ +import assert from "node:assert/strict" +import { readFileSync } from "node:fs" +import { test } from "node:test" +import { catalog } from "@checkfu/integrations/catalog" +import { availabilityFor, publicMaps } from "./prototype.mjs" + +const reference = { type: "reference-only" } +const runtime = (id, kind, surface) => { + const entry = catalog.find(candidate => candidate.id === id) + const capability = availabilityFor(entry, publicMaps).capabilities.find(candidate => + candidate.kind === kind && candidate.surface === surface) + assert.ok(capability, `${id} ${kind}/${surface}`) + return capability.runtime +} + +test("matches discovery capabilities against actual definitions and protocol helpers", () => { + assert.deepEqual(runtime("openai", "provider", "inference"), + { type: "definition", export: "providers", key: "openai" }) + assert.deepEqual(runtime("google-gemini", "provider", "inference"), reference) + assert.deepEqual(runtime("linear", "connector", "mcp"), + { type: "definition", export: "connectors", key: "linear" }) + assert.deepEqual(runtime("linear", "connector", "api"), reference) + assert.deepEqual(runtime("linear", "trigger", "webhook"), { + type: "protocol-helper", export: "webhooks", key: "linear", helpers: ["verifyNativeWebhook"], + events: publicMaps.webhooks.linear.events, + }) + assert.deepEqual(runtime("github", "connector", "cli"), reference) + assert.deepEqual(runtime("discord", "trigger", "webhook"), reference) + assert.deepEqual(runtime("discord", "channel", "channel"), { + type: "protocol-helper", export: "channels", key: "discord", + helpers: ["verifyDiscordInteraction", "discordReplyRequest"], + }) + assert.deepEqual(runtime("webhook", "trigger", "webhook"), { + type: "protocol-helper", export: "triggers", key: "webhook", helpers: ["verifyWebhookDelivery"], + }) + assert.deepEqual(runtime("schedule", "trigger", "schedule"), reference) +}) + +test("extends map membership without a vendor registry and ignores inherited keys", () => { + const capabilities = [{ kind: "connector", surface: "mcp" }] + const future = { id: "future", capabilities } + const maps = { ...publicMaps, connectors: { ...publicMaps.connectors, future: { name: "Future connector" } } } + assert.deepEqual(availabilityFor(future, publicMaps).capabilities[0].runtime, reference) + assert.deepEqual(availabilityFor(future, maps).capabilities[0].runtime, + { type: "definition", export: "connectors", key: "future" }) + assert.deepEqual(availabilityFor({ id: "toString", capabilities }, maps).capabilities[0].runtime, reference) +}) + +test("preserves every discovery tuple without mutating catalog or runtime definitions", () => { + const original = structuredClone({ catalog, publicMaps }) + const descriptors = catalog.map(entry => availabilityFor(entry, publicMaps)) + assert.deepEqual(descriptors.map(({ id, capabilities }) => ({ + id, capabilities: capabilities.map(({ kind, surface }) => ({ kind, surface })), + })), catalog.map(({ id, capabilities }) => ({ id, capabilities }))) + const copy = descriptors.find(entry => entry.id === "linear").capabilities + .find(({ kind }) => kind === "trigger").runtime.events + assert.notStrictEqual(copy, publicMaps.webhooks.linear.events) + assert.deepEqual({ catalog, publicMaps }, original) +}) + +test("records the prototype decision", () => { + const decision = JSON.parse(readFileSync(new URL("./decision.json", import.meta.url), "utf8")) + assert.ok(["propose-production-plan", "defer"].includes(decision.outcome)) + assert.ok(decision.reason.trim()) + assert.ok(Array.isArray(decision.openQuestions) && decision.openQuestions.every(question => typeof question === "string")) +})