@espejo/browser 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,288 @@
1
+ import { A as AgentActionType, a as AgentToolDefinition, b as ActResult, C as ConfirmRequest, E as EspejoAgent } from './index-Djj7dbiY.cjs';
2
+ import { W as WidgetCorner, a as WidgetTheme } from './shadow-scaffold-DUJmxf_n.cjs';
3
+
4
+ interface AgentChatToolCall {
5
+ id: string;
6
+ name: AgentToolDefinition['name'];
7
+ input: Record<string, unknown>;
8
+ }
9
+ type AgentChatErrorCode = 'provider_auth' | 'provider_rate_limited' | 'provider_error' | 'timeout' | 'iteration_limit' | 'internal';
10
+ type AgentWidgetTheme = 'auto' | 'light' | 'dark';
11
+ interface AgentPublicConfig {
12
+ enabled: boolean;
13
+ allowed_actions: AgentActionType[];
14
+ theme: AgentWidgetTheme;
15
+ name: string | null;
16
+ icon: string | null;
17
+ sections: AgentWidgetSection[];
18
+ }
19
+ type AgentWidgetSection = 'home' | 'support' | 'tickets' | 'guides';
20
+
21
+ interface ChatIdentity {
22
+ email: string;
23
+ hash: string;
24
+ }
25
+ interface ChatQueueItem {
26
+ id: number;
27
+ text: string;
28
+ }
29
+ type ChatErrorCode = 'no_agent' | 'daily_cap' | 'rate_limited' | 'conversation_limit' | 'conversation_expired' | 'conversation_busy' | 'identity_changed' | 'conflict' | 'forbidden' | 'bad_request' | 'unavailable' | 'network' | AgentChatErrorCode;
30
+ type ChatClientEvent = {
31
+ type: 'text';
32
+ delta: string;
33
+ } | {
34
+ type: 'tool_start';
35
+ call: AgentChatToolCall;
36
+ label: string;
37
+ target?: string;
38
+ value?: string;
39
+ destination?: string;
40
+ } | {
41
+ type: 'tool';
42
+ call: AgentChatToolCall;
43
+ label: string;
44
+ target?: string;
45
+ value?: string;
46
+ destination?: string;
47
+ result: ActResult;
48
+ } | {
49
+ type: 'done';
50
+ conversationId: string;
51
+ } | {
52
+ type: 'error';
53
+ code: ChatErrorCode;
54
+ message: string;
55
+ retryAfter?: number;
56
+ } | {
57
+ type: 'queue';
58
+ queue: ChatQueueItem[];
59
+ paused: boolean;
60
+ } | {
61
+ type: 'dequeued';
62
+ id: number;
63
+ message: string;
64
+ };
65
+ interface ChatClientOptions {
66
+ key: string;
67
+ baseUrl?: string;
68
+ onConfirm?: (req: ConfirmRequest) => boolean | Promise<boolean>;
69
+ onEvent?: (event: ChatClientEvent) => void;
70
+ agent?: EspejoAgent;
71
+ allow?: AgentActionType[];
72
+ fetch?: typeof fetch;
73
+ storage?: Storage | null;
74
+ identity?: ChatIdentity | null;
75
+ }
76
+ interface ChatClient {
77
+ send(message: string): Promise<void>;
78
+ enqueue(message: string): boolean;
79
+ removeQueued(id: number): void;
80
+ editQueued(id: number, message: string): void;
81
+ sendQueuedNow(id: number): Promise<void>;
82
+ clearQueue(): void;
83
+ resumeQueue(): Promise<void>;
84
+ reset(): void;
85
+ abort(): void;
86
+ identify(identity: ChatIdentity | null): void;
87
+ destroy(): void;
88
+ getConfig(): Promise<AgentPublicConfig | null>;
89
+ readonly conversationId: string;
90
+ readonly busy: boolean;
91
+ readonly queue: ChatQueueItem[];
92
+ readonly paused: boolean;
93
+ }
94
+ declare function createChatClient(options: ChatClientOptions): ChatClient;
95
+
96
+ declare const DEFAULT_CHAT_TEXT: {
97
+ open: string;
98
+ title: string;
99
+ close: string;
100
+ newChat: string;
101
+ greeting: string;
102
+ inputLabel: string;
103
+ placeholder: string;
104
+ send: string;
105
+ thinking: string;
106
+ confirmTitle: string;
107
+ allow: string;
108
+ allowAlways: string;
109
+ decline: string;
110
+ allowed: string;
111
+ declined: string;
112
+ confirmHighlight: string;
113
+ confirmScroll: string;
114
+ confirmClick: string;
115
+ confirmClickLink: string;
116
+ confirmFill: string;
117
+ confirmNavigate: string;
118
+ emptyValue: string;
119
+ didHighlight: string;
120
+ didScroll: string;
121
+ didClick: string;
122
+ didFill: string;
123
+ didNavigate: string;
124
+ actionFailed: string;
125
+ errorNoAgent: string;
126
+ errorDailyCap: string;
127
+ errorRateLimited: string;
128
+ errorConversationLimit: string;
129
+ errorBusy: string;
130
+ startOver: string;
131
+ errorNetwork: string;
132
+ errorGeneric: string;
133
+ stop: string;
134
+ presenceNotice: string;
135
+ presenceNoticeNamed: string;
136
+ online: string;
137
+ options: string;
138
+ optionsTitle: string;
139
+ optionsHint: string;
140
+ optionsEmpty: string;
141
+ optionsUnavailable: string;
142
+ anElement: string;
143
+ askFirst: string;
144
+ suggestions: string;
145
+ running: string;
146
+ done: string;
147
+ failed: string;
148
+ actionsCount: string;
149
+ detailTarget: string;
150
+ detailDestination: string;
151
+ detailValue: string;
152
+ nameHighlight: string;
153
+ descHighlight: string;
154
+ nameScroll: string;
155
+ descScroll: string;
156
+ nameClick: string;
157
+ descClick: string;
158
+ nameFill: string;
159
+ descFill: string;
160
+ nameNavigate: string;
161
+ descNavigate: string;
162
+ whyNotAllowed: string;
163
+ whyPrivate: string;
164
+ whyDisabled: string;
165
+ whyGone: string;
166
+ whyOtherSite: string;
167
+ whyDeclined: string;
168
+ whyNotFillable: string;
169
+ whyInvalidValue: string;
170
+ whyGeneric: string;
171
+ queueTitle: string;
172
+ queuePaused: string;
173
+ queueResume: string;
174
+ queueClear: string;
175
+ queueSendNow: string;
176
+ queueEdit: string;
177
+ queueRemove: string;
178
+ queueFull: string;
179
+ tabs: string;
180
+ tabHome: string;
181
+ tabSupport: string;
182
+ tabGuides: string;
183
+ hello: string;
184
+ helpPrompt: string;
185
+ askTitle: string;
186
+ askHint: string;
187
+ continueTitle: string;
188
+ agoNow: string;
189
+ agoMinutes: string;
190
+ agoHours: string;
191
+ agoDays: string;
192
+ searchGuides: string;
193
+ popularGuides: string;
194
+ guidesCount: string;
195
+ guidesCountOne: string;
196
+ guidesLoading: string;
197
+ guidesError: string;
198
+ guidesEmpty: string;
199
+ guidesNoMatch: string;
200
+ askInstead: string;
201
+ retry: string;
202
+ backToGuides: string;
203
+ newTab: string;
204
+ openFullPage: string;
205
+ articleLoading: string;
206
+ articleError: string;
207
+ voteQuestion: string;
208
+ voteYes: string;
209
+ voteNo: string;
210
+ voteThanks: string;
211
+ voteSorry: string;
212
+ voteSorryAssist: string;
213
+ tabTickets: string;
214
+ reportProblem: string;
215
+ ticketsFilter: string;
216
+ filterAll: string;
217
+ filterOpen: string;
218
+ filterResolved: string;
219
+ statusTeam: string;
220
+ statusYou: string;
221
+ statusResolved: string;
222
+ recordingAttached: string;
223
+ ticketsLoading: string;
224
+ ticketsError: string;
225
+ ticketsEmpty: string;
226
+ openTicket: string;
227
+ ticketsWaiting: string;
228
+ };
229
+ type ChatText = typeof DEFAULT_CHAT_TEXT;
230
+ type ChatLang = 'en' | 'es' | 'pt';
231
+ declare function chatTextFor(lang: string | undefined): ChatText;
232
+ interface ActionParts {
233
+ type: string;
234
+ target?: string;
235
+ destination?: string;
236
+ }
237
+ declare function describeAction(TEXT: ChatText, phase: 'confirm' | 'done' | 'failed', a: ActionParts): string;
238
+ declare function describeError(TEXT: ChatText, code: string | undefined): string;
239
+ declare function describeValue(TEXT: ChatText, value: string): string;
240
+
241
+ interface ChatWidgetOptions {
242
+ key: string;
243
+ baseUrl?: string;
244
+ position?: WidgetCorner;
245
+ theme?: WidgetTheme;
246
+ lang?: string;
247
+ title?: string;
248
+ greeting?: string;
249
+ suggestions?: string[];
250
+ text?: Partial<ChatText>;
251
+ agent?: EspejoAgent;
252
+ allow?: AgentActionType[];
253
+ presence?: boolean;
254
+ identity?: ChatIdentity | null;
255
+ fetch?: typeof fetch;
256
+ storage?: Storage | null;
257
+ doc?: Document;
258
+ }
259
+ interface ChatWidgetHandle {
260
+ open(): void;
261
+ close(): void;
262
+ destroy(): void;
263
+ identify(email: string | null, hash?: string): void;
264
+ readonly client: ChatClient;
265
+ }
266
+ declare const CHAT_HOST_ATTRIBUTE = "data-espejo-chat";
267
+ declare function installChatWidget(options: ChatWidgetOptions): ChatWidgetHandle | null;
268
+
269
+ declare const PRESENCE_HOST_ATTRIBUTE = "data-espejo-presence";
270
+ interface PresenceOptions {
271
+ lang?: string;
272
+ text?: Partial<Pick<ChatText, 'presenceNotice' | 'presenceNoticeNamed' | 'stop'>>;
273
+ name?: string;
274
+ theme?: WidgetTheme;
275
+ onStop?: () => void;
276
+ idleMs?: number;
277
+ doc?: Document;
278
+ }
279
+ interface PresenceHandle {
280
+ start(): void;
281
+ end(): void;
282
+ stop(): void;
283
+ destroy(): void;
284
+ readonly active: boolean;
285
+ }
286
+ declare function installPresence(agent: EspejoAgent, options?: PresenceOptions): PresenceHandle | null;
287
+
288
+ export { type ActionParts, CHAT_HOST_ATTRIBUTE, type ChatClient, type ChatClientEvent, type ChatClientOptions, type ChatErrorCode, type ChatIdentity, type ChatLang, type ChatQueueItem, type ChatText, type ChatWidgetHandle, type ChatWidgetOptions, DEFAULT_CHAT_TEXT, PRESENCE_HOST_ATTRIBUTE, type PresenceHandle, type PresenceOptions, chatTextFor, createChatClient, describeAction, describeError, describeValue, installChatWidget, installPresence };
package/dist/chat.d.ts ADDED
@@ -0,0 +1,288 @@
1
+ import { A as AgentActionType, a as AgentToolDefinition, b as ActResult, C as ConfirmRequest, E as EspejoAgent } from './index-Djj7dbiY.js';
2
+ import { W as WidgetCorner, a as WidgetTheme } from './shadow-scaffold-DUJmxf_n.js';
3
+
4
+ interface AgentChatToolCall {
5
+ id: string;
6
+ name: AgentToolDefinition['name'];
7
+ input: Record<string, unknown>;
8
+ }
9
+ type AgentChatErrorCode = 'provider_auth' | 'provider_rate_limited' | 'provider_error' | 'timeout' | 'iteration_limit' | 'internal';
10
+ type AgentWidgetTheme = 'auto' | 'light' | 'dark';
11
+ interface AgentPublicConfig {
12
+ enabled: boolean;
13
+ allowed_actions: AgentActionType[];
14
+ theme: AgentWidgetTheme;
15
+ name: string | null;
16
+ icon: string | null;
17
+ sections: AgentWidgetSection[];
18
+ }
19
+ type AgentWidgetSection = 'home' | 'support' | 'tickets' | 'guides';
20
+
21
+ interface ChatIdentity {
22
+ email: string;
23
+ hash: string;
24
+ }
25
+ interface ChatQueueItem {
26
+ id: number;
27
+ text: string;
28
+ }
29
+ type ChatErrorCode = 'no_agent' | 'daily_cap' | 'rate_limited' | 'conversation_limit' | 'conversation_expired' | 'conversation_busy' | 'identity_changed' | 'conflict' | 'forbidden' | 'bad_request' | 'unavailable' | 'network' | AgentChatErrorCode;
30
+ type ChatClientEvent = {
31
+ type: 'text';
32
+ delta: string;
33
+ } | {
34
+ type: 'tool_start';
35
+ call: AgentChatToolCall;
36
+ label: string;
37
+ target?: string;
38
+ value?: string;
39
+ destination?: string;
40
+ } | {
41
+ type: 'tool';
42
+ call: AgentChatToolCall;
43
+ label: string;
44
+ target?: string;
45
+ value?: string;
46
+ destination?: string;
47
+ result: ActResult;
48
+ } | {
49
+ type: 'done';
50
+ conversationId: string;
51
+ } | {
52
+ type: 'error';
53
+ code: ChatErrorCode;
54
+ message: string;
55
+ retryAfter?: number;
56
+ } | {
57
+ type: 'queue';
58
+ queue: ChatQueueItem[];
59
+ paused: boolean;
60
+ } | {
61
+ type: 'dequeued';
62
+ id: number;
63
+ message: string;
64
+ };
65
+ interface ChatClientOptions {
66
+ key: string;
67
+ baseUrl?: string;
68
+ onConfirm?: (req: ConfirmRequest) => boolean | Promise<boolean>;
69
+ onEvent?: (event: ChatClientEvent) => void;
70
+ agent?: EspejoAgent;
71
+ allow?: AgentActionType[];
72
+ fetch?: typeof fetch;
73
+ storage?: Storage | null;
74
+ identity?: ChatIdentity | null;
75
+ }
76
+ interface ChatClient {
77
+ send(message: string): Promise<void>;
78
+ enqueue(message: string): boolean;
79
+ removeQueued(id: number): void;
80
+ editQueued(id: number, message: string): void;
81
+ sendQueuedNow(id: number): Promise<void>;
82
+ clearQueue(): void;
83
+ resumeQueue(): Promise<void>;
84
+ reset(): void;
85
+ abort(): void;
86
+ identify(identity: ChatIdentity | null): void;
87
+ destroy(): void;
88
+ getConfig(): Promise<AgentPublicConfig | null>;
89
+ readonly conversationId: string;
90
+ readonly busy: boolean;
91
+ readonly queue: ChatQueueItem[];
92
+ readonly paused: boolean;
93
+ }
94
+ declare function createChatClient(options: ChatClientOptions): ChatClient;
95
+
96
+ declare const DEFAULT_CHAT_TEXT: {
97
+ open: string;
98
+ title: string;
99
+ close: string;
100
+ newChat: string;
101
+ greeting: string;
102
+ inputLabel: string;
103
+ placeholder: string;
104
+ send: string;
105
+ thinking: string;
106
+ confirmTitle: string;
107
+ allow: string;
108
+ allowAlways: string;
109
+ decline: string;
110
+ allowed: string;
111
+ declined: string;
112
+ confirmHighlight: string;
113
+ confirmScroll: string;
114
+ confirmClick: string;
115
+ confirmClickLink: string;
116
+ confirmFill: string;
117
+ confirmNavigate: string;
118
+ emptyValue: string;
119
+ didHighlight: string;
120
+ didScroll: string;
121
+ didClick: string;
122
+ didFill: string;
123
+ didNavigate: string;
124
+ actionFailed: string;
125
+ errorNoAgent: string;
126
+ errorDailyCap: string;
127
+ errorRateLimited: string;
128
+ errorConversationLimit: string;
129
+ errorBusy: string;
130
+ startOver: string;
131
+ errorNetwork: string;
132
+ errorGeneric: string;
133
+ stop: string;
134
+ presenceNotice: string;
135
+ presenceNoticeNamed: string;
136
+ online: string;
137
+ options: string;
138
+ optionsTitle: string;
139
+ optionsHint: string;
140
+ optionsEmpty: string;
141
+ optionsUnavailable: string;
142
+ anElement: string;
143
+ askFirst: string;
144
+ suggestions: string;
145
+ running: string;
146
+ done: string;
147
+ failed: string;
148
+ actionsCount: string;
149
+ detailTarget: string;
150
+ detailDestination: string;
151
+ detailValue: string;
152
+ nameHighlight: string;
153
+ descHighlight: string;
154
+ nameScroll: string;
155
+ descScroll: string;
156
+ nameClick: string;
157
+ descClick: string;
158
+ nameFill: string;
159
+ descFill: string;
160
+ nameNavigate: string;
161
+ descNavigate: string;
162
+ whyNotAllowed: string;
163
+ whyPrivate: string;
164
+ whyDisabled: string;
165
+ whyGone: string;
166
+ whyOtherSite: string;
167
+ whyDeclined: string;
168
+ whyNotFillable: string;
169
+ whyInvalidValue: string;
170
+ whyGeneric: string;
171
+ queueTitle: string;
172
+ queuePaused: string;
173
+ queueResume: string;
174
+ queueClear: string;
175
+ queueSendNow: string;
176
+ queueEdit: string;
177
+ queueRemove: string;
178
+ queueFull: string;
179
+ tabs: string;
180
+ tabHome: string;
181
+ tabSupport: string;
182
+ tabGuides: string;
183
+ hello: string;
184
+ helpPrompt: string;
185
+ askTitle: string;
186
+ askHint: string;
187
+ continueTitle: string;
188
+ agoNow: string;
189
+ agoMinutes: string;
190
+ agoHours: string;
191
+ agoDays: string;
192
+ searchGuides: string;
193
+ popularGuides: string;
194
+ guidesCount: string;
195
+ guidesCountOne: string;
196
+ guidesLoading: string;
197
+ guidesError: string;
198
+ guidesEmpty: string;
199
+ guidesNoMatch: string;
200
+ askInstead: string;
201
+ retry: string;
202
+ backToGuides: string;
203
+ newTab: string;
204
+ openFullPage: string;
205
+ articleLoading: string;
206
+ articleError: string;
207
+ voteQuestion: string;
208
+ voteYes: string;
209
+ voteNo: string;
210
+ voteThanks: string;
211
+ voteSorry: string;
212
+ voteSorryAssist: string;
213
+ tabTickets: string;
214
+ reportProblem: string;
215
+ ticketsFilter: string;
216
+ filterAll: string;
217
+ filterOpen: string;
218
+ filterResolved: string;
219
+ statusTeam: string;
220
+ statusYou: string;
221
+ statusResolved: string;
222
+ recordingAttached: string;
223
+ ticketsLoading: string;
224
+ ticketsError: string;
225
+ ticketsEmpty: string;
226
+ openTicket: string;
227
+ ticketsWaiting: string;
228
+ };
229
+ type ChatText = typeof DEFAULT_CHAT_TEXT;
230
+ type ChatLang = 'en' | 'es' | 'pt';
231
+ declare function chatTextFor(lang: string | undefined): ChatText;
232
+ interface ActionParts {
233
+ type: string;
234
+ target?: string;
235
+ destination?: string;
236
+ }
237
+ declare function describeAction(TEXT: ChatText, phase: 'confirm' | 'done' | 'failed', a: ActionParts): string;
238
+ declare function describeError(TEXT: ChatText, code: string | undefined): string;
239
+ declare function describeValue(TEXT: ChatText, value: string): string;
240
+
241
+ interface ChatWidgetOptions {
242
+ key: string;
243
+ baseUrl?: string;
244
+ position?: WidgetCorner;
245
+ theme?: WidgetTheme;
246
+ lang?: string;
247
+ title?: string;
248
+ greeting?: string;
249
+ suggestions?: string[];
250
+ text?: Partial<ChatText>;
251
+ agent?: EspejoAgent;
252
+ allow?: AgentActionType[];
253
+ presence?: boolean;
254
+ identity?: ChatIdentity | null;
255
+ fetch?: typeof fetch;
256
+ storage?: Storage | null;
257
+ doc?: Document;
258
+ }
259
+ interface ChatWidgetHandle {
260
+ open(): void;
261
+ close(): void;
262
+ destroy(): void;
263
+ identify(email: string | null, hash?: string): void;
264
+ readonly client: ChatClient;
265
+ }
266
+ declare const CHAT_HOST_ATTRIBUTE = "data-espejo-chat";
267
+ declare function installChatWidget(options: ChatWidgetOptions): ChatWidgetHandle | null;
268
+
269
+ declare const PRESENCE_HOST_ATTRIBUTE = "data-espejo-presence";
270
+ interface PresenceOptions {
271
+ lang?: string;
272
+ text?: Partial<Pick<ChatText, 'presenceNotice' | 'presenceNoticeNamed' | 'stop'>>;
273
+ name?: string;
274
+ theme?: WidgetTheme;
275
+ onStop?: () => void;
276
+ idleMs?: number;
277
+ doc?: Document;
278
+ }
279
+ interface PresenceHandle {
280
+ start(): void;
281
+ end(): void;
282
+ stop(): void;
283
+ destroy(): void;
284
+ readonly active: boolean;
285
+ }
286
+ declare function installPresence(agent: EspejoAgent, options?: PresenceOptions): PresenceHandle | null;
287
+
288
+ export { type ActionParts, CHAT_HOST_ATTRIBUTE, type ChatClient, type ChatClientEvent, type ChatClientOptions, type ChatErrorCode, type ChatIdentity, type ChatLang, type ChatQueueItem, type ChatText, type ChatWidgetHandle, type ChatWidgetOptions, DEFAULT_CHAT_TEXT, PRESENCE_HOST_ATTRIBUTE, type PresenceHandle, type PresenceOptions, chatTextFor, createChatClient, describeAction, describeError, describeValue, installChatWidget, installPresence };