palbase 0.6.2 → 0.7.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.
Files changed (65) hide show
  1. package/dist/ai/index.js +2 -14
  2. package/dist/backend/engine.js +2 -2
  3. package/dist/backend/env.js +1 -1
  4. package/dist/backend/index.js +8 -8
  5. package/dist/backend/stack.js +1 -1
  6. package/dist/backend/test.js +2 -2
  7. package/dist/chunks/3ALGILOX.js +2 -0
  8. package/dist/chunks/{GVFZM4BI.js → 5ZJCEQV5.js} +3 -3
  9. package/dist/chunks/AIIKXCWN.js +2 -0
  10. package/dist/chunks/{53FS342F.js → BKVU4I5R.js} +2 -2
  11. package/dist/chunks/ELEE7XO2.js +18 -0
  12. package/dist/chunks/{DRTZ33XF.js → G3BK7L3J.js} +2 -2
  13. package/dist/chunks/G7E26S3Y.js +13 -0
  14. package/dist/chunks/H2EPK74V.js +20 -0
  15. package/dist/chunks/{VP7V7YRH.js → HEXIIGWS.js} +2 -2
  16. package/dist/chunks/{IYCW6PWG.js → JS3TTUHS.js} +2 -2
  17. package/dist/chunks/{SUX2BJG4.js → KDSWK3XW.js} +1 -1
  18. package/dist/chunks/{U4OZ4HOF.js → L3NTI4AZ.js} +2 -2
  19. package/dist/chunks/LEBVOSG6.js +4 -0
  20. package/dist/chunks/OIA7KLRW.js +2 -0
  21. package/dist/chunks/{AYY4J3B2.js → PJVWGUIT.js} +1 -1
  22. package/dist/chunks/{A3CDCPXX.js → SU7BP6VF.js} +1 -1
  23. package/dist/chunks/{KLANM6M6.js → X3MTLJRV.js} +1 -1
  24. package/dist/chunks/{SXH5AIQX.js → ZBOJEH7K.js} +2 -2
  25. package/dist/cli.js +133 -133
  26. package/dist/refuse/ai.js +1 -1
  27. package/dist/refuse/backend.js +1 -1
  28. package/dist/refuse/server.js +1 -1
  29. package/dist/server/index.js +2 -2
  30. package/dist/server/testing.js +2 -2
  31. package/dist/web/index.js +2 -2
  32. package/dist/web/palbe.js +2 -2
  33. package/dist/web/paywall.js +2 -2
  34. package/dist/web/ssr.js +2 -2
  35. package/dist/web/vite.js +2 -2
  36. package/package.json +2 -2
  37. package/types/ai/src/ai.d.ts +2 -4
  38. package/types/ai/src/chats.d.ts +40 -10
  39. package/types/ai/src/index.d.ts +2 -2
  40. package/types/ai/src/tools.d.ts +3 -8
  41. package/types/backend/src/container.d.ts +2 -2
  42. package/types/backend/src/engine.d.ts +1 -4
  43. package/types/backend/src/gateways.d.ts +250 -0
  44. package/types/backend/src/index.d.ts +2 -2
  45. package/types/backend/src/openapi.d.ts +3 -6
  46. package/types/backend/src/runtime.d.ts +39 -2
  47. package/types/internal/src/chat.d.ts +7 -39
  48. package/types/internal/src/modules/ai.d.ts +68 -35
  49. package/types/internal/src/modules/realtime.d.ts +9 -1
  50. package/types/web/src/backends.d.ts +19 -12
  51. package/types/web/src/chat.d.ts +118 -0
  52. package/types/web/src/client.d.ts +0 -3
  53. package/types/web/src/gateways.d.ts +89 -0
  54. package/types/web/src/index.d.ts +3 -3
  55. package/types/web/src/socket.d.ts +18 -2
  56. package/dist/chunks/2RG3I7LX.js +0 -6
  57. package/dist/chunks/A76UZBAF.js +0 -2
  58. package/dist/chunks/AD5LBZAB.js +0 -4
  59. package/dist/chunks/DRGYTL6T.js +0 -20
  60. package/dist/chunks/IVEAUFGE.js +0 -13
  61. package/dist/chunks/KL7FIRII.js +0 -2
  62. package/types/backend/src/channels.d.ts +0 -81
  63. package/types/backend/src/rooms.d.ts +0 -178
  64. package/types/web/src/ai.d.ts +0 -224
  65. package/types/web/src/rooms.d.ts +0 -61
