/**
 * Core types for Studiograph workspace and repo management
 */
import { z } from 'zod';
/**
 * Base entity metadata (all entities have these fields)
 */
export const EntityBaseSchema = z.object({
    entity_type: z.string(),
    entity_id: z.string().regex(/^[a-z0-9-]+$/, 'Entity ID must be kebab-case'),
    created_at: z.string().datetime(),
    updated_at: z.string().datetime(),
    created_by: z.string(),
    updated_by: z.string(),
    tags: z.array(z.string()).optional(),
}).passthrough(); // Allow custom fields
/**
 * Repo configuration
 */
export const RepoConfigSchema = z.object({
    name: z.string(),
    display_name: z.string().optional(), // Human-readable name (e.g. "Cooper Hewitt"); name is the kebab slug
    type: z.string().optional(), // Legacy field — ignored but tolerated for old configs
    path: z.string(), // Relative to workspace root
    description: z.string().optional(),
    // Personal folders are auto-provisioned per-user ("My Folder") and have no
    // .studiograph marker file. They are committed to their own git repo like any
    // folder (NOT gitignored / not "local-only"); "private" means access-scoped +
    // skipped from routine member push/pull. The flag is an origin marker, NOT a
    // sharing lock — personal folders can be shared with other users via
    // folder_access like any other folder.
    personal: z.boolean().optional(),
    owner_id: z.number().optional(), // User ID of the personal folder's owner
    // System folders are app-managed (e.g. the reserved "Workspace Assets"
    // store). They are excluded from the sidebar + knowledge surfaces (graph /
    // entity-search / vector / orphan-maintenance / agent inventory) and are
    // undeletable. They are still surfaced in the asset manager. See
    // ~/.claude/plans/workspace-asset-rearchitecture.md.
    system: z.boolean().optional(),
    // Workspace-wide folders grant read + upload (create/update) access to every
    // authenticated workspace member without per-user folder_access grants —
    // honored centrally in services/access-control.ts. Does NOT grant delete
    // (asset deletion is uploader + workspace-owner only). Never combine with
    // `personal` (a personal folder is owner-private by definition).
    workspace_wide: z.boolean().optional(),
    sync: z.array(z.object({
        source: z.string(),
        entity_type: z.string().optional(),
        filter: z.record(z.string(), z.any()).optional(),
    })).optional(),
});
/**
 * Workspace configuration
 */
/**
 * Field definition for schema extensions
 */
export const FieldDefinitionSchema = z.object({
    name: z.string(),
    type: z.enum(['string', 'number', 'boolean', 'enum', 'string[]']),
    required: z.boolean().optional().default(false),
    description: z.string().optional(),
    enum_values: z.array(z.string()).optional(),
    default: z.unknown().optional(),
});
/**
 * Schema extension for an existing or custom entity type
 */
export const SchemaExtensionSchema = z.object({
    label: z.string().optional(),
    description: z.string().optional(),
    additional_fields: z.array(FieldDefinitionSchema).optional(), // for extending existing types
    fields: z.array(FieldDefinitionSchema).optional(), // for defining new custom types
    body_template: z.string().optional(), // default markdown body for new entities of this type
});
export const WorkspaceSyncTargetSchema = z.object({
    repo: z.string(),
    filter: z.record(z.string(), z.any()).optional(),
});
export const WorkspaceSyncRuleSchema = z.object({
    source: z.string(),
    entity_type: z.string().optional(),
    targets: z.array(WorkspaceSyncTargetSchema).min(1),
});
export const WorkspaceConfigSchema = z.object({
    version: z.string(),
    team_name: z.string(),
    created_at: z.string().datetime(),
    repos: z.array(RepoConfigSchema),
    // Model configuration
    model_provider: z.string().optional(), // e.g., 'anthropic', 'openai', 'google'
    model_id: z.string().optional(), // e.g., 'claude-sonnet-4-5-20250929'
    api_key: z.string().optional(), // Unified API key field
    r2_config: z.object({
        account_id: z.string().optional(),
        bucket: z.string().optional(),
        public_url: z.string().optional(),
        access_key_id: z.string().optional(),
        secret_access_key: z.string().optional(),
    }).optional(),
    schema_extensions: z.record(z.string(), SchemaExtensionSchema).optional(),
    sync: z.array(WorkspaceSyncRuleSchema).optional(),
    interview_started: z.boolean().optional(),
    search: z.object({
        provider: z.enum(['brave', 'google', 'tavily']).optional(),
        api_key: z.string().optional(),
        google_cx: z.string().optional(),
    }).optional(),
    railway: z.object({
        project_id: z.string().optional(),
        service_id: z.string().optional(),
        environment_id: z.string().optional(),
    }).optional(),
    // Image captioning gate (P3b). Default-on: the boot index sweep captions
    // image assets for search unless a tenant disables it. Flagged because the
    // first sweep after deploy re-derives every legacy image (one vision call
    // each) — a tenant with a large image gallery may want to opt out or stage it.
    captioning: z.object({
        enabled: z.boolean().optional(),
    }).optional(),
});
//# sourceMappingURL=types.js.map