mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 14:04:50 +00:00
Merge pull request #57 from shumaiOne/fix/agent-error-ime-input
fix: agent error messages and IME input
This commit is contained in:
@@ -59,6 +59,46 @@ describe('Agent Activities', () => {
|
|||||||
expect(piAgent.createAgentSession).toHaveBeenCalled()
|
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 () => {
|
it('should call autofillAiActivity and run autofill tool', async () => {
|
||||||
const mockHarness = {
|
const mockHarness = {
|
||||||
prompt: vi.fn().mockResolvedValue({
|
prompt: vi.fn().mockResolvedValue({
|
||||||
|
|||||||
@@ -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')
|
.filter((c) => c.type === 'text')
|
||||||
.map((c) => {
|
.map((c) => {
|
||||||
if ('text' in c && typeof c.text === 'string') {
|
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')
|
.join('\n')
|
||||||
|
|
||||||
|
if (assistantMessage.stopReason === 'error' && assistantMessage.errorMessage) {
|
||||||
|
if (text) {
|
||||||
|
text += '\n\n'
|
||||||
|
}
|
||||||
|
text += `Error: ${assistantMessage.errorMessage}`
|
||||||
|
}
|
||||||
|
|
||||||
const usage: Usage = {
|
const usage: Usage = {
|
||||||
model: modelId,
|
model: modelId,
|
||||||
inputTokens: assistantMessage.usage?.input || 0,
|
inputTokens: assistantMessage.usage?.input || 0,
|
||||||
|
|||||||
@@ -279,6 +279,8 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
||||||
|
if (e.nativeEvent.isComposing) return
|
||||||
|
|
||||||
if (showMentionList && filteredEntities.length > 0) {
|
if (showMentionList && filteredEntities.length > 0) {
|
||||||
if (e.key === 'ArrowUp') {
|
if (e.key === 'ArrowUp') {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|||||||
Reference in New Issue
Block a user