@stainless-api/docs 0.1.0-beta.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.
Files changed (119) hide show
  1. package/.env.example +1 -0
  2. package/CHANGELOG.md +13 -0
  3. package/README.md +11 -0
  4. package/components/variables.css +139 -0
  5. package/eslint.config.js +10 -0
  6. package/package.json +74 -0
  7. package/plugin/assets/fonts/geist/OFL.txt +93 -0
  8. package/plugin/assets/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
  9. package/plugin/assets/fonts/geist/geist-italic-latin.woff2 +0 -0
  10. package/plugin/assets/fonts/geist/geist-latin-ext.woff2 +0 -0
  11. package/plugin/assets/fonts/geist/geist-latin.woff2 +0 -0
  12. package/plugin/assets/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
  13. package/plugin/assets/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
  14. package/plugin/assets/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
  15. package/plugin/assets/fonts/geist/geist-mono-latin.woff2 +0 -0
  16. package/plugin/assets/languages/curl.svg +10 -0
  17. package/plugin/assets/languages/go.svg +4 -0
  18. package/plugin/assets/languages/java.svg +7 -0
  19. package/plugin/assets/languages/kotlin.svg +10 -0
  20. package/plugin/assets/languages/powershell.svg +3 -0
  21. package/plugin/assets/languages/python.svg +19 -0
  22. package/plugin/assets/languages/ruby.svg +125 -0
  23. package/plugin/assets/languages/terraform.svg +5 -0
  24. package/plugin/assets/languages/typescript.svg +11 -0
  25. package/plugin/assets/stainless-logo-dark.png +0 -0
  26. package/plugin/assets/stainless-logo.png +0 -0
  27. package/plugin/buildAlgoliaIndex.ts +72 -0
  28. package/plugin/cms/client.ts +62 -0
  29. package/plugin/cms/server.ts +268 -0
  30. package/plugin/cms/sidebar-builder.ts +420 -0
  31. package/plugin/cms/worker.ts +122 -0
  32. package/plugin/components/SDKSelect.astro +154 -0
  33. package/plugin/components/SnippetCode.tsx +212 -0
  34. package/plugin/components/search/Search.astro +6 -0
  35. package/plugin/components/search/SearchAlgolia.astro +87 -0
  36. package/plugin/components/search/SearchIsland.tsx +100 -0
  37. package/plugin/generateAPIReferenceLink.ts +71 -0
  38. package/plugin/globalJs/ai-dropdown.ts +57 -0
  39. package/plugin/globalJs/code-snippets.ts +87 -0
  40. package/plugin/globalJs/copy.ts +37 -0
  41. package/plugin/globalJs/navigation.ts +81 -0
  42. package/plugin/globalJs/tooltip.ts +32 -0
  43. package/plugin/helpers/getPageLoadEvent.ts +8 -0
  44. package/plugin/index.ts +308 -0
  45. package/plugin/languages.ts +67 -0
  46. package/plugin/loadPluginConfig.ts +273 -0
  47. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +5 -0
  48. package/plugin/middlewareBuilder/stlStarlightMiddleware.ts +5 -0
  49. package/plugin/react/Routing.tsx +435 -0
  50. package/plugin/referencePlaceholderUtils.ts +82 -0
  51. package/plugin/replaceSidebarPlaceholderMiddleware.ts +50 -0
  52. package/plugin/routes/Docs.astro +171 -0
  53. package/plugin/routes/DocsStatic.astro +14 -0
  54. package/plugin/routes/Overview.astro +67 -0
  55. package/plugin/routes/markdown.ts +58 -0
  56. package/plugin/vendor/preview.worker.docs.js +21657 -0
  57. package/plugin/vendor/templates/go.md +314 -0
  58. package/plugin/vendor/templates/java.md +87 -0
  59. package/plugin/vendor/templates/kotlin.md +87 -0
  60. package/plugin/vendor/templates/node.md +233 -0
  61. package/plugin/vendor/templates/python.md +249 -0
  62. package/plugin/vendor/templates/ruby.md +145 -0
  63. package/plugin/vendor/templates/terraform.md +60 -0
  64. package/plugin/vendor/templates/typescript.md +317 -0
  65. package/scripts/vendor_deps.ts +50 -0
  66. package/shared/virtualModule.ts +7 -0
  67. package/stl-docs/components/APIReferenceAIDropdown.tsx +86 -0
  68. package/stl-docs/components/ClientRouterHead.astro +41 -0
  69. package/stl-docs/components/Header.astro +91 -0
  70. package/stl-docs/components/Sidebar.astro +11 -0
  71. package/stl-docs/components/ThemeSelect.astro +225 -0
  72. package/stl-docs/components/content-panel/ContentBreadcrumbs.tsx +84 -0
  73. package/stl-docs/components/content-panel/ContentPanel.astro +72 -0
  74. package/stl-docs/components/content-panel/ProseAIDropdown.tsx +64 -0
  75. package/stl-docs/components/headers/DefaultHeader.astro +36 -0
  76. package/stl-docs/components/headers/HeaderLinks.astro +16 -0
  77. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +49 -0
  78. package/stl-docs/components/headers/StackedHeader.astro +75 -0
  79. package/stl-docs/components/mintlify-compat/Accordion.astro +46 -0
  80. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +25 -0
  81. package/stl-docs/components/mintlify-compat/Card.tsx +32 -0
  82. package/stl-docs/components/mintlify-compat/Columns.astro +66 -0
  83. package/stl-docs/components/mintlify-compat/Frame.astro +37 -0
  84. package/stl-docs/components/mintlify-compat/Step.astro +58 -0
  85. package/stl-docs/components/mintlify-compat/Steps.astro +17 -0
  86. package/stl-docs/components/mintlify-compat/Tab.astro +13 -0
  87. package/stl-docs/components/mintlify-compat/Tabs.astro +7 -0
  88. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +7 -0
  89. package/stl-docs/components/mintlify-compat/callouts/Check.astro +7 -0
  90. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +7 -0
  91. package/stl-docs/components/mintlify-compat/callouts/Info.astro +7 -0
  92. package/stl-docs/components/mintlify-compat/callouts/Note.astro +7 -0
  93. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +7 -0
  94. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +7 -0
  95. package/stl-docs/components/mintlify-compat/callouts/index.ts +9 -0
  96. package/stl-docs/components/mintlify-compat/card.css +44 -0
  97. package/stl-docs/components/mintlify-compat/index.ts +15 -0
  98. package/stl-docs/components/nav-tabs/NavDropdown.astro +106 -0
  99. package/stl-docs/components/nav-tabs/NavTabs.astro +165 -0
  100. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +62 -0
  101. package/stl-docs/components/nav-tabs/buildNavLinks.ts +14 -0
  102. package/stl-docs/index.ts +174 -0
  103. package/stl-docs/loadStlDocsConfig.ts +160 -0
  104. package/stl-docs/redirects.ts +33 -0
  105. package/stl-docs/tabsMiddleware.ts +183 -0
  106. package/styles/code.css +189 -0
  107. package/styles/fonts.css +68 -0
  108. package/styles/links.css +51 -0
  109. package/styles/mintlify-compat.css +1 -0
  110. package/styles/overrides.css +79 -0
  111. package/styles/page.css +76 -0
  112. package/styles/sdk_select.css +11 -0
  113. package/styles/search.css +85 -0
  114. package/styles/sidebar.css +168 -0
  115. package/styles/toc.css +42 -0
  116. package/styles/variables.css +18 -0
  117. package/theme.css +15 -0
  118. package/tsconfig.json +18 -0
  119. package/virtual-module.d.ts +43 -0
