refactor: move attachment metadata schema to shared protocol package

This commit is contained in:
weishu
2026-01-23 16:04:37 +08:00
parent 78f56ad0f7
commit 6f8f44a314
6 changed files with 33 additions and 43 deletions
+17 -14
View File
@@ -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<typeof UsageSchema>
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<typeof MessageMetaSchema>
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<typeof AttachmentMetadataSchema>
export const UserMessageSchema = z.object({
role: z.literal('user'),
content: z.object({
+1 -10
View File
@@ -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,
+2 -10
View File
@@ -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<WebAppEnv> {
+11
View File
@@ -91,6 +91,17 @@ export type TodoItem = z.infer<typeof TodoItemSchema>
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<typeof AttachmentMetadataSchema>
export const DecryptedMessageSchema = z.object({
id: z.string(),
seq: z.number().nullable(),
+1
View File
@@ -2,6 +2,7 @@ export type {
AgentState,
AgentStateCompletedRequest,
AgentStateRequest,
AttachmentMetadata,
DecryptedMessage,
Metadata,
Session,
+1 -9
View File
@@ -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
}