Skip to content

Commit e559543

Browse files
author
linyuan.yang
committed
polish
1 parent d57160a commit e559543

5 files changed

Lines changed: 16 additions & 22 deletions

File tree

packages/chat-ui/src/WebSocketTransport.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,26 @@ export class WebSocketTransport implements IChatTransport {
3737

3838
connect(): void {
3939
if (this.ws?.readyState === WebSocket.CONNECTING || this.ws?.readyState === WebSocket.OPEN) return
40+
if (this.reconnectTimer) { clearTimeout(this.reconnectTimer); this.reconnectTimer = null }
4041
const url = this._baseUrl ? new URL(this._baseUrl) : location
4142
const proto = url.protocol === 'https:' ? 'wss:' : 'ws:'
42-
const host = url.host
43-
const ws = new WebSocket(`${proto}//${host}/ws/chat`)
43+
const ws = new WebSocket(`${proto}//${url.host}/ws/chat`)
4444
this.ws = ws
4545
ws.onopen = () => {
4646
this.emit({ type: ChatEventType.ConnectionStatus, online: true } as ChatEvent)
4747
}
4848
ws.onmessage = (e: MessageEvent) => {
4949
let msg: any
5050
try { msg = JSON.parse(e.data as string) } catch { return }
51-
const type = msg.type as string
52-
if (SESSION_EVENT_TYPES.has(type)) {
53-
this.emit({ type, sessionId: msg.sessionId, data: msg.data } as ChatEvent)
51+
if (msg && SESSION_EVENT_TYPES.has(msg.type)) {
52+
this.emit({ type: msg.type, sessionId: msg.sessionId, data: msg.data } as ChatEvent)
5453
}
5554
}
5655
ws.onclose = () => {
5756
if (this.ws === ws) this.ws = null
5857
this.emit({ type: ChatEventType.ConnectionStatus, online: false } as ChatEvent)
5958
this.reconnectTimer = setTimeout(() => this.connect(), 3000)
6059
}
61-
ws.onerror = () => {}
6260
}
6361

6462
disconnect(): void {

packages/chat-ui/src/components/RichInput.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function fileToDataUrl(file: File): Promise<string> {
2828
})
2929
}
3030
31-
function handleImageDrop(view: any, event: DragEvent, _slice: any, moved: boolean): boolean {
31+
function handleImageDrop(_view: any, event: DragEvent, _slice: any, moved: boolean): boolean {
3232
if (moved || !event.dataTransfer?.files?.length) return false
3333
const allFiles = Array.from(event.dataTransfer.files)
3434
const images = allFiles.filter(f => f.type.startsWith('image/'))
@@ -44,7 +44,7 @@ function handleImageDrop(view: any, event: DragEvent, _slice: any, moved: boolea
4444
return true
4545
}
4646
47-
function handleImagePaste(view: any, event: ClipboardEvent): boolean {
47+
function handleImagePaste(_view: any, event: ClipboardEvent): boolean {
4848
const items = Array.from(event.clipboardData?.items ?? [])
4949
const fileItems = items.filter(i => i.kind === 'file')
5050
if (fileItems.length === 0) return false

packages/chat-ui/src/components/ThinkDrawer.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ function close() {
5555
thinkStack.value = []
5656
}
5757
58-
function onNestedThink(thinkId: string) {
59-
open(thinkId)
60-
}
61-
6258
defineExpose({ open })
6359
</script>
6460

@@ -94,7 +90,7 @@ defineExpose({ open })
9490
:thinks-url-prefix="thinksUrlPrefix"
9591
:labels="labels"
9692
:fetch-fn="fetchFn"
97-
:on-think-click="onNestedThink"
93+
:on-think-click="open"
9894
/>
9995
</template>
10096
</div>

packages/chat-ui/src/components/ToolApprovalBar.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ const countdown = ref(props.initialCountdown)
1818
const argsExpanded = ref(false)
1919
let timer: ReturnType<typeof setInterval> | null = null
2020
21+
function stopTimer() {
22+
if (timer) { clearInterval(timer); timer = null }
23+
}
24+
2125
function startTimer() {
2226
stopTimer()
2327
countdown.value = props.initialCountdown
2428
timer = setInterval(() => { if (countdown.value > 0) countdown.value-- }, 1000)
2529
}
2630
27-
function stopTimer() {
28-
if (timer !== null) { clearInterval(timer); timer = null }
29-
}
30-
3131
function approve(type: ToolApprovalType) {
3232
stopTimer()
3333
emit('approve', { approvalId: props.toolCall.approvalId, approval: type })
3434
}
3535
3636
function formatArgVal(v: unknown): string {
37-
if (v === null || v === undefined) return 'null'
37+
if (v == null) return 'null'
3838
if (typeof v === 'string') return v.length > 80 ? v.slice(0, 80) + '' : v
3939
if (typeof v === 'number' || typeof v === 'boolean') return String(v)
4040
if (Array.isArray(v)) return `[${v.length} items]`

packages/chat-ui/src/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export interface MemoryOption { id: string; name: string }
2222

2323
// ── Message types ──
2424

25+
/** Multimodal message content: a plain string or a list of content parts (text/image_url/…). */
26+
export type DisplayContent = string | any[]
27+
2528
export enum MessageRole {
2629
Human = 'human',
2730
AI = 'ai',
@@ -36,7 +39,7 @@ export interface ToolCall {
3639

3740
export interface ChatMessage {
3841
role: MessageRole | string
39-
content?: string | any[]
42+
content?: DisplayContent
4043
tool_calls?: ToolCall[]
4144
tool_call_id?: string
4245
name?: string
@@ -232,9 +235,6 @@ export interface AskAnswerPayload {
232235
answers: Record<string, string | string[]>
233236
}
234237

235-
// ── Queued messages ──
236-
export type DisplayContent = string | any[]
237-
238238
// ── Directory browser ──
239239
export interface DirListResult {
240240
path: string

0 commit comments

Comments
 (0)