@stainless-api/docs 0.1.0-beta.98 → 1.0.0-beta.140

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 (138) hide show
  1. package/CHANGELOG.md +404 -0
  2. package/ambient.d.ts +6 -0
  3. package/eslint-suppressions.json +22 -6
  4. package/{eslint.config.js → eslint.config.ts} +1 -7
  5. package/package.json +57 -40
  6. package/plugin/assets/languages/php.svg +4 -0
  7. package/plugin/buildAlgoliaIndex.ts +6 -12
  8. package/plugin/components/SDKSelect.astro +0 -6
  9. package/plugin/components/SnippetCode.tsx +6 -37
  10. package/plugin/components/search/SearchAlgolia.astro +1 -1
  11. package/plugin/components/search/SearchIsland.tsx +19 -13
  12. package/plugin/generateAPIReferenceLink.ts +0 -40
  13. package/plugin/globalJs/ai-dropdown-options.ts +26 -13
  14. package/plugin/globalJs/code-snippets.ts +5 -5
  15. package/plugin/globalJs/copy.ts +20 -91
  16. package/plugin/globalJs/navigation.ts +13 -13
  17. package/plugin/globalJs/summary-selection-tweak.ts +29 -0
  18. package/plugin/index.ts +107 -163
  19. package/plugin/languages.ts +2 -1
  20. package/plugin/loadPluginConfig.ts +50 -153
  21. package/plugin/markdown/highlighter.ts +100 -0
  22. package/plugin/markdown/index.ts +39 -0
  23. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +2 -0
  24. package/plugin/react/Routing.tsx +10 -244
  25. package/plugin/referencePlaceholderUtils.ts +1 -1
  26. package/plugin/replaceSidebarPlaceholderMiddleware.ts +1 -1
  27. package/plugin/routes/Docs.astro +3 -1
  28. package/plugin/routes/Overview.astro +14 -7
  29. package/plugin/routes/llms.ts +186 -0
  30. package/plugin/routes/markdown.ts +62 -13
  31. package/plugin/sidebar-utils/sidebar-builder.ts +38 -12
  32. package/plugin/specs/defaultSpecLoader.ts +192 -0
  33. package/plugin/specs/fetchSpecSSR.ts +1 -1
  34. package/plugin/specs/utils.ts +86 -0
  35. package/shared/conditionalIntegration.ts +28 -0
  36. package/shared/getProsePages.ts +6 -7
  37. package/shared/virtualModule.ts +1 -26
  38. package/stl-docs/aiChatExamples.ts +31 -0
  39. package/stl-docs/chat/docs-chat-handler.ts +17 -0
  40. package/stl-docs/chat/hook.ts +225 -0
  41. package/stl-docs/chat/schemas.ts +27 -0
  42. package/stl-docs/chat/ui/AiChat.module.css +591 -0
  43. package/stl-docs/chat/ui/AiChat.tsx +175 -0
  44. package/stl-docs/chat/ui/Trigger.tsx +154 -0
  45. package/stl-docs/chat/ui/components/ChatControls.tsx +51 -0
  46. package/stl-docs/chat/ui/components/ChatEmpty.tsx +42 -0
  47. package/stl-docs/chat/ui/components/ChatLog.tsx +93 -0
  48. package/stl-docs/chat/ui/components/ChatMessage.tsx +47 -0
  49. package/stl-docs/chat/ui/components/CodeBlock.tsx +33 -0
  50. package/stl-docs/chat/ui/components/MessageFeedback.tsx +106 -0
  51. package/stl-docs/chat/ui/components/Table.tsx +15 -0
  52. package/stl-docs/chat/ui/components/ToolCall.tsx +34 -0
  53. package/stl-docs/chat/ui/components/hljs-github.css +81 -0
  54. package/stl-docs/chat/ui/scroll-manager.ts +86 -0
  55. package/stl-docs/chat/ui/types.ts +45 -0
  56. package/stl-docs/components/AiChatIsland.tsx +10 -12
  57. package/stl-docs/components/ContentPanel.astro +9 -0
  58. package/stl-docs/components/Footer.astro +89 -0
  59. package/stl-docs/components/Header.astro +0 -5
  60. package/stl-docs/components/PageFrame.astro +23 -8
  61. package/stl-docs/components/PageSidebar.astro +11 -0
  62. package/stl-docs/components/StainlessLogo.svg +4 -0
  63. package/stl-docs/components/TwoColumnContent.astro +2 -0
  64. package/stl-docs/components/headers/DefaultHeader.astro +6 -8
  65. package/stl-docs/components/headers/StackedHeader.astro +5 -53
  66. package/stl-docs/components/mintlify-compat/Accordion.astro +2 -2
  67. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +0 -4
  68. package/stl-docs/components/mintlify-compat/Columns.astro +2 -2
  69. package/stl-docs/components/mintlify-compat/Frame.astro +2 -2
  70. package/stl-docs/components/mintlify-compat/Tab.astro +2 -2
  71. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +2 -2
  72. package/stl-docs/components/mintlify-compat/callouts/Check.astro +0 -4
  73. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +0 -4
  74. package/stl-docs/components/mintlify-compat/callouts/Info.astro +0 -4
  75. package/stl-docs/components/mintlify-compat/callouts/Note.astro +0 -4
  76. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +0 -4
  77. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +0 -4
  78. package/stl-docs/components/nav-tabs/NavDropdown.astro +12 -7
  79. package/stl-docs/components/nav-tabs/NavTabs.astro +5 -3
  80. package/stl-docs/components/nav-tabs/buildNavLinks.ts +2 -0
  81. package/stl-docs/components/pagination/Pagination.astro +4 -2
  82. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +2 -2
  83. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +2 -2
  84. package/stl-docs/components/pagination/util.ts +3 -3
  85. package/stl-docs/components/sidebars/BaseSidebar.astro +72 -1
  86. package/stl-docs/disableCalloutSyntax.ts +1 -1
  87. package/stl-docs/fonts.ts +5 -5
  88. package/stl-docs/index.ts +76 -53
  89. package/stl-docs/loadStlDocsConfig.ts +38 -8
  90. package/stl-docs/og-image/components/OpenGraphFunctionSignature.tsx +64 -0
  91. package/stl-docs/og-image/components/OpenGraphImage.tsx +126 -0
  92. package/stl-docs/og-image/config.ts +56 -0
  93. package/stl-docs/og-image/image-gen/generate-api-reference-og-image.tsx +188 -0
  94. package/stl-docs/og-image/image-gen/generate-og-image.tsx +119 -0
  95. package/stl-docs/og-image/image-gen/get-logo-url.ts +47 -0
  96. package/stl-docs/og-image/index.ts +135 -0
  97. package/stl-docs/og-image/routes/add-og-image.ts +45 -0
  98. package/stl-docs/og-image/routes/get-api-reference-og-image.ts +36 -0
  99. package/stl-docs/og-image/routes/get-og-image.ts +28 -0
  100. package/stl-docs/og-image/theme.ts +43 -0
  101. package/stl-docs/og-image/utils.ts +14 -0
  102. package/stl-docs/proseDocSync.test.ts +74 -0
  103. package/stl-docs/proseDocSync.ts +344 -0
  104. package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +4 -12
  105. package/stl-docs/schema-extension.ts +12 -0
  106. package/stl-docs/tabsMiddleware.ts +1 -1
  107. package/styles/overrides.css +2 -14
  108. package/styles/page.css +210 -71
  109. package/styles/sidebar.css +30 -17
  110. package/styles/sl-variables.css +3 -8
  111. package/styles/stldocs-variables.css +2 -2
  112. package/styles/toc.css +8 -0
  113. package/tsconfig.json +1 -1
  114. package/virtual-module.d.ts +35 -11
  115. package/playground-virtual-modules.d.ts +0 -96
  116. package/plugin/globalJs/create-playground.shim.ts +0 -3
  117. package/plugin/globalJs/playground-data.shim.ts +0 -1
  118. package/plugin/globalJs/playground-data.ts +0 -14
  119. package/plugin/specs/FileCache.ts +0 -99
  120. package/plugin/specs/generateSpec.ts +0 -112
  121. package/plugin/specs/index.ts +0 -132
  122. package/plugin/specs/inputResolver.ts +0 -146
  123. package/plugin/specs/worker.ts +0 -199
  124. package/plugin/vendor/preview.worker.docs.js +0 -26108
  125. package/plugin/vendor/templates/cli.md +0 -1
  126. package/plugin/vendor/templates/go.md +0 -316
  127. package/plugin/vendor/templates/java.md +0 -89
  128. package/plugin/vendor/templates/kotlin.md +0 -89
  129. package/plugin/vendor/templates/node.md +0 -235
  130. package/plugin/vendor/templates/python.md +0 -251
  131. package/plugin/vendor/templates/ruby.md +0 -147
  132. package/plugin/vendor/templates/terraform.md +0 -60
  133. package/plugin/vendor/templates/typescript.md +0 -319
  134. package/scripts/vendor_deps.ts +0 -50
  135. package/stl-docs/components/ClientRouterHead.astro +0 -41
  136. package/stl-docs/components/content-panel/ContentPanel.astro +0 -42
  137. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +0 -65
  138. package/stl-docs/proseSearchIndexing.ts +0 -606
