// src/server/schemas.ts
import { z } from "zod/v4";
var httpHeaderSchema = z.object({
  name: z.string(),
  value: z.string()
});
var nullishString = z.string().nullish().transform((value) => value ?? null);
var handoffLocalGitStateSchema = z.object({
  head: nullishString,
  branch: nullishString,
  upstreamHead: nullishString,
  upstreamRemote: nullishString,
  upstreamMergeRef: nullishString
});
var remoteMcpServerSchema = z.object({
  type: z.enum(["http", "sse"]),
  name: z.string().min(1, "MCP server name is required"),
  url: z.url({ error: "MCP server url must be a valid URL" }),
  headers: z.array(httpHeaderSchema).default([])
});
var mcpServersSchema = z.array(remoteMcpServerSchema);
var claudeCodeConfigSchema = z.object({
  systemPrompt: z.union([
    z.string(),
    z.object({
      type: z.literal("preset"),
      preset: z.literal("claude_code"),
      append: z.string().optional()
    })
  ]).optional(),
  plugins: z.array(z.object({ type: z.literal("local"), path: z.string() })).optional()
});
var jsonRpcRequestSchema = z.object({
  jsonrpc: z.literal("2.0"),
  method: z.string(),
  params: z.record(z.string(), z.unknown()).optional(),
  id: z.union([z.string(), z.number()]).optional()
});
var userMessageParamsSchema = z.object({
  content: z.union([
    z.string().min(1, "Content is required"),
    z.array(z.record(z.string(), z.unknown())).min(1, "Content is required")
  ]).optional(),
  artifacts: z.array(z.record(z.string(), z.unknown())).optional()
}).refine(
  (params) => {
    const hasContent = typeof params.content === "string" ? params.content.trim().length > 0 : Array.isArray(params.content) && params.content.length > 0;
    const hasArtifacts = Array.isArray(params.artifacts) && params.artifacts.length > 0;
    return hasContent || hasArtifacts;
  },
  { error: "Either content or artifacts are required" }
);
var permissionResponseParamsSchema = z.object({
  requestId: z.string().min(1, "requestId is required"),
  optionId: z.string().min(1, "optionId is required"),
  customInput: z.string().optional(),
  answers: z.record(z.string(), z.string()).optional()
});
var setConfigOptionParamsSchema = z.object({
  configId: z.string().min(1, "configId is required"),
  value: z.string().min(1, "value is required")
});
var refreshSessionParamsSchema = z.object({
  mcpServers: mcpServersSchema
});
var closeParamsSchema = z.object({
  localGitState: handoffLocalGitStateSchema.optional()
}).optional();
var commandParamsSchemas = {
  user_message: userMessageParamsSchema,
  "posthog/user_message": userMessageParamsSchema,
  cancel: z.object({}).optional(),
  "posthog/cancel": z.object({}).optional(),
  close: closeParamsSchema,
  "posthog/close": closeParamsSchema,
  permission_response: permissionResponseParamsSchema,
  "posthog/permission_response": permissionResponseParamsSchema,
  set_config_option: setConfigOptionParamsSchema,
  "posthog/set_config_option": setConfigOptionParamsSchema,
  refresh_session: refreshSessionParamsSchema,
  "posthog/refresh_session": refreshSessionParamsSchema,
  "_posthog/refresh_session": refreshSessionParamsSchema
};
function validateCommandParams(method, params) {
  const schema = commandParamsSchemas[method] ?? commandParamsSchemas[method.replace(/^_?posthog\//, "")];
  if (!schema) {
    return { success: false, error: `Unknown method: ${method}` };
  }
  const result = schema.safeParse(params);
  if (!result.success) {
    return { success: false, error: result.error.message };
  }
  return { success: true, data: result.data };
}
export {
  claudeCodeConfigSchema,
  closeParamsSchema,
  commandParamsSchemas,
  handoffLocalGitStateSchema,
  jsonRpcRequestSchema,
  mcpServersSchema,
  permissionResponseParamsSchema,
  refreshSessionParamsSchema,
  setConfigOptionParamsSchema,
  userMessageParamsSchema,
  validateCommandParams
};
//# sourceMappingURL=schemas.js.map