@dabalabs/agent 0.0.2-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.
Files changed (40) hide show
  1. package/README.md +56 -3
  2. package/dist/chunk-3BQ6LE6X.cjs +222 -0
  3. package/dist/chunk-3BQ6LE6X.cjs.map +1 -0
  4. package/dist/{chunk-CMHPVBEF.js → chunk-ETI4LRM7.js} +841 -100
  5. package/dist/chunk-ETI4LRM7.js.map +1 -0
  6. package/dist/chunk-TYOHYQDK.js +220 -0
  7. package/dist/chunk-TYOHYQDK.js.map +1 -0
  8. package/dist/{chunk-IMPMGYCG.cjs → chunk-VAIC5ACS.cjs} +841 -99
  9. package/dist/chunk-VAIC5ACS.cjs.map +1 -0
  10. package/dist/custom-element.cjs +4 -4
  11. package/dist/custom-element.d.cts +191 -2
  12. package/dist/custom-element.d.ts +191 -2
  13. package/dist/custom-element.js +2 -2
  14. package/dist/daba-agent.cjs +5 -14
  15. package/dist/daba-agent.d.cts +2 -4
  16. package/dist/daba-agent.d.ts +2 -4
  17. package/dist/daba-agent.js +2 -3
  18. package/dist/daba-agent.min.js +141 -36
  19. package/dist/daba-agent.min.js.map +1 -1
  20. package/dist/react.cjs +41 -14
  21. package/dist/react.cjs.map +1 -1
  22. package/dist/react.d.cts +1 -1
  23. package/dist/react.d.ts +1 -1
  24. package/dist/react.js +38 -2
  25. package/dist/react.js.map +1 -1
  26. package/dist/{types-hdR_wQ1B.d.cts → types-BQRgqD4n.d.cts} +70 -4
  27. package/dist/{types-hdR_wQ1B.d.ts → types-BQRgqD4n.d.ts} +70 -4
  28. package/package.json +1 -1
  29. package/dist/chunk-7ENX2QZK.js +0 -193
  30. package/dist/chunk-7ENX2QZK.js.map +0 -1
  31. package/dist/chunk-CMHPVBEF.js.map +0 -1
  32. package/dist/chunk-GCU5OBSZ.js +0 -40
  33. package/dist/chunk-GCU5OBSZ.js.map +0 -1
  34. package/dist/chunk-HJPH4GNS.cjs +0 -196
  35. package/dist/chunk-HJPH4GNS.cjs.map +0 -1
  36. package/dist/chunk-IMPMGYCG.cjs.map +0 -1
  37. package/dist/chunk-JQMJMSFT.cjs +0 -46
  38. package/dist/chunk-JQMJMSFT.cjs.map +0 -1
  39. package/dist/custom-element-BZAUI4Dc.d.cts +0 -121
  40. package/dist/custom-element-PL2IXpG2.d.ts +0 -121
