gitlab.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os from "os"
  2. import { InstallationVersion } from "../../installation/version"
  3. import { Effect } from "effect"
  4. import { define } from "../internal"
  5. import { ProviderV2 } from "../../provider"
  6. export const GitLabPlugin = define({
  7. id: "gitlab",
  8. effect: Effect.fn(function* (ctx) {
  9. yield* ctx.aisdk.sdk(
  10. Effect.fn(function* (evt) {
  11. if (evt.package !== "gitlab-ai-provider") return
  12. const mod = yield* Effect.promise(() => import("gitlab-ai-provider"))
  13. evt.sdk = mod.createGitLab({
  14. ...evt.options,
  15. instanceUrl:
  16. typeof evt.options.instanceUrl === "string"
  17. ? evt.options.instanceUrl
  18. : (process.env.GITLAB_INSTANCE_URL ?? "https://gitlab.com"),
  19. apiKey: typeof evt.options.apiKey === "string" ? evt.options.apiKey : process.env.GITLAB_TOKEN,
  20. aiGatewayHeaders: {
  21. "User-Agent": `kirincode/${InstallationVersion} gitlab-ai-provider/${mod.VERSION} (${os.platform()} ${os.release()}; ${os.arch()})`,
  22. "anthropic-beta": "context-1m-2025-08-07",
  23. ...evt.options.aiGatewayHeaders,
  24. },
  25. featureFlags: {
  26. duo_agent_platform_agentic_chat: true,
  27. duo_agent_platform: true,
  28. ...evt.options.featureFlags,
  29. },
  30. })
  31. }),
  32. )
  33. yield* ctx.aisdk.language(
  34. Effect.fn(function* (evt) {
  35. if (evt.model.providerID !== ProviderV2.ID.gitlab) return
  36. const featureFlags =
  37. typeof evt.options.featureFlags === "object" && evt.options.featureFlags ? evt.options.featureFlags : {}
  38. if (evt.model.api.id.startsWith("duo-workflow-")) {
  39. const gitlab = yield* Effect.promise(() => import("gitlab-ai-provider")).pipe(Effect.orDie)
  40. const workflowRef =
  41. typeof evt.model.request.body.workflowRef === "string" ? evt.model.request.body.workflowRef : undefined
  42. const workflowDefinition =
  43. typeof evt.model.request.body.workflowDefinition === "string"
  44. ? evt.model.request.body.workflowDefinition
  45. : undefined
  46. const language = evt.sdk.workflowChat(
  47. gitlab.isWorkflowModel(evt.model.api.id) ? evt.model.api.id : "duo-workflow",
  48. {
  49. featureFlags,
  50. workflowDefinition,
  51. },
  52. )
  53. if (workflowRef) language.selectedModelRef = workflowRef
  54. evt.language = language
  55. return
  56. }
  57. evt.language = evt.sdk.agenticChat(evt.model.api.id, {
  58. aiGatewayHeaders: evt.options.aiGatewayHeaders,
  59. featureFlags,
  60. })
  61. }),
  62. )
  63. }),
  64. })