π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(agent-documents): include authored docs in listDocuments sourceType="file" (#20077)
Arvin Xu1b8eea1dfe6e
diff --git a/packages/builtin-tool-agent-documents/src/manifest.ts b/packages/builtin-tool-agent-documents/src/manifest.tsindex b5a440a585f..786e518d3b4 100644--- a/packages/builtin-tool-agent-documents/src/manifest.ts+++ b/packages/builtin-tool-agent-documents/src/manifest.ts@@ -254,7 +254,7 @@ export const AgentDocumentsManifest: BuiltinToolManifest = {},sourceType: {default: 'all',- description: `Filter by document source within this agent-document system (unrelated to the user's resource library uploads). "file" = documents authored/edited directly as agent documents; "web" = crawled from external URLs; "all" returns both. Web-crawled documents are hidden from the default agent_documents_index β pass sourceType="web" here to see them.`,+ description: `Filter by document source within this agent-document system (unrelated to the user's resource library uploads). "file" = every non-web agent document (authored or edited as agent documents, plus uploaded originals); "web" = crawled from external URLs; "all" returns both. Web-crawled documents are hidden from the default agent_documents_index β pass sourceType="web" here to see them.`,enum: ['all', 'file', 'web'],type: 'string',},diff --git a/packages/database/src/models/agentDocuments/__tests__/agentDocument.test.ts b/packages/database/src/models/agentDocuments/__tests__/agentDocument.test.tsindex b904b950e76..e1dece1b0e2 100644--- a/packages/database/src/models/agentDocuments/__tests__/agentDocument.test.ts+++ b/packages/database/src/models/agentDocuments/__tests__/agentDocument.test.ts@@ -1000,6 +1000,30 @@ describe('AgentDocumentModel', () => {expect(nonWeb.map((item) => item.filename)).toEqual(['file.md']);});+ it('should include agent-authored docs when filtering by the "file" source type', async () => {+ // `create` defaults to the `agent` source type β that is how every+ // createDocument / Portal doc is stored. The tool contract defines+ // sourceType="file" as "documents authored or edited as agent documents",+ // so it has to cover them, not only uploaded originals (`file`).+ const authored = await agentDocumentModel.create(agentId, 'daily-report.md', 'report');+ await agentDocumentModel.create(agentId, 'upload.pdf', 'parsed pdf', { sourceType: 'file' });+ await agentDocumentModel.create(agentId, 'web-page', 'web content', {+ fileType: 'article',+ sourceType: 'web',+ });++ const fileOnly = await agentDocumentModel.listByAgent(agentId, { sourceType: 'file' });+ expect(fileOnly.map((item) => item.filename).sort()).toEqual([+ 'daily-report.md',+ 'upload.pdf',+ ]);++ const byIds = await agentDocumentModel.listByDocumentIds(agentId, [authored.documentId], {+ sourceType: 'file',+ });+ expect(byIds.map((item) => item.filename)).toEqual(['daily-report.md']);+ });+it('should return only skill-managed docs for skill registry assembly', async () => {const bundle = await agentDocumentModel.create(agentId, 'bug-triage', 'bundle body', {fileType: SKILL_BUNDLE_FILE_TYPE,diff --git a/packages/database/src/models/agentDocuments/agentDocument.ts b/packages/database/src/models/agentDocuments/agentDocument.tsindex 234627356af..343e67bcb1e 100644--- a/packages/database/src/models/agentDocuments/agentDocument.ts+++ b/packages/database/src/models/agentDocuments/agentDocument.ts@@ -105,6 +105,20 @@ interface AgentDocumentListQueryRow {updatedAt: Date;}+/**+ * Map the list API's source filter onto `documents.source_type`.+ *+ * The list contract has two buckets: `web` (crawled pages) and `file` (everything+ * authored or uploaded as an agent document). Authored docs are stored as+ * `agent` / `agent-signal` / `api`, so `file` means "not web" rather than the+ * literal `file` source type, which only covers uploaded originals.+ */+const listSourceTypeFilter = (sourceType?: AgentDocumentListSourceType) => {+ if (sourceType === 'web') return [eq(documents.sourceType, 'web')];+ if (sourceType === 'file') return [ne(documents.sourceType, 'web')];+ return [];+};+export class AgentDocumentModel {private userId: string;private workspaceId?: string;@@ -1137,7 +1151,7 @@ export class AgentDocumentModel {this.agentDocOwnership(),eq(agentDocuments.agentId, agentId),isNull(agentDocuments.deletedAt),- ...(sourceType && sourceType !== 'all' ? [eq(documents.sourceType, sourceType)] : []),+ ...listSourceTypeFilter(sourceType),...(excludeWeb ? [ne(documents.sourceType, 'web')] : []),...(parentId ? [eq(documents.parentId, parentId)] : []),),@@ -1323,7 +1337,7 @@ export class AgentDocumentModel {eq(agentDocuments.agentId, agentId),inArray(agentDocuments.documentId, documentIds),isNull(agentDocuments.deletedAt),- ...(sourceType && sourceType !== 'all' ? [eq(documents.sourceType, sourceType)] : []),+ ...listSourceTypeFilter(sourceType),),).orderBy(desc(agentDocuments.updatedAt));