π€― 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(resource): stop agent artifacts from flooding user resource listings (#19215)
Arvin Xuf7103947cff1
diff --git a/apps/server/src/services/toolExecution/serverRuntimes/lobeAgentPlan.ts b/apps/server/src/services/toolExecution/serverRuntimes/lobeAgentPlan.tsindex c207d265b09..13dd7ebdc5f 100644--- a/apps/server/src/services/toolExecution/serverRuntimes/lobeAgentPlan.ts+++ b/apps/server/src/services/toolExecution/serverRuntimes/lobeAgentPlan.ts@@ -1,5 +1,5 @@import { type PlanDocument, type PlanRuntimeService } from '@lobechat/builtin-tool-lobe-agent';-import { AGENT_PLAN_FILE_TYPE } from '@lobechat/const';+import { AGENT_DOCUMENT_SOURCE_TYPE, AGENT_PLAN_FILE_TYPE } from '@lobechat/const';import { type LobeChatDatabase } from '@lobechat/database';import { DocumentModel } from '@/database/models/document';@@ -52,17 +52,22 @@ export const createServerPlanRuntimeService = (description,fileType: AGENT_PLAN_FILE_TYPE,source: `lobe-agent:${topicId}`,- sourceType: 'api',+ // A plan is a machine-generated artifact; 'api' would make it+ // indistinguishable from a user-authored Page in resource listings.+ sourceType: AGENT_DOCUMENT_SOURCE_TYPE,title: goal,totalCharCount: content.length,totalLineCount: content.split('\n').length,// Private-agent plans stay in the owner's private Pages; public// agents' plans stay visible to the workspace. When null (no agent- // context resolvable), fall through to `DocumentModel.create`'s- // existing `sourceType='api'` fallback (β private in workspace mode).+ // context resolvable) default workspace plans to private β the+ // `sourceType='api'` fallback in `DocumentModel.create` that used to+ // cover this no longer applies to 'agent' rows....(callerAgentVisibility === 'private' || callerAgentVisibility === 'public'? { visibility: callerAgentVisibility }- : {}),+ : workspaceId+ ? { visibility: 'private' as const }+ : {}),});await topicDocumentModel.associate({ documentId: doc.id, topicId });diff --git a/packages/const/src/agentDocument.ts b/packages/const/src/agentDocument.tsindex 2029d94b97f..56c0fcf63f1 100644--- a/packages/const/src/agentDocument.ts+++ b/packages/const/src/agentDocument.ts@@ -24,5 +24,21 @@ export const EDITOR_DOCUMENT_SOURCE_TYPES = [DERIVED_DOCUMENT_SOURCE_TYPE,];+/**+ * `documents.source_type` values machine-generated rows carry. User-facing+ * page/resource listings exclude these by default so agent working artifacts+ * (tool outputs, skill bundles) don't flood the library.+ */+export const AGENT_ARTIFACT_SOURCE_TYPES = ['agent', 'agent-signal'] as const;++/**+ * `documents.source_type` values a user-authored Page row carries in the DB.+ * `DocumentSourceType.EDITOR` ('editor') is stamped client-side on in-memory+ * drafts only and never reaches the database β keep it out of SQL filters.+ */+export const PAGE_DOCUMENT_SOURCE_TYPES: string[] = ['file', 'api'];++export const PAGE_DOCUMENT_FILE_TYPES: string[] = [CUSTOM_DOCUMENT_FILE_TYPE, 'application/pdf'];+export const hasFilenameExtension = (filename: string): boolean =>/(?:^|[^.])\.[^.]+$/.test(filename);diff --git a/packages/database/src/models/document.ts b/packages/database/src/models/document.tsindex a9addc0fc70..4b78a7f4c75 100644--- a/packages/database/src/models/document.ts+++ b/packages/database/src/models/document.ts@@ -1,3 +1,4 @@+import { AGENT_ARTIFACT_SOURCE_TYPES } from '@lobechat/const';import { and, asc, count, desc, eq, inArray, isNull, ne, notInArray, or, sum } from 'drizzle-orm';import type { DocumentItem, NewDocument } from '../schemas';@@ -175,7 +176,7 @@ export class DocumentModel {),);} else {- conditions.push(notInArray(documents.sourceType, ['agent', 'agent-signal']));+ conditions.push(notInArray(documents.sourceType, [...AGENT_ARTIFACT_SOURCE_TYPES]));}const whereCondition = and(...conditions);diff --git a/packages/database/src/repositories/knowledge/index.ts b/packages/database/src/repositories/knowledge/index.tsindex 0bc83205d30..6f335779ff0 100644--- a/packages/database/src/repositories/knowledge/index.ts+++ b/packages/database/src/repositories/knowledge/index.ts@@ -1,4 +1,5 @@import {+ AGENT_ARTIFACT_SOURCE_TYPES,CUSTOM_DOCUMENT_FILE_TYPE,CUSTOM_FOLDER_FILE_TYPE,MARKDOWN_MIME_TYPES,@@ -404,10 +405,18 @@ export class KnowledgeRepo {.where(and(this.fileScope(sourceFilter), ...where));};+ /**+ * `includeAgentArtifacts` is the only opt-out from hiding machine-generated+ * rows (`agent` / `agent-signal`): a knowledge-base listing shows exactly the+ * rows the user filed into that base, agent artifacts included. Every other+ * listing keeps them out β they are working files of the agent runtime, not+ * library content, and they arrive by the hundreds.+ */private documentArm = (where: (SQL | undefined)[],includeContent: boolean = true,includeContentPreview: boolean = false,+ includeAgentArtifacts: boolean = false,) =>this.db.select(@@ -415,7 +424,16 @@ export class KnowledgeRepo {).from(d).leftJoin(users, eq(users.id, d.userId))- .where(and(this.documentScope(), ne(d.sourceType, 'file'), ...where));+ .where(+ and(+ this.documentScope(),+ ne(d.sourceType, 'file'),+ includeAgentArtifacts+ ? undefined+ : notInArray(d.sourceType, [...AGENT_ARTIFACT_SOURCE_TYPES]),+ ...where,+ ),+ );/*** Query combined results from files and documents tables@@ -501,6 +519,7 @@ export class KnowledgeRepo {],includeContent,includeContentPreview,+ Boolean(knowledgeBaseId),);const rows = await unionAll(fileArm, documentArm)diff --git a/src/services/document/index.ts b/src/services/document/index.tsindex 249c5f0730c..8f970385079 100644--- a/src/services/document/index.ts+++ b/src/services/document/index.ts@@ -1,4 +1,4 @@-import { CUSTOM_DOCUMENT_FILE_TYPE } from '@lobechat/const';+import { PAGE_DOCUMENT_FILE_TYPES, PAGE_DOCUMENT_SOURCE_TYPES } from '@lobechat/const';import { type DocumentItem } from '@lobechat/database/schemas';import { lambdaClient } from '@/libs/trpc/client';@@ -185,16 +185,16 @@ export class DocumentService {async getPageDocuments(pageSize: number = 20): Promise<DocumentItem[]> {const result = await this.queryDocuments({current: 0,- fileTypes: [CUSTOM_DOCUMENT_FILE_TYPE, 'application/pdf'],+ fileTypes: PAGE_DOCUMENT_FILE_TYPES,pageSize,- sourceTypes: ['editor', 'file', 'api'],+ sourceTypes: PAGE_DOCUMENT_SOURCE_TYPES,});return result.items.filter((doc) =>- ['editor', 'file', 'api'].includes(doc.sourceType) &&- [CUSTOM_DOCUMENT_FILE_TYPE, 'application/pdf'].includes(doc.fileType),+ PAGE_DOCUMENT_SOURCE_TYPES.includes(doc.sourceType) &&+ PAGE_DOCUMENT_FILE_TYPES.includes(doc.fileType),).map((doc) => ({ ...doc, filename: doc.filename ?? doc.title ?? 'Untitled' }));}diff --git a/src/store/file/slices/document/action.ts b/src/store/file/slices/document/action.tsindex 6cbbc46b55f..a38f4f30912 100644--- a/src/store/file/slices/document/action.ts+++ b/src/store/file/slices/document/action.ts@@ -2,6 +2,8 @@ import {CUSTOM_DOCUMENT_FILE_TYPE,CUSTOM_FOLDER_FILE_TYPE,DERIVED_DOCUMENT_SOURCE_TYPE,+ PAGE_DOCUMENT_FILE_TYPES,+ PAGE_DOCUMENT_SOURCE_TYPES,} from '@lobechat/const';import { createNanoId } from '@lobechat/utils';import { type SWRResponse } from 'swr';@@ -21,8 +23,12 @@ import { type DocumentQueryFilter } from './initialState';const n = setNamespace('document');-const ALLOWED_DOCUMENT_SOURCE_TYPES = new Set(['editor', 'file', 'api']);-const ALLOWED_DOCUMENT_FILE_TYPES = new Set([CUSTOM_DOCUMENT_FILE_TYPE, 'application/pdf']);+// EDITOR is a client-only stamp on in-memory drafts; DB rows never carry it.+const ALLOWED_DOCUMENT_SOURCE_TYPES = new Set([+ DocumentSourceType.EDITOR as string,+ ...PAGE_DOCUMENT_SOURCE_TYPES,+]);+const ALLOWED_DOCUMENT_FILE_TYPES = new Set(PAGE_DOCUMENT_FILE_TYPES);const EDITOR_DOCUMENT_FILE_TYPE = CUSTOM_DOCUMENT_FILE_TYPE;interface ResourceDocumentSnapshot {@@ -437,8 +443,8 @@ export class DocumentActionImpl {const pageSize = useGlobalStore.getState().status.pagePageSize || 20;const queryFilters: DocumentQueryFilter | undefined = pageOnly? {- fileTypes: Array.from(ALLOWED_DOCUMENT_FILE_TYPES),- sourceTypes: Array.from(ALLOWED_DOCUMENT_SOURCE_TYPES),+ fileTypes: PAGE_DOCUMENT_FILE_TYPES,+ sourceTypes: PAGE_DOCUMENT_SOURCE_TYPES,}: undefined;diff --git a/src/store/page/slices/list/action.ts b/src/store/page/slices/list/action.tsindex 6283c2b6df1..3be7ab9b832 100644--- a/src/store/page/slices/list/action.ts+++ b/src/store/page/slices/list/action.ts@@ -1,4 +1,4 @@-import { CUSTOM_DOCUMENT_FILE_TYPE } from '@lobechat/const';+import { PAGE_DOCUMENT_FILE_TYPES, PAGE_DOCUMENT_SOURCE_TYPES } from '@lobechat/const';import { type DocumentItem } from '@lobechat/database/schemas';import { type SWRResponse } from 'swr';@@ -36,8 +36,12 @@ const documentItemToLobeDocument = (document: DocumentItem): LobeDocument => ({const n = setNamespace('page/list');-const ALLOWED_PAGE_SOURCE_TYPES = new Set(['editor', 'file', 'api']);-const ALLOWED_PAGE_FILE_TYPES = new Set([CUSTOM_DOCUMENT_FILE_TYPE, 'application/pdf']);+// EDITOR is a client-only stamp on in-memory drafts; DB rows never carry it.+const ALLOWED_PAGE_SOURCE_TYPES = new Set([+ DocumentSourceType.EDITOR as string,+ ...PAGE_DOCUMENT_SOURCE_TYPES,+]);+const ALLOWED_PAGE_FILE_TYPES = new Set(PAGE_DOCUMENT_FILE_TYPES);/*** Check if a page should be displayed in the page list