@wrikka/create-docs 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -0
- package/bin/cli.js +408 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +475 -0
- package/dist/index.d.ts +475 -0
- package/dist/index.js +20 -0
- package/docs/_dir.yml +2 -0
- package/docs/config.md +75 -0
- package/docs/data-sources.md +88 -0
- package/docs/deploy.md +38 -0
- package/docs/features.md +51 -0
- package/docs/getting-started.md +42 -0
- package/docs/index.md +34 -0
- package/docs/markdown.md +154 -0
- package/docs/theming.md +53 -0
- package/package.json +142 -0
- package/scripts/generate-docs-index.ts +111 -0
- package/scripts/github-pull.ts +124 -0
- package/src/adapters/config/index.ts +1 -0
- package/src/adapters/config/node-config-loader.ts +36 -0
- package/src/adapters/fs/fs-docs-loader.ts +31 -0
- package/src/adapters/fs/index.ts +12 -0
- package/src/adapters/fs/memory-fs.ts +60 -0
- package/src/adapters/fs/node-fs.ts +116 -0
- package/src/adapters/git/index.ts +164 -0
- package/src/adapters/github/github-pull.ts +340 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/velite.ts +112 -0
- package/src/adapters/vite/docs-watcher.ts +36 -0
- package/src/adapters/vite/index.ts +2 -0
- package/src/adapters/vite/polling-watcher.ts +89 -0
- package/src/code-block-enhancements/index.ts +3 -0
- package/src/config/index.ts +15 -0
- package/src/content/index.ts +11 -0
- package/src/content-validation/index.ts +5 -0
- package/src/index.ts +174 -0
- package/src/live-editor/index.ts +7 -0
- package/src/modules/analytics/application/plausible-adapter.ts +103 -0
- package/src/modules/analytics/application/umami-adapter.ts +109 -0
- package/src/modules/analytics/domain/events/index.ts +37 -0
- package/src/modules/analytics/domain/models/index.ts +35 -0
- package/src/modules/analytics/domain/operations/analytics-operations.ts +67 -0
- package/src/modules/analytics/domain/validators/index.ts +50 -0
- package/src/modules/analytics/index.ts +9 -0
- package/src/modules/analytics/ports/analytics-port.ts +17 -0
- package/src/modules/analytics/types/analytics.ts +16 -0
- package/src/modules/api-docs/application/type-docs-adapter.ts +34 -0
- package/src/modules/api-docs/domain/events/index.ts +42 -0
- package/src/modules/api-docs/domain/models/index.ts +40 -0
- package/src/modules/api-docs/domain/operations/api-docs-operations.ts +59 -0
- package/src/modules/api-docs/domain/validators/index.ts +56 -0
- package/src/modules/api-docs/index.ts +8 -0
- package/src/modules/api-docs/ports/api-docs-port.ts +21 -0
- package/src/modules/api-docs/types/api-docs.ts +15 -0
- package/src/modules/api-reference/openapi.ts +166 -0
- package/src/modules/api-reference/orpc.ts +94 -0
- package/src/modules/code-block-enhancements/application/usecases/index.ts +39 -0
- package/src/modules/code-block-enhancements/domain/code-operations.ts +72 -0
- package/src/modules/code-block-enhancements/domain/events/index.ts +58 -0
- package/src/modules/code-block-enhancements/domain/index.ts +11 -0
- package/src/modules/code-block-enhancements/domain/models/index.ts +36 -0
- package/src/modules/code-block-enhancements/domain/validators/index.ts +50 -0
- package/src/modules/code-block-enhancements/index.ts +10 -0
- package/src/modules/code-block-enhancements/ports/index.ts +18 -0
- package/src/modules/code-block-enhancements/types/index.ts +37 -0
- package/src/modules/code-execution/application/sandbox-adapter.ts +44 -0
- package/src/modules/code-execution/domain/events/index.ts +58 -0
- package/src/modules/code-execution/domain/models/index.ts +33 -0
- package/src/modules/code-execution/domain/operations/execution-operations.ts +60 -0
- package/src/modules/code-execution/domain/validators/index.ts +50 -0
- package/src/modules/code-execution/index.ts +8 -0
- package/src/modules/code-execution/ports/execution-port.ts +15 -0
- package/src/modules/code-execution/types/execution.ts +15 -0
- package/src/modules/comments/application/giscus-adapter.ts +55 -0
- package/src/modules/comments/domain/events/index.ts +55 -0
- package/src/modules/comments/domain/models/index.ts +30 -0
- package/src/modules/comments/domain/operations/comment-operations.ts +46 -0
- package/src/modules/comments/domain/validators/index.ts +50 -0
- package/src/modules/comments/index.ts +8 -0
- package/src/modules/comments/ports/comment-port.ts +18 -0
- package/src/modules/comments/types/comments.ts +19 -0
- package/src/modules/config/application/usecases/index.ts +1 -0
- package/src/modules/config/application/usecases/loadConfig.ts +38 -0
- package/src/modules/config/application/workflows/index.ts +1 -0
- package/src/modules/config/application/workflows/validateConfig.ts +14 -0
- package/src/modules/config/domain/events/index.ts +50 -0
- package/src/modules/config/domain/models/index.ts +9 -0
- package/src/modules/config/domain/operations/defaults.ts +74 -0
- package/src/modules/config/domain/operations/index.ts +2 -0
- package/src/modules/config/domain/operations/resolve.ts +40 -0
- package/src/modules/config/domain/validators/index.ts +152 -0
- package/src/modules/config/index.ts +23 -0
- package/src/modules/config/ports/index.ts +15 -0
- package/src/modules/config/types/index.ts +113 -0
- package/src/modules/config/types/public.ts +19 -0
- package/src/modules/content/application/cache/index.ts +6 -0
- package/src/modules/content/application/cache/parse-cache.ts +6 -0
- package/src/modules/content/application/cache/parseCache.ts +56 -0
- package/src/modules/content/application/usecases/index.ts +2 -0
- package/src/modules/content/application/usecases/load-doc-page.ts +1 -0
- package/src/modules/content/application/usecases/loadDocPage.ts +111 -0
- package/src/modules/content/application/usecases/scanDocsDir.ts +105 -0
- package/src/modules/content/application/workflows/index.ts +1 -0
- package/src/modules/content/application/workflows/processDocs.ts +51 -0
- package/src/modules/content/domain/events/index.ts +61 -0
- package/src/modules/content/domain/models/index.ts +13 -0
- package/src/modules/content/domain/operations/build-page.ts +146 -0
- package/src/modules/content/domain/operations/buildPage.ts +93 -0
- package/src/modules/content/domain/operations/index.ts +17 -0
- package/src/modules/content/domain/operations/parse.ts +241 -0
- package/src/modules/content/domain/validators/frontmatter.ts +82 -0
- package/src/modules/content/domain/validators/index.ts +6 -0
- package/src/modules/content/index.ts +27 -0
- package/src/modules/content/ports/index.ts +45 -0
- package/src/modules/content/ports/velite.ts +134 -0
- package/src/modules/content/types/index.ts +76 -0
- package/src/modules/content/types/public.ts +1 -0
- package/src/modules/content-linting/application/builtin-linting-adapter.ts +82 -0
- package/src/modules/content-linting/domain/events/index.ts +58 -0
- package/src/modules/content-linting/domain/models/index.ts +46 -0
- package/src/modules/content-linting/domain/operations/linting-operations.ts +82 -0
- package/src/modules/content-linting/domain/validators/index.ts +50 -0
- package/src/modules/content-linting/index.ts +8 -0
- package/src/modules/content-linting/ports/linting-port.ts +21 -0
- package/src/modules/content-linting/types/linting.ts +18 -0
- package/src/modules/content-validation/application/usecases/index.ts +18 -0
- package/src/modules/content-validation/domain/events/index.ts +7 -0
- package/src/modules/content-validation/domain/index.ts +16 -0
- package/src/modules/content-validation/domain/models/index.ts +33 -0
- package/src/modules/content-validation/domain/operations/index.ts +157 -0
- package/src/modules/content-validation/domain/types/index.ts +17 -0
- package/src/modules/content-validation/domain/validators/index.ts +8 -0
- package/src/modules/content-validation/index.ts +9 -0
- package/src/modules/content-validation/ports/index.ts +15 -0
- package/src/modules/content-validation/types/index.ts +5 -0
- package/src/modules/export/application/puppeteer-export-adapter.ts +63 -0
- package/src/modules/export/domain/events/index.ts +55 -0
- package/src/modules/export/domain/models/index.ts +38 -0
- package/src/modules/export/domain/operations/export-operations.ts +56 -0
- package/src/modules/export/domain/validators/index.ts +52 -0
- package/src/modules/export/index.ts +8 -0
- package/src/modules/export/ports/export-port.ts +15 -0
- package/src/modules/export/types/export.ts +15 -0
- package/src/modules/external-search/application/algolia-adapter.ts +182 -0
- package/src/modules/external-search/application/meilisearch-adapter.ts +161 -0
- package/src/modules/external-search/domain/events/index.ts +42 -0
- package/src/modules/external-search/domain/models/index.ts +42 -0
- package/src/modules/external-search/domain/operations/search-operations.ts +53 -0
- package/src/modules/external-search/domain/validators/index.ts +55 -0
- package/src/modules/external-search/index.ts +9 -0
- package/src/modules/external-search/ports/external-search-port.ts +23 -0
- package/src/modules/external-search/types/search.ts +19 -0
- package/src/modules/git-history/application/simple-git-adapter.ts +46 -0
- package/src/modules/git-history/domain/events/index.ts +34 -0
- package/src/modules/git-history/domain/models/index.ts +25 -0
- package/src/modules/git-history/domain/operations/git-history-operations.ts +56 -0
- package/src/modules/git-history/domain/validators/index.ts +52 -0
- package/src/modules/git-history/index.ts +8 -0
- package/src/modules/git-history/ports/git-history-port.ts +21 -0
- package/src/modules/git-history/types/git-history.ts +15 -0
- package/src/modules/i18n/application/fs-locale-loader.ts +39 -0
- package/src/modules/i18n/domain/events/index.ts +34 -0
- package/src/modules/i18n/domain/models/index.ts +34 -0
- package/src/modules/i18n/domain/operations/locale-operations.ts +74 -0
- package/src/modules/i18n/domain/validators/index.ts +52 -0
- package/src/modules/i18n/index.ts +8 -0
- package/src/modules/i18n/ports/locale-loader-port.ts +18 -0
- package/src/modules/i18n/types/locale.ts +17 -0
- package/src/modules/image-optimization/application/sharp-adapter.ts +58 -0
- package/src/modules/image-optimization/domain/events/index.ts +39 -0
- package/src/modules/image-optimization/domain/models/index.ts +27 -0
- package/src/modules/image-optimization/domain/operations/image-operations.ts +65 -0
- package/src/modules/image-optimization/domain/validators/index.ts +52 -0
- package/src/modules/image-optimization/index.ts +8 -0
- package/src/modules/image-optimization/ports/image-optimizer-port.ts +15 -0
- package/src/modules/image-optimization/types/image.ts +17 -0
- package/src/modules/live-editor/application/usecases/index.ts +60 -0
- package/src/modules/live-editor/domain/events/index.ts +37 -0
- package/src/modules/live-editor/domain/gitOperations.ts +110 -0
- package/src/modules/live-editor/domain/index.ts +15 -0
- package/src/modules/live-editor/domain/models/index.ts +21 -0
- package/src/modules/live-editor/domain/validators/index.ts +55 -0
- package/src/modules/live-editor/index.ts +14 -0
- package/src/modules/live-editor/ports/index.ts +49 -0
- package/src/modules/live-editor/types/index.ts +80 -0
- package/src/modules/live-preview/application/vite-preview-adapter.ts +20 -0
- package/src/modules/live-preview/domain/operations/preview-operations.ts +56 -0
- package/src/modules/live-preview/index.ts +8 -0
- package/src/modules/live-preview/ports/preview-port.ts +20 -0
- package/src/modules/live-preview/types/preview.ts +16 -0
- package/src/modules/mdx/application/mdx-js-adapter.ts +38 -0
- package/src/modules/mdx/domain/operations/parse-mdx.ts +43 -0
- package/src/modules/mdx/index.ts +8 -0
- package/src/modules/mdx/ports/mdx-parser-port.ts +15 -0
- package/src/modules/mdx/types/mdx.ts +14 -0
- package/src/modules/navigation/application/usecases/buildNav.ts +15 -0
- package/src/modules/navigation/application/usecases/buildSidebar.ts +45 -0
- package/src/modules/navigation/application/usecases/index.ts +2 -0
- package/src/modules/navigation/domain/events/index.ts +30 -0
- package/src/modules/navigation/domain/models/index.ts +7 -0
- package/src/modules/navigation/domain/operations/group.ts +79 -0
- package/src/modules/navigation/domain/operations/index.ts +10 -0
- package/src/modules/navigation/domain/operations/sort.ts +27 -0
- package/src/modules/navigation/domain/shared/utils/array.ts +39 -0
- package/src/modules/navigation/domain/validators/index.ts +88 -0
- package/src/modules/navigation/index.ts +15 -0
- package/src/modules/navigation/ports/index.ts +9 -0
- package/src/modules/navigation/types/index.ts +38 -0
- package/src/modules/navigation/types/public.ts +9 -0
- package/src/modules/openapi/application/swagger-parser-adapter.ts +178 -0
- package/src/modules/openapi/domain/operations/parse-openapi.ts +46 -0
- package/src/modules/openapi/index.ts +8 -0
- package/src/modules/openapi/ports/openapi-parser-port.ts +15 -0
- package/src/modules/openapi/types/openapi.ts +37 -0
- package/src/modules/plugin/application/usecases/build-virtual-modules.ts +53 -0
- package/src/modules/plugin/application/usecases/index.ts +1 -0
- package/src/modules/plugin/application/workflows/build-docs.ts +79 -0
- package/src/modules/plugin/application/workflows/index.ts +1 -0
- package/src/modules/plugin/domain/events/index.ts +62 -0
- package/src/modules/plugin/domain/models/index.ts +1 -0
- package/src/modules/plugin/domain/operations/build-virtual.ts +76 -0
- package/src/modules/plugin/domain/operations/index.ts +11 -0
- package/src/modules/plugin/domain/validators/index.ts +30 -0
- package/src/modules/plugin/index.ts +14 -0
- package/src/modules/plugin/ports/index.ts +21 -0
- package/src/modules/plugin/types/index.ts +27 -0
- package/src/modules/plugin/types/public.ts +1 -0
- package/src/modules/search/application/usecases/index.ts +1 -0
- package/src/modules/search/application/usecases/indexPages.ts +15 -0
- package/src/modules/search/domain/events/index.ts +32 -0
- package/src/modules/search/domain/models/index.ts +1 -0
- package/src/modules/search/domain/operations/build-index.ts +6 -0
- package/src/modules/search/domain/operations/buildIndex.ts +70 -0
- package/src/modules/search/domain/operations/index.ts +7 -0
- package/src/modules/search/domain/operations/query.ts +186 -0
- package/src/modules/search/domain/validators/index.ts +32 -0
- package/src/modules/search/index.ts +9 -0
- package/src/modules/search/types/index.ts +22 -0
- package/src/modules/search/types/public.ts +1 -0
- package/src/modules/search-analytics/application/local-storage-adapter.ts +68 -0
- package/src/modules/search-analytics/domain/operations/search-analytics-operations.ts +74 -0
- package/src/modules/search-analytics/index.ts +8 -0
- package/src/modules/search-analytics/ports/search-analytics-port.ts +20 -0
- package/src/modules/search-analytics/types/search-analytics.ts +16 -0
- package/src/modules/search-highlighting/application/dom-highlighting-adapter.ts +36 -0
- package/src/modules/search-highlighting/domain/operations/highlighting-operations.ts +72 -0
- package/src/modules/search-highlighting/index.ts +8 -0
- package/src/modules/search-highlighting/ports/highlighting-port.ts +14 -0
- package/src/modules/search-highlighting/types/highlighting.ts +15 -0
- package/src/modules/seo-optimization/application/usecases/index.ts +18 -0
- package/src/modules/seo-optimization/domain/index.ts +12 -0
- package/src/modules/seo-optimization/domain/seoOperations.ts +92 -0
- package/src/modules/seo-optimization/index.ts +8 -0
- package/src/modules/seo-optimization/ports/index.ts +18 -0
- package/src/modules/seo-optimization/types/index.ts +41 -0
- package/src/modules/theme/application/css-theme-adapter.ts +50 -0
- package/src/modules/theme/domain/operations/theme-operations.ts +68 -0
- package/src/modules/theme/index.ts +8 -0
- package/src/modules/theme/ports/theme-port.ts +8 -0
- package/src/modules/theme/types/theme.ts +12 -0
- package/src/modules/toc/application/markdown-toc-adapter.ts +106 -0
- package/src/modules/toc/domain/operations/toc-operations.ts +92 -0
- package/src/modules/toc/index.ts +8 -0
- package/src/modules/toc/ports/toc-port.ts +21 -0
- package/src/modules/toc/types/toc.ts +17 -0
- package/src/modules/toc-generator/application/usecases/index.ts +30 -0
- package/src/modules/toc-generator/domain/index.ts +12 -0
- package/src/modules/toc-generator/domain/tocOperations.ts +104 -0
- package/src/modules/toc-generator/index.ts +9 -0
- package/src/modules/toc-generator/ports/index.ts +20 -0
- package/src/modules/toc-generator/types/index.ts +50 -0
- package/src/modules/version-control/domain/events/index.ts +39 -0
- package/src/modules/version-control/domain/models/index.ts +25 -0
- package/src/modules/version-control/domain/validators/index.ts +50 -0
- package/src/modules/versioning/application/fs-version-loader.ts +44 -0
- package/src/modules/versioning/domain/operations/versioning-operations.ts +80 -0
- package/src/modules/versioning/index.ts +8 -0
- package/src/modules/versioning/ports/version-loader-port.ts +18 -0
- package/src/modules/versioning/types/versioning.ts +17 -0
- package/src/modules/workflow/domain/events/index.ts +55 -0
- package/src/modules/workflow/domain/models/index.ts +40 -0
- package/src/modules/workflow/domain/validators/index.ts +50 -0
- package/src/modules/yaml-parser/application/js-yaml-adapter.ts +34 -0
- package/src/modules/yaml-parser/domain/operations/parse-yaml.ts +58 -0
- package/src/modules/yaml-parser/index.ts +7 -0
- package/src/modules/yaml-parser/ports/yaml-parser-port.ts +18 -0
- package/src/navigation/index.ts +9 -0
- package/src/plugin/index.ts +4 -0
- package/src/presentation/index.ts +1 -0
- package/src/presentation/live-editor/index.ts +22 -0
- package/src/presentation/live-editor/live-editor-component.ts +219 -0
- package/src/presentation/live-editor/virtual-module.ts +16 -0
- package/src/presentation/solid/CodeBlock.tsx +120 -0
- package/src/presentation/solid/Toc.tsx +58 -0
- package/src/presentation/solid/index.ts +11 -0
- package/src/presentation/vite-plugin/docs-plugin.ts +212 -0
- package/src/presentation/vite-plugin/index.ts +9 -0
- package/src/presentation/vite-plugin/transform-markdown.ts +26 -0
- package/src/runtime/analytics.ts +59 -0
- package/src/runtime/api-diff.ts +115 -0
- package/src/runtime/app.tsx +32 -0
- package/src/runtime/components/AccentPicker.tsx +114 -0
- package/src/runtime/components/ApiPlayground.tsx +332 -0
- package/src/runtime/components/AskAiDialog.tsx +127 -0
- package/src/runtime/components/BackToTop.tsx +38 -0
- package/src/runtime/components/Banner.tsx +75 -0
- package/src/runtime/components/Breadcrumbs.tsx +42 -0
- package/src/runtime/components/CollectionDropdown.tsx +85 -0
- package/src/runtime/components/CustomizeDrawer.tsx +195 -0
- package/src/runtime/components/DocMarkdown.tsx +579 -0
- package/src/runtime/components/DocPrevNext.tsx +54 -0
- package/src/runtime/components/DocToc.tsx +147 -0
- package/src/runtime/components/DocsDropdown.tsx +184 -0
- package/src/runtime/components/Footer.tsx +52 -0
- package/src/runtime/components/GitHubAuth.tsx +82 -0
- package/src/runtime/components/GitHubStats.tsx +73 -0
- package/src/runtime/components/Head.tsx +225 -0
- package/src/runtime/components/LocaleDropdown.tsx +75 -0
- package/src/runtime/components/MobileBottomNav.tsx +111 -0
- package/src/runtime/components/NotFound.tsx +139 -0
- package/src/runtime/components/PageActions.tsx +144 -0
- package/src/runtime/components/RelatedDocs.tsx +50 -0
- package/src/runtime/components/ScrollProgress.tsx +32 -0
- package/src/runtime/components/SearchPalette.tsx +333 -0
- package/src/runtime/components/ShowcaseCard.tsx +87 -0
- package/src/runtime/components/SidebarNav.tsx +237 -0
- package/src/runtime/components/Skeleton.tsx +39 -0
- package/src/runtime/components/ThemeToggle.tsx +26 -0
- package/src/runtime/components/TopNav.tsx +270 -0
- package/src/runtime/components/VersionDropdown.tsx +189 -0
- package/src/runtime/components/markdown/components.ts +280 -0
- package/src/runtime/config.ts +225 -0
- package/src/runtime/content.ts +451 -0
- package/src/runtime/context.tsx +30 -0
- package/src/runtime/data.ts +93 -0
- package/src/runtime/github.ts +226 -0
- package/src/runtime/icons.ts +32 -0
- package/src/runtime/index.ts +153 -0
- package/src/runtime/layouts/DocsLayout.tsx +144 -0
- package/src/runtime/markdown-content.css +996 -0
- package/src/runtime/pages/AbTestPage.tsx +88 -0
- package/src/runtime/pages/AnalyticsPage.tsx +90 -0
- package/src/runtime/pages/ApiDiffPage.tsx +86 -0
- package/src/runtime/pages/ApiEndpointPage.tsx +248 -0
- package/src/runtime/pages/BuilderPage.tsx +150 -0
- package/src/runtime/pages/ChangelogPage.tsx +210 -0
- package/src/runtime/pages/CollectionPage.tsx +140 -0
- package/src/runtime/pages/CommunityPage.tsx +384 -0
- package/src/runtime/pages/CreatePage.tsx +448 -0
- package/src/runtime/pages/DocPage.tsx +193 -0
- package/src/runtime/pages/EditPage.tsx +201 -0
- package/src/runtime/pages/HomePage.tsx +187 -0
- package/src/runtime/pages/IssuesPage.tsx +140 -0
- package/src/runtime/pages/OAuthCallbackPage.tsx +80 -0
- package/src/runtime/pages/PluginsPage.tsx +249 -0
- package/src/runtime/pages/ShowcasePage.tsx +202 -0
- package/src/runtime/pwa.ts +39 -0
- package/src/runtime/router.tsx +192 -0
- package/src/runtime/seo.ts +192 -0
- package/src/runtime/theme.css +175 -0
- package/src/runtime/theme.ts +224 -0
- package/src/runtime/types.ts +217 -0
- package/src/search/index.ts +6 -0
- package/src/seo-optimization/index.ts +4 -0
- package/src/shared/constants/index.ts +26 -0
- package/src/shared/errors/index.ts +195 -0
- package/src/shared/index.ts +27 -0
- package/src/shared/types/brand.ts +14 -0
- package/src/shared/types/client.d.ts +45 -0
- package/src/shared/types/either.ts +38 -0
- package/src/shared/types/index.ts +42 -0
- package/src/shared/types/option.ts +52 -0
- package/src/shared/types/result.ts +81 -0
- package/src/shared/utils/array.ts +97 -0
- package/src/shared/utils/index.ts +46 -0
- package/src/shared/utils/object.ts +47 -0
- package/src/shared/utils/string.ts +74 -0
- package/src/toc-generator/index.ts +1 -0
- package/src/types/js-yaml.d.ts +42 -0
- package/src/worker.ts +462 -0
package/src/worker.ts
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
interface Env {
|
|
2
|
+
ASSETS: { fetch: (req: Request) => Promise<Response> };
|
|
3
|
+
AI: {
|
|
4
|
+
run: (
|
|
5
|
+
model: string,
|
|
6
|
+
input: Record<string, unknown>,
|
|
7
|
+
) => Promise<{ response?: string }>;
|
|
8
|
+
};
|
|
9
|
+
GITHUB_TOKEN?: string;
|
|
10
|
+
GITHUB_CLIENT_ID?: string;
|
|
11
|
+
GITHUB_CLIENT_SECRET?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const GITHUB_API_HEADERS: Record<string, string> = {
|
|
15
|
+
Accept: "application/vnd.github+json",
|
|
16
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
17
|
+
"User-Agent": "create-docs",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function json(data: unknown, status = 200): Response {
|
|
21
|
+
return new Response(JSON.stringify(data), {
|
|
22
|
+
status,
|
|
23
|
+
headers: { "Content-Type": "application/json" },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Prefer the caller's token; fall back to the worker secret. */
|
|
28
|
+
function githubAuth(request: Request, env: Env): string | null {
|
|
29
|
+
return (
|
|
30
|
+
request.headers.get("Authorization") ??
|
|
31
|
+
(env.GITHUB_TOKEN ? `Bearer ${env.GITHUB_TOKEN}` : null)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toBase64(text: string): string {
|
|
36
|
+
const bytes = new TextEncoder().encode(text);
|
|
37
|
+
let bin = "";
|
|
38
|
+
const chunk = 0x8000;
|
|
39
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
40
|
+
bin += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
41
|
+
}
|
|
42
|
+
return btoa(bin);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function handleOAuthStart(request: Request, env: Env): Response {
|
|
46
|
+
if (!env.GITHUB_CLIENT_ID) {
|
|
47
|
+
return json({ error: "GITHUB_CLIENT_ID not configured" }, 503);
|
|
48
|
+
}
|
|
49
|
+
const url = new URL(request.url);
|
|
50
|
+
const redirectUri =
|
|
51
|
+
url.searchParams.get("redirect_uri") ??
|
|
52
|
+
`${url.origin}/auth/github/callback`;
|
|
53
|
+
const state = url.searchParams.get("state") ?? "";
|
|
54
|
+
const scope = url.searchParams.get("scope") ?? "repo";
|
|
55
|
+
const auth = new URL("https://github.com/login/oauth/authorize");
|
|
56
|
+
auth.searchParams.set("client_id", env.GITHUB_CLIENT_ID);
|
|
57
|
+
auth.searchParams.set("redirect_uri", redirectUri);
|
|
58
|
+
auth.searchParams.set("scope", scope);
|
|
59
|
+
if (state) auth.searchParams.set("state", state);
|
|
60
|
+
return json({ url: auth.toString() });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function handleOAuthToken(request: Request, env: Env): Promise<Response> {
|
|
64
|
+
if (request.method !== "POST") {
|
|
65
|
+
return new Response("Method not allowed", { status: 405 });
|
|
66
|
+
}
|
|
67
|
+
if (!env.GITHUB_CLIENT_ID || !env.GITHUB_CLIENT_SECRET) {
|
|
68
|
+
return json({ error: "GitHub OAuth is not configured" }, 503);
|
|
69
|
+
}
|
|
70
|
+
const { code, redirect_uri } = (await request.json().catch(() => ({}))) as {
|
|
71
|
+
code?: string;
|
|
72
|
+
redirect_uri?: string;
|
|
73
|
+
};
|
|
74
|
+
if (!code) return json({ error: "Missing code" }, 400);
|
|
75
|
+
const res = await fetch("https://github.com/login/oauth/access_token", {
|
|
76
|
+
method: "POST",
|
|
77
|
+
headers: {
|
|
78
|
+
Accept: "application/json",
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
"User-Agent": "create-docs",
|
|
81
|
+
},
|
|
82
|
+
body: JSON.stringify({
|
|
83
|
+
client_id: env.GITHUB_CLIENT_ID,
|
|
84
|
+
client_secret: env.GITHUB_CLIENT_SECRET,
|
|
85
|
+
code,
|
|
86
|
+
...(redirect_uri ? { redirect_uri } : {}),
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
const data = (await res.json().catch(() => ({}))) as {
|
|
90
|
+
access_token?: string;
|
|
91
|
+
error?: string;
|
|
92
|
+
error_description?: string;
|
|
93
|
+
};
|
|
94
|
+
if (data.error || !data.access_token) {
|
|
95
|
+
return json(
|
|
96
|
+
{
|
|
97
|
+
error: data.error_description ?? data.error ?? "Token exchange failed",
|
|
98
|
+
},
|
|
99
|
+
400,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
return json({ access_token: data.access_token });
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async function handleDeploy(request: Request): Promise<Response> {
|
|
106
|
+
if (request.method !== "POST") {
|
|
107
|
+
return new Response("Method not allowed", { status: 405 });
|
|
108
|
+
}
|
|
109
|
+
const cfToken = request.headers
|
|
110
|
+
.get("Authorization")
|
|
111
|
+
?.replace(/^Bearer\s+/i, "");
|
|
112
|
+
const {
|
|
113
|
+
accountId,
|
|
114
|
+
projectName,
|
|
115
|
+
owner,
|
|
116
|
+
repo,
|
|
117
|
+
productionBranch = "main",
|
|
118
|
+
} = (await request.json().catch(() => ({}))) as Record<string, string>;
|
|
119
|
+
if (!cfToken) return json({ error: "Missing Cloudflare API token" }, 401);
|
|
120
|
+
if (!accountId || !projectName) {
|
|
121
|
+
return json({ error: "Missing accountId or projectName" }, 400);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const body: Record<string, unknown> = {
|
|
125
|
+
name: projectName,
|
|
126
|
+
production_branch: productionBranch,
|
|
127
|
+
};
|
|
128
|
+
if (owner && repo) {
|
|
129
|
+
body.source = {
|
|
130
|
+
type: "github",
|
|
131
|
+
config: {
|
|
132
|
+
owner,
|
|
133
|
+
repo_name: repo,
|
|
134
|
+
production_branch: productionBranch,
|
|
135
|
+
pr_comments_enabled: true,
|
|
136
|
+
deployments_enabled: true,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const res = await fetch(
|
|
143
|
+
`https://api.cloudflare.com/client/v4/accounts/${accountId}/pages/projects`,
|
|
144
|
+
{
|
|
145
|
+
method: "POST",
|
|
146
|
+
headers: {
|
|
147
|
+
Authorization: `Bearer ${cfToken}`,
|
|
148
|
+
"Content-Type": "application/json",
|
|
149
|
+
},
|
|
150
|
+
body: JSON.stringify(body),
|
|
151
|
+
},
|
|
152
|
+
);
|
|
153
|
+
const data = (await res.json().catch(() => ({}))) as {
|
|
154
|
+
success?: boolean;
|
|
155
|
+
errors?: { message?: string }[];
|
|
156
|
+
result?: { name?: string; subdomain?: string };
|
|
157
|
+
};
|
|
158
|
+
if (!res.ok || data.success === false) {
|
|
159
|
+
return json(
|
|
160
|
+
{
|
|
161
|
+
error: data.errors?.[0]?.message ?? `Cloudflare error ${res.status}`,
|
|
162
|
+
},
|
|
163
|
+
res.ok ? 400 : res.status,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return json({
|
|
167
|
+
ok: true,
|
|
168
|
+
project: data.result?.name ?? projectName,
|
|
169
|
+
url: data.result?.subdomain
|
|
170
|
+
? `https://${data.result.subdomain}`
|
|
171
|
+
: undefined,
|
|
172
|
+
});
|
|
173
|
+
} catch (e) {
|
|
174
|
+
return json(
|
|
175
|
+
{ error: e instanceof Error ? e.message : "Deploy error" },
|
|
176
|
+
502,
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface DocEntry {
|
|
182
|
+
collection: string;
|
|
183
|
+
id: string;
|
|
184
|
+
title: string;
|
|
185
|
+
description: string;
|
|
186
|
+
text: string;
|
|
187
|
+
content: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
let indexCache: { docs: DocEntry[] } | null = null;
|
|
191
|
+
|
|
192
|
+
async function loadIndex(env: Env): Promise<{ docs: DocEntry[] }> {
|
|
193
|
+
if (indexCache) return indexCache;
|
|
194
|
+
const res = await env.ASSETS.fetch(
|
|
195
|
+
new Request("https://assets.local/search-index.json"),
|
|
196
|
+
);
|
|
197
|
+
if (!res.ok) {
|
|
198
|
+
throw new Error("search-index.json not found");
|
|
199
|
+
}
|
|
200
|
+
indexCache = (await res.json()) as { docs: DocEntry[] };
|
|
201
|
+
return indexCache;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
async function handleGitHubProxy(
|
|
205
|
+
request: Request,
|
|
206
|
+
env: Env,
|
|
207
|
+
): Promise<Response> {
|
|
208
|
+
const url = new URL(request.url);
|
|
209
|
+
const path = url.pathname.slice("/api/github".length) + url.search;
|
|
210
|
+
const headers: Record<string, string> = { ...GITHUB_API_HEADERS };
|
|
211
|
+
const auth = githubAuth(request, env);
|
|
212
|
+
if (auth) headers.Authorization = auth;
|
|
213
|
+
const isRead = request.method === "GET" || request.method === "HEAD";
|
|
214
|
+
try {
|
|
215
|
+
const res = await fetch(`https://api.github.com${path}`, {
|
|
216
|
+
method: request.method,
|
|
217
|
+
headers,
|
|
218
|
+
body: isRead ? undefined : request.body,
|
|
219
|
+
});
|
|
220
|
+
return new Response(res.body, {
|
|
221
|
+
status: res.status,
|
|
222
|
+
headers: {
|
|
223
|
+
"Content-Type": res.headers.get("Content-Type") ?? "application/json",
|
|
224
|
+
...(isRead ? { "Cache-Control": "public, max-age=60" } : {}),
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
} catch (e) {
|
|
228
|
+
const message = e instanceof Error ? e.message : "GitHub proxy error";
|
|
229
|
+
return new Response(JSON.stringify({ error: message }), { status: 502 });
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async function handleAi(request: Request, env: Env): Promise<Response> {
|
|
234
|
+
if (request.method !== "POST") {
|
|
235
|
+
return new Response("Method not allowed", { status: 405 });
|
|
236
|
+
}
|
|
237
|
+
const { prompt } = (await request.json().catch(() => ({}))) as {
|
|
238
|
+
prompt?: string;
|
|
239
|
+
};
|
|
240
|
+
if (!prompt) {
|
|
241
|
+
return new Response(JSON.stringify({ error: "Missing prompt" }), {
|
|
242
|
+
status: 400,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
const result = await env.AI.run("@cf/meta/llama-3.1-8b-instruct-fast", {
|
|
247
|
+
prompt,
|
|
248
|
+
});
|
|
249
|
+
return new Response(JSON.stringify({ suggestion: result.response ?? "" }), {
|
|
250
|
+
headers: { "Content-Type": "application/json" },
|
|
251
|
+
});
|
|
252
|
+
} catch (e) {
|
|
253
|
+
const message = e instanceof Error ? e.message : "AI error";
|
|
254
|
+
return new Response(JSON.stringify({ error: message }), { status: 500 });
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
async function handleSave(request: Request, env: Env): Promise<Response> {
|
|
259
|
+
if (request.method !== "POST") {
|
|
260
|
+
return new Response("Method not allowed", { status: 405 });
|
|
261
|
+
}
|
|
262
|
+
const auth = githubAuth(request, env);
|
|
263
|
+
if (!auth) {
|
|
264
|
+
return json({ error: "GitHub credentials not configured" }, 503);
|
|
265
|
+
}
|
|
266
|
+
const {
|
|
267
|
+
owner,
|
|
268
|
+
repo,
|
|
269
|
+
path: filePath,
|
|
270
|
+
content,
|
|
271
|
+
branch = "main",
|
|
272
|
+
message,
|
|
273
|
+
} = (await request.json().catch(() => ({}))) as Record<string, string>;
|
|
274
|
+
if (!owner || !repo || !filePath || !content || !message) {
|
|
275
|
+
return new Response(JSON.stringify({ error: "Missing required fields" }), {
|
|
276
|
+
status: 400,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
const getRes = await fetch(
|
|
282
|
+
`https://api.github.com/repos/${owner}/${repo}/contents/${filePath}?ref=${branch}`,
|
|
283
|
+
{
|
|
284
|
+
headers: { ...GITHUB_API_HEADERS, Authorization: auth },
|
|
285
|
+
},
|
|
286
|
+
);
|
|
287
|
+
const existing = getRes.ok
|
|
288
|
+
? ((await getRes.json()) as { sha: string })
|
|
289
|
+
: null;
|
|
290
|
+
|
|
291
|
+
const body = JSON.stringify({
|
|
292
|
+
message,
|
|
293
|
+
content: toBase64(content),
|
|
294
|
+
branch,
|
|
295
|
+
sha: existing?.sha,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const putRes = await fetch(
|
|
299
|
+
`https://api.github.com/repos/${owner}/${repo}/contents/${filePath}`,
|
|
300
|
+
{
|
|
301
|
+
method: "PUT",
|
|
302
|
+
headers: {
|
|
303
|
+
...GITHUB_API_HEADERS,
|
|
304
|
+
Authorization: auth,
|
|
305
|
+
"Content-Type": "application/json",
|
|
306
|
+
},
|
|
307
|
+
body,
|
|
308
|
+
},
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
if (!putRes.ok) {
|
|
312
|
+
const text = await putRes.text();
|
|
313
|
+
return new Response(JSON.stringify({ error: text }), {
|
|
314
|
+
status: putRes.status,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
return new Response(JSON.stringify({ ok: true }), {
|
|
319
|
+
headers: { "Content-Type": "application/json" },
|
|
320
|
+
});
|
|
321
|
+
} catch (e) {
|
|
322
|
+
const msg = e instanceof Error ? e.message : "Save error";
|
|
323
|
+
return new Response(JSON.stringify({ error: msg }), { status: 500 });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
async function handleMcp(request: Request, env: Env): Promise<Response> {
|
|
328
|
+
if (request.method !== "POST") {
|
|
329
|
+
return new Response("Method not allowed", { status: 405 });
|
|
330
|
+
}
|
|
331
|
+
const body = (await request.json().catch(() => ({}))) as {
|
|
332
|
+
id?: unknown;
|
|
333
|
+
method?: string;
|
|
334
|
+
params?: Record<string, unknown>;
|
|
335
|
+
};
|
|
336
|
+
const { id = null, method, params = {} } = body;
|
|
337
|
+
|
|
338
|
+
const reply = (result: unknown) =>
|
|
339
|
+
new Response(JSON.stringify({ jsonrpc: "2.0", id, result }), {
|
|
340
|
+
headers: { "Content-Type": "application/json" },
|
|
341
|
+
});
|
|
342
|
+
const rpcError = (code: number, message: string) =>
|
|
343
|
+
new Response(
|
|
344
|
+
JSON.stringify({ jsonrpc: "2.0", id, error: { code, message } }),
|
|
345
|
+
{ headers: { "Content-Type": "application/json" } },
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
if (method === "initialize") {
|
|
349
|
+
return reply({
|
|
350
|
+
protocolVersion: "2024-11-05",
|
|
351
|
+
capabilities: { tools: {} },
|
|
352
|
+
serverInfo: { name: "create-docs", version: "0.1.0" },
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (method === "notifications/initialized" || method === "ping") {
|
|
356
|
+
return reply({});
|
|
357
|
+
}
|
|
358
|
+
if (method === "tools/list") {
|
|
359
|
+
return reply({
|
|
360
|
+
tools: [
|
|
361
|
+
{
|
|
362
|
+
name: "search_docs",
|
|
363
|
+
description: "Search documentation content",
|
|
364
|
+
inputSchema: {
|
|
365
|
+
type: "object",
|
|
366
|
+
properties: {
|
|
367
|
+
query: { type: "string", description: "Search query" },
|
|
368
|
+
limit: {
|
|
369
|
+
type: "number",
|
|
370
|
+
description: "Max results",
|
|
371
|
+
default: 5,
|
|
372
|
+
},
|
|
373
|
+
},
|
|
374
|
+
required: ["query"],
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
name: "get_doc",
|
|
379
|
+
description: "Get a document by collection and id",
|
|
380
|
+
inputSchema: {
|
|
381
|
+
type: "object",
|
|
382
|
+
properties: {
|
|
383
|
+
collection: { type: "string", description: "Collection id" },
|
|
384
|
+
id: { type: "string", description: "Document id" },
|
|
385
|
+
},
|
|
386
|
+
required: ["collection", "id"],
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
],
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
if (method === "tools/call") {
|
|
393
|
+
const name = params.name;
|
|
394
|
+
const args = (params.arguments ?? {}) as Record<string, unknown>;
|
|
395
|
+
const { docs } = await loadIndex(env);
|
|
396
|
+
if (name === "search_docs") {
|
|
397
|
+
const q = String(args.query ?? "").toLowerCase();
|
|
398
|
+
const limit = Math.min(Number(args.limit ?? 5), 20);
|
|
399
|
+
const results = docs
|
|
400
|
+
.filter((d) =>
|
|
401
|
+
[d.title, d.description, d.text].join(" ").toLowerCase().includes(q),
|
|
402
|
+
)
|
|
403
|
+
.slice(0, limit)
|
|
404
|
+
.map((d) => ({
|
|
405
|
+
collection: d.collection,
|
|
406
|
+
id: d.id,
|
|
407
|
+
title: d.title,
|
|
408
|
+
description: d.description,
|
|
409
|
+
snippet: d.text.slice(0, 200),
|
|
410
|
+
}));
|
|
411
|
+
return reply({
|
|
412
|
+
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
if (name === "get_doc") {
|
|
416
|
+
const doc = docs.find(
|
|
417
|
+
(d) => d.collection === args.collection && d.id === args.id,
|
|
418
|
+
);
|
|
419
|
+
if (!doc) {
|
|
420
|
+
return rpcError(-32602, "Document not found");
|
|
421
|
+
}
|
|
422
|
+
return reply({
|
|
423
|
+
content: [{ type: "text", text: doc.content }],
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
return rpcError(-32601, "Unknown tool");
|
|
427
|
+
}
|
|
428
|
+
return rpcError(-32601, "Method not found");
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
export default {
|
|
432
|
+
async fetch(request: Request, env: Env) {
|
|
433
|
+
const url = new URL(request.url);
|
|
434
|
+
try {
|
|
435
|
+
if (url.pathname === "/api/ai/suggest") {
|
|
436
|
+
return handleAi(request, env);
|
|
437
|
+
}
|
|
438
|
+
if (url.pathname === "/api/content/save") {
|
|
439
|
+
return handleSave(request, env);
|
|
440
|
+
}
|
|
441
|
+
if (url.pathname === "/api/github/auth") {
|
|
442
|
+
return handleOAuthStart(request, env);
|
|
443
|
+
}
|
|
444
|
+
if (url.pathname === "/api/github/token") {
|
|
445
|
+
return handleOAuthToken(request, env);
|
|
446
|
+
}
|
|
447
|
+
if (url.pathname === "/api/deploy") {
|
|
448
|
+
return handleDeploy(request);
|
|
449
|
+
}
|
|
450
|
+
if (url.pathname.startsWith("/api/github")) {
|
|
451
|
+
return handleGitHubProxy(request, env);
|
|
452
|
+
}
|
|
453
|
+
if (url.pathname === "/api/mcp" || url.pathname === "/mcp") {
|
|
454
|
+
return handleMcp(request, env);
|
|
455
|
+
}
|
|
456
|
+
return await env.ASSETS.fetch(request);
|
|
457
|
+
} catch (e) {
|
|
458
|
+
const message = e instanceof Error ? e.message : "Unknown error";
|
|
459
|
+
return new Response(`Not found: ${message}`, { status: 404 });
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
};
|