@stainless-api/docs 0.1.0-beta.67 → 0.1.0-beta.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @stainless-api/docs
2
2
 
3
+ ## 0.1.0-beta.69
4
+
5
+ ### Patch Changes
6
+
7
+ - 67aa6b5: improves UI for algolia search on desktop and mobile
8
+ - bf9bdd4: Remove old/broken mintlify-compat Steps implementation in favor of the new component
9
+ - 68f4528: Adds support for opengraph images
10
+ - Updated dependencies [67aa6b5]
11
+ - @stainless-api/docs-search@0.1.0-beta.6
12
+ - @stainless-api/docs-ui@0.1.0-beta.54
13
+
14
+ ## 0.1.0-beta.68
15
+
16
+ ### Patch Changes
17
+
18
+ - add prose docs vector indexing
19
+
3
20
  ## 0.1.0-beta.67
4
21
 
5
22
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stainless-api/docs",
3
- "version": "0.1.0-beta.67",
3
+ "version": "0.1.0-beta.69",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -17,7 +17,11 @@
17
17
  "./font-imports": "./styles/fonts.css",
18
18
  "./components": "./stl-docs/components/index.ts",
19
19
  "./components/scripts": "./stl-docs/components/scripts.ts",
20
- "./components/Head": "./stl-docs/components/Head.astro"
20
+ "./docs-config": "./stl-docs/loadStlDocsConfig.ts",
21
+ "./cms-client": "./plugin/cms/client.ts",
22
+ "./generate-docs-routes": "./plugin/helpers/generateDocsRoutes.ts",
23
+ "./components/Head": "./stl-docs/components/Head.astro",
24
+ "./components/ContentBreadcrumbs": "./stl-docs/components/ContentBreadcrumbs.tsx"
21
25
  },
22
26
  "keywords": [],
23
27
  "author": "",
@@ -36,6 +40,7 @@
36
40
  "@astrojs/markdown-remark": "^6.3.10",
37
41
  "@astrojs/react": "^4.4.2",
38
42
  "@stainless-api/sdk": "0.1.0-alpha.19",
43
+ "astro-expressive-code": "^0.41.3",
39
44
  "cheerio": "^1.1.2",
40
45
  "clsx": "^2.1.1",
41
46
  "dotenv": "17.2.3",
@@ -53,8 +58,8 @@
53
58
  "vite-plugin-prebundle-workers": "^0.2.0",
54
59
  "web-worker": "^1.5.0",
55
60
  "yaml": "^2.8.2",
56
- "@stainless-api/docs-search": "0.1.0-beta.5",
57
- "@stainless-api/docs-ui": "0.1.0-beta.53",
61
+ "@stainless-api/docs-search": "0.1.0-beta.6",
62
+ "@stainless-api/docs-ui": "0.1.0-beta.54",
58
63
  "@stainless-api/ui-primitives": "0.1.0-beta.40"
59
64
  },
60
65
  "devDependencies": {
@@ -1,7 +1,7 @@
1
1
  ---
2
- import { Icon } from '@astrojs/starlight/components';
3
2
  import { DocsSearch } from './SearchIsland';
4
3
  import { Button } from '@stainless-api/ui-primitives';
4
+ import { SearchIcon, XIcon } from 'lucide-react';
5
5
  ---
6
6
 
7
7
  <site-search>
@@ -13,7 +13,8 @@ import { Button } from '@stainless-api/ui-primitives';
13
13
  variant="outline"
14
14
  className="stl-algolia-search"
15
15
  >
16
- <Icon name="magnifier" />
16
+ <SearchIcon className="icon-search" size={14} />
17
+ <XIcon className="icon-close" size={14} />
17
18
  <span class="sl-hidden md:sl-block" aria-hidden="true">{Astro.locals.t('search.label')}</span>
18
19
  <kbd class="sl-hidden md:sl-flex" style="display: none;">
19
20
  <kbd>{Astro.locals.t('search.ctrlKey')}</kbd><kbd>K</kbd>
@@ -65,4 +66,32 @@ import { Button } from '@stainless-api/ui-primitives';
65
66
  width: unset;
66
67
  flex-grow: 1;
67
68
  }
