mirror of
https://github.com/langgenius/dify.git
synced 2026-04-20 18:57:19 +08:00
Frontend: - Migrate deprecated imports: modal→dialog, toast→ui/toast, tooltip→tooltip-plus, portal-to-follow-elem→portal-to-follow-elem-plus, select→ui/select, confirm→alert-dialog - Replace next/* with @/next/* wrapper modules - Convert TypeScript enums to const objects (erasable-syntax-only) - Replace all `any` types with `unknown` or specific types in workflow types - Fix unused vars, react-hooks-extra, react-refresh/only-export-components - Extract InteractionMode to separate module, tool-block commands to commands.ts Backend: - Fix pyrefly errors: type narrowing, null guards, getattr patterns - Remove unused TYPE_CHECKING imports in LLM node - Add ignore_imports entries to .importlinter for dify_graph boundary violations Made-with: Cursor
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import { useMemo } from 'react'
|
|
import { useStore as useReactFlowStore, useStoreApi } from 'reactflow'
|
|
import { useStore as useAppStore } from '@/app/components/app/store'
|
|
import { consoleClient, consoleQuery } from '@/service/client'
|
|
|
|
export type ToolDependency = {
|
|
type: string
|
|
provider: string
|
|
tool_name: string
|
|
}
|
|
|
|
type UseNodeSkillsParams = {
|
|
nodeId: string
|
|
promptTemplateKey: string
|
|
enabled?: boolean
|
|
}
|
|
|
|
export function useNodeSkills({ nodeId, promptTemplateKey, enabled = true }: UseNodeSkillsParams) {
|
|
const appId = useAppStore(s => s.appDetail?.id)
|
|
const store = useStoreApi()
|
|
const nodeData = useReactFlowStore(s => s.getNodes().find(n => n.id === nodeId)?.data)
|
|
const isQueryEnabled = enabled && !!appId && !!nodeId
|
|
|
|
const queryKey = useMemo(() => {
|
|
return [
|
|
...consoleQuery.workflowDraft.nodeSkills.queryKey({
|
|
input: {
|
|
params: { appId: appId ?? '' },
|
|
body: {},
|
|
},
|
|
}),
|
|
nodeId,
|
|
promptTemplateKey,
|
|
nodeData,
|
|
store,
|
|
]
|
|
}, [appId, nodeId, promptTemplateKey, nodeData, store])
|
|
|
|
const { data, isLoading } = useQuery({
|
|
queryKey,
|
|
queryFn: () => {
|
|
const node = store.getState().getNodes().find(n => n.id === nodeId)
|
|
return consoleClient.workflowDraft.nodeSkills({
|
|
params: { appId: appId ?? '' },
|
|
body: (node?.data ?? {}) as Record<string, unknown>,
|
|
})
|
|
},
|
|
enabled: isQueryEnabled,
|
|
gcTime: 0,
|
|
})
|
|
|
|
const toolDependencies = useMemo<ToolDependency[]>(
|
|
() => data?.tool_dependencies ?? [],
|
|
[data?.tool_dependencies],
|
|
)
|
|
|
|
const hasData = !!data
|
|
|
|
return {
|
|
toolDependencies,
|
|
isLoading,
|
|
isQueryEnabled,
|
|
hasData,
|
|
}
|
|
}
|