@stainless-api/docs-ui 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 (215) hide show
  1. package/dist/breadcrumbs-BhYwbXkc.d.ts +25 -0
  2. package/dist/breadcrumbs-Cvm5Ifm7.d.ts +25 -0
  3. package/dist/breadcrumbs-DA4WgDhR.js +63 -0
  4. package/dist/chunk-BN_g-Awi.js +18 -0
  5. package/dist/cli-F3kMmeoJ.js +166 -0
  6. package/dist/component-P9sn5yyG.js +23 -0
  7. package/dist/component-generics-ByGsYTc8.d.ts +30 -0
  8. package/dist/component-generics-POFirVVb.js +45 -0
  9. package/dist/component-generics-zU0Pqx8m.d.ts +30 -0
  10. package/dist/components/MaskedInput.d.ts +14 -0
  11. package/dist/components/MaskedInput.js +76 -0
  12. package/dist/components/breadcrumbs.d.ts +2 -0
  13. package/dist/components/breadcrumbs.js +9 -0
  14. package/dist/components/icons.d.ts +60 -0
  15. package/dist/components/icons.js +3 -0
  16. package/dist/components/index.d.ts +11 -0
  17. package/dist/components/index.js +19 -0
  18. package/dist/components/method.d.ts +2 -0
  19. package/dist/components/method.js +10 -0
  20. package/dist/components/overview.d.ts +2 -0
  21. package/dist/components/overview.js +11 -0
  22. package/dist/components/primitives.d.ts +2 -0
  23. package/dist/components/primitives.js +8 -0
  24. package/dist/components/properties.d.ts +2 -0
  25. package/dist/components/properties.js +9 -0
  26. package/dist/components/sdk-sidebar.d.ts +2 -0
  27. package/dist/components/sdk-sidebar.js +10 -0
  28. package/dist/components/sdk.d.ts +2 -0
  29. package/dist/components/sdk.js +10 -0
  30. package/dist/components/snippets.d.ts +3 -0
  31. package/dist/components/snippets.js +9 -0
  32. package/dist/components/stl-sidebar.d.ts +2 -0
  33. package/dist/components/stl-sidebar.js +5 -0
  34. package/dist/components-w1JmIrB0.js +71 -0
  35. package/dist/contexts/component-generics.d.ts +2 -0
  36. package/dist/contexts/component-generics.js +3 -0
  37. package/dist/contexts/component-types.d.ts +17 -0
  38. package/dist/contexts/component-types.js +0 -0
  39. package/dist/contexts/component.d.ts +30 -0
  40. package/dist/contexts/component.js +30 -0
  41. package/dist/contexts/docs.d.ts +2 -0
  42. package/dist/contexts/docs.js +3 -0
  43. package/dist/contexts/index.d.ts +23 -0
  44. package/dist/contexts/index.js +7 -0
  45. package/dist/contexts/markdown.d.ts +2 -0
  46. package/dist/contexts/markdown.js +4 -0
  47. package/dist/contexts/navigation.d.ts +2 -0
  48. package/dist/contexts/navigation.js +3 -0
  49. package/dist/contexts/use-components.d.ts +15 -0
  50. package/dist/contexts/use-components.js +4 -0
  51. package/dist/contexts-CVj20VV4.js +41 -0
  52. package/dist/csharp-D6_jlynY.js +283 -0
  53. package/dist/docs-BmOB2f-I.js +61 -0
  54. package/dist/docs-g4IPmtZr.d.ts +48 -0
  55. package/dist/docs-z3fl2eW-.d.ts +48 -0
  56. package/dist/go-COaHV3Hc.js +303 -0
  57. package/dist/http-fOPCX17A.js +389 -0
  58. package/dist/icons-BYKn5X8E.js +885 -0
  59. package/dist/index-B8Zys1C2.d.ts +347 -0
  60. package/dist/index-C5Zmb2CI.d.ts +16 -0
  61. package/dist/index-CwjGm9zX.d.ts +1722 -0
  62. package/dist/index-D7PkxNgB.d.ts +16 -0
  63. package/dist/index-DIaM6Ync.d.ts +347 -0
  64. package/dist/index.d.ts +20 -0
  65. package/dist/index.js +32 -7542
  66. package/dist/java-CxGSJVvv.js +403 -0
  67. package/dist/languages/cli.d.ts +12 -0
  68. package/dist/languages/cli.js +21 -0
  69. package/dist/languages/csharp.d.ts +12 -0
  70. package/dist/languages/csharp.js +9 -0
  71. package/dist/languages/go.d.ts +12 -0
  72. package/dist/languages/go.js +9 -0
  73. package/dist/languages/http.d.ts +12 -0
  74. package/dist/languages/http.js +20 -0
  75. package/dist/languages/index.d.ts +12 -0
  76. package/dist/languages/index.js +29 -0
  77. package/dist/languages/java.d.ts +12 -0
  78. package/dist/languages/java.js +9 -0
  79. package/dist/languages/python.d.ts +12 -0
  80. package/dist/languages/python.js +9 -0
  81. package/dist/languages/ruby.d.ts +12 -0
  82. package/dist/languages/ruby.js +9 -0
  83. package/dist/languages/terraform.d.ts +12 -0
  84. package/dist/languages/terraform.js +9 -0
  85. package/dist/languages/typescript.d.ts +12 -0
  86. package/dist/languages/typescript.js +9 -0
  87. package/dist/languages-B6eap2M6.js +30 -0
  88. package/dist/markdown/index.d.ts +12 -0
  89. package/dist/markdown/index.js +107 -0
  90. package/dist/markdown/md.d.ts +15 -0
  91. package/dist/markdown/md.js +41 -0
  92. package/dist/markdown/printer.d.ts +13 -0
  93. package/dist/markdown/printer.js +100 -0
  94. package/dist/markdown/utils.d.ts +21 -0
  95. package/dist/markdown/utils.js +31 -0
  96. package/dist/markdown-CTKHMLVr.js +49 -0
  97. package/dist/markdown-Cdh0TSHp.d.ts +22 -0
  98. package/dist/markdown-Cibv9fDR.d.ts +22 -0
  99. package/dist/method-630cPKDl.d.ts +59 -0
  100. package/dist/method-BPDUyBlD.js +96 -0
  101. package/dist/method-BzkPRXGL.d.ts +59 -0
  102. package/dist/navigation-BW-SBvb4.d.ts +29 -0
  103. package/dist/navigation-DWYqC_HX.d.ts +29 -0
  104. package/dist/navigation-aoYZ_tl4.js +24 -0
  105. package/dist/overview-Cui1XtuC.d.ts +39 -0
  106. package/dist/overview-DFwfIK6k.js +138 -0
  107. package/dist/overview-RXc9iPzz.d.ts +39 -0
  108. package/dist/primitives-DJEqe_r1.js +250 -0
  109. package/dist/primitives-DhGxFYx6.d.ts +105 -0
  110. package/dist/primitives-MsH-h0bU.d.ts +105 -0
  111. package/dist/properties-BnbBKd5a.js +132 -0
  112. package/dist/properties-Bynmj9_H.d.ts +54 -0
  113. package/dist/properties-C9W4QJ_F.d.ts +54 -0
  114. package/dist/python-DsTuWCKE.js +269 -0
  115. package/dist/routing-C64k4fmX.js +205 -0
  116. package/dist/routing-Cm_9XJiQ.d.ts +61 -0
  117. package/dist/routing-utiR5mY3.d.ts +61 -0
  118. package/dist/routing.d.ts +2 -0
  119. package/dist/routing.js +3 -180
  120. package/dist/ruby-BncKp6hd.js +387 -0
  121. package/dist/sdk-BvZeXpsj.d.ts +122 -0
  122. package/dist/sdk-Bw99eXxA.js +399 -0
  123. package/dist/sdk-GMOw94wL.d.ts +122 -0
  124. package/dist/sdk-sidebar-NCBSWuUW.d.ts +15 -0
  125. package/dist/sdk-sidebar-VNY2-O1Y.d.ts +15 -0
  126. package/dist/sdk-sidebar-V_MTkVw8.js +50 -0
  127. package/dist/snippets-BehbU3rt.js +164 -0
  128. package/dist/snippets-Bj7Ey56K.d.ts +53 -0
  129. package/dist/snippets-CQQSDvg2.d.ts +53 -0
  130. package/dist/spec.d.ts +65 -0
  131. package/dist/spec.js +167 -0
  132. package/dist/stl-sidebar-CXzs_shz.d.ts +58 -0
  133. package/dist/stl-sidebar-DSkUHwcU.d.ts +58 -0
  134. package/dist/stl-sidebar-WtimNrk1.js +106 -0
  135. package/dist/style-HpXpcJ9v.js +172 -0
  136. package/dist/style.d.ts +171 -0
  137. package/dist/style.js +3 -0
  138. package/dist/styles/main.css +744 -754
  139. package/dist/styles/main.js +0 -0
  140. package/dist/styles/primitives.css +327 -458
  141. package/dist/styles/primitives.js +0 -0
  142. package/dist/styles/resets.css +32 -41
  143. package/dist/styles/resets.js +0 -0
  144. package/dist/styles/search.css +192 -270
  145. package/dist/styles/search.js +0 -0
  146. package/dist/styles/sidebar.css +170 -69
  147. package/dist/styles/sidebar.js +0 -0
  148. package/dist/styles/variables.css +26 -89
  149. package/dist/styles/variables.js +0 -0
  150. package/dist/styles.css +3273 -0
  151. package/dist/styles.mjs +1 -0
  152. package/dist/terraform-B95X4rNK.js +243 -0
  153. package/dist/typescript-n46M9OtL.js +449 -0
  154. package/dist/use-components-BUz3GbO4.js +7 -0
  155. package/dist/utils-DPbkW1Tz.js +54 -0
  156. package/dist/utils.d.ts +20 -0
  157. package/dist/utils.js +3 -0
  158. package/package.json +74 -22
  159. package/dist/mcp.js +0 -16003
  160. package/dist/styles/snippets.css +0 -132
  161. package/src/components/breadcrumbs.tsx +0 -94
  162. package/src/components/chat.tsx +0 -154
  163. package/src/components/dropdown.tsx +0 -91
  164. package/src/components/icons.tsx +0 -584
  165. package/src/components/index.ts +0 -9
  166. package/src/components/method.tsx +0 -144
  167. package/src/components/overview.tsx +0 -159
  168. package/src/components/primitives.tsx +0 -284
  169. package/src/components/properties.tsx +0 -130
  170. package/src/components/scripts/dropdown.ts +0 -78
  171. package/src/components/sdk.tsx +0 -402
  172. package/src/components/sidebar.tsx +0 -99
  173. package/src/components/snippets.tsx +0 -179
  174. package/src/contexts/component-generics.tsx +0 -48
  175. package/src/contexts/component-types.tsx +0 -5
  176. package/src/contexts/component.tsx +0 -32
  177. package/src/contexts/docs.tsx +0 -75
  178. package/src/contexts/index.tsx +0 -17
  179. package/src/contexts/markdown.tsx +0 -43
  180. package/src/contexts/navigation.tsx +0 -44
  181. package/src/contexts/search.tsx +0 -28
  182. package/src/contexts/use-components.tsx +0 -4
  183. package/src/index.ts +0 -6
  184. package/src/languages/go.tsx +0 -281
  185. package/src/languages/http.tsx +0 -321
  186. package/src/languages/index.ts +0 -26
  187. package/src/languages/java.tsx +0 -358
  188. package/src/languages/python.tsx +0 -255
  189. package/src/languages/ruby.tsx +0 -320
  190. package/src/languages/typescript.tsx +0 -393
  191. package/src/markdown/index.ts +0 -107
  192. package/src/markdown/md.ts +0 -45
  193. package/src/markdown/utils.ts +0 -49
  194. package/src/routing.ts +0 -238
  195. package/src/search/form.tsx +0 -127
  196. package/src/search/index.tsx +0 -1
  197. package/src/search/indexer.ts +0 -246
  198. package/src/search/mcp.ts +0 -61
  199. package/src/search/printer.tsx +0 -86
  200. package/src/search/providers/algolia.ts +0 -88
  201. package/src/search/providers/fuse.ts +0 -19
  202. package/src/search/providers/pagefind.ts +0 -17
  203. package/src/search/providers/walker.ts +0 -30
  204. package/src/search/results.tsx +0 -181
  205. package/src/search/state.ts +0 -64
  206. package/src/search/types.ts +0 -116
  207. package/src/style.ts +0 -197
  208. package/src/styles/main.css +0 -993
  209. package/src/styles/primitives.css +0 -572
  210. package/src/styles/resets.css +0 -47
  211. package/src/styles/search.css +0 -342
  212. package/src/styles/sidebar.css +0 -87
  213. package/src/styles/snippets.css +0 -132
  214. package/src/styles/variables.css +0 -90
  215. package/src/utils.ts +0 -41
