import { z } from 'zod';
export const ProjectSchema = z.object({
    id: z.string(),
    name: z.string(),
    path: z.string(),
    isGitRepo: z.boolean(),
    createdAt: z.string(),
    updatedAt: z.string(),
    favorite: z.boolean().default(false),
    tags: z.array(z.string()).default([])
});
export const GitFileChangeSchema = z.object({
    path: z.string(),
    originalPath: z.string().optional(),
    status: z.enum(['added', 'modified', 'deleted', 'renamed', 'untracked']),
    staged: z.boolean(),
    insertions: z.number().optional(),
    deletions: z.number().optional()
});
export const GitStatusResultSchema = z.object({
    branch: z.string(),
    upstream: z.string().nullable(),
    ahead: z.number(),
    behind: z.number(),
    staged: z.array(GitFileChangeSchema),
    unstaged: z.array(GitFileChangeSchema),
    clean: z.boolean(),
    insertions: z.number().optional(),
    deletions: z.number().optional()
});
export const GitLogEntrySchema = z.object({
    hash: z.string(),
    shortHash: z.string(),
    message: z.string(),
    author: z.string(),
    date: z.string(),
    refs: z.string()
});
export const BranchInfoSchema = z.object({
    name: z.string(),
    current: z.boolean(),
    remote: z.boolean()
});
export const TerminalSessionSchema = z.object({
    id: z.string(),
    projectId: z.string(),
    name: z.string(),
    alive: z.boolean(),
    createdAt: z.string(),
    updatedAt: z.string(),
    exitCode: z.number().nullable().optional()
});
export const AgentProviderSchema = z.object({
    id: z.enum(['claude', 'codex']),
    label: z.string(),
    command: z.string(),
    available: z.boolean(),
    version: z.string().nullable(),
    defaultModel: z.string().nullable().default(null),
    commitMessageDefaultModel: z.string().nullable().default(null),
    defaultEffort: z.string().nullable().default(null),
    fallbackEffortOptions: z.array(z.string()).default([]),
    models: z
        .array(z.object({
        value: z.string(),
        label: z.string(),
        effortOptions: z.array(z.string()).default([]),
        defaultEffort: z.string().nullable().default(null)
    }))
        .default([])
});
export const ProviderUsageCodeSchema = z.enum([
    'ok',
    'missing_creds',
    'parse_error',
    'auth_expired',
    'rate_limited',
    'network_error',
    'schema_changed',
    'partial_data'
]);
export const ProviderUsageDataSchema = z.object({
    sessionRemainingPct: z.number().nullable(),
    weeklyRemainingPct: z.number().nullable(),
    sessionUsedPct: z.number().nullable(),
    weeklyUsedPct: z.number().nullable(),
    sessionResetsAtIso: z.string().nullable(),
    weeklyResetsAtIso: z.string().nullable()
});
export const ProviderUsageSnapshotSchema = z.object({
    provider: z.enum(['claude', 'codex']),
    label: z.string(),
    code: ProviderUsageCodeSchema,
    data: ProviderUsageDataSchema.nullable(),
    updatedAtIso: z.string().nullable()
});
export const ProviderUsageSummarySchema = z.object({
    providers: z.object({
        codex: ProviderUsageSnapshotSchema,
        claude: ProviderUsageSnapshotSchema
    }),
    lastUpdatedAtIso: z.string().nullable()
});
export const AppSettingsSchema = z.object({
    commitMessageProvider: z.enum(['claude', 'codex']),
    commitMessageModel: z.string(),
    timeFormat: z.enum(['12h', '24h']),
    dateFormat: z.enum(['locale', 'iso', 'us', 'eu', 'long']),
    telegramBotToken: z.string().nullable().default(null),
    telegramChatId: z.string().nullable().default(null)
});
export const AgentSessionSchema = z.object({
    id: z.string(),
    projectId: z.string(),
    provider: z.enum(['claude', 'codex']),
    title: z.string(),
    status: z.enum(['idle', 'running', 'queued', 'exited', 'error', 'cancelled']),
    model: z.string().nullable(),
    permissionMode: z.string().nullable(),
    interactionMode: z.enum(['build', 'plan']).default('build'),
    effort: z.string().nullable().default(null),
    providerSessionId: z.string().nullable(),
    createdAt: z.string(),
    updatedAt: z.string(),
    lastOpenedAt: z.string().nullable().default(null),
    lastError: z.string().nullable(),
    archived: z.boolean().default(false),
    archivedAt: z.string().nullable().default(null)
});
export const AgentMessageSchema = z.object({
    id: z.string(),
    sessionId: z.string(),
    role: z.enum(['user', 'assistant', 'system', 'tool', 'error']),
    content: z.string(),
    eventType: z.string(),
    createdAt: z.string(),
    metadata: z.record(z.string(), z.unknown()).default({})
});
export const AgentAttachmentSchema = z.object({
    id: z.string(),
    sessionId: z.string(),
    messageId: z.string().nullable(),
    kind: z.enum(['project_file', 'local_upload']),
    name: z.string(),
    path: z.string(),
    size: z.number().nullable(),
    mimeType: z.string().nullable(),
    createdAt: z.string()
});
export const ExternalSessionSourceSchema = z.enum(['claude', 'codex']);
export const ExternalSessionScanGroupSchema = z.object({
    cwd: z.string(),
    source: z.enum(['claude', 'codex', 'mixed']),
    sessionCount: z.number().int().nonnegative(),
    files: z.array(z.object({
        source: ExternalSessionSourceSchema,
        path: z.string(),
        providerSessionId: z.string()
    }))
});
export const ExternalSessionImportRequestSchema = z
    .object({
    cwd: z.string().optional(),
    projectId: z.string().optional()
})
    .refine((v) => !(v.cwd && v.projectId), {
    message: 'specify cwd OR projectId, not both'
});
export const ExternalSessionImportResultSchema = z.object({
    scanned: z.number().int().nonnegative(),
    imported: z.number().int().nonnegative(),
    skipped: z.number().int().nonnegative(),
    failed: z.number().int().nonnegative(),
    createdProjects: z.array(z.string()),
    attachedToProjects: z.array(z.string()),
    groups: z.array(z.object({
        cwd: z.string(),
        sessionCount: z.number().int().nonnegative(),
        messageCount: z.number().int().nonnegative()
    }))
});
export const ProjectImportBlockSchema = z.object({
    path: z.string(),
    createdAt: z.string()
});
export const ProjectSummarySchema = ProjectSchema.extend({
    git: GitStatusResultSchema.nullable(),
    activeTerminals: z.number(),
    activeAgentSessions: z.number(),
    unreadAgentSessions: z.number(),
    lastActivity: z.string().nullable()
});
export const ExtensionKindSchema = z.enum(['skill', 'mcp']);
export const SkillOverrideStateSchema = z.enum(['on', 'off', 'name-only', 'user-invocable-only']);
export const InstalledSkillSchema = z.object({
    name: z.string(),
    description: z.string().nullable().default(null),
    scope: z.enum(['user', 'project']),
    paths: z
        .object({
        claude: z.string().nullable().default(null),
        agents: z.string().nullable().default(null)
    })
        .default({ claude: null, agents: null }),
    source: z
        .object({
        registry: z.string().nullable().default(null),
        ref: z.string().nullable().default(null),
        version: z.string().nullable().default(null),
        url: z.string().nullable().default(null)
    })
        .default({ registry: null, ref: null, version: null, url: null })
});
export const McpTransportSchema = z.enum(['stdio', 'http']);
export const InstalledMcpServerSchema = z.object({
    name: z.string(),
    transport: McpTransportSchema,
    command: z.string().nullable().default(null),
    args: z.array(z.string()).default([]),
    env: z.record(z.string(), z.string()).default({}),
    url: z.string().nullable().default(null),
    headers: z.record(z.string(), z.string()).default({}),
    presentIn: z
        .object({
        claudeUser: z.boolean().default(false),
        codexUser: z.boolean().default(false)
    })
        .default({ claudeUser: false, codexUser: false }),
    source: z
        .object({
        registry: z.string().nullable().default(null),
        ref: z.string().nullable().default(null),
        version: z.string().nullable().default(null),
        url: z.string().nullable().default(null)
    })
        .default({ registry: null, ref: null, version: null, url: null })
});
export const RegistryEntrySchema = z.object({
    id: z.string(),
    source: z.string(),
    kind: ExtensionKindSchema,
    name: z.string(),
    title: z.string().nullable().default(null),
    description: z.string().nullable().default(null),
    version: z.string().nullable().default(null),
    repository: z.string().nullable().default(null),
    homepage: z.string().nullable().default(null),
    installManifest: z.record(z.string(), z.unknown()).default({})
});
export const RegistrySourceSchema = z.object({
    id: z.string(),
    label: z.string(),
    kinds: z.array(ExtensionKindSchema),
    requiresAuth: z.boolean().default(false),
    enabled: z.boolean().default(true)
});
export const ProjectExtensionSchema = z.object({
    projectId: z.string(),
    kind: ExtensionKindSchema,
    name: z.string(),
    enabled: z.boolean()
});
export const SessionExtensionOverrideSchema = z.object({
    sessionId: z.string(),
    kind: ExtensionKindSchema,
    name: z.string(),
    skillState: SkillOverrideStateSchema.nullable().default(null),
    mcpEnabled: z.boolean().nullable().default(null)
});
export const SessionExtensionsSchema = z.object({
    skills: z.array(z.object({
        name: z.string(),
        description: z.string().nullable().default(null),
        projectState: SkillOverrideStateSchema.default('off'),
        sessionState: SkillOverrideStateSchema.nullable().default(null),
        effectiveState: SkillOverrideStateSchema.default('off')
    })),
    mcpServers: z.array(z.object({
        name: z.string(),
        transport: McpTransportSchema,
        projectEnabled: z.boolean().default(false),
        sessionEnabled: z.boolean().nullable().default(null),
        effectiveEnabled: z.boolean().default(false)
    }))
});
export const ExtensionInstallRequestSchema = z.object({
    kind: ExtensionKindSchema,
    source: z.string(),
    payload: z.record(z.string(), z.unknown())
});
export const WsClientMessageSchema = z.discriminatedUnion('method', [
    z.object({
        method: z.literal('terminal.create'),
        projectId: z.string(),
        name: z.string().optional(),
        cols: z.number().int().min(10).default(80),
        rows: z.number().int().min(2).default(24)
    }),
    z.object({
        method: z.literal('terminal.attach'),
        terminalId: z.string()
    }),
    z.object({
        method: z.literal('terminal.input'),
        terminalId: z.string(),
        data: z.string()
    }),
    z.object({
        method: z.literal('terminal.resize'),
        terminalId: z.string(),
        cols: z.number().int().min(10),
        rows: z.number().int().min(2)
    }),
    z.object({
        method: z.literal('terminal.close'),
        terminalId: z.string()
    }),
    z.object({
        method: z.literal('agent.send'),
        sessionId: z.string(),
        prompt: z.string().min(1),
        attachmentIds: z.array(z.string()).default([])
    }),
    z.object({
        method: z.literal('agent.cancel'),
        sessionId: z.string()
    }),
    z.object({
        method: z.literal('git.refresh'),
        projectId: z.string()
    })
]);
export const WsServerMessageSchema = z.discriminatedUnion('type', [
    z.object({
        type: z.literal('terminal.output'),
        terminalId: z.string(),
        data: z.string(),
        replay: z.boolean().default(false)
    }),
    z.object({
        type: z.literal('terminal.status'),
        session: TerminalSessionSchema
    }),
    z.object({
        type: z.literal('agent.event'),
        projectId: z.string(),
        sessionId: z.string(),
        message: AgentMessageSchema.optional(),
        event: z.record(z.string(), z.unknown())
    }),
    z.object({
        type: z.literal('agent.status'),
        session: AgentSessionSchema
    }),
    z.object({
        type: z.literal('git.status'),
        projectId: z.string(),
        result: GitStatusResultSchema
    }),
    z.object({
        type: z.literal('error'),
        method: z.string(),
        message: z.string()
    })
]);
//# sourceMappingURL=index.js.map