Skip to content

🀯 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.

πŸ› fix(resource): link pages and files to their Docs routes (#21912)

Arvin Xu2b41f6dab9f3
diff --git a/apps/cli/src/commands/doc.test.ts b/apps/cli/src/commands/doc.test.ts
index bd9ba5c51f6..97c540ce72f 100644
--- a/apps/cli/src/commands/doc.test.ts
+++ b/apps/cli/src/commands/doc.test.ts
@@ -108,7 +108,11 @@ describe('doc command', () => {
await program.parseAsync(['node', 'test', 'doc', 'list', '--json']);
expect(consoleSpy).toHaveBeenCalledWith(
- JSON.stringify([{ ...docs[0], url: 'https://app.lobehub.com/page/doc1' }], null, 2),
+ JSON.stringify(
+ [{ ...docs[0], url: 'https://app.lobehub.com/resource/page/doc1' }],
+ null,
+ 2,
+ ),
);
});
@@ -213,7 +217,7 @@ describe('doc command', () => {
expect(consoleSpy).toHaveBeenCalledWith(
JSON.stringify(
- { ...doc, url: 'https://app.lobehub.com/resource/library/kb1?file=doc1' },
+ { ...doc, url: 'https://app.lobehub.com/resource/library/kb1/file/doc1' },
null,
2,
),
@@ -680,7 +684,11 @@ describe('doc command', () => {
await program.parseAsync(['node', 'test', 'doc', 'topic-docs', 'topic_123', '--json']);
expect(consoleSpy).toHaveBeenCalledWith(
- JSON.stringify([{ ...docs[0], url: 'https://app.lobehub.com/page/doc1' }], null, 2),
+ JSON.stringify(
+ [{ ...docs[0], url: 'https://app.lobehub.com/resource/page/doc1' }],
+ null,
+ 2,
+ ),
);
});
diff --git a/apps/cli/src/commands/doc.ts b/apps/cli/src/commands/doc.ts
index e68c4a66968..0cbf4c84570 100644
--- a/apps/cli/src/commands/doc.ts
+++ b/apps/cli/src/commands/doc.ts
@@ -164,10 +164,9 @@ export function registerDocCommand(program: Command) {
slug: options.slug,
title: options.title,
});
- const pathname = options.kb
- ? `/resource/library/${encodeURIComponent(options.kb)}?file=${encodeURIComponent(result.id)}`
- : `/page/${encodeURIComponent(result.id)}`;
- const url = buildUrl(pathname);
+ const url = buildUrl(
+ resourcePath.document({ id: result.id, knowledgeBaseId: options.kb })!,
+ );
console.log(`${pc.green('βœ“')} Created document ${pc.bold(result.id)}`);
console.log(`${pc.bold('document')}: ${url}`);
@@ -219,10 +218,9 @@ export function registerDocCommand(program: Command) {
const urls = await Promise.all(
created.map((document, index) => {
const source = items[index];
- const pathname = source?.knowledgeBaseId
- ? `/resource/library/${encodeURIComponent(source.knowledgeBaseId)}?file=${encodeURIComponent(document.id)}`
- : `/page/${encodeURIComponent(document.id)}`;
- return buildUrl(pathname);
+ return buildUrl(
+ resourcePath.document({ id: document.id, knowledgeBaseId: source?.knowledgeBaseId })!,
+ );
}),
);
console.log(`${pc.green('βœ“')} Created ${created.length} document(s)`);
diff --git a/apps/cli/src/commands/kb.ts b/apps/cli/src/commands/kb.ts
index da57be7e07c..287a82c7fd2 100644
--- a/apps/cli/src/commands/kb.ts
+++ b/apps/cli/src/commands/kb.ts
@@ -306,9 +306,7 @@ export function registerKbCommand(program: Command) {
parentId: options.parent,
title: options.title,
});
- const url = buildUrl(
- `/resource/library/${encodeURIComponent(knowledgeBaseId)}?file=${encodeURIComponent((result as any).id)}`,
- );
+ const url = buildUrl(resourcePath.document({ id: (result as any).id, knowledgeBaseId })!);
console.log(`${pc.green('βœ“')} Created document ${pc.bold((result as any).id)}`);
console.log(`${pc.bold('document')}: ${url}`);
},
diff --git a/apps/cli/src/commands/resourceUrl.test.ts b/apps/cli/src/commands/resourceUrl.test.ts
index 6bcaf9202ca..28c67d00213 100644
--- a/apps/cli/src/commands/resourceUrl.test.ts
+++ b/apps/cli/src/commands/resourceUrl.test.ts
@@ -30,10 +30,10 @@ describe('resourcePath', () => {
'/group/grp_1/tpc_1#msg_1',
],
[resourcePath.message({ groupId: 'grp_1', id: 'msg_1' }), '/group/grp_1#msg_1'],
- [resourcePath.document({ id: 'docs_1' }), '/page/docs_1'],
+ [resourcePath.document({ id: 'docs_1' }), '/resource/page/docs_1'],
[
resourcePath.document({ id: 'docs_1', knowledgeBaseId: 'kb_1' }),
- '/resource/library/kb_1?file=docs_1',
+ '/resource/library/kb_1/docs/docs_1',
],
[resourcePath.file({ id: 'file_1' }), '/resource/file/file_1'],
[resourcePath.dashboard({ id: 'dsh_1', projectId: 'prj_1' }), '/project/prj_1/dashboard/dsh_1'],
diff --git a/apps/cli/src/commands/resourceUrl.ts b/apps/cli/src/commands/resourceUrl.ts
index 3c1a3536736..4d6ae1933e2 100644
--- a/apps/cli/src/commands/resourceUrl.ts
+++ b/apps/cli/src/commands/resourceUrl.ts
@@ -11,8 +11,13 @@ type Id = string | null | undefined;
const seg = (value: string) => encodeURIComponent(value);
+/** Library items are addressed inside their library: `…/library/<kb>/{docs,file}/<id>`. */
const libraryItemPath = (id: string, knowledgeBaseId: Id) =>
- `/resource/library/${seg(knowledgeBaseId!)}?file=${seg(id)}`;
+ `/resource/library/${seg(knowledgeBaseId!)}/${id.startsWith('docs_') ? 'docs' : 'file'}/${seg(id)}`;
+
+/** Standalone pages and files open in Docs; `/page/:id` and `/resource/file/` only redirect there. */
+const docsPagePath = (id: string) => `/resource/page/${seg(id)}`;
+const docsFilePath = (id: string) => `/resource/file/${seg(id)}`;
export const resourcePath = {
acceptance: (id: Id) => (id ? `/acceptance/${seg(id)}` : undefined),
@@ -28,14 +33,14 @@ export const resourcePath = {
if (!doc.id) return undefined;
return doc.knowledgeBaseId
? libraryItemPath(doc.id, doc.knowledgeBaseId)
- : `/page/${seg(doc.id)}`;
+ : docsPagePath(doc.id);
},
/** A library file opens inside its library, else in Docs at `/resource/file/<id>`. */
file: (file: { id?: Id; knowledgeBaseId?: Id }) => {
if (!file.id) return undefined;
return file.knowledgeBaseId
? libraryItemPath(file.id, file.knowledgeBaseId)
- : `/resource/file/${seg(file.id)}`;
+ : docsFilePath(file.id);
},
goal: (id: Id) => (id ? `/goal/${seg(id)}` : undefined),
group: (id: Id) => (id ? `/group/${seg(id)}` : undefined),
@@ -83,7 +88,7 @@ export const searchResultPath = (item: Record<string, any>): string | undefined
return resourcePath.file(item);
}
case 'page': {
- return item.id ? `/page/${seg(item.id)}` : undefined;
+ return item.id ? docsPagePath(item.id) : undefined;
}
case 'knowledgeBase': {
return resourcePath.knowledgeBase(item.id);
diff --git a/apps/server/src/routers/lambda/recent.ts b/apps/server/src/routers/lambda/recent.ts
index 1708bfcd690..7a037a74595 100644
--- a/apps/server/src/routers/lambda/recent.ts
+++ b/apps/server/src/routers/lambda/recent.ts
@@ -63,7 +63,7 @@ export const recentRouter = router({
break;
}
case 'document': {
- routePath = `/page/${item.id}`;
+ routePath = `/resource/page/${item.id}`;
break;
}
case 'task': {
diff --git a/packages/prompts/src/prompts/workspaceContext/index.test.ts b/packages/prompts/src/prompts/workspaceContext/index.test.ts
index fea284a8bc4..4fb767aa205 100644
--- a/packages/prompts/src/prompts/workspaceContext/index.test.ts
+++ b/packages/prompts/src/prompts/workspaceContext/index.test.ts
@@ -45,7 +45,7 @@ describe('workspaceContextPrompt', () => {
expect(result).toContain('<workspace_slug>acme</workspace_slug>');
expect(result).not.toContain('<app_url>');
expect(result).toContain('<link_base>/acme</link_base>');
- expect(result).toContain('page (workspace document): /acme/page/<documentId>');
+ expect(result).toContain('page (workspace document): /acme/resource/page/<documentId>');
});
it('describes the personal scope when there is no workspace', () => {
diff --git a/packages/prompts/src/prompts/workspaceContext/index.ts b/packages/prompts/src/prompts/workspaceContext/index.ts
index 2fa7d64c4bb..21713cc836e 100644
--- a/packages/prompts/src/prompts/workspaceContext/index.ts
+++ b/packages/prompts/src/prompts/workspaceContext/index.ts
@@ -33,7 +33,8 @@ const ROUTE_HINTS: [label: string, path: string][] = [
['agent chat', '/agent/<agentId>'],
['agent task detail', '/agent/<agentId>/task/<taskIdentifier>'],
['agent document', '/agent/<agentId>/docs/<docId>'],
- ['page (workspace document)', '/page/<documentId>'],
+ ['page (workspace document)', '/resource/page/<documentId>'],
+ ['uploaded file', '/resource/file/<fileId>'],
['knowledge base', '/resource/library/<knowledgeBaseId>'],
];
diff --git a/src/features/CommandMenu/SearchResults.tsx b/src/features/CommandMenu/SearchResults.tsx
index 601c5f506c6..aec932c0d6f 100644
--- a/src/features/CommandMenu/SearchResults.tsx
+++ b/src/features/CommandMenu/SearchResults.tsx
@@ -25,6 +25,7 @@ import AgentAvatar from '@/components/AgentAvatar';
import type { FtsSearchResult } from '@/database/repositories/ftsSearch';
import { taskDetailPath } from '@/features/AgentTasks/shared/taskDetailPath';
import { useCommandMenuContext } from '@/features/CommandMenu/CommandMenuContext';
+import { docsFilePath, docsPagePath } from '@/features/ResourceHome/paths';
import { libraryFolderPath, libraryItemPath } from '@/features/ResourceManager/utils/resourcePath';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { useImageStore } from '@/store/image';
@@ -125,7 +126,7 @@ const SearchResults = memo<SearchResultsProps>(
// Open the file inside its library, or over the Docs home
const fileUrl = result.knowledgeBaseId
? libraryItemPath(result.knowledgeBaseId, result.id)
- : `/resource?file=${result.id}`;
+ : docsFilePath(result.id);
console.info('[SearchResults] File navigation:', {
fileDetails: result,
url: fileUrl,
@@ -143,7 +144,7 @@ const SearchResults = memo<SearchResultsProps>(
break;
}
case 'page': {
- navigate(`/page/${result.id.split('_')[1]}`);
+ navigate(docsPagePath(result.id));
break;
}
case 'mcp': {
diff --git a/src/features/DocumentModal/url.test.ts b/src/features/DocumentModal/url.test.ts
index c3ac8e663ce..4328bf6b174 100644
--- a/src/features/DocumentModal/url.test.ts
+++ b/src/features/DocumentModal/url.test.ts
@@ -5,13 +5,13 @@ import { buildDocumentModalUrl } from './url';
describe('buildDocumentModalUrl', () => {
it('builds a canonical personal page URL independently of the current route', () => {
expect(buildDocumentModalUrl('https://example.com', 'doc-1')).toBe(
- 'https://example.com/page/doc-1',
+ 'https://example.com/resource/page/doc-1',
);
});
it('includes the active workspace slug', () => {
expect(buildDocumentModalUrl('https://example.com', 'doc-1', 'acme')).toBe(
- 'https://example.com/acme/page/doc-1',
+ 'https://example.com/acme/resource/page/doc-1',
);
});
});
diff --git a/src/features/DocumentModal/url.ts b/src/features/DocumentModal/url.ts
index ad7cdcb7d1a..de2376ac048 100644
--- a/src/features/DocumentModal/url.ts
+++ b/src/features/DocumentModal/url.ts
@@ -1,3 +1,4 @@
+import { docsPagePath } from '@/features/ResourceHome/paths';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
export const buildDocumentModalUrl = (
@@ -5,6 +6,6 @@ export const buildDocumentModalUrl = (
documentId: string,
activeWorkspaceSlug?: string | null,
) => {
- const path = buildWorkspaceAwarePath(`/page/${documentId}`, activeWorkspaceSlug);
+ const path = buildWorkspaceAwarePath(docsPagePath(documentId), activeWorkspaceSlug);
return `${appOrigin}${path}`;
};
diff --git a/src/features/HomeSidebar/hooks/useCreateMenuItems.tsx b/src/features/HomeSidebar/hooks/useCreateMenuItems.tsx
index 129c2404f76..52004ecfb0e 100644
--- a/src/features/HomeSidebar/hooks/useCreateMenuItems.tsx
+++ b/src/features/HomeSidebar/hooks/useCreateMenuItems.tsx
@@ -19,6 +19,7 @@ import { useGroupTemplates } from '@/components/ChatGroupWizard/templates';
import { DEFAULT_CHAT_GROUP_CHAT_CONFIG } from '@/const/settings';
import { openConnectAgentModal } from '@/features/ConnectAgent';
import { useOptionalAgentModal } from '@/features/HomeSidebar/Body/Agent/ModalProvider';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { usePermission } from '@/hooks/usePermission';
import type { CreateAgentParams } from '@/services/agent';
@@ -412,7 +413,7 @@ export const useCreateMenuItems = () => {
const untitledTitle = tFile('pageList.untitled');
try {
const newPageId = await pageActions.createNewPage(untitledTitle);
- navigate(`/page/${newPageId}`);
+ navigate(docsPagePath(newPageId));
} catch (error) {
console.error('Failed to create page:', error);
toast.error(tFile('pageList.createFailed'));
diff --git a/src/features/LibraryModal/AssignKnowledgeBase/Item/Action.tsx b/src/features/LibraryModal/AssignKnowledgeBase/Item/Action.tsx
index b93a648be6f..0338fb6756f 100644
--- a/src/features/LibraryModal/AssignKnowledgeBase/Item/Action.tsx
+++ b/src/features/LibraryModal/AssignKnowledgeBase/Item/Action.tsx
@@ -4,7 +4,7 @@ import { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
-import { buildLibraryPath, buildPagePath } from '@/features/ResourceManager/utils/resourcePath';
+import { buildFilePath, buildLibraryPath } from '@/features/ResourceManager/utils/resourcePath';
import { useAgentStore } from '@/store/agent';
import { useServerConfigStore } from '@/store/serverConfig';
import { KnowledgeType } from '@/types/knowledgeBase';
@@ -68,7 +68,7 @@ const Actions = memo<ActionsProps>(({ id, type, enabled }) => {
window.open(
type === KnowledgeType.KnowledgeBase
? buildLibraryPath(id, activeWorkspaceSlug)
- : buildPagePath(id, activeWorkspaceSlug),
+ : buildFilePath(id, activeWorkspaceSlug),
);
},
},
diff --git a/src/features/MemoryRules/DetailPanel.tsx b/src/features/MemoryRules/DetailPanel.tsx
index 5dc28b80ad4..540bcbed2e4 100644
--- a/src/features/MemoryRules/DetailPanel.tsx
+++ b/src/features/MemoryRules/DetailPanel.tsx
@@ -36,6 +36,7 @@ import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
+import { docsFilePath, docsPagePath } from '@/features/ResourceHome/paths';
import RightPanel from '@/features/RightPanel';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
import type { RuleGroup, RuleItem, UpdateRuleInput } from '@/services/expertise';
@@ -577,8 +578,8 @@ const RuleDocument = ({
className={styles.link}
href={buildWorkspaceAwarePath(
source.documentFileId
- ? `/resource?file=${source.documentFileId}`
- : `/page/${source.documentId}`,
+ ? docsFilePath(source.documentFileId)
+ : docsPagePath(source.documentId),
workspaceSlug,
)}
onClick={(e) => {
diff --git a/src/features/PageExplorer/PageExplorerPlaceholder.tsx b/src/features/PageExplorer/PageExplorerPlaceholder.tsx
index 3e5d5c3892b..8489a3217f3 100644
--- a/src/features/PageExplorer/PageExplorerPlaceholder.tsx
+++ b/src/features/PageExplorer/PageExplorerPlaceholder.tsx
@@ -15,12 +15,12 @@ import React, { memo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import NavHeader from '@/features/NavHeader';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import useNotionImport from '@/features/ResourceManager/components/Header/hooks/useNotionImport';
import { usePermission } from '@/hooks/usePermission';
import { useFileStore } from '@/store/file';
import { pageActions } from '@/store/page';
import { DocumentSourceType } from '@/types/document';
-import { standardizeIdentifier } from '@/utils/identifier';
const ICON_SIZE = 80;
@@ -223,9 +223,7 @@ const PageExplorerPlaceholder = memo<PageExplorerPlaceholderProps>(
pageActions.setSelectedPageId(parsedDocument.id, false);
// Update URL with stripped ID (without prefix)
- const cleanId = standardizeIdentifier(parsedDocument.id);
- const newPath = cleanId ? `/page/${cleanId}` : '/page';
- window.history.replaceState({}, '', newPath);
+ window.history.replaceState({}, '', docsPagePath(parsedDocument.id));
} catch (error) {
console.error('Failed to upload and parse file:', error);
// Remove temp document on error
diff --git a/src/features/PagePermission/index.tsx b/src/features/PagePermission/index.tsx
index c47b2ba2ada..ac98842626f 100644
--- a/src/features/PagePermission/index.tsx
+++ b/src/features/PagePermission/index.tsx
@@ -4,6 +4,7 @@ import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import ResourceAccessPage from '@/features/ResourcePermission/ResourceAccessPage';
import { pageActions, pageSelectors, usePageStore } from '@/store/page';
@@ -25,8 +26,8 @@ const PagePermission = memo(() => {
return (
<ResourceAccessPage
- redirectPath={`/page/${id}`}
- resourceHomePath={`/page/${id}`}
+ redirectPath={docsPagePath(id)}
+ resourceHomePath={docsPagePath(id)}
resourceId={id}
resourceName={title}
resourceType={'document'}
diff --git a/src/features/Pages/PageLayout/Body/List/Item/index.tsx b/src/features/Pages/PageLayout/Body/List/Item/index.tsx
index 8f8a5238bcb..196b6fce2b4 100644
--- a/src/features/Pages/PageLayout/Body/List/Item/index.tsx
+++ b/src/features/Pages/PageLayout/Body/List/Item/index.tsx
@@ -9,6 +9,7 @@ import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspace
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
import { isDesktop } from '@/const/version';
import NavItem from '@/features/NavPanel/components/NavItem';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
import { useElectronStore } from '@/store/electron';
import { pageActions, pageSelectors, usePageStore } from '@/store/page';
@@ -96,7 +97,7 @@ const PageListItem = memo<DocumentItemProps>(({ pageId, className }) => {
clearTimeout(clickTimerRef.current);
clickTimerRef.current = null;
}
- addTab(buildWorkspaceAwarePath(`/page/${pageId}`, activeWorkspaceSlug));
+ addTab(buildWorkspaceAwarePath(docsPagePath(pageId), activeWorkspaceSlug));
pageActions.selectPage(pageId);
}, [pageId, activeWorkspaceSlug, addTab]);
@@ -121,7 +122,7 @@ const PageListItem = memo<DocumentItemProps>(({ pageId, className }) => {
className={className}
contextMenuItems={dropdownMenu}
disabled={editing}
- href={`/page/${pageId}`}
+ href={docsPagePath(pageId)}
icon={icon}
key={pageId}
title={
diff --git a/src/features/Pages/PageLayout/Body/List/Item/useDropdownMenu.tsx b/src/features/Pages/PageLayout/Body/List/Item/useDropdownMenu.tsx
index 9588861c4e3..66bcc8a00a8 100644
--- a/src/features/Pages/PageLayout/Body/List/Item/useDropdownMenu.tsx
+++ b/src/features/Pages/PageLayout/Body/List/Item/useDropdownMenu.tsx
@@ -8,6 +8,7 @@ import { useActiveWorkspaceId } from '@/business/client/hooks/useActiveWorkspace
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
import { useDocumentTransferMenuItem } from '@/business/client/hooks/useDocumentTransferMenuItem';
import { isDesktop } from '@/const/version';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import VisibilityConfirmContent from '@/features/VisibilityConfirmContent';
import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
@@ -37,12 +38,10 @@ interface MenuClickInfo {
* rename field with it β€” before anything can be typed, which is why "Rename"
* appeared to do nothing. Close the handler over the row and stop the event.
*/
-const stopRowClick =
- (run: () => void) =>
- (info?: MenuClickInfo) => {
- info?.domEvent?.stopPropagation();
- run();
- };
+const stopRowClick = (run: () => void) => (info?: MenuClickInfo) => {
+ info?.domEvent?.stopPropagation();
+ run();
+};
/**
* Business builds inject their own transfer entries (Move to a library, …).
@@ -165,7 +164,7 @@ export const useDropdownMenu = ({ pageId, toggleEditing }: ActionProps): (() =>
key: 'openInNewTab',
label: t('pageList.actions.openInNewTab', { ns: 'file' }),
onClick: stopRowClick(() => {
- const url = buildWorkspaceAwarePath(`/page/${pageId}`, activeWorkspaceSlug);
+ const url = buildWorkspaceAwarePath(docsPagePath(pageId), activeWorkspaceSlug);
addTab(url);
navigate(url, { escape: true });
}),
diff --git a/src/features/Portal/Document/usePortalDocumentHeader.test.ts b/src/features/Portal/Document/usePortalDocumentHeader.test.ts
index a122da38f68..12559c71d9e 100644
--- a/src/features/Portal/Document/usePortalDocumentHeader.test.ts
+++ b/src/features/Portal/Document/usePortalDocumentHeader.test.ts
@@ -328,8 +328,8 @@ describe('usePortalDocumentHeaderActions', () => {
// The agent docs route redirects unowned ids to its index, so the link
// must not point there.
- expect(result.current.path).toBe('/page/document-1');
- expect(result.current.url).toBe('https://app.lobehub.com/page/document-1');
+ expect(result.current.path).toBe('/resource/page/document-1');
+ expect(result.current.url).toBe('https://app.lobehub.com/resource/page/document-1');
});
it('refresh revalidates the document caches', async () => {
@@ -356,7 +356,7 @@ describe('usePortalDocumentHeaderActions', () => {
describe('resolvePortalDocumentPath', () => {
it('uses the agent docs route only for a bound document', () => {
expect(resolvePortalDocumentPath('docs_abc', 'agt_1', 'ad_1')).toBe('/agent/agt_1/docs/abc');
- expect(resolvePortalDocumentPath('docs_abc', 'agt_1', undefined)).toBe('/page/abc');
+ expect(resolvePortalDocumentPath('docs_abc', 'agt_1', undefined)).toBe('/resource/page/abc');
expect(resolvePortalDocumentPath(undefined, 'agt_1', 'ad_1')).toBeUndefined();
});
});
diff --git a/src/features/Portal/Document/usePortalDocumentHeader.ts b/src/features/Portal/Document/usePortalDocumentHeader.ts
index 11112a55d6b..bba5f2e01e4 100644
--- a/src/features/Portal/Document/usePortalDocumentHeader.ts
+++ b/src/features/Portal/Document/usePortalDocumentHeader.ts
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import { useActiveWorkspaceSlug } from '@/business/client/hooks/useActiveWorkspaceSlug';
import { buildAgentDocumentPath } from '@/features/AgentDocumentPage/navigation';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import { useAppOrigin } from '@/hooks/useAppOrigin';
import { useSingleton } from '@/hooks/useSingleton';
import { documentService } from '@/services/document';
@@ -13,7 +14,6 @@ import { invalidateDocumentMutation } from '@/services/document/invalidation';
import { useAgentStore } from '@/store/agent';
import { useDocumentStore } from '@/store/document';
import { getDocumentRenderMode } from '@/utils/documentRenderMode';
-import { standardizeIdentifier } from '@/utils/identifier';
import { isSkillMarkdownDocument } from '@/utils/skillMarkdown';
import { useResolvedAgentDocumentId, useResolvedDocumentId } from './documentViewContext';
@@ -117,7 +117,7 @@ export const resolvePortalDocumentPath = (
): string | undefined => {
if (!documentId) return undefined;
if (agentId && agentDocumentId) return buildAgentDocumentPath(agentId, documentId);
- return `/page/${standardizeIdentifier(documentId)}`;
+ return docsPagePath(documentId);
};
/**
diff --git a/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.test.tsx b/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.test.tsx
index 86fd2cdc3d7..0e45ed38d2a 100644
--- a/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.test.tsx
+++ b/src/features/ResourceManager/components/Explorer/ItemDropdown/useFileItemDropdown.test.tsx
@@ -130,7 +130,7 @@ describe('useFileItemDropdown β€” copy link', () => {
mocks.activeWorkspaceId = 'ws-1';
mocks.activeWorkspaceSlug = 'acme';
await expect(copyLink({ id: 'docs_abc' })).resolves.toBe(
- 'https://app.example.com/acme/resource?file=docs_abc',
+ 'https://app.example.com/acme/resource/page/abc',
);
});
@@ -144,7 +144,7 @@ describe('useFileItemDropdown β€” copy link', () => {
it('leaves the personal-scope page link unprefixed', async () => {
await expect(copyLink({ id: 'docs_abc' })).resolves.toBe(
- 'https://app.example.com/resource?file=docs_abc',
+ 'https://app.example.com/resource/page/abc',
);
});
diff --git a/src/features/ResourceManager/utils/resourcePath.test.ts b/src/features/ResourceManager/utils/resourcePath.test.ts
index b3eaff44fd1..c268328db18 100644
--- a/src/features/ResourceManager/utils/resourcePath.test.ts
+++ b/src/features/ResourceManager/utils/resourcePath.test.ts
@@ -1,6 +1,7 @@
import { describe, expect, it } from 'vitest';
import {
+ buildFilePath,
buildLibraryPath,
buildPagePath,
legacyLibraryItemRedirect,
@@ -25,9 +26,16 @@ describe('resourcePath', () => {
});
});
+ describe('buildFilePath', () => {
+ it('opens the file in Docs, inside the active workspace', () => {
+ expect(buildFilePath('file_1', 'acme')).toBe('/acme/resource/file/file_1');
+ expect(buildFilePath('file_1', null)).toBe('/resource/file/file_1');
+ });
+ });
+
describe('buildPagePath', () => {
it('prefixes the page path with the active workspace slug', () => {
- expect(buildPagePath('docs_abc', 'acme')).toBe('/acme/resource?file=docs_abc');
+ expect(buildPagePath('docs_abc', 'acme')).toBe('/acme/resource/page/abc');
});
it('keeps a library page inside the workspace', () => {
@@ -37,7 +45,7 @@ describe('resourcePath', () => {
});
it('leaves the personal-scope page path unprefixed', () => {
- expect(buildPagePath('docs_abc', null)).toBe('/resource?file=docs_abc');
+ expect(buildPagePath('docs_abc', null)).toBe('/resource/page/abc');
expect(buildPagePath('docs_abc', undefined, 'kb_1')).toBe(
'/resource/library/kb_1/docs/docs_abc',
);
diff --git a/src/features/ResourceManager/utils/resourcePath.ts b/src/features/ResourceManager/utils/resourcePath.ts
index eb302a73599..340b208095a 100644
--- a/src/features/ResourceManager/utils/resourcePath.ts
+++ b/src/features/ResourceManager/utils/resourcePath.ts
@@ -1,3 +1,4 @@
+import { docsFilePath, docsPagePath } from '@/features/ResourceHome/paths';
import { buildWorkspaceAwarePath } from '@/features/Workspace/workspaceAwarePath';
/**
@@ -61,7 +62,7 @@ export const buildLibraryPath = (
): string => buildWorkspaceAwarePath(`/resource/library/${libraryId}`, activeWorkspaceSlug);
/**
- * Path that opens a page: `/resource?file=<id>`, or the library-scoped
+ * Path that opens a page: `/resource/page/<id>`, or the library-scoped
* `/resource/library/<libraryId>/docs/<id>` when the page lives in a library.
*/
export const buildPagePath = (
@@ -70,6 +71,12 @@ export const buildPagePath = (
libraryId?: string | null,
): string =>
buildWorkspaceAwarePath(
- libraryId ? libraryItemPath(libraryId, fileId) : `/resource?file=${fileId}`,
+ libraryId ? libraryItemPath(libraryId, fileId) : docsPagePath(fileId),
activeWorkspaceSlug,
);
+
+/** Path that opens an uploaded file in Docs: `/resource/file/<id>`. */
+export const buildFilePath = (
+ fileId: string,
+ activeWorkspaceSlug: string | null | undefined,
+): string => buildWorkspaceAwarePath(docsFilePath(fileId), activeWorkspaceSlug);
diff --git a/src/store/home/slices/homeInput/action.test.ts b/src/store/home/slices/homeInput/action.test.ts
index fac92e5b5f6..944ce4e4ff2 100644
--- a/src/store/home/slices/homeInput/action.test.ts
+++ b/src/store/home/slices/homeInput/action.test.ts
@@ -378,7 +378,7 @@ describe('HomeInputActionImpl', () => {
await action.sendAsWrite({ message: 'write me a doc' });
expect(createDocumentMock).toHaveBeenCalled();
- expect(navigateMock).toHaveBeenCalledWith('/page/doc-new');
+ expect(navigateMock).toHaveBeenCalledWith('/resource/page/doc-new');
// The new editor has not mounted yet, so the doc id must travel in context
// explicitly rather than relying on the page editor runtime singleton.
expect(sendMessageMock).toHaveBeenCalledWith(
diff --git a/src/store/home/slices/homeInput/action.ts b/src/store/home/slices/homeInput/action.ts
index 172524b3659..77945ed0992 100644
--- a/src/store/home/slices/homeInput/action.ts
+++ b/src/store/home/slices/homeInput/action.ts
@@ -2,6 +2,7 @@ import { BUILTIN_AGENT_SLUGS } from '@lobechat/builtin-agents';
import { CUSTOM_DOCUMENT_FILE_TYPE } from '@lobechat/const';
import type { ContextSelection, PageSelection } from '@lobechat/types';
+import { docsPagePath } from '@/features/ResourceHome/paths';
import { stableWorkspaceAwareNavigate } from '@/features/Workspace/stableWorkspaceAwareNavigate';
import { chatGroupService } from '@/services/chatGroup';
import { documentService } from '@/services/document';
@@ -340,7 +341,7 @@ export class HomeInputActionImpl {
});
// 3. Navigate to Page
- stableWorkspaceAwareNavigate(`/page/${newDoc.id}`);
+ stableWorkspaceAwareNavigate(docsPagePath(newDoc.id));
// 4. Send the initial page-agent message. Hydrate first to avoid the same
// race the agent/group flows hit.
diff --git a/src/store/page/action.test.ts b/src/store/page/action.test.ts
index f6481ec7a26..7bb23d4745c 100644
--- a/src/store/page/action.test.ts
+++ b/src/store/page/action.test.ts
@@ -104,7 +104,7 @@ describe('pageActions β€” createNewPage', () => {
expect(items()[0].title).toBe('My page');
expect(usePageStore.getState().selectedPageId).toBe('docnew1');
expect(usePageStore.getState().isCreatingNew).toBe(false);
- expect(navigate).toHaveBeenCalledWith('/page/docnew1');
+ expect(navigate).toHaveBeenCalledWith('/resource/page/docnew1');
});
it('shows the optimistic row while the request is in flight', async () => {
@@ -140,7 +140,7 @@ describe('pageActions β€” createNewPage', () => {
expect(items()).toEqual([]);
expect(usePageStore.getState().selectedPageId).toBeNull();
expect(usePageStore.getState().isCreatingNew).toBe(false);
- expect(navigate).toHaveBeenCalledWith('/page');
+ expect(navigate).toHaveBeenCalledWith('/resource');
});
});
@@ -173,7 +173,7 @@ describe('pageActions β€” removePage', () => {
await pageActions.removePage('docs_a');
expect(usePageStore.getState().selectedPageId).toBeNull();
- expect(navigate).toHaveBeenCalledWith('/page');
+ expect(navigate).toHaveBeenCalledWith('/resource');
});
});
diff --git a/src/store/page/action.ts b/src/store/page/action.ts
index 118bc816df5..8a5e62bb605 100644
--- a/src/store/page/action.ts
+++ b/src/store/page/action.ts
@@ -1,13 +1,13 @@
import { CUSTOM_DOCUMENT_FILE_TYPE } from '@lobechat/const';
import type { DocumentItem } from '@lobechat/database/schemas';
+import { docsPagePath, RESOURCE_HOME_PATH } from '@/features/ResourceHome/paths';
import { type ReplicaSyncResult } from '@/libs/replica';
import { documentService } from '@/services/document';
import { useGlobalStore } from '@/store/global';
import { systemStatusSelectors } from '@/store/global/selectors';
import type { StoreSetter } from '@/store/types';
import { DocumentSourceType, type LobeDocument } from '@/types/document';
-import { standardizeIdentifier } from '@/utils/identifier';
import { setNamespace } from '@/utils/storeDebug';
import { initialState, type PageState } from './initialState';
@@ -164,7 +164,7 @@ export class PageActionImpl {
};
navigateToPage = (pageId: string | null): void => {
- this.#get().navigate?.(pageId ? `/page/${standardizeIdentifier(pageId)}` : '/page');
+ this.#get().navigate?.(pageId ? docsPagePath(pageId) : RESOURCE_HOME_PATH);
};
createNewPage = async (title: string, visibility?: 'private' | 'public'): Promise<string> => {