@@ -1,178 +0,0 @@
1
- import type { realtime } from '../../internal/src/modules/index.js';
2
- import { type StandardSchemaV1 } from './decorators.js';
3
- import { type SignedUser } from './platform-calls.js';
4
- export declare const ROOM: unique symbol;
5
- export declare const ROOM_HOOKS: unique symbol;
6
- /** The moments a room's methods are told of. */
7
- export type RoomHook = 'authorize' | 'first' | 'join' | 'leave' | 'empty';
8
- export interface RoomOptions {
9
- /**
10
- * What the room sends its members, by event name, each its payload's
11
- * schema: the room's public surface, typed in every generated client. A
12
- * room emits from anywhere in its class, so there is no return type to read
13
- * them from — they are declared.
14
- */
15
- events: Record<string, StandardSchemaV1>;
16
- /**
17
- * How long the room is held after its last member left before it is empty
18
- * (@OnEmpty), in milliseconds: 60000 unless said. Raise it for an upstream
19
- * that is expensive to start again; one who comes back within it finds the
20
- * room as it was.
21
- */
22
- graceMs?: number;
23
- }
24
- /** A room as its decorators declare it. */
25
- export interface RoomDeclaration {
26
- pattern: string;
27
- events: Record<string, StandardSchemaV1>;
28
- graceMs: number;
29
- /** Each moment, the method told of it. */
30
- hooks: Partial<Record<RoomHook, string>>;
31
- /** Each message a member may send: its method, and its payload's schema — an object of no prototype, whatever the names. */
32
- messages: Record<string, {
33
- fn: string;
34
- schema: StandardSchemaV1;
35
- }>;
36
- }
37
- /** Who a member is, to a room's methods. */
38
- export interface RoomUser {
39
- /** The user's id; "" in @OnFirst and @OnEmpty, which no one in particular caused. */
40
- id: string;
41
- }
42
- /** What @OnAuthorize is given: who asks to join, and the channel's parameters. */
43
- export interface RoomAuthorizeContext {
44
- user: RoomUser;
45
- params: Readonly<Record<string, string>>;
46
- }
47
- /**
48
- * What @OnAuthorize answers: true lets the user in to hear and to send; an
49
- * object says which — { read: false } is no way in (admitted to hear nothing
50
- * is not admitted), { write: false } a listener who may not send; null,
51
- * undefined or false keep the user out. A room with no @OnAuthorize lets
52
- * nobody in, and one whose @OnAuthorize throws lets that user in nowhere.
53
- * So does any other answer — a number, a string, an object that says
54
- * neither read nor write ({} too): only a grant lets anyone in, and the
55
- * app's log says what was answered instead.
56
- */
57
- export type RoomGrant = boolean | null | undefined | {
58
- read?: boolean;
59
- write?: boolean;
60
- };
61
- /** What a room's moments are given (@OnFirst, @OnJoin, @OnLeave, @OnEmpty). */
62
- export interface RoomContext {
63
- /** The channel: "ai:42". */
64
- room: string;
65
- /** The pattern's parameters: { sessionId: "42" }. */
66
- params: Readonly<Record<string, string>>;
67
- /**
68
- * The room's own: aborted when it empties (before @OnEmpty runs), or when
69
- * owner.release() gives it up — what @OnFirst started stops on it.
70
- */
71
- signal: AbortSignal;
72
- /** Its members now, across realtime's replicas; 0 in @OnMessage. */
73
- count: number;
74
- user: RoomUser;
75
- /**
76
- * An event to the room's members — in @OnJoin, to the member who joined
77
- * alone. Sent in the order emitted, and never thrown: realtime is lossy,
78
- * and what could not be sent is in the app's log.
79
- */
80
- emit(event: string, payload?: unknown): void;
81
- owner: {
82
- /** Runs `work` past the method, until the room's signal aborts: an upstream's loop. Its failure is logged, never the app's crash. */
83
- hold(work: (signal: AbortSignal) => unknown): void;
84
- /** Gives the room up now: its signal aborts, and the next member to come finds it unheld (@OnFirst again). */
85
- release(): void;
86
- };
87
- }
88
- /** What @OnMessage is given: the room's context, the member, and the payload as its schema made it. */
89
- export interface RoomMessageContext<P = unknown> extends RoomContext {
90
- payload: P;
91
- }
92
- /** v2 held a room a minute after its last member: twice the slowest client's heartbeat, and margin. */
93
- export declare const DEFAULT_GRACE_MS = 60000;
94
- /**
95
- * Why `pattern` is no room's, or undefined. A pattern is a channel's: ':'
96
- * segments, a "{name}" segment taking exactly one — and realtime takes a
97
- * pattern it cannot decide for no room at all, silently: the room would
98
- * compile, ship and never be joined. So everything it would not take is
99
- * refused here, by name, while someone is looking.
100
- */
101
- export declare function patternProblem(pattern: string): string | undefined;
102
- /**
103
- * A class whose methods manage the room `pattern` names. It is a provider a
104
- * module lists (its constructor injected as any provider's), built once: what
105
- * @OnFirst starts and @OnEmpty stops lives in it.
106
- *
107
- * @Room('ai:{sessionId}', { events: { token: Token } })
108
- * class AiRoom {
109
- * @OnAuthorize() can({ user, params }: RoomAuthorizeContext): RoomGrant { … }
110
- * @OnFirst() open(ctx: RoomContext) { ctx.owner.hold((signal) => this.stream(ctx, signal)); }
111
- * @OnEmpty() close(ctx: RoomContext) { … }
112
- * @OnMessage('say', Say) say(ctx: RoomMessageContext<Say>) { … }
113
- * }
114
- */
115
- export declare function Room(pattern: string, options: RoomOptions): ClassDecorator;
116
- /** Who may join: answers a RoomGrant (RoomAuthorizeContext). No @OnAuthorize, and nobody joins. */
117
- export declare const OnAuthorize: () => MethodDecorator;
118
- /**
119
- * The room is occupied and held by no one: start what it needs. Told once
120
- * across realtime's replicas when its first member comes — before that
121
- * member is answered — and again only after it emptied.
122
- */
123
- export declare const OnFirst: () => MethodDecorator;
124
- /** A member joined (after it was answered): what it emits goes to that member alone. */
125
- export declare const OnJoin: () => MethodDecorator;
126
- /** A member left. */
127
- export declare const OnLeave: () => MethodDecorator;
128
- /** Nobody has been in the room for its graceMs: stop what @OnFirst started. Its signal is aborted already. */
129
- export declare const OnEmpty: () => MethodDecorator;
130
- /**
131
- * A message a member sends, `name`, its payload checked against `schema`
132
- * before the method runs (RoomMessageContext): a payload that does not fit
133
- * never reaches it, and the member hears why.
134
- */
135
- export declare function OnMessage(name: string, schema: StandardSchemaV1): MethodDecorator;
136
- /** The room a class declares, or undefined: a room is one by its decorator, never its name. */
137
- export declare function roomOf(cls: Function): RoomDeclaration | undefined;
138
- /** A room's channel's parameters, or undefined when the channel is not one of its. */
139
- export declare function matchRoom(pattern: string, channel: string): Record<string, string> | undefined;
140
- /** One event to a room's members, as realtime's broadcast takes it: its channel (topic), and conn_id for one membership alone. */
141
- type RoomBroadcast = realtime.BroadcastMessage;
142
- export interface RoomDeps {
143
- /**
144
- * `work` as the platform's caller names it — in a transaction as `user`,
145
- * or as the app itself when the moment is no one's (first, empty) —
146
- * committed unless it throws, or the platform hung up before it ended.
147
- */
148
- run<T>(user: SignedUser | undefined, where: string, signal: AbortSignal | undefined, work: () => Promise<T>): Promise<T>;
149
- /** realtime's POST /realtime/broadcast, as the app (its secret key). */
150
- broadcast(messages: RoomBroadcast[]): Promise<unknown>;
151
- /** The platform's infrastructure, not the method, failed: the call is answered 503, and realtime asks again. */
152
- isOutage(e: unknown): boolean;
153
- }
154
- /** What a room's call is answered: JSON, nothing (204), or a refusal. */
155
- export type RoomAnswer = {
156
- status: 200;
157
- body: unknown;
158
- } | {
159
- status: 204;
160
- } | {
161
- status: number;
162
- code: string;
163
- message: string;
164
- retryAfter?: number;
165
- };
166
- export interface Rooms {
167
- readonly declarations: readonly RoomDeclaration[];
168
- /** The platform's call about a room — authorize, message or lifecycle — its JSON body. */
169
- serve(kind: string, body: unknown, signal?: AbortSignal): Promise<RoomAnswer>;
170
- /** Every room let go: what was held is aborted (the app is stopping). */
171
- close(): void;
172
- }
173
- /** The app's rooms, served: `classes` its providers that are rooms, each with its instance. */
174
- export declare function createRooms(classes: {
175
- cls: Function;
176
- instance: object;
177
- }[], deps: RoomDeps): Rooms;
178
- export {};
@@ -1,224 +0,0 @@
1
- import { type AgentEvent, type ToolEvent, type TurnEvent, type VoiceEvent } from '../../internal/src/chat.js';
2
- import { ai as aiModule } from '../../internal/src/modules/index.js';
3
- import { type ToolResult } from '../../internal/src/tool-output.js';
4
- import { type Transport } from '../../internal/src/transport.js';
5
- import type { SessionManager } from './session.js';
6
- export type Chat = aiModule.Chat;
7
- export type { AgentEvent, ChatEvent, ToolEvent, TurnEvent, VoiceEvent } from '../../internal/src/chat.js';
8
- export type { ToolResult } from '../../internal/src/tool-output.js';
9
- /** A member's message as this client holds it: one it sent is here at once, pending until the agent has it. */
10
- export interface ChatMessageView {
11
- /** The writer's id for it: the same id is the same message. */
12
- clientId: string;
13
- /** The module's id; null until it answered. */
14
- id: string | null;
15
- text: string;
16
- /** The member who wrote it; null: the project's server (or, for one this client sent, not yet answered — mine says it is the user's). */
17
- author: string | null;
18
- authorName: string;
19
- delivery: string;
20
- /** pending until the agent has it, delivered once it does, failed when it could not be given (or sent). */
21
- status: 'pending' | 'delivered' | 'failed';
22
- /** Why it failed: the module's code. */
23
- error: string | null;
24
- /** The turn it started or reached. */
25
- responseId: string | null;
26
- createdAt: string;
27
- /** Sent from this client. */
28
- mine: boolean;
29
- }
30
- /** A piece of an answer, in order: its text, split where a tool was called or a subagent handed work. */
31
- export type ChatPart = {
32
- type: 'text';
33
- text: string;
34
- } | {
35
- type: 'tool';
36
- tool: ToolEvent;
37
- } | {
38
- type: 'agent';
39
- agent: AgentEvent;
40
- };
41
- /** One answer of the agent's (or of one of its subagents). */
42
- export interface ChatResponse {
43
- id: string;
44
- status: TurnEvent['status'] | null;
45
- waiting: TurnEvent['waiting'];
46
- error: TurnEvent['error'];
47
- /** The whole answer so far. */
48
- text: string;
49
- parts: ChatPart[];
50
- /** A subagent's: its run, its name, and the response that handed it the work. */
51
- runId: string | null;
52
- agent: string | null;
53
- parentId: string | null;
54
- /** The member whose turn it is (a subagent's: its turn's); null: the project's server's, or the engine's. */
55
- startedBy: string | null;
56
- /** The signed-in user's own turn: theirs alone to answer its client tools and decide its approvals. */
57
- mine: boolean;
58
- /** The chat has had one member all its life, as its turn last said (null until it did): only then does this app answer its client tools by itself. */
59
- solo: boolean | null;
60
- }
61
- export type ChatItem = {
62
- type: 'message';
63
- message: ChatMessageView;
64
- } | {
65
- type: 'response';
66
- response: ChatResponse;
67
- };
68
- export interface ChatState {
69
- /** idle until the chat is first used; live while its stream is open; failed when the stream was refused (error says why). */
70
- status: 'idle' | 'connecting' | 'live' | 'failed' | 'closed';
71
- error: unknown;
72
- /** The conversation in order: the members' messages and the agent's answers (a subagent's is in its parent's parts). */
73
- items: ChatItem[];
74
- messages: ChatMessageView[];
75
- /** Every answer, the subagents' too, as they began. */
76
- responses: ChatResponse[];
77
- /** The last turn's state. */
78
- turn: TurnEvent | null;
79
- /**
80
- * What waits for this user: tool calls of their own turns waiting for
81
- * their yes (approve/deny), and client tool calls of their own turns
82
- * waiting for their app's answer. Another member's turn is theirs to
83
- * decide — its calls are in its parts, not here.
84
- */
85
- waiting: {
86
- approvals: ToolEvent[];
87
- outputs: ToolEvent[];
88
- };
89
- /** The chat's live voice as it went: what was said either way, in order, and when it began, ended or handed a task over. */
90
- voice: VoiceEvent[];
91
- }
92
- /**
93
- * A chat's live voice this app started (startVoice): its id, its peer connection, and stop. What the voice is
94
- * told besides what it hears is the app's server's to say (the server SDK), never a member's.
95
- */
96
- export interface ChatVoice {
97
- readonly id: string;
98
- readonly peer: RTCPeerConnection;
99
- /** Ends the voice; how long it lasted, in seconds. */
100
- stop(): Promise<number>;
101
- }
102
- export interface ChatOptions {
103
- /** The journal id to follow from (default 0: the chat from its start). */
104
- after?: number;
105
- /** How long a stream that keeps being cut is followed again before the chat fails (default 2 minutes). */
106
- resumeFor?: number;
107
- }
108
- /** A client tool's answer, by the tool's name: what it returns is shown to the agent; a throw is the tool's failure. */
109
- export type ClientToolHandlers = Record<string, (input: unknown, call: ToolEvent) => ToolResult | Promise<ToolResult>>;
110
- /** One chat, followed: its state, its changes, and what the user does in it. */
111
- export declare class ChatSession implements AsyncIterable<ChatState> {
112
- readonly id: string;
113
- private readonly api;
114
- private readonly session;
115
- private readonly options;
116
- private status;
117
- private error;
118
- private readonly messages;
119
- private readonly responses;
120
- private readonly order;
121
- private turn;
122
- private readonly calls;
123
- private readonly voiceParts;
124
- private readonly handlers;
125
- private readonly answering;
126
- private readonly listeners;
127
- private following;
128
- /** Where the stream is: a chat followed again (after a failure) goes on from there, not from its start. */
129
- private position;
130
- private snapshot;
131
- private told;
132
- constructor(api: ReturnType<typeof aiModule.client>, id: string, options?: ChatOptions, session?: SessionManager);
133
- /** The chat as this client holds it now: the same object until it changes. */
134
- get state(): ChatState;
135
- /** Told the state each time it changes (at most once a microtask); returns the unsubscribe. The chat is followed from now on. */
136
- subscribe(listener: (state: ChatState) => void): () => void;
137
- /** The state now, then each time it changes; a break leaves the chat followed (close() ends it). */
138
- [Symbol.asyncIterator](): AsyncGenerator<ChatState, void, undefined>;
139
- /**
140
- * Writes to the chat: the message is in the state at once, pending, and
141
- * delivered when the agent has it (the stream says so); failed when it
142
- * could not be sent — the promise rejects with why (429
143
- * too_many_messages, 409 history_full). The same clientId again (a
144
- * failed message sent again) is the same message.
145
- */
146
- send(text: string, options?: {
147
- delivery?: 'next' | 'now';
148
- clientId?: string;
149
- }): Promise<ChatMessageView>;
150
- /**
151
- * The client tools this app answers by itself, by name: a call of one of
152
- * them that waits for its output (a tool part, awaiting_output) is
153
- * answered with what the function returns — in a turn the signed-in user
154
- * started, of a chat that is theirs alone (solo). In a chat with other
155
- * members a message of theirs may have asked for it (a location, a
156
- * photo), and they see the answer: the call stays in waiting.outputs for
157
- * the app to ask its user and answer (answer()). A call in another
158
- * member's turn is theirs: it never runs on this device (the module
159
- * refuses another's answer, 403 not_your_turn). Returns the function that
160
- * takes them back.
161
- */
162
- tools(handlers: ClientToolHandlers): () => void;
163
- /**
164
- * Answers a client tool's call of the user's own turn (a tool part's
165
- * call_id, awaiting_output) — what tools() does by itself in a chat that is
166
- * theirs alone, and the app does here when it is not, once its user said
167
- * yes. True when this answer is the one; false when the call was answered
168
- * already or waits no more.
169
- */
170
- answer(callId: string, output: ToolResult, options?: {
171
- isError?: boolean;
172
- }): Promise<boolean>;
173
- /** A call that waits for a person's yes (a tool part's approval_id): made. */
174
- approve(approvalId: string, reason?: string): Promise<void>;
175
- /** Not made: the agent is told, with the reason, and goes on. */
176
- deny(approvalId: string, reason?: string): Promise<void>;
177
- /** Stops the turn the agent is working on: what it wrote stays. Its response's id, or null when none ran. */
178
- stop(): Promise<string | null>;
179
- /**
180
- * Starts the chat's live voice from the microphone's stream: the voice's
181
- * audio plays in audio (a new element unless given), and what is said
182
- * either way comes into the state's voice parts. One voice a chat at a time.
183
- */
184
- startVoice(options: {
185
- stream: MediaStream;
186
- voice?: string;
187
- audio?: HTMLAudioElement;
188
- }): Promise<ChatVoice>;
189
- /** A message for one of the agent's subagents at work (an agent part's run_id), at its next step. */
190
- sendToSubagent(runId: string, text: string): Promise<void>;
191
- /** Stops following the chat. */
192
- close(): void;
193
- private follow;
194
- private take;
195
- private heard;
196
- private response;
197
- private autoAnswer;
198
- /** The signed-in user started this response's turn (its turn event said so). */
199
- private mine;
200
- private changed;
201
- private build;
202
- }
203
- /** The project's agents for the signed-in user. */
204
- export declare class AI {
205
- /** Every client operation of the ai contract, through the session's transport. */
206
- readonly api: ReturnType<typeof aiModule.client>;
207
- private readonly session;
208
- /** The chats the user is in: started with a named agent the project opened to its users (as its owner), listed, read, deleted (an owner's). */
209
- readonly chats: {
210
- /** A chat with a named agent (clients: true), the user its owner under `name`. A user's chat carries no metadata: that is the server's to write. */
211
- create(chat: {
212
- agent: string;
213
- name?: string;
214
- title?: string;
215
- }): Promise<Chat>;
216
- /** The chats the user is in, the newest first (100 at most). */
217
- list(): Promise<Chat[]>;
218
- get(id: string): Promise<Chat>;
219
- delete(id: string): Promise<void>;
220
- };
221
- constructor(transport: Transport, session?: SessionManager);
222
- /** A chat the user is in, to follow and write to. */
223
- chat(chatId: string, options?: ChatOptions): ChatSession;
224
- }
@@ -1,61 +0,0 @@
1
- import type { RealtimeSocket } from './socket.js';
2
- /** One event of a room, as a generated module's union has it. */
3
- export type RoomEvent = {
4
- event: string;
5
- payload: unknown;
6
- };
7
- /**
8
- * A room, as the generator writes one. `send` and `event` carry types alone —
9
- * their values are never read: `room.send('say', { … })` is checked against
10
- * the message's shape, and a handler's event against the room's events.
11
- */
12
- export interface RoomDescriptor<E extends RoomEvent, S, P extends readonly string[] = readonly string[]> {
13
- /** The channel pattern the backend declared: `ai:{sessionId}`. */
14
- pattern: string;
15
- /** The `{param}` names, in the pattern's order: a join takes exactly these. */
16
- params: P;
17
- /** The declared event names: what a handle listens to. */
18
- events: readonly string[];
19
- /** The declared message names: what a handle sends. */
20
- messages: readonly string[];
21
- send: S;
22
- event: E;
23
- }
24
- /** What `on` returns: called, it stops that callback (`off` does the same). */
25
- export type RoomSubscription = () => void;
26
- /** A live room. Hold it for as long as the view is on screen, and `leave` it when the view goes: an occupied room is one its backend is still running for. */
27
- export interface RoomHandle<E extends RoomEvent, S> {
28
- /** The channel this handle is on: `ai:42`. */
29
- readonly topic: string;
30
- /** Every event the room declares, as a union to switch over. */
31
- on(handler: (event: E) => void): RoomSubscription;
32
- /** One event by its name, its payload typed. */
33
- on<K extends E['event']>(event: K, handler: (payload: Extract<E, {
34
- event: K;
35
- }>['payload']) => void): RoomSubscription;
36
- /** Stops one callback. */
37
- off(subscription: RoomSubscription): void;
38
- /**
39
- * Sends one declared message and waits for the room's backend to take it;
40
- * rejects with a RoomError — its reason — when it did not.
41
- */
42
- send<K extends keyof S & string>(message: K, payload: S[K]): Promise<void>;
43
- /** Drops every callback of this handle and lets go of the room; the channel is left with its last handle. */
44
- leave(): void;
45
- }
46
- /**
47
- * Why a room did not do what was asked. `reason` is the server's: for a join,
48
- * `unauthorized` (the backend did not let the user in) or `unavailable` (it
49
- * could not be asked: try again); for a message, the reason the backend gave,
50
- * `forbidden` when it gave none or the user may only listen, `rate_limited`,
51
- * `unavailable`. When no answer came it is `no reply` or `socket closed` —
52
- * the message may have been taken — and `not joined` when nothing was sent:
53
- * the handle left, its socket closed (a sign-out, another user's sign-in), or
54
- * the socket dropped and is being opened again.
55
- */
56
- export declare class RoomError extends Error {
57
- readonly reason: string;
58
- constructor(message: string, reason: string);
59
- }
60
- /** Joins `room` on `socket`: resolves once the backend let the user in, rejects with a RoomError when it did not. */
61
- export declare function joinRoom<E extends RoomEvent, S, P extends readonly string[]>(socket: RealtimeSocket, room: RoomDescriptor<E, S, P>, params: Record<P[number], string>): Promise<RoomHandle<E, S>>;