@stainless-api/docs 0.1.0-beta.129 → 0.1.0-beta.130

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 (61) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/ambient.d.ts +6 -0
  3. package/eslint-suppressions.json +0 -5
  4. package/package.json +19 -15
  5. package/plugin/generateAPIReferenceLink.ts +0 -40
  6. package/plugin/index.ts +12 -0
  7. package/plugin/loadPluginConfig.ts +36 -5
  8. package/plugin/markdown/highlighter.ts +1 -1
  9. package/plugin/react/Routing.tsx +1 -85
  10. package/plugin/referencePlaceholderUtils.ts +1 -1
  11. package/plugin/routes/llms.ts +186 -0
  12. package/plugin/sidebar-utils/sidebar-builder.ts +2 -7
  13. package/plugin/specs/FileCache.ts +1 -1
  14. package/plugin/specs/index.ts +1 -6
  15. package/plugin/vendor/preview.worker.docs.js +9001 -8694
  16. package/shared/virtualModule.ts +1 -9
  17. package/stl-docs/chat/docs-chat-handler.ts +18 -0
  18. package/stl-docs/chat/hook.ts +215 -0
  19. package/stl-docs/chat/schemas.ts +70 -0
  20. package/stl-docs/chat/stainless-handler/index.ts +126 -0
  21. package/stl-docs/chat/stream-util.ts +16 -0
  22. package/stl-docs/chat/ui/AiChat.module.css +591 -0
  23. package/stl-docs/chat/ui/AiChat.tsx +188 -0
  24. package/stl-docs/chat/ui/Trigger.tsx +154 -0
  25. package/stl-docs/chat/ui/components/ChatControls.tsx +51 -0
  26. package/stl-docs/chat/ui/components/ChatEmpty.tsx +42 -0
  27. package/stl-docs/chat/ui/components/ChatLog.tsx +96 -0
  28. package/stl-docs/chat/ui/components/ChatMessage.tsx +47 -0
  29. package/stl-docs/chat/ui/components/CodeBlock.tsx +33 -0
  30. package/stl-docs/chat/ui/components/MessageFeedback.tsx +109 -0
  31. package/stl-docs/chat/ui/components/Table.tsx +15 -0
  32. package/stl-docs/chat/ui/components/ToolCall.tsx +34 -0
  33. package/stl-docs/chat/ui/components/hljs-github.css +81 -0
  34. package/stl-docs/chat/ui/scroll-manager.ts +86 -0
  35. package/stl-docs/chat/ui/types.ts +45 -0
  36. package/stl-docs/components/AiChatIsland.tsx +14 -12
  37. package/stl-docs/components/PageFrame.astro +7 -4
  38. package/stl-docs/components/headers/DefaultHeader.astro +2 -2
  39. package/stl-docs/components/headers/StackedHeader.astro +2 -2
  40. package/stl-docs/components/mintlify-compat/Accordion.astro +2 -2
  41. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +0 -4
  42. package/stl-docs/components/mintlify-compat/Columns.astro +2 -2
  43. package/stl-docs/components/mintlify-compat/Frame.astro +2 -2
  44. package/stl-docs/components/mintlify-compat/Tab.astro +2 -2
  45. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +2 -2
  46. package/stl-docs/components/mintlify-compat/callouts/Check.astro +0 -4
  47. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +0 -4
  48. package/stl-docs/components/mintlify-compat/callouts/Info.astro +0 -4
  49. package/stl-docs/components/mintlify-compat/callouts/Note.astro +0 -4
  50. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +0 -4
  51. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +0 -4
  52. package/stl-docs/components/nav-tabs/NavDropdown.astro +1 -1
  53. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +2 -2
  54. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +2 -2
  55. package/stl-docs/components/pagination/util.ts +3 -3
  56. package/stl-docs/disableCalloutSyntax.ts +1 -1
  57. package/stl-docs/index.ts +14 -28
  58. package/stl-docs/loadStlDocsConfig.ts +15 -4
  59. package/stl-docs/proseSearchIndexing.ts +2 -6
  60. package/virtual-module.d.ts +8 -17
  61. package/stl-docs/components/ClientRouterHead.astro +0 -41
package/stl-docs/index.ts CHANGED
@@ -76,7 +76,7 @@ function stainlessDocsStarlightIntegration(config: NormalizedStainlessDocsConfig
76
76
  disableCalloutSyntaxStarlightPlugin,
77
77
  ];
78
78
 
