@nextclaw/ui 0.20.2 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/dist/assets/{api-DvpQWjTS.js → api-DNLQPHfQ.js} +5 -5
- package/dist/assets/{appearance-settings-page-U0m0ktu3.js → appearance-settings-page-BlAFMOGV.js} +1 -1
- package/dist/assets/{book-open-DRofSTWr.js → book-open-BryfPTTa.js} +1 -1
- package/dist/assets/{channels-list-page-BURQarD0.js → channels-list-page-Cfbgubyv.js} +2 -2
- package/dist/assets/{config-split-page-BrAQYTIl.js → config-split-page-Dd8xG0Jk.js} +1 -1
- package/dist/assets/{confirm-dialog-DDJomLnO.js → confirm-dialog-CZIWjnJ6.js} +2 -2
- package/dist/assets/{createLucideIcon-DzkNHr5Z.js → createLucideIcon-BxwVe8ZD.js} +1 -1
- package/dist/assets/desktop-capabilities-page-C6YxsHeV.js +1 -0
- package/dist/assets/desktop-update-config-BVN4QPJn.js +1 -0
- package/dist/assets/{dist-NskPB_yW.js → dist-BRloKr3S.js} +1 -1
- package/dist/assets/{dist-DXbLo2b1.js → dist-Cd8Nm3BW.js} +1 -1
- package/dist/assets/doc-browser-Bzgqmmiu.js +1 -0
- package/dist/assets/doc-browser-D0qI0Z_R.js +1 -0
- package/dist/assets/{doc-browser-context-CnKV4gJy.js → doc-browser-context-3JGufiMA.js} +1 -1
- package/dist/assets/{extensions-DvlFMpAs.js → extensions-Dedd2oDI.js} +1 -1
- package/dist/assets/{form-actions-UnPEZBkx.js → form-actions-FWCEof3V.js} +1 -1
- package/dist/assets/index-CXkHcESm.css +1 -0
- package/dist/assets/index-D25tRg1p.js +109 -0
- package/dist/assets/loader-circle-BoyCoFps.js +1 -0
- package/dist/assets/mcp-marketplace-page-Cn-9CDh3.js +1 -0
- package/dist/assets/mcp-marketplace-page-e9Rmfz-d.js +10 -0
- package/dist/assets/model-config-page-C173Ssil.js +1 -0
- package/dist/assets/{navigation-link-NjUdG6Vp.js → navigation-link-DTPOvGGL.js} +1 -1
- package/dist/assets/plus-D1R4Vipq.js +1 -0
- package/dist/assets/privacy-settings-page-CRserBVF.js +1 -0
- package/dist/assets/providers-config-page-C8jUtnZb.js +1 -0
- package/dist/assets/react-BAzO6LZS.js +8 -0
- package/dist/assets/{refresh-cw-CkeninE0.js → refresh-cw-BCj-yjde.js} +1 -1
- package/dist/assets/remote-6BHWP5zi.js +1 -0
- package/dist/assets/{rotate-cw-DP33PuXU.js → rotate-cw-BPnW4qUl.js} +1 -1
- package/dist/assets/runtime-config-page-aeQ1Dryz.js +1 -0
- package/dist/assets/{save-Cw2Xz-pB.js → save-KT0MumfJ.js} +1 -1
- package/dist/assets/{search-C2CFAVvd.js → search-Cv1Hx_nx.js} +1 -1
- package/dist/assets/{search-config-page-dqNT0Swf.js → search-config-page-b283V-fo.js} +1 -1
- package/dist/assets/{secrets-config-page-De6J3wVx.js → secrets-config-page-ss7x3BOo.js} +2 -2
- package/dist/assets/security-config-HHz62oxH.js +1 -0
- package/dist/assets/{select-DSuMhwVP.js → select-BVgD4EpG.js} +1 -1
- package/dist/assets/skeleton-ChUmcyys.js +1 -0
- package/dist/assets/{tag-chip-DFBLgsGf.js → tag-chip-DZ4ircUB.js} +1 -1
- package/dist/assets/x-BWDRfVWL.js +1 -0
- package/dist/index.html +21 -21
- package/package.json +5 -5
- package/src/app/components/layout/sidebar.tsx +12 -1
- package/src/app/configs/app-navigation.config.ts +17 -2
- package/src/app/hooks/use-feature-controls.ts +11 -0
- package/src/app/index.tsx +10 -0
- package/src/features/apps/components/app-package-card.tsx +29 -7
- package/src/features/apps/components/app-packages-panel.tsx +4 -0
- package/src/features/chat/components/conversation/chat-conversation-content.tsx +18 -2
- package/src/features/chat/components/conversation/chat-conversation-workspace-section.tsx +6 -0
- package/src/features/chat/components/layout/__tests__/chat-sidebar-session-area.test.tsx +16 -2
- package/src/features/chat/components/layout/chat-page-shell.tsx +19 -2
- package/src/features/chat/components/layout/chat-sidebar-desktop-layout.tsx +16 -0
- package/src/features/chat/components/layout/chat-sidebar.tsx +5 -1
- package/src/features/chat/features/message/utils/__tests__/chat-message-timeline-compaction.utils.test.ts +2 -2
- package/src/features/chat/features/message/utils/chat-message-timeline.utils.ts +2 -2
- package/src/features/chat/features/ncp/hooks/__tests__/use-ncp-session-list-view.test.tsx +11 -3
- package/src/features/chat/features/ncp/hooks/use-ncp-session-list-view.ts +12 -5
- package/src/features/chat/features/ncp/hooks/use-ncp-session-queries.ts +15 -1
- package/src/features/chat/features/session/components/__tests__/chat-sidebar-session-item.test.tsx +12 -0
- package/src/features/chat/features/session/components/chat-sidebar-session-entry.tsx +3 -0
- package/src/features/chat/features/session/components/chat-sidebar-session-item.tsx +14 -1
- package/src/features/chat/features/session/utils/chat-session-deletion.utils.ts +25 -0
- package/src/features/chat/features/workspace/components/__tests__/chat-session-token-usage.test.tsx +4 -1
- package/src/features/chat/features/workspace/components/__tests__/chat-session-workspace-file-preview.scroll-restoration.test.tsx +182 -0
- package/src/features/chat/features/workspace/components/__tests__/session-cron-job-content.test.tsx +78 -0
- package/src/features/chat/features/workspace/components/chat-session-workspace-file-preview.tsx +47 -2
- package/src/features/chat/features/workspace/components/chat-session-workspace-panel-content.tsx +14 -1
- package/src/features/chat/features/workspace/components/chat-session-workspace-panel.tsx +9 -0
- package/src/features/chat/features/workspace/components/overview/chat-session-token-usage.tsx +17 -0
- package/src/features/chat/features/workspace/components/session-cron-job-content.tsx +269 -75
- package/src/features/chat/features/workspace/hooks/use-chat-conversation-workspace-state.ts +5 -0
- package/src/features/chat/managers/__tests__/chat-thread-deletion.manager.test.ts +125 -0
- package/src/features/chat/managers/__tests__/chat-thread.manager.test.ts +0 -37
- package/src/features/chat/managers/chat-thread.manager.ts +17 -28
- package/src/features/cron/components/__tests__/cron-config.test.tsx +16 -5
- package/src/features/cron/components/cron-config.tsx +20 -46
- package/src/features/cron/components/cron-job-row.tsx +1 -1
- package/src/features/cron/hooks/__tests__/use-cron-job-actions.test.tsx +95 -0
- package/src/features/cron/hooks/use-cron-job-actions.ts +109 -0
- package/src/features/cron/index.ts +2 -0
- package/src/features/desktop-capabilities/components/desktop-authorization-dialog.test.tsx +58 -0
- package/src/features/desktop-capabilities/components/desktop-authorization-dialog.tsx +161 -0
- package/src/features/desktop-capabilities/hooks/use-desktop-capabilities.test.ts +10 -0
- package/src/features/desktop-capabilities/hooks/use-desktop-capabilities.ts +55 -0
- package/src/features/desktop-capabilities/index.ts +1 -0
- package/src/features/desktop-capabilities/managers/desktop-capability.manager.ts +25 -0
- package/src/features/desktop-capabilities/pages/desktop-capabilities-page.test.tsx +44 -0
- package/src/features/desktop-capabilities/pages/desktop-capabilities-page.tsx +171 -0
- package/src/features/desktop-capabilities/stores/desktop-authorization.store.ts +21 -0
- package/src/features/inbox/pages/inbox-page.tsx +18 -2
- package/src/features/marketplace/components/marketplace-page.tsx +7 -0
- package/src/features/marketplace/components/mcp/__tests__/mcp-connection-dialog.test.tsx +23 -0
- package/src/features/marketplace/components/mcp/mcp-connection-dialog.tsx +35 -0
- package/src/features/marketplace/components/mcp/mcp-marketplace-page.tsx +20 -2
- package/src/features/panel-apps/pages/panel-app-main-page.tsx +8 -0
- package/src/platforms/desktop/components/desktop-app-shell.tsx +10 -1
- package/src/platforms/mobile/components/mobile-settings-shell.tsx +5 -1
- package/src/shared/components/doc-browser/doc-browser.tsx +0 -1
- package/src/shared/components/doc-browser/hooks/use-doc-browser-scroll-restoration.ts +9 -113
- package/src/shared/components/ui/__tests__/confirm-dialog.test.tsx +31 -0
- package/src/shared/components/ui/confirm-dialog.tsx +11 -1
- package/src/shared/hooks/use-panel-app-scroll-restoration.test.tsx +66 -0
- package/src/shared/hooks/use-panel-app-scroll-restoration.ts +107 -0
- package/src/shared/hooks/use-scroll-restoration.test.tsx +62 -0
- package/src/shared/hooks/use-scroll-restoration.ts +61 -0
- package/src/shared/lib/api/index.ts +1 -0
- package/src/shared/lib/api/ncp-session-query-cache.utils.ts +1 -0
- package/src/shared/lib/api/ncp-session.types.ts +3 -0
- package/src/shared/lib/api/types.ts +1 -0
- package/src/shared/lib/api/utils/mcp-connection.utils.ts +10 -0
- package/src/shared/lib/api/utils/ncp-session.utils.ts +3 -0
- package/src/shared/lib/i18n/locales/en-US/chat.json +10 -5
- package/src/shared/lib/i18n/locales/en-US/core.json +43 -0
- package/src/shared/lib/i18n/locales/en-US/cron.json +4 -2
- package/src/shared/lib/i18n/locales/en-US/doc-browser.json +1 -0
- package/src/shared/lib/i18n/locales/en-US/marketplace.json +29 -1
- package/src/shared/lib/i18n/locales/zh-CN/chat.json +10 -5
- package/src/shared/lib/i18n/locales/zh-CN/core.json +43 -0
- package/src/shared/lib/i18n/locales/zh-CN/cron.json +4 -2
- package/src/shared/lib/i18n/locales/zh-CN/doc-browser.json +1 -0
- package/src/shared/lib/i18n/locales/zh-CN/marketplace.json +29 -1
- package/src/shared/lib/navigation-history/index.ts +1 -0
- package/src/shared/lib/navigation-history/scroll-restoration.manager.test.ts +37 -0
- package/src/shared/lib/navigation-history/scroll-restoration.manager.ts +60 -0
- package/dist/assets/desktop-update-config-BzZFhMv9.js +0 -1
- package/dist/assets/doc-browser-DB22tQKU.js +0 -1
- package/dist/assets/doc-browser-sJjw9fl5.js +0 -1
- package/dist/assets/index-Dc_ZMkmo.css +0 -1
- package/dist/assets/index-N1HnesBp.js +0 -109
- package/dist/assets/loader-circle-BlPXxgDB.js +0 -1
- package/dist/assets/mcp-marketplace-page-BIgFTbMq.js +0 -9
- package/dist/assets/mcp-marketplace-page-CZN4ovdK.js +0 -1
- package/dist/assets/model-config-page-CnSm7kfa.js +0 -1
- package/dist/assets/plus-DVXol9Q5.js +0 -1
- package/dist/assets/privacy-settings-page-DVn2HU7W.js +0 -1
- package/dist/assets/providers-config-page-CzHJS3eg.js +0 -1
- package/dist/assets/react-DCVbGroo.js +0 -8
- package/dist/assets/remote-B2lsJF1c.js +0 -1
- package/dist/assets/runtime-config-page-D69buyGp.js +0 -1
- package/dist/assets/security-config-Dcu9C4OL.js +0 -1
- package/dist/assets/skeleton-QoWydNLp.js +0 -1
- package/dist/assets/x-BXvAzpjb.js +0 -1
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { fireEvent, render, screen } from "@testing-library/react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { ChatSessionWorkspaceFilePreview } from "@/features/chat/features/workspace/components/chat-session-workspace-file-preview";
|
|
5
|
+
import { scrollRestorationManager } from "@/shared/lib/navigation-history";
|
|
6
|
+
|
|
7
|
+
const serverPathReadMock = vi.fn();
|
|
8
|
+
const serverPathBrowseMock = vi.fn();
|
|
9
|
+
|
|
10
|
+
vi.mock("@/shared/hooks/use-server-path-read", () => ({
|
|
11
|
+
useServerPathRead: (...args: unknown[]) => serverPathReadMock(...args),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
vi.mock("@/shared/hooks/use-server-path-browse", () => ({
|
|
15
|
+
useServerPathBrowse: (...args: unknown[]) => serverPathBrowseMock(...args),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
vi.mock("@nextclaw/agent-chat-ui", () => ({
|
|
19
|
+
ChatMessageMarkdown: ({ text }: { text: string }) => <div data-testid="markdown-preview">{text}</div>,
|
|
20
|
+
FileOperationCodeSurface: () => null,
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
vi.mock(
|
|
24
|
+
"@/features/chat/features/workspace/components/workspace-text-selection-menu",
|
|
25
|
+
() => ({
|
|
26
|
+
WorkspaceTextSelectionMenu: ({ children }: { children: ReactNode }) => children,
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
function renderMarkdownPreview(file: {
|
|
31
|
+
key: string;
|
|
32
|
+
path: string;
|
|
33
|
+
previewViewer?: "rendered" | "source";
|
|
34
|
+
} = {
|
|
35
|
+
key: "markdown-tab",
|
|
36
|
+
path: "/tmp/README.md",
|
|
37
|
+
previewViewer: "rendered",
|
|
38
|
+
}) {
|
|
39
|
+
return render(
|
|
40
|
+
<ChatSessionWorkspaceFilePreview
|
|
41
|
+
file={{
|
|
42
|
+
key: file.key,
|
|
43
|
+
parentSessionKey: "session-1",
|
|
44
|
+
path: file.path,
|
|
45
|
+
viewMode: "preview",
|
|
46
|
+
previewViewer: file.previewViewer ?? "rendered",
|
|
47
|
+
}}
|
|
48
|
+
sessionProjectRoot="/tmp"
|
|
49
|
+
sessionWorkingDir="/tmp"
|
|
50
|
+
showBreadcrumbs={false}
|
|
51
|
+
onFileOpen={vi.fn()}
|
|
52
|
+
/>,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("ChatSessionWorkspaceFilePreview Markdown scroll restoration", () => {
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
scrollRestorationManager.clear();
|
|
59
|
+
serverPathReadMock.mockImplementation(({ path }: { path: string }) => ({
|
|
60
|
+
isLoading: false,
|
|
61
|
+
error: null,
|
|
62
|
+
data: {
|
|
63
|
+
kind: "markdown",
|
|
64
|
+
resolvedPath: path,
|
|
65
|
+
startLine: 1,
|
|
66
|
+
text: `# ${path}`,
|
|
67
|
+
truncated: false,
|
|
68
|
+
},
|
|
69
|
+
}));
|
|
70
|
+
serverPathBrowseMock.mockReturnValue({
|
|
71
|
+
isLoading: false,
|
|
72
|
+
error: new Error("not a directory"),
|
|
73
|
+
data: null,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("restores the rendered Markdown position when returning to the same file tab", () => {
|
|
78
|
+
const firstView = renderMarkdownPreview();
|
|
79
|
+
const firstScrollContainer = screen.getByTestId("markdown-preview").parentElement as HTMLDivElement;
|
|
80
|
+
firstScrollContainer.scrollTop = 144;
|
|
81
|
+
fireEvent.scroll(firstScrollContainer);
|
|
82
|
+
firstView.unmount();
|
|
83
|
+
|
|
84
|
+
renderMarkdownPreview();
|
|
85
|
+
|
|
86
|
+
expect((screen.getByTestId("markdown-preview").parentElement as HTMLDivElement).scrollTop).toBe(144);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("keeps each Markdown tab's position when switching files in one preview instance", () => {
|
|
90
|
+
const firstFile = { key: "markdown-a", path: "/tmp/A.md" };
|
|
91
|
+
const secondFile = { key: "markdown-b", path: "/tmp/B.md" };
|
|
92
|
+
const resolvedPaths = new Map([
|
|
93
|
+
[firstFile.path, "/tmp/first-location/A.md"],
|
|
94
|
+
[secondFile.path, "/tmp/B.md"],
|
|
95
|
+
]);
|
|
96
|
+
serverPathReadMock.mockImplementation(({ path }: { path: string }) => ({
|
|
97
|
+
isLoading: false,
|
|
98
|
+
error: null,
|
|
99
|
+
data: {
|
|
100
|
+
kind: "markdown",
|
|
101
|
+
resolvedPath: resolvedPaths.get(path) ?? path,
|
|
102
|
+
startLine: 1,
|
|
103
|
+
text: `# ${path}`,
|
|
104
|
+
truncated: false,
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
107
|
+
const view = renderMarkdownPreview(firstFile);
|
|
108
|
+
const firstScrollContainer = screen.getByTestId("markdown-preview").parentElement as HTMLDivElement;
|
|
109
|
+
firstScrollContainer.scrollTop = 144;
|
|
110
|
+
fireEvent.scroll(firstScrollContainer);
|
|
111
|
+
|
|
112
|
+
view.rerender(
|
|
113
|
+
<ChatSessionWorkspaceFilePreview
|
|
114
|
+
file={{ ...secondFile, parentSessionKey: "session-1", viewMode: "preview" }}
|
|
115
|
+
sessionProjectRoot="/tmp"
|
|
116
|
+
sessionWorkingDir="/tmp"
|
|
117
|
+
showBreadcrumbs={false}
|
|
118
|
+
onFileOpen={vi.fn()}
|
|
119
|
+
/>,
|
|
120
|
+
);
|
|
121
|
+
const secondScrollContainer = screen.getByTestId("markdown-preview").parentElement as HTMLDivElement;
|
|
122
|
+
secondScrollContainer.scrollTop = 72;
|
|
123
|
+
fireEvent.scroll(secondScrollContainer);
|
|
124
|
+
|
|
125
|
+
// Server-path data can be stale while the query swaps back to the first
|
|
126
|
+
// tab. Its resolved path is display data, not tab identity.
|
|
127
|
+
resolvedPaths.set(firstFile.path, "/tmp/returned-location/A.md");
|
|
128
|
+
|
|
129
|
+
view.rerender(
|
|
130
|
+
<ChatSessionWorkspaceFilePreview
|
|
131
|
+
file={{ ...firstFile, parentSessionKey: "session-1", viewMode: "preview" }}
|
|
132
|
+
sessionProjectRoot="/tmp"
|
|
133
|
+
sessionWorkingDir="/tmp"
|
|
134
|
+
showBreadcrumbs={false}
|
|
135
|
+
onFileOpen={vi.fn()}
|
|
136
|
+
/>,
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
expect((screen.getByTestId("markdown-preview").parentElement as HTMLDivElement).scrollTop).toBe(144);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("restores Markdown after returning from its source-view tab", () => {
|
|
143
|
+
const renderedFile = {
|
|
144
|
+
key: "markdown-rendered",
|
|
145
|
+
path: "/tmp/README.md",
|
|
146
|
+
previewViewer: "rendered" as const,
|
|
147
|
+
};
|
|
148
|
+
const sourceFile = {
|
|
149
|
+
key: "markdown-source",
|
|
150
|
+
path: "/tmp/README.md",
|
|
151
|
+
previewViewer: "source" as const,
|
|
152
|
+
};
|
|
153
|
+
const view = renderMarkdownPreview(renderedFile);
|
|
154
|
+
const scrollContainer = screen.getByTestId("markdown-preview").parentElement as HTMLDivElement;
|
|
155
|
+
scrollContainer.scrollTop = 144;
|
|
156
|
+
fireEvent.scroll(scrollContainer);
|
|
157
|
+
|
|
158
|
+
// The source-view switch replaces the rendered scroll surface before the
|
|
159
|
+
// rendered effect cleanup executes.
|
|
160
|
+
scrollContainer.scrollTop = 0;
|
|
161
|
+
view.rerender(
|
|
162
|
+
<ChatSessionWorkspaceFilePreview
|
|
163
|
+
file={{ ...sourceFile, parentSessionKey: "session-1", viewMode: "preview" }}
|
|
164
|
+
sessionProjectRoot="/tmp"
|
|
165
|
+
sessionWorkingDir="/tmp"
|
|
166
|
+
showBreadcrumbs={false}
|
|
167
|
+
onFileOpen={vi.fn()}
|
|
168
|
+
/>,
|
|
169
|
+
);
|
|
170
|
+
view.rerender(
|
|
171
|
+
<ChatSessionWorkspaceFilePreview
|
|
172
|
+
file={{ ...renderedFile, parentSessionKey: "session-1", viewMode: "preview" }}
|
|
173
|
+
sessionProjectRoot="/tmp"
|
|
174
|
+
sessionWorkingDir="/tmp"
|
|
175
|
+
showBreadcrumbs={false}
|
|
176
|
+
onFileOpen={vi.fn()}
|
|
177
|
+
/>,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
expect((screen.getByTestId("markdown-preview").parentElement as HTMLDivElement).scrollTop).toBe(144);
|
|
181
|
+
});
|
|
182
|
+
});
|
package/src/features/chat/features/workspace/components/__tests__/session-cron-job-content.test.tsx
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import userEvent from "@testing-library/user-event";
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import type { CronJobView } from "@/shared/lib/api";
|
|
7
|
+
import { setLanguage } from "@/shared/lib/i18n";
|
|
8
|
+
import { SessionCronJobContent } from "@/features/chat/features/workspace/components/session-cron-job-content";
|
|
9
|
+
|
|
10
|
+
const mocks = vi.hoisted(() => ({
|
|
11
|
+
deleteJob: vi.fn(),
|
|
12
|
+
runJob: vi.fn(),
|
|
13
|
+
toggleJob: vi.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
vi.mock("@/features/cron", () => ({
|
|
17
|
+
CronJobDetailDialog: ({ job, open }: { job: CronJobView | null; open: boolean }) => (
|
|
18
|
+
open ? createElement("div", { role: "dialog" }, job?.payload.message) : null
|
|
19
|
+
),
|
|
20
|
+
useCronJobActions: () => ({
|
|
21
|
+
ConfirmDialog: () => createElement("div", { "data-testid": "cron-confirm" }),
|
|
22
|
+
deleteJob: mocks.deleteJob,
|
|
23
|
+
isPending: () => false,
|
|
24
|
+
runJob: mocks.runJob,
|
|
25
|
+
toggleJob: mocks.toggleJob,
|
|
26
|
+
}),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
function createJob(): CronJobView {
|
|
30
|
+
return {
|
|
31
|
+
id: "paint-daily",
|
|
32
|
+
name: "每日绘画",
|
|
33
|
+
enabled: true,
|
|
34
|
+
schedule: { kind: "cron", expr: "0 9 * * *", tz: "Asia/Shanghai" },
|
|
35
|
+
payload: {
|
|
36
|
+
kind: "agent_turn",
|
|
37
|
+
message: "请生成一幅拥有柔和晨光、细腻建筑纹理和远处山景的城市水彩画,并将结果保存到项目图库。",
|
|
38
|
+
agentId: "main",
|
|
39
|
+
sessionId: "session:paint",
|
|
40
|
+
},
|
|
41
|
+
state: {
|
|
42
|
+
nextRunAt: "2026-08-27T01:00:00.000Z",
|
|
43
|
+
lastRunAt: "2026-08-26T01:00:00.000Z",
|
|
44
|
+
lastStatus: "ok",
|
|
45
|
+
lastError: null,
|
|
46
|
+
},
|
|
47
|
+
createdAt: "2026-08-26T01:00:00.000Z",
|
|
48
|
+
updatedAt: "2026-08-26T01:00:00.000Z",
|
|
49
|
+
deleteAfterRun: false,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
describe("SessionCronJobContent", () => {
|
|
54
|
+
beforeEach(() => {
|
|
55
|
+
setLanguage("zh");
|
|
56
|
+
vi.clearAllMocks();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("keeps the task prompt as a two-line summary and exposes task controls", async () => {
|
|
60
|
+
const user = userEvent.setup();
|
|
61
|
+
const job = createJob();
|
|
62
|
+
render(createElement(SessionCronJobContent, { jobs: [job] }));
|
|
63
|
+
|
|
64
|
+
const summary = screen.getByText(job.payload.message);
|
|
65
|
+
expect(summary.className.split(" ")).toContain("line-clamp-2");
|
|
66
|
+
expect(screen.getAllByTestId("cron-confirm").length).toBe(1);
|
|
67
|
+
|
|
68
|
+
await user.click(screen.getByRole("switch", { name: "暂停" }));
|
|
69
|
+
expect(mocks.toggleJob).toHaveBeenCalledWith(job, false);
|
|
70
|
+
|
|
71
|
+
await user.click(screen.getByRole("button", { name: "更多操作 每日绘画" }));
|
|
72
|
+
await user.click(screen.getByRole("button", { name: "立即执行" }));
|
|
73
|
+
expect(mocks.runJob).toHaveBeenCalledWith(job);
|
|
74
|
+
|
|
75
|
+
await user.click(screen.getByRole("button", { name: "查看任务详情" }));
|
|
76
|
+
expect(screen.getByRole("dialog").textContent).toContain(job.payload.message);
|
|
77
|
+
});
|
|
78
|
+
});
|
package/src/features/chat/features/workspace/components/chat-session-workspace-file-preview.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo, useRef, type ReactNode, type RefObject } from 'react';
|
|
1
|
+
import { useMemo, useRef, type ReactNode, type RefObject, type UIEvent } from 'react';
|
|
2
2
|
import type { ChatFileOpenActionViewModel, ChatFileOperationBlockViewModel } from '@nextclaw/agent-chat-ui';
|
|
3
3
|
import { NextClawClientError } from '@nextclaw/client-sdk';
|
|
4
4
|
import { ChatMessageMarkdown, FileOperationCodeSurface } from '@nextclaw/agent-chat-ui';
|
|
@@ -24,6 +24,7 @@ import { buildWorkspaceFileBreadcrumb, resolveWorkspaceRelativePath } from '@/sh
|
|
|
24
24
|
import { cn } from '@/shared/lib/utils';
|
|
25
25
|
import { resolveWorkspaceFileViewer } from '@/features/chat/features/workspace/utils/chat-workspace-file-viewer.utils';
|
|
26
26
|
import { WorkspaceMarkdownOutline } from './workspace-markdown-outline';
|
|
27
|
+
import { useScrollRestoration } from '@/shared/hooks/use-scroll-restoration';
|
|
27
28
|
|
|
28
29
|
function inferPreviewKind(params: {
|
|
29
30
|
path: string;
|
|
@@ -42,6 +43,31 @@ function appendPreviewRefreshVersion(url: string, refreshVersion: number): strin
|
|
|
42
43
|
return `${url}${url.includes('?') ? '&' : '?'}refresh=${refreshVersion}`;
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
function createMarkdownScrollRestorationKey(params: {
|
|
47
|
+
contentUrl: string | null;
|
|
48
|
+
fileKey: string;
|
|
49
|
+
previewKind: 'text' | 'markdown' | 'binary';
|
|
50
|
+
previewText: string | null;
|
|
51
|
+
previewViewer: 'source' | 'rendered' | null;
|
|
52
|
+
refreshVersion: number;
|
|
53
|
+
}): string | null {
|
|
54
|
+
const {
|
|
55
|
+
contentUrl,
|
|
56
|
+
fileKey,
|
|
57
|
+
previewKind,
|
|
58
|
+
previewText,
|
|
59
|
+
previewViewer,
|
|
60
|
+
refreshVersion,
|
|
61
|
+
} = params;
|
|
62
|
+
if (previewKind !== 'markdown' || previewViewer === 'source' || !previewText || contentUrl) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
// `fileKey` is the workspace tab's stable identity. Do not include resolvedPath:
|
|
66
|
+
// React Query may temporarily expose a previous result while a different file
|
|
67
|
+
// loads, which would turn one tab into several restoration records.
|
|
68
|
+
return `workspace-preview:markdown:${fileKey}:${refreshVersion}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
45
71
|
function buildPreviewBlock(params: {
|
|
46
72
|
path: string;
|
|
47
73
|
text: string;
|
|
@@ -159,6 +185,7 @@ function WorkspacePreviewBody({
|
|
|
159
185
|
onFileOpen,
|
|
160
186
|
onHtmlContentHeightChange,
|
|
161
187
|
markdownScrollRef,
|
|
188
|
+
onMarkdownScroll,
|
|
162
189
|
previewBlock,
|
|
163
190
|
previewKind,
|
|
164
191
|
previewViewer,
|
|
@@ -176,6 +203,7 @@ function WorkspacePreviewBody({
|
|
|
176
203
|
onFileOpen: (action: ChatFileOpenActionViewModel) => void;
|
|
177
204
|
onHtmlContentHeightChange?: (height: number) => void;
|
|
178
205
|
markdownScrollRef: RefObject<HTMLDivElement>;
|
|
206
|
+
onMarkdownScroll: (event: UIEvent<HTMLDivElement>) => void;
|
|
179
207
|
previewBlock: ChatFileOperationBlockViewModel | null;
|
|
180
208
|
previewKind: 'text' | 'markdown' | 'binary';
|
|
181
209
|
previewViewer: 'source' | 'rendered' | null;
|
|
@@ -224,7 +252,11 @@ function WorkspacePreviewBody({
|
|
|
224
252
|
|
|
225
253
|
if (previewKind === 'markdown' && previewViewer !== 'source' && previewText) {
|
|
226
254
|
return (
|
|
227
|
-
<div
|
|
255
|
+
<div
|
|
256
|
+
ref={markdownScrollRef}
|
|
257
|
+
onScroll={onMarkdownScroll}
|
|
258
|
+
className="h-full overflow-auto custom-scrollbar px-5 py-4"
|
|
259
|
+
>
|
|
228
260
|
<ChatMessageMarkdown
|
|
229
261
|
text={previewText}
|
|
230
262
|
role="assistant"
|
|
@@ -338,6 +370,18 @@ export function ChatSessionWorkspaceFilePreview({
|
|
|
338
370
|
previewText,
|
|
339
371
|
]);
|
|
340
372
|
const isTextPreviewTruncated = !contentUrl && Boolean(previewQuery?.data?.truncated);
|
|
373
|
+
const markdownScrollRestoration = useScrollRestoration({
|
|
374
|
+
restorationKey: createMarkdownScrollRestorationKey({
|
|
375
|
+
contentUrl,
|
|
376
|
+
fileKey: file.key,
|
|
377
|
+
previewKind,
|
|
378
|
+
previewText,
|
|
379
|
+
previewViewer,
|
|
380
|
+
refreshVersion,
|
|
381
|
+
}),
|
|
382
|
+
scrollRef: markdownScrollRef,
|
|
383
|
+
});
|
|
384
|
+
const { onScroll: onMarkdownScroll } = markdownScrollRestoration;
|
|
341
385
|
const breadcrumbBasePath = sessionProjectRoot ?? sessionWorkingDir;
|
|
342
386
|
const excerptPath =
|
|
343
387
|
resolveWorkspaceRelativePath({
|
|
@@ -365,6 +409,7 @@ export function ChatSessionWorkspaceFilePreview({
|
|
|
365
409
|
onFileOpen={onFileOpen}
|
|
366
410
|
onHtmlContentHeightChange={onHtmlContentHeightChange}
|
|
367
411
|
markdownScrollRef={markdownScrollRef}
|
|
412
|
+
onMarkdownScroll={onMarkdownScroll}
|
|
368
413
|
previewBlock={previewBlock}
|
|
369
414
|
previewKind={previewKind}
|
|
370
415
|
previewViewer={previewViewer}
|
package/src/features/chat/features/workspace/components/chat-session-workspace-panel-content.tsx
CHANGED
|
@@ -39,8 +39,11 @@ type ChatSessionWorkspacePanelContentProps = {
|
|
|
39
39
|
filePreviewRefreshVersion: number;
|
|
40
40
|
sessionKey: string | null;
|
|
41
41
|
sessionCronJobs: readonly CronJobView[];
|
|
42
|
+
sessionCronJobsError?: boolean;
|
|
43
|
+
sessionCronJobsLoading?: boolean;
|
|
42
44
|
sessionProjectRoot: string | null;
|
|
43
45
|
sessionWorkingDir: string | null;
|
|
46
|
+
onRetrySessionCronJobs?: () => void;
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
function WorkspaceOverviewEntry({
|
|
@@ -220,8 +223,11 @@ function WorkspaceSelectedContent({
|
|
|
220
223
|
filePreviewRefreshVersion,
|
|
221
224
|
sessionKey,
|
|
222
225
|
sessionCronJobs,
|
|
226
|
+
sessionCronJobsError = false,
|
|
227
|
+
sessionCronJobsLoading = false,
|
|
223
228
|
sessionProjectRoot,
|
|
224
229
|
sessionWorkingDir,
|
|
230
|
+
onRetrySessionCronJobs,
|
|
225
231
|
explorerControl,
|
|
226
232
|
}: ChatSessionWorkspacePanelContentProps & {
|
|
227
233
|
explorerControl?: { open: boolean; onToggle: () => void };
|
|
@@ -309,7 +315,14 @@ function WorkspaceSelectedContent({
|
|
|
309
315
|
);
|
|
310
316
|
}
|
|
311
317
|
|
|
312
|
-
return
|
|
318
|
+
return (
|
|
319
|
+
<SessionCronJobContent
|
|
320
|
+
jobs={sessionCronJobs}
|
|
321
|
+
isError={sessionCronJobsError}
|
|
322
|
+
isLoading={sessionCronJobsLoading}
|
|
323
|
+
onRetry={onRetrySessionCronJobs}
|
|
324
|
+
/>
|
|
325
|
+
);
|
|
313
326
|
}
|
|
314
327
|
|
|
315
328
|
export function ChatSessionWorkspacePanelContent({
|
|
@@ -44,6 +44,9 @@ type ChatSessionWorkspacePanelProps = {
|
|
|
44
44
|
workspaceNavigationHistoryIndex?: number;
|
|
45
45
|
activePanelKind?: ChatWorkspacePanelKind | null;
|
|
46
46
|
sessionCronJobs?: readonly CronJobView[];
|
|
47
|
+
sessionCronJobsError?: boolean;
|
|
48
|
+
sessionCronJobsLoading?: boolean;
|
|
49
|
+
onRetrySessionCronJobs?: () => void;
|
|
47
50
|
sessionProjectRoot: string | null;
|
|
48
51
|
sessionWorkingDir: string | null;
|
|
49
52
|
workspacePanelWidth?: number;
|
|
@@ -62,6 +65,9 @@ export function ChatSessionWorkspacePanel({
|
|
|
62
65
|
workspaceNavigationHistoryIndex = 0,
|
|
63
66
|
activePanelKind,
|
|
64
67
|
sessionCronJobs = [],
|
|
68
|
+
sessionCronJobsError = false,
|
|
69
|
+
sessionCronJobsLoading = false,
|
|
70
|
+
onRetrySessionCronJobs,
|
|
65
71
|
sessionProjectRoot,
|
|
66
72
|
sessionWorkingDir,
|
|
67
73
|
workspacePanelWidth = CHAT_WORKSPACE_PANEL_DEFAULT_WIDTH,
|
|
@@ -218,6 +224,9 @@ export function ChatSessionWorkspacePanel({
|
|
|
218
224
|
filePreviewRefreshVersion={filePreviewRefreshVersion}
|
|
219
225
|
sessionKey={sessionKey}
|
|
220
226
|
sessionCronJobs={sessionCronJobs}
|
|
227
|
+
sessionCronJobsError={sessionCronJobsError}
|
|
228
|
+
sessionCronJobsLoading={sessionCronJobsLoading}
|
|
229
|
+
onRetrySessionCronJobs={onRetrySessionCronJobs}
|
|
221
230
|
sessionProjectRoot={sessionProjectRoot}
|
|
222
231
|
sessionWorkingDir={sessionWorkingDir}
|
|
223
232
|
/>
|
package/src/features/chat/features/workspace/components/overview/chat-session-token-usage.tsx
CHANGED
|
@@ -8,6 +8,10 @@ function formatTokenCount(value: number | null): string {
|
|
|
8
8
|
return value === null ? '—' : new Intl.NumberFormat().format(value);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
function formatCount(value: number | null): string {
|
|
12
|
+
return value === null ? '—' : new Intl.NumberFormat().format(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
11
15
|
function formatCacheHitRate(value: number | null): string {
|
|
12
16
|
return value === null
|
|
13
17
|
? '—'
|
|
@@ -119,6 +123,14 @@ export function ChatSessionTokenUsage({ sessionKey }: { sessionKey: string | nul
|
|
|
119
123
|
label={t('chatWorkspaceTokenUsageRuns')}
|
|
120
124
|
value={String(usage.runCount)}
|
|
121
125
|
/>
|
|
126
|
+
<TokenUsageMetric
|
|
127
|
+
label={t('chatWorkspaceTokenUsageModelCalls')}
|
|
128
|
+
value={formatCount(usage.modelCallCount)}
|
|
129
|
+
/>
|
|
130
|
+
<TokenUsageMetric
|
|
131
|
+
label={t('chatWorkspaceTokenUsageReportedModelCalls')}
|
|
132
|
+
value={formatCount(usage.reportedModelCallCount)}
|
|
133
|
+
/>
|
|
122
134
|
</div>
|
|
123
135
|
<div>
|
|
124
136
|
<div className="mb-1.5 text-[11px] font-medium text-gray-700">
|
|
@@ -136,6 +148,11 @@ export function ChatSessionTokenUsage({ sessionKey }: { sessionKey: string | nul
|
|
|
136
148
|
<div className="mt-1 text-[10px] text-gray-500">
|
|
137
149
|
{t('chatWorkspaceTokenUsageModelRunCount').replace('{count}', String(modelUsage.runCount))}
|
|
138
150
|
{' · '}
|
|
151
|
+
{t('chatWorkspaceTokenUsageModelCallCount').replace(
|
|
152
|
+
'{count}',
|
|
153
|
+
formatCount(modelUsage.modelCallCount),
|
|
154
|
+
)}
|
|
155
|
+
{' · '}
|
|
139
156
|
{t('chatWorkspaceTokenUsageModelCacheHitRate').replace(
|
|
140
157
|
'{rate}',
|
|
141
158
|
formatCacheHitRate(modelUsage.cacheHitRate),
|