@steerable/agent-shell-web 0.14.2 → 0.14.4
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/chat/ApprovalModal.tsx +426 -124
- package/src/components/chat/AssistantMessage.tsx +37 -11
- package/src/components/chat/ChatInput.tsx +172 -71
- package/src/components/chat/ChatProjectBadge.tsx +89 -23
- package/src/components/chat/ContextUsagePill.tsx +73 -21
- package/src/components/chat/ExecPolicyPicker.tsx +2 -2
- package/src/components/chat/ExecutedActionsCard.tsx +886 -180
- package/src/components/chat/LocalChatPanel.tsx +31 -5
- package/src/components/chat/Markdown.tsx +109 -11
- package/src/components/chat/ModelPicker.tsx +5 -2
- package/src/components/chat/PlanTodoList.tsx +184 -78
- package/src/components/chat/TurnProcessGroup.tsx +37 -3
- package/src/components/chat/TurnProcessTimeline.tsx +533 -50
- package/src/components/chat/executed-actions-model.ts +1103 -61
- package/src/components/chat/process-status.ts +72 -4
- package/src/components/chat/rich-tool-views.tsx +666 -0
- package/src/components/chat/todo-list-model.ts +15 -0
- package/src/components/chat/turn-timeline.ts +51 -4
- package/src/components/settings/LlmSettingsPanel.tsx +1 -1
- package/src/components/settings/llm-vendors.ts +1 -1
- package/src/lib/browser-dev-host-mock.ts +1 -1
- package/src/lib/chat-mode-store.ts +241 -0
- package/src/pages/AgentPage.tsx +183 -77
- package/src/styles/index.css +10 -25
|
@@ -205,10 +205,18 @@ export function parseTurnBlocks(raw: unknown): TurnBlock[] | null {
|
|
|
205
205
|
* Trailing text is the final conclusion — but only after the turn finishes.
|
|
206
206
|
* While streaming, every text block stays in the process as a post-think
|
|
207
207
|
* response so the next reasoning burst cannot restyle it as thinking.
|
|
208
|
+
*
|
|
209
|
+
* When a finished turn ends with terminal housekeeping tool calls (`todo_write`
|
|
210
|
+
* marking all items done, or `present_files`) emitted alongside the final text,
|
|
211
|
+
* promote that concluding text block to `answer` while keeping the housekeeping
|
|
212
|
+
* tools inside `process`.
|
|
208
213
|
*/
|
|
209
214
|
export function splitTurnProcess<TTool = ExecutedAction>(
|
|
210
215
|
blocks: ReadonlyArray<ProcessTimelineBlock<TTool>>,
|
|
211
|
-
options?: {
|
|
216
|
+
options?: {
|
|
217
|
+
finalize?: boolean;
|
|
218
|
+
isTrailingHousekeepingTool?: (action: TTool) => boolean;
|
|
219
|
+
},
|
|
212
220
|
): {
|
|
213
221
|
process: ProcessTimelineBlock<TTool>[];
|
|
214
222
|
answer: Extract<ProcessTimelineBlock<TTool>, { type: 'text' }>[];
|
|
@@ -218,10 +226,49 @@ export function splitTurnProcess<TTool = ExecutedAction>(
|
|
|
218
226
|
return { process: [...blocks], answer: [] };
|
|
219
227
|
}
|
|
220
228
|
let split = blocks.length;
|
|
221
|
-
while (split > 0 && blocks[split - 1]
|
|
229
|
+
while (split > 0 && blocks[split - 1]!.type === 'text') split -= 1;
|
|
230
|
+
if (split < blocks.length) {
|
|
231
|
+
return {
|
|
232
|
+
process: blocks.slice(0, split),
|
|
233
|
+
answer: blocks.slice(split) as Extract<ProcessTimelineBlock<TTool>, { type: 'text' }>[],
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const isHousekeeping = options?.isTrailingHousekeepingTool;
|
|
238
|
+
if (isHousekeeping) {
|
|
239
|
+
let housekeepingStart = blocks.length;
|
|
240
|
+
while (housekeepingStart > 0) {
|
|
241
|
+
const candidate = blocks[housekeepingStart - 1]!;
|
|
242
|
+
if (
|
|
243
|
+
candidate.type === 'tools' &&
|
|
244
|
+
candidate.actions.length > 0 &&
|
|
245
|
+
candidate.actions.every(isHousekeeping)
|
|
246
|
+
) {
|
|
247
|
+
housekeepingStart -= 1;
|
|
248
|
+
} else {
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (housekeepingStart < blocks.length) {
|
|
253
|
+
let answerStart = housekeepingStart;
|
|
254
|
+
while (answerStart > 0 && blocks[answerStart - 1]!.type === 'text') {
|
|
255
|
+
answerStart -= 1;
|
|
256
|
+
}
|
|
257
|
+
const trailingAnswer = blocks.slice(answerStart, housekeepingStart) as Array<
|
|
258
|
+
Extract<ProcessTimelineBlock<TTool>, { type: 'text' }>
|
|
259
|
+
>;
|
|
260
|
+
if (trailingAnswer.some((block) => block.content.trim().length > 0)) {
|
|
261
|
+
return {
|
|
262
|
+
process: [...blocks.slice(0, answerStart), ...blocks.slice(housekeepingStart)],
|
|
263
|
+
answer: trailingAnswer,
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
222
269
|
return {
|
|
223
|
-
process: blocks
|
|
224
|
-
answer:
|
|
270
|
+
process: [...blocks],
|
|
271
|
+
answer: [],
|
|
225
272
|
};
|
|
226
273
|
}
|
|
227
274
|
|
|
@@ -89,7 +89,7 @@ export const LlmSettingsPanel = forwardRef<LlmSettingsPanelHandle, LlmSettingsPa
|
|
|
89
89
|
const [settings, setSettings] = useState<LlmSettings>({
|
|
90
90
|
provider: 'openai-compat',
|
|
91
91
|
vendorId: 'deepseek',
|
|
92
|
-
model: 'deepseek-
|
|
92
|
+
model: 'deepseek-flash',
|
|
93
93
|
baseUrl: 'https://api.deepseek.com',
|
|
94
94
|
apiKey: '',
|
|
95
95
|
// temperature 缺省 = 自动(命中厂商预制用预制值,否则不下发)。
|
|
@@ -60,7 +60,7 @@ export const FALLBACK_VENDORS: CatalogProviderDescriptor[] = [
|
|
|
60
60
|
apiBaseUrl: 'https://api.deepseek.com',
|
|
61
61
|
envVars: ['DEEPSEEK_API_KEY'],
|
|
62
62
|
wireKind: 'openai_compat',
|
|
63
|
-
models: ['deepseek-
|
|
63
|
+
models: ['deepseek-flash', 'deepseek-v4-pro'],
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
id: 'openai',
|
|
@@ -132,7 +132,7 @@ const DEMO_CATALOG_PROVIDERS: CatalogProviderDescriptor[] = [
|
|
|
132
132
|
apiBaseUrl: 'https://api.deepseek.com/v1',
|
|
133
133
|
envVars: ['DEEPSEEK_API_KEY'],
|
|
134
134
|
wireKind: 'openai-compat',
|
|
135
|
-
models: ['deepseek-
|
|
135
|
+
models: ['deepseek-flash', 'deepseek-v4-pro'],
|
|
136
136
|
},
|
|
137
137
|
{
|
|
138
138
|
id: 'anthropic',
|
|
@@ -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
|
+
}
|