@stainless-api/docs 0.1.0-beta.7 → 0.1.0-beta.70

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 (120) hide show
  1. package/CHANGELOG.md +554 -0
  2. package/README.md +1 -1
  3. package/eslint-suppressions.json +52 -0
  4. package/locals.d.ts +17 -0
  5. package/package.json +51 -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 +45 -28
  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 +243 -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/helpers/generateDocsRoutes.ts +27 -0
  24. package/plugin/index.ts +178 -35
  25. package/plugin/languages.ts +5 -2
  26. package/plugin/loadPluginConfig.ts +121 -32
  27. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +1 -1
  28. package/plugin/react/Routing.tsx +208 -129
  29. package/plugin/referencePlaceholderUtils.ts +1 -1
  30. package/plugin/replaceSidebarPlaceholderMiddleware.ts +5 -1
  31. package/plugin/routes/Docs.astro +62 -89
  32. package/plugin/routes/DocsStatic.astro +1 -1
  33. package/plugin/routes/Overview.astro +10 -16
  34. package/plugin/routes/markdown.ts +9 -8
  35. package/plugin/vendor/preview.worker.docs.js +19768 -17702
  36. package/plugin/vendor/templates/go.md +1 -1
  37. package/plugin/vendor/templates/python.md +1 -1
  38. package/resolveSrcFile.ts +10 -0
  39. package/scripts/vendor_deps.ts +5 -5
  40. package/shared/getProsePages.ts +42 -0
  41. package/shared/getSharedLogger.ts +15 -0
  42. package/shared/terminalUtils.ts +3 -0
  43. package/src/content.config.ts +9 -0
  44. package/stl-docs/components/AIDropdown.tsx +63 -0
  45. package/stl-docs/components/AiChatIsland.tsx +14 -0
  46. package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +10 -18
  47. package/stl-docs/components/Head.astro +16 -0
  48. package/stl-docs/components/Header.astro +6 -8
  49. package/stl-docs/components/PageFrame.astro +18 -0
  50. package/stl-docs/components/PageTitle.astro +82 -0
  51. package/stl-docs/components/TableOfContents.astro +34 -0
  52. package/stl-docs/components/ThemeProvider.astro +36 -0
  53. package/stl-docs/components/ThemeSelect.astro +84 -139
  54. package/stl-docs/components/content-panel/ContentPanel.astro +16 -25
  55. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +17 -1
  56. package/stl-docs/components/headers/StackedHeader.astro +29 -24
  57. package/stl-docs/components/icons/chat-gpt.tsx +17 -0
  58. package/stl-docs/components/icons/claude.tsx +10 -0
  59. package/stl-docs/components/icons/cursor.tsx +10 -0
  60. package/stl-docs/components/icons/gemini.tsx +19 -0
  61. package/stl-docs/components/icons/markdown.tsx +10 -0
  62. package/stl-docs/components/index.ts +1 -0
  63. package/stl-docs/components/mintlify-compat/Accordion.astro +7 -5
  64. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +7 -3
  65. package/stl-docs/components/mintlify-compat/Columns.astro +40 -42
  66. package/stl-docs/components/mintlify-compat/Frame.astro +16 -18
  67. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +1 -1
  68. package/stl-docs/components/mintlify-compat/callouts/Check.astro +1 -1
  69. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +1 -1
  70. package/stl-docs/components/mintlify-compat/callouts/Info.astro +1 -1
  71. package/stl-docs/components/mintlify-compat/callouts/Note.astro +1 -1
  72. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +1 -1
  73. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +1 -1
  74. package/stl-docs/components/mintlify-compat/card.css +33 -35
  75. package/stl-docs/components/mintlify-compat/index.ts +2 -4
  76. package/stl-docs/components/nav-tabs/NavDropdown.astro +31 -70
  77. package/stl-docs/components/nav-tabs/NavTabs.astro +78 -80
  78. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +15 -8
  79. package/stl-docs/components/nav-tabs/buildNavLinks.ts +3 -2
  80. package/stl-docs/components/pagination/HomeLink.astro +10 -0
  81. package/stl-docs/components/pagination/Pagination.astro +175 -0
  82. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
  83. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
  84. package/stl-docs/components/pagination/util.ts +71 -0
  85. package/stl-docs/components/scripts.ts +1 -0
  86. package/stl-docs/disableCalloutSyntax.ts +36 -0
  87. package/stl-docs/index.ts +141 -50
  88. package/stl-docs/loadStlDocsConfig.ts +45 -5
  89. package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +61 -0
  90. package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +39 -0
  91. package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
  92. package/stl-docs/proseSearchIndexing.ts +450 -0
  93. package/stl-docs/tabsMiddleware.ts +11 -3
  94. package/styles/code.css +108 -140
  95. package/styles/fonts.css +32 -17
  96. package/styles/links.css +11 -48
  97. package/styles/method-descriptions.css +36 -0
  98. package/styles/overrides.css +48 -60
  99. package/styles/page.css +92 -52
  100. package/styles/sdk_select.css +9 -7
  101. package/styles/search.css +56 -69
  102. package/styles/sidebar.css +211 -131
  103. package/styles/{variables.css → sl-variables.css} +3 -2
  104. package/styles/stldocs-variables.css +6 -0
  105. package/styles/toc.css +41 -34
  106. package/theme.css +10 -10
  107. package/tsconfig.json +2 -5
  108. package/virtual-module.d.ts +26 -4
  109. package/components/variables.css +0 -135
  110. package/stl-docs/components/mintlify-compat/Step.astro +0 -58
  111. package/stl-docs/components/mintlify-compat/Steps.astro +0 -17
  112. /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
  113. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
  114. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
  115. /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
  116. /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
  117. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
  118. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
  119. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
  120. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
