@webority/mobile-chat 0.122.0 → 0.125.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/README.md +39 -7
- package/lib/commonjs/components/ActionCard.js +1 -1
- package/lib/commonjs/components/ChatComposer.js +1 -1
- package/lib/commonjs/components/ChatConversationList.js +1 -1
- package/lib/commonjs/components/ChatLauncher.js +1 -1
- package/lib/commonjs/components/ChatMarkdown.js +1 -1
- package/lib/commonjs/components/ChatMessage.js +1 -1
- package/lib/commonjs/components/ChatScreen.js +1 -1
- package/lib/commonjs/components/ChatThread.js +1 -1
- package/lib/commonjs/components/ComposerAttachments.js +1 -0
- package/lib/commonjs/components/ReplyRating.js +1 -1
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/useChat.js +1 -1
- package/lib/module/components/ActionCard.js +1 -1
- package/lib/module/components/ChatComposer.js +1 -1
- package/lib/module/components/ChatConversationList.js +1 -1
- package/lib/module/components/ChatLauncher.js +1 -1
- package/lib/module/components/ChatMarkdown.js +1 -1
- package/lib/module/components/ChatMessage.js +1 -1
- package/lib/module/components/ChatScreen.js +1 -1
- package/lib/module/components/ChatThread.js +1 -1
- package/lib/module/components/ComposerAttachments.js +1 -0
- package/lib/module/components/ReplyRating.js +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/useChat.js +1 -1
- package/lib/typescript/commonjs/components/ActionCard.d.ts +2 -2
- package/lib/typescript/commonjs/components/ChatComposer.d.ts +12 -1
- package/lib/typescript/commonjs/components/ChatConversationList.d.ts +3 -4
- package/lib/typescript/commonjs/components/ChatLauncher.d.ts +1 -1
- package/lib/typescript/commonjs/components/ChatMarkdown.d.ts +8 -1
- package/lib/typescript/commonjs/components/ChatMessage.d.ts +23 -6
- package/lib/typescript/commonjs/components/ChatScreen.d.ts +7 -2
- package/lib/typescript/commonjs/components/ChatThread.d.ts +9 -1
- package/lib/typescript/commonjs/components/ComposerAttachments.d.ts +12 -0
- package/lib/typescript/commonjs/components/ReplyRating.d.ts +2 -2
- package/lib/typescript/commonjs/index.d.ts +2 -7
- package/lib/typescript/commonjs/useChat.d.ts +9 -53
- package/lib/typescript/module/components/ActionCard.d.ts +2 -2
- package/lib/typescript/module/components/ChatComposer.d.ts +12 -1
- package/lib/typescript/module/components/ChatConversationList.d.ts +3 -4
- package/lib/typescript/module/components/ChatLauncher.d.ts +1 -1
- package/lib/typescript/module/components/ChatMarkdown.d.ts +8 -1
- package/lib/typescript/module/components/ChatMessage.d.ts +23 -6
- package/lib/typescript/module/components/ChatScreen.d.ts +7 -2
- package/lib/typescript/module/components/ChatThread.d.ts +9 -1
- package/lib/typescript/module/components/ComposerAttachments.d.ts +12 -0
- package/lib/typescript/module/components/ReplyRating.d.ts +2 -2
- package/lib/typescript/module/index.d.ts +2 -7
- package/lib/typescript/module/useChat.d.ts +9 -53
- package/package.json +7 -6
- package/lib/commonjs/client.js +0 -1
- package/lib/commonjs/labels.js +0 -1
- package/lib/commonjs/sse.js +0 -1
- package/lib/commonjs/types.js +0 -1
- package/lib/module/client.js +0 -1
- package/lib/module/labels.js +0 -1
- package/lib/module/sse.js +0 -1
- package/lib/module/types.js +0 -1
- package/lib/typescript/commonjs/client.d.ts +0 -73
- package/lib/typescript/commonjs/labels.d.ts +0 -63
- package/lib/typescript/commonjs/sse.d.ts +0 -23
- package/lib/typescript/commonjs/types.d.ts +0 -71
- package/lib/typescript/module/client.d.ts +0 -73
- package/lib/typescript/module/labels.d.ts +0 -63
- package/lib/typescript/module/sse.d.ts +0 -23
- package/lib/typescript/module/types.d.ts +0 -71
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ChatAttachment, ChatRating, SupportActionTicket } from "@webority/markdown-core/chat";
|
|
2
|
+
import { type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
3
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels";
|
|
3
|
-
import type { ChatRating, SupportActionTicket } from "../types";
|
|
4
4
|
import type { ChatTurn } from "../useChat";
|
|
5
5
|
/** The props a thread passes to each of its turns. */
|
|
6
6
|
export interface ChatReplyProps<T = string> {
|
|
@@ -10,6 +10,12 @@ export interface ChatReplyProps<T = string> {
|
|
|
10
10
|
resolveLink?: (href: string) => T | null | undefined;
|
|
11
11
|
/** Opens what `resolveLink` returned. */
|
|
12
12
|
onLinkPress?: (target: T) => void;
|
|
13
|
+
/** Tells a citation marker in a reply from an ordinary link; see `ChatMarkdown`. */
|
|
14
|
+
isCitation?: (inner: string) => boolean;
|
|
15
|
+
/** Opens the citation a reply marker names; see `ChatMarkdown`. */
|
|
16
|
+
onOpenCitation?: (citation: string) => void;
|
|
17
|
+
/** Sends a suggested follow-up question; shows the suggestions under the last answer. */
|
|
18
|
+
onAskSuggestion?: (text: string) => void;
|
|
13
19
|
/** Shows support action cards; see `ActionCard`. */
|
|
14
20
|
confirmAction?: (token: string) => Promise<SupportActionTicket>;
|
|
15
21
|
onViewTicket?: (ticket: SupportActionTicket) => void;
|
|
@@ -20,19 +26,30 @@ export interface ChatReplyProps<T = string> {
|
|
|
20
26
|
renderReply?: (turn: ChatTurn, state: {
|
|
21
27
|
streaming: boolean;
|
|
22
28
|
}) => React.ReactNode;
|
|
29
|
+
/** Sends a failed or stopped question again; shows Try again under it. */
|
|
30
|
+
onRetry?: (turnId: string) => void;
|
|
31
|
+
/** Asks for a new answer to this turn; shows New answer under the answer when `canRegenerate` is set. */
|
|
32
|
+
onRegenerate?: (turnId: string) => void;
|
|
33
|
+
/** Puts this question back in the box to edit; shows Edit under the question. */
|
|
34
|
+
onEdit?: (turnId: string) => void;
|
|
35
|
+
/** Opens an attached file from its chip under the question. */
|
|
36
|
+
onOpenAttachment?: (attachment: ChatAttachment) => void;
|
|
23
37
|
labels?: Partial<ChatLabels>;
|
|
24
38
|
}
|
|
25
39
|
export interface ChatMessageProps<T = string> extends ChatReplyProps<T> {
|
|
26
40
|
turn: ChatTurn;
|
|
41
|
+
/** Set on the one turn a New answer is offered for, normally the last answered turn. */
|
|
42
|
+
canRegenerate?: boolean;
|
|
27
43
|
testID?: string;
|
|
28
44
|
}
|
|
29
45
|
/**
|
|
30
46
|
* One turn on mobile-ui's chat parts: the person's question in a `MessageBubble` on the trailing
|
|
31
|
-
* side,
|
|
32
|
-
*
|
|
33
|
-
*
|
|
47
|
+
* side, with its files, a stopped note and Try again or Edit under it; the typing dots and the
|
|
48
|
+
* tool step while the answer has not started, then the answer in a bubble on the leading side.
|
|
49
|
+
* The answer is announced once, when it finishes arriving. Support actions show under the answer,
|
|
50
|
+
* and the rating once the reply is stored.
|
|
34
51
|
*/
|
|
35
|
-
declare function ChatMessageView<T = string>({ turn, onRate, resolveLink, onLinkPress, confirmAction, onViewTicket, renderReply, labels: labelOverrides, testID, }: ChatMessageProps<T>): React.ReactElement;
|
|
52
|
+
declare function ChatMessageView<T = string>({ turn, canRegenerate, onRetry, onRegenerate, onEdit, onOpenAttachment, onRate, resolveLink, onLinkPress, isCitation, onOpenCitation, onAskSuggestion, confirmAction, onViewTicket, renderReply, labels: labelOverrides, testID, }: ChatMessageProps<T>): React.ReactElement;
|
|
36
53
|
export declare const ChatMessage: typeof ChatMessageView;
|
|
37
54
|
export {};
|
|
38
55
|
//# sourceMappingURL=ChatMessage.d.ts.map
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { type ChatAttachment, type ChatUploadFile } from "@webority/markdown-core/chat";
|
|
1
2
|
import type React from "react";
|
|
2
3
|
import type { UseChatResult } from "../useChat";
|
|
3
4
|
import type { ChatReplyProps } from "./ChatMessage";
|
|
4
|
-
export interface ChatScreenProps<T = string> extends Omit<ChatReplyProps<T>, "onRate"> {
|
|
5
|
+
export interface ChatScreenProps<T = string> extends Omit<ChatReplyProps<T>, "onRate" | "onAskSuggestion"> {
|
|
5
6
|
/** The `useChat` result. */
|
|
6
7
|
chat: UseChatResult;
|
|
8
|
+
/** Opens the file picker. The attach button shows only with this and the chat's attachment settings. */
|
|
9
|
+
pickAttachments?: () => Promise<ChatUploadFile[]>;
|
|
10
|
+
/** Opens an attachment shown in a message. */
|
|
11
|
+
onOpenAttachment?: (attachment: ChatAttachment) => void;
|
|
7
12
|
/** Header title. Defaults to the `panelTitle` label. */
|
|
8
13
|
title?: string;
|
|
9
14
|
/** Extra header controls before New chat, e.g. an "All chats" button. */
|
|
@@ -31,5 +36,5 @@ export interface ChatScreenProps<T = string> extends Omit<ChatReplyProps<T>, "on
|
|
|
31
36
|
* box rides the keyboard and the newest turn stays above it. Place it in a stack screen and keep
|
|
32
37
|
* the `useChat` call above the navigator, so the conversation survives leaving the screen.
|
|
33
38
|
*/
|
|
34
|
-
export declare function ChatScreen<T = string>({ chat, title, headerActions, empty, disclaimer, maxLength, allowanceThreshold, rating, keyboardOffset, testID, ...reply }: ChatScreenProps<T>): React.ReactElement;
|
|
39
|
+
export declare function ChatScreen<T = string>({ chat, pickAttachments, onOpenAttachment, title, headerActions, empty, disclaimer, maxLength, allowanceThreshold, rating, keyboardOffset, testID, ...reply }: ChatScreenProps<T>): React.ReactElement;
|
|
35
40
|
//# sourceMappingURL=ChatScreen.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ChatAttachment } from "@webority/markdown-core/chat";
|
|
1
2
|
import type React from "react";
|
|
2
3
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
3
4
|
import type { ChatTurn } from "../useChat";
|
|
@@ -10,6 +11,13 @@ export interface ChatThreadProps<T = string> extends ChatReplyProps<T> {
|
|
|
10
11
|
keyboardAware?: boolean;
|
|
11
12
|
/** The composer's `keyboardOffset`. Default: the bottom safe-area inset. */
|
|
12
13
|
keyboardOffset?: number;
|
|
14
|
+
/** Asks a failed or stopped turn's question again. */
|
|
15
|
+
onRetry?: (turnId: string) => void;
|
|
16
|
+
/** Asks for a new answer; offered on the last answered turn only. */
|
|
17
|
+
onRegenerate?: (turnId: string) => void;
|
|
18
|
+
/** Puts a question back in the box to be edited. */
|
|
19
|
+
onEdit?: (turnId: string) => void;
|
|
20
|
+
onOpenAttachment?: (attachment: ChatAttachment) => void;
|
|
13
21
|
style?: StyleProp<ViewStyle>;
|
|
14
22
|
testID?: string;
|
|
15
23
|
}
|
|
@@ -18,5 +26,5 @@ export interface ChatThreadProps<T = string> extends ChatReplyProps<T> {
|
|
|
18
26
|
* streaming answer growing in place, a jump to the latest once scrolled up,
|
|
19
27
|
* and the newest turn kept above the keyboard.
|
|
20
28
|
*/
|
|
21
|
-
export declare function ChatThread<T = string>({ turns, empty, keyboardAware, keyboardOffset, style, testID, ...reply }: ChatThreadProps<T>): React.ReactElement;
|
|
29
|
+
export declare function ChatThread<T = string>({ turns, empty, keyboardAware, keyboardOffset, onRetry, onRegenerate, onEdit, onOpenAttachment, onAskSuggestion, style, testID, ...reply }: ChatThreadProps<T>): React.ReactElement;
|
|
22
30
|
//# sourceMappingURL=ChatThread.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChatLabels, type ComposerAttachment } from "@webority/markdown-core/chat";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export interface ComposerAttachmentsProps {
|
|
4
|
+
attachments: ComposerAttachment[];
|
|
5
|
+
/** Omit to show the files without remove buttons. */
|
|
6
|
+
onRemove?: (key: string) => void;
|
|
7
|
+
labels?: Partial<ChatLabels>;
|
|
8
|
+
testID?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The files on the question being written: a chip per file, a progress bar while it uploads. */
|
|
11
|
+
export declare const ComposerAttachments: React.FC<ComposerAttachmentsProps>;
|
|
12
|
+
//# sourceMappingURL=ComposerAttachments.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ChatRating } from "@webority/markdown-core/chat";
|
|
2
|
+
import { type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
3
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels";
|
|
3
|
-
import type { ChatRating } from "../types";
|
|
4
4
|
export interface ReplyRatingProps {
|
|
5
5
|
/** The rating already saved. */
|
|
6
6
|
rating?: ChatRating | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { ChatClient, ChatHttpClient, ChatHttpRequestConfig } from "
|
|
2
|
-
export { ChatApiError, createChatClient } from "
|
|
1
|
+
export type { ChatAbortSignal, ChatAttachment, ChatAttachmentLimits, ChatBlob, ChatClient, ChatEditing, ChatHttpClient, ChatHttpRequestConfig, ChatLabels, ChatRating, ChatRatingInput, ChatSession, ChatSessionOptions, ChatSessionState, ChatSettings, ChatStreamEventName, ChatStreamOptions, ChatTurnInput, ChatTurnResult, ChatUploadFile, ComposerAttachment, ComposerAttachmentStatus, Conversation, ConversationList, ConversationListOptions, ConversationListState, ConversationMessage, ConversationSummary, FrameScheduler, PagedDataObject, SseEvent, SseParser, SupportAction, SupportActionTicket, } from "@webority/markdown-core/chat";
|
|
2
|
+
export { ChatApiError, createChatClient, createChatSession, createConversationList, createSseParser, DEFAULT_CHAT_LABELS, } from "@webority/markdown-core/chat";
|
|
3
3
|
export type { ActionCardProps } from "./components/ActionCard";
|
|
4
4
|
export { ActionCard } from "./components/ActionCard";
|
|
5
5
|
export type { ChatComposerProps } from "./components/ChatComposer";
|
|
@@ -18,11 +18,6 @@ export type { ChatThreadProps } from "./components/ChatThread";
|
|
|
18
18
|
export { ChatThread } from "./components/ChatThread";
|
|
19
19
|
export type { ReplyRatingProps } from "./components/ReplyRating";
|
|
20
20
|
export { ReplyRating } from "./components/ReplyRating";
|
|
21
|
-
export type { ChatLabels } from "./labels";
|
|
22
|
-
export { DEFAULT_CHAT_LABELS } from "./labels";
|
|
23
|
-
export type { SseEvent, SseParser } from "./sse";
|
|
24
|
-
export { createSseParser } from "./sse";
|
|
25
|
-
export type { ChatRating, ChatRatingInput, ChatStreamEventName, ChatStreamOptions, ChatTurnInput, ChatTurnResult, Conversation, ConversationMessage, ConversationSummary, SupportAction, SupportActionTicket, } from "./types";
|
|
26
21
|
export type { ChatTurn, ChatTurnError, UseChatOptions, UseChatResult } from "./useChat";
|
|
27
22
|
export { useChat } from "./useChat";
|
|
28
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,63 +1,19 @@
|
|
|
1
|
-
import type { ChatClient } from "
|
|
2
|
-
|
|
3
|
-
export interface ChatTurnError {
|
|
4
|
-
code: string;
|
|
5
|
-
/** Written for the person. */
|
|
6
|
-
message: string;
|
|
7
|
-
resetsAtUtc: string | null;
|
|
8
|
-
}
|
|
9
|
-
/** One question and its answer. */
|
|
10
|
-
export interface ChatTurn {
|
|
11
|
-
/** Local key; for a reopened conversation, the stored message's id. */
|
|
12
|
-
id: string;
|
|
13
|
-
question: string;
|
|
14
|
-
/** What is shown: the streamed text, then the reply of record. */
|
|
15
|
-
answer: string;
|
|
16
|
-
streaming: boolean;
|
|
17
|
-
error: ChatTurnError | null;
|
|
18
|
-
actions: SupportAction[];
|
|
19
|
-
/** The stored reply's id; rating needs it. */
|
|
20
|
-
messageId: string | null;
|
|
21
|
-
rating: ChatRating | null;
|
|
22
|
-
ratingNote: string | null;
|
|
23
|
-
}
|
|
1
|
+
import type { ChatClient, ChatSession, ChatSessionState } from "@webority/markdown-core/chat";
|
|
2
|
+
export type { ChatTurn, ChatTurnError } from "@webority/markdown-core/chat";
|
|
24
3
|
export interface UseChatOptions {
|
|
25
4
|
/** From `createChatClient`. */
|
|
26
5
|
client: ChatClient;
|
|
27
6
|
/** Sent with each question; read at the moment of sending. */
|
|
28
7
|
pageContext?: unknown;
|
|
29
8
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
conversationId: string | null;
|
|
35
|
-
/** From the last answer or `refreshAllowance()`; null with no daily limit. */
|
|
36
|
-
messagesLeftToday: number | null;
|
|
37
|
-
/** An answer is arriving. */
|
|
38
|
-
streaming: boolean;
|
|
39
|
-
/** `openConversation` is loading. */
|
|
40
|
-
loading: boolean;
|
|
41
|
-
/** `openConversation` failed. */
|
|
42
|
-
loadError: ChatTurnError | null;
|
|
43
|
-
/** Asks a question. Ignored while an answer is still arriving. */
|
|
44
|
-
submit: (message: string) => Promise<void>;
|
|
45
|
-
/** Replaces the thread with a stored conversation. */
|
|
46
|
-
openConversation: (id: string) => Promise<void>;
|
|
47
|
-
/** Clears the thread; the next question starts a conversation. */
|
|
48
|
-
newConversation: () => void;
|
|
49
|
-
/** Saves a rating, shown at once; a failed save puts the old one back and rejects. */
|
|
50
|
-
rate: (turnId: string, rating: ChatRating, note?: string) => Promise<void>;
|
|
51
|
-
/** Reads the questions left today. */
|
|
52
|
-
refreshAllowance: () => Promise<void>;
|
|
53
|
-
/** Clears everything, for sign-out or an account switch. */
|
|
54
|
-
reset: () => void;
|
|
55
|
-
}
|
|
9
|
+
type ChatActions = Pick<ChatSession, "submit" | "stop" | "retry" | "regenerate" | "startEdit" | "cancelEdit" | "attach" | "removeAttachment" | "openConversation" | "newConversation" | "rate" | "refreshAllowance" | "reset">;
|
|
10
|
+
export type UseChatResult = ChatSessionState & ChatActions & {
|
|
11
|
+
client: ChatClient;
|
|
12
|
+
};
|
|
56
13
|
/**
|
|
57
|
-
* The chat's state and actions
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* `openConversation` and unmount.
|
|
14
|
+
* The chat's state and actions. The session lives in the component that calls it: one per client,
|
|
15
|
+
* disposed when the client changes or the component unmounts. Call `reset()` when the signed-in
|
|
16
|
+
* person or account changes so nothing of one person's chat shows to the next.
|
|
61
17
|
*/
|
|
62
18
|
export declare const useChat: ({ client, pageContext }: UseChatOptions) => UseChatResult;
|
|
63
19
|
//# sourceMappingURL=useChat.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { SupportAction, SupportActionTicket } from "@webority/markdown-core/chat";
|
|
2
|
+
import { type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
3
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels.js";
|
|
3
|
-
import type { SupportAction, SupportActionTicket } from "../types.js";
|
|
4
4
|
export interface ActionCardProps {
|
|
5
5
|
action: SupportAction;
|
|
6
6
|
/**
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { type ChatEditing, type ChatLabels, type ComposerAttachment } from "@webority/markdown-core/chat";
|
|
1
2
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels.js";
|
|
3
3
|
export interface ChatComposerProps {
|
|
4
4
|
/** Called with the trimmed question; the box clears once it is handed over. */
|
|
5
5
|
onSubmit: (message: string) => unknown;
|
|
6
6
|
/** An answer is arriving: the question can be typed but not sent. */
|
|
7
7
|
busy?: boolean;
|
|
8
|
+
/** While busy, the send button becomes a stop button that calls this. */
|
|
9
|
+
onStop?: () => void;
|
|
8
10
|
/** No question can be asked, e.g. none left today. */
|
|
9
11
|
disabled?: boolean;
|
|
10
12
|
/** The server's message limit. Default 4000. */
|
|
@@ -19,6 +21,15 @@ export interface ChatComposerProps {
|
|
|
19
21
|
keyboardOffset?: number;
|
|
20
22
|
/** Pads for the bottom safe area. Default true. */
|
|
21
23
|
safeArea?: boolean;
|
|
24
|
+
/** The files on the question being written. */
|
|
25
|
+
attachments?: ComposerAttachment[];
|
|
26
|
+
/** Opens the app's file picker. The attach button shows only when this is given. */
|
|
27
|
+
onAttach?: () => void;
|
|
28
|
+
/** Removes one file by its key. */
|
|
29
|
+
onRemoveAttachment?: (key: string) => void;
|
|
30
|
+
/** The question being edited; its banner's Cancel calls `onCancelEdit`. */
|
|
31
|
+
editing?: ChatEditing | null;
|
|
32
|
+
onCancelEdit?: () => void;
|
|
22
33
|
labels?: Partial<ChatLabels>;
|
|
23
34
|
testID?: string;
|
|
24
35
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import type { ConversationSummary } from "@webority/markdown-core/chat";
|
|
2
|
+
import { type ChatClient, type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
3
|
import type React from "react";
|
|
2
4
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
3
|
-
import type { ChatClient } from "../client.js";
|
|
4
|
-
import { type ChatLabels } from "../labels.js";
|
|
5
|
-
import type { ConversationSummary } from "../types.js";
|
|
6
5
|
export interface ChatConversationListProps {
|
|
7
6
|
client: ChatClient;
|
|
8
7
|
/** E.g. go to the chat and call `chat.openConversation(conversation.publicId)`. */
|
|
@@ -17,7 +16,7 @@ export interface ChatConversationListProps {
|
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
19
18
|
* The person's past chats, newest first. It pages with Show more, refreshes on pull, opens one
|
|
20
|
-
* through `onOpen`, and deletes one after a confirm.
|
|
19
|
+
* through `onOpen`, renames and deletes one after a confirm.
|
|
21
20
|
*/
|
|
22
21
|
export declare const ChatConversationList: React.FC<ChatConversationListProps>;
|
|
23
22
|
//# sourceMappingURL=ChatConversationList.d.ts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
2
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels.js";
|
|
3
3
|
export interface ChatLauncherProps {
|
|
4
4
|
onPress: () => void;
|
|
5
5
|
/** `end` (the default) or `start`: the bottom corner it sits in. */
|
|
@@ -10,8 +10,15 @@ export interface ChatMarkdownProps<T = string> {
|
|
|
10
10
|
resolveLink?: (href: string) => T | null | undefined;
|
|
11
11
|
/** Opens what `resolveLink` returned. Without it, links show as plain text. */
|
|
12
12
|
onLinkPress?: (target: T) => void;
|
|
13
|
+
/**
|
|
14
|
+
* Tells a citation marker (the bracketed inner text, e.g. `1` for `[1]`) from an ordinary link.
|
|
15
|
+
* A citation draws as a pressable marker and never as a link.
|
|
16
|
+
*/
|
|
17
|
+
isCitation?: (inner: string) => boolean;
|
|
18
|
+
/** Opens the citation a reply marker names. Without it, citation markers show as plain text. */
|
|
19
|
+
onOpenCitation?: (citation: string) => void;
|
|
13
20
|
testID?: string;
|
|
14
21
|
}
|
|
15
22
|
/** A reply never opens a web address, and its headings draw as bold lines, not large type. */
|
|
16
|
-
export declare function ChatMarkdown<T = string>({ text, resolveLink, onLinkPress, testID }: ChatMarkdownProps<T>): React.ReactElement;
|
|
23
|
+
export declare function ChatMarkdown<T = string>({ text, resolveLink, onLinkPress, isCitation, onOpenCitation, testID, }: ChatMarkdownProps<T>): React.ReactElement;
|
|
17
24
|
//# sourceMappingURL=ChatMarkdown.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ChatAttachment, ChatRating, SupportActionTicket } from "@webority/markdown-core/chat";
|
|
2
|
+
import { type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
3
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels.js";
|
|
3
|
-
import type { ChatRating, SupportActionTicket } from "../types.js";
|
|
4
4
|
import type { ChatTurn } from "../useChat.js";
|
|
5
5
|
/** The props a thread passes to each of its turns. */
|
|
6
6
|
export interface ChatReplyProps<T = string> {
|
|
@@ -10,6 +10,12 @@ export interface ChatReplyProps<T = string> {
|
|
|
10
10
|
resolveLink?: (href: string) => T | null | undefined;
|
|
11
11
|
/** Opens what `resolveLink` returned. */
|
|
12
12
|
onLinkPress?: (target: T) => void;
|
|
13
|
+
/** Tells a citation marker in a reply from an ordinary link; see `ChatMarkdown`. */
|
|
14
|
+
isCitation?: (inner: string) => boolean;
|
|
15
|
+
/** Opens the citation a reply marker names; see `ChatMarkdown`. */
|
|
16
|
+
onOpenCitation?: (citation: string) => void;
|
|
17
|
+
/** Sends a suggested follow-up question; shows the suggestions under the last answer. */
|
|
18
|
+
onAskSuggestion?: (text: string) => void;
|
|
13
19
|
/** Shows support action cards; see `ActionCard`. */
|
|
14
20
|
confirmAction?: (token: string) => Promise<SupportActionTicket>;
|
|
15
21
|
onViewTicket?: (ticket: SupportActionTicket) => void;
|
|
@@ -20,19 +26,30 @@ export interface ChatReplyProps<T = string> {
|
|
|
20
26
|
renderReply?: (turn: ChatTurn, state: {
|
|
21
27
|
streaming: boolean;
|
|
22
28
|
}) => React.ReactNode;
|
|
29
|
+
/** Sends a failed or stopped question again; shows Try again under it. */
|
|
30
|
+
onRetry?: (turnId: string) => void;
|
|
31
|
+
/** Asks for a new answer to this turn; shows New answer under the answer when `canRegenerate` is set. */
|
|
32
|
+
onRegenerate?: (turnId: string) => void;
|
|
33
|
+
/** Puts this question back in the box to edit; shows Edit under the question. */
|
|
34
|
+
onEdit?: (turnId: string) => void;
|
|
35
|
+
/** Opens an attached file from its chip under the question. */
|
|
36
|
+
onOpenAttachment?: (attachment: ChatAttachment) => void;
|
|
23
37
|
labels?: Partial<ChatLabels>;
|
|
24
38
|
}
|
|
25
39
|
export interface ChatMessageProps<T = string> extends ChatReplyProps<T> {
|
|
26
40
|
turn: ChatTurn;
|
|
41
|
+
/** Set on the one turn a New answer is offered for, normally the last answered turn. */
|
|
42
|
+
canRegenerate?: boolean;
|
|
27
43
|
testID?: string;
|
|
28
44
|
}
|
|
29
45
|
/**
|
|
30
46
|
* One turn on mobile-ui's chat parts: the person's question in a `MessageBubble` on the trailing
|
|
31
|
-
* side,
|
|
32
|
-
*
|
|
33
|
-
*
|
|
47
|
+
* side, with its files, a stopped note and Try again or Edit under it; the typing dots and the
|
|
48
|
+
* tool step while the answer has not started, then the answer in a bubble on the leading side.
|
|
49
|
+
* The answer is announced once, when it finishes arriving. Support actions show under the answer,
|
|
50
|
+
* and the rating once the reply is stored.
|
|
34
51
|
*/
|
|
35
|
-
declare function ChatMessageView<T = string>({ turn, onRate, resolveLink, onLinkPress, confirmAction, onViewTicket, renderReply, labels: labelOverrides, testID, }: ChatMessageProps<T>): React.ReactElement;
|
|
52
|
+
declare function ChatMessageView<T = string>({ turn, canRegenerate, onRetry, onRegenerate, onEdit, onOpenAttachment, onRate, resolveLink, onLinkPress, isCitation, onOpenCitation, onAskSuggestion, confirmAction, onViewTicket, renderReply, labels: labelOverrides, testID, }: ChatMessageProps<T>): React.ReactElement;
|
|
36
53
|
export declare const ChatMessage: typeof ChatMessageView;
|
|
37
54
|
export {};
|
|
38
55
|
//# sourceMappingURL=ChatMessage.d.ts.map
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import { type ChatAttachment, type ChatUploadFile } from "@webority/markdown-core/chat";
|
|
1
2
|
import type React from "react";
|
|
2
3
|
import type { UseChatResult } from "../useChat.js";
|
|
3
4
|
import type { ChatReplyProps } from "./ChatMessage.js";
|
|
4
|
-
export interface ChatScreenProps<T = string> extends Omit<ChatReplyProps<T>, "onRate"> {
|
|
5
|
+
export interface ChatScreenProps<T = string> extends Omit<ChatReplyProps<T>, "onRate" | "onAskSuggestion"> {
|
|
5
6
|
/** The `useChat` result. */
|
|
6
7
|
chat: UseChatResult;
|
|
8
|
+
/** Opens the file picker. The attach button shows only with this and the chat's attachment settings. */
|
|
9
|
+
pickAttachments?: () => Promise<ChatUploadFile[]>;
|
|
10
|
+
/** Opens an attachment shown in a message. */
|
|
11
|
+
onOpenAttachment?: (attachment: ChatAttachment) => void;
|
|
7
12
|
/** Header title. Defaults to the `panelTitle` label. */
|
|
8
13
|
title?: string;
|
|
9
14
|
/** Extra header controls before New chat, e.g. an "All chats" button. */
|
|
@@ -31,5 +36,5 @@ export interface ChatScreenProps<T = string> extends Omit<ChatReplyProps<T>, "on
|
|
|
31
36
|
* box rides the keyboard and the newest turn stays above it. Place it in a stack screen and keep
|
|
32
37
|
* the `useChat` call above the navigator, so the conversation survives leaving the screen.
|
|
33
38
|
*/
|
|
34
|
-
export declare function ChatScreen<T = string>({ chat, title, headerActions, empty, disclaimer, maxLength, allowanceThreshold, rating, keyboardOffset, testID, ...reply }: ChatScreenProps<T>): React.ReactElement;
|
|
39
|
+
export declare function ChatScreen<T = string>({ chat, pickAttachments, onOpenAttachment, title, headerActions, empty, disclaimer, maxLength, allowanceThreshold, rating, keyboardOffset, testID, ...reply }: ChatScreenProps<T>): React.ReactElement;
|
|
35
40
|
//# sourceMappingURL=ChatScreen.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ChatAttachment } from "@webority/markdown-core/chat";
|
|
1
2
|
import type React from "react";
|
|
2
3
|
import { type StyleProp, type ViewStyle } from "react-native";
|
|
3
4
|
import type { ChatTurn } from "../useChat.js";
|
|
@@ -10,6 +11,13 @@ export interface ChatThreadProps<T = string> extends ChatReplyProps<T> {
|
|
|
10
11
|
keyboardAware?: boolean;
|
|
11
12
|
/** The composer's `keyboardOffset`. Default: the bottom safe-area inset. */
|
|
12
13
|
keyboardOffset?: number;
|
|
14
|
+
/** Asks a failed or stopped turn's question again. */
|
|
15
|
+
onRetry?: (turnId: string) => void;
|
|
16
|
+
/** Asks for a new answer; offered on the last answered turn only. */
|
|
17
|
+
onRegenerate?: (turnId: string) => void;
|
|
18
|
+
/** Puts a question back in the box to be edited. */
|
|
19
|
+
onEdit?: (turnId: string) => void;
|
|
20
|
+
onOpenAttachment?: (attachment: ChatAttachment) => void;
|
|
13
21
|
style?: StyleProp<ViewStyle>;
|
|
14
22
|
testID?: string;
|
|
15
23
|
}
|
|
@@ -18,5 +26,5 @@ export interface ChatThreadProps<T = string> extends ChatReplyProps<T> {
|
|
|
18
26
|
* streaming answer growing in place, a jump to the latest once scrolled up,
|
|
19
27
|
* and the newest turn kept above the keyboard.
|
|
20
28
|
*/
|
|
21
|
-
export declare function ChatThread<T = string>({ turns, empty, keyboardAware, keyboardOffset, style, testID, ...reply }: ChatThreadProps<T>): React.ReactElement;
|
|
29
|
+
export declare function ChatThread<T = string>({ turns, empty, keyboardAware, keyboardOffset, onRetry, onRegenerate, onEdit, onOpenAttachment, onAskSuggestion, style, testID, ...reply }: ChatThreadProps<T>): React.ReactElement;
|
|
22
30
|
//# sourceMappingURL=ChatThread.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ChatLabels, type ComposerAttachment } from "@webority/markdown-core/chat";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export interface ComposerAttachmentsProps {
|
|
4
|
+
attachments: ComposerAttachment[];
|
|
5
|
+
/** Omit to show the files without remove buttons. */
|
|
6
|
+
onRemove?: (key: string) => void;
|
|
7
|
+
labels?: Partial<ChatLabels>;
|
|
8
|
+
testID?: string;
|
|
9
|
+
}
|
|
10
|
+
/** The files on the question being written: a chip per file, a progress bar while it uploads. */
|
|
11
|
+
export declare const ComposerAttachments: React.FC<ComposerAttachmentsProps>;
|
|
12
|
+
//# sourceMappingURL=ComposerAttachments.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ChatRating } from "@webority/markdown-core/chat";
|
|
2
|
+
import { type ChatLabels } from "@webority/markdown-core/chat";
|
|
1
3
|
import type React from "react";
|
|
2
|
-
import { type ChatLabels } from "../labels.js";
|
|
3
|
-
import type { ChatRating } from "../types.js";
|
|
4
4
|
export interface ReplyRatingProps {
|
|
5
5
|
/** The rating already saved. */
|
|
6
6
|
rating?: ChatRating | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type { ChatClient, ChatHttpClient, ChatHttpRequestConfig } from "
|
|
2
|
-
export { ChatApiError, createChatClient } from "
|
|
1
|
+
export type { ChatAbortSignal, ChatAttachment, ChatAttachmentLimits, ChatBlob, ChatClient, ChatEditing, ChatHttpClient, ChatHttpRequestConfig, ChatLabels, ChatRating, ChatRatingInput, ChatSession, ChatSessionOptions, ChatSessionState, ChatSettings, ChatStreamEventName, ChatStreamOptions, ChatTurnInput, ChatTurnResult, ChatUploadFile, ComposerAttachment, ComposerAttachmentStatus, Conversation, ConversationList, ConversationListOptions, ConversationListState, ConversationMessage, ConversationSummary, FrameScheduler, PagedDataObject, SseEvent, SseParser, SupportAction, SupportActionTicket, } from "@webority/markdown-core/chat";
|
|
2
|
+
export { ChatApiError, createChatClient, createChatSession, createConversationList, createSseParser, DEFAULT_CHAT_LABELS, } from "@webority/markdown-core/chat";
|
|
3
3
|
export type { ActionCardProps } from "./components/ActionCard.js";
|
|
4
4
|
export { ActionCard } from "./components/ActionCard.js";
|
|
5
5
|
export type { ChatComposerProps } from "./components/ChatComposer.js";
|
|
@@ -18,11 +18,6 @@ export type { ChatThreadProps } from "./components/ChatThread.js";
|
|
|
18
18
|
export { ChatThread } from "./components/ChatThread.js";
|
|
19
19
|
export type { ReplyRatingProps } from "./components/ReplyRating.js";
|
|
20
20
|
export { ReplyRating } from "./components/ReplyRating.js";
|
|
21
|
-
export type { ChatLabels } from "./labels.js";
|
|
22
|
-
export { DEFAULT_CHAT_LABELS } from "./labels.js";
|
|
23
|
-
export type { SseEvent, SseParser } from "./sse.js";
|
|
24
|
-
export { createSseParser } from "./sse.js";
|
|
25
|
-
export type { ChatRating, ChatRatingInput, ChatStreamEventName, ChatStreamOptions, ChatTurnInput, ChatTurnResult, Conversation, ConversationMessage, ConversationSummary, SupportAction, SupportActionTicket, } from "./types.js";
|
|
26
21
|
export type { ChatTurn, ChatTurnError, UseChatOptions, UseChatResult } from "./useChat.js";
|
|
27
22
|
export { useChat } from "./useChat.js";
|
|
28
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,63 +1,19 @@
|
|
|
1
|
-
import type { ChatClient } from "
|
|
2
|
-
|
|
3
|
-
export interface ChatTurnError {
|
|
4
|
-
code: string;
|
|
5
|
-
/** Written for the person. */
|
|
6
|
-
message: string;
|
|
7
|
-
resetsAtUtc: string | null;
|
|
8
|
-
}
|
|
9
|
-
/** One question and its answer. */
|
|
10
|
-
export interface ChatTurn {
|
|
11
|
-
/** Local key; for a reopened conversation, the stored message's id. */
|
|
12
|
-
id: string;
|
|
13
|
-
question: string;
|
|
14
|
-
/** What is shown: the streamed text, then the reply of record. */
|
|
15
|
-
answer: string;
|
|
16
|
-
streaming: boolean;
|
|
17
|
-
error: ChatTurnError | null;
|
|
18
|
-
actions: SupportAction[];
|
|
19
|
-
/** The stored reply's id; rating needs it. */
|
|
20
|
-
messageId: string | null;
|
|
21
|
-
rating: ChatRating | null;
|
|
22
|
-
ratingNote: string | null;
|
|
23
|
-
}
|
|
1
|
+
import type { ChatClient, ChatSession, ChatSessionState } from "@webority/markdown-core/chat";
|
|
2
|
+
export type { ChatTurn, ChatTurnError } from "@webority/markdown-core/chat";
|
|
24
3
|
export interface UseChatOptions {
|
|
25
4
|
/** From `createChatClient`. */
|
|
26
5
|
client: ChatClient;
|
|
27
6
|
/** Sent with each question; read at the moment of sending. */
|
|
28
7
|
pageContext?: unknown;
|
|
29
8
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
conversationId: string | null;
|
|
35
|
-
/** From the last answer or `refreshAllowance()`; null with no daily limit. */
|
|
36
|
-
messagesLeftToday: number | null;
|
|
37
|
-
/** An answer is arriving. */
|
|
38
|
-
streaming: boolean;
|
|
39
|
-
/** `openConversation` is loading. */
|
|
40
|
-
loading: boolean;
|
|
41
|
-
/** `openConversation` failed. */
|
|
42
|
-
loadError: ChatTurnError | null;
|
|
43
|
-
/** Asks a question. Ignored while an answer is still arriving. */
|
|
44
|
-
submit: (message: string) => Promise<void>;
|
|
45
|
-
/** Replaces the thread with a stored conversation. */
|
|
46
|
-
openConversation: (id: string) => Promise<void>;
|
|
47
|
-
/** Clears the thread; the next question starts a conversation. */
|
|
48
|
-
newConversation: () => void;
|
|
49
|
-
/** Saves a rating, shown at once; a failed save puts the old one back and rejects. */
|
|
50
|
-
rate: (turnId: string, rating: ChatRating, note?: string) => Promise<void>;
|
|
51
|
-
/** Reads the questions left today. */
|
|
52
|
-
refreshAllowance: () => Promise<void>;
|
|
53
|
-
/** Clears everything, for sign-out or an account switch. */
|
|
54
|
-
reset: () => void;
|
|
55
|
-
}
|
|
9
|
+
type ChatActions = Pick<ChatSession, "submit" | "stop" | "retry" | "regenerate" | "startEdit" | "cancelEdit" | "attach" | "removeAttachment" | "openConversation" | "newConversation" | "rate" | "refreshAllowance" | "reset">;
|
|
10
|
+
export type UseChatResult = ChatSessionState & ChatActions & {
|
|
11
|
+
client: ChatClient;
|
|
12
|
+
};
|
|
56
13
|
/**
|
|
57
|
-
* The chat's state and actions
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* `openConversation` and unmount.
|
|
14
|
+
* The chat's state and actions. The session lives in the component that calls it: one per client,
|
|
15
|
+
* disposed when the client changes or the component unmounts. Call `reset()` when the signed-in
|
|
16
|
+
* person or account changes so nothing of one person's chat shows to the next.
|
|
61
17
|
*/
|
|
62
18
|
export declare const useChat: ({ client, pageContext }: UseChatOptions) => UseChatResult;
|
|
63
19
|
//# sourceMappingURL=useChat.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.125.0",
|
|
4
4
|
"description": "AI assistant chat for Webority React Native apps: a streaming chat client, a store-agnostic chat hook, and the chat screen, thread, composer, past chats, reply rating and support action cards, built on @webority/mobile-ui.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"!**/*.map"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@webority/markdown-core": "0.
|
|
45
|
+
"@webority/markdown-core": "0.125.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@webority/mobile-core": "0.
|
|
49
|
-
"@webority/mobile-ui": "0.
|
|
48
|
+
"@webority/mobile-core": "0.125.0",
|
|
49
|
+
"@webority/mobile-ui": "0.125.0",
|
|
50
|
+
"expo-clipboard": ">=57.0.0",
|
|
50
51
|
"react": "^19.1.0",
|
|
51
52
|
"react-native": ">=0.81.0",
|
|
52
53
|
"react-native-keyboard-controller": ">=1.21.9",
|
|
@@ -87,9 +88,9 @@
|
|
|
87
88
|
"@react-native/metro-config": "0.86.3",
|
|
88
89
|
"@testing-library/react-native": "12.9.0",
|
|
89
90
|
"@types/react": "19.2.18",
|
|
90
|
-
"@webority/mobile-core": "0.
|
|
91
|
+
"@webority/mobile-core": "0.125.0",
|
|
91
92
|
"@webority/mobile-dev": "0.0.0",
|
|
92
|
-
"@webority/mobile-ui": "0.
|
|
93
|
+
"@webority/mobile-ui": "0.125.0",
|
|
93
94
|
"jest": "29.7.0",
|
|
94
95
|
"react": "19.2.8",
|
|
95
96
|
"react-native": "0.86.3",
|
package/lib/commonjs/client.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createChatClient=exports.ChatApiError=void 0;var _sse=require("./sse.js");const FALLBACK_MESSAGE="Something went wrong. Please try again.";class ChatApiError extends Error{constructor(e,t,r,s=null){super(t),this.name="ChatApiError",this.code=e,this.status=r,this.resetsAtUtc=s}}exports.ChatApiError=ChatApiError;const parseBody=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch{return null}return e??null},isCancel=(e,t)=>Boolean(t?.aborted)||"ERR_CANCELED"===e?.code||"CanceledError"===e?.name||"AbortError"===e?.name,toChatApiError=(e,t)=>{if(e instanceof ChatApiError)return e;const r=e;if(isCancel(r,t))return new ChatApiError("aborted","The request was cancelled.");const s=r?.response;if(!s)return new ChatApiError("network",FALLBACK_MESSAGE);const n=parseBody(s.data),a="string"==typeof n?.code&&n.code?n.code:"unknown",o="string"==typeof n?.message&&n.message?n.message:FALLBACK_MESSAGE,i="string"==typeof n?.resetsAtUtc?n.resetsAtUtc:null,c="number"==typeof s.status?s.status:void 0;return new ChatApiError(a,o,c,i)},call=async e=>{try{return(await e()).data}catch(e){throw toChatApiError(e)}},receivedText=e=>{const t=e?.event,r=t?.target;if(r&&"string"==typeof r.responseText&&("number"!=typeof r.status||!(r.status<200||r.status>=300)))return r.responseText},createChatClient=(e,{base:t})=>{if("string"!=typeof t||""===t.trim())throw new TypeError('createChatClient needs a base path, e.g. { base: "/api/assistant" }.');const r=t.replace(/\/+$/,""),conversationUrl=e=>`${r}/conversations/${encodeURIComponent(e)}`;return{sendMessage:async({message:t,conversationId:s,pageContext:n},{signal:a,onEvent:o}={})=>{let i=null,c=null;const l=(0,_sse.createSseParser)(({name:e,data:t})=>{i||c||("done"===e?i=t:"error"===e?c=t??{}:"delta"!==e&&"reset"!==e&&"actions"!==e||o?.(e,t))});let p=0;const read=e=>{"string"!=typeof e||e.length<=p||(l.push(e.slice(p)),p=e.length)},u={message:t};let h;s&&(u.conversationId=s),null!=n&&(u.pageContext=n);try{h=await e.post(`${r}/chat`,u,{responseType:"text",headers:{Accept:"text/event-stream"},signal:a,onDownloadProgress:e=>read(receivedText(e))})}catch(e){throw toChatApiError(e,a)}read(h.data),l.end();const C=c;if(C)throw new ChatApiError(C.code||"unknown",C.message||FALLBACK_MESSAGE);const g=i;if(!g)throw new ChatApiError("invalid-response",FALLBACK_MESSAGE,h.status);return g},getAllowance:()=>call(()=>e.get(`${r}/allowance`)),listConversations:({skip:t,take:s}={})=>{const n=[];return null!=t&&n.push(`skip=${t}`),null!=s&&n.push(`take=${s}`),call(()=>e.get(`${r}/conversations${n.length?`?${n.join("&")}`:""}`))},getConversation:t=>call(()=>e.get(conversationUrl(t))),deleteConversation:async t=>{await call(()=>e.delete(conversationUrl(t)))},rateMessage:async(t,r,{rating:s,note:n})=>{const a="string"==typeof n?n.trim():"";await call(()=>e.put(`${conversationUrl(t)}/messages/${encodeURIComponent(r)}/rating`,{rating:s,note:a||null}))}}};exports.createChatClient=createChatClient;
|
package/lib/commonjs/labels.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeLabels=exports.DEFAULT_CHAT_LABELS=void 0;const DEFAULT_CHAT_LABELS=exports.DEFAULT_CHAT_LABELS=Object.freeze({launcher:"Ask the assistant",panelTitle:"Assistant",newChat:"New chat",close:"Close",thread:"Conversation",you:"You",assistant:"Assistant",thinking:"Thinking",emptyTitle:"How can I help?",emptyText:"Ask a question about what you see on this page.",composer:"Your question",placeholder:"Ask a question",send:"Send",composerHint:"Press Enter to send, Shift and Enter for a new line.",allowance:e=>0===e?"You have no questions left today.":1===e?"You have 1 question left today.":`You have ${e} questions left today.`,disclaimer:"Answers are written by AI and can be wrong. Check anything important.",loadingConversation:"Loading the conversation",rateUp:"Helpful",rateDown:"Not helpful",rated:"Thanks for the feedback.",ratingNote:"What was wrong with this answer?",ratingNoteHint:"Optional.",ratingNoteSend:"Send",ratingNoteSkip:"Skip",ratingFailed:"Your rating did not save. Please try again.",actionRaiseTicket:"New support ticket",actionReply:e=>`Reply on ${e}`,actionReopen:e=>`Reopen ${e}`,actionNote:"Nothing is sent until you confirm.",actionConfirm:"Confirm",actionDismiss:"Not now",actionDismissed:"Not sent.",actionExpired:"This request expired and was not sent. Ask again if you still need it.",actionFailed:"We could not send this. Please try again.",actionDoneRaiseTicket:e=>`Ticket ${e} raised.`,actionDoneReply:e=>`Your reply was added to ${e}.`,actionDoneReopen:e=>`${e} is open again.`,viewTicket:"View ticket",conversations:"Past chats",conversationsEmptyTitle:"No past chats",conversationsEmptyText:"Your conversations with the assistant show here.",untitled:"Untitled chat",deleteConversation:"Delete chat",deleteConfirmTitle:"Delete this chat?",deleteConfirmMessage:"The conversation is removed for good.",deleteConfirm:"Delete",deleteFailed:"We could not delete this chat. Please try again.",cancel:"Cancel",loadMore:"Show more",loadFailed:"We could not load your chats. Please try again.",retry:"Try again"}),mergeLabels=e=>e?{...DEFAULT_CHAT_LABELS,...e}:DEFAULT_CHAT_LABELS;exports.mergeLabels=mergeLabels;
|
package/lib/commonjs/sse.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createSseParser=void 0;const createSseParser=e=>{let t="";const dispatch=t=>{let r="message";const s=[];for(const e of t.split("\n")){if(""===e||e.startsWith(":"))continue;const t=e.indexOf(":"),n=-1===t?e:e.slice(0,t);let a=-1===t?"":e.slice(t+1);a.startsWith(" ")&&(a=a.slice(1)),"event"===n?r=a:"data"===n&&s.push(a)}if(0===s.length)return;let n;try{n=JSON.parse(s.join("\n"))}catch{return void e({name:"error",data:{code:"invalid-response",message:null}})}e({name:r,data:n})};return{push(e){if(!e)return;t=(t+e).replace(/\r\n/g,"\n").replace(/\r(?!$)/g,"\n");const r=t.split("\n\n");t=r.pop()??"";for(const e of r)dispatch(e)},end(){const e=t.replace(/\r$/,"");t="",e.trim()&&dispatch(e)}}};exports.createSseParser=createSseParser;
|
package/lib/commonjs/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
package/lib/module/client.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";import{createSseParser}from"./sse.js";const FALLBACK_MESSAGE="Something went wrong. Please try again.";export class ChatApiError extends Error{constructor(e,t,r,s=null){super(t),this.name="ChatApiError",this.code=e,this.status=r,this.resetsAtUtc=s}}const parseBody=e=>{if("string"==typeof e)try{return JSON.parse(e)}catch{return null}return e??null},isCancel=(e,t)=>Boolean(t?.aborted)||"ERR_CANCELED"===e?.code||"CanceledError"===e?.name||"AbortError"===e?.name,toChatApiError=(e,t)=>{if(e instanceof ChatApiError)return e;const r=e;if(isCancel(r,t))return new ChatApiError("aborted","The request was cancelled.");const s=r?.response;if(!s)return new ChatApiError("network",FALLBACK_MESSAGE);const n=parseBody(s.data),a="string"==typeof n?.code&&n.code?n.code:"unknown",o="string"==typeof n?.message&&n.message?n.message:FALLBACK_MESSAGE,i="string"==typeof n?.resetsAtUtc?n.resetsAtUtc:null,c="number"==typeof s.status?s.status:void 0;return new ChatApiError(a,o,c,i)},call=async e=>{try{return(await e()).data}catch(e){throw toChatApiError(e)}},receivedText=e=>{const t=e?.event,r=t?.target;if(r&&"string"==typeof r.responseText&&("number"!=typeof r.status||!(r.status<200||r.status>=300)))return r.responseText};export const createChatClient=(e,{base:t})=>{if("string"!=typeof t||""===t.trim())throw new TypeError('createChatClient needs a base path, e.g. { base: "/api/assistant" }.');const r=t.replace(/\/+$/,""),conversationUrl=e=>`${r}/conversations/${encodeURIComponent(e)}`;return{sendMessage:async({message:t,conversationId:s,pageContext:n},{signal:a,onEvent:o}={})=>{let i=null,c=null;const l=createSseParser(({name:e,data:t})=>{i||c||("done"===e?i=t:"error"===e?c=t??{}:"delta"!==e&&"reset"!==e&&"actions"!==e||o?.(e,t))});let p=0;const read=e=>{"string"!=typeof e||e.length<=p||(l.push(e.slice(p)),p=e.length)},u={message:t};let g;s&&(u.conversationId=s),null!=n&&(u.pageContext=n);try{g=await e.post(`${r}/chat`,u,{responseType:"text",headers:{Accept:"text/event-stream"},signal:a,onDownloadProgress:e=>read(receivedText(e))})}catch(e){throw toChatApiError(e,a)}read(g.data),l.end();const h=c;if(h)throw new ChatApiError(h.code||"unknown",h.message||FALLBACK_MESSAGE);const d=i;if(!d)throw new ChatApiError("invalid-response",FALLBACK_MESSAGE,g.status);return d},getAllowance:()=>call(()=>e.get(`${r}/allowance`)),listConversations:({skip:t,take:s}={})=>{const n=[];return null!=t&&n.push(`skip=${t}`),null!=s&&n.push(`take=${s}`),call(()=>e.get(`${r}/conversations${n.length?`?${n.join("&")}`:""}`))},getConversation:t=>call(()=>e.get(conversationUrl(t))),deleteConversation:async t=>{await call(()=>e.delete(conversationUrl(t)))},rateMessage:async(t,r,{rating:s,note:n})=>{const a="string"==typeof n?n.trim():"";await call(()=>e.put(`${conversationUrl(t)}/messages/${encodeURIComponent(r)}/rating`,{rating:s,note:a||null}))}}};
|