@smarter.sh/ui-chat 0.10.0 → 0.11.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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Smarter Chat's message catalogs: generated from locale/<language>/LC_MESSAGES/smarter-chat.po by
3
+ * scripts/i18n.mjs. Do not edit; run `npm run i18n`. See src/lib/i18n.tsx.
4
+ */
5
+ /** A language's translated messages, by msgid (context, \u0004, msgid in a context), and its plural rule. */
6
+ export interface Catalog {
7
+ /** The index of the plural form for a count. */
8
+ plural: (n: number) => number;
9
+ /** A message's translation, or its plural forms' translations. */
10
+ messages: Record<string, string | string[]>;
11
+ }
12
+ export declare const CATALOGS: Record<string, Catalog>;
@@ -1,7 +1,3 @@
1
- /**
2
- * The chat's title: the LLMClient's app name and version, with icons for whether it is valid, and
3
- * whether it is deployed or is still in the sandbox.
4
- */
5
1
  import "@/components/AppTitle/styles.css";
6
2
  interface AppTitleProps {
7
3
  title: string;
@@ -11,8 +11,8 @@ export interface DocSection {
11
11
  links: DocLink[];
12
12
  }
13
13
  /** The technical references for prompt engineers, who build LLMClients in the sandbox. */
14
- export declare const PROMPT_ENGINEER_LINKS: DocLink[];
14
+ export declare function promptEngineerLinks(): DocLink[];
15
15
  /** The technical references for software engineers, who build the applications that host them. */
16
- export declare const SOFTWARE_ENGINEER_LINKS: DocLink[];
16
+ export declare function softwareEngineerLinks(): DocLink[];
17
17
  /** The tabs of the Docs dialog, from left to right. The first one is selected when it opens. */
18
- export declare const DOC_SECTIONS: DocSection[];
18
+ export declare function docSections(): DocSection[];
@@ -12,6 +12,6 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBoundaryS
12
12
  state: ErrorBoundaryState;
13
13
  static getDerivedStateFromError(error: Error): ErrorBoundaryState;
14
14
  componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
15
- render(): string | number | bigint | boolean | import("react").JSX.Element | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | null | undefined;
15
+ render(): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
16
16
  }
17
17
  export default ErrorBoundary;
@@ -20,11 +20,16 @@
20
20
  * The LLMClient's styles (its manifest's spec.config.styles) set its logo, which is displayed in
21
21
  * the header, its avatars, its background image, its fonts and its colors. See lib/styles.ts.
22
22
  *
23
+ * The chat's own text, e.g. its buttons' labels, is in the language that the `language` prop asks for, or else the
24
+ * page's, or else the browser's: English, Spanish or French. See lib/i18n.tsx. The LLMClient's own text, e.g. its
25
+ * welcome message and its example prompts, and the messages of the conversation are displayed as they are.
26
+ *
27
+
23
28
  * This is the component that the @smarter.sh/ui-chat npm package exports, and that the Smarter web
24
29
  * console's LLMClient prompt workbench renders. See main.tsx.
25
30
  */
26
31
  import "@chatscope/chat-ui-kit-styles/dist/default/styles.min.css";
27
32
  import type { SmarterChatProps } from "@/types";
28
33
  import "@/components/SmarterChat/styles.css";
29
- declare function SmarterChat({ apiUrl, apiKey, toggleMetadata, csrfCookieName, csrftoken, debugCookieName, debugCookieExpiration, debugMode, sessionCookieName, sessionCookieExpiration, cookiePath, showConsole, cookieDomain, smarterRequestId, logStreamUrl, streamProgress, }: SmarterChatProps): import("react").JSX.Element;
34
+ declare function SmarterChat({ apiUrl, apiKey, toggleMetadata, csrfCookieName, csrftoken, debugCookieName, debugCookieExpiration, debugMode, sessionCookieName, sessionCookieExpiration, cookiePath, showConsole, cookieDomain, smarterRequestId, logStreamUrl, streamProgress, language, }: SmarterChatProps): import("react").JSX.Element;
30
35
  export default SmarterChat;
@@ -3,7 +3,7 @@ export declare const ELEMENT_NAME = "smarter-chat";
3
3
  export declare const TOGGLE_EVENT = "smarter-chat-toggle";
