@mast-ai/react-ui 0.1.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 +193 -0
- package/README.md +57 -0
- package/dist/approval.d.ts +82 -0
- package/dist/components/AssistantMessage.d.ts +44 -0
- package/dist/components/ChatInput.d.ts +41 -0
- package/dist/components/ConversationPanel.d.ts +43 -0
- package/dist/components/InlineApproval.d.ts +26 -0
- package/dist/components/MessageItem.d.ts +29 -0
- package/dist/components/MessageList.d.ts +38 -0
- package/dist/components/ThinkingBlock.d.ts +32 -0
- package/dist/components/ToolCallBlock.d.ts +11 -0
- package/dist/components/UserMessage.d.ts +19 -0
- package/dist/context.d.ts +113 -0
- package/dist/hooks/useAgentStream.d.ts +131 -0
- package/dist/icons.d.ts +21 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +1012 -0
- package/dist/mentions/MentionPicker.d.ts +30 -0
- package/dist/mentions/index.d.ts +6 -0
- package/dist/mentions/types.d.ts +63 -0
- package/dist/mentions/useMentions.d.ts +54 -0
- package/dist/mentions/utils.d.ts +33 -0
- package/dist/styles.css +631 -0
- package/dist/types.d.ts +162 -0
- package/package.json +71 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { MentionItem } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Props accepted by {@link MentionPicker}. Exported for consumers building
|
|
5
|
+
* a bespoke compound input on top of {@link useMentions}.
|
|
6
|
+
*/
|
|
7
|
+
export interface MentionPickerProps<T = unknown> {
|
|
8
|
+
/** Items to render. Empty list hides the picker entirely. */
|
|
9
|
+
items: MentionItem<T>[];
|
|
10
|
+
/** Index of the keyboard-active row. */
|
|
11
|
+
activeIndex: number;
|
|
12
|
+
/** Called when the user clicks a row. */
|
|
13
|
+
onSelect: (item: MentionItem<T>) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Stable id prefix used to build the per-option DOM id. Consumers that
|
|
16
|
+
* wire `aria-activedescendant` on a textarea should pass the same prefix
|
|
17
|
+
* and read the active id as `${idPrefix}-${activeIndex}`.
|
|
18
|
+
*/
|
|
19
|
+
idPrefix: string;
|
|
20
|
+
/** Renders a custom row body. Default: a `<div>` showing `item.label`. */
|
|
21
|
+
renderItem?: (item: MentionItem<T>, isActive: boolean) => ReactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Floating popover rendered above {@link import('../components/ChatInput').ChatInput}
|
|
25
|
+
* when an in-progress mention has at least one filtered item.
|
|
26
|
+
*
|
|
27
|
+
* Uses `role="listbox"` with `role="option"` rows so screen readers announce
|
|
28
|
+
* the active row when the textarea's `aria-activedescendant` updates.
|
|
29
|
+
*/
|
|
30
|
+
export declare function MentionPicker<T = unknown>({ items, activeIndex, onSelect, idPrefix, renderItem, }: MentionPickerProps<T>): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { MentionItem, MentionSegment, MentionsConfig } from './types';
|
|
2
|
+
export { buildInlineMentionPrompt, extractMentionQuery, removeMentionTrigger } from './utils';
|
|
3
|
+
export { useMentions } from './useMentions';
|
|
4
|
+
export type { UseMentionsReturn } from './useMentions';
|
|
5
|
+
export { MentionPicker } from './MentionPicker';
|
|
6
|
+
export type { MentionPickerProps } from './MentionPicker';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A single picker entry. Generic over `T` so consumers can attach arbitrary
|
|
4
|
+
* payloads (document records, file paths, skill descriptors, …) without the
|
|
5
|
+
* library knowing the domain shape.
|
|
6
|
+
*/
|
|
7
|
+
export interface MentionItem<T = unknown> {
|
|
8
|
+
/** Stable key. Used as the React key in the picker and the chip identifier. */
|
|
9
|
+
id: string;
|
|
10
|
+
/** Shown in the picker row and rendered as the chip text after the trigger. */
|
|
11
|
+
label: string;
|
|
12
|
+
/** Optional secondary text rendered alongside `label` in the picker. */
|
|
13
|
+
description?: string;
|
|
14
|
+
/** Arbitrary payload accessible from `buildPrompt`, `renderItem`, `renderChip`. */
|
|
15
|
+
data?: T;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The committed compound input is `MentionSegment<T>[]` followed by a free-form
|
|
19
|
+
* trailing string. Each segment is the plain text immediately preceding a chip
|
|
20
|
+
* plus the mentioned item itself; selecting a new item from the picker
|
|
21
|
+
* appends a segment and starts a fresh trailing region.
|
|
22
|
+
*/
|
|
23
|
+
export interface MentionSegment<T = unknown> {
|
|
24
|
+
/** Plain text preceding the chip. */
|
|
25
|
+
text: string;
|
|
26
|
+
/** The mentioned item that terminates this segment. */
|
|
27
|
+
item: MentionItem<T>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Configuration object accepted by `<ChatInput mentions={...}>`,
|
|
31
|
+
* `<ConversationPanel mentions={...}>`, and `useMentions`. Every field except
|
|
32
|
+
* one of `items` / `onSearch` is optional.
|
|
33
|
+
*/
|
|
34
|
+
export interface MentionsConfig<T = unknown> {
|
|
35
|
+
/** Trigger character. Default: `'@'`. Must be a single character. */
|
|
36
|
+
trigger?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Static item list. The picker filters by case-insensitive substring on
|
|
39
|
+
* `label`. Mutually exclusive with `onSearch`; if both are provided
|
|
40
|
+
* `onSearch` wins.
|
|
41
|
+
*/
|
|
42
|
+
items?: MentionItem<T>[];
|
|
43
|
+
/**
|
|
44
|
+
* Async or sync search function. Called with the current query each time it
|
|
45
|
+
* changes. The latest result wins — stale resolutions are discarded so
|
|
46
|
+
* out-of-order responses cannot replace newer matches.
|
|
47
|
+
*/
|
|
48
|
+
onSearch?: (query: string) => MentionItem<T>[] | Promise<MentionItem<T>[]>;
|
|
49
|
+
/** Renders a custom row in the picker. Default: `<div>{item.label}</div>`. */
|
|
50
|
+
renderItem?: (item: MentionItem<T>, isActive: boolean) => ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Renders the chip that replaces the in-progress `@<query>` once selected.
|
|
53
|
+
* Default: the library renders `@<label>` followed by an `x` remove button.
|
|
54
|
+
*/
|
|
55
|
+
renderChip?: (item: MentionItem<T>, onRemove: () => void) => ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* Builds the prompt sent to the LLM from the segment list and trailing
|
|
58
|
+
* text. Default: returns the inline display form (segments joined as
|
|
59
|
+
* `<text>@<label>...<trailing>`). Override this to inject context
|
|
60
|
+
* (document IDs, file paths, …) around or before the inline text.
|
|
61
|
+
*/
|
|
62
|
+
buildPrompt?: (segments: MentionSegment<T>[], trailing: string) => string;
|
|
63
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { KeyboardEvent } from 'react';
|
|
2
|
+
import type { MentionItem, MentionSegment, MentionsConfig } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Return shape of {@link useMentions}.
|
|
5
|
+
*
|
|
6
|
+
* Consumers either pass the whole object to `<ChatInput mentions>` (via the
|
|
7
|
+
* `mentions` config — `<ChatInput>` calls `useMentions` internally) or wire
|
|
8
|
+
* the individual fields into a bespoke compound input.
|
|
9
|
+
*/
|
|
10
|
+
export interface UseMentionsReturn<T = unknown> {
|
|
11
|
+
/** Committed segments preceding the trailing-text region. */
|
|
12
|
+
segments: MentionSegment<T>[];
|
|
13
|
+
/** Free-form text after the last chip (or the whole field when no chips). */
|
|
14
|
+
trailingInput: string;
|
|
15
|
+
/** Current `@<query>` if the cursor is inside an in-progress mention. */
|
|
16
|
+
mentionQuery: string | null;
|
|
17
|
+
/** Items the picker should render right now (filtered or async-resolved). */
|
|
18
|
+
filteredItems: MentionItem<T>[];
|
|
19
|
+
/** Index of the keyboard-highlighted picker row. */
|
|
20
|
+
pickerIndex: number;
|
|
21
|
+
/** Set the trailing-text region. Recomputes `mentionQuery` and resets picker focus. */
|
|
22
|
+
setTrailingInput: (text: string) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Wire to the textarea's `onKeyDown`. Returns `true` if the key was
|
|
25
|
+
* consumed by the picker so the host can suppress its own handling. Up /
|
|
26
|
+
* Down / Enter / Escape are only consumed when the picker has at least one
|
|
27
|
+
* filtered item.
|
|
28
|
+
*/
|
|
29
|
+
handleKeyDown: (event: KeyboardEvent<HTMLTextAreaElement>) => boolean;
|
|
30
|
+
/** Append a chip and reset the in-progress mention. */
|
|
31
|
+
selectItem: (item: MentionItem<T>) => void;
|
|
32
|
+
/** Remove a chip by id, re-merging its preceding text into the next region. */
|
|
33
|
+
removeChip: (id: string) => void;
|
|
34
|
+
/** Build `{ prompt, displayText }` for `sendMessage`. */
|
|
35
|
+
buildSubmission: () => {
|
|
36
|
+
prompt: string;
|
|
37
|
+
displayText: string;
|
|
38
|
+
};
|
|
39
|
+
/** Clear all segments and trailing text. */
|
|
40
|
+
clear: () => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Owns the segment / trailing-text / picker-index state behind the optional
|
|
44
|
+
* `<ChatInput mentions>` UI. Exported so consumers can build a bespoke input
|
|
45
|
+
* (e.g. with their own picker component or virtualisation) without giving up
|
|
46
|
+
* the segment management and async-search plumbing.
|
|
47
|
+
*
|
|
48
|
+
* - `config.items` filters by case-insensitive substring on `label`.
|
|
49
|
+
* - `config.onSearch` is called every time the query changes; the latest
|
|
50
|
+
* resolution wins so out-of-order responses cannot replace newer matches.
|
|
51
|
+
* Already-selected items are filtered out of the picker so the same
|
|
52
|
+
* reference cannot be picked twice.
|
|
53
|
+
*/
|
|
54
|
+
export declare function useMentions<T = unknown>(config: MentionsConfig<T>): UseMentionsReturn<T>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { MentionSegment } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the query suffix at the end of `input` if the user is currently
|
|
4
|
+
* typing an in-progress mention, or `null` otherwise.
|
|
5
|
+
*
|
|
6
|
+
* A mention is considered in-progress when the trigger character appears
|
|
7
|
+
* after the last whitespace and is not followed by another whitespace
|
|
8
|
+
* character. The query may be empty (just typed `@` and nothing after).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* extractMentionQuery('hello @doc') === 'doc'
|
|
12
|
+
* extractMentionQuery('hello @') === ''
|
|
13
|
+
* extractMentionQuery('hello @doc ') === null // space ends the mention
|
|
14
|
+
* extractMentionQuery('hello world') === null // no trigger
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractMentionQuery(input: string, trigger?: string): string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Strips a trailing `@<query>` from `input`, preserving any whitespace
|
|
19
|
+
* the user typed before the trigger. Used after the user commits a picker
|
|
20
|
+
* selection — the preserved whitespace survives into the segment text so
|
|
21
|
+
* the inline display form (`<text>@<label>`) keeps the natural space
|
|
22
|
+
* between the preceding word and the chip.
|
|
23
|
+
*/
|
|
24
|
+
export declare function removeMentionTrigger(input: string, trigger?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Default `buildPrompt` implementation: returns the inline form
|
|
27
|
+
* `<text1>@<label1><text2>@<label2>...<trailing>`.
|
|
28
|
+
*
|
|
29
|
+
* Apps that want to inject extra context (document IDs, file paths, …) can
|
|
30
|
+
* call this and prepend / wrap the result, or build the string from scratch
|
|
31
|
+
* using `segments` and `trailing`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildInlineMentionPrompt<T>(segments: MentionSegment<T>[], trailing: string): string;
|