-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(copilot): credentials validation and api keys for hosted models #2998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile OverviewGreptile SummaryThis PR adds pre-validation for credential and API key inputs in workflow edit operations. The changes introduce a new
Key changes:
Potential concerns:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant EditWorkflowTool
participant PreValidate as preValidateCredentialInputs
participant Validator as validateSelectorIds
participant DB as Database
participant ApplyOps as applyOperationsToWorkflowState
participant PostValidate as validateWorkflowSelectorIds
Client->>EditWorkflowTool: editWorkflow(operations, workflowId)
EditWorkflowTool->>PreValidate: preValidateCredentialInputs(operations, {userId})
PreValidate->>PreValidate: Collect oauth-input credentials
PreValidate->>PreValidate: Collect apiKey inputs for hosted models
alt Has credentials to validate
PreValidate->>Validator: validateSelectorIds('oauth-input', credentialIds, context)
Validator->>DB: Query accounts by userId
DB-->>Validator: Return valid credential IDs
Validator-->>PreValidate: {valid, invalid, warning}
PreValidate->>PreValidate: Remove invalid credentials from operations
PreValidate->>PreValidate: Add validation errors
end
alt Has hosted model apiKeys (isHosted=true)
PreValidate->>PreValidate: Delete apiKey from operations
PreValidate->>PreValidate: Add error messages
end
PreValidate-->>EditWorkflowTool: {filteredOperations, errors}
EditWorkflowTool->>ApplyOps: applyOperationsToWorkflowState(state, filteredOperations)
ApplyOps-->>EditWorkflowTool: {modifiedState, validationErrors, skippedItems}
EditWorkflowTool->>EditWorkflowTool: Merge credential errors with validation errors
EditWorkflowTool->>DB: Get workspaceId
DB-->>EditWorkflowTool: workspaceId
EditWorkflowTool->>PostValidate: validateWorkflowSelectorIds(modifiedState, {userId, workspaceId})
Note over PostValidate: Skips oauth-input (already validated)
PostValidate->>Validator: Validate other selector types
Validator->>DB: Query selector resources
DB-->>Validator: Return valid IDs
Validator-->>PostValidate: Validation results
PostValidate-->>EditWorkflowTool: Additional errors
EditWorkflowTool->>EditWorkflowTool: Merge all validation errors
EditWorkflowTool-->>Client: {modifiedState, validationErrors, skippedItems}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 4 comments
| }) | ||
|
|
||
| const allCredentialIds = credentialInputs.map((c) => c.value) | ||
| const validationResult = await validateSelectorIds('oauth-input', allCredentialIds, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context only contains userId but validateSelectorIds expects { userId: string; workspaceId?: string } - workspaceId is missing
| const validationResult = await validateSelectorIds('oauth-input', allCredentialIds, context) | |
| const validationResult = await validateSelectorIds('oauth-input', allCredentialIds, { userId: context.userId }) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts
Line: 2695:2695
Comment:
`context` only contains `userId` but `validateSelectorIds` expects `{ userId: string; workspaceId?: string }` - workspaceId is missing
```suggestion
const validationResult = await validateSelectorIds('oauth-input', allCredentialIds, { userId: context.userId })
```
How can I resolve this? If you propose a fix, please make it concise.| } | ||
|
|
||
| // Deep clone operations so we can modify them | ||
| const filteredOperations = JSON.parse(JSON.stringify(operations)) as EditWorkflowOperation[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.parse(JSON.stringify()) will fail on operations containing functions, undefined values, or circular references - consider using a proper deep clone library like structuredClone() or lodash's cloneDeep
| const filteredOperations = JSON.parse(JSON.stringify(operations)) as EditWorkflowOperation[] | |
| const filteredOperations = structuredClone(operations) |
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts
Line: 2661:2661
Comment:
`JSON.parse(JSON.stringify())` will fail on operations containing functions, undefined values, or circular references - consider using a proper deep clone library like `structuredClone()` or lodash's `cloneDeep`
```suggestion
const filteredOperations = structuredClone(operations)
```
How can I resolve this? If you propose a fix, please make it concise.| errors.push({ | ||
| blockId: apiKeyInput.blockId, | ||
| blockType: apiKeyInput.blockType, | ||
| field: 'apiKey', | ||
| value: '[redacted]', | ||
| error: `API key not allowed for hosted model "${apiKeyInput.model}" - platform provides the key`, | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding an error for filtering out apiKey creates noise - users expect apiKeys to be ignored on hosted models, not receive errors about them
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts
Line: 2677:2683
Comment:
adding an error for filtering out `apiKey` creates noise - users expect apiKeys to be ignored on hosted models, not receive errors about them
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| const hostedModels = isHosted ? getHostedModels() : [] | ||
| const hostedModelsLower = new Set(hostedModels.map((m) => m.toLowerCase())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
calling getHostedModels() when isHosted is false returns an empty array, making the subsequent hostedModelsLower Set and all hosted model checks unnecessary - move this inside the if (isHosted) check on line 2638
| const hostedModels = isHosted ? getHostedModels() : [] | |
| const hostedModelsLower = new Set(hostedModels.map((m) => m.toLowerCase())) | |
| const hostedModels = isHosted ? getHostedModels() : [] | |
| const hostedModelsLower = isHosted ? new Set(hostedModels.map((m) => m.toLowerCase())) : new Set() |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/lib/copilot/tools/server/workflow/edit-workflow.ts
Line: 2612:2613
Comment:
calling `getHostedModels()` when `isHosted` is false returns an empty array, making the subsequent `hostedModelsLower` Set and all hosted model checks unnecessary - move this inside the `if (isHosted)` check on line 2638
```suggestion
const hostedModels = isHosted ? getHostedModels() : []
const hostedModelsLower = isHosted ? new Set(hostedModels.map((m) => m.toLowerCase())) : new Set()
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Summary
Brief description of what this PR does and why.
Fixes #(issue)
Type of Change
Testing
How has this been tested? What should reviewers focus on?
Checklist
Screenshots/Videos