@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, 06:00 UTC

main
ts 58 lines 2.26 KB
Raw
1 import type * as eventbridge from "@distilled.cloud/aws/eventbridge";
2 import * as Binding from "alchemy/Binding";
3 import type { BatchRetryExhaustedError } from "alchemy/Util/BatchedSink";
4 import type * as Effect from "effect/Effect";
5 import type * as Sink from "effect/Sink";
6 import type { EventBus } from "./EventBus.ts";
7
8 /**
9 * A raw `PutEventsRequestEntry` minus `EventBusName`, which the sink derives
10 * from the bus it is bound to. Callers stay in control of `Source`,
11 * `DetailType`, `Detail`, `Time`, `Resources`, and `TraceHeader` — no
12 * auto-marshalling.
13 */
14 export interface BusSinkEntry extends Omit<eventbridge.PutEventsRequestEntry, "EventBusName"> {}
15
16 export type BusSinkError = eventbridge.PutEventsError | BatchRetryExhaustedError<BusSinkEntry>;
17
18 /**
19 * A batching sink over EventBridge `PutEvents` (10 entries / 256 KiB per
20 * call). Per-entry failures with transient error codes (`ThrottlingException`,
21 * `InternalFailure`) are re-submitted on a bounded schedule; any other
22 * per-entry `ErrorCode` (e.g. `MalformedDetail`) is permanent — those entries
23 * are dropped and surfaced via a logged warning. Exhausting retries fails the
24 * sink with a typed `BatchRetryExhaustedError` carrying the stranded entries.
25 *
26 * Omit the bus argument to publish to the account's default event bus.
27 *
28 * ### Streaming Events
29 * **Example:** Run a Stream of Entries into the Bus
30 * ```typescript
31 * // init — bind the sink (provide AWS.EventBridge.BusSinkHttp on the Function)
32 * const sink = yield* AWS.EventBridge.BusSink(bus);
33 *
34 * return {
35 * fetch: Effect.gen(function* () {
36 * // runtime — publish a stream of raw PutEvents entries
37 * const entries: AWS.EventBridge.BusSinkEntry[] = markers.map((marker) => ({
38 * Source: "my.app",
39 * DetailType: "MarkerSeen",
40 * Detail: JSON.stringify({ marker }),
41 * }));
42 * yield* Stream.fromIterable(entries).pipe(Stream.run(sink));
43 * return HttpServerResponse.json({ ok: true });
44 * }),
45 * };
46 * ```
47 *
48 * @binding
49 */
50 export interface BusSink extends Binding.Service<
51 BusSink,
52 "AWS.EventBridge.BusSink",
53 (
54 bus?: EventBus,
55 ) => Effect.Effect<Sink.Sink<void, BusSinkEntry, readonly BusSinkEntry[], BusSinkError>>
56 > {}
57
58 export const BusSink = Binding.Service<BusSink>("AWS.EventBridge.BusSink");