69
+ .stl-algolia-search {
70
+ padding: 0;
71
+ }
72
+ @media (min-width: 50rem) {
73
+ .stl-algolia-search {
74
+ padding: 8px 10px;
75
+ }
76
+ }
77
+
78
+ .stl-algolia-search {
79
+ .icon-search {
80
+ display: inline;
81
+ }
82
+
83
+ .icon-close {
84
+ display: none;
85
+ }
86
+ }
87
+
88
+ site-search:has(#stldocs-search[data-stldocs-modal-open='true']) .stl-algolia-search {
89
+ .icon-search {
90
+ display: none;
91
+ }
92
+
93
+ .icon-close {
94
+ display: inline;
95
+ }
96
+ }
68
97
  </style>
@@ -0,0 +1,27 @@
1
+ import type * as SDKJSON from '@stainless/sdk-json';
2
+ import { DocsLanguage, generateRouteList } from '@stainless-api/docs-ui/routing';
3
+ import { EXCLUDE_LANGUAGES } from 'virtual:stl-starlight-virtual-module';
4
+
5
+ export function generateDocsRoutes(spec: SDKJSON.Spec, excludeLanguages: DocsLanguage[] = EXCLUDE_LANGUAGES) {
6
+ const paths = generateRouteList({
7
+ spec,
8
+ excludeLanguages,
9
+ });
10
+ const readmes = Object.entries(spec.readme)
11
+ .filter(([language]) => language !== 'http')
12
+ .filter(([language]) => !excludeLanguages.includes(language as DocsLanguage))
13
+ .map(([language]) => ({
14
+ slug: language,
15
+ stainlessPath: null,
16
+ language: language as DocsLanguage,
17
+ title: 'Readme',
18
+ kind: 'readme',
19
+ }));
20
+
21
+ return [...paths, ...readmes].map(({ slug, stainlessPath, language, title, kind }) => {
22
+ return {
23
+ params: { slug },
24
+ props: { stainlessPath, language, title, kind },
25
+ };
26
+ });
27
+ }
@@ -14,7 +14,6 @@ import type * as SDKJSON from '@stainless/sdk-json';
14
14
  import { LanguageNames, SupportedLanguageSyntaxes, type DocsLanguage } from '@stainless-api/docs-ui/routing';
15
15
 
