@wakflo/react 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,104 @@
1
+ import { ClientOptions, Conversation, WakfloClient, ChatConfig, ConnectionState, ConversationData, Message, Notice, PendingTool, ConversationStatus, Author, ToolCall, Theme } from '@wakflo/client';
2
+ export { Author, ChatConfig, ConnectionState, ConversationData, ConversationStatus, Message, Notice, PendingTool, PublicError, Theme, ToolCall, ToolResult } from '@wakflo/client';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ReactNode } from 'react';
5
+
6
+ type FieldType = "text" | "email" | "number" | "textarea";
7
+ interface ContactField {
8
+ readonly key: string;
9
+ readonly label: string;
10
+ readonly required: boolean;
11
+ readonly type: FieldType;
12
+ }
13
+ /**
14
+ * The form's fields from the tool call's arguments, dropping any it can't
15
+ * draw, or the default contact fields when the call names none.
16
+ */
17
+ declare function contactFields(args: Record<string, unknown>): ContactField[];
18
+
19
+ interface UseWakfloChatOptions extends ClientOptions {
20
+ /** Hold the events stream open while mounted. Defaults to true. */
21
+ readonly connect?: boolean;
22
+ /** Whether the bubble starts open. */
23
+ readonly defaultOpen?: boolean;
24
+ }
25
+ interface WakfloChatState {
26
+ /** The live Conversation object behind this state. */
27
+ readonly chat: Conversation;
28
+ /** The client, for calls the hook doesn't wrap. */
29
+ readonly client: WakfloClient;
30
+ /** The endpoint's public settings, once loaded. */
31
+ readonly config: ChatConfig | null;
32
+ /** The stream's state. */
33
+ readonly connection: ConnectionState;
34
+ /** The conversation itself, or null before the first message. */
35
+ readonly conversation: ConversationData | null;
36
+ readonly error: {
37
+ readonly code: string;
38
+ readonly message: string;
39
+ } | null;
40
+ /** Asks for a person. Resolves false when the call failed. */
41
+ handover(): Promise<boolean>;
42
+ readonly messages: readonly Message[];
43
+ readonly notices: readonly Notice[];
44
+ readonly open: boolean;
45
+ /** A paused run's frontend tool calls, waiting for `respond`. */
46
+ readonly pendingTool: PendingTool | null;
47
+ /** A new chat: closes this one and forgets it. */
48
+ reset(): Promise<void>;
49
+ /**
50
+ * Answers one frontend tool call of the pending run. The answers go to the
51
+ * server together once every call of the run has one.
52
+ */
53
+ respond(callId: string, result: unknown, error?: string): void;
54
+ /** Sends a message. Resolves false when it wasn't sent. */
55
+ send(content: string): Promise<boolean>;
56
+ /** Leaves an email for the team. Resolves false when the call failed. */
57
+ setEmail(email: string, name?: string): Promise<boolean>;
58
+ setOpen(open: boolean | ((open: boolean) => boolean)): void;
59
+ /** The conversation's status, or null before it starts. */
60
+ readonly status: ConversationStatus | null;
61
+ /** The same as pendingTool. */
62
+ readonly toolCall: PendingTool | null;
63
+ /** Who is typing now, other than the visitor. */
64
+ readonly typing: readonly Author[];
65
+ }
66
+ /**
67
+ * A Wakflo website chat, headless: the endpoint's config, the live
68
+ * conversation and the calls on it. Render it however you like.
69
+ */
70
+ declare function useWakfloChat(options: UseWakfloChatOptions): WakfloChatState;
71
+
72
+ type Position = "bottom-right" | "bottom-left";
73
+ /** Answers a frontend tool call: its result, or an error. */
74
+ type RespondToTool = (result: unknown, error?: string) => void;
75
+ interface WakfloChatProps extends Pick<ClientOptions, "apiUrl" | "baseUrl" | "botToken" | "fetch" | "portalToken" | "storage"> {
76
+ /** A css colour for the accent. Defaults to the endpoint's, then orange. */
77
+ readonly accent?: string;
78
+ readonly className?: string;
79
+ readonly defaultOpen?: boolean;
80
+ /** The first bot bubble. Defaults to the endpoint's greeting. */
81
+ readonly greeting?: string;
82
+ /** The composer's placeholder. */
83
+ readonly placeholder?: string;
84
+ readonly position?: Position;
85
+ readonly publishableKey: string;
86
+ /**
87
+ * Draws a frontend tool call. Return undefined to leave it to the bubble,
88
+ * which draws contact_form itself and declines the rest.
89
+ */
90
+ readonly renderTool?: (call: ToolCall, respond: RespondToTool) => ReactNode;
91
+ /** Questions offered until the first message. */
92
+ readonly suggestions?: readonly string[];
93
+ readonly theme?: Theme;
94
+ /** The bubble's name. Defaults to the endpoint's title. */
95
+ readonly title?: string;
96
+ }
97
+ /**
98
+ * The Wakflo website chat bubble: a launcher pill, and a panel above it with
99
+ * the conversation. Reads its title, greeting, suggestions and theme from the
100
+ * endpoint; props override them. Import "@wakflo/react/styles.css" once.
101
+ */
102
+ declare function WakfloChat(props: WakfloChatProps): react_jsx_runtime.JSX.Element;
103
+
104
+ export { type ContactField, type Position, type RespondToTool, type UseWakfloChatOptions, WakfloChat, type WakfloChatProps, type WakfloChatState, contactFields, useWakfloChat };
@@ -0,0 +1,104 @@
1
+ import { ClientOptions, Conversation, WakfloClient, ChatConfig, ConnectionState, ConversationData, Message, Notice, PendingTool, ConversationStatus, Author, ToolCall, Theme } from '@wakflo/client';
2
+ export { Author, ChatConfig, ConnectionState, ConversationData, ConversationStatus, Message, Notice, PendingTool, PublicError, Theme, ToolCall, ToolResult } from '@wakflo/client';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import { ReactNode } from 'react';
5
+
6
+ type FieldType = "text" | "email" | "number" | "textarea";
7
+ interface ContactField {
8
+ readonly key: string;
9
+ readonly label: string;
10
+ readonly required: boolean;
11
+ readonly type: FieldType;
12
+ }
13
+ /**
14
+ * The form's fields from the tool call's arguments, dropping any it can't
15
+ * draw, or the default contact fields when the call names none.
16
+ */
17
+ declare function contactFields(args: Record<string, unknown>): ContactField[];
18
+
19
+ interface UseWakfloChatOptions extends ClientOptions {
20
+ /** Hold the events stream open while mounted. Defaults to true. */
21
+ readonly connect?: boolean;
22
+ /** Whether the bubble starts open. */
23
+ readonly defaultOpen?: boolean;
24
+ }
25
+ interface WakfloChatState {
26
+ /** The live Conversation object behind this state. */
27
+ readonly chat: Conversation;
28
+ /** The client, for calls the hook doesn't wrap. */
29
+ readonly client: WakfloClient;
30
+ /** The endpoint's public settings, once loaded. */
31
+ readonly config: ChatConfig | null;
32
+ /** The stream's state. */
33
+ readonly connection: ConnectionState;
34
+ /** The conversation itself, or null before the first message. */
35
+ readonly conversation: ConversationData | null;
36
+ readonly error: {
37
+ readonly code: string;
38
+ readonly message: string;
39
+ } | null;
40
+ /** Asks for a person. Resolves false when the call failed. */
41
+ handover(): Promise<boolean>;
42
+ readonly messages: readonly Message[];
43
+ readonly notices: readonly Notice[];
44
+ readonly open: boolean;
45
+ /** A paused run's frontend tool calls, waiting for `respond`. */
46
+ readonly pendingTool: PendingTool | null;
47
+ /** A new chat: closes this one and forgets it. */
48
+ reset(): Promise<void>;
49
+ /**
50
+ * Answers one frontend tool call of the pending run. The answers go to the
51
+ * server together once every call of the run has one.
52
+ */
53
+ respond(callId: string, result: unknown, error?: string): void;
54
+ /** Sends a message. Resolves false when it wasn't sent. */
55
+ send(content: string): Promise<boolean>;
56
+ /** Leaves an email for the team. Resolves false when the call failed. */
57
+ setEmail(email: string, name?: string): Promise<boolean>;
58
+ setOpen(open: boolean | ((open: boolean) => boolean)): void;
59
+ /** The conversation's status, or null before it starts. */
60
+ readonly status: ConversationStatus | null;
61
+ /** The same as pendingTool. */
62
+ readonly toolCall: PendingTool | null;
63
+ /** Who is typing now, other than the visitor. */
64
+ readonly typing: readonly Author[];
65
+ }
66
+ /**
67
+ * A Wakflo website chat, headless: the endpoint's config, the live
68
+ * conversation and the calls on it. Render it however you like.
69
+ */
70
+ declare function useWakfloChat(options: UseWakfloChatOptions): WakfloChatState;
71
+
72
+ type Position = "bottom-right" | "bottom-left";
73
+ /** Answers a frontend tool call: its result, or an error. */
74
+ type RespondToTool = (result: unknown, error?: string) => void;
75
+ interface WakfloChatProps extends Pick<ClientOptions, "apiUrl" | "baseUrl" | "botToken" | "fetch" | "portalToken" | "storage"> {
76
+ /** A css colour for the accent. Defaults to the endpoint's, then orange. */
77
+ readonly accent?: string;
78
+ readonly className?: string;
79
+ readonly defaultOpen?: boolean;
80
+ /** The first bot bubble. Defaults to the endpoint's greeting. */
81
+ readonly greeting?: string;
82
+ /** The composer's placeholder. */
83
+ readonly placeholder?: string;
84
+ readonly position?: Position;
85
+ readonly publishableKey: string;
86
+ /**
87
+ * Draws a frontend tool call. Return undefined to leave it to the bubble,
88
+ * which draws contact_form itself and declines the rest.
89
+ */
90
+ readonly renderTool?: (call: ToolCall, respond: RespondToTool) => ReactNode;
91
+ /** Questions offered until the first message. */
92
+ readonly suggestions?: readonly string[];
93
+ readonly theme?: Theme;
94
+ /** The bubble's name. Defaults to the endpoint's title. */
95
+ readonly title?: string;
96
+ }
97
+ /**
98
+ * The Wakflo website chat bubble: a launcher pill, and a panel above it with
99
+ * the conversation. Reads its title, greeting, suggestions and theme from the
100
+ * endpoint; props override them. Import "@wakflo/react/styles.css" once.
101
+ */
102
+ declare function WakfloChat(props: WakfloChatProps): react_jsx_runtime.JSX.Element;
103
+
104
+ export { type ContactField, type Position, type RespondToTool, type UseWakfloChatOptions, WakfloChat, type WakfloChatProps, type WakfloChatState, contactFields, useWakfloChat };