Skip to content

fix: The way for AI node agents to generate, modify, and obtain workspaces - #8215

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_ai_chat_node_agent
Nov 30, 2026
Merged

shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_ai_chat_node_agent

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: The way for AI node agents to generate, modify, and obtain workspaces

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.

@shaohuzhang1
shaohuzhang1 merged commit cb864d1 into v3 Nov 30, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@fix_ai_chat_node_agent branch November 30, 2026 05:47
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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant