Repository navigation
ANS-53 fix credential modal agentflow #642
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fec9f0
fix: resolve credential modal issues in agentflow canvas
diecoscai f762299
refactor: enhance credential modal handling in agentflow and marketplβ¦
diecoscai fc6db1d
refactor: consolidate credential modal logic and update billing proviβ¦
diecoscai f0dc435
fix: restore credential modal logic in agentflow canvas after rebase
diecoscai dbd9c80
Refactor credential extraction and defer agentflow modal
diecoscai b8a0c73
refactor: improve error handling in flow credential processes
diecoscai db7f6f6
fix: address critical PR review issues in credential modal flow
maxtechera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,80 +1,15 @@ | ||
| import { getCredentialCategory } from './getCredentialCategory' | ||
| import { processFlowCredentials } from './processFlowCredentials' | ||
|
|
||
| /** | ||
| * Extract all credentials (assigned and unassigned) from flow data for QuickSetup mode | ||
| * @param {string|object} flowData - Flow data as JSON string or object | ||
| * @returns {object} Object containing all credentials info | ||
| */ | ||
| export const extractAllCredentials = (flowData: string | any) => { | ||
| try { | ||
| // Parse flow data if it's a string | ||
| const flow = typeof flowData === 'string' ? JSON.parse(flowData) : flowData | ||
| const { credentials, hasCredentials } = processFlowCredentials(flowData) | ||
|
|
||
| if (!flow.nodes || !Array.isArray(flow.nodes)) { | ||
| return { allCredentials: [], hasCredentials: false } | ||
| } | ||
|
|
||
| const allCredentials: any[] = [] | ||
| const credentialTypes = new Set<string>() | ||
|
|
||
| // Iterate through all nodes | ||
| flow.nodes.forEach((node: any) => { | ||
| if (node.data && node.data.inputParams) { | ||
| // Find all credential input parameters | ||
| const credentialParams = node.data.inputParams.filter((param: any) => { | ||
| return param.type === 'credential' | ||
| }) | ||
|
|
||
| credentialParams.forEach((credentialParam: any) => { | ||
| // Check if credential is assigned | ||
| const hasCredential = | ||
| node.data.credential || | ||
| (node.data.inputs && node.data.inputs[credentialParam.name]) || | ||
| (node.data.inputs && node.data.inputs['FLOWISE_CREDENTIAL_ID']) | ||
|
|
||
| // Extract credential names | ||
| const credentialNames = credentialParam.credentialNames || [] | ||
|
|
||
| credentialNames.forEach((credentialName: string) => { | ||
| credentialTypes.add(credentialName) | ||
|
|
||
| // Get category information to determine if credential is core | ||
| const category = getCredentialCategory(node.data.category, credentialName) | ||
|
|
||
| // Credential is required if: | ||
| // 1. Category is core (Chat Models, Agents, etc), OR | ||
| // 2. Parameter explicitly marked as NOT optional (optional: false) | ||
| // Default to optional if not explicitly marked | ||
| const isRequired = category.isCore || (credentialParam.optional === false) | ||
|
|
||
| const credInfo = { | ||
| nodeId: node.id, | ||
| nodeName: node.data.name || 'Unknown Node', | ||
| nodeCategory: node.data.category || 'Unknown', | ||
| nodeType: node.data.type || node.type || 'Unknown', | ||
| credentialType: credentialName, | ||
| parameterName: credentialParam.name, | ||
| label: credentialParam.label || credentialParam.name, | ||
| isRequired: isRequired, | ||
| isCore: category.isCore, | ||
| categoryType: category.type, | ||
| categoryDisplayName: category.displayName, | ||
| isAssigned: !!hasCredential, | ||
| assignedCredentialId: hasCredential || null | ||
| } | ||
|
|
||
| allCredentials.push(credInfo) | ||
| }) | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| return { | ||
| allCredentials, | ||
| hasCredentials: credentialTypes.size > 0 | ||
| } | ||
| } catch (error) { | ||
| console.error('Error in extractAllCredentials:', error) | ||
| return { allCredentials: [], hasCredentials: false } | ||
| return { | ||
| allCredentials: credentials, | ||
| hasCredentials | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { getCredentialCategory } from './getCredentialCategory' | ||
|
|
||
| type FlowData = string | Record<string, any> | ||
|
|
||
| export type FlowCredentialRecord = { | ||
| nodeId: string | ||
| nodeName: string | ||
| nodeCategory: string | ||
| nodeType: string | ||
| credentialType: string | ||
| parameterName: string | ||
| label: string | ||
| isRequired: boolean | ||
| isCore: boolean | ||
| categoryType: string | ||
| categoryDisplayName: string | ||
| isAssigned: boolean | ||
| assignedCredentialId: string | null | ||
| } | ||
|
|
||
| type ProcessResult = { | ||
| credentials: FlowCredentialRecord[] | ||
| hasCredentials: boolean | ||
| } | ||
|
|
||
| export const processFlowCredentials = (flowData: FlowData): ProcessResult => { | ||
| try { | ||
| const flow = typeof flowData === 'string' ? JSON.parse(flowData) : flowData | ||
|
|
||
| if (!flow || !Array.isArray(flow.nodes)) { | ||
| return { credentials: [], hasCredentials: false } | ||
| } | ||
|
|
||
| const credentials: FlowCredentialRecord[] = [] | ||
| const credentialTypes = new Set<string>() | ||
|
|
||
| flow.nodes.forEach((node: any) => { | ||
| const inputParams = node?.data?.inputParams | ||
| if (!Array.isArray(inputParams)) return | ||
|
|
||
| const credentialParams = inputParams.filter((param: any) => param?.type === 'credential') | ||
|
|
||
| credentialParams.forEach((credentialParam: any) => { | ||
| const inputs = node?.data?.inputs | ||
| const hasCredential = | ||
| node?.data?.credential || (inputs && (inputs[credentialParam.name] || inputs['FLOWISE_CREDENTIAL_ID'])) | ||
|
|
||
| const credentialNames: string[] = credentialParam?.credentialNames || [] | ||
|
|
||
| credentialNames.forEach((credentialName: string) => { | ||
| credentialTypes.add(credentialName) | ||
|
|
||
| const category = getCredentialCategory(node?.data?.category, credentialName) | ||
| const isRequired = category.isCore || credentialParam?.optional === false | ||
|
|
||
| credentials.push({ | ||
| nodeId: node?.id, | ||
| nodeName: node?.data?.name || 'Unknown Node', | ||
| nodeCategory: node?.data?.category || 'Unknown', | ||
| nodeType: node?.data?.type || node?.type || 'Unknown', | ||
| credentialType: credentialName, | ||
| parameterName: credentialParam?.name, | ||
| label: credentialParam?.label || credentialParam?.name, | ||
| isRequired, | ||
| isCore: category.isCore, | ||
| categoryType: category.type, | ||
| categoryDisplayName: category.displayName, | ||
| isAssigned: !!hasCredential, | ||
| assignedCredentialId: hasCredential || null | ||
| }) | ||
| }) | ||
| }) | ||
| }) | ||
|
|
||
| return { | ||
| credentials, | ||
| hasCredentials: credentialTypes.size > 0 | ||
| } | ||
| } catch (_error) { | ||
| return { credentials: [], hasCredentials: false } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.