// src/components/docs/advanced/AdvancedMCPPage.tsx
import Link from "@contractspec/lib.ui-link";
import { ChevronRight } from "lucide-react";
import { jsx, jsxs } from "react/jsx-runtime";
function AdvancedMCPPage() {
  return /* @__PURE__ */ jsxs("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h1", {
            className: "text-4xl font-bold",
            children: "MCP Adapters"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "The ",
              /* @__PURE__ */ jsx("strong", {
                children: "Model Context Protocol (MCP)"
              }),
              " is an open standard for connecting AI models to external tools and data sources. ContractSpec provides MCP adapters that allow you to expose your capabilities as MCP tools and consume external MCP servers as capabilities."
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Why MCP integration matters"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "AI agents need access to real-world tools and data to be useful. MCP provides a standardized way to expose these capabilities. By integrating ContractSpec with MCP, you can:"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsx("li", {
                children: "Let AI agents invoke your ContractSpec capabilities safely and securely"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Use external MCP servers (databases, APIs, search engines) as capability providers in your workflows"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Build AI-powered features without writing custom integration code"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Enforce policies on AI agent actions just like any other user"
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Exposing capabilities as MCP tools"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "Any",
              " ",
              /* @__PURE__ */ jsx(Link, {
                href: "/docs/specs/capabilities",
                className: "text-violet-400 hover:text-violet-300",
                children: "CapabilitySpec"
              }),
              " ",
              "can be automatically exposed as an MCP tool. ContractSpec generates:"
            ]
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsx("li", {
                children: "A tool schema describing the capability's inputs, outputs, and purpose"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "An MCP server endpoint that AI agents can connect to"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Policy enforcement ensuring agents can only invoke capabilities they're authorized to use"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Audit logging of all agent actions for compliance and debugging"
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Example: Exposing a capability"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "Here's how to expose ContractSpec operations as MCP tools:"
          }),
          /* @__PURE__ */ jsx("div", {
            className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded-lg border p-4 font-mono text-sm",
            children: /* @__PURE__ */ jsx("pre", {
              children: `import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { createMcpServer } from '@contractspec/lib.contracts-runtime-server-mcp/provider-mcp';
import { registry, resources, prompts } from './lib/registry';

const server = new McpServer({
  name: 'my-app-mcp',
  version: '1.0.0',
});

createMcpServer(server, registry, resources, prompts, {
  toolCtx: () => ({ actor: 'ai-agent' }),
  promptCtx: () => ({ userId: null, orgId: null }),
  resourceCtx: () => ({ userId: null, orgId: null }),
});

const transport = new StdioServerTransport();
await server.connect(transport);`
            })
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "AI agents can now discover and invoke your operations through the MCP protocol. ContractSpec handles authentication, authorization, and execution automatically via the `OperationSpecRegistry`."
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Consuming external MCP servers"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "You can integrate external MCP servers into your workflows. Define an integration spec and use it in your operations:"
          }),
          /* @__PURE__ */ jsx("div", {
            className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded-lg border p-4 font-mono text-sm",
            children: /* @__PURE__ */ jsx("pre", {
              children: `import { defineIntegration } from '@contractspec/lib.contracts-integrations';
import { SchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';

const SearchProductsIntegration = defineIntegration({
  meta: {
    key: 'products.search',
    version: '1.0.0',
    category: 'mcp',
    description: 'Search products via external MCP server',
  },
  connection: {
    serverUrl: 'https://api.example.com/mcp',
    toolName: 'search_products',
  },
  io: {
    input: new SchemaModel({
      name: 'SearchProductsInput',
      fields: {
        query: { type: ScalarTypeEnum.String(), isOptional: false },
        category: { type: ScalarTypeEnum.String(), isOptional: true },
      },
    }),
    output: new SchemaModel({
      name: 'ProductResults',
      fields: {
        products: { type: ScalarTypeEnum.JSON(), isOptional: false, isArray: true },
      },
    }),
  },
});`
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Policy enforcement for AI agents"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "AI agents are treated like any other actor in ContractSpec. They must authenticate, and all their actions are subject to",
              " ",
              /* @__PURE__ */ jsx(Link, {
                href: "/docs/specs/policy",
                className: "text-violet-400 hover:text-violet-300",
                children: "PolicySpecs"
              }),
              ". You can define specific policies in TypeScript:"
            ]
          }),
          /* @__PURE__ */ jsx("div", {
            className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded-lg border p-4 font-mono text-sm",
            children: /* @__PURE__ */ jsx("pre", {
              children: `import { definePolicy } from '@contractspec/lib.contracts-spec';

export const AIAgentRestrictions = definePolicy({
  meta: {
    key: 'ai.agent.restrictions',
    version: '1.0.0',
    description: 'Restrict AI agent actions',
  },
  rules: [
    {
      id: 'agents-read-only',
      effect: 'DENY',
      condition: (ctx) => ctx.actor === 'ai-agent' && ctx.action === 'write',
    },
    {
      id: 'agents-require-approval',
      effect: 'DENY',
      condition: (ctx, spec) => 
        ctx.actor === 'ai-agent' && 
        spec.policy.escalate === 'human_review' &&
        !ctx.approvalGranted,
    },
  ],
});`
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Human-in-the-loop workflows"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "For sensitive operations, you can require human approval before an AI agent can proceed. ContractSpec provides built-in approval workflows:"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsx("li", {
                children: "Agent requests permission to invoke a capability"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Request is sent to designated approvers (via email, Slack, etc.)"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Approver reviews the request and approves or denies it"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Agent receives the decision and can proceed if approved"
              })
            ]
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "All approval decisions are logged in the",
              " ",
              /* @__PURE__ */ jsx(Link, {
                href: "/docs/safety/auditing",
                className: "text-violet-400 hover:text-violet-300",
                children: "audit log"
              }),
              "."
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Best practices"
          }),
          /* @__PURE__ */ jsxs("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsx("li", {
                children: "Start with read-only capabilities for AI agents—only grant write access when necessary."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Use human-in-the-loop approval for any capability that modifies critical data or triggers financial transactions."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Set rate limits to prevent runaway agents from overwhelming your system."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Provide clear, detailed descriptions for each capability so agents know when to use them."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Monitor agent actions closely in production and adjust policies as needed."
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Test agent integrations thoroughly with realistic scenarios before deploying."
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "flex items-center gap-4 pt-4",
        children: [
          /* @__PURE__ */ jsx(Link, {
            href: "/docs/advanced/renderers",
            className: "btn-ghost",
            children: "Previous: Custom Renderers"
          }),
          /* @__PURE__ */ jsxs(Link, {
            href: "/docs/advanced/telemetry",
            className: "btn-primary",
            children: [
              "Next: Telemetry ",
              /* @__PURE__ */ jsx(ChevronRight, {
                size: 16
              })
            ]
          })
        ]
      })
    ]
  });
}

