diff --git a/cli/src/api/types.ts b/cli/src/api/types.ts index 142a6397..74f00c92 100644 --- a/cli/src/api/types.ts +++ b/cli/src/api/types.ts @@ -1,15 +1,29 @@ -import { AgentStateSchema, MetadataSchema, ModelModeSchema, PermissionModeSchema, TodosSchema } from '@hapi/protocol/schemas' +import { + AgentStateSchema, + AttachmentMetadataSchema, + MetadataSchema, + ModelModeSchema, + PermissionModeSchema, + TodosSchema +} from '@hapi/protocol/schemas' import type { ModelMode, PermissionMode } from '@hapi/protocol/types' import { z } from 'zod' import { UsageSchema } from '@/claude/types' export type Usage = z.infer -export type { AgentState, ClaudePermissionMode, CodexPermissionMode, Metadata, Session } from '@hapi/protocol/types' +export type { + AgentState, + AttachmentMetadata, + ClaudePermissionMode, + CodexPermissionMode, + Metadata, + Session +} from '@hapi/protocol/types' export type SessionPermissionMode = PermissionMode export type SessionModelMode = ModelMode -export { AgentStateSchema, MetadataSchema } +export { AgentStateSchema, AttachmentMetadataSchema, MetadataSchema } export const MachineMetadataSchema = z.object({ host: z.string(), @@ -109,17 +123,6 @@ export const MessageMetaSchema = z.object({ export type MessageMeta = z.infer -export const AttachmentMetadataSchema = z.object({ - id: z.string(), - filename: z.string(), - mimeType: z.string(), - size: z.number(), - path: z.string(), - previewUrl: z.string().optional() -}) - -export type AttachmentMetadata = z.infer - export const UserMessageSchema = z.object({ role: z.literal('user'), content: z.object({ diff --git a/server/src/sync/messageService.ts b/server/src/sync/messageService.ts index 08fab90a..c5bfd316 100644 --- a/server/src/sync/messageService.ts +++ b/server/src/sync/messageService.ts @@ -1,17 +1,8 @@ -import type { DecryptedMessage } from '@hapi/protocol/types' +import type { AttachmentMetadata, DecryptedMessage } from '@hapi/protocol/types' import type { Server } from 'socket.io' import type { Store } from '../store' import { EventPublisher } from './eventPublisher' -type AttachmentMetadata = { - id: string - filename: string - mimeType: string - size: number - path: string - previewUrl?: string -} - export class MessageService { constructor( private readonly store: Store, diff --git a/server/src/web/routes/messages.ts b/server/src/web/routes/messages.ts index f2f536b2..492298f2 100644 --- a/server/src/web/routes/messages.ts +++ b/server/src/web/routes/messages.ts @@ -1,4 +1,5 @@ import { Hono } from 'hono' +import { AttachmentMetadataSchema } from '@hapi/protocol/schemas' import { z } from 'zod' import type { SyncEngine } from '../../sync/syncEngine' import type { WebAppEnv } from '../middleware/auth' @@ -9,19 +10,10 @@ const querySchema = z.object({ beforeSeq: z.coerce.number().int().min(1).optional() }) -const attachmentMetadataSchema = z.object({ - id: z.string(), - filename: z.string(), - mimeType: z.string(), - size: z.number(), - path: z.string(), - previewUrl: z.string().optional() -}) - const sendMessageBodySchema = z.object({ text: z.string(), localId: z.string().min(1).optional(), - attachments: z.array(attachmentMetadataSchema).optional() + attachments: z.array(AttachmentMetadataSchema).optional() }) export function createMessagesRoutes(getSyncEngine: () => SyncEngine | null): Hono { diff --git a/shared/src/schemas.ts b/shared/src/schemas.ts index ead5b5b9..df273f11 100644 --- a/shared/src/schemas.ts +++ b/shared/src/schemas.ts @@ -91,6 +91,17 @@ export type TodoItem = z.infer export const TodosSchema = z.array(TodoItemSchema) +export const AttachmentMetadataSchema = z.object({ + id: z.string(), + filename: z.string(), + mimeType: z.string(), + size: z.number(), + path: z.string(), + previewUrl: z.string().optional() +}) + +export type AttachmentMetadata = z.infer + export const DecryptedMessageSchema = z.object({ id: z.string(), seq: z.number().nullable(), diff --git a/shared/src/types.ts b/shared/src/types.ts index 8aa8d9db..8499d9fe 100644 --- a/shared/src/types.ts +++ b/shared/src/types.ts @@ -2,6 +2,7 @@ export type { AgentState, AgentStateCompletedRequest, AgentStateRequest, + AttachmentMetadata, DecryptedMessage, Metadata, Session, diff --git a/web/src/types/api.ts b/web/src/types/api.ts index c20a552a..3c50f426 100644 --- a/web/src/types/api.ts +++ b/web/src/types/api.ts @@ -8,6 +8,7 @@ import type { export type { AgentState, + AttachmentMetadata, ModelMode, PermissionMode, Session, @@ -182,12 +183,3 @@ export type VisibilityPayload = { } export type SyncEvent = ProtocolSyncEvent - -export type AttachmentMetadata = { - id: string - filename: string - mimeType: string - size: number - path: string - previewUrl?: string -}