Open History to see the last commit
1import { RelayManagedEndpointRuntimeConfig } from "@t3tools/contracts/relay";
2import * as Effect from "effect/Effect";
3import * as Option from "effect/Option";
4import * as Schema from "effect/Schema";
5
6import type * as ServerSecretStore from "../auth/ServerSecretStore.ts";
7
8export const CLOUD_MINT_PUBLIC_KEY = "cloud-mint-ed25519-public-key";
9export const CLOUD_ENDPOINT_RUNTIME_CONFIG = "cloud-endpoint-runtime-config";
10export const CLOUD_LINKED_USER_ID = "cloud-linked-user-id";
11export const RELAY_URL_SECRET = "cloud-relay-url";
12export const RELAY_ISSUER_SECRET = "cloud-relay-issuer";
13export const RELAY_ENVIRONMENT_CREDENTIAL_SECRET = "cloud-relay-environment-credential";
14export const PUBLISH_AGENT_ACTIVITY_SECRET = "cloud-publish-agent-activity";
15
16export const encodeEndpointRuntimeConfigJson = Schema.encodeEffect(
17 Schema.fromJsonString(RelayManagedEndpointRuntimeConfig),
18);
19
20export const decodeRuntimeConfig = Schema.decodeUnknownOption(
21 Schema.fromJsonString(RelayManagedEndpointRuntimeConfig),
22);
23
24export function isAgentActivityPublishingEnabledValue(value: string | null): boolean {
25 return value === "true";
26}
27
28/** Whether agent-activity publishes currently leave this environment: the
29 publish opt-in secret is enabled and the relay link credentials exist.
30 Mirrors the per-publish gate in AgentAwarenessRelay, so the descriptor
31 capability never advertises publishing that the publisher would skip. */
32export const readAgentActivityPublishingActive = (
33 secrets: ServerSecretStore.ServerSecretStore["Service"],
34): Effect.Effect<boolean> =>
35 Effect.gen(function* () {
36 const readSecretString = (name: string) =>
37 secrets
38 .get(name)
39 .pipe(
40 Effect.map((bytes) =>
41 Option.isSome(bytes) ? new TextDecoder().decode(bytes.value) : null,
42 ),
43 );
44 const [enabled, url, environmentCredential] = yield* Effect.all([
45 readSecretString(PUBLISH_AGENT_ACTIVITY_SECRET),
46 readSecretString(RELAY_URL_SECRET),
47 readSecretString(RELAY_ENVIRONMENT_CREDENTIAL_SECRET),
48 ]);
49 // Empty strings are as unconfigured as missing files: the publisher's
50 // truthiness gate skips them, so the capability must too.
51 return (
52 isAgentActivityPublishingEnabledValue(enabled) &&
53 url !== null &&
54 url !== "" &&
55 environmentCredential !== null &&
56 environmentCredential !== ""
57 );
58 }).pipe(Effect.orElseSucceed(() => false));