@btst/plugin-search 0.0.0-stage → 1.0.0-beta.2
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/LICENSE.md +17 -0
- package/dist/api/index.cjs +17 -0
- package/dist/api/index.d.cts +62 -0
- package/dist/api/index.d.mts +62 -0
- package/dist/api/index.d.ts +62 -0
- package/dist/api/index.mjs +4 -0
- package/dist/api/operations.cjs +127 -0
- package/dist/api/operations.mjs +125 -0
- package/dist/api/plugin.cjs +23 -0
- package/dist/api/plugin.mjs +21 -0
- package/dist/client/components/index.cjs +11 -0
- package/dist/client/components/index.d.cts +35 -0
- package/dist/client/components/index.d.mts +35 -0
- package/dist/client/components/index.d.ts +35 -0
- package/dist/client/components/index.mjs +3 -0
- package/dist/client/components/pages/search-page.cjs +39 -0
- package/dist/client/components/pages/search-page.internal.cjs +100 -0
- package/dist/client/components/pages/search-page.internal.mjs +98 -0
- package/dist/client/components/pages/search-page.mjs +37 -0
- package/dist/client/components/search-dialog.cjs +148 -0
- package/dist/client/components/search-dialog.mjs +145 -0
- package/dist/client/components/search-results.cjs +100 -0
- package/dist/client/components/search-results.mjs +96 -0
- package/dist/client/components/source-filter.cjs +31 -0
- package/dist/client/components/source-filter.mjs +29 -0
- package/dist/client/constants.cjs +5 -0
- package/dist/client/constants.mjs +3 -0
- package/dist/client/hooks/index.cjs +10 -0
- package/dist/client/hooks/index.d.cts +340 -0
- package/dist/client/hooks/index.d.mts +340 -0
- package/dist/client/hooks/index.d.ts +340 -0
- package/dist/client/hooks/index.mjs +3 -0
- package/dist/client/hooks/use-search-state.cjs +36 -0
- package/dist/client/hooks/use-search-state.mjs +34 -0
- package/dist/client/hooks/use-search.cjs +44 -0
- package/dist/client/hooks/use-search.mjs +42 -0
- package/dist/client/index.cjs +7 -0
- package/dist/client/index.d.cts +55 -0
- package/dist/client/index.d.mts +55 -0
- package/dist/client/index.d.ts +55 -0
- package/dist/client/index.mjs +1 -0
- package/dist/client/plugin.cjs +76 -0
- package/dist/client/plugin.mjs +74 -0
- package/dist/client/search-state.cjs +20 -0
- package/dist/client/search-state.mjs +17 -0
- package/dist/permissions.cjs +12 -0
- package/dist/permissions.d.cts +12 -0
- package/dist/permissions.d.mts +12 -0
- package/dist/permissions.d.ts +12 -0
- package/dist/permissions.mjs +10 -0
- package/dist/providers.cjs +122 -0
- package/dist/providers.d.cts +82 -0
- package/dist/providers.d.mts +82 -0
- package/dist/providers.d.ts +82 -0
- package/dist/providers.mjs +116 -0
- package/dist/query-keys.cjs +35 -0
- package/dist/query-keys.d.cts +71 -0
- package/dist/query-keys.d.mts +71 -0
- package/dist/query-keys.d.ts +71 -0
- package/dist/query-keys.mjs +32 -0
- package/dist/schemas.cjs +23 -0
- package/dist/schemas.d.cts +14 -0
- package/dist/schemas.d.mts +14 -0
- package/dist/schemas.d.ts +14 -0
- package/dist/schemas.mjs +17 -0
- package/dist/shared/plugin-search.5GvThkZW.d.cts +20 -0
- package/dist/shared/plugin-search.5GvThkZW.d.mts +20 -0
- package/dist/shared/plugin-search.5GvThkZW.d.ts +20 -0
- package/dist/style.css +2 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +53 -0
- package/dist/types.d.mts +53 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.mjs +1 -0
- package/dist/ui/src/components/button.cjs +56 -0
- package/dist/ui/src/components/button.mjs +53 -0
- package/dist/ui/src/components/command.cjs +88 -0
- package/dist/ui/src/components/command.mjs +83 -0
- package/dist/ui/src/components/dialog.cjs +127 -0
- package/dist/ui/src/components/dialog.mjs +105 -0
- package/dist/ui/src/components/input.cjs +23 -0
- package/dist/ui/src/components/input.mjs +21 -0
- package/dist/ui/src/lib/utils.cjs +10 -0
- package/dist/ui/src/lib/utils.mjs +8 -0
- package/package.json +181 -3
- package/README.md +0 -3
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as _btst_stack_plugins_client from '@btst/stack/plugins/client';
|
|
2
|
+
import { ResourceClient } from '@btst/stack/plugins/client';
|
|
3
|
+
import { StackIdentity } from '@btst/stack/context';
|
|
4
|
+
import { SearchResponse } from './types.js';
|
|
5
|
+
import '@btst/stack/plugins/api';
|
|
6
|
+
|
|
7
|
+
/** Identity is a cache discriminator only; it is never sent as HTTP input. */
|
|
8
|
+
type SearchIdentityPartition = StackIdentity | {
|
|
9
|
+
identity: StackIdentity | null;
|
|
10
|
+
generation: number;
|
|
11
|
+
} | `pending:${number}` | `error:${number}`;
|
|
12
|
+
/** Query arguments shared by the search route, dialog, and SSR loader. */
|
|
13
|
+
interface SearchQueryParams {
|
|
14
|
+
q: string;
|
|
15
|
+
sources?: readonly string[];
|
|
16
|
+
page?: number;
|
|
17
|
+
limit?: number;
|
|
18
|
+
}
|
|
19
|
+
declare const searchResources: {
|
|
20
|
+
searchResults: {
|
|
21
|
+
queries: {
|
|
22
|
+
list: {
|
|
23
|
+
path: string;
|
|
24
|
+
query: (params: SearchQueryParams, _identity?: SearchIdentityPartition) => {
|
|
25
|
+
q: string;
|
|
26
|
+
sources: string | undefined;
|
|
27
|
+
page: number;
|
|
28
|
+
limit: number;
|
|
29
|
+
};
|
|
30
|
+
key: (params: SearchQueryParams, identity?: SearchIdentityPartition) => (StackIdentity | {
|
|
31
|
+
identity: StackIdentity | null;
|
|
32
|
+
generation: number;
|
|
33
|
+
} | `pending:${number}` | `error:${number}` | {
|
|
34
|
+
q: string;
|
|
35
|
+
sources: string[] | undefined;
|
|
36
|
+
page: number;
|
|
37
|
+
limit: number;
|
|
38
|
+
} | undefined)[];
|
|
39
|
+
select: (data: unknown) => SearchResponse;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
declare function createSearchQueryKeys(client: ResourceClient, headers?: HeadersInit): _btst_stack_plugins_client.ResourceQueryKeys<{
|
|
45
|
+
searchResults: {
|
|
46
|
+
queries: {
|
|
47
|
+
list: {
|
|
48
|
+
path: string;
|
|
49
|
+
query: (params: SearchQueryParams, _identity?: SearchIdentityPartition) => {
|
|
50
|
+
q: string;
|
|
51
|
+
sources: string | undefined;
|
|
52
|
+
page: number;
|
|
53
|
+
limit: number;
|
|
54
|
+
};
|
|
55
|
+
key: (params: SearchQueryParams, identity?: SearchIdentityPartition) => (StackIdentity | {
|
|
56
|
+
identity: StackIdentity | null;
|
|
57
|
+
generation: number;
|
|
58
|
+
} | `pending:${number}` | `error:${number}` | {
|
|
59
|
+
q: string;
|
|
60
|
+
sources: string[] | undefined;
|
|
61
|
+
page: number;
|
|
62
|
+
limit: number;
|
|
63
|
+
} | undefined)[];
|
|
64
|
+
select: (data: unknown) => SearchResponse;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
|
|
70
|
+
export { createSearchQueryKeys, searchResources };
|
|
71
|
+
export type { SearchIdentityPartition, SearchQueryParams };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createResourceQueryKeys } from '@btst/stack/plugins/client';
|
|
2
|
+
|
|
3
|
+
const searchResources = {
|
|
4
|
+
searchResults: {
|
|
5
|
+
queries: {
|
|
6
|
+
list: {
|
|
7
|
+
path: "/search",
|
|
8
|
+
query: (params, _identity) => ({
|
|
9
|
+
q: params.q.trim(),
|
|
10
|
+
sources: params.sources?.join(","),
|
|
11
|
+
page: params.page ?? 1,
|
|
12
|
+
limit: params.limit ?? 20
|
|
13
|
+
}),
|
|
14
|
+
key: (params, identity) => [
|
|
15
|
+
{
|
|
16
|
+
q: params.q.trim(),
|
|
17
|
+
sources: params.sources ? [...params.sources].sort() : void 0,
|
|
18
|
+
page: params.page ?? 1,
|
|
19
|
+
limit: params.limit ?? 20
|
|
20
|
+
},
|
|
21
|
+
identity
|
|
22
|
+
],
|
|
23
|
+
select: (data) => data
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
function createSearchQueryKeys(client, headers) {
|
|
29
|
+
return createResourceQueryKeys(client, searchResources, headers);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { createSearchQueryKeys, searchResources };
|
package/dist/schemas.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const zod = require('zod');
|
|
4
|
+
|
|
5
|
+
const SEARCH_MAX_SOURCES = 8;
|
|
6
|
+
const SEARCH_MAX_RESULTS = 200;
|
|
7
|
+
const SEARCH_MAX_PAGES = 10;
|
|
8
|
+
const searchSourceIdSchema = zod.z.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
|
|
9
|
+
const searchInputSchema = zod.z.object({
|
|
10
|
+
q: zod.z.string().trim().max(200),
|
|
11
|
+
sources: zod.z.preprocess(
|
|
12
|
+
(value) => typeof value === "string" ? value.split(",").filter(Boolean) : value,
|
|
13
|
+
zod.z.array(searchSourceIdSchema).max(SEARCH_MAX_SOURCES).optional()
|
|
14
|
+
),
|
|
15
|
+
page: zod.z.coerce.number().int().min(1).max(SEARCH_MAX_PAGES).default(1),
|
|
16
|
+
limit: zod.z.coerce.number().int().min(1).max(20).default(20)
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
exports.SEARCH_MAX_PAGES = SEARCH_MAX_PAGES;
|
|
20
|
+
exports.SEARCH_MAX_RESULTS = SEARCH_MAX_RESULTS;
|
|
21
|
+
exports.SEARCH_MAX_SOURCES = SEARCH_MAX_SOURCES;
|
|
22
|
+
exports.searchInputSchema = searchInputSchema;
|
|
23
|
+
exports.searchSourceIdSchema = searchSourceIdSchema;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const SEARCH_MAX_SOURCES = 8;
|
|
4
|
+
declare const SEARCH_MAX_RESULTS = 200;
|
|
5
|
+
declare const SEARCH_MAX_PAGES = 10;
|
|
6
|
+
declare const searchSourceIdSchema: z.ZodString;
|
|
7
|
+
declare const searchInputSchema: z.ZodObject<{
|
|
8
|
+
q: z.ZodString;
|
|
9
|
+
sources: z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodString>>, unknown>;
|
|
10
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
11
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
|
|
14
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchSourceIdSchema };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const SEARCH_MAX_SOURCES = 8;
|
|
4
|
+
declare const SEARCH_MAX_RESULTS = 200;
|
|
5
|
+
declare const SEARCH_MAX_PAGES = 10;
|
|
6
|
+
declare const searchSourceIdSchema: z.ZodString;
|
|
7
|
+
declare const searchInputSchema: z.ZodObject<{
|
|
8
|
+
q: z.ZodString;
|
|
9
|
+
sources: z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodString>>, unknown>;
|
|
10
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
11
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
|
|
14
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchSourceIdSchema };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const SEARCH_MAX_SOURCES = 8;
|
|
4
|
+
declare const SEARCH_MAX_RESULTS = 200;
|
|
5
|
+
declare const SEARCH_MAX_PAGES = 10;
|
|
6
|
+
declare const searchSourceIdSchema: z.ZodString;
|
|
7
|
+
declare const searchInputSchema: z.ZodObject<{
|
|
8
|
+
q: z.ZodString;
|
|
9
|
+
sources: z.ZodPreprocess<z.ZodOptional<z.ZodArray<z.ZodString>>, unknown>;
|
|
10
|
+
page: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
11
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
|
|
14
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchSourceIdSchema };
|
package/dist/schemas.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const SEARCH_MAX_SOURCES = 8;
|
|
4
|
+
const SEARCH_MAX_RESULTS = 200;
|
|
5
|
+
const SEARCH_MAX_PAGES = 10;
|
|
6
|
+
const searchSourceIdSchema = z.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
|
|
7
|
+
const searchInputSchema = z.object({
|
|
8
|
+
q: z.string().trim().max(200),
|
|
9
|
+
sources: z.preprocess(
|
|
10
|
+
(value) => typeof value === "string" ? value.split(",").filter(Boolean) : value,
|
|
11
|
+
z.array(searchSourceIdSchema).max(SEARCH_MAX_SOURCES).optional()
|
|
12
|
+
),
|
|
13
|
+
page: z.coerce.number().int().min(1).max(SEARCH_MAX_PAGES).default(1),
|
|
14
|
+
limit: z.coerce.number().int().min(1).max(20).default(20)
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export { SEARCH_MAX_PAGES, SEARCH_MAX_RESULTS, SEARCH_MAX_SOURCES, searchInputSchema, searchSourceIdSchema };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as _btst_stack_client from '@btst/stack/client';
|
|
2
|
+
|
|
3
|
+
declare function parseSearchState(searchParams?: URLSearchParams | string): _btst_stack_client.InferListState<{
|
|
4
|
+
readonly q: {
|
|
5
|
+
readonly type: "string";
|
|
6
|
+
readonly default: "";
|
|
7
|
+
readonly history: "replace";
|
|
8
|
+
};
|
|
9
|
+
readonly sources: {
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
readonly default: "";
|
|
12
|
+
};
|
|
13
|
+
readonly page: {
|
|
14
|
+
readonly type: "number";
|
|
15
|
+
readonly default: 1;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
type SearchListState = ReturnType<typeof parseSearchState>;
|
|
19
|
+
|
|
20
|
+
export type { SearchListState as S };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as _btst_stack_client from '@btst/stack/client';
|
|
2
|
+
|
|
3
|
+
declare function parseSearchState(searchParams?: URLSearchParams | string): _btst_stack_client.InferListState<{
|
|
4
|
+
readonly q: {
|
|
5
|
+
readonly type: "string";
|
|
6
|
+
readonly default: "";
|
|
7
|
+
readonly history: "replace";
|
|
8
|
+
};
|
|
9
|
+
readonly sources: {
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
readonly default: "";
|
|
12
|
+
};
|
|
13
|
+
readonly page: {
|
|
14
|
+
readonly type: "number";
|
|
15
|
+
readonly default: 1;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
type SearchListState = ReturnType<typeof parseSearchState>;
|
|
19
|
+
|
|
20
|
+
export type { SearchListState as S };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as _btst_stack_client from '@btst/stack/client';
|
|
2
|
+
|
|
3
|
+
declare function parseSearchState(searchParams?: URLSearchParams | string): _btst_stack_client.InferListState<{
|
|
4
|
+
readonly q: {
|
|
5
|
+
readonly type: "string";
|
|
6
|
+
readonly default: "";
|
|
7
|
+
readonly history: "replace";
|
|
8
|
+
};
|
|
9
|
+
readonly sources: {
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
readonly default: "";
|
|
12
|
+
};
|
|
13
|
+
readonly page: {
|
|
14
|
+
readonly type: "number";
|
|
15
|
+
readonly default: 1;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
type SearchListState = ReturnType<typeof parseSearchState>;
|
|
19
|
+
|
|
20
|
+
export type { SearchListState as S };
|
package/dist/style.css
ADDED
package/dist/types.cjs
ADDED
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { OperationContext } from '@btst/stack/plugins/api';
|
|
2
|
+
|
|
3
|
+
/** Stable public source metadata; providers are registered only by application code. */
|
|
4
|
+
type SearchSource = {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
/** A provider's already-authorized public projection. Snippets are plain text. */
|
|
9
|
+
type SearchProviderResult = {
|
|
10
|
+
resourceId: string;
|
|
11
|
+
title: string;
|
|
12
|
+
snippet: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
/** Providers must apply visibility before returning records or continuation metadata. */
|
|
16
|
+
interface SearchProvider extends SearchSource {
|
|
17
|
+
search(context: {
|
|
18
|
+
q: string;
|
|
19
|
+
limit: number;
|
|
20
|
+
request: Request;
|
|
21
|
+
identity: OperationContext<unknown, unknown>["identity"];
|
|
22
|
+
}): Promise<{
|
|
23
|
+
items: readonly SearchProviderResult[];
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
/** Result identity is scoped to its source, with no comparable relevance score. */
|
|
28
|
+
type SearchResult = SearchProviderResult & {
|
|
29
|
+
key: string;
|
|
30
|
+
sourceId: string;
|
|
31
|
+
sourceLabel: string;
|
|
32
|
+
};
|
|
33
|
+
interface SearchInput {
|
|
34
|
+
q: string;
|
|
35
|
+
sources?: readonly string[] | string;
|
|
36
|
+
page?: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Pagination covers a bounded result window, never an exact global total. */
|
|
40
|
+
type SearchResponse = {
|
|
41
|
+
items: SearchResult[];
|
|
42
|
+
sources: SearchSource[];
|
|
43
|
+
page: number;
|
|
44
|
+
limit: number;
|
|
45
|
+
hasMore: boolean;
|
|
46
|
+
nextPage: number | null;
|
|
47
|
+
truncated: boolean;
|
|
48
|
+
};
|
|
49
|
+
interface SearchBackendConfig {
|
|
50
|
+
providers?: readonly SearchProvider[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { SearchBackendConfig, SearchInput, SearchProvider, SearchProviderResult, SearchResponse, SearchResult, SearchSource };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { OperationContext } from '@btst/stack/plugins/api';
|
|
2
|
+
|
|
3
|
+
/** Stable public source metadata; providers are registered only by application code. */
|
|
4
|
+
type SearchSource = {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
/** A provider's already-authorized public projection. Snippets are plain text. */
|
|
9
|
+
type SearchProviderResult = {
|
|
10
|
+
resourceId: string;
|
|
11
|
+
title: string;
|
|
12
|
+
snippet: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
/** Providers must apply visibility before returning records or continuation metadata. */
|
|
16
|
+
interface SearchProvider extends SearchSource {
|
|
17
|
+
search(context: {
|
|
18
|
+
q: string;
|
|
19
|
+
limit: number;
|
|
20
|
+
request: Request;
|
|
21
|
+
identity: OperationContext<unknown, unknown>["identity"];
|
|
22
|
+
}): Promise<{
|
|
23
|
+
items: readonly SearchProviderResult[];
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
/** Result identity is scoped to its source, with no comparable relevance score. */
|
|
28
|
+
type SearchResult = SearchProviderResult & {
|
|
29
|
+
key: string;
|
|
30
|
+
sourceId: string;
|
|
31
|
+
sourceLabel: string;
|
|
32
|
+
};
|
|
33
|
+
interface SearchInput {
|
|
34
|
+
q: string;
|
|
35
|
+
sources?: readonly string[] | string;
|
|
36
|
+
page?: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Pagination covers a bounded result window, never an exact global total. */
|
|
40
|
+
type SearchResponse = {
|
|
41
|
+
items: SearchResult[];
|
|
42
|
+
sources: SearchSource[];
|
|
43
|
+
page: number;
|
|
44
|
+
limit: number;
|
|
45
|
+
hasMore: boolean;
|
|
46
|
+
nextPage: number | null;
|
|
47
|
+
truncated: boolean;
|
|
48
|
+
};
|
|
49
|
+
interface SearchBackendConfig {
|
|
50
|
+
providers?: readonly SearchProvider[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { SearchBackendConfig, SearchInput, SearchProvider, SearchProviderResult, SearchResponse, SearchResult, SearchSource };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { OperationContext } from '@btst/stack/plugins/api';
|
|
2
|
+
|
|
3
|
+
/** Stable public source metadata; providers are registered only by application code. */
|
|
4
|
+
type SearchSource = {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
};
|
|
8
|
+
/** A provider's already-authorized public projection. Snippets are plain text. */
|
|
9
|
+
type SearchProviderResult = {
|
|
10
|
+
resourceId: string;
|
|
11
|
+
title: string;
|
|
12
|
+
snippet: string;
|
|
13
|
+
href: string;
|
|
14
|
+
};
|
|
15
|
+
/** Providers must apply visibility before returning records or continuation metadata. */
|
|
16
|
+
interface SearchProvider extends SearchSource {
|
|
17
|
+
search(context: {
|
|
18
|
+
q: string;
|
|
19
|
+
limit: number;
|
|
20
|
+
request: Request;
|
|
21
|
+
identity: OperationContext<unknown, unknown>["identity"];
|
|
22
|
+
}): Promise<{
|
|
23
|
+
items: readonly SearchProviderResult[];
|
|
24
|
+
hasMore: boolean;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
/** Result identity is scoped to its source, with no comparable relevance score. */
|
|
28
|
+
type SearchResult = SearchProviderResult & {
|
|
29
|
+
key: string;
|
|
30
|
+
sourceId: string;
|
|
31
|
+
sourceLabel: string;
|
|
32
|
+
};
|
|
33
|
+
interface SearchInput {
|
|
34
|
+
q: string;
|
|
35
|
+
sources?: readonly string[] | string;
|
|
36
|
+
page?: number;
|
|
37
|
+
limit?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Pagination covers a bounded result window, never an exact global total. */
|
|
40
|
+
type SearchResponse = {
|
|
41
|
+
items: SearchResult[];
|
|
42
|
+
sources: SearchSource[];
|
|
43
|
+
page: number;
|
|
44
|
+
limit: number;
|
|
45
|
+
hasMore: boolean;
|
|
46
|
+
nextPage: number | null;
|
|
47
|
+
truncated: boolean;
|
|
48
|
+
};
|
|
49
|
+
interface SearchBackendConfig {
|
|
50
|
+
providers?: readonly SearchProvider[];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type { SearchBackendConfig, SearchInput, SearchProvider, SearchProviderResult, SearchResponse, SearchResult, SearchSource };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
const reactSlot = require('@radix-ui/react-slot');
|
|
5
|
+
const classVarianceAuthority = require('class-variance-authority');
|
|
6
|
+
const utils = require('../lib/utils.cjs');
|
|
7
|
+
|
|
8
|
+
const buttonVariants = classVarianceAuthority.cva(
|
|
9
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
10
|
+
{
|
|
11
|
+
variants: {
|
|
12
|
+
variant: {
|
|
13
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
14
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
15
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
16
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
17
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
18
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
19
|
+
},
|
|
20
|
+
size: {
|
|
21
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
22
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
23
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
24
|
+
icon: "size-9",
|
|
25
|
+
"icon-sm": "size-8",
|
|
26
|
+
"icon-lg": "size-10"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
variant: "default",
|
|
31
|
+
size: "default"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
function Button({
|
|
36
|
+
className,
|
|
37
|
+
variant = "default",
|
|
38
|
+
size = "default",
|
|
39
|
+
asChild = false,
|
|
40
|
+
...props
|
|
41
|
+
}) {
|
|
42
|
+
const Comp = asChild ? reactSlot.Slot : "button";
|
|
43
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
44
|
+
Comp,
|
|
45
|
+
{
|
|
46
|
+
"data-slot": "button",
|
|
47
|
+
"data-variant": variant,
|
|
48
|
+
"data-size": size,
|
|
49
|
+
className: utils.cn(buttonVariants({ variant, size, className })),
|
|
50
|
+
...props
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
exports.Button = Button;
|
|
56
|
+
exports.buttonVariants = buttonVariants;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
3
|
+
import { cva } from 'class-variance-authority';
|
|
4
|
+
import { cn } from '../lib/utils.mjs';
|
|
5
|
+
|
|
6
|
+
const buttonVariants = cva(
|
|
7
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
8
|
+
{
|
|
9
|
+
variants: {
|
|
10
|
+
variant: {
|
|
11
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
12
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
13
|
+
outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
|
|
14
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
15
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
|
16
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
17
|
+
},
|
|
18
|
+
size: {
|
|
19
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
20
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
21
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
22
|
+
icon: "size-9",
|
|
23
|
+
"icon-sm": "size-8",
|
|
24
|
+
"icon-lg": "size-10"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
defaultVariants: {
|
|
28
|
+
variant: "default",
|
|
29
|
+
size: "default"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
function Button({
|
|
34
|
+
className,
|
|
35
|
+
variant = "default",
|
|
36
|
+
size = "default",
|
|
37
|
+
asChild = false,
|
|
38
|
+
...props
|
|
39
|
+
}) {
|
|
40
|
+
const Comp = asChild ? Slot : "button";
|
|
41
|
+
return /* @__PURE__ */ jsx(
|
|
42
|
+
Comp,
|
|
43
|
+
{
|
|
44
|
+
"data-slot": "button",
|
|
45
|
+
"data-variant": variant,
|
|
46
|
+
"data-size": size,
|
|
47
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
48
|
+
...props
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { Button, buttonVariants };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const jsxRuntime = require('react/jsx-runtime');
|
|
5
|
+
const cmdk = require('cmdk');
|
|
6
|
+
const lucideReact = require('lucide-react');
|
|
7
|
+
const utils = require('../lib/utils.cjs');
|
|
8
|
+
require('@radix-ui/react-dialog');
|
|
9
|
+
|
|
10
|
+
function Command({
|
|
11
|
+
className,
|
|
12
|
+
...props
|
|
13
|
+
}) {
|
|
14
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
15
|
+
cmdk.Command,
|
|
16
|
+
{
|
|
17
|
+
"data-slot": "command",
|
|
18
|
+
className: utils.cn(
|
|
19
|
+
"bg-popover text-popover-foreground flex h-full w-full flex-col overflow-hidden rounded-md",
|
|
20
|
+
className
|
|
21
|
+
),
|
|
22
|
+
...props
|
|
23
|
+
}
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
function CommandInput({
|
|
27
|
+
className,
|
|
28
|
+
...props
|
|
29
|
+
}) {
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
31
|
+
"div",
|
|
32
|
+
{
|
|
33
|
+
"data-slot": "command-input-wrapper",
|
|
34
|
+
className: "pointer-events-auto flex h-9 items-center gap-2 border-b px-3",
|
|
35
|
+
children: [
|
|
36
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchIcon, { className: "size-4 shrink-0 opacity-50" }),
|
|
37
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
38
|
+
cmdk.Command.Input,
|
|
39
|
+
{
|
|
40
|
+
"data-slot": "command-input",
|
|
41
|
+
className: utils.cn(
|
|
42
|
+
"pointer-events-auto placeholder:text-muted-foreground flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50",
|
|
43
|
+
className
|
|
44
|
+
),
|
|
45
|
+
...props
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
function CommandList({
|
|
53
|
+
className,
|
|
54
|
+
...props
|
|
55
|
+
}) {
|
|
56
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
57
|
+
cmdk.Command.List,
|
|
58
|
+
{
|
|
59
|
+
"data-slot": "command-list",
|
|
60
|
+
className: utils.cn(
|
|
61
|
+
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
|
62
|
+
className
|
|
63
|
+
),
|
|
64
|
+
...props
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function CommandItem({
|
|
69
|
+
className,
|
|
70
|
+
...props
|
|
71
|
+
}) {
|
|
72
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
73
|
+
cmdk.Command.Item,
|
|
74
|
+
{
|
|
75
|
+
"data-slot": "command-item",
|
|
76
|
+
className: utils.cn(
|
|
77
|
+
"data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground pointer-events-auto relative flex cursor-pointer items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled='true']:pointer-events-none data-[disabled='true']:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
78
|
+
className
|
|
79
|
+
),
|
|
80
|
+
...props
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.Command = Command;
|
|
86
|
+
exports.CommandInput = CommandInput;
|
|
87
|
+
exports.CommandItem = CommandItem;
|
|
88
|
+
exports.CommandList = CommandList;
|