Skip to content

Commit 52be19b

Browse files
committed
add missing credential field on start node
1 parent 55d585c commit 52be19b

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

packages/agentflow/src/features/canvas/hooks/useOpenNodeEditor.test.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jest.mock('./useFlowNodes', () => ({
2020
}))
2121

2222
let mockNodes: ReturnType<typeof makeFlowNode>[] = []
23-
let mockAvailableNodes: { name: string; inputs?: { name: string }[] }[] = []
23+
let mockAvailableNodes: { name: string; inputs?: { name: string }[]; credential?: { name: string; type: string } }[] = []
2424

2525
describe('useOpenNodeEditor', () => {
2626
beforeEach(() => {
@@ -112,6 +112,31 @@ describe('useOpenNodeEditor', () => {
112112
)
113113
})
114114

115+
it('should prepend credential param to inputParams when schema has credential', () => {
116+
mockAvailableNodes = [
117+
{
118+
name: 'llmAgentflow',
119+
inputs: [{ name: 'model' }],
120+
credential: { name: 'credential', type: 'credential' }
121+
}
122+
]
123+
const { result } = renderHook(() => useOpenNodeEditor())
124+
result.current.openNodeEditor('node-1')
125+
126+
expect(mockOpenEditDialog).toHaveBeenCalledWith('node-1', expect.objectContaining({ name: 'llmAgentflow' }), [
127+
{ name: 'credential', type: 'credential' },
128+
{ name: 'model' }
129+
])
130+
})
131+
132+
it('should not prepend credential when schema has no credential', () => {
133+
mockAvailableNodes = [{ name: 'llmAgentflow', inputs: [{ name: 'model' }] }]
134+
const { result } = renderHook(() => useOpenNodeEditor())
135+
result.current.openNodeEditor('node-1')
136+
137+
expect(mockOpenEditDialog).toHaveBeenCalledWith('node-1', expect.objectContaining({ name: 'llmAgentflow' }), [{ name: 'model' }])
138+
})
139+
115140
it('should open dialog with empty inputs when schema has no inputs', () => {
116141
mockAvailableNodes = [{ name: 'llmAgentflow' }] // no inputs property
117142
const { result } = renderHook(() => useOpenNodeEditor())

packages/agentflow/src/features/canvas/hooks/useOpenNodeEditor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useCallback } from 'react'
22

3-
import type { NodeData } from '@/core/types'
3+
import type { InputParam, NodeData } from '@/core/types'
44
import { useAgentflowContext } from '@/infrastructure/store'
55

66
import { useFlowNodes } from './useFlowNodes'
@@ -22,7 +22,12 @@ export function useOpenNodeEditor() {
2222
// Find the node schema from available nodes (contains InputParam[] definitions)
2323
// Fall back to node.data.inputs when the API schema isn't available
2424
const nodeSchema = availableNodes.find((n) => n.name === node.data.name)
25-
const inputParams = nodeSchema?.inputs || node.data.inputs || []
25+
const baseParams = nodeSchema?.inputs || node.data.inputs || []
26+
27+
// The credential field is a separate property on the node schema (not in inputs).
28+
// Prepend it to inputParams so the dialog renders it.
29+
const credentialParam = (nodeSchema as Record<string, unknown>)?.credential as InputParam | undefined
30+
const inputParams = credentialParam ? [credentialParam, ...baseParams] : baseParams
2631

2732
// Ensure inputValues object exists for storing user input
2833
const nodeDataWithInputValues: NodeData = {

0 commit comments

Comments
 (0)