feat(36-02): add voiceMode field to createMessageSchema and ChatMessage interface

- Add VOICE_MODES constant and VoiceMode type to shared validators/chat.ts
- Extend createMessageSchema with optional voiceMode enum field
- Add voiceMode optional field to ChatMessage interface in types/chat.ts
- Add 36-voice-schema.test.ts with 6 passing tests for voiceMode validation
This commit is contained in:
Nexus Dev 2026-04-04 01:22:55 +00:00
parent edd7b17569
commit 390034c76d
3 changed files with 68 additions and 0 deletions

View file

@ -67,6 +67,7 @@ export interface ChatMessage {
content: string;
agentId: string | null;
messageType: string | null;
voiceMode?: "text" | "voice_input" | "full_voice" | null;
createdAt: string;
updatedAt: string | null;
files?: ChatFile[];

View file

@ -12,11 +12,15 @@ export const updateConversationSchema = z.object({
archivedAt: z.string().datetime().nullable().optional(),
});
export const VOICE_MODES = ["text", "voice_input", "full_voice"] as const;
export type VoiceMode = (typeof VOICE_MODES)[number];
export const createMessageSchema = z.object({
role: z.enum(["user", "assistant", "system"]),
content: z.string().min(1).max(100_000),
agentId: z.string().uuid().optional(),
messageType: z.string().optional(),
voiceMode: z.enum(VOICE_MODES).optional(),
});
export const handoffSchema = z.object({

View file

@ -0,0 +1,63 @@
// [nexus] Schema validation tests for voiceMode field (Plan 36-02)
import { describe, it, expect } from "vitest";
import { createMessageSchema } from "@paperclipai/shared/validators/chat";
describe("createMessageSchema — voiceMode field", () => {
it("parses voiceMode 'full_voice' and returns the value", () => {
const result = createMessageSchema.parse({
role: "user",
content: "hi",
voiceMode: "full_voice",
});
expect(result.voiceMode).toBe("full_voice");
});
it("parses voiceMode 'voice_input' and returns the value", () => {
const result = createMessageSchema.parse({
role: "user",
content: "hi",
voiceMode: "voice_input",
});
expect(result.voiceMode).toBe("voice_input");
});
it("parses voiceMode 'text' and returns the value", () => {
const result = createMessageSchema.parse({
role: "user",
content: "hi",
voiceMode: "text",
});
expect(result.voiceMode).toBe("text");
});
it("parses without voiceMode and returns undefined for voiceMode", () => {
const result = createMessageSchema.parse({
role: "user",
content: "hi",
});
expect(result.voiceMode).toBeUndefined();
});
it("throws ZodError when voiceMode is invalid", () => {
expect(() =>
createMessageSchema.parse({
role: "user",
content: "hi",
voiceMode: "invalid",
})
).toThrow();
});
it("preserves existing fields — role, content, agentId, messageType", () => {
const result = createMessageSchema.parse({
role: "assistant",
content: "hello world",
agentId: "00000000-0000-0000-0000-000000000001",
messageType: "markdown",
});
expect(result.role).toBe("assistant");
expect(result.content).toBe("hello world");
expect(result.agentId).toBe("00000000-0000-0000-0000-000000000001");
expect(result.messageType).toBe("markdown");
});
});