instantsearch-ui-components 0.17.0 → 0.17.1

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.
@@ -18,6 +18,9 @@ function createAutocompleteIndexComponent(_ref) {
18
18
  getItemProps = userProps.getItemProps,
19
19
  _userProps$classNames = userProps.classNames,
20
20
  classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
21
+ if (items.length === 0) {
22
+ return null;
23
+ }
21
24
  return createElement("div", {
22
25
  className: (0, _cx.cx)('ais-AutocompleteIndex', classNames.root)
23
26
  }, HeaderComponent && createElement("div", {
@@ -113,6 +113,17 @@ Object.keys(_ChatPrompt).forEach(function (key) {
113
113
  }
114
114
  });
115
115
  });
116
+ var _ChatPromptSuggestions = require("./chat/ChatPromptSuggestions");
117
+ Object.keys(_ChatPromptSuggestions).forEach(function (key) {
118
+ if (key === "default" || key === "__esModule") return;
119
+ if (key in exports && exports[key] === _ChatPromptSuggestions[key]) return;
120
+ Object.defineProperty(exports, key, {
121
+ enumerable: true,
122
+ get: function get() {
123
+ return _ChatPromptSuggestions[key];
124
+ }
125
+ });
126
+ });
116
127
  var _ChatToggleButton = require("./chat/ChatToggleButton");
117
128
  Object.keys(_ChatToggleButton).forEach(function (key) {
118
129
  if (key === "default" || key === "__esModule") return;
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '0.17.0';
7
+ var _default = exports.default = '0.17.1';
@@ -37,4 +37,4 @@ export type AutocompleteIndexClassNames = {
37
37
  */
38
38
  item: string | string[];
39
39
  };
40
- export declare function createAutocompleteIndexComponent({ createElement }: Renderer): (userProps: AutocompleteIndexProps) => JSX.Element;
40
+ export declare function createAutocompleteIndexComponent({ createElement }: Renderer): (userProps: AutocompleteIndexProps) => JSX.Element | null;
@@ -11,6 +11,9 @@ export function createAutocompleteIndexComponent(_ref) {
11
11
  getItemProps = userProps.getItemProps,
12
12
  _userProps$classNames = userProps.classNames,
13
13
  classNames = _userProps$classNames === void 0 ? {} : _userProps$classNames;
14
+ if (items.length === 0) {
15
+ return null;
16
+ }
14
17
  return createElement("div", {
15
18
  className: cx('ais-AutocompleteIndex', classNames.root)
16
19
  }, HeaderComponent && createElement("div", {
@@ -1,12 +1,352 @@
1
- import type { AbstractChat, ChatInit, UIMessage } from 'ai';
2
1
  export type ChatStatus = 'ready' | 'submitted' | 'streaming' | 'error';
3
2
  export type ChatRole = 'data' | 'user' | 'assistant' | 'system';
3
+ /**
4
+ * Provider metadata type for UI message parts.
5
+ */
6
+ export type ProviderMetadata = Record<string, Record<string, unknown>>;
7
+ /**
8
+ * A record of data types for data parts in UI messages.
9
+ */
10
+ export type UIDataTypes = Record<string, unknown>;
11
+ /**
12
+ * Tool input/output type definition.
13
+ */
14
+ export type UITool = {
15
+ input: unknown;
16
+ output: unknown | undefined;
17
+ };
18
+ /**
19
+ * A record of UI tools.
20
+ */
21
+ export type UITools = Record<string, UITool>;
22
+ /**
23
+ * Helper type to get values of an object.
24
+ */
25
+ type ValueOf<T> = T[keyof T];
26
+ /**
27
+ * Deep partial type.
28
+ */
29
+ type DeepPartial<T> = T extends object ? {
30
+ [P in keyof T]?: DeepPartial<T[P]>;
31
+ } : T;
32
+ /**
33
+ * A text part of a message.
34
+ */
35
+ export type TextUIPart = {
36
+ type: 'text';
37
+ text: string;
38
+ state?: 'streaming' | 'done';
39
+ providerMetadata?: ProviderMetadata;
40
+ };
41
+ /**
42
+ * A reasoning part of a message.
43
+ */
44
+ export type ReasoningUIPart = {
45
+ type: 'reasoning';
46
+ text: string;
47
+ state?: 'streaming' | 'done';
48
+ providerMetadata?: ProviderMetadata;
49
+ };
50
+ /**
51
+ * A source URL part of a message.
52
+ */
53
+ export type SourceUrlUIPart = {
54
+ type: 'source-url';
55
+ sourceId: string;
56
+ url: string;
57
+ title?: string;
58
+ providerMetadata?: ProviderMetadata;
59
+ };
60
+ /**
61
+ * A document source part of a message.
62
+ */
63
+ export type SourceDocumentUIPart = {
64
+ type: 'source-document';
65
+ sourceId: string;
66
+ mediaType: string;
67
+ title: string;
68
+ filename?: string;
69
+ providerMetadata?: ProviderMetadata;
70
+ };
71
+ /**
72
+ * A file part of a message.
73
+ */
74
+ export type FileUIPart = {
75
+ type: 'file';
76
+ mediaType: string;
77
+ filename?: string;
78
+ url: string;
79
+ providerMetadata?: ProviderMetadata;
80
+ };
81
+ /**
82
+ * A step boundary part of a message.
83
+ */
84
+ export type StepStartUIPart = {
85
+ type: 'step-start';
86
+ };
87
+ /**
88
+ * A data part of a message.
89
+ */
90
+ export type DataUIPart<TDataTypes extends UIDataTypes> = ValueOf<{
91
+ [NAME in keyof TDataTypes & string]: {
92
+ type: `data-${NAME}`;
93
+ id?: string;
94
+ data: TDataTypes[NAME];
95
+ };
96
+ }>;
97
+ /**
98
+ * A tool invocation part of a message.
99
+ */
100
+ export type ToolUIPart<TTools extends UITools = UITools> = ValueOf<{
101
+ [NAME in keyof TTools & string]: {
102
+ type: `tool-${NAME}`;
103
+ toolCallId: string;
104
+ } & ({
105
+ state: 'input-streaming';
106
+ input: DeepPartial<TTools[NAME]['input']> | undefined;
107
+ providerExecuted?: boolean;
108
+ output?: never;
109
+ errorText?: never;
110
+ } | {
111
+ state: 'input-available';
112
+ input: TTools[NAME]['input'];
113
+ providerExecuted?: boolean;
114
+ output?: never;
115
+ errorText?: never;
116
+ callProviderMetadata?: ProviderMetadata;
117
+ } | {
118
+ state: 'output-available';
119
+ input: TTools[NAME]['input'];
120
+ output: TTools[NAME]['output'];
121
+ errorText?: never;
122
+ providerExecuted?: boolean;
123
+ callProviderMetadata?: ProviderMetadata;
124
+ preliminary?: boolean;
125
+ } | {
126
+ state: 'output-error';
127
+ input: TTools[NAME]['input'] | undefined;
128
+ rawInput?: unknown;
129
+ output?: never;
130
+ errorText: string;
131
+ providerExecuted?: boolean;
132
+ callProviderMetadata?: ProviderMetadata;
133
+ });
134
+ }>;
135
+ /**
136
+ * A dynamic tool invocation part of a message.
137
+ */
138
+ export type DynamicToolUIPart = {
139
+ type: 'dynamic-tool';
140
+ toolName: string;
141
+ toolCallId: string;
142
+ } & ({
143
+ state: 'input-streaming';
144
+ input: unknown | undefined;
145
+ output?: never;
146
+ errorText?: never;
147
+ } | {
148
+ state: 'input-available';
149
+ input: unknown;
150
+ output?: never;
151
+ errorText?: never;
152
+ callProviderMetadata?: ProviderMetadata;
153
+ } | {
154
+ state: 'output-available';
155
+ input: unknown;
156
+ output: unknown;
157
+ errorText?: never;
158
+ callProviderMetadata?: ProviderMetadata;
159
+ preliminary?: boolean;
160
+ } | {
161
+ state: 'output-error';
162
+ input: unknown;
163
+ output?: never;
164
+ errorText: string;
165
+ callProviderMetadata?: ProviderMetadata;
166
+ });
167
+ /**
168
+ * All possible message part types.
169
+ */
170
+ export type UIMessagePart<TDataTypes extends UIDataTypes = UIDataTypes, TTools extends UITools = UITools> = TextUIPart | ReasoningUIPart | ToolUIPart<TTools> | DynamicToolUIPart | SourceUrlUIPart | SourceDocumentUIPart | FileUIPart | DataUIPart<TDataTypes> | StepStartUIPart;
171
+ /**
172
+ * AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
173
+ */
174
+ export interface UIMessage<TMetadata = unknown, TDataParts extends UIDataTypes = UIDataTypes, TTools extends UITools = UITools> {
175
+ /** A unique identifier for the message. */
176
+ id: string;
177
+ /** The role of the message. */
178
+ role: 'system' | 'user' | 'assistant';
179
+ /** The metadata of the message. */
180
+ metadata?: TMetadata;
181
+ /** The parts of the message. Use this for rendering the message in the UI. */
182
+ parts: Array<UIMessagePart<TDataParts, TTools>>;
183
+ }
4
184
  export type ChatMessageBase = UIMessage;
5
185
  export type ChatToolMessage = Extract<ChatMessageBase['parts'][number], {
6
186
  type: `tool-${string}`;
7
187
  }>;
8
188
  export type ChatToolType = ChatToolMessage['type'];
9
- export type { ChatInit } from 'ai';
189
+ /**
190
+ * Infer metadata type from UIMessage.
191
+ */
192
+ export type InferUIMessageMetadata<T extends UIMessage> = T extends UIMessage<infer TMetadata> ? TMetadata : unknown;
193
+ /**
194
+ * Infer data types from UIMessage.
195
+ */
196
+ export type InferUIMessageData<T extends UIMessage> = T extends UIMessage<unknown, infer TDataTypes> ? TDataTypes : UIDataTypes;
197
+ /**
198
+ * Infer tools from UIMessage.
199
+ */
200
+ export type InferUIMessageTools<T extends UIMessage> = T extends UIMessage<unknown, UIDataTypes, infer TTools> ? TTools : UITools;
201
+ /**
202
+ * Chat state interface.
203
+ */
204
+ export interface ChatState<TUIMessage extends UIMessage> {
205
+ status: ChatStatus;
206
+ error: Error | undefined;
207
+ messages: TUIMessage[];
208
+ pushMessage: (message: TUIMessage) => void;
209
+ popMessage: () => void;
210
+ replaceMessage: (index: number, message: TUIMessage) => void;
211
+ snapshot: <T>(thing: T) => T;
212
+ }
213
+ /**
214
+ * ID generator function type.
215
+ */
216
+ export type IdGenerator = () => string;
217
+ /**
218
+ * Callback function to be called when an error is encountered.
219
+ */
220
+ export type ChatOnErrorCallback = (error: Error) => void;
221
+ /**
222
+ * Infer tool call type from UIMessage.
223
+ */
224
+ export type InferUIMessageToolCall<TUIMessage extends UIMessage> = ValueOf<{
225
+ [NAME in keyof InferUIMessageTools<TUIMessage>]: {
226
+ toolName: NAME & string;
227
+ toolCallId: string;
228
+ input: InferUIMessageTools<TUIMessage>[NAME] extends {
229
+ input: infer INPUT;
230
+ } ? INPUT : never;
231
+ dynamic?: false;
232
+ };
233
+ }> | {
234
+ toolName: string;
235
+ toolCallId: string;
236
+ input: unknown;
237
+ dynamic: true;
238
+ };
239
+ /**
240
+ * Optional callback function that is invoked when a tool call is received.
241
+ */
242
+ export type ChatOnToolCallCallback<TUIMessage extends UIMessage = UIMessage> = (options: {
243
+ toolCall: InferUIMessageToolCall<TUIMessage>;
244
+ }) => void | PromiseLike<void>;
245
+ /**
246
+ * Function that is called when the assistant response has finished streaming.
247
+ */
248
+ export type ChatOnFinishCallback<TUIMessage extends UIMessage> = (options: {
249
+ message: TUIMessage;
250
+ messages: TUIMessage[];
251
+ isAbort: boolean;
252
+ isDisconnect: boolean;
253
+ isError: boolean;
254
+ }) => void;
255
+ /**
256
+ * Optional callback function that is called when a data part is received.
257
+ */
258
+ export type ChatOnDataCallback<TUIMessage extends UIMessage> = (dataPart: DataUIPart<InferUIMessageData<TUIMessage>>) => void;
259
+ /**
260
+ * Transport interface for sending and receiving chat messages.
261
+ */
262
+ export interface ChatTransport<TUIMessage extends UIMessage> {
263
+ sendMessages: (options: {
264
+ chatId: string;
265
+ messages: TUIMessage[];
266
+ abortSignal: AbortSignal;
267
+ requestMetadata?: unknown;
268
+ trigger: 'submit-message' | 'regenerate-message';
269
+ messageId?: string;
270
+ }) => Promise<ReadableStream<unknown>>;
271
+ reconnectToStream: (options: {
272
+ chatId: string;
273
+ }) => Promise<ReadableStream<unknown> | null>;
274
+ }
275
+ /**
276
+ * Chat initialization options.
277
+ */
278
+ export interface ChatInit<TUIMessage extends UIMessage> {
279
+ /** A unique identifier for the chat. If not provided, a random one will be generated. */
280
+ id?: string;
281
+ messages?: TUIMessage[];
282
+ /** A way to provide a function for generating message and chat IDs. */
283
+ generateId?: IdGenerator;
284
+ transport?: ChatTransport<TUIMessage>;
285
+ /** Callback function to be called when an error is encountered. */
286
+ onError?: ChatOnErrorCallback;
287
+ /** Optional callback function that is invoked when a tool call is received. */
288
+ onToolCall?: ChatOnToolCallCallback<TUIMessage>;
289
+ /** Function that is called when the assistant response has finished streaming. */
290
+ onFinish?: ChatOnFinishCallback<TUIMessage>;
291
+ /** Optional callback function that is called when a data part is received. */
292
+ onData?: ChatOnDataCallback<TUIMessage>;
293
+ /**
294
+ * When provided, this function will be called when the stream is finished or a tool call is added
295
+ * to determine if the current messages should be resubmitted.
296
+ */
297
+ sendAutomaticallyWhen?: (options: {
298
+ messages: TUIMessage[];
299
+ }) => boolean | PromiseLike<boolean>;
300
+ }
301
+ /**
302
+ * Abstract base class for chat implementations.
303
+ */
304
+ export interface AbstractChat<TUIMessage extends UIMessage> {
305
+ readonly id: string;
306
+ readonly generateId: IdGenerator;
307
+ status: ChatStatus;
308
+ error: Error | undefined;
309
+ messages: TUIMessage[];
310
+ lastMessage: TUIMessage | undefined;
311
+ sendMessage: (message?: (Omit<TUIMessage, 'id' | 'role'> & {
312
+ id?: TUIMessage['id'];
313
+ role?: TUIMessage['role'];
314
+ text?: never;
315
+ files?: never;
316
+ messageId?: string;
317
+ }) | {
318
+ text: string;
319
+ files?: FileList | FileUIPart[];
320
+ metadata?: InferUIMessageMetadata<TUIMessage>;
321
+ parts?: never;
322
+ messageId?: string;
323
+ } | {
324
+ files: FileList | FileUIPart[];
325
+ metadata?: InferUIMessageMetadata<TUIMessage>;
326
+ parts?: never;
327
+ messageId?: string;
328
+ }, options?: {
329
+ headers?: Record<string, string> | Headers;
330
+ body?: object;
331
+ }) => Promise<void>;
332
+ regenerate: (options?: {
333
+ messageId?: string;
334
+ } & {
335
+ headers?: Record<string, string> | Headers;
336
+ body?: object;
337
+ }) => Promise<void>;
338
+ resumeStream: (options?: {
339
+ headers?: Record<string, string> | Headers;
340
+ body?: object;
341
+ }) => Promise<void>;
342
+ clearError: () => void;
343
+ addToolResult: <TTool extends keyof InferUIMessageTools<TUIMessage>>(params: {
344
+ tool: TTool;
345
+ toolCallId: string;
346
+ output: InferUIMessageTools<TUIMessage>[TTool]['output'];
347
+ }) => Promise<void>;
348
+ stop: () => Promise<void>;
349
+ }
10
350
  export type AddToolResult = AbstractChat<UIMessage>['addToolResult'];
11
351
  export type AddToolResultWithOutput = (params: Pick<Parameters<AddToolResult>[0], 'output'>) => ReturnType<AddToolResult>;
12
352
  export type ClientSideToolComponentProps = {
@@ -27,3 +367,4 @@ export type ClientSideTool = {
27
367
  export type ClientSideTools = Record<string, ClientSideTool>;
28
368
  export type UserClientSideTool = Omit<ClientSideTool, 'addToolResult'>;
29
369
  export type UserClientSideTools = Record<string, UserClientSideTool>;
370
+ export {};
@@ -8,6 +8,7 @@ export * from './chat/ChatMessages';
8
8
  export * from './chat/ChatMessageLoader';
9
9
  export * from './chat/ChatMessageError';
10
10
  export * from './chat/ChatPrompt';
11
+ export * from './chat/ChatPromptSuggestions';
11
12
  export * from './chat/ChatToggleButton';
12
13
  export * from './chat/icons';
13
14
  export * from './chat/types';
@@ -8,6 +8,7 @@ export * from "./chat/ChatMessages.js";
8
8
  export * from "./chat/ChatMessageLoader.js";
9
9
  export * from "./chat/ChatMessageError.js";
10
10
  export * from "./chat/ChatPrompt.js";
11
+ export * from "./chat/ChatPromptSuggestions.js";
11
12
  export * from "./chat/ChatToggleButton.js";
12
13
  export * from "./chat/icons.js";
13
14
  export * from "./chat/types.js";
@@ -1,2 +1,2 @@
1
- declare const _default: "0.17.0";
1
+ declare const _default: "0.17.1";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '0.17.0';
1
+ export default '0.17.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch-ui-components",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Common UI components for InstantSearch.",
5
5
  "types": "dist/es/index.d.ts",
6
6
  "main": "dist/cjs/index.js",
@@ -48,10 +48,9 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@babel/runtime": "^7.27.6",
51
- "ai": "^5.0.18",
52
51
  "markdown-to-jsx": "^7.7.15",
53
52
  "zod": "^3.25.76 || ^4",
54
53
  "zod-to-json-schema": "3.24.6"
55
54
  },
56
- "gitHead": "c796f45db6153fb5fa627b90e334a572bbf31e33"
55
+ "gitHead": "d40d81bc9232c88f0dba1fdaada8471237f31847"
57
56
  }