@wakeshift/sdk 0.2.0 → 0.4.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.
@@ -1 +1 @@
1
- {"version":3,"file":"wakeshift.js","sourceRoot":"","sources":["../src/wakeshift.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAiE,MAAM,aAAa,CAAC;AACrH,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAe,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,iIAAiI;AACjI,MAAM,CAAC,MAAM,YAAY,GAAG,0BAA0B,CAAC;AAEvD,oFAAoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AAEzC,qEAAqE;AACrE,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAElD,iEAAiE;AACjE,sDAAsD;AACtD,MAAM,mBAAmB,GAAG,2HAA2H,CAAC;AACxJ,MAAM,mBAAmB,GACvB,6QAA6Q,CAAC;AAChR,MAAM,wBAAwB,GAC5B,4MAA4M,CAAC;AA6B/M,oFAAoF;AACpF,MAAM,CAAC,MAAM,sBAAsB,GACjC,+GAA+G;IAC/G,2HAA2H;IAC3H,0HAA0H;IAC1H,2HAA2H;IAC3H,wHAAwH;IACxH,uGAAuG;IACvG,8DAA8D,CAAC;AAiLjE,wEAAwE;AACxE,yCAAyC;AACzC,SAAS,WAAW,CAAC,KAA4B;IAC/C,MAAM,OAAO,GAAG,KAAK,EAAE,WAAW,EAAE,OAAO,CAAC;IAC5C,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,CAA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C,EAAE,IAAI,KAAK,YAAY;YACpD,CAAC,CAAC,oBAAoB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG;YAC9C,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;QAClG,OAAO,IAAI,cAAc,CACvB,CAAC,EACD,aAAa,EACb,4BAA4B,IAAI,CAAC,IAAI,KAAK,GAAG,oGAAoG,EACjJ,EAAE,KAAK,EAAE,GAAG,EAAE,CACf,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { z } from \"zod\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { AnySchema } from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport { WakeshiftError } from \"./errors.js\";\nimport { WakeEvent, attachEvents, type AttachOptions, type EventOptions, type EventTypeManifest } from \"./events.js\";\nimport { parseKey, signAssertion, type AppKey } from \"./key.js\";\nimport { retryRefused } from \"./retry.js\";\n\n/** Wakeshift's production core, the default for every key but an older wst_test_ one. Override with `core` or WAKESHIFT_CORE. */\nexport const DEFAULT_CORE = \"https://app.wakeshift.ai\";\n\n/** The tool argument an agent passes its session key in (a result gives it one). */\nexport const SESSION_ARG = \"session_key\";\n\n/** The tool argument an agent says which program it runs in with. */\nexport const HARNESS_ARG = \"harness\";\n\n/**\n * The tool argument an agent passes its own ID for the conversation in,\n * when its program gives it one (Cursor and Grok Bot: CURSOR_CONVERSATION_ID).\n */\nexport const CONVERSATION_ARG = \"conversation_id\";\n\n// What the agent is told each argument is (the core's own words:\n// internal/harnesses, whose tests check these match).\nconst SESSION_DESCRIPTION = \"The session key an earlier result gave you, if it did. It's a secret: keep it to this conversation; don't share or log it\";\nconst HARNESS_DESCRIPTION =\n \"The program you're running in: codex, claude-code, cursor (local CLI or IDE), cursor-cloud (Cursor cloud agent), grok-bot, copilot-cli, opencode, antigravity, openclaw (even when it runs your turns in Codex), hermes, chatgpt, or your program's name if it isn't listed\";\nconst CONVERSATION_DESCRIPTION =\n \"Your own ID for this conversation, if your program gives you one. Cursor and Grok Bot: the output of `printenv CURSOR_CONVERSATION_ID`. Codex and Antigravity send it automatically; others leave it empty\";\n\nexport interface WakeshiftOptions {\n /** The app key from the console: wst_ and 50 characters (or an older wst_test_… or wst_live_… key). */\n key: string;\n /**\n * Wakeshift's base URL: the console you got the key from. Default:\n * WAKESHIFT_CORE from the environment, else https://app.wakeshift.ai.\n * An older wst_test_… key has no default: it needs one of the two.\n */\n core?: string;\n /** Default: the global fetch. */\n fetch?: typeof fetch;\n /** Per-request timeout in milliseconds. Default 20000. */\n timeoutMs?: number;\n /**\n * Called with a problem that doesn't fail the call but makes it work less\n * well, for example a tool call Wakeshift recognised no harness in. Each kind is\n * reported once. Default: console.warn.\n */\n onWarning?: (message: string) => void;\n}\n\n/** Which app a key is, as Wakeshift says (wake.app()). */\nexport interface AppInfo {\n id: string;\n name: string;\n}\n\n/** What the SDK says, once, when Wakeshift recognised no harness in a tool call. */\nexport const UNKNOWN_CLIENT_WARNING =\n \"wakeshift: Wakeshift couldn't tell which agent made a tool call (no MCP client name, nothing it knows in the \" +\n \"call's _meta or User-Agent, and no harness argument), so it treats the agent as one it can't wake (its messages are held \" +\n \"for its next call to the tool). The name comes from the client's initialize request, which a server created per request \" +\n \"(stateless Streamable HTTP) never sees; Claude Code, Codex, Antigravity, Copilot CLI, opencode and Cursor are recognised \" +\n \"without it. Spread ...wake.args into the tool's input and pass args to wake.call, so the agent can say (harness); for \" +\n \"other clients, keep one McpServer per MCP session (a stateful transport), or pass the name yourself: \" +\n \"wake.call(extra, { client }) or wake.callOf({ clientName }).\";\n\n/**\n * Who called one of the app's tools, as Wakeshift needs it. Make one with\n * `wake.call(extra, …)` inside an MCP tool callback, or `wake.callOf(…)`.\n */\nexport interface Call {\n /** The app's own ID for the person (optional). */\n user?: string;\n /**\n * The MCP client's name (initialize's clientInfo.name). A stateless\n * server has none; Wakeshift then tells the harness from meta, else\n * user_agent.\n */\n client: string;\n /** The tool call's _meta (Codex sends its thread there). */\n meta?: Record<string, unknown>;\n /** The session handle an earlier result gave the agent. */\n session?: string;\n /** The MCP request's HTTP User-Agent. */\n user_agent?: string;\n /** The conversation's ID as the agent passed it (conversation_id: Cursor's CURSOR_CONVERSATION_ID). */\n conversation?: string;\n /** The program the agent says it runs in (harness): a hint, never a credential. */\n harness?: string;\n}\n\n/**\n * What Wakeshift recognised the calling conversation's harness as, and by\n * which signal (\"claim\": only the agent's harness argument named it); both\n * null when nothing named one. claimed is what the agent said (normalized:\n * \"Grok Bot\" is grok-bot), null if it didn't; a claimed that differs from\n * harness was ignored, since it contradicted what the call was recognised\n * as (the claim only refines it: Cursor's calls may be Grok Bot's).\n */\nexport interface Recognised {\n harness: string | null;\n via: \"client\" | \"meta\" | \"user_agent\" | \"claim\" | null;\n claimed: string | null;\n}\n\n/**\n * Seconds, or a string like \"90s\", \"5m\", \"2h\", \"30d\". Wakeshift checks the\n * value: days must be whole (\"1.5d\" is a bad_request; use \"36h\").\n */\nexport type Duration = number | `${number}${\"s\" | \"m\" | \"h\" | \"d\"}`;\n\nexport interface SubscribeOptions {\n /** Wake only for events whose data has these top-level fields equal to these values. */\n filter?: Record<string, string | number | boolean | null>;\n /** End after the first delivery. */\n once?: boolean;\n /** Deliver the latest event published within this long before subscribing (at most 24 hours). */\n replay?: Duration;\n /** End after this long without a delivery or a fresh subscribe (1 minute to 365 days; default 30 days). */\n ttl?: Duration;\n}\n\n/** What Wakeshift adds to a tool result: text for the agent, _meta for its harness. */\nexport interface Addition {\n text?: string;\n meta?: Record<string, unknown>;\n /** What Wakeshift recognised the caller's harness as (not added to the result). */\n agent?: Recognised;\n}\n\nexport interface Subscription {\n /** For `send`. */\n id: string;\n topic: string;\n filter?: Record<string, unknown>;\n once: boolean;\n expiresAt: Date;\n /**\n * The conversation's session key (the agent passes it back as session_key;\n * the result says so). It's a secret that acts as the conversation: don't\n * show, store or log it. To name the conversation, use id, or an HMAC of it.\n */\n session: string;\n /** What the tool result must carry for the caller's harness. */\n addition: Addition;\n /** What Wakeshift recognised the caller's harness as. */\n agent: Recognised;\n /**\n * The tool result to return: your text (or result) followed by\n * Wakeshift's, with its _meta.\n */\n result(text: string | CallToolResult): CallToolResult;\n}\n\nexport interface TopicEvent {\n /** What the agent reads first (at most 1000 bytes). */\n text: string;\n /** A JSON object, within the 64 KB request limit; filters match its top-level fields. */\n data?: Record<string, unknown>;\n /** Makes retries publish once for a day (at most 200 characters); after a day, the same id publishes again. */\n id?: string;\n}\n\nexport interface Published {\n /** Conversations it woke (or will). */\n matched: number;\n /** An earlier publish had this event's id. */\n duplicate: boolean;\n}\n\n/** delivered: on its way to a connected conversation; queued: waits for it; closed: the subscription ended. */\nexport type SendStatus = \"delivered\" | \"queued\" | \"closed\";\n\n/**\n * How a conversation is connected: stream (a stream held open, e.g.\n * Cursor's background command), poll (long polls or waits, e.g. Claude\n * Code's Monitor, in the last minute) or hooks (Wakeshift's hooks or\n * connector on the user's machine).\n */\nexport type Via = \"stream\" | \"poll\" | \"hooks\" | \"webhook\";\n\nexport interface TopicStatus {\n topic: string;\n /** Conversations subscribed (ended or expired subscriptions don't count). */\n subscriptions: number;\n /** Of those, connected now. */\n connected: number;\n /** How many are connected each way. */\n via: Record<Via, number>;\n}\n\nexport interface SubscriptionStatus {\n id: string;\n topic: string;\n status: \"active\" | \"closed\";\n connected: boolean;\n via?: Via;\n expiresAt?: Date;\n}\n\n/** A publish URL: `topic` for a topic's (`wake.publishUrl`), `event` for an event's (`event.publishUrl`). */\nexport interface PublishUrl {\n id: string;\n topic?: string;\n event?: string;\n url: string;\n}\n\n/** An event pattern a manifest asks for, and what the person is told it's for. */\nexport interface ScopeEvent {\n pattern: string;\n description: string;\n}\n\n/** What the app may do with the agents in the workspaces it keeps (manifest.agent). */\nexport interface AgentScope {\n wake: ScopeEvent[];\n post: ScopeEvent[];\n /** Days the person's consent lasts. */\n ttl_days: number;\n /** At most max wake-ups in any seconds, on top of Wakeshift's own limits. */\n wake_limits?: { seconds: number; max: number }[];\n /** What the person should say to their agent once it's connected; at most 120 characters. */\n start_prompt?: string;\n groups?: boolean;\n}\n\n/** What the app tells Wakeshift it may do (see wake.publishManifest). */\nexport interface Manifest {\n description?: string;\n agent?: AgentScope;\n /** The app's event types: defineEvent fills this in for you. */\n events?: EventTypeManifest[];\n}\n\n/** The parts of an MCP tool callback's `extra` that Wakeshift reads. */\nexport interface ToolExtra {\n _meta?: Record<string, unknown>;\n requestInfo?: { headers?: Record<string, string | string[] | undefined> };\n}\n\n// userAgentOf is the User-Agent of the HTTP request a tool call came in\n// (\"\" if there's none, e.g. over stdio).\nfunction userAgentOf(extra: ToolExtra | undefined): string {\n const headers = extra?.requestInfo?.headers;\n if (!headers) return \"\";\n const v = headers[\"user-agent\"] ?? headers[\"User-Agent\"];\n return (Array.isArray(v) ? v[0] : v) ?? \"\";\n}\n\n/** An McpServer or a low-level Server: anything that knows its client's name. */\nexport type ClientInfoSource =\n | { getClientVersion(): { name: string } | undefined }\n | { server: { getClientVersion(): { name: string } | undefined } };\n\nexport interface CallOptions {\n /** The MCP server the call came to, for the client's name (or pass client). */\n server?: ClientInfoSource;\n /** The client's name, if you know it (instead of server). */\n client?: string;\n /** The app's own ID for the person. */\n user?: string;\n /** The tool's arguments: session_key, harness and conversation_id (wake.args) are read from them. */\n args?: { [SESSION_ARG]?: string; [HARNESS_ARG]?: string; [CONVERSATION_ARG]?: string } | Record<string, unknown>;\n /** The session key, if you read it yourself. */\n session?: string;\n /** The program the agent says it runs in (harness), if you read it yourself. */\n harness?: string;\n /** The conversation's ID the agent passed (conversation_id), if you read it yourself. */\n conversation?: string;\n}\n\nexport function clientNameOf(s: ClientInfoSource): string {\n const info = \"getClientVersion\" in s ? s.getClientVersion() : s.server.getClientVersion();\n return info?.name ?? \"\";\n}\n\n/** Adds Wakeshift's text and _meta to a tool result (a copy). */\nexport function applyAddition(a: Addition, base: string | CallToolResult): CallToolResult {\n let out: CallToolResult;\n if (typeof base === \"string\") {\n const text = (base.trim() + \"\\n\\n\" + (a.text ?? \"\")).trim();\n out = { content: text ? [{ type: \"text\", text }] : [] };\n } else {\n out = { ...base, content: [...(base.content ?? [])] };\n if (a.text) out.content.push({ type: \"text\", text: a.text });\n }\n if (a.meta && Object.keys(a.meta).length > 0) out._meta = { ...(out._meta ?? {}), ...a.meta };\n return out;\n}\n\nconst argsShape = {\n [SESSION_ARG]: z.string().optional().describe(SESSION_DESCRIPTION),\n [HARNESS_ARG]: z.string().optional().describe(HARNESS_DESCRIPTION),\n [CONVERSATION_ARG]: z.string().optional().describe(CONVERSATION_DESCRIPTION),\n};\n\n// str is a tool argument's value if it's a string.\nfunction str(args: Record<string, unknown> | undefined, name: string): string | undefined {\n return typeof args?.[name] === \"string\" ? (args[name] as string) : undefined;\n}\n\n/**\n * The Wakeshift client for an app: subscribe the conversations that call\n * your tools to topics, and publish to them.\n */\nexport class Wakeshift {\n /**\n * An older key's mode (wst_test_…, wst_live_…); null for a current key.\n * @deprecated Modes mean nothing now, and current keys have none.\n */\n readonly mode: \"test\" | \"live\" | null;\n readonly core: string;\n private readonly key: AppKey;\n // The app's ID: from the key, if it names the app, or else from app().\n private knownAppId: string | null;\n private appInfo?: Promise<AppInfo>;\n private readonly fetchFn: typeof fetch;\n private readonly timeoutMs: number;\n private readonly warnFn: (message: string) => void;\n private readonly warned = new Set<string>();\n\n constructor(opts: WakeshiftOptions) {\n if (!opts?.key) throw new Error(\"wakeshift: no app key (WAKESHIFT_KEY?)\");\n this.key = parseKey(opts.key);\n this.knownAppId = this.key.appId;\n this.mode = this.key.mode;\n // Test keys come from staging and local consoles, and one sent to\n // production fails in a way that's hard to read: ask for the core.\n const core = opts.core || process.env.WAKESHIFT_CORE || (this.mode === \"test\" ? \"\" : DEFAULT_CORE);\n if (!core) {\n throw new Error(\n \"wakeshift: no core URL for this test key: set WAKESHIFT_CORE, or pass { core }, to the address of the console the key came from (for example https://app.staging.wakeshift.ai)\",\n );\n }\n this.core = core.replace(/\\/+$/, \"\");\n // A request the load balancer refused during a rollout is sent again (retry.ts).\n this.fetchFn = retryRefused(opts.fetch ?? globalThis.fetch);\n this.timeoutMs = opts.timeoutMs ?? 20_000;\n this.warnFn = opts.onWarning ?? ((m) => console.warn(m));\n }\n\n /**\n * The app's ID. An older key (wst_test_…, wst_live_…) names it; for a\n * current key, which doesn't, this throws until `await wake.app()` has\n * asked Wakeshift.\n */\n get appId(): string {\n if (!this.knownAppId) throw new Error(\"wakeshift: call await wake.app() first: this key doesn't name its app\");\n return this.knownAppId;\n }\n\n /**\n * Which app the key is, as Wakeshift says: its ID and name. Asks once\n * (GET /api/apps/v1/app) and remembers the answer; afterwards\n * `wake.appId` works for any key.\n */\n app(): Promise<AppInfo> {\n this.appInfo ??= this.request<{ id?: unknown; name?: unknown }>(\"GET\", \"/app\")\n .then((r) => {\n if (typeof r.id !== \"string\" || !r.id) {\n throw new WakeshiftError(200, \"bad_response\", `Wakeshift at ${this.core} didn't say which app this key is`);\n }\n const id = this.knownAppId ?? r.id;\n this.knownAppId = id;\n return { id, name: typeof r.name === \"string\" ? r.name : \"\" };\n })\n .catch((err: unknown) => {\n this.appInfo = undefined; // a later call asks again\n throw err;\n });\n return this.appInfo;\n }\n\n /** @internal The app's ID if it's known yet (the key names it, or app() has answered), else null. */\n knownApp(): string | null {\n return this.knownAppId;\n }\n\n // A fresh assertion of the app's identity, naming the app once it's known.\n private assertion(): string {\n return signAssertion(this.key, this.core, Date.now(), this.knownAppId);\n }\n\n /** @internal Reports a problem through onWarning, every time. */\n warn(message: string): void {\n this.warnFn(message);\n }\n\n /** Reports a warning, once per kind. */\n private warnOnce(kind: string, message: string): void {\n if (this.warned.has(kind)) return;\n this.warned.add(kind);\n this.warnFn(message);\n }\n\n /**\n * The arguments the agent passes Wakeshift's part of the call in, as a\n * zod shape for your subscribe tool's input (and any other tool whose\n * results you annotate): `inputSchema: { repo: z.string(), ...wake.args }`.\n * session_key (the key a result gives the conversation), harness (the\n * program the agent runs in) and conversation_id (its own ID for the\n * conversation, where its program gives one). Wakeshift adds nothing to\n * tools you don't spread it into.\n */\n get args(): typeof argsShape {\n return argsShape;\n }\n\n /**\n * Packs the tool call from an MCP tool callback's `extra`: its _meta and\n * User-Agent, the client's name (from `server`, or pass `client`), the\n * user, and session_key, harness and conversation_id from `args`.\n */\n call(extra: ToolExtra | undefined, opts: CallOptions = {}): Call {\n let client = opts.client;\n if (client === undefined) {\n if (!opts.server) throw new Error(\"wakeshift: wake.call needs the MCP client's name: pass { server } (your McpServer), or { client }\");\n client = clientNameOf(opts.server);\n }\n const args = opts.args as Record<string, unknown> | undefined;\n return this.callOf({\n meta: extra?._meta,\n clientName: client,\n user: opts.user,\n session: opts.session ?? str(args, SESSION_ARG),\n userAgent: userAgentOf(extra),\n harness: opts.harness ?? str(args, HARNESS_ARG),\n conversation: opts.conversation ?? str(args, CONVERSATION_ARG),\n });\n }\n\n /** Packs a tool call without an MCP framework. */\n callOf(c: {\n meta?: Record<string, unknown>;\n clientName: string;\n user?: string;\n session?: string;\n userAgent?: string;\n harness?: string;\n conversation?: string;\n }): Call {\n const out: Call = { client: c.clientName ?? \"\" };\n if (c.user) out.user = c.user;\n if (c.meta && Object.keys(c.meta).length > 0) out.meta = c.meta;\n if (c.session) out.session = c.session;\n if (c.userAgent) out.user_agent = c.userAgent;\n if (c.harness?.trim()) out.harness = c.harness.trim();\n if (c.conversation?.trim()) out.conversation = c.conversation.trim();\n return out;\n }\n\n // recognised reads what the core recognised the caller as, and warns\n // once if it was nothing and the agent didn't say (an older core that\n // doesn't say: no warning).\n private recognised(agent: Partial<Recognised> | undefined): Recognised {\n if (agent && !agent.harness && !agent.claimed) this.warnOnce(\"unknown_client\", UNKNOWN_CLIENT_WARNING);\n return { harness: agent?.harness ?? null, via: agent?.via ?? null, claimed: agent?.claimed ?? null };\n }\n\n /**\n * Subscribes the calling conversation to topic (again: refreshes it).\n * Check the caller may see the topic first: Wakeshift only refuses another\n * user's u/<user>/… topics.\n */\n async subscribe(call: Call, topic: string, opts: SubscribeOptions = {}): Promise<Subscription> {\n const body: Record<string, unknown> = { call, topic, once: !!opts.once };\n if (opts.filter && Object.keys(opts.filter).length > 0) body.filter = opts.filter;\n if (opts.replay !== undefined) body.replay = opts.replay;\n if (opts.ttl !== undefined) body.ttl = opts.ttl;\n const out = await this.request<{\n subscription: { id: string; topic: string; filter?: Record<string, unknown>; once: boolean; expires_at: string };\n session: string;\n addition: Addition;\n agent?: Recognised;\n }>(\"POST\", \"/topics/subscribe\", body);\n const agent = this.recognised(out.agent);\n const addition = out.addition ?? {};\n const s = out.subscription;\n return {\n id: s.id,\n topic: s.topic,\n filter: s.filter,\n once: s.once,\n expiresAt: new Date(s.expires_at),\n session: out.session,\n addition,\n agent,\n result: (text) => applyAddition(addition, text),\n };\n }\n\n /** Ends the conversation's subscription to topic, or to all the app's topics. Returns how many ended. */\n async unsubscribe(call: Call, topic?: string): Promise<number> {\n const out = await this.request<{ unsubscribed: number }>(\"POST\", \"/topics/unsubscribe\", topic ? { call, topic } : { call });\n return out.unsubscribed;\n }\n\n /** Wakes every conversation subscribed to one of topics whose filter the event passes (each once). */\n async publish(topics: string | string[], event: TopicEvent): Promise<Published> {\n const out = await this.request<Published>(\"POST\", \"/topics/publish\", { topics: typeof topics === \"string\" ? [topics] : topics, event });\n return { matched: out.matched, duplicate: !!out.duplicate };\n }\n\n /** Wakes exactly one subscription's conversation, whatever its filter. */\n async send(subscriptionId: string, event: TopicEvent): Promise<SendStatus> {\n const out = await this.request<{ status: SendStatus }>(\"POST\", `/subscriptions/${encodeURIComponent(subscriptionId)}/send`, { event });\n return out.status;\n }\n\n /**\n * How many conversations are subscribed to topic, and how many are\n * connected now, and how. Only reads: nothing is delivered, minted or ended.\n */\n async topicStatus(topic: string): Promise<TopicStatus> {\n const out = await this.request<Omit<TopicStatus, \"via\"> & { via?: Partial<Record<Via, number>> }>(\"GET\", `/topics/status?topic=${encodeURIComponent(topic)}`);\n return { topic: out.topic, subscriptions: out.subscriptions, connected: out.connected, via: { stream: 0, poll: 0, hooks: 0, webhook: 0, ...out.via } };\n }\n\n /** Whether a subscription is active and its conversation connected now, and how. Only reads. */\n async subscriptionStatus(subscriptionId: string): Promise<SubscriptionStatus> {\n const out = await this.request<{ id: string; topic: string; status: \"active\" | \"closed\"; connected: boolean; via?: Via; expires_at?: string }>(\n \"GET\",\n `/subscriptions/${encodeURIComponent(subscriptionId)}`,\n );\n const s: SubscriptionStatus = { id: out.id, topic: out.topic, status: out.status, connected: out.connected };\n if (out.via) s.via = out.via;\n if (out.expires_at) s.expiresAt = new Date(out.expires_at);\n return s;\n }\n\n /** A capability URL that publishes to topic: a POST's body becomes an event. */\n async publishUrl(topic: string): Promise<PublishUrl> {\n return this.request<PublishUrl>(\"POST\", \"/topics/publish-urls\", { topic });\n }\n\n /** Stops a publish URL working, a topic's or an event's (410 from then on). */\n async revokePublishUrl(id: string): Promise<void> {\n await this.request(\"DELETE\", `/events/publish-urls/${encodeURIComponent(id)}`);\n }\n\n /** What Wakeshift would add to any other tool result for this conversation (creates nothing). */\n async addition(call: Call): Promise<Addition> {\n const out = await this.request<Addition>(\"POST\", \"/topics/annotate\", { call });\n return { ...out, agent: this.recognised(out.agent) };\n }\n\n /**\n * Adds what Wakeshift has for the calling conversation to a tool result\n * of yours (a copy): what's waiting for a harness that can't be woken, a\n * fresh connector beacon while a Codex thread's connector isn't running.\n * Only results you pass here (and a subscription's result()) change.\n */\n async annotate(call: Call, result: CallToolResult): Promise<CallToolResult> {\n return applyAddition(await this.addition(call), result);\n }\n\n /** Ends every subscription to topic; each conversation is told. Returns how many ended. */\n async closeTopic(topic: string): Promise<number> {\n return (await this.request<{ closed: number }>(\"POST\", \"/topics/close\", { topic })).closed;\n }\n\n /**\n * Ends one subscription by its id, telling its conversation that the app\n * ended it. Returns false if it had already ended (or there's no such\n * subscription of the app's).\n */\n async endSubscription(subscriptionId: string): Promise<boolean> {\n return (await this.request<{ ended: boolean }>(\"POST\", `/subscriptions/${encodeURIComponent(subscriptionId)}/end`, {})).ended;\n }\n\n /**\n * Ends the subscriptions of every conversation of one of the app's users\n * to topic, or to all of the app's topics (they lost access to something),\n * telling each conversation. Returns how many ended.\n */\n async unsubscribeUser(user: string, topic?: string): Promise<number> {\n return (await this.request<{ unsubscribed: number }>(\"POST\", \"/topics/unsubscribe\", topic ? { user, topic } : { user })).unsubscribed;\n }\n\n /**\n * Deletes everything Wakeshift keeps for one of the app's users: their\n * conversations, subscriptions, events and deliveries, recent publishes to\n * their u/<user>/… topics and publish URLs for them, and their ID. Open\n * streams close. Returns false if there was nothing to forget.\n */\n async forgetUser(user: string): Promise<boolean> {\n return (await this.request<{ forgotten: boolean }>(\"POST\", \"/users/forget\", { user })).forgotten;\n }\n\n /**\n * Tells Wakeshift what the app may do, replacing what it said before.\n * The events you defined (defineEvent) are added unless m has events of\n * its own. Returns the manifest as Wakeshift keeps it.\n */\n async publishManifest(m: Manifest): Promise<Manifest> {\n const body: Manifest = m.events === undefined && this.events.size > 0 ? { ...m, events: [...this.events.values()].map((e) => e.manifest) } : m;\n const out = await this.request<Manifest>(\"PUT\", \"/manifest\", body);\n this.manifestBase = m;\n this.published = Promise.resolve();\n return out;\n }\n\n // ── Events (MCP Events, natively or bridged) ──────────────────────────\n\n private readonly events = new Map<string, WakeEvent>();\n private manifestBase: Manifest = {};\n private published: Promise<void> | null = null;\n\n /**\n * Defines one of the app's event types: what a subscriber picks (args),\n * what each occurrence carries (payload), and the line an agent reads\n * first (text). Returns the event, whose emit sends occurrences. Define\n * every event before attach.\n *\n * const message = wake.defineEvent(\"chat.message\", {\n * description: \"A new message in a channel\",\n * args: z.object({ channel: z.string() }),\n * payload: z.object({ from: z.string(), text: z.string() }),\n * text: (m) => `${m.from}: ${m.text}`,\n * })\n * await message.emit({ channel: \"eng\" }, { from: \"ada\", text: \"shipped\" })\n */\n defineEvent<A extends AnySchema, P extends AnySchema>(name: string, opts: EventOptions<A, P>): WakeEvent<A, P> {\n if (this.events.has(name)) throw new Error(`wakeshift: event ${name} is defined twice`);\n const ev = new WakeEvent<A, P>(this, name, opts);\n this.events.set(name, ev as unknown as WakeEvent);\n this.published = null; // the manifest changed\n return ev;\n }\n\n /**\n * Attaches Wakeshift to your MCP server, before you connect it: the one\n * call that connects the two. Today it serves the defined events: MCP\n * Events (events/list, events/subscribe, events/unsubscribe) for clients\n * that speak it, such as ChatGPT, and the subscribe_events tool for\n * everyone else, whom Wakeshift wakes its own ways; plus\n * unsubscribe_events and list_subscriptions for every client, so a person\n * can always see and stop what they're subscribed to.\n *\n * wake.attach(server, { identify: (extra) => ({ user: guestOf(extra)?.user }) })\n */\n attach(server: McpServer, opts: AttachOptions = {}): void {\n attachEvents(this, server, [...this.events.values()], opts);\n }\n\n /** @internal Publishes the manifest with the defined events, once (again after a defineEvent). */\n ensureEvents(): Promise<void> {\n if (!this.published) {\n const p = this.publishManifest(this.manifestBase).then(() => undefined);\n this.published = p;\n p.catch(() => {\n if (this.published === p) this.published = null; // try again next time\n });\n }\n return this.published;\n }\n\n /** @internal An event's emit. */\n async emitEvent(e: { name: string; arguments: unknown; payload: unknown; text: string; id?: string; to?: string }): Promise<Published> {\n await this.ensureEvents();\n const body: Record<string, unknown> = { name: e.name, arguments: e.arguments, payload: e.payload, text: e.text };\n if (e.id) body.id = e.id;\n if (e.to) body.to = e.to;\n const out = await this.request<Published>(\"POST\", \"/events/emit\", body);\n return { matched: out.matched, duplicate: !!out.duplicate };\n }\n\n /** @internal A call to the app API (the events machinery's), after the manifest with the defined events is published. */\n async requestApp<T>(method: string, path: string, body?: unknown): Promise<T> {\n await this.ensureEvents();\n return this.request<T>(method, path, body);\n }\n\n // ── Guests' workspaces (GuestAuth) ─────────────────────────────────────\n\n /**\n * The workspace Wakeshift keeps for one of the app's users (user: the\n * app's own ID for them, as in wake.call's user), creating it on first use.\n * Topics keep that user's conversations there too. GuestAuth calls this;\n * most apps never need to.\n */\n async workspace(user: string, name: string): Promise<string> {\n return (await this.request<{ workspace: string }>(\"POST\", \"/workspaces\", { external_id: user, name })).workspace;\n }\n\n /** Creates an agent in one of the app's workspaces (if new), and its grant for the app's manifest scope. Returns the grant's ID. */\n async addAgent(workspace: string, agent: string, displayName: string): Promise<string> {\n return (await this.request<{ grant: string }>(\"POST\", `/workspaces/${encodeURIComponent(workspace)}/agents`, { agent, display_name: displayName })).grant;\n }\n\n /**\n * Checks that one of the app's agents still has a live grant, asking\n * Wakeshift each time. Throws a WakeshiftError: no_grant once the grant is\n * revoked, unknown_workspace once the workspace is forgotten.\n */\n async checkAgent(workspace: string, agent: string): Promise<void> {\n await this.request(\"POST\", `/workspaces/${encodeURIComponent(workspace)}/agents/${encodeURIComponent(agent)}/token`);\n }\n\n /** @internal The app key's seed: what GuestAuth keys its signed values from. Never send or log it. */\n secretSeed(): Buffer {\n return this.key.seed;\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const headers: Record<string, string> = { Authorization: \"Bearer \" + this.assertion() };\n if (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n let resp: Response;\n let text: string;\n try {\n resp = await this.fetchFn(this.core + \"/api/apps/v1\" + path, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n text = await resp.text();\n } catch (err) {\n throw this.unreachable(err);\n }\n let json: any;\n try {\n json = text ? JSON.parse(text) : undefined;\n } catch {\n json = undefined;\n }\n if (!resp.ok) {\n const e = json?.error ?? {};\n throw new WakeshiftError(resp.status, e.code ?? \"\", e.message ?? (text.slice(0, 200) || resp.statusText), {\n reason: typeof e.reason === \"string\" ? e.reason : undefined,\n });\n }\n // A 2xx that isn't Wakeshift's JSON: a proxy's page, or a wrong core.\n if (json === null || typeof json !== \"object\") {\n throw new WakeshiftError(\n resp.status,\n \"bad_response\",\n `Wakeshift at ${this.core} answered ${resp.status} without a JSON object. Check that WAKESHIFT_CORE, or the core option, is the address of the console your key came from`,\n );\n }\n return json as T;\n }\n\n // A request that got no answer. Name the core it went to: a wrong or\n // missing WAKESHIFT_CORE is the usual cause.\n private unreachable(err: unknown): WakeshiftError {\n const e = err as { name?: string; message?: string; cause?: { code?: string; message?: string } } | undefined;\n const why =\n e?.name === \"TimeoutError\" || e?.name === \"AbortError\"\n ? `no answer within ${this.timeoutMs / 1000}s`\n : [e?.message, e?.cause?.code ?? e?.cause?.message].filter(Boolean).join(\": \") || String(err);\n return new WakeshiftError(\n 0,\n \"unreachable\",\n `can't reach Wakeshift at ${this.core} (${why}). Check that WAKESHIFT_CORE, or the core option, is the address of the console your key came from`,\n { cause: err },\n );\n }\n}\n"]}
1
+ {"version":3,"file":"wakeshift.js","sourceRoot":"","sources":["../src/wakeshift.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAiE,MAAM,aAAa,CAAC;AAErH,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAe,SAAS,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C,iIAAiI;AACjI,MAAM,CAAC,MAAM,YAAY,GAAG,0BAA0B,CAAC;AAEvD,oFAAoF;AACpF,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AAEzC,qEAAqE;AACrE,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAkGlD,gEAAgE;AAChE,8CAA8C;AAC9C,SAAS,YAAY,CAAC,GAAY;IAChC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,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ySchema } from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport { WakeshiftError } from \"./errors.js\";\nimport { WakeEvent, attachEvents, type AttachOptions, type EventOptions, type EventTypeManifest } from \"./events.js\";\nimport type { Attached } from \"./toolcall.js\";\nimport { parseKey, signAssertion, type AppKey, isTestKey } from \"./key.js\";\nimport { retryRefused } from \"./retry.js\";\n\n/** Wakeshift's production core, the default for every key but an older wst_test_ one. Override with `core` or WAKESHIFT_CORE. */\nexport const DEFAULT_CORE = \"https://app.wakeshift.ai\";\n\n/** The tool argument an agent passes its session key in (a result gives it one). */\nexport const SESSION_ARG = \"session_key\";\n\n/** The tool argument an agent says which program it runs in with. */\nexport const HARNESS_ARG = \"harness\";\n\n/**\n * The tool argument an agent passes its own ID for the conversation in,\n * when its program gives it one (Cursor and Grok Bot: CURSOR_CONVERSATION_ID).\n */\nexport const CONVERSATION_ARG = \"conversation_id\";\n\nexport interface WakeshiftOptions {\n /** The app key from the console: wst_ and 50 characters (or an older wst_test_… or wst_live_… key). */\n key: string;\n /**\n * Wakeshift's base URL: the console you got the key from. Default:\n * WAKESHIFT_CORE from the environment, else https://app.wakeshift.ai.\n * An older wst_test_… key has no default: it needs one of the two.\n */\n core?: string;\n /** Default: the global fetch. */\n fetch?: typeof fetch;\n /** Per-request timeout in milliseconds. Default 20000. */\n timeoutMs?: number;\n /**\n * Called with a problem that doesn't fail the call but makes it work less\n * well: each time for a failure, such as a failed call's subscription\n * that couldn't be rolled back, and once for each kind of misuse, such as\n * a wrapped tool that returned with a subscribe still in flight. Default:\n * console.warn.\n */\n onWarning?: (message: string) => void;\n}\n\n/** Which app a key is, as Wakeshift says (wake.app()). */\nexport interface AppInfo {\n id: string;\n name: string;\n /** The key: the console's ID for it, and its name (\"\" if Wakeshift didn't say). */\n key: { id: string; name: string };\n}\n\n/**\n * @internal A tool call as Wakeshift takes it: who called, from which\n * client, in which conversation. The wrapper (attached.events) and attach's\n * own tools pack it.\n */\nexport interface Call {\n /** The app's own ID for the person (optional). */\n user?: string;\n /** The MCP client's name (initialize's clientInfo.name); a stateless server has none. */\n client: string;\n /** The tool call's _meta (Codex sends its thread there). */\n meta?: Record<string, unknown>;\n /** The session handle an earlier result gave the agent. */\n session?: string;\n /** The MCP request's HTTP User-Agent. */\n user_agent?: string;\n /** The conversation's ID as the agent passed it (conversation_id). */\n conversation?: string;\n /** The program the agent says it runs in (harness): a hint, never a credential. */\n harness?: string;\n /** The name of the tool being called: a connector beacon in its result names it. */\n tool?: string;\n}\n\n/**\n * What Wakeshift recognised the calling conversation's harness as, and by\n * which signal (\"claim\": only the agent's harness argument named it); both\n * null when nothing named one. claimed is what the agent said (normalized:\n * \"Grok Bot\" is grok-bot), null if it didn't; a claimed that differs from\n * harness was ignored, since it contradicted what the call was recognised\n * as (the claim only refines it: Cursor's calls may be Grok Bot's).\n */\nexport interface Recognised {\n harness: string | null;\n via: \"client\" | \"meta\" | \"user_agent\" | \"claim\" | null;\n claimed: string | null;\n}\n\n/**\n * Seconds, or a string like \"90s\", \"5m\", \"2h\", \"30d\". Wakeshift checks the\n * value: days must be whole (\"1.5d\" is a bad_request; use \"36h\").\n */\nexport type Duration = number | `${number}${\"s\" | \"m\" | \"h\" | \"d\"}`;\n\n/**\n * One recipient of a personal event's emit, beside a plain user (the app's\n * ID for them: every subscription they have to the event with these\n * arguments): `{ user, subscription }`, exactly that subscription of that\n * user's; `{ native: user }`, only that user's native (webhook)\n * subscriptions to the event with these arguments.\n */\nexport type Recipient = { user: string; subscription: string } | { native: string };\n\n/** What an event's emit did. */\nexport interface Emitted {\n /** Conversations it woke (or will). */\n matched: number;\n /** An earlier emit had this occurrence's id. */\n duplicate: boolean;\n /** User and native recipients with no live subscription it reached (an emit to several recipients only). */\n unmatched: (string | Recipient)[];\n /** Subscription recipients no longer live (or not that user's). */\n ended: (string | Recipient)[];\n}\n\n// recipientsOf reads an emit's unmatched or ended list: \"user\",\n// { native: user } or { user, subscription }.\nfunction recipientsOf(raw: unknown): (string | Recipient)[] {\n if (!Array.isArray(raw)) return [];\n const out: (string | Recipient)[] = [];\n for (const r of raw) {\n if (typeof r === \"string\") out.push(r);\n else if (r && typeof r === \"object\") {\n const m = r as Record<string, unknown>;\n if (typeof m.native === \"string\" && m.native) out.push({ native: m.native });\n else if (typeof m.user === \"string\") out.push({ user: m.user, subscription: typeof m.subscription === \"string\" ? m.subscription : \"\" });\n }\n }\n return out;\n}\n\n/**\n * How a connected conversation receives what it's woken by: stream (it holds\n * a connection to Wakeshift open), poll (it asked Wakeshift for messages\n * within the last minute), hooks (Wakeshift's connector on the user's\n * computer delivers to it) or webhook (its client subscribed with MCP\n * Events, and Wakeshift sends to the client's webhook).\n */\nexport type Via = \"stream\" | \"poll\" | \"hooks\" | \"webhook\";\n\n/** An event's publish URL (`event.publishUrl`). */\nexport interface PublishUrl {\n id: string;\n event?: string;\n url: string;\n}\n\n/** An event pattern a manifest asks for, and what the person is told it's for. */\nexport interface ScopeEvent {\n pattern: string;\n description: string;\n}\n\n/** What the app may do with the agents in the workspaces it keeps (manifest.agent). */\nexport interface AgentScope {\n wake: ScopeEvent[];\n post: ScopeEvent[];\n /** Days the person's consent lasts. */\n ttl_days: number;\n /** At most max wake-ups in any seconds, on top of Wakeshift's own limits. */\n wake_limits?: { seconds: number; max: number }[];\n /** What the person should say to their agent once it's connected; at most 120 characters. */\n start_prompt?: string;\n}\n\n/** What the app tells Wakeshift it may do (see wake.publishManifest). */\nexport interface Manifest {\n description?: string;\n agent?: AgentScope;\n /** Event types defined elsewhere, not with defineEvent: Wakeshift gets these, then the defined ones. Listing a defined one is an error. */\n events?: EventTypeManifest[];\n /** Your app wakes its users' agents with what other people and their agents do there (messages, moves): the consent screen says agents of people they don't know can wake theirs. */\n others_can_wake?: boolean;\n /**\n * Your MCP tools (as your server lists them) that agents' programs can run without asking each time:\n * tools that only read, and routine ones the agent calls on every wake that reach only what it already joined.\n * Never one that deletes, spends, or reaches people the user hasn't chosen. When a user connects Claude Code\n * or Cursor CLI, Wakeshift offers to allow exactly these, by name, in the same question as its install.\n * Letters, digits, _ and -; at most 20.\n */\n preapprove_tools?: string[];\n}\n\n/** The parts of an MCP tool callback's `extra` that Wakeshift reads. */\nexport interface ToolExtra {\n _meta?: Record<string, unknown>;\n requestInfo?: { headers?: Record<string, string | string[] | undefined> };\n}\n\n// userAgentOf is the User-Agent of the HTTP request a tool call came in\n// (\"\" if there's none, e.g. over stdio).\nfunction userAgentOf(extra: ToolExtra | undefined): string {\n const headers = extra?.requestInfo?.headers;\n if (!headers) return \"\";\n const v = headers[\"user-agent\"] ?? headers[\"User-Agent\"];\n return (Array.isArray(v) ? v[0] : v) ?? \"\";\n}\n\n/** @internal Packs a tool call as Wakeshift takes it: empty fields left out, the agent's claims trimmed. */\nexport function packCall(c: {\n meta?: Record<string, unknown>;\n clientName: string;\n user?: string;\n session?: string;\n userAgent?: string;\n harness?: string;\n conversation?: string;\n tool?: string;\n}): Call {\n const out: Call = { client: c.clientName ?? \"\" };\n if (c.user) out.user = c.user;\n if (c.meta && Object.keys(c.meta).length > 0) out.meta = c.meta;\n if (c.session) out.session = c.session;\n if (c.userAgent) out.user_agent = c.userAgent;\n if (c.harness?.trim()) out.harness = c.harness.trim();\n if (c.conversation?.trim()) out.conversation = c.conversation.trim();\n if (c.tool?.trim()) out.tool = c.tool.trim();\n return out;\n}\n\n/**\n * @internal The call to one of attach's own tools (subscribe_events and the\n * others): its _meta and User-Agent, the client's name, the user, and\n * session_key, harness and conversation_id from its arguments.\n */\nexport function toolCallOf(extra: ToolExtra | undefined, client: string, user: string | undefined, args: Record<string, unknown>, tool: string): Call {\n return packCall({\n meta: extra?._meta,\n clientName: client,\n user,\n session: str(args, SESSION_ARG),\n userAgent: userAgentOf(extra),\n harness: str(args, HARNESS_ARG),\n conversation: str(args, CONVERSATION_ARG),\n tool,\n });\n}\n\n// str is a tool argument's value if it's a string.\nfunction str(args: Record<string, unknown> | undefined, name: string): string | undefined {\n return typeof args?.[name] === \"string\" ? (args[name] as string) : undefined;\n}\n\n/**\n * The Wakeshift client for an app: define the events your app offers,\n * attach them to your MCP server, and emit them when they happen.\n */\nexport class Wakeshift {\n readonly core: string;\n private readonly key: AppKey;\n // The app's ID: from the key, if it names the app, or else from app().\n private knownAppId: string | null;\n private appInfo?: Promise<AppInfo>;\n private readonly fetchFn: typeof fetch;\n private readonly timeoutMs: number;\n private readonly warnFn: (message: string) => void;\n private readonly warned = new Set<string>();\n\n constructor(opts: WakeshiftOptions) {\n if (!opts?.key) throw new Error(\"wakeshift: no app key (WAKESHIFT_KEY?)\");\n this.key = parseKey(opts.key);\n this.knownAppId = this.key.appId;\n // Test keys come from staging and local consoles, and one sent to\n // production fails in a way that's hard to read: ask for the core.\n const core = opts.core || process.env.WAKESHIFT_CORE || (isTestKey(opts.key) ? \"\" : DEFAULT_CORE);\n if (!core) {\n throw new Error(\n \"wakeshift: no core URL for this test key: set WAKESHIFT_CORE, or pass { core }, to the address of the console the key came from (for example https://app.staging.wakeshift.ai)\",\n );\n }\n this.core = core.replace(/\\/+$/, \"\");\n // A request the load balancer refused during a rollout is sent again (retry.ts).\n this.fetchFn = retryRefused(opts.fetch ?? globalThis.fetch);\n this.timeoutMs = opts.timeoutMs ?? 20_000;\n this.warnFn = opts.onWarning ?? ((m) => console.warn(m));\n }\n\n /**\n * The app's ID. An older key (wst_test_…, wst_live_…) names it; for a\n * current key, which doesn't, this throws until `await wake.app()` has\n * asked Wakeshift.\n */\n get appId(): string {\n if (!this.knownAppId) throw new Error(\"wakeshift: call await wake.app() first: this key doesn't name its app\");\n return this.knownAppId;\n }\n\n /**\n * Which app the key is, as Wakeshift says: its ID and name, and the\n * key's. Asks once\n * (GET /api/apps/v1/app) and remembers the answer; afterwards\n * `wake.appId` works for any key.\n */\n app(): Promise<AppInfo> {\n this.appInfo ??= this.request<{ id?: unknown; name?: unknown; key?: { key_id?: unknown; name?: unknown } }>(\"GET\", \"/app\")\n .then((r) => {\n if (typeof r.id !== \"string\" || !r.id) {\n throw new WakeshiftError(200, \"bad_response\", `Wakeshift at ${this.core} didn't say which app this key is`);\n }\n const id = this.knownAppId ?? r.id;\n this.knownAppId = id;\n const str = (v: unknown) => (typeof v === \"string\" ? v : \"\");\n return { id, name: str(r.name), key: { id: str(r.key?.key_id), name: str(r.key?.name) } };\n })\n .catch((err: unknown) => {\n this.appInfo = undefined; // a later call asks again\n throw err;\n });\n return this.appInfo;\n }\n\n /** @internal The app's ID if it's known yet (the key names it, or app() has answered), else null. */\n knownApp(): string | null {\n return this.knownAppId;\n }\n\n // A fresh assertion of the app's identity, naming the app once it's known.\n private assertion(): string {\n return signAssertion(this.key, this.core, Date.now(), this.knownAppId);\n }\n\n /** @internal Reports a problem through onWarning, every time. */\n warn(message: string): void {\n this.warnFn(message);\n }\n\n /** @internal Reports a warning, once per kind. */\n warnOnce(kind: string, message: string): void {\n if (this.warned.has(kind)) return;\n this.warned.add(kind);\n this.warnFn(message);\n }\n\n /** Stops a publish URL working (410 from then on). */\n async revokePublishUrl(id: string): Promise<void> {\n await this.request(\"DELETE\", `/events/publish-urls/${encodeURIComponent(id)}`);\n }\n\n /**\n * Deletes everything Wakeshift keeps for one of the app's users: their\n * conversations, subscriptions, events and deliveries, publish URLs for\n * them, and their ID. Open streams close. Returns false if there was nothing to forget.\n */\n async forgetUser(user: string): Promise<boolean> {\n return (await this.request<{ forgotten: boolean }>(\"POST\", \"/users/forget\", { user })).forgotten;\n }\n\n /**\n * Tells Wakeshift what the app may do, replacing what it said before: m,\n * with the events you defined (defineEvent) after m's own events. An\n * event both defined and listed in m.events is an error, and nothing is\n * sent. You needn't call it: Wakeshift gets the manifest automatically\n * when the app first needs it. Once called, m is what every automatic\n * send carries (even if this one failed), with the events defined by\n * then. Returns the manifest as Wakeshift keeps it.\n */\n async publishManifest(m: Manifest): Promise<Manifest> {\n const version = this.manifestVersion; // before the body: a later defineEvent is sent again\n const body = this.manifestBody(m);\n this.manifestBase = m;\n const run = this.serial(() => this.request<Manifest>(\"PUT\", \"/manifest\", body));\n this.track(run, version);\n return run;\n }\n\n // serial runs a send after every send before it, explicit or automatic,\n // so the last manifest Wakeshift gets is the newest.\n private sending: Promise<unknown> = Promise.resolve();\n private serial<T>(send: () => Promise<T>): Promise<T> {\n const run = this.sending.then(send, send);\n this.sending = run.catch(() => undefined);\n return run;\n }\n\n // track makes a send the one event calls wait for: once it's done,\n // Wakeshift has the manifest for the events defined at version, unless it\n // failed (the next call sends again) or an event was defined since.\n private track(send: Promise<unknown>, version: number): void {\n const p: Promise<void> = send.then(() => {\n if (this.manifestVersion !== version && this.published === p) this.published = null;\n });\n this.published = p;\n p.catch(() => {\n if (this.published === p) this.published = null;\n });\n }\n\n // The manifest as Wakeshift gets it: m's events, then the defined ones,\n // refusing a name in both.\n private manifestBody(m: Manifest): Manifest {\n const listed = m.events ?? [];\n for (const name of this.events.keys()) {\n if (listed.some((e) => e.name === name)) {\n throw new Error(`wakeshift: event ${name} is defined with defineEvent and listed in the manifest's events: keep one`);\n }\n }\n const events = [...listed, ...[...this.events.values()].map((e) => e.manifest)];\n const { events: _listed, ...rest } = m;\n return events.length > 0 ? { ...rest, events } : rest;\n }\n\n // The automatic send: the manifest the app last published, or else the\n // settings Wakeshift has (asked for first, so the send never wipes what\n // was published separately), with the defined events.\n private async sendManifest(): Promise<void> {\n if (this.manifestBase) {\n await this.request(\"PUT\", \"/manifest\", this.manifestBody(this.manifestBase));\n return;\n }\n const stored = await this.request<Record<string, unknown>>(\"GET\", \"/manifest\");\n const kept: Manifest = { description: typeof stored.description === \"string\" ? stored.description : \"\" };\n if (stored.agent !== null && typeof stored.agent === \"object\") kept.agent = stored.agent as AgentScope;\n if (stored.others_can_wake === true) kept.others_can_wake = true;\n if (Array.isArray(stored.preapprove_tools) && stored.preapprove_tools.length > 0) kept.preapprove_tools = stored.preapprove_tools as string[];\n await this.request(\"PUT\", \"/manifest\", this.manifestBody(kept));\n }\n\n // ── Events (MCP Events, natively or bridged) ──────────────────────────\n\n private readonly events = new Map<string, WakeEvent>();\n // What publishManifest was last given (null: nothing yet); whether\n // Wakeshift has the manifest for the events defined now (the send; null:\n // not yet, or a defineEvent since); and how many defineEvents there were.\n private manifestBase: Manifest | null = null;\n private published: Promise<void> | null = null;\n private manifestVersion = 0;\n\n /**\n * Defines one of the app's event types: what a subscriber picks (args),\n * what each occurrence carries (payload), and the line an agent reads\n * first (text). Returns the event, whose emit sends occurrences. Define\n * every event before attach.\n *\n * const message = wake.defineEvent(\"chat.message\", {\n * description: \"A new message in a channel\",\n * args: z.object({ channel: z.string() }),\n * payload: z.object({ from: z.string(), text: z.string() }),\n * text: (m) => `${m.from}: ${m.text}`,\n * })\n * await message.emit({ channel: \"eng\" }, { from: \"ada\", text: \"shipped\" })\n */\n defineEvent<A extends AnySchema, P extends AnySchema>(name: string, opts: EventOptions<A, P>): WakeEvent<A, P> {\n if (this.events.has(name)) throw new Error(`wakeshift: event ${name} is defined twice`);\n const ev = new WakeEvent<A, P>(this, name, opts);\n this.events.set(name, ev as unknown as WakeEvent);\n this.published = null; // the manifest changed: sent again when next needed\n this.manifestVersion++;\n return ev;\n }\n\n /**\n * Attaches Wakeshift to your MCP server, before you connect it: the one\n * call that connects the two. Today it serves the defined events: MCP\n * Events (events/list, events/subscribe, events/unsubscribe) for clients\n * that speak it, such as ChatGPT, and the subscribe_events tool for\n * everyone else, whom Wakeshift wakes its own ways; plus\n * unsubscribe_events and list_subscriptions for every client, so a person\n * can always see and stop what they're subscribed to.\n *\n * const attached = wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })\n *\n * It returns the handle your own tools use to subscribe the conversation\n * calling them: wrap a tool's callback with attached.events, and give it\n * Wakeshift's arguments with attached.inputs.\n */\n attach(server: McpServer, opts: AttachOptions = {}): Attached {\n return attachEvents(this, server, [...this.events.values()], opts);\n }\n\n /** @internal Sends the manifest with the defined events, once (again after a defineEvent). */\n ensureEvents(): Promise<void> {\n if (!this.published) this.track(this.serial(() => this.sendManifest()), this.manifestVersion);\n return this.published!;\n }\n\n /** @internal An event's emit. */\n async emitEvent(e: { name: string; arguments: unknown; payload: unknown; text: string; id?: string; to?: string | (string | Recipient)[] }): Promise<Emitted> {\n await this.ensureEvents();\n const body: Record<string, unknown> = { name: e.name, arguments: e.arguments, payload: e.payload, text: e.text };\n if (e.id) body.id = e.id;\n if (e.to) body.to = e.to;\n const out = await this.request<{ matched: number; duplicate?: boolean; unmatched?: unknown; ended?: unknown }>(\"POST\", \"/events/emit\", body);\n return { matched: out.matched, duplicate: !!out.duplicate, unmatched: recipientsOf(out.unmatched), ended: recipientsOf(out.ended) };\n }\n\n /** @internal A call to the app API (the events machinery's), after the manifest with the defined events is published. */\n async requestApp<T>(method: string, path: string, body?: unknown): Promise<T> {\n await this.ensureEvents();\n return this.request<T>(method, path, body);\n }\n\n // ── Users' workspaces ──────────────────────────────────────────────────\n\n /**\n * The workspace Wakeshift keeps for one of the app's users (user: the\n * app's own ID for them, as attach's identify gives it), created on first\n * use. Wakeshift keeps that user's conversations there.\n */\n async workspace(user: string, name: string): Promise<string> {\n return (await this.request<{ workspace: string }>(\"POST\", \"/workspaces\", { external_id: user, name })).workspace;\n }\n\n /** Creates an agent in one of the app's workspaces (if new), and its grant for the app's manifest scope. Returns the grant's ID. */\n async addAgent(workspace: string, agent: string, displayName: string): Promise<string> {\n return (await this.request<{ grant: string }>(\"POST\", `/workspaces/${encodeURIComponent(workspace)}/agents`, { agent, display_name: displayName })).grant;\n }\n\n /**\n * Checks that one of the app's agents still has a live grant, asking\n * Wakeshift each time. Throws a WakeshiftError: no_grant once the grant is\n * revoked, unknown_workspace once the workspace is forgotten.\n */\n async checkAgent(workspace: string, agent: string): Promise<void> {\n await this.request(\"POST\", `/workspaces/${encodeURIComponent(workspace)}/agents/${encodeURIComponent(agent)}/token`);\n }\n\n private async request<T>(method: string, path: string, body?: unknown): Promise<T> {\n const headers: Record<string, string> = { Authorization: \"Bearer \" + this.assertion() };\n if (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n let resp: Response;\n let text: string;\n try {\n resp = await this.fetchFn(this.core + \"/api/apps/v1\" + path, {\n method,\n headers,\n body: body === undefined ? undefined : JSON.stringify(body),\n signal: AbortSignal.timeout(this.timeoutMs),\n });\n text = await resp.text();\n } catch (err) {\n throw this.unreachable(err);\n }\n let json: any;\n try {\n json = text ? JSON.parse(text) : undefined;\n } catch {\n json = undefined;\n }\n if (!resp.ok) {\n // Wakeshift's code, message and reason where it sent them as strings, else\n // the body's start, else the status's text, as every SDK reads it (test/errors.json).\n const e = json?.error !== null && typeof json?.error === \"object\" ? json.error : {};\n const str = (v: unknown) => (typeof v === \"string\" ? v : \"\");\n throw new WakeshiftError(resp.status, str(e.code), str(e.message) || text.slice(0, 200) || resp.statusText, {\n reason: str(e.reason) || undefined,\n });\n }\n // A 2xx that isn't Wakeshift's JSON: a proxy's page, or a wrong core.\n if (json === null || typeof json !== \"object\" || Array.isArray(json)) {\n throw new WakeshiftError(\n resp.status,\n \"bad_response\",\n `Wakeshift at ${this.core} answered ${resp.status} without a JSON object. Check that WAKESHIFT_CORE, or the core option, is the address of the console your key came from`,\n );\n }\n return json as T;\n }\n\n // A request that got no answer. Name the core it went to: a wrong or\n // missing WAKESHIFT_CORE is the usual cause.\n private unreachable(err: unknown): WakeshiftError {\n const e = err as { name?: string; message?: string; cause?: { code?: string; message?: string } } | undefined;\n const why =\n e?.name === \"TimeoutError\" || e?.name === \"AbortError\"\n ? `no answer within ${this.timeoutMs / 1000}s`\n : [e?.message, e?.cause?.code ?? e?.cause?.message].filter(Boolean).join(\": \") || String(err);\n return new WakeshiftError(\n 0,\n \"unreachable\",\n `can't reach Wakeshift at ${this.core} (${why}). Check that WAKESHIFT_CORE, or the core option, is the address of the console your key came from`,\n { cause: err },\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,8 +1,18 @@
1
1
  {
2
2
  "name": "@wakeshift/sdk",
3
- "version": "0.2.0",
4
- "description": "Let agents subscribe to things in your app: Wakeshift wakes them when you publish.",
3
+ "version": "0.4.0",
4
+ "description": "Let agents subscribe to things in your app: Wakeshift wakes them when you emit an event.",
5
5
  "license": "Apache-2.0",
6
+ "author": "Clawvisor Inc. <support@wakeshift.ai>",
7
+ "keywords": [
8
+ "mcp",
9
+ "model-context-protocol",
10
+ "ai-agents",
11
+ "agents",
12
+ "events",
13
+ "webhooks",
14
+ "wakeshift"
15
+ ],
6
16
  "homepage": "https://github.com/wakeshift/wakeshift-node#readme",
7
17
  "repository": {
8
18
  "type": "git",
@@ -28,6 +38,9 @@
28
38
  "engines": {
29
39
  "node": ">=22"
30
40
  },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
31
44
  "scripts": {
32
45
  "build": "tsc -p tsconfig.json",
33
46
  "typecheck": "tsc -p tsconfig.test.json --noEmit",
@@ -44,7 +57,8 @@
44
57
  "devDependencies": {
45
58
  "@modelcontextprotocol/sdk": "^1.32.1",
46
59
  "@types/node": "^22.20.5",
47
- "typescript": "^5.9.3",
60
+ "expect-type": "^1.4.0",
61
+ "typescript": "^7.0.2",
48
62
  "zod": "^4.6.7"
49
63
  }
50
64
  }
package/dist/guest.d.ts DELETED
@@ -1,119 +0,0 @@
1
- import type { IncomingMessage, ServerResponse } from "node:http";
2
- import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
3
- import type { Wakeshift } from "./wakeshift.js";
4
- /** Who a guest access token is for. */
5
- export interface Guest {
6
- /**
7
- * The app's ID for the guest: pass it as wake.call's user, so topics keep
8
- * the guest's conversations in its workspace. guest:<id>, one per
9
- * registered client.
10
- */
11
- user: string;
12
- /** The guest's workspace and agent (named after its harness: claude-code). */
13
- workspace: string;
14
- agent: string;
15
- /** The client's name, e.g. "Claude Code". */
16
- client: string;
17
- expires: Date;
18
- }
19
- export interface GuestAuthOptions {
20
- wake: Wakeshift;
21
- /** The app's MCP URL: the OAuth resource (https://…/mcp). */
22
- mcpUrl: string;
23
- /** The app's public URL, where the OAuth endpoints are (default: mcpUrl without /mcp). */
24
- base?: string;
25
- /** Seconds an access token lasts (default an hour). */
26
- accessTtl?: number;
27
- /** Seconds a refresh token lasts (default 30 days); each refresh returns a new one, good for this long from then. */
28
- refreshTtl?: number;
29
- /**
30
- * Asked at each refresh whether the guest's refresh token issued at
31
- * issuedAt is revoked: an app's own denylist, or a per-guest cutoff. A
32
- * refresh is also refused once wake.forgetUser(guest.user) has run (and,
33
- * with grants, once the guest's grant is revoked), so either signs the
34
- * guest out within accessTtl.
35
- */
36
- revoked?: (guest: Guest, issuedAt: Date) => boolean | Promise<boolean>;
37
- /**
38
- * Also give each guest's agent a grant for the app's manifest agent scope,
39
- * as the Go SDK does, and refuse refreshes once it's revoked. Needs a
40
- * manifest with an agent scope; topics don't use grants, so leave it off
41
- * for an app that only uses topics.
42
- */
43
- grants?: boolean;
44
- /**
45
- * How many trusted proxies in front append to X-Forwarded-For (behind
46
- * Google's load balancer: 2), for the per-address limits. 0 (the
47
- * default): the connection's own address.
48
- */
49
- proxyHops?: number;
50
- /** Registrations (default 20) and token requests (default 60) per address per rateWindow, per process; negative turns a limit off. */
51
- registerLimit?: number;
52
- tokenLimit?: number;
53
- /** Seconds (default 600). */
54
- rateWindow?: number;
55
- /** Called with a problem worth logging (never with a token or secret). Default: console.error. */
56
- onError?: (message: string, err: unknown) => void;
57
- /** For tests. */
58
- now?: () => number;
59
- }
60
- /** What the MCP transport passes to tool callbacks (extra.authInfo) for a guest. */
61
- export type GuestAuthInfo = AuthInfo & {
62
- extra: {
63
- guest: Guest;
64
- };
65
- };
66
- /** The guest a tool call came from, if GuestAuth signed it in (extra: the tool callback's second argument). */
67
- export declare function guestOf(extra: {
68
- authInfo?: AuthInfo;
69
- } | undefined): Guest | undefined;
70
- export declare class GuestAuth {
71
- private readonly wake;
72
- readonly mcpUrl: string;
73
- readonly base: string;
74
- private readonly accessTtl;
75
- private readonly refreshTtl;
76
- private readonly revokedFn?;
77
- private readonly grants;
78
- private readonly proxyHops;
79
- private readonly registers;
80
- private readonly tokens;
81
- private readonly errorFn;
82
- private readonly now;
83
- private readonly seed;
84
- constructor(o: GuestAuthOptions);
85
- /** Where MCP clients read the app's protected-resource metadata (RFC 9728). */
86
- get resourceMetadataUrl(): string;
87
- /**
88
- * Serves the OAuth endpoints and the metadata that points MCP clients at
89
- * them. Returns false for any other request, for your own routes. Mount it
90
- * before any body parser (it reads its own bodies), or after one: a parsed
91
- * req.body is used as it is.
92
- */
93
- handle(req: IncomingMessage, res: ServerResponse): Promise<boolean>;
94
- /**
95
- * Checks the request's bearer token. On success it returns the guest and
96
- * sets req.auth, which the MCP SDK's Streamable HTTP transport passes to
97
- * tool callbacks as extra.authInfo (read it with guestOf). On failure it
98
- * answers 401 with the WWW-Authenticate header MCP clients start signing
99
- * in from, and returns null.
100
- */
101
- authenticate(req: IncomingMessage & {
102
- auth?: AuthInfo;
103
- }, res: ServerResponse): Guest | null;
104
- /** Checks a guest access token; null if it isn't one of this app's, or has expired. */
105
- verify(token: string): Guest | null;
106
- private seconds;
107
- private resourceMetadata;
108
- private metadata;
109
- private mac;
110
- private sign;
111
- private open;
112
- /** The secret registration gave a client: an HMAC of its client_id, so it's never stored and only the app can make it. */
113
- private clientSecret;
114
- private clientAuth;
115
- private register;
116
- private authorize;
117
- private token;
118
- private stillThere;
119
- }