Effect CommunityEC
Effect Community7mo ago
2 replies
fawwaz

how to provide config to ManagedRuntime?

So far, I've created a managed runtime and I've been using it to run all the effects that I've created inside the application. But now I'm at a point where I want to provide runtime-level configuration to be accessed by different effects. The commented code would cause an error. How to best provide runtime-level configuration (envs)?

export const createRuntime = (c: C) => {
  const googleModel = createGoogleGenerativeAI({
    apiKey: c.env.GOOGLE_GENERATIVE_AI_API_KEY,
  });
  const mainLayer = Layer.mergeAll(
    createDbServiceLayer(c.get("DrizzleDB")),
    createBlobStorageServiceLayer(c.env.mooz),
    Layer.succeed(GoogleModel, googleModel),
    createQueueServiceLayer(c.env.mooz_q),
    createKVStorageServiceLayer(c.env.mooz_kv),
    createWingmanServiceLayer(),
    // 👇 will cause an error
    // Effect.withConfigProvider(
    //   ConfigProvider.fromMap(
    //     new Map([
    //       ["WINGMAN_URL", c.env.WINGMAN_URL],
    //       ["WINGMAN_API_KEY", c.env.WINGMAN_API_KEY],
    //     ])
    //   )
    // ),
  );
  return ManagedRuntime.make(mainLayer);
};
Was this page helpful?