@green-on-grey/ui-kit 1.0.1 → 1.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.
@@ -6,6 +6,28 @@ export interface AgentOption {
6
6
  label: string;
7
7
  icon: IconName;
8
8
  }
9
+ /** A model the user may choose for the agent (FTR.NAB.CHAT-0001 R16, design §3.3). */
10
+ export interface AgentModelOption {
11
+ key: string;
12
+ label: string;
13
+ /** The connection or the default model, grey under the name. */
14
+ sub?: string;
15
+ /** The capabilities: images, reasoning, the window. */
16
+ badges?: {
17
+ icon?: IconName;
18
+ text: string;
19
+ }[];
20
+ /** Under the row of the chosen model: the context will be compacted. */
21
+ warn?: ReactNode;
22
+ }
23
+ /** The block «Model» of the menu: one model is shown without a choice; none — the text of the product. */
24
+ export interface AgentModels {
25
+ label: ReactNode;
26
+ options: AgentModelOption[];
27
+ value: string;
28
+ onPick: (key: string) => void;
29
+ empty?: ReactNode;
30
+ }
9
31
  /** The round button of the agent: its icon, and the menu behind it. */
10
32
  export declare function AgentButton({ icon, label, title, expanded, small, disabled, onClick }: {
11
33
  icon: IconName;
@@ -19,7 +41,7 @@ export declare function AgentButton({ icon, label, title, expanded, small, disab
19
41
  /** The menu of the agent (FTR.NAB.CMN-0005 R15, design §6.6): its name and a
20
42
  * choice among the options of the product, as tiles with icons. The name is
21
43
  * saved on Enter and on leaving the field; a pick is saved at once. */
22
- export declare function AgentMenu({ label, name, options, value, optionsLabel, hint, narrow, onRename, onPick, onClose }: {
44
+ export declare function AgentMenu({ label, name, options, value, optionsLabel, hint, narrow, models, onRename, onPick, onClose }: {
23
45
  /** The name of the dialog for a screen reader. */
24
46
  label: string;
25
47
  name: string;
@@ -29,6 +51,8 @@ export declare function AgentMenu({ label, name, options, value, optionsLabel, h
29
51
  hint?: ReactNode;
30
52
  /** A narrow place — a side panel: the options go in one column. */
31
53
  narrow?: boolean;
54
+ /** The choice of the model after the options. */
55
+ models?: AgentModels;
32
56
  onRename: (name: string) => void;
33
57
  onPick: (key: string) => void;
34
58
  /** Must keep its identity between renders. */
@@ -1,5 +1,6 @@
1
1
  import type { ChatProps } from "./types";
2
2
  /** The conversation: the messages and the composer (FTR.NAB.CMN-0005 R11–R13,
3
- * design §6). The behaviour is the one of the chat of Nabu. A control exists
4
- * only when the product gave its handler: no `onCancel` — no cancel button. */
3
+ * design §6; FTR.NAB.CHAT-0001 design §3.1). The behaviour is the one of the
4
+ * chat of Nabu. A control exists only when the product gave its handler: no
5
+ * `onCancel` — no cancel button, no `commands` — no palette. */
5
6
  export declare function Chat(props: ChatProps): import("react").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import type { ChatCommand } from "./types";
2
+ /** The items of the palette that match what is typed after "/". */
3
+ export declare function matchCommands(commands: ChatCommand[], query: string): ChatCommand[];
4
+ /** The palette of commands and skills over the composer (FTR.NAB.CHAT-0001 R4,
5
+ * design §3.1). The composer owns the keys: arrows move `active`, Enter and Tab
6
+ * pick it, Esc closes. */
7
+ export declare function CommandPalette({ items, active, onPick, onHover }: {
8
+ items: ChatCommand[];
9
+ active: number;
10
+ onPick: (c: ChatCommand) => void;
11
+ onHover: (i: number) => void;
12
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import type { ChatContext } from "./types";
2
+ /** A number of tokens shortly: 42K, 1.2M in the language of the interface. */
3
+ export declare function tokens(n: number, lng: string): string;
4
+ /** The fill of the context window by a ring next to the send button
5
+ * (FTR.NAB.CHAT-0001 R3, design §3.1): grey, amber from 70 %, red from 90 %.
6
+ * A click shows the numbers; a full context offers to compact or to reset. */
7
+ export declare function ContextMeter({ context, onCompact, onReset }: {
8
+ context: ChatContext;
9
+ onCompact?: () => void;
10
+ onReset?: () => void;
11
+ }): import("react").JSX.Element;
@@ -1,5 +1,8 @@
1
1
  export { Chat } from "./Chat";
2
2
  export { ChatLayout, ConversationList, NewTopicModal } from "./ConversationList";
3
- export { AgentButton, AgentMenu, type AgentOption } from "./AgentMenu";
3
+ export { AgentButton, AgentMenu, type AgentModelOption, type AgentModels, type AgentOption } from "./AgentMenu";
4
+ export { CommandPalette } from "./CommandPalette";
5
+ export { ContextMeter, tokens } from "./ContextMeter";
6
+ export { MessageView } from "./MessageView";
4
7
  export { useRecorder } from "./useRecorder";
5
- export type { ChatAttachment, ChatConfirmation, ChatConversation, ChatMark, ChatMessage, ChatProps, ChatStep, ChatUpload, ChatWait, ConversationListProps, } from "./types";
8
+ export type { ChatAttachment, ChatCommand, ChatConfirmation, ChatContext, ChatConversation, ChatEvent, ChatMark, ChatMessage, ChatProps, ChatStep, ChatUpload, ChatWait, ConversationListProps, } from "./types";
@@ -34,10 +34,20 @@ export type ChatWait = {
34
34
  state: "queued";
35
35
  position: number;
36
36
  };
37
+ /** An event of the conversation shown as a divider (FTR.NAB.CHAT-0001 design §3.2):
38
+ * a reset of the context, a compaction, a change of the model. */
39
+ export interface ChatEvent {
40
+ icon: IconName;
41
+ text: string;
42
+ /** Unfolded by a click: the summary of a compaction. */
43
+ details?: string;
44
+ }
37
45
  export interface ChatMessage {
38
46
  id: string;
39
- /** `note` is a line of the system without a bubble: the outcome of a confirmation, a cancelled turn. */
40
- role: "user" | "assistant" | "note";
47
+ /** `note` is a line of the system without a bubble: the outcome of a confirmation, a cancelled turn.
48
+ * `event` is a divider of the conversation (`event` is set). */
49
+ role: "user" | "assistant" | "note" | "event";
50
+ event?: ChatEvent;
41
51
  text: string;
42
52
  /** ISO time. */
43
53
  createdAt: string;
@@ -52,12 +62,31 @@ export interface ChatMessage {
52
62
  };
53
63
  /** The content of the product inside the message: a mail card, a digest. */
54
64
  content?: ReactNode;
65
+ /** The tooltip of the bubble: the model of an answer (FTR.NAB.CHAT-0001 R18). */
66
+ hint?: string;
55
67
  }
56
68
  export interface ChatConfirmation {
57
69
  id: string;
58
70
  summary: string;
59
71
  preview?: string;
60
72
  }
73
+ /** An item of the palette of commands (FTR.NAB.CHAT-0001 R4): a command of the
74
+ * conversation or a skill. */
75
+ export interface ChatCommand {
76
+ kind: "command" | "skill";
77
+ /** What is typed after "/": `new`, `compact`; the name of a skill. */
78
+ name: string;
79
+ description?: string;
80
+ /** The source of a skill: the item of the catalog. */
81
+ source?: string;
82
+ /** A command that takes a text after it (`/compact <what to keep>`). */
83
+ takesText?: boolean;
84
+ }
85
+ /** The fill of the context window of the conversation (R3). */
86
+ export interface ChatContext {
87
+ tokens: number;
88
+ window: number;
89
+ }
61
90
  /** Give the chat a `key` of the conversation: its composer and its scroll belong to one conversation. */
62
91
  export interface ChatProps {
63
92
  agentName: string;
@@ -81,14 +110,27 @@ export interface ChatProps {
81
110
  maxBytes: number;
82
111
  accept?: string;
83
112
  };
84
- /** Resolves when the message is accepted (the composer is cleared); rejects to keep the text. */
85
- onSend(text: string, attachmentIds: string[], voice: boolean): Promise<void>;
113
+ /** The palette of "/": commands and skills; without it "/" is plain text. */
114
+ commands?: ChatCommand[];
115
+ /** Runs a command of the palette or one typed in full; rejects to keep the text. */
116
+ onCommand?(name: string, text: string): Promise<void>;
117
+ /** The fill of the context; with `onCompact` and `onReset` a full context offers them. */
118
+ context?: ChatContext;
119
+ onCompact?(): void;
120
+ onReset?(): void;
121
+ /** The longest recording in seconds (the recording stops by itself). */
122
+ voiceMaxSeconds?: number;
123
+ /** Resolves when the message is accepted (the composer is cleared); rejects to keep the text.
124
+ * `skill` is the skill the user picked in the palette. */
125
+ onSend(text: string, attachmentIds: string[], voice: boolean, skill?: string): Promise<void>;
86
126
  onLoadOlder?(): void;
87
127
  onRetry?(messageId: string): void;
88
128
  onCancel?(): void;
89
129
  onConfirm?(id: string, approve: boolean): void;
90
130
  /** `null`: the upload failed and the product has told the user. */
91
131
  onUpload?(file: File): Promise<ChatUpload | null>;
132
+ /** The files attached to the message being written, after every change. */
133
+ onPendingChange?(uploads: ChatUpload[]): void;
92
134
  /** The text of a recording; `null`: it failed and the product has told the user. */
93
135
  onTranscribe?(recording: Blob): Promise<string | null>;
94
136
  }
@@ -1,9 +1,15 @@
1
- /** Push-to-talk recording with MediaRecorder. */
2
- export declare function useRecorder(): {
1
+ /** Recording with MediaRecorder (FTR.NAB.CHAT-0001 R20): started and stopped
2
+ * by the user, stopped by itself at `maxSeconds`; the level of the voice is
3
+ * sampled for the bar of the recording. */
4
+ export declare function useRecorder(maxSeconds?: number, onLimit?: () => void): {
3
5
  supported: boolean;
4
6
  recording: boolean;
5
- seconds: string;
7
+ seconds: number;
8
+ level: number;
6
9
  error: boolean;
7
10
  start: () => Promise<void>;
8
11
  stop: () => Promise<Blob | null>;
12
+ cancel: () => void;
9
13
  };
14
+ /** m:ss of a number of seconds. */
15
+ export declare function clock(seconds: number): string;