mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-05 01:01:42 +00:00
refactor: share core REST payload types
This commit is contained in:
+21
-53
@@ -1,18 +1,22 @@
|
||||
import {
|
||||
AgentStateSchema,
|
||||
AttachmentMetadataSchema,
|
||||
CodexCollaborationModeSchema,
|
||||
MachineMetadataSchema,
|
||||
MachineSchema,
|
||||
MetadataSchema,
|
||||
PermissionModeSchema,
|
||||
RunnerStateSchema,
|
||||
TodosSchema
|
||||
RunnerStateSchema
|
||||
} from '@hapi/protocol/schemas'
|
||||
import {
|
||||
CliMessagesResponseSchema,
|
||||
CreateMachineResponseSchema,
|
||||
CreateSessionResponseSchema,
|
||||
GetSessionResponseSchema,
|
||||
LocalHandoffResponseSchema,
|
||||
LocalResumeTargetResponseSchema,
|
||||
ResumableSessionsResponseSchema
|
||||
ResumableSessionsResponseSchema,
|
||||
type CliMessagesResponse,
|
||||
type CreateMachineResponse,
|
||||
type CreateSessionResponse,
|
||||
type GetSessionResponse
|
||||
} from '@hapi/protocol'
|
||||
import type { CodexCollaborationMode, Machine, MachineMetadata, PermissionMode, RunnerState } from '@hapi/protocol/types'
|
||||
import { z } from 'zod'
|
||||
@@ -40,59 +44,23 @@ export type SessionEffort = string | null
|
||||
|
||||
export { AgentStateSchema, AttachmentMetadataSchema, MachineMetadataSchema, MetadataSchema, RunnerStateSchema }
|
||||
|
||||
export const CliMessagesResponseSchema = z.object({
|
||||
messages: z.array(z.object({
|
||||
id: z.string(),
|
||||
seq: z.number(),
|
||||
createdAt: z.number(),
|
||||
localId: z.string().nullable().optional(),
|
||||
content: z.unknown()
|
||||
}))
|
||||
})
|
||||
|
||||
export type CliMessagesResponse = z.infer<typeof CliMessagesResponseSchema>
|
||||
|
||||
export const CreateSessionResponseSchema = z.object({
|
||||
session: z.object({
|
||||
id: z.string(),
|
||||
namespace: z.string(),
|
||||
seq: z.number(),
|
||||
createdAt: z.number(),
|
||||
updatedAt: z.number(),
|
||||
active: z.boolean(),
|
||||
activeAt: z.number(),
|
||||
metadata: z.unknown().nullable(),
|
||||
metadataVersion: z.number(),
|
||||
agentState: z.unknown().nullable(),
|
||||
agentStateVersion: z.number(),
|
||||
thinking: z.boolean(),
|
||||
thinkingAt: z.number(),
|
||||
todos: TodosSchema.optional(),
|
||||
model: z.string().nullable().optional().default(null),
|
||||
modelReasoningEffort: z.string().nullable().optional().default(null),
|
||||
effort: z.string().nullable().optional().default(null),
|
||||
permissionMode: PermissionModeSchema.optional(),
|
||||
collaborationMode: CodexCollaborationModeSchema.optional()
|
||||
})
|
||||
})
|
||||
|
||||
export type CreateSessionResponse = z.infer<typeof CreateSessionResponseSchema>
|
||||
|
||||
export const CreateMachineResponseSchema = z.object({
|
||||
machine: MachineSchema
|
||||
})
|
||||
|
||||
export type CreateMachineResponse = z.infer<typeof CreateMachineResponseSchema>
|
||||
|
||||
export const GetSessionResponseSchema = CreateSessionResponseSchema
|
||||
export type GetSessionResponse = z.infer<typeof GetSessionResponseSchema>
|
||||
|
||||
export {
|
||||
CliMessagesResponseSchema,
|
||||
CreateMachineResponseSchema,
|
||||
CreateSessionResponseSchema,
|
||||
GetSessionResponseSchema,
|
||||
LocalHandoffResponseSchema,
|
||||
LocalResumeTargetResponseSchema,
|
||||
ResumableSessionsResponseSchema
|
||||
}
|
||||
|
||||
export type {
|
||||
CliMessagesResponse,
|
||||
CreateMachineResponse,
|
||||
CreateSessionResponse,
|
||||
GetSessionResponse
|
||||
}
|
||||
|
||||
export const MessageMetaSchema = z.object({
|
||||
sentFrom: z.string().optional(),
|
||||
fallbackModel: z.string().nullable().optional(),
|
||||
|
||||
Reference in New Issue
Block a user