authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-04-01 09:19:36-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-04-01 16:19:36+00:00
log80b282ece7be0b8c32c8d0573bc6569d3b7ecbe1
tree7f58d85ac46d281d428ad658e676a2ee0ae34504
parentd15075b32d5a0670ae76e32d8e1c85f8a913dd7e
signature Signed by PGP key B5690EEEBB952194

[codex] migrate Effect.fn in apps/server/src/provider/Layers/ProviderRegistry.ts (#1638)

Co-authored-by: codex <codex@users.noreply.github.com>

1 files changed, 29 insertions(+), 26 deletions(-)

apps/server/src/provider/Layers/ProviderRegistry.ts+29-26
......@@ -40,18 +40,19 @@ export const ProviderRegistryLive = Layer.effect(
4040 yield* loadProviders(codexProvider, claudeProvider),
4141 );
4242
43 const syncProviders = (options?: { readonly publish?: boolean }) =>
44 Effect.gen(function* () {
45 const previousProviders = yield* Ref.get(providersRef);
46 const providers = yield* loadProviders(codexProvider, claudeProvider);
47 yield* Ref.set(providersRef, providers);
43 const syncProviders = Effect.fn("syncProviders")(function* (options?: {
44 readonly publish?: boolean;
45 }) {
46 const previousProviders = yield* Ref.get(providersRef);
47 const providers = yield* loadProviders(codexProvider, claudeProvider);
48 yield* Ref.set(providersRef, providers);
4849
49 if (options?.publish !== false && haveProvidersChanged(previousProviders, providers)) {
50 yield* PubSub.publish(changesPubSub, providers);
51 }
50 if (options?.publish !== false && haveProvidersChanged(previousProviders, providers)) {
51 yield* PubSub.publish(changesPubSub, providers);
52 }
5253
53 return providers;
54 });
54 return providers;
55 });
5556
5657 yield* Stream.runForEach(codexProvider.streamChanges, () => syncProviders()).pipe(
5758 Effect.forkScoped,
......@@ -60,28 +61,30 @@ export const ProviderRegistryLive = Layer.effect(
6061 Effect.forkScoped,
6162 );
6263
64 const refresh = Effect.fn("refresh")(function* (provider?: ProviderKind) {
65 switch (provider) {
66 case "codex":
67 yield* codexProvider.refresh;
68 break;
69 case "claudeAgent":
70 yield* claudeProvider.refresh;
71 break;
72 default:
73 yield* Effect.all([codexProvider.refresh, claudeProvider.refresh], {
74 concurrency: "unbounded",
75 });
76 break;
77 }
78 return yield* syncProviders();
79 });
80
6381 return {
6482 getProviders: syncProviders({ publish: false }).pipe(
6583 Effect.tapError(Effect.logError),
6684 Effect.orElseSucceed(() => []),
6785 ),
6886 refresh: (provider?: ProviderKind) =>
69 Effect.gen(function* () {
70 switch (provider) {
71 case "codex":
72 yield* codexProvider.refresh;
73 break;
74 case "claudeAgent":
75 yield* claudeProvider.refresh;
76 break;
77 default:
78 yield* Effect.all([codexProvider.refresh, claudeProvider.refresh], {
79 concurrency: "unbounded",
80 });
81 break;
82 }
83 return yield* syncProviders();
84 }).pipe(
87 refresh(provider).pipe(
8588 Effect.tapError(Effect.logError),
8689 Effect.orElseSucceed(() => []),
8790 ),