Skip to content

Commit 232b1ca

Browse files
waleedlatif1claude
andcommitted
feat(knowledge): mirror agent block API key visibility for Cohere reranker
Restore required:true on the Cohere API Key field and hide it server-side via a new NEXT_PUBLIC_COHERE_CONFIGURED public env flag — same pattern the Agent block uses for Azure (NEXT_PUBLIC_AZURE_CONFIGURED). Self-hosters who set COHERE_API_KEY in their environment also set NEXT_PUBLIC_COHERE_CONFIGURED=true, which removes the field from the UI; everyone else sees a required field. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3fcd053 commit 232b1ca

6 files changed

Lines changed: 29 additions & 4 deletions

File tree

apps/sim/.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ API_ENCRYPTION_KEY=your_api_encryption_key # Use `openssl rand -hex 32` to gener
3535
# AZURE_ANTHROPIC_API_KEY= # Azure Anthropic API key
3636
# AZURE_ANTHROPIC_API_VERSION= # Azure Anthropic API version (e.g., 2023-06-01)
3737
# NEXT_PUBLIC_AZURE_CONFIGURED=true # Set when Azure credentials are pre-configured above. Hides endpoint/key/version fields in Agent block UI.
38+
# COHERE_API_KEY= # Cohere API key for the Knowledge block reranker (rerank-v4.0-pro/-fast, rerank-v3.5). Alternatively set COHERE_API_KEY_1/2/3 for rotation.
39+
# NEXT_PUBLIC_COHERE_CONFIGURED=true # Set when COHERE_API_KEY (or rotation keys) are pre-configured above. Hides the Cohere API Key field on the Knowledge block UI.
3840

3941
# Admin API (Optional - for self-hosted GitOps)
4042
# ADMIN_API_KEY= # Use `openssl rand -hex 32` to generate. Enables admin API for workflow export/import.

apps/sim/blocks/blocks/knowledge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const KnowledgeBlock: BlockConfig = {
125125
placeholder: 'Enter your Cohere API key',
126126
password: true,
127127
connectionDroppable: false,
128+
required: true,
128129
condition: getCohereRerankerApiKeyCondition(),
129130
},
130131

