@stainless-api/docs 0.1.0-beta.13 → 0.1.0-beta.131

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 (188) hide show
  1. package/CHANGELOG.md +1110 -0
  2. package/ambient.d.ts +6 -0
  3. package/eslint-suppressions.json +90 -0
  4. package/{eslint.config.js → eslint.config.ts} +0 -2
  5. package/locals.d.ts +17 -0
  6. package/package.json +62 -44
  7. package/playground-virtual-modules.d.ts +96 -0
  8. package/plugin/assets/languages/cli.svg +14 -0
  9. package/plugin/assets/languages/csharp.svg +1 -0
  10. package/plugin/assets/languages/php.svg +4 -0
  11. package/plugin/buildAlgoliaIndex.ts +40 -39
  12. package/plugin/components/MethodDescription.tsx +54 -0
  13. package/plugin/components/RequestBuilder/ParamEditor.tsx +55 -0
  14. package/plugin/components/RequestBuilder/SnippetStainlessIsland.tsx +107 -0
  15. package/plugin/components/RequestBuilder/index.tsx +40 -0
  16. package/plugin/components/RequestBuilder/props.ts +9 -0
  17. package/plugin/components/RequestBuilder/spec-helpers.ts +47 -0
  18. package/plugin/components/RequestBuilder/styles.css +67 -0
  19. package/plugin/components/SDKSelect.astro +18 -111
  20. package/plugin/components/SnippetCode.tsx +112 -70
  21. package/plugin/components/StainlessIslands.tsx +126 -0
  22. package/plugin/components/search/SearchAlgolia.astro +46 -29
  23. package/plugin/components/search/SearchIsland.tsx +61 -37
  24. package/plugin/generateAPIReferenceLink.ts +0 -40
  25. package/plugin/globalJs/ai-dropdown-options.ts +248 -0
  26. package/plugin/globalJs/code-snippets.ts +45 -16
  27. package/plugin/globalJs/copy.ts +115 -27
  28. package/plugin/globalJs/create-playground.shim.ts +3 -0
  29. package/plugin/globalJs/method-descriptions.ts +33 -0
  30. package/plugin/globalJs/navigation.ts +24 -44
  31. package/plugin/globalJs/playground-data.shim.ts +1 -0
  32. package/plugin/globalJs/playground-data.ts +14 -0
  33. package/plugin/globalJs/summary-selection-tweak.ts +29 -0
  34. package/plugin/helpers/generateDocsRoutes.ts +59 -0
  35. package/plugin/helpers/multiSpec.ts +8 -0
  36. package/plugin/index.ts +317 -141
  37. package/plugin/languages.ts +8 -2
  38. package/plugin/loadPluginConfig.ts +284 -109
  39. package/plugin/markdown/highlighter.ts +100 -0
  40. package/plugin/markdown/index.ts +39 -0
  41. package/plugin/middlewareBuilder/stainlessMiddleware.d.ts +3 -1
  42. package/plugin/react/Routing.tsx +98 -263
  43. package/plugin/referencePlaceholderUtils.ts +17 -14
  44. package/plugin/replaceSidebarPlaceholderMiddleware.ts +39 -35
  45. package/plugin/routes/Docs.astro +72 -111
  46. package/plugin/routes/DocsStatic.astro +6 -5
  47. package/plugin/routes/Overview.astro +46 -22
  48. package/plugin/routes/llms.ts +186 -0
  49. package/plugin/routes/markdown.ts +13 -12
  50. package/plugin/{cms → sidebar-utils}/sidebar-builder.ts +84 -69
  51. package/plugin/specs/FileCache.ts +99 -0
  52. package/plugin/specs/fetchSpecSSR.ts +27 -0
  53. package/plugin/specs/generateSpec.ts +112 -0
  54. package/plugin/specs/index.ts +132 -0
  55. package/plugin/specs/inputResolver.ts +148 -0
  56. package/plugin/{cms → specs}/worker.ts +82 -5
  57. package/plugin/vendor/preview.worker.docs.js +27121 -16890
  58. package/plugin/vendor/templates/cli.md +1 -0
  59. package/plugin/vendor/templates/go.md +4 -2
  60. package/plugin/vendor/templates/java.md +5 -1
  61. package/plugin/vendor/templates/kotlin.md +5 -1
  62. package/plugin/vendor/templates/node.md +4 -2
  63. package/plugin/vendor/templates/python.md +4 -2
  64. package/plugin/vendor/templates/ruby.md +4 -2
  65. package/plugin/vendor/templates/terraform.md +1 -1
  66. package/plugin/vendor/templates/typescript.md +3 -1
  67. package/resolveSrcFile.ts +10 -0
  68. package/scripts/vendor_deps.ts +5 -5
  69. package/shared/conditionalIntegration.ts +28 -0
  70. package/shared/getProsePages.ts +41 -0
  71. package/shared/getSharedLogger.ts +15 -0
  72. package/shared/terminalUtils.ts +3 -0
  73. package/shared/virtualModule.ts +46 -1
  74. package/src/content.config.ts +9 -0
  75. package/stl-docs/aiChatExamples.ts +95 -0
  76. package/stl-docs/chat/docs-chat-handler.ts +18 -0
  77. package/stl-docs/chat/hook.ts +215 -0
  78. package/stl-docs/chat/schemas.ts +70 -0
  79. package/stl-docs/chat/stainless-handler/index.ts +126 -0
  80. package/stl-docs/chat/stream-util.ts +16 -0
  81. package/stl-docs/chat/ui/AiChat.module.css +591 -0
  82. package/stl-docs/chat/ui/AiChat.tsx +188 -0
  83. package/stl-docs/chat/ui/Trigger.tsx +154 -0
  84. package/stl-docs/chat/ui/components/ChatControls.tsx +51 -0
  85. package/stl-docs/chat/ui/components/ChatEmpty.tsx +42 -0
  86. package/stl-docs/chat/ui/components/ChatLog.tsx +96 -0
  87. package/stl-docs/chat/ui/components/ChatMessage.tsx +47 -0
  88. package/stl-docs/chat/ui/components/CodeBlock.tsx +33 -0
  89. package/stl-docs/chat/ui/components/MessageFeedback.tsx +109 -0
  90. package/stl-docs/chat/ui/components/Table.tsx +15 -0
  91. package/stl-docs/chat/ui/components/ToolCall.tsx +34 -0
  92. package/stl-docs/chat/ui/components/hljs-github.css +81 -0
  93. package/stl-docs/chat/ui/scroll-manager.ts +86 -0
  94. package/stl-docs/chat/ui/types.ts +45 -0
  95. package/stl-docs/components/AIDropdown.tsx +63 -0
  96. package/stl-docs/components/AiChatIsland.tsx +16 -0
  97. package/stl-docs/components/{content-panel/ContentBreadcrumbs.tsx → ContentBreadcrumbs.tsx} +2 -2
  98. package/stl-docs/components/ContentPanel.astro +9 -0
  99. package/stl-docs/components/Footer.astro +89 -0
  100. package/stl-docs/components/Head.astro +20 -0
  101. package/stl-docs/components/Header.astro +3 -9
  102. package/stl-docs/components/PageFrame.astro +37 -0
  103. package/stl-docs/components/PageSidebar.astro +11 -0
  104. package/stl-docs/components/PageTitle.astro +82 -0
  105. package/stl-docs/components/StainlessLogo.svg +4 -0
  106. package/stl-docs/components/ThemeProvider.astro +36 -0
  107. package/stl-docs/components/ThemeSelect.astro +84 -146
  108. package/stl-docs/components/TwoColumnContent.astro +2 -0
  109. package/stl-docs/components/headers/DefaultHeader.astro +6 -8
  110. package/stl-docs/components/headers/StackedHeader.astro +10 -53
  111. package/stl-docs/components/icons/chat-gpt.tsx +2 -2
  112. package/stl-docs/components/icons/cursor.tsx +10 -0
  113. package/stl-docs/components/icons/gemini.tsx +19 -0
  114. package/stl-docs/components/icons/markdown.tsx +1 -1
  115. package/stl-docs/components/index.ts +1 -0
  116. package/stl-docs/components/mintlify-compat/Accordion.astro +2 -2
  117. package/stl-docs/components/mintlify-compat/AccordionGroup.astro +0 -4
  118. package/stl-docs/components/mintlify-compat/Columns.astro +2 -2
  119. package/stl-docs/components/mintlify-compat/Frame.astro +6 -6
  120. package/stl-docs/components/mintlify-compat/Tab.astro +2 -2
  121. package/stl-docs/components/mintlify-compat/callouts/Callout.astro +2 -2
  122. package/stl-docs/components/mintlify-compat/callouts/Check.astro +0 -4
  123. package/stl-docs/components/mintlify-compat/callouts/Danger.astro +0 -4
  124. package/stl-docs/components/mintlify-compat/callouts/Info.astro +0 -4
  125. package/stl-docs/components/mintlify-compat/callouts/Note.astro +0 -4
  126. package/stl-docs/components/mintlify-compat/callouts/Tip.astro +0 -4
  127. package/stl-docs/components/mintlify-compat/callouts/Warning.astro +0 -4
  128. package/stl-docs/components/mintlify-compat/card.css +4 -4
  129. package/stl-docs/components/mintlify-compat/index.ts +2 -4
  130. package/stl-docs/components/nav-tabs/NavDropdown.astro +38 -77
  131. package/stl-docs/components/nav-tabs/NavTabs.astro +81 -81
  132. package/stl-docs/components/nav-tabs/SecondaryNavTabs.astro +1 -2
  133. package/stl-docs/components/nav-tabs/buildNavLinks.ts +5 -2
  134. package/stl-docs/components/pagination/HomeLink.astro +10 -0
  135. package/stl-docs/components/pagination/Pagination.astro +177 -0
  136. package/stl-docs/components/pagination/PaginationLinkEmphasized.astro +22 -0
  137. package/stl-docs/components/pagination/PaginationLinkQuiet.astro +13 -0
  138. package/stl-docs/components/pagination/util.ts +71 -0
  139. package/stl-docs/components/scripts.ts +1 -0
  140. package/stl-docs/components/sidebars/BaseSidebar.astro +80 -2
  141. package/stl-docs/components/sidebars/SidebarWithComponents.tsx +10 -0
  142. package/stl-docs/components/sidebars/convertAstroSidebarToStl.tsx +62 -0
  143. package/stl-docs/disableCalloutSyntax.ts +36 -0
  144. package/stl-docs/fonts.ts +186 -0
  145. package/stl-docs/index.ts +176 -58
  146. package/stl-docs/loadStlDocsConfig.ts +73 -8
  147. package/stl-docs/proseDocSync.test.ts +74 -0
  148. package/stl-docs/proseDocSync.ts +344 -0
  149. package/stl-docs/proseMarkdown/proseMarkdownIntegration.ts +53 -0
  150. package/stl-docs/proseMarkdown/proseMarkdownMiddleware.ts +41 -0
  151. package/stl-docs/proseMarkdown/toMarkdown.ts +158 -0
  152. package/stl-docs/proseSearchIndexing.ts +218 -0
  153. package/stl-docs/tabsMiddleware.ts +14 -5
  154. package/styles/code.css +53 -49
  155. package/styles/links.css +2 -37
  156. package/styles/method-descriptions.css +36 -0
  157. package/styles/overrides.css +28 -46
  158. package/styles/page.css +228 -38
  159. package/styles/sdk_select.css +9 -6
  160. package/styles/search.css +11 -21
  161. package/styles/sidebar.css +28 -215
  162. package/styles/{variables.css → sl-variables.css} +4 -8
  163. package/styles/stldocs-variables.css +6 -0
  164. package/styles/toc.css +19 -8
  165. package/theme.css +11 -9
  166. package/tsconfig.json +1 -4
  167. package/virtual-module.d.ts +66 -8
  168. package/components/variables.css +0 -112
  169. package/plugin/cms/client.ts +0 -62
  170. package/plugin/cms/server.ts +0 -268
  171. package/plugin/globalJs/ai-dropdown.ts +0 -57
  172. package/stl-docs/components/APIReferenceAIDropdown.tsx +0 -58
  173. package/stl-docs/components/ClientRouterHead.astro +0 -41
  174. package/stl-docs/components/content-panel/ContentPanel.astro +0 -69
  175. package/stl-docs/components/content-panel/ProseAIDropdown.tsx +0 -55
  176. package/stl-docs/components/headers/SplashMobileMenuToggle.astro +0 -49
  177. package/stl-docs/components/mintlify-compat/Step.astro +0 -56
  178. package/stl-docs/components/mintlify-compat/Steps.astro +0 -15
  179. package/styles/fonts.css +0 -68
  180. /package/{plugin/assets → assets}/fonts/geist/OFL.txt +0 -0
  181. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin-ext.woff2 +0 -0
  182. /package/{plugin/assets → assets}/fonts/geist/geist-italic-latin.woff2 +0 -0
  183. /package/{plugin/assets → assets}/fonts/geist/geist-latin-ext.woff2 +0 -0
  184. /package/{plugin/assets → assets}/fonts/geist/geist-latin.woff2 +0 -0
  185. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin-ext.woff2 +0 -0
  186. /package/{plugin/assets → assets}/fonts/geist/geist-mono-italic-latin.woff2 +0 -0
  187. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin-ext.woff2 +0 -0
  188. /package/{plugin/assets → assets}/fonts/geist/geist-mono-latin.woff2 +0 -0