16
16
  import {
17
- generateRouteList,
18
17
  generateRoute,
19
18
  parseStainlessPath,
20
19
  walkTree,
@@ -67,30 +66,6 @@ import { AIDropdown } from '../../stl-docs/components/AIDropdown';
67
66
  import { ChevronsUpDownIcon } from 'lucide-react';
68
67
  import { MethodDescription } from '../components/MethodDescription';
69
68
 
70
- export function generateDocsRoutes(spec: SDKJSON.Spec) {
71
- const paths = generateRouteList({
72
- spec,
73
- excludeLanguages: EXCLUDE_LANGUAGES as DocsLanguage[],
74
- });
75
- const readmes = Object.entries(spec.readme)
76
- .filter(([language]) => language !== 'http')
77
- .filter(([language]) => !EXCLUDE_LANGUAGES.includes(language as DocsLanguage))
78
- .map(([language]) => ({
79
- slug: language,
80
- stainlessPath: null,
81
- language: language as DocsLanguage,
82
- title: 'Readme',
83
- kind: 'readme',
84
- }));
85
-
86
- return [...paths, ...readmes].map(({ slug, stainlessPath, language, title, kind }) => {
87
- return {
88
- params: { slug },
89
- props: { stainlessPath, language, title, kind },
90
- };
91
- });
92
- }
93
-
94
69
  function isResourceNonEmpty(resource: SDKJSON.Resource) {
95
70
  return (
96
71
  Object.keys(resource.methods ?? {}).length > 0 ||
@@ -1,15 +1,10 @@
1
1
  ---
2
2
  import StarlightPage from '@astrojs/starlight/components/StarlightPage.astro';
3
3
  import { cmsClient } from '../cms/client';
4
- import {
5
- getReadmeContent,
6
- generateDocsRoutes,
7
- buildPageNavigation,
8
- RenderSpec,
9
- astroMarkdownRender,
10
- } from '../react/Routing';
4
+ import { getReadmeContent, buildPageNavigation, RenderSpec, astroMarkdownRender } from '../react/Routing';
11
5
  import { getResourceFromSpec } from '@stainless-api/docs-ui/utils';
12
6
  import { BASE_PATH, CONTENT_PANEL_LAYOUT, MIDDLEWARE } from 'virtual:stl-starlight-virtual-module';
7
+ import { generateDocsRoutes } from '../helpers/generateDocsRoutes';
13
8
 
14
9
  const spec = await cmsClient.getSpec();
15
10
  const routes = generateDocsRoutes(spec);
@@ -2,7 +2,7 @@
2
2
  import type { GetStaticPaths } from 'astro';
3
3
  import Docs from './Docs.astro';
4
4
  import { cmsClient } from '../cms/client';
5
- import { generateDocsRoutes } from '../react/Routing';
5
+ import { generateDocsRoutes } from '../helpers/generateDocsRoutes';
6
6
 
7
7
  export const getStaticPaths = (async () => {
8
8
  const spec = await cmsClient.getSpec();
@@ -1,6 +1,6 @@
1
1
  import type { APIRoute, GetStaticPaths } from 'astro';
2
2
  import { cmsClient } from '../cms/client';
3
- import { generateDocsRoutes, getReadmeContent } from '../react/Routing';
3
+ import { getReadmeContent } from '../react/Routing';
4
4
  import { getResourceFromSpec } from '@stainless-api/docs-ui/utils';
5
5
 
6
6
  import { renderMarkdown } from '@stainless-api/docs-ui/markdown';
@@ -8,6 +8,7 @@ import { renderMarkdown } from '@stainless-api/docs-ui/markdown';
8
8
  import { parseStainlessPath, type DocsLanguage } from '@stainless-api/docs-ui/routing';
9
9
  import type { EnvironmentType } from '@stainless-api/docs-ui/markdown/utils';
10
10
  import { PROPERTY_SETTINGS, MIDDLEWARE } from 'virtual:stl-starlight-virtual-module';
11
+ import { generateDocsRoutes } from '../helpers/generateDocsRoutes';
11
12
 
12
13
  type RouteProps = {
13
14
  stainlessPath: string;
@@ -3,13 +3,11 @@ import Tab from './Tab.astro';
3
3
  import Tabs from './Tabs.astro';
4
4
  import Frame from './Frame.astro';
5
5
  import Columns from './Columns.astro';
6
- import Steps from './Steps.astro';
7
- import Step from './Step.astro';
8
6
  import Accordion from './Accordion.astro';
9
7
  import AccordionGroup from './AccordionGroup.astro';
10
8
 
11
9
  export * from './callouts';
12
10
  export * from './Card';
13
11
 
14
- export { Tab, Tabs, Frame, Columns, Steps, Step, AccordionGroup, Accordion };
15
- export { Button } from '@stainless-api/ui-primitives';
12
+ export { Tab, Tabs, Frame, Columns, AccordionGroup, Accordion };
13
+ export { Button, Steps, Step } from '@stainless-api/ui-primitives';
package/stl-docs/index.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import starlight from '@astrojs/starlight';
2
2
  import react from '@astrojs/react';
3
3
  import type { StarlightPlugin } from '@astrojs/starlight/types';
4
- import { stainlessStarlight } from '../plugin';
5
4
  import { disableCalloutSyntaxStarlightPlugin } from './disableCalloutSyntax';
6
5
 
7
6
  import type { AstroIntegration } from 'astro';
@@ -22,7 +21,8 @@ import type * as StlDocsVirtualModule from 'virtual:stl-docs-virtual-module';
22
21
  import { resolveSrcFile } from '../resolveSrcFile';
23
22
  import { stainlessDocsMarkdownRenderer } from './proseMarkdown/proseMarkdownIntegration';
24
23
  import { setSharedLogger } from '../shared/getSharedLogger';
25
- import { stainlessDocsProseIndexing } from './proseSearchIndexing';
24
+ import { stainlessDocsAlgoliaProseIndexing, stainlessDocsVectorProseIndexing } from './proseSearchIndexing';
25
+ import { stainlessStarlight } from '../plugin';
26
26
 
27
27
  export * from '../plugin';
28
28
 
@@ -244,7 +244,7 @@ function sharedLoggerIntegration(): AstroIntegration {
244
244
  };
245
245
  }
246
246
 
247
- export function stainlessDocs(config: StainlessDocsUserConfig) {
247
+ export function stainlessDocs(config: StainlessDocsUserConfig): StarlightPlugin[] {
248
248
  const normalizedConfigResult = parseStlDocsConfig(config);
249
249
  if (normalizedConfigResult.result === 'error') {
250
250
  // TODO: would be good to use the astro logger somehow
@@ -271,6 +271,7 @@ export function stainlessDocs(config: StainlessDocsUserConfig) {
271
271
  enabled: normalizedConfig.enableProseMarkdownRendering,
272
272
  apiReferenceBasePath,
273
273
  }),
274
- stainlessDocsProseIndexing({ apiReferenceBasePath }),
274
+ stainlessDocsAlgoliaProseIndexing({ apiReferenceBasePath }),
275
+ stainlessDocsVectorProseIndexing(normalizedConfig, apiReferenceBasePath),
275
276
  ];
276
277
  }
@@ -40,7 +40,7 @@ type ExperimentalStarlightCompatibilityConfig = Pick<
40
40
  'components' | 'routeMiddleware' | 'plugins'
41
41
  >;
42
42
 
43
- type Tabs = {
43
+ export type Tabs = {
44
44
  label: string;
45
45
  link: string;
46
46
  sidebar?: SidebarEntry[];
@@ -3,8 +3,10 @@ import { readFile } from 'fs/promises';
3
3
  import { getProsePages } from '../shared/getProsePages';
4
4
  import { getSharedLogger } from '../shared/getSharedLogger';
5
5
  import { bold } from '../shared/terminalUtils';
6
- import { buildProseIndex } from '@stainless-api/docs-search/providers/algolia';
7
6
  import * as cheerio from 'cheerio';
7
+ import { toMarkdown } from './proseMarkdown/toMarkdown';
8
+ import { NormalizedStainlessDocsConfig } from './loadStlDocsConfig';
9
+ import { buildProseIndex } from '@stainless-api/docs-search/providers/algolia';
8
10
 
9
11
  interface ContentBlock {
10
12
  type: 'header' | 'content';
@@ -307,7 +309,7 @@ export function* indexHTML(content: string, root: string, pattern: string) {
307
309
  const root = 'main';
308
310
  const pattern = 'h1, h2, h3, h4, h5, h6, p, li';
309
311
 
310
- export function stainlessDocsProseIndexing({
312
+ export function stainlessDocsAlgoliaProseIndexing({
311
313
  apiReferenceBasePath,
312
314
  }: {
313
315
  apiReferenceBasePath: string | null;
@@ -331,7 +333,7 @@ export function stainlessDocsProseIndexing({
331
333
  }
332
334
 
333
335
  const pagesToRender = await getProsePages({ apiReferenceBasePath, outputBasePath });
334
- logger.info(bold(`Indexing ${pagesToRender.length} prose pages for search`));
336
+ logger.info(bold(`Indexing ${pagesToRender.length} prose pages for algolia search`));
335
337
 
336
338
  const objects = [];
337
339
  for (const absHtmlPath of pagesToRender) {
@@ -353,3 +355,96 @@ export function stainlessDocsProseIndexing({
353
355
  },
354
356
  };
355
357
  }
358
+
359
+ export function stainlessDocsVectorProseIndexing(
360
+ config: NormalizedStainlessDocsConfig,
361
+ apiReferenceBasePath: string | null,
362
+ ): AstroIntegration {
363
+ return {
364
+ name: 'stl-docs-prose-indexing',
365
+ hooks: {
366
+ 'astro:build:done': async ({ logger: localLogger, dir }) => {
367
+ const logger = getSharedLogger({ fallback: localLogger });
368
+ const outputBasePath = dir.pathname;
369
+
370
+ const stainlessProjectName = config.apiReference?.stainlessProject;
371
+
372
+ const {
373
+ STAINLESS_API_KEY: stainlessApiKey,
374
+ STAINLESS_DOCS_SITE_ID: stainlessDocsSiteId,
375
+ STAINLESS_DOCS_REPO_SHA: stainlessDocsRepoSha,
376
+ } = process.env;
377
+
378
+ // Skip indexing if required environment variables are not set
379
+ if (!stainlessApiKey || !stainlessProjectName || !stainlessDocsSiteId || !stainlessDocsRepoSha) {
380
+ logger.info(
381
+ `Skipping vector prose search indexing: required environment/config variables not set, missing: ${[
382
+ !stainlessApiKey && 'STAINLESS_API_KEY',
383
+ !stainlessDocsSiteId && 'STAINLESS_DOCS_SITE_ID',
384
+ !stainlessDocsRepoSha && 'STAINLESS_DOCS_REPO_SHA',
385
+ !stainlessProjectName && 'stainlessProject in apiReference config',
386
+ ]
387
+ .filter(Boolean)
388
+ .join(', ')}`,
389
+ );
390
+ return;
391
+ }
392
+
393
+ const pagesToRender = await getProsePages({ apiReferenceBasePath, outputBasePath });
394
+
395
+ if (pagesToRender.length === 0) {
396
+ logger.info('No prose pages found to index for vector search');
397
+ return;
398
+ }
399
+
400
+ logger.info(bold(`Indexing ${pagesToRender.length} prose pages for vector search`));
401
+
402
+ const objects: {
403
+ id: string;
404
+ tag: string;
405
+ content: string;
406
+ kind: 'prose';
407
+ source: string;
408
+ }[] = [];
409
+ for (const absHtmlPath of pagesToRender) {
410
+ const content = await readFile(absHtmlPath, 'utf-8');
411
+ const markdown = await toMarkdown(content);
412
+
413
+ if (markdown) {
414
+ const idx = indexMarkdown(markdown);
415
+ for (const { chunk, ...entry } of idx)
416
+ objects.push({
417
+ ...entry,
418
+ kind: 'prose',
419
+ source: absHtmlPath.slice(outputBasePath.length),
420
+ });
421
+ }
422
+ }
423
+
424
+ if (objects.length === 0) {
425
+ logger.info('No prose content extracted to index for vector search');
426
+ return;
427
+ }
428
+
429
+ logger.info(bold(`Uploading ${objects.length} prose content chunks to stainless docs index`));
430
+
431
+ const response = await fetch(
432
+ `https://api.stainless.com/api/projects/${stainlessProjectName}/docs-sites/${stainlessDocsSiteId}/index`,
433
+ {
434
+ method: 'POST',
435
+ headers: {
436
+ 'Content-Type': 'application/json',
437
+ Authorization: `Bearer ${stainlessApiKey}`,
438
+ },
439
+ body: JSON.stringify({
440
+ docs_repo_sha: stainlessDocsRepoSha,
441
+ index: objects,
442
+ }),
443
+ },
444
+ );
445
+
446
+ console.log(`docs index API response code ${response.status}: ${await response.text()}`);
447
+ },
448
+ },
449
+ };
450
+ }
package/styles/search.css CHANGED
@@ -57,8 +57,6 @@ site-search {
57
57
  site-search {
58
58
  > button {
59
59
  border-radius: var(--sl-button-border-radius);
60
- padding-inline-start: var(--sl-button-padding-x);
61
- padding-inline-end: var(--sl-button-padding-x);
62
60
  width: 100%;
63
61
  max-width: 30rem;
64
62
  justify-content: start;
@@ -6,10 +6,11 @@ declare module 'virtual:stl-starlight-virtual-module' {
6
6
  import type { CreateShikiHighlighterOptions } from '@astrojs/markdown-remark';
7
7
  import type { PropertySettingsType } from '@stainless-api/docs-ui/contexts';
8
8
  import type { StlStarlightMiddleware } from '@stainless-api/docs/plugin/MiddlewareTypes';
9
+ import type { DocsLanguage } from '@stainless-api/docs-ui/routing';
9
10
 
10
11
  export const BASE_PATH: string;
11
12
  export const CMS_PORT: number;
12
- export const EXCLUDE_LANGUAGES: string[];
13
+ export const EXCLUDE_LANGUAGES: DocsLanguage[];
13
14
  export const DEFAULT_LANGUAGE: string;
14
15
  export const BREADCRUMB_CONFIG: {
15
16
  includeCurrentPage?: boolean;
@@ -1,56 +0,0 @@
1
- ---
2
- export interface Props {
3
- title?: string;
4
- }
5
-
6
- const { title } = Astro.props;
7
- ---
8
-
9
- <li class="stl-ui-mintlify-compat-step" data-stl-ui-element>
10
- <div class="stl-ui-mintlify-compat-step-step-number"></div>
11
- <div>
12
- <p class="stl-ui-mintlify-compat-step-title">{title}</p>
13
- <div class="stl-ui-mintlify-compat-step-content"><slot /></div>
14
- </div>
15
- </li>
16
-
17
- <style>
18
- .stl-ui-mintlify-compat-step {
19
- display: flex;
20
-
21
- &:not(:first-child) {
22
- margin-top: 1rem;
23
- }
24
- }
25
-
26
- .stl-ui-mintlify-compat-step-step-number {
27
- margin-right: 1rem;
28
- display: flex;
29
- align-items: top;
30
- justify-content: center;
31
- margin-top: 4px;
32
-
33
- &::before {
34
- counter-increment: ui-steps;
35
- content: counter(ui-steps);
36
- border-radius: 50%;
37
- height: 1.5rem;
38
- width: 1.5rem;
39
- font-size: 0.8rem;
40
- color: var(--stl-color-foreground);
41
- font-weight: 600;
42
- background-color: var(--stl-color-faint-background);
43
- display: flex;
44
- align-items: center;
45
- justify-content: center;
46
- }
47
- }
48
-
49
- .stl-ui-mintlify-compat-step-title {
50
- font-weight: 600;
51
- color: var(--stl-color-foreground);
52
- }
53
- .stl-ui-mintlify-compat-step-content {
54
- margin-top: 0.5rem;
55
- }
56
- </style>
@@ -1,15 +0,0 @@
1
- <ol class="stl-ui-mintlify-compat-steps"><slot /></ol>
2
-
3
- <style>
4
- .stl-ui-mintlify-compat-steps {
5
- counter-reset: ui-steps;
6
- list-style: none;
7
- margin: 0;
8
- padding: 0;
9
- margin-top: 1rem;
10
-
11
- * {
12
- margin: 0;
13
- }
14
- }
15
- </style>