Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

server.ts

741 lines25.4 KB

1import {
2 type EnvironmentId,
3 type ServerConfig,
4 type ServerConfigStreamEvent,
5 type ServerLifecycleWelcomePayload,
6 type ServerLifecycleStreamReadyEvent,
7 type ServerSelfUpdateProgressEvent,
8 type ServerSelfUpdateResult,
9 WS_METHODS,
10} from "@t3tools/contracts";
11import * as Cause from "effect/Cause";
12import * as Duration from "effect/Duration";
13import * as Effect from "effect/Effect";
14import * as Exit from "effect/Exit";
15import * as Option from "effect/Option";
16import * as Queue from "effect/Queue";
17import * as Ref from "effect/Ref";
18import * as Result from "effect/Result";
19import * as Schema from "effect/Schema";
20import * as Stream from "effect/Stream";
21import * as SubscriptionRef from "effect/SubscriptionRef";
22import { AsyncResult, Atom } from "effect/unstable/reactivity";
23​
24import {
25 createAtomCommandScheduler,
26 createEnvironmentRpcCommand,
27 createEnvironmentRpcQueryAtomFamily,
28 createEnvironmentRpcSubscriptionAtomFamily,
29 createRuntimeCommand,
30 scheduleAtomCommandEffect,
31} from "./runtime.ts";
32import { EnvironmentRegistry } from "../connection/registry.ts";
33import { EnvironmentSupervisor } from "../connection/supervisor.ts";
34import { safeErrorLogAttributes } from "../errors/safeLog.ts";
35import { EnvironmentCacheStore } from "../platform/persistence.ts";
36import {
37 isRpcClientError,
38 request,
39 runStream,
40 subscribe,
41 type EnvironmentRpcInput,
42} from "../rpc/client.ts";
43import { followStreamInEnvironment } from "./runtime.ts";
44​
45export type ServerUpdateStage = "downloading" | "installing" | "resuming";
46​
47export type ServerUpdateState =
48 | { readonly status: "idle" }
49 | {
50 readonly status: "running";
51 readonly stage: ServerUpdateStage;
52 readonly fromVersion: string;
53 readonly targetVersion: string;
54 }
55 | {
56 readonly status: "failed";
57 readonly stage: ServerUpdateStage;
58 readonly fromVersion: string;
59 readonly targetVersion: string;
60 readonly message: string;
61 };
62​
63export interface ServerUpdateTarget {
64 readonly environmentId: EnvironmentId;
65 readonly input: EnvironmentRpcInput<typeof WS_METHODS.serverUpdateServer>;
67​
68const IDLE_SERVER_UPDATE_STATE: ServerUpdateState = { status: "idle" };
69const EMPTY_SERVER_UPDATE_STATE_ATOM = Atom.make<ServerUpdateState>(IDLE_SERVER_UPDATE_STATE).pipe(
70 Atom.withLabel("environment-data:server:update-state:empty"),
71);
72const serverUpdateStateAtom = Atom.family((environmentId: EnvironmentId) =>
73 Atom.make<ServerUpdateState>(IDLE_SERVER_UPDATE_STATE).pipe(
74 Atom.withLabel(`environment-data:server:update-state:${environmentId}`),
75 ),
76);
77​
78export class ServerUpdateResumeTimeoutError extends Schema.TaggedErrorClass<ServerUpdateResumeTimeoutError>()(
79 "ServerUpdateResumeTimeoutError",
80 {
81 environmentId: Schema.String,
82 targetVersion: Schema.String,
83 },
84) {
85 override get message(): string {
86 return `The server did not resume on t3@${this.targetVersion}.`;
87 }
89​
90export class ServerUpdateProgressIncompleteError extends Schema.TaggedErrorClass<ServerUpdateProgressIncompleteError>()(
91 "ServerUpdateProgressIncompleteError",
92 {
93 targetVersion: Schema.String,
94 },
95) {
96 override get message(): string {
97 return `The t3@${this.targetVersion} update ended before the server accepted the restart.`;
98 }
100​
101export class ServerUpdateTerminalError extends Schema.TaggedErrorClass<ServerUpdateTerminalError>()(
102 "ServerUpdateTerminalError",
103 {
104 targetVersion: Schema.String,
105 status: Schema.Literals(["committed", "rolled-back", "failed"]),
106 reason: Schema.optional(Schema.String),
107 },
108) {
109 override get message(): string {
110 return this.reason ?? `The t3@${this.targetVersion} update ${this.status}.`;
111 }
113​
114// Covers the 120-second trial deadline and a final restart of the previous
115// version when the trial rolls back.
116const SERVER_UPDATE_RESUME_TIMEOUT = Duration.minutes(4);
117​
118export function matchesServerUpdateReadyEvent(
119 result: ServerSelfUpdateResult,
120 event: ServerLifecycleStreamReadyEvent,
121): boolean {
122 return result.updateId === undefined
123 ? event.payload.environment.serverVersion === result.targetVersion
124 : event.payload.updateOutcome?.id === result.updateId;
126​
127export function validateServerUpdateReadyEvent(
128 result: ServerSelfUpdateResult,
129 event: ServerLifecycleStreamReadyEvent,
130): Effect.Effect<void, ServerUpdateTerminalError> {
131 if (result.updateId === undefined) return Effect.void;
132 const outcome = event.payload.updateOutcome;
133 if (
134 outcome?.id === result.updateId &&
135 outcome.status === "committed" &&
136 outcome.targetVersion === result.targetVersion &&
137 event.payload.environment.serverVersion === result.targetVersion
138 ) {
139 return Effect.void;
140 }
141 return Effect.fail(
142 new ServerUpdateTerminalError({
143 targetVersion: result.targetVersion,
144 status: outcome?.status ?? "failed",
145 reason:
146 outcome?.reason ??
147 "The service launcher resumed without committing the requested server version.",
148 }),
149 );
151​
152export function serverUpdateStateForProgressEvent(
153 fromVersion: string,
154 targetVersion: string,
155 event: ServerSelfUpdateProgressEvent,
156): Extract<ServerUpdateState, { status: "running" }> {
157 return {
158 status: "running",
159 stage: event.type === "complete" ? "resuming" : event.stage,
160 fromVersion,
161 targetVersion,
162 };
164​
165export function serverUpdateStateForServerVersion(
166 state: ServerUpdateState,
167 serverVersion: string | null,
168): ServerUpdateState {
169 return state.status === "idle" ||
170 state.status === "running" ||
171 serverVersion === null ||
172 state.fromVersion === serverVersion
173 ? state
174 : IDLE_SERVER_UPDATE_STATE;
176​
177function serverUpdateFailureMessage(error: unknown): string {
178 return error instanceof Error ? error.message : "Server update failed.";
180​
181function isRpcSocketError(error: unknown): boolean {
182 if (!isRpcClientError(error)) {
183 return false;
184 }
185 switch (error.reason._tag) {
186 case "SocketReadError":
187 case "SocketWriteError":
188 case "SocketCloseError":
189 return true;
190 default:
191 return false;
192 }
194​
195export function isLegacyUpdateHandoffLoss(cause: Cause.Cause<unknown>): boolean {
196 if (Cause.hasInterruptsOnly(cause)) {
197 return true;
198 }
199 return (
200 cause.reasons.length > 0 &&
201 cause.reasons.every((reason) => Cause.isFailReason(reason) && isRpcSocketError(reason.error))
202 );
204​
205export function resolveServerUpdateProgressResult<E>(
206 targetVersion: string,
207 terminal: Option.Option<ServerSelfUpdateResult>,
208 streamExit: Exit.Exit<void, E>,
209): Effect.Effect<ServerSelfUpdateResult, E | ServerUpdateProgressIncompleteError> {
210 if (
211 Option.isSome(terminal) &&
212 (Exit.isSuccess(streamExit) || isLegacyUpdateHandoffLoss(streamExit.cause))
213 ) {
214 return Effect.succeed(terminal.value);
215 }
216 if (Exit.isFailure(streamExit)) {
217 return Effect.failCause(streamExit.cause);
218 }
219 return Effect.fail(new ServerUpdateProgressIncompleteError({ targetVersion }));
221​
222export interface ServerConfigProjection {
223 readonly config: ServerConfig;
224 readonly latestEvent: ServerConfigStreamEvent;
225 readonly source: "cache" | "live";
227​
228export function applyServerConfigProjection(
229 current: Option.Option<ServerConfigProjection>,
230 event: ServerConfigStreamEvent,
231): Option.Option<ServerConfigProjection> {
232 switch (event.type) {
233 case "snapshot":
234 return Option.some({
235 config: event.config,
236 latestEvent: event,
237 source: "live",
238 });
239 case "keybindingsUpdated":
240 return Option.map(current, (projection) => ({
241 config: {
242 ...projection.config,
243 keybindings: event.payload.keybindings,
244 issues: event.payload.issues,
245 },
246 latestEvent: event,
247 source: "live",
248 }));
249 case "providerStatuses":
250 return Option.map(current, (projection) => ({
251 config: {
252 ...projection.config,
253 providers: event.payload.providers,
254 },
255 latestEvent: event,
256 source: "live",
257 }));
258 case "settingsUpdated":
259 return Option.map(current, (projection) => ({
260 config: {
261 ...projection.config,
262 settings: event.payload.settings,
263 },
264 latestEvent: event,
265 source: "live",
266 }));
267 }
269​
270export function projectServerConfig(
271 current: Option.Option<ServerConfigProjection>,
272 event: ServerConfigStreamEvent,
273): readonly [Option.Option<ServerConfigProjection>, ReadonlyArray<ServerConfigProjection>] {
274 const next = applyServerConfigProjection(current, event);
275 return [next, Option.toArray(next)];
277​
278const cachedConfigSnapshotEvent = (config: ServerConfig): ServerConfigStreamEvent => ({
279 version: 1,
280 type: "snapshot",
281 config,
282});
283​
284/**
285 * Keeps a complete server configuration available during reconnects. Server
286 * config carries the provider/model catalogue used by task creation, so it is
287 * useful—and safe—to retain after a transport session ends.
288 */
289export const makeEnvironmentServerConfigState = Effect.fn("EnvironmentServerConfigState.make")(
290 function* () {
291 const supervisor = yield* EnvironmentSupervisor;
292 const cache = yield* EnvironmentCacheStore;
293 const environmentId = supervisor.target.environmentId;
294 const cachedConfig = yield* cache.loadServerConfig(environmentId).pipe(
295 Effect.catch((error) =>
296 Effect.logWarning("Could not load cached server configuration.").pipe(
297 Effect.annotateLogs({
298 environmentId,
299 ...safeErrorLogAttributes(error),
300 }),
301 Effect.as(Option.none<ServerConfig>()),
302 ),
303 ),
304 );
305 const state = yield* SubscriptionRef.make<Option.Option<ServerConfigProjection>>(
306 Option.map(cachedConfig, (config) => ({
307 config,
308 latestEvent: cachedConfigSnapshotEvent(config),
309 source: "cache" as const,
310 })),
311 );
312 const persistence = yield* Queue.sliding<ServerConfig>(1);
313 const pendingPersistence = yield* Ref.make<Option.Option<ServerConfig>>(Option.none());
314​
315 const persist = Effect.fn("EnvironmentServerConfigState.persist")(function* (
316 config: ServerConfig,
317 ) {
318 return yield* cache.saveServerConfig(environmentId, config).pipe(
319 Effect.as(true),
320 Effect.catch((error) =>
321 Effect.logWarning("Could not persist cached server configuration.").pipe(
322 Effect.annotateLogs({
323 environmentId,
324 ...safeErrorLogAttributes(error),
325 }),
326 Effect.as(false),
327 ),
328 ),
329 );
330 });
331​
332 const persistPending = Effect.fn("EnvironmentServerConfigState.persistPending")(function* (
333 config: ServerConfig,
334 ) {
335 if (!(yield* persist(config))) {
336 return;
337 }
338 yield* Ref.update(pendingPersistence, (pending) =>
339 Option.isSome(pending) && pending.value === config ? Option.none() : pending,
340 );
341 });
342​
343 yield* Stream.fromQueue(persistence).pipe(
344 Stream.debounce("500 millis"),
345 Stream.runForEach(persistPending),
346 Effect.forkScoped,
347 );
348​
349 yield* subscribe(WS_METHODS.subscribeServerConfig, {}).pipe(
350 Stream.runForEach((event) =>
351 Effect.gen(function* () {
352 const next = applyServerConfigProjection(yield* SubscriptionRef.get(state), event);
353 if (Option.isNone(next)) {
354 return;
355 }
356 yield* Ref.set(pendingPersistence, Option.some(next.value.config));
357 yield* SubscriptionRef.set(state, next);
358 yield* Queue.offer(persistence, next.value.config);
359 }),
360 ),
361 Effect.forkScoped,
362 );
363​
364 yield* Effect.addFinalizer(() =>
365 Ref.get(pendingPersistence).pipe(
366 Effect.flatMap(
367 Option.match({
368 onNone: () => Effect.void,
369 onSome: (config) => persist(config).pipe(Effect.asVoid),
370 }),
371 ),
372 ),
373 );
374​
375 return state;
376 },
377);
378​
379export function serverConfigStateChanges(environmentId: EnvironmentId) {
380 return followStreamInEnvironment(
381 environmentId,
382 Stream.unwrap(
383 makeEnvironmentServerConfigState().pipe(
384 Effect.map((state) =>
385 SubscriptionRef.changes(state).pipe(
386 Stream.filterMap((projection) =>
387 Option.match(projection, {
388 onNone: () => Result.failVoid,
389 onSome: (value) => Result.succeed(value),
390 }),
391 ),
392 ),
393 ),
394 ),
395 ),
396 );
398​
399export function projectServerWelcome(
400 current: Option.Option<ServerLifecycleWelcomePayload>,
401 event: {
402 readonly type: "welcome" | "ready";
403 readonly payload: unknown;
404 },
405): readonly [
406 Option.Option<ServerLifecycleWelcomePayload>,
407 ReadonlyArray<ServerLifecycleWelcomePayload>,
408] {
409 if (event.type !== "welcome") {
410 return [current, []];
411 }
412 const welcome = event.payload as ServerLifecycleWelcomePayload;
413 return [Option.some(welcome), [welcome]];
415​
416export function resolveServerConfigValue(
417 projection: ServerConfigProjection | null,
418 initialConfig: ServerConfig | null,
419): ServerConfig | null {
420 if (
421 projection?.source === "live" &&
422 (initialConfig === null ||
423 projection.config.environment.serverVersion === initialConfig.environment.serverVersion)
424 ) {
425 return projection.config;
426 }
427 return initialConfig ?? projection?.config ?? null;
429​
430export function createServerEnvironmentAtoms<R, E>(
431 runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>,
432 options: {
433 readonly initialConfigValueAtom: (
434 environmentId: EnvironmentId,
435 ) => Atom.Atom<ServerConfig | null>;
436 },
437) {
438 const configScheduler = createAtomCommandScheduler();
439 // Updates stay serial end-to-end, but only their handoff phase occupies the config lane.
440 const updateScheduler = createAtomCommandScheduler();
441 const configConcurrency = {
442 mode: "serial" as const,
443 key: ({ environmentId }: { readonly environmentId: string }) => environmentId,
444 };
445 const configProjectionFamily = Atom.family((environmentId: EnvironmentId) =>
446 runtime
447 .atom(serverConfigStateChanges(environmentId))
448 .pipe(
449 Atom.setIdleTTL(5 * 60_000),
450 Atom.withLabel(`environment-data:server:config-projection:${environmentId}`),
451 ),
452 );
453 const configProjection = (target: {
454 readonly environmentId: EnvironmentId;
455 readonly input: EnvironmentRpcInput<typeof WS_METHODS.subscribeServerConfig>;
456 }) => configProjectionFamily(target.environmentId);
457 const emptyConfigAtom = Atom.make<ServerConfig | null>(null).pipe(
458 Atom.withLabel("environment-data:server:config:empty"),
459 );
460 const configValueAtom = Atom.family((environmentId: EnvironmentId | null) => {
461 if (environmentId === null) {
462 return emptyConfigAtom;
463 }
464 return Atom.make((get): ServerConfig | null => {
465 const projection = Option.getOrNull(
466 AsyncResult.value(get(configProjection({ environmentId, input: {} }))),
467 );
468 return resolveServerConfigValue(
469 projection,
470 get(options.initialConfigValueAtom(environmentId)),
471 );
472 }).pipe(Atom.withLabel(`environment-data:server:config:${environmentId}`));
473 });
474 const updateStateValueAtom = Atom.family((environmentId: EnvironmentId) =>
475 Atom.make((get) =>
476 serverUpdateStateForServerVersion(
477 get(serverUpdateStateAtom(environmentId)),
478 get(configValueAtom(environmentId))?.environment.serverVersion ?? null,
479 ),
480 ).pipe(Atom.withLabel(`environment-data:server:update-state-value:${environmentId}`)),
481 );
482 const updateStateAtom = (environmentId: EnvironmentId | null) =>
483 environmentId === null ? EMPTY_SERVER_UPDATE_STATE_ATOM : updateStateValueAtom(environmentId);
484 const updateServer = createRuntimeCommand<
485 EnvironmentRegistry | EnvironmentCacheStore | R,
486 E,
487 ServerUpdateTarget,
488 ServerSelfUpdateResult,
489 unknown
490 >(runtime, {
491 label: "environment-data:server:update-server",
492 scheduler: updateScheduler,
493 concurrency: configConcurrency,
494 execute: (target, atomRegistry) => {
495 const stateAtom = serverUpdateStateAtom(target.environmentId);
496 const targetVersion = target.input.targetVersion;
497 let fromVersion =
498 atomRegistry.get(configValueAtom(target.environmentId))?.environment.serverVersion ??
499 targetVersion;
500 let currentStage: ServerUpdateStage = "downloading";
501 atomRegistry.set(stateAtom, {
502 status: "running",
503 stage: currentStage,
504 fromVersion,
505 targetVersion,
506 });
507​
508 return Effect.gen(function* () {
509 const environmentRegistry = yield* EnvironmentRegistry;
510 const result = yield* scheduleAtomCommandEffect(
511 atomRegistry,
512 configScheduler,
513 configConcurrency,
514 target,
515 Effect.gen(function* () {
516 const currentConfig = atomRegistry.get(configValueAtom(target.environmentId));
517 fromVersion = currentConfig?.environment.serverVersion ?? targetVersion;
518 atomRegistry.set(stateAtom, {
519 status: "running",
520 stage: currentStage,
521 fromVersion,
522 targetVersion,
523 });
524​
525 const supportsProgress =
526 currentConfig?.environment.capabilities.serverSelfUpdateProgress === true;
527 const updateResult: ServerSelfUpdateResult = supportsProgress
528 ? yield* Effect.gen(function* () {
529 const terminal = yield* Ref.make<Option.Option<ServerSelfUpdateResult>>(
530 Option.none(),
531 );
532 const streamExit = yield* environmentRegistry
533 .runStream(
534 target.environmentId,
535 runStream(WS_METHODS.serverUpdateServerWithProgress, target.input),
536 )
537 .pipe(
538 Stream.runForEach((event) =>
539 Effect.sync(() => {
540 currentStage = event.type === "complete" ? "resuming" : event.stage;
541 atomRegistry.set(
542 stateAtom,
543 serverUpdateStateForProgressEvent(fromVersion, targetVersion, event),
544 );
545 }).pipe(
546 Effect.andThen(
547 event.type === "complete"
548 ? Ref.set(terminal, Option.some(event.result))
549 : Effect.void,
550 ),
551 ),
552 ),
553 Effect.exit,
554 );
555 return yield* resolveServerUpdateProgressResult(
556 targetVersion,
557 yield* Ref.get(terminal),
558 streamExit,
559 );
560 })
561 : yield* Effect.gen(function* () {
562 const selfUpdateMethod = currentConfig?.environment.capabilities.serverSelfUpdate;
563 const exit = yield* environmentRegistry
564 .run(target.environmentId, request(WS_METHODS.serverUpdateServer, target.input))
565 .pipe(Effect.exit);
566 if (Exit.isSuccess(exit)) {
567 return exit.value;
568 }
569 if (
570 (selfUpdateMethod === "boot-service" || selfUpdateMethod === "respawn") &&
571 isLegacyUpdateHandoffLoss(exit.cause)
572 ) {
573 // Older servers can tear down the transport before their
574 // unary acknowledgement arrives. Treat only that transport
575 // loss as a handoff, then prove it by waiting for target ready.
576 return { targetVersion, method: selfUpdateMethod };
577 }
578 return yield* Effect.failCause(exit.cause);
579 });
580​
581 currentStage = "resuming";
582 atomRegistry.set(stateAtom, {
583 status: "running",
584 stage: currentStage,
585 fromVersion,
586 targetVersion,
587 });
588 return updateResult;
589 }),
590 );
591​
592 // The update restart is intentional. As soon as the supervisor sees
593 // that first failed connection, discard any prior backoff debt and
594 // retry immediately instead of carrying an old 16-second delay.
595 yield* environmentRegistry.stateChanges(target.environmentId).pipe(
596 Stream.filter((state) => state.phase === "backoff"),
597 Stream.take(1),
598 Stream.runDrain,
599 Effect.andThen(environmentRegistry.retryNow(target.environmentId)),
600 Effect.timeoutOption(Duration.seconds(30)),
601 Effect.ignore,
602 Effect.forkChild,
603 );
604​
605 const resumed = yield* environmentRegistry
606 .followStream(target.environmentId, subscribe(WS_METHODS.subscribeServerLifecycle, {}))
607 .pipe(
608 Stream.filter(
609 (event): event is ServerLifecycleStreamReadyEvent =>
610 event.type === "ready" && matchesServerUpdateReadyEvent(result, event),
611 ),
612 Stream.runHead,
613 Effect.timeoutOption(SERVER_UPDATE_RESUME_TIMEOUT),
614 Effect.map(Option.flatten),
615 );
616 if (Option.isNone(resumed)) {
617 return yield* new ServerUpdateResumeTimeoutError({
618 environmentId: target.environmentId,
619 targetVersion,
620 });
621 }
622 yield* validateServerUpdateReadyEvent(result, resumed.value);
623​
624 atomRegistry.set(stateAtom, IDLE_SERVER_UPDATE_STATE);
625 return result;
626 }).pipe(
627 Effect.onExit((exit) =>
628 Effect.sync(() => {
629 if (Exit.isSuccess(exit)) {
630 return;
631 }
632 if (Cause.hasInterruptsOnly(exit.cause)) {
633 atomRegistry.set(stateAtom, IDLE_SERVER_UPDATE_STATE);
634 return;
635 }
636 atomRegistry.set(stateAtom, {
637 status: "failed",
638 stage: currentStage,
639 fromVersion,
640 targetVersion,
641 message: serverUpdateFailureMessage(Cause.squash(exit.cause)),
642 });
643 }),
644 ),
645 );
646 },
647 });
648 const settingsValueAtom = Atom.family((environmentId: EnvironmentId) =>
649 Atom.make((get) => get(configValueAtom(environmentId))?.settings ?? null).pipe(
650 Atom.withLabel(`environment-data:server:settings:${environmentId}`),
651 ),
652 );
653 const providersValueAtom = Atom.family((environmentId: EnvironmentId) =>
654 Atom.make((get) => get(configValueAtom(environmentId))?.providers ?? null).pipe(
655 Atom.withLabel(`environment-data:server:providers:${environmentId}`),
656 ),
657 );
658​
659 return {
660 configValueAtom,
661 updateStateAtom,
662 settingsValueAtom,
663 providersValueAtom,
664 traceDiagnostics: createEnvironmentRpcQueryAtomFamily(runtime, {
665 label: "environment-data:server:trace-diagnostics",
666 tag: WS_METHODS.serverGetTraceDiagnostics,
667 }),
668 processDiagnostics: createEnvironmentRpcQueryAtomFamily(runtime, {
669 label: "environment-data:server:process-diagnostics",
670 tag: WS_METHODS.serverGetProcessDiagnostics,
671 }),
672 processResourceHistory: createEnvironmentRpcQueryAtomFamily(runtime, {
673 label: "environment-data:server:process-resource-history",
674 tag: WS_METHODS.serverGetProcessResourceHistory,
675 }),
676 resourceTelemetry: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
677 label: "environment-data:server:resource-telemetry",
678 tag: WS_METHODS.subscribeResourceTelemetry,
679 idleTtlMs: 0,
680 }),
681 resourceTelemetryHistory: createEnvironmentRpcQueryAtomFamily(runtime, {
682 label: "environment-data:server:resource-telemetry-history",
683 tag: WS_METHODS.serverGetResourceTelemetryHistory,
684 staleTimeMs: 5_000,
685 }),
686 configProjection,
687 welcome: createEnvironmentRpcSubscriptionAtomFamily(runtime, {
688 label: "environment-data:server:welcome",
689 tag: WS_METHODS.subscribeServerLifecycle,
690 transform: (stream) =>
691 stream.pipe(
692 Stream.mapAccum(Option.none<ServerLifecycleWelcomePayload>, projectServerWelcome),
693 ),
694 }),
695 refreshProviders: createEnvironmentRpcCommand(runtime, {
696 label: "environment-data:server:refresh-providers",
697 tag: WS_METHODS.serverRefreshProviders,
698 concurrency: {
699 mode: "singleFlight",
700 key: ({ environmentId }) => environmentId,
701 },
702 }),
703 updateProvider: createEnvironmentRpcCommand(runtime, {
704 label: "environment-data:server:update-provider",
705 tag: WS_METHODS.serverUpdateProvider,
706 scheduler: configScheduler,
707 concurrency: configConcurrency,
708 }),
709 updateServer,
710 upsertKeybinding: createEnvironmentRpcCommand(runtime, {
711 label: "environment-data:server:upsert-keybinding",
712 tag: WS_METHODS.serverUpsertKeybinding,
713 scheduler: configScheduler,
714 concurrency: configConcurrency,
715 }),
716 removeKeybinding: createEnvironmentRpcCommand(runtime, {
717 label: "environment-data:server:remove-keybinding",
718 tag: WS_METHODS.serverRemoveKeybinding,
719 scheduler: configScheduler,
720 concurrency: configConcurrency,
721 }),
722 updateSettings: createEnvironmentRpcCommand(runtime, {
723 label: "environment-data:server:update-settings",
724 tag: WS_METHODS.serverUpdateSettings,
725 scheduler: configScheduler,
726 concurrency: configConcurrency,
727 }),
728 signalProcess: createEnvironmentRpcCommand(runtime, {
729 label: "environment-data:server:signal-process",
730 tag: WS_METHODS.serverSignalProcess,
731 }),
732 retryResourceTelemetry: createEnvironmentRpcCommand(runtime, {
733 label: "environment-data:server:retry-resource-telemetry",
734 tag: WS_METHODS.serverRetryResourceTelemetry,
735 concurrency: {
736 mode: "singleFlight",
737 key: ({ environmentId }) => environmentId,
738 },
739 }),
740 };