// src/components/docs/knowledge/KnowledgeSourcesPage.tsx
import Link from "@contractspec/lib.ui-link";
import { ChevronRight } from "lucide-react";
import { jsx, jsxs } from "react/jsx-runtime";
function KnowledgeSourcesPage() {
  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: "Knowledge Sources"
          }),
          /* @__PURE__ */ jsxs("p", {
            className: "text-muted-foreground",
            children: [
              "A ",
              /* @__PURE__ */ jsx("strong", {
                children: "KnowledgeSourceConfig"
              }),
              " connects a tenant's data sources (Notion, Gmail, uploads, databases) to knowledge spaces. Each source is synced, chunked, embedded, and indexed according to the space's configuration."
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "KnowledgeSourceConfig"
          }),
          /* @__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: `type KnowledgeSourceConfig = {
  id: string;
  tenantId: string;
  spaceId: string;
  
  // Source type and location
  kind: "uploaded-document" | "url" | "email" 
        | "notion" | "database-query" | "raw-text"
        | "slack" | "confluence" | "google-drive";
  location: string;
  
  // Sync configuration
  syncPolicy: {
    interval?: string;  // e.g., "1h", "24h"
    webhook?: boolean;
    manual?: boolean;
  };
  
  // State
  status: "active" | "paused" | "error";
  lastSyncedAt?: string;
  lastErrorMessage?: string;
  
  // Metadata
  metadata?: Record<string, unknown>;
  createdAt: string;
  updatedAt: string;
};`
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Source types"
          }),
          /* @__PURE__ */ jsxs("div", {
            className: "space-y-6",
            children: [
              /* @__PURE__ */ jsxs("div", {
                className: "card-subtle p-4",
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "mb-2 text-lg font-semibold",
                    children: "Uploaded Documents"
                  }),
                  /* @__PURE__ */ jsx("div", {
                    className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded border p-3 font-mono text-xs",
                    children: /* @__PURE__ */ jsx("pre", {
                      children: `{
  kind: "uploaded-document",
  location: "s3://bucket/tenant-123/docs/product-spec.pdf",
  syncPolicy: { manual: true }
}`
                    })
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground mt-2 text-sm",
                    children: "PDFs, Word docs, presentations uploaded by users"
                  })
                ]
              }),
              /* @__PURE__ */ jsxs("div", {
                className: "card-subtle p-4",
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "mb-2 text-lg font-semibold",
                    children: "Notion"
                  }),
                  /* @__PURE__ */ jsx("div", {
                    className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded border p-3 font-mono text-xs",
                    children: /* @__PURE__ */ jsx("pre", {
                      children: `{
  kind: "notion",
  location: "https://notion.so/workspace/product-docs",
  syncPolicy: { interval: "1h", webhook: true }
}`
                    })
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground mt-2 text-sm",
                    children: "Notion pages and databases with real-time webhook updates"
                  })
                ]
              }),
              /* @__PURE__ */ jsxs("div", {
                className: "card-subtle p-4",
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "mb-2 text-lg font-semibold",
                    children: "Gmail / Email"
                  }),
                  /* @__PURE__ */ jsx("div", {
                    className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded border p-3 font-mono text-xs",
                    children: /* @__PURE__ */ jsx("pre", {
                      children: `{
  kind: "email",
  location: "support@company.com",
  syncPolicy: { webhook: true }
}`
                    })
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground mt-2 text-sm",
                    children: "Email threads from Gmail or other providers"
                  })
                ]
              }),
              /* @__PURE__ */ jsxs("div", {
                className: "card-subtle p-4",
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "mb-2 text-lg font-semibold",
                    children: "Database Query"
                  }),
                  /* @__PURE__ */ jsx("div", {
                    className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded border p-3 font-mono text-xs",
                    children: /* @__PURE__ */ jsx("pre", {
                      children: `{
  kind: "database-query",
  location: "SELECT * FROM products WHERE active = true",
  syncPolicy: { interval: "24h" }
}`
                    })
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground mt-2 text-sm",
                    children: "Structured data from application databases"
                  })
                ]
              }),
              /* @__PURE__ */ jsxs("div", {
                className: "card-subtle p-4",
                children: [
                  /* @__PURE__ */ jsx("h3", {
                    className: "mb-2 text-lg font-semibold",
                    children: "URL / Web Scraping"
                  }),
                  /* @__PURE__ */ jsx("div", {
                    className: "bg-background/50 border-border text-muted-foreground overflow-x-auto rounded border p-3 font-mono text-xs",
                    children: /* @__PURE__ */ jsx("pre", {
                      children: `{
  kind: "url",
  location: "https://stripe.com/docs",
  syncPolicy: { interval: "24h" }
}`
                    })
                  }),
                  /* @__PURE__ */ jsx("p", {
                    className: "text-muted-foreground mt-2 text-sm",
                    children: "External documentation and web content"
                  })
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Sync strategies"
          }),
          /* @__PURE__ */ jsx("div", {
            className: "border-border/50 overflow-x-auto rounded-lg border",
            children: /* @__PURE__ */ jsxs("table", {
              className: "w-full text-left text-sm",
              children: [
                /* @__PURE__ */ jsx("thead", {
                  className: "bg-card/50",
                  children: /* @__PURE__ */ jsxs("tr", {
                    className: "border-border/50 border-b",
                    children: [
                      /* @__PURE__ */ jsx("th", {
                        className: "px-4 py-3 font-semibold",
                        children: "Strategy"
                      }),
                      /* @__PURE__ */ jsx("th", {
                        className: "px-4 py-3 font-semibold",
                        children: "When to Use"
                      }),
                      /* @__PURE__ */ jsx("th", {
                        className: "px-4 py-3 font-semibold",
                        children: "Latency"
                      })
                    ]
                  })
                }),
                /* @__PURE__ */ jsxs("tbody", {
                  className: "divide-border/50 divide-y",
                  children: [
                    /* @__PURE__ */ jsxs("tr", {
                      children: [
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3 font-mono text-xs",
                          children: "webhook"
                        }),
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3",
                          children: "Real-time updates (Notion, Gmail, Slack)"
                        }),
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3",
                          children: "Seconds"
                        })
                      ]
                    }),
                    /* @__PURE__ */ jsxs("tr", {
                      children: [
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3 font-mono text-xs",
                          children: "interval"
                        }),
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3",
                          children: "Periodic sync (databases, URLs)"
                        }),
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3",
                          children: "Minutes to hours"
                        })
                      ]
                    }),
                    /* @__PURE__ */ jsxs("tr", {
                      children: [
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3 font-mono text-xs",
                          children: "manual"
                        }),
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3",
                          children: "User-triggered (uploads, one-time imports)"
                        }),
                        /* @__PURE__ */ jsx("td", {
                          className: "px-4 py-3",
                          children: "On-demand"
                        })
                      ]
                    })
                  ]
                })
              ]
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Example: Multi-source space"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "A single knowledge space can be fed by multiple sources:"
          }),
          /* @__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: `// Product Canon space with multiple sources
{
  spaceId: "product-canon",
  sources: [
    {
      id: "src_database_schema",
      kind: "database-query",
      location: "SELECT * FROM schema_definitions",
      syncPolicy: { interval: "1h" }
    },
    {
      id: "src_notion_product_docs",
      kind: "notion",
      location: "https://notion.so/product-docs",
      syncPolicy: { interval: "1h", webhook: true }
    },
    {
      id: "src_uploaded_specs",
      kind: "uploaded-document",
      location: "s3://bucket/specs/",
      syncPolicy: { manual: true }
    }
  ]
}`
            })
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "space-y-4",
        children: [
          /* @__PURE__ */ jsx("h2", {
            className: "text-2xl font-bold",
            children: "Processing pipeline"
          }),
          /* @__PURE__ */ jsx("p", {
            className: "text-muted-foreground",
            children: "When a source is synced, ContractSpec processes it through several stages:"
          }),
          /* @__PURE__ */ jsxs("ol", {
            className: "text-muted-foreground list-inside list-decimal space-y-3",
            children: [
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Fetch"
                  }),
                  " - Retrieve content from source (API, database, file)"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Parse"
                  }),
                  " - Extract text from documents (PDF, Word, HTML)"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Chunk"
                  }),
                  " - Split into semantic chunks (paragraphs, sections)"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Embed"
                  }),
                  " - Generate vector embeddings (OpenAI, Cohere)"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Index"
                  }),
                  " - Store in vector database (Qdrant) or search engine"
                ]
              }),
              /* @__PURE__ */ jsxs("li", {
                children: [
                  /* @__PURE__ */ jsx("strong", {
                    children: "Audit"
                  }),
                  " - Log sync operation and results"
                ]
              })
            ]
          })
        ]
      }),
      /* @__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: "Use webhooks for real-time sources (Notion, Gmail) to minimize latency"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Set appropriate sync intervals - hourly for active docs, daily for stable content"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Monitor sync failures and set up alerts for critical sources"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Test sources in sandbox before enabling in production"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Document the purpose and ownership of each source for your team"
              }),
              /* @__PURE__ */ jsx("li", {
                children: "Use manual sync for sensitive or infrequently updated content"
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsxs("div", {
        className: "flex items-center gap-4 pt-4",
        children: [
          /* @__PURE__ */ jsx(Link, {
            href: "/docs/knowledge/spaces",
            className: "btn-ghost",
            children: "Previous: Spaces"
          }),
          /* @__PURE__ */ jsxs(Link, {
            href: "/docs/knowledge/examples",
            className: "btn-primary",
            children: [
              "Examples ",
              /* @__PURE__ */ jsx(ChevronRight, {
                size: 16
              })
            ]
          })
        ]
      })
    ]
  });
}
export {
  KnowledgeSourcesPage
};