@@ -1,22 +1,24 @@
1
1
  import * as React from 'react';
2
- import { marked } from 'marked';
3
- import hljs from 'highlight.js';
4
- import { createMarkdownProcessor, type MarkdownProcessor } from '@astrojs/markdown-remark';
2
+ import { marked, Tokens } from 'marked';
3
+
4
+ import {
5
+ createMarkdownProcessor,
6
+ CreateShikiHighlighterOptions,
7
+ type MarkdownProcessor,
8
+ } from '@astrojs/markdown-remark';
5
9
  import remarkGfmAlerts from 'remark-github-alerts';
6
10
 
7
11
  import type { MarkdownHeading } from 'astro';
8
12
  import type { StarlightRouteData } from '@astrojs/starlight/route-data';
9
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
10
- import type { DocsLanguage } from '@stainless-api/docs-ui/src/routing';
13
+ import type * as SDKJSON from '@stainless/sdk-json';
14
+ import { LanguageNames, SupportedLanguageSyntaxes, type DocsLanguage } from '@stainless-api/docs-ui/routing';
11
15
 
12
16
  import {
13
- generateRouteList,
14
17
  generateRoute,
15
18
  parseStainlessPath,
16
19
  walkTree,
17
- SupportedLanguageSyntaxes,
18
20
  getLanguageSnippet,
19
- } from '@stainless-api/docs-ui/src/routing';
21
+ } from '@stainless-api/docs-ui/routing';
20
22
 
21
23
  import {
22
24
  DocsProvider,
@@ -24,23 +26,22 @@ import {
24
26
  NavigationProvider,
25
27
  useSpec,
26
28
  type ContentPanelLayout,
27
- } from '@stainless-api/docs-ui/src/contexts';
29
+ } from '@stainless-api/docs-ui/contexts';
28
30
 
29
- import { flatResources, getResourceFromSpec } from '@stainless-api/docs-ui/src/utils';
31
+ import { flatResources, getResourceFromSpec } from '@stainless-api/docs-ui/utils';
30
32
 