@@ -5,20 +5,22 @@ import { existsSync, readFileSync } from 'fs';
5
5
  import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
6
6
  import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
7
7
  import type { PropertySettingsType } from '@stainless-api/docs-ui/contexts';
8
- import { bold } from '../shared/terminalUtils';
9
- import { resolveSpec, SpecInputResolver } from './specs/inputResolver';
10
- import { specCache, SpecCacheResult } from './specs/generateSpec';
11
8
 
12
- export type LanguageGenerateQuery = {
13
- mode: 'exclude' | 'only';
14
- list: DocsLanguage[];
9
+ import { defaultSpecLoader } from './specs/defaultSpecLoader';
10
+ import { SpecLoaderFn } from './specs/utils';
11
+
12
+ type ApiKeySource = 'explicit-config' | 'environment-variable' | 'cli';
13
+
14
+ type LoadedApiKey = {
15
+ value: string;
16
+ source: ApiKeySource;
15
17
  };
16
18
 
17
- export type AstroCommand = 'dev' | 'build' | 'preview' | 'sync';
19
+ type AstroCommand = 'dev' | 'build' | 'preview' | 'sync';
18
20
 
19
- export type ContentLayout = 'double-pane' | 'single-pane';
21
+ type ContentLayout = 'double-pane' | 'single-pane';
20
22
 
21
- export type VersionUserConfig = {
23
+ type VersionUserConfig = {
22
24
  version: string;
23
25
  stainlessProject: string;
24
26
  branch: string;
@@ -50,17 +52,9 @@ export type StainlessStarlightUserConfig = {
50
52
  stainlessProject: string;
51
53
 
52
54
  /**
53
- * Powerful configuration options for customized use cases
55
+ * Optional function to provide your own loader for API reference data.
54
56
  */
55
- advanced?: {
56
- /**
57
- *
58
- * More advanced replacement for versions, basePath, and excludeLanguages.
59
- */
60
- overrideSpecs?: {
61
- specs: SpecInputResolver[];
62
- };
63
- };
57
+ loadSpecs?: SpecLoaderFn;
64
58
 
65
59
  /**
66
60
  * Optional list of versions to render in the API reference.
@@ -149,13 +143,7 @@ export type StainlessStarlightUserConfig = {
149
143
  * @default true
150
144
  */
151
145
 
152
- contextMenu?: boolean;
153
-
154
- /**
155
- * When set to `import playgrounds from '@stainless-api/playgrounds'`, code snippets will have a "Play" button,
156
- * allowing users to edit and run code snippets in their browser.
157
- */
158
- experimentalPlaygrounds?: { playgroundsBase: string };
146
+ contextMenu?: boolean | { thirdParty?: boolean };
159
147
 
160
148
  /** When set to true, enables the experimental request builder interface for testing API endpoints. */
161
149
  experimentalRequestBuilder?: boolean;
@@ -165,6 +153,31 @@ export type StainlessStarlightUserConfig = {
165
153
  * @default true
166
154
  */
167
155
  experimentalPrerender?: boolean;
156
+
157
+ /**
158
+ * Configuration for the generated `/llms.txt` file.
159
+ */
160
+ llmsTxt?: {
161
+ /**
162
+ * Whether to disable the generated `/llms.txt` file.
163
+ *
164
+ * @default false
165
+ */
166
+ disabled?: boolean;
167
+ /**
168
+ * A short description of the site, used as the blockquote summary at the top of the file.
169
+ * Falls back to the top-level Starlight `description` field if not set.
170
+ */
171
+ description?: string;
172
+ /**
173
+ * The maximum number of total routes (prose + API reference) at which the file switches
174
+ * from compact mode (resources only) to detailed mode (resources and
175
+ * methods).
176
+ *
177
+ * @default 2000
178
+ */
179
+ detailThreshold?: number;
180
+ };
168
181
  };
169
182
 
170
183
  // TODO: eventually? re-add support for external spec servers
@@ -174,37 +187,6 @@ export type StainlessStarlightUserConfig = {
174
187
 
175
188
  export type SomeStainlessStarlightUserConfig = StainlessStarlightUserConfig;
176
189
 
177
- function resolvePath(inputPath: string) {
178
- return path.resolve(process.cwd(), inputPath);
179
- }
180
-
181
- function getLocalFilePaths(command: AstroCommand) {
182
- if (command !== 'dev') {
183
- return null;
184
- }
185
-
186
- // eslint-disable-next-line turbo/no-undeclared-env-vars
187
- const oasPath = process.env.OPENAPI_PATH;
188
- // eslint-disable-next-line turbo/no-undeclared-env-vars
189
- const configPath = process.env.STAINLESS_CONFIG_PATH;
190
-
191
- if (!oasPath || !configPath) {
192
- return null;
193
- }
194
-
195
- return {
196
- oasPath: resolvePath(oasPath),
197
- configPath: resolvePath(configPath),
198
- };
199
- }
200
-
201
- export type ApiKeySource = 'explicit-config' | 'environment-variable' | 'cli';
202
-
203
- export type LoadedApiKey = {
204
- value: string;
205
- source: ApiKeySource;
206
- };
207
-
208
190
  function parseAuthJson(authJsonStr: string) {
209
191
  let json: unknown;
210
192
  try {
@@ -252,6 +234,7 @@ function loadApiKey(configValue: string | undefined): LoadedApiKey | null {
252
234
  return { value: accessToken, source: 'cli' };
253
235
  }
254
236
 
237
+ /** @public but discouraged - used by cloudflare via relative import */
255
238
  export function forceLoadStainlessCredentials(): LoadedApiKey {
256
239
  const v = loadApiKey(undefined);
257
240
  if (!v) {
@@ -265,99 +248,11 @@ type AstroOptions = {
265
248
  base: string;
266
249
  };
267
250
 
268
- export type ResolvedAPIConfigEntry = {
269
- loadSpecs: () => Promise<SpecCacheResult[]>;
270
- };
271
-
272
- function makeSimpleAPIConfig(
273
- partial: SomeStainlessStarlightUserConfig,
274
- astroOptions: AstroOptions,
275
- ): ResolvedAPIConfigEntry {
276
- if (!('stainlessProject' in partial)) {
277
- throw new Error('You must provide a stainlessProject when using Stainless Starlight');
278
- }
279
-
280
- const excludedLanguages = ['php' as const, ...(partial.excludeLanguages ?? [])];
281
-
282
- const apiKey = loadApiKey(partial.apiKey);
283
-
284
- function getResolver() {
285
- const localFilePaths = getLocalFilePaths(astroOptions.command);
286
- if (localFilePaths) {
287
- return resolveSpec.fromFiles({
288
- oasPath: localFilePaths.oasPath,
289
- configPath: localFilePaths.configPath,
290
- languageOverrides: {
291
- mode: 'exclude',
292
- list: excludedLanguages,
293
- },
294
- stainlessProject: partial.stainlessProject,
295
- });
296
- }
297
-
298
- if (!apiKey) {
299
- throw new Error(
300
- [
301
- bold(
302
- 'No Stainless credentials found. Please choose one of the following options to authenticate with Stainless:',
303
- ),
304
- '- Run `stl auth login` to authenticate via the Stainless CLI',
305
- '- Provide a Stainless API key via the `STAINLESS_API_KEY` environment variable (eg. in a .env file)',
306
- '- Set the `apiKey` option in the Stainless Docs config',
307
- ].join('\n'),
308
- );
309
- }
310
- return resolveSpec.fromStainlessApi({
311
- stainlessProject: partial.stainlessProject,
312
- branch: partial.versions?.[0]?.branch ?? 'main',
313
- apiKey: apiKey,
314
- languageOverrides: {
315
- mode: 'exclude',
316
- list: excludedLanguages,
317
- },
318
- });
319
- }
320
-
321
- const resolver = getResolver();
322
-
323
- return {
324
- loadSpecs: async function loadSpecs() {
325
- const inputs = await resolver.resolve({ apiKey });
326
-
327
- const result = await specCache.get(inputs);
328
-
329
- return [result];
330
- },
331
- };
332
- }
333
-
334
- function loadAPIConfig(
335
- partial: SomeStainlessStarlightUserConfig,
336
- astroOptions: AstroOptions,
337
- ): ResolvedAPIConfigEntry {
338
- if (partial.advanced?.overrideSpecs) {
339
- const overrides = partial.advanced.overrideSpecs;
340
- const apiKey = loadApiKey(partial.apiKey);
341
- return {
342
- loadSpecs: async function loadSpecs() {
343
- const specsPromises = overrides.specs.map(async (spec) => {
344
- const inputs = await spec.resolve({ apiKey });
345
- return await specCache.get(inputs);
346
- });
347
-
348
- return await Promise.all(specsPromises);
349
- },
350
- };
351
- }
352
- return makeSimpleAPIConfig(partial, astroOptions);
353
- }
354
-
355
251
  function normalizeConfig(partial: SomeStainlessStarlightUserConfig, astroOptions: AstroOptions) {
356
252
  const configWithDefaults = {
357
253
  basePath: partial.basePath ?? '/api',
358
254
  astroBase: astroOptions.base,
359
- // TODO: why are we excluding php; do we need to
360
- excludeLanguages: ['php' as const, ...(partial.excludeLanguages ?? [])],
255
+ excludeLanguages: partial.excludeLanguages ?? [],
361
256
  defaultLanguage: partial.defaultLanguage ?? 'http',
362
257
  breadcrumbs: {
363
258
  includeCurrentPage: partial.breadcrumbs?.includeCurrentPage ?? false,
@@ -382,18 +277,20 @@ function normalizeConfig(partial: SomeStainlessStarlightUserConfig, astroOptions
382
277
  includeModelProperties: partial.propertySettings?.includeModelProperties ?? true,
383
278
  },
384
279
  contextMenu: partial.contextMenu ?? true,
385
- experimentalPlaygrounds: partial.experimentalPlaygrounds ?? undefined,
386
280
  experimentalRequestBuilder: partial.experimentalRequestBuilder ?? false,
387
281
  experimentalPrerender: partial.experimentalPrerender ?? true,
388
282
  stainlessProject: partial.stainlessProject,
283
+ llmsTxt: {
284
+ enabled: !partial.llmsTxt?.disabled,
285
+ description: partial.llmsTxt?.description ?? null,
286
+ detailThreshold: partial.llmsTxt?.detailThreshold ?? 2000,
287
+ },
288
+ apiKey: loadApiKey(partial.apiKey),
289
+ loadSpecs: partial.loadSpecs ?? defaultSpecLoader,
290
+ branch: partial.versions?.[0]?.branch ?? 'main',
389
291
  };
390
292
 
391
- const api = loadAPIConfig(partial, astroOptions);
392
-
393
- return {
394
- ...configWithDefaults,
395
- api,
396
- };
293
+ return configWithDefaults;
397
294
  }
398
295
 
399
296
  export type NormalizedStainlessStarlightConfig = ReturnType<typeof normalizeConfig>;
@@ -0,0 +1,100 @@
1
+ import {
2
+ createHighlighter,
3
+ type HighlighterGeneric,
4
+ type ThemeInput,
5
+ type BundledTheme,
6
+ type BundledLanguage,
7
+ } from 'shiki';
8
+ import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
9
+ import { SupportedLanguageSyntaxes } from '@stainless-api/docs-ui/routing';
10
+ import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
11
+
12
+ const STAINLESS_DOCS_JSON_THEME = {
13
+ name: 'stainless-docs-json',
14
+ colors: {
15
+ 'editor.background': 'var(--stl-color-background)',
16
+ 'editor.foreground': 'var(--stl-color-foreground)',
17
+ },
18
+
19
+ tokenColors: [
20
+ {
21
+ scope: ['comment', 'punctuation.definition.comment'],
22
+ settings: { foreground: 'var(--stl-color-foreground-muted)' },
23
+ },
24
+ // numbers, booleans, null
25
+ {
26
+ scope: ['constant.numeric', 'constant.language'],
27
+ settings: { foreground: 'var(--stl-color-orange-foreground)' },
28
+ },
29
+ // strings
30
+ {
31
+ scope: ['string', 'string.quoted', 'string.template'],
32
+ settings: { foreground: 'var(--stl-color-green-foreground)' },
33
+ },
34
+ // Keys, brackets
35
+ {
36
+ scope: ['support.type', 'meta'],
37
+ settings: { foreground: 'var(--stl-color-foreground)' },
38
+ },
39
+ // brackets
40
+ {
41
+ scope: ['meta'],
42
+ settings: { foreground: 'var(--stl-color-foreground-muted)' },
43
+ },
44
+ // built-in types
45
+ {
46
+ scope: ['support.type.builtin'],
47
+ settings: { foreground: 'var(--stl-color-purple-foreground)' },
48
+ },
49
+ ],
50
+ } satisfies ThemeInput;
51
+
52
+ // singleton
53
+ let astroShikiHighlighter:
54
+ | HighlighterGeneric<BundledLanguage, BundledTheme>
55
+ | Promise<HighlighterGeneric<BundledLanguage, BundledTheme>>
56
+ | null = null;
57
+ async function getAstroHighlighter() {
58
+ if (astroShikiHighlighter) {
59
+ return astroShikiHighlighter;
60
+ }
61
+
62
+ astroShikiHighlighter = createHighlighter({
63
+ themes: [
64
+ HIGHLIGHT_THEMES?.dark ?? 'github-dark',
65
+ HIGHLIGHT_THEMES?.light ?? 'github-light',
66
+ STAINLESS_DOCS_JSON_THEME,
67
+ ],
68
+ langs: SupportedLanguageSyntaxes,
69
+ });
70
+
71
+ return astroShikiHighlighter;
72
+ }
73
+
74
+ function runHighlight({
75
+ highlighter,
76
+ content,
77
+ language,
78
+ themes,
79
+ }: {
80
+ highlighter: HighlighterGeneric<BundledLanguage, BundledTheme>;
81
+ content: string;
82
+ language?: string;
83
+ themes?: CreateShikiHighlighterOptions['themes'] | Record<string, 'stainless-docs-json'>;
84
+ }) {
85
+ return highlighter.codeToHtml(content, {
86
+ lang: language ?? 'javascript',
87
+ themes:
88
+ // Default to user-provided themes except in case of json
89
+ themes ??
90
+ (language === 'JSON'
91
+ ? { light: 'stainless-docs-json', dark: 'stainless-docs-json' }
92
+ : HIGHLIGHT_THEMES) ??
93
+ {},
94
+ });
95
+ }
96
+
97
+ export async function highlight(content: string, language?: string) {
98
+ const highlighter = await getAstroHighlighter();
99
+ return runHighlight({ highlighter, content, language });
100
+ }
@@ -0,0 +1,39 @@
1
+ import { createMarkdownProcessor, type MarkdownProcessor } from '@astrojs/markdown-remark';
2
+ import remarkGfmAlerts from 'remark-github-alerts';
3
+ import { HIGHLIGHT_THEMES } from 'virtual:stl-starlight-virtual-module';
4
+
5
+ // singleton
6
+ let astroMarkdownProcessor: MarkdownProcessor;
7
+ async function getAstroMarkdown() {
8
+ if (!astroMarkdownProcessor) {
9
+ astroMarkdownProcessor = await createMarkdownProcessor({
10
+ gfm: true,
11
+ remarkPlugins: [remarkGfmAlerts],
12
+ shikiConfig: { themes: HIGHLIGHT_THEMES },
13
+ });
14
+ }
15
+
16
+ return astroMarkdownProcessor;
17
+ }
18
+
19
+ export async function astroMarkdownRender(content: string) {
20
+ const md = await getAstroMarkdown();
21
+ const output = await md.render(content);
22
+
23
+ // Map GFM callouts to the closest Starlight equivalent
24
+ // TODO: this sucks; we should be rendering via ui-primitives callouts instead of ugly theme-incompatible starlight ones
25
+ output.code = output.code
26
+ .replaceAll('markdown-alert-caution', 'markdown-alert-danger')
27
+ .replaceAll('markdown-alert-warning', 'markdown-alert-caution')
28
+ .replaceAll('markdown-alert-important', 'markdown-alert-caution')
29
+ .replaceAll('markdown-alert-title', 'starlight-aside__title')
30
+ .replaceAll('markdown-alert-', 'starlight-aside--')
31
+ .replaceAll('markdown-alert', 'starlight-aside');
32
+
33
+ return output;
34
+ }
35
+
36
+ export async function astroMarkdownRenderText(content: string) {
37
+ const result = await astroMarkdownRender(content);
38
+ return result.code;
39
+ }
@@ -1,5 +1,7 @@
1
1
  import type { TransformRequestSnippetFn } from '@stainless-api/docs-ui/components/sdk';
2
+ import type { AppComponents } from '@stainless-api/docs-ui/contexts/component';
2
3
 
3
4
  export type StlStarlightMiddleware = {
4
5
  transformRequestSnippet?: TransformRequestSnippetFn;
6
+ componentOverrides?: Partial<AppComponents>;
5
7
  };