Open History to see the last commit
1import * as Context from "effect/Context";
2import type * as DateTime from "effect/DateTime";
3import * as Schema from "effect/Schema";
4import * as HttpApi from "effect/http-api/HttpApi";
5import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
6import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
7import * as HttpApiMiddleware from "effect/http-api/HttpApiMiddleware";
8import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
9import * as HttpServerRespondable from "effect/http/HttpServerRespondable";
10import * as HttpServerResponse from "effect/http/HttpServerResponse";
11
12import {
13 AuthAccessTokenResult,
14 AuthBrowserSessionRequest,
15 AuthBrowserSessionResult,
16 AuthClientSession,
17 AuthCreatePairingCredentialInput,
18 AuthPairingCredentialResult,
19 AuthPairingLink,
20 AuthRevokeClientSessionInput,
21 AuthRevokePairingLinkInput,
22 AuthEnvironmentScope,
23 AuthTokenExchangeRequest,
24 AuthSessionState,
25 AuthWebSocketTicketResult,
26 ServerAuthSessionMethod,
27} from "./auth.ts";
28import {
29 ExecutionEnvironmentDescriptor,
30 ORCHESTRATION_PROTOCOL_HEADER,
31 ORCHESTRATION_PROTOCOL_VERSION_TEXT,
32} from "./environment.ts";
33import {
34 DpopFailureReason,
35 AuthSessionId,
36 ThreadId,
37 TrimmedNonEmptyString,
38} from "./baseSchemas.ts";
39import {
40 OrchestrationV2ShellSnapshot,
41 OrchestrationV2ThreadBoundedSnapshot,
42 OrchestrationV2ThreadDetailSnapshot,
43 OrchestrationV2ThreadHistoryPage,
44} from "./orchestrationV2.ts";
45import { Project, ProjectMutation, ProjectSnapshot } from "./project.ts";
46import {
47 PullRequestDiffInput,
48 PullRequestDiffResult,
49 PullRequestOperationError,
50 PullRequestUnavailableError,
51} from "./pullRequest.ts";
52import {
53 RelayCloudEnvironmentHealthRequest,
54 RelayCloudMintCredentialRequest,
55 RelayEnvironmentConfigRequest,
56 RelayEnvironmentHealthResponse,
57 RelayEnvironmentLinkProof,
58 RelayEnvironmentMintResponse,
59 RelayLinkProofRequest,
60} from "./relay.ts";
61
62const OptionalBearerHeaders = Schema.Struct({
63 authorization: Schema.optionalKey(Schema.String),
64 dpop: Schema.optionalKey(Schema.String),
65});
66
67const OrchestrationProtocolHeaders = Schema.Struct({
68 authorization: Schema.optionalKey(Schema.String),
69 dpop: Schema.optionalKey(Schema.String),
70 [ORCHESTRATION_PROTOCOL_HEADER]: Schema.Literal(ORCHESTRATION_PROTOCOL_VERSION_TEXT),
71});
72
73const OptionalDpopProofHeaders = Schema.Struct({
74 dpop: Schema.optionalKey(Schema.String),
75});
76
77export const EnvironmentRequestInvalidReason = Schema.Literals([
78 "invalid_scope",
79 "scope_not_granted",
80 "invalid_command",
81 "invalid_history_cursor",
82]);
83export type EnvironmentRequestInvalidReason = typeof EnvironmentRequestInvalidReason.Type;
84
85export const EnvironmentAuthInvalidReason = Schema.Literals([
86 "missing_credential",
87 "invalid_credential",
88]);
89export type EnvironmentAuthInvalidReason = typeof EnvironmentAuthInvalidReason.Type;
90
91export const EnvironmentOperationForbiddenReason = Schema.Literals([
92 "current_session_revoke_not_allowed",
93]);
94export type EnvironmentOperationForbiddenReason = typeof EnvironmentOperationForbiddenReason.Type;
95
96export const EnvironmentInternalErrorReason = Schema.Literals([
97 "bootstrap_validation_failed",
98 "browser_session_issuance_failed",
99 "browser_session_cookie_failed",
100 "access_token_issuance_failed",
101 "websocket_ticket_issuance_failed",
102 "pairing_credential_issuance_failed",
103 "pairing_links_load_failed",
104 "pairing_link_revoke_failed",
105 "client_sessions_load_failed",
106 "client_session_revoke_failed",
107 "project_snapshot_failed",
108 "project_mutation_failed",
109 "orchestration_snapshot_failed",
110 "orchestration_thread_snapshot_failed",
111 "orchestration_thread_bounded_snapshot_failed",
112 "orchestration_thread_history_failed",
113 "internal_error",
114]);
115export type EnvironmentInternalErrorReason = typeof EnvironmentInternalErrorReason.Type;
116
117export class EnvironmentRequestInvalidError extends Schema.TaggedError<EnvironmentRequestInvalidError>()(
118 "EnvironmentRequestInvalidError",
119 {
120 code: Schema.Literal("invalid_request"),
121 reason: EnvironmentRequestInvalidReason,
122 traceId: TrimmedNonEmptyString,
123 },
124 { httpApiStatus: 400 },
125) {
126 [HttpServerRespondable.symbol]() {
127 return HttpServerResponse.schemaJson(EnvironmentRequestInvalidError)(this, { status: 400 });
128 }
129
130 override get message(): string {
131 return `The environment rejected the request (${this.reason}).`;
132 }
133}
134
135export class EnvironmentAuthInvalidError extends Schema.TaggedError<EnvironmentAuthInvalidError>()(
136 "EnvironmentAuthInvalidError",
137 {
138 code: Schema.Literal("auth_invalid"),
139 reason: EnvironmentAuthInvalidReason,
140 // Older servers do not send a DPoP failure category.
141 dpopFailureReason: Schema.optionalKey(DpopFailureReason),
142 traceId: TrimmedNonEmptyString,
143 },
144 { httpApiStatus: 401 },
145) {
146 [HttpServerRespondable.symbol]() {
147 return HttpServerResponse.schemaJson(EnvironmentAuthInvalidError)(this, { status: 401 });
148 }
149
150 override get message(): string {
151 return `The environment rejected this client's credentials (${this.reason}).`;
152 }
153}
154
155export class EnvironmentScopeRequiredError extends Schema.TaggedError<EnvironmentScopeRequiredError>()(
156 "EnvironmentScopeRequiredError",
157 {
158 code: Schema.Literal("insufficient_scope"),
159 requiredScope: AuthEnvironmentScope,
160 traceId: TrimmedNonEmptyString,
161 },
162 { httpApiStatus: 403 },
163) {
164 [HttpServerRespondable.symbol]() {
165 return HttpServerResponse.schemaJson(EnvironmentScopeRequiredError)(this, { status: 403 });
166 }
167
168 override get message(): string {
169 return `This request needs the ${this.requiredScope} scope, which this client does not have.`;
170 }
171}
172
173export class EnvironmentOperationForbiddenError extends Schema.TaggedError<EnvironmentOperationForbiddenError>()(
174 "EnvironmentOperationForbiddenError",
175 {
176 code: Schema.Literal("operation_forbidden"),
177 reason: EnvironmentOperationForbiddenReason,
178 traceId: TrimmedNonEmptyString,
179 },
180 { httpApiStatus: 403 },
181) {
182 [HttpServerRespondable.symbol]() {
183 return HttpServerResponse.schemaJson(EnvironmentOperationForbiddenError)(this, { status: 403 });
184 }
185
186 override get message(): string {
187 return `The environment refused this operation (${this.reason}).`;
188 }
189}
190
191export class EnvironmentInternalError extends Schema.TaggedError<EnvironmentInternalError>()(
192 "EnvironmentInternalError",
193 {
194 code: Schema.Literal("internal_error"),
195 reason: EnvironmentInternalErrorReason,
196 traceId: TrimmedNonEmptyString,
197 },
198 { httpApiStatus: 500 },
199) {
200 [HttpServerRespondable.symbol]() {
201 return HttpServerResponse.schemaJson(EnvironmentInternalError)(this, { status: 500 });
202 }
203
204 override get message(): string {
205 return `The environment failed to answer this request (${this.reason}).`;
206 }
207}
208
209export const EnvironmentResourceNotFoundReason = Schema.Literals(["thread_not_found"]);
210export type EnvironmentResourceNotFoundReason = typeof EnvironmentResourceNotFoundReason.Type;
211
212export class EnvironmentResourceNotFoundError extends Schema.TaggedError<EnvironmentResourceNotFoundError>()(
213 "EnvironmentResourceNotFoundError",
214 {
215 code: Schema.Literal("not_found"),
216 reason: EnvironmentResourceNotFoundReason,
217 traceId: TrimmedNonEmptyString,
218 },
219 { httpApiStatus: 404 },
220) {
221 [HttpServerRespondable.symbol]() {
222 return HttpServerResponse.schemaJson(EnvironmentResourceNotFoundError)(this, { status: 404 });
223 }
224
225 override get message(): string {
226 return `The environment could not find what this request named (${this.reason}).`;
227 }
228}
229
230export const EnvironmentHttpCommonError = Schema.Union([
231 EnvironmentRequestInvalidError,
232 EnvironmentAuthInvalidError,
233 EnvironmentScopeRequiredError,
234 EnvironmentOperationForbiddenError,
235 EnvironmentResourceNotFoundError,
236 EnvironmentInternalError,
237]);
238export type EnvironmentHttpCommonError = typeof EnvironmentHttpCommonError.Type;
239
240const EnvironmentAuthenticationErrors = [
241 EnvironmentAuthInvalidError,
242 EnvironmentInternalError,
243] as const;
244
245export class EnvironmentHttpBadRequestError extends Schema.TaggedError<EnvironmentHttpBadRequestError>()(
246 "EnvironmentHttpBadRequestError",
247 {
248 message: Schema.String,
249 },
250 { httpApiStatus: 400 },
251) {
252 [HttpServerRespondable.symbol]() {
253 return HttpServerResponse.schemaJson(EnvironmentHttpBadRequestError)(this, { status: 400 });
254 }
255}
256
257export class EnvironmentHttpUnauthorizedError extends Schema.TaggedError<EnvironmentHttpUnauthorizedError>()(
258 "EnvironmentHttpUnauthorizedError",
259 {
260 message: Schema.String,
261 },
262 { httpApiStatus: 401 },
263) {
264 [HttpServerRespondable.symbol]() {
265 return HttpServerResponse.schemaJson(EnvironmentHttpUnauthorizedError)(this, { status: 401 });
266 }
267}
268
269export class EnvironmentHttpForbiddenError extends Schema.TaggedError<EnvironmentHttpForbiddenError>()(
270 "EnvironmentHttpForbiddenError",
271 {
272 message: Schema.String,
273 },
274 { httpApiStatus: 403 },
275) {
276 [HttpServerRespondable.symbol]() {
277 return HttpServerResponse.schemaJson(EnvironmentHttpForbiddenError)(this, { status: 403 });
278 }
279}
280
281export class EnvironmentHttpInternalServerError extends Schema.TaggedError<EnvironmentHttpInternalServerError>()(
282 "EnvironmentHttpInternalServerError",
283 {
284 message: Schema.String,
285 },
286 { httpApiStatus: 500 },
287) {
288 [HttpServerRespondable.symbol]() {
289 return HttpServerResponse.schemaJson(EnvironmentHttpInternalServerError)(this, { status: 500 });
290 }
291}
292
293export class EnvironmentHttpConflictError extends Schema.TaggedError<EnvironmentHttpConflictError>()(
294 "EnvironmentHttpConflictError",
295 {
296 message: Schema.String,
297 },
298 { httpApiStatus: 409 },
299) {
300 [HttpServerRespondable.symbol]() {
301 return HttpServerResponse.schemaJson(EnvironmentHttpConflictError)(this, { status: 409 });
302 }
303}
304
305export class EnvironmentCloudEndpointUnavailableError extends Schema.TaggedError<EnvironmentCloudEndpointUnavailableError>()(
306 "EnvironmentCloudEndpointUnavailableError",
307 {
308 message: Schema.String,
309 endpointRuntimeStatus: Schema.Unknown,
310 },
311 { httpApiStatus: 503 },
312) {
313 [HttpServerRespondable.symbol]() {
314 return HttpServerResponse.schemaJson(EnvironmentCloudEndpointUnavailableError)(this, {
315 status: 503,
316 });
317 }
318}
319const EnvironmentSessionCreationErrors = [
320 EnvironmentAuthInvalidError,
321 EnvironmentInternalError,
322] as const;
323const EnvironmentTokenExchangeErrors = [
324 EnvironmentRequestInvalidError,
325 EnvironmentAuthInvalidError,
326 EnvironmentInternalError,
327] as const;
328const EnvironmentScopedOperationErrors = [
329 EnvironmentScopeRequiredError,
330 EnvironmentInternalError,
331] as const;
332const EnvironmentPairingCredentialErrors = [
333 EnvironmentRequestInvalidError,
334 ...EnvironmentScopedOperationErrors,
335] as const;
336const EnvironmentSessionRevokeErrors = [
337 EnvironmentScopeRequiredError,
338 EnvironmentOperationForbiddenError,
339 EnvironmentInternalError,
340] as const;
341const EnvironmentProjectSnapshotErrors = [
342 EnvironmentScopeRequiredError,
343 EnvironmentInternalError,
344] as const;
345const EnvironmentOrchestrationSnapshotErrors = [
346 EnvironmentScopeRequiredError,
347 EnvironmentInternalError,
348] as const;
349const EnvironmentOrchestrationThreadSnapshotErrors = [
350 EnvironmentScopeRequiredError,
351 EnvironmentResourceNotFoundError,
352 EnvironmentInternalError,
353] as const;
354const EnvironmentProjectMutationErrors = [
355 EnvironmentRequestInvalidError,
356 EnvironmentScopeRequiredError,
357 EnvironmentInternalError,
358] as const;
359
360export interface EnvironmentSessionPrincipalShape {
361 readonly sessionId: AuthSessionId;
362 readonly subject: string;
363 readonly method: ServerAuthSessionMethod;
364 readonly scopes: ReadonlySet<AuthEnvironmentScope>;
365 readonly proofKeyThumbprint?: string;
366 readonly expiresAt?: DateTime.DateTime;
367}
368
369export class EnvironmentAuthenticatedPrincipal extends Context.Service<
370 EnvironmentAuthenticatedPrincipal,
371 EnvironmentSessionPrincipalShape
372>()("@t3tools/contracts/environmentHttp/EnvironmentAuthenticatedPrincipal") {}
373
374export class EnvironmentAuthenticatedAuth extends HttpApiMiddleware.Service<
375 EnvironmentAuthenticatedAuth,
376 { provides: EnvironmentAuthenticatedPrincipal }
377>()("EnvironmentAuthenticatedAuth", {
378 error: EnvironmentAuthenticationErrors,
379}) {}
380
381const EnvironmentHttpCloudErrors = [
382 EnvironmentHttpBadRequestError,
383 EnvironmentHttpUnauthorizedError,
384 EnvironmentHttpForbiddenError,
385 EnvironmentHttpConflictError,
386 EnvironmentHttpInternalServerError,
387 EnvironmentScopeRequiredError,
388] as const;
389
390export const EnvironmentCloudRelayConfigResult = Schema.Struct({
391 ok: Schema.Boolean,
392 endpointRuntimeStatus: Schema.Unknown,
393});
394export type EnvironmentCloudRelayConfigResult = typeof EnvironmentCloudRelayConfigResult.Type;
395
396export const EnvironmentCloudLinkStateResult = Schema.Struct({
397 linked: Schema.Boolean,
398 cloudUserId: Schema.NullOr(Schema.String),
399 relayUrl: Schema.NullOr(Schema.String),
400 relayIssuer: Schema.NullOr(Schema.String),
401 // A managed Cloudflare tunnel is provisioned for this link. False for a
402 // publish-only link (activity publishing without a relay-managed tunnel), so
403 // clients can present the two capabilities as independent settings.
404 // Optional so newer clients tolerate older environment servers.
405 managedTunnelActive: Schema.optional(Schema.Boolean),
406 publishAgentActivity: Schema.Boolean,
407 // Opt-in: T3 Connect holds webhook requests while this environment is
408 // offline. Optional so newer clients tolerate older environment servers.
409 holdWebhooksWhileOffline: Schema.optional(Schema.Boolean),
410});
411export type EnvironmentCloudLinkStateResult = typeof EnvironmentCloudLinkStateResult.Type;
412
413export const EnvironmentCloudPreferencesRequest = Schema.Struct({
414 publishAgentActivity: Schema.Boolean,
415 // Omit to leave the current value unchanged.
416 holdWebhooksWhileOffline: Schema.optional(Schema.Boolean),
417});
418export type EnvironmentCloudPreferencesRequest = typeof EnvironmentCloudPreferencesRequest.Type;
419
420export const AuthPairingLinkRevokeResult = Schema.Struct({
421 revoked: Schema.Boolean,
422});
423export type AuthPairingLinkRevokeResult = typeof AuthPairingLinkRevokeResult.Type;
424
425export const AuthClientSessionRevokeResult = Schema.Struct({
426 revoked: Schema.Boolean,
427});
428export type AuthClientSessionRevokeResult = typeof AuthClientSessionRevokeResult.Type;
429
430export const AuthOtherClientSessionsRevokeResult = Schema.Struct({
431 revokedCount: Schema.Number,
432});
433export type AuthOtherClientSessionsRevokeResult = typeof AuthOtherClientSessionsRevokeResult.Type;
434
435class EnvironmentMetadataHttpApi extends HttpApiGroup.make("metadata").add(
436 HttpApiEndpoint.get("descriptor", "/.well-known/t3/environment", {
437 success: ExecutionEnvironmentDescriptor,
438 }),
439) {}
440
441class EnvironmentAuthHttpApi extends HttpApiGroup.make("auth")
442 .add(
443 HttpApiEndpoint.get("session", "/api/auth/session", {
444 headers: OptionalBearerHeaders,
445 success: AuthSessionState,
446 error: [EnvironmentInternalError],
447 }),
448 )
449 .add(
450 HttpApiEndpoint.post("browserSession", "/api/auth/browser-session", {
451 payload: AuthBrowserSessionRequest,
452 success: AuthBrowserSessionResult,
453 error: EnvironmentSessionCreationErrors,
454 }),
455 )
456 .add(
457 HttpApiEndpoint.post("token", "/oauth/token", {
458 headers: OptionalDpopProofHeaders,
459 payload: AuthTokenExchangeRequest,
460 success: AuthAccessTokenResult,
461 error: EnvironmentTokenExchangeErrors,
462 }),
463 )
464 .add(
465 HttpApiEndpoint.post("webSocketTicket", "/api/auth/websocket-ticket", {
466 headers: OptionalBearerHeaders,
467 success: AuthWebSocketTicketResult,
468 error: [EnvironmentInternalError],
469 }).middleware(EnvironmentAuthenticatedAuth),
470 )
471 .add(
472 HttpApiEndpoint.post("pairingCredential", "/api/auth/pairing-token", {
473 headers: OptionalBearerHeaders,
474 payload: AuthCreatePairingCredentialInput,
475 success: AuthPairingCredentialResult,
476 error: EnvironmentPairingCredentialErrors,
477 }).middleware(EnvironmentAuthenticatedAuth),
478 )
479 .add(
480 HttpApiEndpoint.get("pairingLinks", "/api/auth/pairing-links", {
481 headers: OptionalBearerHeaders,
482 success: Schema.Array(AuthPairingLink),
483 error: EnvironmentScopedOperationErrors,
484 }).middleware(EnvironmentAuthenticatedAuth),
485 )
486 .add(
487 HttpApiEndpoint.post("revokePairingLink", "/api/auth/pairing-links/revoke", {
488 headers: OptionalBearerHeaders,
489 payload: AuthRevokePairingLinkInput,
490 success: AuthPairingLinkRevokeResult,
491 error: EnvironmentScopedOperationErrors,
492 }).middleware(EnvironmentAuthenticatedAuth),
493 )
494 .add(
495 HttpApiEndpoint.get("clients", "/api/auth/clients", {
496 headers: OptionalBearerHeaders,
497 success: Schema.Array(AuthClientSession),
498 error: EnvironmentScopedOperationErrors,
499 }).middleware(EnvironmentAuthenticatedAuth),
500 )
501 .add(
502 HttpApiEndpoint.post("revokeClient", "/api/auth/clients/revoke", {
503 headers: OptionalBearerHeaders,
504 payload: AuthRevokeClientSessionInput,
505 success: AuthClientSessionRevokeResult,
506 error: EnvironmentSessionRevokeErrors,
507 }).middleware(EnvironmentAuthenticatedAuth),
508 )
509 .add(
510 HttpApiEndpoint.post("revokeOtherClients", "/api/auth/clients/revoke-others", {
511 headers: OptionalBearerHeaders,
512 success: AuthOtherClientSessionsRevokeResult,
513 error: EnvironmentScopedOperationErrors,
514 }).middleware(EnvironmentAuthenticatedAuth),
515 ) {}
516
517const EnvironmentOrchestrationThreadSnapshotParams = Schema.Struct({
518 threadId: ThreadId,
519});
520
521const EnvironmentOrchestrationThreadHistoryQuery = Schema.Struct({
522 cursor: TrimmedNonEmptyString,
523});
524
525const EnvironmentOrchestrationThreadHistoryErrors = [
526 EnvironmentRequestInvalidError,
527 EnvironmentScopeRequiredError,
528 EnvironmentResourceNotFoundError,
529 EnvironmentInternalError,
530] as const;
531
532class EnvironmentOrchestrationHttpApi extends HttpApiGroup.make("orchestration")
533 .add(
534 HttpApiEndpoint.get("shellSnapshot", "/api/orchestration/shell", {
535 headers: OrchestrationProtocolHeaders,
536 success: OrchestrationV2ShellSnapshot,
537 error: EnvironmentOrchestrationSnapshotErrors,
538 }).middleware(EnvironmentAuthenticatedAuth),
539 )
540 .add(
541 HttpApiEndpoint.get("threadSnapshot", "/api/orchestration/threads/:threadId", {
542 headers: OrchestrationProtocolHeaders,
543 params: EnvironmentOrchestrationThreadSnapshotParams,
544 success: OrchestrationV2ThreadDetailSnapshot,
545 error: EnvironmentOrchestrationThreadSnapshotErrors,
546 }).middleware(EnvironmentAuthenticatedAuth),
547 )
548 .add(
549 HttpApiEndpoint.get("threadBoundedSnapshot", "/api/orchestration/threads/:threadId/bounded", {
550 headers: OrchestrationProtocolHeaders,
551 params: EnvironmentOrchestrationThreadSnapshotParams,
552 success: OrchestrationV2ThreadBoundedSnapshot,
553 error: EnvironmentOrchestrationThreadSnapshotErrors,
554 }).middleware(EnvironmentAuthenticatedAuth),
555 )
556 .add(
557 HttpApiEndpoint.get("threadHistoryPage", "/api/orchestration/threads/:threadId/history", {
558 headers: OrchestrationProtocolHeaders,
559 params: EnvironmentOrchestrationThreadSnapshotParams,
560 query: EnvironmentOrchestrationThreadHistoryQuery,
561 success: OrchestrationV2ThreadHistoryPage,
562 error: EnvironmentOrchestrationThreadHistoryErrors,
563 }).middleware(EnvironmentAuthenticatedAuth),
564 ) {}
565
566class EnvironmentProjectsHttpApi extends HttpApiGroup.make("projects")
567 .add(
568 HttpApiEndpoint.get("snapshot", "/api/projects", {
569 headers: OptionalBearerHeaders,
570 success: ProjectSnapshot,
571 error: EnvironmentProjectSnapshotErrors,
572 }).middleware(EnvironmentAuthenticatedAuth),
573 )
574 .add(
575 HttpApiEndpoint.post("mutate", "/api/projects/mutate", {
576 headers: OptionalBearerHeaders,
577 payload: ProjectMutation,
578 success: Project,
579 error: EnvironmentProjectMutationErrors,
580 }).middleware(EnvironmentAuthenticatedAuth),
581 ) {}
582
583/** Large, compressible pull-request payloads travel over HTTP rather than the RPC socket. */
584class EnvironmentPullRequestsHttpApi extends HttpApiGroup.make("pullRequests").add(
585 HttpApiEndpoint.post("diff", "/api/pull-requests/diff", {
586 headers: OptionalBearerHeaders,
587 payload: PullRequestDiffInput,
588 success: PullRequestDiffResult,
589 error: [
590 PullRequestUnavailableError,
591 PullRequestOperationError,
592 EnvironmentAuthInvalidError,
593 EnvironmentScopeRequiredError,
594 EnvironmentInternalError,
595 ],
596 }).middleware(EnvironmentAuthenticatedAuth),
597) {}
598
599class EnvironmentConnectHttpApi extends HttpApiGroup.make("connect")
600 .add(
601 HttpApiEndpoint.post("linkProof", "/api/connect/link-proof", {
602 headers: OptionalBearerHeaders,
603 payload: RelayLinkProofRequest,
604 success: RelayEnvironmentLinkProof,
605 error: EnvironmentHttpCloudErrors,
606 }).middleware(EnvironmentAuthenticatedAuth),
607 )
608 .add(
609 HttpApiEndpoint.post("relayConfig", "/api/connect/relay-config", {
610 headers: OptionalBearerHeaders,
611 payload: RelayEnvironmentConfigRequest,
612 success: EnvironmentCloudRelayConfigResult,
613 error: [...EnvironmentHttpCloudErrors, EnvironmentCloudEndpointUnavailableError],
614 }).middleware(EnvironmentAuthenticatedAuth),
615 )
616 .add(
617 HttpApiEndpoint.get("linkState", "/api/connect/link-state", {
618 headers: OptionalBearerHeaders,
619 success: EnvironmentCloudLinkStateResult,
620 error: EnvironmentHttpCloudErrors,
621 }).middleware(EnvironmentAuthenticatedAuth),
622 )
623 .add(
624 HttpApiEndpoint.post("unlink", "/api/connect/unlink", {
625 headers: OptionalBearerHeaders,
626 success: EnvironmentCloudRelayConfigResult,
627 error: EnvironmentHttpCloudErrors,
628 }).middleware(EnvironmentAuthenticatedAuth),
629 )
630 .add(
631 HttpApiEndpoint.post("preferences", "/api/connect/preferences", {
632 headers: OptionalBearerHeaders,
633 payload: EnvironmentCloudPreferencesRequest,
634 success: EnvironmentCloudLinkStateResult,
635 error: EnvironmentHttpCloudErrors,
636 }).middleware(EnvironmentAuthenticatedAuth),
637 )
638 .add(
639 HttpApiEndpoint.post("health", "/api/t3-connect/health", {
640 payload: RelayCloudEnvironmentHealthRequest,
641 success: RelayEnvironmentHealthResponse,
642 error: EnvironmentHttpCloudErrors,
643 }),
644 )
645 .add(
646 HttpApiEndpoint.post("mintCredential", "/api/connect/mint-credential", {
647 payload: RelayCloudMintCredentialRequest,
648 success: RelayEnvironmentMintResponse,
649 error: EnvironmentHttpCloudErrors,
650 }),
651 )
652 .add(
653 HttpApiEndpoint.post("t3MintCredential", "/api/t3-connect/mint-credential", {
654 payload: RelayCloudMintCredentialRequest,
655 success: RelayEnvironmentMintResponse,
656 error: EnvironmentHttpCloudErrors,
657 }),
658 ) {}
659
660/**
661 * Public entry point for webhook tasks. Unauthenticated by design: the token
662 * in the path, and an optional body signature, are the credential. The handler
663 * reads the raw body itself so a signature is checked over the exact bytes.
664 */
665const WebhookParams = Schema.Struct({
666 hookId: TrimmedNonEmptyString,
667 token: TrimmedNonEmptyString,
668});
669const WebhookAccepted = Schema.Struct({ deliveryId: TrimmedNonEmptyString }).pipe(
670 HttpApiSchema.status(202),
671);
672const webhookEndpoint = {
673 params: WebhookParams,
674 success: WebhookAccepted,
675} as const;
676const WEBHOOK_PATH = "/api/hooks/:hookId/:token";
677
678class EnvironmentWebhooksHttpApi extends HttpApiGroup.make("webhooks")
679 .add(HttpApiEndpoint.post("webhookPost", WEBHOOK_PATH, webhookEndpoint))
680 .add(HttpApiEndpoint.put("webhookPut", WEBHOOK_PATH, webhookEndpoint))
681 .add(HttpApiEndpoint.patch("webhookPatch", WEBHOOK_PATH, webhookEndpoint))
682 .add(HttpApiEndpoint.get("webhookGet", WEBHOOK_PATH, webhookEndpoint)) {}
683
684export class EnvironmentHttpApi extends HttpApi.make("environment")
685 .add(EnvironmentMetadataHttpApi)
686 .add(EnvironmentAuthHttpApi)
687 .add(EnvironmentOrchestrationHttpApi)
688 .add(EnvironmentPullRequestsHttpApi)
689 .add(EnvironmentProjectsHttpApi)
690 .add(EnvironmentConnectHttpApi)
691 .add(EnvironmentWebhooksHttpApi) {}