79
- if (config.apiReference !== null) {
79
+ if (config.apiReference) {
80
80
  plugins.push(
81
81
  stainlessStarlight({
82
82
  ...config.apiReference,
@@ -162,8 +162,6 @@ function stainlessDocsIntegration(
162
162
  config: NormalizedStainlessDocsConfig,
163
163
  apiReferenceBasePath: string | null,
164
164
  ): AstroIntegration {
165
- // The '\0' prefix tells Vite “this is a virtual module” and prevents it from being resolved again.
166
- const resolveVirtualModuleId = (id: string) => `\0${id}`;
167
165
  let redirects: NormalizedRedirectConfig | null = null;
168
166
 
169
167
  return {
@@ -196,56 +194,44 @@ function stainlessDocsIntegration(
196
194
  FONTS: getFontRoles(config.fonts),
197
195
  LINK_GROUP_TITLES_TO_OVERVIEW_PAGES: config.linkGroupTitlesToOverviewPages,
198
196
  RENDER_CREDITS: config.credits,
197
+ SITE_TITLE: config.siteTitle,
198
+ ENABLE_AI_CHAT: !!config.aiChat,
199
199
  } satisfies typeof StlDocsVirtualModule),
200
-
201
- 'virtual:stl-docs/components/AiChat.tsx': `
202
- ${
203
- config.aiChat
204
- ? `export { default } from ${JSON.stringify(config.aiChat.chatComponentPath)};`
205
- : // export null when no AI chat component is provided
206
- `export default null;`
207
- }
208
- export const STAINLESS_PROJECT = ${config.apiReference ? JSON.stringify(config.apiReference.stainlessProject) : 'undefined'};
209
- `,
210
200
  }),
211
201
  );
212
202
 
213
203
  updateConfig({
214
204
  fonts: [...flattenFonts(config.fonts), ...(astroConfig?.fonts ?? [])],
215
205
  vite: {
206
+ define: {
207
+ __STLDOCS_HAS_API_REFERENCE__: !!config.apiReference,
208
+ __STLDOCS_ENABLE_AI_CHAT__: !!config.aiChat,
209
+ },
216
210
  plugins: [
217
211
  {
218
- name: 'stl-docs-vite',
212
+ name: 'stl-docs-virtual-modules',
219
213
  resolveId(id) {
220
- if (virtualModules.has(id)) return resolveVirtualModuleId(id);
214
+ // The '\0' prefix tells Vite “this is a virtual module” and prevents it from being resolved again.
215
+ if (virtualModules.has(id)) return `\0${id}`;
221
216
  },
222
217
  load(id) {
223
218
  const bare = id.replace(/^\0/, '');
224
219
  if (virtualModules.has(bare)) return virtualModules.get(bare);
225
220
  },
226
221
  },
222
+ // Separate plugin for the examples because it has async resolution; not a simple string
223
+ // like the above plugins
227
224
  ...(config.aiChat
228
225
  ? [
229
226
  await generateExamplesPlugin({
230
227
  projectName: config.apiReference?.stainlessProject ?? undefined,
231
228
  logger,
232
- exampleOverrides: config.aiChat?.exampleOverrides,
229
+ exampleOverrides:
230
+ typeof config.aiChat === 'object' ? config.aiChat.exampleOverrides : undefined,
233
231
  }),
234
232
  ]
235
233
  : []),
236
234
  ],
237
- optimizeDeps: {
238
- include: config.aiChat
239
- ? [
240
- '@stainless-api/docs-ai-chat > @stainless-api/ai-chat > lucide-react',
241
- '@stainless-api/docs-ai-chat > @stainless-api/ai-chat > motion',
242
- '@stainless-api/docs-ai-chat > @stainless-api/ai-chat > motion > framer-motion',
243
- '@stainless-api/docs-ai-chat > @stainless-api/ai-chat > react-markdown',
244
- '@stainless-api/docs-ai-chat > @stainless-api/ai-chat > react-syntax-highlighter',
245
- '@stainless-api/docs-ai-chat > @stainless-api/ai-chat > remark-gfm',
246
- ]
247
- : [],
248
- },
249
235
  },
250
236
  build: {
251
237
  ...astroConfig.build,
@@ -80,10 +80,7 @@ export type StainlessDocsUserConfig = {
80
80
  */
81
81
  disableProseMarkdownRendering?: boolean;
82
82
  disableStainlessProseIndexing?: boolean;
83
- aiChat?: {
84
- chatComponentPath: string;
85
- exampleOverrides?: ExamplePromptResponse;
86
- };
83
+ aiChat?: { exampleOverrides?: ExamplePromptResponse } | true;
87
84
  /**
88
85
  * Whether to link group titles to overview pages. Note: overview pages must already be present in the sidebar for this to work.
89
86
  *
@@ -140,6 +137,19 @@ function normalizeRouteMiddleware(userConfig: StainlessDocsUserConfig) {
140
137
  return entry;
141
138
  }
142
139
 
140
+ function normalizeSiteTitle(userConfig: StainlessDocsUserConfig) {
141
+ if (typeof userConfig.title === 'string') {
142
+ return userConfig.title;
143
+ }
144
+ if (typeof userConfig.title === 'object') {
145
+ const firstValue = Object.values(userConfig.title)[0];
146
+ if (typeof firstValue === 'string') {
147
+ return firstValue;
148
+ }
149
+ }
150
+ throw new Error('Site title provided in config is not valid.');
151
+ }
152
+
143
153
  function normalizeConfig(userConfig: StainlessDocsUserConfig) {
144
154
  const splitTabsEnabled = areSplitTabsEnabled(userConfig);
145
155
 
@@ -189,6 +199,7 @@ function normalizeConfig(userConfig: StainlessDocsUserConfig) {
189
199
  aiChat: userConfig.experimental?.aiChat,
190
200
  linkGroupTitlesToOverviewPages: userConfig.experimental?.linkGroupTitlesToOverviewPages ?? false,
191
201
  credits: !userConfig.disableCredits,
202
+ siteTitle: normalizeSiteTitle(userConfig),
192
203
  };
193
204
 
194
205
  return configWithDefaults;
@@ -103,7 +103,7 @@ function chunkTextByWords(text: string): string[] {
103
103
  return chunks;
104
104
  }
105
105
 
106
- export type IndexEntry = {
106
+ type IndexEntry = {
107
107
  chunk: { id: string; index: number; total: number };
108
108
  id: string;
109
109
  tag: string;
@@ -123,11 +123,7 @@ const DEFAULT_PATTERN = 'h1, h2, h3, h4, h5, h6, p, li, pre code';
123
123
  * - Extracts language metadata from code blocks (class="language-js")
124
124
  * - Uses word-based chunking with sentence boundary detection
125
125
  */
126
- export function* indexHTML(
127
- content: string,
128
- root = DEFAULT_ROOT,
129
- pattern = DEFAULT_PATTERN,
130
- ): Generator<IndexEntry> {
126
+ function* indexHTML(content: string, root = DEFAULT_ROOT, pattern = DEFAULT_PATTERN): Generator<IndexEntry> {
131
127
  const $ = cheerio.load(content);
132
128
  const matches = $(root).find(pattern);
133
129
 
@@ -21,6 +21,8 @@ declare module 'virtual:stl-starlight-virtual-module' {
21
21
  export const MIDDLEWARE: StlStarlightMiddleware;
22
22
  export const ENABLE_CONTEXT_MENU: boolean;
23
23
  export const STAINLESS_PROJECT: string | undefined;
24
+ export const LLMS_TXT_DESCRIPTION: string | null;
25
+ export const LLMS_TXT_DETAIL_THRESHOLD: number;
24
26
  }
25
27
 
26
28
  declare module 'virtual:stl-docs-virtual-module' {
@@ -61,26 +63,12 @@ declare module 'virtual:stl-docs-virtual-module' {
61
63
  additional?: FontConfig[];
62
64
  };
63
65
  export const RENDER_CREDITS: boolean;
64
- }
65
-
66
- declare module 'virtual:stl-docs/components/AiChat.tsx' {
67
- const AiChatComponent:
68
- | import('react').ComponentType<{
69
- projectId: string;
70
- language: import('@stainless-api/docs-ui/routing').DocsLanguage | undefined;
71
- siteTitle: string | undefined;
72
- }>
73
- | null;
74
- export default AiChatComponent;
75
- export const STAINLESS_PROJECT: string | undefined;
66
+ export const SITE_TITLE: string;
67
+ export const ENABLE_AI_CHAT: boolean;
76
68
  }
77
69
 
78
70
  declare module 'virtual:stl-docs-ai-chat-examples' {
79
- export type ExamplePrompt = {
80
- longPrompt: string;
81
- shortPrompt: string;
82
- icon: React.ComponentType;
83
- };
71
+ import type { ExamplePrompt } from './stl-docs/chat/ui/types';
84
72
 
85
73
  export const examples: ExamplePrompt[] | undefined;
86
74
  }
@@ -110,3 +98,6 @@ declare module 'virtual:stl-starlight-reference-sidebars' {
110
98
 
111
99
  export const sidebars: GeneratedSidebarDef[];
112
100
  }
101
+
102
+ declare const __STLDOCS_HAS_API_REFERENCE__: boolean;
103
+ declare const __STLDOCS_ENABLE_AI_CHAT__: boolean;
@@ -1,41 +0,0 @@
1
- ---
2
- import { ClientRouter } from 'astro:transitions';
3
- import Default from '@astrojs/starlight/components/Head.astro';
4
- ---
5
-
6
- <style is:global>
7
- /* Disable native View Transitions animations */
8
- :root::view-transition-old(root),
9
- :root::view-transition-new(root) {
10
- animation: none;
11
- }
12
- :root::view-transition-group(root) {
13
- animation-duration: 0s;
14
- }
15
- </style>
16
-
17
- <script>
18
- console.log('[EXPERIMENTAL] using client router');
19
- </script>
20
- <script>
21
- function setNavLinksMode(doc: Document) {
22
- let mode = localStorage.getItem('stl-nav-links-mode');
23
- // initial guess
24
- if (mode === null) {
25
- mode = window.innerWidth < 1000 ? 'mobile' : 'desktop';
26
- }
27
- doc.documentElement.classList.add('stl-nav-links-mode-' + mode);
28
- }
29
-
30
- setNavLinksMode(document);
31
-
32
- // https://docs.astro.build/en/guides/view-transitions/#astrobefore-swap
33
-
34
- document.addEventListener('astro:before-swap', (event) => {
35
- setNavLinksMode(event.newDocument);
36
- });
37
- </script>
38
-
39
- <ClientRouter />
40
-
41
- <Default />