From 95cbdc79007701ba524f01dd72fb28fff287ff50 Mon Sep 17 00:00:00 2001 From: darkskygit Date: Fri, 14 Mar 2025 07:07:28 +0000 Subject: [PATCH] chore(server): enable copilot in doc service (#10850) --- .github/actions/deploy/deploy.mjs | 8 +++++-- .../charts/doc/templates/deployment.yaml | 22 +++++++++++++++++++ .github/helm/affine/charts/doc/values.yaml | 5 +++++ .../server/src/plugins/copilot/index.ts | 2 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/.github/actions/deploy/deploy.mjs b/.github/actions/deploy/deploy.mjs index bc7a7bff98..e2c02f910d 100644 --- a/.github/actions/deploy/deploy.mjs +++ b/.github/actions/deploy/deploy.mjs @@ -35,7 +35,6 @@ const { STATIC_IP_NAME, } = process.env; -// eslint-disable-next-line @typescript-eslint/no-non-null-assertion const buildType = BUILD_TYPE || 'canary'; const isProduction = buildType === 'stable'; @@ -136,7 +135,7 @@ const createHelmCommand = ({ isDryRun }) => { : isInternal ? 'internal' : 'dev'; - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const host = DEPLOY_HOST || CANARY_DEPLOY_HOST; const deployCommand = [ `helm upgrade --install affine .github/helm/affine`, @@ -183,6 +182,11 @@ const createHelmCommand = ({ isDryRun }) => { `--set renderer.replicaCount=${replica.renderer}`, `--set-string doc.image.tag="${imageTag}"`, `--set doc.app.host=${host}`, + `--set doc.app.copilot.enabled=true`, + `--set-string doc.app.copilot.openai.key="${COPILOT_OPENAI_API_KEY}"`, + `--set-string doc.app.copilot.fal.key="${COPILOT_FAL_API_KEY}"`, + `--set-string doc.app.copilot.perplexity.key="${COPILOT_PERPLEXITY_API_KEY}"`, + `--set-string doc.app.copilot.unsplash.key="${COPILOT_UNSPLASH_API_KEY}"`, `--set doc.replicaCount=${replica.doc}`, ...serviceAnnotations, ...resources, diff --git a/.github/helm/affine/charts/doc/templates/deployment.yaml b/.github/helm/affine/charts/doc/templates/deployment.yaml index b64088cf42..64d5a8d09f 100644 --- a/.github/helm/affine/charts/doc/templates/deployment.yaml +++ b/.github/helm/affine/charts/doc/templates/deployment.yaml @@ -75,6 +75,28 @@ spec: value: "{{ .Values.app.host }}" - name: AFFINE_SERVER_HTTPS value: "{{ .Values.app.https }}" + {{ if .Values.app.copilot.enabled }} + - name: COPILOT_OPENAI_API_KEY + valueFrom: + secretKeyRef: + name: "{{ .Values.app.copilot.secretName }}" + key: openaiSecret + - name: COPILOT_FAL_API_KEY + valueFrom: + secretKeyRef: + name: "{{ .Values.app.copilot.secretName }}" + key: falSecret + - name: COPILOT_PERPLEXITY_API_KEY + valueFrom: + secretKeyRef: + name: "{{ .Values.app.copilot.secretName }}" + key: perplexitySecret + - name: COPILOT_UNSPLASH_API_KEY + valueFrom: + secretKeyRef: + name: "{{ .Values.app.copilot.secretName }}" + key: unsplashSecret + {{ end }} ports: - name: http containerPort: {{ .Values.global.docService.port }} diff --git a/.github/helm/affine/charts/doc/values.yaml b/.github/helm/affine/charts/doc/values.yaml index 78b3d1a0e8..1220255c3b 100644 --- a/.github/helm/affine/charts/doc/values.yaml +++ b/.github/helm/affine/charts/doc/values.yaml @@ -15,6 +15,11 @@ app: # AFFINE_SERVER_HOST host: '0.0.0.0' https: true + copilot: + enabled: false + secretName: copilot + openai: + key: '' serviceAccount: create: true annotations: {} diff --git a/packages/backend/server/src/plugins/copilot/index.ts b/packages/backend/server/src/plugins/copilot/index.ts index 4b06aca516..2630e1f6d3 100644 --- a/packages/backend/server/src/plugins/copilot/index.ts +++ b/packages/backend/server/src/plugins/copilot/index.ts @@ -60,7 +60,7 @@ registerCopilotProvider(PerplexityProvider); controllers: [CopilotController], contributesTo: ServerFeature.Copilot, if: config => { - if (config.flavor.graphql) { + if (config.flavor.graphql || config.flavor.doc) { return assertProvidersConfigs(config); } return false;