@wakeshift/sdk 0.0.0-stage → 0.2.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 +25 -0
- package/LICENSE +202 -0
- package/NOTICE +4 -0
- package/README.md +198 -2
- package/dist/errors.d.ts +20 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +195 -0
- package/dist/events.js +523 -0
- package/dist/events.js.map +1 -0
- package/dist/guest.d.ts +119 -0
- package/dist/guest.js +506 -0
- package/dist/guest.js.map +1 -0
- package/dist/harness.d.ts +6 -0
- package/dist/harness.js +78 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/key.d.ts +29 -0
- package/dist/key.js +107 -0
- package/dist/key.js.map +1 -0
- package/dist/limits.d.ts +19 -0
- package/dist/limits.js +105 -0
- package/dist/limits.js.map +1 -0
- package/dist/retry.d.ts +1 -0
- package/dist/retry.js +58 -0
- package/dist/retry.js.map +1 -0
- package/dist/sealed.d.ts +4 -0
- package/dist/sealed.js +38 -0
- package/dist/sealed.js.map +1 -0
- package/dist/spec.d.ts +28 -0
- package/dist/spec.js +43 -0
- package/dist/spec.js.map +1 -0
- package/dist/wakeshift.d.ts +415 -0
- package/dist/wakeshift.js +481 -0
- package/dist/wakeshift.js.map +1 -0
- package/package.json +48 -4
package/dist/spec.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spec.js","sourceRoot":"","sources":["../src/spec.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,yEAAyE;AACzE,6CAA6C;AAE7C,8BAA8B;AAC9B,MAAM,CAAC,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAEhD,6GAA6G;AAC7G,MAAM,CAAC,MAAM,aAAa,GAAG,gCAAgC,CAAC;AAC9D,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC;AAEnC,gCAAgC;AAChC,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAEtC,sFAAsF;AACtF,MAAM,CAAC,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAE7C,6FAA6F;AAC7F,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AAYtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AACrC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,KAAK,CAAC;AACtC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAK,CAAC;AAErC,uEAAuE;AACvE,MAAM,UAAU,QAAQ,CAAC,OAAgB;IACvC,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,CAAC;IAC3I,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,KAAK,EAAE,gBAAgB,EAAE,CAAC,KAAK,EAAE,CAAC;AAC3H,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,SAAS,CAAC,UAAkB,EAAE,SAAiB;IAC7D,OAAO,UAAU,CAAC,WAAW,EAAE,KAAK,YAAY,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;AAC7H,CAAC;AAED,mIAAmI;AACnI,MAAM,UAAU,WAAW,CAAC,CAAS;IACnC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC9D,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACjE,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC;YAAE,OAAO,IAAI,CAAC;QAChH,OAAO,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["// The SEP-3415 (MCP Events) constants the SDK uses, in one place, matching\n// Wakeshift's own (internal/mcpevents/event/spec.go, which a test checks\n// these against): the draft is still moving.\n\n/** The draft these follow. */\nexport const REVISION = \"SEP-3415 (2026-10-16)\";\n\n/** Capability keys: the draft's extension, and the top-level key ChatGPT reads. A server advertises both. */\nexport const EXTENSION_KEY = \"io.modelcontextprotocol/events\";\nexport const LEGACY_KEY = \"events\";\n\n/** On every events/* result. */\nexport const RESULT_TYPE = \"complete\";\n\n/** The _meta key of an occurrence's rendered line (Wakeshift adds it on delivery). */\nexport const TEXT_META = \"ai.wakeshift/text\";\n\n/** The Streamable HTTP header events/subscribe and events/unsubscribe carry: params.name. */\nexport const NAME_HEADER = \"mcp-name\";\n\nexport type Dialect = \"draft\" | \"chatgpt\";\n\nexport interface Codes {\n notFound: number;\n forbidden: number;\n resourceExhausted: number;\n unsupported: number;\n callbackEndpoint: number;\n}\n\nexport const INVALID_PARAMS = -32602;\nexport const HEADER_MISMATCH = -32020;\nexport const INTERNAL_ERROR = -32603;\n\n/** A dialect's error codes: the draft's (provisional) or ChatGPT's. */\nexport function codesFor(dialect: Dialect): Codes {\n if (dialect === \"chatgpt\") {\n return { notFound: -32011, forbidden: -32012, resourceExhausted: INVALID_PARAMS, unsupported: INVALID_PARAMS, callbackEndpoint: -32015 };\n }\n return { notFound: -32023, forbidden: -32024, resourceExhausted: -32025, unsupported: -32026, callbackEndpoint: -32027 };\n}\n\n/** A client's dialect, by its clientInfo name or User-Agent: ChatGPT's MCP client is openai-mcp. */\nexport function dialectOf(clientName: string, userAgent: string): Dialect {\n return clientName.toLowerCase() === \"openai-mcp\" || userAgent.toLowerCase().startsWith(\"openai-mcp\") ? \"chatgpt\" : \"draft\";\n}\n\n/** Decodes an Mcp-Name header: plain ASCII, or SEP-2243's base64 sentinel (=?base64?…?=). null: a sentinel that doesn't decode. */\nexport function headerValue(h: string): string | null {\n if (!h.startsWith(\"=?base64?\") || !h.endsWith(\"?=\")) return h;\n try {\n const b = Buffer.from(h.slice(\"=?base64?\".length, -2), \"base64\");\n if (b.toString(\"base64\").replace(/=+$/, \"\") !== h.slice(\"=?base64?\".length, -2).replace(/=+$/, \"\")) return null;\n return b.toString(\"utf8\");\n } catch {\n return null;\n }\n}\n"]}
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import type { AnySchema } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
5
|
+
import { WakeEvent, type AttachOptions, type EventOptions, type EventTypeManifest } from "./events.js";
|
|
6
|
+
/** Wakeshift's production core, the default for every key but an older wst_test_ one. Override with `core` or WAKESHIFT_CORE. */
|
|
7
|
+
export declare const DEFAULT_CORE = "https://app.wakeshift.ai";
|
|
8
|
+
/** The tool argument an agent passes its session key in (a result gives it one). */
|
|
9
|
+
export declare const SESSION_ARG = "session_key";
|
|
10
|
+
/** The tool argument an agent says which program it runs in with. */
|
|
11
|
+
export declare const HARNESS_ARG = "harness";
|
|
12
|
+
/**
|
|
13
|
+
* The tool argument an agent passes its own ID for the conversation in,
|
|
14
|
+
* when its program gives it one (Cursor and Grok Bot: CURSOR_CONVERSATION_ID).
|
|
15
|
+
*/
|
|
16
|
+
export declare const CONVERSATION_ARG = "conversation_id";
|
|
17
|
+
export interface WakeshiftOptions {
|
|
18
|
+
/** The app key from the console: wst_ and 50 characters (or an older wst_test_… or wst_live_… key). */
|
|
19
|
+
key: string;
|
|
20
|
+
/**
|
|
21
|
+
* Wakeshift's base URL: the console you got the key from. Default:
|
|
22
|
+
* WAKESHIFT_CORE from the environment, else https://app.wakeshift.ai.
|
|
23
|
+
* An older wst_test_… key has no default: it needs one of the two.
|
|
24
|
+
*/
|
|
25
|
+
core?: string;
|
|
26
|
+
/** Default: the global fetch. */
|
|
27
|
+
fetch?: typeof fetch;
|
|
28
|
+
/** Per-request timeout in milliseconds. Default 20000. */
|
|
29
|
+
timeoutMs?: number;
|
|
30
|
+
/**
|
|
31
|
+
* 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.
|
|
34
|
+
*/
|
|
35
|
+
onWarning?: (message: string) => void;
|
|
36
|
+
}
|
|
37
|
+
/** Which app a key is, as Wakeshift says (wake.app()). */
|
|
38
|
+
export interface AppInfo {
|
|
39
|
+
id: string;
|
|
40
|
+
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
|
+
/**
|
|
69
|
+
* What Wakeshift recognised the calling conversation's harness as, and by
|
|
70
|
+
* which signal ("claim": only the agent's harness argument named it); both
|
|
71
|
+
* null when nothing named one. claimed is what the agent said (normalized:
|
|
72
|
+
* "Grok Bot" is grok-bot), null if it didn't; a claimed that differs from
|
|
73
|
+
* harness was ignored, since it contradicted what the call was recognised
|
|
74
|
+
* as (the claim only refines it: Cursor's calls may be Grok Bot's).
|
|
75
|
+
*/
|
|
76
|
+
export interface Recognised {
|
|
77
|
+
harness: string | null;
|
|
78
|
+
via: "client" | "meta" | "user_agent" | "claim" | null;
|
|
79
|
+
claimed: string | null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Seconds, or a string like "90s", "5m", "2h", "30d". Wakeshift checks the
|
|
83
|
+
* value: days must be whole ("1.5d" is a bad_request; use "36h").
|
|
84
|
+
*/
|
|
85
|
+
export type Duration = number | `${number}${"s" | "m" | "h" | "d"}`;
|
|
86
|
+
export interface SubscribeOptions {
|
|
87
|
+
/** Wake only for events whose data has these top-level fields equal to these values. */
|
|
88
|
+
filter?: Record<string, string | number | boolean | null>;
|
|
89
|
+
/** End after the first delivery. */
|
|
90
|
+
once?: boolean;
|
|
91
|
+
/** Deliver the latest event published within this long before subscribing (at most 24 hours). */
|
|
92
|
+
replay?: Duration;
|
|
93
|
+
/** End after this long without a delivery or a fresh subscribe (1 minute to 365 days; default 30 days). */
|
|
94
|
+
ttl?: Duration;
|
|
95
|
+
}
|
|
96
|
+
/** What Wakeshift adds to a tool result: text for the agent, _meta for its harness. */
|
|
97
|
+
export interface Addition {
|
|
98
|
+
text?: string;
|
|
99
|
+
meta?: Record<string, unknown>;
|
|
100
|
+
/** What Wakeshift recognised the caller's harness as (not added to the result). */
|
|
101
|
+
agent?: Recognised;
|
|
102
|
+
}
|
|
103
|
+
export interface Subscription {
|
|
104
|
+
/** For `send`. */
|
|
105
|
+
id: string;
|
|
106
|
+
topic: string;
|
|
107
|
+
filter?: Record<string, unknown>;
|
|
108
|
+
once: boolean;
|
|
109
|
+
expiresAt: Date;
|
|
110
|
+
/**
|
|
111
|
+
* The conversation's session key (the agent passes it back as session_key;
|
|
112
|
+
* the result says so). It's a secret that acts as the conversation: don't
|
|
113
|
+
* show, store or log it. To name the conversation, use id, or an HMAC of it.
|
|
114
|
+
*/
|
|
115
|
+
session: string;
|
|
116
|
+
/** What the tool result must carry for the caller's harness. */
|
|
117
|
+
addition: Addition;
|
|
118
|
+
/** What Wakeshift recognised the caller's harness as. */
|
|
119
|
+
agent: Recognised;
|
|
120
|
+
/**
|
|
121
|
+
* The tool result to return: your text (or result) followed by
|
|
122
|
+
* Wakeshift's, with its _meta.
|
|
123
|
+
*/
|
|
124
|
+
result(text: string | CallToolResult): CallToolResult;
|
|
125
|
+
}
|
|
126
|
+
export interface TopicEvent {
|
|
127
|
+
/** What the agent reads first (at most 1000 bytes). */
|
|
128
|
+
text: string;
|
|
129
|
+
/** A JSON object, within the 64 KB request limit; filters match its top-level fields. */
|
|
130
|
+
data?: Record<string, unknown>;
|
|
131
|
+
/** Makes retries publish once for a day (at most 200 characters); after a day, the same id publishes again. */
|
|
132
|
+
id?: string;
|
|
133
|
+
}
|
|
134
|
+
export interface Published {
|
|
135
|
+
/** Conversations it woke (or will). */
|
|
136
|
+
matched: number;
|
|
137
|
+
/** An earlier publish had this event's id. */
|
|
138
|
+
duplicate: boolean;
|
|
139
|
+
}
|
|
140
|
+
/** delivered: on its way to a connected conversation; queued: waits for it; closed: the subscription ended. */
|
|
141
|
+
export type SendStatus = "delivered" | "queued" | "closed";
|
|
142
|
+
/**
|
|
143
|
+
* How a conversation is connected: stream (a stream held open, e.g.
|
|
144
|
+
* Cursor's background command), poll (long polls or waits, e.g. Claude
|
|
145
|
+
* Code's Monitor, in the last minute) or hooks (Wakeshift's hooks or
|
|
146
|
+
* connector on the user's machine).
|
|
147
|
+
*/
|
|
148
|
+
export type Via = "stream" | "poll" | "hooks" | "webhook";
|
|
149
|
+
export interface TopicStatus {
|
|
150
|
+
topic: string;
|
|
151
|
+
/** Conversations subscribed (ended or expired subscriptions don't count). */
|
|
152
|
+
subscriptions: number;
|
|
153
|
+
/** Of those, connected now. */
|
|
154
|
+
connected: number;
|
|
155
|
+
/** How many are connected each way. */
|
|
156
|
+
via: Record<Via, number>;
|
|
157
|
+
}
|
|
158
|
+
export interface SubscriptionStatus {
|
|
159
|
+
id: string;
|
|
160
|
+
topic: string;
|
|
161
|
+
status: "active" | "closed";
|
|
162
|
+
connected: boolean;
|
|
163
|
+
via?: Via;
|
|
164
|
+
expiresAt?: Date;
|
|
165
|
+
}
|
|
166
|
+
/** A publish URL: `topic` for a topic's (`wake.publishUrl`), `event` for an event's (`event.publishUrl`). */
|
|
167
|
+
export interface PublishUrl {
|
|
168
|
+
id: string;
|
|
169
|
+
topic?: string;
|
|
170
|
+
event?: string;
|
|
171
|
+
url: string;
|
|
172
|
+
}
|
|
173
|
+
/** An event pattern a manifest asks for, and what the person is told it's for. */
|
|
174
|
+
export interface ScopeEvent {
|
|
175
|
+
pattern: string;
|
|
176
|
+
description: string;
|
|
177
|
+
}
|
|
178
|
+
/** What the app may do with the agents in the workspaces it keeps (manifest.agent). */
|
|
179
|
+
export interface AgentScope {
|
|
180
|
+
wake: ScopeEvent[];
|
|
181
|
+
post: ScopeEvent[];
|
|
182
|
+
/** Days the person's consent lasts. */
|
|
183
|
+
ttl_days: number;
|
|
184
|
+
/** At most max wake-ups in any seconds, on top of Wakeshift's own limits. */
|
|
185
|
+
wake_limits?: {
|
|
186
|
+
seconds: number;
|
|
187
|
+
max: number;
|
|
188
|
+
}[];
|
|
189
|
+
/** What the person should say to their agent once it's connected; at most 120 characters. */
|
|
190
|
+
start_prompt?: string;
|
|
191
|
+
groups?: boolean;
|
|
192
|
+
}
|
|
193
|
+
/** What the app tells Wakeshift it may do (see wake.publishManifest). */
|
|
194
|
+
export interface Manifest {
|
|
195
|
+
description?: string;
|
|
196
|
+
agent?: AgentScope;
|
|
197
|
+
/** The app's event types: defineEvent fills this in for you. */
|
|
198
|
+
events?: EventTypeManifest[];
|
|
199
|
+
}
|
|
200
|
+
/** The parts of an MCP tool callback's `extra` that Wakeshift reads. */
|
|
201
|
+
export interface ToolExtra {
|
|
202
|
+
_meta?: Record<string, unknown>;
|
|
203
|
+
requestInfo?: {
|
|
204
|
+
headers?: Record<string, string | string[] | undefined>;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** An McpServer or a low-level Server: anything that knows its client's name. */
|
|
208
|
+
export type ClientInfoSource = {
|
|
209
|
+
getClientVersion(): {
|
|
210
|
+
name: string;
|
|
211
|
+
} | undefined;
|
|
212
|
+
} | {
|
|
213
|
+
server: {
|
|
214
|
+
getClientVersion(): {
|
|
215
|
+
name: string;
|
|
216
|
+
} | undefined;
|
|
217
|
+
};
|
|
218
|
+
};
|
|
219
|
+
export interface CallOptions {
|
|
220
|
+
/** The MCP server the call came to, for the client's name (or pass client). */
|
|
221
|
+
server?: ClientInfoSource;
|
|
222
|
+
/** The client's name, if you know it (instead of server). */
|
|
223
|
+
client?: string;
|
|
224
|
+
/** The app's own ID for the person. */
|
|
225
|
+
user?: string;
|
|
226
|
+
/** The tool's arguments: session_key, harness and conversation_id (wake.args) are read from them. */
|
|
227
|
+
args?: {
|
|
228
|
+
[SESSION_ARG]?: string;
|
|
229
|
+
[HARNESS_ARG]?: string;
|
|
230
|
+
[CONVERSATION_ARG]?: string;
|
|
231
|
+
} | Record<string, unknown>;
|
|
232
|
+
/** The session key, if you read it yourself. */
|
|
233
|
+
session?: string;
|
|
234
|
+
/** The program the agent says it runs in (harness), if you read it yourself. */
|
|
235
|
+
harness?: string;
|
|
236
|
+
/** The conversation's ID the agent passed (conversation_id), if you read it yourself. */
|
|
237
|
+
conversation?: string;
|
|
238
|
+
}
|
|
239
|
+
export declare function clientNameOf(s: ClientInfoSource): string;
|
|
240
|
+
/** Adds Wakeshift's text and _meta to a tool result (a copy). */
|
|
241
|
+
export declare function applyAddition(a: Addition, base: string | CallToolResult): CallToolResult;
|
|
242
|
+
declare const argsShape: {
|
|
243
|
+
session_key: z.ZodOptional<z.ZodString>;
|
|
244
|
+
harness: z.ZodOptional<z.ZodString>;
|
|
245
|
+
conversation_id: z.ZodOptional<z.ZodString>;
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* The Wakeshift client for an app: subscribe the conversations that call
|
|
249
|
+
* your tools to topics, and publish to them.
|
|
250
|
+
*/
|
|
251
|
+
export declare class Wakeshift {
|
|
252
|
+
/**
|
|
253
|
+
* An older key's mode (wst_test_…, wst_live_…); null for a current key.
|
|
254
|
+
* @deprecated Modes mean nothing now, and current keys have none.
|
|
255
|
+
*/
|
|
256
|
+
readonly mode: "test" | "live" | null;
|
|
257
|
+
readonly core: string;
|
|
258
|
+
private readonly key;
|
|
259
|
+
private knownAppId;
|
|
260
|
+
private appInfo?;
|
|
261
|
+
private readonly fetchFn;
|
|
262
|
+
private readonly timeoutMs;
|
|
263
|
+
private readonly warnFn;
|
|
264
|
+
private readonly warned;
|
|
265
|
+
constructor(opts: WakeshiftOptions);
|
|
266
|
+
/**
|
|
267
|
+
* The app's ID. An older key (wst_test_…, wst_live_…) names it; for a
|
|
268
|
+
* current key, which doesn't, this throws until `await wake.app()` has
|
|
269
|
+
* asked Wakeshift.
|
|
270
|
+
*/
|
|
271
|
+
get appId(): string;
|
|
272
|
+
/**
|
|
273
|
+
* Which app the key is, as Wakeshift says: its ID and name. Asks once
|
|
274
|
+
* (GET /api/apps/v1/app) and remembers the answer; afterwards
|
|
275
|
+
* `wake.appId` works for any key.
|
|
276
|
+
*/
|
|
277
|
+
app(): Promise<AppInfo>;
|
|
278
|
+
private assertion;
|
|
279
|
+
/** Reports a warning, once per kind. */
|
|
280
|
+
private warnOnce;
|
|
281
|
+
/**
|
|
282
|
+
* The arguments the agent passes Wakeshift's part of the call in, as a
|
|
283
|
+
* zod shape for your subscribe tool's input (and any other tool whose
|
|
284
|
+
* results you annotate): `inputSchema: { repo: z.string(), ...wake.args }`.
|
|
285
|
+
* session_key (the key a result gives the conversation), harness (the
|
|
286
|
+
* program the agent runs in) and conversation_id (its own ID for the
|
|
287
|
+
* conversation, where its program gives one). Wakeshift adds nothing to
|
|
288
|
+
* tools you don't spread it into.
|
|
289
|
+
*/
|
|
290
|
+
get args(): typeof argsShape;
|
|
291
|
+
/**
|
|
292
|
+
* Packs the tool call from an MCP tool callback's `extra`: its _meta and
|
|
293
|
+
* User-Agent, the client's name (from `server`, or pass `client`), the
|
|
294
|
+
* user, and session_key, harness and conversation_id from `args`.
|
|
295
|
+
*/
|
|
296
|
+
call(extra: ToolExtra | undefined, opts?: CallOptions): Call;
|
|
297
|
+
/** Packs a tool call without an MCP framework. */
|
|
298
|
+
callOf(c: {
|
|
299
|
+
meta?: Record<string, unknown>;
|
|
300
|
+
clientName: string;
|
|
301
|
+
user?: string;
|
|
302
|
+
session?: string;
|
|
303
|
+
userAgent?: string;
|
|
304
|
+
harness?: string;
|
|
305
|
+
conversation?: string;
|
|
306
|
+
}): Call;
|
|
307
|
+
private recognised;
|
|
308
|
+
/**
|
|
309
|
+
* Subscribes the calling conversation to topic (again: refreshes it).
|
|
310
|
+
* Check the caller may see the topic first: Wakeshift only refuses another
|
|
311
|
+
* user's u/<user>/… topics.
|
|
312
|
+
*/
|
|
313
|
+
subscribe(call: Call, topic: string, opts?: SubscribeOptions): Promise<Subscription>;
|
|
314
|
+
/** Ends the conversation's subscription to topic, or to all the app's topics. Returns how many ended. */
|
|
315
|
+
unsubscribe(call: Call, topic?: string): Promise<number>;
|
|
316
|
+
/** Wakes every conversation subscribed to one of topics whose filter the event passes (each once). */
|
|
317
|
+
publish(topics: string | string[], event: TopicEvent): Promise<Published>;
|
|
318
|
+
/** Wakes exactly one subscription's conversation, whatever its filter. */
|
|
319
|
+
send(subscriptionId: string, event: TopicEvent): Promise<SendStatus>;
|
|
320
|
+
/**
|
|
321
|
+
* How many conversations are subscribed to topic, and how many are
|
|
322
|
+
* connected now, and how. Only reads: nothing is delivered, minted or ended.
|
|
323
|
+
*/
|
|
324
|
+
topicStatus(topic: string): Promise<TopicStatus>;
|
|
325
|
+
/** Whether a subscription is active and its conversation connected now, and how. Only reads. */
|
|
326
|
+
subscriptionStatus(subscriptionId: string): Promise<SubscriptionStatus>;
|
|
327
|
+
/** A capability URL that publishes to topic: a POST's body becomes an event. */
|
|
328
|
+
publishUrl(topic: string): Promise<PublishUrl>;
|
|
329
|
+
/** Stops a publish URL working, a topic's or an event's (410 from then on). */
|
|
330
|
+
revokePublishUrl(id: string): Promise<void>;
|
|
331
|
+
/** What Wakeshift would add to any other tool result for this conversation (creates nothing). */
|
|
332
|
+
addition(call: Call): Promise<Addition>;
|
|
333
|
+
/**
|
|
334
|
+
* Adds what Wakeshift has for the calling conversation to a tool result
|
|
335
|
+
* of yours (a copy): what's waiting for a harness that can't be woken, a
|
|
336
|
+
* fresh connector beacon while a Codex thread's connector isn't running.
|
|
337
|
+
* Only results you pass here (and a subscription's result()) change.
|
|
338
|
+
*/
|
|
339
|
+
annotate(call: Call, result: CallToolResult): Promise<CallToolResult>;
|
|
340
|
+
/** Ends every subscription to topic; each conversation is told. Returns how many ended. */
|
|
341
|
+
closeTopic(topic: string): Promise<number>;
|
|
342
|
+
/**
|
|
343
|
+
* Ends one subscription by its id, telling its conversation that the app
|
|
344
|
+
* ended it. Returns false if it had already ended (or there's no such
|
|
345
|
+
* subscription of the app's).
|
|
346
|
+
*/
|
|
347
|
+
endSubscription(subscriptionId: string): Promise<boolean>;
|
|
348
|
+
/**
|
|
349
|
+
* Ends the subscriptions of every conversation of one of the app's users
|
|
350
|
+
* to topic, or to all of the app's topics (they lost access to something),
|
|
351
|
+
* telling each conversation. Returns how many ended.
|
|
352
|
+
*/
|
|
353
|
+
unsubscribeUser(user: string, topic?: string): Promise<number>;
|
|
354
|
+
/**
|
|
355
|
+
* Deletes everything Wakeshift keeps for one of the app's users: their
|
|
356
|
+
* conversations, subscriptions, events and deliveries, recent publishes to
|
|
357
|
+
* their u/<user>/… topics and publish URLs for them, and their ID. Open
|
|
358
|
+
* streams close. Returns false if there was nothing to forget.
|
|
359
|
+
*/
|
|
360
|
+
forgetUser(user: string): Promise<boolean>;
|
|
361
|
+
/**
|
|
362
|
+
* Tells Wakeshift what the app may do, replacing what it said before.
|
|
363
|
+
* The events you defined (defineEvent) are added unless m has events of
|
|
364
|
+
* its own. Returns the manifest as Wakeshift keeps it.
|
|
365
|
+
*/
|
|
366
|
+
publishManifest(m: Manifest): Promise<Manifest>;
|
|
367
|
+
private readonly events;
|
|
368
|
+
private manifestBase;
|
|
369
|
+
private published;
|
|
370
|
+
/**
|
|
371
|
+
* Defines one of the app's event types: what a subscriber picks (args),
|
|
372
|
+
* what each occurrence carries (payload), and the line an agent reads
|
|
373
|
+
* first (text). Returns the event, whose emit sends occurrences. Define
|
|
374
|
+
* every event before attach.
|
|
375
|
+
*
|
|
376
|
+
* const message = wake.defineEvent("chat.message", {
|
|
377
|
+
* description: "A new message in a channel",
|
|
378
|
+
* args: z.object({ channel: z.string() }),
|
|
379
|
+
* payload: z.object({ from: z.string(), text: z.string() }),
|
|
380
|
+
* text: (m) => `${m.from}: ${m.text}`,
|
|
381
|
+
* })
|
|
382
|
+
* await message.emit({ channel: "eng" }, { from: "ada", text: "shipped" })
|
|
383
|
+
*/
|
|
384
|
+
defineEvent<A extends AnySchema, P extends AnySchema>(name: string, opts: EventOptions<A, P>): WakeEvent<A, P>;
|
|
385
|
+
/**
|
|
386
|
+
* Attaches Wakeshift to your MCP server, before you connect it: the one
|
|
387
|
+
* call that connects the two. Today it serves the defined events: MCP
|
|
388
|
+
* Events (events/list, events/subscribe, events/unsubscribe) for clients
|
|
389
|
+
* that speak it, such as ChatGPT, and the subscribe_events tool for
|
|
390
|
+
* everyone else, whom Wakeshift wakes its own ways; plus
|
|
391
|
+
* unsubscribe_events and list_subscriptions for every client, so a person
|
|
392
|
+
* can always see and stop what they're subscribed to.
|
|
393
|
+
*
|
|
394
|
+
* wake.attach(server, { identify: (extra) => ({ user: guestOf(extra)?.user }) })
|
|
395
|
+
*/
|
|
396
|
+
attach(server: McpServer, opts?: AttachOptions): void;
|
|
397
|
+
/**
|
|
398
|
+
* The workspace Wakeshift keeps for one of the app's users (user: the
|
|
399
|
+
* app's own ID for them, as in wake.call's user), creating it on first use.
|
|
400
|
+
* Topics keep that user's conversations there too. GuestAuth calls this;
|
|
401
|
+
* most apps never need to.
|
|
402
|
+
*/
|
|
403
|
+
workspace(user: string, name: string): Promise<string>;
|
|
404
|
+
/** 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. */
|
|
405
|
+
addAgent(workspace: string, agent: string, displayName: string): Promise<string>;
|
|
406
|
+
/**
|
|
407
|
+
* Checks that one of the app's agents still has a live grant, asking
|
|
408
|
+
* Wakeshift each time. Throws a WakeshiftError: no_grant once the grant is
|
|
409
|
+
* revoked, unknown_workspace once the workspace is forgotten.
|
|
410
|
+
*/
|
|
411
|
+
checkAgent(workspace: string, agent: string): Promise<void>;
|
|
412
|
+
private request;
|
|
413
|
+
private unreachable;
|
|
414
|
+
}
|
|
415
|
+
export {};
|