| ... | @@ -26,6 +26,7 @@ import { | ... | @@ -26,6 +26,7 @@ import { |
| 26 | WebSocketRequest, | 26 | WebSocketRequest, |
| 27 | WsPush, | 27 | WsPush, |
| 28 | WsResponse, | 28 | WsResponse, |
| | 29 | ServerProviderStatus, |
| 29 | } from "@t3tools/contracts"; | 30 | } from "@t3tools/contracts"; |
| 30 | import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"; | 31 | import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer"; |
| 31 | import { | 32 | import { |
| ... | @@ -268,9 +269,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< | ... | @@ -268,9 +269,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< |
| 268 | ), | 269 | ), |
| 269 | ); | 270 | ); |
| 270 | | 271 | |
| 271 | // Read provider statuses lazily so background health checks are reflected. | | |
| 272 | const getProviderStatuses = () => Effect.runSync(providerHealth.getStatuses); | | |
| 273 | | | |
| 274 | const clients = yield* Ref.make(new Set<WebSocket>()); | 272 | const clients = yield* Ref.make(new Set<WebSocket>()); |
| 275 | const logger = createLogger("ws"); | 273 | const logger = createLogger("ws"); |
| 276 | | 274 | |
| ... | @@ -618,6 +616,23 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< | ... | @@ -618,6 +616,23 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< |
| 618 | const subscriptionsScope = yield* Scope.make("sequential"); | 616 | const subscriptionsScope = yield* Scope.make("sequential"); |
| 619 | yield* Effect.addFinalizer(() => Scope.close(subscriptionsScope, Exit.void)); | 617 | yield* Effect.addFinalizer(() => Scope.close(subscriptionsScope, Exit.void)); |
| 620 | | 618 | |
| | 619 | // Push updated provider statuses to connected clients once background health checks finish. |
| | 620 | let providers: ReadonlyArray<ServerProviderStatus> = []; |
| | 621 | yield* providerHealth.getStatuses.pipe( |
| | 622 | Effect.flatMap((statuses) => { |
| | 623 | providers = statuses; |
| | 624 | return broadcastPush({ |
| | 625 | type: "push", |
| | 626 | channel: WS_CHANNELS.serverConfigUpdated, |
| | 627 | data: { |
| | 628 | issues: [], |
| | 629 | providers: statuses, |
| | 630 | }, |
| | 631 | }); |
| | 632 | }), |
| | 633 | Effect.forkIn(subscriptionsScope), |
| | 634 | ); |
| | 635 | |
| 621 | yield* Stream.runForEach(orchestrationEngine.streamDomainEvents, (event) => | 636 | yield* Stream.runForEach(orchestrationEngine.streamDomainEvents, (event) => |
| 622 | broadcastPush({ | 637 | broadcastPush({ |
| 623 | type: "push", | 638 | type: "push", |
| ... | @@ -632,23 +647,11 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< | ... | @@ -632,23 +647,11 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< |
| 632 | channel: WS_CHANNELS.serverConfigUpdated, | 647 | channel: WS_CHANNELS.serverConfigUpdated, |
| 633 | data: { | 648 | data: { |
| 634 | issues: event.issues, | 649 | issues: event.issues, |
| 635 | providers: getProviderStatuses(), | 650 | providers, |
| 636 | }, | 651 | }, |
| 637 | }), | 652 | }), |
| 638 | ).pipe(Effect.forkIn(subscriptionsScope)); | 653 | ).pipe(Effect.forkIn(subscriptionsScope)); |
| 639 | | 654 | |
| 640 | // Push updated provider statuses to connected clients once background health checks finish. | | |
| 641 | providerHealth.onReady((statuses) => { | | |
| 642 | broadcastPush({ | | |
| 643 | type: "push", | | |
| 644 | channel: WS_CHANNELS.serverConfigUpdated, | | |
| 645 | data: { | | |
| 646 | issues: [], | | |
| 647 | providers: statuses, | | |
| 648 | }, | | |
| 649 | }).pipe(Effect.runPromise).catch(() => {}); | | |
| 650 | }); | | |
| 651 | | | |
| 652 | yield* Scope.provide(orchestrationReactor.start, subscriptionsScope); | 655 | yield* Scope.provide(orchestrationReactor.start, subscriptionsScope); |
| 653 | | 656 | |
| 654 | let welcomeBootstrapProjectId: ProjectId | undefined; | 657 | let welcomeBootstrapProjectId: ProjectId | undefined; |
| ... | @@ -896,7 +899,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< | ... | @@ -896,7 +899,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return< |
| 896 | keybindingsConfigPath, | 899 | keybindingsConfigPath, |
| 897 | keybindings: keybindingsConfig.keybindings, | 900 | keybindings: keybindingsConfig.keybindings, |
| 898 | issues: keybindingsConfig.issues, | 901 | issues: keybindingsConfig.issues, |
| 899 | providers: getProviderStatuses(), | 902 | providers, |
| 900 | availableEditors, | 903 | availableEditors, |
| 901 | }; | 904 | }; |
| 902 | | 905 | |