Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import { AuthMcpClientAccess } from "./auth.ts";
4import { EnvironmentId, TrimmedNonEmptyString } from "./baseSchemas.ts";
5
6/**
7 * A link from this environment to another one (the peer). This environment
8 * signed in to the peer's `/mcp` as an outside agent, with a pairing code from
9 * the peer, so its agents can work there. The peer enforces the access chosen
10 * at linking, and revokes the link from its own Connections.
11 */
12export const PeerLink = Schema.Struct({
13 environmentId: EnvironmentId,
14 label: Schema.String,
15 /** Addresses the peer was linked at, tried in order. */
16 urls: Schema.Array(TrimmedNonEmptyString),
17 access: AuthMcpClientAccess,
18 linkedAt: Schema.DateTimeUtc,
19 expiresAt: Schema.DateTimeUtc,
20 lastReachedAt: Schema.NullOr(Schema.DateTimeUtc),
21 lastError: Schema.NullOr(Schema.String),
22});
23export type PeerLink = typeof PeerLink.Type;
24
25/** Whether a link can be used now, as worked out when it is listed. */
26export const PeerLinkStatus = Schema.Literals(["reachable", "unreachable", "expired"]);
27export type PeerLinkStatus = typeof PeerLinkStatus.Type;
28
29export const PeerLinkSummary = Schema.Struct({
30 ...PeerLink.fields,
31 status: PeerLinkStatus,
32});
33export type PeerLinkSummary = typeof PeerLinkSummary.Type;
34
35export const PeerLinkCreateInput = Schema.Struct({
36 /** Where the peer answers: an https, Tailscale, LAN or loopback base URL. */
37 url: TrimmedNonEmptyString,
38 /** More addresses for the same peer, tried after `url`. */
39 alternateUrls: Schema.optionalKey(Schema.Array(TrimmedNonEmptyString)),
40 /** A pairing code from the peer (`t3 pair` there, or its Connections settings). */
41 pairingCode: TrimmedNonEmptyString,
42 access: AuthMcpClientAccess,
43});
44export type PeerLinkCreateInput = typeof PeerLinkCreateInput.Type;
45
46export const PeerLinkRemoveInput = Schema.Struct({ environmentId: EnvironmentId });
47export type PeerLinkRemoveInput = typeof PeerLinkRemoveInput.Type;
48
49export const PeerLinkRemoveResult = Schema.Struct({ removed: Schema.Boolean });
50export type PeerLinkRemoveResult = typeof PeerLinkRemoveResult.Type;
51
52/** Why linking or calling a peer failed, in words a user can act on. */
53export class PeerLinkError extends Schema.TaggedError<PeerLinkError>()("PeerLinkError", {
54 reason: Schema.Literals([
55 "unreachable",
56 "not_a_t3_environment",
57 "incompatible",
58 "self",
59 "pairing_rejected",
60 "expired",
61 "unknown_link",
62 "storage",
63 ]),
64 message: Schema.String,
65 cause: Schema.optionalKey(Schema.Defect()),
66}) {}