@wakeshift/sdk 0.3.0 → 0.5.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolcall.js","sourceRoot":"","sources":["../src/toolcall.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,yEAAyE;AACzE,wEAAwE;AACxE,2EAA2E;AAC3E,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,yDAAyD;AACzD,EAAE;AACF,6FAA6F;AAC7F,gCAAgC;AAChC,iFAAiF;AACjF,2DAA2D;AAC3D,6FAA6F;AAC7F,qDAAqD;AACrD,4CAA4C;AAC5C,UAAU;AAEV,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI7B,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,qBAAqB,EAAE,cAAc,EAA8E,MAAM,gDAAgD,CAAC;AAC/M,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,QAAQ,EAA6D,MAAM,gBAAgB,CAAC;AAErG,2EAA2E;AAC3E,6DAA6D;AAC7D,MAAM,WAAW,GAAG,aAAa,CAAC;AAClC,MAAM,WAAW,GAAG,SAAS,CAAC;AAC9B,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAK3C,wEAAwE;AACxE,2BAA2B;AAC3B,MAAM,uBAAuB,GAC3B,mKAAmK,CAAC;AACtK,MAAM,mBAAmB,GACvB,6QAA6Q,CAAC;AAChR,MAAM,wBAAwB,GAC5B,4MAA4M,CAAC;AAC/M,MAAM,4BAA4B,GAAG,gFAAgF,CAAC;AAEtH,MAAM,UAAU,GAAG;IACjB,CAAC,WAAW,CAAC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O,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,mEAAmE,QAAQ,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,EAAE,CAAC;QAC/J,CAAC;QACD,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;QACtD,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,IAAI,GAAG,CAAC,iBAAiB,EAAE,CAAC;YACrE,IAAI,CAAC,EAAE,CAAC,QAAQ,CACd,SAAS,GAAG,IAAI,EAChB,+BAA+B,IAAI,qIAAqI,CACzK,CAAC;QACJ,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAED,2EAA2E;AAC3E,yEAAyE;AACzE,KAAK,UAAU,WAAW,CAAC,YAAmC,EAAE,MAAqB;IACnF,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,iBAAiB;QAAE,OAAO,KAAK,CAAC;IAC1E,MAAM,GAAG,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAChD,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,OAAO,CAAC,MAAM,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,OAAO,CAAC;AACvE,CAAC","sourcesContent":["// One way to subscribe from a tool (docs/subscribe-from-tools.md): a tool\n// callback wrapped by the handle attach returns (attached.events) gets a\n// ToolCall, and subscribes the calling conversation with call.subscribe\n// (ends it with call.unsubscribe). The wrapper adds one Wakeshift block to\n// whatever the handler returns, so a conversation can't be left unwakeable\n// by a forgotten argument, a wrong tool name or an unreturned result; and a\n// call that fails ends the subscriptions it made. A port of the Go SDK's\n// appkit.Events (pkg/appkit/toolcall.go, attachcall.go).\n//\n// const attached = wake.attach(server, { identify: (extra) => ({ user: userOf(extra) }) })\n// server.registerTool(\"join\",\n// { description: \"…\", inputSchema: attached.inputs({ table: z.string() }) },\n// attached.events(\"join\", async ({ table }, call) => {\n// const sub = await call.subscribe(turn, { table }, { reason: `Playing at ${table}` })\n// await casino.seat(call.user!, table, sub.id)\n// return `You're seated at ${table}.`\n// }))\n\nimport { z } from \"zod\";\nimport * as z3 from \"zod/v3\";\nimport * as z4 from \"zod/v4\";\nimport type { CallToolResult, ServerNotification, ServerRequest } from \"@modelcontextprotocol/sdk/types.js\";\nimport type { McpServer, ToolCallback } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { RequestHandlerExtra } from \"@modelcontextprotocol/sdk/shared/protocol.js\";\nimport { getObjectShape, isZ4Schema, normalizeObjectSchema, safeParseAsync, type AnySchema, type SchemaInput, type ShapeOutput, type ZodRawShapeCompat } from \"@modelcontextprotocol/sdk/server/zod-compat.js\";\nimport { WakeshiftError } from \"./errors.js\";\nimport { EXTENSION_KEY, dialectOf } from \"./spec.js\";\nimport type { Identity, WakeEvent } from \"./events.js\";\nimport { packCall, type Call, type Duration, type Recognized, type Wakeshift } from \"./wakeshift.js\";\n\n// Wakeshift's three arguments (wakeshift.ts's SESSION_ARG, HARNESS_ARG and\n// CONVERSATION_ARG, repeated: that module imports this one).\nconst SESSION_ARG = \"session_key\";\nconst HARNESS_ARG = \"harness\";\nconst CONVERSATION_ARG = \"conversation_id\";\n\n/** MCP's own extra for a tool call: the request's signal, auth, _meta, HTTP request. */\nexport type ToolCallExtra = RequestHandlerExtra<ServerRequest, ServerNotification>;\n\n// What the agent is told each of Wakeshift's arguments is: the Go SDK's\n// WakeArgs, word for word.\nconst SESSION_KEY_DESCRIPTION =\n \"This conversation's session_key, from an earlier result (a secret token, or a handle such as claude-code#2). 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\";\nconst WAKESHIFT_OUTPUT_DESCRIPTION = \"What Wakeshift adds for this conversation: how it's woken by this app's events\";\n\nconst wakeInputs = {\n [SESSION_ARG]: z.string().optional().describe(SESSION_KEY_DESCRIPTION),\n [HARNESS_ARG]: z.string().optional().describe(HARNESS_DESCRIPTION),\n [CONVERSATION_ARG]: z.string().optional().describe(CONVERSATION_DESCRIPTION),\n};\n/** @internal Wakeshift's three arguments as attach's own tools take them: worded as a wrapped tool's (test/events-list.json pins it). */\nexport const toolArgs = wakeInputs;\nconst wakeOutput = { wakeshift: z.string().optional().describe(WAKESHIFT_OUTPUT_DESCRIPTION) };\n\n// The same in each of zod's two APIs: MCP refuses a shape that mixes them,\n// so a shape written with zod/v3 (or zod/v4) gets Wakeshift's fields in its\n// own (zod 3.25 and later carry both).\nconst byVersion = {\n v3: {\n inputs: {\n [SESSION_ARG]: z3.string().optional().describe(SESSION_KEY_DESCRIPTION),\n [HARNESS_ARG]: z3.string().optional().describe(HARNESS_DESCRIPTION),\n [CONVERSATION_ARG]: z3.string().optional().describe(CONVERSATION_DESCRIPTION),\n },\n output: { wakeshift: z3.string().optional().describe(WAKESHIFT_OUTPUT_DESCRIPTION) },\n },\n v4: {\n inputs: {\n [SESSION_ARG]: z4.string().optional().describe(SESSION_KEY_DESCRIPTION),\n [HARNESS_ARG]: z4.string().optional().describe(HARNESS_DESCRIPTION),\n [CONVERSATION_ARG]: z4.string().optional().describe(CONVERSATION_DESCRIPTION),\n },\n output: { wakeshift: z4.string().optional().describe(WAKESHIFT_OUTPUT_DESCRIPTION) },\n },\n};\n\n// fieldsFor is Wakeshift's fields in the zod API shape's own fields use\n// (the default import's for an empty shape).\nfunction fieldsFor<K extends \"inputs\" | \"output\">(shape: ZodRawShapeCompat, kind: K): K extends \"inputs\" ? WakeInputs : WakeOutputShape {\n const first = Object.values(shape ?? {})[0];\n const fields = !first ? (kind === \"inputs\" ? wakeInputs : wakeOutput) : byVersion[isZ4Schema(first) ? \"v4\" : \"v3\"][kind];\n return fields as any;\n}\n\n/** Wakeshift's three arguments, as attached.inputs adds them. */\nexport type WakeInputs = typeof wakeInputs;\n/** The optional wakeshift string attached.output adds. */\nexport type WakeOutputShape = typeof wakeOutput;\n/** The names of Wakeshift's three arguments. */\nexport type WakeKey = typeof SESSION_ARG | typeof HARNESS_ARG | typeof CONVERSATION_ARG;\n/** An input shape with Wakeshift's three arguments in it (attached.inputs'). */\nexport type WakeShape = ZodRawShapeCompat & { [K in WakeKey]: AnySchema };\n/** What a wrapped handler gets: the tool's own arguments, without Wakeshift's three. */\nexport type AppArgs<S extends ZodRawShapeCompat> = Omit<ShapeOutput<S>, WakeKey>;\n/** What a wrapped handler returns: a string (one text block) or a CallToolResult. */\nexport type WrappedResult = string | CallToolResult;\n\nconst WAKE_KEYS: readonly WakeKey[] = [SESSION_ARG, HARNESS_ARG, CONVERSATION_ARG];\n\n/**\n * @internal The tools/call _meta keys a harness names its conversation in\n * (the core's harnesses ConversationMeta, dotted for nested objects):\n * test/conversation-meta.json, which a Go test keeps current.\n */\nexport const CONVERSATION_META: readonly string[] = [\n \"agent-session-id\",\n \"antigravity.google/conversation_id\",\n \"vscode.conversationId\",\n \"wakeshift/conversation\",\n \"x-codex-turn-metadata.thread_id\",\n];\n\n/**\n * The calling conversation's subscription, made or renewed by\n * call.subscribe. id and user address it later: emit's\n * `to: [{ user, subscription: id }]`, or `event.end(user, id)`.\n */\nexport interface Subscription {\n id: string;\n user: string;\n /** False for a renewal. */\n created: boolean;\n /** The conversation's session. A secret: don't show, store or log it. */\n session: string;\n /** What Wakeshift recognized the agent's program as. */\n recognized: Recognized;\n /** The caller subscribes itself (call.native): nothing was made, id is \"\", and the block tells it what to subscribe to. */\n native: boolean;\n}\n\n/** How call.subscribe subscribes. */\nexport interface ToolSubscribeOptions {\n /** End after this long without a delivery or a fresh subscribe (default 30 days). */\n ttl?: Duration;\n /** Why the app subscribes the conversation, shown in the console (at most 200 characters). */\n reason?: string;\n /** Names a new session (agent@label), for an app acting for its agents. */\n label?: string;\n}\n\n/**\n * One call of a wrapped tool (attached.events): who's calling, and the\n * calls that subscribe the calling conversation. Only the wrapper makes\n * one, and it works until the handler returns (then CallEnded).\n */\nexport interface ToolCall {\n /** Who attach's identify says is calling (undefined for none). */\n readonly user: string | undefined;\n /** The tool being called. */\n readonly tool: string;\n /**\n * The client subscribes to the app's events itself (MCP Events: ChatGPT,\n * the house agents). call.subscribe then makes no conversation\n * subscription, and the block tells it what to subscribe to.\n */\n readonly native: boolean;\n /** A native client's conversation, when it names one (ChatGPT's _meta[\"openai/session\"]). */\n readonly nativeConversation: string | null;\n /** The session_key passed; after a subscribe or resolveSession, the conversation's session. */\n readonly session: string | null;\n /** What Wakeshift recognized the agent's program as: null until a subscribe or resolveSession. */\n readonly recognized: Recognized | null;\n /** MCP's own extra for the call. */\n readonly extra: ToolCallExtra;\n /**\n * Subscribes the calling conversation to event with args, or renews its\n * subscription. The reply then carries what the conversation needs to be\n * woken (one block for the call, however many subscribes it makes), and\n * if the call fails, the subscription is ended. For a native caller\n * nothing is made. Your tool decides who may: authorize isn't consulted.\n * A personal event needs a user (identify's).\n */\n subscribe<A extends AnySchema>(event: WakeEvent<A, any>, args: SchemaInput<A>, opts?: ToolSubscribeOptions): Promise<Subscription>;\n /**\n * Ends the calling conversation's subscription to event with args,\n * resolving to whether one ended. For a native caller it ends the user's\n * own (webhook) subscriptions to the event with those arguments.\n */\n unsubscribe<A extends AnySchema>(event: WakeEvent<A, any>, args: SchemaInput<A>): Promise<boolean>;\n /** Finds or starts the calling conversation's session without subscribing it (it doesn't make it wakeable). */\n resolveSession(): Promise<string>;\n}\n\n/** A ToolCall used after its handler returned. */\nexport class CallEnded extends Error {\n constructor() {\n super(\"wakeshift: the tool call has ended: subscribe before the handler returns\");\n this.name = \"CallEnded\";\n }\n}\n\n/** attach's event options. */\nexport interface EventsOptions {\n /**\n * Asked first whether a wrapped tool's call comes from a client that\n * subscribes to the app's events itself (call.native), for callers the\n * SDK can't tell (an app's own house agents). False leaves it to the\n * SDK's own checks.\n */\n native?: (extra: ToolCallExtra) => boolean;\n}\n\n// The line a text-carried beacon is on (the core's beacon.Text), which a\n// harness's hook reads only as the last line of a result's text.\nconst BEACON_LINE_PREFIX = \"(For Wakeshift's hook on this computer, not for you: wakeshift-beacon: \";\nconst CONNECTOR_META_KEY = \"wakeshift/connector\";\n// The most native lines Wakeshift takes for one call.\nconst MAX_NATIVE_LINES = 20;\n\n/** /calls/addition's answer. */\nexport interface CallAddition {\n text?: string;\n trailer?: string;\n meta?: Record<string, unknown>;\n}\n\ntype Content = CallToolResult[\"content\"][number];\n\n// takeTrailer takes a beacon line off the end of the result's text\n// (dropping its block if nothing else is in it), returning it (\"\" if\n// there's none).\nfunction takeTrailer(content: Content[]): string {\n const last = content.at(-1);\n if (!last || last.type !== \"text\") return \"\";\n const text = last.text.replace(/[ \\t\\r\\n]+$/, \"\");\n const i = text.lastIndexOf(\"\\n\");\n const line = i >= 0 ? text.slice(i + 1) : text;\n if (!line.startsWith(BEACON_LINE_PREFIX) || !line.endsWith(\")\")) return \"\";\n const rest = i >= 0 ? text.slice(0, i).replace(/[ \\t\\r\\n]+$/, \"\") : \"\";\n if (rest === \"\") content.pop();\n else content[content.length - 1] = { ...last, text: rest };\n return line;\n}\n\n/**\n * @internal Adds the call's block to a wrapped handler's result: Wakeshift's\n * text as a block after the app's content, then a text-carried beacon last,\n * and _meta; a string result stays one text block. A result that already\n * carries a beacon keeps it, last, and gets no second one. With wakeOutput,\n * structuredContent's wakeshift is the block's text. test/wrapped-block.json\n * is the shape, shared with the other SDKs.\n */\nexport function mergeBlock(result: WrappedResult, add: CallAddition, wakeOutput: boolean): CallToolResult {\n const isString = typeof result === \"string\";\n const base: CallToolResult = isString ? { content: [{ type: \"text\", text: result }] } : result;\n const out: CallToolResult = { ...base, content: [...(base.content ?? [])] };\n const text = (add.text ?? \"\").trim();\n const metaBeacon = !!out._meta && CONNECTOR_META_KEY in out._meta;\n const existing = takeTrailer(out.content);\n if (text) out.content.push({ type: \"text\", text });\n const has = metaBeacon || existing !== \"\";\n if (existing) out.content.push({ type: \"text\", text: existing });\n else if (!has && add.trailer) out.content.push({ type: \"text\", text: add.trailer });\n for (const [k, v] of Object.entries(add.meta ?? {})) {\n if (k === CONNECTOR_META_KEY && has) continue;\n out._meta = { ...(out._meta ?? {}), [k]: v };\n }\n if (isString) {\n const texts = out.content.map((c) => (c.type === \"text\" ? c.text : \"\")).filter((t) => t !== \"\");\n out.content = [{ type: \"text\", text: texts.join(\"\\n\\n\") }];\n }\n if (text && wakeOutput && out.structuredContent && typeof out.structuredContent === \"object\" && !Array.isArray(out.structuredContent)) {\n out.structuredContent = { ...out.structuredContent, wakeshift: text };\n }\n return out;\n}\n\n// metaString is the string at key in a tool call's _meta: the key itself,\n// else a dotted path into nested objects (the core's harnesses.metaString).\nfunction metaString(meta: Record<string, unknown> | undefined, key: string): string {\n if (!meta) return \"\";\n const limit = (s: unknown) => (typeof s === \"string\" && s.length <= 200 ? s : \"\");\n if (typeof meta[key] === \"string\") return limit(meta[key]);\n let cur: unknown = meta;\n for (const part of key.split(\".\")) {\n if (!cur || typeof cur !== \"object\" || Array.isArray(cur)) return \"\";\n cur = (cur as Record<string, unknown>)[part];\n }\n return limit(cur);\n}\n\n/** @internal Whether a tool call's _meta names its conversation, the way a harness puts it there (test/conversation-meta.json). */\nexport function namesConversation(meta: Record<string, unknown> | undefined): boolean {\n return CONVERSATION_META.some((k) => metaString(meta, k) !== \"\");\n}\n\nfunction sameJSON(a: unknown, b: unknown): boolean {\n const norm = (v: unknown): unknown =>\n v === null || v === undefined\n ? {}\n : Array.isArray(v)\n ? v.map(norm)\n : typeof v === \"object\"\n ? Object.fromEntries(Object.keys(v as object).sort().map((k) => [k, norm((v as Record<string, unknown>)[k])]))\n : v;\n return JSON.stringify(norm(a)) === JSON.stringify(norm(b));\n}\n\nfunction detailOf(err: unknown): string {\n return err instanceof WakeshiftError ? err.detail : String((err as Error)?.message ?? err);\n}\n\n// The parts of an McpServer the wrapper reads that aren't public: its\n// registered tools (the handler, input and output schemas). A unit test pins\n// them against the supported MCP SDK versions.\ninterface RegisteredToolInternal {\n inputSchema?: AnySchema;\n outputSchema?: AnySchema;\n handler?: unknown;\n callback?: unknown;\n}\n\nfunction registeredTool(server: McpServer, name: string): RegisteredToolInternal | undefined | null {\n const tools = (server as unknown as { _registeredTools?: Record<string, RegisteredToolInternal> })._registeredTools;\n if (!tools || typeof tools !== \"object\") return null; // an MCP SDK that keeps them elsewhere\n return tools[name];\n}\n\ninterface CreatedSub {\n name: string;\n arguments: unknown;\n session: string;\n pending: string; // the call's pending-addition record, which made it\n}\n\ninterface NativeLine {\n name: string;\n arguments: unknown;\n}\n\n/** @internal What the wrapper needs of attach: the client, the server, who's calling, the event options. */\nexport interface AttachContext {\n wake: Wakeshift;\n server: McpServer;\n /** Who attach's identify says is calling: its user and client. */\n identify(extra: ToolCallExtra): Identity | undefined;\n /** The client's name: the request's (initialize's, else _meta's), else identified (identify's), else \"\". */\n clientOf(meta: Record<string, unknown> | undefined, identified?: string): string;\n events: EventsOptions;\n warnOnce(key: string, message: string): void;\n}\n\n/** One tools/call of a wrapped tool: what its handler subscribed, for the block and the rollback. */\nclass CallScope implements ToolCall {\n user: string | undefined;\n tool: string;\n native = false;\n nativeConversation: string | null = null;\n session: string | null;\n recognized: Recognized | null = null;\n extra: ToolCallExtra;\n\n ended = false;\n pending = \"\";\n armed = false;\n created: CreatedSub[] = [];\n nativeLines: NativeLine[] = [];\n inflight = new Set<Promise<unknown>>();\n private queue: Promise<unknown> = Promise.resolve();\n // The client's name identify gave, for a request that names none.\n private readonly identified: string | undefined;\n\n constructor(\n private readonly at: AttachContext,\n tool: string,\n extra: ToolCallExtra,\n private readonly args: { session?: string; harness?: string; conversation?: string },\n ) {\n this.tool = tool;\n this.extra = extra;\n const id = at.identify(extra);\n this.user = id?.user;\n this.identified = id?.client;\n this.session = args.session || null;\n const n = nativeOf(at, extra, this.identified);\n this.native = n.native;\n this.nativeConversation = n.conversation;\n }\n\n // wire is the call as Wakeshift takes it: the request's client, _meta and\n // User-Agent, the agent's harness and conversation_id arguments, the\n // conversation's session, and who's calling.\n wire(session = this.session): Call {\n const meta = this.extra._meta as Record<string, unknown> | undefined;\n return packCall({\n meta,\n clientName: this.at.clientOf(meta, this.identified),\n user: this.user,\n session: session ?? undefined,\n userAgent: userAgentOf(this.extra),\n harness: this.args.harness,\n conversation: this.args.conversation,\n tool: this.tool,\n });\n }\n\n // request runs one request of the call to Wakeshift, after any before it\n // (one at a time per call), refusing once the handler has returned.\n private request<T>(fn: () => Promise<T>): Promise<T> {\n if (this.ended) return Promise.reject(new CallEnded());\n const run = this.queue.then(() => (this.ended ? Promise.reject(new CallEnded()) : fn()));\n this.queue = run.catch(() => undefined);\n this.inflight.add(run);\n run.then(\n () => this.inflight.delete(run),\n () => this.inflight.delete(run),\n );\n return run;\n }\n\n private checkEvent(event: WakeEvent<any, any>): void {\n if (!event || typeof event.owner !== \"function\" || event.owner() !== this.at.wake) {\n throw new WakeshiftError(404, \"unknown_event\", `${event?.name ?? \"that\"} is another app's event: this app doesn't offer it`);\n }\n }\n\n subscribe<A extends AnySchema>(event: WakeEvent<A, any>, args: SchemaInput<A>, opts: ToolSubscribeOptions = {}): Promise<Subscription> {\n return this.request(async () => {\n this.checkEvent(event);\n const known = event.parseArgs(args);\n if (this.native) {\n this.addNative(event.name, known);\n return { id: \"\", user: this.user ?? \"\", created: false, session: \"\", recognized: { harness: null, via: null, claimed: null }, native: true };\n }\n if (event.personal && !this.user) {\n throw new WakeshiftError(400, \"bad_arguments\", `${event.name} is personal: call.subscribe needs a user (attach's identify), who the subscription belongs to`);\n }\n const body: Record<string, unknown> = { call: this.wire(), name: event.name, arguments: known, defer_addition: true };\n if (this.pending) body.pending = this.pending;\n if (opts.ttl !== undefined) body.ttl = opts.ttl;\n if (opts.reason) body.reason = opts.reason;\n if (opts.label) body.label = opts.label;\n const out = await this.at.wake.requestApp<{\n event_subscription: { id: string; user?: string; created: boolean };\n session: string;\n agent?: Partial<Recognized>;\n pending?: string;\n }>(\"POST\", \"/event-subscriptions\", body);\n if (out.pending) this.pending = out.pending;\n this.armed = true;\n this.session = out.session;\n const rec = recognizedOf(out.agent);\n this.recognized = rec;\n const es = out.event_subscription;\n if (es.created) this.created.push({ name: event.name, arguments: known, session: out.session, pending: out.pending ?? this.pending });\n return { id: es.id, user: es.user ?? this.user ?? \"\", created: !!es.created, session: out.session, recognized: rec, native: false };\n });\n }\n\n unsubscribe<A extends AnySchema>(event: WakeEvent<A, any>, args: SchemaInput<A>): Promise<boolean> {\n return this.request(async () => {\n this.checkEvent(event);\n const known = event.parseArgs(args);\n if (this.native) return this.endNative(event.name, known);\n const out = await this.at.wake.requestApp<{ ended?: boolean }>(\"POST\", \"/event-subscriptions/unsubscribe\", { call: this.wire(), name: event.name, arguments: known });\n return !!out.ended;\n });\n }\n\n resolveSession(): Promise<string> {\n return this.request(async () => {\n if (this.pending && this.session) return this.session;\n const out = await this.at.wake.requestApp<{ session: string; pending: string; agent?: Partial<Recognized> }>(\"POST\", \"/calls/session\", { call: this.wire() });\n this.pending = out.pending;\n this.session = out.session;\n this.recognized = recognizedOf(out.agent);\n return out.session;\n });\n }\n\n // endNative ends the user's webhook subscriptions to event with these arguments.\n private async endNative(name: string, args: unknown): Promise<boolean> {\n if (!this.user) return false;\n const out = await this.at.wake.requestApp<{ subscriptions?: { id: string; event: string; arguments: unknown; destination: string }[] }>(\"POST\", \"/event-subscriptions/list\", {\n user: this.user,\n });\n let ended = false;\n for (const s of out.subscriptions ?? []) {\n if (s.event !== name || s.destination !== \"webhook\" || !sameJSON(s.arguments, args)) continue;\n const r = await this.at.wake.requestApp<{ ended?: boolean }>(\"POST\", \"/event-subscriptions/end\", { user: this.user, id: s.id });\n ended = ended || !!r.ended;\n }\n return ended;\n }\n\n // addNative adds a native line, once per event and arguments.\n private addNative(name: string, args: unknown): void {\n if (this.nativeLines.some((l) => l.name === name && sameJSON(l.arguments, args))) return;\n if (this.nativeLines.length === MAX_NATIVE_LINES) {\n this.at.warnOnce(\n \"native:\" + this.tool,\n `wakeshift: the wrapped tool ${this.tool} subscribed a native client to more than ${MAX_NATIVE_LINES} events in one call; only ${MAX_NATIVE_LINES} are named`,\n );\n return;\n }\n this.nativeLines.push({ name, arguments: args });\n }\n\n // end closes the call to further requests, after waiting for any in\n // flight (warning once per tool: the handler should have waited for them).\n async end(): Promise<void> {\n if (this.inflight.size > 0) {\n this.at.warnOnce(\n \"inflight:\" + this.tool,\n `wakeshift: the wrapped tool ${this.tool} returned while a subscribe was in flight; it was waited for: await call.subscribe, call.unsubscribe and call.resolveSession before returning`,\n );\n await Promise.allSettled([...this.inflight]);\n }\n this.ended = true;\n }\n\n // rollback ends every subscription the call created and no other call\n // has renewed since (the core checks the pending record that made it),\n // with reason rolled_back (audited as such, no \"ended\" notice), whatever\n // became of the request.\n async rollback(): Promise<void> {\n for (const c of this.created) {\n try {\n await this.at.wake.requestApp(\"POST\", \"/event-subscriptions/unsubscribe\", { call: this.wire(c.session), name: c.name, arguments: c.arguments, reason: \"rolled_back\", pending: c.pending });\n } catch (err) {\n this.at.wake.warn(`wakeshift: rolling back a failed tool call's subscription (${this.tool}, ${c.name}): ${detailOf(err)}`);\n }\n }\n this.created = [];\n }\n\n // addition asks Wakeshift for the call's block: what the conversation\n // needs to be woken (from the call's pending-addition record, if a\n // subscribe or resolveSession made one; otherwise what any other tool\n // result of the app's carries), and a line per event a native caller\n // should subscribe to. A call that names no conversation, and subscribed\n // nothing, gets nothing (null). Only a failure for a call that subscribed\n // is thrown: without a subscription, the block is a courtesy.\n async addition(): Promise<CallAddition | null> {\n const wire = this.wire();\n if (!this.pending && this.nativeLines.length === 0 && !wire.session && !wire.conversation && !namesConversation(wire.meta)) return null;\n const body: Record<string, unknown> = { call: wire };\n if (this.pending) body.pending = this.pending;\n if (this.nativeLines.length > 0) body.native = this.nativeLines;\n try {\n return await this.at.wake.requestApp<CallAddition>(\"POST\", \"/calls/addition\", body);\n } catch (err) {\n if (this.armed || this.nativeLines.length > 0) throw err;\n this.at.wake.warn(`wakeshift: Wakeshift's addition to a result of ${this.tool}: ${detailOf(err)}`);\n return null;\n }\n }\n}\n\nfunction recognizedOf(a: Partial<Recognized> | undefined): Recognized {\n return { harness: a?.harness ?? null, via: a?.via ?? null, claimed: a?.claimed ?? null };\n}\n\nfunction headerOf(extra: ToolCallExtra, name: string): string {\n const h = extra?.requestInfo?.headers as Record<string, string | string[] | undefined> | undefined;\n if (!h) return \"\";\n const v = h[name] ?? h[name.toLowerCase()];\n return (Array.isArray(v) ? v[0] : v) ?? \"\";\n}\n\nfunction userAgentOf(extra: ToolCallExtra): string {\n return headerOf(extra, \"user-agent\") || headerOf(extra, \"User-Agent\");\n}\n\nfunction hasKey(o: unknown, key: string): boolean {\n return !!o && typeof o === \"object\" && !Array.isArray(o) && (o as Record<string, unknown>)[key] !== undefined;\n}\n\n/**\n * @internal Whether a call comes from a client that subscribes to the app's\n * events itself, on stateless servers too (which never see initialize), in\n * this order: the app's override (events.native); ChatGPT's\n * _meta[\"openai/session\"]; a client name (initialize's, or _meta's, else\n * identify's) or User-Agent of a known native client; a client that\n * declares the MCP Events extension (initialize's capabilities, or\n * _meta's). conversation is ChatGPT's conversation, when it names one.\n */\nexport function nativeOf(\n at: Pick<AttachContext, \"server\" | \"clientOf\" | \"events\">,\n extra: ToolCallExtra,\n identified?: string,\n): { native: boolean; conversation: string | null } {\n const meta = (extra._meta ?? {}) as Record<string, unknown>;\n const conversation = typeof meta[\"openai/session\"] === \"string\" && meta[\"openai/session\"] ? (meta[\"openai/session\"] as string) : null;\n if (at.events.native?.(extra)) return { native: true, conversation };\n if (conversation) return { native: true, conversation };\n if (dialectOf(at.clientOf(meta, identified), userAgentOf(extra)) === \"chatgpt\") return { native: true, conversation: null };\n const caps = at.server.server.getClientCapabilities() as Record<string, unknown> | undefined;\n if (hasKey(caps?.extensions, EXTENSION_KEY)) return { native: true, conversation: null };\n const metaCaps = meta[\"io.modelcontextprotocol/clientCapabilities\"] as Record<string, unknown> | undefined;\n if (hasKey(metaCaps?.extensions, EXTENSION_KEY)) return { native: true, conversation: null };\n return { native: false, conversation: null };\n}\n\n/**\n * Wakeshift attached to an MCP server: the handle `wake.attach` returns.\n * Wrap a tool's callback with events, and give its input schema\n * Wakeshift's three arguments with inputs.\n */\nexport class Attached {\n /** @internal */\n private readonly wrapped = new Map<string, unknown>();\n\n /** @internal Use wake.attach. */\n constructor(private readonly at: AttachContext) {}\n\n /**\n * shape plus Wakeshift's three optional arguments (session_key, harness\n * and conversation_id), for a wrapped tool's inputSchema:\n * `inputSchema: attached.inputs({ table: z.string() })`.\n */\n inputs<S extends ZodRawShapeCompat>(shape: S): S & WakeInputs {\n for (const k of WAKE_KEYS) if (k in (shape ?? {})) throw new Error(`wakeshift: attached.inputs adds ${k} itself: leave it out of the shape`);\n return { ...shape, ...fieldsFor(shape, \"inputs\") };\n }\n\n /**\n * shape plus an optional wakeshift string, for a wrapped tool's\n * outputSchema: the wrapper sets it to the block's text (without the\n * beacon line), for hosts that show the model only structuredContent.\n * The block stays in the content too.\n */\n output<S extends ZodRawShapeCompat>(shape: S): S & WakeOutputShape {\n if (\"wakeshift\" in (shape ?? {})) throw new Error(\"wakeshift: attached.output adds wakeshift itself: leave it out of the shape\");\n return { ...shape, ...fieldsFor(shape, \"output\") };\n }\n\n /**\n * Wraps a tool's callback, for `server.registerTool(name, …)` with the\n * same name (MCP doesn't tell a callback its tool's name): the handler\n * gets the tool's own arguments and a ToolCall, and returns a string or\n * a CallToolResult; the reply gets Wakeshift's block. The tool's\n * inputSchema must come from attached.inputs (a type error otherwise).\n * Register it on the server passed to attach.\n */\n events<S extends WakeShape>(name: string, handler: (args: AppArgs<S>, call: ToolCall) => WrappedResult | Promise<WrappedResult>): ToolCallback<S> {\n if (!name || typeof name !== \"string\") throw new Error(\"wakeshift: attached.events needs the tool's name, as registered\");\n if (typeof handler !== \"function\") throw new Error(\"wakeshift: attached.events needs a handler\");\n const cb = (async (args: Record<string, unknown>, extra: ToolCallExtra) => this.run(name, cb, handler as any, args ?? {}, extra)) as unknown as ToolCallback<S>;\n this.wrapped.set(name, cb);\n return cb;\n }\n\n private async run(\n name: string,\n cb: unknown,\n handler: (args: Record<string, unknown>, call: ToolCall) => WrappedResult | Promise<WrappedResult>,\n input: Record<string, unknown>,\n extra: ToolCallExtra,\n ): Promise<CallToolResult> {\n const tool = registeredTool(this.at.server, name);\n if (tool === undefined || (tool && (tool.handler ?? tool.callback) !== cb)) {\n throw new Error(`wakeshift: attached.events(\"${name}\", …) isn't the tool named ${name} on the server passed to attach: register it with the same name, on that server`);\n }\n let wakeOutput = false;\n let outputSchema: AnySchema | undefined;\n if (tool) {\n const shape = getObjectShape(normalizeObjectSchema(tool.inputSchema));\n if (!shape || WAKE_KEYS.some((k) => !(k in shape))) {\n throw new Error(`wakeshift: the tool ${name} doesn't take Wakeshift's arguments: make its inputSchema with attached.inputs(…)`);\n }\n outputSchema = tool.outputSchema;\n const out = getObjectShape(normalizeObjectSchema(outputSchema));\n wakeOutput = !!out && \"wakeshift\" in out;\n } else {\n this.at.warnOnce(\"internals\", \"wakeshift: this MCP SDK keeps its tools where Wakeshift can't read them, so wrapped tools' registration and output aren't checked\");\n }\n const str = (k: string) => (typeof input[k] === \"string\" && (input[k] as string) ? (input[k] as string) : undefined);\n const call = new CallScope(this.at, name, extra, { session: str(SESSION_ARG), harness: str(HARNESS_ARG), conversation: str(CONVERSATION_ARG) });\n const appArgs: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(input)) if (!(WAKE_KEYS as readonly string[]).includes(k)) appArgs[k] = v;\n\n let result: WrappedResult;\n try {\n result = await handler(appArgs, call);\n } catch (err) {\n await call.end();\n await call.rollback();\n throw err;\n }\n await call.end();\n // Rollback is decided from the final result, the one the client would\n // receive: MCP validates the output after this callback returns, so\n // the wrapper checks it the same way first.\n if (result === null || result === undefined || (typeof result !== \"string\" && typeof result !== \"object\")) {\n await call.rollback();\n return result as unknown as CallToolResult;\n }\n if ((typeof result === \"object\" && result.isError) || extra?.signal?.aborted || !(await validOutput(outputSchema, result))) {\n await call.rollback();\n return typeof result === \"string\" ? { content: [{ type: \"text\", text: result }] } : result;\n }\n let add: CallAddition | null;\n try {\n add = await call.addition();\n } catch (err) {\n // The conversation is subscribed but wouldn't learn how it's woken:\n // the call fails, as one whose handler failed does.\n await call.rollback();\n this.at.wake.warn(`wakeshift: Wakeshift's block for a result of ${name} failed, so the call's subscriptions were rolled back: ${detailOf(err)}`);\n return { isError: true, content: [{ type: \"text\", text: `Wakeshift couldn't finish setting up this conversation's wakes (${detailOf(err)}). Try again.` }] };\n }\n const out = mergeBlock(result, add ?? {}, wakeOutput);\n if ((add?.text ?? \"\").trim() && !wakeOutput && out.structuredContent) {\n this.at.warnOnce(\n \"output:\" + name,\n `wakeshift: the wrapped tool ${name} returns structuredContent without attached.output: hosts that show only structuredContent won't see how this conversation is woken`,\n );\n }\n return out;\n }\n}\n\n// validOutput mirrors McpServer's own check of a result against the tool's\n// outputSchema (validateToolOutput): one it would refuse fails the call.\nasync function validOutput(outputSchema: AnySchema | undefined, result: WrappedResult): Promise<boolean> {\n if (!outputSchema) return true;\n if (typeof result === \"string\" || !result.structuredContent) return false;\n const obj = normalizeObjectSchema(outputSchema);\n if (!obj) return true;\n return (await safeParseAsync(obj, result.structuredContent)).success;\n}\n"]}
@@ -1,8 +1,7 @@
1
- import { z } from "zod";
2
- import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
1
  import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
