The best way to control Claude Code, Codex and more from any computer or phone

main
ts 56 lines 1.9 KB
Raw
1 import type * as ivschat from "@distilled.cloud/aws/ivschat";
2 import * as Binding from "alchemy/Binding";
3 import type * as Effect from "effect/Effect";
4 import type { Room } from "./Room.ts";
5
6 /**
7 * The `roomIdentifier` is injected by the binding from the bound room;
8 * the caller supplies the event name and optional attributes.
9 */
10 export interface SendEventRequest extends Omit<ivschat.SendEventRequest, "roomIdentifier"> {}
11
12 /**
13 * Send an application-defined event to every client connected to the bound
14 * room — the effectful call made from a deployed Lambda or Task. Use it to
15 * broadcast state changes (poll results, stream metadata, moderation
16 * notices) alongside user chat messages; `attributes` carries the payload
17 * as string key-value pairs.
18 *
19 * ### Broadcasting Events
20 * Provide the `SendEventHttp` implementation layer on the Function effect,
21 * bind the room in the init phase, then call the returned client at
22 * runtime. The binding grants `ivschat:SendEvent` on the room and injects
23 * its ARN as the `roomIdentifier` automatically.
24 *
25 * **Example:** Broadcast from a Lambda
26 * ```typescript
27 * // init
28 * const room = yield* IVSChat.Room("LiveChat");
29 * const sendEvent = yield* IVSChat.SendEvent(room);
30 *
31 * return {
32 * fetch: Effect.gen(function* () {
33 * // runtime
34 * const { id } = yield* sendEvent({
35 * eventName: "app:poll-result",
36 * attributes: { question: "q1", winner: "option-b" },
37 * });
38 * return HttpServerResponse.json({ id });
39 * }),
40 * };
41 * // on the Function effect:
42 * // .pipe(Effect.provide(IVSChat.SendEventHttp))
43 * ```
44 *
45 * @binding
46 */
47 export interface SendEvent extends Binding.Service<
48 SendEvent,
49 "AWS.IVSChat.SendEvent",
50 (
51 room: Room,
52 ) => Effect.Effect<
53 (request: SendEventRequest) => Effect.Effect<ivschat.SendEventResponse, ivschat.SendEventError>
54 >
55 > {}
56 export const SendEvent = Binding.Service<SendEvent>("AWS.IVSChat.SendEvent");