apps/sim/blocks/utils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { toError } from '@sim/utils/errors'
2-
import { isAzureConfigured, isHosted, isOllamaConfigured } from '@/lib/core/config/feature-flags'
2+
import {
3+
isAzureConfigured,
4+
isCohereConfigured,
5+
isHosted,
6+
isOllamaConfigured,
7+
} from '@/lib/core/config/feature-flags'
38
import { getScopesForService } from '@/lib/oauth/utils'
49
import { buildCanonicalIndex } from '@/lib/workflows/subblocks/visibility'
510
import type { BlockOutput, OutputFieldDefinition, SubBlockConfig } from '@/blocks/types'
@@ -186,14 +191,15 @@ export function getApiKeyCondition() {
186191

187192
/**
188193
* Visibility condition for the Cohere reranker API key field on the Knowledge block.
189-
* On hosted Sim, the platform supplies the Cohere key (via workspace BYOK or rotating
190-
* env keys), so the field is hidden. On self-hosted deployments, the field is shown
194+
* Hidden on hosted Sim (platform supplies the key via workspace BYOK or rotating env keys)
195+
* and on self-hosted deployments that have set `NEXT_PUBLIC_COHERE_CONFIGURED=true` to
196+
* indicate `COHERE_API_KEY` is pre-configured server-side. Otherwise shown (and required)
191197
* whenever reranking is enabled for a search operation, mirroring the agent block's
192198
* `getApiKeyCondition` pattern.
193199
*/
194200
export function getCohereRerankerApiKeyCondition() {
195201
return () => {
196-
if (isHosted) {
202+
if (isHosted || isCohereConfigured) {
197203
return { field: 'operation', value: '__never_show__' }
198204
}
199205
return {

apps/sim/lib/core/config/env.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ export const env = createEnv({
430430
NEXT_PUBLIC_E2B_ENABLED: z.string().optional(),
431431
NEXT_PUBLIC_BEDROCK_DEFAULT_CREDENTIALS: z.string().optional(), // Hide Bedrock credential fields when deployment uses AWS default credential chain (IAM roles, instance profiles, ECS task roles, IRSA)
432432
NEXT_PUBLIC_AZURE_CONFIGURED: z.string().optional(), // Hide Azure credential fields when endpoint/key/version are pre-configured server-side
433+
NEXT_PUBLIC_COHERE_CONFIGURED: z.string().optional(), // Hide Cohere API key field on Knowledge block when COHERE_API_KEY is pre-configured server-side
433434
NEXT_PUBLIC_COPILOT_TRAINING_ENABLED: z.string().optional(),
434435
NEXT_PUBLIC_ENABLE_PLAYGROUND: z.string().optional(), // Enable component playground at /playground
435436
NEXT_PUBLIC_DOCUMENTATION_URL: z.string().url().optional(), // Custom documentation URL
@@ -496,6 +497,7 @@ export const env = createEnv({
496497
NEXT_PUBLIC_E2B_ENABLED: process.env.NEXT_PUBLIC_E2B_ENABLED,
497498
NEXT_PUBLIC_BEDROCK_DEFAULT_CREDENTIALS: process.env.NEXT_PUBLIC_BEDROCK_DEFAULT_CREDENTIALS,
498499
NEXT_PUBLIC_AZURE_CONFIGURED: process.env.NEXT_PUBLIC_AZURE_CONFIGURED,
500+
NEXT_PUBLIC_COHERE_CONFIGURED: process.env.NEXT_PUBLIC_COHERE_CONFIGURED,
499501
NEXT_PUBLIC_COPILOT_TRAINING_ENABLED: process.env.NEXT_PUBLIC_COPILOT_TRAINING_ENABLED,
500502
NEXT_PUBLIC_ENABLE_PLAYGROUND: process.env.NEXT_PUBLIC_ENABLE_PLAYGROUND,
501503
NEXT_PUBLIC_POSTHOG_ENABLED: process.env.NEXT_PUBLIC_POSTHOG_ENABLED,

apps/sim/lib/core/config/feature-flags.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,14 @@ export const isOllamaConfigured = Boolean(env.OLLAMA_URL)
156156
*/
157157
export const isAzureConfigured = isTruthy(getEnv('NEXT_PUBLIC_AZURE_CONFIGURED'))
158158

159+
/**
160+
* Whether a Cohere API key is pre-configured server-side for the Knowledge block reranker
161+
* (`COHERE_API_KEY` or `COHERE_API_KEY_1/2/3`). When true, the Cohere API Key field is hidden
162+
* in the Knowledge block UI.
163+
* Set NEXT_PUBLIC_COHERE_CONFIGURED=true in self-hosted deployments that ship a Cohere key.
164+
*/
165+
export const isCohereConfigured = isTruthy(getEnv('NEXT_PUBLIC_COHERE_CONFIGURED'))
166+
159167
/**
160168
* Are invitations disabled globally
161169
* When true, workspace invitations are disabled for all users

helm/sim/values.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ app:
275275
# in the Agent block UI — users just pick an Azure model and run.
276276
NEXT_PUBLIC_AZURE_CONFIGURED: "" # Set to "true" to hide Azure credential fields
277277

278+
# Cohere Reranker (Knowledge block)
279+
# Set COHERE_API_KEY (or COHERE_API_KEY_1/2/3 for rotation) and NEXT_PUBLIC_COHERE_CONFIGURED=true
280+
# to pre-configure the Cohere reranker server-side. When configured, the Cohere API Key field is
281+
# hidden in the Knowledge block UI.
282+
NEXT_PUBLIC_COHERE_CONFIGURED: "" # Set to "true" to hide the Cohere API Key field on the Knowledge block
283+
278284
# AWS S3 Cloud Storage Configuration (optional - for file storage)
279285
# If configured, files will be stored in S3 instead of local storage
280286
AWS_REGION: "" # AWS region (e.g., "us-east-1")

0 commit comments

Comments
 (0)