mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-25 00:27:32 +00:00
* feat(protocol): extract shared protocol package from agent-core - add `@moonshot-ai/protocol` package with REST/WS schemas, envelopes, error codes, event types, and display schemas\n- migrate agent-core `events.ts` and `display/schemas.ts` to re-export from protocol - add centralized `onUnexpectedError` handler for safe emitter listener callbacks - reject forkSession when source session has an active running turn - add protocol schema tests and unexpectedError handler tests
35 lines
920 B
TypeScript
35 lines
920 B
TypeScript
import { z } from 'zod';
|
|
|
|
import { ErrorCode } from './error-codes';
|
|
|
|
export const cursorQuerySchema = z
|
|
.object({
|
|
before_id: z.string().min(1).optional(),
|
|
after_id: z.string().min(1).optional(),
|
|
page_size: z.number().int().min(1).max(100).optional(),
|
|
})
|
|
.superRefine((value, ctx) => {
|
|
if (value.before_id !== undefined && value.after_id !== undefined) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
message: 'before_id and after_id are mutually exclusive',
|
|
path: ['before_id'],
|
|
params: { code: ErrorCode.VALIDATION_FAILED },
|
|
});
|
|
}
|
|
});
|
|
|
|
export type CursorQuery = z.infer<typeof cursorQuerySchema>;
|
|
|
|
export const CursorQuery = cursorQuerySchema;
|
|
|
|
export const pageResponseSchema = <T extends z.ZodTypeAny>(item: T) =>
|
|
z.object({
|
|
items: z.array(item),
|
|
has_more: z.boolean(),
|
|
});
|
|
|
|
export interface PageResponse<T> {
|
|
items: T[];
|
|
has_more: boolean;
|
|
}
|