Sfoglia il codice sorgente

fix(core): mark models.dev env providers as integrations

Dax Raad 1 mese fa
parent
commit
25f6b1a2db

+ 4 - 1
packages/core/src/plugin/models-dev.ts

@@ -26,7 +26,10 @@ export const ModelsDevPlugin = define({
     })
     yield* ctx.catalog.transform((catalog) => {
       for (const provider of loaded.data) {
-        catalog.provider.update(provider.info.id, (draft) => Object.assign(draft, provider.info))
+        catalog.provider.update(provider.info.id, (draft) => {
+          Object.assign(draft, provider.info)
+          if (provider.environment.length > 0) draft.integrationID = provider.info.id
+        })
         for (const model of provider.models) {
           catalog.model.update(provider.info.id, model.id, (draft) => Object.assign(draft, model))
         }

+ 32 - 0
packages/core/test/plugin/models-dev.test.ts

@@ -236,6 +236,38 @@ describe("ModelsDevPlugin", () => {
     ),
   )
 
+  it.effect("marks environment-backed source providers with integration identity", () =>
+    Effect.gen(function* () {
+      const integrations = yield* Integration.Service
+      const catalog = yield* Catalog.Service
+      const providerID = ProviderV2.ID.make("env-provider")
+      const models = ModelsDev.Service.of({
+        get: () =>
+          Effect.succeed([
+            {
+              info: {
+                id: providerID,
+                name: "Env Provider",
+                package: ProviderV2.aisdk("@ai-sdk/openai-compatible"),
+              },
+              environment: ["ENV_PROVIDER_API_KEY"],
+              models: [],
+            },
+          ] satisfies readonly ModelsDev.Snapshot[]),
+        refresh: () => Effect.void,
+      })
+
+      yield* ModelsDevPlugin.effect(
+        host({
+          catalog: catalogHost(catalog),
+          integration: integrationHost(integrations),
+        }),
+      ).pipe(Effect.provideService(ModelsDev.Service, models))
+
+      expect((yield* catalog.provider.get(providerID))?.integrationID).toBe(Integration.ID.make(providerID))
+    }),
+  )
+
   it.effect("converts reasoning options into settings variants", () =>
     Effect.acquireUseRelease(
       Effect.sync(() => {