@webless/agent 0.2.0 → 0.2.6

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/dist/embed.js CHANGED
@@ -1,142 +1,34 @@
1
+ import "./embed.css";
1
2
  import {
2
- AgentRail,
3
- AssistEdgeTab,
3
+ AgentWidget,
4
+ DEFAULT_AGENT_PLACEMENT,
4
5
  DEFAULT_RUNTIME_ORIGIN,
5
- createIdleSuggestions,
6
- hasVisitorMessages,
7
- resolveAgentRuntimeConfig,
8
- useAgentChat
9
- } from "./chunk-WLQDMWO6.js";
6
+ closeAgentPanel,
7
+ normalizeAgentPlacement,
8
+ openAgentPanel,
9
+ resolveAgentRuntimeConfig
10
+ } from "./chunk-GMG4WJNF.js";
10
11
 
11
12
  // src/embed/mount.tsx
12
13
  import { createRoot } from "react-dom/client";
13
14
 
14
- // src/embed/controller.ts
15
- var controllers = /* @__PURE__ */ new Map();
16
- function registerAgentPanelController(customerId, controller) {
17
- controllers.set(customerId, controller);
18
- }
19
- function unregisterAgentPanelController(customerId) {
20
- controllers.delete(customerId);
21
- }
22
- function openAgentPanel(customerId) {
23
- controllers.get(customerId)?.open();
24
- }
25
- function closeAgentPanel(customerId) {
26
- controllers.get(customerId)?.close();
27
- }
28
-
29
15
  // src/embed/AgentWidget.tsx
