Merge pull request #57 from shumaiOne/fix/agent-error-ime-input

fix: agent error messages and IME input
This commit is contained in:
Yiling-J
2026-06-03 12:00:09 +08:00
committed by GitHub
3 changed files with 50 additions and 1 deletions
@@ -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<DatabaseSessionMetadata>,
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({
+8 -1
View File
@@ -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,
@@ -279,6 +279,8 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
}
const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.nativeEvent.isComposing) return
if (showMentionList && filteredEntities.length > 0) {
if (e.key === 'ArrowUp') {
e.preventDefault()