Skip to content
Open
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
21 changes: 18 additions & 3 deletions packages/gateway/src/routes/chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ import type { ChannelIncomingMessage } from '@ownpilot/core';

const log = getLog('ChatHistory');

function normalizeTrace(trace: any): any {
if (!trace) return trace;
return {
...trace,
modelCalls: trace.modelCalls || [],
autonomyChecks: trace.autonomyChecks || [],
dbOperations: trace.dbOperations || { reads: 0, writes: 0 },
memoryOps: trace.memoryOps || { adds: 0, recalls: 0 },
triggersFired: trace.triggersFired || [],
errors: trace.errors || [],
events: trace.events || [],
toolCalls: trace.toolCalls || [],
};
}

export const chatHistoryRoutes = new Hono();

// =====================================================
Expand Down Expand Up @@ -254,7 +269,7 @@ chatHistoryRoutes.get('/history/:id', async (c) => {
provider: msg.provider,
model: msg.model,
toolCalls: msg.toolCalls,
trace: msg.trace,
trace: normalizeTrace(msg.trace),
isError: msg.isError,
createdAt: msg.createdAt.toISOString(),
})),
Expand Down Expand Up @@ -315,7 +330,7 @@ chatHistoryRoutes.get('/history/:id/unified', async (c) => {
provider: msg.provider,
model: msg.model,
toolCalls: msg.toolCalls,
trace: msg.trace,
trace: normalizeTrace(msg.trace),
isError: msg.isError,
createdAt: msg.createdAt.toISOString(),
source: 'web' as const,
Expand Down Expand Up @@ -400,7 +415,7 @@ chatHistoryRoutes.get('/history/:id/unified', async (c) => {
provider: msg.provider,
model: msg.model,
toolCalls: msg.toolCalls,
trace: msg.trace,
trace: normalizeTrace(msg.trace),
isError: msg.isError,
createdAt: msg.createdAt.toISOString(),
source: 'ai',
Expand Down
5 changes: 5 additions & 0 deletions packages/gateway/src/services/conversation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ export class ConversationService {
},
]
: [],
autonomyChecks: [],
dbOperations: { reads: 0, writes: 0 },
memoryOps: { adds: 0, recalls: 0 },
triggersFired: [],
errors: [],
mcpToolEvents,
events: mcpToolEvents.map((event) => ({
type: event.type,
Expand Down
Loading