@stainless-api/docs-ui 0.1.0-beta.6 → 0.1.0-beta.61

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 (206) hide show
  1. package/dist/breadcrumbs-BVskoBYz.d.ts +25 -0
  2. package/dist/breadcrumbs-C9LLJyuJ.d.ts +25 -0
  3. package/dist/breadcrumbs-CqA6kow2.js +63 -0
  4. package/dist/chunk-BN_g-Awi.js +18 -0
  5. package/dist/cli-0bJ66S1r.js +157 -0
  6. package/dist/component-CjJJYIxG.js +23 -0
  7. package/dist/component-generics-BC_P155r.d.ts +30 -0
  8. package/dist/component-generics-BkwbbxJF.d.ts +30 -0
  9. package/dist/component-generics-POFirVVb.js +45 -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 +10 -0
  17. package/dist/components/index.js +18 -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.d.ts +2 -0
  27. package/dist/components/sdk.js +10 -0
  28. package/dist/components/sidebar.d.ts +2 -0
  29. package/dist/components/sidebar.js +9 -0
  30. package/dist/components/snippets.d.ts +3 -0
  31. package/dist/components/snippets.js +9 -0
  32. package/dist/components-FEHnQBJC.js +70 -0
  33. package/dist/contexts/component-generics.d.ts +2 -0
  34. package/dist/contexts/component-generics.js +3 -0
  35. package/dist/contexts/component-types.d.ts +16 -0
  36. package/dist/contexts/component-types.js +0 -0
  37. package/dist/contexts/component.d.ts +29 -0
  38. package/dist/contexts/component.js +28 -0
  39. package/dist/contexts/docs.d.ts +2 -0
  40. package/dist/contexts/docs.js +3 -0
  41. package/dist/contexts/index.d.ts +22 -0
  42. package/dist/contexts/index.js +7 -0
  43. package/dist/contexts/markdown.d.ts +2 -0
  44. package/dist/contexts/markdown.js +4 -0
  45. package/dist/contexts/navigation.d.ts +2 -0
  46. package/dist/contexts/navigation.js +3 -0
  47. package/dist/contexts/use-components.d.ts +14 -0
  48. package/dist/contexts/use-components.js +4 -0
  49. package/dist/contexts-CeV_L_Iy.js +39 -0
  50. package/dist/csharp-Dl2RIiYP.js +283 -0
  51. package/dist/docs--qWFuJCM.d.ts +46 -0
  52. package/dist/docs-DSFRsmbQ.d.ts +46 -0
  53. package/dist/docs-Di94viZV.js +54 -0
  54. package/dist/go-DuKdRGqU.js +303 -0
  55. package/dist/http-C7bu4oCl.js +331 -0
  56. package/dist/icons-BYKn5X8E.js +885 -0
  57. package/dist/index-C0qvL4yP.d.ts +15 -0
  58. package/dist/index-DE1vA8T2.d.ts +302 -0
  59. package/dist/index-DsFyACw9.d.ts +15 -0
  60. package/dist/index-FDM-j9s-.d.ts +302 -0
  61. package/dist/index-zNpvNvtN.d.ts +1691 -0
  62. package/dist/index.d.ts +19 -0
  63. package/dist/index.js +30 -7542
  64. package/dist/java-DSyzO-6F.js +403 -0
  65. package/dist/languages/cli.d.ts +11 -0
  66. package/dist/languages/cli.js +20 -0
  67. package/dist/languages/csharp.d.ts +11 -0
  68. package/dist/languages/csharp.js +9 -0
  69. package/dist/languages/go.d.ts +11 -0
  70. package/dist/languages/go.js +9 -0
  71. package/dist/languages/http.d.ts +11 -0
  72. package/dist/languages/http.js +19 -0
  73. package/dist/languages/index.d.ts +11 -0
  74. package/dist/languages/index.js +27 -0
  75. package/dist/languages/java.d.ts +11 -0
  76. package/dist/languages/java.js +9 -0
  77. package/dist/languages/python.d.ts +11 -0
  78. package/dist/languages/python.js +9 -0
  79. package/dist/languages/ruby.d.ts +11 -0
  80. package/dist/languages/ruby.js +9 -0
  81. package/dist/languages/typescript.d.ts +11 -0
  82. package/dist/languages/typescript.js +9 -0
  83. package/dist/languages-BO5YJ6cy.js +28 -0
  84. package/dist/markdown/index.d.ts +12 -0
  85. package/dist/markdown/index.js +105 -0
  86. package/dist/markdown/md.d.ts +15 -0
  87. package/dist/markdown/md.js +41 -0
  88. package/dist/markdown/printer.d.ts +13 -0
  89. package/dist/markdown/printer.js +98 -0
  90. package/dist/markdown/utils.d.ts +21 -0
  91. package/dist/markdown/utils.js +31 -0
  92. package/dist/markdown-B517MrZh.d.ts +22 -0
  93. package/dist/markdown-C7Tb41LZ.d.ts +22 -0
  94. package/dist/markdown-D2JWyRws.js +49 -0
  95. package/dist/method-BaQEZVlw.d.ts +59 -0
  96. package/dist/method-Dln4ZTIB.d.ts +59 -0
  97. package/dist/method-jTnA0G8m.js +90 -0
  98. package/dist/navigation-XhIgqXwM.d.ts +29 -0
  99. package/dist/navigation-aoYZ_tl4.js +24 -0
  100. package/dist/navigation-rKdts-BR.d.ts +29 -0
  101. package/dist/overview-B3kgyac2.d.ts +39 -0
  102. package/dist/overview-BnagZfH1.js +139 -0
  103. package/dist/overview-Dp-gGl3v.d.ts +39 -0
  104. package/dist/primitives-B6zu2rrx.d.ts +105 -0
  105. package/dist/primitives-DQLc9kN7.js +250 -0
  106. package/dist/primitives-VtUGoYwX.d.ts +105 -0
  107. package/dist/properties-Bun4nfUE.d.ts +54 -0
  108. package/dist/properties-DGL2J11L.js +131 -0
  109. package/dist/properties-ZOIqpkET.d.ts +54 -0
  110. package/dist/python-D8ABqtn1.js +269 -0
  111. package/dist/routing-Ce0_tBW6.js +197 -0
  112. package/dist/routing-CtbZJru_.d.ts +54 -0
  113. package/dist/routing.d.ts +2 -0
  114. package/dist/routing.js +3 -180
  115. package/dist/ruby-261jvCjl.js +387 -0
  116. package/dist/sdk-BebFnWYL.d.ts +118 -0
  117. package/dist/sdk-CIxaNoAs.d.ts +118 -0
  118. package/dist/sdk-GGpyGTao.js +338 -0
  119. package/dist/sidebar-BWno0E4w.js +85 -0
  120. package/dist/sidebar-CLsIJZZf.d.ts +36 -0
  121. package/dist/sidebar-D4m_pVpS.d.ts +36 -0
  122. package/dist/snippets-CwVjwsAo.d.ts +53 -0
  123. package/dist/snippets-Ym3mnHO3.d.ts +53 -0
  124. package/dist/snippets-kI8eNs1F.js +164 -0
  125. package/dist/spec.d.ts +65 -0
  126. package/dist/spec.js +167 -0
  127. package/dist/style-LwfvXElj.js +170 -0
  128. package/dist/style.d.ts +169 -0
  129. package/dist/style.js +3 -0
  130. package/dist/styles/main.css +722 -755
  131. package/dist/styles/main.js +0 -0
  132. package/dist/styles/primitives.css +322 -459
  133. package/dist/styles/primitives.js +0 -0
  134. package/dist/styles/resets.css +32 -41
  135. package/dist/styles/resets.js +0 -0
  136. package/dist/styles/search.css +192 -270
  137. package/dist/styles/search.js +0 -0
  138. package/dist/styles/sidebar.css +56 -61
  139. package/dist/styles/sidebar.js +0 -0
  140. package/dist/styles/variables.css +26 -89
  141. package/dist/styles/variables.js +0 -0
  142. package/dist/styles.css +3145 -0
  143. package/dist/styles.mjs +1 -0
  144. package/dist/typescript-D924WidI.js +449 -0
  145. package/dist/use-components-BUz3GbO4.js +7 -0
  146. package/dist/utils-D01mAUfQ.js +32 -0
  147. package/dist/utils.d.ts +14 -0
  148. package/dist/utils.js +3 -0
  149. package/package.json +73 -21
  150. package/dist/mcp.js +0 -16003
  151. package/dist/styles/snippets.css +0 -132
  152. package/src/components/breadcrumbs.tsx +0 -94
  153. package/src/components/chat.tsx +0 -154
  154. package/src/components/dropdown.tsx +0 -91
  155. package/src/components/icons.tsx +0 -584
  156. package/src/components/index.ts +0 -9
  157. package/src/components/method.tsx +0 -144
  158. package/src/components/overview.tsx +0 -159
  159. package/src/components/primitives.tsx +0 -284
  160. package/src/components/properties.tsx +0 -130
  161. package/src/components/scripts/dropdown.ts +0 -78
  162. package/src/components/sdk.tsx +0 -402
  163. package/src/components/sidebar.tsx +0 -99
  164. package/src/components/snippets.tsx +0 -179
  165. package/src/contexts/component-generics.tsx +0 -48
  166. package/src/contexts/component-types.tsx +0 -5
  167. package/src/contexts/component.tsx +0 -32
  168. package/src/contexts/docs.tsx +0 -75
  169. package/src/contexts/index.tsx +0 -17
  170. package/src/contexts/markdown.tsx +0 -43
  171. package/src/contexts/navigation.tsx +0 -44
  172. package/src/contexts/search.tsx +0 -28
  173. package/src/contexts/use-components.tsx +0 -4
  174. package/src/index.ts +0 -6
  175. package/src/languages/go.tsx +0 -281
  176. package/src/languages/http.tsx +0 -321
  177. package/src/languages/index.ts +0 -26
  178. package/src/languages/java.tsx +0 -358
  179. package/src/languages/python.tsx +0 -255
  180. package/src/languages/ruby.tsx +0 -320
  181. package/src/languages/typescript.tsx +0 -393
  182. package/src/markdown/index.ts +0 -107
  183. package/src/markdown/md.ts +0 -45
  184. package/src/markdown/utils.ts +0 -49
  185. package/src/routing.ts +0 -238
  186. package/src/search/form.tsx +0 -127
  187. package/src/search/index.tsx +0 -1
  188. package/src/search/indexer.ts +0 -246
  189. package/src/search/mcp.ts +0 -61
  190. package/src/search/printer.tsx +0 -86
  191. package/src/search/providers/algolia.ts +0 -88
  192. package/src/search/providers/fuse.ts +0 -19
  193. package/src/search/providers/pagefind.ts +0 -17
  194. package/src/search/providers/walker.ts +0 -30
  195. package/src/search/results.tsx +0 -181
  196. package/src/search/state.ts +0 -64
  197. package/src/search/types.ts +0 -116
  198. package/src/style.ts +0 -197
  199. package/src/styles/main.css +0 -993
  200. package/src/styles/primitives.css +0 -573
  201. package/src/styles/resets.css +0 -47
  202. package/src/styles/search.css +0 -342
  203. package/src/styles/sidebar.css +0 -87
  204. package/src/styles/snippets.css +0 -132
  205. package/src/styles/variables.css +0 -90
  206. 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 };