@steerable/agent-shell-web 0.12.8 → 0.14.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/package.json +4 -4
- package/src/components/AgentSidebar.tsx +9 -4
- package/src/components/SafeRecoveryBanner.tsx +64 -0
- package/src/components/chat/ApprovalModal.tsx +196 -133
- package/src/components/chat/AssistantMessage.tsx +40 -25
- package/src/components/chat/ChatInput.tsx +15 -1
- package/src/components/chat/ContextUsagePill.tsx +249 -0
- package/src/components/chat/MemorySaveNoticeBar.tsx +88 -0
- package/src/components/chat/MessageList.tsx +39 -0
- package/src/components/chat/TurnFailureCard.tsx +8 -0
- package/src/components/chat/turn-failure.ts +15 -3
- package/src/components/settings/DiagnoseSettingsPanel.tsx +2 -0
- package/src/components/settings/MemorySettingsPanel.tsx +370 -0
- package/src/layouts/AgentLayout.tsx +47 -1
- package/src/lib/browser-dev-host-mock.ts +134 -0
- package/src/lib/host-bridge.ts +2 -0
- package/src/lib/local-api.ts +48 -0
- package/src/lib/safe-mode.ts +83 -0
- package/src/packs/registry.ts +7 -0
- package/src/pages/AgentPage.tsx +82 -13
- package/src/pages/SettingsPage.tsx +11 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getHostBridge, hasHostBridge } from './host-bridge';
|
|
2
|
+
|
|
3
|
+
export type HiddenNavItem = 'skills' | 'mcp' | 'agents' | 'terminal';
|
|
4
|
+
|
|
5
|
+
export interface ActiveApplicationState {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly title: Readonly<Record<string, string>>;
|
|
8
|
+
readonly defaultAgentProfileId: string;
|
|
9
|
+
readonly allowedPackIds: readonly string[];
|
|
10
|
+
readonly defaultWorkbenchTabs: readonly string[];
|
|
11
|
+
readonly hiddenNavItems: readonly HiddenNavItem[];
|
|
12
|
+
readonly safeMode: boolean;
|
|
13
|
+
readonly customApplicationBypassed: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Detects `/?safe=1` (or `#/...?safe=1`) safe recovery mode so operators can
|
|
18
|
+
* always bypass a broken or overly restrictive ApplicationManifest.
|
|
19
|
+
*/
|
|
20
|
+
export function isSafeRecoveryMode(
|
|
21
|
+
loc: Pick<Location, 'search' | 'hash'> | undefined =
|
|
22
|
+
typeof window !== 'undefined' ? window.location : undefined,
|
|
23
|
+
): boolean {
|
|
24
|
+
if (!loc) return false;
|
|
25
|
+
if (new URLSearchParams(loc.search).get('safe') === '1') return true;
|
|
26
|
+
const hashQueryIdx = loc.hash.indexOf('?');
|
|
27
|
+
if (hashQueryIdx >= 0) {
|
|
28
|
+
const hashParams = new URLSearchParams(loc.hash.slice(hashQueryIdx + 1));
|
|
29
|
+
if (hashParams.get('safe') === '1') return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Strips `safe=1` from both `location.search` and `location.hash` after reset. */
|
|
35
|
+
export function stripSafeQueryParam(href: string): string {
|
|
36
|
+
try {
|
|
37
|
+
const url = new URL(href, 'http://localhost');
|
|
38
|
+
url.searchParams.delete('safe');
|
|
39
|
+
if (url.hash.includes('?')) {
|
|
40
|
+
const [hashPath, rawQuery] = url.hash.split('?', 2);
|
|
41
|
+
const hp = new URLSearchParams(rawQuery);
|
|
42
|
+
hp.delete('safe');
|
|
43
|
+
const qs = hp.toString();
|
|
44
|
+
url.hash = qs ? `${hashPath}?${qs}` : hashPath;
|
|
45
|
+
}
|
|
46
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
47
|
+
} catch {
|
|
48
|
+
return '#/';
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function fetchActiveApplication(
|
|
53
|
+
safeMode: boolean,
|
|
54
|
+
): Promise<ActiveApplicationState | null> {
|
|
55
|
+
if (!hasHostBridge()) return null;
|
|
56
|
+
const b = getHostBridge();
|
|
57
|
+
if (!b) return null;
|
|
58
|
+
try {
|
|
59
|
+
const data = await b.localBackend.request<{ application?: ActiveApplicationState }>({
|
|
60
|
+
method: 'GET',
|
|
61
|
+
path: `/api/v2/applications/active${safeMode ? '?safe=1' : ''}`,
|
|
62
|
+
});
|
|
63
|
+
return data?.application ?? null;
|
|
64
|
+
} catch {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function resetToDefaultApplication(): Promise<boolean> {
|
|
70
|
+
if (!hasHostBridge()) return false;
|
|
71
|
+
const b = getHostBridge();
|
|
72
|
+
if (!b) return false;
|
|
73
|
+
try {
|
|
74
|
+
const data = await b.localBackend.request<{ application?: ActiveApplicationState }>({
|
|
75
|
+
method: 'POST',
|
|
76
|
+
path: '/api/v2/applications/reset',
|
|
77
|
+
body: {},
|
|
78
|
+
});
|
|
79
|
+
return Boolean(data?.application);
|
|
80
|
+
} catch {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
}
|
package/src/packs/registry.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* 的 web/ 目录)。
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import type { ComponentType } from 'react';
|
|
12
13
|
import type {
|
|
13
14
|
PackChatSlotAutoRevealApi,
|
|
14
15
|
PackChatSlotContribution,
|
|
@@ -33,6 +34,7 @@ export type {
|
|
|
33
34
|
const routes: PackRouteContribution[] = [];
|
|
34
35
|
const settingsPanels: PackSettingsPanelContribution[] = [];
|
|
35
36
|
const chatSlots: PackChatSlotContribution[] = [];
|
|
37
|
+
const topBanners: ComponentType[] = [];
|
|
36
38
|
const hiddenSlashSkills = new Set<string>();
|
|
37
39
|
const registeredPacks = new Set<string>();
|
|
38
40
|
|
|
@@ -45,6 +47,7 @@ export function registerPackRenderer(packId: string, contributions: PackRenderer
|
|
|
45
47
|
routes.push(...(contributions.routes ?? []));
|
|
46
48
|
settingsPanels.push(...(contributions.settingsPanels ?? []));
|
|
47
49
|
chatSlots.push(...(contributions.chatSlots ?? []));
|
|
50
|
+
topBanners.push(...(contributions.topBanners ?? []));
|
|
48
51
|
for (const name of contributions.hiddenSlashSkills ?? []) hiddenSlashSkills.add(name);
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -60,6 +63,10 @@ export function getPackChatSlots(): readonly PackChatSlotContribution[] {
|
|
|
60
63
|
return chatSlots;
|
|
61
64
|
}
|
|
62
65
|
|
|
66
|
+
export function getPackTopBanners(): readonly ComponentType[] {
|
|
67
|
+
return topBanners;
|
|
68
|
+
}
|
|
69
|
+
|
|
63
70
|
/** 包贡献的隐藏 slash 技能名集合(bootstrap 完成后稳定,渲染期只读)。 */
|
|
64
71
|
export function getPackHiddenSlashSkills(): ReadonlySet<string> {
|
|
65
72
|
return hiddenSlashSkills;
|
package/src/pages/AgentPage.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import { ChatHeader } from "@/components/ChatHeader";
|
|
|
12
12
|
import { EmptyChatHero } from "@/components/chat/EmptyChatHero";
|
|
13
13
|
import type { RetryState } from "@/components/chat/RetryStatus";
|
|
14
14
|
import type { FailureAction } from "@/components/chat/turn-failure";
|
|
15
|
+
import { ContextUsagePill } from "@/components/chat/ContextUsagePill";
|
|
15
16
|
import { LocalChatPanel } from "@/components/chat/LocalChatPanel";
|
|
16
17
|
import { ModelPicker } from "@/components/chat/ModelPicker";
|
|
17
18
|
import {
|
|
@@ -58,6 +59,7 @@ import {
|
|
|
58
59
|
} from "@/components/chat/ChatProjectBadge";
|
|
59
60
|
import { ProjectTrustBanner } from "@/components/chat/ProjectTrustBanner";
|
|
60
61
|
import {
|
|
62
|
+
compactChat,
|
|
61
63
|
getChatLiveStream,
|
|
62
64
|
type ChatLiveStream,
|
|
63
65
|
type LocalChatMessage,
|
|
@@ -686,6 +688,8 @@ function AgentChatView({
|
|
|
686
688
|
persistExecPolicy(next);
|
|
687
689
|
}, []);
|
|
688
690
|
|
|
691
|
+
const setMessagesRef = useRef<((updater: (prev: any[]) => any[]) => void) | null>(null);
|
|
692
|
+
|
|
689
693
|
const handleUnknownEvent = useCallback((event: SSEEvent) => {
|
|
690
694
|
const ev = event as any;
|
|
691
695
|
if (ev.type !== "agent") return;
|
|
@@ -825,6 +829,23 @@ function AgentChatView({
|
|
|
825
829
|
}
|
|
826
830
|
pendingTurnUsageRef.current = undefined;
|
|
827
831
|
setTailAssistantDbId(messageId);
|
|
832
|
+
const persistedMetadata = ev.payload?.messageMetadata;
|
|
833
|
+
if (typeof persistedMetadata === "string" && persistedMetadata) {
|
|
834
|
+
setMessagesRef.current?.((prev) => {
|
|
835
|
+
for (let idx = prev.length - 1; idx >= 0; idx -= 1) {
|
|
836
|
+
if (prev[idx]?.role === "assistant") {
|
|
837
|
+
const next = [...prev];
|
|
838
|
+
next[idx] = {
|
|
839
|
+
...next[idx],
|
|
840
|
+
id: messageId,
|
|
841
|
+
messageMetadata: persistedMetadata,
|
|
842
|
+
};
|
|
843
|
+
return next;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return prev;
|
|
847
|
+
});
|
|
848
|
+
}
|
|
828
849
|
}
|
|
829
850
|
// AI 标题更新走的是后台 IPC 广播(chat-title-updated)而不是 SSE——
|
|
830
851
|
// 见 AgentLayout 里的订阅。SSE 通道在 [DONE] 之后就不再监听了,title-gen
|
|
@@ -857,6 +878,7 @@ function AgentChatView({
|
|
|
857
878
|
onUnknownEvent: handleUnknownEvent,
|
|
858
879
|
onStreamError: handleStreamError,
|
|
859
880
|
});
|
|
881
|
+
setMessagesRef.current = setMessages as any;
|
|
860
882
|
const awaitingRemoteActiveSnapshotRef = useRef(false);
|
|
861
883
|
useEffect(() => {
|
|
862
884
|
awaitingRemoteActiveSnapshotRef.current = false;
|
|
@@ -1040,6 +1062,20 @@ function AgentChatView({
|
|
|
1040
1062
|
|
|
1041
1063
|
const handleSubmit = useCallback(
|
|
1042
1064
|
(input: { content: string; metadata?: Record<string, unknown> }) => {
|
|
1065
|
+
const trimmedCmd = input.content.trim();
|
|
1066
|
+
if (/^\/compact(?:\s+|$)/i.test(trimmedCmd) && hasHostBridge()) {
|
|
1067
|
+
const focusArg = trimmedCmd.replace(/^\/compact\s*/i, "").trim();
|
|
1068
|
+
void compactChat(chatId, focusArg ? { focus: focusArg } : {})
|
|
1069
|
+
.then((res) => {
|
|
1070
|
+
if (res.compacted > 0) {
|
|
1071
|
+
onBranchTick();
|
|
1072
|
+
}
|
|
1073
|
+
})
|
|
1074
|
+
.catch((err: unknown) =>
|
|
1075
|
+
setNewChatError(err instanceof Error ? err.message : String(err)),
|
|
1076
|
+
);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1043
1079
|
trackBehavior('composer_send', {
|
|
1044
1080
|
empty: !input.content.trim(),
|
|
1045
1081
|
mode: input.metadata?.mode === 'plan' ? 'plan' : 'agent',
|
|
@@ -1087,7 +1123,7 @@ function AgentChatView({
|
|
|
1087
1123
|
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
1088
1124
|
});
|
|
1089
1125
|
},
|
|
1090
|
-
[sendUserMessage, modelOverride, effortOverride, execPolicy],
|
|
1126
|
+
[sendUserMessage, modelOverride, effortOverride, execPolicy, chatId, onBranchTick],
|
|
1091
1127
|
);
|
|
1092
1128
|
|
|
1093
1129
|
const handleEditUserMessage = useCallback(
|
|
@@ -1297,6 +1333,27 @@ function AgentChatView({
|
|
|
1297
1333
|
disabled: isStreaming,
|
|
1298
1334
|
hint: isStreaming ? t("This chat is running. Continue when it finishes.") : undefined,
|
|
1299
1335
|
};
|
|
1336
|
+
case "compact-and-retry":
|
|
1337
|
+
return hasHostBridge()
|
|
1338
|
+
? {
|
|
1339
|
+
onClick: () => {
|
|
1340
|
+
void compactChat(chatId)
|
|
1341
|
+
.then(() => {
|
|
1342
|
+
onBranchTick();
|
|
1343
|
+
void handleContinueInterrupted();
|
|
1344
|
+
})
|
|
1345
|
+
.catch((err: unknown) =>
|
|
1346
|
+
setNewChatError(err instanceof Error ? err.message : String(err)),
|
|
1347
|
+
);
|
|
1348
|
+
},
|
|
1349
|
+
disabled: isStreaming,
|
|
1350
|
+
hint: isStreaming
|
|
1351
|
+
? t("This chat is running. Continue when it finishes.")
|
|
1352
|
+
: undefined,
|
|
1353
|
+
}
|
|
1354
|
+
: null;
|
|
1355
|
+
case "open-license-settings":
|
|
1356
|
+
return null;
|
|
1300
1357
|
case "network-diagnostics":
|
|
1301
1358
|
// 诊断区挂在设置页「通用」下(settingsChrome('diagnose') 控制显隐)。
|
|
1302
1359
|
return settingsChrome("diagnose")
|
|
@@ -1330,10 +1387,12 @@ function AgentChatView({
|
|
|
1330
1387
|
[
|
|
1331
1388
|
chat?.agentId,
|
|
1332
1389
|
chat?.projectId,
|
|
1390
|
+
chatId,
|
|
1333
1391
|
ctx,
|
|
1334
1392
|
handleContinueInterrupted,
|
|
1335
1393
|
isStreaming,
|
|
1336
1394
|
navigate,
|
|
1395
|
+
onBranchTick,
|
|
1337
1396
|
],
|
|
1338
1397
|
);
|
|
1339
1398
|
|
|
@@ -1602,18 +1661,28 @@ function AgentChatView({
|
|
|
1602
1661
|
: undefined
|
|
1603
1662
|
}
|
|
1604
1663
|
inputToolbarExtras={
|
|
1605
|
-
<
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1664
|
+
<div className="inline-flex items-center gap-1.5">
|
|
1665
|
+
<ModelPicker
|
|
1666
|
+
model={modelOverride}
|
|
1667
|
+
reasoningEffort={effortOverride}
|
|
1668
|
+
onSelectModel={setModelOverride}
|
|
1669
|
+
onSelectEffort={setEffortOverride}
|
|
1670
|
+
onOpenSettings={
|
|
1671
|
+
hasHostBridge() && settingsChrome("llm")
|
|
1672
|
+
? () => setLlmSettingsOpen(true)
|
|
1673
|
+
: undefined
|
|
1674
|
+
}
|
|
1675
|
+
disabled={isStreaming}
|
|
1676
|
+
/>
|
|
1677
|
+
<ContextUsagePill
|
|
1678
|
+
chatId={chatId}
|
|
1679
|
+
messageCount={effectiveMessages.length}
|
|
1680
|
+
isStreaming={effectiveIsStreaming}
|
|
1681
|
+
livePromptTokens={currentTurnUsage?.promptTokens}
|
|
1682
|
+
liveCachedPromptTokens={currentTurnUsage?.cachedPromptTokens}
|
|
1683
|
+
onCompacted={() => onBranchTick()}
|
|
1684
|
+
/>
|
|
1685
|
+
</div>
|
|
1617
1686
|
}
|
|
1618
1687
|
mode={mode}
|
|
1619
1688
|
onModeChange={handleModeChange}
|
|
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } fr
|
|
|
2
2
|
import {
|
|
3
3
|
LuActivity,
|
|
4
4
|
LuBlocks,
|
|
5
|
+
LuBookOpen,
|
|
5
6
|
LuBot,
|
|
6
7
|
LuChartBar,
|
|
7
8
|
LuCodeXml,
|
|
@@ -21,6 +22,7 @@ import { getLocale, t } from '@/i18n';
|
|
|
21
22
|
import { useAppRelease } from '@/components/SidebarRelease';
|
|
22
23
|
import { AgentsSettingsPanel } from '@/components/settings/AgentsSettingsPanel';
|
|
23
24
|
import { AppearanceSettingsPanel } from '@/components/settings/AppearanceSettingsPanel';
|
|
25
|
+
import { MemorySettingsPanel } from '@/components/settings/MemorySettingsPanel';
|
|
24
26
|
import { OrchestrationSettingsPanel } from '@/components/settings/OrchestrationSettingsPanel';
|
|
25
27
|
import { AppUpdateSettingsPanel } from '@/components/settings/AppUpdateSettingsPanel';
|
|
26
28
|
import { PortableSettingsPanel } from '@/components/settings/PortableSettingsPanel';
|
|
@@ -209,6 +211,7 @@ export function SettingsPage() {
|
|
|
209
211
|
if (settingsChrome('security')) {
|
|
210
212
|
list.push({ id: 'security', label: t('Security'), Icon: LuShieldCheck });
|
|
211
213
|
}
|
|
214
|
+
list.push({ id: 'memory', label: t('Memory'), Icon: LuBookOpen });
|
|
212
215
|
if (settingsChrome('insights')) {
|
|
213
216
|
list.push({ id: 'insights', label: t('Help improve the product'), Icon: LuChartBar });
|
|
214
217
|
}
|
|
@@ -471,6 +474,14 @@ export function SettingsPage() {
|
|
|
471
474
|
</section>
|
|
472
475
|
)}
|
|
473
476
|
|
|
477
|
+
<section className="space-y-2" data-testid="settings-section-memory">
|
|
478
|
+
<h2 className="flex items-center gap-1.5 text-xs font-semibold text-agent-foreground">
|
|
479
|
+
<LuBookOpen className="h-3.5 w-3.5 text-agent-muted-foreground" />
|
|
480
|
+
{t('Memory')}
|
|
481
|
+
</h2>
|
|
482
|
+
<MemorySettingsPanel />
|
|
483
|
+
</section>
|
|
484
|
+
|
|
474
485
|
{settingsChrome('insights') && (
|
|
475
486
|
<section className="space-y-2" data-testid="settings-section-insights">
|
|
476
487
|
<h2 className="flex items-center gap-1.5 text-xs font-semibold text-agent-foreground">
|