@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.
- package/CHANGELOG.md +24 -0
- package/ambient.d.ts +6 -0
- package/eslint-suppressions.json +0 -5
- package/package.json +19 -15
- package/plugin/generateAPIReferenceLink.ts +0 -40
- package/plugin/index.ts +12 -0
- package/plugin/loadPluginConfig.ts +36 -5
- package/plugin/markdown/highlighter.ts +1 -1
- package/plugin/react/Routing.tsx +1 -85
- package/plugin/referencePlaceholderUtils.ts +1 -1
- package/plugin/routes/llms.ts +186 -0
- package/plugin/sidebar-utils/sidebar-builder.ts +2 -7
- package/plugin/specs/FileCache.ts +1 -1
- package/plugin/specs/index.ts +1 -6
- package/plugin/vendor/preview.worker.docs.js +9001 -8694
- package/shared/virtualModule.ts +1 -9
- package/stl-docs/chat/docs-chat-handler.ts +18 -0
- package/stl-docs/chat/hook.ts +215 -0
- package/stl-docs/chat/schemas.ts +70 -0
- package/stl-docs/chat/stainless-handler/index.ts +126 -0
- package/stl-docs/chat/stream-util.ts +16 -0
- package/stl-docs/chat/ui/AiChat.module.css +591 -0
- package/stl-docs/chat/ui/AiChat.tsx +188 -0
- package/stl-docs/chat/ui/Trigger.tsx +154 -0
- package/stl-docs/chat/ui/components/ChatControls.tsx +51 -0
- package/stl-docs/chat/ui/components/ChatEmpty.tsx +42 -0
- package/stl-docs/chat/ui/components/ChatLog.tsx +96 -0
- package/stl-docs/chat/ui/components/ChatMessage.tsx +47 -0
- package/stl-docs/chat/ui/components/CodeBlock.tsx +33 -0
- package/stl-docs/chat/ui/components/MessageFeedback.tsx +109 -0
- package/stl-docs/chat/ui/components/Table.tsx +15 -0
- package/stl-docs/chat/ui/components/ToolCall.tsx +34 -0
- package/stl-docs/chat/ui/components/hljs-github.css +81 -0
- package/stl-docs/chat/ui/scroll-manager.ts +86 -0
- package/stl-docs/chat/ui/types.ts +45 -0
- package/stl-docs/components/AiChatIsland.tsx +14 -12
- package/stl-docs/components/PageFrame.astro +7 -4
- package/stl-docs/components/headers/DefaultHeader.astro +2 -2
- package/stl-docs/components/headers/StackedHeader.astro +2 -2
- package/stl-docs/components/mintlify-compat/Accordion.astro +2 -2
- package/stl-docs/components/mintlify-compat/AccordionGroup.astro +0 -4
- package/stl-docs/components/mintlify-compat/Columns.astro +2 -2
- package/stl-docs/components/mintlify-compat/Frame.astro +2 -2
- package/stl-docs/components/mintlify-compat/Tab.astro +2 -2
- package/stl-docs/components/mintlify-compat/callouts/Callout.astro +2 -2
- package/stl-docs/components/mintlify-compat/callouts/Check.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Danger.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Info.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Note.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Tip.astro +0 -4
- package/stl-docs/components/mintlify-compat/callouts/Warning.astro +0 -4
- package/stl-docs/components/nav-tabs/NavDropdown.astro +1 -1
- package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +2 -2
- package/stl-docs/components/pagination/PaginationLinkQuiet.astro +2 -2
- package/stl-docs/components/pagination/util.ts +3 -3
- package/stl-docs/disableCalloutSyntax.ts +1 -1
- package/stl-docs/index.ts +14 -28
- package/stl-docs/loadStlDocsConfig.ts +15 -4
- package/stl-docs/proseSearchIndexing.ts +2 -6
- package/virtual-module.d.ts +8 -17
- 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
|
|
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-
|
|
212
|
+
name: 'stl-docs-virtual-modules',
|
|
219
213
|
resolveId(id) {
|
|
220
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
package/virtual-module.d.ts
CHANGED
|
@@ -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
|
-
|
|
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 />
|