@stainless-api/docs 0.1.0-beta.1 → 0.1.0-beta.100

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.
Files changed (158) hide show
  1. package/CHANGELOG.md +917 -0
  2. package/eslint-suppressions.json +27 -0
  3. package/locals.d.ts +17 -0
  4. package/package.json +50 -40
  5. package/playground-virtual-modules.d.ts +96 -0
  6. package/plugin/assets/languages/cli.svg +14 -0
  7. package/plugin/assets/languages/csharp.svg +1 -0
  8. package/plugin/assets/languages/php.svg +4 -0
  9. package/plugin/buildAlgoliaIndex.ts +40 -39
  10. package/plugin/components/MethodDescription.tsx +54 -0
  11. package/plugin/components/RequestBuilder/ParamEditor.tsx +55 -0
  12. package/plugin/components/RequestBuilder/SnippetStainlessIsland.tsx +107 -0
  13. package/plugin/components/RequestBuilder/index.tsx +37 -0
  14. package/plugin/components/RequestBuilder/props.ts +9 -0
  15. package/plugin/components/RequestBuilder/spec-helpers.ts +47 -0
  16. package/plugin/components/RequestBuilder/styles.css +67 -0
  17. package/plugin/components/SDKSelect.astro +18 -105
  18. package/plugin/components/SnippetCode.tsx +111 -66
  19. package/plugin/components/StainlessIslands.tsx +126 -0
  20. package/plugin/components/search/SearchAlgolia.astro +45 -35
  21. package/plugin/components/search/SearchIsland.tsx +47 -29
  22. package/plugin/generateAPIReferenceLink.ts +2 -2
  23. package/plugin/globalJs/ai-dropdown-options.ts +243 -0
  24. package/plugin/globalJs/code-snippets.ts +40 -11
  25. package/plugin/globalJs/copy.ts +95 -17
  26. package/plugin/globalJs/create-playground.shim.ts +3 -0
  27. package/plugin/globalJs/method-descriptions.ts +33 -0
  28. package/plugin/globalJs/navigation.ts +12 -33
  29. package/plugin/globalJs/playground-data.shim.ts +1 -0
  30. package/plugin/globalJs/playground-data.ts +14 -0
  31. package/plugin/helpers/generateDocsRoutes.ts +59 -0
  32. package/plugin/helpers/getPageLoadEvent.ts +1 -1
  33. package/plugin/helpers/multiSpec.ts +8 -0
  34. package/plugin/index.ts +299 -117
  35. package/plugin/languages.ts +8 -2
  36. package/plugin/loadPluginConfig.ts +254 -102
  37. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +1 -1
  38. package/plugin/react/Routing.tsx +210 -140
  39. package/plugin/referencePlaceholderUtils.ts +18 -15
  40. package/plugin/replaceSidebarPlaceholderMiddleware.ts +40 -32
  41. package/plugin/routes/Docs.astro +70 -119
  42. package/plugin/routes/DocsStatic.astro +6 -5
  43. package/plugin/routes/Overview.astro +37 -27
  44. package/plugin/routes/markdown.ts +13 -12
  45. package/plugin/{cms → sidebar-utils}/sidebar-builder.ts +49 -60
  46. package/plugin/specs/FileCache.ts +99 -0
  47. package/plugin/specs/fetchSpecSSR.ts +27 -0
  48. package/plugin/specs/generateSpec.ts +112 -0
  49. package/plugin/specs/index.ts +132 -0
  50. package/plugin/specs/inputResolver.ts +146 -0
  51. package/plugin/{cms → specs}/worker.ts +82 -5
  52. package/plugin/vendor/preview.worker.docs.js +22406 -17955
  53. package/plugin/vendor/templates/cli.md +1 -0
  54. package/plugin/vendor/templates/go.md +4 -2
  55. package/plugin/vendor/templates/java.md +3 -1
  56. package/plugin/vendor/templates/kotlin.md +3 -1
  57. package/plugin/vendor/templates/node.md +4 -2
  58. package/plugin/vendor/templates/python.md +4 -2
  59. package/plugin/vendor/templates/ruby.md +4 -2
  60. package/plugin/vendor/templates/terraform.md +1 -1
  61. package/plugin/vendor/templates/typescript.md +3 -1
  62. package/resolveSrcFile.ts +10 -0
  63. package/scripts/vendor_deps.ts +5 -5
  64. package/shared/getProsePages.ts +42 -0
  65. package/shared/getSharedLogger.ts +15 -0
  66. package/shared/terminalUtils.ts +3 -0
  67. package/shared/virtualModule.ts +54 -1
  68. package/src/content.config.ts +9 -0
  69. package/stl-docs/components/AIDropdown.tsx +63 -0
  70. package/stl-docs/components/AiChatIsland.tsx +14 -0
  71. package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +2 -2
  72. package/stl-docs/components/Head.astro +20 -0
  73. package/stl-docs/components/Header.astro +7 -9
  74. package/stl-docs/components/PageFrame.astro +18 -0
  75. package/stl-docs/components/PageTitle.astro +82 -0
  76. package/stl-docs/components/TableOfContents.astro +34 -0
  77. package/stl-docs/components/ThemeProvider.astro +36 -0
  78. package/stl-docs/components/ThemeSelect.astro +84 -144
  79. package/stl-docs/components/content-panel/ContentPanel.astro +16 -46
  80. package/stl-docs/components/headers/DefaultHeader.astro +1 -1
  81. package/stl-docs/components/headers/HeaderLinks.astro +1 -1
  82. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +17 -1
  83. package/stl-docs/components/headers/StackedHeader.astro +29 -24
  84. package/stl-docs/components/icons/chat-gpt.tsx +17 -0
  85. package/stl-docs/components/icons/claude.tsx +10 -0
  86. package/stl-docs/components/icons/cursor.tsx +10 -0
  87. package/stl-docs/components/icons/gemini.tsx +19 -0
  88. package/stl-docs/components/icons/markdown.tsx +10 -0
  89. package/stl-docs/components/index.ts +1 -0
  90. package/stl-docs/components/mintlify-compat/Accordion.astro +7 -38
  91. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +9 -23
  92. package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
  93. package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
  94. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +10 -3
  95. package/stl-docs/components/mintlify-compat/callouts/Check.astro +7 -3
  96. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +7 -3
  97. package/stl-docs/components/mintlify-compat/callouts/Info.astro +7 -3
  98. package/stl-docs/components/mintlify-compat/callouts/Note.astro +7 -3
  99. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +7 -3
  100. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +7 -3
  101. package/stl-docs/components/mintlify-compat/card.css +33 -35
  102. package/stl-docs/components/mintlify-compat/index.ts +2 -4
  103. package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -75
  104. package/stl-docs/components/nav-tabs/NavTabs.astro +78 -80
  105. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -8
  106. package/stl-docs/components/nav-tabs/buildNavLinks.ts +4 -3
  107. package/stl-docs/components/pagination/HomeLink.astro +10 -0
  108. package/stl-docs/components/pagination/Pagination.astro +175 -0
  109. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
  110. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
  111. package/stl-docs/components/pagination/util.ts +71 -0
  112. package/stl-docs/components/scripts.ts +1 -0
  113. package/stl-docs/components/sidebars/BaseSidebar.astro +87 -0
  114. package/stl-docs/components/sidebars/SDKSelectSidebar.astro +8 -0
  115. package/stl-docs/components/sidebars/SidebarWithComponents.tsx +10 -0
  116. package/stl-docs/components/sidebars/convertAstroSidebarToStl.tsx +62 -0
  117. package/stl-docs/disableCalloutSyntax.ts +36 -0
  118. package/stl-docs/fonts.ts +186 -0
  119. package/stl-docs/index.ts +159 -43
  120. package/stl-docs/loadStlDocsConfig.ts +60 -9
  121. package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +61 -0
  122. package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +41 -0
  123. package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
  124. package/stl-docs/proseSearchIndexing.ts +606 -0
  125. package/stl-docs/tabsMiddleware.ts +14 -5
  126. package/styles/code.css +133 -136
  127. package/styles/links.css +11 -48
  128. package/styles/method-descriptions.css +36 -0
  129. package/styles/overrides.css +49 -57
  130. package/styles/page.css +100 -59
  131. package/styles/sdk_select.css +9 -7
  132. package/styles/search.css +57 -69
  133. package/styles/sidebar.css +26 -156
  134. package/styles/{variables.css → sl-variables.css} +3 -2
  135. package/styles/stldocs-variables.css +6 -0
  136. package/styles/toc.css +41 -34
  137. package/theme.css +13 -3
  138. package/tsconfig.json +2 -5
  139. package/virtual-module.d.ts +65 -7
  140. package/components/variables.css +0 -139
  141. package/plugin/cms/client.ts +0 -62
  142. package/plugin/cms/server.ts +0 -268
  143. package/plugin/globalJs/ai-dropdown.ts +0 -57
  144. package/stl-docs/components/APIReferenceAIDropdown.tsx +0 -86
  145. package/stl-docs/components/Sidebar.astro +0 -11
  146. package/stl-docs/components/content-panel/ProseAIDropdown.tsx +0 -64
  147. package/stl-docs/components/mintlify-compat/Step.astro +0 -58
  148. package/stl-docs/components/mintlify-compat/Steps.astro +0 -17
  149. package/styles/fonts.css +0 -68
  150. /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
  151. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
  152. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
  153. /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
  154. /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
  155. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
  156. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
  157. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
  158. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
