@dabalabs/agent 0.0.1-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 +193 -0
- package/custom-element.d.ts +1 -0
- package/custom-element.js +1 -0
- package/dist/chunk-EF6D33VT.cjs +103 -0
- package/dist/chunk-EF6D33VT.cjs.map +1 -0
- package/dist/chunk-G22V7GGM.js +1667 -0
- package/dist/chunk-G22V7GGM.js.map +1 -0
- package/dist/chunk-N4TBGDUO.cjs +1669 -0
- package/dist/chunk-N4TBGDUO.cjs.map +1 -0
- package/dist/chunk-QM6HDEVV.js +39 -0
- package/dist/chunk-QM6HDEVV.js.map +1 -0
- package/dist/chunk-WJQ444GI.js +100 -0
- package/dist/chunk-WJQ444GI.js.map +1 -0
- package/dist/chunk-ZXZX2D55.cjs +45 -0
- package/dist/chunk-ZXZX2D55.cjs.map +1 -0
- package/dist/custom-element-CpPr7b2Z.d.ts +66 -0
- package/dist/custom-element-XiZg8UN8.d.cts +66 -0
- package/dist/custom-element.cjs +17 -0
- package/dist/custom-element.cjs.map +1 -0
- package/dist/custom-element.d.cts +2 -0
- package/dist/custom-element.d.ts +2 -0
- package/dist/custom-element.js +4 -0
- package/dist/custom-element.js.map +1 -0
- package/dist/daba-agent.cjs +30 -0
- package/dist/daba-agent.cjs.map +1 -0
- package/dist/daba-agent.d.cts +4 -0
- package/dist/daba-agent.d.ts +4 -0
- package/dist/daba-agent.js +5 -0
- package/dist/daba-agent.js.map +1 -0
- package/dist/daba-agent.min.js +378 -0
- package/dist/daba-agent.min.js.map +1 -0
- package/dist/react.cjs +21 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +7 -0
- package/dist/react.d.ts +7 -0
- package/dist/react.js +4 -0
- package/dist/react.js.map +1 -0
- package/dist/types-DYRGPzyp.d.cts +76 -0
- package/dist/types-DYRGPzyp.d.ts +76 -0
- package/package.json +100 -0
- package/react.d.ts +1 -0
- package/react.js +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
# daba-agent
|
|
2
|
+
|
|
3
|
+
Embeddable voice AI assistant widget for [dabalabs](https://dabalabs.com) projects. Drop it into any site and visitors can press **Ctrl+Space**, talk in any language, and get a spoken reply — the agent can also read the page, fill out and submit forms, and navigate to other pages on request.
|
|
4
|
+
|
|
5
|
+
Works natively in **Plain HTML**, **React**, **Next.js**, **Vue**, **Nuxt**, **Svelte**, **SvelteKit**, **Astro**, and any modern JavaScript stack.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @dabalabs/agent
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
### 1. Web Component (`<daba-agent>`) — Works in Any JS Framework / HTML
|
|
16
|
+
|
|
17
|
+
Simply import `@dabalabs/agent` (or `@dabalabs/agent/custom-element`) and use `<daba-agent>` directly in your HTML or JSX/Vue/Svelte template:
|
|
18
|
+
|
|
19
|
+
```html
|
|
20
|
+
<daba-agent
|
|
21
|
+
project-id="YOUR_PROJECT_ID"
|
|
22
|
+
api-key="YOUR_API_KEY"
|
|
23
|
+
position="bottom-right"
|
|
24
|
+
></daba-agent>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Plain HTML / Script Tag
|
|
28
|
+
|
|
29
|
+
```html
|
|
30
|
+
<script src="https://unpkg.com/@dabalabs/agent/dist/daba-agent.min.js"></script>
|
|
31
|
+
<daba-agent project-id="YOUR_PROJECT_ID" api-key="YOUR_API_KEY"></daba-agent>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
#### Vue 3 / Nuxt 3
|
|
35
|
+
|
|
36
|
+
```vue
|
|
37
|
+
<script setup>
|
|
38
|
+
import '@dabalabs/agent/custom-element';
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<daba-agent
|
|
43
|
+
project-id="YOUR_PROJECT_ID"
|
|
44
|
+
api-key="YOUR_API_KEY"
|
|
45
|
+
position="bottom-right"
|
|
46
|
+
/>
|
|
47
|
+
</template>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Svelte / SvelteKit / Astro
|
|
51
|
+
|
|
52
|
+
```svelte
|
|
53
|
+
<script>
|
|
54
|
+
import '@dabalabs/agent/custom-element';
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<daba-agent project-id="YOUR_PROJECT_ID" api-key="YOUR_API_KEY" />
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
### 2. React Component (`<DabaAgent />`) — React & Next.js
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
"use client";
|
|
66
|
+
|
|
67
|
+
import { DabaAgent } from "@dabalabs/agent/react";
|
|
68
|
+
|
|
69
|
+
export function App() {
|
|
70
|
+
return (
|
|
71
|
+
<DabaAgent
|
|
72
|
+
projectId="YOUR_PROJECT_ID"
|
|
73
|
+
apiKey="YOUR_API_KEY"
|
|
74
|
+
position="bottom-right"
|
|
75
|
+
onStatusChange={(status) => console.log("Agent status:", status)}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
### 3. Programmatic Class API (`new DabaAgent()`)
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { DabaAgent } from "@dabalabs/agent";
|
|
87
|
+
|
|
88
|
+
const agent = new DabaAgent({
|
|
89
|
+
projectId: "YOUR_PROJECT_ID",
|
|
90
|
+
apiKey: "YOUR_API_KEY",
|
|
91
|
+
position: "bottom-right",
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Get a project ID and API key from the Developer section of your [dabalabs dashboard](https://dabalabs.com/dashboard/developer) — the same API key used for the [dabalabs](https://www.npmjs.com/package/dabalabs) video player works here too.
|
|
96
|
+
|
|
97
|
+
## Custom Events on Web Component (`<daba-agent>`)
|
|
98
|
+
|
|
99
|
+
The `<daba-agent>` element dispatches native DOM Custom Events:
|
|
100
|
+
|
|
101
|
+
- `daba-status-change` (`e.detail.status`) — Fired when status changes (`idle`, `connecting`, `listening`, `thinking`, `speaking`)
|
|
102
|
+
- `daba-transcript` (`e.detail: { role, text, isFinal }`) — Fired on user or agent transcript deltas
|
|
103
|
+
- `daba-error` (`e.detail.error`) — Fired on network or session errors
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
```js
|
|
107
|
+
const agentEl = document.querySelector('daba-agent');
|
|
108
|
+
agentEl.addEventListener('daba-status-change', (e) => {
|
|
109
|
+
console.log('Status:', e.detail.status);
|
|
110
|
+
});
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## API keys are publishable
|
|
114
|
+
|
|
115
|
+
The API key is meant to sit in your site's frontend source, the same trust model as a Stripe.js or Google Maps JS key. Server-side, it's restricted to the exact origins you list when you create it, and to the one agent project it was scoped to. It can't create, modify, or delete anything, and it can be revoked instantly from your dashboard.
|
|
116
|
+
|
|
117
|
+
## Options
|
|
118
|
+
|
|
119
|
+
| Option / Attribute | Type | Description |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `projectId` / `project-id` | `string` | Your agent project ID from the dashboard |
|
|
122
|
+
| `apiKey` / `api-key` | `string` | Your publishable API key |
|
|
123
|
+
| `position` | `"bottom-right" \| "bottom-left" \| "top-right" \| "top-left"` | Corner of the viewport for the default badge (default: `"bottom-right"`). |
|
|
124
|
+
| `accentColor` / `accent-color` | `string` | Accent color hex for the badge's active-state indicator |
|
|
125
|
+
| `hotkey` | `string \| null` | Keyboard shortcut to toggle the agent (default: `"ctrl+space"`). Pass `null` to disable. |
|
|
126
|
+
| `gatewayUrl` / `gateway-url` | `string` (optional) | Base URL of the gateway (defaults to `"https://api.dabalabs.com"`) |
|
|
127
|
+
| `onStatusChange` | `(status: DabaAgentStatus) => void` | Fired as the agent moves through status lifecycle (React / JS API) |
|
|
128
|
+
| `onTranscript` | `(role: "user" \| "agent", text: string, isFinal: boolean) => void` | Fired with transcript deltas (React / JS API) |
|
|
129
|
+
| `onError` | `(error: DabaError) => void` | Fired on connection or session errors (React / JS API) |
|
|
130
|
+
|
|
131
|
+
## Methods (on `agent` instance or `element.dabaAgent`)
|
|
132
|
+
|
|
133
|
+
- `agent.toggle()` — start or stop a session
|
|
134
|
+
- `agent.destroy()` — tear down the session, remove the badge, and detach all listeners
|
|
135
|
+
- `agent.currentStatus` — the current `DabaAgentStatus`
|
|
136
|
+
- `agent.isActive` — whether a session is currently running
|
|
137
|
+
|
|
138
|
+
## What the agent can do
|
|
139
|
+
|
|
140
|
+
- **Talk.** Full duplex voice in and out over a single realtime connection — no separate transcription/TTS round trip.
|
|
141
|
+
- **Read the page.** On session start, the agent is given the page title, visible text, navigable links, and form fields, so it can answer questions about the page and knows what it can act on.
|
|
142
|
+
- **Fill out and submit forms.** The agent fills fields by label, then confirms with the visitor before submitting — it never submits silently. Password, card, and other sensitive-looking fields are refused outright, whether marked or not.
|
|
143
|
+
- **Navigate.** Ask it to go to another page and it will, resuming the same conversation on the other side rather than starting over.
|
|
144
|
+
|
|
145
|
+
## Security guards
|
|
146
|
+
|
|
147
|
+
- `data-daba-agent-ignore` on any element (or a container) excludes it and its subtree from page reading and from form-filling.
|
|
148
|
+
- `data-daba-agent-restricted` on `<html>`, or `<meta name="daba-agent-restricted">` in `<head>`, opts an entire page out — the agent won't read the page or start a session there at all. Use this on account, billing, or checkout pages.
|
|
149
|
+
- Password fields, payment fields (`autocomplete="cc-*"`), and labels that read like a PIN or security code are never filled or spoken back, regardless of how the model was asked.
|
|
150
|
+
|
|
151
|
+
## Browser support
|
|
152
|
+
|
|
153
|
+
Requires `WebSocket`, `AudioContext`, and `getUserMedia` — every evergreen browser. The widget itself renders no UI beyond the floating badge, so it has no layout dependencies on the host page.
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT
|
|
158
|
+
|
|
159
|
+
## Environments
|
|
160
|
+
|
|
161
|
+
By default the widget talks to Dabalabs production. Point it at staging
|
|
162
|
+
with `env`:
|
|
163
|
+
|
|
164
|
+
```html
|
|
165
|
+
<div data-daba-agent
|
|
166
|
+
data-project-id="YOUR_PROJECT_ID"
|
|
167
|
+
data-api-key="YOUR_API_KEY"
|
|
168
|
+
data-daba-env="staging"
|
|
169
|
+
></div>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
new DabaAgent({
|
|
174
|
+
// ...
|
|
175
|
+
env: "staging",
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
| `env` | Gateway |
|
|
180
|
+
|---|---|
|
|
181
|
+
| omitted | `https://api.dabalabs.com` |
|
|
182
|
+
| `"production"` | `https://api.dabalabs.com` |
|
|
183
|
+
| `"staging"` | `https://api-staging.dabalabs.com` |
|
|
184
|
+
|
|
185
|
+
Production is the default in every direction — an embed that says nothing
|
|
186
|
+
about its environment is a live site, so staging has to be asked for by
|
|
187
|
+
name. An unrecognised value warns in the console and falls back to
|
|
188
|
+
production rather than throwing, so a typo cannot take a customer's page
|
|
189
|
+
down.
|
|
190
|
+
|
|
191
|
+
`gatewayUrl` still overrides `env` when both are given: it is the only
|
|
192
|
+
option that can name a host neither tier covers (a self-hosted
|
|
193
|
+
deployment, a local gateway).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/custom-element";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/custom-element.js";
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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IAAA,EAAM,QAAA,EAAU,IAAA,EAAM;AAAA,SAC3F;AAAA,MACF;AAAA,KACD,CAAA;AAAA,EACH;AAAA,EAEA,oBAAA,GAA6B;AAC3B,IAAA,IAAI,KAAK,KAAA,EAAO;AACd,MAAA,IAAA,CAAK,MAAM,OAAA,EAAQ;AACnB,MAAA,IAAA,CAAK,KAAA,GAAQ,IAAA;AAAA,IACf;AAAA,EACF;AAAA,EAEA,IAAW,SAAA,GAA8B;AACvC,IAAA,OAAO,IAAA,CAAK,KAAA;AAAA,EACd;AAAA,EAEO,SAAS,IAAA,EAAyC;AACvD,IAAA,OAAO,IAAA,CAAK,KAAA,EAAO,QAAA,CAAS,IAAI,CAAA;AAAA,EAClC;AAAA,EAEO,QAAA,GAAiB;AACtB,IAAA,IAAA,CAAK,OAAO,QAAA,EAAS;AAAA,EACvB;AAAA,EAEO,SAAA,GAAkB;AACvB,IAAA,IAAA,CAAK,OAAO,SAAA,EAAU;AAAA,EACxB;AAAA,EAEO,UAAA,GAAmB;AACxB,IAAA,IAAA,CAAK,OAAO,UAAA,EAAW;AAAA,EACzB;AACF;AAEO,SAAS,sBAAA,CAAuB,UAAU,YAAA,EAAoB;AACnE,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,OAAO,mBAAmB,WAAA,EAAa;AAC1E,IAAA,IAAI,CAAC,cAAA,CAAe,GAAA,CAAI,OAAO,CAAA,EAAG;AAChC,MAAA,cAAA,CAAe,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"]}
|