provider.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import type { Model, ModelID, ProviderID } from "./schema"
  2. export type ModelOptions = Pick<Model.Input, "defaults" | "compatibility">
  3. /**
  4. * Advanced structural provider definition helper. Built-in providers should
  5. * prefer explicit `configure(options).model(id)` facades so deployment config is
  6. * chosen before model selection. The optional `apis` map remains for external
  7. * structural providers that expose multiple route selectors behind one provider.
  8. */
  9. export type ModelFactory<Options extends ModelOptions = ModelOptions> = (
  10. id: string | ModelID,
  11. options?: Options,
  12. ) => Model
  13. type AnyModelFactory = (...args: never[]) => Model
  14. export interface Definition<Factory extends AnyModelFactory = ModelFactory> {
  15. readonly id: ProviderID
  16. readonly model: Factory
  17. readonly apis?: Record<string, AnyModelFactory>
  18. }
  19. type DefinitionShape = {
  20. readonly id: ProviderID
  21. readonly model: (...args: never[]) => Model
  22. readonly apis?: Record<string, (...args: never[]) => Model>
  23. }
  24. type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>
  25. export const make = <DefinitionType extends DefinitionShape>(
  26. definition: NoExtraFields<DefinitionType, DefinitionShape>,
  27. ) => definition
  28. export * as Provider from "./provider"