@stainless-api/docs-search 0.1.0-beta.4 → 0.1.0-beta.40
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/dist/context.d.ts +1 -2
- package/dist/context.js +30 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +50 -49
- package/dist/indexer.d.ts +35 -0
- package/dist/{indexer-DBU0POrK.js → indexer.js} +10 -9
- package/dist/mcp.d.ts +3 -7
- package/dist/mcp.js +2 -4
- package/dist/providers/algolia.d.ts +3 -4
- package/dist/providers/algolia.js +81 -4
- package/dist/providers/fuse.d.ts +2 -3
- package/dist/providers/fuse.js +3 -5
- package/dist/providers/pagefind.d.ts +1 -1
- package/dist/providers/pagefind.js +19 -3
- package/dist/providers/walker.d.ts +2 -3
- package/dist/providers/walker.js +3 -5
- package/dist/types-O3Jwo7Us.d.ts +1604 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +34 -3
- package/package.json +20 -16
- package/dist/algolia-BOY-OcxU.js +0 -83
- package/dist/context-CBTWkDal.js +0 -32
- package/dist/pagefind-Dcn-gjDe.js +0 -15
- package/dist/types-BhJLoaNF.js +0 -35
- package/dist/types-Gg968wOz.d.ts +0 -91
package/dist/context.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { f as ResultType, g as SearchSettings, h as SearchParams } from "./types-
|
|
2
|
-
import * as React from "react";
|
|
1
|
+
import { f as ResultType, g as SearchSettings, h as SearchParams } from "./types-O3Jwo7Us.js";
|
|
3
2
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
4
3
|
|
|
5
4
|
//#region src/context.d.ts
|
package/dist/context.js
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { search } from "./providers/algolia.js";
|
|
2
|
+
import { createContext, use, useCallback } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/context.tsx
|
|
5
|
+
function createStrictContext(displayName) {
|
|
6
|
+
const Context = createContext(null);
|
|
7
|
+
Context.displayName = displayName;
|
|
8
|
+
function useStrictContext() {
|
|
9
|
+
const context = use(Context);
|
|
10
|
+
if (context === null) throw new Error(`use${displayName} must be used within a ${displayName}Provider`);
|
|
11
|
+
return context;
|
|
12
|
+
}
|
|
13
|
+
return [Context.Provider, useStrictContext];
|
|
14
|
+
}
|
|
15
|
+
const [Provider, useSearchContext] = createStrictContext("SearchContext");
|
|
16
|
+
function useSearch() {
|
|
17
|
+
const { settings } = useSearchContext();
|
|
18
|
+
return useCallback((params) => search({
|
|
19
|
+
settings,
|
|
20
|
+
params
|
|
21
|
+
}), [settings]);
|
|
22
|
+
}
|
|
23
|
+
function SearchProvider({ children, ...props }) {
|
|
24
|
+
return /* @__PURE__ */ jsx(Provider, {
|
|
25
|
+
value: props,
|
|
26
|
+
children
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { SearchProvider, useSearch, useSearchContext };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import {
|
|
3
|
-
import "./
|
|
4
|
-
import {
|
|
5
|
-
import { t as guideSearch } from "./pagefind-Dcn-gjDe.js";
|
|
6
|
-
import * as React from "react";
|
|
1
|
+
import { QueryKinds } from "./types.js";
|
|
2
|
+
import { useSearch, useSearchContext } from "./context.js";
|
|
3
|
+
import { guideSearch } from "./providers/pagefind.js";
|
|
4
|
+
import { createElement, useEffect, useRef, useState } from "react";
|
|
7
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { BookOpenText, Box, Code, Folder, Search, Wrench
|
|
6
|
+
import { BookOpenText, Box, Code, Folder, Search, Wrench } from "lucide-react";
|
|
9
7
|
import { useLanguage } from "@stainless-api/docs-ui/contexts";
|
|
10
8
|
import { useComponents } from "@stainless-api/docs-ui/contexts/use-components";
|
|
11
9
|
import style from "@stainless-api/docs-ui/style";
|
|
12
|
-
|
|
10
|
+
import { Button } from "@stainless-api/ui-primitives";
|
|
13
11
|
//#region src/results.tsx
|
|
14
12
|
const QueryKindDisplay = {
|
|
15
13
|
all: {
|
|
@@ -215,7 +213,6 @@ function SearchResultContent({ result }) {
|
|
|
215
213
|
});
|
|
216
214
|
}
|
|
217
215
|
}
|
|
218
|
-
|
|
219
216
|
//#endregion
|
|
220
217
|
//#region src/form.tsx
|
|
221
218
|
function SearchForm() {
|
|
@@ -223,35 +220,40 @@ function SearchForm() {
|
|
|
223
220
|
const search = useSearch();
|
|
224
221
|
const language = useLanguage();
|
|
225
222
|
const { onSelect, pageFind } = useSearchContext();
|
|
226
|
-
const [results, setResults] =
|
|
227
|
-
const [filterKind, setFilterKind] =
|
|
228
|
-
const [searchQuery, setSearchQuery] =
|
|
229
|
-
const inputRef =
|
|
230
|
-
|
|
231
|
-
const guideLimit =
|
|
232
|
-
const
|
|
233
|
-
const
|
|
223
|
+
const [results, setResults] = useState(null);
|
|
224
|
+
const [filterKind, setFilterKind] = useState("all");
|
|
225
|
+
const [searchQuery, setSearchQuery] = useState("");
|
|
226
|
+
const inputRef = useRef(null);
|
|
227
|
+
useEffect(() => {
|
|
228
|
+
const guideLimit = 25;
|
|
229
|
+
const apiKindFilter = ["all", "guide"].includes(filterKind) ? void 0 : filterKind;
|
|
230
|
+
const ac = new AbortController();
|
|
231
|
+
Promise.all([pageFind ? guideSearch(pageFind, searchQuery, guideLimit) : [], search({
|
|
234
232
|
query: searchQuery,
|
|
235
|
-
kind,
|
|
233
|
+
kind: apiKindFilter,
|
|
236
234
|
language
|
|
237
|
-
})])
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
235
|
+
})]).then(([guideResults, apiResults]) => {
|
|
236
|
+
if (ac.signal.aborted) return;
|
|
237
|
+
setResults({
|
|
238
|
+
items: filterKind === "guide" ? guideResults : filterKind === "all" ? [
|
|
239
|
+
...guideResults.slice(0, 5),
|
|
240
|
+
...apiResults?.hits ?? [],
|
|
241
|
+
...guideResults.slice(5)
|
|
242
|
+
] : apiResults?.hits ?? [],
|
|
243
|
+
counts: {
|
|
244
|
+
...apiResults?.facets?.["kind"],
|
|
245
|
+
guide: guideResults.length,
|
|
246
|
+
all: (apiResults?.nbHits ?? 0) + guideResults.length
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
}).catch(() => {});
|
|
250
|
+
return () => ac.abort();
|
|
251
|
+
}, [
|
|
252
252
|
searchQuery,
|
|
253
253
|
filterKind,
|
|
254
|
-
language
|
|
254
|
+
language,
|
|
255
|
+
search,
|
|
256
|
+
pageFind
|
|
255
257
|
]);
|
|
256
258
|
return /* @__PURE__ */ jsxs("div", {
|
|
257
259
|
className: style.SearchForm,
|
|
@@ -264,19 +266,13 @@ function SearchForm() {
|
|
|
264
266
|
size: 16,
|
|
265
267
|
className: style.Icon
|
|
266
268
|
}),
|
|
267
|
-
right: searchQuery && /* @__PURE__ */ jsx(X, {
|
|
268
|
-
cursor: "pointer",
|
|
269
|
-
onClick: () => clearInput(),
|
|
270
|
-
size: 16,
|
|
271
|
-
className: style.Icon
|
|
272
|
-
}),
|
|
273
269
|
value: searchQuery,
|
|
274
270
|
placeholder: "Search"
|
|
275
271
|
}),
|
|
276
272
|
/* @__PURE__ */ jsx(SearchFilter, {
|
|
277
273
|
results,
|
|
278
274
|
filterKind,
|
|
279
|
-
onChange: (filterKind
|
|
275
|
+
onChange: (filterKind) => setFilterKind(filterKind)
|
|
280
276
|
}),
|
|
281
277
|
/* @__PURE__ */ jsx(Docs.ListView, {
|
|
282
278
|
items: results?.items ?? [],
|
|
@@ -287,16 +283,15 @@ function SearchForm() {
|
|
|
287
283
|
});
|
|
288
284
|
}
|
|
289
285
|
function SearchFilter({ results, filterKind, onChange }) {
|
|
290
|
-
const Docs = useComponents();
|
|
291
286
|
const { pageFind } = useSearchContext();
|
|
292
|
-
const toggles = pageFind ? QueryKinds : QueryKinds.
|
|
287
|
+
const toggles = pageFind ? QueryKinds : QueryKinds.filter((k) => k !== "guide");
|
|
293
288
|
return /* @__PURE__ */ jsx("div", {
|
|
294
289
|
className: style.SearchFilter,
|
|
295
|
-
children: toggles.map((kind, index) => /* @__PURE__ */ jsxs(
|
|
296
|
-
|
|
290
|
+
children: toggles.map((kind, index) => /* @__PURE__ */ jsxs(Button, {
|
|
291
|
+
variant: filterKind === kind ? "accent" : "outline",
|
|
297
292
|
onClick: () => onChange?.(kind),
|
|
298
293
|
children: [
|
|
299
|
-
|
|
294
|
+
createElement(QueryKindDisplay[kind].icon, {
|
|
300
295
|
size: 16,
|
|
301
296
|
className: style.Icon
|
|
302
297
|
}),
|
|
@@ -313,7 +308,14 @@ function SearchFilter({ results, filterKind, onChange }) {
|
|
|
313
308
|
});
|
|
314
309
|
}
|
|
315
310
|
function SearchModal({ id, open: isOpen }) {
|
|
316
|
-
const [open, setOpen] =
|
|
311
|
+
const [open, setOpen] = useState(isOpen ?? false);
|
|
312
|
+
useEffect(() => {
|
|
313
|
+
if (open) document.body.style.overflow = "hidden";
|
|
314
|
+
else document.body.style.overflow = "";
|
|
315
|
+
return () => {
|
|
316
|
+
document.body.style.overflow = "";
|
|
317
|
+
};
|
|
318
|
+
}, [open]);
|
|
317
319
|
return /* @__PURE__ */ jsx("div", {
|
|
318
320
|
id,
|
|
319
321
|
onToggle: (ev) => setOpen(ev.newState === "open"),
|
|
@@ -323,6 +325,5 @@ function SearchModal({ id, open: isOpen }) {
|
|
|
323
325
|
children: open && /* @__PURE__ */ jsx(SearchForm, {})
|
|
324
326
|
});
|
|
325
327
|
}
|
|
326
|
-
|
|
327
328
|
//#endregion
|
|
328
|
-
export { SearchFilter, SearchForm, SearchModal };
|
|
329
|
+
export { SearchFilter, SearchForm, SearchModal };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { b as Resource, n as IndexEntry, x as Spec } from "./types-O3Jwo7Us.js";
|
|
2
|
+
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
+
|
|
4
|
+
//#region src/indexer.d.ts
|
|
5
|
+
declare function getResourceNames(resourceIds: string[], topResources?: Record<string, Resource>): string[];
|
|
6
|
+
declare function generateChatIndex(spec: Spec): Generator<{
|
|
7
|
+
language: string;
|
|
8
|
+
title: string;
|
|
9
|
+
content: string;
|
|
10
|
+
url: string;
|
|
11
|
+
name?: undefined;
|
|
12
|
+
endpoint?: undefined;
|
|
13
|
+
httpMethod?: undefined;
|
|
14
|
+
summary?: undefined;
|
|
15
|
+
description?: undefined;
|
|
16
|
+
stainlessPath?: undefined;
|
|
17
|
+
qualified?: undefined;
|
|
18
|
+
ident?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
language: "cli" | "csharp" | "go" | "http" | "java" | "kotlin" | "node" | "php" | "python" | "ruby" | "terraform" | "typescript";
|
|
21
|
+
title: string;
|
|
22
|
+
name: string;
|
|
23
|
+
endpoint: string;
|
|
24
|
+
httpMethod: string;
|
|
25
|
+
summary: string | undefined;
|
|
26
|
+
description: string | undefined;
|
|
27
|
+
stainlessPath: string;
|
|
28
|
+
qualified: string | undefined;
|
|
29
|
+
ident: string | undefined;
|
|
30
|
+
content: string;
|
|
31
|
+
url: string | null;
|
|
32
|
+
}, void, unknown>;
|
|
33
|
+
declare function generateIndex(spec: Spec, renderMarkdownFn?: (_: string) => string | null, includeTypes?: boolean, languages?: DocsLanguage[]): Generator<IndexEntry>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { generateChatIndex, generateIndex, getResourceNames };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Languages, generateRoute, parseStainlessPath, walkTree } from "@stainless-api/docs-ui/routing";
|
|
2
2
|
import { printer, renderMarkdown } from "@stainless-api/docs-ui/markdown";
|
|
3
|
-
|
|
3
|
+
import { isResourceEmpty } from "@stainless-api/docs-ui/utils";
|
|
4
4
|
//#region src/indexer.ts
|
|
5
5
|
function getResourceNames(resourceIds, topResources) {
|
|
6
|
-
let element
|
|
6
|
+
let element;
|
|
7
7
|
let resources = topResources;
|
|
8
8
|
const resourceName = [];
|
|
9
9
|
for (const resource of resourceIds) {
|
|
@@ -72,8 +72,9 @@ function* generateChatIndex(spec) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
75
|
+
function* generateIndex(spec, renderMarkdownFn, includeTypes, languages) {
|
|
76
76
|
const parentCrumbs = {};
|
|
77
|
+
const targetLangs = languages ?? Languages;
|
|
77
78
|
for (const { data } of walkTree(spec, true)) {
|
|
78
79
|
const { kind, name, title, stainlessPath } = data;
|
|
79
80
|
const common = {
|
|
@@ -84,7 +85,8 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
84
85
|
const crumbs = getResourceNames(parseStainlessPath(stainlessPath).resource, spec.resources);
|
|
85
86
|
switch (kind) {
|
|
86
87
|
case "resource":
|
|
87
|
-
|
|
88
|
+
if (isResourceEmpty(data)) break;
|
|
89
|
+
for (const language of targetLangs) {
|
|
88
90
|
if (!data[language]) continue;
|
|
89
91
|
parentCrumbs[stainlessPath] = crumbs;
|
|
90
92
|
const { Name, QualifiedName } = data[language];
|
|
@@ -101,7 +103,7 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
101
103
|
break;
|
|
102
104
|
case "http_method": {
|
|
103
105
|
const { summary, endpoint, httpMethod } = data;
|
|
104
|
-
for (const language of
|
|
106
|
+
for (const language of targetLangs) {
|
|
105
107
|
const found = spec.decls[language]?.[stainlessPath];
|
|
106
108
|
if (!found) continue;
|
|
107
109
|
parentCrumbs[stainlessPath] = [...crumbs, title];
|
|
@@ -123,7 +125,7 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
123
125
|
}
|
|
124
126
|
break;
|
|
125
127
|
}
|
|
126
|
-
case "model": for (const language of
|
|
128
|
+
case "model": for (const language of targetLangs) {
|
|
127
129
|
if (!spec.decls[language]) continue;
|
|
128
130
|
parentCrumbs[stainlessPath] = [...crumbs, title];
|
|
129
131
|
const schema = spec.decls[language]?.[`${stainlessPath} > (schema)`];
|
|
@@ -143,7 +145,7 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
|
-
for (const language of
|
|
148
|
+
for (const language of targetLangs) {
|
|
147
149
|
const decls = spec.decls?.[language];
|
|
148
150
|
if (!decls) continue;
|
|
149
151
|
for (const decl of Object.values(decls)) switch (decl.kind) {
|
|
@@ -176,6 +178,5 @@ function* generateIndex(spec, renderMarkdownFn, includeTypes) {
|
|
|
176
178
|
}
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
|
-
|
|
180
181
|
//#endregion
|
|
181
|
-
export { generateIndex
|
|
182
|
+
export { generateChatIndex, generateIndex, getResourceNames };
|
package/dist/mcp.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { n as IndexEntry, r as IndexMethod } from "./types-
|
|
1
|
+
import { n as IndexEntry, r as IndexMethod, x as Spec } from "./types-O3Jwo7Us.js";
|
|
2
|
+
import { generateIndex } from "./indexer.js";
|
|
2
3
|
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
4
4
|
|
|
5
|
-
//#region src/indexer.d.ts
|
|
6
|
-
|
|
7
|
-
declare function generateIndex(spec: SDKJSON.Spec, renderMarkdownFn?: (_: string) => string | null, includeTypes?: boolean): Generator<IndexEntry>;
|
|
8
|
-
//#endregion
|
|
9
5
|
//#region src/mcp.d.ts
|
|
10
6
|
type Item = IndexEntry & IndexMethod;
|
|
11
|
-
declare function render(spec:
|
|
7
|
+
declare function render(spec: Spec, language: DocsLanguage, items: Item[], includeModelProperties: boolean): any;
|
|
12
8
|
//#endregion
|
|
13
9
|
export { generateIndex, render };
|
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { generateIndex } from "./indexer.js";
|
|
2
2
|
import { parseStainlessPath } from "@stainless-api/docs-ui/routing";
|
|
3
3
|
import { renderMarkdown } from "@stainless-api/docs-ui/markdown";
|
|
4
4
|
import { getResourceFromSpec } from "@stainless-api/docs-ui/utils";
|
|
5
|
-
|
|
6
5
|
//#region src/mcp.ts
|
|
7
6
|
function consolidate(results) {
|
|
8
7
|
const resources = /* @__PURE__ */ new Set();
|
|
@@ -31,6 +30,5 @@ function render(spec, language, items, includeModelProperties) {
|
|
|
31
30
|
});
|
|
32
31
|
return Object.fromEntries(output);
|
|
33
32
|
}
|
|
34
|
-
|
|
35
33
|
//#endregion
|
|
36
|
-
export { generateIndex, render };
|
|
34
|
+
export { generateIndex, render };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { f as ResultType, g as SearchSettings, h as SearchParams, s as ProseIndexEntry } from "../types-
|
|
2
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
1
|
+
import { f as ResultType, g as SearchSettings, h as SearchParams, n as IndexEntry, s as ProseIndexEntry, x as Spec } from "../types-O3Jwo7Us.js";
|
|
3
2
|
|
|
4
3
|
//#region src/providers/algolia.d.ts
|
|
5
|
-
declare function buildIndex(appId: string, indexName: string, writeKey: string,
|
|
6
|
-
declare function buildChatIndex(appId: string, indexName: string, writeKey: string, spec:
|
|
4
|
+
declare function buildIndex(appId: string, indexName: string, writeKey: string, content: Spec | IndexEntry[], renderMarkdown: (_: string) => string | null): Promise<void>;
|
|
5
|
+
declare function buildChatIndex(appId: string, indexName: string, writeKey: string, spec: Spec): Promise<void>;
|
|
7
6
|
declare function buildProseIndex(appId: string, indexName: string, writeKey: string, objects: ProseIndexEntry[]): Promise<void>;
|
|
8
7
|
declare function search({
|
|
9
8
|
settings: {
|
|
@@ -1,4 +1,81 @@
|
|
|
1
|
-
import "../indexer
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { generateChatIndex, generateIndex } from "../indexer.js";
|
|
2
|
+
import { SearchableAttributes, SearchableAttributesChat, SearchableAttributesProse } from "../types.js";
|
|
3
|
+
import { searchClient } from "@algolia/client-search";
|
|
4
|
+
//#region src/providers/algolia.ts
|
|
5
|
+
async function buildIndex(appId, indexName, writeKey, content, renderMarkdown) {
|
|
6
|
+
if (!appId || !indexName || !writeKey) return;
|
|
7
|
+
const objects = Array.isArray(content) ? content : Array.from(generateIndex(content, renderMarkdown));
|
|
8
|
+
const client = searchClient(appId, writeKey);
|
|
9
|
+
await client.setSettings({
|
|
10
|
+
indexName,
|
|
11
|
+
indexSettings: {
|
|
12
|
+
highlightPreTag: "<mark>",
|
|
13
|
+
highlightPostTag: "</mark>",
|
|
14
|
+
customRanking: ["asc(priority)"],
|
|
15
|
+
attributesForFaceting: ["language", "kind"],
|
|
16
|
+
searchableAttributes: [...SearchableAttributes]
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
await client.replaceAllObjects({
|
|
20
|
+
indexName,
|
|
21
|
+
objects
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function buildChatIndex(appId, indexName, writeKey, spec) {
|
|
25
|
+
if (!appId || !indexName || !writeKey) return;
|
|
26
|
+
const objects = Array.from(generateChatIndex(spec));
|
|
27
|
+
const client = searchClient(appId, writeKey);
|
|
28
|
+
await client.setSettings({
|
|
29
|
+
indexName,
|
|
30
|
+
indexSettings: {
|
|
31
|
+
attributesForFaceting: ["language"],
|
|
32
|
+
attributeForDistinct: "stainlessPath",
|
|
33
|
+
searchableAttributes: SearchableAttributesChat
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
await client.replaceAllObjects({
|
|
37
|
+
indexName,
|
|
38
|
+
objects
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function buildProseIndex(appId, indexName, writeKey, objects) {
|
|
42
|
+
if (!appId || !indexName || !writeKey) return;
|
|
43
|
+
const client = searchClient(appId, writeKey);
|
|
44
|
+
await client.setSettings({
|
|
45
|
+
indexName,
|
|
46
|
+
indexSettings: { searchableAttributes: SearchableAttributesProse }
|
|
47
|
+
});
|
|
48
|
+
await client.replaceAllObjects({
|
|
49
|
+
indexName,
|
|
50
|
+
objects
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async function search({ settings: { appId, indexName, searchKey }, params: { query, language, kind } }) {
|
|
54
|
+
const client = searchClient(appId, searchKey);
|
|
55
|
+
const filters = language ? `language:${language}` : void 0;
|
|
56
|
+
const facetFilters = kind ? [`kind:${kind}`] : void 0;
|
|
57
|
+
const { results } = await client.search({ requests: [{
|
|
58
|
+
query,
|
|
59
|
+
indexName,
|
|
60
|
+
filters,
|
|
61
|
+
hitsPerPage: 5,
|
|
62
|
+
facets: ["kind"]
|
|
63
|
+
}, {
|
|
64
|
+
query,
|
|
65
|
+
indexName,
|
|
66
|
+
filters,
|
|
67
|
+
facetFilters,
|
|
68
|
+
facets: ["kind"],
|
|
69
|
+
hitsPerPage: 50
|
|
70
|
+
}] });
|
|
71
|
+
if ("hits" in results[0] && "hits" in results[1]) {
|
|
72
|
+
const [{ nbHits, facets }, { hits }] = results;
|
|
73
|
+
return {
|
|
74
|
+
hits,
|
|
75
|
+
nbHits: nbHits ?? 0,
|
|
76
|
+
facets
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
export { buildChatIndex, buildIndex, buildProseIndex, search };
|
package/dist/providers/fuse.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { n as IndexEntry } from "../types-
|
|
1
|
+
import { n as IndexEntry, x as Spec } from "../types-O3Jwo7Us.js";
|
|
2
2
|
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
3
|
import * as fuse_js0 from "fuse.js";
|
|
4
4
|
import { FuseIndex } from "fuse.js";
|
|
5
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
6
5
|
|
|
7
6
|
//#region src/providers/fuse.d.ts
|
|
8
7
|
type FuseIndexData = {
|
|
9
8
|
content: IndexEntry[];
|
|
10
9
|
index: FuseIndex<IndexEntry>;
|
|
11
10
|
};
|
|
12
|
-
declare function buildIndex(spec:
|
|
11
|
+
declare function buildIndex(spec: Spec, language?: DocsLanguage): FuseIndexData;
|
|
13
12
|
declare function search({
|
|
14
13
|
content,
|
|
15
14
|
index
|
package/dist/providers/fuse.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { generateIndex } from "../indexer.js";
|
|
2
|
+
import { SearchableAttributes } from "../types.js";
|
|
3
3
|
import Fuse from "fuse.js";
|
|
4
|
-
|
|
5
4
|
//#region src/providers/fuse.ts
|
|
6
5
|
function buildIndex(spec, language) {
|
|
7
6
|
const idx = Array.from(generateIndex(spec, void 0, false));
|
|
@@ -14,6 +13,5 @@ function buildIndex(spec, language) {
|
|
|
14
13
|
function search({ content, index }, query, limit = 100) {
|
|
15
14
|
return new Fuse(content, { keys: [...SearchableAttributes] }, index).search(query).slice(0, limit);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
|
-
export { buildIndex, search };
|
|
17
|
+
export { buildIndex, search };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as GuideResultType } from "../types-
|
|
1
|
+
import { t as GuideResultType } from "../types-O3Jwo7Us.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/pagefind.d.ts
|
|
4
4
|
declare function guideSearch(loadPath: string, query: string, limit?: number): Promise<GuideResultType[]>;
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/providers/pagefind.ts
|
|
2
|
+
async function loadPagefind(path) {
|
|
3
|
+
return await import(new URL(path, import.meta.url).href);
|
|
4
|
+
}
|
|
5
|
+
async function guideSearch(loadPath, query, limit) {
|
|
6
|
+
try {
|
|
7
|
+
const response = await (await loadPagefind(loadPath)).search(query);
|
|
8
|
+
const items = limit ? response.results.slice(0, limit) : response.results;
|
|
9
|
+
return Promise.all(items.map((result) => result.data().then((data) => ({
|
|
10
|
+
...result,
|
|
11
|
+
data
|
|
12
|
+
}))));
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error(error);
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { guideSearch };
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { n as IndexEntry } from "../types-
|
|
1
|
+
import { n as IndexEntry, x as Spec } from "../types-O3Jwo7Us.js";
|
|
2
2
|
import { DocsLanguage } from "@stainless-api/docs-ui/routing";
|
|
3
|
-
import * as SDKJSON from "@stainless/sdk-json";
|
|
4
3
|
|
|
5
4
|
//#region src/providers/walker.d.ts
|
|
6
|
-
declare function buildIndex(spec:
|
|
5
|
+
declare function buildIndex(spec: Spec): Generator<IndexEntry, any, any>;
|
|
7
6
|
declare function search(index: Generator<IndexEntry>, language: DocsLanguage, query: string, limit?: number): IndexEntry[];
|
|
8
7
|
//#endregion
|
|
9
8
|
export { buildIndex, search };
|
package/dist/providers/walker.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { generateIndex } from "../indexer.js";
|
|
2
|
+
import { SearchableAttributes } from "../types.js";
|
|
4
3
|
//#region src/providers/walker.ts
|
|
5
4
|
function buildIndex(spec) {
|
|
6
5
|
return generateIndex(spec, void 0, false);
|
|
@@ -18,6 +17,5 @@ function search(index, language, query, limit = 100) {
|
|
|
18
17
|
const results = findEntryInIndex(index, language, query);
|
|
19
18
|
return Array.from(results).sort((a, b) => a.priority - b.priority).slice(0, limit);
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
//#endregion
|
|
23
|
-
export { buildIndex, search };
|
|
21
|
+
export { buildIndex, search };
|