@headband/react 0.1.0 → 0.2.0
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 +21 -0
- package/README.md +249 -159
- package/dist/index.d.mts +168 -5
- package/dist/index.d.ts +168 -5
- package/dist/index.js +279 -96
- package/dist/index.mjs +267 -102
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,13 +1,112 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, ComponentType } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Runtime helpers for Headband-managed retrieval experiments.
|
|
6
|
+
*
|
|
7
|
+
* Headband stores experiment rules, but applications own runtime assignment.
|
|
8
|
+
* These helpers fetch the saved rules and deterministically assign a subject
|
|
9
|
+
* to a variant without adding another dependency.
|
|
10
|
+
*/
|
|
11
|
+
type ExperimentConfigStatus = "draft" | "active" | "paused" | "archived";
|
|
12
|
+
interface ExperimentVariantConfig {
|
|
13
|
+
key: string;
|
|
14
|
+
indexUid: string;
|
|
15
|
+
weight: number;
|
|
16
|
+
}
|
|
17
|
+
interface ExperimentConfig {
|
|
18
|
+
id?: string;
|
|
19
|
+
experimentKey: string;
|
|
20
|
+
name: string;
|
|
21
|
+
status: ExperimentConfigStatus;
|
|
22
|
+
trafficPercent: number;
|
|
23
|
+
killSwitch: boolean;
|
|
24
|
+
primaryMetric: string;
|
|
25
|
+
guardrailMetric: string | null;
|
|
26
|
+
assignmentSalt: string;
|
|
27
|
+
variants: ExperimentVariantConfig[];
|
|
28
|
+
updatedAt?: string;
|
|
29
|
+
}
|
|
30
|
+
interface ExperimentSearchMetadata {
|
|
31
|
+
experimentKey: string;
|
|
32
|
+
variant: string;
|
|
33
|
+
sessionId?: string;
|
|
34
|
+
}
|
|
35
|
+
type ExperimentEventType = "experiment_view" | "search_result_click" | "conversion" | "custom";
|
|
36
|
+
interface ExperimentEventInput extends ExperimentSearchMetadata {
|
|
37
|
+
eventType: ExperimentEventType;
|
|
38
|
+
indexUid: string;
|
|
39
|
+
query?: string;
|
|
40
|
+
filters?: string;
|
|
41
|
+
conversionValue?: number;
|
|
42
|
+
metadata?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
interface ExperimentEventResponse {
|
|
45
|
+
accepted: boolean;
|
|
46
|
+
eventType: ExperimentEventType;
|
|
47
|
+
experimentKey: string;
|
|
48
|
+
variant: string;
|
|
49
|
+
indexUid: string;
|
|
50
|
+
}
|
|
51
|
+
interface ExperimentAssignment extends ExperimentSearchMetadata {
|
|
52
|
+
indexUid: string;
|
|
53
|
+
config: ExperimentConfig;
|
|
54
|
+
}
|
|
55
|
+
interface HostedExperimentAssignmentQuery {
|
|
56
|
+
projectId?: string;
|
|
57
|
+
indexUid?: string;
|
|
58
|
+
experimentKey: string;
|
|
59
|
+
subjectId: string;
|
|
60
|
+
sessionId?: string;
|
|
61
|
+
}
|
|
62
|
+
interface HostedExperimentAssignmentResponse {
|
|
63
|
+
assigned: boolean;
|
|
64
|
+
reason?: "not_runnable" | "outside_rollout" | "no_weight";
|
|
65
|
+
experimentKey: string;
|
|
66
|
+
variant?: string;
|
|
67
|
+
indexUid?: string;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
config: {
|
|
70
|
+
status: ExperimentConfigStatus;
|
|
71
|
+
trafficPercent: number;
|
|
72
|
+
killSwitch: boolean;
|
|
73
|
+
updatedAt?: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface ExperimentConfigQuery {
|
|
77
|
+
projectId?: string;
|
|
78
|
+
indexUid?: string;
|
|
79
|
+
experimentKey?: string;
|
|
80
|
+
}
|
|
81
|
+
interface ExperimentConfigResponse {
|
|
82
|
+
data?: {
|
|
83
|
+
experiments?: ExperimentConfig[];
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
declare function buildExperimentConfigPath(query?: ExperimentConfigQuery): string;
|
|
87
|
+
declare function isRunnableExperiment(config: ExperimentConfig): boolean;
|
|
88
|
+
declare function chooseExperimentVariant(config: ExperimentConfig, subjectId: string): ExperimentVariantConfig | null;
|
|
89
|
+
declare function assignExperiment(config: ExperimentConfig, subjectId: string, options?: {
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
}): ExperimentAssignment | null;
|
|
92
|
+
declare function experimentSearchMetadata(assignment: ExperimentAssignment | null | undefined): ExperimentSearchMetadata | undefined;
|
|
93
|
+
|
|
4
94
|
/**
|
|
5
95
|
* Headband search client.
|
|
6
96
|
*
|
|
7
|
-
* Makes requests to the Headband `/v1/search
|
|
97
|
+
* Makes requests to the Headband `/v1/search`, `/v1/multi-search` and `/v1/warm` endpoints.
|
|
8
98
|
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Visor's ranking mode: `instant` (the default, typo-tolerant, as-you-type) or `retrieval` (BM25F,
|
|
102
|
+
* for longer queries), on the same index. Indexes on the other engines ignore it.
|
|
103
|
+
*/
|
|
104
|
+
type SearchMode = "instant" | "retrieval";
|
|
9
105
|
interface SearchParams {
|
|
10
|
-
|
|
106
|
+
experimentKey?: string;
|
|
107
|
+
variant?: string;
|
|
108
|
+
sessionId?: string;
|
|
109
|
+
filter?: string | string[];
|
|
11
110
|
facets?: string[];
|
|
12
111
|
sort?: string[];
|
|
13
112
|
limit?: number;
|
|
@@ -15,9 +114,13 @@ interface SearchParams {
|
|
|
15
114
|
attributesToHighlight?: string[];
|
|
16
115
|
attributesToRetrieve?: string[];
|
|
17
116
|
attributesToCrop?: string[];
|
|
117
|
+
/** Visor crops to 20 words and refuses any other value with 400 feature_not_supported. */
|
|
18
118
|
cropLength?: number;
|
|
119
|
+
/** Visor returns no match positions and refuses `true` with 400 feature_not_supported. */
|
|
19
120
|
showMatchesPosition?: boolean;
|
|
121
|
+
/** Visor matches as `last` does and refuses `all` and `frequency` with 400 feature_not_supported. */
|
|
20
122
|
matchingStrategy?: "all" | "last" | "frequency";
|
|
123
|
+
mode?: SearchMode;
|
|
21
124
|
}
|
|
22
125
|
interface SearchResponse {
|
|
23
126
|
hits: Record<string, unknown>[];
|
|
@@ -34,22 +137,51 @@ interface SearchResponse {
|
|
|
34
137
|
interface MultiSearchQuery {
|
|
35
138
|
indexUid: string;
|
|
36
139
|
q: string;
|
|
37
|
-
filter?: string;
|
|
140
|
+
filter?: string | string[];
|
|
38
141
|
facets?: string[];
|
|
39
142
|
sort?: string[];
|
|
40
143
|
limit?: number;
|
|
41
144
|
offset?: number;
|
|
42
145
|
attributesToHighlight?: string[];
|
|
43
146
|
attributesToRetrieve?: string[];
|
|
147
|
+
mode?: SearchMode;
|
|
44
148
|
}
|
|
45
149
|
interface MultiSearchResponse {
|
|
46
150
|
results: Array<SearchResponse & {
|
|
47
151
|
indexUid: string;
|
|
48
152
|
}>;
|
|
49
153
|
}
|
|
154
|
+
interface ExperimentConfigsResponse {
|
|
155
|
+
experiments: ExperimentConfig[];
|
|
156
|
+
}
|
|
157
|
+
/** `auto` starts an engine used in the last 24 hours and stages an older one. */
|
|
158
|
+
type WarmLevel = "auto" | "stage" | "start";
|
|
159
|
+
/** Indexes by name, or every index of a project. */
|
|
160
|
+
type WarmInput = {
|
|
161
|
+
indexes: string[];
|
|
162
|
+
} | {
|
|
163
|
+
project: string;
|
|
164
|
+
branch?: string;
|
|
165
|
+
};
|
|
166
|
+
interface WarmResponse {
|
|
167
|
+
level: WarmLevel;
|
|
168
|
+
indexes: Array<{
|
|
169
|
+
index: string;
|
|
170
|
+
engine: string;
|
|
171
|
+
state: "awake" | "staging" | "staged" | "starting" | "refused";
|
|
172
|
+
reason?: string;
|
|
173
|
+
}>;
|
|
174
|
+
}
|
|
50
175
|
interface HeadbandClient {
|
|
51
176
|
search(index: string, query: string, params?: SearchParams): Promise<SearchResponse>;
|
|
52
177
|
multiSearch(queries: MultiSearchQuery[]): Promise<MultiSearchResponse>;
|
|
178
|
+
getExperimentConfigs(query?: ExperimentConfigQuery): Promise<ExperimentConfigsResponse>;
|
|
179
|
+
assignExperiment(query: HostedExperimentAssignmentQuery): Promise<HostedExperimentAssignmentResponse>;
|
|
180
|
+
recordExperimentEvent(event: ExperimentEventInput): Promise<ExperimentEventResponse>;
|
|
181
|
+
/** Pre-wakes indexes, or a project's, so the next search does not wait for a sleeping engine. Free. */
|
|
182
|
+
warm(target: WarmInput, opts?: {
|
|
183
|
+
level?: WarmLevel;
|
|
184
|
+
}): Promise<WarmResponse>;
|
|
53
185
|
}
|
|
54
186
|
declare class HeadbandError extends Error {
|
|
55
187
|
readonly status: number;
|
|
@@ -58,6 +190,25 @@ declare class HeadbandError extends Error {
|
|
|
58
190
|
}
|
|
59
191
|
declare function headband(host: string, apiKey: string): HeadbandClient;
|
|
60
192
|
|
|
193
|
+
type FilterValue = string | number | boolean;
|
|
194
|
+
type FilterInput = string | string[] | null | undefined;
|
|
195
|
+
declare function quoteFilterValue(value: FilterValue): string;
|
|
196
|
+
declare function filterEq(attribute: string, value: FilterValue): string;
|
|
197
|
+
declare function filterNotEq(attribute: string, value: FilterValue): string;
|
|
198
|
+
declare function filterIn(attribute: string, values: FilterValue[]): string;
|
|
199
|
+
declare function filterExists(attribute: string): string;
|
|
200
|
+
declare function filterRange(attribute: string, range: {
|
|
201
|
+
gt?: number;
|
|
202
|
+
gte?: number;
|
|
203
|
+
lt?: number;
|
|
204
|
+
lte?: number;
|
|
205
|
+
min?: number;
|
|
206
|
+
max?: number;
|
|
207
|
+
}): string | undefined;
|
|
208
|
+
declare function andFilters(...filters: FilterInput[]): string | undefined;
|
|
209
|
+
declare function orFilters(...filters: FilterInput[]): string | undefined;
|
|
210
|
+
declare function combineFilters(baseFilter: FilterInput, generatedFilter: FilterInput): string | string[] | undefined;
|
|
211
|
+
|
|
61
212
|
/** Map of attribute -> selected values for facet refinements. */
|
|
62
213
|
type RefinementMap = Map<string, Set<string>>;
|
|
63
214
|
/** Numeric range filter: attribute -> { min?, max? }. */
|
|
@@ -103,9 +254,21 @@ interface HeadbandProviderProps {
|
|
|
103
254
|
client: HeadbandClient;
|
|
104
255
|
index: string;
|
|
105
256
|
initialQuery?: string;
|
|
257
|
+
experiment?: ExperimentSearchMetadata | null;
|
|
258
|
+
/**
|
|
259
|
+
* Optional app-owned filter expression(s) ANDed with UI refinements/ranges.
|
|
260
|
+
* Use this for tenant, permission, availability, or custom OR/AND groups that
|
|
261
|
+
* should apply to every search request.
|
|
262
|
+
*/
|
|
263
|
+
baseFilter?: FilterInput;
|
|
264
|
+
/**
|
|
265
|
+
* Visor's ranking mode for every search: `instant` (the engine's default) or `retrieval` (BM25F,
|
|
266
|
+
* for longer queries). Indexes on the other engines ignore it.
|
|
267
|
+
*/
|
|
268
|
+
mode?: SearchMode;
|
|
106
269
|
children: ReactNode;
|
|
107
270
|
}
|
|
108
|
-
declare function HeadbandProvider({ client, index, initialQuery, children, }: HeadbandProviderProps): react_jsx_runtime.JSX.Element;
|
|
271
|
+
declare function HeadbandProvider({ client, index, initialQuery, experiment, baseFilter, mode, children, }: HeadbandProviderProps): react_jsx_runtime.JSX.Element;
|
|
109
272
|
|
|
110
273
|
/**
|
|
111
274
|
* Core hook that exposes the full search state and actions.
|
|
@@ -413,4 +576,4 @@ interface PoweredByProps {
|
|
|
413
576
|
*/
|
|
414
577
|
declare function PoweredBy({ className, styled, href, }: PoweredByProps): react_jsx_runtime.JSX.Element;
|
|
415
578
|
|
|
416
|
-
export { type HeadbandClient, type HeadbandContextValue, HeadbandError, HeadbandProvider, type HeadbandProviderProps, Highlight, type HighlightProps, type Hit, Hits, type HitsProps, type MultiSearchQuery, type MultiSearchResponse, Pagination, type PaginationProps, PoweredBy, type PoweredByProps, RangeInput, type RangeInputProps, type RangeMap, RefinementList, type RefinementListItem, type RefinementListProps, type RefinementMap, type SearchActions, SearchBox, type SearchBoxProps, type SearchParams, type SearchResponse, type SearchState, SortBy, type SortByItem, type SortByProps, Stats, type StatsProps, type UseHighlightProps, type UseHighlightReturn, type UseHitsReturn, type UsePaginationReturn, type UseRangeProps, type UseRangeReturn, type UseRefinementListProps, type UseRefinementListReturn, type UseSearchBoxReturn, type UseSortByProps, type UseSortByReturn, type UseStatsReturn, headband, useHeadbandContext, useHighlight, useHits, usePagination, useRange, useRefinementList, useSearch, useSearchBox, useSortBy, useStats };
|
|
579
|
+
export { type ExperimentAssignment, type ExperimentConfig, type ExperimentConfigQuery, type ExperimentConfigResponse, type ExperimentConfigStatus, type ExperimentConfigsResponse, type ExperimentEventInput, type ExperimentEventResponse, type ExperimentEventType, type ExperimentSearchMetadata, type ExperimentVariantConfig, type FilterInput, type FilterValue, type HeadbandClient, type HeadbandContextValue, HeadbandError, HeadbandProvider, type HeadbandProviderProps, Highlight, type HighlightProps, type Hit, Hits, type HitsProps, type HostedExperimentAssignmentQuery, type HostedExperimentAssignmentResponse, type MultiSearchQuery, type MultiSearchResponse, Pagination, type PaginationProps, PoweredBy, type PoweredByProps, RangeInput, type RangeInputProps, type RangeMap, RefinementList, type RefinementListItem, type RefinementListProps, type RefinementMap, type SearchActions, SearchBox, type SearchBoxProps, type SearchMode, type SearchParams, type SearchResponse, type SearchState, SortBy, type SortByItem, type SortByProps, Stats, type StatsProps, type UseHighlightProps, type UseHighlightReturn, type UseHitsReturn, type UsePaginationReturn, type UseRangeProps, type UseRangeReturn, type UseRefinementListProps, type UseRefinementListReturn, type UseSearchBoxReturn, type UseSortByProps, type UseSortByReturn, type UseStatsReturn, type WarmInput, type WarmLevel, type WarmResponse, andFilters, assignExperiment, buildExperimentConfigPath, chooseExperimentVariant, combineFilters, experimentSearchMetadata, filterEq, filterExists, filterIn, filterNotEq, filterRange, headband, isRunnableExperiment, orFilters, quoteFilterValue, useHeadbandContext, useHighlight, useHits, usePagination, useRange, useRefinementList, useSearch, useSearchBox, useSortBy, useStats };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,112 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, ComponentType } from 'react';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Runtime helpers for Headband-managed retrieval experiments.
|
|
6
|
+
*
|
|
7
|
+
* Headband stores experiment rules, but applications own runtime assignment.
|
|
8
|
+
* These helpers fetch the saved rules and deterministically assign a subject
|
|
9
|
+
* to a variant without adding another dependency.
|
|
10
|
+
*/
|
|
11
|
+
type ExperimentConfigStatus = "draft" | "active" | "paused" | "archived";
|
|
12
|
+
interface ExperimentVariantConfig {
|
|
13
|
+
key: string;
|
|
14
|
+
indexUid: string;
|
|
15
|
+
weight: number;
|
|
16
|
+
}
|
|
17
|
+
interface ExperimentConfig {
|
|
18
|
+
id?: string;
|
|
19
|
+
experimentKey: string;
|
|
20
|
+
name: string;
|
|
21
|
+
status: ExperimentConfigStatus;
|
|
22
|
+
trafficPercent: number;
|
|
23
|
+
killSwitch: boolean;
|
|
24
|
+
primaryMetric: string;
|
|
25
|
+
guardrailMetric: string | null;
|
|
26
|
+
assignmentSalt: string;
|
|
27
|
+
variants: ExperimentVariantConfig[];
|
|
28
|
+
updatedAt?: string;
|
|
29
|
+
}
|
|
30
|
+
interface ExperimentSearchMetadata {
|
|
31
|
+
experimentKey: string;
|
|
32
|
+
variant: string;
|
|
33
|
+
sessionId?: string;
|
|
34
|
+
}
|
|
35
|
+
type ExperimentEventType = "experiment_view" | "search_result_click" | "conversion" | "custom";
|
|
36
|
+
interface ExperimentEventInput extends ExperimentSearchMetadata {
|
|
37
|
+
eventType: ExperimentEventType;
|
|
38
|
+
indexUid: string;
|
|
39
|
+
query?: string;
|
|
40
|
+
filters?: string;
|
|
41
|
+
conversionValue?: number;
|
|
42
|
+
metadata?: Record<string, unknown>;
|
|
43
|
+
}
|
|
44
|
+
interface ExperimentEventResponse {
|
|
45
|
+
accepted: boolean;
|
|
46
|
+
eventType: ExperimentEventType;
|
|
47
|
+
experimentKey: string;
|
|
48
|
+
variant: string;
|
|
49
|
+
indexUid: string;
|
|
50
|
+
}
|
|
51
|
+
interface ExperimentAssignment extends ExperimentSearchMetadata {
|
|
52
|
+
indexUid: string;
|
|
53
|
+
config: ExperimentConfig;
|
|
54
|
+
}
|
|
55
|
+
interface HostedExperimentAssignmentQuery {
|
|
56
|
+
projectId?: string;
|
|
57
|
+
indexUid?: string;
|
|
58
|
+
experimentKey: string;
|
|
59
|
+
subjectId: string;
|
|
60
|
+
sessionId?: string;
|
|
61
|
+
}
|
|
62
|
+
interface HostedExperimentAssignmentResponse {
|
|
63
|
+
assigned: boolean;
|
|
64
|
+
reason?: "not_runnable" | "outside_rollout" | "no_weight";
|
|
65
|
+
experimentKey: string;
|
|
66
|
+
variant?: string;
|
|
67
|
+
indexUid?: string;
|
|
68
|
+
sessionId: string;
|
|
69
|
+
config: {
|
|
70
|
+
status: ExperimentConfigStatus;
|
|
71
|
+
trafficPercent: number;
|
|
72
|
+
killSwitch: boolean;
|
|
73
|
+
updatedAt?: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface ExperimentConfigQuery {
|
|
77
|
+
projectId?: string;
|
|
78
|
+
indexUid?: string;
|
|
79
|
+
experimentKey?: string;
|
|
80
|
+
}
|
|
81
|
+
interface ExperimentConfigResponse {
|
|
82
|
+
data?: {
|
|
83
|
+
experiments?: ExperimentConfig[];
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
declare function buildExperimentConfigPath(query?: ExperimentConfigQuery): string;
|
|
87
|
+
declare function isRunnableExperiment(config: ExperimentConfig): boolean;
|
|
88
|
+
declare function chooseExperimentVariant(config: ExperimentConfig, subjectId: string): ExperimentVariantConfig | null;
|
|
89
|
+
declare function assignExperiment(config: ExperimentConfig, subjectId: string, options?: {
|
|
90
|
+
sessionId?: string;
|
|
91
|
+
}): ExperimentAssignment | null;
|
|
92
|
+
declare function experimentSearchMetadata(assignment: ExperimentAssignment | null | undefined): ExperimentSearchMetadata | undefined;
|
|
93
|
+
|
|
4
94
|
/**
|
|
5
95
|
* Headband search client.
|
|
6
96
|
*
|
|
7
|
-
* Makes requests to the Headband `/v1/search
|
|
97
|
+
* Makes requests to the Headband `/v1/search`, `/v1/multi-search` and `/v1/warm` endpoints.
|
|
8
98
|
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Visor's ranking mode: `instant` (the default, typo-tolerant, as-you-type) or `retrieval` (BM25F,
|
|
102
|
+
* for longer queries), on the same index. Indexes on the other engines ignore it.
|
|
103
|
+
*/
|
|
104
|
+
type SearchMode = "instant" | "retrieval";
|
|
9
105
|
interface SearchParams {
|
|
10
|
-
|
|
106
|
+
experimentKey?: string;
|
|
107
|
+
variant?: string;
|
|
108
|
+
sessionId?: string;
|
|
109
|
+
filter?: string | string[];
|
|
11
110
|
facets?: string[];
|
|
12
111
|
sort?: string[];
|
|
13
112
|
limit?: number;
|
|
@@ -15,9 +114,13 @@ interface SearchParams {
|
|
|
15
114
|
attributesToHighlight?: string[];
|
|
16
115
|
attributesToRetrieve?: string[];
|
|
17
116
|
attributesToCrop?: string[];
|
|
117
|
+
/** Visor crops to 20 words and refuses any other value with 400 feature_not_supported. */
|
|
18
118
|
cropLength?: number;
|
|
119
|
+
/** Visor returns no match positions and refuses `true` with 400 feature_not_supported. */
|
|
19
120
|
showMatchesPosition?: boolean;
|
|
121
|
+
/** Visor matches as `last` does and refuses `all` and `frequency` with 400 feature_not_supported. */
|
|
20
122
|
matchingStrategy?: "all" | "last" | "frequency";
|
|
123
|
+
mode?: SearchMode;
|
|
21
124
|
}
|
|
22
125
|
interface SearchResponse {
|
|
23
126
|
hits: Record<string, unknown>[];
|
|
@@ -34,22 +137,51 @@ interface SearchResponse {
|
|
|
34
137
|
interface MultiSearchQuery {
|
|
35
138
|
indexUid: string;
|
|
36
139
|
q: string;
|
|
37
|
-
filter?: string;
|
|
140
|
+
filter?: string | string[];
|
|
38
141
|
facets?: string[];
|
|
39
142
|
sort?: string[];
|
|
40
143
|
limit?: number;
|
|
41
144
|
offset?: number;
|
|
42
145
|
attributesToHighlight?: string[];
|
|
43
146
|
attributesToRetrieve?: string[];
|
|
147
|
+
mode?: SearchMode;
|
|
44
148
|
}
|
|
45
149
|
interface MultiSearchResponse {
|
|
46
150
|
results: Array<SearchResponse & {
|
|
47
151
|
indexUid: string;
|
|
48
152
|
}>;
|
|
49
153
|
}
|
|
154
|
+
interface ExperimentConfigsResponse {
|
|
155
|
+
experiments: ExperimentConfig[];
|
|
156
|
+
}
|
|
157
|
+
/** `auto` starts an engine used in the last 24 hours and stages an older one. */
|
|
158
|
+
type WarmLevel = "auto" | "stage" | "start";
|
|
159
|
+
/** Indexes by name, or every index of a project. */
|
|
160
|
+
type WarmInput = {
|
|
161
|
+
indexes: string[];
|
|
162
|
+
} | {
|
|
163
|
+
project: string;
|
|
164
|
+
branch?: string;
|
|
165
|
+
};
|
|
166
|
+
interface WarmResponse {
|
|
167
|
+
level: WarmLevel;
|
|
168
|
+
indexes: Array<{
|
|
169
|
+
index: string;
|
|
170
|
+
engine: string;
|
|
171
|
+
state: "awake" | "staging" | "staged" | "starting" | "refused";
|
|
172
|
+
reason?: string;
|
|
173
|
+
}>;
|
|
174
|
+
}
|
|
50
175
|
interface HeadbandClient {
|
|
51
176
|
search(index: string, query: string, params?: SearchParams): Promise<SearchResponse>;
|
|
52
177
|
multiSearch(queries: MultiSearchQuery[]): Promise<MultiSearchResponse>;
|
|
178
|
+
getExperimentConfigs(query?: ExperimentConfigQuery): Promise<ExperimentConfigsResponse>;
|
|
179
|
+
assignExperiment(query: HostedExperimentAssignmentQuery): Promise<HostedExperimentAssignmentResponse>;
|
|
180
|
+
recordExperimentEvent(event: ExperimentEventInput): Promise<ExperimentEventResponse>;
|
|
181
|
+
/** Pre-wakes indexes, or a project's, so the next search does not wait for a sleeping engine. Free. */
|
|
182
|
+
warm(target: WarmInput, opts?: {
|
|
183
|
+
level?: WarmLevel;
|
|
184
|
+
}): Promise<WarmResponse>;
|
|
53
185
|
}
|
|
54
186
|
declare class HeadbandError extends Error {
|
|
55
187
|
readonly status: number;
|
|
@@ -58,6 +190,25 @@ declare class HeadbandError extends Error {
|
|
|
58
190
|
}
|
|
59
191
|
declare function headband(host: string, apiKey: string): HeadbandClient;
|
|
60
192
|
|
|
193
|
+
type FilterValue = string | number | boolean;
|
|
194
|
+
type FilterInput = string | string[] | null | undefined;
|
|
195
|
+
declare function quoteFilterValue(value: FilterValue): string;
|
|
196
|
+
declare function filterEq(attribute: string, value: FilterValue): string;
|
|
197
|
+
declare function filterNotEq(attribute: string, value: FilterValue): string;
|
|
198
|
+
declare function filterIn(attribute: string, values: FilterValue[]): string;
|
|
199
|
+
declare function filterExists(attribute: string): string;
|
|
200
|
+
declare function filterRange(attribute: string, range: {
|
|
201
|
+
gt?: number;
|
|
202
|
+
gte?: number;
|
|
203
|
+
lt?: number;
|
|
204
|
+
lte?: number;
|
|
205
|
+
min?: number;
|
|
206
|
+
max?: number;
|
|
207
|
+
}): string | undefined;
|
|
208
|
+
declare function andFilters(...filters: FilterInput[]): string | undefined;
|
|
209
|
+
declare function orFilters(...filters: FilterInput[]): string | undefined;
|
|
210
|
+
declare function combineFilters(baseFilter: FilterInput, generatedFilter: FilterInput): string | string[] | undefined;
|
|
211
|
+
|
|
61
212
|
/** Map of attribute -> selected values for facet refinements. */
|
|
62
213
|
type RefinementMap = Map<string, Set<string>>;
|
|
63
214
|
/** Numeric range filter: attribute -> { min?, max? }. */
|
|
@@ -103,9 +254,21 @@ interface HeadbandProviderProps {
|
|
|
103
254
|
client: HeadbandClient;
|
|
104
255
|
index: string;
|
|
105
256
|
initialQuery?: string;
|
|
257
|
+
experiment?: ExperimentSearchMetadata | null;
|
|
258
|
+
/**
|
|
259
|
+
* Optional app-owned filter expression(s) ANDed with UI refinements/ranges.
|
|
260
|
+
* Use this for tenant, permission, availability, or custom OR/AND groups that
|
|
261
|
+
* should apply to every search request.
|
|
262
|
+
*/
|
|
263
|
+
baseFilter?: FilterInput;
|
|
264
|
+
/**
|
|
265
|
+
* Visor's ranking mode for every search: `instant` (the engine's default) or `retrieval` (BM25F,
|
|
266
|
+
* for longer queries). Indexes on the other engines ignore it.
|
|
267
|
+
*/
|
|
268
|
+
mode?: SearchMode;
|
|
106
269
|
children: ReactNode;
|
|
107
270
|
}
|
|
108
|
-
declare function HeadbandProvider({ client, index, initialQuery, children, }: HeadbandProviderProps): react_jsx_runtime.JSX.Element;
|
|
271
|
+
declare function HeadbandProvider({ client, index, initialQuery, experiment, baseFilter, mode, children, }: HeadbandProviderProps): react_jsx_runtime.JSX.Element;
|
|
109
272
|
|
|
110
273
|
/**
|
|
111
274
|
* Core hook that exposes the full search state and actions.
|
|
@@ -413,4 +576,4 @@ interface PoweredByProps {
|
|
|
413
576
|
*/
|
|
414
577
|
declare function PoweredBy({ className, styled, href, }: PoweredByProps): react_jsx_runtime.JSX.Element;
|
|
415
578
|
|
|
416
|
-
export { type HeadbandClient, type HeadbandContextValue, HeadbandError, HeadbandProvider, type HeadbandProviderProps, Highlight, type HighlightProps, type Hit, Hits, type HitsProps, type MultiSearchQuery, type MultiSearchResponse, Pagination, type PaginationProps, PoweredBy, type PoweredByProps, RangeInput, type RangeInputProps, type RangeMap, RefinementList, type RefinementListItem, type RefinementListProps, type RefinementMap, type SearchActions, SearchBox, type SearchBoxProps, type SearchParams, type SearchResponse, type SearchState, SortBy, type SortByItem, type SortByProps, Stats, type StatsProps, type UseHighlightProps, type UseHighlightReturn, type UseHitsReturn, type UsePaginationReturn, type UseRangeProps, type UseRangeReturn, type UseRefinementListProps, type UseRefinementListReturn, type UseSearchBoxReturn, type UseSortByProps, type UseSortByReturn, type UseStatsReturn, headband, useHeadbandContext, useHighlight, useHits, usePagination, useRange, useRefinementList, useSearch, useSearchBox, useSortBy, useStats };
|
|
579
|
+
export { type ExperimentAssignment, type ExperimentConfig, type ExperimentConfigQuery, type ExperimentConfigResponse, type ExperimentConfigStatus, type ExperimentConfigsResponse, type ExperimentEventInput, type ExperimentEventResponse, type ExperimentEventType, type ExperimentSearchMetadata, type ExperimentVariantConfig, type FilterInput, type FilterValue, type HeadbandClient, type HeadbandContextValue, HeadbandError, HeadbandProvider, type HeadbandProviderProps, Highlight, type HighlightProps, type Hit, Hits, type HitsProps, type HostedExperimentAssignmentQuery, type HostedExperimentAssignmentResponse, type MultiSearchQuery, type MultiSearchResponse, Pagination, type PaginationProps, PoweredBy, type PoweredByProps, RangeInput, type RangeInputProps, type RangeMap, RefinementList, type RefinementListItem, type RefinementListProps, type RefinementMap, type SearchActions, SearchBox, type SearchBoxProps, type SearchMode, type SearchParams, type SearchResponse, type SearchState, SortBy, type SortByItem, type SortByProps, Stats, type StatsProps, type UseHighlightProps, type UseHighlightReturn, type UseHitsReturn, type UsePaginationReturn, type UseRangeProps, type UseRangeReturn, type UseRefinementListProps, type UseRefinementListReturn, type UseSearchBoxReturn, type UseSortByProps, type UseSortByReturn, type UseStatsReturn, type WarmInput, type WarmLevel, type WarmResponse, andFilters, assignExperiment, buildExperimentConfigPath, chooseExperimentVariant, combineFilters, experimentSearchMetadata, filterEq, filterExists, filterIn, filterNotEq, filterRange, headband, isRunnableExperiment, orFilters, quoteFilterValue, useHeadbandContext, useHighlight, useHits, usePagination, useRange, useRefinementList, useSearch, useSearchBox, useSortBy, useStats };
|