Skip to content
Merged
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
10 changes: 2 additions & 8 deletions ui/src/workflow-canvas/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type ApiModule = {
/** 共享给当前范围的工具不分页列表,与工具选择弹窗共享目录一致 */
getAllSharedTool?: (query?: Dict<unknown>) => Promise<ToolItem[]>
getToolById?: (toolId: string) => Promise<ToolItem>
getKnowledgeTags?: (knowledgeIds: string[]) => Promise<KnowledgeTagGroup[]>
getLatestKnowledgeAction?: (knowledgeId: string) => Promise<KnowledgeWorkflowAction | null>
postPromptGenerate: (modelId: string, payload: PromptGeneratePayload) => Promise<Response>
postChatCompletion?: (modelId: string, payload: ChatCompletionPayload, signal?: AbortSignal) => Promise<Response>
Expand All @@ -48,7 +47,6 @@ export type WorkflowStoreApi = {
getAllApplication: (query?: Dict<unknown>) => Promise<ApplicationDetail[]>
/** 应用详情;当前范围不支持时返回空对象 */
getApplicationDetail: (applicationId: string) => Promise<ApplicationDetail>
getAllTags: (knowledgeIds: string[]) => Promise<KnowledgeTagGroup[]>
getModelListWithShared: (query?: Dict<unknown>) => Promise<ModelItem[]>
getProviderList: () => Promise<ModelProviderItem[]>
getModelParamsForm: (modelId: string) => Promise<DynamicFormField[]>
Expand Down Expand Up @@ -158,10 +156,6 @@ export function useWorkflowStore(resourceScope: string, getResourceWorkspaceId?:
if (!requestApi.getApplicationDetail) return Promise.resolve({} as ApplicationDetail)
return withCache(`application:${applicationId}`, () => requestApi.getApplicationDetail!(applicationId), force)
},
getAllTags(knowledgeIds: string[]): Promise<KnowledgeTagGroup[]> {
if (!requestApi.getAllTags) return Promise.resolve([])
return withCache(`knowledge-tags:${JSON.stringify(knowledgeIds)}`, () => requestApi.getAllTags!(knowledgeIds), force)
},
getModelListWithShared(query?: Dict<unknown>): Promise<ModelItem[]> {
return withCache(`model:${JSON.stringify(query ?? {})}`, () => requestApi.getModelListWithShared(query), force)
},
Expand Down Expand Up @@ -212,8 +206,8 @@ export function useWorkflowStore(resourceScope: string, getResourceWorkspaceId?:
return requestApi.getLatestKnowledgeAction ? requestApi.getLatestKnowledgeAction(knowledgeId) : Promise.resolve(null)
},
getKnowledgeTags(knowledgeIds: string[]): Promise<KnowledgeTagGroup[]> {
if (!requestApi.getKnowledgeTags) return Promise.resolve([])
return withCache(`knowledge-tags:${JSON.stringify(knowledgeIds)}`, () => requestApi.getKnowledgeTags!(knowledgeIds), force)
if (!requestApi.getAllTags) return Promise.resolve([])
return withCache(`knowledge-tags:${JSON.stringify(knowledgeIds)}`, () => requestApi.getAllTags!(knowledgeIds), force)
},
}
}

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 diff looks like an attempt to consolidate two duplicate tag APIs (getKnowledgeTags / getAllTags) into one, but there are several things to verify.

Potential issues

  1. Type/API inconsistency

    • getKnowledgeTags is removed from ApiModule, and the store’s getKnowledgeTags now calls requestApi.getAllTags.
    • Make sure ApiModule actually declares getAllTags:
      getAllTags?: (knowledgeIds: string[]) => Promise<KnowledgeTagGroup[]>
    • If it does not, this will be a TypeScript error: Property 'getAllTags' does not exist on type 'ApiModule'.
  2. Breaking change for store consumers

    • getAllTags is removed from WorkflowStoreApi and from the returned store object.
    • Any caller using workflowStore.getAllTags(...) will break at compile time and/or runtime.
    • If migration is incomplete, keep a deprecated alias temporarily:
      getAllTags(knowledgeIds: string[]) {
        return this.getKnowledgeTags(knowledgeIds)
      }
    • Otherwise, update all call sites and tests.
  3. Possible semantic regression

    • The store method is still named getKnowledgeTags, but it now delegates to requestApi.getAllTags.
    • Confirm that getAllTags has exactly the same semantics, return shape, and error behavior as the old getKnowledgeTags.
    • Also check all requestApi implementations: any adapter that only implements getKnowledgeTags and not getAllTags will now silently return [].
  4. Silent fallback hides missing implementation

    • if (!requestApi.getAllTags) return Promise.resolve([])
      This can hide a missing API implementation. Consider logging a warning in development, or making getAllTags required for scopes that need tag data.
  5. Cache key concerns

    • knowledge-tags:${JSON.stringify(knowledgeIds)} is order-sensitive. If ID order is not meaningful, sort a copy to improve cache hit rate:
      const key = `knowledge-tags:${[...knowledgeIds].sort().join(',')}`
    • Ensure withCache is scoped per resourceScope / workspace. If the cache is global, include the scope in the key.
    • Since the implementation switched from getKnowledgeTags to getAllTags, verify that reusing the same cache key is still correct.

Suggested cleanup

Use a local variable to avoid repeated optional access and the non-null assertion:

getKnowledgeTags(knowledgeIds: string[]): Promise<KnowledgeTagGroup[]> {
  const getAllTags = requestApi.getAllTags
  if (!getAllTags) return Promise.resolve([])

  const cacheKey = `knowledge-tags:${JSON.stringify(knowledgeIds)}`
  return withCache(cacheKey, () => getAllTags(knowledgeIds), force)
}

Summary

The diff is reasonable if:

  • ApiModule.getAllTags exists and is implemented everywhere,
  • all callers of store.getAllTags have been migrated,
  • getAllTags and getKnowledgeTags are semantically identical.

Otherwise, it can cause TypeScript errors, runtime fallbacks to empty arrays, or breaking changes for store consumers.

Expand Down
Loading