mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-04 14:02:22 +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
29 lines
724 B
TypeScript
29 lines
724 B
TypeScript
import { z } from 'zod';
|
|
|
|
const ISO_8601_REGEX =
|
|
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:Z|[+-]\d{2}(?::?\d{2})?)$/;
|
|
|
|
export const isoDateTimeSchema = z
|
|
.string()
|
|
.refine((value) => ISO_8601_REGEX.test(value), {
|
|
message: 'must be an ISO 8601 datetime string',
|
|
})
|
|
.transform((value, ctx) => {
|
|
const ms = Date.parse(value);
|
|
if (Number.isNaN(ms)) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
message: 'invalid ISO 8601 datetime',
|
|
});
|
|
return z.NEVER;
|
|
}
|
|
return new Date(ms).toISOString();
|
|
});
|
|
|
|
export const IsoDateTime = isoDateTimeSchema;
|
|
|
|
export type IsoDateTime = string;
|
|
|
|
export function nowIsoDateTime(): IsoDateTime {
|
|
return new Date().toISOString();
|
|
}
|