Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/src/workflow-canvas/WORKFLOW_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ AI 生成的 validate 工具复用同一入口(`collectWorkflowValidationError
页面通过 WorkflowCanvas.getLogicFlow() 提供画布,生成结果只改图,不自动保存。
模型选择支持参数设置,不提供添加模型入口;优先沿用默认 LLM 的参数,切换模型加载对应默认参数。
首轮生成时固定模型及参数,父 agent 和委派的子 agent 共用,并通过 `model_params_setting` 传入补全请求;新建会话后可重新配置。
面板从 `resourceWorkspaceId` 注入读取资源所属空间,以 `AgentBindings.getResourceWorkspaceId` 传给节点 agent,
资源查询经 `useWorkflowStore(resourceScope, getResourceWorkspaceId)` 与节点回显、选择弹窗保持同一查询范围。

| 位置 | 职责 |
| --------------- | -------------------------------------------------------- |
Expand Down
3 changes: 3 additions & 0 deletions ui/src/workflow-canvas/ai-generate/panel/AiGeneratePanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { AgentEvent, AgentHandle, AgentMessage } from '../type'
import type { DefaultModelSettingPayload, ModelItem, ModelProviderItem } from '@/api/types'
import type LogicFlow from '@logicflow/core'
import type { ScrollbarInstance } from 'element-plus'
import type { Ref } from 'vue'
import SelectModel from '@/components/business/select-model/index.vue'
import ContentList from '@/conversation-panel/components/content-list/index.vue'
import QuickQuestion from '@/conversation-panel/components/markdown-renderer/QuickQuestion.vue'
Expand Down Expand Up @@ -36,6 +37,7 @@ const props = withDefaults(
const emit = defineEmits<{ (event: 'done'): void }>()

const resourceScope = inject('resourceScope', 'workspace')
const resourceWorkspaceId = inject<Ref<string | null | undefined>>('resourceWorkspaceId', ref())
const route = useRoute()
const store = useWorkflowStore(resourceScope)

Expand Down Expand Up @@ -152,6 +154,7 @@ async function run(text: string) {
workflowMode: props.workflowMode,
resourceScope,
resourceId: resourceIdOf(),
getResourceWorkspaceId: () => resourceWorkspaceId.value,
position: [],
maxIterations: 200,
context: sessionGoal,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the key points to consider:


1. Missing ref import

You added import type { Ref } from 'vue' but also use ref() in:

const resourceWorkspaceId = inject<Ref<string | null | undefined>>('resourceWorkspaceId', ref())

However, ref is only imported as a type (Ref), not as a value. You’ll need either:

import { ref } from 'vue'
// or
import { ref, type Ref } from 'vue'

Otherwise, this will throw a runtime error.


2. Default value in inject – acceptable, but aware of behavior

Using ref() as a default is valid in Vue 3. If 'resourceWorkspaceId' is not provided by an ancestor, resourceWorkspaceId becomes a standalone Ref with undefined as its value. That’s fine.

However, note that because you’re passing a new ref object as a default, if the provider does provide one, you get the provided ref. If not, you get the fallback. The reactivity is preserved in both cases.


3. getResourceWorkspaceId callback

The arrow function:

getResourceWorkspaceId: () => resourceWorkspaceId.value

captures the injected ref and returns its current value. This is good if the workspace ID can change dynamically — the callback will always read the latest value.


4. Possible optimization / consistency

If resourceWorkspaceId is used more than once in the component, it’s usually cleaner to expose a computed getter like:

const getResourceWorkspaceId = () => resourceWorkspaceId.value

and reuse that function instead of writing the arrow inline every time. But since this appears only once, it’s not necessary.


5. Type safety consideration

Make sure that the upstream provide for 'resourceWorkspaceId' also matches Ref<string | null | undefined>. If the provided value is e.g. Ref<string> it still fits, but if it’s something else, TypeScript will complain at compile time.


Summary: The main issue is the missing ref import. Everything else is functionally sound.

Expand Down
2 changes: 2 additions & 0 deletions ui/src/workflow-canvas/ai-generate/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ export interface AgentBindings {
resourceScope: string
/** 画布所属资源 id(应用 / 工具 / 知识库),MCP 等按资源查询的接口使用 */
resourceId?: string
/** 读取画布资源所属工作空间,传给 useWorkflowStore;系统资源管理按它查询自有工具与 Skills */
getResourceWorkspaceId?: () => string | null | undefined
/** 事件树层级路径(顶层=[]) */
position?: string[]
/** 循环轮次上限 */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The added member looks straightforward, but here are a few points to consider:

  1. Return type is too broad
    () => string | null | undefined allows all three. Consider narrowing to () => string | undefined or () => string | null, depending on semantics. If the caller only needs to know “not available”, undefined is enough.

  2. Optional callback may be missing
    Since getResourceWorkspaceId?: is optional, any consumer must guard against undefined before calling.

  3. Naming clarity
    The name suggests an async getter (getResourceWorkspaceId), but it’s synchronous. If it ever becomes async, it should return Promise<string | undefined>. Consider naming it resourceWorkspaceId or resolveResourceWorkspaceId if it computes rather than fetches.

  4. Potential serializability concern
    If AgentBindings is ever stored, sent over IPC, or persisted, including a function makes it non-serializable. Verify that this object stays in-memory only.

  5. Comment formatting
    The comments are fine; consider using Past tense (“读取” → “获取”) for consistency with other comments.

No critical bug seen — just ensure null/undefined handling and avoid serializing the bindings object.

Expand Down
2 changes: 1 addition & 1 deletion ui/src/workflow-canvas/nodes/ai-chat-node/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function currentResourceIds(context: NodeAgentContext) {
* 工具、Skills 取自有与共享目录合并,MCP 沿用 MCP 设置弹窗的查询;工具类只取已启用的,智能体只取已发布的,均排除当前资源。
*/
async function loadSkillResources(context: NodeAgentContext): Promise<SkillResources> {
const store = useWorkflowStore(context.bindings.resourceScope)
const store = useWorkflowStore(context.bindings.resourceScope, context.bindings.getResourceWorkspaceId)
const [ownTools, sharedTools, ownSkills, sharedSkills, mcps, applications] = await Promise.all([
store.getToolList(),
store.getSharedToolList(),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a review of the change:

Potential Issues

  1. Undefined getResourceWorkspaceId risk
    The new second argument context.bindings.getResourceWorkspaceId is passed directly. If that binding is not always present (e.g., optional in some contexts), the store may receive undefined and fail. Consider adding a fallback:

    const store = useWorkflowStore(
      context.bindings.resourceScope,
      context.bindings.getResourceWorkspaceId ?? null
    )

    Or validate that the binding exists before using it.

  2. Signature mismatch
    Ensure useWorkflowStore actually accepts a second parameter. If it only accepts one argument, this change will silently ignore the second argument or throw a TypeScript error. Check the store definition and update its type if necessary.

  3. Composable / store call inside an async function
    If useWorkflowStore is a Pinia store, this is fine. If it is a Vue composable that expects to be called during setup(), calling it inside a regular async function could cause issues. Verify that it can be safely called outside of a component setup context.

  4. Comment/code mismatch
    The comment says “均排除当前资源”, but the snippet doesn’t show that filtering logic. Make sure the exclusion is actually applied, otherwise the result set may include the current resource.

Optimization Suggestions

  1. Parallel fetching is already good
    Using Promise.all for all six API calls is efficient. Keep it unless you need progressive rendering.

  2. Consider caching
    If these resources are frequently requested and don’t change often, adding a simple cache layer could reduce redundant network calls.

  3. Maybe rename the function
    The function loads tools, skills, MCPs, and applications, but is named loadSkillResources. A more accurate name like loadAgentResources would improve readability.

  4. Handle partial failures
    With Promise.all, if one request fails, all others are rejected too. If partial results are acceptable, use Promise.allSettled or handle errors per request.


Overall, the main thing to check before merging is whether context.bindings.getResourceWorkspaceId is guaranteed to exist and whether useWorkflowStore supports the second argument.

Expand Down
Loading