2
  import type { AnySchema } from "@modelcontextprotocol/sdk/server/zod-compat.js";
5
3
  import { WakeEvent, type AttachOptions, type EventOptions, type EventTypeManifest } from "./events.js";
4
+ import type { Attached } from "./toolcall.js";
6
5
  /** Wakeshift's production core, the default for every key but an older wst_test_ one. Override with `core` or WAKESHIFT_CORE. */
7
6
  export declare const DEFAULT_CORE = "https://app.wakeshift.ai";
8
7
  /** The tool argument an agent passes its session key in (a result gives it one). */
@@ -29,8 +28,10 @@ export interface WakeshiftOptions {
29
28
  timeoutMs?: number;
30
29
  /**
31
30
  * Called with a problem that doesn't fail the call but makes it work less
32
- * well, for example a tool call Wakeshift recognised no harness in. Each kind is
33
- * reported once. Default: console.warn.
31
+ * well: each time for a failure, such as a failed call's subscription
32
+ * that couldn't be rolled back, and once for each kind of misuse, such as
33
+ * a wrapped tool that returned with a subscribe still in flight. Default:
34
+ * console.warn.
34
35
  */
35
36
  onWarning?: (message: string) => void;
36
37
  }
@@ -38,48 +39,21 @@ export interface WakeshiftOptions {
38
39
  export interface AppInfo {
39
40
  id: string;
40
41
  name: string;
41
- }
42
- /** What the SDK says, once, when Wakeshift recognised no harness in a tool call. */
43
- export declare const UNKNOWN_CLIENT_WARNING: string;
44
- /**
45
- * Who called one of the app's tools, as Wakeshift needs it. Make one with
46
- * `wake.call(extra, …)` inside an MCP tool callback, or `wake.callOf(…)`.
47
- */
48
- export interface Call {
49
- /** The app's own ID for the person (optional). */
50
- user?: string;
51
- /**
52
- * The MCP client's name (initialize's clientInfo.name). A stateless
53
- * server has none; Wakeshift then tells the harness from meta, else
54
- * user_agent.
55
- */
56
- client: string;
57
- /** The tool call's _meta (Codex sends its thread there). */
58
- meta?: Record<string, unknown>;
59
- /** The session handle an earlier result gave the agent. */
60
- session?: string;
61
- /** The MCP request's HTTP User-Agent. */
62
- user_agent?: string;
63
- /** The conversation's ID as the agent passed it (conversation_id: Cursor's CURSOR_CONVERSATION_ID). */
64
- conversation?: string;
65
- /** The program the agent says it runs in (harness): a hint, never a credential. */
66
- harness?: string;
67
- /**
68
- * The name of the tool being called. A connector beacon in its result
69
- * names it, and Wakeshift's hooks act on the beacon only from that
70
- * tool's result: put the addition in the result of the tool you name.
71
- */
72
- tool?: string;
42
+ /** The key: the console's ID for it, and its name ("" if Wakeshift didn't say). */
43
+ key: {
44
+ id: string;
45
+ name: string;
46
+ };
73
47
  }
74
48
  /**
75
- * What Wakeshift recognised the calling conversation's harness as, and by
49
+ * What Wakeshift recognized the calling conversation's harness as, and by
76
50
  * which signal ("claim": only the agent's harness argument named it); both
77
51
  * null when nothing named one. claimed is what the agent said (normalized:
78
52
  * "Grok Bot" is grok-bot), null if it didn't; a claimed that differs from
79
- * harness was ignored, since it contradicted what the call was recognised
53
+ * harness was ignored, since it contradicted what the call was recognized
80
54
  * as (the claim only refines it: Cursor's calls may be Grok Bot's).
81
55
  */
82
- export interface Recognised {
56
+ export interface Recognized {
83
57
  harness: string | null;
84
58
  via: "client" | "meta" | "user_agent" | "claim" | null;
85
59
  claimed: string | null;
@@ -89,90 +63,41 @@ export interface Recognised {
89
63
  * value: days must be whole ("1.5d" is a bad_request; use "36h").
90
64
  */
91
65
  export type Duration = number | `${number}${"s" | "m" | "h" | "d"}`;
92
- export interface SubscribeOptions {
93
- /** Wake only for events whose data has these top-level fields equal to these values. */
94
- filter?: Record<string, string | number | boolean | null>;
95
- /** End after the first delivery. */
96
- once?: boolean;
97
- /** Deliver the latest event published within this long before subscribing (at most 24 hours). */
98
- replay?: Duration;
99
- /** End after this long without a delivery or a fresh subscribe (1 minute to 365 days; default 30 days). */
100
- ttl?: Duration;
101
- }
102
- /** What Wakeshift adds to a tool result: text for the agent, _meta for its harness. */
103
- export interface Addition {
104
- text?: string;
105
- meta?: Record<string, unknown>;
106
- /** What Wakeshift recognised the caller's harness as (not added to the result). */
107
- agent?: Recognised;
108
- }
109
- export interface Subscription {
110
- /** For `send`. */
111
- id: string;
112
- topic: string;
113
- filter?: Record<string, unknown>;
114
- once: boolean;
115
- expiresAt: Date;
116
- /**
117
- * The conversation's session key (the agent passes it back as session_key;
118
- * the result says so). It's a secret that acts as the conversation: don't
119
- * show, store or log it. To name the conversation, use id, or an HMAC of it.
120
- */
121
- session: string;
122
- /** What the tool result must carry for the caller's harness. */
123
- addition: Addition;
124
- /** What Wakeshift recognised the caller's harness as. */
125
- agent: Recognised;
126
- /**
127
- * The tool result to return: your text (or result) followed by
128
- * Wakeshift's, with its _meta.
129
- */
130
- result(text: string | CallToolResult): CallToolResult;
131
- }
132
- export interface TopicEvent {
133
- /** What the agent reads first (at most 1000 bytes). */
134
- text: string;
135
- /** A JSON object, within the 64 KB request limit; filters match its top-level fields. */
136
- data?: Record<string, unknown>;
137
- /** Makes retries publish once for a day (at most 200 characters); after a day, the same id publishes again. */
138
- id?: string;
139
- }
140
- export interface Published {
66
+ /**
67
+ * One recipient of a personal event's emit, beside a plain user (the app's
68
+ * ID for them: every subscription they have to the event with these
69
+ * arguments): `{ user, subscription }`, exactly that subscription of that
70
+ * user's; `{ native: user }`, only that user's native (webhook)
71
+ * subscriptions to the event with these arguments.
72
+ */
73
+ export type Recipient = {
74
+ user: string;
75
+ subscription: string;
76
+ } | {
77
+ native: string;
78
+ };
79
+ /** What an event's emit did. */
80
+ export interface Emitted {
141
81
  /** Conversations it woke (or will). */
142
82
  matched: number;
143
- /** An earlier publish had this event's id. */
83
+ /** An earlier emit had this occurrence's id. */
144
84
  duplicate: boolean;
85
+ /** User and native recipients with no live subscription it reached (an emit to several recipients only). */
86
+ unmatched: (string | Recipient)[];
87
+ /** Subscription recipients no longer live (or not that user's). */
88
+ ended: (string | Recipient)[];
145
89
  }
146
- /** delivered: on its way to a connected conversation; queued: waits for it; closed: the subscription ended. */
147
- export type SendStatus = "delivered" | "queued" | "closed";
148
90
  /**
149
- * How a conversation is connected: stream (a stream held open, e.g.
150
- * Cursor's background command), poll (long polls or waits, e.g. Claude
151
- * Code's Monitor, in the last minute) or hooks (Wakeshift's hooks or
152
- * connector on the user's machine).
91
+ * How a connected conversation receives what it's woken by: stream (it holds
92
+ * a connection to Wakeshift open), poll (it asked Wakeshift for messages
93
+ * within the last minute), hooks (Wakeshift's connector on the user's
94
+ * computer delivers to it) or webhook (its client subscribed with MCP
95
+ * Events, and Wakeshift sends to the client's webhook).
153
96
  */
154
97
  export type Via = "stream" | "poll" | "hooks" | "webhook";
155
- export interface TopicStatus {
156
- topic: string;
157
- /** Conversations subscribed (ended or expired subscriptions don't count). */
158
- subscriptions: number;
159
- /** Of those, connected now. */
160
- connected: number;
161
- /** How many are connected each way. */
162
- via: Record<Via, number>;
163
- }
164
- export interface SubscriptionStatus {
165
- id: string;
166
- topic: string;
167
- status: "active" | "closed";
168
- connected: boolean;
169
- via?: Via;
170
- expiresAt?: Date;
171
- }
172
- /** A publish URL: `topic` for a topic's (`wake.publishUrl`), `event` for an event's (`event.publishUrl`). */
98
+ /** An event's publish URL (`event.publishUrl`). */
173
99
  export interface PublishUrl {
174
100
  id: string;
175
- topic?: string;
176
101
  event?: string;
177
102
  url: string;
178
103
  }
@@ -194,14 +119,23 @@ export interface AgentScope {
194
119
  }[];
195
120
  /** What the person should say to their agent once it's connected; at most 120 characters. */
196
121
  start_prompt?: string;
197
- groups?: boolean;
198
122
  }
199
123
  /** What the app tells Wakeshift it may do (see wake.publishManifest). */
200
124
  export interface Manifest {
201
125
  description?: string;
202
126
  agent?: AgentScope;
203
- /** The app's event types: defineEvent fills this in for you. */
127
+ /** Event types defined elsewhere, not with defineEvent: Wakeshift gets these, then the defined ones. Listing a defined one is an error. */
204
128
  events?: EventTypeManifest[];
129
+ /** 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. */
130
+ others_can_wake?: boolean;
131
+ /**
132
+ * Your MCP tools (as your server lists them) that agents' programs can run without asking each time:
133
+ * tools that only read, and routine ones the agent calls on every wake that reach only what it already joined.
134
+ * Never one that deletes, spends, or reaches people the user hasn't chosen. When a user connects Claude Code
135
+ * or Cursor CLI, Wakeshift offers to allow exactly these, by name, in the same question as its install.
136
+ * Letters, digits, _ and -; at most 20.
137
+ */
138
+ preapprove_tools?: string[];
205
139
  }
206
140
  /** The parts of an MCP tool callback's `extra` that Wakeshift reads. */
207
141
  export interface ToolExtra {
@@ -210,62 +144,11 @@ export interface ToolExtra {
210
144
  headers?: Record<string, string | string[] | undefined>;
211
145
  };
212
146
  }
213
- /** An McpServer or a low-level Server: anything that knows its client's name. */
214
- export type ClientInfoSource = {
215
- getClientVersion(): {
216
- name: string;
217
- } | undefined;
218
- } | {
219
- server: {
220
- getClientVersion(): {
221
- name: string;
222
- } | undefined;
223
- };
224
- };
225
- export interface CallOptions {
226
- /** The MCP server the call came to, for the client's name (or pass client). */
227
- server?: ClientInfoSource;
228
- /** The client's name, if you know it (instead of server). */
229
- client?: string;
230
- /** The app's own ID for the person. */
231
- user?: string;
232
- /** The tool's arguments: session_key, harness and conversation_id (wake.args) are read from them. */
233
- args?: {
234
- [SESSION_ARG]?: string;
235
- [HARNESS_ARG]?: string;
236
- [CONVERSATION_ARG]?: string;
237
- } | Record<string, unknown>;
238
- /** The session key, if you read it yourself. */
239
- session?: string;
240
- /** The program the agent says it runs in (harness), if you read it yourself. */
241
- harness?: string;
242
- /** The conversation's ID the agent passed (conversation_id), if you read it yourself. */
243
- conversation?: string;
244
- /**
245
- * The name of the tool being called (the MCP SDK doesn't hand callbacks
246
- * it, so pass it): Wakeshift's hooks act on a connector beacon only from
247
- * the result of the tool it names.
248
- */
249
- tool?: string;
250
- }
251
- export declare function clientNameOf(s: ClientInfoSource): string;
252
- /** Adds Wakeshift's text and _meta to a tool result (a copy). */
253
- export declare function applyAddition(a: Addition, base: string | CallToolResult): CallToolResult;
254
- declare const argsShape: {
255
- session_key: z.ZodOptional<z.ZodString>;
256
- harness: z.ZodOptional<z.ZodString>;
257
- conversation_id: z.ZodOptional<z.ZodString>;
258
- };
259
147
  /**
260
- * The Wakeshift client for an app: subscribe the conversations that call
261
- * your tools to topics, and publish to them.
148
+ * The Wakeshift client for an app: define the events your app offers,
149
+ * attach them to your MCP server, and emit them when they happen.
262
150
  */
263
151
  export declare class Wakeshift {
264
- /**
265
- * An older key's mode (wst_test_…, wst_live_…); null for a current key.
266
- * @deprecated Modes mean nothing now, and current keys have none.
267
- */
268
- readonly mode: "test" | "live" | null;
269
152
  readonly core: string;
270
153
  private readonly key;
271
154
  private knownAppId;
@@ -282,104 +165,43 @@ export declare class Wakeshift {
282
165
  */
283
166
  get appId(): string;
284
167
  /**
285
- * Which app the key is, as Wakeshift says: its ID and name. Asks once
168
+ * Which app the key is, as Wakeshift says: its ID and name, and the
169
+ * key's. Asks once
286
170
  * (GET /api/apps/v1/app) and remembers the answer; afterwards
287
171
  * `wake.appId` works for any key.
288
172
  */
289
173
  app(): Promise<AppInfo>;
290
174
  private assertion;
291
- /** Reports a warning, once per kind. */
292
- private warnOnce;
293
- /**
294
- * The arguments the agent passes Wakeshift's part of the call in, as a
295
- * zod shape for your subscribe tool's input (and any other tool whose
296
- * results you annotate): `inputSchema: { repo: z.string(), ...wake.args }`.
297
- * session_key (the key a result gives the conversation), harness (the
298
- * program the agent runs in) and conversation_id (its own ID for the
299
- * conversation, where its program gives one). Wakeshift adds nothing to
300
- * tools you don't spread it into.
301
- */
302
- get args(): typeof argsShape;
303
- /**
304
- * Packs the tool call from an MCP tool callback's `extra`: its _meta and
305
- * User-Agent, the client's name (from `server`, or pass `client`), the
306
- * user, and session_key, harness and conversation_id from `args`.
307
- */
308
- call(extra: ToolExtra | undefined, opts?: CallOptions): Call;
309
- /** Packs a tool call without an MCP framework. */
310
- callOf(c: {
311
- meta?: Record<string, unknown>;
312
- clientName: string;
313
- user?: string;
314
- session?: string;
315
- userAgent?: string;
316
- harness?: string;
317
- conversation?: string;
318
- tool?: string;
319
- }): Call;
320
- private recognised;
321
- /**
322
- * Subscribes the calling conversation to topic (again: refreshes it).
323
- * Check the caller may see the topic first: Wakeshift only refuses another
324
- * user's u/<user>/… topics.
325
- */
326
- subscribe(call: Call, topic: string, opts?: SubscribeOptions): Promise<Subscription>;
327
- /** Ends the conversation's subscription to topic, or to all the app's topics. Returns how many ended. */
328
- unsubscribe(call: Call, topic?: string): Promise<number>;
329
- /** Wakes every conversation subscribed to one of topics whose filter the event passes (each once). */
330
- publish(topics: string | string[], event: TopicEvent): Promise<Published>;
331
- /** Wakes exactly one subscription's conversation, whatever its filter. */
332
- send(subscriptionId: string, event: TopicEvent): Promise<SendStatus>;
333
- /**
334
- * How many conversations are subscribed to topic, and how many are
335
- * connected now, and how. Only reads: nothing is delivered, minted or ended.
336
- */
337
- topicStatus(topic: string): Promise<TopicStatus>;
338
- /** Whether a subscription is active and its conversation connected now, and how. Only reads. */
339
- subscriptionStatus(subscriptionId: string): Promise<SubscriptionStatus>;
340
- /** A capability URL that publishes to topic: a POST's body becomes an event. */
341
- publishUrl(topic: string): Promise<PublishUrl>;
342
- /** Stops a publish URL working, a topic's or an event's (410 from then on). */
175
+ /** Stops a publish URL working (410 from then on). */
343
176
  revokePublishUrl(id: string): Promise<void>;
344
- /** What Wakeshift would add to any other tool result for this conversation (creates nothing). */
345
- addition(call: Call): Promise<Addition>;
346
- /**
347
- * Adds what Wakeshift has for the calling conversation to a tool result
348
- * of yours (a copy): what's waiting for a harness that can't be woken, a
349
- * fresh connector beacon while a Codex thread's connector isn't running.
350
- * Only results you pass here (and a subscription's result()) change.
351
- */
352
- annotate(call: Call, result: CallToolResult): Promise<CallToolResult>;
353
- /** Ends every subscription to topic; each conversation is told. Returns how many ended. */
354
- closeTopic(topic: string): Promise<number>;
355
- /**
356
- * Ends one subscription by its id, telling its conversation that the app
357
- * ended it. Returns false if it had already ended (or there's no such
358
- * subscription of the app's).
359
- */
360
- endSubscription(subscriptionId: string): Promise<boolean>;
361
- /**
362
- * Ends the subscriptions of every conversation of one of the app's users
363
- * to topic, or to all of the app's topics (they lost access to something),
364
- * telling each conversation. Returns how many ended.
365
- */
366
- unsubscribeUser(user: string, topic?: string): Promise<number>;
367
177
  /**
368
178
  * Deletes everything Wakeshift keeps for one of the app's users: their
369
- * conversations, subscriptions, events and deliveries, recent publishes to
370
- * their u/<user>/… topics and publish URLs for them, and their ID. Open
371
- * streams close. Returns false if there was nothing to forget.
179
+ * conversations, subscriptions, events and deliveries, publish URLs for
180
+ * them, and their ID. Open streams close. Returns false if there was nothing to forget.
372
181
  */
373
182
  forgetUser(user: string): Promise<boolean>;
374
183
  /**
375
- * Tells Wakeshift what the app may do, replacing what it said before.
376
- * The events you defined (defineEvent) are added unless m has events of
377
- * its own. Returns the manifest as Wakeshift keeps it.
184
+ * Tells Wakeshift what the app may do, replacing what it said before: m,
185
+ * with the events you defined (defineEvent) after m's own events. An
186
+ * event both defined and listed in m.events is an error, and nothing is
187
+ * sent. You needn't call it: a process that serves your tools (attach)
188
+ * sends the manifest automatically, merged into the one Wakeshift has.
189
+ * Call it to remove an event or clear a setting. Once called, m's
190
+ * settings are what every automatic send carries (even if this one
191
+ * failed), with the events defined by then. Returns the manifest as
192
+ * Wakeshift keeps it.
378
193
  */
379
194
  publishManifest(m: Manifest): Promise<Manifest>;
195
+ private sending;
196
+ private serial;
197
+ private track;
198
+ private manifestBody;
199
+ private sendManifest;
380
200
  private readonly events;
381
201
  private manifestBase;
202
+ private serving;
382
203
  private published;
204
+ private manifestVersion;
383
205
  /**
384
206
  * Defines one of the app's event types: what a subscriber picks (args),
385
207
  * what each occurrence carries (payload), and the line an agent reads
@@ -404,13 +226,17 @@ export declare class Wakeshift {
404
226
  * unsubscribe_events and list_subscriptions for every client, so a person
405
227
  * can always see and stop what they're subscribed to.
406
228
  *
407
- * wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })
229
+ * const attached = wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })
230
+ *
231
+ * It returns the handle your own tools use to subscribe the conversation
232
+ * calling them: wrap a tool's callback with attached.events, and give it
233
+ * Wakeshift's arguments with attached.inputs.
408
234
  */
409
- attach(server: McpServer, opts?: AttachOptions): void;
235
+ attach(server: McpServer, opts?: AttachOptions): Attached;
410
236
  /**
411
237
  * The workspace Wakeshift keeps for one of the app's users (user: the
412
- * app's own ID for them, as in wake.call's user), created on first use.
413
- * Topics keep that user's conversations there.
238
+ * app's own ID for them, as attach's identify gives it), created on first
239
+ * use. Wakeshift keeps that user's conversations there.
414
240
  */
415
241
  workspace(user: string, name: string): Promise<string>;
416
242
  /** 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. */
@@ -424,4 +250,3 @@ export declare class Wakeshift {
424
250
  private request;
425
251
  private unreachable;
426
252
  }
427
- export {};