// src/components/docs/advanced/AdvancedOverlayEditorPage.tsx
import Link2 from "@contractspec/lib.ui-link";
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
function AdvancedOverlayEditorPage() {
  return /* @__PURE__ */ jsxs2("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs2("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx2("h1", {
            className: "text-4xl font-bold",
            children: "Overlay Editor"
          }),
          /* @__PURE__ */ jsx2("p", {
            className: "text-muted-foreground text-lg",
            children: "A Next.js app (`@contractspec/app.overlay-editor`) that lets tenant admins tweak field visibility, labels, and ordering, then sign OverlaySpecs."
          })
        ]
      }),
      /* @__PURE__ */ jsxs2("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx2("h2", {
            className: "text-2xl font-bold",
            children: "Features"
          }),
          /* @__PURE__ */ jsxs2("ul", {
            className: "list-disc space-y-2 pl-6",
            children: [
              /* @__PURE__ */ jsx2("li", {
                children: "Toggle visibility and rename labels without touching code."
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Move fields up/down to define the overlay order."
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Preview JSON output powered by `@contractspec/lib.overlay-engine`."
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Server action for PEM signing (Ed25519/RSA-PSS)."
              })
            ]
          }),
          /* @__PURE__ */ jsxs2("p", {
            children: [
              "Project path: ",
              /* @__PURE__ */ jsx2("code", {
                children: "packages/apps/overlay-editor"
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs2("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx2("h2", {
            className: "text-2xl font-bold",
            children: "Provisioning flow"
          }),
          /* @__PURE__ */ jsxs2("ol", {
            className: "list-decimal space-y-2 pl-6",
            children: [
              /* @__PURE__ */ jsxs2("li", {
                children: [
                  "Clone the repo and run ",
                  /* @__PURE__ */ jsx2("code", {
                    children: "bun dev"
                  }),
                  " inside the app."
                ]
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Use the UI to craft the overlay for a tenant."
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Paste the tenant's PEM private key (stored in Vault/KMS)."
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Click “Sign overlay” to get the final JSON payload."
              }),
              /* @__PURE__ */ jsx2("li", {
                children: "Persist in the `Overlay` table and register with `OverlayRegistry`."
              })
            ]
          }),
          /* @__PURE__ */ jsxs2("p", {
            children: [
              "See also:",
              " ",
              /* @__PURE__ */ jsx2(Link2, {
                href: "/docs/ops/tenant-customization",
                className: "text-violet-400 underline",
                children: "Tenant customization runbook"
              }),
              "."
            ]
          })
        ]
      })
    ]
  });
}

