@steerable/agent-shell-web 0.14.3 → 0.14.5
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 +189 -46
- package/src/components/ChatHeader.tsx +12 -1
- package/src/components/SidebarAccount.tsx +33 -41
- package/src/components/chat/AssistantMessage.tsx +36 -10
- package/src/components/chat/ChatInput.tsx +308 -131
- package/src/components/chat/ChatProjectBadge.tsx +311 -100
- package/src/components/chat/ContextUsagePill.tsx +20 -5
- package/src/components/chat/ExecPolicyPicker.tsx +72 -67
- package/src/components/chat/LocalChatPanel.tsx +33 -35
- package/src/components/chat/Markdown.tsx +109 -11
- package/src/components/chat/MessageList.tsx +109 -19
- package/src/components/chat/ModelPicker.tsx +2 -2
- package/src/components/chat/PlanTodoList.tsx +184 -78
- package/src/components/chat/SessionTodoList.tsx +63 -72
- package/src/components/chat/TurnFilesCard.tsx +270 -112
- package/src/components/chat/TurnProcessGroup.tsx +3 -0
- package/src/components/chat/TurnProcessTimeline.tsx +13 -0
- package/src/components/chat/UserMessage.tsx +8 -1
- package/src/components/chat/next-steps-tags.ts +13 -0
- package/src/components/chat/process-status.ts +112 -2
- package/src/components/chat/todo-list-model.ts +52 -4
- package/src/layouts/AgentLayout.tsx +173 -10
- package/src/layouts/PanelToggleButton.tsx +27 -9
- package/src/layouts/conversation-preview.ts +3 -0
- package/src/layouts/request-chat-slot.ts +20 -0
- package/src/layouts/right-panel-tabs.ts +32 -0
- package/src/lib/chat-mode-store.ts +241 -0
- package/src/lib/file-preview-registry.ts +57 -0
- package/src/pages/AgentPage.tsx +188 -78
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
extractLatestProposedPlan,
|
|
4
|
+
type ParsedProposedPlan,
|
|
5
|
+
} from '@steerable/agent-protocol';
|
|
6
|
+
import { clampWebChatMode, getWebChatModes, type ChatModeId } from './host-tools';
|
|
7
|
+
|
|
8
|
+
const CHAT_MODE_SESSION_STORAGE_KEY = 'steerable:chat-mode-by-id:v1';
|
|
9
|
+
const DISMISSED_PLANS_STORAGE_KEY = 'steerable:dismissed-plan-msgs:v1';
|
|
10
|
+
const MAX_STORED_ENTRIES = 100;
|
|
11
|
+
|
|
12
|
+
function readSessionMap(): Record<string, ChatModeId> {
|
|
13
|
+
if (typeof sessionStorage === 'undefined') return {};
|
|
14
|
+
try {
|
|
15
|
+
const raw = sessionStorage.getItem(CHAT_MODE_SESSION_STORAGE_KEY);
|
|
16
|
+
if (!raw) return {};
|
|
17
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
18
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) return {};
|
|
19
|
+
const out: Record<string, ChatModeId> = {};
|
|
20
|
+
for (const [k, v] of Object.entries(parsed as Record<string, unknown>)) {
|
|
21
|
+
if (v === 'plan' || v === 'agent') {
|
|
22
|
+
out[k] = v;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
} catch {
|
|
27
|
+
return {};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function writeSessionMap(map: Record<string, ChatModeId>): void {
|
|
32
|
+
if (typeof sessionStorage === 'undefined') return;
|
|
33
|
+
try {
|
|
34
|
+
const entries = Object.entries(map);
|
|
35
|
+
const trimmed =
|
|
36
|
+
entries.length > MAX_STORED_ENTRIES
|
|
37
|
+
? Object.fromEntries(entries.slice(entries.length - MAX_STORED_ENTRIES))
|
|
38
|
+
: map;
|
|
39
|
+
sessionStorage.setItem(CHAT_MODE_SESSION_STORAGE_KEY, JSON.stringify(trimmed));
|
|
40
|
+
} catch {
|
|
41
|
+
// Ignore storage quota errors in private browsing contexts.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function extractMessageMode(messageMetadata: unknown): ChatModeId | null {
|
|
46
|
+
if (!messageMetadata) return null;
|
|
47
|
+
try {
|
|
48
|
+
const parsed =
|
|
49
|
+
typeof messageMetadata === 'string'
|
|
50
|
+
? (JSON.parse(messageMetadata) as Record<string, unknown>)
|
|
51
|
+
: (messageMetadata as Record<string, unknown>);
|
|
52
|
+
if (parsed?.mode === 'plan') return 'plan';
|
|
53
|
+
if (parsed?.mode === 'agent') return 'agent';
|
|
54
|
+
} catch {
|
|
55
|
+
// Ignore malformed historical metadata.
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Resolve the initial chat mode for a specific `chatId` without cross-chat leakage.
|
|
62
|
+
* New chats always default to `'agent'`; existing chats restore their session-scoped
|
|
63
|
+
* selection or infer from the latest persisted user message metadata.
|
|
64
|
+
*/
|
|
65
|
+
export function readChatModeForSession(
|
|
66
|
+
chatId: string,
|
|
67
|
+
messages?: ReadonlyArray<{ role: string; messageMetadata?: unknown }>,
|
|
68
|
+
): ChatModeId {
|
|
69
|
+
if (chatId) {
|
|
70
|
+
const map = readSessionMap();
|
|
71
|
+
const saved = map[chatId];
|
|
72
|
+
if (saved) return clampWebChatMode(saved);
|
|
73
|
+
}
|
|
74
|
+
if (messages && messages.length > 0) {
|
|
75
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
76
|
+
const msg = messages[i]!;
|
|
77
|
+
if (msg.role !== 'user') continue;
|
|
78
|
+
const msgMode = extractMessageMode(msg.messageMetadata);
|
|
79
|
+
return clampWebChatMode(msgMode ?? 'agent');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return clampWebChatMode('agent');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function writeChatModeForSession(chatId: string, mode: ChatModeId): void {
|
|
86
|
+
if (!chatId) return;
|
|
87
|
+
const map = readSessionMap();
|
|
88
|
+
map[chatId] = clampWebChatMode(mode);
|
|
89
|
+
writeSessionMap(map);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function clearChatModeStoreForTests(): void {
|
|
93
|
+
if (typeof sessionStorage === 'undefined') return;
|
|
94
|
+
sessionStorage.removeItem(CHAT_MODE_SESSION_STORAGE_KEY);
|
|
95
|
+
sessionStorage.removeItem(DISMISSED_PLANS_STORAGE_KEY);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function readDismissedSet(): Set<string> {
|
|
99
|
+
if (typeof sessionStorage === 'undefined') return new Set();
|
|
100
|
+
try {
|
|
101
|
+
const raw = sessionStorage.getItem(DISMISSED_PLANS_STORAGE_KEY);
|
|
102
|
+
if (!raw) return new Set();
|
|
103
|
+
const parsed = JSON.parse(raw) as unknown;
|
|
104
|
+
if (!Array.isArray(parsed)) return new Set();
|
|
105
|
+
return new Set(parsed.filter((item): item is string => typeof item === 'string'));
|
|
106
|
+
} catch {
|
|
107
|
+
return new Set();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function isPlanMessageDismissed(chatId: string, messageId: string): boolean {
|
|
112
|
+
if (!chatId || !messageId) return false;
|
|
113
|
+
return readDismissedSet().has(`${chatId}:${messageId}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function dismissPlanMessage(chatId: string, messageId: string): void {
|
|
117
|
+
if (!chatId || !messageId || typeof sessionStorage === 'undefined') return;
|
|
118
|
+
try {
|
|
119
|
+
const current = Array.from(readDismissedSet());
|
|
120
|
+
const key = `${chatId}:${messageId}`;
|
|
121
|
+
if (!current.includes(key)) current.push(key);
|
|
122
|
+
const trimmed =
|
|
123
|
+
current.length > MAX_STORED_ENTRIES
|
|
124
|
+
? current.slice(current.length - MAX_STORED_ENTRIES)
|
|
125
|
+
: current;
|
|
126
|
+
sessionStorage.setItem(DISMISSED_PLANS_STORAGE_KEY, JSON.stringify(trimmed));
|
|
127
|
+
} catch {
|
|
128
|
+
// Ignore storage quota errors.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface ParsedModeSlashCommand {
|
|
133
|
+
targetMode: ChatModeId;
|
|
134
|
+
remainder: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Parse built-in `/plan` and `/agent` composer commands:
|
|
139
|
+
* - `/plan` -> switch to Plan mode without sending
|
|
140
|
+
* - `/plan off` -> switch to Agent mode without sending
|
|
141
|
+
* - `/plan <goal>` -> switch to Plan mode and submit `<goal>` in Plan mode
|
|
142
|
+
* - `/agent` -> switch to Agent mode without sending
|
|
143
|
+
* - `/agent <task>` -> switch to Agent mode and submit `<task>` in Agent mode
|
|
144
|
+
*/
|
|
145
|
+
export function parseModeSlashCommand(rawText: string): ParsedModeSlashCommand | null {
|
|
146
|
+
if (!getWebChatModes().includes('plan')) return null;
|
|
147
|
+
const trimmed = rawText.trim();
|
|
148
|
+
const planMatch = trimmed.match(/^\/plan(?:\s+([\s\S]*))?$/i);
|
|
149
|
+
if (planMatch) {
|
|
150
|
+
const rest = (planMatch[1] ?? '').trim();
|
|
151
|
+
if (rest.toLowerCase() === 'off') {
|
|
152
|
+
return { targetMode: 'agent', remainder: '' };
|
|
153
|
+
}
|
|
154
|
+
return { targetMode: 'plan', remainder: rest };
|
|
155
|
+
}
|
|
156
|
+
const agentMatch = trimmed.match(/^\/agent(?:\s+([\s\S]*))?$/i);
|
|
157
|
+
if (agentMatch) {
|
|
158
|
+
const rest = (agentMatch[1] ?? '').trim();
|
|
159
|
+
return { targetMode: 'agent', remainder: rest };
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface ActionablePlanState {
|
|
165
|
+
messageId: string;
|
|
166
|
+
plan: ParsedProposedPlan;
|
|
167
|
+
contextUsedPercent: number | null;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function resolveActionablePlan(input: {
|
|
171
|
+
chatId: string;
|
|
172
|
+
messages: ReadonlyArray<{
|
|
173
|
+
id: string;
|
|
174
|
+
role: string;
|
|
175
|
+
content: string;
|
|
176
|
+
messageMetadata?: unknown;
|
|
177
|
+
}>;
|
|
178
|
+
isStreaming: boolean;
|
|
179
|
+
interrupted?: boolean;
|
|
180
|
+
dismissedIds?: ReadonlySet<string>;
|
|
181
|
+
contextUsedPercent?: number | null;
|
|
182
|
+
}): ActionablePlanState | null {
|
|
183
|
+
const { chatId, messages, isStreaming, interrupted = false, dismissedIds, contextUsedPercent = null } =
|
|
184
|
+
input;
|
|
185
|
+
if (isStreaming || interrupted || messages.length === 0) return null;
|
|
186
|
+
if (!getWebChatModes().includes('plan')) return null;
|
|
187
|
+
|
|
188
|
+
const lastMessage = messages[messages.length - 1]!;
|
|
189
|
+
if (lastMessage.role !== 'assistant' || !lastMessage.content) return null;
|
|
190
|
+
|
|
191
|
+
if (dismissedIds?.has(lastMessage.id) || isPlanMessageDismissed(chatId, lastMessage.id)) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Skip turns that recorded a terminal failure or user cancellation in metadata.
|
|
196
|
+
if (lastMessage.messageMetadata) {
|
|
197
|
+
try {
|
|
198
|
+
const meta =
|
|
199
|
+
typeof lastMessage.messageMetadata === 'string'
|
|
200
|
+
? (JSON.parse(lastMessage.messageMetadata) as Record<string, unknown>)
|
|
201
|
+
: (lastMessage.messageMetadata as Record<string, unknown>);
|
|
202
|
+
if (
|
|
203
|
+
meta?.turnFailure ||
|
|
204
|
+
meta?.stopped === true ||
|
|
205
|
+
meta?.status === 'failed' ||
|
|
206
|
+
meta?.status === 'cancelled'
|
|
207
|
+
) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
} catch {
|
|
211
|
+
// Ignore malformed metadata.
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const plan = extractLatestProposedPlan(lastMessage.content);
|
|
216
|
+
if (!plan || !plan.complete) return null;
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
messageId: lastMessage.id,
|
|
220
|
+
plan,
|
|
221
|
+
contextUsedPercent,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface PlanActionContextValue {
|
|
226
|
+
actionable: ActionablePlanState | null;
|
|
227
|
+
onExecuteInPlace: () => void;
|
|
228
|
+
onExecuteInFreshChat?: (planMarkdown: string) => void;
|
|
229
|
+
onDismiss: (messageId: string) => void;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export const PlanActionContext = createContext<PlanActionContextValue | null>(null);
|
|
233
|
+
export const CurrentMessageIdContext = createContext<string | null>(null);
|
|
234
|
+
|
|
235
|
+
export function usePlanActionContext(): PlanActionContextValue | null {
|
|
236
|
+
return useContext(PlanActionContext);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export function useCurrentMessageId(): string | null {
|
|
240
|
+
return useContext(CurrentMessageIdContext);
|
|
241
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Product-neutral registry for in-app deliverable preview handlers.
|
|
3
|
+
*
|
|
4
|
+
* Host packs register file matchers and side-panel openers here so
|
|
5
|
+
* `DeliverableCard` can render a first-class `Preview` button without
|
|
6
|
+
* coupling `@steerable/agent-shell-web` to specific document packs.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface DeliverablePreviewOpenInput {
|
|
10
|
+
chatId: string | null;
|
|
11
|
+
messageId?: string;
|
|
12
|
+
filePath: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface DeliverablePreviewHandler {
|
|
16
|
+
id: string;
|
|
17
|
+
canPreview: (filePath: string) => boolean;
|
|
18
|
+
openPreview: (input: DeliverablePreviewOpenInput) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const handlers = new Map<string, DeliverablePreviewHandler>();
|
|
22
|
+
const listeners = new Set<() => void>();
|
|
23
|
+
|
|
24
|
+
function notify(): void {
|
|
25
|
+
for (const listener of listeners) listener();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function registerDeliverablePreviewer(handler: DeliverablePreviewHandler): () => void {
|
|
29
|
+
handlers.set(handler.id, handler);
|
|
30
|
+
notify();
|
|
31
|
+
return () => {
|
|
32
|
+
if (handlers.get(handler.id) === handler) {
|
|
33
|
+
handlers.delete(handler.id);
|
|
34
|
+
notify();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function findDeliverablePreviewer(filePath: string): DeliverablePreviewHandler | null {
|
|
40
|
+
if (!filePath) return null;
|
|
41
|
+
for (const handler of handlers.values()) {
|
|
42
|
+
if (handler.canPreview(filePath)) return handler;
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function subscribeDeliverablePreviewers(listener: () => void): () => void {
|
|
48
|
+
listeners.add(listener);
|
|
49
|
+
return () => {
|
|
50
|
+
listeners.delete(listener);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function clearDeliverablePreviewersForTests(): void {
|
|
55
|
+
handlers.clear();
|
|
56
|
+
notify();
|
|
57
|
+
}
|