@wakeshift/sdk 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 (2026-10-26)
4
+
5
+ ### Breaking
6
+
7
+ Guest sign-in is gone. Your app identifies its own users with its own sign-in, and passes `identify` to `attach` to say who is behind each request. Apps on 0.2 that use `GuestAuth` must replace it with their own sign-in before upgrading.
8
+
9
+ Removed:
10
+
11
+ - `GuestAuth`, `guestOf` and their types `Guest`, `GuestAuthOptions` and `GuestAuthInfo`.
12
+ - `Wakeshift.secretSeed()`, which only `GuestAuth` used.
13
+ - `attach`'s default `identify`, which read the guest `GuestAuth` signed in. Without `identify`, requests have no user, so personal events and `list_subscriptions` refuse.
14
+
15
+ ```ts
16
+ // before
17
+ wake.attach(server)
18
+ // now
19
+ wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })
20
+ ```
21
+
22
+ `wake.workspace`, `wake.addAgent`, `wake.checkAgent` and `harnessAgent` stay: they serve the users your own sign-in identifies.
23
+
24
+ ### Added
25
+
26
+ - `Call.tool`, set with `wake.call(extra, { tool })` or `wake.callOf({ tool })`: the name of the tool being called. The connector beacon Wakeshift adds to a result names that tool, and Wakeshift's hooks act on it only from that tool's result, so pass it for wake-ups to connect with updated hooks. The tools `attach` adds, and `defineEvent`'s `subscribe` and `unsubscribe` (new `tool` option), pass theirs.
27
+
28
+ ### Changed
29
+
30
+ - An app's user has at most 20 live MCP Events webhook subscriptions. Wakeshift refuses one more with `403 subscription_limit`, which `attach` answers with MCP Events' `ResourceExhausted` (`InvalidParams` for ChatGPT), with data `{ kind: "subscriptions" }`.
31
+
32
+ ## 0.2.0 (2026-10-26)
33
+
34
+ ### Breaking
35
+
36
+ Sign in with Wakeshift is gone: Wakeshift no longer gives apps grants in people's own workspaces. Your app identifies its own users, with `GuestAuth` or its own sign-in, and acts for the agents in the workspaces it keeps (`wake.workspace`, `wake.addAgent`, `wake.checkAgent`). Topics, events and `GuestAuth` work as before.
37
+
38
+ Removed:
39
+
40
+ - `WakeshiftSignIn`, `SignInError` and their types `WakeshiftSignInOptions` and `StartOptions`.
41
+ - `Agent` and `Claims`.
42
+ - On `Wakeshift`: `protectedResource()`, `challenge()`, `verifyAccessToken()`, `exchange()`, `pkce()`, `authorizeUrl()`, `signIn()`, `refresh()` and the `mcpUrl` option and property.
43
+ - The types `SignedIn`, `AuthorizeOptions` and `Connection`.
44
+ - `Manifest.accounts`, `Manifest.workspace` and `AgentScope.redirect_uris`. Wakeshift refuses a manifest with `accounts: "wakeshift"`, a workspace scope or redirect URIs (`bad_manifest`).
45
+ - `serveEvents`' `agent` option, the `agent` option of `wake.call`, `event.subscribe` and `event.unsubscribe`, and `Call.agent_token`.
46
+
47
+ `serveEvents` is renamed `attach`, the one call that attaches Wakeshift to your MCP server. Its `user` option is replaced by `identify`, which returns an `Identity` (`{ user }`); the type `ServeEventsOptions` is now `AttachOptions`. It behaves as before:
48
+
49
+ ```ts
50
+ // before
51
+ wake.serveEvents(server, { user: (extra) => myUser(extra) })
52
+ // now
53
+ wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })
54
+ ```
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Wakeshift SDK for Node
2
+ Copyright 2026 Clawvisor Inc.
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (LICENSE).
package/README.md CHANGED
@@ -1,3 +1,190 @@
1
- # Temporary Holding Version
1
+ # @wakeshift/sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Let agents subscribe to things in your app. You define the events your app offers, serve them on your MCP server, and emit them when they happen; Wakeshift wakes every subscribed agent, whether it's Claude Code, Codex, ChatGPT or another. Your events follow MCP Events: clients that speak it subscribe natively, and Wakeshift bridges every other agent. You don't deal with harnesses.
4
+
5
+ Node 22 or later. The package is ESM-only: load it with `import`, from an ES module (`"type": "module"`, or a `.mjs` or `.mts` file). It has no CommonJS build, so `require("@wakeshift/sdk")` works only where Node can require ES modules. Peer dependencies: `@modelcontextprotocol/sdk` (1.23 or later: the first that takes zod 4) and `zod` (3.25 or later, or 4). Import `z` from `"zod"`, not `"zod/v4"`: the SDK's schemas are built from `"zod"`, and the MCP SDK refuses a schema that mixes the two.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @wakeshift/sdk @modelcontextprotocol/sdk zod
11
+ ```
12
+
13
+ Install the package, not a checkout of this repository (a `file:` dependency): a `file:` dependency links the directory along with its `node_modules`, so the SDK can load its own development copy of zod instead of yours, and the MCP SDK then fails with "Mixed Zod versions detected in object shape". To try a change of your own, `npm pack` and install the tarball it writes.
14
+
15
+ ## Quickstart: a CI bot
16
+
17
+ You have an MCP server and a GitHub webhook handler. Register an app in the Wakeshift console (Build), and put its key in `WAKESHIFT_KEY` (`wst_` and 50 characters). The SDK talks to `https://app.wakeshift.ai` unless `WAKESHIFT_CORE` names another address. Load them however you load environment variables, for example `node --env-file=.env server.ts`.
18
+
19
+ ```ts
20
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
21
+ import { z } from "zod"
22
+ import { Wakeshift } from "@wakeshift/sdk"
23
+
24
+ const wake = new Wakeshift({ key: process.env.WAKESHIFT_KEY! })
25
+
26
+ const ciFinished = wake.defineEvent("ci.finished", {
27
+ description: "CI finished on a GitHub repo",
28
+ args: z.object({ owner: z.string(), repo: z.string(), branch: z.string().optional() }),
29
+ payload: z.object({ branch: z.string(), conclusion: z.string(), name: z.string(), url: z.string() }),
30
+ authorize: (subscriber, { owner, repo }) => canSeeRepo(subscriber, `${owner}/${repo}`),
31
+ text: (run, { owner, repo }) => `CI ${run.conclusion} on ${owner}/${repo} ${run.branch}: ${run.name}`,
32
+ })
33
+
34
+ // One McpServer per MCP session; serve the events before connecting it.
35
+ const server = new McpServer({ name: "ci-bot", version: "1.0.0" })
36
+ // myUser: your own sign-in's ID for the person behind the request.
37
+ wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })
38
+ ```
39
+
40
+ ```ts
41
+ // In your GitHub webhook handler, after checking X-Hub-Signature-256:
42
+ if (req.headers["x-github-event"] === "workflow_run" && body.action === "completed") {
43
+ const run = body.workflow_run
44
+ const [owner, repo] = body.repository.full_name.toLowerCase().split("/")
45
+ await ciFinished.emit(
46
+ { owner, repo },
47
+ { branch: run.head_branch, conclusion: run.conclusion, name: run.name, url: run.html_url },
48
+ { id: String(req.headers["x-github-delivery"]) },
49
+ )
50
+ }
51
+ ```
52
+
53
+ That's all. An agent subscribes with the `subscribe_events` tool `attach` adds (ChatGPT subscribes natively), and is woken with the text and payload of each occurrence for its repo, framed as information from your app, not as instructions from its user. A subscriber that names a `branch` only gets that branch's occurrences.
54
+
55
+ - `owner` and `repo` are required, so they route occurrences; their values are lowercase IDs (`a-z 0-9 . _ -`). The optional `branch` filters on the payload's `branch`.
56
+ - `attach` adds `subscribe_events`, `unsubscribe_events` and `list_subscriptions`, and touches no other tool or result.
57
+ - Native subscriptions (ChatGPT) and personal events need a signed-in user: your app signs its users in and passes `identify` to `attach`.
58
+
59
+ ## Events
60
+
61
+ Events follow MCP Events (SEP-3415): you define the event types your app offers, serve them, and emit occurrences. Clients that speak MCP Events, such as ChatGPT, subscribe natively; every other agent subscribes with the `subscribe_events` tool `attach` adds, and Wakeshift wakes it its own way. You write no subscribe tool and handle no harnesses.
62
+
63
+ ```ts
64
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
65
+ import { z } from "zod"
66
+ import { Wakeshift } from "@wakeshift/sdk"
67
+
68
+ const wake = new Wakeshift({ key: process.env.WAKESHIFT_KEY! })
69
+
70
+ const message = wake.defineEvent("chat.message", {
71
+ description: "A new message in a channel",
72
+ args: z.object({ channel: z.string() }),
73
+ payload: z.object({ from: z.string(), text: z.string() }),
74
+ text: (m) => `${m.from}: ${m.text}`,
75
+ })
76
+
77
+ // A personal event: each subscription belongs to its subscriber, and an
78
+ // occurrence goes to one of them, so it can carry their own private view.
79
+ const turn = wake.defineEvent("game.turn", {
80
+ description: "It's your move at a table",
81
+ args: z.object({ table: z.string() }),
82
+ payload: z.object({ hole: z.array(z.string()), toCall: z.number() }),
83
+ text: (t) => `Your move: ${t.toCall} to call`,
84
+ personal: true,
85
+ })
86
+
87
+ // One server per connection; attach before connecting it.
88
+ const server = new McpServer({ name: "chat", version: "1.0.0" })
89
+ // myUser: your own sign-in's ID for the person behind the request.
90
+ wake.attach(server, { identify: (extra) => ({ user: myUser(extra) }) })
91
+
92
+ // When something happens:
93
+ await message.emit({ channel: "eng" }, { from: "ada", text: "shipped it" })
94
+ await turn.emit({ table: "juniper" }, { hole: ["As", "Kd"], toCall: 2 }, { to: "user-123" })
95
+ ```
96
+
97
+ - **`wake.defineEvent(name, { description, args, payload, text, authorize?, personal? })`** returns the event. `args` is what a subscriber picks; its required string, integer and boolean fields route occurrences, so their values are lowercase IDs (a-z 0-9 . _ -), and an optional one filters on the payload field of the same name. `authorize(subscriber, args)` decides who may subscribe. Define every event before `attach`.
98
+ - **`event.emit(args, payload, { id?, to? })`** checks the payload against its schema and sends it to everyone subscribed with those arguments; a personal event goes to the one subscriber `to` names (the `user` attach's `identify` gives for them). `id` makes retries emit once.
99
+ - **`wake.attach(server, { identify? })`** attaches Wakeshift to your MCP server. Today it serves `events/list`, `events/subscribe` and `events/unsubscribe` to clients that speak MCP Events, and adds `subscribe_events` (for everyone else), `unsubscribe_events` and `list_subscriptions` (for every client, so a person can always see and stop what they're subscribed to). `identify(extra)` says who is behind a request, as `{ user }`, your app's ID for the person, from your own sign-in; without it, requests have no user, so personal events and `list_subscriptions` refuse. The events go into your manifest on first use; `publishManifest` adds them too.
100
+ - **`event.subscribe(extra, args, { server or client, tool?, user?, wakeArgs? })`** subscribes the conversation calling one of your own tools, the way `subscribe_events` would, so a tool like "join" can set up its wakes in one step; pass `tool`, your tool's name, for wake-ups to connect (see `wake.call`); it gives back the subscription's `id`, the conversation's `session` (its `session_key`) and `result(text)`, your tool's text with what the agent needs added. Your tool decides who may (`authorize` isn't consulted). Clients that speak MCP Events subscribe themselves. **`event.unsubscribe(extra, args, …)`** ends the calling conversation's subscription with those arguments (for a tool like "unwatch"); **`event.end(user, id)`** ends one of a user's subscriptions by its ID.
101
+
102
+ ## Reference
103
+
104
+ ### `new Wakeshift({ key, core?, fetch?, timeoutMs?, onWarning? })`
105
+
106
+ - `key`: `wst_` and 50 characters. It's your app's Ed25519 private key; it never goes over the wire. Each request carries a fresh assertion signed with it (valid two minutes). Older keys, `wst_test_<app>_<seed>` and `wst_live_<app>_<seed>`, keep working.
107
+ - `core`: the address of the console the key came from. Default: `WAKESHIFT_CORE` from the environment, else `https://app.wakeshift.ai`. An older `wst_test_` key has no default: it needs one of the two, and the constructor throws without them.
108
+ - `onWarning(message)`: called once per kind of problem that doesn't fail a call, such as a tool call Wakeshift recognised no harness in. Default: `console.warn`.
109
+ - `await wake.app()`: `{ id, name }`, which app the key is, as Wakeshift says. It asks once and remembers the answer.
110
+ - `wake.appId`: the app's ID. A current key doesn't name its app, so this throws until `await wake.app()` has answered; an older key names it. `wake.core`: the address in use. `wake.mode` is deprecated: `"test"` or `"live"` for an older key, `null` for a current one.
111
+
112
+ ### The caller
113
+
114
+ For your own tools that subscribe (`event.subscribe`) and for topics.
115
+
116
+
117
+ - `wake.call(extra, { server, tool, user?, args?, session?, harness?, conversation?, client? })` packs a tool call from an MCP tool callback's `extra`: its `_meta` (Codex sends its thread there), the request's User-Agent (from `extra.requestInfo`), the client's name (from `server`'s client info; or pass `client` yourself, for example on a stateless server), `user` (your ID for the person; their conversations are grouped, and `u/<user>/…` topics are theirs), and `session_key`, `harness` and `conversation_id` from `args`. Pass `tool`, the name of the tool being called (the MCP SDK doesn't give callbacks it): the connector beacon Wakeshift adds to a result works only in the result of the tool it was made for, so wake-ups connect only when you pass it.
118
+ - `wake.callOf({ meta, clientName, tool?, user?, session?, userAgent?, harness?, conversation? })` does the same without an MCP framework.
119
+ - `wake.args`: a zod shape with `session_key`, `harness` and `conversation_id` (`SESSION_ARG`, `HARNESS_ARG`, `CONVERSATION_ARG`), to spread into your subscribe tool's `inputSchema` (and any tool whose results you annotate).
120
+
121
+ ### Topics
122
+
123
+ Topics are what events are built on; use them directly for publish URLs, `send` and a subscribe tool of your own with `once` or `replay`. Lowercase segments of `a-z 0-9 . _ -` joined by `/`, up to 200 characters, scoped to your app. `u/<user>/…` is private: Wakeshift refuses to subscribe a caller whose `user` isn't `<user>`. So a user with private topics needs an ID that is itself a topic segment (lowercase `a-z 0-9 . _ -`): use an opaque ID, or a hash of yours, not an email. Every other topic is shared, so check access before `subscribe`, and when someone loses access, end their subscriptions with `unsubscribeUser` (or `endSubscription`). Don't put secrets in topic names.
124
+
125
+ ### Calls
126
+
127
+ | Call | Returns |
128
+ | --- | --- |
129
+ | `subscribe(call, topic, { filter?, once?, replay?, ttl? })` | `{ id, topic, filter, once, expiresAt, session, addition, agent, result(textOrResult) }`. `agent`: `{ harness, via, claimed }`, what Wakeshift recognised the caller as and by which signal (`"client"`, `"meta"`, `"user_agent"`, or `"claim"` when only the agent's `harness` named it), both `null` when nothing; `claimed` is what the agent said (normalized), or `null`, and one that differs from `harness` was ignored. `filter`: equality on top-level fields of the event's `data`. `once`: end after the first delivery. `replay`: deliver the latest event published within this long before subscribing (at most `"24h"`). `ttl`: end after this long without a delivery or a fresh subscribe (default `"30d"`). Durations are seconds or `"90s"`, `"5m"`, `"2h"`, `"30d"` (whole days). Subscribing again refreshes it. `result` returns your text (or `CallToolResult`) followed by Wakeshift's text, with its `_meta`. |
130
+ | `unsubscribe(call, topic?)` | How many of the calling conversation's subscriptions ended (all your topics without `topic`). |
131
+ | `unsubscribeUser(user, topic?)` | How many ended: every conversation of `user` stops getting `topic` (all your topics without it). Each conversation is told you ended it. For when someone loses access. |
132
+ | `endSubscription(subscriptionId)` | `true` if it ended one subscription (its conversation is told you ended it); `false` if it had already ended or isn't yours. |
133
+ | `publish(topics, { text, data?, id? })` | `{ matched, duplicate }`. `topics`: one or up to 20. `text` at most 1000 bytes; `data` a JSON object within the 64 KB request limit. The same `id` within a day publishes once (`duplicate: true`); after a day, it publishes again. |
134
+ | `send(subscriptionId, event)` | `"delivered"` (connected, on its way), `"queued"` (waits for the conversation) or `"closed"` (the subscription ended). Ignores the filter. |
135
+ | `topicStatus(topic)` | `{ topic, subscriptions, connected, via: { stream, poll, hooks, webhook } }`: how many conversations are subscribed, and how many are connected now and how (`stream`: a stream held open; `poll`: waiting or polling; `hooks`: Wakeshift's hooks or plugin on the user's machine; `webhook`: a client subscribed natively, such as ChatGPT). Only reads. |
136
+ | `subscriptionStatus(subscriptionId)` | `{ id, topic, status: "active" \| "closed", connected, via?, expiresAt? }`. Only reads. |
137
+ | `publishUrl(topic)` | `{ id, topic, url }`: anyone can POST to `url` to publish to `topic` (a JSON object body becomes `data`; `Idempotency-Key` or `X-GitHub-Delivery` dedupes). |
138
+ | `revokePublishUrl(id)` | The URL answers 410 from then on. |
139
+ | `annotate(call, result)` | A copy of `result` with what Wakeshift adds for this conversation (messages waiting for an agent that can't be woken, or what an agent needs to reconnect; usually nothing). Only results you pass here (and `sub.result`) change. `addition(call)` returns the raw `{ text?, meta?, agent }`. |
140
+ | `closeTopic(topic)` | How many subscriptions ended. Each conversation gets what was already published to it, then a notice. |
141
+ | `forgetUser(user)` | `false` if there was nothing to forget. Deletes everything Wakeshift keeps for the user: their conversations, subscriptions, events and deliveries, stream links (open streams close), recent publishes to their `u/<user>/…` topics and publish URLs for them, and their ID. Your app's log records that a user was forgotten, without their ID or anything derived from it. Their subscription IDs stay known as closed. |
142
+
143
+ ### Manifest and workspaces
144
+
145
+ - `wake.publishManifest({ description?, agent?, events? })`: what your app may do; returns it as Wakeshift keeps it. `agent`: `{ wake, post, ttl_days, wake_limits?, start_prompt? }`, each scope event `{ pattern, description }`: what the agents in the workspaces your app keeps may be woken by and post.
146
+ - Your app identifies its own users with its own sign-in, and acts for the agents in the workspaces it keeps.
147
+ - `wake.workspace(user, name)`, `wake.addAgent(workspace, agent, displayName)`, `wake.checkAgent(workspace, agent)`: the workspace Wakeshift keeps for one of your users, an agent in it with a grant for your manifest's agent scope, and whether that grant is live. Topics keep a user's conversations in that workspace; you don't need these for topics.
148
+ - `harnessAgent(clientName)`: the agent ID a client name maps to (`"Claude Code"` is `claude-code`), as Wakeshift names it.
149
+
150
+ ### Errors
151
+
152
+ API errors throw `WakeshiftError` with `status` and `code`, the same codes as the [HTTP API](https://wakeshift.ai/docs/http-api)'s, plus `unreachable`:
153
+
154
+ | Status | Code | When |
155
+ | --- | --- | --- |
156
+ | `400` | `bad_request` | Something in the request is invalid, including a field the API doesn't take. The message says what. |
157
+ | `401` | `unauthenticated` | The assertion was refused: expired, reused, signed with another key, or for another `aud` (a key for another Wakeshift). The message says which. |
158
+ | `400` | `bad_arguments` | An event's arguments don't match its schema, or a routing value isn't a lowercase ID. |
159
+ | `403` | `private_topic` | Subscribing a caller to another user's `u/<user>/…` topic. |
160
+ | `403` | `other_client` | The `session` key is a conversation in another MCP client of the same user. Call again without it. |
161
+ | `404` | `unknown_subscription` | The subscription ID isn't one of your app's. |
162
+ | `404` | `unknown_publish_url` | The publish URL ID isn't one of your app's. |
163
+ | `404` | `unknown_event` | Your app offers no event by that name. |
164
+ | `413` | `too_large` | The request body is over 64 KB. The limit is on the whole body, so `data` must leave room for the rest of the request. |
165
+ | `0` | `unreachable` | No answer at all: a wrong `core`, a network problem, or the timeout. The message names the core it tried. |
166
+
167
+ `isCode(err, "private_topic")` checks one.
168
+
169
+ ## Documentation
170
+
171
+ The guides and the full reference are at [wakeshift.ai/docs](https://wakeshift.ai/docs): the [quickstart](https://wakeshift.ai/docs/quickstart), [events](https://wakeshift.ai/docs/events), [your users](https://wakeshift.ai/docs/users) and [the TypeScript SDK](https://wakeshift.ai/docs/sdk). The same calls are in the [Go](https://github.com/wakeshift/wakeshift-go) and [Python](https://github.com/wakeshift/wakeshift-python) SDKs.
172
+
173
+ ## Development
174
+
175
+ ```sh
176
+ npm ci
177
+ npm run typecheck
178
+ npm test # unit tests (node:test) and the README's examples
179
+ npm run build # dist/
180
+ ```
181
+
182
+ The end-to-end tests (`test/e2e*.test.ts`) run against a Wakeshift server, so they run in Wakeshift's own repository and skip here.
183
+
184
+ ## Contributing and security
185
+
186
+ This repository is generated from Wakeshift's main repository. Pull requests are welcome: we apply them there and publish the result. See [CONTRIBUTING](CONTRIBUTING.md). Report a security problem privately to support@wakeshift.ai, not in an issue ([SECURITY](SECURITY.md)).
187
+
188
+ ## License
189
+
190
+ Apache License 2.0; see [LICENSE](LICENSE).
@@ -0,0 +1,20 @@
1
+ /**
2
+ * An error response from Wakeshift: `code` is the API's error code (e.g.
3
+ * "private_topic", "other_client", "unknown_subscription", "bad_request"),
4
+ * `status` the HTTP status. A request that got no answer
5
+ * has code "unreachable" and status 0.
6
+ */
7
+ export declare class WakeshiftError extends Error {
8
+ readonly status: number;
9
+ readonly code: string;
10
+ /** Wakeshift's own message, without the prefix. */
11
+ readonly detail: string;
12
+ /** Why, where the API says (callback_failed: what the callback did). */
13
+ readonly reason?: string;
14
+ constructor(status: number, code: string, message: string, options?: {
15
+ cause?: unknown;
16
+ reason?: string;
17
+ });
18
+ }
19
+ /** Whether err is a WakeshiftError with code. */
20
+ export declare function isCode(err: unknown, code: string): boolean;
package/dist/errors.js ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * An error response from Wakeshift: `code` is the API's error code (e.g.
3
+ * "private_topic", "other_client", "unknown_subscription", "bad_request"),
4
+ * `status` the HTTP status. A request that got no answer
5
+ * has code "unreachable" and status 0.
6
+ */
7
+ export class WakeshiftError extends Error {
8
+ status;
9
+ code;
10
+ /** Wakeshift's own message, without the prefix. */
11
+ detail;
12
+ /** Why, where the API says (callback_failed: what the callback did). */
13
+ reason;
14
+ constructor(status, code, message, options) {
15
+ super(status ? `wakeshift: ${code || "error"} (${status}): ${message}` : `wakeshift: ${message}`, options);
16
+ this.name = "WakeshiftError";
17
+ this.status = status;
18
+ this.code = code;
19
+ this.detail = message;
20
+ if (options?.reason)
21
+ this.reason = options.reason;
22
+ }
23
+ }
24
+ /** Whether err is a WakeshiftError with code. */
25
+ export function isCode(err, code) {
26
+ return err instanceof WakeshiftError && err.code === code;
27
+ }
28
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IAC9B,MAAM,CAAS;IACf,IAAI,CAAS;IACtB,mDAAmD;IAC1C,MAAM,CAAS;IACxB,wEAAwE;IAC/D,MAAM,CAAU;IAEzB,YAAY,MAAc,EAAE,IAAY,EAAE,OAAe,EAAE,OAA8C;QACvG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,IAAI,IAAI,OAAO,KAAK,MAAM,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,cAAc,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC;QAC3G,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;QACtB,IAAI,OAAO,EAAE,MAAM;YAAE,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IACpD,CAAC;CACF;AAED,iDAAiD;AACjD,MAAM,UAAU,MAAM,CAAC,GAAY,EAAE,IAAY;IAC/C,OAAO,GAAG,YAAY,cAAc,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC;AAC5D,CAAC","sourcesContent":["/**\n * An error response from Wakeshift: `code` is the API's error code (e.g.\n * \"private_topic\", \"other_client\", \"unknown_subscription\", \"bad_request\"),\n * `status` the HTTP status. A request that got no answer\n * has code \"unreachable\" and status 0.\n */\nexport class WakeshiftError extends Error {\n readonly status: number;\n readonly code: string;\n /** Wakeshift's own message, without the prefix. */\n readonly detail: string;\n /** Why, where the API says (callback_failed: what the callback did). */\n readonly reason?: string;\n\n constructor(status: number, code: string, message: string, options?: { cause?: unknown; reason?: string }) {\n super(status ? `wakeshift: ${code || \"error\"} (${status}): ${message}` : `wakeshift: ${message}`, options);\n this.name = \"WakeshiftError\";\n this.status = status;\n this.code = code;\n this.detail = message;\n if (options?.reason) this.reason = options.reason;\n }\n}\n\n/** Whether err is a WakeshiftError with code. */\nexport function isCode(err: unknown, code: string): boolean {\n return err instanceof WakeshiftError && err.code === code;\n}\n"]}