- Updated chat message types to include tool statuses. - Enhanced localization files for English, Thai, and Chinese to support new tool status messages. - Modified HomePage and SkillsPage components to handle tool statuses in chat messages. - Implemented tool status merging and updating logic in the chat store. - Added handling for tool status events in the gateway event processing. - Created tests for chat message rendering with tool statuses and skill installation shortcuts. - Improved gateway event dispatching for tool lifecycle events.
140 lines
3.0 KiB
TypeScript
140 lines
3.0 KiB
TypeScript
import type { RawMessage } from '@runtime/shared/chat-model';
|
|
|
|
export type RuntimeRefreshTopic =
|
|
| 'providers'
|
|
| 'models'
|
|
| 'agents'
|
|
| 'channels'
|
|
| 'channel-targets'
|
|
| 'skills';
|
|
|
|
export type GatewayToolStatus = 'running' | 'completed' | 'error';
|
|
|
|
/// Gateway 向 Renderer 推送的事件类型
|
|
export type GatewayEvent =
|
|
| {
|
|
type: 'chat:delta';
|
|
sessionKey: string;
|
|
runId: string;
|
|
delta: string;
|
|
}
|
|
| {
|
|
type: 'chat:final';
|
|
sessionKey: string;
|
|
runId: string;
|
|
message: RawMessage;
|
|
}
|
|
| {
|
|
type: 'chat:error';
|
|
sessionKey: string;
|
|
runId: string;
|
|
error: string;
|
|
}
|
|
| {
|
|
type: 'chat:aborted';
|
|
sessionKey: string;
|
|
runId: string;
|
|
}
|
|
| {
|
|
type: 'tool:status';
|
|
sessionKey: string;
|
|
runId: string;
|
|
toolName: string;
|
|
status: GatewayToolStatus;
|
|
updatedAt: number;
|
|
toolCallId?: string;
|
|
summary?: string;
|
|
durationMs?: number;
|
|
input?: unknown;
|
|
result?: unknown;
|
|
}
|
|
| {
|
|
type: 'gateway:status';
|
|
status: 'connected' | 'disconnected' | 'reconnecting';
|
|
}
|
|
| {
|
|
type: 'runtime:changed';
|
|
topics: RuntimeRefreshTopic[];
|
|
reason?: string;
|
|
syncedAt: string;
|
|
warnings?: string[];
|
|
channelType?: string;
|
|
accountId?: string;
|
|
};
|
|
|
|
/// Gateway RPC 方法参数映射
|
|
export interface GatewayRpcParams {
|
|
'chat.send': {
|
|
sessionKey: string;
|
|
message: RawMessage;
|
|
options?: {
|
|
providerAccountId?: string;
|
|
};
|
|
};
|
|
'chat.history': {
|
|
sessionKey: string;
|
|
limit?: number;
|
|
};
|
|
'chat.abort': {
|
|
sessionKey: string;
|
|
};
|
|
'session.list': Record<string, never>;
|
|
'session.delete': {
|
|
sessionKey: string;
|
|
};
|
|
'provider.list': Record<string, never>;
|
|
'provider.getDefault': Record<string, never>;
|
|
'skills.status': Record<string, never>;
|
|
'skills.update': {
|
|
skillKey: string;
|
|
enabled?: boolean;
|
|
};
|
|
'skills.install': {
|
|
kind: 'marketplace';
|
|
slug: string;
|
|
version?: string;
|
|
force?: boolean;
|
|
} | {
|
|
kind: 'github-url';
|
|
url: string;
|
|
force?: boolean;
|
|
};
|
|
}
|
|
|
|
/// Gateway RPC 方法返回值映射
|
|
export interface GatewayRpcReturns {
|
|
'chat.send': { runId: string };
|
|
'chat.history': RawMessage[];
|
|
'chat.abort': void;
|
|
'session.list': string[];
|
|
'session.delete': { success: boolean };
|
|
'provider.list': { accounts: any[]; defaultAccountId: string | null };
|
|
'provider.getDefault': { accountId: string | null };
|
|
'skills.status': {
|
|
skills: Array<{
|
|
skillKey: string;
|
|
slug?: string;
|
|
name?: string;
|
|
description?: string;
|
|
disabled?: boolean;
|
|
emoji?: string;
|
|
version?: string;
|
|
author?: string;
|
|
config?: Record<string, unknown>;
|
|
bundled?: boolean;
|
|
always?: boolean;
|
|
source?: string;
|
|
baseDir?: string;
|
|
filePath?: string;
|
|
}>;
|
|
};
|
|
'skills.update': { success: boolean };
|
|
'skills.install': {
|
|
success: true;
|
|
slug: string;
|
|
baseDir: string;
|
|
source: 'marketplace' | 'github-url';
|
|
enabled: true;
|
|
};
|
|
}
|