feat: extend supply workbench demo and map navigation
This commit is contained in:
@@ -17,9 +17,51 @@ export async function mockAgentApi(page: Page, options: MockAgentApiOptions = {}
|
||||
description: "Playwright 浏览器测试",
|
||||
icon: "bolt" as const
|
||||
};
|
||||
const triggeredSessions = new Map<string, { sessionId: string; triggerId: string }>();
|
||||
await page.route("**/api/v1/agent/chat/**", async (route) => {
|
||||
const pathname = new URL(route.request().url()).pathname;
|
||||
|
||||
if (pathname.endsWith("/session") && route.request().method() === "POST") {
|
||||
const body = route.request().postDataJSON() as {
|
||||
trigger_context?: { trigger_id?: string };
|
||||
};
|
||||
const triggerId = body.trigger_context?.trigger_id;
|
||||
const existing = triggerId ? triggeredSessions.get(triggerId) : undefined;
|
||||
const sessionId = existing?.sessionId ?? `browser-session-${triggeredSessions.size + 1}`;
|
||||
if (triggerId && !existing) triggeredSessions.set(triggerId, { sessionId, triggerId });
|
||||
await route.fulfill({
|
||||
status: existing ? 200 : 201,
|
||||
json: {
|
||||
session_id: sessionId,
|
||||
title: "水质投诉事件调查",
|
||||
status: "active",
|
||||
created_at: "2026-09-22T02:00:00Z",
|
||||
updated_at: "2026-09-22T02:00:00Z",
|
||||
created: !existing,
|
||||
event_duplicate: Boolean(existing),
|
||||
trigger_id: triggerId
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const sessionMatch = pathname.match(/\/session\/([^/]+)$/);
|
||||
if (sessionMatch && route.request().method() === "GET") {
|
||||
await route.fulfill({
|
||||
json: {
|
||||
id: sessionMatch[1],
|
||||
session_id: sessionMatch[1],
|
||||
title: "水质投诉事件调查",
|
||||
status: "active",
|
||||
created_at: "2026-09-22T02:00:00Z",
|
||||
updated_at: "2026-09-22T02:00:00Z",
|
||||
messages: [],
|
||||
is_streaming: false
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (pathname.endsWith("/stream")) {
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
|
||||
@@ -8,7 +8,10 @@ export async function mockWorkbenchContext(
|
||||
projectPresentation?: { metadata: unknown; accessContext: unknown },
|
||||
analysisRuns: Record<string, unknown> = {},
|
||||
analysisHistory: unknown[] = [],
|
||||
options: { runtimeMode?: "auto" | "demo" | "history" | "backend" } = {}
|
||||
options: {
|
||||
runtimeMode?: "auto" | "demo" | "history" | "backend";
|
||||
tiandituToken?: string;
|
||||
} = {}
|
||||
) {
|
||||
await mockScadaApi(
|
||||
page,
|
||||
@@ -29,6 +32,7 @@ export async function mockWorkbenchContext(
|
||||
TJWATER_MAP_URL: "https://workbench-map.invalid/geoserver",
|
||||
TJWATER_GEOSERVER_WORKSPACE: "tjwater_next",
|
||||
TJWATER_MAPBOX_ACCESS_TOKEN: "",
|
||||
TJWATER_TIANDITU_TOKEN: options.tiandituToken ?? "",
|
||||
TJWATER_WORKBENCH_RUNTIME_MODE: options.runtimeMode ?? "auto",
|
||||
TJWATER_ENABLE_MSW: "false"
|
||||
})};`
|
||||
|
||||
Reference in New Issue
Block a user