30
- import { useEffect, useState } from "react";
31
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
32
- function useIsMobile(breakpoint = 767) {
33
- const [isMobile, setIsMobile] = useState(
34
- () => typeof window !== "undefined" && window.matchMedia(`(max-width: ${breakpoint}px)`).matches
16
+ import { jsx } from "react/jsx-runtime";
17
+ function AgentWidget2({ manifest }) {
18
+ return /* @__PURE__ */ jsx(
19
+ AgentWidget,
20
+ {
21
+ indexId: manifest.indexId,
22
+ customerId: manifest.customerId,
23
+ runtimeOrigin: manifest.runtimeOrigin,
24
+ placement: manifest.placement,
25
+ defaultCollapsed: true,
26
+ registerPanelController: true
27
+ }
35
28
  );
36
- useEffect(() => {
37
- const media = window.matchMedia(`(max-width: ${breakpoint}px)`);
38
- const onChange = () => setIsMobile(media.matches);
39
- onChange();
40
- media.addEventListener("change", onChange);
41
- return () => media.removeEventListener("change", onChange);
42
- }, [breakpoint]);
43
- return isMobile;
44
- }
45
- function AgentWidget({ manifest }) {
46
- const isMobile = useIsMobile();
47
- const [railCollapsed, setRailCollapsed] = useState(true);
48
- const [railExpanded, setRailExpanded] = useState(false);
49
- const { state, submit } = useAgentChat({
50
- customerId: manifest.customerId,
51
- indexId: manifest.indexId,
52
- runtimeOrigin: manifest.runtimeOrigin
53
- });
54
- const idle = state.phase === "idle" && !hasVisitorMessages(state.messages);
55
- const placement = manifest.placement;
56
- useEffect(() => {
57
- registerAgentPanelController(manifest.customerId, {
58
- open: () => setRailCollapsed(false),
59
- close: () => {
60
- setRailCollapsed(true);
61
- setRailExpanded(false);
62
- }
63
- });
64
- return () => unregisterAgentPanelController(manifest.customerId);
65
- }, [manifest.customerId]);
66
- async function handleSubmit(message) {
67
- if (isMobile) setRailCollapsed(false);
68
- await submit(message);
69
- }
70
- return /* @__PURE__ */ jsxs(Fragment, { children: [
71
- /* @__PURE__ */ jsx(
72
- "div",
73
- {
74
- className: `webless-agent-root__shell${railCollapsed ? " webless-agent-root__shell--collapsed" : ""}${railExpanded ? " webless-agent-root__shell--expanded" : ""}`,
75
- children: /* @__PURE__ */ jsx(
76
- "div",
77
- {
78
- className: "webless-agent-root__rail-slot",
79
- inert: railCollapsed || void 0,
80
- "aria-hidden": railCollapsed,
81
- children: /* @__PURE__ */ jsx(
82
- AgentRail,
83
- {
84
- state: idle ? {
85
- ...state,
86
- followUps: createIdleSuggestions()
87
- } : state,
88
- mobileFullscreen: isMobile && !railCollapsed,
89
- expanded: railExpanded,
90
- onCollapse: !isMobile ? () => setRailCollapsed(true) : void 0,
91
- onClose: isMobile ? () => setRailCollapsed(true) : void 0,
92
- onExpandToggle: !isMobile ? () => setRailExpanded((current) => !current) : void 0,
93
- onSubmit: handleSubmit,
94
- onFollowUpSelect: (label) => void handleSubmit(label)
95
- }
96
- )
97
- }
98
- )
99
- }
100
- ),
101
- !isMobile && railExpanded && !railCollapsed ? /* @__PURE__ */ jsx(
102
- "button",
103
- {
104
- type: "button",
105
- className: "webless-agent-root__backdrop",
106
- "aria-label": "Close expanded assist",
107
- onClick: () => setRailExpanded(false)
108
- }
109
- ) : null,
110
- railCollapsed ? /* @__PURE__ */ jsx(
111
- AssistEdgeTab,
112
- {
113
- variant: placement.variant,
114
- side: placement.side,
115
- along: placement.along,
116
- inset: placement.inset,
117
- visible: true,
118
- onOpen: () => setRailCollapsed(false)
119
- }
120
- ) : null
121
- ] });
122
29
  }
123
30
 
124
31
  // src/embed/manifest.ts
125
- var DEFAULT_AGENT_PLACEMENT = {
126
- side: "right",
127
- along: 50,
128
- inset: 0,
129
- variant: "outline"
130
- };
131
- function normalizeAgentPlacement(placement) {
132
- const along = placement?.along ?? DEFAULT_AGENT_PLACEMENT.along;
133
- return {
134
- side: placement?.side ?? DEFAULT_AGENT_PLACEMENT.side,
135
- along: Math.min(100, Math.max(0, along)),
136
- inset: Math.max(0, placement?.inset ?? DEFAULT_AGENT_PLACEMENT.inset),
137
- variant: placement?.variant ?? DEFAULT_AGENT_PLACEMENT.variant
138
- };
139
- }
140
32
  function normalizeAgentTagManifest(manifest) {
141
33
  const indexId = manifest.indexId.trim();
142
34
  if (!indexId) {
@@ -180,7 +72,6 @@ function resolveMountHost(manifest, script) {
180
72
  }
181
73
  function createHost(customerId) {
182
74
  const host = document.createElement("div");
183
- host.className = "webless-agent-root";
184
75
  host.dataset.weblessAgentCustomerId = customerId;
185
76
  host.setAttribute("data-webless-agent", customerId);
186
77
  return host;
@@ -195,7 +86,7 @@ function mountAgent(input) {
195
86
  const host = createHost(manifest.customerId);
196
87
  mountTarget.append(host);
197
88
  const root = createRoot(host);
198
- root.render(/* @__PURE__ */ jsx2(AgentWidget, { manifest }));
89
+ root.render(/* @__PURE__ */ jsx2(AgentWidget2, { manifest }));
199
90
  const handle = {
200
91
  customerId: manifest.customerId,
201
92
  manifest,
package/dist/embed.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/embed/mount.tsx","../src/embed/controller.ts","../src/embed/AgentWidget.tsx","../src/embed/manifest.ts"],"sourcesContent":["import { createRoot, type Root } from \"react-dom/client\";\nimport { closeAgentPanel, openAgentPanel } from \"./controller\";\nimport { AgentWidget } from \"./AgentWidget\";\nimport {\n normalizeAgentTagManifest,\n type AgentTagManifest,\n type NormalizedAgentTagManifest,\n} from \"./manifest\";\n\nexport type AgentRuntimeHandle = {\n customerId: string;\n manifest: NormalizedAgentTagManifest;\n host: HTMLElement;\n root: Root;\n open: () => void;\n close: () => void;\n unmount: () => void;\n};\n\nconst mountedHandles = new Map<string, AgentRuntimeHandle>();\nlet latestCustomerId: string | null = null;\n\nfunction resolveMountHost(manifest: NormalizedAgentTagManifest, script?: HTMLScriptElement | null) {\n const strategy = manifest.mount.strategy ?? \"body\";\n\n if (strategy === \"script-parent\" && script?.parentElement instanceof HTMLElement) {\n return script.parentElement;\n }\n\n if (strategy === \"selector\" && manifest.mount.selector) {\n const target = document.querySelector(manifest.mount.selector);\n if (target instanceof HTMLElement) return target;\n }\n\n return document.body;\n}\n\nfunction createHost(customerId: string) {\n const host = document.createElement(\"div\");\n host.className = \"webless-agent-root\";\n host.dataset.weblessAgentCustomerId = customerId;\n host.setAttribute(\"data-webless-agent\", customerId);\n return host;\n}\n\nexport function mountAgent(input: {\n manifest: AgentTagManifest;\n script?: HTMLScriptElement | null;\n}): AgentRuntimeHandle {\n const manifest = normalizeAgentTagManifest(input.manifest);\n const existing = mountedHandles.get(manifest.customerId);\n if (existing) {\n return existing;\n }\n\n const mountTarget = resolveMountHost(manifest, input.script ?? null);\n const host = createHost(manifest.customerId);\n mountTarget.append(host);\n\n const root = createRoot(host);\n root.render(<AgentWidget manifest={manifest} />);\n\n const handle: AgentRuntimeHandle = {\n customerId: manifest.customerId,\n manifest,\n host,\n root,\n open: () => {\n openAgentPanel(manifest.customerId);\n },\n close: () => {\n closeAgentPanel(manifest.customerId);\n },\n unmount: () => {\n root.unmount();\n host.remove();\n mountedHandles.delete(manifest.customerId);\n if (latestCustomerId === manifest.customerId) {\n latestCustomerId = null;\n }\n },\n };\n\n mountedHandles.set(manifest.customerId, handle);\n latestCustomerId = manifest.customerId;\n return handle;\n}\n\nexport function unmountAgent(customerId?: string) {\n const id = customerId ?? latestCustomerId;\n if (!id) return false;\n const handle = mountedHandles.get(id);\n if (!handle) return false;\n handle.unmount();\n return true;\n}\n\nexport function getMountedAgent(customerId?: string) {\n if (customerId) return mountedHandles.get(customerId) ?? null;\n if (latestCustomerId) return mountedHandles.get(latestCustomerId) ?? null;\n return mountedHandles.values().next().value ?? null;\n}\n\nexport function bootstrapAgent(manifest: AgentTagManifest, script?: HTMLScriptElement | null) {\n return mountAgent({ manifest, script });\n}\n","type AgentPanelController = {\n open: () => void;\n close: () => void;\n};\n\nconst controllers = new Map<string, AgentPanelController>();\n\nexport function registerAgentPanelController(customerId: string, controller: AgentPanelController) {\n controllers.set(customerId, controller);\n}\n\nexport function unregisterAgentPanelController(customerId: string) {\n controllers.delete(customerId);\n}\n\nexport function openAgentPanel(customerId: string) {\n controllers.get(customerId)?.open();\n}\n\nexport function closeAgentPanel(customerId: string) {\n controllers.get(customerId)?.close();\n}\n","import { useEffect, useState } from \"react\";\nimport { AgentRail } from \"../react/components/AgentRail\";\nimport { AssistEdgeTab } from \"../react/components/AssistEdgeTab/AssistEdgeTab\";\nimport {\n createIdleSuggestions,\n hasVisitorMessages,\n useAgentChat,\n} from \"../react/hooks/useAgentChat\";\nimport {\n registerAgentPanelController,\n unregisterAgentPanelController,\n} from \"./controller\";\nimport type { NormalizedAgentTagManifest } from \"./manifest\";\nimport \"../react/styles/tokens.css\";\nimport \"../react/styles/widget.css\";\nimport \"../react/components/AgentRail/AgentRail.css\";\nimport \"../react/components/AgentActivityBubble/AgentActivityBubble.css\";\nimport \"../react/components/Composer/Composer.css\";\nimport \"../react/components/FollowUpChips/FollowUpChips.css\";\nimport \"../react/components/MessageBubble/MessageBubble.css\";\nimport \"../react/components/ToolTimeline/ToolTimeline.css\";\nimport \"../react/components/AssistEdgeTab/AssistEdgeTab.css\";\n\nfunction useIsMobile(breakpoint = 767) {\n const [isMobile, setIsMobile] = useState(\n () => typeof window !== \"undefined\" && window.matchMedia(`(max-width: ${breakpoint}px)`).matches,\n );\n\n useEffect(() => {\n const media = window.matchMedia(`(max-width: ${breakpoint}px)`);\n const onChange = () => setIsMobile(media.matches);\n onChange();\n media.addEventListener(\"change\", onChange);\n return () => media.removeEventListener(\"change\", onChange);\n }, [breakpoint]);\n\n return isMobile;\n}\n\nexport function AgentWidget({ manifest }: { manifest: NormalizedAgentTagManifest }) {\n const isMobile = useIsMobile();\n const [railCollapsed, setRailCollapsed] = useState(true);\n const [railExpanded, setRailExpanded] = useState(false);\n const { state, submit } = useAgentChat({\n customerId: manifest.customerId,\n indexId: manifest.indexId,\n runtimeOrigin: manifest.runtimeOrigin,\n });\n\n const idle = state.phase === \"idle\" && !hasVisitorMessages(state.messages);\n const placement = manifest.placement;\n\n useEffect(() => {\n registerAgentPanelController(manifest.customerId, {\n open: () => setRailCollapsed(false),\n close: () => {\n setRailCollapsed(true);\n setRailExpanded(false);\n },\n });\n return () => unregisterAgentPanelController(manifest.customerId);\n }, [manifest.customerId]);\n\n async function handleSubmit(message: string) {\n if (isMobile) setRailCollapsed(false);\n await submit(message);\n }\n\n return (\n <>\n <div\n className={`webless-agent-root__shell${railCollapsed ? \" webless-agent-root__shell--collapsed\" : \"\"}${railExpanded ? \" webless-agent-root__shell--expanded\" : \"\"}`}\n >\n <div\n className=\"webless-agent-root__rail-slot\"\n inert={railCollapsed || undefined}\n aria-hidden={railCollapsed}\n >\n <AgentRail\n state={\n idle\n ? {\n ...state,\n followUps: createIdleSuggestions(),\n }\n : state\n }\n mobileFullscreen={isMobile && !railCollapsed}\n expanded={railExpanded}\n onCollapse={!isMobile ? () => setRailCollapsed(true) : undefined}\n onClose={isMobile ? () => setRailCollapsed(true) : undefined}\n onExpandToggle={!isMobile ? () => setRailExpanded((current) => !current) : undefined}\n onSubmit={handleSubmit}\n onFollowUpSelect={(label) => void handleSubmit(label)}\n />\n </div>\n </div>\n\n {!isMobile && railExpanded && !railCollapsed ? (\n <button\n type=\"button\"\n className=\"webless-agent-root__backdrop\"\n aria-label=\"Close expanded assist\"\n onClick={() => setRailExpanded(false)}\n />\n ) : null}\n\n {railCollapsed ? (\n <AssistEdgeTab\n variant={placement.variant}\n side={placement.side}\n along={placement.along}\n inset={placement.inset}\n visible\n onOpen={() => setRailCollapsed(false)}\n />\n ) : null}\n </>\n );\n}\n","import { DEFAULT_RUNTIME_ORIGIN, resolveAgentRuntimeConfig } from \"../runtime/config\";\n\nexport type AgentMountStrategy = \"body\" | \"selector\" | \"script-parent\";\n\nexport type AgentTabVariant = \"outline\";\nexport type AgentTabSide = \"right\" | \"left\" | \"top\" | \"bottom\";\n\nexport type AgentPlacementConfig = {\n side: AgentTabSide;\n along: number;\n inset: number;\n variant: AgentTabVariant;\n};\n\nexport type AgentTagManifest = {\n customerId: string;\n indexId: string;\n runtimeOrigin?: string;\n version?: string;\n mount?: {\n selector?: string;\n strategy?: AgentMountStrategy;\n };\n placement?: Partial<AgentPlacementConfig>;\n};\n\nexport const DEFAULT_AGENT_PLACEMENT: AgentPlacementConfig = {\n side: \"right\",\n along: 50,\n inset: 0,\n variant: \"outline\",\n};\n\nexport function normalizeAgentPlacement(\n placement?: Partial<AgentPlacementConfig>,\n): AgentPlacementConfig {\n const along = placement?.along ?? DEFAULT_AGENT_PLACEMENT.along;\n return {\n side: placement?.side ?? DEFAULT_AGENT_PLACEMENT.side,\n along: Math.min(100, Math.max(0, along)),\n inset: Math.max(0, placement?.inset ?? DEFAULT_AGENT_PLACEMENT.inset),\n variant: placement?.variant ?? DEFAULT_AGENT_PLACEMENT.variant,\n };\n}\n\nexport function normalizeAgentTagManifest(manifest: AgentTagManifest) {\n const indexId = manifest.indexId.trim();\n if (!indexId) {\n throw new Error(\"Agent manifest requires indexId.\");\n }\n\n const customerId = manifest.customerId.trim();\n if (!customerId) {\n throw new Error(\"Agent manifest requires customerId.\");\n }\n\n const runtime = resolveAgentRuntimeConfig({\n indexId,\n runtimeOrigin: manifest.runtimeOrigin?.trim() || DEFAULT_RUNTIME_ORIGIN,\n });\n\n return {\n customerId,\n indexId,\n runtimeOrigin: runtime.origin,\n version: manifest.version?.trim() || \"published\",\n mount: {\n selector: manifest.mount?.selector?.trim(),\n strategy: manifest.mount?.strategy ?? \"body\",\n },\n placement: normalizeAgentPlacement(manifest.placement),\n };\n}\n\nexport type NormalizedAgentTagManifest = ReturnType<typeof normalizeAgentTagManifest>;\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,kBAA6B;;;ACKtC,IAAM,cAAc,oBAAI,IAAkC;AAEnD,SAAS,6BAA6B,YAAoB,YAAkC;AACjG,cAAY,IAAI,YAAY,UAAU;AACxC;AAEO,SAAS,+BAA+B,YAAoB;AACjE,cAAY,OAAO,UAAU;AAC/B;AAEO,SAAS,eAAe,YAAoB;AACjD,cAAY,IAAI,UAAU,GAAG,KAAK;AACpC;AAEO,SAAS,gBAAgB,YAAoB;AAClD,cAAY,IAAI,UAAU,GAAG,MAAM;AACrC;;;ACrBA,SAAS,WAAW,gBAAgB;AAqEhC,mBASM,KATN;AA9CJ,SAAS,YAAY,aAAa,KAAK;AACrC,QAAM,CAAC,UAAU,WAAW,IAAI;AAAA,IAC9B,MAAM,OAAO,WAAW,eAAe,OAAO,WAAW,eAAe,UAAU,KAAK,EAAE;AAAA,EAC3F;AAEA,YAAU,MAAM;AACd,UAAM,QAAQ,OAAO,WAAW,eAAe,UAAU,KAAK;AAC9D,UAAM,WAAW,MAAM,YAAY,MAAM,OAAO;AAChD,aAAS;AACT,UAAM,iBAAiB,UAAU,QAAQ;AACzC,WAAO,MAAM,MAAM,oBAAoB,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EvB,QAAM,OAAO,WAAW,IAAI;AAC5B,OAAK,OAAO,gBAAAA,KAAC,eAAY,UAAoB,CAAE;AAE/C,QAAM,SAA6B;AAAA,IACjC,YAAY,SAAS;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,MAAM;AACV,qBAAe,SAAS,UAAU;AAAA,IACpC;AAAA,IACA,OAAO,MAAM;AACX,sBAAgB,SAAS,UAAU;AAAA,IACrC;AAAA,IACA,SAAS,MAAM;AACb,WAAK,QAAQ;AACb,WAAK,OAAO;AACZ,qBAAe,OAAO,SAAS,UAAU;AACzC,UAAI,qBAAqB,SAAS,YAAY;AAC5C,2BAAmB;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,iBAAe,IAAI,SAAS,YAAY,MAAM;AAC9C,qBAAmB,SAAS;AAC5B,SAAO;AACT;AAEO,SAAS,aAAa,YAAqB;AAChD,QAAM,KAAK,cAAc;AACzB,MAAI,CAAC,GAAI,QAAO;AAChB,QAAM,SAAS,eAAe,IAAI,EAAE;AACpC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,QAAQ;AACf,SAAO;AACT;AAEO,SAAS,gBAAgB,YAAqB;AACnD,MAAI,WAAY,QAAO,eAAe,IAAI,UAAU,KAAK;AACzD,MAAI,iBAAkB,QAAO,eAAe,IAAI,gBAAgB,KAAK;AACrE,SAAO,eAAe,OAAO,EAAE,KAAK,EAAE,SAAS;AACjD;AAEO,SAAS,eAAe,UAA4B,QAAmC;AAC5F,SAAO,WAAW,EAAE,UAAU,OAAO,CAAC;AACxC;","names":["jsx"]}
1
+ {"version":3,"sources":["../src/embed/mount.tsx","../src/embed/AgentWidget.tsx","../src/embed/manifest.ts"],"sourcesContent":["import { createRoot, type Root } from \"react-dom/client\";\nimport { closeAgentPanel, openAgentPanel } from \"./controller\";\nimport { AgentWidget } from \"./AgentWidget\";\nimport {\n normalizeAgentTagManifest,\n type AgentTagManifest,\n type NormalizedAgentTagManifest,\n} from \"./manifest\";\n\nexport type AgentRuntimeHandle = {\n customerId: string;\n manifest: NormalizedAgentTagManifest;\n host: HTMLElement;\n root: Root;\n open: () => void;\n close: () => void;\n unmount: () => void;\n};\n\nconst mountedHandles = new Map<string, AgentRuntimeHandle>();\nlet latestCustomerId: string | null = null;\n\nfunction resolveMountHost(manifest: NormalizedAgentTagManifest, script?: HTMLScriptElement | null) {\n const strategy = manifest.mount.strategy ?? \"body\";\n\n if (strategy === \"script-parent\" && script?.parentElement instanceof HTMLElement) {\n return script.parentElement;\n }\n\n if (strategy === \"selector\" && manifest.mount.selector) {\n const target = document.querySelector(manifest.mount.selector);\n if (target instanceof HTMLElement) return target;\n }\n\n return document.body;\n}\n\nfunction createHost(customerId: string) {\n const host = document.createElement(\"div\");\n host.dataset.weblessAgentCustomerId = customerId;\n host.setAttribute(\"data-webless-agent\", customerId);\n return host;\n}\n\nexport function mountAgent(input: {\n manifest: AgentTagManifest;\n script?: HTMLScriptElement | null;\n}): AgentRuntimeHandle {\n const manifest = normalizeAgentTagManifest(input.manifest);\n const existing = mountedHandles.get(manifest.customerId);\n if (existing) {\n return existing;\n }\n\n const mountTarget = resolveMountHost(manifest, input.script ?? null);\n const host = createHost(manifest.customerId);\n mountTarget.append(host);\n\n const root = createRoot(host);\n root.render(<AgentWidget manifest={manifest} />);\n\n const handle: AgentRuntimeHandle = {\n customerId: manifest.customerId,\n manifest,\n host,\n root,\n open: () => {\n openAgentPanel(manifest.customerId);\n },\n close: () => {\n closeAgentPanel(manifest.customerId);\n },\n unmount: () => {\n root.unmount();\n host.remove();\n mountedHandles.delete(manifest.customerId);\n if (latestCustomerId === manifest.customerId) {\n latestCustomerId = null;\n }\n },\n };\n\n mountedHandles.set(manifest.customerId, handle);\n latestCustomerId = manifest.customerId;\n return handle;\n}\n\nexport function unmountAgent(customerId?: string) {\n const id = customerId ?? latestCustomerId;\n if (!id) return false;\n const handle = mountedHandles.get(id);\n if (!handle) return false;\n handle.unmount();\n return true;\n}\n\nexport function getMountedAgent(customerId?: string) {\n if (customerId) return mountedHandles.get(customerId) ?? null;\n if (latestCustomerId) return mountedHandles.get(latestCustomerId) ?? null;\n return mountedHandles.values().next().value ?? null;\n}\n\nexport function bootstrapAgent(manifest: AgentTagManifest, script?: HTMLScriptElement | null) {\n return mountAgent({ manifest, script });\n}\n","import { AgentWidget as WeblessAgentWidget } from \"../react/components/AgentWidget\";\nimport type { NormalizedAgentTagManifest } from \"./manifest\";\n\nexport function AgentWidget({ manifest }: { manifest: NormalizedAgentTagManifest }) {\n return (\n <WeblessAgentWidget\n indexId={manifest.indexId}\n customerId={manifest.customerId}\n runtimeOrigin={manifest.runtimeOrigin}\n placement={manifest.placement}\n defaultCollapsed\n registerPanelController\n />\n );\n}\n","import { DEFAULT_RUNTIME_ORIGIN, resolveAgentRuntimeConfig } from \"../runtime/config\";\nimport {\n DEFAULT_AGENT_PLACEMENT,\n normalizeAgentPlacement,\n type AgentPlacementConfig,\n} from \"../react/placement\";\n\nexport type { AgentPlacementConfig };\nexport type AgentMountStrategy = \"body\" | \"selector\" | \"script-parent\";\n\nexport type AgentTabVariant = AgentPlacementConfig[\"variant\"];\nexport type AgentTabSide = AgentPlacementConfig[\"side\"];\n\nexport type AgentTagManifest = {\n customerId: string;\n indexId: string;\n runtimeOrigin?: string;\n version?: string;\n mount?: {\n selector?: string;\n strategy?: AgentMountStrategy;\n };\n placement?: Partial<AgentPlacementConfig>;\n};\n\nexport { DEFAULT_AGENT_PLACEMENT, normalizeAgentPlacement };\n\nexport function normalizeAgentTagManifest(manifest: AgentTagManifest) {\n const indexId = manifest.indexId.trim();\n if (!indexId) {\n throw new Error(\"Agent manifest requires indexId.\");\n }\n\n const customerId = manifest.customerId.trim();\n if (!customerId) {\n throw new Error(\"Agent manifest requires customerId.\");\n }\n\n const runtime = resolveAgentRuntimeConfig({\n indexId,\n runtimeOrigin: manifest.runtimeOrigin?.trim() || DEFAULT_RUNTIME_ORIGIN,\n });\n\n return {\n customerId,\n indexId,\n runtimeOrigin: runtime.origin,\n version: manifest.version?.trim() || \"published\",\n mount: {\n selector: manifest.mount?.selector?.trim(),\n strategy: manifest.mount?.strategy ?? \"body\",\n },\n placement: normalizeAgentPlacement(manifest.placement),\n };\n}\n\nexport type NormalizedAgentTagManifest = ReturnType<typeof normalizeAgentTagManifest>;\n"],"mappings":";;;;;;;;;;;AAAA,SAAS,kBAA6B;;;ACKlC;AAFG,SAASA,aAAY,EAAE,SAAS,GAA6C;AAClF,SACE;AAAA,IAAC;AAAA;AAAA,MACC,SAAS,SAAS;AAAA,MAClB,YAAY,SAAS;AAAA,MACrB,eAAe,SAAS;AAAA,MACxB,WAAW,SAAS;AAAA,MACpB,kBAAgB;AAAA,MAChB,yBAAuB;AAAA;AAAA,EACzB;AAEJ;;;ACaO,SAAS,0BAA0B,UAA4B;AACpE,QAAM,UAAU,SAAS,QAAQ,KAAK;AACtC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,kCAAkC;AAAA,EACpD;AAEA,QAAM,aAAa,SAAS,WAAW,KAAK;AAC5C,MAAI,CAAC,YAAY;AACf,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AAEA,QAAM,UAAU,0BAA0B;AAAA,IACxC;AAAA,IACA,eAAe,SAAS,eAAe,KAAK,KAAK;AAAA,EACnD,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,eAAe,QAAQ;AAAA,IACvB,SAAS,SAAS,SAAS,KAAK,KAAK;AAAA,IACrC,OAAO;AAAA,MACL,UAAU,SAAS,OAAO,UAAU,KAAK;AAAA,MACzC,UAAU,SAAS,OAAO,YAAY;AAAA,IACxC;AAAA,IACA,WAAW,wBAAwB,SAAS,SAAS;AAAA,EACvD;AACF;;;AFKc,gBAAAC,YAAA;AAxCd,IAAM,iBAAiB,oBAAI,IAAgC;AAC3D,IAAI,mBAAkC;AAEtC,SAAS,iBAAiB,UAAsC,QAAmC;AACjG,QAAM,WAAW,SAAS,MAAM,YAAY;AAE5C,M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C,GAAI,QAAO;AAChB,QAAM,SAAS,eAAe,IAAI,EAAE;AACpC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,QAAQ;AACf,SAAO;AACT;AAEO,SAAS,gBAAgB,YAAqB;AACnD,MAAI,WAAY,QAAO,eAAe,IAAI,UAAU,KAAK;AACzD,MAAI,iBAAkB,QAAO,eAAe,IAAI,gBAAgB,KAAK;AACrE,SAAO,eAAe,OAAO,EAAE,KAAK,EAAE,SAAS;AACjD;AAEO,SAAS,eAAe,UAA4B,QAAmC;AAC5F,SAAO,WAAW,EAAE,UAAU,OAAO,CAAC;AACxC;","names":["AgentWidget","jsx","AgentWidget"]}
@@ -0,0 +1,23 @@
1
+ import * as react from 'react';
2
+
3
+ type AssistTabVariant = "outline" | "ask" | "fill";
4
+ type AssistTabSide = "right" | "left" | "top" | "bottom";
5
+ declare function AssistEdgeTab({ variant, side, along, inset, visible, onOpen, }: {
6
+ variant: AssistTabVariant;
7
+ side: AssistTabSide;
8
+ along: number;
9
+ inset: number;
10
+ visible: boolean;
11
+ onOpen: () => void;
12
+ }): react.JSX.Element;
13
+
14
+ type AgentPlacementConfig = {
15
+ side: AssistTabSide;
16
+ along: number;
17
+ inset: number;
18
+ variant: AssistTabVariant;
19
+ };
20
+ declare const DEFAULT_AGENT_PLACEMENT: AgentPlacementConfig;
21
+ declare function normalizeAgentPlacement(placement?: Partial<AgentPlacementConfig>): AgentPlacementConfig;
22
+
23
+ export { type AgentPlacementConfig as A, DEFAULT_AGENT_PLACEMENT as D, AssistEdgeTab as a, type AssistTabSide as b, type AssistTabVariant as c, normalizeAgentPlacement as n };
@@ -0,0 +1,23 @@
1
+ import * as react from 'react';
2
+
3
+ type AssistTabVariant = "outline" | "ask" | "fill";
4
+ type AssistTabSide = "right" | "left" | "top" | "bottom";
5
+ declare function AssistEdgeTab({ variant, side, along, inset, visible, onOpen, }: {
6
+ variant: AssistTabVariant;
7
+ side: AssistTabSide;
8
+ along: number;
9
+ inset: number;
10
+ visible: boolean;
11
+ onOpen: () => void;
12
+ }): react.JSX.Element;
13
+
14
+ type AgentPlacementConfig = {
15
+ side: AssistTabSide;
16
+ along: number;
17
+ inset: number;
18
+ variant: AssistTabVariant;
19
+ };
20
+ declare const DEFAULT_AGENT_PLACEMENT: AgentPlacementConfig;
21
+ declare function normalizeAgentPlacement(placement?: Partial<AgentPlacementConfig>): AgentPlacementConfig;
22
+
23
+ export { type AgentPlacementConfig as A, DEFAULT_AGENT_PLACEMENT as D, AssistEdgeTab as a, type AssistTabSide as b, type AssistTabVariant as c, normalizeAgentPlacement as n };