provider.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. export * as Provider from "./provider"
  2. import { Schema } from "effect"
  3. import { optional } from "./schema"
  4. import { Integration } from "./integration"
  5. import { statics } from "./schema"
  6. export const ID = Schema.String.pipe(
  7. Schema.brand("ProviderV2.ID"),
  8. statics((schema) => ({
  9. kirincode: schema.make("kirincode"),
  10. anthropic: schema.make("anthropic"),
  11. openai: schema.make("openai"),
  12. google: schema.make("google"),
  13. googleVertex: schema.make("google-vertex"),
  14. githubCopilot: schema.make("github-copilot"),
  15. amazonBedrock: schema.make("amazon-bedrock"),
  16. azure: schema.make("azure"),
  17. openrouter: schema.make("openrouter"),
  18. mistral: schema.make("mistral"),
  19. gitlab: schema.make("gitlab"),
  20. })),
  21. )
  22. export type ID = typeof ID.Type
  23. export interface AISDK extends Schema.Schema.Type<typeof AISDK> {}
  24. export const AISDK = Schema.Struct({
  25. type: Schema.Literal("aisdk"),
  26. package: Schema.String,
  27. url: Schema.String.pipe(optional),
  28. settings: Schema.Record(Schema.String, Schema.Unknown).pipe(optional),
  29. }).annotate({ identifier: "Provider.AISDK" })
  30. export interface Native extends Schema.Schema.Type<typeof Native> {}
  31. export const Native = Schema.Struct({
  32. type: Schema.Literal("native"),
  33. url: Schema.String.pipe(optional),
  34. settings: Schema.Record(Schema.String, Schema.Unknown),
  35. }).annotate({ identifier: "Provider.Native" })
  36. export const Api = Schema.Union([AISDK, Native])
  37. .pipe(Schema.toTaggedUnion("type"))
  38. .annotate({ identifier: "Provider.Api" })
  39. export type Api = typeof Api.Type
  40. export interface Request extends Schema.Schema.Type<typeof Request> {}
  41. export const Request = Schema.Struct({
  42. headers: Schema.Record(Schema.String, Schema.String),
  43. body: Schema.Record(Schema.String, Schema.Json),
  44. }).annotate({ identifier: "Provider.Request" })
  45. export interface Info extends Schema.Schema.Type<typeof Info> {}
  46. export const Info = Schema.Struct({
  47. id: ID,
  48. integrationID: Integration.ID.pipe(optional),
  49. name: Schema.String,
  50. disabled: Schema.Boolean.pipe(optional),
  51. api: Api,
  52. request: Request,
  53. })
  54. .annotate({ identifier: "ProviderV2.Info" })
  55. .pipe(
  56. statics((schema) => ({
  57. empty: (id: ID) =>
  58. schema.make({
  59. id,
  60. name: id,
  61. api: { type: "native", settings: {} },
  62. request: { headers: {}, body: {} },
  63. }),
  64. })),
  65. )