kimi-code/packages/protocol/src/workspace.ts
Haozhe 4603d8ad6e
feat(protocol): extract shared protocol package from agent-core (#612)
* 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
2026-06-10 14:03:38 +08:00

37 lines
1 KiB
TypeScript

import { z } from 'zod';
import { isoDateTimeSchema } from './time';
export const workspaceIdSchema = z
.string()
.regex(/^wd_[a-z0-9._-]+_[0-9a-f]{12}$/, {
message: 'workspace_id must be a wd_<slug>_<hash12> string',
});
export type WorkspaceId = z.infer<typeof workspaceIdSchema>;
export const workspaceSchema = z.object({
id: workspaceIdSchema,
root: z.string().min(1),
name: z.string().min(1).max(100),
is_git_repo: z.boolean(),
branch: z.string().nullable(),
created_at: isoDateTimeSchema,
last_opened_at: isoDateTimeSchema,
session_count: z.number().int().nonnegative(),
});
export type Workspace = z.infer<typeof workspaceSchema>;
export const workspaceCreateSchema = z.object({
root: z.string().min(1),
name: z.string().min(1).max(100).optional(),
});
export type WorkspaceCreate = z.infer<typeof workspaceCreateSchema>;
export const workspaceUpdateSchema = z.object({
name: z.string().min(1).max(100),
});
export type WorkspaceUpdate = z.infer<typeof workspaceUpdateSchema>;