@green-on-grey/ui-kit 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,76 @@
1
- # Temporary Holding Version
1
+ # ui-kit
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `@green-on-grey/ui-kit` — the UI kit of the Nabu and Hammurapi products: design tokens, styles,
4
+ React components, icons, the chat and the sign-in screen. The look is the one of Nabu.
5
+
6
+ Specification: `hammurapi-specs/specs/NAB/CMN/FTR.NAB.CMN-0005/`.
7
+ Showcase: <https://greenongrey.github.io/ui-kit/> (every release also lives in `/vX.Y.Z/`).
8
+
9
+ ## Use in a product
10
+
11
+ ```sh
12
+ npm install --save-exact @green-on-grey/ui-kit
13
+ ```
14
+
15
+ ```ts
16
+ // main.tsx — the styles of the kit come before the styles of the product
17
+ import "@green-on-grey/ui-kit/styles.css";
18
+ import "./styles.css";
19
+
20
+ // i18n — the strings of the components live in the namespace `uikit`
21
+ import { resources as kit } from "@green-on-grey/ui-kit/locales";
22
+ const resources = { en: { translation: en, uikit: kit.en }, ru: { translation: ru, uikit: kit.ru } /* … */ };
23
+ ```
24
+
25
+ ```tsx
26
+ import { Avatar, Icon, Modal, ToastProvider, TopBar, useToast } from "@green-on-grey/ui-kit";
27
+ import { Chat, ChatLayout, ConversationList } from "@green-on-grey/ui-kit/chat";
28
+ import { LoginScreen } from "@green-on-grey/ui-kit/login";
29
+ ```
30
+
31
+ | Entry | What |
32
+ |---|---|
33
+ | `@green-on-grey/ui-kit` | Components, icons, hooks |
34
+ | `@green-on-grey/ui-kit/chat` | The chat and its view types. It never talks to a server: the product adapts its API to the types |
35
+ | `@green-on-grey/ui-kit/login` | The sign-in screen |
36
+ | `@green-on-grey/ui-kit/locales` | Strings in en, ru, de, es, zh |
37
+ | `@green-on-grey/ui-kit/styles.css` | All the styles in one file; works without React |
38
+ | `@green-on-grey/ui-kit/tokens.css` | Tokens and themes only |
39
+ | `ui-kit-check` | Fails when a stylesheet of the product redefines the kit |
40
+
41
+ `index.html` of a product links the fonts and applies the saved theme before the first paint:
42
+
43
+ ```html
44
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
45
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
46
+ <link href="https://fonts.googleapis.com/css2?family=Onest:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet" />
47
+ <script>
48
+ try { var t = localStorage.getItem("<product>-theme"); if (t && t !== "system") document.documentElement.setAttribute("data-theme", t); } catch (e) {}
49
+ </script>
50
+ ```
51
+
52
+ A product does not redefine classes and tokens of the kit; `npm run lint` of a product runs
53
+ `ui-kit-check src/styles.css`.
54
+
55
+ ## Develop
56
+
57
+ ```sh
58
+ npm ci
59
+ npm run dev # the showcase on http://localhost:5180, built from src/
60
+ npm test # vitest
61
+ npm run test:e2e # Playwright on the showcase: behaviour and snapshots
62
+ npm run lint # oxlint + tsc
63
+ npm run build # dist/: ESM, types, styles.css, tokens.css, manifest.json
64
+ ```
65
+
66
+ To try a change in a product before a release, start the product with `UI_KIT_SRC=../ui-kit`.
67
+
68
+ ## Release
69
+
70
+ 1. Raise `version` in `package.json` and describe the release in `CHANGELOG.md` (`## X.Y.Z`).
71
+ A visible change of the look is at least a minor.
72
+ 2. Tag `vX.Y.Z` and push the tag: CI publishes the package to npm (trusted publishing) and the
73
+ showcase to GitHub Pages.
74
+
75
+ Snapshots of the showcase are compared with zero tolerance; their baselines are made by the
76
+ `update-snapshots` workflow, never on a developer machine.
@@ -0,0 +1,6 @@
1
+ export interface Manifest { version: string; classes: string[]; roots: string[]; tokens: string[] }
2
+ export interface Violation { line: number; selector: string; rule: 1 | 2 | 3; text: string }
3
+ export function classesOf(selector: string): string[];
4
+ export function compounds(selector: string): string[];
5
+ export function target(selector: string): string;
6
+ export function check(css: string, manifest: Manifest, from?: string): Violation[];
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env node
2
+ // ui-kit-check: a product does not redefine the kit (FTR.NAB.CMN-0005 R23, tech §3.6).
3
+ // ui-kit-check src/styles.css [more files]
4
+ // A violation is
5
+ // 1. a declaration of a token of the kit;
6
+ // 2. a rule whose target — the rightmost compound of the selector — is an element
7
+ // of the kit: it has a root class of the kit (one the kit styles on its own:
8
+ // .btn, .chip, .t) and no class of the product. Names of parts and states
9
+ // (.on, .hd, .lab) under a class of the product are the product's own;
10
+ // 3. a rule whose selector has no class of the product at all: only tags, only
11
+ // classes of the kit or both.
12
+ // There are no exceptions and no disabling comments: another look means a class
13
+ // of the product or a change of the kit.
14
+ import fs from "node:fs";
15
+ import path from "node:path";
16
+ import { fileURLToPath } from "node:url";
17
+ import { parse } from "postcss";
18
+
19
+ export const classesOf = (selector) => [...selector.matchAll(/\.(-?[A-Za-z_][\w-]*)/g)].map((m) => m[1]);
20
+
21
+ /** The compounds of a selector, left to right. Brackets and parentheses are kept
22
+ * whole: attribute values and arguments of :is() may hold spaces and combinators. */
23
+ export function compounds(selector) {
24
+ const out = [];
25
+ let depth = 0;
26
+ let cur = "";
27
+ for (const ch of selector.trim()) {
28
+ if (ch === "(" || ch === "[") depth++;
29
+ if (ch === ")" || ch === "]") depth--;
30
+ if (depth === 0 && /[\s>+~]/.test(ch)) {
31
+ if (cur) out.push(cur);
32
+ cur = "";
33
+ } else cur += ch;
34
+ }
35
+ if (cur) out.push(cur);
36
+ return out;
37
+ }
38
+
39
+ /** The rightmost compound of a selector: what the rule styles. */
40
+ export const target = (selector) => compounds(selector).at(-1) ?? "";
41
+
42
+ /** A compound without the arguments of its functions: `.a:not(.b)` → `.a:not()`. */
43
+ const outer = (compound) => {
44
+ let prev;
45
+ do { prev = compound; compound = compound.replace(/\([^()]*\)/g, "()"); } while (compound !== prev);
46
+ return compound;
47
+ };
48
+
49
+ /** Classes a compound may match through :is() and :where(): `:is(.btn, .chip)` → btn, chip. */
50
+ function alternatives(compound) {
51
+ const out = [];
52
+ for (const m of compound.matchAll(/:(?:is|where|matches)\(/g)) {
53
+ let depth = 1;
54
+ let i = m.index + m[0].length;
55
+ const from = i;
56
+ for (; i < compound.length && depth > 0; i++) depth += compound[i] === "(" ? 1 : compound[i] === ")" ? -1 : 0;
57
+ // of every alternative only its own target counts
58
+ for (const alt of compound.slice(from, i - 1).split(",")) out.push(...classesOf(outer(target(alt))));
59
+ }
60
+ return out;
61
+ }
62
+
63
+ /** The selectors of a rule with the selectors of the rules it is nested in. */
64
+ function resolved(rule) {
65
+ let list = rule.selectors;
66
+ for (let p = rule.parent; p; p = p.parent) {
67
+ if (p.type !== "rule") continue;
68
+ list = p.selectors.flatMap((ps) => list.map((s) => (s.includes("&") ? s.replaceAll("&", ps) : `${ps} ${s}`)));
69
+ }
70
+ return list;
71
+ }
72
+
73
+ /** Root classes of a stylesheet: those it styles on their own, as the single
74
+ * class of the first compound of a selector. */
75
+ export function rootsOf(ast) {
76
+ const roots = new Set();
77
+ ast.walkRules((r) => {
78
+ for (const selector of r.selectors) {
79
+ const first = classesOf(compounds(selector)[0] ?? "");
80
+ if (first.length === 1) roots.add(first[0]);
81
+ }
82
+ });
83
+ return roots;
84
+ }
85
+
86
+ /** Violations of one stylesheet: `{ line, selector, rule, text }`. */
87
+ export function check(css, manifest, from = "styles.css") {
88
+ const kit = new Set(manifest.classes);
89
+ const roots = new Set(manifest.roots);
90
+ const tokens = new Set(manifest.tokens);
91
+ const out = [];
92
+ const ast = parse(css, { from });
93
+ ast.walkDecls(/^--/, (d) => {
94
+ if (tokens.has(d.prop)) out.push({ line: d.source.start.line, selector: d.parent.selector ?? "", rule: 1, text: `the token ${d.prop} of the kit is redefined` });
95
+ });
96
+ ast.walkRules((r) => {
97
+ if (r.parent.type === "atrule" && r.parent.name.endsWith("keyframes")) return;
98
+ if (!r.nodes.some((n) => n.type === "decl" && !n.prop.startsWith("--"))) return;
99
+ for (const selector of resolved(r)) {
100
+ const own = (list) => list.some((c) => !kit.has(c));
101
+ const all = classesOf(selector);
102
+ // the classes the target has for certain, and those it may have through :is() / :where()
103
+ const sure = classesOf(outer(target(selector)));
104
+ const hit = [...sure, ...alternatives(target(selector))].filter((c) => roots.has(c));
105
+ if (!own(all)) out.push({ line: r.source.start.line, selector, rule: 3, text: "the selector has no class of the product" });
106
+ else if (hit.length > 0 && !own(sure)) out.push({ line: r.source.start.line, selector, rule: 2, text: `the rule restyles ${hit.map((c) => "." + c).join(", ")} of the kit` });
107
+ }
108
+ });
109
+ return out.toSorted((a, b) => a.line - b.line);
110
+ }
111
+
112
+ function main(argv) {
113
+ const files = argv.filter((a) => !a.startsWith("--"));
114
+ if (files.length === 0) {
115
+ console.error("usage: ui-kit-check <stylesheet> [more stylesheets]");
116
+ return 2;
117
+ }
118
+ const manifest = JSON.parse(fs.readFileSync(path.resolve(import.meta.dirname, "../dist/manifest.json"), "utf8"));
119
+ let bad = 0;
120
+ for (const file of files) {
121
+ for (const v of check(fs.readFileSync(file, "utf8"), manifest, file)) {
122
+ console.error(`${file}:${v.line} ${v.selector} — ${v.text} (rule ${v.rule})`);
123
+ bad++;
124
+ }
125
+ }
126
+ if (bad) console.error(`\nui-kit-check: ${bad} redefinition(s) of @green-on-grey/ui-kit ${manifest.version}. Use a class of the product or change the kit.`);
127
+ return bad ? 1 : 0;
128
+ }
129
+
130
+ if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) process.exit(main(process.argv.slice(2)));
@@ -0,0 +1,5 @@
1
+ import type { ChatProps } from "./types";
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. */
5
+ export declare function Chat(props: ChatProps): import("react").JSX.Element;
@@ -0,0 +1,19 @@
1
+ import { type ReactNode } from "react";
2
+ import type { ConversationListProps } from "./types";
3
+ /** The conversations of the user: the main one, the topics, the archive (design
4
+ * §6.2). In a wide place the list stands left of the messages; on a phone and in
5
+ * a narrow place it lies over them while open and closes by a pick, a tap
6
+ * beside it or Escape. */
7
+ export declare function ConversationList({ conversations, currentId, open, onPick, onClose, onCreate }: ConversationListProps): import("react").JSX.Element;
8
+ /** The place of a chat: the list of conversations, the conversation and what the
9
+ * product puts beside them. `narrow` is for a side panel: the list lies over the
10
+ * messages as on a phone, whatever the width of the window. */
11
+ export declare function ChatLayout({ narrow, children }: {
12
+ narrow?: boolean;
13
+ children: ReactNode;
14
+ }): import("react").JSX.Element;
15
+ /** The dialog of a new topic: one field, Enter creates. */
16
+ export declare function NewTopicModal({ onClose, onCreate }: {
17
+ onClose: () => void;
18
+ onCreate: (title: string) => Promise<void>;
19
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import type { ChatMessage, ChatStep } from "./types";
2
+ /** The time of a caption: hours and minutes in the language of the interface. */
3
+ export declare function markTime(iso: string, language: string): string;
4
+ /** More than three steps are folded to the last two (design §6.4). */
5
+ export declare function visibleSteps(steps: ChatStep[], open: boolean): ChatStep[];
6
+ /** One message of the conversation (design §6.4). */
7
+ export declare function MessageView({ m, busy, onRetry }: {
8
+ m: ChatMessage;
9
+ busy: boolean;
10
+ onRetry?: () => void;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1,4 @@
1
+ export { Chat } from "./Chat";
2
+ export { ChatLayout, ConversationList, NewTopicModal } from "./ConversationList";
3
+ export { useRecorder } from "./useRecorder";
4
+ export type { ChatAttachment, ChatConfirmation, ChatConversation, ChatMark, ChatMessage, ChatProps, ChatStep, ChatUpload, ChatWait, ConversationListProps, } from "./types";
@@ -0,0 +1,104 @@
1
+ import type { ReactNode } from "react";
2
+ import type { IconName } from "../components/Icon";
3
+ export interface ChatConversation {
4
+ id: string;
5
+ group: "main" | "topic" | "archive";
6
+ title: string;
7
+ /** The time of the last message, already worded by the product. */
8
+ when?: string;
9
+ unread?: number;
10
+ icon?: IconName;
11
+ }
12
+ /** A file the user has attached to the message being written. */
13
+ export interface ChatUpload {
14
+ id: string;
15
+ fileName: string;
16
+ }
17
+ export interface ChatAttachment extends ChatUpload {
18
+ href: string;
19
+ }
20
+ export interface ChatStep {
21
+ id: string;
22
+ text: string;
23
+ title?: string;
24
+ status: "running" | "done" | "error";
25
+ }
26
+ /** The caption over a message: the channel it came from or the context of the product. */
27
+ export interface ChatMark {
28
+ icon: IconName;
29
+ text: string;
30
+ }
31
+ export type ChatWait = {
32
+ state: "starting";
33
+ } | {
34
+ state: "queued";
35
+ position: number;
36
+ };
37
+ export interface ChatMessage {
38
+ 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";
41
+ text: string;
42
+ /** ISO time. */
43
+ createdAt: string;
44
+ status: "pending" | "streaming" | "done" | "failed";
45
+ mark?: ChatMark;
46
+ attachments?: ChatAttachment[];
47
+ steps?: ChatStep[];
48
+ wait?: ChatWait;
49
+ error?: {
50
+ text: string;
51
+ transient: boolean;
52
+ };
53
+ /** The content of the product inside the message: a mail card, a digest. */
54
+ content?: ReactNode;
55
+ }
56
+ export interface ChatConfirmation {
57
+ id: string;
58
+ summary: string;
59
+ preview?: string;
60
+ }
61
+ /** Give the chat a `key` of the conversation: its composer and its scroll belong to one conversation. */
62
+ export interface ChatProps {
63
+ agentName: string;
64
+ messages: ChatMessage[];
65
+ /** The header of the conversation: the agent, the model, the menus of the product. */
66
+ header?: ReactNode;
67
+ /** The second line of the empty conversation. */
68
+ emptyHint?: ReactNode;
69
+ loading?: boolean;
70
+ historyError?: ReactNode;
71
+ hasOlder?: boolean;
72
+ loadingOlder?: boolean;
73
+ /** A turn is being sent or answered: sending and retrying wait. */
74
+ busy?: boolean;
75
+ /** Shown instead of the composer: why one cannot write here and what to do. */
76
+ readOnly?: ReactNode;
77
+ confirmations?: ChatConfirmation[];
78
+ /** Over the composer: the modes of the chat of Hammurapi. */
79
+ aboveComposer?: ReactNode;
80
+ upload?: {
81
+ maxBytes: number;
82
+ accept?: string;
83
+ };
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>;
86
+ onLoadOlder?(): void;
87
+ onRetry?(messageId: string): void;
88
+ onCancel?(): void;
89
+ onConfirm?(id: string, approve: boolean): void;
90
+ /** `null`: the upload failed and the product has told the user. */
91
+ onUpload?(file: File): Promise<ChatUpload | null>;
92
+ /** The text of a recording; `null`: it failed and the product has told the user. */
93
+ onTranscribe?(recording: Blob): Promise<string | null>;
94
+ }
95
+ export interface ConversationListProps {
96
+ conversations: ChatConversation[];
97
+ currentId?: string;
98
+ /** In a narrow place and on a phone the list lies over the messages while open. */
99
+ open: boolean;
100
+ onPick(id: string): void;
101
+ onClose(): void;
102
+ /** Rejects with an Error whose message is shown in the dialog. */
103
+ onCreate?(title: string): Promise<void>;
104
+ }
@@ -0,0 +1,9 @@
1
+ /** Push-to-talk recording with MediaRecorder. */
2
+ export declare function useRecorder(): {
3
+ supported: boolean;
4
+ recording: boolean;
5
+ seconds: string;
6
+ error: boolean;
7
+ start: () => Promise<void>;
8
+ stop: () => Promise<Blob | null>;
9
+ };