Skip to content

Commit 810510d

Browse files
authored
Merge pull request #115 from hongwei1/develop
Enhance chat store to support new API message
2 parents 131b734 + 11d0067 commit 810510d

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

server/controllers/StatusController.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import { commitId } from '../app'
3838
export class StatusController {
3939
private obpExplorerHome = process.env.VITE_OBP_API_EXPLORER_HOST
4040
private connectors = [
41-
'kafka_vSept2018',
4241
'akka_vDec2018',
4342
'rest_vMar2019',
4443
'stored_procedure_vDec2019',

src/obp/message-docs.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import { OBP_API_VERSION, get, isServerUp } from '../obp'
2929
import { updateLoadingInfoMessage } from './common-functions'
3030

3131
export const connectors = [
32-
'kafka_vSept2018',
3332
'akka_vDec2018',
3433
'rest_vMar2019',
3534
'stored_procedure_vDec2019',

src/stores/chat.ts

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ export const useChat = defineStore('chat', {
284284

285285

286286
// This is where we process different types of messages from Opey by their 'type' field
287-
// Process pending tool calls
287+
// Support both legacy ('message','tool','token') and new streaming types
288+
// Pending tool calls (legacy)
288289
if (data.type === 'message') {
289290

290291
if (content.tool_approval_request) {
@@ -310,7 +311,7 @@ export const useChat = defineStore('chat', {
310311
}
311312
}
312313

313-
// Now we handle the actual messages from the completed/ failed tool calls
314+
// Now we handle the actual messages from the completed/ failed tool calls (legacy)
314315
if (data.type === 'tool') {
315316
const toolCallId = content.tool_call_id;
316317
if (!toolCallId) {
@@ -336,13 +337,51 @@ export const useChat = defineStore('chat', {
336337

337338
}
338339

339-
if (data.type === 'assistant_complete' && data.content) {
340+
// Assistant token streaming (legacy and new)
341+
if ((data.type === 'token' || data.type === 'assistant_token') && data.content) {
340342
this.currentAssistantMessage.loading = false;
341343
// Append content to the current assistant message
342344
this.currentAssistantMessage.content += data.content;
343345
// Force Vue to detect the change
344346
this.messages = [...this.messages];
345347
}
348+
349+
// Assistant final content (new API emits assistant_complete)
350+
if (data.type === 'assistant_complete' && data.content) {
351+
this.currentAssistantMessage.loading = false;
352+
this.currentAssistantMessage.content += data.content;
353+
this.messages = [...this.messages];
354+
}
355+
356+
// New API: Tool lifecycle events mapping to UI model
357+
if (data.type === 'tool_start') {
358+
const toolMessage: OpeyToolCall = {
359+
status: 'pending',
360+
toolCall: {
361+
id: data.tool_call_id,
362+
name: data.tool_name,
363+
args: data.tool_input,
364+
}
365+
} as unknown as OpeyToolCall;
366+
this.currentAssistantMessage.toolCalls.push(toolMessage)
367+
this.messages = [...this.messages];
368+
}
369+
if (data.type === 'tool_end') {
370+
const toolMessage = this.getToolCallById(data.tool_call_id)
371+
if (toolMessage) {
372+
toolMessage.status = data.status === 'error' ? 'error' : 'success'
373+
toolMessage.output = data.tool_output
374+
this.messages = [...this.messages];
375+
}
376+
}
377+
if (data.type === 'approval_request') {
378+
// Mark awaiting approval on matched tool call if present
379+
const toolMessage = this.getToolCallById(data.tool_call_id)
380+
if (toolMessage) {
381+
toolMessage.status = 'awaiting_approval'
382+
this.messages = [...this.messages];
383+
}
384+
}
346385
} catch (e) {
347386
throw new Error(`${e}`);
348387
}

0 commit comments

Comments
 (0)