var s=Object.defineProperty;var p=(t)=>t;function c(t,i){this[t]=p.bind(null,i)}var d=(t,i)=>{for(var a in i)s(t,a,{get:i[a],enumerable:!0,configurable:!0,set:c.bind(i,a)})};var g=(t,i)=>()=>(t&&(i=t(t=0)),i);import{CodeBlock as o}from"@contractspec/lib.design-system";import r from"@contractspec/lib.ui-link";import{ChevronRight as l}from"lucide-react";import{jsx as e,jsxs as n}from"react/jsx-runtime";function b(){return n("div",{className:"space-y-8",children:[n("div",{className:"space-y-4",children:[e("h1",{className:"font-bold text-4xl",children:"App Configuration"}),e("p",{className:"text-muted-foreground",children:"ContractSpec uses a three-tier configuration model that separates global app definitions from tenant-specific settings and runtime resolution."})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"AppBlueprintSpec"}),n("p",{className:"text-muted-foreground",children:["The ",e("strong",{children:"AppBlueprintSpec"})," is the global, versioned definition of your application. It contains no tenant-specific information and is stored in version control."]}),e(o,{language:"typescript",code:`type AppBlueprintSpec = {
  id: string;
  version: string;
  name: string;
  description: string;
  
  // Core specs
  capabilities: CapabilitySpec[];
  dataViews: DataViewSpec[];
  workflows: WorkflowSpec[];
  policies: PolicySpec[];
  
  // Required integrations
  requiredIntegrations: {
    integrationId: string;
    category: IntegrationCategory;
    purpose: string;
    optional?: boolean;
  }[];
  
  // Expected knowledge spaces
  knowledgeSpaces: {
    spaceId: string;
    category: KnowledgeCategory;
    required: boolean;
    purpose: string;
  }[];
  
  // UI/UX
  theme: ThemeSpec;
  overlays: OverlaySpec[];
  
  // Observability
  telemetry: TelemetrySpec;
  
  // Schema evolution
  migrations: MigrationSpec[];
};`})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"TenantAppConfig"}),n("p",{className:"text-muted-foreground",children:["The ",e("strong",{children:"TenantAppConfig"})," is the per-tenant, per-environment configuration that customizes how a specific tenant uses the app."]}),e(o,{language:"typescript",code:`type TenantAppConfig = {
  tenantId: string;
  blueprintId: string;
  blueprintVersion: string;
  environment: "sandbox" | "staging" | "production";
  status: "draft" | "preview" | "published" | "archived" | "superseded";
  
  // Integration bindings
  integrationBindings: AppIntegrationBinding[];
  
  // Knowledge bindings
  knowledgeBindings: AppKnowledgeBinding[];
  
  // Tenant-specific overrides
  featureFlags: Record<string, boolean>;
  limits: {
    maxUsers?: number;
    maxStorage?: number;
    rateLimit?: number;
  };
  
  // Tenant customization
  branding: {
    logo?: string;
    colors?: Record<string, string>;
    domain?: string;
  };
  
  metadata: Record<string, unknown>;
  createdAt: string;
  updatedAt: string;
};`})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"AppIntegrationBinding"}),e("p",{className:"text-muted-foreground",children:"Defines how a tenant connects specific integration instances to satisfy capabilities and workflows."}),e(o,{language:"typescript",code:`type AppIntegrationBinding = {
  slotId: string;          // References AppIntegrationSlot.slotId
  connectionId: string;    // References IntegrationConnection.meta.id
  scope?: {
    workflows?: string[];
    operations?: string[];
    features?: string[];
  };
  priority?: number;       // Lower number = higher priority
};

// Example:
{
  slotId: "payments.primary",
  connectionId: "conn_stripe_acme_prod",
  scope: {
    workflows: ["checkout", "subscription-renewal"],
    operations: ["payments.stripe.*"]
  },
  priority: 1
}`})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"AppKnowledgeBinding"}),e("p",{className:"text-muted-foreground",children:"Defines which knowledge spaces a tenant's app can access and how."}),e(o,{language:"typescript",code:`type AppKnowledgeBinding = {
  spaceId: string;
  enabled: boolean;
  
  // Which workflows/agents can read this space
  allowedConsumers: {
    workflowIds?: string[];
    agentIds?: string[];
    roles?: string[];
  };
  
  // Category-based access control
  allowedCategories: KnowledgeCategory[];
  
  // Sources feeding this space for this tenant
  sources: string[];  // References KnowledgeSourceConfig IDs
  
  metadata?: Record<string, unknown>;
};

// Example:
{
  spaceId: "product-canon",
  enabled: true,
  allowedConsumers: {
    workflowIds: ["invoice-generation", "quote-creation"],
    agentIds: ["support-agent"]
  },
  allowedCategories: ["canonical", "operational"],
  sources: ["src_notion_product_docs", "src_database_schema"]
}`})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"ResolvedAppConfig"}),n("p",{className:"text-muted-foreground",children:["The ",e("strong",{children:"ResolvedAppConfig"})," is the runtime result of merging AppBlueprintSpec with TenantAppConfig. It's computed on-demand and never persisted."]}),e(o,{language:"typescript",code:`type ResolvedAppConfig = {
  appId: string;
  tenantId: string;
  blueprintName: string;
  blueprintVersion: number;
  environment?: string;
  configVersion: number;

  capabilities: { enabled: CapabilityRef[]; disabled: CapabilityRef[] };
  features: { include: FeatureRef[]; exclude: FeatureRef[] };
  dataViews: Record<string, SpecPointer>;
  workflows: Record<string, SpecPointer>;
  policies: PolicyRef[];
  theme?: AppThemeBinding;
  telemetry?: TelemetryBinding;
  experiments: {
    catalog: ExperimentRef[];
    active: ExperimentRef[];
    paused: ExperimentRef[];
  };
  featureFlags: FeatureFlagState[];
  routes: AppRouteConfig[];

  integrations: ResolvedIntegration[]; // [{ slot, binding, connection, spec }]
  knowledge: ResolvedKnowledge[];       // [{ binding, space, sources }]
  branding: ResolvedBranding;           // { appName, assets, colors, domain }
  notes?: string;
};`})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Configuration flow"}),e("p",{className:"text-muted-foreground",children:"Here's how configuration flows from definition to runtime:"}),n("ol",{className:"list-inside list-decimal space-y-3 text-muted-foreground",children:[n("li",{children:[e("strong",{children:"Development"})," - Define AppBlueprintSpec with required integrations and knowledge spaces"]}),n("li",{children:[e("strong",{children:"Deployment"})," - Deploy blueprint to environment (sandbox, staging, production)"]}),n("li",{children:[e("strong",{children:"Tenant Setup"})," - Create TenantAppConfig with specific integration connections and knowledge sources"]}),n("li",{children:[e("strong",{children:"Runtime"})," - Resolve configuration on-demand when tenant accesses the app"]}),n("li",{children:[e("strong",{children:"Execution"})," - Use ResolvedAppConfig to execute capabilities, workflows, and enforce policies"]})]})]}),n("div",{className:"space-y-4",children:[e("h2",{className:"font-bold text-2xl",children:"Best practices"}),n("ul",{className:"list-inside list-disc space-y-2 text-muted-foreground",children:[e("li",{children:"Keep AppBlueprintSpec environment-agnostic - no secrets or tenant-specific data"}),e("li",{children:"Use TenantAppConfig for all tenant-specific settings and connections"}),e("li",{children:"Cache ResolvedAppConfig per request to avoid repeated resolution"}),e("li",{children:"Version blueprints carefully - migrations affect all tenants"}),e("li",{children:"Test blueprint changes in sandbox before promoting to production"})]})]}),n("div",{className:"flex items-center gap-4 pt-4",children:[e(r,{href:"/docs/architecture",className:"btn-ghost",children:"Back to Architecture"}),n(r,{href:"/docs/architecture/integration-binding",className:"btn-primary",children:["Integration Binding ",e(l,{size:16})]})]})]})}export{b as ArchitectureAppConfigPage};
