mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
refactor: move attachment metadata schema to shared protocol package
This commit is contained in:
+17
-14
@@ -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,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,
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -2,6 +2,7 @@ export type {
|
||||
AgentState,
|
||||
AgentStateCompletedRequest,
|
||||
AgentStateRequest,
|
||||
AttachmentMetadata,
|
||||
DecryptedMessage,
|
||||
Metadata,
|
||||
Session,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user