feat: report local task terminal events
This commit is contained in:
23
src/localAgentProtocol.test.ts
Normal file
23
src/localAgentProtocol.test.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import { localAgentClientMessageSchema } from './localAgentProtocol.js';
|
||||||
|
|
||||||
|
describe('localAgentClientMessageSchema', () => {
|
||||||
|
it('parses a completed local task', () => {
|
||||||
|
const parsed = localAgentClientMessageSchema.parse({
|
||||||
|
type: 'task.completed',
|
||||||
|
taskId: 'task-1',
|
||||||
|
text: 'Created CODE_INDEX.md.',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(parsed.type).toBe('task.completed');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects a failed local task without a message', () => {
|
||||||
|
const result = localAgentClientMessageSchema.safeParse({
|
||||||
|
type: 'task.failed',
|
||||||
|
taskId: 'task-1',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.success).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -21,6 +21,25 @@ const taskDispatchServerMessageSchema = z.object({
|
|||||||
prompt: z.string().min(1),
|
prompt: z.string().min(1),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const taskResultClientMessageSchema = z.object({
|
||||||
|
type: z.literal('task.result'),
|
||||||
|
taskId: z.string().min(1),
|
||||||
|
status: z.enum(['accepted', 'rejected']),
|
||||||
|
reason: z.string().min(1).optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const taskCompletedClientMessageSchema = z.object({
|
||||||
|
type: z.literal('task.completed'),
|
||||||
|
taskId: z.string().min(1),
|
||||||
|
text: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const taskFailedClientMessageSchema = z.object({
|
||||||
|
type: z.literal('task.failed'),
|
||||||
|
taskId: z.string().min(1),
|
||||||
|
message: z.string().min(1),
|
||||||
|
});
|
||||||
|
|
||||||
const errorServerMessageSchema = z.object({
|
const errorServerMessageSchema = z.object({
|
||||||
type: z.literal('error'),
|
type: z.literal('error'),
|
||||||
code: z.string().min(1),
|
code: z.string().min(1),
|
||||||
@@ -35,3 +54,11 @@ export const localAgentServerMessageSchema = z.discriminatedUnion('type', [
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
export type LocalAgentServerMessage = z.infer<typeof localAgentServerMessageSchema>;
|
export type LocalAgentServerMessage = z.infer<typeof localAgentServerMessageSchema>;
|
||||||
|
|
||||||
|
export const localAgentClientMessageSchema = z.discriminatedUnion('type', [
|
||||||
|
taskResultClientMessageSchema,
|
||||||
|
taskCompletedClientMessageSchema,
|
||||||
|
taskFailedClientMessageSchema,
|
||||||
|
]);
|
||||||
|
|
||||||
|
export type LocalAgentClientMessage = z.infer<typeof localAgentClientMessageSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user