@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.
- package/README.md +56 -3
- package/dist/chunk-3BQ6LE6X.cjs +222 -0
- package/dist/chunk-3BQ6LE6X.cjs.map +1 -0
- package/dist/{chunk-CMHPVBEF.js → chunk-ETI4LRM7.js} +841 -100
- 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-IMPMGYCG.cjs → chunk-VAIC5ACS.cjs} +841 -99
- 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 +141 -36
- 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-hdR_wQ1B.d.cts → types-BQRgqD4n.d.cts} +70 -4
- package/dist/{types-hdR_wQ1B.d.ts → types-BQRgqD4n.d.ts} +70 -4
- package/package.json +1 -1
- package/dist/chunk-7ENX2QZK.js +0 -193
- package/dist/chunk-7ENX2QZK.js.map +0 -1
- package/dist/chunk-CMHPVBEF.js.map +0 -1
- package/dist/chunk-GCU5OBSZ.js +0 -40
- package/dist/chunk-GCU5OBSZ.js.map +0 -1
- package/dist/chunk-HJPH4GNS.cjs +0 -196
- package/dist/chunk-HJPH4GNS.cjs.map +0 -1
- package/dist/chunk-IMPMGYCG.cjs.map +0 -1
- package/dist/chunk-JQMJMSFT.cjs +0 -46
- package/dist/chunk-JQMJMSFT.cjs.map +0 -1
- package/dist/custom-element-BZAUI4Dc.d.cts +0 -121
- package/dist/custom-element-PL2IXpG2.d.ts +0 -121
package/dist/chunk-GCU5OBSZ.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DabaAgent } from './chunk-CMHPVBEF.js';
|
|
2
|
-
import React, { useRef, useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
function DabaAgentComponent(props) {
|
|
5
|
-
const containerRef = useRef(null);
|
|
6
|
-
const agentRef = useRef(null);
|
|
7
|
-
const propsRef = useRef(props);
|
|
8
|
-
propsRef.current = props;
|
|
9
|
-
const configKey = JSON.stringify(
|
|
10
|
-
props,
|
|
11
|
-
(_key, value) => typeof value === "function" ? void 0 : value
|
|
12
|
-
);
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
if (!containerRef.current) return;
|
|
15
|
-
const agent = new DabaAgent({
|
|
16
|
-
...propsRef.current,
|
|
17
|
-
// After the spread: this component owns where the widget mounts.
|
|
18
|
-
container: containerRef.current,
|
|
19
|
-
onStatusChange: (status) => propsRef.current.onStatusChange?.(status),
|
|
20
|
-
onTranscript: (role, text, isFinal) => propsRef.current.onTranscript?.(role, text, isFinal),
|
|
21
|
-
onChatToggle: (isOpen) => propsRef.current.onChatToggle?.(isOpen),
|
|
22
|
-
onCards: (cards) => propsRef.current.onCards?.(cards),
|
|
23
|
-
onError: (error) => propsRef.current.onError?.(error)
|
|
24
|
-
});
|
|
25
|
-
agentRef.current = agent;
|
|
26
|
-
return () => {
|
|
27
|
-
agent.destroy();
|
|
28
|
-
agentRef.current = null;
|
|
29
|
-
};
|
|
30
|
-
}, [configKey]);
|
|
31
|
-
return React.createElement("div", {
|
|
32
|
-
ref: containerRef,
|
|
33
|
-
style: { display: "contents" },
|
|
34
|
-
"data-daba-agent-react-container": "true"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { DabaAgent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D,IAAA,QAAA,CAAS,OAAA,GAAU,KAAA;AAEnB,IAAA,OAAO,MAAM;AACX,MAAA,KAAA,CAAM,OAAA,EAAQ;AACd,MAAA,QAAA,CAAS,OAAA,GAAU,IAAA;AAAA,IACrB,CAAA;AAAA,EACF,CAAA,EAAG,CAAC,SAAS,CAAC,CAAA;AAEd,EAAA,OAAO,KAAA,CAAM,cAAc,KAAA,EAAO;AAAA,IAChC,GAAA,EAAK,YAAA;AAAA,IACL,KAAA,EAAO,EAAE,OAAA,EAAS,UAAA,EAAW;AAAA,IAC7B,iCAAA,EAAmC;AAAA,GACpC,CAAA;AACH","file":"chunk-GCU5OBSZ.js","sourcesContent":["import React, { useEffect, useRef } from \"react\";\nimport { DabaAgent } from \"../agent\";\nimport type { DabaAgentOptions } from \"../types\";\n\nexport type DabaAgentProps = Omit<DabaAgentOptions, \"container\">;\n\nexport function DabaAgentComponent(props: DabaAgentProps): React.ReactElement {\n const containerRef = useRef<HTMLDivElement>(null);\n const agentRef = useRef<DabaAgent | null>(null);\n\n // The agent reads its handlers back out of this ref at call time, which\n // is what keeps an inline `onCards={(c) => setCards(c)}` current without\n // its per-render identity forcing a rebuild below.\n const propsRef = useRef(props);\n propsRef.current = props;\n\n /**\n * The effect keys on the configuration's VALUE, not on the prop objects.\n *\n * `theme={{ accentColor: \"#0c8c5e\" }}` is a fresh object on every render\n * of the parent, so listing it as a dependency would destroy and rebuild\n * the widget — closing the panel, dropping the conversation, restarting\n * a voice session — every time an unrelated piece of the host page's\n * state changed. Serialising compares the way the integrator meant it.\n *\n * Functions are stripped rather than compared: callbacks are re-created\n * on every render too, and they reach the live agent through `propsRef`\n * instead. Serialising also means a newly added option is covered here\n * the moment it exists, which the hand-listed dependency array this\n * replaces was already out of step with (`env` never made it in).\n */\n const configKey = JSON.stringify(props, (_key, value) =>\n typeof value === \"function\" ? undefined : value,\n );\n\n useEffect(() => {\n if (!containerRef.current) return;\n\n const agent = new DabaAgent({\n ...propsRef.current,\n // After the spread: this component owns where the widget mounts.\n container: containerRef.current,\n onStatusChange: (status) => propsRef.current.onStatusChange?.(status),\n onTranscript: (role, text, isFinal) =>\n propsRef.current.onTranscript?.(role, text, isFinal),\n onChatToggle: (isOpen) => propsRef.current.onChatToggle?.(isOpen),\n onCards: (cards) => propsRef.current.onCards?.(cards),\n onError: (error) => propsRef.current.onError?.(error),\n });\n agentRef.current = agent;\n\n return () => {\n agent.destroy();\n agentRef.current = null;\n };\n }, [configKey]);\n\n return React.createElement(\"div\", {\n ref: containerRef,\n style: { display: \"contents\" },\n \"data-daba-agent-react-container\": \"true\",\n });\n}\n\nexport { DabaAgentComponent as DabaAgentReact, DabaAgentComponent as DabaAgent };\n"]}
|
package/dist/chunk-HJPH4GNS.cjs
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var chunkIMPMGYCG_cjs = require('./chunk-IMPMGYCG.cjs');
|
|
4
|
-
|
|
5
|
-
// src/components/custom-element.ts
|
|
6
|
-
var VALID_POSITIONS = [
|
|
7
|
-
"bottom-right",
|
|
8
|
-
"bottom-left",
|
|
9
|
-
"top-right",
|
|
10
|
-
"top-left"
|
|
11
|
-
];
|
|
12
|
-
var VALID_MODES = ["voice", "chat", "hybrid"];
|
|
13
|
-
var VALID_DIRECTIONS = ["auto", "ltr", "rtl"];
|
|
14
|
-
var VALID_THEMES = ["auto", "light", "dark"];
|
|
15
|
-
var VALID_LAUNCHER_SHAPES = ["rounded", "circle", "pill"];
|
|
16
|
-
var VALID_MEDIA_TYPES = ["video", "image", "none"];
|
|
17
|
-
var PROMPT_SEPARATOR = "|";
|
|
18
|
-
function readAttr(el, name) {
|
|
19
|
-
for (const attr of [name, `data-${name}`]) {
|
|
20
|
-
const raw = el.getAttribute(attr);
|
|
21
|
-
if (raw === null) continue;
|
|
22
|
-
const value = raw.trim();
|
|
23
|
-
if (value === "") continue;
|
|
24
|
-
return { attr, value };
|
|
25
|
-
}
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
function stringAttr(el, name) {
|
|
29
|
-
return readAttr(el, name)?.value;
|
|
30
|
-
}
|
|
31
|
-
function enumAttr(el, name, allowed) {
|
|
32
|
-
const found = readAttr(el, name);
|
|
33
|
-
if (!found) return void 0;
|
|
34
|
-
if (allowed.includes(found.value)) return found.value;
|
|
35
|
-
console.error(
|
|
36
|
-
`daba-agent: invalid ${found.attr} "${found.value}" on <daba-agent>. Expected one of ${allowed.join(
|
|
37
|
-
", "
|
|
38
|
-
)} \u2014 ignoring it.`,
|
|
39
|
-
el
|
|
40
|
-
);
|
|
41
|
-
return void 0;
|
|
42
|
-
}
|
|
43
|
-
function flagAttr(el, name) {
|
|
44
|
-
for (const attr of [name, `data-${name}`]) {
|
|
45
|
-
const raw = el.getAttribute(attr);
|
|
46
|
-
if (raw === null) continue;
|
|
47
|
-
const value = raw.trim().toLowerCase();
|
|
48
|
-
return value !== "false" && value !== "0" && value !== "no";
|
|
49
|
-
}
|
|
50
|
-
return void 0;
|
|
51
|
-
}
|
|
52
|
-
function promptsAttr(el, name) {
|
|
53
|
-
const found = readAttr(el, name);
|
|
54
|
-
if (!found) return void 0;
|
|
55
|
-
const prompts = found.value.split(PROMPT_SEPARATOR).map((prompt) => prompt.trim()).filter((prompt) => prompt !== "");
|
|
56
|
-
return prompts.length > 0 ? prompts : void 0;
|
|
57
|
-
}
|
|
58
|
-
function group(fields) {
|
|
59
|
-
return Object.values(fields).some((value) => value !== void 0) ? fields : void 0;
|
|
60
|
-
}
|
|
61
|
-
var DabaAgentElement = class extends HTMLElement {
|
|
62
|
-
constructor() {
|
|
63
|
-
super(...arguments);
|
|
64
|
-
this.agent = null;
|
|
65
|
-
}
|
|
66
|
-
connectedCallback() {
|
|
67
|
-
if (this.agent) return;
|
|
68
|
-
const projectId = stringAttr(this, "project-id");
|
|
69
|
-
const apiKey = stringAttr(this, "api-key");
|
|
70
|
-
if (!projectId || !apiKey) {
|
|
71
|
-
console.error(
|
|
72
|
-
"daba-agent: <daba-agent> custom element requires project-id and api-key attributes.",
|
|
73
|
-
this
|
|
74
|
-
);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const position = enumAttr(this, "position", VALID_POSITIONS);
|
|
78
|
-
const accentColor = stringAttr(this, "accent-color");
|
|
79
|
-
const mode = enumAttr(this, "mode", VALID_MODES);
|
|
80
|
-
const title = stringAttr(this, "title");
|
|
81
|
-
const placeholder = stringAttr(this, "placeholder");
|
|
82
|
-
const initialOpen = flagAttr(this, "initial-open");
|
|
83
|
-
const hotkey = stringAttr(this, "hotkey");
|
|
84
|
-
const gatewayUrl = stringAttr(this, "gateway-url");
|
|
85
|
-
const env = stringAttr(this, "env");
|
|
86
|
-
const theme = group({
|
|
87
|
-
accentColor,
|
|
88
|
-
accentContrast: stringAttr(this, "accent-contrast"),
|
|
89
|
-
surfaceColor: stringAttr(this, "surface-color"),
|
|
90
|
-
textColor: stringAttr(this, "text-color"),
|
|
91
|
-
radius: stringAttr(this, "radius"),
|
|
92
|
-
fontFamily: stringAttr(this, "font-family"),
|
|
93
|
-
theme: enumAttr(this, "theme", VALID_THEMES)
|
|
94
|
-
});
|
|
95
|
-
const introDisabled = flagAttr(this, "intro-disabled");
|
|
96
|
-
const intro = group({
|
|
97
|
-
enabled: introDisabled === void 0 ? void 0 : !introDisabled,
|
|
98
|
-
headline: stringAttr(this, "intro-headline"),
|
|
99
|
-
subheadline: stringAttr(this, "intro-subheadline"),
|
|
100
|
-
mediaUrl: stringAttr(this, "intro-media-url"),
|
|
101
|
-
mediaType: enumAttr(this, "intro-media-type", VALID_MEDIA_TYPES),
|
|
102
|
-
suggestedPrompts: promptsAttr(this, "suggested-prompts")
|
|
103
|
-
});
|
|
104
|
-
const launcher = group({
|
|
105
|
-
shape: enumAttr(this, "launcher-shape", VALID_LAUNCHER_SHAPES),
|
|
106
|
-
iconUrl: stringAttr(this, "launcher-icon-url"),
|
|
107
|
-
label: stringAttr(this, "launcher-label")
|
|
108
|
-
});
|
|
109
|
-
this.agent = new chunkIMPMGYCG_cjs.DabaAgent({
|
|
110
|
-
container: this,
|
|
111
|
-
projectId,
|
|
112
|
-
apiKey,
|
|
113
|
-
position,
|
|
114
|
-
accentColor,
|
|
115
|
-
mode,
|
|
116
|
-
title,
|
|
117
|
-
placeholder,
|
|
118
|
-
initialOpen,
|
|
119
|
-
hotkey,
|
|
120
|
-
gatewayUrl,
|
|
121
|
-
env,
|
|
122
|
-
theme,
|
|
123
|
-
intro,
|
|
124
|
-
launcher,
|
|
125
|
-
logoUrl: stringAttr(this, "logo-url"),
|
|
126
|
-
uiLanguage: stringAttr(this, "ui-language"),
|
|
127
|
-
direction: enumAttr(this, "direction", VALID_DIRECTIONS),
|
|
128
|
-
onStatusChange: (status) => {
|
|
129
|
-
this.dispatchEvent(
|
|
130
|
-
new CustomEvent("daba-status-change", { detail: { status }, bubbles: true, composed: true })
|
|
131
|
-
);
|
|
132
|
-
},
|
|
133
|
-
onTranscript: (role, text, isFinal) => {
|
|
134
|
-
this.dispatchEvent(
|
|
135
|
-
new CustomEvent("daba-transcript", {
|
|
136
|
-
detail: { role, text, isFinal },
|
|
137
|
-
bubbles: true,
|
|
138
|
-
composed: true
|
|
139
|
-
})
|
|
140
|
-
);
|
|
141
|
-
},
|
|
142
|
-
onError: (error) => {
|
|
143
|
-
this.dispatchEvent(
|
|
144
|
-
new CustomEvent("daba-error", { detail: { error }, bubbles: true, composed: true })
|
|
145
|
-
);
|
|
146
|
-
},
|
|
147
|
-
onChatToggle: (isOpen) => {
|
|
148
|
-
this.dispatchEvent(
|
|
149
|
-
new CustomEvent("daba-chat-toggle", { detail: { isOpen }, bubbles: true, composed: true })
|
|
150
|
-
);
|
|
151
|
-
},
|
|
152
|
-
// Cards arrive once per reply that carried structured items, so a
|
|
153
|
-
// host page can render them in its own layout instead of (or as well
|
|
154
|
-
// as) the panel's — a listing site putting event cards on the page.
|
|
155
|
-
onCards: (cards) => {
|
|
156
|
-
this.dispatchEvent(
|
|
157
|
-
new CustomEvent("daba-cards", { detail: { cards }, bubbles: true, composed: true })
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
disconnectedCallback() {
|
|
163
|
-
if (this.agent) {
|
|
164
|
-
this.agent.destroy();
|
|
165
|
-
this.agent = null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
get dabaAgent() {
|
|
169
|
-
return this.agent;
|
|
170
|
-
}
|
|
171
|
-
sendText(text) {
|
|
172
|
-
return this.agent?.sendText(text);
|
|
173
|
-
}
|
|
174
|
-
openChat() {
|
|
175
|
-
this.agent?.openChat();
|
|
176
|
-
}
|
|
177
|
-
closeChat() {
|
|
178
|
-
this.agent?.closeChat();
|
|
179
|
-
}
|
|
180
|
-
toggleChat() {
|
|
181
|
-
this.agent?.toggleChat();
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
function defineDabaAgentElement(tagName = "daba-agent") {
|
|
185
|
-
if (typeof window !== "undefined" && typeof customElements !== "undefined") {
|
|
186
|
-
if (!customElements.get(tagName)) {
|
|
187
|
-
customElements.define(tagName, DabaAgentElement);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
defineDabaAgentElement();
|
|
192
|
-
|
|
193
|
-
exports.DabaAgentElement = DabaAgentElement;
|
|
194
|
-
exports.defineDabaAgentElement = defineDabaAgentElement;
|
|
195
|
-
//# sourceMappingURL=chunk-HJPH4GNS.cjs.map
|
|
196
|
-
//# sourceMappingURL=chunk-HJPH4GNS.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/custom-element.ts"],"names":["DabaAgent"],"mappings":";;;;;AAaA,IAAM,eAAA,GAAgD;AAAA,EACpD,cAAA;AAAA,EACA,aAAA;AAAA,EACA,WAAA;AAAA,EACA;AACF,CAAA;AACA,IAAM,WAAA,GAAwC,CAAC,OAAA,EAAS,MAAA,EAAQ,QAAQ,C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","file":"chunk-HJPH4GNS.cjs","sourcesContent":["import { DabaAgent } from \"../agent\";\nimport type {\n DabaAgentMode,\n DabaAgentOptions,\n DabaAgentPosition,\n DabaDirection,\n DabaIntro,\n DabaLauncher,\n DabaLauncherShape,\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/** 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\nexport class DabaAgentElement extends HTMLElement {\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 label: stringAttr(this, \"launcher-label\"),\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 hotkey,\n gatewayUrl,\n env,\n theme,\n intro,\n launcher,\n logoUrl: stringAttr(this, \"logo-url\"),\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}\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"]}
|