Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/edge/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ export function handleExtensionMessage(
});
break;
}
case "error": {
const id = edgeRegistry.findInstanceByWs(ws);
if (!id) return;
upstream.send({
type: "instance_error",
payload: {
instanceId: id,
message: msg.payload.message,
action: msg.payload.action,
},
});
break;
}
case "quit": {
const id = edgeRegistry.findInstanceByWs(ws);
if (id) {
Expand Down
8 changes: 8 additions & 0 deletions src/extensions/paimon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,14 @@ function handleHubMessage(
if (ctx && ctx.isIdle()) {
ctx.compact({
customInstructions: msg.payload?.customInstructions,
onError: (error: Error) => {
if (client.connected) {
client.send({
type: "error",
payload: { message: error.message, action: "compact" },
});
}
},
});
}
break;
Expand Down
17 changes: 17 additions & 0 deletions src/hub/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,23 @@ export function handleEdgeMessage(
hubRegistry.unregisterInstance(msg.payload.instanceId);
break;
}
case "instance_error": {
const subscribers = hubRegistry.getSubscribers(msg.payload.instanceId);
if (subscribers.length > 0) {
const errorMsg = JSON.stringify({
type: "instance_error",
payload: {
instanceId: msg.payload.instanceId,
message: msg.payload.message,
action: msg.payload.action,
},
});
for (const browser of subscribers) {
browser.send(errorMsg);
}
}
break;
}
case "spawn_result": {
hubRegistry.resolveSpawn(
msg.payload.token,
Expand Down
35 changes: 34 additions & 1 deletion src/protocol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,19 @@ export type ExtensionToEdgeMessage =
| ExtStateMessage
| ExtHistoryMessage
| ExtSessionListMessage
| ExtErrorMessage
| ExtQuitMessage;

/** 操作失败通知 */
export interface ExtErrorMessage {
type: "error";
payload: {
message: string;
/** 触发错误的操作 */
action?: string;
};
}

/** 主动退出通知(跳过 grace period) */
export interface ExtQuitMessage {
type: "quit";
Expand Down Expand Up @@ -491,6 +502,7 @@ export type HubToBrowserMessage =
| HubForwardedEventMessage
| HubHistoryMessage
| HubSessionListMessage
| HubInstanceErrorMessage
| HubErrorMessage;

/** 实例列表 */
Expand Down Expand Up @@ -547,7 +559,17 @@ export interface HubSessionListMessage {
};
}

/** 错误 */
/** 实例操作错误 */
export interface HubInstanceErrorMessage {
type: "instance_error";
payload: {
instanceId: InstanceId;
message: string;
action?: string;
};
}

/** 系统级错误 */
export interface HubErrorMessage {
type: "error";
payload: {
Expand Down Expand Up @@ -582,6 +604,7 @@ export type EdgeToHubMessage =
| EdgeInstanceStateMessage
| EdgeInstanceHistoryMessage
| EdgeInstanceSessionListMessage
| EdgeInstanceErrorMessage
| EdgeInstanceQuitMessage
| EdgeSpawnResultMessage
| EdgeBrowseResultMessage;
Expand Down Expand Up @@ -662,6 +685,16 @@ export interface EdgeInstanceSessionListMessage {
};
}

/** 转发:pi 操作失败 */
export interface EdgeInstanceErrorMessage {
type: "instance_error";
payload: {
instanceId: InstanceId;
message: string;
action?: string;
};
}

/** 转发:pi 主动退出 */
export interface EdgeInstanceQuitMessage {
type: "instance_quit";
Expand Down
17 changes: 17 additions & 0 deletions src/web/src/components/InstanceView/useConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// 6. 暴露 loadMore() 加载更多历史

import { useState, useEffect, useCallback, useRef } from "react";
import { useTranslation } from "react-i18next";
import type {
InstanceId,
InstanceInfo,
Expand All @@ -17,6 +18,7 @@ import type {
} from "../../../../protocol/types";
import { useWebSocket } from "../../stores/useWebSocket";
import type { SessionEntry, ConversationLoadState } from "../../stores/types";
import { showToast } from "../ui/Toast";

// ── 返回值类型 ──

Expand Down Expand Up @@ -63,6 +65,7 @@ export function useConversation(
instanceId: InstanceId,
instance: InstanceInfo | undefined,
): ConversationState {
const { t } = useTranslation();
const send = useWebSocket((s) => s.send);
const subscribe = useWebSocket((s) => s.subscribe);
const connected = useWebSocket((s) => s.connectionState === "connected");
Expand Down Expand Up @@ -140,6 +143,20 @@ export function useConversation(
setErrorMessage(msg.payload.message);
break;
}
case "instance_error": {
if (msg.payload.instanceId !== instanceId) return;
const actionKey = msg.payload.action
? `error.action.${msg.payload.action}`
: null;
const localizedMsg = actionKey
? t(actionKey, {
message: msg.payload.message,
defaultValue: msg.payload.message,
})
: msg.payload.message;
showToast(localizedMsg);
break;
}
}
});
}, [instanceId, subscribe]);
Expand Down
3 changes: 3 additions & 0 deletions src/web/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ const en: LocaleResource = {
message: "Error message",
type: "Error type",
requestId: "Request ID",
action: {
compact: "Compaction failed: {{message}}",
},
},
} as const;

Expand Down
3 changes: 3 additions & 0 deletions src/web/src/i18n/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ const zhCN = {
message: "错误信息",
type: "错误类型",
requestId: "请求 ID",
action: {
compact: "压缩失败:{{message}}",
},
},
} as const;

Expand Down