// src/components/docs/advanced/AdvancedRenderersPage.tsx
import Link3 from "@contractspec/lib.ui-link";
import { ChevronRight as ChevronRight2 } from "lucide-react";
import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
function AdvancedRenderersPage() {
  return /* @__PURE__ */ jsxs3("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs3("div", {
        className: "space-y-2",
        children: [
          /* @__PURE__ */ jsx3("h1", {
            className: "text-4xl font-bold",
            children: "Custom Renderers"
          }),
          /* @__PURE__ */ jsx3("p", {
            className: "text-muted-foreground text-lg",
            children: "ContractSpec ships with React and React Native renderers. You can build custom renderers for any framework."
          })
        ]
      }),
      /* @__PURE__ */ jsxs3("div", {
        className: "space-y-6",
        children: [
          /* @__PURE__ */ jsxs3("div", {
            className: "space-y-3",
            children: [
              /* @__PURE__ */ jsx3("h2", {
                className: "text-2xl font-bold",
                children: "Overview"
              }),
              /* @__PURE__ */ jsxs3("p", {
                className: "text-muted-foreground",
                children: [
                  "The presentation runtime libraries (",
                  /* @__PURE__ */ jsx3("code", {
                    children: "@contractspec/lib.presentation-runtime-react"
                  }),
                  " and",
                  /* @__PURE__ */ jsx3("code", {
                    children: "@contractspec/lib.presentation-runtime-react-native"
                  }),
                  ") provide hooks and components to render ContractSpec-defined UI like workflows and data views. You can extend these or create custom implementations for other frameworks."
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsxs3("div", {
            className: "space-y-3",
            children: [
              /* @__PURE__ */ jsx3("h2", {
                className: "text-2xl font-bold",
                children: "Using the React Renderer"
              }),
              /* @__PURE__ */ jsx3("div", {
                className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded-lg border p-4 font-mono text-sm",
                children: /* @__PURE__ */ jsx3("pre", {
                  children: `import { useWorkflow, WorkflowStepRenderer } from '@contractspec/lib.presentation-runtime-react';
import { MyWorkflowSpec } from './specs';

export function WorkflowPage() {
  const workflow = useWorkflow(MyWorkflowSpec);

  return (
    <div>
      <h1>{workflow.currentStep.title}</h1>
      <WorkflowStepRenderer workflow={workflow} />
      <button onClick={workflow.next} disabled={!workflow.canProceed}>
        Next
      </button>
    </div>
  );
}`
                })
              })
            ]
          }),
          /* @__PURE__ */ jsxs3("div", {
            className: "space-y-3",
            children: [
              /* @__PURE__ */ jsx3("h2", {
                className: "text-2xl font-bold",
                children: "Custom Platform Support"
              }),
              /* @__PURE__ */ jsx3("p", {
                className: "text-muted-foreground",
                children: "To support a new platform (e.g., Vue, Svelte), you would:"
              }),
              /* @__PURE__ */ jsxs3("ol", {
                className: "text-muted-foreground list-inside list-decimal space-y-2",
                children: [
                  /* @__PURE__ */ jsxs3("li", {
                    children: [
                      "Implement the core workflow state machine (from",
                      " ",
                      /* @__PURE__ */ jsx3("code", {
                        children: "@contractspec/lib.presentation-runtime-core"
                      }),
                      ")"
                    ]
                  }),
                  /* @__PURE__ */ jsx3("li", {
                    children: "Create framework-specific hooks/components for step rendering"
                  }),
                  /* @__PURE__ */ jsx3("li", {
                    children: "Handle validation and submission via the ContractSpec I/O schemas"
                  })
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsx3("div", {
            className: "flex items-center gap-4 pt-4",
            children: /* @__PURE__ */ jsxs3(Link3, {
              href: "/docs",
              className: "btn-primary",
              children: [
                "Back to docs ",
                /* @__PURE__ */ jsx3(ChevronRight2, {
                  size: 16
                })
              ]
            })
          })
        ]
      })
    ]
  });
}

// src/components/docs/advanced/AdvancedSpecExperimentsPage.tsx
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
function AdvancedSpecExperimentsPage() {
  return /* @__PURE__ */ jsxs4("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs4("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx4("h1", {
            className: "text-4xl font-bold",
            children: "Spec Experiments"
          }),
          /* @__PURE__ */ jsx4("p", {
            className: "text-muted-foreground text-lg",
            children: "Run controlled experiments on ContractSpec operations, gradually shift traffic, and roll back automatically when guardrails trip."
          })
        ]
      }),
      /* @__PURE__ */ jsxs4("div", {
        className: "space-y-3",
        children: [
          /* @__PURE__ */ jsx4("h2", {
            className: "text-2xl font-bold",
            children: "Define control + variants"
          }),
          /* @__PURE__ */ jsx4("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import { SpecExperimentRegistry } from '@contractspec/lib.growth/spec-experiments';

const registry = new SpecExperimentRegistry().register({
  target: { name: 'billing.createInvoice', version: 4 },
  experiment: {
    key: 'billing.createInvoice.evolution',
    version: '1.0.0',
    goal: 'Reduce PO validation failures',
    primaryMetric: 'latency_ms',
    variants: [
      { id: 'control' },
      { id: 'po-required', description: 'Force PO field', weight: 1 },
    ],
  },
  control: BillingCreateInvoiceV4,
  variants: [
    { id: 'po-required', spec: BillingCreateInvoiceForAcme },
  ],
  rolloutStages: [0.01, 0.1, 0.5, 1],
  guardrails: { errorRateThreshold: 0.02, latencyP99ThresholdMs: 500 },
});`
          })
        ]
      }),
      /* @__PURE__ */ jsxs4("div", {
        className: "space-y-3",
        children: [
          /* @__PURE__ */ jsx4("h2", {
            className: "text-2xl font-bold",
            children: "Attach to runtime"
          }),
          /* @__PURE__ */ jsx4("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import { createSpecVariantResolver } from '@contractspec/lib.growth/spec-experiments';

adapterContext.specVariantResolver = createSpecVariantResolver({
  adapter,
  resolveUserId: (ctx) => ctx.userId ?? ctx.organizationId ?? 'anon',
});`
          })
        ]
      }),
      /* @__PURE__ */ jsxs4("div", {
        className: "space-y-3",
        children: [
          /* @__PURE__ */ jsx4("h2", {
            className: "text-2xl font-bold",
            children: "Track outcomes + auto-rollback"
          }),
          /* @__PURE__ */ jsx4("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import {
  SpecExperimentAnalyzer,
  SpecExperimentController,
} from '@contractspec/lib.growth/spec-experiments';

const analyzer = new SpecExperimentAnalyzer(tracker);
const controller = new SpecExperimentController({
  registry,
  analyzer,
  onRollback: (target, evaluation) => notifyOps(target, evaluation.reasons),
});`
          })
        ]
      }),
      /* @__PURE__ */ jsx4("div", {
        className: "grid gap-4 md:grid-cols-2",
        children: [
          {
            title: "Deterministic bucketing",
            description: "ExperimentRunner reuses the same hashing logic as growth experiments—every user sticks to a variant."
          },
          {
            title: "Multi-stage rollouts",
            description: "Use `rolloutStages` to shift 1% → 10% → 50% → 100%. Guardrails trigger rollbacks automatically."
          }
        ].map((card) => /* @__PURE__ */ jsxs4("div", {
          className: "card-subtle space-y-2 p-4",
          children: [
            /* @__PURE__ */ jsx4("h3", {
              className: "text-lg font-semibold",
              children: card.title
            }),
            /* @__PURE__ */ jsx4("p", {
              className: "text-muted-foreground text-sm",
              children: card.description
            })
          ]
        }, card.title))
      })
    ]
  });
}

// src/components/docs/advanced/AdvancedTelemetryPage.tsx
import Link4 from "@contractspec/lib.ui-link";
import { ChevronRight as ChevronRight3 } from "lucide-react";
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
function AdvancedTelemetryPage() {
  return /* @__PURE__ */ jsxs5("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h1", {
            className: "text-4xl font-bold",
            children: "Telemetry"
          }),
          /* @__PURE__ */ jsxs5("p", {
            className: "text-muted-foreground",
            children: [
              "A ",
              /* @__PURE__ */ jsx5("strong", {
                children: "TelemetrySpec"
              }),
              " defines what metrics, logs, and traces to collect for observability. ContractSpec automatically instruments your application based on these specs, ensuring you have the visibility you need to monitor, debug, and optimize your system."
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Why telemetry matters"
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "You can't fix what you can't see. Telemetry provides visibility into how your application is performing, where errors are occurring, and how users are interacting with your system. Without proper instrumentation, you're flying blind in production."
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "ContractSpec takes a spec-first approach to telemetry: you declare what you want to observe, and runtime adapters instrument operations automatically. This ensures consistent, comprehensive coverage without manual effort."
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Three pillars of observability"
          }),
          /* @__PURE__ */ jsxs5("div", {
            className: "space-y-3",
            children: [
              /* @__PURE__ */ jsxs5("div", {
                children: [
                  /* @__PURE__ */ jsx5("h3", {
                    className: "text-lg font-semibold",
                    children: "Metrics"
                  }),
                  /* @__PURE__ */ jsx5("p", {
                    className: "text-muted-foreground",
                    children: "Numerical measurements collected over time. Examples: request count, error rate, latency percentiles, active users, queue depth. Metrics are cheap to collect and store, making them ideal for high-level monitoring and alerting."
                  })
                ]
              }),
              /* @__PURE__ */ jsxs5("div", {
                children: [
                  /* @__PURE__ */ jsx5("h3", {
                    className: "text-lg font-semibold",
                    children: "Logs"
                  }),
                  /* @__PURE__ */ jsx5("p", {
                    className: "text-muted-foreground",
                    children: 'Timestamped text records of events. Examples: "User 123 logged in", "Payment failed for order 456", "Database connection pool exhausted". Logs provide detailed context for debugging specific issues.'
                  })
                ]
              }),
              /* @__PURE__ */ jsxs5("div", {
                children: [
                  /* @__PURE__ */ jsx5("h3", {
                    className: "text-lg font-semibold",
                    children: "Traces"
                  }),
                  /* @__PURE__ */ jsx5("p", {
                    className: "text-muted-foreground",
                    children: "Records of requests as they flow through your system. A trace shows the complete path of a request—which services it touched, how long each step took, and where errors occurred. Traces are essential for debugging distributed systems."
                  })
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Example TelemetrySpec"
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "Here's how telemetry is configured in TypeScript:"
          }),
          /* @__PURE__ */ jsx5("div", {
            className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded-lg border p-4 font-mono text-sm",
            children: /* @__PURE__ */ jsx5("pre", {
              children: `import { defineTelemetry } from '@contractspec/lib.contracts-spec/telemetry';

export const OrderProcessingTelemetry = defineTelemetry({
  meta: {
    key: 'order.processing.observability',
    version: '1.0.0',
  },
  metrics: [
    {
      name: 'orders_created_total',
      type: 'counter',
      description: 'Total number of orders created',
      labels: ['status', 'payment_method'],
    },
    {
      name: 'order_processing_duration_seconds',
      type: 'histogram',
      description: 'Time to process an order',
      buckets: [0.1, 0.5, 1.0, 2.0, 5.0, 10.0],
      labels: ['status'],
    },
  ],
  traces: [
    {
      operation: 'createOrder',
      sampleRate: 1.0, // Trace 100% of requests
      includeInputs: true,
      includeOutputs: true,
      redactFields: ['creditCard', 'ssn'],
    },
    {
      operation: 'processPayment',
      sampleRate: 0.1, // Trace 10% of requests
      includeInputs: false, // Don't log payment details
    },
  ],
  alerts: [
    {
      name: 'high-error-rate',
      condition: 'error_rate > 0.05',
      duration: '5m',
      severity: 'critical',
      notify: ['pagerduty', 'slack'],
    },
  ],
});`
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Automatic instrumentation"
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "ContractSpec automatically instruments:"
          }),
          /* @__PURE__ */ jsxs5("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "All operations"
                  }),
                  " – Request count, latency, error rate per Command/Query"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "All workflows"
                  }),
                  " – Step execution time, retry counts, compensation events"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "All data views"
                  }),
                  " – Query execution time, result set size"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "All policy decisions"
                  }),
                  " – Decision time, permit/deny ratio"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "System resources"
                  }),
                  " – CPU, memory, disk, network usage"
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "You don't need to add instrumentation code manually—the runtime handles it based on your specs."
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Integration with observability platforms"
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "ContractSpec supports multiple observability backends:"
          }),
          /* @__PURE__ */ jsxs5("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Prometheus"
                  }),
                  " – For metrics collection and alerting"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Grafana"
                  }),
                  " – For dashboards and visualization"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Jaeger / Tempo"
                  }),
                  " – For distributed tracing"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Loki"
                  }),
                  " – For log aggregation"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Datadog"
                  }),
                  " – All-in-one observability platform"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "New Relic"
                  }),
                  " – Application performance monitoring"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Honeycomb"
                  }),
                  " – Observability for complex systems"
                ]
              })
            ]
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "You can configure multiple backends and send telemetry to all of them simultaneously."
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Sampling and performance"
          }),
          /* @__PURE__ */ jsx5("p", {
            className: "text-muted-foreground",
            children: "Collecting telemetry has a cost—CPU, memory, network bandwidth, and storage. ContractSpec provides several mechanisms to control overhead:"
          }),
          /* @__PURE__ */ jsxs5("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Sampling"
                  }),
                  " – Trace only a percentage of requests (e.g., 10%)"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Adaptive sampling"
                  }),
                  " – Automatically reduce sampling rate under high load"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Tail-based sampling"
                  }),
                  " – Keep traces for failed requests, sample successful ones"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Field redaction"
                  }),
                  " – Remove sensitive data from traces and logs"
                ]
              }),
              /* @__PURE__ */ jsxs5("li", {
                children: [
                  /* @__PURE__ */ jsx5("strong", {
                    children: "Aggregation"
                  }),
                  " – Pre-aggregate metrics before sending to reduce network traffic"
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx5("h2", {
            className: "text-2xl font-bold",
            children: "Best practices"
          }),
          /* @__PURE__ */ jsxs5("ul", {
            className: "text-muted-foreground list-inside list-disc space-y-2",
            children: [
              /* @__PURE__ */ jsx5("li", {
                children: "Start with high-level metrics (request rate, error rate, latency) and add more detailed instrumentation as needed."
              }),
              /* @__PURE__ */ jsx5("li", {
                children: "Use structured logging—log events with structured fields, not free-form text."
              }),
              /* @__PURE__ */ jsx5("li", {
                children: "Set up alerts for critical metrics so you're notified when things go wrong."
              }),
              /* @__PURE__ */ jsx5("li", {
                children: "Use traces to debug complex issues—they show the complete picture of a request."
              }),
              /* @__PURE__ */ jsx5("li", {
                children: "Redact sensitive data from logs and traces to comply with privacy regulations."
              }),
              /* @__PURE__ */ jsx5("li", {
                children: "Review dashboards regularly to understand normal behavior—this makes anomalies easier to spot."
              }),
              /* @__PURE__ */ jsx5("li", {
                children: "Use sampling to control costs, but always trace errors and slow requests."
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs5("div", {
        className: "flex items-center gap-4 pt-4",
        children: [
          /* @__PURE__ */ jsx5(Link4, {
            href: "/docs/advanced/mcp",
            className: "btn-ghost",
            children: "Previous: MCP Adapters"
          }),
          /* @__PURE__ */ jsxs5(Link4, {
            href: "/docs/comparison",
            className: "btn-primary",
            children: [
              "Next: Comparison ",
              /* @__PURE__ */ jsx5(ChevronRight3, {
                size: 16
              })
            ]
          })
        ]
      })
    ]
  });
}

// src/components/docs/advanced/AdvancedWorkflowMonitoringPage.tsx
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
function AdvancedWorkflowMonitoringPage() {
  return /* @__PURE__ */ jsxs6("div", {
    className: "space-y-8",
    children: [
      /* @__PURE__ */ jsxs6("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx6("h1", {
            className: "text-4xl font-bold",
            children: "Workflow Monitoring"
          }),
          /* @__PURE__ */ jsx6("p", {
            className: "text-muted-foreground text-lg",
            children: "Production workflows need robust observability. ContractSpec provides SLA monitoring, distributed tracing, and audit logging out of the box."
          })
        ]
      }),
      /* @__PURE__ */ jsxs6("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx6("h2", {
            className: "text-2xl font-bold",
            children: "SLA Monitoring"
          }),
          /* @__PURE__ */ jsxs6("p", {
            children: [
              "Use the ",
              /* @__PURE__ */ jsx6("code", {
                children: "SLAMonitor"
              }),
              " to detect when workflows or individual steps exceed their budgeted duration."
            ]
          }),
          /* @__PURE__ */ jsx6("pre", {
            className: "bg-muted rounded-lg border p-4 text-sm",
            children: `import { SLAMonitor } from '@contractspec/lib.contracts-spec/workflow/sla-monitor';

const monitor = new SLAMonitor((event, payload) => {
  if (event === 'workflow.sla_breach') {
    console.error('SLA Breach!', payload);
    // Send to PagerDuty / Slack
  }
});

// Check periodically
monitor.check(currentState, workflowSpec);`
          })
        ]
      }),
      /* @__PURE__ */ jsxs6("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx6("h2", {
            className: "text-2xl font-bold",
            children: "Telemetry & Tracing"
          }),
          /* @__PURE__ */ jsx6("p", {
            children: "Workflows automatically generate OpenTelemetry spans for:"
          }),
          /* @__PURE__ */ jsxs6("ul", {
            className: "list-disc space-y-2 pl-6",
            children: [
              /* @__PURE__ */ jsx6("li", {
                children: "Overall workflow execution"
              }),
              /* @__PURE__ */ jsx6("li", {
                children: "Individual steps"
              }),
              /* @__PURE__ */ jsx6("li", {
                children: "Retries and compensation"
              })
            ]
          }),
          /* @__PURE__ */ jsx6("p", {
            children: "Configure your OpenTelemetry exporter to send traces to Jaeger, Datadog, or Honeycomb."
          })
        ]
      }),
      /* @__PURE__ */ jsxs6("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx6("h2", {
            className: "text-2xl font-bold",
            children: "Dashboarding"
          }),
          /* @__PURE__ */ jsxs6("p", {
            children: [
              "You can build a custom dashboard using ",
              /* @__PURE__ */ jsx6("code", {
                children: "DataViews"
              }),
              " over your workflow state database. See the DataViews tutorial for how to visualize ",
              /* @__PURE__ */ jsx6("code", {
                children: "WorkflowState"
              }),
              " records."
            ]
          })
        ]
      })
    ]
  });
}
export {
  AdvancedWorkflowMonitoringPage,
  AdvancedTelemetryPage,
  AdvancedSpecExperimentsPage,
  AdvancedRenderersPage,
  AdvancedOverlayEditorPage,
  AdvancedMCPPage
};
