@devries-cameron20 / t3code Mirror · read-only / commits / 1bcfc88f58
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 25, 05:00 UTC

Adopt idiomatic Effect APIs in generator and decider (#2581)

Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

cursor[bot] committed May 7, 2026 at 12:19 UTC 1bcfc88f589051c92882151788217c1410141ef7
2 files changed +45 -59
apps/server/src/orchestration/decider.ts
+11 -21
@@ -3,7 +3,7 @@ import type {
3 OrchestrationEvent,
4 OrchestrationReadModel,
5 } from "@t3tools/contracts";
6 -import { Effect } from "effect";
6 +import { DateTime, Effect } from "effect";
7
8 import { OrchestrationCommandInvariantError } from "./Errors.ts";
9 import {
@@ -17,17 +17,7 @@ import {
17 } from "./commandInvariants.ts";
18 import { projectEvent } from "./projector.ts";
19
20 -const nowIso = () => new Date().toISOString();
21 -const defaultMetadata: Omit<OrchestrationEvent, "sequence" | "type" | "payload"> = {
22 - eventId: crypto.randomUUID() as OrchestrationEvent["eventId"],
23 - aggregateKind: "thread",
24 - aggregateId: "" as OrchestrationEvent["aggregateId"],
25 - occurredAt: nowIso(),
26 - commandId: null,
27 - causationEventId: null,
28 - correlationId: null,
29 - metadata: {},
30 -};
20 +const currentIso = DateTime.now.pipe(Effect.map(DateTime.formatIso));
21
22 function withEventBase(
23 input: Pick<OrchestrationCommand, "commandId"> & {
@@ -38,12 +28,12 @@ function withEventBase(
28 },
29 ): Omit<OrchestrationEvent, "sequence" | "type" | "payload"> {
30 return {
41 - ...defaultMetadata,
31 eventId: crypto.randomUUID() as OrchestrationEvent["eventId"],
32 aggregateKind: input.aggregateKind,
33 aggregateId: input.aggregateId,
34 occurredAt: input.occurredAt,
35 commandId: input.commandId,
36 + causationEventId: null,
37 correlationId: input.commandId,
38 metadata: input.metadata ?? {},
39 };
@@ -126,7 +116,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
116 command,
117 projectId: command.projectId,
118 });
129 - const occurredAt = nowIso();
119 + const occurredAt = yield* currentIso;
120 return {
121 ...withEventBase({
122 aggregateKind: "project",
@@ -183,7 +173,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
173 });
174 }
175
186 - const occurredAt = nowIso();
176 + const occurredAt = yield* currentIso;
177 return {
178 ...withEventBase({
179 aggregateKind: "project",
@@ -239,7 +229,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
229 command,
230 threadId: command.threadId,
231 });
242 - const occurredAt = nowIso();
232 + const occurredAt = yield* currentIso;
233 return {
234 ...withEventBase({
235 aggregateKind: "thread",
@@ -261,7 +251,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
251 command,
252 threadId: command.threadId,
253 });
264 - const occurredAt = nowIso();
254 + const occurredAt = yield* currentIso;
255 return {
256 ...withEventBase({
257 aggregateKind: "thread",
@@ -284,7 +274,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
274 command,
275 threadId: command.threadId,
276 });
287 - const occurredAt = nowIso();
277 + const occurredAt = yield* currentIso;
278 return {
279 ...withEventBase({
280 aggregateKind: "thread",
@@ -306,7 +296,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
296 command,
297 threadId: command.threadId,
298 });
309 - const occurredAt = nowIso();
299 + const occurredAt = yield* currentIso;
300 return {
301 ...withEventBase({
302 aggregateKind: "thread",
@@ -334,7 +324,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
324 command,
325 threadId: command.threadId,
326 });
337 - const occurredAt = nowIso();
327 + const occurredAt = yield* currentIso;
328 return {
329 ...withEventBase({
330 aggregateKind: "thread",
@@ -357,7 +347,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
347 command,
348 threadId: command.threadId,
349 });
360 - const occurredAt = nowIso();
350 + const occurredAt = yield* currentIso;
351 return {
352 ...withEventBase({
353 aggregateKind: "thread",
packages/effect-codex-app-server/scripts/generate.ts
+34 -38
@@ -4,6 +4,12 @@ import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
4 import * as NodeServices from "@effect/platform-node/NodeServices";
5 import { make as makeJsonSchemaGenerator } from "@effect/openapi-generator/JsonSchemaGenerator";
6 import { Effect, FileSystem, Layer, Logger, Path, Schema } from "effect";
7 +import {
8 + FetchHttpClient,
9 + HttpClient,
10 + HttpClientRequest,
11 + HttpClientResponse,
12 +} from "effect/unstable/http";
13 import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
14
15 const UPSTREAM_REF = "be75785504ff152fa6333e380a2d50642f42fba0";
@@ -21,6 +27,13 @@ const GithubContentEntries = Schema.Array(
27 );
28 type GithubContentEntry = (typeof GithubContentEntries.Type)[number];
29
30 +const JsonSchemaDocument = Schema.StructWithRest(
31 + Schema.Struct({
32 + definitions: Schema.optionalKey(Schema.Record(Schema.String, Schema.Json)),
33 + }),
34 + [Schema.Record(Schema.String, Schema.Json)],
35 +);
36 +
37 interface GeneratedPaths {
38 readonly generatedDir: string;
39 readonly schemaOutputPath: string;
@@ -143,40 +156,19 @@ const ensureGeneratedDir = Effect.fn("ensureGeneratedDir")(function* () {
156 });
157
158 const fetchText = Effect.fn("fetchText")(function* (url: string) {
146 - const response = yield* Effect.tryPromise({
147 - try: () =>
148 - fetch(url, {
149 - headers: {
150 - "user-agent": USER_AGENT,
151 - },
152 - }),
153 - catch: (cause) =>
154 - new GeneratorError({
155 - detail: `Failed to fetch ${url}`,
156 - cause,
157 - }),
158 - });
159 -
160 - if (!response.ok) {
161 - const detail = yield* Effect.tryPromise({
162 - try: () => response.text(),
163 - catch: () => "",
164 - });
165 - return yield* Effect.fail(
166 - new GeneratorError({
167 - detail: `Failed to download ${url}: ${response.status} ${detail}`,
168 - }),
169 - );
170 - }
171 -
172 - return yield* Effect.tryPromise({
173 - try: () => response.text(),
174 - catch: (cause) =>
175 - new GeneratorError({
176 - detail: `Failed to read response body for ${url}`,
177 - cause,
178 - }),
179 - });
159 + return yield* HttpClientRequest.get(url).pipe(
160 + HttpClientRequest.setHeader("user-agent", USER_AGENT),
161 + HttpClient.execute,
162 + Effect.flatMap(HttpClientResponse.filterStatusOk),
163 + Effect.flatMap((okResponse) => okResponse.text),
164 + Effect.mapError(
165 + (cause) =>
166 + new GeneratorError({
167 + detail: `Failed to fetch ${url}`,
168 + cause,
169 + }),
170 + ),
171 + );
172 });
173
174 const fetchDirectoryEntries = Effect.fn("fetchDirectoryEntries")(function* (path: string) {
@@ -548,9 +540,7 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
540
541 for (const file of jsonSchemaFiles) {
542 const raw = yield* fetchText(file.downloadUrl);
551 - const parsed = JSON.parse(raw) as {
552 - readonly definitions?: Record<string, typeof Schema.Json.Type>;
553 - } & Record<string, typeof Schema.Json.Type>;
543 + const parsed = yield* Schema.decodeEffect(Schema.fromJsonString(JsonSchemaDocument))(raw);
544 const localDefinitionNames = new Map(
545 Object.keys(parsed.definitions ?? {}).map((definitionName) => [
546 definitionName,
@@ -767,6 +757,12 @@ const generateFiles = Effect.fn("generateFiles")(function* () {
757
758 generateFiles().pipe(
759 Effect.scoped,
770 - Effect.provide(Layer.mergeAll(Logger.layer([Logger.consolePretty()]), NodeServices.layer)),
760 + Effect.provide(
761 + Layer.mergeAll(
762 + Logger.layer([Logger.consolePretty()]),
763 + NodeServices.layer,
764 + FetchHttpClient.layer,
765 + ),
766 + ),
767 NodeRuntime.runMain,
768 );