@vinaverse/react-native 0.1.0-alpha.10 → 0.1.0-alpha.11
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 +25 -1
- package/dist/chat.cjs +118 -117
- package/dist/chat.d.cts +7 -205
- package/dist/chat.d.ts +7 -205
- package/dist/chat.js +2 -1
- package/dist/chunk-2J2LIJLW.js +624 -0
- package/dist/chunk-2J2LIJLW.js.map +1 -0
- package/dist/chunk-4PXQ7DEY.cjs +680 -0
- package/dist/chunk-4PXQ7DEY.cjs.map +1 -0
- package/dist/{chunk-43I4ZAEK.js → chunk-KSHDF3MG.js} +13 -624
- package/dist/chunk-KSHDF3MG.js.map +1 -0
- package/dist/{chunk-NRYNK7E4.cjs → chunk-XAG2P447.cjs} +11 -675
- package/dist/chunk-XAG2P447.cjs.map +1 -0
- package/dist/context-gHCLFsJh.d.cts +212 -0
- package/dist/context-gHCLFsJh.d.ts +212 -0
- package/dist/history.cjs +673 -0
- package/dist/history.cjs.map +1 -0
- package/dist/history.d.cts +177 -0
- package/dist/history.d.ts +177 -0
- package/dist/history.js +618 -0
- package/dist/history.js.map +1 -0
- package/dist/index.cjs +133 -132
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/package.json +79 -10
- package/dist/chunk-43I4ZAEK.js.map +0 -1
- package/dist/chunk-NRYNK7E4.cjs.map +0 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType, ReactElement, RefObject } from 'react';
|
|
3
|
+
import { ReadCard, AgentCardTarget } from '@vinaverse/client/agent';
|
|
4
|
+
import { MessageItem, Welcome, TimelineItem, CardItem, HeldCard, ProposalOutcome, Question, ConversationStore } from '@vinaverse/client/conversation';
|
|
5
|
+
import { ImageProps } from 'react-native';
|
|
6
|
+
|
|
7
|
+
interface HeaderProps {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly avatarUrl: string | null;
|
|
10
|
+
/** While a person from the business replies: their role. */
|
|
11
|
+
readonly takeoverBy: string | null;
|
|
12
|
+
readonly Default: ComponentType<Omit<HeaderProps, 'Default'>>;
|
|
13
|
+
}
|
|
14
|
+
interface MessageBubbleProps {
|
|
15
|
+
readonly item: MessageItem;
|
|
16
|
+
/** The text to draw: the message's, or the streamed text so far. */
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly Default: ComponentType<Omit<MessageBubbleProps, 'Default'>>;
|
|
19
|
+
}
|
|
20
|
+
interface ComposerProps {
|
|
21
|
+
readonly placeholder: string;
|
|
22
|
+
readonly responding: boolean;
|
|
23
|
+
readonly onSend: (text: string) => void;
|
|
24
|
+
readonly onStop: () => void;
|
|
25
|
+
readonly Default: ComponentType<Omit<ComposerProps, 'Default'>>;
|
|
26
|
+
}
|
|
27
|
+
interface EmptyStateProps {
|
|
28
|
+
readonly agentName: string;
|
|
29
|
+
/** The tenant's greeting and chips for the session's mode (`Session.welcome`), or null. */
|
|
30
|
+
readonly welcome: Welcome | null;
|
|
31
|
+
/** Sends a chip's `message` as the person's own text. */
|
|
32
|
+
readonly onChip: (message: string) => void;
|
|
33
|
+
}
|
|
34
|
+
/** `components.CardGroup`: the cards one turn drew together with `group.layout: carousel`, in order. */
|
|
35
|
+
interface CardGroupProps {
|
|
36
|
+
readonly items: readonly CardItem[];
|
|
37
|
+
}
|
|
38
|
+
/** The props the kit gives its list: FlashList's, so FlashList or LegendList take them as they are. */
|
|
39
|
+
interface ListProps {
|
|
40
|
+
readonly data: readonly TimelineItem[];
|
|
41
|
+
readonly renderItem: (info: {
|
|
42
|
+
item: TimelineItem;
|
|
43
|
+
index: number;
|
|
44
|
+
}) => ReactElement | null;
|
|
45
|
+
readonly keyExtractor: (item: TimelineItem) => string;
|
|
46
|
+
readonly getItemType: (item: TimelineItem) => string;
|
|
47
|
+
readonly maintainVisibleContentPosition: {
|
|
48
|
+
readonly startRenderingFromBottom: boolean;
|
|
49
|
+
readonly autoscrollToBottomThreshold: number;
|
|
50
|
+
readonly animateAutoScrollToBottom: boolean;
|
|
51
|
+
};
|
|
52
|
+
readonly ListFooterComponent: ReactElement | null;
|
|
53
|
+
readonly ListEmptyComponent: ReactElement | null;
|
|
54
|
+
readonly keyboardShouldPersistTaps: 'handled';
|
|
55
|
+
readonly contentContainerStyle: object;
|
|
56
|
+
}
|
|
57
|
+
/** A failure the person needs a way out of: a turn that failed before any reply, or no session to talk to. */
|
|
58
|
+
interface FailureState {
|
|
59
|
+
/** `turn_failed`: a turn failed before any of its reply; `unavailable`: the backend gave no session, or none it could use. */
|
|
60
|
+
readonly kind: 'turn_failed' | 'unavailable';
|
|
61
|
+
/** Why: the turn's error `code` (`internal`, `timeout`, …), or the conversation's status (`unavailable`, `unauthorized`). */
|
|
62
|
+
readonly reason: string | null;
|
|
63
|
+
/** Try again, when it can be: the person's text again for a turn the server allows to retry, a new session otherwise. */
|
|
64
|
+
readonly retry: (() => void) | undefined;
|
|
65
|
+
/** The conversation, once a session named it: for your support records. */
|
|
66
|
+
readonly conversationId: string | null;
|
|
67
|
+
}
|
|
68
|
+
/** A slot for a failure (`components.Error`, `components.Unavailable`): the state, and the kit's own part to wrap. */
|
|
69
|
+
interface FailureProps {
|
|
70
|
+
readonly state: FailureState;
|
|
71
|
+
readonly Default: ComponentType<{
|
|
72
|
+
readonly state: FailureState;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
/** One action on every failure, drawn as a button by the kit's own parts: a person is always the way out. */
|
|
76
|
+
interface FailureAction {
|
|
77
|
+
/** Default: the copy's `talkToPerson` ("Talk to a person"), in the person's language. */
|
|
78
|
+
readonly label?: string;
|
|
79
|
+
readonly onPress: (state: FailureState) => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare function CardCarousel(props: CardGroupProps): react.JSX.Element;
|
|
83
|
+
|
|
84
|
+
interface CardProps {
|
|
85
|
+
readonly card: HeldCard;
|
|
86
|
+
/** The card read once for drawing, every field checked (`readCard`): kind, target, photo, rating, price, group, links. */
|
|
87
|
+
readonly read: ReadCard | null;
|
|
88
|
+
/** A proposal being decided: draw its buttons busy. */
|
|
89
|
+
readonly busy: boolean;
|
|
90
|
+
/** Restored after a restart: draw it as it was, taking no answer or action. */
|
|
91
|
+
readonly restored: boolean;
|
|
92
|
+
/** Drawn inside a carousel with its group: a photo keeps the policy's fixed frame, so the row stays even. */
|
|
93
|
+
readonly grouped?: boolean;
|
|
94
|
+
/** The kit's own renderer for this kind, to wrap rather than rewrite. */
|
|
95
|
+
readonly Default: ComponentType<Omit<CardProps, 'Default'>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type ProposalDecision = 'confirm' | 'decline';
|
|
99
|
+
/** What the kit asks of the tenant's app. Only `onProposal` and `onOpenLink` are needed for the cards that use them. */
|
|
100
|
+
/** What a chat warning is about. */
|
|
101
|
+
interface ChatWarning {
|
|
102
|
+
readonly code: 'theme' | 'copy' | 'send_failed' | 'answer_failed' | 'proposal_failed' | 'photo_failed';
|
|
103
|
+
}
|
|
104
|
+
interface ChatHandlers {
|
|
105
|
+
/**
|
|
106
|
+
* The person confirmed or declined a proposal: call your backend with the person's own token, then say what
|
|
107
|
+
* happened (`confirmed`, `declined`, `failed`, or `expired` when it had expired). The kit reports it to the session.
|
|
108
|
+
*/
|
|
109
|
+
readonly onProposal?: (card: HeldCard, decision: ProposalDecision) => Promise<ProposalOutcome>;
|
|
110
|
+
/**
|
|
111
|
+
* Open a card's link in your app: a deep link that already passed the deep-link rule (route by the page it names),
|
|
112
|
+
* or a `links` card's https page (your in-app browser; without this handler the system opens it).
|
|
113
|
+
*/
|
|
114
|
+
readonly onOpenLink?: (link: string, card: HeldCard) => void;
|
|
115
|
+
/** A card action without a link (`show_times`, …): sent to the session; this tells your app too. */
|
|
116
|
+
readonly onCardAction?: (card: HeldCard, action: string) => void;
|
|
117
|
+
/** A photo question: let the person pick one, upload it to your backend, and give back its `upload_ref`. */
|
|
118
|
+
readonly onPickPhoto?: (question: Question, card: HeldCard) => Promise<{
|
|
119
|
+
readonly upload_ref: string;
|
|
120
|
+
} | null>;
|
|
121
|
+
/**
|
|
122
|
+
* A way out on a failed turn and on "couldn't connect": a button with your label (default "Talk to a person"),
|
|
123
|
+
* drawn by the kit's own parts when no `components.Error` or `components.Unavailable` replaces them.
|
|
124
|
+
*/
|
|
125
|
+
readonly failureAction?: FailureAction;
|
|
126
|
+
/**
|
|
127
|
+
* Warnings for the app's logger: a theme that is hard to read, copy that says "assistant", a send, an answer, a
|
|
128
|
+
* proposal or a photo pick that failed. `warning.code` says which, so a logger counts them without the text.
|
|
129
|
+
*/
|
|
130
|
+
readonly onWarning?: (message: string, warning: ChatWarning) => void;
|
|
131
|
+
/**
|
|
132
|
+
* The person tapped a card about something of yours (its `ref`: a professional, a space, a booking): open its page
|
|
133
|
+
* with your router. Without it, only the card's own actions open anything.
|
|
134
|
+
*/
|
|
135
|
+
readonly onOpenTarget?: (target: AgentCardTarget, card: HeldCard) => void;
|
|
136
|
+
/** Card photos arrive: fetch them ahead with your image library (`Image.prefetch`), so the cards draw at once. */
|
|
137
|
+
readonly prefetchImage?: (url: string) => void;
|
|
138
|
+
/** Reads a line to a screen reader (a finished reply, the launcher's greeting). Default: the platform's. */
|
|
139
|
+
readonly announce?: (text: string) => void;
|
|
140
|
+
/** A chip was tapped (a welcome chip, a starter, the suggestion); its message is sent as the person's own. */
|
|
141
|
+
readonly onChip?: (chip: Chip) => void;
|
|
142
|
+
}
|
|
143
|
+
/** Which card photos are drawn, in what frame, and what stands in for one that is not. */
|
|
144
|
+
interface ImagePolicy {
|
|
145
|
+
/** Hosts a photo may come from (exact names); default any https host. */
|
|
146
|
+
readonly hosts?: readonly string[];
|
|
147
|
+
/**
|
|
148
|
+
* Width / height of a listing's photo frame. Default 1.6 (16:10). `natural`: a card on its own takes its photo's
|
|
149
|
+
* own shape (its `width` and `height`), held within `naturalAspect`; a card in a carousel keeps 1.6, so the row
|
|
150
|
+
* stays even, and a photo without its size too.
|
|
151
|
+
*/
|
|
152
|
+
readonly aspectRatio?: number | 'natural';
|
|
153
|
+
/** The shapes a `natural` photo is held within. Default square to 2:1 (`{ min: 1, max: 2 }`). */
|
|
154
|
+
readonly naturalAspect?: {
|
|
155
|
+
readonly min: number;
|
|
156
|
+
readonly max: number;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* What stands in for a missing, refused or failed photo, by the card's `kind` (a person's tile, a space's tile).
|
|
160
|
+
* Default the name's monogram.
|
|
161
|
+
*/
|
|
162
|
+
readonly Placeholder?: ComponentType<{
|
|
163
|
+
readonly title: string;
|
|
164
|
+
readonly kind: string;
|
|
165
|
+
}>;
|
|
166
|
+
}
|
|
167
|
+
/** Parts a tenant can replace. Each gets the default's props and the default itself (`Default`), to wrap it. */
|
|
168
|
+
interface ChatSlots {
|
|
169
|
+
readonly Header?: ComponentType<HeaderProps>;
|
|
170
|
+
readonly MessageBubble?: ComponentType<MessageBubbleProps>;
|
|
171
|
+
readonly Composer?: ComponentType<ComposerProps>;
|
|
172
|
+
readonly EmptyState?: ComponentType<EmptyStateProps>;
|
|
173
|
+
readonly Image?: ComponentType<ImageProps>;
|
|
174
|
+
/** A list with FlashList's props (LegendList works). Default: FlashList. */
|
|
175
|
+
readonly ListComponent?: ComponentType<ListProps>;
|
|
176
|
+
/** A turn that failed before any reply: replaces the "Something went wrong." row. */
|
|
177
|
+
readonly Error?: ComponentType<FailureProps>;
|
|
178
|
+
/** No session to talk to: replaces the "Couldn't connect." banner. */
|
|
179
|
+
readonly Unavailable?: ComponentType<FailureProps>;
|
|
180
|
+
/**
|
|
181
|
+
* Draws a turn's cards that ask for a carousel (`group.layout: carousel`) in one row: the kit's `CardCarousel`, or
|
|
182
|
+
* yours. Without it they draw one under another. Opt-in, so an app that never draws a carousel does not ship one.
|
|
183
|
+
*/
|
|
184
|
+
readonly CardGroup?: ComponentType<CardGroupProps>;
|
|
185
|
+
/** Card renderers by kind (`professional`, `proposal`, …). */
|
|
186
|
+
readonly cards?: Readonly<Partial<Record<string, ComponentType<CardProps>>>>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* What the parts ask of a conversation: the live store, or history's read-only view of a past conversation (every
|
|
190
|
+
* action a no-op, nothing restored takes one).
|
|
191
|
+
*/
|
|
192
|
+
type ChatStore = Pick<ConversationStore, 'getSnapshot' | 'subscribe' | 'getStreaming' | 'subscribeStreaming' | 'send' | 'retry' | 'retryTurn' | 'cancel' | 'answer' | 'cardAction' | 'decideProposal' | 'checkLink' | 'continueHere' | 'setForeground' | 'start'>;
|
|
193
|
+
interface ChatContextValue {
|
|
194
|
+
readonly store: ChatStore;
|
|
195
|
+
readonly handlers: RefObject<ChatHandlers>;
|
|
196
|
+
readonly slots: ChatSlots;
|
|
197
|
+
readonly agentAvatar: string | undefined;
|
|
198
|
+
readonly timeZone: string | undefined;
|
|
199
|
+
/** The failure action's label when there is one (`label` undefined: the copy's); `onPress` is read from `handlers`. */
|
|
200
|
+
readonly failureAction: {
|
|
201
|
+
readonly label: string | undefined;
|
|
202
|
+
} | null;
|
|
203
|
+
/** Chips for an empty conversation when the session brings no welcome. */
|
|
204
|
+
readonly starters: readonly Chip[] | undefined;
|
|
205
|
+
readonly imagePolicy: ImagePolicy | undefined;
|
|
206
|
+
}
|
|
207
|
+
/** A tap target that sends `message` as the person's own text (a welcome chip, a starter, a suggestion). */
|
|
208
|
+
type Chip = Welcome['chips'][number];
|
|
209
|
+
/** The conversation, handlers and slots; only inside `VinaverseChat` (or `VinaverseChatProvider`). */
|
|
210
|
+
declare function useChat(): ChatContextValue;
|
|
211
|
+
|
|
212
|
+
export { CardCarousel as C, type EmptyStateProps as E, type FailureAction as F, type HeaderProps as H, type ImagePolicy as I, type ListProps as L, type MessageBubbleProps as M, type ProposalDecision as P, type CardGroupProps as a, type CardProps as b, type ChatHandlers as c, type ChatSlots as d, type ChatStore as e, type ChatWarning as f, type Chip as g, type ComposerProps as h, type FailureProps as i, type FailureState as j, useChat as u };
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ComponentType, ReactElement, RefObject } from 'react';
|
|
3
|
+
import { ReadCard, AgentCardTarget } from '@vinaverse/client/agent';
|
|
4
|
+
import { MessageItem, Welcome, TimelineItem, CardItem, HeldCard, ProposalOutcome, Question, ConversationStore } from '@vinaverse/client/conversation';
|
|
5
|
+
import { ImageProps } from 'react-native';
|
|
6
|
+
|
|
7
|
+
interface HeaderProps {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly avatarUrl: string | null;
|
|
10
|
+
/** While a person from the business replies: their role. */
|
|
11
|
+
readonly takeoverBy: string | null;
|
|
12
|
+
readonly Default: ComponentType<Omit<HeaderProps, 'Default'>>;
|
|
13
|
+
}
|
|
14
|
+
interface MessageBubbleProps {
|
|
15
|
+
readonly item: MessageItem;
|
|
16
|
+
/** The text to draw: the message's, or the streamed text so far. */
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly Default: ComponentType<Omit<MessageBubbleProps, 'Default'>>;
|
|
19
|
+
}
|
|
20
|
+
interface ComposerProps {
|
|
21
|
+
readonly placeholder: string;
|
|
22
|
+
readonly responding: boolean;
|
|
23
|
+
readonly onSend: (text: string) => void;
|
|
24
|
+
readonly onStop: () => void;
|
|
25
|
+
readonly Default: ComponentType<Omit<ComposerProps, 'Default'>>;
|
|
26
|
+
}
|
|
27
|
+
interface EmptyStateProps {
|
|
28
|
+
readonly agentName: string;
|
|
29
|
+
/** The tenant's greeting and chips for the session's mode (`Session.welcome`), or null. */
|
|
30
|
+
readonly welcome: Welcome | null;
|
|
31
|
+
/** Sends a chip's `message` as the person's own text. */
|
|
32
|
+
readonly onChip: (message: string) => void;
|
|
33
|
+
}
|
|
34
|
+
/** `components.CardGroup`: the cards one turn drew together with `group.layout: carousel`, in order. */
|
|
35
|
+
interface CardGroupProps {
|
|
36
|
+
readonly items: readonly CardItem[];
|
|
37
|
+
}
|
|
38
|
+
/** The props the kit gives its list: FlashList's, so FlashList or LegendList take them as they are. */
|
|
39
|
+
interface ListProps {
|
|
40
|
+
readonly data: readonly TimelineItem[];
|
|
41
|
+
readonly renderItem: (info: {
|
|
42
|
+
item: TimelineItem;
|
|
43
|
+
index: number;
|
|
44
|
+
}) => ReactElement | null;
|
|
45
|
+
readonly keyExtractor: (item: TimelineItem) => string;
|
|
46
|
+
readonly getItemType: (item: TimelineItem) => string;
|
|
47
|
+
readonly maintainVisibleContentPosition: {
|
|
48
|
+
readonly startRenderingFromBottom: boolean;
|
|
49
|
+
readonly autoscrollToBottomThreshold: number;
|
|
50
|
+
readonly animateAutoScrollToBottom: boolean;
|
|
51
|
+
};
|
|
52
|
+
readonly ListFooterComponent: ReactElement | null;
|
|
53
|
+
readonly ListEmptyComponent: ReactElement | null;
|
|
54
|
+
readonly keyboardShouldPersistTaps: 'handled';
|
|
55
|
+
readonly contentContainerStyle: object;
|
|
56
|
+
}
|
|
57
|
+
/** A failure the person needs a way out of: a turn that failed before any reply, or no session to talk to. */
|
|
58
|
+
interface FailureState {
|
|
59
|
+
/** `turn_failed`: a turn failed before any of its reply; `unavailable`: the backend gave no session, or none it could use. */
|
|
60
|
+
readonly kind: 'turn_failed' | 'unavailable';
|
|
61
|
+
/** Why: the turn's error `code` (`internal`, `timeout`, …), or the conversation's status (`unavailable`, `unauthorized`). */
|
|
62
|
+
readonly reason: string | null;
|
|
63
|
+
/** Try again, when it can be: the person's text again for a turn the server allows to retry, a new session otherwise. */
|
|
64
|
+
readonly retry: (() => void) | undefined;
|
|
65
|
+
/** The conversation, once a session named it: for your support records. */
|
|
66
|
+
readonly conversationId: string | null;
|
|
67
|
+
}
|
|
68
|
+
/** A slot for a failure (`components.Error`, `components.Unavailable`): the state, and the kit's own part to wrap. */
|
|
69
|
+
interface FailureProps {
|
|
70
|
+
readonly state: FailureState;
|
|
71
|
+
readonly Default: ComponentType<{
|
|
72
|
+
readonly state: FailureState;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
/** One action on every failure, drawn as a button by the kit's own parts: a person is always the way out. */
|
|
76
|
+
interface FailureAction {
|
|
77
|
+
/** Default: the copy's `talkToPerson` ("Talk to a person"), in the person's language. */
|
|
78
|
+
readonly label?: string;
|
|
79
|
+
readonly onPress: (state: FailureState) => void;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
declare function CardCarousel(props: CardGroupProps): react.JSX.Element;
|
|
83
|
+
|
|
84
|
+
interface CardProps {
|
|
85
|
+
readonly card: HeldCard;
|
|
86
|
+
/** The card read once for drawing, every field checked (`readCard`): kind, target, photo, rating, price, group, links. */
|
|
87
|
+
readonly read: ReadCard | null;
|
|
88
|
+
/** A proposal being decided: draw its buttons busy. */
|
|
89
|
+
readonly busy: boolean;
|
|
90
|
+
/** Restored after a restart: draw it as it was, taking no answer or action. */
|
|
91
|
+
readonly restored: boolean;
|
|
92
|
+
/** Drawn inside a carousel with its group: a photo keeps the policy's fixed frame, so the row stays even. */
|
|
93
|
+
readonly grouped?: boolean;
|
|
94
|
+
/** The kit's own renderer for this kind, to wrap rather than rewrite. */
|
|
95
|
+
readonly Default: ComponentType<Omit<CardProps, 'Default'>>;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type ProposalDecision = 'confirm' | 'decline';
|
|
99
|
+
/** What the kit asks of the tenant's app. Only `onProposal` and `onOpenLink` are needed for the cards that use them. */
|
|
100
|
+
/** What a chat warning is about. */
|
|
101
|
+
interface ChatWarning {
|
|
102
|
+
readonly code: 'theme' | 'copy' | 'send_failed' | 'answer_failed' | 'proposal_failed' | 'photo_failed';
|
|
103
|
+
}
|
|
104
|
+
interface ChatHandlers {
|
|
105
|
+
/**
|
|
106
|
+
* The person confirmed or declined a proposal: call your backend with the person's own token, then say what
|
|
107
|
+
* happened (`confirmed`, `declined`, `failed`, or `expired` when it had expired). The kit reports it to the session.
|
|
108
|
+
*/
|
|
109
|
+
readonly onProposal?: (card: HeldCard, decision: ProposalDecision) => Promise<ProposalOutcome>;
|
|
110
|
+
/**
|
|
111
|
+
* Open a card's link in your app: a deep link that already passed the deep-link rule (route by the page it names),
|
|
112
|
+
* or a `links` card's https page (your in-app browser; without this handler the system opens it).
|
|
113
|
+
*/
|
|
114
|
+
readonly onOpenLink?: (link: string, card: HeldCard) => void;
|
|
115
|
+
/** A card action without a link (`show_times`, …): sent to the session; this tells your app too. */
|
|
116
|
+
readonly onCardAction?: (card: HeldCard, action: string) => void;
|
|
117
|
+
/** A photo question: let the person pick one, upload it to your backend, and give back its `upload_ref`. */
|
|
118
|
+
readonly onPickPhoto?: (question: Question, card: HeldCard) => Promise<{
|
|
119
|
+
readonly upload_ref: string;
|
|
120
|
+
} | null>;
|
|
121
|
+
/**
|
|
122
|
+
* A way out on a failed turn and on "couldn't connect": a button with your label (default "Talk to a person"),
|
|
123
|
+
* drawn by the kit's own parts when no `components.Error` or `components.Unavailable` replaces them.
|
|
124
|
+
*/
|
|
125
|
+
readonly failureAction?: FailureAction;
|
|
126
|
+
/**
|
|
127
|
+
* Warnings for the app's logger: a theme that is hard to read, copy that says "assistant", a send, an answer, a
|
|
128
|
+
* proposal or a photo pick that failed. `warning.code` says which, so a logger counts them without the text.
|
|
129
|
+
*/
|
|
130
|
+
readonly onWarning?: (message: string, warning: ChatWarning) => void;
|
|
131
|
+
/**
|
|
132
|
+
* The person tapped a card about something of yours (its `ref`: a professional, a space, a booking): open its page
|
|
133
|
+
* with your router. Without it, only the card's own actions open anything.
|
|
134
|
+
*/
|
|
135
|
+
readonly onOpenTarget?: (target: AgentCardTarget, card: HeldCard) => void;
|
|
136
|
+
/** Card photos arrive: fetch them ahead with your image library (`Image.prefetch`), so the cards draw at once. */
|
|
137
|
+
readonly prefetchImage?: (url: string) => void;
|
|
138
|
+
/** Reads a line to a screen reader (a finished reply, the launcher's greeting). Default: the platform's. */
|
|
139
|
+
readonly announce?: (text: string) => void;
|
|
140
|
+
/** A chip was tapped (a welcome chip, a starter, the suggestion); its message is sent as the person's own. */
|
|
141
|
+
readonly onChip?: (chip: Chip) => void;
|
|
142
|
+
}
|
|
143
|
+
/** Which card photos are drawn, in what frame, and what stands in for one that is not. */
|
|
144
|
+
interface ImagePolicy {
|
|
145
|
+
/** Hosts a photo may come from (exact names); default any https host. */
|
|
146
|
+
readonly hosts?: readonly string[];
|
|
147
|
+
/**
|
|
148
|
+
* Width / height of a listing's photo frame. Default 1.6 (16:10). `natural`: a card on its own takes its photo's
|
|
149
|
+
* own shape (its `width` and `height`), held within `naturalAspect`; a card in a carousel keeps 1.6, so the row
|
|
150
|
+
* stays even, and a photo without its size too.
|
|
151
|
+
*/
|
|
152
|
+
readonly aspectRatio?: number | 'natural';
|
|
153
|
+
/** The shapes a `natural` photo is held within. Default square to 2:1 (`{ min: 1, max: 2 }`). */
|
|
154
|
+
readonly naturalAspect?: {
|
|
155
|
+
readonly min: number;
|
|
156
|
+
readonly max: number;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* What stands in for a missing, refused or failed photo, by the card's `kind` (a person's tile, a space's tile).
|
|
160
|
+
* Default the name's monogram.
|
|
161
|
+
*/
|
|
162
|
+
readonly Placeholder?: ComponentType<{
|
|
163
|
+
readonly title: string;
|
|
164
|
+
readonly kind: string;
|
|
165
|
+
}>;
|
|
166
|
+
}
|
|
167
|
+
/** Parts a tenant can replace. Each gets the default's props and the default itself (`Default`), to wrap it. */
|
|
168
|
+
interface ChatSlots {
|
|
169
|
+
readonly Header?: ComponentType<HeaderProps>;
|
|
170
|
+
readonly MessageBubble?: ComponentType<MessageBubbleProps>;
|
|
171
|
+
readonly Composer?: ComponentType<ComposerProps>;
|
|
172
|
+
readonly EmptyState?: ComponentType<EmptyStateProps>;
|
|
173
|
+
readonly Image?: ComponentType<ImageProps>;
|
|
174
|
+
/** A list with FlashList's props (LegendList works). Default: FlashList. */
|
|
175
|
+
readonly ListComponent?: ComponentType<ListProps>;
|
|
176
|
+
/** A turn that failed before any reply: replaces the "Something went wrong." row. */
|
|
177
|
+
readonly Error?: ComponentType<FailureProps>;
|
|
178
|
+
/** No session to talk to: replaces the "Couldn't connect." banner. */
|
|
179
|
+
readonly Unavailable?: ComponentType<FailureProps>;
|
|
180
|
+
/**
|
|
181
|
+
* Draws a turn's cards that ask for a carousel (`group.layout: carousel`) in one row: the kit's `CardCarousel`, or
|
|
182
|
+
* yours. Without it they draw one under another. Opt-in, so an app that never draws a carousel does not ship one.
|
|
183
|
+
*/
|
|
184
|
+
readonly CardGroup?: ComponentType<CardGroupProps>;
|
|
185
|
+
/** Card renderers by kind (`professional`, `proposal`, …). */
|
|
186
|
+
readonly cards?: Readonly<Partial<Record<string, ComponentType<CardProps>>>>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* What the parts ask of a conversation: the live store, or history's read-only view of a past conversation (every
|
|
190
|
+
* action a no-op, nothing restored takes one).
|
|
191
|
+
*/
|
|
192
|
+
type ChatStore = Pick<ConversationStore, 'getSnapshot' | 'subscribe' | 'getStreaming' | 'subscribeStreaming' | 'send' | 'retry' | 'retryTurn' | 'cancel' | 'answer' | 'cardAction' | 'decideProposal' | 'checkLink' | 'continueHere' | 'setForeground' | 'start'>;
|
|
193
|
+
interface ChatContextValue {
|
|
194
|
+
readonly store: ChatStore;
|
|
195
|
+
readonly handlers: RefObject<ChatHandlers>;
|
|
196
|
+
readonly slots: ChatSlots;
|
|
197
|
+
readonly agentAvatar: string | undefined;
|
|
198
|
+
readonly timeZone: string | undefined;
|
|
199
|
+
/** The failure action's label when there is one (`label` undefined: the copy's); `onPress` is read from `handlers`. */
|
|
200
|
+
readonly failureAction: {
|
|
201
|
+
readonly label: string | undefined;
|
|
202
|
+
} | null;
|
|
203
|
+
/** Chips for an empty conversation when the session brings no welcome. */
|
|
204
|
+
readonly starters: readonly Chip[] | undefined;
|
|
205
|
+
readonly imagePolicy: ImagePolicy | undefined;
|
|
206
|
+
}
|
|
207
|
+
/** A tap target that sends `message` as the person's own text (a welcome chip, a starter, a suggestion). */
|
|
208
|
+
type Chip = Welcome['chips'][number];
|
|
209
|
+
/** The conversation, handlers and slots; only inside `VinaverseChat` (or `VinaverseChatProvider`). */
|
|
210
|
+
declare function useChat(): ChatContextValue;
|
|
211
|
+
|
|
212
|
+
export { CardCarousel as C, type EmptyStateProps as E, type FailureAction as F, type HeaderProps as H, type ImagePolicy as I, type ListProps as L, type MessageBubbleProps as M, type ProposalDecision as P, type CardGroupProps as a, type CardProps as b, type ChatHandlers as c, type ChatSlots as d, type ChatStore as e, type ChatWarning as f, type Chip as g, type ComposerProps as h, type FailureProps as i, type FailureState as j, useChat as u };
|