@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 32 lines 1.03 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Layer from "effect/Layer";
3 import { makeQueueBinding, makeQueueHelpers } from "./QueueBinding.ts";
4 import type { SendMessage, SendOptions } from "./QueueTypes.ts";
5 import { WriteQueue, type WriteQueueClient } from "./WriteQueue.ts";
6
7 /**
8 * Implementation of the {@link WriteQueue} service that uses a native Worker
9 * queue binding.
10 */
11 export const WriteQueueBinding = Layer.effect(
12 WriteQueue,
13 Effect.suspend(() => makeQueueBinding({ makeClient: makeWriteQueueClient })),
14 );
15
16 /** Build the producer client over a native Worker queue binding. */
17 export const makeWriteQueueClient = ({
18 raw,
19 use,
20 }: ReturnType<typeof makeQueueHelpers>): WriteQueueClient => ({
21 raw,
22 send: (body: unknown, options?: SendOptions) => use((q) => q.send(body, options)),
23 sendBatch: (messages: ReadonlyArray<SendMessage>) =>
24 use((q) =>
25 q.sendBatch(
26 messages.map((m) => ({
27 body: m.body,
28 ...(m.contentType ? { contentType: m.contentType } : {}),
29 })),
30 ),
31 ),
32 });