Skip to content

Commit 0a26f10

Browse files
committed
Fix data store name referential integrity in agent flows
Keep original format for backward compatibility while fetching current store name from database to prevent UI breaks when document store names are updated.
1 parent 622febd commit 0a26f10

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

packages/components/nodes/agentflow/Agent/Agent.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,8 @@ class Agent_Agentflow implements INode {
433433
for (const store of stores) {
434434
if (store.status === 'UPSERTED') {
435435
const obj = {
436-
name: store.id, // Store only the ID, not the name
437-
label: store.name, // Display the current name
436+
name: `${store.id}:${store.name}`,
437+
label: store.name,
438438
description: store.description
439439
}
440440
returnData.push(obj)
@@ -564,6 +564,12 @@ class Agent_Agentflow implements INode {
564564
storeName = store?.name || storeId // Fallback to ID if store not found
565565
}
566566

567+
// Always fetch the current store name from database for referential integrity
568+
const appDataSource = options.appDataSource as DataSource
569+
const databaseEntities = options.databaseEntities as IDatabaseEntity
570+
const store = await appDataSource.getRepository(databaseEntities['DocumentStore']).findOneBy({ id: storeId })
571+
const currentStoreName = store?.name || storeId // Use current name from database
572+
567573
const docStoreVectorInstanceFilePath = options.componentNodes['documentStoreVS'].filePath as string
568574
const docStoreVectorModule = await import(docStoreVectorInstanceFilePath)
569575
const newDocStoreVectorInstance = new docStoreVectorModule.nodeClass()
@@ -586,7 +592,7 @@ class Agent_Agentflow implements INode {
586592
...nodeData,
587593
inputs: {
588594
...nodeData.inputs,
589-
name: storeName
595+
name: currentStoreName
590596
.toLowerCase()
591597
.replace(/ /g, '_')
592598
.replace(/[^a-z0-9_-]/g, ''),
@@ -606,7 +612,7 @@ class Agent_Agentflow implements INode {
606612
const componentNode = options.componentNodes['retrieverTool']
607613

608614
availableTools.push({
609-
name: storeName
615+
name: currentStoreName
610616
.toLowerCase()
611617
.replace(/ /g, '_')
612618
.replace(/[^a-z0-9_-]/g, ''),

packages/components/nodes/agentflow/Retriever/Retriever.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ class Retriever_Agentflow implements INode {
124124
for (const store of stores) {
125125
if (store.status === 'UPSERTED') {
126126
const obj = {
127-
name: store.id, // please store only the ID, not the name
128-
label: store.name, // display the current name
127+
name: `${store.id}:${store.name}`,
128+
label: store.name,
129129
description: store.description
130130
}
131131
returnData.push(obj)
@@ -152,16 +152,7 @@ class Retriever_Agentflow implements INode {
152152
const knowledgeBases = nodeData.inputs?.retrieverKnowledgeDocumentStores as IKnowledgeBase[]
153153
if (knowledgeBases && knowledgeBases.length > 0) {
154154
for (const knowledgeBase of knowledgeBases) {
155-
// Handle both old format (id:name) and new format (id only)
156-
let storeId = knowledgeBase.documentStore
157-
158-
if (knowledgeBase.documentStore.includes(':')) {
159-
// Old format - split to get ID
160-
;[storeId] = knowledgeBase.documentStore.split(':')
161-
} else {
162-
// New format - only ID is stored
163-
storeId = knowledgeBase.documentStore
164-
}
155+
const [storeId] = knowledgeBase.documentStore.split(':')
165156

166157
const docStoreVectorInstanceFilePath = options.componentNodes['documentStoreVS'].filePath as string
167158
const docStoreVectorModule = await import(docStoreVectorInstanceFilePath)

0 commit comments

Comments
 (0)