feat: extend supply workbench demo and map navigation

This commit is contained in:
2026-09-23 13:19:30 +08:00
parent bebcf2a06c
commit 1752b9ef84
45 changed files with 2137 additions and 449 deletions
@@ -21,6 +21,7 @@ import {
type AgentApprovalMode,
type AgentChatMessage,
type AgentConnectionStatus,
type AgentEventTriggerContext,
type AgentModelOption,
type AgentPermissionReply,
type AgentPermissionRequest,
@@ -694,6 +695,70 @@ export function useWorkbenchAgent({
[approvalMode, chat, selectedModel, streaming]
);
const triggerEvent = useCallback(
async (trigger: AgentEventTriggerContext, prompt: string) => {
if (streaming) {
throw new Error("Agent 正在处理上一条指令,请稍后重试事件触发。");
}
stopSessionStreamSubscription();
const reserved = await clientRef.current.createSession({ triggerContext: trigger });
const nextSessionId = reserved.session_id;
const loadedSession = await clientRef.current.loadSession(nextSessionId);
if (!loadedSession) {
throw new Error("Agent 事件会话创建后无法读取。");
}
applySessionId(nextSessionId);
setSessionTitle(loadedSession.title || "水质投诉事件调查");
setPermissionOverrides({});
setQuestionOverrides({});
const nextMessages = toAgentUiMessages(loadedSession.messages);
chat.setMessages(nextMessages);
setStreamRenderState(createCompletedStreamRenderState(nextMessages));
setConnectionStatus("online");
if (loadedSession.runStatus === "running" || loadedSession.isStreaming) {
setStatusLabel("Agent 事件调查进行中");
startSessionStreamSubscription(nextSessionId);
return { sessionId: nextSessionId, reused: true };
}
if (nextMessages.length > 0) {
setStatusLabel("Agent 事件调查会话已打开");
await refreshSessionHistory();
return { sessionId: nextSessionId, reused: true };
}
setStatusLabel("Agent 正在调查水质投诉事件");
const eventRun = chat.sendMessage(
{ text: prompt },
{
body: {
session_id: nextSessionId,
model: selectedModel || undefined,
approval_mode: approvalMode,
trigger_context: trigger
}
}
);
void eventRun
.then(() => refreshSessionHistory())
.catch(() => undefined);
return { sessionId: nextSessionId, reused: reserved.event_duplicate === true };
},
[
approvalMode,
applySessionId,
chat,
refreshSessionHistory,
selectedModel,
startSessionStreamSubscription,
stopSessionStreamSubscription,
streaming
]
);
const stopPrompt = useCallback(() => {
chat.stop();
stopSessionStreamSubscription();
@@ -845,6 +910,7 @@ export function useWorkbenchAgent({
replyPermission,
replyQuestion,
resolveRenderRef,
triggerEvent,
submitPrompt
};
}