@dabalabs/agent 0.0.1-beta → 0.0.4-beta
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 +56 -3
- package/dist/chunk-3BQ6LE6X.cjs +222 -0
- package/dist/chunk-3BQ6LE6X.cjs.map +1 -0
- package/dist/chunk-ETI4LRM7.js +5936 -0
- package/dist/chunk-ETI4LRM7.js.map +1 -0
- package/dist/chunk-TYOHYQDK.js +220 -0
- package/dist/chunk-TYOHYQDK.js.map +1 -0
- package/dist/chunk-VAIC5ACS.cjs +5939 -0
- package/dist/chunk-VAIC5ACS.cjs.map +1 -0
- package/dist/custom-element.cjs +4 -4
- package/dist/custom-element.d.cts +191 -2
- package/dist/custom-element.d.ts +191 -2
- package/dist/custom-element.js +2 -2
- package/dist/daba-agent.cjs +5 -14
- package/dist/daba-agent.d.cts +2 -4
- package/dist/daba-agent.d.ts +2 -4
- package/dist/daba-agent.js +2 -3
- package/dist/daba-agent.min.js +1847 -215
- package/dist/daba-agent.min.js.map +1 -1
- package/dist/react.cjs +41 -14
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +38 -2
- package/dist/react.js.map +1 -1
- package/dist/types-BQRgqD4n.d.cts +305 -0
- package/dist/types-BQRgqD4n.d.ts +305 -0
- package/package.json +2 -2
- package/dist/chunk-EF6D33VT.cjs +0 -103
- package/dist/chunk-EF6D33VT.cjs.map +0 -1
- package/dist/chunk-G22V7GGM.js +0 -1667
- package/dist/chunk-G22V7GGM.js.map +0 -1
- package/dist/chunk-N4TBGDUO.cjs +0 -1669
- package/dist/chunk-N4TBGDUO.cjs.map +0 -1
- package/dist/chunk-QM6HDEVV.js +0 -39
- package/dist/chunk-QM6HDEVV.js.map +0 -1
- package/dist/chunk-WJQ444GI.js +0 -100
- package/dist/chunk-WJQ444GI.js.map +0 -1
- package/dist/chunk-ZXZX2D55.cjs +0 -45
- package/dist/chunk-ZXZX2D55.cjs.map +0 -1
- package/dist/custom-element-CpPr7b2Z.d.ts +0 -66
- package/dist/custom-element-XiZg8UN8.d.cts +0 -66
- package/dist/types-DYRGPzyp.d.cts +0 -76
- package/dist/types-DYRGPzyp.d.ts +0 -76
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which deployment tier this widget talks to.
|
|
3
|
+
*
|
|
4
|
+
* Production is the default in every direction: an embed that says
|
|
5
|
+
* nothing about its environment is a customer's live site, and the one
|
|
6
|
+
* outcome worth engineering against is a production page silently
|
|
7
|
+
* pointing at staging. So the mapping is deliberately asymmetric —
|
|
8
|
+
* "staging" must be asked for by name, and anything else resolves to
|
|
9
|
+
* production.
|
|
10
|
+
*/
|
|
11
|
+
type DabaEnvironment = "production" | "staging";
|
|
12
|
+
|
|
13
|
+
type DabaVoiceEngine = "realtime" | "live";
|
|
14
|
+
type DabaErrorKind = "invalid_key" | "origin_not_allowed" | "not_found" | "network" | "restricted";
|
|
15
|
+
interface DabaError {
|
|
16
|
+
kind: DabaErrorKind;
|
|
17
|
+
message: string;
|
|
18
|
+
}
|
|
19
|
+
/** "listening" = mic capturing, "thinking" = waiting on a model turn,
|
|
20
|
+
* "speaking" = agent audio playing back, "idle" = session not active.
|
|
21
|
+
* Text chat uses "thinking" and "idle" only — it never opens a mic. */
|
|
22
|
+
type DabaAgentStatus = "idle" | "connecting" | "listening" | "thinking" | "speaking";
|
|
23
|
+
/** Which viewport corner the default floating badge is pinned to. Only
|
|
24
|
+
* applies to the default badge (no custom `container`) — a host handing
|
|
25
|
+
* in its own `container` owns that element's placement entirely. */
|
|
26
|
+
type DabaAgentPosition = "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
27
|
+
/**
|
|
28
|
+
* Which media the assistant offers.
|
|
29
|
+
*
|
|
30
|
+
* - "voice" — talk only. Badge click starts/stops a Realtime session.
|
|
31
|
+
* - "chat" — type only. No microphone is ever requested.
|
|
32
|
+
* - "hybrid" — both, in one panel, sharing one transcript.
|
|
33
|
+
*
|
|
34
|
+
* These are genuinely independent transports, not one feature with a
|
|
35
|
+
* switch: chat is a plain HTTP turn against the gateway, voice is a
|
|
36
|
+
* Realtime WebSocket with a mic. A visitor in "chat" mode never grants
|
|
37
|
+
* microphone permission and never costs a voice minute.
|
|
38
|
+
*/
|
|
39
|
+
type DabaAgentMode = "hybrid" | "voice" | "chat";
|
|
40
|
+
/** Text direction of the widget's own chrome. "auto" reads the host
|
|
41
|
+
* page's `dir`/`lang`, which is what makes the panel flip to RTL on an
|
|
42
|
+
* Arabic site without the integrator configuring anything. */
|
|
43
|
+
type DabaDirection = "auto" | "ltr" | "rtl";
|
|
44
|
+
type DabaThemePreference = "auto" | "light" | "dark";
|
|
45
|
+
type DabaLauncherShape = "rounded" | "circle" | "pill";
|
|
46
|
+
/** What a card is about. Drives the icon, the accent and which fields the
|
|
47
|
+
* card bothers to render — an event shows a date and a map link, an
|
|
48
|
+
* article shows a date and a read-more link. Unknown kinds render as
|
|
49
|
+
* "page", never as nothing. */
|
|
50
|
+
type DabaCardKind = "article" | "event" | "news" | "page" | "contact" | "action";
|
|
51
|
+
interface DabaCardMeta {
|
|
52
|
+
label: string;
|
|
53
|
+
value: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* One structured item in a reply — an event, an article, a news item.
|
|
57
|
+
*
|
|
58
|
+
* The gateway builds and sanitises these (see routes/public_agents.rs::
|
|
59
|
+
* sanitize_cards): `mapUrl` is always constructed server-side from the
|
|
60
|
+
* address, and `url`/`imageUrl` are dropped unless they point at the
|
|
61
|
+
* site the widget is embedded in. So the widget can render every field
|
|
62
|
+
* here without re-validating it.
|
|
63
|
+
*/
|
|
64
|
+
interface DabaCard {
|
|
65
|
+
kind: DabaCardKind;
|
|
66
|
+
title: string;
|
|
67
|
+
summary?: string | null;
|
|
68
|
+
/** ISO-8601 date or datetime. Formatted for display with `Intl` in the
|
|
69
|
+
* resolved UI locale, so an Arabic panel shows an Arabic date. */
|
|
70
|
+
date?: string | null;
|
|
71
|
+
endDate?: string | null;
|
|
72
|
+
locationName?: string | null;
|
|
73
|
+
address?: string | null;
|
|
74
|
+
/** Always gateway-built from the address — never whatever the model said. */
|
|
75
|
+
mapUrl?: string | null;
|
|
76
|
+
url?: string | null;
|
|
77
|
+
imageUrl?: string | null;
|
|
78
|
+
sourcePath?: string | null;
|
|
79
|
+
meta?: DabaCardMeta[];
|
|
80
|
+
}
|
|
81
|
+
interface ChatMessage {
|
|
82
|
+
id: string;
|
|
83
|
+
role: "user" | "agent" | "system";
|
|
84
|
+
text: string;
|
|
85
|
+
timestamp: number;
|
|
86
|
+
isFinal?: boolean;
|
|
87
|
+
cards?: DabaCard[];
|
|
88
|
+
suggestions?: string[];
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Colour and shape overrides. Every field is optional and every absent
|
|
92
|
+
* field falls back to the DabaLabs brand kit, so `{}` is a complete,
|
|
93
|
+
* correct theme rather than an empty one.
|
|
94
|
+
*/
|
|
95
|
+
interface DabaTheme {
|
|
96
|
+
accentColor?: string;
|
|
97
|
+
/** Text/icon colour drawn ON the accent. Defaults to white; a site with
|
|
98
|
+
* a pale accent needs to be able to say "ink", or its buttons are
|
|
99
|
+
* illegible. */
|
|
100
|
+
accentContrast?: string;
|
|
101
|
+
surfaceColor?: string;
|
|
102
|
+
textColor?: string;
|
|
103
|
+
mutedColor?: string;
|
|
104
|
+
borderColor?: string;
|
|
105
|
+
/** Any CSS length — "18px", "0", "1.5rem". */
|
|
106
|
+
radius?: string;
|
|
107
|
+
fontFamily?: string;
|
|
108
|
+
theme?: DabaThemePreference;
|
|
109
|
+
}
|
|
110
|
+
/** The panel shown on first open, before anybody has said anything. */
|
|
111
|
+
interface DabaIntro {
|
|
112
|
+
enabled?: boolean;
|
|
113
|
+
headline?: string | null;
|
|
114
|
+
subheadline?: string | null;
|
|
115
|
+
/** A short looping video or a still. Same-origin or https. */
|
|
116
|
+
mediaUrl?: string | null;
|
|
117
|
+
mediaType?: "video" | "image" | "none";
|
|
118
|
+
/** Tappable starter questions. These are what turn an empty box into an
|
|
119
|
+
* obvious next action, and they are the single biggest lever on whether
|
|
120
|
+
* a visitor ever sends a first message. */
|
|
121
|
+
suggestedPrompts?: string[];
|
|
122
|
+
}
|
|
123
|
+
interface DabaLauncher {
|
|
124
|
+
shape?: DabaLauncherShape;
|
|
125
|
+
/** Replaces the shipped mark entirely. Use for a customer's own logo. */
|
|
126
|
+
iconUrl?: string | null;
|
|
127
|
+
/**
|
|
128
|
+
* The mark as inline SVG markup rather than a URL.
|
|
129
|
+
*
|
|
130
|
+
* Wins over `iconUrl`. Worth preferring on a site with a strict
|
|
131
|
+
* Content-Security-Policy, where `img-src 'self'` blocks an <img> at
|
|
132
|
+
* someone else's CDN and the launcher would render empty; inline markup
|
|
133
|
+
* has no such dependency and can inherit `currentColor`. Script, event
|
|
134
|
+
* handlers and external references are stripped before it is inserted.
|
|
135
|
+
*/
|
|
136
|
+
iconSvg?: string | null;
|
|
137
|
+
/** An emoji or a letter or two, drawn as the mark. Wins over `iconUrl`,
|
|
138
|
+
* loses to `iconSvg`. */
|
|
139
|
+
iconText?: string | null;
|
|
140
|
+
/** Text beside the icon, turning the badge into a labelled pill. */
|
|
141
|
+
label?: string | null;
|
|
142
|
+
/** The launcher button itself, as any CSS length. Default "56px" — or
|
|
143
|
+
* "52px" below 480px wide, which an explicit value overrides on phones
|
|
144
|
+
* too. */
|
|
145
|
+
size?: string | number;
|
|
146
|
+
/** The mark inside the button, as any CSS length. Default "100%", so it
|
|
147
|
+
* fills the button; a wordmark with its own whitespace usually wants
|
|
148
|
+
* less. */
|
|
149
|
+
iconSize?: string | number;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The chat panel's own box.
|
|
153
|
+
*
|
|
154
|
+
* Separate from `launcher` because "width and height" is ambiguous
|
|
155
|
+
* between the two, and an integrator who meant the panel and got the
|
|
156
|
+
* button has no way to tell from the option name.
|
|
157
|
+
*
|
|
158
|
+
* Ignored below 480px wide, where the panel goes full-screen: a fixed
|
|
159
|
+
* width on a phone either overflows the viewport or leaves a gutter.
|
|
160
|
+
*/
|
|
161
|
+
interface DabaPanel {
|
|
162
|
+
/** Any CSS length. Default "400px". */
|
|
163
|
+
width?: string | number;
|
|
164
|
+
/** Any CSS length. Default "740px". Still clamped to the viewport, so a
|
|
165
|
+
* value taller than the window does not push the launcher off-screen. */
|
|
166
|
+
height?: string | number;
|
|
167
|
+
}
|
|
168
|
+
interface DabaAgentOptions {
|
|
169
|
+
projectId: string;
|
|
170
|
+
apiKey: string;
|
|
171
|
+
/** Overrides `env` when both are given — the only option that can name
|
|
172
|
+
* a host neither tier covers (self-hosted, a local gateway). */
|
|
173
|
+
gatewayUrl?: string;
|
|
174
|
+
/** Which DabaLabs tier to talk to. Omit for production; pass "staging"
|
|
175
|
+
* to point the agent at the staging gateway. */
|
|
176
|
+
env?: DabaEnvironment;
|
|
177
|
+
/** Where to mount the widget. Defaults to a fixed-position element
|
|
178
|
+
* appended to <body> when omitted. */
|
|
179
|
+
container?: string | HTMLElement;
|
|
180
|
+
/** Corner of the viewport the default badge is fixed to. */
|
|
181
|
+
position?: DabaAgentPosition;
|
|
182
|
+
/**
|
|
183
|
+
* Everything below is an OVERRIDE of what the project already carries.
|
|
184
|
+
*
|
|
185
|
+
* The gateway serves a project's mode, theme, intro and locale from
|
|
186
|
+
* `GET /v1/public/agents/:id`, so an owner restyles their assistant
|
|
187
|
+
* from the dashboard and every embed picks it up on next load. An
|
|
188
|
+
* option passed here wins over the served value — an integrator who
|
|
189
|
+
* hard-codes a colour means it.
|
|
190
|
+
*
|
|
191
|
+
* Undefined is not "default", it is "defer to the server". That
|
|
192
|
+
* distinction is what makes remote configuration work at all.
|
|
193
|
+
*/
|
|
194
|
+
mode?: DabaAgentMode;
|
|
195
|
+
voiceEngine?: DabaVoiceEngine;
|
|
196
|
+
theme?: DabaTheme;
|
|
197
|
+
intro?: DabaIntro;
|
|
198
|
+
launcher?: DabaLauncher;
|
|
199
|
+
panel?: DabaPanel;
|
|
200
|
+
/** Brand logo shown in the panel header. */
|
|
201
|
+
logoUrl?: string | null;
|
|
202
|
+
/** The header logo as inline SVG markup. Wins over `logoUrl`; same CSP
|
|
203
|
+
* reasoning as `launcher.iconSvg`. */
|
|
204
|
+
logoSvg?: string | null;
|
|
205
|
+
/** BCP-47 code for the widget's own chrome, or "auto" to follow the
|
|
206
|
+
* host page's `lang`. Independent of what the assistant replies in —
|
|
207
|
+
* it always answers in the visitor's language regardless. */
|
|
208
|
+
uiLanguage?: string;
|
|
209
|
+
direction?: DabaDirection;
|
|
210
|
+
accentColor?: string;
|
|
211
|
+
/** Recolour the trigger icon's background substrate (the colour under
|
|
212
|
+
* the grain/noise texture). Defaults to the icon's shipped green. */
|
|
213
|
+
iconBackgroundColor?: string;
|
|
214
|
+
/** Recolour the trigger icon's centre mark (the face/mask shape). */
|
|
215
|
+
iconMarkColor?: string;
|
|
216
|
+
/** Header title displayed in the chat window. Defaults to the project's
|
|
217
|
+
* title, then to a localised "AI Assistant". */
|
|
218
|
+
title?: string;
|
|
219
|
+
placeholder?: string;
|
|
220
|
+
/** Whether the chat popover starts open. */
|
|
221
|
+
initialOpen?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Keep past conversations in this browser, so a visitor can go back to
|
|
224
|
+
* one — a history button appears in the panel header once there is
|
|
225
|
+
* something in it.
|
|
226
|
+
*
|
|
227
|
+
* OFF unless you pass `true`. The live transcript is sessionStorage and
|
|
228
|
+
* dies with the tab on purpose ("a conversation is a visit, not an
|
|
229
|
+
* identity"); an archive is localStorage and outlives it, which on a
|
|
230
|
+
* shared or public machine is a decision an embed has to make
|
|
231
|
+
* deliberately rather than inherit. Nothing is sent to the gateway, and
|
|
232
|
+
* the visitor can delete any thread or clear the lot from the panel.
|
|
233
|
+
*/
|
|
234
|
+
historyEnabled?: boolean;
|
|
235
|
+
/**
|
|
236
|
+
* Keyboard shortcut that opens and closes the assistant.
|
|
237
|
+
*
|
|
238
|
+
* A combination — `"ctrl+space"`, `"alt+k"` — or a modifier held on its
|
|
239
|
+
* own: `"hold:ctrl"`, and likewise `hold:alt`, `hold:shift`, `hold:meta`.
|
|
240
|
+
* A held modifier fires after about half a second and is abandoned the
|
|
241
|
+
* moment another key joins it, so `Ctrl+C` never opens the widget.
|
|
242
|
+
*
|
|
243
|
+
* Defaults per platform: `alt+space` on macOS, where the OS binds
|
|
244
|
+
* Ctrl+Space to the input-source switcher, and `ctrl+space` elsewhere.
|
|
245
|
+
* `null` disables the shortcut entirely.
|
|
246
|
+
*/
|
|
247
|
+
hotkey?: string | null;
|
|
248
|
+
onError?: (error: DabaError) => void;
|
|
249
|
+
onStatusChange?: (status: DabaAgentStatus) => void;
|
|
250
|
+
/** Fired for both user speech/text and agent reply deltas. */
|
|
251
|
+
onTranscript?: (role: "user" | "agent", text: string, isFinal: boolean) => void;
|
|
252
|
+
onChatToggle?: (isOpen: boolean) => void;
|
|
253
|
+
/** Fired once per reply that carried structured items. */
|
|
254
|
+
onCards?: (cards: DabaCard[]) => void;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* What the gateway serves for a project. Mirrors the JSON of
|
|
258
|
+
* `GET /v1/public/agents/:id` with keys camelised; every field is present
|
|
259
|
+
* because the gateway fills its own defaults before responding.
|
|
260
|
+
*/
|
|
261
|
+
interface DabaRemoteConfig {
|
|
262
|
+
projectId: string;
|
|
263
|
+
title: string;
|
|
264
|
+
greetingMessage: string | null;
|
|
265
|
+
mode: DabaAgentMode;
|
|
266
|
+
voiceEngine?: DabaVoiceEngine;
|
|
267
|
+
appearance: {
|
|
268
|
+
accentColor: string | null;
|
|
269
|
+
accentContrast: string | null;
|
|
270
|
+
surfaceColor: string | null;
|
|
271
|
+
textColor: string | null;
|
|
272
|
+
radius: string | null;
|
|
273
|
+
fontFamily: string | null;
|
|
274
|
+
logoUrl: string | null;
|
|
275
|
+
launcherIconUrl: string | null;
|
|
276
|
+
launcherLabel: string | null;
|
|
277
|
+
launcherShape: DabaLauncherShape;
|
|
278
|
+
position: DabaAgentPosition | null;
|
|
279
|
+
theme: DabaThemePreference;
|
|
280
|
+
};
|
|
281
|
+
intro: {
|
|
282
|
+
enabled: boolean;
|
|
283
|
+
headline: string | null;
|
|
284
|
+
subheadline: string | null;
|
|
285
|
+
mediaUrl: string | null;
|
|
286
|
+
mediaType: "video" | "image" | "none";
|
|
287
|
+
suggestedPrompts: string[];
|
|
288
|
+
};
|
|
289
|
+
locale: {
|
|
290
|
+
uiLanguage: string;
|
|
291
|
+
direction: DabaDirection;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/** One text turn, as the chat endpoint returns it. */
|
|
295
|
+
interface DabaChatReply {
|
|
296
|
+
reply: string;
|
|
297
|
+
language: string;
|
|
298
|
+
cards: DabaCard[];
|
|
299
|
+
/** Follow-up questions the assistant thinks are likely next. Rendered as
|
|
300
|
+
* tappable chips under the reply; tapping one sends it. */
|
|
301
|
+
suggestions: string[];
|
|
302
|
+
conversationId: string;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export type { ChatMessage as C, DabaAgentOptions as D, DabaAgentStatus as a, DabaAgentMode as b, DabaAgentPosition as c, DabaCard as d, DabaCardKind as e, DabaCardMeta as f, DabaChatReply as g, DabaDirection as h, DabaError as i, DabaIntro as j, DabaLauncher as k, DabaLauncherShape as l, DabaPanel as m, DabaRemoteConfig as n, DabaTheme as o, DabaThemePreference as p, DabaVoiceEngine as q };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dabalabs/agent",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Embeddable voice AI website assistant widget for dabalabs projects
|
|
3
|
+
"version": "0.0.4-beta",
|
|
4
|
+
"description": "Embeddable voice AI website assistant widget for dabalabs projects — press Ctrl+Space, talk to your site.",
|
|
5
5
|
"author": "dabalabs",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://dabalabs.com",
|
package/dist/chunk-EF6D33VT.cjs
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkN4TBGDUO_cjs = require('./chunk-N4TBGDUO.cjs');
|
|
4
|
-
|
|
5
|
-
// src/components/custom-element.ts
|
|
6
|
-
var DabaAgentElement = class extends HTMLElement {
|
|
7
|
-
constructor() {
|
|
8
|
-
super(...arguments);
|
|
9
|
-
this.agent = null;
|
|
10
|
-
}
|
|
11
|
-
connectedCallback() {
|
|
12
|
-
if (this.agent) return;
|
|
13
|
-
const getAttr = (name) => this.getAttribute(name) ?? this.getAttribute(`data-${name}`);
|
|
14
|
-
const projectId = getAttr("project-id");
|
|
15
|
-
const apiKey = getAttr("api-key");
|
|
16
|
-
if (!projectId || !apiKey) {
|
|
17
|
-
console.error(
|
|
18
|
-
"daba-agent: <daba-agent> custom element requires project-id and api-key attributes.",
|
|
19
|
-
this
|
|
20
|
-
);
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const position = getAttr("position") ?? void 0;
|
|
24
|
-
const accentColor = getAttr("accent-color") ?? void 0;
|
|
25
|
-
const mode = getAttr("mode") ?? void 0;
|
|
26
|
-
const title = getAttr("title") ?? void 0;
|
|
27
|
-
const placeholder = getAttr("placeholder") ?? void 0;
|
|
28
|
-
const initialOpen = this.hasAttribute("initial-open") || this.hasAttribute("data-initial-open");
|
|
29
|
-
const hotkey = getAttr("hotkey") ?? void 0;
|
|
30
|
-
const gatewayUrl = getAttr("gateway-url") ?? void 0;
|
|
31
|
-
this.agent = new chunkN4TBGDUO_cjs.DabaAgent({
|
|
32
|
-
container: this,
|
|
33
|
-
projectId,
|
|
34
|
-
apiKey,
|
|
35
|
-
position,
|
|
36
|
-
accentColor,
|
|
37
|
-
mode,
|
|
38
|
-
title,
|
|
39
|
-
placeholder,
|
|
40
|
-
initialOpen,
|
|
41
|
-
hotkey,
|
|
42
|
-
gatewayUrl,
|
|
43
|
-
onStatusChange: (status) => {
|
|
44
|
-
this.dispatchEvent(
|
|
45
|
-
new CustomEvent("daba-status-change", { detail: { status }, bubbles: true, composed: true })
|
|
46
|
-
);
|
|
47
|
-
},
|
|
48
|
-
onTranscript: (role, text, isFinal) => {
|
|
49
|
-
this.dispatchEvent(
|
|
50
|
-
new CustomEvent("daba-transcript", {
|
|
51
|
-
detail: { role, text, isFinal },
|
|
52
|
-
bubbles: true,
|
|
53
|
-
composed: true
|
|
54
|
-
})
|
|
55
|
-
);
|
|
56
|
-
},
|
|
57
|
-
onError: (error) => {
|
|
58
|
-
this.dispatchEvent(
|
|
59
|
-
new CustomEvent("daba-error", { detail: { error }, bubbles: true, composed: true })
|
|
60
|
-
);
|
|
61
|
-
},
|
|
62
|
-
onChatToggle: (isOpen) => {
|
|
63
|
-
this.dispatchEvent(
|
|
64
|
-
new CustomEvent("daba-chat-toggle", { detail: { isOpen }, bubbles: true, composed: true })
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
disconnectedCallback() {
|
|
70
|
-
if (this.agent) {
|
|
71
|
-
this.agent.destroy();
|
|
72
|
-
this.agent = null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
get dabaAgent() {
|
|
76
|
-
return this.agent;
|
|
77
|
-
}
|
|
78
|
-
sendText(text) {
|
|
79
|
-
return this.agent?.sendText(text);
|
|
80
|
-
}
|
|
81
|
-
openChat() {
|
|
82
|
-
this.agent?.openChat();
|
|
83
|
-
}
|
|
84
|
-
closeChat() {
|
|
85
|
-
this.agent?.closeChat();
|
|
86
|
-
}
|
|
87
|
-
toggleChat() {
|
|
88
|
-
this.agent?.toggleChat();
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
function defineDabaAgentElement(tagName = "daba-agent") {
|
|
92
|
-
if (typeof window !== "undefined" && typeof customElements !== "undefined") {
|
|
93
|
-
if (!customElements.get(tagName)) {
|
|
94
|
-
customElements.define(tagName, DabaAgentElement);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
defineDabaAgentElement();
|
|
99
|
-
|
|
100
|
-
exports.DabaAgentElement = DabaAgentElement;
|
|
101
|
-
exports.defineDabaAgentElement = defineDabaAgentElement;
|
|
102
|
-
//# sourceMappingURL=chunk-EF6D33VT.cjs.map
|
|
103
|
-
//# sourceMappingURL=chunk-EF6D33VT.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/custom-element.ts"],"names":["DabaAgent"],"mappings":";;;;;AAGO,IAAM,gBAAA,GAAN,cAA+B,WAAA,CAAY;AAAA,EAA3C,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA;AACL,IAAA,IAAA,CAAQ,KAAA,GAA0B,IAAA;AAAA,EAAA;AAAA,EAElC,iBAAA,GAA0B;AACxB,IAAA,IAAI,KAAK,KAAA,EAAO;AAEhB,IAAA,MAAM,OAAA,GAAU,CAAC,IAAA,KACf,IAAA,CAAK,YAAA,CAAa,IAAI,CAAA,IAAK,IAAA,CAAK,YAAA,CAAa,CAAA,KAAA,EAAQ,IAAI,CAAA,CAAE,CAAA;AAE7D,IAAA,MAAM,SAAA,GAAY,QAAQ,YAAY,CAAA;AACtC,IAAA,MAAM,MAAA,GAAS,QAAQ,SAAS,CAAA;AAEhC,IAAA,IAAI,CAAC,SAAA,IAAa,CAAC,MAAA,EAAQ;AACzB,MAAA,OAAA,CAAQ,KAAA;AAAA,QACN,qFAAA;AAAA,QACA;AAAA,OACF;AACA,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,QAAA,GAAY,OAAA,CAAQ,UAAU,CAAA,IAA2B,MAAA;AAC/D,IAAA,MAAM,WAAA,GAAc,OAAA,CAAQ,cAAc,CAAA,IAAK,MAAA;AAC/C,IAAA,MAAM,IAAA,GAAQ,OAAA,CAAQ,MAAM,CAAA,IAAuB,MAAA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e,MAAA,CAAO,SAAS,gBAAgB,CAAA;AAAA,IACjD;AAAA,EACF;AACF;AAEA,sBAAA,EAAuB","file":"chunk-EF6D33VT.cjs","sourcesContent":["import { DabaAgent } from \"../agent\";\nimport type { DabaAgentPosition, DabaAgentMode } from \"../types\";\n\nexport class DabaAgentElement extends HTMLElement {\n private agent: DabaAgent | null = null;\n\n connectedCallback(): void {\n if (this.agent) return;\n\n const getAttr = (name: string): string | null =>\n this.getAttribute(name) ?? this.getAttribute(`data-${name}`);\n\n const projectId = getAttr(\"project-id\");\n const apiKey = getAttr(\"api-key\");\n\n if (!projectId || !apiKey) {\n console.error(\n \"daba-agent: <daba-agent> custom element requires project-id and api-key attributes.\",\n this,\n );\n return;\n }\n\n const position = (getAttr(\"position\") as DabaAgentPosition) ?? undefined;\n const accentColor = getAttr(\"accent-color\") ?? undefined;\n const mode = (getAttr(\"mode\") as DabaAgentMode) ?? undefined;\n const title = getAttr(\"title\") ?? undefined;\n const placeholder = getAttr(\"placeholder\") ?? undefined;\n const initialOpen = this.hasAttribute(\"initial-open\") || this.hasAttribute(\"data-initial-open\");\n const hotkey = getAttr(\"hotkey\") ?? undefined;\n const gatewayUrl = getAttr(\"gateway-url\") ?? undefined;\n\n this.agent = new DabaAgent({\n container: this,\n projectId,\n apiKey,\n position,\n accentColor,\n mode,\n title,\n placeholder,\n initialOpen,\n hotkey,\n gatewayUrl,\n onStatusChange: (status) => {\n this.dispatchEvent(\n new CustomEvent(\"daba-status-change\", { detail: { status }, bubbles: true, composed: true }),\n );\n },\n onTranscript: (role, text, isFinal) => {\n this.dispatchEvent(\n new CustomEvent(\"daba-transcript\", {\n detail: { role, text, isFinal },\n bubbles: true,\n composed: true,\n }),\n );\n },\n onError: (error) => {\n this.dispatchEvent(\n new CustomEvent(\"daba-error\", { detail: { error }, bubbles: true, composed: true }),\n );\n },\n onChatToggle: (isOpen) => {\n this.dispatchEvent(\n new CustomEvent(\"daba-chat-toggle\", { detail: { isOpen }, bubbles: true, composed: true }),\n );\n },\n });\n }\n\n disconnectedCallback(): void {\n if (this.agent) {\n this.agent.destroy();\n this.agent = null;\n }\n }\n\n public get dabaAgent(): DabaAgent | null {\n return this.agent;\n }\n\n public sendText(text: string): Promise<void> | undefined {\n return this.agent?.sendText(text);\n }\n\n public openChat(): void {\n this.agent?.openChat();\n }\n\n public closeChat(): void {\n this.agent?.closeChat();\n }\n\n public toggleChat(): void {\n this.agent?.toggleChat();\n }\n}\n\nexport function defineDabaAgentElement(tagName = \"daba-agent\"): void {\n if (typeof window !== \"undefined\" && typeof customElements !== \"undefined\") {\n if (!customElements.get(tagName)) {\n customElements.define(tagName, DabaAgentElement);\n }\n }\n}\n\ndefineDabaAgentElement();\n"]}
|