@@ -0,0 +1,273 @@
1
+ import path from 'path';
2
+
3
+ import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
4
+ import type { DocsLanguage } from '@stainless-api/docs-ui/src/routing';
5
+ import type { PropertySettingsType } from '@stainless-api/docs-ui/src/contexts';
6
+ import type { InputFilePaths } from '../plugin/cms/server';
7
+
8
+ export type AstroCommand = 'dev' | 'build' | 'preview' | 'sync';
9
+
10
+ export type ContentLayout = 'double-pane' | 'single-pane';
11
+
12
+ export type VersionUserConfig = {
13
+ version: string;
14
+ stainlessProject: string;
15
+ branch: string;
16
+ };
17
+
18
+ type BreadcrumbUserConfig = {
19
+ /**
20
+ * Include the current page in the breadcrumb list.
21
+ * Defaults to `false`.
22
+ */
23
+ includeCurrentPage?: boolean;
24
+ };
25
+
26
+ export type StainlessStarlightUserConfig = {
27
+ /**
28
+ * Optional api key for Stainless API.
29
+ * If not provided, it will look for the STAINLESS_API_KEY environment variable.
30
+ */
31
+ apiKey?: string;
32
+
33
+ /**
34
+ * The slug of your Stainless project.
35
+ */
36
+ stainlessProject: string;
37
+
38
+ /**
39
+ * Optional list of versions to render in the API reference.
40
+ */
41
+ versions?: VersionUserConfig[];
42
+
43
+ /**
44
+ * Optional mount point for API reference docs.
45
+ * Defaults to `/api`.
46
+ * Example: `/my-api` → docs available at `/my-api/…`.
47
+ */
48
+ basePath?: string;
49
+
50
+ /**
51
+ * Optional list of languages to exclude from the API reference.
52
+ * Example: `["python", "javascript"]`
53
+ */
54
+ excludeLanguages?: DocsLanguage[];
55
+
56
+ /**
57
+ * Optional language to treat as the default when the user hasn't selected one.
58
+ * Defaults to `"http"` when none is provided.
59
+ * Example: `"python"`
60
+ */
61
+ defaultLanguage?: DocsLanguage;
62
+
63
+ /**
64
+ * Configure breadcrumbs for API reference pages
65
+ */
66
+ breadcrumbs?: BreadcrumbUserConfig;
67
+
68
+ /**
69
+ * Optional setting that automatically expands the top-level sidebar resources when set to true.
70
+ * When no value is provided, top-level resources automatically expand if the total number of
71
+ * endpoints in the API is less than 20. You can explicitly set the value to `false` to prevent
72
+ * that behavior.
73
+ */
74
+ expandResources?: boolean;
75
+
76
+ /**
77
+ * Options that control syntax highlighting for embedded code snippets in the API reference.
78
+ */
79
+ highlighting?: {
80
+ /**
81
+ * Optionally set the syntax highlighting theme to use for code snippets.
82
+ * Defaults to Github Dark. Can accept any standard shiki syntax highlighting theme.
83
+ */
84
+ themes?: CreateShikiHighlighterOptions['themes'];
85
+ };
86
+
87
+ /**
88
+ * Configure the content panel for API reference pages.
89
+ */
90
+ contentPanel?: {
91
+ /**
92
+ * Optional layout for the content panel.
93
+ * Defaults to `"double-pane"`.
94
+ */
95
+ layout?: ContentLayout;
96
+ };
97
+
98
+ /**
99
+ * Configure the API reference property design
100
+ */
101
+ propertySettings?: PropertySettingsType;
102
+
103
+ /**
104
+ * Options to control the documentation site's search functionality
105
+ */
106
+ search?: {
107
+ /**
108
+ * When set to `true`, the enableAISearch` setting turns on support for
109
+ * LLM-based conversations with the API documentation
110
+ */
111
+ enableAISearch?: boolean;
112
+ };
113
+
114
+ /**
115
+ * Enable experimental collapsible code snippets. Snippets will be collapsed by default for
116
+ * single-pane and mobile layouts.
117
+ * Defaults to `false`.
118
+ */
119
+ experimentalCollapsibleSnippets?: boolean;
120
+ };
121
+
122
+ export type ExternalSpecServerUserConfig = Omit<StainlessStarlightUserConfig, 'stainlessProject'> & {
123
+ externalSpecServerUrl: string;
124
+ };
125
+
126
+ export type SomeStainlessStarlightUserConfig = StainlessStarlightUserConfig | ExternalSpecServerUserConfig;
127
+
128
+ function resolvePath(inputPath: string) {
129
+ return path.resolve(process.cwd(), inputPath);
130
+ }
131
+
132
+ function getLocalFilePaths(command: AstroCommand): InputFilePaths | null {
133
+ if (command !== 'dev') {
134
+ return null;
135
+ }
136
+ if (!process.env.OPENAPI_PATH || !process.env.STAINLESS_SPEC_PATH) {
137
+ return null;
138
+ }
139
+ return {
140
+ oasPath: resolvePath(process.env.OPENAPI_PATH),
141
+ configPath: resolvePath(process.env.STAINLESS_SPEC_PATH),
142
+ };
143
+ }
144
+
145
+ export type SpecRetrieverConfig =
146
+ | {
147
+ kind: 'external_spec_server';
148
+ specServerUrl: string;
149
+ stainlessProject: null;
150
+ }
151
+ | {
152
+ kind: 'local_spec_server_with_files';
153
+ stainlessProject: string;
154
+ devPaths: InputFilePaths;
155
+ apiKey: string | null;
156
+ version: VersionUserConfig;
157
+ }
158
+ | {
159
+ kind: 'local_spec_server_with_remote_files';
160
+ stainlessProject: string;
161
+ apiKey: string;
162
+ version: VersionUserConfig;
163
+ };
164
+
165
+ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: AstroCommand) {
166
+ const configWithDefaults = {
167
+ basePath: partial.basePath ?? '/api',
168
+ excludeLanguages: partial.excludeLanguages ?? [],
169
+ defaultLanguage: partial.defaultLanguage ?? 'http',
170
+ breadcrumbs: {
171
+ includeCurrentPage: partial.breadcrumbs?.includeCurrentPage ?? false,
172
+ },
173
+ expandResources: partial.expandResources ?? true,
174
+ highlighting: {
175
+ themes: partial.highlighting?.themes ?? {
176
+ light: 'github-light',
177
+ dark: 'github-dark',
178
+ },
179
+ },
180
+ contentPanel: {
181
+ layout: partial.contentPanel?.layout ?? 'double-pane',
182
+ },
183
+ experimentalCollapsibleSnippets: partial.experimentalCollapsibleSnippets ?? false,
184
+ propertySettings: {
185
+ types: partial.propertySettings?.types ?? 'rich',
186
+ collapseDescription: partial.propertySettings?.collapseDescription ?? true,
187
+ expandDepth: partial.propertySettings?.expandDepth ?? 0,
188
+ includeModelProperties: partial.propertySettings?.includeModelProperties ?? true,
189
+ },
190
+ search: {
191
+ enableAISearch: partial.search?.enableAISearch ?? false,
192
+ },
193
+ };
194
+
195
+ function getSpecRetrieverConfig(): SpecRetrieverConfig {
196
+ if ('externalSpecServerUrl' in partial) {
197
+ return {
198
+ kind: 'external_spec_server',
199
+ specServerUrl: partial.externalSpecServerUrl,
200
+ stainlessProject: null,
201
+ };
202
+ }
203
+
204
+ if (!('stainlessProject' in partial)) {
205
+ throw new Error('You must provide a stainlessProject when using Stainless Starlight');
206
+ }
207
+
208
+ const apiKey = partial.apiKey ?? process.env.STAINLESS_API_KEY ?? null;
209
+
210
+ const version = {
211
+ stainlessProject: partial.stainlessProject,
212
+ branch: partial.versions?.[0]?.branch ?? 'main',
213
+ version: partial.versions?.[0]?.version ?? 'v1',
214
+ };
215
+
216
+ const localFilePaths = getLocalFilePaths(command);
217
+ if (localFilePaths) {
218
+ return {
219
+ kind: 'local_spec_server_with_files',
220
+ devPaths: localFilePaths,
221
+ stainlessProject: partial.stainlessProject,
222
+ apiKey,
223
+ version,
224
+ };
225
+ }
226
+
227
+ if (!apiKey) {
228
+ throw new Error(
229
+ 'Please provide a Stainless API key via the STAINLESS_API_KEY environment variable or the apiKey option in the Stainless Starlight config.',
230
+ );
231
+ }
232
+
233
+ return {
234
+ kind: 'local_spec_server_with_remote_files',
235
+ apiKey,
236
+ stainlessProject: partial.stainlessProject,
237
+ version,
238
+ };
239
+ }
240
+
241
+ const specRetrieverConfig = getSpecRetrieverConfig();
242
+
243
+ return {
244
+ ...configWithDefaults,
245
+ specRetrieverConfig,
246
+ };
247
+ }
248
+
249
+ export type NormalizedStainlessStarlightConfig = ReturnType<typeof normalizeConfig>;
250
+
251
+ /*
252
+ The goal of the code in this file is to take a user's config and normalize it.
253
+ Specifically: we want a single complete config format used throughout the internals of the plugin.
254
+
255
+ We've tried to avoid any config values being optional/undefined. To accomplish this:
256
+ - Any optional config values should have their defaults set here: eg. basePath defaults to /api
257
+ - If a field is only used in certain contexts, we make each context a discriminated union (see SpecRetrieverConfig)
258
+ - We prefer empty arrays over undefined/null
259
+ */
260
+ export function parseStarlightPluginConfig(partial: SomeStainlessStarlightUserConfig, command: AstroCommand) {
261
+ try {
262
+ const config = normalizeConfig(partial, command);
263
+ return {
264
+ result: 'success' as const,
265
+ config,
266
+ };
267
+ } catch (error) {
268
+ return {
269
+ result: 'error' as const,
270
+ message: error instanceof Error ? error.message : 'An unknown error occurred',
271
+ };
272
+ }
273
+ }
@@ -0,0 +1,5 @@
1
+ import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/src/components/sdk';
2
+
3
+ export type StlStarlightMiddleware = {
4
+ transformRequestSnippet?: TransformRequestSnippetFn;
5
+ };
@@ -0,0 +1,5 @@
1
+ import type { StlStarlightMiddleware } from './stainlessMiddleware';
2
+
3
+ export function defineStainlessMiddleware(middleware: StlStarlightMiddleware) {
4
+ return middleware;
5
+ }