@@ -0,0 +1,220 @@
1
+ import { DabaAgent, cssLength } from './chunk-ETI4LRM7.js';
2
+
3
+ // src/components/custom-element.ts
4
+ var VALID_POSITIONS = [
5
+ "bottom-right",
6
+ "bottom-left",
7
+ "top-right",
8
+ "top-left"
9
+ ];
10
+ var VALID_MODES = ["voice", "chat", "hybrid"];
11
+ var VALID_DIRECTIONS = ["auto", "ltr", "rtl"];
12
+ var VALID_THEMES = ["auto", "light", "dark"];
13
+ var VALID_LAUNCHER_SHAPES = ["rounded", "circle", "pill"];
14
+ var VALID_MEDIA_TYPES = ["video", "image", "none"];
15
+ var PROMPT_SEPARATOR = "|";
16
+ function readAttr(el, name) {
17
+ for (const attr of [name, `data-${name}`]) {
18
+ const raw = el.getAttribute(attr);
19
+ if (raw === null) continue;
20
+ const value = raw.trim();
21
+ if (value === "") continue;
22
+ return { attr, value };
23
+ }
24
+ return void 0;
25
+ }
26
+ function stringAttr(el, name) {
27
+ return readAttr(el, name)?.value;
28
+ }
29
+ function enumAttr(el, name, allowed) {
30
+ const found = readAttr(el, name);
31
+ if (!found) return void 0;
32
+ if (allowed.includes(found.value)) return found.value;
33
+ console.error(
34
+ `daba-agent: invalid ${found.attr} "${found.value}" on <daba-agent>. Expected one of ${allowed.join(
35
+ ", "
36
+ )} \u2014 ignoring it.`,
37
+ el
38
+ );
39
+ return void 0;
40
+ }
41
+ function flagAttr(el, name) {
42
+ for (const attr of [name, `data-${name}`]) {
43
+ const raw = el.getAttribute(attr);
44
+ if (raw === null) continue;
45
+ const value = raw.trim().toLowerCase();
46
+ return value !== "false" && value !== "0" && value !== "no";
47
+ }
48
+ return void 0;
49
+ }
50
+ function promptsAttr(el, name) {
51
+ const found = readAttr(el, name);
52
+ if (!found) return void 0;
53
+ const prompts = found.value.split(PROMPT_SEPARATOR).map((prompt) => prompt.trim()).filter((prompt) => prompt !== "");
54
+ return prompts.length > 0 ? prompts : void 0;
55
+ }
56
+ function lengthAttr(el, name) {
57
+ const found = readAttr(el, name);
58
+ if (!found) return void 0;
59
+ const length = cssLength(found.value, false);
60
+ if (length) return length;
61
+ console.error(
62
+ `daba-agent: invalid ${found.attr} "${found.value}" on <daba-agent>. Expected a CSS length such as "400px", "28rem" or "90%".`,
63
+ el
64
+ );
65
+ return void 0;
66
+ }
67
+ function group(fields) {
68
+ return Object.values(fields).some((value) => value !== void 0) ? fields : void 0;
69
+ }
70
+ function buildElementClass() {
71
+ return class DabaAgentElement extends HTMLElement {
72
+ constructor() {
73
+ super(...arguments);
74
+ this.agent = null;
75
+ }
76
+ connectedCallback() {
77
+ if (this.agent) return;
78
+ const projectId = stringAttr(this, "project-id");
79
+ const apiKey = stringAttr(this, "api-key");
80
+ if (!projectId || !apiKey) {
81
+ console.error(
82
+ "daba-agent: <daba-agent> custom element requires project-id and api-key attributes.",
83
+ this
84
+ );
85
+ return;
86
+ }
87
+ const position = enumAttr(this, "position", VALID_POSITIONS);
88
+ const accentColor = stringAttr(this, "accent-color");
89
+ const mode = enumAttr(this, "mode", VALID_MODES);
90
+ const title = stringAttr(this, "title");
91
+ const placeholder = stringAttr(this, "placeholder");
92
+ const initialOpen = flagAttr(this, "initial-open");
93
+ const hotkey = stringAttr(this, "hotkey");
94
+ const gatewayUrl = stringAttr(this, "gateway-url");
95
+ const env = stringAttr(this, "env");
96
+ const theme = group({
97
+ accentColor,
98
+ accentContrast: stringAttr(this, "accent-contrast"),
99
+ surfaceColor: stringAttr(this, "surface-color"),
100
+ textColor: stringAttr(this, "text-color"),
101
+ radius: stringAttr(this, "radius"),
102
+ fontFamily: stringAttr(this, "font-family"),
103
+ theme: enumAttr(this, "theme", VALID_THEMES)
104
+ });
105
+ const introDisabled = flagAttr(this, "intro-disabled");
106
+ const intro = group({
107
+ enabled: introDisabled === void 0 ? void 0 : !introDisabled,
108
+ headline: stringAttr(this, "intro-headline"),
109
+ subheadline: stringAttr(this, "intro-subheadline"),
110
+ mediaUrl: stringAttr(this, "intro-media-url"),
111
+ mediaType: enumAttr(this, "intro-media-type", VALID_MEDIA_TYPES),
112
+ suggestedPrompts: promptsAttr(this, "suggested-prompts")
113
+ });
114
+ const launcher = group({
115
+ shape: enumAttr(this, "launcher-shape", VALID_LAUNCHER_SHAPES),
116
+ iconUrl: stringAttr(this, "launcher-icon-url"),
117
+ iconSvg: stringAttr(this, "launcher-icon-svg"),
118
+ iconText: stringAttr(this, "launcher-icon-text"),
119
+ label: stringAttr(this, "launcher-label"),
120
+ size: lengthAttr(this, "launcher-size"),
121
+ iconSize: lengthAttr(this, "launcher-icon-size")
122
+ });
123
+ const panel = group({
124
+ width: lengthAttr(this, "panel-width"),
125
+ height: lengthAttr(this, "panel-height")
126
+ });
127
+ this.agent = new DabaAgent({
128
+ container: this,
129
+ projectId,
130
+ apiKey,
131
+ position,
132
+ accentColor,
133
+ mode,
134
+ title,
135
+ placeholder,
136
+ initialOpen,
137
+ historyEnabled: flagAttr(this, "history-enabled"),
138
+ hotkey,
139
+ gatewayUrl,
140
+ env,
141
+ theme,
142
+ intro,
143
+ launcher,
144
+ panel,
145
+ logoUrl: stringAttr(this, "logo-url"),
146
+ logoSvg: stringAttr(this, "logo-svg"),
147
+ iconBackgroundColor: stringAttr(this, "icon-background-color"),
148
+ iconMarkColor: stringAttr(this, "icon-mark-color"),
149
+ uiLanguage: stringAttr(this, "ui-language"),
150
+ direction: enumAttr(this, "direction", VALID_DIRECTIONS),
151
+ onStatusChange: (status) => {
152
+ this.dispatchEvent(
153
+ new CustomEvent("daba-status-change", { detail: { status }, bubbles: true, composed: true })
154
+ );
155
+ },
156
+ onTranscript: (role, text, isFinal) => {
157
+ this.dispatchEvent(
158
+ new CustomEvent("daba-transcript", {
159
+ detail: { role, text, isFinal },
160
+ bubbles: true,
161
+ composed: true
162
+ })
163
+ );
164
+ },
165
+ onError: (error) => {
166
+ this.dispatchEvent(
167
+ new CustomEvent("daba-error", { detail: { error }, bubbles: true, composed: true })
168
+ );
169
+ },
170
+ onChatToggle: (isOpen) => {
171
+ this.dispatchEvent(
172
+ new CustomEvent("daba-chat-toggle", { detail: { isOpen }, bubbles: true, composed: true })
173
+ );
174
+ },
175
+ // Cards arrive once per reply that carried structured items, so a
176
+ // host page can render them in its own layout instead of (or as well
177
+ // as) the panel's — a listing site putting event cards on the page.
178
+ onCards: (cards) => {
179
+ this.dispatchEvent(
180
+ new CustomEvent("daba-cards", { detail: { cards }, bubbles: true, composed: true })
181
+ );
182
+ }
183
+ });
184
+ }
185
+ disconnectedCallback() {
186
+ if (this.agent) {
187
+ this.agent.destroy();
188
+ this.agent = null;
189
+ }
190
+ }
191
+ get dabaAgent() {
192
+ return this.agent;
193
+ }
194
+ sendText(text) {
195
+ return this.agent?.sendText(text);
196
+ }
197
+ openChat() {
198
+ this.agent?.openChat();
199
+ }
200
+ closeChat() {
201
+ this.agent?.closeChat();
202
+ }
203
+ toggleChat() {
204
+ this.agent?.toggleChat();
205
+ }
206
+ };
207
+ }
208
+ var DabaAgentElement;
209
+ function defineDabaAgentElement(tagName = "daba-agent") {
210
+ if (typeof window === "undefined" || typeof customElements === "undefined") return;
211
+ if (customElements.get(tagName)) return;
212
+ const ctor = buildElementClass();
213
+ customElements.define(tagName, ctor);
214
+ DabaAgentElement ?? (DabaAgentElement = ctor);
215
+ }
216
+ defineDabaAgentElement();
217
+
218
+ export { DabaAgentElement, defineDabaAgentElement };
219
+ //# sourceMappingURL=chunk-TYOHYQDK.js.map
220
+ //# sourceMappingURL=chunk-TYOHYQDK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/custom-element.ts"],"names":[],"mappings":";;;AAeA,IAAM,eAAA,GAAgD;AA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MAAM,OAAO,iBAAA,EAAkB;AAC/B,EAAA,cAAA,CAAe,MAAA,CAAO,SAAS,IAAI,CAAA;AAGnC,EAAA,gBAAA,KAAA,gBAAA,GAAqB,IAAA,CAAA;AACvB;AAEA,sBAAA,EAAuB","file":"chunk-TYOHYQDK.js","sourcesContent":["import { DabaAgent } from \"../agent\";\nimport { cssLength } from \"../utils/css-length\";\nimport type {\n DabaAgentMode,\n DabaAgentOptions,\n DabaAgentPosition,\n DabaDirection,\n DabaIntro,\n DabaLauncher,\n DabaLauncherShape,\n DabaPanel,\n DabaTheme,\n DabaThemePreference,\n} from \"../types\";\n\nconst VALID_POSITIONS: readonly DabaAgentPosition[] = [\n \"bottom-right\",\n \"bottom-left\",\n \"top-right\",\n \"top-left\",\n];\nconst VALID_MODES: readonly DabaAgentMode[] = [\"voice\", \"chat\", \"hybrid\"];\nconst VALID_DIRECTIONS: readonly DabaDirection[] = [\"auto\", \"ltr\", \"rtl\"];\nconst VALID_THEMES: readonly DabaThemePreference[] = [\"auto\", \"light\", \"dark\"];\nconst VALID_LAUNCHER_SHAPES: readonly DabaLauncherShape[] = [\"rounded\", \"circle\", \"pill\"];\nconst VALID_MEDIA_TYPES = [\"video\", \"image\", \"none\"] as const;\n\n/** Same separator as the script-tag embed's data-daba-suggested-prompts —\n * a pipe, because starter prompts are sentences and sentences contain\n * commas. See src/auto-init.ts for the reasoning. */\nconst PROMPT_SEPARATOR = \"|\";\n\n/**\n * Reads `<name>`, then the `data-<name>` alias this element has always\n * accepted, and reports which spelling was found so a warning can quote\n * what the integrator actually typed.\n *\n * Absent AND blank both read as \"not set\", because an option left\n * `undefined` is what tells the agent to use the project's dashboard\n * configuration. A framework binding that renders `radius=\"\"` must leave\n * the served radius alone rather than override it with nothing.\n *\n * These readers deliberately mirror src/auto-init.ts: the two embeds spell\n * their attributes differently but must accept exactly the same values.\n */\nfunction readAttr(el: HTMLElement, name: string): { attr: string; value: string } | undefined {\n for (const attr of [name, `data-${name}`]) {\n const raw = el.getAttribute(attr);\n if (raw === null) continue;\n const value = raw.trim();\n if (value === \"\") continue;\n return { attr, value };\n }\n return undefined;\n}\n\nfunction stringAttr(el: HTMLElement, name: string): string | undefined {\n return readAttr(el, name)?.value;\n}\n\n/** A value outside the allowed set is dropped rather than forwarded, which\n * leaves the option `undefined` and so degrades a typo to the project's own\n * setting instead of letting garbage reach the DOM. */\nfunction enumAttr<T extends string>(\n el: HTMLElement,\n name: string,\n allowed: readonly T[],\n): T | undefined {\n const found = readAttr(el, name);\n if (!found) return undefined;\n if ((allowed as readonly string[]).includes(found.value)) return found.value as T;\n console.error(\n `daba-agent: invalid ${found.attr} \"${found.value}\" on <daba-agent>. Expected one of ${allowed.join(\n \", \",\n )} — ignoring it.`,\n el,\n );\n return undefined;\n}\n\n/** Present with no value is true, the way HTML spells a boolean, but an\n * explicit \"false\" still means false so a bound attribute\n * (`:intro-disabled=\"hideIntro\"`) does not disable the intro everywhere. */\nfunction flagAttr(el: HTMLElement, name: string): boolean | undefined {\n for (const attr of [name, `data-${name}`]) {\n const raw = el.getAttribute(attr);\n if (raw === null) continue;\n const value = raw.trim().toLowerCase();\n return value !== \"false\" && value !== \"0\" && value !== \"no\";\n }\n return undefined;\n}\n\n/** A list that separates into nothing is unset, not empty — far likelier a\n * binding that rendered nothing than a deliberate clearing of the\n * project's prompts. */\nfunction promptsAttr(el: HTMLElement, name: string): string[] | undefined {\n const found = readAttr(el, name);\n if (!found) return undefined;\n const prompts = found.value\n .split(PROMPT_SEPARATOR)\n .map((prompt) => prompt.trim())\n .filter((prompt) => prompt !== \"\");\n return prompts.length > 0 ? prompts : undefined;\n}\n\n/** Mirrors enumAttr: a value that is not a length is dropped and named,\n * rather than forwarded to become an invalid `width` that would collapse\n * the element it was meant to size. Functions are refused on the attribute\n * surfaces — the value usually comes from a template, where a half-written\n * calc() is far likelier than a deliberate one. */\nfunction lengthAttr(el: HTMLElement, name: string): string | undefined {\n const found = readAttr(el, name);\n if (!found) return undefined;\n const length = cssLength(found.value, false);\n if (length) return length;\n console.error(\n `daba-agent: invalid ${found.attr} \"${found.value}\" on <daba-agent>. Expected a CSS length such as \"400px\", \"28rem\" or \"90%\".`,\n el,\n );\n return undefined;\n}\n\n/** Grouped options exist only when one of their fields was configured;\n * an empty group would read downstream as an intentional override. */\nfunction group<T extends object>(fields: T): T | undefined {\n return Object.values(fields).some((value) => value !== undefined) ? fields : undefined;\n}\n\n/**\n * The element's public shape.\n *\n * A type, not a class: `class ... extends HTMLElement` evaluates its\n * extends clause the moment the module does, and on a server there is no\n * HTMLElement — which is why importing the package root from a Next.js\n * layout threw \"HTMLElement is not defined\" and forced every integrator\n * into a dynamic import inside an effect. The real class is built by\n * defineDabaAgentElement(), which only ever runs in a browser.\n */\nexport interface DabaAgentElement extends HTMLElement {\n readonly dabaAgent: DabaAgent | null;\n sendText(text: string): Promise<void> | undefined;\n openChat(): void;\n closeChat(): void;\n toggleChat(): void;\n}\n\nexport type DabaAgentElementConstructor = new () => DabaAgentElement;\n\n/**\n * The constructor, once a browser has been seen. `undefined` on a server.\n *\n * A fresh subclass per tag name: customElements.define() rejects a\n * constructor that is already registered under another name with a\n * NotSupportedError, so a caller passing their own tag would otherwise\n * break the moment the default one had been defined.\n */\nfunction buildElementClass(): DabaAgentElementConstructor {\n return class DabaAgentElement extends HTMLElement {\n\n private agent: DabaAgent | null = null;\n\n connectedCallback(): void {\n if (this.agent) return;\n\n const projectId = stringAttr(this, \"project-id\");\n const apiKey = stringAttr(this, \"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 = enumAttr(this, \"position\", VALID_POSITIONS);\n const accentColor = stringAttr(this, \"accent-color\");\n const mode = enumAttr(this, \"mode\", VALID_MODES);\n const title = stringAttr(this, \"title\");\n const placeholder = stringAttr(this, \"placeholder\");\n const initialOpen = flagAttr(this, \"initial-open\");\n const hotkey = stringAttr(this, \"hotkey\");\n const gatewayUrl = stringAttr(this, \"gateway-url\");\n // env=\"staging\" points the element at the staging gateway, the same\n // way data-daba-env does for the script-tag embed. Absent means\n // production — see environment.ts.\n const env = stringAttr(this, \"env\") as DabaAgentOptions[\"env\"];\n\n // The accent is offered under both names it has on the option surface:\n // the flat `accentColor` the badge already reads, and the grouped\n // `theme.accentColor` that sits with the rest of the appearance\n // overrides. Same value either way.\n const theme = group<DabaTheme>({\n accentColor,\n accentContrast: stringAttr(this, \"accent-contrast\"),\n surfaceColor: stringAttr(this, \"surface-color\"),\n textColor: stringAttr(this, \"text-color\"),\n radius: stringAttr(this, \"radius\"),\n fontFamily: stringAttr(this, \"font-family\"),\n theme: enumAttr(this, \"theme\", VALID_THEMES),\n });\n\n // The attribute names the state an integrator wants to force — an\n // intro is on unless switched off — while the option carries the state\n // itself, so the flag is inverted here rather than in the agent.\n const introDisabled = flagAttr(this, \"intro-disabled\");\n const intro = group<DabaIntro>({\n enabled: introDisabled === undefined ? undefined : !introDisabled,\n headline: stringAttr(this, \"intro-headline\"),\n subheadline: stringAttr(this, \"intro-subheadline\"),\n mediaUrl: stringAttr(this, \"intro-media-url\"),\n mediaType: enumAttr(this, \"intro-media-type\", VALID_MEDIA_TYPES),\n suggestedPrompts: promptsAttr(this, \"suggested-prompts\"),\n });\n\n const launcher = group<DabaLauncher>({\n shape: enumAttr(this, \"launcher-shape\", VALID_LAUNCHER_SHAPES),\n iconUrl: stringAttr(this, \"launcher-icon-url\"),\n iconSvg: stringAttr(this, \"launcher-icon-svg\"),\n iconText: stringAttr(this, \"launcher-icon-text\"),\n label: stringAttr(this, \"launcher-label\"),\n size: lengthAttr(this, \"launcher-size\"),\n iconSize: lengthAttr(this, \"launcher-icon-size\"),\n });\n\n const panel = group<DabaPanel>({\n width: lengthAttr(this, \"panel-width\"),\n height: lengthAttr(this, \"panel-height\"),\n });\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 historyEnabled: flagAttr(this, \"history-enabled\"),\n hotkey,\n gatewayUrl,\n env,\n theme,\n intro,\n launcher,\n panel,\n logoUrl: stringAttr(this, \"logo-url\"),\n logoSvg: stringAttr(this, \"logo-svg\"),\n iconBackgroundColor: stringAttr(this, \"icon-background-color\"),\n iconMarkColor: stringAttr(this, \"icon-mark-color\"),\n uiLanguage: stringAttr(this, \"ui-language\"),\n direction: enumAttr(this, \"direction\", VALID_DIRECTIONS),\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 // Cards arrive once per reply that carried structured items, so a\n // host page can render them in its own layout instead of (or as well\n // as) the panel's — a listing site putting event cards on the page.\n onCards: (cards) => {\n this.dispatchEvent(\n new CustomEvent(\"daba-cards\", { detail: { cards }, 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 } as unknown as DabaAgentElementConstructor;\n}\n\nexport let DabaAgentElement: DabaAgentElementConstructor | undefined;\n\nexport function defineDabaAgentElement(tagName = \"daba-agent\"): void {\n if (typeof window === \"undefined\" || typeof customElements === \"undefined\") return;\n if (customElements.get(tagName)) return;\n const ctor = buildElementClass();\n customElements.define(tagName, ctor);\n // The exported binding names the default element. A host registering an\n // extra tag gets its own class and leaves this one pointing at the first.\n DabaAgentElement ??= ctor;\n}\n\ndefineDabaAgentElement();\n"]}