diff --git a/packages/agent/src/activities/agent.test.ts b/packages/agent/src/activities/agent.test.ts index 5c87dbdd..77a250cb 100644 --- a/packages/agent/src/activities/agent.test.ts +++ b/packages/agent/src/activities/agent.test.ts @@ -59,6 +59,46 @@ describe('Agent Activities', () => { expect(piAgent.createAgentSession).toHaveBeenCalled() }) + it('should include error message in text when stopReason is error', async () => { + const mockHarness = { + prompt: vi.fn().mockResolvedValue({ + content: [], + usage: { input: 0, output: 0 }, + stopReason: 'error', + errorMessage: 'API key not valid', + }), + } + const mockSession = { + getEntries: vi.fn().mockResolvedValue([]), + getStorage: vi.fn().mockReturnValue({ sessionId: 'mock-session-id' }), + } + + vi.mocked(piAgent.createAgentSession).mockResolvedValue({ + session: mockSession as unknown as Session, + harness: mockHarness as unknown as AgentHarness, + }) + + const context = { + agent: { id: 'b1', provider: { name: 'google' }, modelRef: { modelId: 'gemini' } }, + dbProviders: [], + teamSkills: [], + allowedDomains: [], + } as unknown as AgentExecutionContext + + const res = await agentChatActivity({ + teamId: 't1', + agentId: 'b1', + message: 'Hi', + imageUrls: [], + projectId: 'p1', + folderId: 'f1', + sessionId: 'mock-session-id', + context, + }) + + expect(res.text).toBe('Error: API key not valid') + }) + it('should call autofillAiActivity and run autofill tool', async () => { const mockHarness = { prompt: vi.fn().mockResolvedValue({ diff --git a/packages/agent/src/activities/agent.ts b/packages/agent/src/activities/agent.ts index d5234108..da46e79d 100644 --- a/packages/agent/src/activities/agent.ts +++ b/packages/agent/src/activities/agent.ts @@ -153,7 +153,7 @@ If you need to create files in the local filesystem (for example, a temporary fi } }) - const text = assistantMessage.content + let text = assistantMessage.content .filter((c) => c.type === 'text') .map((c) => { if ('text' in c && typeof c.text === 'string') { @@ -163,6 +163,13 @@ If you need to create files in the local filesystem (for example, a temporary fi }) .join('\n') + if (assistantMessage.stopReason === 'error' && assistantMessage.errorMessage) { + if (text) { + text += '\n\n' + } + text += `Error: ${assistantMessage.errorMessage}` + } + const usage: Usage = { model: modelId, inputTokens: assistantMessage.usage?.input || 0, diff --git a/packages/webui/components/chat/message-input.tsx b/packages/webui/components/chat/message-input.tsx index c51ca284..84b102b7 100644 --- a/packages/webui/components/chat/message-input.tsx +++ b/packages/webui/components/chat/message-input.tsx @@ -279,6 +279,8 @@ export const ChatInput = React.forwardRef( } const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.nativeEvent.isComposing) return + if (showMentionList && filteredEntities.length > 0) { if (e.key === 'ArrowUp') { e.preventDefault()