@stainless-api/docs 0.1.0-beta.6 → 0.1.0-beta.61

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 (115) hide show
  1. package/CHANGELOG.md +486 -0
  2. package/README.md +1 -1
  3. package/eslint-suppressions.json +52 -0
  4. package/locals.d.ts +16 -0
  5. package/package.json +45 -40
  6. package/plugin/assets/languages/csharp.svg +1 -0
  7. package/plugin/buildAlgoliaIndex.ts +32 -7
  8. package/plugin/cms/server.ts +130 -58
  9. package/plugin/cms/sidebar-builder.ts +7 -26
  10. package/plugin/cms/worker.ts +83 -5
  11. package/plugin/components/MethodDescription.tsx +54 -0
  12. package/plugin/components/SDKSelect.astro +7 -87
  13. package/plugin/components/SnippetCode.tsx +53 -8
  14. package/plugin/components/search/SearchAlgolia.astro +14 -26
  15. package/plugin/components/search/SearchIsland.tsx +38 -24
  16. package/plugin/create-playground.shim.tsx +3 -0
  17. package/plugin/generateAPIReferenceLink.ts +2 -2
  18. package/plugin/globalJs/ai-dropdown-options.ts +235 -0
  19. package/plugin/globalJs/code-snippets.ts +15 -8
  20. package/plugin/globalJs/copy.ts +81 -16
  21. package/plugin/globalJs/method-descriptions.ts +33 -0
  22. package/plugin/globalJs/navigation.ts +7 -4
  23. package/plugin/index.ts +179 -35
  24. package/plugin/languages.ts +5 -2
  25. package/plugin/loadPluginConfig.ts +121 -32
  26. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +1 -1
  27. package/plugin/react/Routing.tsx +208 -104
  28. package/plugin/referencePlaceholderUtils.ts +1 -1
  29. package/plugin/replaceSidebarPlaceholderMiddleware.ts +5 -1
  30. package/plugin/routes/Docs.astro +61 -83
  31. package/plugin/routes/Overview.astro +10 -16
  32. package/plugin/routes/markdown.ts +7 -7
  33. package/plugin/vendor/preview.worker.docs.js +19768 -17702
  34. package/plugin/vendor/templates/go.md +1 -1
  35. package/plugin/vendor/templates/python.md +1 -1
  36. package/resolveSrcFile.ts +10 -0
  37. package/scripts/vendor_deps.ts +5 -5
  38. package/shared/getSharedLogger.ts +15 -0
  39. package/shared/terminalUtils.ts +3 -0
  40. package/src/content.config.ts +9 -0
  41. package/stl-docs/components/AIDropdown.tsx +63 -0
  42. package/stl-docs/components/AiChatIsland.tsx +10 -0
  43. package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +10 -18
  44. package/stl-docs/components/Head.astro +16 -0
  45. package/stl-docs/components/Header.astro +6 -8
  46. package/stl-docs/components/PageFrame.astro +14 -0
  47. package/stl-docs/components/PageTitle.astro +82 -0
  48. package/stl-docs/components/TableOfContents.astro +34 -0
  49. package/stl-docs/components/ThemeSelect.astro +118 -136
  50. package/stl-docs/components/content-panel/ContentPanel.astro +16 -25
  51. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +17 -1
  52. package/stl-docs/components/headers/StackedHeader.astro +29 -24
  53. package/stl-docs/components/icons/chat-gpt.tsx +17 -0
  54. package/stl-docs/components/icons/claude.tsx +10 -0
  55. package/stl-docs/components/icons/cursor.tsx +10 -0
  56. package/stl-docs/components/icons/gemini.tsx +19 -0
  57. package/stl-docs/components/icons/markdown.tsx +10 -0
  58. package/stl-docs/components/index.ts +1 -0
  59. package/stl-docs/components/mintlify-compat/Accordion.astro +7 -5
  60. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +7 -3
  61. package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
  62. package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
  63. package/stl-docs/components/mintlify-compat/Step.astro +30 -32
  64. package/stl-docs/components/mintlify-compat/Steps.astro +8 -10
  65. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +1 -1
  66. package/stl-docs/components/mintlify-compat/callouts/Check.astro +1 -1
  67. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +1 -1
  68. package/stl-docs/components/mintlify-compat/callouts/Info.astro +1 -1
  69. package/stl-docs/components/mintlify-compat/callouts/Note.astro +1 -1
  70. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +1 -1
  71. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +1 -1
  72. package/stl-docs/components/mintlify-compat/card.css +33 -35
  73. package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -70
  74. package/stl-docs/components/nav-tabs/NavTabs.astro +78 -80
  75. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -8
  76. package/stl-docs/components/nav-tabs/buildNavLinks.ts +3 -2
  77. package/stl-docs/components/pagination/HomeLink.astro +10 -0
  78. package/stl-docs/components/pagination/Pagination.astro +175 -0
  79. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
  80. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
  81. package/stl-docs/components/pagination/util.ts +71 -0
  82. package/stl-docs/components/scripts.ts +1 -0
  83. package/stl-docs/disableCalloutSyntax.ts +36 -0
  84. package/stl-docs/index.ts +130 -48
  85. package/stl-docs/loadStlDocsConfig.ts +44 -4
  86. package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +64 -0
  87. package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +34 -0
  88. package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
  89. package/stl-docs/proseSearchIndexing.ts +113 -0
  90. package/stl-docs/tabsMiddleware.ts +11 -3
  91. package/styles/code.css +108 -140
  92. package/styles/fonts.css +32 -17
  93. package/styles/links.css +11 -48
  94. package/styles/method-descriptions.css +36 -0
  95. package/styles/overrides.css +48 -60
  96. package/styles/page.css +92 -52
  97. package/styles/sdk_select.css +9 -7
  98. package/styles/search.css +58 -69
  99. package/styles/sidebar.css +211 -131
  100. package/styles/{variables.css → sl-variables.css} +3 -2
  101. package/styles/stldocs-variables.css +6 -0
  102. package/styles/toc.css +41 -34
  103. package/theme.css +10 -10
  104. package/tsconfig.json +2 -5
  105. package/virtual-module.d.ts +23 -3
  106. package/components/variables.css +0 -135
  107. /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
  108. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
  109. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
  110. /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
  111. /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
  112. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
  113. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
  114. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
  115. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
