mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 04:51:51 +00:00
fix(ui): remove unsupported Lighthouse run cancellation
This commit is contained in:
@@ -271,15 +271,6 @@ export function buildLighthouseV2MessagePayload(input: {
|
||||
};
|
||||
}
|
||||
|
||||
export function buildLighthouseV2CancelRunPayload(taskId: string) {
|
||||
return {
|
||||
data: {
|
||||
type: "lighthouse-run-cancellations",
|
||||
attributes: { task_id: taskId },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function validateLighthouseV2ConfigurationInput(input: {
|
||||
providerType: LighthouseV2ProviderType;
|
||||
credentials?: LighthouseV2Credentials;
|
||||
|
||||
@@ -12,13 +12,11 @@ import type {
|
||||
LighthouseV2Session,
|
||||
LighthouseV2SupportedModel,
|
||||
LighthouseV2SupportedProvider,
|
||||
LighthouseV2Task,
|
||||
} from "@/app/(prowler)/lighthouse/_types";
|
||||
import { apiBaseUrl, getAuthHeaders } from "@/lib/helper";
|
||||
import { handleApiError, handleApiResponse } from "@/lib/server-actions-helper";
|
||||
|
||||
import {
|
||||
buildLighthouseV2CancelRunPayload,
|
||||
buildLighthouseV2ConfigurationPayload,
|
||||
buildLighthouseV2ConfigurationUpdatePayload,
|
||||
buildLighthouseV2MessagePayload,
|
||||
@@ -265,21 +263,6 @@ export async function sendLighthouseV2Message(
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelLighthouseV2Run(
|
||||
sessionId: string,
|
||||
taskId: string,
|
||||
): Promise<LighthouseV2ActionResult<LighthouseV2Task>> {
|
||||
return mutateSingle(
|
||||
`/lighthouse/sessions/${encodeURIComponent(sessionId)}/cancel-run`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify(buildLighthouseV2CancelRunPayload(taskId)),
|
||||
},
|
||||
mapLighthouseV2Task,
|
||||
"/lighthouse",
|
||||
);
|
||||
}
|
||||
|
||||
async function getCollection<TResource, TOutput>(
|
||||
path: string,
|
||||
mapper: (resource: TResource) => TOutput,
|
||||
|
||||
@@ -25,7 +25,6 @@ interface ChatComposerPanelProps {
|
||||
modelSelector: ReactNode;
|
||||
selectedConfigurationConnected: boolean;
|
||||
onInputChange: (value: string) => void;
|
||||
onStop: () => void;
|
||||
onSubmit: (event: SubmitEvent<HTMLFormElement>) => void;
|
||||
onSubmitText: (text: string) => Promise<void>;
|
||||
}
|
||||
@@ -87,9 +86,6 @@ interface ChatComposerProps {
|
||||
modelSelector: ReactNode;
|
||||
selectedConfigurationConnected: boolean;
|
||||
onInputChange: (value: string) => void;
|
||||
// Kept on the contract but unused for now: the backend can't cancel a run yet,
|
||||
// so the stop control is replaced by a non-interactive spinner.
|
||||
onStop: () => void;
|
||||
onSubmit: (event: SubmitEvent<HTMLFormElement>) => void;
|
||||
onSubmitText: (text: string) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,6 @@ interface ChatEmptyStateProps {
|
||||
modelSelector: ReactNode;
|
||||
selectedConfigurationConnected: boolean;
|
||||
onInputChange: (value: string) => void;
|
||||
onStop: () => void;
|
||||
onSubmit: (event: SubmitEvent<HTMLFormElement>) => void;
|
||||
onSubmitText: (text: string) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -59,13 +59,11 @@ function stubEventSource() {
|
||||
}
|
||||
|
||||
const {
|
||||
cancelRunMock,
|
||||
createSessionMock,
|
||||
getMessagesMock,
|
||||
sendMessageMock,
|
||||
updateConfigurationMock,
|
||||
} = vi.hoisted(() => ({
|
||||
cancelRunMock: vi.fn(),
|
||||
createSessionMock: vi.fn(),
|
||||
getMessagesMock: vi.fn(),
|
||||
sendMessageMock: vi.fn(),
|
||||
@@ -73,7 +71,6 @@ const {
|
||||
}));
|
||||
|
||||
vi.mock("@/app/(prowler)/lighthouse/_actions", () => ({
|
||||
cancelLighthouseV2Run: cancelRunMock,
|
||||
createLighthouseV2Session: createSessionMock,
|
||||
getLighthouseV2Messages: getMessagesMock,
|
||||
sendLighthouseV2Message: sendMessageMock,
|
||||
@@ -138,7 +135,6 @@ describe("LighthouseV2ChatPage", () => {
|
||||
configurable: true,
|
||||
value: vi.fn(),
|
||||
});
|
||||
cancelRunMock.mockReset();
|
||||
createSessionMock.mockReset();
|
||||
getMessagesMock.mockReset();
|
||||
sendMessageMock.mockReset();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { type SubmitEvent, useRef, useState } from "react";
|
||||
|
||||
import {
|
||||
cancelLighthouseV2Run,
|
||||
createLighthouseV2Session,
|
||||
getLighthouseV2Messages,
|
||||
sendLighthouseV2Message,
|
||||
@@ -151,7 +150,6 @@ export function LighthouseV2ChatPage({
|
||||
) => {
|
||||
if (
|
||||
event.type === LIGHTHOUSE_V2_SSE_EVENT.MESSAGE_END ||
|
||||
event.type === LIGHTHOUSE_V2_SSE_EVENT.RUN_CANCELLED ||
|
||||
event.type === LIGHTHOUSE_V2_SSE_EVENT.ERROR
|
||||
) {
|
||||
closeStream();
|
||||
@@ -195,11 +193,6 @@ export function LighthouseV2ChatPage({
|
||||
source.addEventListener("message.end", (event) =>
|
||||
applyEvent(parseStreamEvent(event, LIGHTHOUSE_V2_SSE_EVENT.MESSAGE_END)),
|
||||
);
|
||||
source.addEventListener("run.cancelled", (event) =>
|
||||
applyEvent(
|
||||
parseStreamEvent(event, LIGHTHOUSE_V2_SSE_EVENT.RUN_CANCELLED),
|
||||
),
|
||||
);
|
||||
source.addEventListener("error", (event) => {
|
||||
if (event instanceof MessageEvent) {
|
||||
applyEvent(parseStreamEvent(event, LIGHTHOUSE_V2_SSE_EVENT.ERROR));
|
||||
@@ -339,25 +332,6 @@ export function LighthouseV2ChatPage({
|
||||
void submitMessage(input);
|
||||
};
|
||||
|
||||
const handleStop = async () => {
|
||||
if (!activeSessionId || !streamState.activeTaskId) return;
|
||||
const taskId = streamState.activeTaskId;
|
||||
const result = await cancelLighthouseV2Run(activeSessionId, taskId);
|
||||
closeStream();
|
||||
setStreamState((current) =>
|
||||
reduceLighthouseV2Event(current, {
|
||||
type: "run.cancelled",
|
||||
taskId,
|
||||
}),
|
||||
);
|
||||
setBlockedByConflict(false);
|
||||
await refreshMessages(activeSessionId);
|
||||
notifyLighthouseV2SessionsChanged();
|
||||
if ("error" in result) {
|
||||
setFeedback(result.error);
|
||||
}
|
||||
};
|
||||
|
||||
useMountEffect(() => {
|
||||
if (initialSessionId && initialActiveTaskId && initialStreamUrl) {
|
||||
startStream(initialStreamUrl, initialSessionId);
|
||||
@@ -427,7 +401,6 @@ export function LighthouseV2ChatPage({
|
||||
),
|
||||
selectedConfigurationConnected: selectedConfiguration?.connected === true,
|
||||
onInputChange: setInput,
|
||||
onStop: handleStop,
|
||||
onSubmit: handleSubmit,
|
||||
onSubmitText: submitMessage,
|
||||
};
|
||||
|
||||
@@ -112,22 +112,6 @@ describe("event-reducer", () => {
|
||||
expect(next.activeTaskId).toBeNull();
|
||||
});
|
||||
|
||||
it("should mark run cancellation as terminal without error", () => {
|
||||
// Given
|
||||
const state = createInitialLighthouseV2StreamState("task-1");
|
||||
|
||||
// When
|
||||
const next = reduceLighthouseV2Event(state, {
|
||||
type: "run.cancelled",
|
||||
taskId: "task-1",
|
||||
});
|
||||
|
||||
// Then
|
||||
expect(next.status).toBe("cancelled");
|
||||
expect(next.error).toBeUndefined();
|
||||
expect(next.activeTaskId).toBeNull();
|
||||
});
|
||||
|
||||
it("should store terminal errors", () => {
|
||||
// Given
|
||||
const state = createInitialLighthouseV2StreamState("task-1");
|
||||
|
||||
@@ -7,7 +7,6 @@ export const LIGHTHOUSE_V2_STREAM_STATUS = {
|
||||
IDLE: "idle",
|
||||
STREAMING: "streaming",
|
||||
COMPLETED: "completed",
|
||||
CANCELLED: "cancelled",
|
||||
ERROR: "error",
|
||||
DISCONNECTED: "disconnected",
|
||||
} as const;
|
||||
@@ -141,12 +140,6 @@ export function reduceLighthouseV2Event(
|
||||
activeTaskId: null,
|
||||
messageId: event.messageId,
|
||||
};
|
||||
case LIGHTHOUSE_V2_SSE_EVENT.RUN_CANCELLED:
|
||||
return {
|
||||
...state,
|
||||
status: LIGHTHOUSE_V2_STREAM_STATUS.CANCELLED,
|
||||
activeTaskId: null,
|
||||
};
|
||||
case LIGHTHOUSE_V2_SSE_EVENT.ERROR:
|
||||
return {
|
||||
...state,
|
||||
|
||||
@@ -37,12 +37,6 @@ export function parseStreamEvent(
|
||||
messageId: readString(data, "message_id"),
|
||||
};
|
||||
}
|
||||
if (type === LIGHTHOUSE_V2_SSE_EVENT.RUN_CANCELLED) {
|
||||
return {
|
||||
type,
|
||||
taskId: readString(data, "task_id"),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: LIGHTHOUSE_V2_SSE_EVENT.ERROR,
|
||||
code: readString(data, "code"),
|
||||
|
||||
@@ -3,7 +3,6 @@ export const LIGHTHOUSE_V2_SSE_EVENT = {
|
||||
TOOL_CALL_START: "tool_call.start",
|
||||
TOOL_CALL_END: "tool_call.end",
|
||||
MESSAGE_END: "message.end",
|
||||
RUN_CANCELLED: "run.cancelled",
|
||||
ERROR: "error",
|
||||
DISCONNECT: "disconnect",
|
||||
} as const;
|
||||
@@ -33,11 +32,6 @@ export interface LighthouseV2MessageEndEvent {
|
||||
messageId: string;
|
||||
}
|
||||
|
||||
export interface LighthouseV2RunCancelledEvent {
|
||||
type: typeof LIGHTHOUSE_V2_SSE_EVENT.RUN_CANCELLED;
|
||||
taskId: string;
|
||||
}
|
||||
|
||||
export interface LighthouseV2ErrorEvent {
|
||||
type: typeof LIGHTHOUSE_V2_SSE_EVENT.ERROR;
|
||||
code: string;
|
||||
@@ -53,6 +47,5 @@ export type LighthouseV2SSEEvent =
|
||||
| LighthouseV2ToolCallStartEvent
|
||||
| LighthouseV2ToolCallEndEvent
|
||||
| LighthouseV2MessageEndEvent
|
||||
| LighthouseV2RunCancelledEvent
|
||||
| LighthouseV2ErrorEvent
|
||||
| LighthouseV2DisconnectEvent;
|
||||
|
||||
Reference in New Issue
Block a user