@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 40 lines 1.43 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as Layer from "effect/Layer";
3 import { makeLocalStreamBinding } from "./StreamHttp.ts";
4 import { WriteStream } from "./WriteStream.ts";
5
6 /**
7 * Local implementation of the {@link WriteStream} service — POSTs records
8 * to the stream's HTTP ingest endpoint with the **current credentials**
9 * instead of a native Worker binding (`WriteStreamBinding`) or a scoped
10 * API token (`WriteStreamHttp`).
11 *
12 * Provide it on an Action (or any deploy-time Effect) to send events with
13 * the same typed client you use inside a Worker. The stream needs its HTTP
14 * endpoint enabled (`http: true`), and the current credentials need the
15 * `Pipelines Send` permission when it is authenticated.
16 * ### Providing the Layer
17 * **Example:** Seed a stream from an Action
18 * ```typescript
19 * const Seed = Alchemy.Action(
20 * "Seed",
21 * Effect.gen(function* () {
22 * const views = yield* Cloudflare.Basin.WriteStream(PageViews);
23 * return Effect.fn(function* () {
24 * yield* views.send([new PageView({ url: "/", at: new Date() })]);
25 * });
26 * }).pipe(Effect.provide(Cloudflare.Basin.WriteStreamLocal)),
27 * );
28 * ```
29 *
30 * @layer
31 * @provides Cloudflare.Pipelines.WriteStream
32 * @product Pipelines
33 * @category Storage & Databases
34 */
35 export const WriteStreamLocal = Layer.effect(
36 WriteStream,
37 Effect.suspend(() =>
38 makeLocalStreamBinding({ layer: "WriteStreamLocal", makeClient: (client) => client }),
39 ),
40 );