package/src/routing.ts DELETED
@@ -1,238 +0,0 @@
1
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
2
-
3
- export const Languages = [
4
- 'http',
5
- 'node',
6
- 'python',
7
- 'go',
8
- 'typescript',
9
- 'terraform',
10
- 'ruby',
11
- 'java',
12
- 'kotlin',
13
- ] as const;
14
-
15
- export const SupportedLanguageSyntaxes = [
16
- 'http',
17
- 'javascript',
18
- 'python',
19
- 'go',
20
- 'typescript',
21
- 'terraform',
22
- 'ruby',
23
- 'java',
24
- 'kotlin',
25
- ];
26
-
27
- export type DocsLanguage = (typeof Languages)[number];
28
-
29
- export const LanguageNames: Record<DocsLanguage, string> = {
30
- http: 'HTTP',
31
- node: 'TypeScript',
32
- typescript: 'TypeScript',
33
- python: 'Python',
34
- go: 'Go',
35
- ruby: 'Ruby',
36
- java: 'Java',
37
- kotlin: 'Kotlin',
38
- terraform: 'Terraform',
39
- };
40
-
41
- export function getLanguageSnippet(language: DocsLanguage) {
42
- return language === 'http' ? ('http.curl' as const) : (`${language}.default` as const);
43
- }
44
-
45
- export function isSupportedLanguage(language: string): language is DocsLanguage {
46
- return Languages.includes(language as DocsLanguage);
47
- }
48
-
49
- const DefaultLanguage = 'http';
50
-
51
- const StainlessPathPattern =
52
- /(\(resource\) (?<resource>[^\s]+))( > (\(method\) (?<method>[^\s]+)|\(model\) (?<model>[^\s]+))?)?/;
53
-
54
- export type ParsedStainlessPath = ReturnType<typeof parseStainlessPath>;
55
-
56
- export function parseStainlessPath(stainlessPath: string) {
57
- const match = stainlessPath.match(StainlessPathPattern);
58
-
59
- if (!match) return null;
60
-
61
- return {
62
- resource: match.groups.resource.split('.'),
63
- method: match.groups.method ?? null,
64
- model: match.groups.model ?? null,
65
- routable: match.groups.model ? match[1] : match[0],
66
- };
67
- }
68
-
69
- export function trimStainlessPath(stainlessPath: string) {
70
- return stainlessPath.replace(/ > \([^\s]+\)$/, '');
71
- }
72
-
73
- export function getResource(stainlessPath: string) {
74
- const parsed = parseStainlessPath(stainlessPath);
75
- return parsed?.resource[0];
76
- }
77
-
78
- export function parseRoute(
79
- basePath: string,
80
- route: string,
81
- ): { stainlessPath: string; language: DocsLanguage } {
82
- if (!route.startsWith(basePath)) return { stainlessPath: '', language: DefaultLanguage };
83
-
84
- if (basePath && route.startsWith(basePath)) route = route.slice(basePath.length);
85
-
86
- let stainlessPath = '';
87
- let elements = route.slice(1).split('/');
88
- let language: DocsLanguage = DefaultLanguage;
89
-
90
- if (elements[0] && Languages.includes(elements[0] as DocsLanguage)) {
91
- language = elements[0] as DocsLanguage;
92
- elements = elements.slice(1);
93
- }
94
-
95
- while (elements.length > 0) {
96
- const element = elements.shift();
97
- switch (element) {
98
- case 'resources':
99
- stainlessPath += `(resource) ${elements.shift()}`;
100
- break;
101
-
102
- case 'subresources':
103
- stainlessPath += `.${elements.shift()}`;
104
- break;
105
-
106
- case 'methods':
107
- stainlessPath += ` > (method) ${elements.shift()}`;
108
- break;
109
- }
110
- }
111
-
112
- return { stainlessPath, language };
113
- }
114
-
115
- export function generateRoute(basePath: string, language: string, stainlessPath: string) {
116
- const parsedPath = parseStainlessPath(stainlessPath);
117
- if (!parsedPath) return null;
118
-
119
- const path = [basePath.endsWith('/') ? basePath.slice(0, -1) : basePath];
120
- if (language && language !== DefaultLanguage) path.push(language);
121
-
122
- const resources = parsedPath.resource.flatMap((name, index) => [
123
- index > 0 ? 'subresources' : 'resources',
124
- name,
125
- ]);
126
-
127
- // Ensure model links always go to top-level resource page
128
- const resourcePath = parsedPath.model ? resources.slice(0, 2) : resources;
129
- path.push(...resourcePath);
130
-
131
- if (parsedPath.method) path.push('methods', parsedPath.method);
132
-
133
- return stainlessPath.length > parsedPath.routable.length
134
- ? `${path.join('/')}#${encodeURIComponent(stainlessPath)}`
135
- : path.join('/');
136
- }
137
-
138
- export type SpecTreeEntry = {
139
- data: SDKJSON.Method | SDKJSON.Resource | SDKJSON.Model;
140
- path: string[];
141
- };
142
-
143
- function* walkResource(
144
- resource: SDKJSON.Resource,
145
- path: string[],
146
- includeModels?: boolean,
147
- ): Generator<SpecTreeEntry> {
148
- yield { data: resource, path };
149
-
150
- for (const data of Object.values(resource.methods)) {
151
- yield { data, path: [...path, 'methods', data.name] };
152
- }
153
-
154
- if (includeModels)
155
- for (const data of Object.values(resource.models)) {
156
- yield { data, path: [...path, 'models', data.name] };
157
- }
158
-
159
- for (const data of Object.values(resource.subresources ?? {})) {
160
- yield* walkResource(data, [...path, 'subresources', data.name]);
161
- }
162
- }
163
-
164
- export function* walkTree(spec: SDKJSON.Spec, includeModels?: boolean) {
165
- for (const data of Object.values(spec.resources)) {
166
- yield* walkResource(data, ['resources', data.name], includeModels);
167
- }
168
- }
169
-
170
- export type RouteEntry = {
171
- title: string;
172
- kind: SpecTreeEntry['data']['kind'];
173
- language: DocsLanguage;
174
- stainlessPath: string;
175
- slug: string;
176
- };
177
-
178
- export function generateRouteList({
179
- spec,
180
- languages,
181
- excludeLanguages = [],
182
- }: {
183
- spec: SDKJSON.Spec;
184
- languages?: DocsLanguage[];
185
- excludeLanguages?: DocsLanguage[];
186
- }): RouteEntry[] {
187
- const entries = Array.from(walkTree(spec));
188
- const langs = languages ?? spec.docs?.languages ?? ['http'];
189
-
190
- return langs
191
- .filter((lang) => Languages.includes(lang) && lang !== 'terraform')
192
- .filter((lang) => !excludeLanguages?.includes(lang))
193
- .flatMap((language) =>
194
- entries.map(({ path, data: { title, kind, stainlessPath } }) => ({
195
- title,
196
- kind,
197
- language,
198
- stainlessPath,
199
- slug: (language === 'http' ? path : [language, ...path]).join('/'),
200
- })),
201
- );
202
- }
203
-
204
- type ResourceOrMethod = SDKJSON.Resource | SDKJSON.Method;
205
-
206
- export function findNavigationPath(items: ResourceOrMethod[], target: string) {
207
- for (const item of Object.values(items)) {
208
- if (item.stainlessPath === target) return [item.stainlessPath];
209
- if (item.kind === 'http_method') continue;
210
-
211
- const path = findNavigationPath(
212
- [...Object.values(item.methods ?? {}), ...Object.values(item.subresources ?? {})],
213
- target,
214
- );
215
-
216
- if (path) return [item.stainlessPath, ...path];
217
- }
218
- }
219
-
220
- export function expandToElement(el: HTMLElement) {
221
- while (el) {
222
- if (el.tagName === 'DETAILS') el['open'] = true;
223
- el = el.parentElement;
224
- }
225
- }
226
-
227
- export function scrollToPath(stainlessPath: string) {
228
- const el = document.getElementById(stainlessPath);
229
- if (el) {
230
- expandToElement(el);
231
- el.scrollIntoView({ behavior: 'smooth' });
232
- }
233
- }
234
-
235
- export function updateHistory(basePath: string, language: DocsLanguage, stainlessPath: string) {
236
- const path = generateRoute(basePath, language, stainlessPath);
237
- window.history.pushState({ stainlessPath, language }, '', path);
238
- }
@@ -1,127 +0,0 @@
1
- import * as React from 'react';
2
- import { Search as SearchIcon, X as XIcon } from 'lucide-react';
3
- import { QueryKinds, QueryKindsType, ResultData } from './types';
4
- import { GuideResult, QueryKindDisplay, SearchResult } from './results';
5
- import { guideSearch } from './providers/pagefind';
6
- import { useLanguage, useSearch, useSearchContext } from '../contexts';
7
- import { useComponents } from '../contexts/use-components';
8
-
9
- import style from '../style';
10
-
11
- export function SearchForm() {
12
- const Docs = useComponents();
13
- const search = useSearch();
14
- const language = useLanguage();
15
- const { onSelect, pageFind } = useSearchContext();
16
-
17
- const [results, setResults] = React.useState<ResultData>(null);
18
- const [filterKind, setFilterKind] = React.useState<QueryKindsType>('all');
19
- const [searchQuery, setSearchQuery] = React.useState<string>('');
20
- const inputRef = React.useRef<HTMLInputElement>(null);
21
-
22
- async function performSearch() {
23
- const guideLimit = filterKind === 'guide' ? 25 : 5;
24
- const kind = ['all', 'guide'].includes(filterKind) ? undefined : filterKind;
25
-
26
- const [guideResults, apiResults] = await Promise.all([
27
- pageFind ? guideSearch(pageFind, searchQuery, guideLimit) : [],
28
- search({ query: searchQuery, kind, language }),
29
- ]);
30
-
31
- setResults({
32
- items: filterKind === 'guide' ? guideResults : [...guideResults, ...apiResults.hits],
33
- counts: {
34
- ...apiResults.facets?.['kind'],
35
- guide: guideResults.length,
36
- all: apiResults.nbHits,
37
- },
38
- });
39
- }
40
-
41
- function clearInput() {
42
- setSearchQuery('');
43
- inputRef?.current?.focus();
44
- }
45
-
46
- React.useEffect(() => void performSearch(), [searchQuery, filterKind, language]);
47
-
48
- return (
49
- <div className={style.SearchForm}>
50
- <Docs.Input
51
- ref={inputRef}
52
- autoFocus
53
- onChange={(ev) => setSearchQuery(ev.target.value)}
54
- left={<SearchIcon size={16} className={style.Icon} />}
55
- right={
56
- searchQuery && (
57
- <XIcon cursor="pointer" onClick={() => clearInput()} size={16} className={style.Icon} />
58
- )
59
- }
60
- value={searchQuery}
61
- placeholder="Search"
62
- />
63
-
64
- <SearchFilter
65
- results={results}
66
- filterKind={filterKind}
67
- onChange={(filterKind) => setFilterKind(filterKind)}
68
- />
69
-
70
- <Docs.ListView
71
- items={results?.items ?? []}
72
- itemDelegate={(item) =>
73
- 'kind' in item ? <SearchResult result={item} /> : <GuideResult result={item} />
74
- }
75
- onSelectListItem={(item) => onSelect?.(item['data']?.['url'] ?? item['stainlessPath'])}
76
- />
77
- </div>
78
- );
79
- }
80
-
81
- export type SearchFilterProps = {
82
- results: ResultData;
83
- filterKind: QueryKindsType;
84
- onChange: (filterKind?: QueryKindsType) => void;
85
- };
86
-
87
- export function SearchFilter({ results, filterKind, onChange }: SearchFilterProps) {
88
- const Docs = useComponents();
89
- const { pageFind } = useSearchContext();
90
- const toggles = pageFind ? QueryKinds : QueryKinds.slice(0, -1);
91
-
92
- return (
93
- <div className={style.SearchFilter}>
94
- {toggles.map((kind, index) => (
95
- <Docs.ToggleButton key={index} selected={filterKind === kind} onClick={() => onChange?.(kind)}>
96
- {React.createElement(QueryKindDisplay[kind].icon, {
97
- size: 16,
98
- className: style.Icon,
99
- })}
100
- {QueryKindDisplay[kind].name}
101
- <span className={style.SearchFilterCount}>{results?.counts?.[kind] ?? 0}</span>
102
- </Docs.ToggleButton>
103
- ))}
104
- </div>
105
- );
106
- }
107
-
108
- export type SearchModalProps = {
109
- id?: string;
110
- open?: boolean;
111
- };
112
-
113
- export function SearchModal({ id, open: isOpen }: SearchModalProps) {
114
- const [open, setOpen] = React.useState<boolean>(isOpen);
115
-
116
- return (
117
- <div
118
- id={id}
119
- onToggle={(ev) => setOpen(ev.newState === 'open')}
120
- className={style.SearchModal}
121
- popover="auto"
122
- data-stldocs-modal-open={open}
123
- >
124
- {open && <SearchForm />}
125
- </div>
126
- );
127
- }
@@ -1 +0,0 @@
1
- export * from './form';
@@ -1,246 +0,0 @@
1
- import { generateRoute, Languages, parseStainlessPath, walkTree } from '../routing';
2
- import * as printer from './printer';
3
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
4
- import type { IndexEntry } from './types';
5
- import { renderMarkdown } from '../markdown';
6
-
7
- // function sanitizeTerraformType(key: string, value: any) {
8
- // return typeof value === "number" && !Number.isSafeInteger(value)
9
- // ? value.toString()
10
- // : value;
11
- // }
12
-
13
- export function getResourceNames(resourceIds: string[], topResources?: Record<string, SDKJSON.Resource>) {
14
- let element: SDKJSON.Resource | undefined = undefined;
15
- let resources: Record<string, SDKJSON.Resource> | undefined = topResources;
16
- const resourceName = [];
17
- for (const resource of resourceIds) {
18
- element = resources?.[resource];
19
- if (!element) break;
20
- resourceName.push(element.title);
21
- resources = element?.subresources;
22
- }
23
-
24
- return resourceName;
25
- }
26
-
27
- function chunkByLines(content: string, maxSize: number = 60000) {
28
- if (Buffer.byteLength(content, 'utf8') < maxSize) return [content];
29
-
30
- const lines = content.split('\n');
31
- const chunks = [];
32
-
33
- let currentChunk = [];
34
- let currentSize = 0;
35
-
36
- for (const line of lines) {
37
- const lineSize = Buffer.byteLength(line + '\n', 'utf8');
38
- if (currentSize + lineSize > maxSize) {
39
- chunks.push(currentChunk.join('\n'));
40
- currentChunk = [];
41
- currentSize = 0;
42
- }
43
-
44
- currentChunk.push(line);
45
- currentSize += lineSize;
46
- }
47
-
48
- if (currentChunk.length > 0) chunks.push(currentChunk.join('\n'));
49
- return chunks;
50
- }
51
-
52
- export function* generateChatIndex(spec: SDKJSON.Spec) {
53
- for (const [language, readme] of Object.entries(spec.readme)) {
54
- const chunks = chunkByLines(readme);
55
-
56
- for (const chunk of chunks) {
57
- yield {
58
- language,
59
- title: 'Overview',
60
- content: chunk,
61
- url: `docs://BASE_PATH/${language}`,
62
- };
63
- }
64
- }
65
-
66
- for (const { data } of walkTree(spec)) {
67
- if (data.kind !== 'http_method') continue;
68
- const { title, name, stainlessPath, httpMethod, summary, description } = data;
69
- const endpoint = data.endpoint.slice(httpMethod.length).trim();
70
-
71
- for (const language of Languages) {
72
- const decl = spec.decls[language]?.[stainlessPath];
73
- if (!decl) continue;
74
-
75
- const env = {
76
- spec,
77
- language,
78
- options: {
79
- includeModelProperties: true,
80
- },
81
- };
82
-
83
- const content = renderMarkdown(env, data);
84
- const chunks = chunkByLines(content);
85
-
86
- for (const chunk of chunks) {
87
- yield {
88
- language,
89
- title,
90
- name,
91
- endpoint,
92
- httpMethod,
93
- summary,
94
- description,
95
- stainlessPath,
96
- qualified: decl['qualified'],
97
- ident: decl['ident'],
98
- content: chunk,
99
- url: generateRoute('docs://BASE_PATH', language, stainlessPath),
100
- };
101
- }
102
- }
103
- }
104
- }
105
-
106
- export function* generateIndex(
107
- spec: SDKJSON.Spec,
108
- renderMarkdownFn?: (string?) => string | null,
109
- includeTypes?: boolean,
110
- ): Generator<IndexEntry> {
111
- const parentCrumbs: Record<string, string[]> = {};
112
- for (const { data } of walkTree(spec, true)) {
113
- const { kind, name, title, stainlessPath } = data;
114
- const common = { name, title, stainlessPath };
115
-
116
- const parsedPath = parseStainlessPath(stainlessPath);
117
- const crumbs = getResourceNames(parsedPath.resource, spec.resources);
118
-
119
- switch (kind) {
120
- case 'resource':
121
- for (const language of Languages) {
122
- if (!data[language]) continue;
123
-
124
- parentCrumbs[stainlessPath] = crumbs;
125
- const { Name, QualifiedName } = data[language]!;
126
-
127
- yield {
128
- kind,
129
- crumbs,
130
- language,
131
- Name,
132
- QualifiedName,
133
- priority: 0,
134
- ...common,
135
- };
136
- }
137
-
138
- break;
139
-
140
- case 'http_method': {
141
- const { summary, endpoint, httpMethod } = data;
142
- for (const language of Languages) {
143
- const found = spec.decls[language]?.[stainlessPath];
144
- if (!found) continue;
145
-
146
- parentCrumbs[stainlessPath] = [...crumbs, title];
147
- const qualified = found['qualified'];
148
- const ident = qualified?.split('.')?.at(-1);
149
-
150
- yield {
151
- kind,
152
- crumbs: [...crumbs, title],
153
- ident,
154
- qualified,
155
- language,
156
- description: renderMarkdownFn?.(data.description) ?? data.description,
157
- endpoint: endpoint.slice(httpMethod.length).trim(),
158
- httpMethod,
159
- summary,
160
- priority: 0,
161
- ...common,
162
- };
163
- }
164
-
165
- break;
166
- }
167
-
168
- case 'model':
169
- for (const language of Languages) {
170
- if (!spec.decls[language]) continue;
171
-
172
- parentCrumbs[stainlessPath] = [...crumbs, title];
173
- const schema = spec.decls[language]?.[`${stainlessPath} > (schema)`];
174
- const children =
175
- schema?.['children']
176
- ?.map((childPath) => {
177
- const child = spec.decls?.[language]?.[childPath];
178
- return (
179
- child?.['ident'] ??
180
- child?.['name'] ??
181
- child?.['key'] ??
182
- child?.['type']?.['literal']?.['value'] ??
183
- child?.['type']?.['literal'] ??
184
- child?.['type']?.['value']
185
- );
186
- })
187
- ?.filter((child) => child) ?? [];
188
-
189
- yield {
190
- kind,
191
- crumbs: [...crumbs, title],
192
- children,
193
- language,
194
- priority: 2,
195
- ident: schema?.['ident'],
196
- ...common,
197
- };
198
- }
199
- }
200
- }
201
-
202
- for (const language of Languages) {
203
- const decls = spec.decls?.[language];
204
- if (!decls) continue;
205
-
206
- for (const decl of Object.values<SDKJSON.LanguageDeclNodes[SDKJSON.SpecLanguage]>(decls)) {
207
- switch (decl.kind) {
208
- // case "TerraformDeclAttribute":
209
- case 'JavaDeclProperty':
210
- case 'GoDeclProperty':
211
- case 'PythonDeclProperty':
212
- case 'RubyDeclProperty':
213
- case 'HttpDeclProperty':
214
- case 'TSDeclProperty':
215
- {
216
- const parsedPath = parseStainlessPath(decl.stainlessPath);
217
- const type = includeTypes === false ? undefined : printer.typeName(language, decl.type);
218
- const name = decl['ident'] ?? decl['name'] ?? decl['key'];
219
-
220
- const parent = parentCrumbs[parsedPath.routable];
221
- // Filter out properties of non-routable response types
222
- if (parent === undefined) continue;
223
-
224
- const matches = decl.stainlessPath.matchAll(/\((property|params|param)\) ([^\s]+)/g);
225
-
226
- const props = Array.from(matches)
227
- .map((p) => p[2])
228
- .filter((p) => p !== undefined);
229
-
230
- yield {
231
- kind: 'property',
232
- name,
233
- stainlessPath: decl.stainlessPath,
234
- crumbs: [...parent, ...props],
235
- docstring: renderMarkdownFn?.(decl.docstring) ?? decl.docstring,
236
- type,
237
- language,
238
- priority: 3,
239
- };
240
- }
241
-
242
- break;
243
- }
244
- }
245
- }
246
- }
package/src/search/mcp.ts DELETED
@@ -1,61 +0,0 @@
1
- import { renderMarkdown } from '../markdown';
2
- import { DocsLanguage, parseStainlessPath } from '../routing';
3
- import { getResourceFromSpec } from '../utils';
4
- import { buildIndex, search } from './providers/fuse';
5
- import type { IndexEntry } from './types';
6
- import type * as SDKJSON from '~/lib/json-spec-v2/types';
7
-
8
- export function consolidate(results: IndexEntry[]) {
9
- const resources = new Set<string>();
10
- const methods = new Set<string>();
11
-
12
- for (const entry of results) {
13
- const parsed = parseStainlessPath(entry.stainlessPath);
14
- if (parsed.method) methods.add(parsed.routable);
15
- else resources.add(parsed.routable);
16
- }
17
-
18
- const filtered = Array.from(methods).filter((path) => !resources.has(path.split(' >').at(0)));
19
- return [...resources, ...filtered];
20
- }
21
-
22
- export function render(
23
- spec: SDKJSON.Spec,
24
- language: DocsLanguage,
25
- items: IndexEntry[],
26
- includeModelProperties: boolean,
27
- ) {
28
- const env = {
29
- spec,
30
- language,
31
- options: {
32
- renderNestedResources: false,
33
- includeModelProperties,
34
- },
35
- };
36
-
37
- const paths = consolidate(items);
38
- const output = paths.map((entry) => {
39
- const parsed = parseStainlessPath(entry);
40
- const resource = getResourceFromSpec(parsed.resource, spec);
41
- const target = parsed.method ? resource.methods[parsed.method] : resource;
42
- const content = renderMarkdown(env, target);
43
- return [entry, content];
44
- });
45
-
46
- return Object.fromEntries(output);
47
- }
48
-
49
- export function searchAndRender(
50
- spec: SDKJSON.Spec,
51
- language: DocsLanguage,
52
- query: string,
53
- limit?: number,
54
- includeModelProperties: boolean = false,
55
- ) {
56
- const idx = buildIndex(spec, language);
57
- const results = search(idx, query, limit).map(({ item }) => item);
58
- return render(spec, language, results, includeModelProperties);
59
- }
60
-
61
- export { buildIndex };