@nextclaw/ui 0.15.27 → 0.15.29
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 +16 -0
- package/dist/assets/{appearance-settings-page-DlGXLgff.js → appearance-settings-page-Bpd2RhK5.js} +1 -1
- package/dist/assets/{channels-list-page-BEEk4Uc9.js → channels-list-page-CTblam4c.js} +2 -2
- package/dist/assets/chat-page-Bg3_X8G9.js +1 -0
- package/dist/assets/{desktop-update-config--zagjHic.js → desktop-update-config-D9AyIhJZ.js} +1 -1
- package/dist/assets/index-VQAVqwG8.js +109 -0
- package/dist/assets/{model-config-page-rrhFaque.js → model-config-page-B8Aubkwx.js} +1 -1
- package/dist/assets/{provider-scoped-model-input-CFsfWEt9.js → provider-scoped-model-input-BRnIH-5O.js} +1 -1
- package/dist/assets/providers-config-page-0r9AZNNZ.js +1 -0
- package/dist/assets/remote-DQzE55WW.js +1 -0
- package/dist/assets/runtime-config-page-BgeYpvMK.js +1 -0
- package/dist/assets/{search-config-page-B3fvzMd1.js → search-config-page-CzNzLyd0.js} +1 -1
- package/dist/assets/{secrets-config-page-ClwTxtXd.js → secrets-config-page-C4k3ik0v.js} +2 -2
- package/dist/index.html +1 -1
- package/package.json +6 -6
- package/src/features/apps/components/__tests__/app-packages-panel.test.tsx +35 -11
- package/src/features/apps/components/app-packages-panel.tsx +34 -28
- package/src/features/chat/features/message/hooks/__tests__/use-chat-message-actions.test.tsx +64 -0
- package/src/features/chat/features/message/hooks/use-chat-message-actions.tsx +5 -1
- package/src/features/chat/features/ncp/hooks/__tests__/use-ncp-session-conversation.test.tsx +1 -1
- package/src/features/chat/features/ncp/hooks/use-ncp-session-message-history.ts +1 -1
- package/src/features/chat/features/workspace/components/__tests__/chat-session-workspace-panel-content.test.tsx +6 -1
- package/src/features/chat/features/workspace/components/chat-session-workspace-panel-content.tsx +1 -1
- package/src/features/chat/managers/__tests__/chat-completion-notification.manager.test.ts +3 -3
- package/src/features/chat/managers/chat-completion-notification.manager.ts +10 -4
- package/src/features/chat/pages/__tests__/ncp-chat-page.test.tsx +34 -7
- package/src/features/chat/pages/ncp-chat-page.tsx +19 -4
- package/dist/assets/chat-page-DUQXXqQm.js +0 -1
- package/dist/assets/index-Ba_o5fu9.js +0 -109
- package/dist/assets/providers-config-page-D-TYFZsF.js +0 -1
- package/dist/assets/remote-BwVv_Qq-.js +0 -1
- package/dist/assets/runtime-config-page-Br9j9Vxe.js +0 -1
package/src/features/chat/features/workspace/components/chat-session-workspace-panel-content.tsx
CHANGED
|
@@ -444,7 +444,7 @@ export function ChatSessionWorkspacePanelContent({
|
|
|
444
444
|
) : null}
|
|
445
445
|
</div>
|
|
446
446
|
{projectFilesActive ? null : (
|
|
447
|
-
<div className="min-
|
|
447
|
+
<div className="flex min-h-0 min-w-0 flex-1 flex-col">
|
|
448
448
|
<WorkspaceSelectedContent
|
|
449
449
|
{...selectedContentProps}
|
|
450
450
|
activeSelection={activeSelection}
|
|
@@ -101,13 +101,13 @@ describe("ChatCompletionNotificationManager", () => {
|
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
it("suppresses messages completed in
|
|
104
|
+
it("suppresses messages completed in any visible session, including later replays", () => {
|
|
105
105
|
manager.start();
|
|
106
|
-
manager.
|
|
106
|
+
manager.syncVisibleSessions(["session-main", "session-background"]);
|
|
107
107
|
emit(createCompletedEvent());
|
|
108
108
|
expect(show).not.toHaveBeenCalled();
|
|
109
109
|
|
|
110
|
-
manager.
|
|
110
|
+
manager.syncVisibleSessions(["session-main"]);
|
|
111
111
|
emit(createCompletedEvent());
|
|
112
112
|
expect(show).not.toHaveBeenCalled();
|
|
113
113
|
|
|
@@ -61,7 +61,7 @@ function readAssistantReplyPreview(message: NcpMessage): string {
|
|
|
61
61
|
export class ChatCompletionNotificationManager {
|
|
62
62
|
private readonly cleanups: Array<() => void> = [];
|
|
63
63
|
private readonly handledMessageIds = new Set<string>();
|
|
64
|
-
private
|
|
64
|
+
private visibleSessionIds = new Set<string>();
|
|
65
65
|
private started = false;
|
|
66
66
|
|
|
67
67
|
constructor(
|
|
@@ -88,8 +88,14 @@ export class ChatCompletionNotificationManager {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
syncVisibleSessions = (
|
|
92
|
+
sessionIds: readonly (string | null | undefined)[],
|
|
93
|
+
): void => {
|
|
94
|
+
this.visibleSessionIds = new Set(
|
|
95
|
+
sessionIds
|
|
96
|
+
.map((sessionId) => sessionId?.trim())
|
|
97
|
+
.filter((sessionId): sessionId is string => Boolean(sessionId)),
|
|
98
|
+
);
|
|
93
99
|
};
|
|
94
100
|
|
|
95
101
|
private readonly handleNcpEvent = (event: NcpEndpointEvent): void => {
|
|
@@ -109,7 +115,7 @@ export class ChatCompletionNotificationManager {
|
|
|
109
115
|
return;
|
|
110
116
|
}
|
|
111
117
|
this.rememberHandledMessage(message.id);
|
|
112
|
-
if (
|
|
118
|
+
if (this.visibleSessionIds.has(sessionId)) {
|
|
113
119
|
return;
|
|
114
120
|
}
|
|
115
121
|
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { render, screen } from '@testing-library/react';
|
|
1
|
+
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
2
2
|
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
|
3
3
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
4
|
|
|
5
5
|
import { AppPresenterProvider } from '@/app/components/app-presenter-provider';
|
|
6
6
|
import { NcpChatPage } from '@/features/chat/pages/ncp-chat-page';
|
|
7
7
|
import { buildSessionPath } from '@/features/chat/features/session/utils/chat-session-route.utils';
|
|
8
|
+
import { useChatThreadStore } from '@/features/chat/stores/chat-thread.store';
|
|
8
9
|
|
|
9
10
|
const mocks = vi.hoisted(() => ({
|
|
10
11
|
confirm: vi.fn(),
|
|
11
12
|
consumePending: vi.fn(() => null),
|
|
12
13
|
markConsumed: vi.fn(),
|
|
13
14
|
subscribe: vi.fn(() => vi.fn()),
|
|
14
|
-
|
|
15
|
+
syncVisibleSessions: vi.fn(),
|
|
15
16
|
useChatSessionSync: vi.fn(),
|
|
16
17
|
}));
|
|
17
18
|
|
|
@@ -24,7 +25,7 @@ vi.mock('@/app/presenters/app.presenter', () => ({
|
|
|
24
25
|
subscribe: mocks.subscribe,
|
|
25
26
|
},
|
|
26
27
|
chatCompletionNotificationManager: {
|
|
27
|
-
|
|
28
|
+
syncVisibleSessions: mocks.syncVisibleSessions,
|
|
28
29
|
},
|
|
29
30
|
}),
|
|
30
31
|
}));
|
|
@@ -57,8 +58,13 @@ vi.mock('@/features/chat/features/ncp/hooks/use-ui-show-content-event', () => ({
|
|
|
57
58
|
|
|
58
59
|
describe('NcpChatPage render boundary', () => {
|
|
59
60
|
beforeEach(() => {
|
|
60
|
-
mocks.
|
|
61
|
+
mocks.syncVisibleSessions.mockReset();
|
|
61
62
|
mocks.useChatSessionSync.mockReset();
|
|
63
|
+
useChatThreadStore.getState().setSnapshot({
|
|
64
|
+
workspacePanelParentKey: null,
|
|
65
|
+
activeWorkspacePanelKind: null,
|
|
66
|
+
activeChildSessionKey: null,
|
|
67
|
+
});
|
|
62
68
|
});
|
|
63
69
|
|
|
64
70
|
it('creates its chat presenter from the global app presenter provider', () => {
|
|
@@ -74,8 +80,13 @@ describe('NcpChatPage render boundary', () => {
|
|
|
74
80
|
expect(mocks.useChatSessionSync).toHaveBeenCalledOnce();
|
|
75
81
|
});
|
|
76
82
|
|
|
77
|
-
it('
|
|
83
|
+
it('tracks visible route and workspace sessions, then clears them when chat unmounts', async () => {
|
|
78
84
|
const sessionPath = buildSessionPath('session-background');
|
|
85
|
+
useChatThreadStore.getState().setSnapshot({
|
|
86
|
+
workspacePanelParentKey: 'session-background',
|
|
87
|
+
activeWorkspacePanelKind: 'child-session',
|
|
88
|
+
activeChildSessionKey: 'session-child',
|
|
89
|
+
});
|
|
79
90
|
const view = render(
|
|
80
91
|
<MemoryRouter initialEntries={[sessionPath]}>
|
|
81
92
|
<AppPresenterProvider>
|
|
@@ -86,8 +97,24 @@ describe('NcpChatPage render boundary', () => {
|
|
|
86
97
|
</MemoryRouter>,
|
|
87
98
|
);
|
|
88
99
|
|
|
89
|
-
expect(mocks.
|
|
100
|
+
expect(mocks.syncVisibleSessions).toHaveBeenCalledWith([
|
|
101
|
+
'session-background',
|
|
102
|
+
'session-child',
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
act(() => {
|
|
106
|
+
useChatThreadStore.getState().setSnapshot({
|
|
107
|
+
activeWorkspacePanelKind: 'file',
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await waitFor(() => {
|
|
111
|
+
expect(mocks.syncVisibleSessions).toHaveBeenLastCalledWith([
|
|
112
|
+
'session-background',
|
|
113
|
+
null,
|
|
114
|
+
]);
|
|
115
|
+
});
|
|
116
|
+
|
|
90
117
|
view.unmount();
|
|
91
|
-
expect(mocks.
|
|
118
|
+
expect(mocks.syncVisibleSessions).toHaveBeenLastCalledWith([]);
|
|
92
119
|
});
|
|
93
120
|
});
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
import { useConfirmDialog } from "@/shared/hooks/use-confirm-dialog";
|
|
19
19
|
import { useAppPresenter } from "@/app/components/app-presenter-provider";
|
|
20
20
|
import { useUiShowContentEvent } from "@/features/chat/features/ncp/hooks/use-ui-show-content-event";
|
|
21
|
+
import { useChatThreadStore } from "@/features/chat/stores/chat-thread.store";
|
|
21
22
|
|
|
22
23
|
function useNcpChatRouteSelection() {
|
|
23
24
|
const { sessionId: routeSessionIdParam } = useParams<{ sessionId?: string }>();
|
|
@@ -64,14 +65,28 @@ function NcpChatPageContent({ view }: ChatPageProps) {
|
|
|
64
65
|
const confirmDialog = useNcpChatUiBindings();
|
|
65
66
|
const routeSelection = useNcpChatRouteSelection();
|
|
66
67
|
const { routeSessionKey, sessionKey } = routeSelection;
|
|
68
|
+
const visibleWorkspaceSessionKey = useChatThreadStore((state) => {
|
|
69
|
+
const { snapshot } = state;
|
|
70
|
+
if (
|
|
71
|
+
snapshot.workspacePanelParentKey !== (sessionKey ?? null) ||
|
|
72
|
+
snapshot.activeWorkspacePanelKind !== "child-session"
|
|
73
|
+
) {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return snapshot.activeChildSessionKey?.trim() || null;
|
|
77
|
+
});
|
|
67
78
|
useEffect(() => {
|
|
68
|
-
appPresenter.chatCompletionNotificationManager.
|
|
69
|
-
sessionKey
|
|
79
|
+
appPresenter.chatCompletionNotificationManager.syncVisibleSessions(
|
|
80
|
+
[sessionKey, visibleWorkspaceSessionKey],
|
|
70
81
|
);
|
|
71
82
|
return () => {
|
|
72
|
-
appPresenter.chatCompletionNotificationManager.
|
|
83
|
+
appPresenter.chatCompletionNotificationManager.syncVisibleSessions([]);
|
|
73
84
|
};
|
|
74
|
-
}, [
|
|
85
|
+
}, [
|
|
86
|
+
appPresenter.chatCompletionNotificationManager,
|
|
87
|
+
sessionKey,
|
|
88
|
+
visibleWorkspaceSessionKey,
|
|
89
|
+
]);
|
|
75
90
|
useChatQueryStoreSync({
|
|
76
91
|
sessionKey: sessionKey ?? null,
|
|
77
92
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./chunk-DseTPa7n.js";import{I as t,P as n,V as r,i,z as a}from"./react-BlXwvOLo.js";import{d as o,f as s,u as c}from"./navigation-link-mpHFXwRr.js";import{$t as l,Et as u,Qt as d,nn as f,sn as p,tn as m}from"./api-a_GaOFc7.js";import{g as h,h as g}from"./mcp-marketplace-page-w8panjZG.js";import{c as _}from"./dist-DkR7_Dpl.js";import{C as v,a as ee,i as y,n as b,r as x,t as S}from"./select-rUZ8nIZu.js";import{a as C,c as w,i as T,n as E,o as D,r as te,s as O}from"./confirm-dialog-DJSUNG33.js";import{t as ne}from"./provider-scoped-model-input-CFsfWEt9.js";import{t as k}from"./plus-Dhb4KuMH.js";import{t as re}from"./settings-2-BI4SCkxQ.js";import{t as ie}from"./tag-chip-BdI_yIOA.js";import{$ as ae,D as A,Gt as oe,It as se,Jt as ce,Kt as le,O as j,Pt as ue,Q as de,R as fe,Ut as pe,Vt as me,Yt as M,_ as N,_t as P,a as he,at as F,ct as ge,dt as I,et as _e,ft as ve,g as ye,h as be,ht as xe,i as Se,it as Ce,lt as we,m as Te,mt as Ee,o as De,ot as Oe,q as ke,r as L,s as Ae,st as R,t as z,tt as B,u as je,ut as Me,vt as V,zt as H}from"./index-Ba_o5fu9.js";var Ne=_(`Gauge`,[[`path`,{d:`m12 14 4-4`,key:`9kzdfg`}],[`path`,{d:`M3.34 19a10 10 0 1 1 17.32 0`,key:`19p75a`}]]),U=e(r(),1),W=a(),G=new Intl.NumberFormat;function Pe({agent:e,defaults:t,runtimeOptions:n,defaultRuntime:r,defaultRuntimeLabel:a,onOpenChange:o,onEdit:s}){if(!e)return null;let c=K(e.model,t?.model),l=Fe({agent:e,defaults:t,runtimeOptions:n,defaultRuntime:r,defaultRuntimeLabel:a}),u=q(e.contextTokens,t?.contextTokens??2e5),d=q(e.reservedContextTokens,t?.reservedContextTokens),p=q(e.maxToolIterations,t?.maxToolIterations??1e3),m=K(e.thinkingDefault,t?.thinkingDefault??`off`),h=Y(e.runtimeConfig??e.engineConfig,t?.engineConfig),g=Y(e.models,t?.models);return(0,W.jsx)(E,{open:e!==null,onOpenChange:o,children:(0,W.jsxs)(te,{className:`flex max-h-[calc(100vh-2rem)] flex-col overflow-hidden border-none bg-popover p-0 sm:max-h-[720px] sm:max-w-2xl`,children:[(0,W.jsx)(`div`,{className:`shrink-0 px-5 pb-3 pt-5`,children:(0,W.jsx)(D,{className:`text-left`,children:(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,W.jsx)(B,{agentId:e.id,displayName:e.displayName,avatarUrl:e.avatarUrl,className:`h-10 w-10 shrink-0`}),(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(O,{className:`truncate text-base`,children:e.displayName?.trim()||e.id}),(0,W.jsxs)(T,{className:`truncate text-xs`,children:[`@`,e.id]})]})]})})}),(0,W.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-4 overflow-y-auto overscroll-contain px-5 py-3`,children:[(0,W.jsxs)(X,{icon:M,title:i(`agentsDetailsIdentitySection`),children:[(0,W.jsx)(Z,{label:i(`agentsDetailsFieldDisplayName`),value:e.displayName?.trim()||e.id}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldId`),value:e.id,mono:!0}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldDescription`),value:e.description?.trim()||i(`agentsDetailsEmptyValue`),wide:!0}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldWorkspace`),value:e.workspace??i(`agentsDetailsUnsetValue`),mono:!0,wide:!0})]}),(0,W.jsxs)(X,{icon:w,title:i(`agentsDetailsRuntimeSection`),children:[(0,W.jsx)(Z,{label:i(`agentsDetailsFieldModel`),value:c.value,source:c.source}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldRuntime`),value:l.value,source:l.source}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldRuntimeConfig`),value:h.value,source:h.source,mono:!0,prewrap:!0})]}),(0,W.jsxs)(X,{icon:Ne,title:i(`agentsDetailsContextSection`),children:[(0,W.jsx)(Z,{label:i(`agentsDetailsFieldContextTokens`),value:u.value,source:u.source}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldReservedContextTokens`),value:d.value,source:d.source}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldMaxToolIterations`),value:p.value,source:p.source})]}),(0,W.jsxs)(X,{icon:ce,title:i(`agentsDetailsBehaviorSection`),children:[(0,W.jsx)(Z,{label:i(`agentsDetailsFieldThinkingDefault`),value:m.value,source:m.source}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldModelOverrides`),value:g.value,source:g.source,mono:!0,prewrap:!0}),(0,W.jsx)(Z,{label:i(`agentsDetailsFieldAvatar`),value:e.avatar??i(`agentsDetailsUnsetValue`),mono:!0})]})]}),(0,W.jsxs)(C,{className:`shrink-0 px-5 pb-4 pt-2`,children:[(0,W.jsx)(f,{type:`button`,variant:`ghost`,onClick:()=>o(!1),children:i(`cancel`)}),(0,W.jsxs)(f,{type:`button`,variant:`primary`,className:`px-4`,onClick:()=>s(e),children:[(0,W.jsx)(H,{className:`mr-2 h-4 w-4`}),i(`agentsDetailsEditAction`)]})]})]})})}function K(e,t){let n=e?.trim();return n?{value:n,source:`override`}:{value:t?.trim()||i(`agentsDetailsUnsetValue`),source:`default`}}function q(e,t){return typeof e==`number`?{value:G.format(e),source:`override`}:{value:typeof t==`number`?G.format(t):i(`agentsDetailsUnsetValue`),source:`default`}}function Fe(e){let{agent:t,defaults:n,runtimeOptions:r,defaultRuntime:i,defaultRuntimeLabel:a}=e,o=t.runtime?.trim()||t.engine?.trim();if(o)return{value:J(o,r,a),source:`override`};let s=n?.engine?.trim()||i;return{value:s?J(s,r,a):a,source:`default`}}function J(e,t,n){let r=F(e);return r?t.find(e=>e.value===r)?.label??R(r):n}function Y(e,t){return Ie(e)?{value:JSON.stringify(e,null,2),source:`override`}:{value:Ie(t)?JSON.stringify(t,null,2):i(`agentsDetailsUnsetValue`),source:`default`}}function Ie(e){return!!(e&&typeof e==`object`&&!Array.isArray(e)&&Object.keys(e).length>0)}function X(e){let{icon:t,title:n,children:r}=e;return(0,W.jsxs)(`section`,{className:`space-y-2 border-t border-border/60 pt-3 first:border-t-0 first:pt-0`,children:[(0,W.jsxs)(`h3`,{className:`flex items-center gap-1.5 text-xs font-semibold leading-5 text-foreground`,children:[(0,W.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),n]}),(0,W.jsx)(`dl`,{className:`grid min-w-0 gap-x-6 gap-y-2.5 pl-5 sm:grid-cols-2`,children:r})]})}function Z(e){let{label:n,value:r,source:i,mono:a=!1,prewrap:o=!1,wide:s=!1}=e,c=o&&r.trim().startsWith(`{`),l=a&&(!o||c);return(0,W.jsxs)(`div`,{className:t(`grid min-w-0 grid-cols-[10rem_minmax(0,1fr)] items-baseline gap-x-2`,(s||c)&&`sm:col-span-2`),children:[(0,W.jsx)(`dt`,{className:`flex min-w-0 items-baseline leading-5`,children:(0,W.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium text-muted-foreground`,children:n})}),(0,W.jsxs)(`dd`,{className:t(`min-w-0 break-words text-xs leading-5 text-foreground`,c?`max-h-28 overflow-auto whitespace-pre-wrap rounded bg-muted/50 px-2 py-1.5 text-left`:``),children:[(0,W.jsx)(`span`,{className:l?`font-mono`:void 0,children:r}),i?(0,W.jsx)(Le,{source:i}):null]})]})}function Le({source:e}){return(0,W.jsxs)(`span`,{className:t(`ml-1 whitespace-nowrap text-xs font-normal leading-5`,e===`override`?`text-blue-500`:`text-muted-foreground`),children:[`(`,i(e===`override`?`agentsDetailsAgentOverride`:`agentsDetailsInheritedDefault`),`)`]})}function Re({form:e,disabled:t=!1,onChange:n}){return(0,W.jsxs)(`details`,{className:`group rounded-2xl border border-border bg-card`,children:[(0,W.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 px-4 py-3 text-sm font-semibold text-foreground [&::-webkit-details-marker]:hidden`,children:[(0,W.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(re,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,W.jsx)(`span`,{className:`truncate`,children:i(`agentsAdvancedConfigToggle`)})]}),(0,W.jsx)(v,{className:`h-4 w-4 shrink-0 text-muted-foreground transition-transform group-open:rotate-180`})]}),(0,W.jsxs)(`div`,{className:`space-y-4 border-t border-border/60 px-4 py-4`,children:[(0,W.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:i(`agentsAdvancedConfigDescription`)}),(0,W.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:(0,W.jsx)(ze,{label:i(`agentsAdvancedContextTokensLabel`),value:e.contextTokens,min:1e3,step:1e3,disabled:t,onChange:e=>n({contextTokens:e})})})]})]})}function ze(e){let{label:t,value:n,min:r,step:a,disabled:o,onChange:s}=e;return(0,W.jsxs)(`label`,{className:`space-y-2 text-sm font-medium text-foreground`,children:[(0,W.jsx)(`span`,{children:t}),(0,W.jsx)(m,{type:`number`,min:r,step:a,value:n,disabled:o,placeholder:i(`agentsAdvancedInheritPlaceholder`),"aria-label":t,onChange:e=>s(e.target.value)})]})}function Be(e){return{displayName:e.displayName??``,description:e.description??``,avatar:e.avatar??``,model:e.model??``,runtime:e.runtime??e.engine??``,contextTokens:Ve(e.contextTokens)}}function Ve(e){return typeof e==`number`?String(e):``}var He=U.forwardRef(({className:e,...n},r)=>(0,W.jsx)(`textarea`,{className:t(`flex min-h-28 w-full rounded-xl border border-border/75 bg-card px-3.5 py-2.5 text-sm text-foreground placeholder:text-muted-foreground/55 placeholder:font-normal transition-colors focus:outline-none focus:ring-0 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));He.displayName=`Textarea`;function Ue(e){let{runtimeOptions:t,currentRuntime:n}=e,r=n.trim();if(!r)return t;let i=F(r);return t.some(e=>e.value===i)?t:[...t,{value:i,label:R(i),icon:null,ready:!1,reason:`unavailable`,reasonMessage:null,supportedModels:void 0,recommendedModel:null,cta:null}].sort((e,t)=>e.value===`native`?-1:t.value===`native`?1:e.value.localeCompare(t.value))}function We({value:e,disabled:t=!1,runtimeOptions:n,defaultRuntime:r,onChange:a}){let o=e.trim()?F(e):``,s=Ue({runtimeOptions:n,currentRuntime:e}),c=s.find(e=>e.value===o)??null,l=c?.reasonMessage?.trim()||(c?.ready===!1?i(`agentsRuntimeUnavailableHelp`):``);return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(S,{value:o||r,onValueChange:e=>a(e===r?``:e),disabled:t,children:[(0,W.jsx)(y,{"aria-label":i(`agentsCardRuntimeLabel`),className:`rounded-xl`,children:(0,W.jsx)(ee,{placeholder:i(`agentsRuntimeSelectPlaceholder`)})}),(0,W.jsx)(b,{className:`rounded-xl`,children:s.map(e=>(0,W.jsx)(x,{value:e.value,disabled:e.ready===!1&&e.value!==o,className:`rounded-lg`,children:e.label},e.value))})]}),l?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:l}):null]})}function Ge({agent:e,pending:t,providerCatalog:n,runtimeOptions:r,defaultRuntime:i,onOpenChange:a,onSubmit:o}){return(0,W.jsx)(E,{open:e!==null,onOpenChange:a,children:e?(0,W.jsx)(Ke,{agent:e,pending:t,providerCatalog:n,runtimeOptions:r,defaultRuntime:i,onOpenChange:a,onSubmit:o},e.id):null})}function Ke(e){let{agent:t,pending:n,providerCatalog:r,runtimeOptions:a,defaultRuntime:o,onOpenChange:s,onSubmit:c}=e,[l,u]=(0,U.useState)(Be(t));return(0,W.jsxs)(te,{className:`flex max-h-[calc(100vh-2rem)] flex-col overflow-hidden border-none bg-popover p-0 sm:max-h-[760px] sm:max-w-xl`,children:[(0,W.jsx)(`div`,{className:`shrink-0 border-b border-border px-6 py-6`,children:(0,W.jsxs)(D,{className:`text-left`,children:[(0,W.jsx)(O,{children:i(`agentsEditDialogTitle`)}),(0,W.jsx)(T,{children:i(`agentsEditDialogDescription`)})]})}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain px-6 py-6`,children:(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(h,{tone:`warning`,title:i(`agentsEditHomeReadonly`),description:i(`agentsEditHomeReadonlyHint`),children:(0,W.jsx)(`div`,{className:`break-all text-sm text-amber-950`,children:t.workspace??`-`})}),(0,W.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,W.jsx)(m,{value:l.displayName,onChange:e=>u(t=>({...t,displayName:e.target.value})),placeholder:i(`agentsFormNamePlaceholder`)}),(0,W.jsx)(He,{value:l.description,onChange:e=>u(t=>({...t,description:e.target.value})),placeholder:i(`agentsFormDescriptionPlaceholder`),rows:4,className:`md:col-span-2`}),(0,W.jsx)(m,{value:l.avatar,onChange:e=>u(t=>({...t,avatar:e.target.value})),placeholder:i(`agentsFormAvatarPlaceholder`)}),(0,W.jsx)(ne,{value:l.model,onChange:e=>u(t=>({...t,model:e})),providerCatalog:r,disabled:n,className:`md:col-span-2`}),(0,W.jsx)(We,{value:l.runtime,onChange:e=>u(t=>({...t,runtime:e})),runtimeOptions:a,defaultRuntime:o,disabled:n})]}),(0,W.jsx)(Re,{form:l,disabled:n,onChange:e=>u(t=>({...t,...e}))})]})}),(0,W.jsxs)(C,{className:`shrink-0 border-t border-border px-6 py-5`,children:[(0,W.jsx)(f,{type:`button`,variant:`ghost`,onClick:()=>s(!1),disabled:n,children:i(`cancel`)}),(0,W.jsxs)(f,{type:`button`,variant:`primary`,className:`rounded-2xl px-5`,onClick:()=>c(t.id,l),disabled:n,children:[(0,W.jsx)(H,{className:`mr-2 h-4 w-4`}),i(`agentsEditSaveAction`)]})]})]})}var qe=`请直接创建一个默认示例 Agent,不要问我问题。创建完成后,简单告诉我它能做什么。`;function Je(e){let t=e.trim();if(!t)return null;let n=Number(t);if(!Number.isFinite(n))throw Error(i(`agentsAdvancedInvalidNumberError`));return Math.trunc(n)}function Ye(e){return{displayName:e.displayName,description:e.description,avatar:e.avatar,model:e.model,...e.runtime.trim()?{runtime:e.runtime.trim()}:{runtime:``},contextTokens:Je(e.contextTokens)}}function Q(e){let{icon:n,label:r,disabled:i=!1,destructive:a=!1,onClick:o}=e;return(0,W.jsxs)(`button`,{type:`button`,className:t(`flex w-full items-center gap-2 rounded-lg px-3 py-2 text-left text-sm transition-colors disabled:cursor-not-allowed disabled:opacity-50`,a?`text-destructive hover:bg-destructive/10`:`text-foreground hover:bg-muted`),onClick:o,disabled:i,children:[(0,W.jsx)(n,{className:`h-4 w-4 shrink-0`}),(0,W.jsx)(`span`,{children:r})]})}function Xe(e){let{agent:t,runtimeOptions:n,defaultRuntimeLabel:r,updatePending:a,deletePending:o,onStartChat:s,onView:c,onEdit:l,onDelete:u}=e,d=t.runtime?.trim()||t.engine?.trim()||``,p=d?n.find(e=>e.value===F(d))?.label??R(d):r;return(0,W.jsx)(P,{className:`group overflow-hidden border border-border bg-card shadow-none transition-colors duration-200 hover:border-border/80`,children:(0,W.jsxs)(V,{className:`relative flex h-full flex-col gap-3 px-3.5 py-3.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2.5 pr-16`,children:[(0,W.jsx)(B,{agentId:t.id,displayName:t.displayName,avatarUrl:t.avatarUrl,className:`h-9 w-9 shrink-0`}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-0.5`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`div`,{className:`truncate text-sm font-semibold text-foreground`,children:t.displayName?.trim()||t.id}),t.builtIn?(0,W.jsxs)(ie,{tone:`warning`,className:`h-5 gap-1 border-amber-200 bg-amber-50 px-1.5 text-[10px] text-amber-700`,children:[(0,W.jsx)(se,{className:`h-3 w-3`}),i(`agentsCardBuiltInTag`)]}):null]}),(0,W.jsxs)(`div`,{className:`truncate text-xs text-muted-foreground`,children:[`@`,t.id]})]})]}),(0,W.jsxs)(`div`,{className:`absolute right-2.5 top-2.5 flex items-center gap-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100 md:group-focus-within:opacity-100`,children:[(0,W.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-lg text-muted-foreground hover:text-foreground`,"aria-label":i(`agentsCardStartChat`),title:i(`agentsCardStartChat`),onClick:s,children:(0,W.jsx)(me,{className:`h-4 w-4`})}),(0,W.jsxs)(ve,{children:[(0,W.jsx)(xe,{asChild:!0,children:(0,W.jsx)(f,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8 rounded-lg text-muted-foreground hover:text-foreground`,"aria-label":i(`chatSessionMoreActions`),title:i(`chatSessionMoreActions`),children:(0,W.jsx)(le,{className:`h-4 w-4`})})}),(0,W.jsxs)(Ee,{align:`end`,className:`w-44 p-1.5`,children:[(0,W.jsx)(Q,{icon:oe,label:i(`agentsViewDetailsAction`),onClick:c}),(0,W.jsx)(Q,{icon:H,label:i(`agentsEditAction`),onClick:l,disabled:a}),t.builtIn?null:(0,W.jsx)(Q,{icon:ue,label:i(`agentsRemoveAction`),onClick:u,disabled:o,destructive:!0})]})]})]}),(0,W.jsx)(`p`,{className:`line-clamp-2 min-h-10 text-sm leading-5 text-muted-foreground`,children:t.description?.trim()||(t.builtIn?i(`agentsCardBuiltInSummary`):i(`agentsCardCustomSummary`))}),(0,W.jsxs)(`div`,{className:`mt-auto grid gap-2 border-t border-border/60 pt-2 text-xs text-muted-foreground`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(w,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/60`}),(0,W.jsx)(`span`,{className:`truncate`,children:p})]}),(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(pe,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/60`}),(0,W.jsx)(`span`,{className:`truncate`,children:t.workspace??`-`})]})]})]})})}function Ze(){let e=I(),t=de(),n=N(),r=j(),a=A(),o=L(),s=_e(),c=ae(),[u,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),_=(0,U.useMemo)(()=>t.data?.agents??[],[t.data?.agents]),v=(0,U.useMemo)(()=>[..._].sort((e,t)=>Number(!!t.builtIn)-Number(!!e.builtIn)||e.id.localeCompare(t.id)),[_]),ee=(0,U.useMemo)(()=>fe({config:n.data,providersView:r.data,templatesView:a.data,onlyConfigured:!0}),[n.data,r.data,a.data]),y=(0,U.useMemo)(()=>Ce(o.data?.options??[]),[o.data?.options]),b=(0,U.useMemo)(()=>F(o.data?.defaultType??`native`),[o.data?.defaultType]),x=(0,U.useMemo)(()=>y.find(e=>e.value===b)?.label??R(b),[b,y]),S=n.data?.agents.defaults,C=e=>{m(e)},w=e=>{g(e)},T=async(e,t)=>{let n;try{n=Ye(t)}catch(e){p.error(e instanceof Error?e.message:i(`agentsAdvancedParseFailed`));return}await s.mutateAsync({agentId:e,data:n}),g(null)},E=t=>{e.chatSessionListManager.startAgentDraftChat(t.id,Oe(t,b))},D=()=>{e.chatSessionListManager.startAgentDraftChat(`main`,b,qe)};return(0,W.jsxs)(l,{className:`space-y-6`,children:[(0,W.jsx)(d,{headingLevel:1,title:i(`agentsHeroEyebrow`),description:i(`agentsHeroDescription`),actions:(0,W.jsxs)(f,{type:`button`,variant:`primary`,className:`h-9 shrink-0 rounded-xl px-4 text-sm font-semibold`,onClick:D,children:[(0,W.jsx)(k,{className:`mr-2 h-4 w-4`}),i(`agentsCreateButton`)]})}),(0,W.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:t.isLoading?(0,W.jsx)(P,{className:`md:col-span-2 xl:col-span-3 border-dashed border-border bg-card/70`,children:(0,W.jsx)(V,{className:`py-14 text-center text-sm text-muted-foreground`,children:i(`agentsLoading`)})}):v.length===0?(0,W.jsx)(P,{className:`md:col-span-2 xl:col-span-3 overflow-hidden border-dashed border-border bg-gradient-subtle`,children:(0,W.jsxs)(V,{className:`flex min-h-[240px] flex-col items-center justify-center px-6 py-14 text-center`,children:[(0,W.jsx)(`div`,{className:`mb-4 flex h-16 w-16 items-center justify-center rounded-full bg-card/80 shadow-[0_18px_44px_rgba(0,0,0,0.08)]`,children:(0,W.jsx)(M,{className:`h-8 w-8 text-warning`})}),(0,W.jsx)(`div`,{className:`text-lg font-semibold text-foreground`,children:i(`agentsEmpty`)}),(0,W.jsx)(`p`,{className:`mt-2 max-w-md text-sm leading-6 text-muted-foreground`,children:i(`agentsEmptyDescription`)}),(0,W.jsxs)(f,{type:`button`,variant:`primary`,className:`mt-5 rounded-2xl px-5`,onClick:D,children:[(0,W.jsx)(k,{className:`mr-2 h-4 w-4`}),i(`agentsCreateButton`)]})]})}):v.map(e=>(0,W.jsx)(Xe,{agent:e,runtimeOptions:y,defaultRuntimeLabel:x,updatePending:s.isPending,deletePending:c.isPending,onStartChat:()=>E(e),onView:()=>C(e),onEdit:()=>w(e),onDelete:()=>c.mutate({agentId:e.id})},e.id))}),(0,W.jsx)(Pe,{agent:u,defaults:S,runtimeOptions:y,defaultRuntime:b,defaultRuntimeLabel:x,onOpenChange:e=>{e||m(null)},onEdit:e=>{m(null),g(e)}}),(0,W.jsx)(Ge,{agent:h,pending:s.isPending,providerCatalog:ee,runtimeOptions:y,defaultRuntime:b,onOpenChange:e=>{!e&&!s.isPending&&g(null)},onSubmit:T})]})}var $=`max-w-[min(1180px,100%)]`;function Qe(e){let{routeSessionKey:t,syncRouteSessionSelection:n}=e;(0,U.useLayoutEffect)(()=>{n(t)},[t,n])}function $e({view:e,confirmDialog:t}){let{isMobile:n}=ye();return(0,W.jsxs)(`div`,{className:`h-full flex`,children:[n?null:(0,W.jsx)(De,{}),e===`chat`?n?(0,W.jsx)(Ae,{}):(0,W.jsx)(Te,{}):(0,W.jsx)(`section`,{className:`flex-1 min-h-0 overflow-hidden bg-background`,children:e===`inbox`?(0,W.jsx)(`div`,{className:`mx-auto flex h-full min-h-0 w-full flex-col py-4 sm:px-6 sm:py-5 ${$}`,children:(0,W.jsx)(je,{})}):e===`cron`?(0,W.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar`,children:(0,W.jsx)(`div`,{className:`mx-auto w-full px-4 py-4 sm:px-6 sm:py-5 ${$}`,children:(0,W.jsx)(be,{})})}):e===`agents`?(0,W.jsx)(`div`,{className:`h-full overflow-auto custom-scrollbar`,children:(0,W.jsx)(`div`,{className:`mx-auto w-full px-4 py-4 sm:px-6 sm:py-5 ${$}`,children:(0,W.jsx)(Ze,{})})}):(0,W.jsx)(`div`,{className:`h-full overflow-hidden`,children:(0,W.jsx)(`div`,{className:`mx-auto flex h-full min-h-0 w-full flex-col px-4 py-4 sm:px-6 sm:py-5 ${$}`,children:(0,W.jsx)(ke,{forcedType:`skills`})})})}),t]})}function et(e){let t=I(),n=N(),r=j(),i=A(),a=we({limit:200}),o=L(),s=e.sessionKey?.trim()||`draft-session`,c=ge({sessionId:s});(0,U.useEffect)(()=>{t.chatQueryManager.syncSnapshot({configQuery:n,providersQuery:r,providerTemplatesQuery:i,sessionsQuery:a,sessionTypesQuery:o,sessionSkillsSessionId:s,sessionSkillsQuery:c})},[n,t.chatQueryManager,r,s,c,a,o,i])}function tt(){let e=I();(0,U.useEffect)(()=>u.eventBus.on(n.uiShowContent,t=>{e.chatThreadManager.handleUiShowContentEvent(t)}),[e])}function nt(){let{sessionId:e}=s(),t=(0,U.useMemo)(()=>he(e),[e]);return{routeSessionKey:t,sessionKey:t??void 0}}function rt(){let e=I(),{confirm:t,ConfirmDialog:n}=g(),r=c(),i=o();return(0,U.useEffect)(()=>{e.chatUiManager.syncState({pathname:r.pathname}),e.chatUiManager.bindActions({navigate:i,confirm:t})},[t,r.pathname,i,e]),(0,W.jsx)(n,{})}function it({view:e}){let t=z();return(0,W.jsx)(Me,{presenter:(0,U.useMemo)(()=>new Se(t),[t]),children:(0,W.jsx)(at,{view:e})})}function at({view:e}){let t=z(),n=I(),r=rt(),{routeSessionKey:i,sessionKey:a}=nt();return(0,U.useEffect)(()=>(t.chatCompletionNotificationManager.syncActiveSession(a??null),()=>{t.chatCompletionNotificationManager.syncActiveSession(null)}),[t.chatCompletionNotificationManager,a]),et({sessionKey:a??null}),Qe({routeSessionKey:i,syncRouteSessionSelection:n.chatSessionListManager.syncRouteSessionSelection}),tt(),(0,W.jsx)($e,{view:e,confirmDialog:r})}function ot({view:e}){return(0,W.jsx)(it,{view:e})}export{ot as ChatPage};
|