31
33
  import {
32
34
  SDKMethod,
33
35
  SDKResource,
34
36
  type SDKRequestTitleProps,
35
37
  SDKBreadcrumbs,
36
- Dropdown,
37
- DropdownTrigger,
38
- DropdownMenu,
39
- DropdownItem,
40
38
  SDKIcon,
41
39
  SDKOverview,
42
40
  SDKLanguageBlock,
43
- } from '@stainless-api/docs-ui/src/components';
41
+ } from '@stainless-api/docs-ui/components';
42
+
43
+ import { Dropdown } from '@stainless-api/docs/components';
44
+
44
45
  import {
45
46
  BASE_PATH,
46
47
  EXCLUDE_LANGUAGES,
@@ -48,37 +49,22 @@ import {
48
49
  HIGHLIGHT_THEMES,
49
50
  BREADCRUMB_CONFIG,
50
51
  PROPERTY_SETTINGS,
52
+ ENABLE_CONTEXT_MENU,
53
+ EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS,
51
54
  } from 'virtual:stl-starlight-virtual-module';
52
- import style from '@stainless-api/docs-ui/src/style';
53
- import { createHighlighter, type BundledLanguage, type BundledTheme, type HighlighterGeneric } from 'shiki';
54
- import { SnippetCode, SnippetContainer, SnippetRequestContainer } from '../components/SnippetCode';
55
- import clsx from 'clsx';
55
+ import style from '@stainless-api/docs-ui/style';
56
+ import { BundledTheme, createHighlighter, HighlighterGeneric, type BundledLanguage } from 'shiki';
57
+ import {
58
+ SnippetCode,
59
+ SnippetContainer,
60
+ SnippetRequestContainer,
61
+ SnippetButtons,
62
+ } from '../components/SnippetCode';
56
63
  import type { StlStarlightMiddleware } from '../middlewareBuilder/stainlessMiddleware';
57
- import { ComponentProvider } from '@stainless-api/docs-ui/src/contexts/component';
58
-
59
- export function generateDocsRoutes(spec: SDKJSON.Spec) {
60
- const paths = generateRouteList({
61
- spec,
62
- excludeLanguages: EXCLUDE_LANGUAGES as DocsLanguage[],
63
- });
64
- const readmes = Object.entries(spec.readme)
65
- .filter(([language]) => language !== 'http')
66
- .filter(([language]) => !EXCLUDE_LANGUAGES.includes(language as DocsLanguage))
67
- .map(([language]) => ({
68
- slug: language,
69
- stainlessPath: null,
70
- language: language as DocsLanguage,
71
- title: 'Readme',
72
- kind: 'readme',
73
- }));
74
-
75
- return [...paths, ...readmes].map(({ slug, stainlessPath, language, title, kind }) => {
76
- return {
77
- params: { slug },
78
- props: { stainlessPath, language, title, kind },
79
- };
80
- });
81
- }
64
+ import { ComponentProvider } from '@stainless-api/docs-ui/contexts/component';
65
+ import { AIDropdown } from '../../stl-docs/components/AIDropdown';
66
+ import { ChevronsUpDownIcon } from 'lucide-react';
67
+ import { MethodDescription } from '../components/MethodDescription';
82
68
 
83
69
  function isResourceNonEmpty(resource: SDKJSON.Resource) {
84
70
  return (
@@ -119,7 +105,6 @@ export function buildSidebar(
119
105
 
120
106
  const meths: SidebarEntry[] = Object.values(resource.methods ?? [])
121
107
  .filter((method) => spec.decls?.[language]?.[method.stainlessPath])
122
- .toSorted((first, second) => first.name.localeCompare(second.name))
123
108
  .map((method) => ({
124
109
  type: 'link',
125
110
  isCurrent: current === method.stainlessPath,
@@ -151,19 +136,58 @@ export function buildPageNavigation(resource: SDKJSON.Resource, depth: number =
151
136
  return [...output, ...subs];
152
137
  }
153
138
 
154
- function renderMarkdown(content: string) {
155
- return marked.parse(content, { gfm: true }) as string;
139
+ async function renderMarkdown(content: string) {
140
+ const highlighter = await astroHighlight();
141
+
142
+ const renderer = {
143
+ code({ text, lang }: Tokens.Code) {
144
+ return shikiHighlight({
145
+ highlighter,
146
+ content: text,
147
+ language: lang,
148
+ });
149
+ },
150
+ };
151
+
152
+ marked.use({ renderer });
153
+ return marked.parse(content, {
154
+ gfm: true,
155
+ }) as string;
156
156
  }
157
157
 
158
- async function highlight(content: string, language?: string) {
159
- if (language === 'json') return hljs.highlight(content, { language }).value;
160
- const highlighter = await astroHighlight();
158
+ function shikiHighlight({
159
+ highlighter,
160
+ content,
161
+ language,
162
+ themes,
163
+ }: {
164
+ highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
165
+ content: string;
166
+ language?: string;
167
+ themes?: CreateShikiHighlighterOptions['themes'] | Record<string, 'stainless-docs-json'>;
168
+ }) {
169
+ let _themes = themes;
170
+ if (!themes && language === 'json') {
171
+ _themes = {
172
+ light: 'stainless-docs-json',
173
+ dark: 'stainless-docs-json',
174
+ };
175
+ }
176
+
177
+ if (!_themes) {
178
+ _themes = HIGHLIGHT_THEMES;
179
+ }
161
180
  return highlighter.codeToHtml(content, {
162
181
  lang: language ?? 'javascript',
163
- themes: HIGHLIGHT_THEMES || {},
182
+ themes: _themes || {},
164
183
  });
165
184
  }
166
185
 
186
+ async function highlight(content: string, language?: string) {
187
+ const highlighter = await astroHighlight();
188
+ return shikiHighlight({ highlighter, content, language });
189
+ }
190
+
167
191
  export function SDKSelectReactComponent({
168
192
  selected,
169
193
  languages,
@@ -177,30 +201,36 @@ export function SDKSelectReactComponent({
177
201
  }) {
178
202
  return (
179
203
  <Dropdown id={id} data-current-value={selected} className={className}>
180
- <DropdownTrigger
181
- className="dropdown-toggle stldocs-button-tertiary"
182
- type="button"
183
- id="stldocs-snippet-title-button"
184
- aria-expanded="false"
185
- withChevron
186
- >
187
- <SDKIcon language={getLanguageSnippet(selected)} size={16} />
188
- <span className={clsx('stl-snippet-dropdown-button-text', selected)}>{selected}</span>
189
- </DropdownTrigger>
190
- <DropdownMenu
204
+ <Dropdown.Trigger>
205
+ <Dropdown.TriggerSelectedItem>
206
+ <Dropdown.Icon>
207
+ <SDKIcon language={getLanguageSnippet(selected)} />
208
+ </Dropdown.Icon>
209
+ <span className="stl-snippet-dropdown-button-text">{LanguageNames[selected]}</span>
210
+ </Dropdown.TriggerSelectedItem>
211
+ <Dropdown.TriggerIcon>
212
+ <ChevronsUpDownIcon size={16} />
213
+ </Dropdown.TriggerIcon>
214
+ </Dropdown.Trigger>
215
+ <Dropdown.Menu
191
216
  className="dropdown-menu stl-sdk-select-dropdown-menu"
192
- position="below"
193
- aria-labelledby="stldocs-snippet-title-button"
217
+ aria-labelledby="stl-docs-snippet-title-button"
194
218
  >
195
219
  {languages.map((item) => (
196
- <DropdownItem key={item} value={item} selected={item === selected}>
197
- <div>
220
+ <Dropdown.MenuItem key={item} value={item} isSelected={item === selected}>
221
+ <Dropdown.Icon>
198
222
  <SDKIcon language={getLanguageSnippet(item)} size={16} />
199
- <span className={clsx('stl-snippet-dropdown-button-text', item)}>{item}</span>
200
- </div>
201
- </DropdownItem>
223
+ </Dropdown.Icon>
224
+ <Dropdown.MenuItemText>{LanguageNames[item]}</Dropdown.MenuItemText>
225
+ <Dropdown.MenuItemTemplate>
226
+ <Dropdown.Icon>
227
+ <SDKIcon language={getLanguageSnippet(item)} size={16} />
228
+ </Dropdown.Icon>
229
+ <span className="stl-snippet-dropdown-button-text">{LanguageNames[item]}</span>
230
+ </Dropdown.MenuItemTemplate>
231
+ </Dropdown.MenuItem>
202
232
  ))}
203
- </DropdownMenu>
233
+ </Dropdown.Menu>
204
234
  </Dropdown>
205
235
  );
206
236
  }
@@ -216,13 +246,13 @@ function SDKRequestTitle({ snippetLanguage }: SDKRequestTitleProps) {
216
246
  selected={selected || 'http'}
217
247
  languages={languages}
218
248
  id="stldocs-snippet-select"
219
- className="stl-sdk-select"
249
+ className="stl-sdk-select stl-ui-not-prose"
220
250
  />
221
251
  );
222
252
  }
223
253
 
224
254
  export type SpecMetadata = [
225
- 'http' | 'node' | 'python' | 'go' | 'typescript' | 'terraform' | 'ruby' | 'java' | 'kotlin',
255
+ DocsLanguage,
226
256
  {
227
257
  repo_url?: string;
228
258
  code_url?: string;
@@ -232,9 +262,18 @@ export type SpecMetadata = [
232
262
  },
233
263
  ][];
234
264
 
265
+ const componentOverrides = {
266
+ SDKRequestTitle,
267
+ SnippetCode,
268
+ SnippetContainer,
269
+ SnippetRequestContainer,
270
+ SnippetButtons,
271
+ ...(EXPERIMENTAL_COLLAPSIBLE_METHOD_DESCRIPTIONS ? { MethodDescription } : {}),
272
+ };
273
+
235
274
  export function RenderLibraries({ metadata }: { metadata: SpecMetadata }) {
236
275
  return (
237
- <ComponentProvider components={{}}>
276
+ <ComponentProvider components={componentOverrides}>
238
277
  {metadata.map(([language, data]) => (
239
278
  <SDKLanguageBlock
240
279
  language={language}
@@ -252,14 +291,7 @@ export function RenderSpecOverview({ spec, language }: { spec: SDKJSON.Spec; lan
252
291
 
253
292
  return (
254
293
  <DocsProvider spec={spec} language={language ?? 'node'}>
255
- <ComponentProvider
256
- components={{
257
- SDKRequestTitle,
258
- SnippetCode,
259
- SnippetContainer,
260
- SnippetRequestContainer,
261
- }}
262
- >
294
+ <ComponentProvider components={componentOverrides}>
263
295
  <NavigationProvider basePath={BASE_PATH}>
264
296
  <MarkdownProvider render={renderMarkdown} highlight={highlight}>
265
297
  <div className={style.Overview}>
@@ -301,7 +333,10 @@ export function RenderSpec({
301
333
  const parsed = parseStainlessPath(path);
302
334
  const resource = getResourceFromSpec(path, spec);
303
335
 
304
- if (!resource || !parsed) return null;
336
+ if (!resource || !parsed) {
337
+ console.warn(`Could not find resource or parsed path for '${path}'`);
338
+ return null;
339
+ }
305
340
 
306
341
  return (
307
342
  <DocsProvider
@@ -312,40 +347,30 @@ export function RenderSpec({
312
347
  properties: PROPERTY_SETTINGS,
313
348
  }}
314
349
  >
315
- <ComponentProvider
316
- components={{
317
- SDKRequestTitle,
318
- SnippetCode,
319
- SnippetContainer,
320
- SnippetRequestContainer,
321
- }}
322
- >
350
+ <ComponentProvider components={componentOverrides}>
323
351
  <NavigationProvider basePath={BASE_PATH} selectedPath={path}>
324
352
  <MarkdownProvider render={renderMarkdown} highlight={highlight}>
325
- {kind === 'http_method' ? (
353
+ {
326
354
  <div className="stldocs-root stl-ui-not-prose">
327
- <SDKBreadcrumbs
328
- spec={spec as SDKJSON.Spec}
329
- currentPath={currentPath}
330
- basePath={BASE_PATH}
331
- config={BREADCRUMB_CONFIG}
332
- />
333
- <SDKMethod
334
- method={resource.methods[parsed.method]}
335
- transformRequestSnippet={transformRequestSnippet}
336
- />
337
- </div>
338
- ) : (
339
- <div className="stldocs-root stl-ui-not-prose">
340
- <SDKBreadcrumbs
341
- spec={spec as SDKJSON.Spec}
342
- currentPath={currentPath}
343
- basePath={BASE_PATH}
344
- config={BREADCRUMB_CONFIG}
345
- />
346
- <SDKOverview resource={resource} />
355
+ <div className="stl-page-nav-container">
356
+ <SDKBreadcrumbs
357
+ spec={spec as SDKJSON.Spec}
358
+ currentPath={currentPath}
359
+ basePath={BASE_PATH}
360
+ config={BREADCRUMB_CONFIG}
361
+ />
362
+ {ENABLE_CONTEXT_MENU && <AIDropdown />}
363
+ </div>
364
+ {kind === 'http_method' ? (
365
+ <SDKMethod
366
+ method={resource.methods[parsed.method!]!}
367
+ transformRequestSnippet={transformRequestSnippet}
368
+ />
369
+ ) : (
370
+ <SDKOverview resource={resource} />
371
+ )}
347
372
  </div>
348
- )}
373
+ }
349
374
  </MarkdownProvider>
350
375
  </NavigationProvider>
351
376
  </ComponentProvider>
@@ -359,10 +384,14 @@ export function RenderMethod({ path }: { path: string }) {
359
384
 
360
385
  const parsed = parseStainlessPath(path);
361
386
  const resource = getResourceFromSpec(path, spec);
362
- if (!resource || !parsed) return null;
363
387
 
364
- const meth = resource.methods[parsed.method];
365
- return <SDKMethod method={meth} />;
388
+ if (!resource || !parsed) {
389
+ console.warn(`Could not find resource or parsed path for '${path}'`);
390
+ return null;
391
+ }
392
+
393
+ const method = resource.methods[parsed.method!]!;
394
+ return <SDKMethod method={method} />;
366
395
  }
367
396
 
368
397
  export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguage) {
@@ -375,13 +404,75 @@ export async function getReadmeContent(spec: SDKJSON.Spec, language: DocsLanguag
375
404
  const response = await fetch(`${rawUrl}/refs/heads/main/README.md`);
376
405
  if (response && response.ok) return response.text();
377
406
  }
378
- } catch (err) {}
407
+ } catch {
408
+ // ignore
409
+ }
379
410
 
380
411
  return spec.readme[language];
381
412
  }
382
413
 
414
+ let astroShikiHighlighter:
415
+ | HighlighterGeneric<BundledLanguage, BundledTheme>
416
+ | Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
417
+ | null = null;
418
+
419
+ async function astroHighlight() {
420
+ if (astroShikiHighlighter) {
421
+ return astroShikiHighlighter;
422
+ }
423
+
424
+ astroShikiHighlighter = createHighlighter({
425
+ themes: [
426
+ 'github-light',
427
+ 'github-dark',
428
+ {
429
+ name: 'stainless-docs-json',
430
+ colors: {
431
+ 'editor.background': 'var(--stl-color-background)',
432
+ 'editor.foreground': 'var(--stl-color-foreground)',
433
+ },
434
+
435
+ tokenColors: [
436
+ {
437
+ scope: ['comment', 'punctuation.definition.comment'],
438
+ settings: { foreground: 'var(--stl-color-foreground-muted)' },
439
+ },
440
+ // numbers, booleans, null
441
+ {
442
+ scope: ['constant.numeric', 'constant.language'],
443
+ settings: { foreground: 'var(--stl-color-orange-foreground)' },
444
+ },
445
+ // strings
446
+ {
447
+ scope: ['string', 'string.quoted', 'string.template'],
448
+ settings: { foreground: 'var(--stl-color-green-foreground)' },
449
+ },
450
+ // Keys, brackets
451
+ {
452
+ scope: ['support.type', 'meta'],
453
+ settings: { foreground: 'var(--stl-color-foreground)' },
454
+ },
455
+ // brackets
456
+ {
457
+ scope: ['meta'],
458
+ settings: { foreground: 'var(--stl-color-foreground-muted)' },
459
+ },
460
+ // built-in types
461
+ {
462
+ scope: ['support.type.builtin'],
463
+ settings: { foreground: 'var(--stl-color-purple-foreground)' },
464
+ },
465
+ ],
466
+ },
467
+ ],
468
+ langs: SupportedLanguageSyntaxes,
469
+ });
470
+
471
+ return astroShikiHighlighter;
472
+ }
473
+
383
474
  // Astro's markdown processor is a singleton
384
- // Need to cache it instead of instanting per request
475
+ // Need to cache it instead of instantiating per request
385
476
  let astroMarkdownProcessor: MarkdownProcessor;
386
477
  async function astroMarkdown() {
387
478
  if (!astroMarkdownProcessor) {
@@ -397,18 +488,6 @@ async function astroMarkdown() {
397
488
  return astroMarkdownProcessor;
398
489
  }
399
490
 
400
- let astroShikiHighlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
401
- async function astroHighlight() {
402
- if (!astroShikiHighlighter) {
403
- astroShikiHighlighter = await createHighlighter({
404
- themes: ['github-light', 'github-dark'],
405
- langs: SupportedLanguageSyntaxes,
406
- });
407
- }
408
-
409
- return astroShikiHighlighter;
410
- }
411
-
412
491
  export async function astroMarkdownRender(content: string) {
413
492
  const md = await astroMarkdown();
414
493
  const output = await md.render(content);
@@ -58,7 +58,7 @@ function recursiveGetPlaceholderItems(
58
58
  items: PlaceholderItemResult[],
59
59
  ): PlaceholderItemResult[] {
60
60
  for (let i = 0; i < sidebar.length; i++) {
61
- const entry = sidebar[i];
61
+ const entry = sidebar[i]!;
62
62
  if ('attrs' in entry && entry.attrs?.about === INTERNAL_REFERENCE_ENTRY_MARKER) {
63
63
  items.push({
64
64
  index: i,
@@ -5,7 +5,7 @@ import { BASE_PATH } from 'virtual:stl-starlight-virtual-module';
5
5
  import { getAPIReferencePlaceholderItems } from './referencePlaceholderUtils';
6
6
  import { getMethodFromSDKJSON, recursiveReplacePlaceholderItems } from './generateAPIReferenceLink';
7
7
  import { forceGenerateRoute } from './cms/sidebar-builder';
8
- import { parseRoute } from '@stainless-api/docs-ui/src/routing';
8
+ import { parseRoute } from '@stainless-api/docs-ui/routing';
9
9
 
10
10
  // this fn is loaded in the plugin via addRouteMiddleware
11
11
 
@@ -15,6 +15,10 @@ export const onRequest = defineRouteMiddleware(async (context) => {
15
15
 
16
16
  const slug = `/${context.locals.starlightRoute.id}`; // same as .slug but not deprecated
17
17
 
18
+ context.locals.starlightRoute._stlStarlight = {
19
+ basePath: BASE_PATH,
20
+ };
21
+
18
22
  const apiReferencePlaceholderItems = getAPIReferencePlaceholderItems(context.locals.starlightRoute.sidebar);
19
23
 
20
24
  const spec = await cmsClient.getSpec();