@devries-cameron20 / t3code Mirror · read-only / commits / 01492ebd3b
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, 03:45 UTC

[codex] Refactor agent awareness relay service (#3197)

Co-authored-by: codex <codex@users.noreply.github.com>

Julius Marminge committed Jun 19, 2026 at 21:18 UTC 01492ebd3b624e544e6375c12540b741c65256b9
1 file changed +23 -25
apps/server/src/relay/AgentAwarenessRelay.ts
+23 -25
@@ -1,8 +1,3 @@
1 -import {
2 - RelayApi,
3 - type RelayAgentActivityPublishProofPayload,
4 - type RelayAgentActivityState,
5 -} from "@t3tools/contracts/relay";
1 import type {
2 EnvironmentId,
3 OrchestrationEvent,
@@ -10,13 +5,18 @@ import type {
5 OrchestrationThreadShell,
6 ThreadId,
7 } from "@t3tools/contracts";
8 +import {
9 + RelayApi,
10 + type RelayAgentActivityPublishProofPayload,
11 + type RelayAgentActivityState,
12 +} from "@t3tools/contracts/relay";
13 import { projectThreadAwareness } from "@t3tools/shared/agentAwareness";
14 import { makeDrainableWorker } from "@t3tools/shared/DrainableWorker";
15 import { withRelayClientTracing } from "@t3tools/shared/relayTracing";
16 import {
17 + normalizeRelayIssuer,
18 RELAY_ACTIVITY_PUBLISH_TYP,
19 signRelayJwt,
19 - normalizeRelayIssuer,
20 } from "@t3tools/shared/relayJwt";
21 import * as Cause from "effect/Cause";
22 import * as Context from "effect/Context";
@@ -28,31 +28,29 @@ import * as Option from "effect/Option";
28 import * as Ref from "effect/Ref";
29 import type * as Scope from "effect/Scope";
30 import * as Stream from "effect/Stream";
31 -import { FetchHttpClient } from "effect/unstable/http";
31 +import * as FetchHttpClient from "effect/unstable/http/FetchHttpClient";
32 import * as HttpClient from "effect/unstable/http/HttpClient";
33 import * as HttpClientRequest from "effect/unstable/http/HttpClientRequest";
34 import * as HttpApiClient from "effect/unstable/httpapi/HttpApiClient";
35
36 import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
37 -import { getOrCreateEnvironmentKeyPairFromSecretStore } from "../cloud/environmentKeys.ts";
37 import {
38 PUBLISH_AGENT_ACTIVITY_SECRET,
39 RELAY_ENVIRONMENT_CREDENTIAL_SECRET,
40 RELAY_ISSUER_SECRET,
41 RELAY_URL_SECRET,
42 } from "../cloud/config.ts";
44 -import { ServerEnvironment } from "../environment/Services/ServerEnvironment.ts";
45 -import { OrchestrationEngineService } from "../orchestration/Services/OrchestrationEngine.ts";
46 -import { ProjectionSnapshotQuery } from "../orchestration/Services/ProjectionSnapshotQuery.ts";
47 -
48 -export interface AgentAwarenessRelayShape {
49 - readonly publishThread: (threadId: ThreadId) => Effect.Effect<void>;
50 - readonly start: () => Effect.Effect<void, never, Scope.Scope>;
51 -}
43 +import { getOrCreateEnvironmentKeyPairFromSecretStore } from "../cloud/environmentKeys.ts";
44 +import * as ServerEnvironment from "../environment/Services/ServerEnvironment.ts";
45 +import * as OrchestrationEngine from "../orchestration/Services/OrchestrationEngine.ts";
46 +import * as ProjectionSnapshotQuery from "../orchestration/Services/ProjectionSnapshotQuery.ts";
47
48 export class AgentAwarenessRelay extends Context.Service<
49 AgentAwarenessRelay,
55 - AgentAwarenessRelayShape
50 + {
51 + readonly publishThread: (threadId: ThreadId) => Effect.Effect<void>;
52 + readonly start: () => Effect.Effect<void, never, Scope.Scope>;
53 + }
54 >()("t3/relay/AgentAwarenessRelay") {}
55
56 export function eventThreadId(event: OrchestrationEvent): ThreadId | null {
@@ -265,11 +263,11 @@ export function resolveAgentAwarenessRelayActiveThreadIds(input: {
263 .map((thread) => thread.id);
264 }
265
268 -const make = Effect.gen(function* () {
266 +export const make = Effect.gen(function* () {
267 const secrets = yield* ServerSecretStore.ServerSecretStore;
270 - const serverEnvironment = yield* ServerEnvironment;
271 - const snapshotQuery = yield* ProjectionSnapshotQuery;
272 - const orchestrationEngine = yield* OrchestrationEngineService;
268 + const serverEnvironment = yield* ServerEnvironment.ServerEnvironment;
269 + const snapshotQuery = yield* ProjectionSnapshotQuery.ProjectionSnapshotQuery;
270 + const orchestrationEngine = yield* OrchestrationEngine.OrchestrationEngineService;
271 const crypto = yield* Crypto.Crypto;
272 const cloudLinkKeyPair = yield* getOrCreateEnvironmentKeyPairFromSecretStore(secrets);
273 const activeSnapshotPublishedRef = yield* Ref.make(false);
@@ -417,7 +415,7 @@ const make = Effect.gen(function* () {
415 });
416 });
417
420 - const publishThread: AgentAwarenessRelayShape["publishThread"] = (threadId) =>
418 + const publishThread: AgentAwarenessRelay["Service"]["publishThread"] = (threadId) =>
419 publishThreadUnsafe(threadId).pipe(
420 Effect.catchCause((cause) => {
421 return Effect.logWarning("agent activity publish failed", {
@@ -480,7 +478,7 @@ const make = Effect.gen(function* () {
478
479 const worker = yield* makeDrainableWorker(publishThread);
480
483 - const start: AgentAwarenessRelayShape["start"] = Effect.fn("AgentAwarenessRelay.start")(
481 + const start: AgentAwarenessRelay["Service"]["start"] = Effect.fn("AgentAwarenessRelay.start")(
482 function* () {
483 const [relayConfig, publishEnabled] = yield* Effect.all([
484 readRelayConfig.pipe(Effect.orElseSucceed(() => null)),
@@ -536,10 +534,10 @@ const make = Effect.gen(function* () {
534 },
535 );
536
539 - return {
537 + return AgentAwarenessRelay.of({
538 publishThread,
539 start,
542 - } satisfies AgentAwarenessRelayShape;
540 + });
541 });
542
543 export const layer = Layer.effect(AgentAwarenessRelay, make);