@@ -1,9 +1,12 @@
1
1
  import path from 'path';
2
+ import { homedir } from 'os';
3
+ import { existsSync, readFileSync } from 'fs';
2
4
 
3
5
  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 { DocsLanguage } from '@stainless-api/docs-ui/routing';
7
+ import type { PropertySettingsType } from '@stainless-api/docs-ui/contexts';
6
8
  import type { InputFilePaths } from '../plugin/cms/server';
9
+ import { bold } from '../shared/terminalUtils';
7
10
 
8
11
  export type AstroCommand = 'dev' | 'build' | 'preview' | 'sync';
9
12
 
@@ -18,7 +21,7 @@ export type VersionUserConfig = {
18
21
  type BreadcrumbUserConfig = {
19
22
  /**
20
23
  * Include the current page in the breadcrumb list.
21
- * Defaults to `false`.
24
+ * Default: `false`
22
25
  */
23
26
  includeCurrentPage?: boolean;
24
27
  };
@@ -26,7 +29,12 @@ type BreadcrumbUserConfig = {
26
29
  export type StainlessStarlightUserConfig = {
27
30
  /**
28
31
  * Optional api key for Stainless API.
29
- * If not provided, it will look for the STAINLESS_API_KEY environment variable.
32
+ * If not provided, we will handle Stainless auth via the `stl` CLI or look for the STAINLESS_API_KEY environment variable.
33
+ * Precedence:
34
+ * 1. Explicity `apiKey` option provided
35
+ * 2. `STAINLESS_API_KEY` environment variable
36
+ * 3. Login status from the `stl` CLI
37
+ * 4. Error (no auth found)
30
38
  */
31
39
  apiKey?: string;
32
40
 
@@ -42,8 +50,8 @@ export type StainlessStarlightUserConfig = {
42
50
 
43
51
  /**
44
52
  * Optional mount point for API reference docs.
45
- * Defaults to `/api`.
46
53
  * Example: `/my-api` → docs available at `/my-api/…`.
54
+ * @default `/api`
47
55
  */
48
56
  basePath?: string;
49
57
 
@@ -55,8 +63,8 @@ export type StainlessStarlightUserConfig = {
55
63
 
56
64
  /**
57
65
  * 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"`
66
+ * Example: `'python'`
67
+ * @default 'http'
60
68
  */
61
69
  defaultLanguage?: DocsLanguage;
62
70
 
@@ -90,7 +98,7 @@ export type StainlessStarlightUserConfig = {
90
98
  contentPanel?: {
91
99
  /**
92
100
  * Optional layout for the content panel.
93
- * Defaults to `"double-pane"`.
101
+ * @default 'double-pane'
94
102
  */
95
103
  layout?: ContentLayout;
96
104
  };
@@ -100,23 +108,35 @@ export type StainlessStarlightUserConfig = {
100
108
  */
101
109
  propertySettings?: PropertySettingsType;
102
110
 
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
111
  /**
115
112
  * Enable experimental collapsible code snippets. Snippets will be collapsed by default for
116
113
  * single-pane and mobile layouts.
117
- * Defaults to `false`.
114
+ *
115
+ * @default false
118
116
  */
119
117
  experimentalCollapsibleSnippets?: boolean;
118
+
119
+ /**
120
+ * Enable experimental collapsible method descriptions. Method descriptions will be
121
+ * collapsed if their content exceeds a certain length.
122
+ *
123
+ * @default false
124
+ */
125
+ experimentalCollapsibleMethodDescriptions?: boolean;
126
+
127
+ /**
128
+ * Whether to show the context menu with options like "Copy as Markdown" and "Open in ChatGPT".
129
+ *
130
+ * @default true
131
+ */
132
+
133
+ contextMenu?: boolean;
134
+
135
+ /**
136
+ * When set to `import playgrounds from '@stainless-api/playgrounds'`, code snippets will have a "Play" button,
137
+ * allowing users to edit and run code snippets in their browser.
138
+ */
139
+ experimentalPlaygrounds?: { playgroundsBase: string };
120
140
  };
121
141
 
122
142
  export type ExternalSpecServerUserConfig = Omit<StainlessStarlightUserConfig, 'stainlessProject'> & {
@@ -133,15 +153,29 @@ function getLocalFilePaths(command: AstroCommand): InputFilePaths | null {
133
153
  if (command !== 'dev') {
134
154
  return null;
135
155
  }
136
- if (!process.env.OPENAPI_PATH || !process.env.STAINLESS_SPEC_PATH) {
156
+
157
+ // eslint-disable-next-line turbo/no-undeclared-env-vars
158
+ const oasPath = process.env.OPENAPI_PATH;
159
+ // eslint-disable-next-line turbo/no-undeclared-env-vars
160
+ const configPath = process.env.STAINLESS_CONFIG_PATH;
161
+
162
+ if (!oasPath || !configPath) {
137
163
  return null;
138
164
  }
165
+
139
166
  return {
140
- oasPath: resolvePath(process.env.OPENAPI_PATH),
141
- configPath: resolvePath(process.env.STAINLESS_SPEC_PATH),
167
+ oasPath: resolvePath(oasPath),
168
+ configPath: resolvePath(configPath),
142
169
  };
143
170
  }
144
171
 
172
+ export type ApiKeySource = 'explicit-config' | 'environment-variable' | 'cli';
173
+
174
+ export type LoadedApiKey = {
175
+ value: string;
176
+ source: ApiKeySource;
177
+ };
178
+
145
179
  export type SpecRetrieverConfig =
146
180
  | {
147
181
  kind: 'external_spec_server';
@@ -152,16 +186,63 @@ export type SpecRetrieverConfig =
152
186
  kind: 'local_spec_server_with_files';
153
187
  stainlessProject: string;
154
188
  devPaths: InputFilePaths;
155
- apiKey: string | null;
189
+ apiKey: LoadedApiKey | null;
156
190
  version: VersionUserConfig;
157
191
  }
158
192
  | {
159
193
  kind: 'local_spec_server_with_remote_files';
160
194
  stainlessProject: string;
161
- apiKey: string;
195
+ apiKey: LoadedApiKey;
162
196
  version: VersionUserConfig;
163
197
  };
164
198
 
199
+ function parseAuthJson(authJsonStr: string) {
200
+ let json: unknown;
201
+ try {
202
+ json = JSON.parse(authJsonStr);
203
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
204
+ } catch (_error) {
205
+ return null;
206
+ }
207
+
208
+ if (typeof json !== 'object' || json === null) {
209
+ return null;
210
+ }
211
+ if (!('access_token' in json)) {
212
+ return null;
213
+ }
214
+ const accessToken = json['access_token'];
215
+ if (typeof accessToken !== 'string') {
216
+ return null;
217
+ }
218
+ return accessToken;
219
+ }
220
+
221
+ function loadApiKey(configValue: string | undefined): LoadedApiKey | null {
222
+ if (typeof configValue === 'string') {
223
+ return { value: configValue, source: 'explicit-config' };
224
+ }
225
+ if (process.env.STAINLESS_API_KEY) {
226
+ return { value: process.env.STAINLESS_API_KEY, source: 'environment-variable' };
227
+ }
228
+
229
+ const homeDirPath = homedir();
230
+
231
+ const authJsonPath = path.join(homeDirPath, '.config', 'stainless', 'auth.json');
232
+
233
+ if (!existsSync(authJsonPath)) {
234
+ return null;
235
+ }
236
+
237
+ const authJsonStr = readFileSync(authJsonPath, 'utf-8');
238
+ const accessToken = parseAuthJson(authJsonStr);
239
+ if (!accessToken) {
240
+ return null;
241
+ }
242
+
243
+ return { value: accessToken, source: 'cli' };
244
+ }
245
+
165
246
  function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: AstroCommand) {
166
247
  const configWithDefaults = {
167
248
  basePath: partial.basePath ?? '/api',
@@ -181,15 +262,16 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: Ast
181
262
  layout: partial.contentPanel?.layout ?? 'double-pane',
182
263
  },
183
264
  experimentalCollapsibleSnippets: partial.experimentalCollapsibleSnippets ?? false,
265
+ experimentalCollapsibleMethodDescriptions: partial.experimentalCollapsibleMethodDescriptions ?? false,
184
266
  propertySettings: {
185
267
  types: partial.propertySettings?.types ?? 'rich',
186
268
  collapseDescription: partial.propertySettings?.collapseDescription ?? true,
269
+ showTitle: partial.propertySettings?.showTitle ?? false,
187
270
  expandDepth: partial.propertySettings?.expandDepth ?? 0,
188
271
  includeModelProperties: partial.propertySettings?.includeModelProperties ?? true,
189
272
  },
190
- search: {
191
- enableAISearch: partial.search?.enableAISearch ?? false,
192
- },
273
+ contextMenu: partial.contextMenu ?? true,
274
+ experimentalPlaygrounds: partial.experimentalPlaygrounds ?? undefined,
193
275
  };
194
276
 
195
277
  function getSpecRetrieverConfig(): SpecRetrieverConfig {
@@ -205,7 +287,7 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: Ast
205
287
  throw new Error('You must provide a stainlessProject when using Stainless Starlight');
206
288
  }
207
289
 
208
- const apiKey = partial.apiKey ?? process.env.STAINLESS_API_KEY ?? null;
290
+ const apiKey = loadApiKey(partial.apiKey);
209
291
 
210
292
  const version = {
211
293
  stainlessProject: partial.stainlessProject,
@@ -226,7 +308,14 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: Ast
226
308
 
227
309
  if (!apiKey) {
228
310
  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.',
311
+ [
312
+ bold(
313
+ 'No Stainless credentials found. Please choose one of the following options to authenticate with Stainless:',
314
+ ),
315
+ '- Run `stl auth login` to authenticate via the Stainless CLI',
316
+ '- Provide a Stainless API key via the `STAINLESS_API_KEY` environment variable (eg. in a .env file)',
317
+ '- Set the `apiKey` option in the Stainless Docs config',
318
+ ].join('\n'),
230
319
  );
231
320
  }
232
321
 
@@ -249,11 +338,11 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, command: Ast
249
338
  export type NormalizedStainlessStarlightConfig = ReturnType<typeof normalizeConfig>;
250
339
 
251
340
  /*
252
- The goal of the code in this file is to take a user's config and normalize it.
341
+ The goal of the code in this file is to take a user's config and normalize it.
253
342
  Specifically: we want a single complete config format used throughout the internals of the plugin.
254
343
 
255
344
  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
345
+ - Any optional config values should have their defaults set here: eg. basePath defaults to /api
257
346
  - If a field is only used in certain contexts, we make each context a discriminated union (see SpecRetrieverConfig)
258
347
  - We prefer empty arrays over undefined/null
259
348
  */
@@ -1,4 +1,4 @@
1
- import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/src/components/sdk';
1
+ import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/components/sdk';
2
2
 
3
3
  export type StlStarlightMiddleware = {
4
4
  transformRequestSnippet?: TransformRequestSnippetFn;