@wakeshift/sdk 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/events.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { type CallToolResult } from "@modelcontextprotocol/sdk/types.js";
2
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
1
  import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
4
2
  import { type AnySchema, type SchemaInput, type SchemaOutput, type ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
3
+ import { WakeshiftError } from "./errors.js";
5
4
  import { type Dialect } from "./spec.js";
6
- import { type Published, type PublishUrl, type Recognised, type ToolExtra, type Wakeshift } from "./wakeshift.js";
5
+ import { type Emitted, type PublishUrl, type Recipient, type ToolExtra, type Via, type Wakeshift } from "./wakeshift.js";
6
+ import { type EventsOptions } from "./toolcall.js";
7
7
  /** Who is subscribing: what authorize decides on. */
8
8
  export interface Subscriber {
9
9
  /** The app's ID for the person (attach's identify), if it has one. */
@@ -45,15 +45,26 @@ export interface EventOptions<A extends AnySchema, P extends AnySchema> {
45
45
  * to keep. One that isn't delivered expires as any other does.
46
46
  */
47
47
  deleteOnDelivery?: boolean;
48
- /** Advanced: the topic template and payload filter, if the defaults don't fit. */
48
+ /**
49
+ * Advanced: the topic template and payload filter, if the defaults don't
50
+ * fit. A filter without a topic adds to the optional arguments' filters,
51
+ * and may not name the same payload field as one of them.
52
+ */
49
53
  topic?: string;
50
54
  filter?: Record<string, string>;
51
55
  }
52
56
  export interface EmitOptions {
53
- /** Makes retries emit once for a day (at most 200 characters). */
57
+ /** Makes retries emit once for a day (at most 200 characters). A retry must name the same recipients: Wakeshift uses the first's. */
54
58
  id?: string;
55
- /** A personal event's one subscriber: the app's ID for them (attach's identify). Required for personal events, refused otherwise. */
56
- to?: string;
59
+ /**
60
+ * A personal event's recipients (at most 1,000), one or a list, mixed: a
61
+ * user, the app's ID for them (attach's identify), reaching every
62
+ * subscription they have to the event with these arguments;
63
+ * `{ user, subscription }`, exactly that subscription of that user's;
64
+ * `{ native: user }`, only that user's native (webhook) subscriptions.
65
+ * Required for personal events, refused otherwise.
66
+ */
67
+ to?: string | Recipient | (string | Recipient)[];
57
68
  }
58
69
  /** The manifest form of an event type. */
59
70
  export interface EventTypeManifest {
@@ -79,10 +90,11 @@ export declare class WakeEvent<A extends AnySchema = AnySchema, P extends AnySch
79
90
  constructor(wake: Wakeshift, name: string, opts: EventOptions<A, P>);
80
91
  /**
81
92
  * Sends one occurrence: to everyone subscribed with these arguments, or,
82
- * for a personal event, to the one subscriber `to` names. The payload is
93
+ * for a personal event, to the recipients `to` names. The payload is
83
94
  * checked against the event's schema first.
84
95
  */
85
- emit(args: SchemaInput<A>, payload: SchemaInput<P>, opts?: EmitOptions): Promise<Published>;
96
+ emit(args: SchemaInput<A>, payload: SchemaInput<P>, opts?: EmitOptions): Promise<Emitted>;
97
+ private wireTo;
86
98
  /**
87
99
  * A capability URL that emits this event with these arguments (a personal
88
100
  * event: to the one subscriber `to` names), for services that can only
@@ -95,65 +107,97 @@ export declare class WakeEvent<A extends AnySchema = AnySchema, P extends AnySch
95
107
  to?: string;
96
108
  }): Promise<PublishUrl>;
97
109
  /**
98
- * Subscribes the conversation calling your tool, the way subscribe_events
99
- * would, so a tool like "join" can set up its own wakes in one step. For
100
- * clients that subscribe through Wakeshift's wake paths; native MCP Events
101
- * clients subscribe themselves. Your tool decides who may: authorize isn't
102
- * consulted here. user is the app's ID for the person (required for a
103
- * personal event); wakeArgs are your tool's wake.args (session_key,
104
- * harness, conversation_id).
110
+ * How many conversations are subscribed to this event with these
111
+ * arguments (a personal event: those of the one user `to` names), how
112
+ * many are connected now, and how. Only reads.
113
+ */
114
+ status(args: SchemaInput<A>, opts?: {
115
+ to?: string;
116
+ }): Promise<EventStatus>;
117
+ /**
118
+ * Reads subscriptions to this event by ID, each with the user
119
+ * `call.subscribe` made it for, up to 1,000 at once: whether each is live
120
+ * and its conversation connected now, and how. Only reads.
105
121
  */
106
- subscribe(extra: ToolExtra, args: SchemaInput<A>, opts: {
107
- server?: McpServer;
108
- client?: string;
109
- user?: string;
110
- wakeArgs?: Record<string, unknown>;
111
- }): Promise<CallerSubscription>;
122
+ statusOf(subs: {
123
+ user: string;
124
+ subscription: string;
125
+ }[]): Promise<EventSubscriptionStatus[]>;
112
126
  /**
113
- * Ends the calling conversation's subscription with these arguments, the
114
- * way unsubscribe_events would: for a tool like "unwatch". False if it
115
- * wasn't subscribed.
127
+ * Ends one of user's subscriptions to this app's events, by its ID (a
128
+ * Subscription's id from call.subscribe, or list_subscriptions'), outside
129
+ * a tool: a player who timed out, a member removed. False if there was none.
116
130
  */
117
- unsubscribe(extra: ToolExtra, args: SchemaInput<A>, opts: {
118
- server?: McpServer;
119
- client?: string;
120
- user?: string;
121
- wakeArgs?: Record<string, unknown>;
122
- }): Promise<boolean>;
123
- /** Ends one of user's subscriptions to this app's events, by its ID (from subscribe or list_subscriptions). False if there was none. */
124
131
  end(user: string, id: string): Promise<boolean>;
125
132
  }
126
- /** A subscription made from inside an app's own tool (WakeEvent.subscribe). */
127
- export interface CallerSubscription {
133
+ /** The most subscriptions one `statusOf` reads. */
134
+ export declare const MAX_STATUS_SUBSCRIPTIONS = 1000;
135
+ /** Who is subscribed to an event with some arguments right now (`event.status`). */
136
+ export interface EventStatus {
137
+ /** Conversations subscribed (ended or expired subscriptions don't count). */
138
+ subscriptions: number;
139
+ /** Of those, connected now. */
140
+ connected: number;
141
+ /** How many are connected each way. */
142
+ via: Record<Via, number>;
143
+ }
144
+ /** One subscription right now (`event.statusOf`). */
145
+ export interface EventSubscriptionStatus {
128
146
  id: string;
129
- /** False when the conversation was already subscribed with these arguments (renewed). */
130
- created: boolean;
131
- /** The conversation's session handle: pass it back as session_key. */
132
- session: string;
133
- /** Which harness Wakeshift recognised, and how. */
134
- agent: Recognised;
135
- /** Your tool's text, with what the agent needs to be woken added. */
136
- result(text: string | CallToolResult): CallToolResult;
147
+ user: string;
148
+ /** The subscription is the user's, to this event, and hasn't ended. One that names nothing is false too. */
149
+ live: boolean;
150
+ /** Its conversation is reachable now, and `via` says how. */
151
+ connected: boolean;
152
+ via?: Via;
137
153
  }
138
- /** A subscriber's arguments don't match the event's schema. */
139
- export declare class ArgsError extends Error {
154
+ /**
155
+ * An event's arguments or payload don't match its schema: a WakeshiftError
156
+ * with code bad_arguments (status 400), as Wakeshift answers the same
157
+ * mistake, thrown before asking it.
158
+ */
159
+ export declare class ArgsError extends WakeshiftError {
160
+ constructor(message: string);
140
161
  }
141
162
  /** Who is behind a request to the app's MCP server, as the app knows them (AttachOptions.identify). */
142
163
  export interface Identity {
143
164
  /** The app's ID for the person: what personal events and list_subscriptions need, and native subscriptions belong to. */
144
165
  user?: string;
166
+ /**
167
+ * The MCP client's name, for a request that doesn't carry one: a
168
+ * stateless server never sees initialize, so the app passes the name it
169
+ * knows from its own sign-in (an OAuth registration's client_name, say).
170
+ * Wakeshift reads it to tell which program the agent runs in, and
171
+ * whether the client subscribes to events itself. A name the request
172
+ * carries (initialize's, or its _meta's) wins. Leave it out for a caller
173
+ * that must have no name.
174
+ */
175
+ client?: string;
145
176
  }
146
177
  export interface AttachOptions {
147
178
  /**
148
- * Who is behind a request, from the server's authentication. Default:
149
- * the guest GuestAuth signed in ({ user: guestOf(extra)?.user }).
179
+ * Who is behind a request. The app passes identify, returning { user }:
180
+ * its own ID for the person, from its own sign-in (and, on a stateless
181
+ * server, the client's name as `client`). Without it, requests have no
182
+ * user, so personal events and list_subscriptions refuse.
150
183
  */
151
184
  identify?: (extra: ToolExtra & {
152
185
  authInfo?: AuthInfo;
153
186
  }) => Identity | undefined;
187
+ /**
188
+ * Which of attach's own tools it adds (BUILTIN_TOOLS): subscribe_events,
189
+ * unsubscribe_events and list_subscriptions. Default: all three; `[]`
190
+ * adds none. Leave out unsubscribe_events or list_subscriptions only if
191
+ * your own tools let a person see and stop their subscriptions.
192
+ */
193
+ tools?: readonly BuiltinTool[];
194
+ /** The event features' options: events.native overrides native detection for wrapped tools (attached.events). */
195
+ events?: EventsOptions;
154
196
  }
155
- /** A client that speaks MCP Events: it declared the extension, or it's one known to (ChatGPT). */
156
- export declare function speaksEvents(capabilities: Record<string, unknown> | undefined, clientName: string): boolean;
197
+ /** The tools attach adds, unless AttachOptions.tools names fewer. */
198
+ export declare const BUILTIN_TOOLS: readonly ["subscribe_events", "unsubscribe_events", "list_subscriptions"];
199
+ /** One of attach's own tools. */
200
+ export type BuiltinTool = (typeof BUILTIN_TOOLS)[number];
157
201
  export declare const EVENT_TOOL_TEXT: {
158
202
  readonly a_webhook: "a webhook";
159
203
  readonly arguments_argument: "The event's arguments, as an object: see the event's list above";