package/tsconfig.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "astro/tsconfigs/strict",
2
+ "extends": "../../tsconfig.base.json",
3
3
  "include": [
4
4
  ".astro/*",
5
5
  "node_modules/@astrojs/starlight/**/*.d.ts",
@@ -7,11 +7,8 @@
7
7
  ".stl-docs/**/*",
8
8
  "./plugin/**/*"
9
9
  ],
10
- "exclude": ["dist"],
10
+ "exclude": ["dist", "**/preview.worker.docs.js"],
11
11
  "compilerOptions": {
12
- "paths": {
13
- "~/*": ["../../../stainless/legacy-dir-root/*"]
14
- },
15
12
  "jsx": "react-jsx",
16
13
  "jsxImportSource": "react"
17
14
  }
@@ -1,12 +1,11 @@
1
1
  declare module 'virtual:stl-starlight-virtual-module' {
2
2
  import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
3
- import type { PropertySettingsType } from '@stainless-api/docs-ui/src/contexts';
3
+ import type { PropertySettingsType } from '@stainless-api/docs-ui/contexts';
4
4
  import type { StlStarlightMiddleware } from '@stainless-api/docs/plugin/MiddlewareTypes';
5
- import type { StainlessStarlightUserConfig } from './plugin/loadPluginConfig';
5
+ import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
6
6
 
7
- export const BASE_PATH: string;
8
- export const CMS_PORT: number;
9
- export const EXCLUDE_LANGUAGES: string[];
7
+ export const RESOLVED_API_REFERENCE_PATH: string;
8
+ export const EXCLUDE_LANGUAGES: DocsLanguage[];
10
9
  export const DEFAULT_LANGUAGE: string;
11
10
  export const BREADCRUMB_CONFIG: {
12
11
  includeCurrentPage?: boolean;
@@ -15,14 +14,19 @@ declare module 'virtual:stl-starlight-virtual-module' {
15
14
  export const HIGHLIGHT_THEMES: CreateShikiHighlighterOptions['themes'];
16
15
  export const CONTENT_PANEL_LAYOUT: 'double-pane' | 'single-pane';
17
16
  export const EXPERIMENTAL_COLLAPSIBLE_SNIPPETS: boolean | undefined;
17
+ export const EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS: boolean | undefined;
18
+ export const EXPERIMENTAL_PLAYGROUNDS: boolean | undefined;
19
+ export const EXPERIMENTAL_REQUEST_BUILDER: boolean | undefined;
18
20
  export const PROPERTY_SETTINGS: PropertySettingsType;
19
21
  export const MIDDLEWARE: StlStarlightMiddleware;
20
- export const SEARCH: StainlessStarlightUserConfig['search'];
22
+ export const ENABLE_CONTEXT_MENU: boolean;
23
+ export const STAINLESS_PROJECT: string | undefined;
21
24
  }
22
25
 
23
- declare module 'virtual:stl-stl-starlight-virtual-module' {
26
+ declare module 'virtual:stl-docs-virtual-module' {
24
27
  import type { ButtonVariant } from '@stainless-api/ui-primitives';
25
28
  import type { AnchorHTMLAttributes } from 'react';
29
+ import { FontPreloadFilter } from 'astro:assets';
26
30
 
27
31
  type Tab = {
28
32
  label: string;
@@ -30,6 +34,11 @@ declare module 'virtual:stl-stl-starlight-virtual-module' {
30
34
  hidden?: boolean;
31
35
  };
32
36
 
37
+ type FontConfig = {
38
+ cssVariable: string;
39
+ preload?: FontPreloadFilter;
40
+ };
41
+
33
42
  export const HEADER_LINKS: {
34
43
  label: string;
35
44
  link: string;
@@ -40,4 +49,53 @@ declare module 'virtual:stl-stl-starlight-virtual-module' {
40
49
  export const SPLIT_TABS_ENABLED: boolean;
41
50
  export const HEADER_LAYOUT: 'default' | 'stacked';
42
51
  export const ENABLE_CLIENT_ROUTER: boolean;
52
+ export const API_REFERENCE_BASE_PATH: string;
53
+ export const ENABLE_PROSE_MARKDOWN_RENDERING: boolean;
54
+ export const ENABLE_CONTEXT_MENU: boolean;
55
+ export const RENDER_PAGE_DESCRIPTIONS: boolean;
56
+ export const LINK_GROUP_TITLES_TO_OVERVIEW_PAGES: boolean;
57
+ export const FONTS: {
58
+ primary?: FontConfig;
59
+ heading?: FontConfig;
60
+ mono?: FontConfig;
61
+ additional?: FontConfig[];
62
+ };
63
+ }
64
+
65
+ declare module 'virtual:stl-docs/components/AiChat.tsx' {
66
+ const AiChatComponent:
67
+ | import('react').ComponentType<{
68
+ projectId: string;
69
+ language: import('@stainless-api/docs-ui/routing').DocsLanguage | undefined;
70
+ siteTitle: string | undefined;
71
+ }>
72
+ | null;
73
+ export default AiChatComponent;
74
+ export const STAINLESS_PROJECT: string | undefined;
75
+ }
76
+
77
+ declare module 'virtual:stainless-apis-manifest' {
78
+ import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
79
+
80
+ export type APIManifestEntry = {
81
+ languages: {
82
+ sdkJSONFilePath: string;
83
+ language: DocsLanguage;
84
+ }[];
85
+ };
86
+
87
+ export const api: APIManifestEntry;
88
+ }
89
+
90
+ declare module 'virtual:stl-starlight-reference-sidebars' {
91
+ import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
92
+ import type { StarlightRouteData } from '@astrojs/starlight/route-data';
93
+
94
+ export type GeneratedSidebarDef = {
95
+ id: number;
96
+ language: DocsLanguage;
97
+ entries: StarlightRouteData['sidebar'];
98
+ };
99
+
100
+ export const sidebars: GeneratedSidebarDef[];
43
101
  }
@@ -1,139 +0,0 @@
1
- :root {
2
- --sl-font: 'Geist', system-ui, sans-serif;
3
- --sl-font-mono: 'Geist Mono', ui-monospace, monospace;
4
-
5
- --stldocs-font: var(--sl-font, system-ui, sans-serif);
6
- --stldocs-font-mono: var(--sl-font-mono, ui-monospace, monospace);
7
-
8
- --stldocs-color-white: var(--sl-color-white);
9
- --stldocs-color-gray-1: var(--sl-color-gray-1);
10
- --stldocs-color-gray-2: var(--sl-color-gray-2);
11
- --stldocs-color-gray-3: var(--sl-color-gray-3);
12
- --stldocs-color-gray-4: var(--sl-color-gray-4);
13
- --stldocs-color-gray-5: var(--sl-color-gray-5);
14
- --stldocs-color-gray-6: var(--sl-color-gray-6);
15
- --stldocs-color-gray-7: var(--sl-color-gray-7);
16
- --stldocs-color-gray-8: var(--sl-color-gray-8);
17
-
18
- --stldocs-color-accent-low: var(--sl-color-accent-low);
19
- --stldocs-color-accent-high: var(--sl-color-accent-high);
20
- --stldocs-color-accent: var(--sl-color-accent);
21
- --stldocs-color-red: var(--sl-color-red);
22
-
23
- --stldocs-color-text: var(--sl-color-text);
24
- --stldocs-color-text-accent: var(--sl-color-text-accent);
25
- --stldocs-color-text-invert: var(--sl-color-text-invert);
26
- --stldocs-color-text-secondary: var(--sl-color-text-secondary);
27
- --stldocs-color-text-tertiary: var(--sl-color-text-tertiary);
28
-
29
- --stldocs-color-bg: var(--sl-color-bg);
30
- --stldocs-color-bg-nav: var(--sl-color-bg-nav);
31
- --stldocs-color-bg-ui: var(--sl-color-bg-ui);
32
-
33
- --stldocs-color-bg-inline-code: var(--sl-color-bg-inline-code);
34
- --stldocs-color-bg-accent: var(--sl-color-bg-accent);
35
- --stldocs-color-hairline: var(--sl-color-hairline);
36
- --stldocs-color-hairline-shade: var(--sl-color-hairline-shade);
37
- --stldocs-color-hairline-light: var(--sl-color-hairline-light);
38
-
39
- --stldocs-badge-default-text: var(--sl-badge-default-text);
40
- --stldocs-color-bg-inline-code-dark: var(--sl-color-bg-inline-code-dark);
41
-
42
- --stldocs-font-size-h1: var(--sl-text-h1);
43
- --stldocs-font-size-h2: var(--sl-text-h2);
44
- --stldocs-font-size-h3: var(--sl-text-h3);
45
- --stldocs-font-size-h4: var(--sl-text-h4);
46
- --stldocs-font-size-h5: var(--sl-text-h5);
47
-
48
- --stlodcs-font-size-body: var(--sl-text-body);
49
- --stldocs-font-size-small: var(--sl-text-body-sm);
50
- --stldocs-font-size-code: var(--sl-text-code);
51
-
52
- --stldocs-content-width: var(--sl-content-width);
53
- --stldocs-content-padding: var(--sl-content-pad-x);
54
-
55
- --stldocs-color-http-get-bg: var(--sl-color-green-low);
56
- --stldocs-color-http-get: var(--sl-color-green);
57
- --stldocs-color-http-put-bg: var(--sl-color-orange-low);
58
- --stldocs-color-http-put: var(--sl-color-orange);
59
- --stldocs-color-http-post-bg: var(--sl-color-blue-low);
60
- --stldocs-color-http-post: var(--sl-color-blue);
61
- --stldocs-color-http-delete-bg: var(--sl-color-red-low);
62
- --stldocs-color-http-delete: var(--sl-color-red);
63
-
64
- --stldocs-syntax-color-red: var(--sl-color-red);
65
- --stldocs-syntax-color-green: var(--sl-color-green);
66
- --stldocs-syntax-color-blue: var(--sl-color-blue);
67
- --stldocs-syntax-color-orange: var(--sl-color-orange);
68
- --stldocs-syntax-color-teal: var(--sl-color-teal);
69
- --stldocs-syntax-color-magenta: var(--sl-color-magenta);
70
- --stldocs-syntax-color-purple: var(--sl-color-purple);
71
-
72
- --stldocs-color-backdrop-overlay: var(--sl-color-backdrop-overlay);
73
- --stldocs-expander-margin-shift: 24px;
74
- --stldocs-expander-right-margin: 8px;
75
- --stldocs-font-size-body: 14px;
76
- --stldocs-font-size-body-xs: 12px;
77
-
78
- /* UI Overrides */
79
- --stl-ui-button-border-radius: var(--sl-button-border-radius);
80
- --stl-ui-text-body: var(--sl-text-sm);
81
- --stl-ui-font-family: var(--sl-font);
82
- --stl-ui-button-size: var(--sl-button-size);
83
-
84
- --stl-ui-color-accent-low: var(--sl-color-accent-low);
85
- --stl-ui-color-accent: var(--sl-color-accent);
86
- --stl-ui-color-accent-high: var(--sl-color-accent-high);
87
-
88
- --stl-ui-color-text: var(--sl-color-text);
89
- --stl-ui-color-text-secondary: var(--sl-color-text-secondary);
90
- --stl-ui-color-text-tertiary: var(--sl-color-text-tertiary);
91
- --stl-ui-color-text-invert: var(--sl-color-text-invert);
92
- --stl-ui-color-text-accent: var(--sl-color-text-accent);
93
-
94
- --stl-ui-color-bg: var(--sl-color-bg);
95
- --stl-ui-color-bg-ui: var(--sl-color-bg-ui);
96
- --stl-ui-color-bg-inline-code: var(--sl-color-bg-inline-code);
97
-
98
- --stl-ui-color-hairline-light: var(--sl-color-hairline-light);
99
- --stl-ui-color-hairline: var(--sl-color-hairline);
100
- --stl-ui-color-hairline-shade: var(--sl-color-hairline-shade);
101
- }
102
-
103
- /* These are the theme overrides - we need to come up with a good way to do this in starlight */
104
- :root {
105
- /*
106
- tmp remove the theme color in favor of the Shiki default theme background
107
- commented out values are the original values in case we want them again
108
- */
109
- /* --stldocs-color-snippet-box-bg: #272727; */
110
- --stldocs-color-snippet-box-bg: #1f1f1f;
111
- /* --stldocs-color-snippet-title-bg: #161616; */
112
- --stldocs-color-snippet-title-bg: #24292f;
113
- --stldocs-color-snippet-title-muted: #8b8b8b;
114
- --stldocs-color-snippet-title-bright: #ffffff;
115
- --stldocs-color-snippet-code-bg: #1d1d1d;
116
-
117
- --stldocs-title-padding-y: 2.5rem;
118
-
119
- --stldocs-z-index-theme-select: 1000;
120
- --stldocs-button-border-radius: var(--sl-button-border-radius);
121
- --stldocs-button-size: var(--sl-button-size);
122
- --stldocs-button-padding-x: var(--sl-button-padding-x);
123
- --stldocs-button-padding-y: var(--sl-button-padding-y);
124
-
125
- --sl-content-pad-x: 1rem;
126
- }
127
-
128
- :root[data-theme='light'] {
129
- --stldocs-color-snippet-box-bg: #eeeeee;
130
- /*
131
- tmp remove the theme color in favor of the Shiki default theme background
132
- commented out value is the original value in case we want it again
133
- */
134
- /* --stldocs-color-snippet-title-bg: #2a2a2a; */
135
- --stldocs-color-snippet-title-bg: #24292f;
136
- --stldocs-color-snippet-title-muted: #959595;
137
- --stldocs-color-snippet-title-bright: #000;
138
- --stldocs-color-snippet-code-bg: #383838;
139
- }
@@ -1,62 +0,0 @@
1
- import { CMS_PORT } from 'virtual:stl-starlight-virtual-module';
2
- import type { SpecResp } from './server';
3
- import type { StarlightRouteData } from '@astrojs/starlight/route-data';
4
- import type { BuildSidebarParams } from './sidebar-builder';
5
-
6
- const SERVER_URL = `http://localhost:${CMS_PORT}`;
7
-
8
- async function makeRequest<T>(method: 'POST' | 'GET', endpoint: string, body?: any) {
9
- const response = await fetch(`${SERVER_URL}${endpoint}`, {
10
- method,
11
- headers: {
12
- 'Content-Type': 'application/json',
13
- },
14
- body: body ? JSON.stringify(body) : undefined,
15
- });
16
- return response.json() as T;
17
- }
18
-
19
- class Client {
20
- private specCache: SpecResp | null = null;
21
- private clientId: string;
22
-
23
- get id() {
24
- return this.clientId;
25
- }
26
-
27
- async buildSidebar(params: BuildSidebarParams & { sidebarId: number }) {
28
- const response = await makeRequest<{ data: StarlightRouteData['sidebar'] }>(
29
- 'POST',
30
- '/build_sidebar',
31
- params,
32
- );
33
- return response.data;
34
- }
35
-
36
- async getSpec() {
37
- const cached = this.specCache;
38
-
39
- const response = await makeRequest<SpecResp>('POST', '/retrieve_spec', {
40
- currentId: cached?.id,
41
- });
42
-
43
- if (response.data === null) {
44
- if (!cached) {
45
- throw new Error('Cache should not be null');
46
- }
47
- if (cached.data === null) {
48
- throw new Error('Cached spec should not be null');
49
- }
50
- return cached.data;
51
- }
52
- // console.log("invalidating spec cache", this.clientId);
53
- this.specCache = response;
54
- return response.data;
55
- }
56
-
57
- constructor() {
58
- this.clientId = crypto.randomUUID();
59
- }
60
- }
61
-
62
- export const cmsClient = new Client();
@@ -1,268 +0,0 @@
1
- import { createServer, IncomingMessage } from 'http';
2
- import { readFile } from 'fs/promises';
3
-
4
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
5
- import { createSDKJSON, parseInputs, transformOAS } from './worker';
6
- import { Languages, parseRoute, type DocsLanguage } from '@stainless-api/docs-ui/src/routing';
7
- import Stainless from '@stainless-api/sdk';
8
-
9
- import {
10
- toStarlightSidebar,
11
- type GeneratedSidebarConfig,
12
- SidebarConfigItemsBuilder,
13
- } from './sidebar-builder';
14
- import type { VersionUserConfig } from '../loadPluginConfig';
15
-
16
- export type InputFilePaths = {
17
- oasPath?: string;
18
- configPath?: string;
19
- };
20
-
21
- async function versionInfo(project: string, apiKey: string) {
22
- const data = await fetch(`https://api.stainless.com/api/projects/${project}/package-versions`, {
23
- headers: { Authorization: `Bearer ${apiKey}` },
24
- });
25
-
26
- const content = await data.text();
27
- return JSON.parse(content);
28
- }
29
-
30
- async function loadSpec({
31
- apiKey,
32
- devPaths,
33
- version,
34
- }: {
35
- apiKey: string;
36
- devPaths: InputFilePaths;
37
- version: VersionUserConfig;
38
- }) {
39
- let oasStr: string;
40
- let configStr: string;
41
- let versions: Record<DocsLanguage, string> | undefined;
42
-
43
- if (devPaths.oasPath && devPaths.configPath) {
44
- [oasStr, configStr] = await Promise.all([
45
- readFile(devPaths.oasPath, 'utf-8'),
46
- readFile(devPaths.configPath, 'utf-8'),
47
- ]);
48
- } else {
49
- const client = new Stainless({ apiKey });
50
- const configs = await client.projects.configs.retrieve({
51
- project: version.stainlessProject,
52
- branch: version.branch,
53
- include: 'openapi',
54
- });
55
-
56
- versions = await versionInfo(version.stainlessProject, apiKey);
57
-
58
- const configYML = Object.values(configs)[0] as { content: any };
59
- const oasJson = Object.values(configs)[1] as { content: any };
60
- oasStr = oasJson['content'];
61
- configStr = configYML['content'];
62
- }
63
-
64
- const { oas, config } = await parseInputs({
65
- oas: oasStr,
66
- config: configStr,
67
- });
68
-
69
- const transformedOAS = await transformOAS({ oas, config });
70
-
71
- const languages =
72
- config.docs?.languages ??
73
- (Object.entries(config.targets)
74
- // @ts-expect-error we don't have the actual Stainless config type here
75
- .filter(([name, target]) => Languages.includes(name) && !target.skip)
76
- .map(([name]) => name) as SDKJSON.SpecLanguage[]);
77
-
78
- const sdkJson = await createSDKJSON({
79
- oas: transformedOAS,
80
- config,
81
- languages,
82
- });
83
-
84
- if (versions) {
85
- for (const [lang, version] of Object.entries(versions)) {
86
- const meta = sdkJson.metadata[lang as DocsLanguage];
87
- if (meta?.version) meta.version = version;
88
- }
89
- }
90
-
91
- const id = crypto.randomUUID();
92
-
93
- return {
94
- data: sdkJson,
95
- id,
96
- };
97
- }
98
-
99
- class Spec {
100
- private specPromise: Promise<{ id: string; data: SDKJSON.Spec }>;
101
- private devPaths: InputFilePaths;
102
- private apiKey: string;
103
- private version: VersionUserConfig;
104
-
105
- reload() {
106
- this.specPromise = loadSpec({
107
- apiKey: this.apiKey,
108
- devPaths: this.devPaths,
109
- version: this.version,
110
- });
111
- }
112
-
113
- async forceGetSpec() {
114
- const spec = await this.specPromise;
115
- return spec;
116
- }
117
-
118
- async getSpec(currentId: string | undefined | null) {
119
- const spec = await this.specPromise;
120
-
121
- if (currentId === spec.id) {
122
- return {
123
- id: spec.id,
124
- data: null,
125
- };
126
- }
127
-
128
- return spec;
129
- }
130
-
131
- constructor(apiKey: string, version: VersionUserConfig, devPaths: InputFilePaths) {
132
- this.specPromise = loadSpec({
133
- apiKey,
134
- devPaths,
135
- version,
136
- });
137
- this.devPaths = devPaths;
138
- this.apiKey = apiKey;
139
- this.version = version;
140
- }
141
- }
142
-
143
- export type SpecResp = Awaited<ReturnType<Spec['getSpec']>>;
144
-
145
- // will be necessary once we add POST methods
146
- function readJsonBody(req: IncomingMessage): Promise<any> {
147
- return new Promise((resolve, reject) => {
148
- let body = '';
149
- req.on('data', (chunk) => {
150
- body += chunk.toString();
151
- });
152
- req.on('end', () => {
153
- try {
154
- const data = JSON.parse(body);
155
- resolve(data);
156
- } catch (error) {
157
- reject(error);
158
- }
159
- });
160
- });
161
- }
162
-
163
- export function startDevServer({
164
- port,
165
- version,
166
- devPaths,
167
- apiKey,
168
- getGeneratedSidebarConfig,
169
- }: {
170
- port: number;
171
- version: VersionUserConfig;
172
- devPaths: InputFilePaths;
173
- apiKey: string;
174
- getGeneratedSidebarConfig: (id: number) => GeneratedSidebarConfig | null;
175
- }) {
176
- const spec = new Spec(apiKey, version, devPaths);
177
-
178
- const server = createServer(async (req, res) => {
179
- // Add CORS headers
180
- res.setHeader('Access-Control-Allow-Origin', '*');
181
- res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
182
- res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
183
-
184
- // Handle preflight requests
185
- if (req.method === 'OPTIONS') {
186
- res.writeHead(204);
187
- res.end();
188
- return;
189
- }
190
-
191
- function respond(code: number, body: any) {
192
- res.setHeader('Content-Type', 'application/json');
193
- res.writeHead(code);
194
- res.end(JSON.stringify(body));
195
- }
196
-
197
- try {
198
- if (req.method === 'POST' && req.url === '/retrieve_spec') {
199
- const body = await readJsonBody(req);
200
-
201
- const currentSpec = await spec.getSpec(body.currentId);
202
-
203
- return respond(200, currentSpec);
204
- }
205
-
206
- if (req.method === 'POST' && req.url === '/build_sidebar') {
207
- const currentSpec = await spec.forceGetSpec();
208
- const body = await readJsonBody(req);
209
- const sidebarId: number = body.sidebarId;
210
-
211
- const sidebarConfig = getGeneratedSidebarConfig(sidebarId);
212
-
213
- const sidebarGenerateOptions = sidebarConfig?.options;
214
-
215
- const { stainlessPath: currentStainlessPath, language } = parseRoute(body.basePath, body.currentSlug);
216
-
217
- const configItemsBuilder = new SidebarConfigItemsBuilder(
218
- currentSpec.data,
219
- language,
220
- sidebarGenerateOptions,
221
- );
222
-
223
- let userSidebarConfig = configItemsBuilder.generateItems();
224
-
225
- if (sidebarConfig && sidebarConfig.transformFn) {
226
- const transformedSidebarConfig = sidebarConfig.transformFn(userSidebarConfig, language);
227
- // the user may not have returned, but they may have mutated the config in place
228
- // if they did return, we use that
229
- if (transformedSidebarConfig) {
230
- userSidebarConfig = transformedSidebarConfig;
231
- }
232
- }
233
-
234
- const starlightSidebar = toStarlightSidebar({
235
- basePath: body.basePath,
236
- currentSlug: body.currentSlug,
237
- spec: currentSpec.data,
238
- entries: userSidebarConfig,
239
- currentStainlessPath,
240
- currentLanguage: language,
241
- });
242
-
243
- return respond(200, { data: starlightSidebar });
244
- }
245
-
246
- return respond(404, { message: 'Not found' });
247
- } catch (e) {
248
- return respond(500, { message: 'Unexpected error', error: e });
249
- }
250
- });
251
-
252
- server.listen(port, () => {
253
- console.log(`Server is running on port ${port}`);
254
- });
255
-
256
- return {
257
- invalidate: () => {
258
- spec.reload();
259
- },
260
- destroy: function destroy() {
261
- return new Promise<void>((resolve) => {
262
- server.close(() => {
263
- resolve();
264
- });
265
- });
266
- },
267
- };
268
- }
@@ -1,57 +0,0 @@
1
- export const copyCurrentPageAsMarkdown = async () => {
2
- const currentUrl = new URL(window.location.href);
3
- const markdownUrl = `${currentUrl.origin}${currentUrl.pathname}.md`;
4
-
5
- try {
6
- const response = await fetch(markdownUrl);
7
- if (!response.ok) {
8
- throw new Error('Network response was not ok');
9
- }
10
- const markdown = await response.text();
11
- await navigator.clipboard.writeText(markdown);
12
- console.log('Markdown copied to clipboard');
13
- } catch (error) {
14
- console.error('There has been a problem with your fetch operation:', error);
15
- }
16
- };
17
-
18
- export function onSelectAIOption(value: string, makeMarkdownLink: boolean = true) {
19
- if (value === 'copy-markdown') {
20
- copyCurrentPageAsMarkdown();
21
- }
22
- if (value === 'view-as-markdown') {
23
- const currentUrl = new URL(window.location.href);
24
- const markdownUrl = `${currentUrl.origin}${currentUrl.pathname}.md`;
25
- window.open(markdownUrl, '_blank');
26
- }
27
-
28
- if (value === 'chat-gpt') {
29
- const currentUrl = new URL(window.location.href);
30
- const llmUrl = makeMarkdownLink ? `${currentUrl.origin}${currentUrl.pathname}.md` : currentUrl.href;
31
-
32
- const prompt = `Read from ${llmUrl} so I can ask questions about it.`;
33
-
34
- const chatGptUrl = `https://chatgpt.com/?hints=search&prompt=${encodeURIComponent(prompt)}`;
35
- window.open(chatGptUrl, '_blank');
36
- }
37
-
38
- if (value === 'claude') {
39
- const currentUrl = new URL(window.location.href);
40
- const llmUrl = makeMarkdownLink ? `${currentUrl.origin}${currentUrl.pathname}.md` : currentUrl.href;
41
-
42
- const prompt = `Read from ${llmUrl} so I can ask questions about it.`;
43
-
44
- const claudeUrl = `https://claude.ai/new?q=${encodeURIComponent(prompt)}`;
45
- window.open(claudeUrl, '_blank');
46
- }
47
-
48
- if (value === 'cursor') {
49
- const currentUrl = new URL(window.location.href);
50
- const llmUrl = makeMarkdownLink ? `${currentUrl.origin}${currentUrl.pathname}.md` : currentUrl.href;
51
-
52
- const prompt = `Read from ${llmUrl} so I can ask questions about it.`;
53
-
54
- const cursorUrl = `https://www.cursor.so/?prompt=${encodeURIComponent(prompt)}`;
55
- window.open(cursorUrl, '_blank');
56
- }
57
- }