@@ -0,0 +1,10 @@
1
+ ---
2
+ import { base } from 'astro:config/client';
3
+ import { HomeIcon } from 'lucide-react';
4
+ import PaginationLinkQuiet from './PaginationLinkQuiet.astro';
5
+ ---
6
+
7
+ <PaginationLinkQuiet href={base}>
8
+ <HomeIcon slot="icon" />
9
+ Home
10
+ </PaginationLinkQuiet>
@@ -0,0 +1,177 @@
1
+ ---
2
+ import HomeLink from './HomeLink.astro';
3
+ import PaginationLinkEmphasized from './PaginationLinkEmphasized.astro';
4
+
5
+ import { getPrevNextPage } from './util';
6
+ import config from 'virtual:starlight/user-config';
7
+ const { prev, next } = (await getPrevNextPage(Astro.locals.starlightRoute, config.pagination)) ?? {};
8
+ ---
9
+
10
+ {
11
+ next || prev ? (
12
+ <div class="pagination-links print:hidden stl-ui-not-prose">
13
+ {/* Previous */}
14
+ {!prev && <HomeLink />}
15
+ {/* TODO: intelligently decide whether or not to emphasize the previous page - including user config option (page level?) */}
16
+ {/* {prev && next && (
17
+ <PaginationLinkQuiet href={prev.href}>
18
+ <ChevronLeftIcon slot="icon" />
19
+ Previous
20
+ </PaginationLinkQuiet>
21
+ )} */}
22
+ {prev && (
23
+ <PaginationLinkEmphasized href={prev.href} direction="prev">
24
+ <h2 slot="page-title">{prev.label}</h2>
25
+ {prev.description && <p slot="page-description">{prev.description}</p>}
26
+ </PaginationLinkEmphasized>
27
+ )}
28
+
29
+ {/* Next */}
30
+ {!next && <HomeLink />}
31
+ {next && (
32
+ <PaginationLinkEmphasized href={next.href} direction="next">
33
+ <h2 slot="page-title">{next.label}</h2>
34
+ {next.description && <p slot="page-description">{next.description}</p>}
35
+ </PaginationLinkEmphasized>
36
+ )}
37
+ </div>
38
+ ) : null
39
+ }
40
+
41
+ <style is:global>
42
+ @layer starlight.core {
43
+ .pagination-links,
44
+ .pagination-links a,
45
+ .pagination-links a:hover,
46
+ .pagination-links a[rel='next'],
47
+ .link-title {
48
+ all: revert-layer;
49
+ }
50
+ }
51
+
52
+ .pagination-links {
53
+ --stl-ui-pagination-padding: 8px;
54
+ --stl-ui-pagination-border-radius-inner: var(--stl-ui-layout-border-radius-sml);
55
+ --stl-ui-pagination-border-radius-outer: calc(
56
+ var(--stl-ui-pagination-border-radius-inner) + var(--stl-ui-pagination-padding)
57
+ );
58
+
59
+ padding: var(--stl-ui-pagination-padding);
60
+ background-color: var(--stl-color-faint-background);
61
+ border: 1px solid var(--stl-color-border);
62
+ border-radius: var(--stl-ui-pagination-border-radius-outer);
63
+
64
+ font-size: var(--stl-typography-scale-sm);
65
+ letter-spacing: normal;
66
+
67
+ display: flex;
68
+ gap: 8px;
69
+
70
+ color: inherit; /* stl-ui-not-prose sets color: initial */
71
+
72
+ a {
73
+ border-radius: var(--stl-ui-pagination-border-radius-inner);
74
+ }
75
+ }
76
+
77
+ .pagination-links__link {
78
+ display: flex;
79
+ border-radius: var(--stl-ui-pagination-border-radius-inner);
80
+ padding: 8px 12px;
81
+ display: flex;
82
+ text-decoration: none;
83
+ align-items: center;
84
+ color: inherit;
85
+ }
86
+
87
+ .pagination-links__link--emphasized {
88
+ background-color: var(--stl-color-background);
89
+ border: 1px solid var(--stl-color-border);
90
+ flex: 1 1 50%;
91
+ gap: 12px;
92
+ }
93
+
94
+ .pagination-links__link--quiet {
95
+ flex: 0 1 auto;
96
+ }
97
+
98
+ .pagination-links__button {
99
+ display: flex;
100
+ align-items: center;
101
+ padding: 8px 14px;
102
+ font-weight: 500;
103
+ line-height: 1;
104
+
105
+ svg {
106
+ width: 16px;
107
+ height: 16px;
108
+ margin-block: -4px;
109
+ margin-inline-start: -6px;
110
+ margin-inline-end: 6px;
111
+ }
112
+
113
+ &.pagination-links__link--quiet {
114
+ padding-inline: 22px;
115
+ }
116
+ }
117
+
118
+ .pagination-links__link__divider {
119
+ border: 0;
120
+ border-inline-start: 1px solid var(--stl-color-border);
121
+ align-self: stretch;
122
+ }
123
+
124
+ .pagination-links__page-description {
125
+ padding-block: 4px;
126
+ padding-inline-start: 8px;
127
+ padding-inline-end: 2px;
128
+ line-height: 1.5;
129
+ flex: 1 1 50%;
130
+ width: 0;
131
+
132
+ h2,
133
+ p {
134
+ white-space: nowrap;
135
+ overflow: hidden;
136
+ text-overflow: ellipsis;
137
+ }
138
+ h2 {
139
+ font-size: inherit;
140
+ font-weight: 500;
141
+ }
142
+ p {
143
+ font-size: var(--stl-typography-scale-xs);
144
+ color: var(--stl-color-foreground-muted);
145
+ }
146
+ }
147
+ .pagination-links__link--quiet:hover {
148
+ background-color: var(--stl-color-background-hover);
149
+ }
150
+ .pagination-links__link--emphasized:hover {
151
+ border-color: var(--stl-color-border-strong);
152
+ .pagination-links__page-description h2 {
153
+ text-decoration: underline;
154
+ text-decoration-color: var(--stl-color-foreground-reduced);
155
+ }
156
+ }
157
+
158
+ /* “next” link runs the opposite direction of the “previous” link */
159
+ .pagination-links__link:last-child {
160
+ flex-direction: row-reverse;
161
+
162
+ &.pagination-links__button,
163
+ .pagination-links__button {
164
+ flex-direction: row-reverse;
165
+ svg {
166
+ margin-inline-start: 6px;
167
+ margin-inline-end: -6px;
168
+ }
169
+ }
170
+
171
+ .pagination-links__page-description {
172
+ padding-inline-start: 2px;
173
+ padding-inline-end: 8px;
174
+ text-align: right;
175
+ }
176
+ }
177
+ </style>
@@ -0,0 +1,22 @@
1
+ ---
2
+ import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
3
+ const { href, direction } = Astro.props;
4
+ type Props = {
5
+ href: string;
6
+ direction: 'prev' | 'next';
7
+ };
8
+ ---
9
+
10
+ <a href={href} class="pagination-links__link pagination-links__link--emphasized">
11
+ <div class="pagination-links__button">
12
+ {{ prev: <ChevronLeftIcon />, next: <ChevronRightIcon /> }[direction]}
13
+ <span>{{ prev: 'Previous', next: 'Next' }[direction]}</span>
14
+ </div>
15
+
16
+ <hr class="pagination-links__link__divider" />
17
+
18
+ <article class="pagination-links__page-description">
19
+ <slot name="page-title" />
20
+ <slot name="page-description" />
21
+ </article>
22
+ </a>
@@ -0,0 +1,13 @@
1
+ ---
2
+ const { href } = Astro.props;
3
+ type Props = {
4
+ href: string;
5
+ };
6
+ ---
7
+
8
+ <a href={href} class="pagination-links__link pagination-links__button pagination-links__link--quiet">
9
+ <slot name="icon" />
10
+ <span>
11
+ <slot />
12
+ </span>
13
+ </a>
@@ -0,0 +1,71 @@
1
+ import type { StarlightRouteData } from '@astrojs/starlight/route-data';
2
+ import { getCollection } from 'astro:content';
3
+
4
+ export type SidebarEntry = StarlightRouteData['sidebar'][number];
5
+ type SidebarLink = Extract<SidebarEntry, { type: 'link' }>;
6
+ type SidebarGroup = Extract<SidebarEntry, { type: 'group' }>;
7
+
8
+ const flattenSidebar = (sidebar: SidebarEntry[]): SidebarLink[] =>
9
+ sidebar.flatMap((e) => (e.type === 'group' ? flattenSidebar(e.entries) : e));
10
+
11
+ function findParentOfSidebarEntry(sidebar: SidebarEntry[], targetEntry: SidebarEntry): SidebarGroup | null {
12
+ for (const entry of sidebar) {
13
+ if (entry.type === 'group') {
14
+ if (entry.entries.includes(targetEntry)) {
15
+ return entry;
16
+ }
17
+ const foundInChild = findParentOfSidebarEntry(entry.entries, targetEntry);
18
+ if (foundInChild) {
19
+ return foundInChild;
20
+ }
21
+ }
22
+ }
23
+ return null;
24
+ }
25
+
26
+ export async function getPrevNextPage(page: StarlightRouteData, paginationEnabled: boolean) {
27
+ // TODO: respect user `next` / `prev` config from frontmatter the way starlight does
28
+
29
+ if (!paginationEnabled) return null;
30
+
31
+ const docsContent = await getCollection('docs');
32
+ const findSidebarLinkInContent = (link: SidebarLink) =>
33
+ docsContent.find((doc) => {
34
+ if (doc.id === 'index' && link.href === '/') return true;
35
+ return doc.id === link.href.replace(/^\//, '').replace(/\/$/, '');
36
+ });
37
+
38
+ const currentSidebar = page.sidebar;
39
+
40
+ const paginationSequence: (SidebarLink & { description?: string })[] = flattenSidebar(currentSidebar)
41
+ // Remove injected stl-mobile-only-sidebar-item links - TODO: better solution for this
42
+ .filter((link) => !(link.attrs.class ?? '').trim().split(/\s+/).includes('stl-mobile-only-sidebar-item'))
43
+ // Remove data-stldocs-method links from pagination sequence
44
+ .filter((link) => !link.attrs['data-stldocs-method'])
45
+ // Map data-stldocs-overview=readme links so that their name is not just “Overview”
46
+ .map((link) => {
47
+ if (link.attrs['data-stldocs-overview'] && link.label === 'Overview') {
48
+ const parent = findParentOfSidebarEntry(currentSidebar, link);
49
+ if (parent) return { ...link, label: parent.label };
50
+ }
51
+ return link;
52
+ })
53
+ .map((link) => {
54
+ const contentEntry = findSidebarLinkInContent(link);
55
+ if (contentEntry) return { ...link, description: contentEntry.data.description };
56
+ return link;
57
+ });
58
+
59
+ const currentIndex = paginationSequence.findIndex((e) => e.isCurrent);
60
+ if (currentIndex === -1) return null;
61
+
62
+ const prevIndex = currentIndex > 0 ? currentIndex - 1 : null;
63
+ const nextIndex = currentIndex < paginationSequence.length - 1 ? currentIndex + 1 : null;
64
+ const prevSidebarEntry = prevIndex !== null ? (paginationSequence[prevIndex] ?? null) : null;
65
+ const nextSidebarEntry = nextIndex !== null ? (paginationSequence[nextIndex] ?? null) : null;
66
+
67
+ return {
68
+ prev: prevSidebarEntry,
69
+ next: nextSidebarEntry,
70
+ };
71
+ }
@@ -0,0 +1 @@
1
+ export * from '@stainless-api/ui-primitives/scripts';
@@ -1,10 +1,88 @@
1
1
  ---
2
- import Default from '@astrojs/starlight/components/Sidebar.astro';
3
2
  import HeaderLinks from '../headers/HeaderLinks.astro';
3
+ import { SidebarWithComponents } from './SidebarWithComponents';
4
+ import SidebarPersister from '@astrojs/starlight/components/SidebarPersister.astro';
5
+ import { convertAstroSidebarToStl } from './convertAstroSidebarToStl';
6
+ import { StlSidebarEntry, StlSidebarGroup, StlSidebarLink } from '@stainless-api/docs-ui/components';
7
+ import { LINK_GROUP_TITLES_TO_OVERVIEW_PAGES } from 'virtual:stl-docs-virtual-module';
8
+
9
+ const { sidebar } = Astro.locals.starlightRoute;
10
+
11
+ let stlSidebar = convertAstroSidebarToStl(sidebar);
12
+
13
+ function extractOverviewPage(entry: StlSidebarGroup): {
14
+ overviewLink: StlSidebarLink | null;
15
+ remainingEntries: StlSidebarEntry[];
16
+ } {
17
+ let overviewLink: StlSidebarLink | null = null;
18
+
19
+ const withoutOverview = entry.entries.filter((e) => {
20
+ if (e.type !== 'link') {
21
+ return true;
22
+ }
23
+ const overviewAttr = e.attrs?.['data-stldocs-overview'];
24
+ if (!overviewAttr) {
25
+ return true;
26
+ }
27
+ overviewLink = e;
28
+ return false;
29
+ });
30
+
31
+ return {
32
+ overviewLink,
33
+ remainingEntries: withoutOverview,
34
+ };
35
+ }
36
+
37
+ function linkGroupTitleToOverviewPages(sidebar: StlSidebarEntry[]): StlSidebarEntry[] {
38
+ return sidebar.map((entry) => {
39
+ if (entry.type === 'group') {
40
+ const { overviewLink, remainingEntries } = extractOverviewPage(entry);
41
+
42
+ // group only contained an overview link
43
+ if (overviewLink && remainingEntries.length === 0) {
44
+ return {
45
+ ...overviewLink,
46
+ label: entry.label, // keep the group label
47
+ };
48
+ }
49
+
50
+ // set the group target to the overview link target
51
+
52
+ let target = entry.target;
53
+ let isCurrent = entry.isCurrent;
54
+ let collapsed = entry.collapsed;
55
+ if (overviewLink) {
56
+ target = overviewLink.target;
57
+ isCurrent = overviewLink.isCurrent;
58
+ if (isCurrent) {
59
+ collapsed = false;
60
+ }
61
+ }
62
+
63
+ return {
64
+ ...entry,
65
+ entries: linkGroupTitleToOverviewPages(remainingEntries),
66
+ target,
67
+ isCurrent,
68
+ collapsed,
69
+ };
70
+ } else {
71
+ return entry;
72
+ }
73
+ });
74
+ }
75
+
76
+ // Since Terraform only renders the top level resource, we don't need to link group titles to overview pages.
77
+ if (LINK_GROUP_TITLES_TO_OVERVIEW_PAGES === true && Astro.locals.language !== 'terraform') {
78
+ stlSidebar = linkGroupTitleToOverviewPages(stlSidebar);
79
+ }
4
80
  ---
5
81
 
6
82
  <div class="stl-sidebar-header-links">
7
83
  <HeaderLinks />
8
84
  </div>
9
85
  <slot name="sdk-select" />
10
- <Default><slot /></Default>
86
+ <SidebarPersister>
87
+ <SidebarWithComponents entries={stlSidebar} withStarlightRestoration />
88
+ </SidebarPersister>
@@ -0,0 +1,10 @@
1
+ import { StlSidebar, StlSidebarProps } from '@stainless-api/docs-ui/components';
2
+ import { ComponentProvider } from '@stainless-api/docs-ui/contexts/component';
3
+
4
+ export function SidebarWithComponents(props: StlSidebarProps) {
5
+ return (
6
+ <ComponentProvider>
7
+ <StlSidebar {...props} />
8
+ </ComponentProvider>
9
+ );
10
+ }
@@ -0,0 +1,62 @@
1
+ import { StlSidebarEntry } from '@stainless-api/docs-ui/components';
2
+ import { SidebarEntry } from '../pagination/util';
3
+ import { ReactNode } from 'react';
4
+ import { Badge, getHttpMethod } from '@stainless-api/ui-primitives';
5
+ import { FunctionIcon } from '@stainless-api/ui-primitives/icons';
6
+ import { BracesIcon } from 'lucide-react';
7
+
8
+ function getIcon(entry: SidebarEntry): ReactNode | undefined {
9
+ if (entry.type !== 'link') {
10
+ return undefined;
11
+ }
12
+ const methodAttr = entry.attrs['data-stldocs-method'];
13
+ const httpMethod = getHttpMethod(methodAttr);
14
+ if (httpMethod) {
15
+ return <Badge.HTTP method={httpMethod} iconOnly size="sm" />;
16
+ }
17
+
18
+ // special handling for the webhooks resource overview page
19
+ if (entry.attrs['data-stldocs-overview'] === 'webhooks') {
20
+ return (
21
+ <Badge size="sm" icon={<BracesIcon />} intent="info">
22
+ {''}
23
+ </Badge>
24
+ );
25
+ }
26
+
27
+ // Support empty string as method to show generic "Function" badge
28
+ else if (methodAttr === '') {
29
+ return (
30
+ <Badge size="sm" icon={<FunctionIcon />} intent="info">
31
+ {''}
32
+ </Badge>
33
+ );
34
+ }
35
+ return undefined;
36
+ }
37
+
38
+ export function convertAstroSidebarToStl(entries: SidebarEntry[]): StlSidebarEntry[] {
39
+ return entries.map((entry): StlSidebarEntry => {
40
+ if (entry.type === 'link') {
41
+ const icon = getIcon(entry);
42
+ return {
43
+ type: 'link',
44
+ attrs: entry.attrs,
45
+ label: entry.label,
46
+ target: {
47
+ type: 'href',
48
+ href: entry.href,
49
+ },
50
+ isCurrent: entry.isCurrent,
51
+ icon,
52
+ };
53
+ } else {
54
+ return {
55
+ type: 'group',
56
+ label: entry.label,
57
+ collapsed: entry.collapsed,
58
+ entries: convertAstroSidebarToStl(entry.entries),
59
+ };
60
+ }
61
+ });
62
+ }
@@ -0,0 +1,36 @@
1
+ import type { AstroIntegration } from 'astro';
2
+ import type { StarlightPlugin } from '@astrojs/starlight/types';
3
+
4
+ const disableCalloutSyntaxAstroIntegration = {
5
+ name: 'stl-starlight-remove-callout-syntax',
6
+ hooks: {
7
+ 'astro:config:setup': ({ config: astroConfig }) => {
8
+ // Remove starlight callout syntax in favor of our own callout component
9
+ // updateConfig always deeply merges arrays so we need to mutate remarkPlugins directly
10
+ // in order to remove plugins that starlight added
11
+ astroConfig.markdown.remarkPlugins = astroConfig.markdown.remarkPlugins.filter((plugin, i, arr) => {
12
+ if (typeof plugin !== 'function') return true;
13
+ // remove:
14
+ // 1. remarkDirective plugin
15
+ if (plugin.name === 'remarkDirective') return false;
16
+ // 2. directly followed by remarkAsides plugin (inner function named 'attacher')
17
+ if (plugin.name === 'attacher') {
18
+ const prev = arr[i - 1];
19
+ if (typeof prev === 'function' && prev.name === 'remarkDirective') return false;
20
+ }
21
+ // 3. remarkDirectivesRestoration plugin
22
+ if (plugin.name === 'remarkDirectivesRestoration') return false;
23
+ return true;
24
+ });
25
+ },
26
+ },
27
+ } satisfies AstroIntegration;
28
+
29
+ export const disableCalloutSyntaxStarlightPlugin = {
30
+ name: 'stl-starlight-remove-callout-syntax',
31
+ hooks: {
32
+ 'config:setup': ({ addIntegration }) => {
33
+ addIntegration(disableCalloutSyntaxAstroIntegration);
34
+ },
35
+ },
36
+ } satisfies StarlightPlugin;
@@ -0,0 +1,186 @@
1
+ import type { AstroConfig } from 'astro';
2
+ import type { Defined } from './loadStlDocsConfig';
3
+ import { fontProviders } from 'astro/config';
4
+ import type { FontPreloadFilter } from 'astro:assets';
5
+
6
+ type AstroFontConfigEntry = Defined<AstroConfig['fonts']>[number];
7
+
8
+ // Apply Omit to each member of the union while preserving union structure
9
+ type PreloadFilter = { preload?: FontPreloadFilter };
10
+ export type StlDocsFontConfigEntry = (AstroFontConfigEntry extends infer T
11
+ ? T extends unknown
12
+ ? Omit<T, 'cssVariable'>
13
+ : never
14
+ : never) &
15
+ PreloadFilter;
16
+
17
+ export type StlDocsFontConfig = {
18
+ primary?: StlDocsFontConfigEntry;
19
+ heading?: StlDocsFontConfigEntry;
20
+ mono?: StlDocsFontConfigEntry;
21
+ additional?: (AstroFontConfigEntry & PreloadFilter)[];
22
+ };
23
+ const latinFeatureSettings = "'ss01' on, 'ss03' on, 'ss04' on, 'ss06' on, 'ss08' on";
24
+ /* prettier-ignore */
25
+ const latinUnicodeRange: readonly string[] = ['U+0000-00FF', 'U+0131', 'U+0152-0153', 'U+02BB-02BC', 'U+02C6', 'U+02DA', 'U+02DC', 'U+0304', 'U+0308', 'U+0329', 'U+2000-206F', 'U+20AC', 'U+2122', 'U+2191', 'U+2193', 'U+2212', 'U+2215', 'U+FEFF', 'U+FFFD'];
26
+ // /* prettier-ignore */
27
+ // const latinExtUnicodeRange: readonly string[] = ['U+0100-02BA', 'U+02BD-02C5', 'U+02C7-02CC', 'U+02CE-02D7', 'U+02DD-02FF', 'U+0304', 'U+0308', 'U+0329', 'U+1D00-1DBF', 'U+1E00-1E9F', 'U+1EF2-1EFF', 'U+2020', 'U+20A0-20AB', 'U+20AD-20C0', 'U+2113', 'U+2C60-2C7F', 'U+A720-A7FF'];
28
+
29
+ export function getFontRoles(fonts: StlDocsFontConfig | undefined) {
30
+ if (!fonts) {
31
+ return {};
32
+ }
33
+ const fontConfigs: {
34
+ primary?: { cssVariable: string; preload?: FontPreloadFilter };
35
+ heading?: { cssVariable: string; preload?: FontPreloadFilter };
36
+ mono?: { cssVariable: string; preload?: FontPreloadFilter };
37
+ additional?: { cssVariable: string; preload?: FontPreloadFilter }[];
38
+ } = {};
39
+ if (fonts.primary) {
40
+ fontConfigs['primary'] = {
41
+ cssVariable: '--stl-typography-font' as const,
42
+ preload: fonts.primary.preload ?? [{ style: 'normal' }],
43
+ };
44
+ }
45
+ if (fonts.heading) {
46
+ fontConfigs['heading'] = {
47
+ cssVariable: '--stl-typography-font-heading' as const,
48
+ preload: fonts.heading.preload ?? [{ style: 'normal' }],
49
+ };
50
+ }
51
+ if (fonts.mono) {
52
+ fontConfigs['mono'] = {
53
+ cssVariable: '--stl-typography-font-mono' as const,
54
+ preload: fonts.mono.preload ?? [{ style: 'normal' }],
55
+ };
56
+ }
57
+ if (fonts.additional) {
58
+ fontConfigs['additional'] = fonts.additional.map((font) => ({
59
+ cssVariable: font.cssVariable,
60
+ preload: font.preload ?? [{ style: 'normal' }],
61
+ }));
62
+ }
63
+ return fontConfigs;
64
+ }
65
+
66
+ export function normalizeFonts(fonts: StlDocsFontConfig | undefined): StlDocsFontConfig {
67
+ const defaultPrimary: StlDocsFontConfigEntry = {
68
+ provider: fontProviders.local(),
69
+ name: 'Geist',
70
+ display: 'swap',
71
+ preload: [
72
+ {
73
+ weight: '100 900',
74
+ style: 'normal',
75
+ },
76
+ ],
77
+ options: {
78
+ variants: [
79
+ {
80
+ weight: '100 900',
81
+ style: 'normal',
82
+ src: [new URL('../assets/fonts/geist/geist-latin.woff2', import.meta.url)],
83
+ unicodeRange: latinUnicodeRange,
84
+ featureSettings: latinFeatureSettings,
85
+ },
86
+ {
87
+ weight: '100 900',
88
+ style: 'italic',
89
+ src: [new URL('../assets/fonts/geist/geist-italic-latin.woff2', import.meta.url)],
90
+ unicodeRange: latinUnicodeRange,
91
+ featureSettings: latinFeatureSettings,
92
+ },
93
+ // {
94
+ // weight: '100 900',
95
+ // style: 'normal',
96
+ // src: [new URL('../assets/fonts/geist/geist-latin-ext.woff2', import.meta.url)],
97
+ // unicodeRange: latinExtUnicodeRange,
98
+ // featureSettings: latinFeatureSettings,
99
+ // },
100
+ // {
101
+ // weight: '100 900',
102
+ // style: 'italic',
103
+ // src: [new URL('../assets/fonts/geist/geist-italic-latin-ext.woff2', import.meta.url)],
104
+ // unicodeRange: latinExtUnicodeRange,
105
+ // featureSettings: latinFeatureSettings,
106
+ // },
107
+ ],
108
+ },
109
+ };
110
+ const defaultMono: StlDocsFontConfigEntry = {
111
+ provider: fontProviders.local(),
112
+ name: 'Geist Mono',
113
+ display: 'swap',
114
+ preload: [
115
+ {
116
+ weight: '100 900',
117
+ style: 'normal',
118
+ },
119
+ ],
120
+ options: {
121
+ variants: [
122
+ {
123
+ weight: '100 900',
124
+ style: 'normal',
125
+ src: [new URL('../assets/fonts/geist/geist-mono-latin.woff2', import.meta.url)],
126
+ unicodeRange: latinUnicodeRange,
127
+ },
128
+ {
129
+ weight: '100 900',
130
+ style: 'italic',
131
+ src: [new URL('../assets/fonts/geist/geist-mono-italic-latin.woff2', import.meta.url)],
132
+ unicodeRange: latinUnicodeRange,
133
+ },
134
+ // {
135
+ // weight: '100 900',
136
+ // style: 'normal',
137
+ // src: [new URL('../assets/fonts/geist/geist-mono-latin-ext.woff2', import.meta.url)],
138
+ // unicodeRange: latinExtUnicodeRange,
139
+ // },
140
+ // {
141
+ // weight: '100 900',
142
+ // style: 'italic',
143
+ // src: [new URL('../assets/fonts/geist/geist-mono-italic-latin-ext.woff2', import.meta.url)],
144
+ // unicodeRange: latinExtUnicodeRange,
145
+ // },
146
+ ],
147
+ },
148
+ };
149
+
150
+ return {
151
+ primary: fonts?.primary ?? defaultPrimary,
152
+ heading: fonts?.heading ?? undefined,
153
+ mono: fonts?.mono ?? defaultMono,
154
+ additional: fonts?.additional ?? [],
155
+ };
156
+ }
157
+
158
+ // Normalize fonts for the Astro config
159
+ export function flattenFonts(fonts: StlDocsFontConfig | undefined): AstroFontConfigEntry[] {
160
+ if (!fonts) {
161
+ return [];
162
+ }
163
+ const fontConfigs: AstroFontConfigEntry[] = [];
164
+ if (fonts.primary) {
165
+ fontConfigs.push({
166
+ ...fonts.primary,
167
+ cssVariable: '--stl-typography-font' as const,
168
+ } as AstroFontConfigEntry);
169
+ }
170
+ if (fonts.heading) {
171
+ fontConfigs.push({
172
+ ...fonts.heading,
173
+ cssVariable: '--stl-typography-font-heading' as const,
174
+ } as AstroFontConfigEntry);
175
+ }
176
+ if (fonts.mono) {
177
+ fontConfigs.push({
178
+ ...fonts.mono,
179
+ cssVariable: '--stl-typography-font-mono' as const,
180
+ } as AstroFontConfigEntry);
181
+ }
182
+ if (fonts.additional) {
183
+ fontConfigs.push(...fonts.additional.map((font) => font as AstroFontConfigEntry));
184
+ }
185
+ return fontConfigs;
186
+ }