4
4
  export declare class SmarterChatElement extends HTMLElement {
5
5
  #private;
6
- static observedAttributes: ("chatbot" | "color" | "label" | "open" | "debug" | "width" | "height" | "position" | "api-key" | "mode" | "z-index" | "session-cookie-name" | "cookie-path" | "stream-progress")[];
6
+ static observedAttributes: ("chatbot" | "color" | "label" | "open" | "debug" | "language" | "width" | "height" | "position" | "api-key" | "mode" | "z-index" | "session-cookie-name" | "cookie-path" | "stream-progress")[];
7
7
  /** The element's options, from its attributes. */
8
8
  get options(): EmbedOptionsResult;
9
9
  /** Whether the launcher is open. */
@@ -11,8 +11,8 @@ export interface EmbedOptions {
11
11
  position: EmbedPosition;
12
12
  /** Whether the launcher starts open. */
13
13
  open: boolean;
14
- /** The launcher's accessible name, and the chat panel's. */
15
- label: string;
14
+ /** The launcher's accessible name, and the chat panel's. Null for the default, "Chat", in the chat's language. */
15
+ label: string | null;
16
16
  /** The launcher button's background color. */
17
17
  color: string;
18
18
  /** The width of the inline chat, or of the launcher's panel. */
@@ -29,6 +29,8 @@ export interface EmbedOptions {
29
29
  streamProgress: boolean;
30
30
  /** Log to the browser console. */
31
31
  debug: boolean;
32
+ /** The language of the chat's own text, e.g. "fr". Null for the page's, or else the browser's. */
33
+ language: string | null;
32
34
  }
33
35
  /** The result of reading the options: the options, or why they can't be used. */
34
36
  export type EmbedOptionsResult = {
@@ -39,8 +41,7 @@ export type EmbedOptionsResult = {
39
41
  error: string;
40
42
  };
41
43
  /** The attributes that a <smarter-chat> element reads, in kebab-case. */
42
- export declare const OPTION_ATTRIBUTES: readonly ["chatbot", "api-key", "mode", "position", "open", "label", "color", "width", "height", "z-index", "session-cookie-name", "cookie-path", "stream-progress", "debug"];
43
- export declare const DEFAULT_LABEL = "Chat";
44
+ export declare const OPTION_ATTRIBUTES: readonly ["chatbot", "api-key", "mode", "position", "open", "label", "color", "width", "height", "z-index", "session-cookie-name", "cookie-path", "stream-progress", "debug", "language"];
44
45
  export declare const DEFAULT_COLOR = "#ff5733";
45
46
  export declare const DEFAULT_Z_INDEX = 2147483000;
46
47
  /** A boolean attribute: present and empty, or "true", is true. "false" is false. Missing is the default. */
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Translation functions for Smarter Chat.
3
+ *
4
+ * Smarter Chat is translated with gettext, the same way as the Smarter web console, and has the same
5
+ * languages: English, which is the source language of every message, Spanish (Latin American, under the
6
+ * generic "es" code) and French. Its message catalogs are its own, in locale/<language>/LC_MESSAGES/smarter-chat.po,
7
+ * because the chat also runs on pages that the Smarter platform didn't render: the npm library's and the embed
8
+ * script's. `npm run i18n` compiles them into src/catalogs.gen.ts, which every build bundles.
9
+ *
10
+ * The language is the one that SmarterChat's `language` prop asks for, or else the page's, from the lang attribute
11
+ * of its <html> element, which the web console sets to the console's language, or else the browser's. A language
12
+ * that Smarter Chat doesn't have falls back to its generic language (fr-CA to fr), and then to English.
13
+ * SmarterChat activates its language as it renders, so that the functions here, which every component and module
14
+ * calls, translate into it. A page with two chats in two languages therefore gets the language of the last one to
15
+ * render.
16
+ *
17
+ * Every message is English source text, and must be a string literal, so that `npm run i18n` can extract it.
18
+ * Interpolate values afterwards, with Python-style named placeholders, so that a translator can move them:
19
+ *
20
+ * @example
21
+ * gettext("Start a new chat");
22
+ * interpolate(gettext("%(assistant)s is typing"), { assistant });
23
+ * interpolate(ngettext("%(count)s tool", "%(count)s tools", n), { count: n });
24
+ * pgettext("button", "Code");
25
+ * // a React element inside a sentence:
26
+ * interpolateNodes(gettext("Delete %(name)s?"), { name: <strong>{name}</strong> });
27
+ *
28
+ * A comment that begins with "Translators:" on the line before a call is copied into the message catalogs, for the
29
+ * translator. Translate when the text is displayed, never in a module-level constant, which is evaluated once,
30
+ * before any language is activated.
31
+ */
32
+ import { type ReactNode } from "react";
33
+ /** The source language, which has no catalog. */
34
+ export declare const DEFAULT_LANGUAGE = "en";
35
+ /** The languages that Smarter Chat is translated into, including English. */
36
+ export declare const LANGUAGES: readonly string[];
37
+ type InterpolationValues = Record<string, string | number | null | undefined>;
38
+ /**
39
+ * The language of Smarter Chat that best matches a language tag, e.g. "fr" for "fr-CA", or null if it has none.
40
+ * The tag is case-insensitive, and may use "_" for "-", as Django's locale names do.
41
+ */
42
+ export declare function matchLanguage(tag: string | null | undefined): string | null;
43
+ /**
44
+ * The language to display: the requested one, if Smarter Chat has it, or else the page's (<html lang>), or else
45
+ * the browser's first one that it has, or else English.
46
+ */
47
+ export declare function resolveLanguage(requested?: string | null): string;
48
+ /** Translates from now on into the language that resolveLanguage() chooses for the request, and returns it. */
49
+ export declare function activateLanguage(requested?: string | null): string;
50
+ /** The active language. Until one is activated, the page's or the browser's. */
51
+ export declare function currentLanguage(): string;
52
+ /** Translates a message. */
53
+ export declare function gettext(msgid: string): string;
54
+ /** Translates a message that has a singular and a plural form, chosen by count. */
55
+ export declare function ngettext(singular: string, pluralText: string, count: number): string;
56
+ /** Translates a message in a context, which tells apart two messages with the same English text. */
57
+ export declare function pgettext(context: string, msgid: string): string;
58
+ /** ngettext() in a context. */
59
+ export declare function npgettext(context: string, singular: string, pluralText: string, count: number): string;
60
+ /**
61
+ * Replaces each %(name)s placeholder in a translated message with values[name].
62
+ * A placeholder with no value is left as it is, so that the mistake shows.
63
+ */
64
+ export declare function interpolate(message: string, values: InterpolationValues): string;
65
+ /**
66
+ * interpolate() for values that are React nodes, e.g. a name in <strong> inside a sentence. Returns a fragment of
67
+ * the message's text and the values, in the order that the (translated) message puts them.
68
+ */
69
+ export declare function interpolateNodes(message: string, values: Record<string, ReactNode>): ReactNode;
70
+ export {};
@@ -112,4 +112,10 @@ export interface SmarterChatProps {
112
112
  * Server-Sent Events. Servers that don't stream answer as before.
113
113
  */
114
114
  streamProgress?: boolean;
115
+ /**
116
+ * The language of the chat's own text, e.g. its buttons' labels, as a language tag: "en", "es" or "fr", or a
117
+ * regional variant of one, e.g. "es-MX", which gets its generic language. By default, the page's (the lang
118
+ * attribute of its <html> element), or else the browser's. Other languages get English.
119
+ */
120
+ language?: string | null;
115
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smarter.sh/ui-chat",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "chatbot React.js component for the https://smarter.sh declarative, plugin-based AI resource management platform.",
5
5
  "homepage": "https://smarter.sh",
6
6
  "type": "module",
@@ -58,6 +58,7 @@
58
58
  "build": "tsc -b && vite build",
59
59
  "build:lib": "vite build --mode lib && tsc -p tsconfig.lib.json",
60
60
  "contract:types": "node scripts/contract-types.mjs",
61
+ "i18n": "node scripts/i18n.mjs",
61
62
  "lint": "eslint --max-warnings=0 .",
62
63
  "preview": "vite preview",
63
64
  "storybook": "storybook dev -p 6006",