2026-07-22 20:51:44 +08:00
|
|
|
/**
|
2026-07-28 21:05:43 +08:00
|
|
|
* goals domain zod schemas. Mutation-only shapes: every value schema is a
|
|
|
|
|
* `{ ref }` acknowledgement (clear: `{ cleared }`) — the current goal state
|
|
|
|
|
* travels exclusively on the 'goal' session projection.
|
2026-07-22 20:51:44 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { z } from 'zod'
|
|
|
|
|
import type { Wire } from './rpc.schema.ts'
|
2026-07-28 21:05:43 +08:00
|
|
|
import type { GoalRef, RequestPayload, ResponseValue } from './index.ts'
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** GoalRef schema. */
|
|
|
|
|
export const goalRefSchema = z.object({
|
|
|
|
|
id: z.string(),
|
|
|
|
|
revision: z.number().int().positive(),
|
|
|
|
|
}) as unknown as z.ZodType<Wire<GoalRef>>
|
|
|
|
|
|
2026-07-28 21:05:43 +08:00
|
|
|
/** Shared `{ ref }` acknowledgement value of every non-clear mutation. */
|
|
|
|
|
const goalRefValueSchema = z.object({ ref: goalRefSchema })
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** goal.create request payload. */
|
|
|
|
|
export const goalCreateRequestSchema = z.object({
|
|
|
|
|
sessionId: z.string(),
|
|
|
|
|
objective: z.string().min(1),
|
|
|
|
|
maxGoalRounds: z.number().int().positive().optional(),
|
|
|
|
|
}) as unknown as z.ZodType<Wire<RequestPayload<'goal.create'>>>
|
|
|
|
|
|
|
|
|
|
/** goal.create response value. */
|
2026-07-28 21:05:43 +08:00
|
|
|
export const goalCreateValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.create'>>>
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** goal.edit request payload. */
|
|
|
|
|
export const goalEditRequestSchema = z.object({
|
|
|
|
|
sessionId: z.string(),
|
|
|
|
|
ref: goalRefSchema,
|
|
|
|
|
objective: z.string().min(1).optional(),
|
|
|
|
|
maxGoalRounds: z.number().int().positive().optional(),
|
2026-07-22 22:18:13 +08:00
|
|
|
}).refine(value => value.objective !== undefined || value.maxGoalRounds !== undefined, {
|
|
|
|
|
message: 'goal.edit requires objective or maxGoalRounds',
|
2026-07-22 20:51:44 +08:00
|
|
|
}) as unknown as z.ZodType<Wire<RequestPayload<'goal.edit'>>>
|
|
|
|
|
|
|
|
|
|
/** goal.edit response value. */
|
2026-07-28 21:05:43 +08:00
|
|
|
export const goalEditValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.edit'>>>
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** goal.pause request payload. */
|
|
|
|
|
export const goalPauseRequestSchema = z.object({
|
|
|
|
|
sessionId: z.string(),
|
|
|
|
|
ref: goalRefSchema,
|
|
|
|
|
}) as unknown as z.ZodType<Wire<RequestPayload<'goal.pause'>>>
|
|
|
|
|
|
|
|
|
|
/** goal.pause response value. */
|
2026-07-28 21:05:43 +08:00
|
|
|
export const goalPauseValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.pause'>>>
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** goal.resume request payload. */
|
|
|
|
|
export const goalResumeRequestSchema = z.object({
|
|
|
|
|
sessionId: z.string(),
|
|
|
|
|
ref: goalRefSchema,
|
|
|
|
|
}) as unknown as z.ZodType<Wire<RequestPayload<'goal.resume'>>>
|
|
|
|
|
|
|
|
|
|
/** goal.resume response value. */
|
2026-07-28 21:05:43 +08:00
|
|
|
export const goalResumeValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.resume'>>>
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** goal.complete request payload. */
|
|
|
|
|
export const goalCompleteRequestSchema = z.object({
|
|
|
|
|
sessionId: z.string(),
|
|
|
|
|
ref: goalRefSchema,
|
|
|
|
|
}) as unknown as z.ZodType<Wire<RequestPayload<'goal.complete'>>>
|
|
|
|
|
|
|
|
|
|
/** goal.complete response value. */
|
2026-07-28 21:05:43 +08:00
|
|
|
export const goalCompleteValueSchema = goalRefValueSchema as unknown as z.ZodType<Wire<ResponseValue<'goal.complete'>>>
|
2026-07-22 20:51:44 +08:00
|
|
|
|
|
|
|
|
/** goal.clear request payload. */
|
|
|
|
|
export const goalClearRequestSchema = z.object({
|
|
|
|
|
sessionId: z.string(),
|
|
|
|
|
ref: goalRefSchema,
|
|
|
|
|
}) as unknown as z.ZodType<Wire<RequestPayload<'goal.clear'>>>
|
|
|
|
|
|
|
|
|
|
/** goal.clear response value. */
|
|
|
|
|
export const goalClearValueSchema = z.object({
|
|
|
|
|
cleared: z.literal(true),
|
|
|
|
|
}) as unknown as z.ZodType<Wire<ResponseValue<'goal.clear'>>>
|