@bikdotai/bik-component-library 0.0.863-beta.0 → 0.0.863-beta.1

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 (97) hide show
  1. package/dist/cjs/components/agent-builder/utils/mentionSerialization.js +2 -2
  2. package/dist/cjs/components/agent-builder/utils/mentionSerialization.js.map +1 -1
  3. package/dist/cjs/components/bik-copilot/BIKCopilot.js +2 -0
  4. package/dist/cjs/components/bik-copilot/BIKCopilot.js.map +1 -0
  5. package/dist/cjs/components/bik-copilot/ControlledCopilot.js +2 -0
  6. package/dist/cjs/components/bik-copilot/ControlledCopilot.js.map +1 -0
  7. package/dist/cjs/components/bik-copilot/ControlledCopilot.styled.js +27 -0
  8. package/dist/cjs/components/bik-copilot/ControlledCopilot.styled.js.map +1 -0
  9. package/dist/cjs/components/bik-copilot/CopilotBall.js +2 -0
  10. package/dist/cjs/components/bik-copilot/CopilotBall.js.map +1 -0
  11. package/dist/cjs/components/bik-copilot/CopilotBall.styled.js +42 -0
  12. package/dist/cjs/components/bik-copilot/CopilotBall.styled.js.map +1 -0
  13. package/dist/cjs/components/bik-copilot/CopilotPanel.js +2 -0
  14. package/dist/cjs/components/bik-copilot/CopilotPanel.js.map +1 -0
  15. package/dist/cjs/components/bik-copilot/CopilotPanel.styled.js +460 -0
  16. package/dist/cjs/components/bik-copilot/CopilotPanel.styled.js.map +1 -0
  17. package/dist/cjs/components/bik-copilot/copilotPlacement.js +2 -0
  18. package/dist/cjs/components/bik-copilot/copilotPlacement.js.map +1 -0
  19. package/dist/cjs/components/bik-copilot/services/copilotDb.js +2 -0
  20. package/dist/cjs/components/bik-copilot/services/copilotDb.js.map +1 -0
  21. package/dist/cjs/components/bik-copilot/services/copilotIcebreakersClient.js +2 -0
  22. package/dist/cjs/components/bik-copilot/services/copilotIcebreakersClient.js.map +1 -0
  23. package/dist/cjs/components/bik-copilot/services/copilotMessagesClient.js +2 -0
  24. package/dist/cjs/components/bik-copilot/services/copilotMessagesClient.js.map +1 -0
  25. package/dist/cjs/components/bik-copilot/services/copilotPageSession.js +2 -0
  26. package/dist/cjs/components/bik-copilot/services/copilotPageSession.js.map +1 -0
  27. package/dist/cjs/components/bik-copilot/services/copilotSseParser.js +7 -0
  28. package/dist/cjs/components/bik-copilot/services/copilotSseParser.js.map +1 -0
  29. package/dist/cjs/components/bik-copilot/services/copilotStreamClient.js +2 -0
  30. package/dist/cjs/components/bik-copilot/services/copilotStreamClient.js.map +1 -0
  31. package/dist/cjs/components/bik-copilot/useCopilotIcebreakers.js +2 -0
  32. package/dist/cjs/components/bik-copilot/useCopilotIcebreakers.js.map +1 -0
  33. package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js +2 -0
  34. package/dist/cjs/components/bik-copilot/useCopilotStreamChat.js.map +1 -0
  35. package/dist/cjs/components/bik-copilot/useDraggableFloater.js +2 -0
  36. package/dist/cjs/components/bik-copilot/useDraggableFloater.js.map +1 -0
  37. package/dist/cjs/index.js +1 -1
  38. package/dist/esm/components/agent-builder/utils/mentionSerialization.d.ts +1 -3
  39. package/dist/esm/components/agent-builder/utils/mentionSerialization.js +14 -22
  40. package/dist/esm/components/agent-builder/utils/mentionSerialization.js.map +1 -1
  41. package/dist/esm/components/bik-copilot/BIKCopilot.d.ts +32 -0
  42. package/dist/esm/components/bik-copilot/BIKCopilot.js +114 -0
  43. package/dist/esm/components/bik-copilot/BIKCopilot.js.map +1 -0
  44. package/dist/esm/components/bik-copilot/ControlledCopilot.d.ts +14 -0
  45. package/dist/esm/components/bik-copilot/ControlledCopilot.js +170 -0
  46. package/dist/esm/components/bik-copilot/ControlledCopilot.js.map +1 -0
  47. package/dist/esm/components/bik-copilot/ControlledCopilot.styled.d.ts +7 -0
  48. package/dist/esm/components/bik-copilot/ControlledCopilot.styled.js +31 -0
  49. package/dist/esm/components/bik-copilot/ControlledCopilot.styled.js.map +1 -0
  50. package/dist/esm/components/bik-copilot/CopilotBall.d.ts +13 -0
  51. package/dist/esm/components/bik-copilot/CopilotBall.js +50 -0
  52. package/dist/esm/components/bik-copilot/CopilotBall.js.map +1 -0
  53. package/dist/esm/components/bik-copilot/CopilotBall.styled.d.ts +9 -0
  54. package/dist/esm/components/bik-copilot/CopilotBall.styled.js +46 -0
  55. package/dist/esm/components/bik-copilot/CopilotBall.styled.js.map +1 -0
  56. package/dist/esm/components/bik-copilot/CopilotPanel.d.ts +9 -0
  57. package/dist/esm/components/bik-copilot/CopilotPanel.js +379 -0
  58. package/dist/esm/components/bik-copilot/CopilotPanel.js.map +1 -0
  59. package/dist/esm/components/bik-copilot/CopilotPanel.styled.d.ts +64 -0
  60. package/dist/esm/components/bik-copilot/CopilotPanel.styled.js +496 -0
  61. package/dist/esm/components/bik-copilot/CopilotPanel.styled.js.map +1 -0
  62. package/dist/esm/components/bik-copilot/copilotPlacement.d.ts +24 -0
  63. package/dist/esm/components/bik-copilot/copilotPlacement.js +38 -0
  64. package/dist/esm/components/bik-copilot/copilotPlacement.js.map +1 -0
  65. package/dist/esm/components/bik-copilot/index.d.ts +16 -0
  66. package/dist/esm/components/bik-copilot/model.d.ts +674 -0
  67. package/dist/esm/components/bik-copilot/services/copilotDb.d.ts +90 -0
  68. package/dist/esm/components/bik-copilot/services/copilotDb.js +96 -0
  69. package/dist/esm/components/bik-copilot/services/copilotDb.js.map +1 -0
  70. package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.d.ts +11 -0
  71. package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.js +54 -0
  72. package/dist/esm/components/bik-copilot/services/copilotIcebreakersClient.js.map +1 -0
  73. package/dist/esm/components/bik-copilot/services/copilotMessagesClient.d.ts +23 -0
  74. package/dist/esm/components/bik-copilot/services/copilotMessagesClient.js +78 -0
  75. package/dist/esm/components/bik-copilot/services/copilotMessagesClient.js.map +1 -0
  76. package/dist/esm/components/bik-copilot/services/copilotPageSession.d.ts +37 -0
  77. package/dist/esm/components/bik-copilot/services/copilotPageSession.js +35 -0
  78. package/dist/esm/components/bik-copilot/services/copilotPageSession.js.map +1 -0
  79. package/dist/esm/components/bik-copilot/services/copilotSseParser.d.ts +22 -0
  80. package/dist/esm/components/bik-copilot/services/copilotSseParser.js +52 -0
  81. package/dist/esm/components/bik-copilot/services/copilotSseParser.js.map +1 -0
  82. package/dist/esm/components/bik-copilot/services/copilotStreamClient.d.ts +31 -0
  83. package/dist/esm/components/bik-copilot/services/copilotStreamClient.js +103 -0
  84. package/dist/esm/components/bik-copilot/services/copilotStreamClient.js.map +1 -0
  85. package/dist/esm/components/bik-copilot/useCopilotIcebreakers.d.ts +17 -0
  86. package/dist/esm/components/bik-copilot/useCopilotIcebreakers.js +60 -0
  87. package/dist/esm/components/bik-copilot/useCopilotIcebreakers.js.map +1 -0
  88. package/dist/esm/components/bik-copilot/useCopilotStreamChat.d.ts +20 -0
  89. package/dist/esm/components/bik-copilot/useCopilotStreamChat.js +333 -0
  90. package/dist/esm/components/bik-copilot/useCopilotStreamChat.js.map +1 -0
  91. package/dist/esm/components/bik-copilot/useDraggableFloater.d.ts +9 -0
  92. package/dist/esm/components/bik-copilot/useDraggableFloater.js +118 -0
  93. package/dist/esm/components/bik-copilot/useDraggableFloater.js.map +1 -0
  94. package/dist/esm/index.d.ts +1 -0
  95. package/dist/esm/index.js +832 -782
  96. package/dist/esm/index.js.map +1 -1
  97. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"mentionSerialization.js","sources":["../../../../../src/components/agent-builder/utils/mentionSerialization.ts"],"sourcesContent":["import type { ApplicationType } from '@bikdotai/bik-models/growth';\nimport { MentionItem } from '@src/editor';\nimport type {\n\tSubHeader,\n\tVariableListInterfaceV3,\n\tVariableV3,\n} from '../../variable-picker-v3/model';\nimport {\n\tAgentTool,\n\tConfigToolConfig,\n\tRestApiToolConfig,\n\tSubAgentRef,\n} from '../AgentBuilder.model';\nimport { TOOL_SOURCE_LABELS, ToolSource } from '../constants/tools';\n\n/**\n * Serialization helpers between the BikEditor document and the firebase\n * `instructions` string.\n *\n * Firebase stores `instructions` as PLAIN TEXT with inline reference tokens:\n * - `{{subagent:<agentId>}}` — hand-off to another agent\n * - `{{tool:<tool_id>}}` — an action the agent can call\n * - `{{variable:<name>}}` — a template variable picked from the catalog\n *\n * In the editor those references are inserted via the `@` mention menu (which we\n * populate with BOTH tools and sub-agents). Mention nodes keep their `id` in the\n * ProseMirror doc JSON (the rendered HTML drops it), so we serialize from the doc\n * JSON — not from HTML.\n */\n\nexport interface MentionKindMeta {\n\t/** Distinguishes a tool / sub-agent / variable reference. */\n\tkind: 'tool' | 'subagent' | 'variable';\n\t/** Plain item name (no prefix) shown in the picker dropdown rows. */\n\tplainLabel?: string;\n\t/** For tools: the source bucket (manifest / shopify / …) the picker groups by. */\n\tsource?: string;\n\t/** For tools: touches customer-private data → shows a shield in the picker. */\n\tauthRequired?: boolean;\n}\n\n// Source labels moved to constants/tools.ts; re-exported for existing importers.\nexport { TOOL_SOURCE_LABELS };\n\n/** Human label for a tool source; falls back to the host-app label, then the raw key. */\nexport const toolSourceLabel = (\n\tsource: string | undefined,\n\tfallback = 'Manifest',\n): string => {\n\tif (!source) {\n\t\treturn fallback;\n\t}\n\treturn TOOL_SOURCE_LABELS[source as ToolSource] ?? source;\n};\n\n/** Human label for the host application, used as the tool-chip prefix. */\nexport const appTypeLabel = (applicationType?: ApplicationType): string => {\n\tconst key = applicationType ? String(applicationType) : '';\n\tif (key === 'BIK') {\n\t\treturn 'BIK';\n\t}\n\tif (key === 'BSP') {\n\t\treturn 'BSP';\n\t}\n\treturn 'Manifest';\n};\n\n/**\n * Build the combined `@` mention list from the available tools + sub-agents.\n *\n * The `label` is the CHIP text shown once inserted — tools read\n * `\"<App> : <tool name>\"` (e.g. \"Manifest : Look up order\"), sub-agents read\n * `\"sub-agent: <name>\"`. `meta.plainLabel` is the un-prefixed name for the\n * picker rows, and `meta.kind` drives the `{{tool}}` / `{{subagent}}` colour.\n */\nexport const buildAgentMentionItems = (\n\ttools: AgentTool[],\n\tsubAgents: SubAgentRef[],\n\tappLabel = 'Manifest',\n): MentionItem[] => [\n\t...tools.map(\n\t\t(t): MentionItem => ({\n\t\t\tid: t.tool_id,\n\t\t\tlabel: `${toolSourceLabel(t.source, appLabel)} : ${t.display_name}`,\n\t\t\tmeta: {\n\t\t\t\tkind: 'tool',\n\t\t\t\tplainLabel: t.display_name,\n\t\t\t\tsource: t.source,\n\t\t\t\tauthRequired: t.auth_required,\n\t\t\t},\n\t\t}),\n\t),\n\t...subAgents.map(\n\t\t(s): MentionItem => ({\n\t\t\tid: s.id,\n\t\t\tlabel: `sub-agent: ${s.name}`,\n\t\t\tmeta: { kind: 'subagent', plainLabel: s.name },\n\t\t}),\n\t),\n];\n\n/** Strip the `{{ }}` wrapper from a variable token (`{{a.b}}` → `a.b`). */\nexport const variableTokenName = (actualValue: string): string =>\n\tactualValue.replace(/^\\{\\{|\\}\\}$/g, '');\n\n/**\n * Flatten the (nested) variable catalog into mention items, so stored\n * `{{<name>}}` tokens rehydrate as `Variable: <display name>` chips. The item\n * id is the BARE token name (no braces) — `resolveMentionToken` re-wraps it on\n * save. Merge alongside {@link buildAgentMentionItems} for serialization.\n */\nexport const buildVariableMentionItems = (\n\tvariablesData: VariableListInterfaceV3[] = [],\n): MentionItem[] => {\n\tconst items: MentionItem[] = [];\n\tconst walk = (entry: VariableListInterfaceV3 | SubHeader | VariableV3) => {\n\t\tconst actual = (entry as VariableV3).actualValue;\n\t\tif (actual) {\n\t\t\tconst name = variableTokenName(actual);\n\t\t\titems.push({\n\t\t\t\tid: name,\n\t\t\t\t// Chip text is the raw token — designers want variables to read as\n\t\t\t\t// {{a.b.c}} (styled purple by the editor), not a labelled chip.\n\t\t\t\tlabel: `{{${name}}}`,\n\t\t\t\tmeta: { kind: 'variable', plainLabel: entry.displayName },\n\t\t\t});\n\t\t}\n\t\tObject.values(entry.variables ?? {}).forEach(walk);\n\t};\n\tvariablesData.forEach(walk);\n\treturn items;\n};\n\n/** Display name for a shared config tool: the merchant's action name when set\n * (MAP-7245), else first recipient / channel (pre-action-name tools), else\n * generic. */\nexport const configToolName = (t: ConfigToolConfig): string => {\n\tif (t.tool_key === 'send_slack_message') {\n\t\treturn (\n\t\t\tString(t.params['channelId']?.value ?? '').trim() || 'Send Slack message'\n\t\t);\n\t}\n\tif (t.tool_key === 'send_email') {\n\t\tconst actionName = String(t.params['name']?.value ?? '').trim();\n\t\tif (actionName) {\n\t\t\treturn actionName;\n\t\t}\n\t\treturn (\n\t\t\tString(t.params['sendTo']?.value ?? '')\n\t\t\t\t.split(',')\n\t\t\t\t.map((s) => s.trim())\n\t\t\t\t.filter(Boolean)[0] || 'Send email'\n\t\t);\n\t}\n\t// Future config-tool keys: no bespoke naming yet — fall back to the key.\n\treturn t.tool_key;\n};\n\n/** Display name for a Rest API tool row / chip. */\nexport const restApiToolName = (t: RestApiToolConfig): string =>\n\tt.name || 'Rest API';\n\n/** The `@`-mention chip item for a Rest API tool (kind 'tool', restapi source). */\nexport const restApiMentionItem = (t: RestApiToolConfig): MentionItem => {\n\tconst name = restApiToolName(t);\n\treturn {\n\t\tid: t.id,\n\t\tlabel: `${TOOL_SOURCE_LABELS[ToolSource.RestApi]} : ${name}`,\n\t\tmeta: { kind: 'tool', plainLabel: name, source: ToolSource.RestApi },\n\t};\n};\n\n/** The `@`-mention chip item for a shared config tool (email / Slack). */\nexport const configToolMentionItem = (t: ConfigToolConfig): MentionItem => {\n\tconst source =\n\t\tt.tool_key === 'send_slack_message'\n\t\t\t? ToolSource.Slack\n\t\t\t: ToolSource.EmailHandover;\n\tconst name = configToolName(t);\n\treturn {\n\t\tid: t.id,\n\t\tlabel: `${TOOL_SOURCE_LABELS[source]} : ${name}`,\n\t\tmeta: { kind: 'tool', plainLabel: name, source },\n\t};\n};\n\n/**\n * Mention items for the inline-configured custom tools (Rest API + email / Slack)\n * so their `{{tool:<id>}}` tokens rehydrate as chips — they live on the agent\n * value, not in the catalog `availableTools`. Merge alongside\n * {@link buildAgentMentionItems} in the editor's mention list.\n */\nexport const buildCustomToolMentionItems = (\n\tconfigTools: ConfigToolConfig[] = [],\n\trestApiTools: RestApiToolConfig[] = [],\n): MentionItem[] => [\n\t...restApiTools.map(restApiMentionItem),\n\t...configTools.map(configToolMentionItem),\n];\n\nconst escapeHtml = (raw: string): string =>\n\traw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nconst escapeAttr = (raw: string): string =>\n\tescapeHtml(raw).replace(/\"/g, '&quot;');\n\n/**\n * The HTML for a single mention chip. Must round-trip through the TipTap mention\n * extension's `parseHTML` (`span[data-type=\"mentionAgent\"]`, reading\n * `data-id`/`data-label`/`data-kind`) — see MentionExtension.ts. `normalizeHtml`\n * is taught to keep `data-type=\"mention…\"` spans so this survives to the parser.\n */\nconst mentionSpanHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: string,\n\tsource?: string,\n): string =>\n\t`<span data-type=\"mentionAgent\" class=\"bik-mention bik-mention--agent\"` +\n\t` data-id=\"${escapeAttr(id)}\" data-label=\"${escapeAttr(label)}\"` +\n\t` data-kind=\"${escapeAttr(kind)}\"` +\n\t(source ? ` data-source=\"${escapeAttr(source)}\"` : '') +\n\t`>${escapeHtml(label)}</span>`;\n\n/**\n * Public: HTML for one mention chip, for inserting at the cursor (e.g. when a\n * tool / sub-agent is added from the Step-3 side panel). Round-trips through the\n * same parser path as the rehydrated chips. `source` (tool source bucket) drives\n * the chip's leading icon.\n */\nexport const buildMentionHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: 'tool' | 'subagent' | 'variable',\n\tsource?: string,\n): string => mentionSpanHtml(id, label, kind, source);\n\n/**\n * `{{tool:<id>}}` / `{{subagent:<id>}}` / `{{<variableName>}}` → the mention\n * item that produced them. The map key is the token's INNER text.\n */\nconst buildTokenLookup = (\n\tmentionItems: MentionItem[],\n): Map<string, MentionItem> => {\n\tconst byToken = new Map<string, MentionItem>();\n\tfor (const item of mentionItems) {\n\t\tconst meta = item.meta as unknown as MentionKindMeta | undefined;\n\t\t// Everything is keyed by its kind-prefixed id (a tool's id is its tool_id).\n\t\tif (meta?.kind === 'tool') {\n\t\t\tbyToken.set(`tool:${String(item.id)}`, item);\n\t\t} else if (meta?.kind === 'subagent') {\n\t\t\tbyToken.set(`subagent:${String(item.id)}`, item);\n\t\t} else if (meta?.kind === 'variable') {\n\t\t\tbyToken.set(`variable:${String(item.id)}`, item);\n\t\t}\n\t}\n\treturn byToken;\n};\n\n// Matches the kind-prefixed reference tokens we render as chips. Other\n// `{{var}}` tokens fall through untouched (left as literal text for the\n// variable decoration).\nconst REFERENCE_TOKEN = /\\{\\{((?:tool|subagent|variable):[^{}]+)\\}\\}/g;\n\n/** Escape plain text, swapping recognised reference tokens for mention spans. */\nconst inlineToHtml = (\n\tsegment: string,\n\tbyToken: Map<string, MentionItem>,\n): string => {\n\tlet out = '';\n\tlet lastIndex = 0;\n\tREFERENCE_TOKEN.lastIndex = 0;\n\tlet match: RegExpExecArray | null;\n\twhile ((match = REFERENCE_TOKEN.exec(segment)) !== null) {\n\t\tout += escapeHtml(segment.slice(lastIndex, match.index));\n\t\tconst item = byToken.get(match[1]);\n\t\tif (item) {\n\t\t\tconst meta = item.meta as unknown as MentionKindMeta;\n\t\t\tout += mentionSpanHtml(\n\t\t\t\tString(item.id),\n\t\t\t\titem.label,\n\t\t\t\tmeta.kind,\n\t\t\t\tmeta.source,\n\t\t\t);\n\t\t} else {\n\t\t\t// Not in any available list (removed tool / unknown variable) → keep the\n\t\t\t// raw token as literal text.\n\t\t\tout += escapeHtml(match[0]);\n\t\t}\n\t\tlastIndex = REFERENCE_TOKEN.lastIndex;\n\t}\n\tout += escapeHtml(segment.slice(lastIndex));\n\treturn out.replace(/\\n/g, '<br>');\n};\n\n/**\n * Convert the stored instructions string into HTML for `BikEditor.initialContent`.\n * `{{tool:KEY}}` / `{{subagent:ID}}` tokens are rehydrated into mention chips\n * (resolved via `mentionItems`); any other `{{…}}` token is left as literal text\n * for the editor's variable decoration. Newlines become paragraph / line breaks.\n */\nexport const instructionsToEditorHtml = (\n\ttext: string,\n\tmentionItems: MentionItem[] = [],\n): string => {\n\tif (!text) {\n\t\treturn '';\n\t}\n\tconst byToken = buildTokenLookup(mentionItems);\n\treturn text\n\t\t.split(/\\n{2,}/)\n\t\t.map((para) => `<p>${inlineToHtml(para, byToken)}</p>`)\n\t\t.join('');\n};\n\ninterface ProseMirrorNode {\n\ttype: string;\n\ttext?: string;\n\tattrs?: Record<string, unknown>;\n\tcontent?: ProseMirrorNode[];\n}\n\n/**\n * The token for a mention node. All kinds store their id in the node, so the\n * token value is just that id — the kind only picks the prefix. The node's\n * `kind` attr is authoritative; `toolIds` is a fallback for older content\n * saved before the kind attr existed.\n */\nconst resolveMentionToken = (\n\tid: string,\n\tkind: string | null,\n\ttoolIds: Set<string>,\n): string => {\n\tif (kind === 'variable') {\n\t\treturn `{{variable:${id}}}`;\n\t}\n\tconst resolved = kind ?? (toolIds.has(id) ? 'tool' : 'subagent');\n\treturn resolved === 'tool' ? `{{tool:${id}}}` : `{{subagent:${id}}}`;\n};\n\nconst nodeToText = (node: ProseMirrorNode, toolIds: Set<string>): string => {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn node.text ?? '';\n\t\tcase 'mentionAgent':\n\t\tcase 'mentionTeam': {\n\t\t\tconst id = node.attrs?.['id'];\n\t\t\tif (id == null) {\n\t\t\t\treturn '';\n\t\t\t}\n\t\t\tconst kind = node.attrs?.['kind'];\n\t\t\treturn resolveMentionToken(\n\t\t\t\tString(id),\n\t\t\t\tkind == null ? null : String(kind),\n\t\t\t\ttoolIds,\n\t\t\t);\n\t\t}\n\t\tcase 'variable':\n\t\t\treturn `{{${String(node.attrs?.['variableName'] ?? '')}}}`;\n\t\tcase 'hardBreak':\n\t\t\treturn '\\n';\n\t\tcase 'orderedList':\n\t\tcase 'bulletList': {\n\t\t\t// Flattening to plain text otherwise drops the list markers, so a\n\t\t\t// numbered / bulleted list looks \"removed\" after publish. Emit an\n\t\t\t// ordinal (\"1. \") / bullet (\"- \") prefix per item to preserve it.\n\t\t\tconst ordered = node.type === 'orderedList';\n\t\t\treturn (\n\t\t\t\t(node.content ?? [])\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(item, i) =>\n\t\t\t\t\t\t\t`${ordered ? `${i + 1}.` : '-'} ${nodeToText(\n\t\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\t\ttoolIds,\n\t\t\t\t\t\t\t).replace(/\\n+$/, '')}`,\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n') + '\\n'\n\t\t\t);\n\t\t}\n\t\tdefault: {\n\t\t\tconst inner = (node.content ?? [])\n\t\t\t\t.map((child) => nodeToText(child, toolIds))\n\t\t\t\t.join('');\n\t\t\t// Block nodes terminate with a newline so paragraphs stay separated.\n\t\t\tconst BLOCK_NODES = ['paragraph', 'heading', 'listItem', 'blockquote'];\n\t\t\treturn BLOCK_NODES.includes(node.type) ? `${inner}\\n` : inner;\n\t\t}\n\t}\n};\n\n/**\n * Convert a BikEditor document (from `ref.getJSON()`) into the firebase\n * instructions string, replacing mention nodes with `{{subagent:<id>}}` /\n * `{{tool:<tool_id>}}` tokens.\n */\nexport const editorDocToInstructions = (\n\tdoc: Record<string, unknown> | null,\n\ttools: AgentTool[],\n): string => {\n\tif (!doc) {\n\t\treturn '';\n\t}\n\tconst toolIds = new Set(tools.map((t) => t.tool_id));\n\treturn nodeToText(doc as unknown as ProseMirrorNode, toolIds).replace(\n\t\t/\\n+$/,\n\t\t'',\n\t);\n};\n"],"names":["toolSourceLabel","source","fallback","TOOL_SOURCE_LABELS","appTypeLabel","applicationType","key","buildAgentMentionItems","tools","subAgents","appLabel","t","s","variableTokenName","actualValue","buildVariableMentionItems","variablesData","items","walk","entry","actual","name","configToolName","actionName","restApiToolName","restApiMentionItem","ToolSource","configToolMentionItem","buildCustomToolMentionItems","configTools","restApiTools","escapeHtml","raw","escapeAttr","mentionSpanHtml","id","label","kind","buildMentionHtml","buildTokenLookup","mentionItems","byToken","item","meta","REFERENCE_TOKEN","inlineToHtml","segment","out","lastIndex","match","instructionsToEditorHtml","text","para","resolveMentionToken","toolIds","nodeToText","node","ordered","i","inner","child","editorDocToInstructions","doc"],"mappings":";AA6CO,MAAMA,IAAkB,CAC9BC,GACAC,IAAW,eAEND,IAGEE,EAAmBF,CAAoB,KAAKA,IAF3CC,GAMIE,IAAe,CAACC,MAA8C;AAC1E,QAAMC,IAAMD,IAAkB,OAAOA,CAAe,IAAI;AACxD,SAAIC,MAAQ,QACJ,QAEJA,MAAQ,QACJ,QAED;AACR,GAUaC,IAAyB,CACrCC,GACAC,GACAC,IAAW,eACQ;AAAA,EACnB,GAAGF,EAAM;AAAA,IACR,CAACG,OAAoB;AAAA,MACpB,IAAIA,EAAE;AAAA,MACN,OAAO,GAAGX,EAAgBW,EAAE,QAAQD,CAAQ,CAAC,MAAMC,EAAE,YAAY;AAAA,MACjE,MAAM;AAAA,QACL,MAAM;AAAA,QACN,YAAYA,EAAE;AAAA,QACd,QAAQA,EAAE;AAAA,QACV,cAAcA,EAAE;AAAA,MAAA;AAAA,IACjB;AAAA,EACD;AAAA,EAED,GAAGF,EAAU;AAAA,IACZ,CAACG,OAAoB;AAAA,MACpB,IAAIA,EAAE;AAAA,MACN,OAAO,cAAcA,EAAE,IAAI;AAAA,MAC3B,MAAM,EAAE,MAAM,YAAY,YAAYA,EAAE,KAAA;AAAA,IAAK;AAAA,EAC9C;AAEF,GAGaC,IAAoB,CAACC,MACjCA,EAAY,QAAQ,gBAAgB,EAAE,GAQ1BC,IAA4B,CACxCC,IAA2C,OACxB;AACnB,QAAMC,IAAuB,CAAA,GACvBC,IAAO,CAACC,MAA4D;AACzE,UAAMC,IAAUD,EAAqB;AACrC,QAAIC,GAAQ;AACX,YAAMC,IAAOR,EAAkBO,CAAM;AACrC,MAAAH,EAAM,KAAK;AAAA,QACV,IAAII;AAAA;AAAA;AAAA,QAGJ,OAAO,KAAKA,CAAI;AAAA,QAChB,M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AAA,IACvD,KAAK;AACJ,aAAO;AAAA;AAAA,IACR,KAAK;AAAA,IACL,KAAK,cAAc;AAIlB,YAAMC,IAAUD,EAAK,SAAS;AAC9B,cACEA,EAAK,WAAW,CAAA,GACf;AAAA,QACA,CAACd,GAAMgB,MACN,GAAGD,IAAU,GAAGC,IAAI,CAAC,MAAM,GAAG,IAAIH;AAAA,UACjCb;AAAA,UACAY;AAAA,QAAA,EACC,QAAQ,QAAQ,EAAE,CAAC;AAAA,MAAA,EAEtB,KAAK;AAAA,CAAI,IAAI;AAAA;AAAA,IAEjB;AAAA,IACA,SAAS;AACR,YAAMK,KAASH,EAAK,WAAW,CAAA,GAC7B,IAAI,CAACI,MAAUL,EAAWK,GAAON,CAAO,CAAC,EACzC,KAAK,EAAE;AAGT,aADoB,CAAC,aAAa,WAAW,YAAY,YAAY,EAClD,SAASE,EAAK,IAAI,IAAI,GAAGG,CAAK;AAAA,IAAOA;AAAA,IACzD;AAAA,EAAA;AAEF,GAOaE,IAA0B,CACtCC,GACAtD,MACY;AACZ,MAAI,CAACsD;AACJ,WAAO;AAER,QAAMR,IAAU,IAAI,IAAI9C,EAAM,IAAI,CAACG,MAAMA,EAAE,OAAO,CAAC;AACnD,SAAO4C,EAAWO,GAAmCR,CAAO,EAAE;AAAA,IAC7D;AAAA,IACA;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"mentionSerialization.js","sources":["../../../../../src/components/agent-builder/utils/mentionSerialization.ts"],"sourcesContent":["import type { ApplicationType } from '@bikdotai/bik-models/growth';\nimport { MentionItem } from '@src/editor';\nimport type {\n\tSubHeader,\n\tVariableListInterfaceV3,\n\tVariableV3,\n} from '../../variable-picker-v3/model';\nimport {\n\tAgentTool,\n\tConfigToolConfig,\n\tRestApiToolConfig,\n\tSubAgentRef,\n} from '../AgentBuilder.model';\nimport { TOOL_SOURCE_LABELS, ToolSource } from '../constants/tools';\n\n/**\n * Serialization helpers between the BikEditor document and the firebase\n * `instructions` string.\n *\n * Firebase stores `instructions` as PLAIN TEXT with inline reference tokens:\n * - `{{subagent:<agentId>}}` — hand-off to another agent\n * - `{{tool:<tool_id>}}` — an action the agent can call\n * - `{{variable:<name>}}` — a template variable picked from the catalog\n *\n * In the editor those references are inserted via the `@` mention menu (which we\n * populate with BOTH tools and sub-agents). Mention nodes keep their `id` in the\n * ProseMirror doc JSON (the rendered HTML drops it), so we serialize from the doc\n * JSON — not from HTML.\n */\n\nexport interface MentionKindMeta {\n\t/** Distinguishes a tool / sub-agent / variable reference. */\n\tkind: 'tool' | 'subagent' | 'variable';\n\t/** Plain item name (no prefix) shown in the picker dropdown rows. */\n\tplainLabel?: string;\n\t/** For tools: the source bucket (manifest / shopify / …) the picker groups by. */\n\tsource?: string;\n\t/** For tools: touches customer-private data → shows a shield in the picker. */\n\tauthRequired?: boolean;\n}\n\n// Source labels moved to constants/tools.ts; re-exported for existing importers.\nexport { TOOL_SOURCE_LABELS };\n\n/** Human label for a tool source; falls back to the host-app label, then the raw key. */\nexport const toolSourceLabel = (\n\tsource: string | undefined,\n\tfallback = 'Manifest',\n): string => {\n\tif (!source) {\n\t\treturn fallback;\n\t}\n\treturn TOOL_SOURCE_LABELS[source as ToolSource] ?? source;\n};\n\n/** Human label for the host application, used as the tool-chip prefix. */\nexport const appTypeLabel = (applicationType?: ApplicationType): string => {\n\tconst key = applicationType ? String(applicationType) : '';\n\tif (key === 'BIK') {\n\t\treturn 'BIK';\n\t}\n\tif (key === 'BSP') {\n\t\treturn 'BSP';\n\t}\n\treturn 'Manifest';\n};\n\n/**\n * Build the combined `@` mention list from the available tools + sub-agents.\n *\n * The `label` is the CHIP text shown once inserted — tools read\n * `\"<App> : <tool name>\"` (e.g. \"Manifest : Look up order\"), sub-agents read\n * `\"sub-agent: <name>\"`. `meta.plainLabel` is the un-prefixed name for the\n * picker rows, and `meta.kind` drives the `{{tool}}` / `{{subagent}}` colour.\n */\nexport const buildAgentMentionItems = (\n\ttools: AgentTool[],\n\tsubAgents: SubAgentRef[],\n\tappLabel = 'Manifest',\n): MentionItem[] => [\n\t...tools.map(\n\t\t(t): MentionItem => ({\n\t\t\tid: t.tool_id,\n\t\t\tlabel: `${toolSourceLabel(t.source, appLabel)} : ${t.display_name}`,\n\t\t\tmeta: {\n\t\t\t\tkind: 'tool',\n\t\t\t\tplainLabel: t.display_name,\n\t\t\t\tsource: t.source,\n\t\t\t\tauthRequired: t.auth_required,\n\t\t\t},\n\t\t}),\n\t),\n\t...subAgents.map(\n\t\t(s): MentionItem => ({\n\t\t\tid: s.id,\n\t\t\tlabel: `sub-agent: ${s.name}`,\n\t\t\tmeta: { kind: 'subagent', plainLabel: s.name },\n\t\t}),\n\t),\n];\n\n/** Strip the `{{ }}` wrapper from a variable token (`{{a.b}}` → `a.b`). */\nexport const variableTokenName = (actualValue: string): string =>\n\tactualValue.replace(/^\\{\\{|\\}\\}$/g, '');\n\n/**\n * Flatten the (nested) variable catalog into mention items, so stored\n * `{{<name>}}` tokens rehydrate as `Variable: <display name>` chips. The item\n * id is the BARE token name (no braces) — `resolveMentionToken` re-wraps it on\n * save. Merge alongside {@link buildAgentMentionItems} for serialization.\n */\nexport const buildVariableMentionItems = (\n\tvariablesData: VariableListInterfaceV3[] = [],\n): MentionItem[] => {\n\tconst items: MentionItem[] = [];\n\tconst walk = (entry: VariableListInterfaceV3 | SubHeader | VariableV3) => {\n\t\tconst actual = (entry as VariableV3).actualValue;\n\t\tif (actual) {\n\t\t\tconst name = variableTokenName(actual);\n\t\t\titems.push({\n\t\t\t\tid: name,\n\t\t\t\t// Chip text is the raw token — designers want variables to read as\n\t\t\t\t// {{a.b.c}} (styled purple by the editor), not a labelled chip.\n\t\t\t\tlabel: `{{${name}}}`,\n\t\t\t\tmeta: { kind: 'variable', plainLabel: entry.displayName },\n\t\t\t});\n\t\t}\n\t\tObject.values(entry.variables ?? {}).forEach(walk);\n\t};\n\tvariablesData.forEach(walk);\n\treturn items;\n};\n\n/** Display name for a shared config tool: first recipient / channel, else generic. */\nexport const configToolName = (t: ConfigToolConfig): string => {\n\tif (t.tool_key === 'send_slack_message') {\n\t\treturn (\n\t\t\tString(t.params['channelId']?.value ?? '').trim() || 'Send Slack message'\n\t\t);\n\t}\n\treturn (\n\t\tString(t.params['sendTo']?.value ?? '')\n\t\t\t.split(',')\n\t\t\t.map((s) => s.trim())\n\t\t\t.filter(Boolean)[0] || 'Send email'\n\t);\n};\n\n/** Display name for a Rest API tool row / chip. */\nexport const restApiToolName = (t: RestApiToolConfig): string =>\n\tt.name || 'Rest API';\n\n/** The `@`-mention chip item for a Rest API tool (kind 'tool', restapi source). */\nexport const restApiMentionItem = (t: RestApiToolConfig): MentionItem => {\n\tconst name = restApiToolName(t);\n\treturn {\n\t\tid: t.id,\n\t\tlabel: `${TOOL_SOURCE_LABELS[ToolSource.RestApi]} : ${name}`,\n\t\tmeta: { kind: 'tool', plainLabel: name, source: ToolSource.RestApi },\n\t};\n};\n\n/** The `@`-mention chip item for a shared config tool (email / Slack). */\nexport const configToolMentionItem = (t: ConfigToolConfig): MentionItem => {\n\tconst source =\n\t\tt.tool_key === 'send_slack_message'\n\t\t\t? ToolSource.Slack\n\t\t\t: ToolSource.EmailHandover;\n\tconst name = configToolName(t);\n\treturn {\n\t\tid: t.id,\n\t\tlabel: `${TOOL_SOURCE_LABELS[source]} : ${name}`,\n\t\tmeta: { kind: 'tool', plainLabel: name, source },\n\t};\n};\n\n/**\n * Mention items for the inline-configured custom tools (Rest API + email / Slack)\n * so their `{{tool:<id>}}` tokens rehydrate as chips — they live on the agent\n * value, not in the catalog `availableTools`. Merge alongside\n * {@link buildAgentMentionItems} in the editor's mention list.\n */\nexport const buildCustomToolMentionItems = (\n\tconfigTools: ConfigToolConfig[] = [],\n\trestApiTools: RestApiToolConfig[] = [],\n): MentionItem[] => [\n\t...restApiTools.map(restApiMentionItem),\n\t...configTools.map(configToolMentionItem),\n];\n\nconst escapeHtml = (raw: string): string =>\n\traw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\n\nconst escapeAttr = (raw: string): string =>\n\tescapeHtml(raw).replace(/\"/g, '&quot;');\n\n/**\n * The HTML for a single mention chip. Must round-trip through the TipTap mention\n * extension's `parseHTML` (`span[data-type=\"mentionAgent\"]`, reading\n * `data-id`/`data-label`/`data-kind`) — see MentionExtension.ts. `normalizeHtml`\n * is taught to keep `data-type=\"mention…\"` spans so this survives to the parser.\n */\nconst mentionSpanHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: string,\n\tsource?: string,\n): string =>\n\t`<span data-type=\"mentionAgent\" class=\"bik-mention bik-mention--agent\"` +\n\t` data-id=\"${escapeAttr(id)}\" data-label=\"${escapeAttr(label)}\"` +\n\t` data-kind=\"${escapeAttr(kind)}\"` +\n\t(source ? ` data-source=\"${escapeAttr(source)}\"` : '') +\n\t`>${escapeHtml(label)}</span>`;\n\n/**\n * Public: HTML for one mention chip, for inserting at the cursor (e.g. when a\n * tool / sub-agent is added from the Step-3 side panel). Round-trips through the\n * same parser path as the rehydrated chips. `source` (tool source bucket) drives\n * the chip's leading icon.\n */\nexport const buildMentionHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: 'tool' | 'subagent' | 'variable',\n\tsource?: string,\n): string => mentionSpanHtml(id, label, kind, source);\n\n/**\n * `{{tool:<id>}}` / `{{subagent:<id>}}` / `{{<variableName>}}` → the mention\n * item that produced them. The map key is the token's INNER text.\n */\nconst buildTokenLookup = (\n\tmentionItems: MentionItem[],\n): Map<string, MentionItem> => {\n\tconst byToken = new Map<string, MentionItem>();\n\tfor (const item of mentionItems) {\n\t\tconst meta = item.meta as unknown as MentionKindMeta | undefined;\n\t\t// Everything is keyed by its kind-prefixed id (a tool's id is its tool_id).\n\t\tif (meta?.kind === 'tool') {\n\t\t\tbyToken.set(`tool:${String(item.id)}`, item);\n\t\t} else if (meta?.kind === 'subagent') {\n\t\t\tbyToken.set(`subagent:${String(item.id)}`, item);\n\t\t} else if (meta?.kind === 'variable') {\n\t\t\tbyToken.set(`variable:${String(item.id)}`, item);\n\t\t}\n\t}\n\treturn byToken;\n};\n\n// Matches the kind-prefixed reference tokens we render as chips. Other\n// `{{var}}` tokens fall through untouched (left as literal text for the\n// variable decoration).\nconst REFERENCE_TOKEN = /\\{\\{((?:tool|subagent|variable):[^{}]+)\\}\\}/g;\n\n/** Escape plain text, swapping recognised reference tokens for mention spans. */\nconst inlineToHtml = (\n\tsegment: string,\n\tbyToken: Map<string, MentionItem>,\n): string => {\n\tlet out = '';\n\tlet lastIndex = 0;\n\tREFERENCE_TOKEN.lastIndex = 0;\n\tlet match: RegExpExecArray | null;\n\twhile ((match = REFERENCE_TOKEN.exec(segment)) !== null) {\n\t\tout += escapeHtml(segment.slice(lastIndex, match.index));\n\t\tconst item = byToken.get(match[1]);\n\t\tif (item) {\n\t\t\tconst meta = item.meta as unknown as MentionKindMeta;\n\t\t\tout += mentionSpanHtml(\n\t\t\t\tString(item.id),\n\t\t\t\titem.label,\n\t\t\t\tmeta.kind,\n\t\t\t\tmeta.source,\n\t\t\t);\n\t\t} else {\n\t\t\t// Not in any available list (removed tool / unknown variable) → keep the\n\t\t\t// raw token as literal text.\n\t\t\tout += escapeHtml(match[0]);\n\t\t}\n\t\tlastIndex = REFERENCE_TOKEN.lastIndex;\n\t}\n\tout += escapeHtml(segment.slice(lastIndex));\n\treturn out.replace(/\\n/g, '<br>');\n};\n\n/**\n * Convert the stored instructions string into HTML for `BikEditor.initialContent`.\n * `{{tool:KEY}}` / `{{subagent:ID}}` tokens are rehydrated into mention chips\n * (resolved via `mentionItems`); any other `{{…}}` token is left as literal text\n * for the editor's variable decoration. Newlines become paragraph / line breaks.\n */\nexport const instructionsToEditorHtml = (\n\ttext: string,\n\tmentionItems: MentionItem[] = [],\n): string => {\n\tif (!text) {\n\t\treturn '';\n\t}\n\tconst byToken = buildTokenLookup(mentionItems);\n\treturn text\n\t\t.split(/\\n{2,}/)\n\t\t.map((para) => `<p>${inlineToHtml(para, byToken)}</p>`)\n\t\t.join('');\n};\n\ninterface ProseMirrorNode {\n\ttype: string;\n\ttext?: string;\n\tattrs?: Record<string, unknown>;\n\tcontent?: ProseMirrorNode[];\n}\n\n/**\n * The token for a mention node. All kinds store their id in the node, so the\n * token value is just that id — the kind only picks the prefix. The node's\n * `kind` attr is authoritative; `toolIds` is a fallback for older content\n * saved before the kind attr existed.\n */\nconst resolveMentionToken = (\n\tid: string,\n\tkind: string | null,\n\ttoolIds: Set<string>,\n): string => {\n\tif (kind === 'variable') {\n\t\treturn `{{variable:${id}}}`;\n\t}\n\tconst resolved = kind ?? (toolIds.has(id) ? 'tool' : 'subagent');\n\treturn resolved === 'tool' ? `{{tool:${id}}}` : `{{subagent:${id}}}`;\n};\n\nconst nodeToText = (node: ProseMirrorNode, toolIds: Set<string>): string => {\n\tswitch (node.type) {\n\t\tcase 'text':\n\t\t\treturn node.text ?? '';\n\t\tcase 'mentionAgent':\n\t\tcase 'mentionTeam': {\n\t\t\tconst id = node.attrs?.['id'];\n\t\t\tif (id == null) {\n\t\t\t\treturn '';\n\t\t\t}\n\t\t\tconst kind = node.attrs?.['kind'];\n\t\t\treturn resolveMentionToken(\n\t\t\t\tString(id),\n\t\t\t\tkind == null ? null : String(kind),\n\t\t\t\ttoolIds,\n\t\t\t);\n\t\t}\n\t\tcase 'variable':\n\t\t\treturn `{{${String(node.attrs?.['variableName'] ?? '')}}}`;\n\t\tcase 'hardBreak':\n\t\t\treturn '\\n';\n\t\tcase 'orderedList':\n\t\tcase 'bulletList': {\n\t\t\t// Flattening to plain text otherwise drops the list markers, so a\n\t\t\t// numbered / bulleted list looks \"removed\" after publish. Emit an\n\t\t\t// ordinal (\"1. \") / bullet (\"- \") prefix per item to preserve it.\n\t\t\tconst ordered = node.type === 'orderedList';\n\t\t\treturn (\n\t\t\t\t(node.content ?? [])\n\t\t\t\t\t.map(\n\t\t\t\t\t\t(item, i) =>\n\t\t\t\t\t\t\t`${ordered ? `${i + 1}.` : '-'} ${nodeToText(\n\t\t\t\t\t\t\t\titem,\n\t\t\t\t\t\t\t\ttoolIds,\n\t\t\t\t\t\t\t).replace(/\\n+$/, '')}`,\n\t\t\t\t\t)\n\t\t\t\t\t.join('\\n') + '\\n'\n\t\t\t);\n\t\t}\n\t\tdefault: {\n\t\t\tconst inner = (node.content ?? [])\n\t\t\t\t.map((child) => nodeToText(child, toolIds))\n\t\t\t\t.join('');\n\t\t\t// Block nodes terminate with a newline so paragraphs stay separated.\n\t\t\tconst BLOCK_NODES = ['paragraph', 'heading', 'listItem', 'blockquote'];\n\t\t\treturn BLOCK_NODES.includes(node.type) ? `${inner}\\n` : inner;\n\t\t}\n\t}\n};\n\n/**\n * Convert a BikEditor document (from `ref.getJSON()`) into the firebase\n * instructions string, replacing mention nodes with `{{subagent:<id>}}` /\n * `{{tool:<tool_id>}}` tokens.\n */\nexport const editorDocToInstructions = (\n\tdoc: Record<string, unknown> | null,\n\ttools: AgentTool[],\n): string => {\n\tif (!doc) {\n\t\treturn '';\n\t}\n\tconst toolIds = new Set(tools.map((t) => t.tool_id));\n\treturn nodeToText(doc as unknown as ProseMirrorNode, toolIds).replace(\n\t\t/\\n+$/,\n\t\t'',\n\t);\n};\n"],"names":["toolSourceLabel","source","fallback","TOOL_SOURCE_LABELS","appTypeLabel","applicationType","key","buildAgentMentionItems","tools","subAgents","appLabel","t","s","variableTokenName","actualValue","buildVariableMentionItems","variablesData","items","walk","entry","actual","name","configToolName","restApiToolName","restApiMentionItem","ToolSource","configToolMentionItem","buildCustomToolMentionItems","configTools","restApiTools","escapeHtml","raw","escapeAttr","mentionSpanHtml","id","label","kind","buildMentionHtml","buildTokenLookup","mentionItems","byToken","item","meta","REFERENCE_TOKEN","inlineToHtml","segment","out","lastIndex","match","instructionsToEditorHtml","text","para","resolveMentionToken","toolIds","nodeToText","node","ordered","i","inner","child","editorDocToInstructions","doc"],"mappings":";AA6CO,MAAMA,IAAkB,CAC9BC,GACAC,IAAW,eAEND,IAGEE,EAAmBF,CAAoB,KAAKA,IAF3CC,GAMIE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AW,CAAA,GAC7B,IAAI,CAACI,MAAUL,EAAWK,GAAON,CAAO,CAAC,EACzC,KAAK,EAAE;AAGT,aADoB,CAAC,aAAa,WAAW,YAAY,YAAY,EAClD,SAASE,EAAK,IAAI,IAAI,GAAGG,CAAK;AAAA,IAAOA;AAAA,IACzD;AAAA,EAAA;AAEF,GAOaE,IAA0B,CACtCC,GACArD,MACY;AACZ,MAAI,CAACqD;AACJ,WAAO;AAER,QAAMR,IAAU,IAAI,IAAI7C,EAAM,IAAI,CAACG,MAAMA,EAAE,OAAO,CAAC;AACnD,SAAO2C,EAAWO,GAAmCR,CAAO,EAAE;AAAA,IAC7D;AAAA,IACA;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,32 @@
1
+ import { default as React } from 'react';
2
+ import { BIKCopilotProps } from './model';
3
+ /**
4
+ * The copilot ball and panel wired to the streaming `/bik-ai/copilot-chatbot`
5
+ * endpoint, with the transcript persisted in IndexedDB and route-aware ice
6
+ * breakers from `/bik-ai/copilot-icebreakers`.
7
+ *
8
+ * Chunks arrive as `STREAM` events and are appended live; the final `TEXT` event
9
+ * replaces the bubble with the authoritative full message and carries the
10
+ * `responseId` that threads the next turn. A session id is created on first use
11
+ * and restored on reload, so a refresh resumes the same conversation. The
12
+ * header's reset button starts a new session id and a new OpenAI thread.
13
+ *
14
+ * Ice breakers are fetched for the current `agent` + `route` the first time the
15
+ * panel is opened, and refetched when the route changes.
16
+ *
17
+ * ```tsx
18
+ * <BIKCopilot
19
+ * baseUrl={AI_BACKEND_URL}
20
+ * getAuthToken={() => firebaseUser.getIdToken()}
21
+ * headers={{ 'bik-referer': 'dashboard' }}
22
+ * storeId={storeId}
23
+ * email={user.email}
24
+ * route={currentRoute}
25
+ * title="Copilot"
26
+ * badge="New"
27
+ * subtitle="Way smarter, wildly more capable"
28
+ * />
29
+ * ```
30
+ */
31
+ export declare const BIKCopilot: React.FC<BIKCopilotProps>;
32
+ export default BIKCopilot;
@@ -0,0 +1,114 @@
1
+ import { jsx as W } from "react/jsx-runtime";
2
+ import { useState as X, useCallback as u } from "react";
3
+ import { ControlledCopilot as Y } from "./ControlledCopilot.js";
4
+ import { useCopilotIcebreakers as Z } from "./useCopilotIcebreakers.js";
5
+ import { useCopilotStreamChat as _ } from "./useCopilotStreamChat.js";
6
+ const es = ({
7
+ // Transport + turn config
8
+ baseUrl: s,
9
+ endpointPath: M,
10
+ icebreakersPath: S,
11
+ headers: e,
12
+ authToken: o,
13
+ getAuthToken: r,
14
+ fetchImpl: t,
15
+ storeId: i,
16
+ agent: a,
17
+ route: n,
18
+ email: f,
19
+ systemPrompt: b,
20
+ model: h,
21
+ maxOutputTokens: H,
22
+ sessionId: O,
23
+ persist: k,
24
+ loadIcebreakers: y = !0,
25
+ onError: L,
26
+ onResponseComplete: R,
27
+ onSessionIdChange: j,
28
+ // Shell
29
+ suggestions: v,
30
+ inputDisabled: w,
31
+ onRefresh: m,
32
+ open: g,
33
+ defaultOpen: l,
34
+ onOpenChange: p,
35
+ ...x
36
+ }) => {
37
+ const [B, D] = X(
38
+ l === !0 || g === !0
39
+ ), {
40
+ messages: K,
41
+ isThinking: N,
42
+ isStreaming: d,
43
+ isRestoring: q,
44
+ error: z,
45
+ isLoadingHistory: E,
46
+ hasMoreHistory: F,
47
+ sendMessage: G,
48
+ loadOlderMessages: I,
49
+ stopStreaming: J,
50
+ startNewConversation: C
51
+ } = _({
52
+ baseUrl: s,
53
+ endpointPath: M,
54
+ headers: e,
55
+ authToken: o,
56
+ getAuthToken: r,
57
+ fetchImpl: t,
58
+ storeId: i,
59
+ agent: a,
60
+ route: n,
61
+ email: f,
62
+ systemPrompt: b,
63
+ model: h,
64
+ maxOutputTokens: H,
65
+ sessionId: O,
66
+ persist: k,
67
+ onError: L,
68
+ onResponseComplete: R,
69
+ onSessionIdChange: j
70
+ }), { icebreakers: P } = Z({
71
+ baseUrl: s,
72
+ icebreakersPath: S,
73
+ headers: e,
74
+ authToken: o,
75
+ getAuthToken: r,
76
+ fetchImpl: t,
77
+ agent: a,
78
+ route: n,
79
+ storeId: i,
80
+ enabled: y && B
81
+ }), Q = u(
82
+ (c) => {
83
+ c && D(!0), p?.(c);
84
+ },
85
+ [p]
86
+ ), V = u(() => {
87
+ C(), m?.();
88
+ }, [m, C]);
89
+ return /* @__PURE__ */ W(
90
+ Y,
91
+ {
92
+ ...x,
93
+ open: g,
94
+ defaultOpen: l,
95
+ onOpenChange: Q,
96
+ messages: K,
97
+ onSendMessage: G,
98
+ isThinking: N,
99
+ isStreaming: d,
100
+ onStop: J,
101
+ isLoadingHistory: E,
102
+ hasMoreHistory: F,
103
+ onLoadOlderMessages: I,
104
+ errorMessage: z,
105
+ suggestions: v ?? P,
106
+ inputDisabled: w || q || d,
107
+ onRefresh: V
108
+ }
109
+ );
110
+ };
111
+ export {
112
+ es as BIKCopilot
113
+ };
114
+ //# sourceMappingURL=BIKCopilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BIKCopilot.js","sources":["../../../../src/components/bik-copilot/BIKCopilot.tsx"],"sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { ControlledCopilot } from './ControlledCopilot';\nimport { BIKCopilotProps } from './model';\nimport { useCopilotIcebreakers } from './useCopilotIcebreakers';\nimport { useCopilotStreamChat } from './useCopilotStreamChat';\n\n/**\n * The copilot ball and panel wired to the streaming `/bik-ai/copilot-chatbot`\n * endpoint, with the transcript persisted in IndexedDB and route-aware ice\n * breakers from `/bik-ai/copilot-icebreakers`.\n *\n * Chunks arrive as `STREAM` events and are appended live; the final `TEXT` event\n * replaces the bubble with the authoritative full message and carries the\n * `responseId` that threads the next turn. A session id is created on first use\n * and restored on reload, so a refresh resumes the same conversation. The\n * header's reset button starts a new session id and a new OpenAI thread.\n *\n * Ice breakers are fetched for the current `agent` + `route` the first time the\n * panel is opened, and refetched when the route changes.\n *\n * ```tsx\n * <BIKCopilot\n * baseUrl={AI_BACKEND_URL}\n * getAuthToken={() => firebaseUser.getIdToken()}\n * headers={{ 'bik-referer': 'dashboard' }}\n * storeId={storeId}\n * email={user.email}\n * route={currentRoute}\n * title=\"Copilot\"\n * badge=\"New\"\n * subtitle=\"Way smarter, wildly more capable\"\n * />\n * ```\n */\nexport const BIKCopilot: React.FC<BIKCopilotProps> = ({\n\t// Transport + turn config\n\tbaseUrl,\n\tendpointPath,\n\ticebreakersPath,\n\theaders,\n\tauthToken,\n\tgetAuthToken,\n\tfetchImpl,\n\tstoreId,\n\tagent,\n\troute,\n\temail,\n\tsystemPrompt,\n\tmodel,\n\tmaxOutputTokens,\n\tsessionId,\n\tpersist,\n\tloadIcebreakers = true,\n\tonError,\n\tonResponseComplete,\n\tonSessionIdChange,\n\t// Shell\n\tsuggestions,\n\tinputDisabled,\n\tonRefresh,\n\topen,\n\tdefaultOpen,\n\tonOpenChange,\n\t...shellProps\n}) => {\n\t// Ice breakers only matter once the panel is visible, so a merchant who never\n\t// opens the copilot costs no request.\n\tconst [hasOpened, setHasOpened] = useState(\n\t\tdefaultOpen === true || open === true,\n\t);\n\n\tconst {\n\t\tmessages,\n\t\tisThinking,\n\t\tisStreaming,\n\t\tisRestoring,\n\t\terror,\n\t\tisLoadingHistory,\n\t\thasMoreHistory,\n\t\tsendMessage,\n\t\tloadOlderMessages,\n\t\tstopStreaming,\n\t\tstartNewConversation,\n\t} = useCopilotStreamChat({\n\t\tbaseUrl,\n\t\tendpointPath,\n\t\theaders,\n\t\tauthToken,\n\t\tgetAuthToken,\n\t\tfetchImpl,\n\t\tstoreId,\n\t\tagent,\n\t\troute,\n\t\temail,\n\t\tsystemPrompt,\n\t\tmodel,\n\t\tmaxOutputTokens,\n\t\tsessionId,\n\t\tpersist,\n\t\tonError,\n\t\tonResponseComplete,\n\t\tonSessionIdChange,\n\t});\n\n\tconst { icebreakers } = useCopilotIcebreakers({\n\t\tbaseUrl,\n\t\ticebreakersPath,\n\t\theaders,\n\t\tauthToken,\n\t\tgetAuthToken,\n\t\tfetchImpl,\n\t\tagent,\n\t\troute,\n\t\tstoreId,\n\t\tenabled: loadIcebreakers && hasOpened,\n\t});\n\n\tconst handleOpenChange = useCallback(\n\t\t(nextOpen: boolean) => {\n\t\t\tif (nextOpen) {\n\t\t\t\tsetHasOpened(true);\n\t\t\t}\n\t\t\tonOpenChange?.(nextOpen);\n\t\t},\n\t\t[onOpenChange],\n\t);\n\n\tconst handleRefresh = useCallback(() => {\n\t\tstartNewConversation();\n\t\tonRefresh?.();\n\t}, [onRefresh, startNewConversation]);\n\n\treturn (\n\t\t<ControlledCopilot\n\t\t\t{...shellProps}\n\t\t\topen={open}\n\t\t\tdefaultOpen={defaultOpen}\n\t\t\tonOpenChange={handleOpenChange}\n\t\t\tmessages={messages}\n\t\t\tonSendMessage={sendMessage}\n\t\t\tisThinking={isThinking}\n\t\t\tisStreaming={isStreaming}\n\t\t\tonStop={stopStreaming}\n\t\t\tisLoadingHistory={isLoadingHistory}\n\t\t\thasMoreHistory={hasMoreHistory}\n\t\t\tonLoadOlderMessages={loadOlderMessages}\n\t\t\terrorMessage={error}\n\t\t\t// An explicit list wins; otherwise the route's fetched prompts show. A\n\t\t\t// failed or empty fetch simply leaves the empty state without chips.\n\t\t\tsuggestions={suggestions ?? icebreakers}\n\t\t\t// A second prompt mid-stream would race the thread's responseId.\n\t\t\tinputDisabled={inputDisabled || isRestoring || isStreaming}\n\t\t\tonRefresh={handleRefresh}\n\t\t/>\n\t);\n};\n\nexport default BIKCopilot;\n"],"names":["BIKCopilot","baseUrl","endpointPath","icebreakersPath","headers","authToken","getAuthToken","fetchImpl","storeId","agent","route","email","systemPrompt","model","maxOutputTokens","sessionId","persist","loadIcebreakers","onError","onResponseComplete","onSessionIdChange","suggestions","inputDisabled","onRefresh","open","defaultOpen","onOpenChange","shellProps","hasOpened","setHasOpened","useState","messages","isThinking","isStreaming","isRestoring","error","isLoadingHistory","hasMoreHistory","sendMessage","loadOlderMessages","stopStreaming","startNewConversation","useCopilotStreamChat","icebreakers","useCopilotIcebreakers","handleOpenChange","useCallback","nextOpen","handleR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mBAAAC;AAAA,EAAA,CACA,GAEK,EAAE,aAAAuB,EAAA,IAAgBC,EAAsB;AAAA,IAC7C,SAAA3C;AAAA,IACA,iBAAAE;AAAA,IACA,SAAAC;AAAA,IACA,WAAAC;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,OAAAE;AAAA,IACA,OAAAC;AAAA,IACA,SAAAF;AAAA,IACA,SAASS,KAAmBW;AAAA,EAAA,CAC5B,GAEKiB,IAAmBC;AAAA,IACxB,CAACC,MAAsB;AACtB,MAAIA,KACHlB,EAAa,EAAI,GAElBH,IAAeqB,CAAQ;AAAA,IACxB;AAAA,IACA,CAACrB,CAAY;AAAA,EAAA,GAGRsB,IAAgBF,EAAY,MAAM;AACvC,IAAAL,EAAA,GACAlB,IAAA;AAAA,EACD,GAAG,CAACA,GAAWkB,CAAoB,CAAC;AAEpC,SACC,gBAAAQ;AAAA,IAACC;AAAA,IAAA;AAAA,MACC,GAAGvB;AAAA,MACJ,MAAAH;AAAA,MACA,aAAAC;AAAA,MACA,cAAcoB;AAAA,MACd,UAAAd;AAAA,MACA,eAAeO;AAAA,MACf,YAAAN;AAAA,MACA,aAAAC;AAAA,MACA,QAAQO;AAAA,MACR,kBAAAJ;AAAA,MACA,gBAAAC;AAAA,MACA,qBAAqBE;AAAA,MACrB,cAAcJ;AAAA,MAGd,aAAad,KAAesB;AAAA,MAE5B,eAAerB,KAAiBY,KAAeD;AAAA,MAC/C,WAAWe;AAAA,IAAA;AAAA,EAAA;AAGd;"}
@@ -0,0 +1,14 @@
1
+ import { default as React } from 'react';
2
+ import { ControlledCopilotProps } from './model';
3
+ /**
4
+ * The presentational half of the copilot: a draggable floating ball that opens a
5
+ * chat panel beside it.
6
+ *
7
+ * Fully controlled — it renders the `messages` it is handed and reports every
8
+ * user action through callbacks, so it carries no backend knowledge. **Use
9
+ * `BIKCopilot` instead** unless you are wiring a backend other than
10
+ * `/bik-ai/copilot-chatbot`; `BIKCopilot` is this component plus the streaming
11
+ * transport, IndexedDB history and route-aware ice breakers.
12
+ */
13
+ export declare const ControlledCopilot: React.FC<ControlledCopilotProps>;
14
+ export default ControlledCopilot;
@@ -0,0 +1,170 @@
1
+ import { jsxs as pe, Fragment as me, jsx as a } from "react/jsx-runtime";
2
+ import { useState as ue, useRef as ge, useCallback as C, useEffect as v } from "react";
3
+ import { COLORS as he } from "../../constants/Theme.js";
4
+ import { PanelPositioner as Ce } from "./ControlledCopilot.styled.js";
5
+ import { CopilotBall as ve, COPILOT_BALL_ATTRIBUTE as we } from "./CopilotBall.js";
6
+ import { CopilotPanel as Le } from "./CopilotPanel.js";
7
+ import { getCopilotPanelPlacement as Pe } from "./copilotPlacement.js";
8
+ import { useDraggableFloater as Ee } from "./useDraggableFloater.js";
9
+ const De = ({
10
+ // Conversation
11
+ messages: w,
12
+ onSendMessage: L,
13
+ isThinking: P = !1,
14
+ thinkingLabel: E,
15
+ isStreaming: k = !1,
16
+ onStop: $,
17
+ interruptedLabel: b,
18
+ followUpsLabel: I,
19
+ hasMoreHistory: O = !1,
20
+ isLoadingHistory: T = !1,
21
+ onLoadOlderMessages: y,
22
+ historyLoadingLabel: B,
23
+ errorMessage: D,
24
+ // Ball
25
+ ballSize: r = 56,
26
+ corner: R = "bottom-right",
27
+ offset: x = 24,
28
+ initialPosition: j,
29
+ draggable: f = !0,
30
+ snapToEdge: A = !0,
31
+ onPositionChange: F,
32
+ ballIcon: U,
33
+ ballOpenIcon: _,
34
+ ballColor: z = he.background.brand,
35
+ zIndex: c = 1200,
36
+ ballAriaLabel: H,
37
+ // Panel
38
+ panelWidth: K = 400,
39
+ panelHeight: S = 700,
40
+ panelGap: q = 12,
41
+ title: G = "Copilot",
42
+ badge: J,
43
+ subtitle: M,
44
+ avatar: N,
45
+ placeholder: Q,
46
+ disclaimer: V,
47
+ emptyStateTitle: W,
48
+ emptyStateSubtitle: X,
49
+ suggestions: Y,
50
+ onSuggestionClick: Z,
51
+ showRefresh: ee = !0,
52
+ onRefresh: oe,
53
+ inputDisabled: te = !1,
54
+ // Open state
55
+ open: d,
56
+ defaultOpen: ne = !1,
57
+ onOpenChange: p,
58
+ closeOnClickOutside: m = !1,
59
+ className: re,
60
+ style: ie
61
+ }) => {
62
+ const [le, se] = ue(ne), u = ge(null), i = d !== void 0, e = i ? d : le, t = C(
63
+ (o) => {
64
+ i || se(o), p?.(o);
65
+ },
66
+ [i, p]
67
+ ), { position: g, isDragging: ae, viewport: fe, dragHandlers: ce, shouldIgnoreClick: h } = Ee({
68
+ size: r,
69
+ corner: R,
70
+ offset: x,
71
+ enabled: f,
72
+ snapToEdge: A,
73
+ initialPosition: j,
74
+ onPositionChange: F
75
+ }), de = C(() => {
76
+ h() || t(!e);
77
+ }, [e, t, h]);
78
+ v(() => {
79
+ if (!e)
80
+ return;
81
+ const o = (l) => {
82
+ l.key === "Escape" && t(!1);
83
+ };
84
+ return document.addEventListener("keydown", o), () => document.removeEventListener("keydown", o);
85
+ }, [e, t]), v(() => {
86
+ if (!e || !m)
87
+ return;
88
+ const o = (l) => {
89
+ const s = l.target;
90
+ s && (u.current?.contains(s) || s.closest(`[${we}]`) || t(!1));
91
+ };
92
+ return document.addEventListener("pointerdown", o), () => document.removeEventListener("pointerdown", o);
93
+ }, [m, e, t]);
94
+ const n = Pe({
95
+ ballPosition: g,
96
+ ballSize: r,
97
+ panelWidth: K,
98
+ panelHeight: S,
99
+ gap: q,
100
+ viewport: fe
101
+ });
102
+ return /* @__PURE__ */ pe(me, { children: [
103
+ e && /* @__PURE__ */ a(
104
+ Ce,
105
+ {
106
+ ref: u,
107
+ $left: n.left,
108
+ $top: n.top,
109
+ $width: n.width,
110
+ $height: n.height,
111
+ $zIndex: c,
112
+ children: /* @__PURE__ */ a(
113
+ Le,
114
+ {
115
+ messages: w,
116
+ onSend: L,
117
+ onClose: () => t(!1),
118
+ title: G,
119
+ badge: J,
120
+ subtitle: M,
121
+ avatar: N,
122
+ placeholder: Q,
123
+ disclaimer: V,
124
+ emptyStateTitle: W,
125
+ emptyStateSubtitle: X,
126
+ suggestions: Y,
127
+ onSuggestionClick: Z,
128
+ showRefresh: ee,
129
+ onRefresh: oe,
130
+ isThinking: P,
131
+ thinkingLabel: E,
132
+ isStreaming: k,
133
+ onStop: $,
134
+ interruptedLabel: b,
135
+ followUpsLabel: I,
136
+ hasMoreHistory: O,
137
+ isLoadingHistory: T,
138
+ onLoadOlderMessages: y,
139
+ historyLoadingLabel: B,
140
+ inputDisabled: te,
141
+ errorMessage: D,
142
+ className: re,
143
+ style: ie
144
+ }
145
+ )
146
+ }
147
+ ),
148
+ /* @__PURE__ */ a(
149
+ ve,
150
+ {
151
+ isOpen: e,
152
+ onToggle: de,
153
+ position: g,
154
+ size: r,
155
+ isDragging: ae,
156
+ draggable: f,
157
+ color: z,
158
+ zIndex: c + 1,
159
+ icon: U,
160
+ openIcon: _,
161
+ ariaLabel: H,
162
+ ...ce
163
+ }
164
+ )
165
+ ] });
166
+ };
167
+ export {
168
+ De as ControlledCopilot
169
+ };
170
+ //# sourceMappingURL=ControlledCopilot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ControlledCopilot.js","sources":["../../../../src/components/bik-copilot/ControlledCopilot.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { COLORS } from '@src/constants/Theme';\nimport { PanelPositioner } from './ControlledCopilot.styled';\nimport { COPILOT_BALL_ATTRIBUTE, CopilotBall } from './CopilotBall';\nimport { CopilotPanel } from './CopilotPanel';\nimport { getCopilotPanelPlacement } from './copilotPlacement';\nimport { ControlledCopilotProps } from './model';\nimport { useDraggableFloater } from './useDraggableFloater';\n\n/**\n * The presentational half of the copilot: a draggable floating ball that opens a\n * chat panel beside it.\n *\n * Fully controlled — it renders the `messages` it is handed and reports every\n * user action through callbacks, so it carries no backend knowledge. **Use\n * `BIKCopilot` instead** unless you are wiring a backend other than\n * `/bik-ai/copilot-chatbot`; `BIKCopilot` is this component plus the streaming\n * transport, IndexedDB history and route-aware ice breakers.\n */\nexport const ControlledCopilot: React.FC<ControlledCopilotProps> = ({\n\t// Conversation\n\tmessages,\n\tonSendMessage,\n\tisThinking = false,\n\tthinkingLabel,\n\tisStreaming = false,\n\tonStop,\n\tinterruptedLabel,\n\tfollowUpsLabel,\n\thasMoreHistory = false,\n\tisLoadingHistory = false,\n\tonLoadOlderMessages,\n\thistoryLoadingLabel,\n\terrorMessage,\n\t// Ball\n\tballSize = 56,\n\tcorner = 'bottom-right',\n\toffset = 24,\n\tinitialPosition,\n\tdraggable = true,\n\tsnapToEdge = true,\n\tonPositionChange,\n\tballIcon,\n\tballOpenIcon,\n\tballColor = COLORS.background.brand,\n\tzIndex = 1200,\n\tballAriaLabel,\n\t// Panel\n\tpanelWidth = 400,\n\tpanelHeight = 700,\n\tpanelGap = 12,\n\ttitle = 'Copilot',\n\tbadge,\n\tsubtitle,\n\tavatar,\n\tplaceholder,\n\tdisclaimer,\n\temptyStateTitle,\n\temptyStateSubtitle,\n\tsuggestions,\n\tonSuggestionClick,\n\tshowRefresh = true,\n\tonRefresh,\n\tinputDisabled = false,\n\t// Open state\n\topen,\n\tdefaultOpen = false,\n\tonOpenChange,\n\tcloseOnClickOutside = false,\n\tclassName,\n\tstyle,\n}) => {\n\tconst [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen);\n\tconst panelRef = useRef<HTMLDivElement>(null);\n\n\tconst isControlled = open !== undefined;\n\tconst isOpen = isControlled ? open : uncontrolledOpen;\n\n\tconst setOpen = useCallback(\n\t\t(next: boolean) => {\n\t\t\tif (!isControlled) {\n\t\t\t\tsetUncontrolledOpen(next);\n\t\t\t}\n\t\t\tonOpenChange?.(next);\n\t\t},\n\t\t[isControlled, onOpenChange],\n\t);\n\n\tconst { position, isDragging, viewport, dragHandlers, shouldIgnoreClick } =\n\t\tuseDraggableFloater({\n\t\t\tsize: ballSize,\n\t\t\tcorner,\n\t\t\toffset,\n\t\t\tenabled: draggable,\n\t\t\tsnapToEdge,\n\t\t\tinitialPosition,\n\t\t\tonPositionChange,\n\t\t});\n\n\tconst handleBallClick = useCallback(() => {\n\t\t// The click that ends a drag gesture must not toggle the panel.\n\t\tif (shouldIgnoreClick()) {\n\t\t\treturn;\n\t\t}\n\t\tsetOpen(!isOpen);\n\t}, [isOpen, setOpen, shouldIgnoreClick]);\n\n\t// Escape closes the panel.\n\tuseEffect(() => {\n\t\tif (!isOpen) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst handleKeyDown = (event: KeyboardEvent) => {\n\t\t\tif (event.key === 'Escape') {\n\t\t\t\tsetOpen(false);\n\t\t\t}\n\t\t};\n\t\tdocument.addEventListener('keydown', handleKeyDown);\n\t\treturn () => document.removeEventListener('keydown', handleKeyDown);\n\t}, [isOpen, setOpen]);\n\n\tuseEffect(() => {\n\t\tif (!isOpen || !closeOnClickOutside) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst handlePointerDown = (event: PointerEvent) => {\n\t\t\tconst target = event.target as HTMLElement | null;\n\t\t\tif (!target) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (panelRef.current?.contains(target)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (target.closest(`[${COPILOT_BALL_ATTRIBUTE}]`)) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tsetOpen(false);\n\t\t};\n\t\tdocument.addEventListener('pointerdown', handlePointerDown);\n\t\treturn () => document.removeEventListener('pointerdown', handlePointerDown);\n\t}, [closeOnClickOutside, isOpen, setOpen]);\n\n\tconst placement = getCopilotPanelPlacement({\n\t\tballPosition: position,\n\t\tballSize,\n\t\tpanelWidth,\n\t\tpanelHeight,\n\t\tgap: panelGap,\n\t\tviewport,\n\t});\n\n\treturn (\n\t\t<>\n\t\t\t{isOpen && (\n\t\t\t\t<PanelPositioner\n\t\t\t\t\tref={panelRef}\n\t\t\t\t\t$left={placement.left}\n\t\t\t\t\t$top={placement.top}\n\t\t\t\t\t$width={placement.width}\n\t\t\t\t\t$height={placement.height}\n\t\t\t\t\t$zIndex={zIndex}\n\t\t\t\t>\n\t\t\t\t\t<CopilotPanel\n\t\t\t\t\t\tmessages={messages}\n\t\t\t\t\t\tonSend={onSendMessage}\n\t\t\t\t\t\tonClose={() => setOpen(false)}\n\t\t\t\t\t\ttitle={title}\n\t\t\t\t\t\tbadge={badge}\n\t\t\t\t\t\tsubtitle={subtitle}\n\t\t\t\t\t\tavatar={avatar}\n\t\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\t\tdisclaimer={disclaimer}\n\t\t\t\t\t\temptyStateTitle={emptyStateTitle}\n\t\t\t\t\t\temptyStateSubtitle={emptyStateSubtitle}\n\t\t\t\t\t\tsuggestions={suggestions}\n\t\t\t\t\t\tonSuggestionClick={onSuggestionClick}\n\t\t\t\t\t\tshowRefresh={showRefresh}\n\t\t\t\t\t\tonRefresh={onRefresh}\n\t\t\t\t\t\tisThinking={isThinking}\n\t\t\t\t\t\tthinkingLabel={thinkingLabel}\n\t\t\t\t\t\tisStreaming={isStreaming}\n\t\t\t\t\t\tonStop={onStop}\n\t\t\t\t\t\tinterruptedLabel={interruptedLabel}\n\t\t\t\t\t\tfollowUpsLabel={followUpsLabel}\n\t\t\t\t\t\thasMoreHistory={hasMoreHistory}\n\t\t\t\t\t\tisLoadingHistory={isLoadingHistory}\n\t\t\t\t\t\tonLoadOlderMessages={onLoadOlderMessages}\n\t\t\t\t\t\thistoryLoadingLabel={historyLoadingLabel}\n\t\t\t\t\t\tinputDisabled={inputDisabled}\n\t\t\t\t\t\terrorMessage={errorMessage}\n\t\t\t\t\t\tclassName={className}\n\t\t\t\t\t\tstyle={style}\n\t\t\t\t\t/>\n\t\t\t\t</PanelPositioner>\n\t\t\t)}\n\n\t\t\t<CopilotBall\n\t\t\t\tisOpen={isOpen}\n\t\t\t\tonToggle={handleBallClick}\n\t\t\t\tposition={position}\n\t\t\t\tsize={ballSize}\n\t\t\t\tisDragging={isDragging}\n\t\t\t\tdraggable={draggable}\n\t\t\t\tcolor={ballColor}\n\t\t\t\tzIndex={zIndex + 1}\n\t\t\t\ticon={ballIcon}\n\t\t\t\topenIcon={ballOpenIcon}\n\t\t\t\tariaLabel={ballAriaLabel}\n\t\t\t\t{...dragHandlers}\n\t\t\t/>\n\t\t</>\n\t);\n};\n\nexport default ControlledCopilot;\n"],"names":["ControlledCopilot","messages","onSendMessage","isThinking","thinkingLabel","isStreaming","onStop","interruptedLabel","followUpsLabel","hasMoreHistory","isLoadingHistory","onLoadOlderMessages","historyLoadingLabel","errorMessage","ballSize","corner","offset","initialPosition","draggable","snapToEdge","onPositionChange","ballIcon","ballOpenIcon","ballColor","COLORS","zIndex","ballAriaLabel","panelWidth","panelHeight","panelGap","title","badge","subtitle","avatar","placeholder","disclaimer","emptyStateTitle","emptyStateSubtitle","suggestions","onSuggestionClick","showRefresh","onRefresh","inputDisabled","open","defaultOpen","onOpenChange","closeOnClickOutside","className","style","uncontrolledOpen","setUncontrolledOpen","useState","panelRef","useRef","isControlled","isOpen","setOpen","useCallback","next","position","isDragging","viewport","dragHandlers","shouldIgnoreClick","useDraggableFloater","handleBallClick","useEffect","handleKeyDown","event","handlePointerDown","target","COPILOT_BALL_ATTRIBUTE","placement","getCopilotPanelPlacement","jsxs","Fragment","jsx","PanelPositioner","CopilotPanel","CopilotBall"],"mappings":";;;;;;;;AAmBO,MAAMA,KAAsD,CAAC;AAAA;AAAA,EAEnE,UAAAC;AAAA,EACA,eAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,eAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,QAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,gBAAAC,IAAiB;AAAA,EACjB,kBAAAC,IAAmB;AAAA,EACnB,qBAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,cAAAC;AAAA;AAAA,EAEA,UAAAC,IAAW;AAAA,EACX,QAAAC,IAAS;AAAA,EACT,QAAAC,IAAS;AAAA,EACT,iBAAAC;AAAA,EACA,WAAAC,IAAY;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A,OAAAC;AAAA,YACA,UAAAC;AAAA,YACA,QAAAC;AAAA,YACA,aAAAC;AAAA,YACA,YAAAC;AAAA,YACA,iBAAAC;AAAA,YACA,oBAAAC;AAAA,YACA,aAAAC;AAAA,YACA,mBAAAC;AAAA,YACA,aAAAC;AAAA,YACA,WAAAC;AAAA,YACA,YAAAtC;AAAA,YACA,eAAAC;AAAA,YACA,aAAAC;AAAA,YACA,QAAAC;AAAA,YACA,kBAAAC;AAAA,YACA,gBAAAC;AAAA,YACA,gBAAAC;AAAA,YACA,kBAAAC;AAAA,YACA,qBAAAC;AAAA,YACA,qBAAAC;AAAA,YACA,eAAA8B;AAAA,YACA,cAAA7B;AAAA,YACA,WAAAkC;AAAA,YACA,OAAAC;AAAA,UAAA;AAAA,QAAA;AAAA,MACD;AAAA,IAAA;AAAA,IAIF,gBAAA4B;AAAA,MAACG;AAAA,MAAA;AAAA,QACA,QAAAxB;AAAA,QACA,UAAUU;AAAA,QACV,UAAAN;AAAA,QACA,MAAM7C;AAAA,QACN,YAAA8C;AAAA,QACA,WAAA1C;AAAA,QACA,OAAOK;AAAA,QACP,QAAQE,IAAS;AAAA,QACjB,MAAMJ;AAAA,QACN,UAAUC;AAAA,QACV,WAAWI;AAAA,QACV,GAAGoC;AAAA,MAAA;AAAA,IAAA;AAAA,EACL,GACD;AAEF;"}
@@ -0,0 +1,7 @@
1
+ export declare const PanelPositioner: import('styled-components').StyledComponent<"div", any, {
2
+ $left: number;
3
+ $top: number;
4
+ $width: number;
5
+ $height: number;
6
+ $zIndex: number;
7
+ }, never>;
@@ -0,0 +1,31 @@
1
+ import e from "styled-components";
2
+ const o = e.div`
3
+ position: fixed;
4
+ left: ${(t) => t.$left}px;
5
+ top: ${(t) => t.$top}px;
6
+ width: ${(t) => t.$width}px;
7
+ height: ${(t) => t.$height}px;
8
+ z-index: ${(t) => t.$zIndex};
9
+ display: flex;
10
+ animation: bikCopilotPanelIn 0.16s ease-out;
11
+
12
+ > * {
13
+ flex: 1;
14
+ min-width: 0;
15
+ }
16
+
17
+ @keyframes bikCopilotPanelIn {
18
+ from {
19
+ opacity: 0;
20
+ transform: translateY(6px) scale(0.98);
21
+ }
22
+ to {
23
+ opacity: 1;
24
+ transform: translateY(0) scale(1);
25
+ }
26
+ }
27
+ `;
28
+ export {
29
+ o as PanelPositioner
30
+ };
31
+ //# sourceMappingURL=ControlledCopilot.styled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ControlledCopilot.styled.js","sources":["../../../../src/components/bik-copilot/ControlledCopilot.styled.ts"],"sourcesContent":["import styled from 'styled-components';\n\nexport const PanelPositioner = styled.div<{\n\t$left: number;\n\t$top: number;\n\t$width: number;\n\t$height: number;\n\t$zIndex: number;\n}>`\n\tposition: fixed;\n\tleft: ${(props) => props.$left}px;\n\ttop: ${(props) => props.$top}px;\n\twidth: ${(props) => props.$width}px;\n\theight: ${(props) => props.$height}px;\n\tz-index: ${(props) => props.$zIndex};\n\tdisplay: flex;\n\tanimation: bikCopilotPanelIn 0.16s ease-out;\n\n\t> * {\n\t\tflex: 1;\n\t\tmin-width: 0;\n\t}\n\n\t@keyframes bikCopilotPanelIn {\n\t\tfrom {\n\t\t\topacity: 0;\n\t\t\ttransform: translateY(6px) scale(0.98);\n\t\t}\n\t\tto {\n\t\t\topacity: 1;\n\t\t\ttransform: translateY(0) scale(1);\n\t\t}\n\t}\n`;\n"],"names":["PanelPositioner","styled","props"],"mappings":";AAEO,MAAMA,IAAkBC,EAAO;AAAA;AAAA,SAQ7B,CAACC,MAAUA,EAAM,KAAK;AAAA,QACvB,CAACA,MAAUA,EAAM,IAAI;AAAA,UACnB,CAACA,MAAUA,EAAM,MAAM;AAAA,WACtB,CAACA,MAAUA,EAAM,OAAO;AAAA,YACvB,CAACA,MAAUA,EAAM,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;"}
@@ -0,0 +1,13 @@
1
+ import { default as React } from 'react';
2
+ import { CopilotBallProps } from './model';
3
+ /**
4
+ * Marks the ball in the DOM so an outside-click handler can tell the ball apart
5
+ * from the rest of the page and not fight the ball's own toggle.
6
+ */
7
+ export declare const COPILOT_BALL_ATTRIBUTE = "data-bik-copilot-ball";
8
+ /**
9
+ * The floating ball that opens the copilot panel. Purely presentational — the
10
+ * drag gesture lives in `useDraggableFloater` and is passed in as handlers.
11
+ */
12
+ export declare const CopilotBall: React.FC<CopilotBallProps>;
13
+ export default CopilotBall;
@@ -0,0 +1,50 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import b from "../../assets/icons/bik_ai_stars_icon.svg.js";
3
+ import s from "../../assets/icons/chevronDown.svg.js";
4
+ import { BallButton as x } from "./CopilotBall.styled.js";
5
+ const C = "data-bik-copilot-ball", w = ({
6
+ isOpen: t,
7
+ onToggle: n,
8
+ position: i,
9
+ size: a,
10
+ isDragging: e,
11
+ draggable: c,
12
+ color: d,
13
+ zIndex: g,
14
+ icon: h,
15
+ openIcon: m,
16
+ ariaLabel: p,
17
+ onPointerDown: $,
18
+ onPointerMove: f,
19
+ onPointerUp: u,
20
+ onPointerCancel: B
21
+ }) => {
22
+ const o = Math.round(a * 0.42), l = t ? /* @__PURE__ */ r(s, { width: o, height: o }) : /* @__PURE__ */ r(b, { width: o, height: o }), I = t ? m ?? l : h ?? l;
23
+ return /* @__PURE__ */ r(
24
+ x,
25
+ {
26
+ type: "button",
27
+ [C]: "true",
28
+ $size: a,
29
+ $left: i.x,
30
+ $top: i.y,
31
+ $color: d,
32
+ $zIndex: g,
33
+ $isDragging: e,
34
+ $draggable: c,
35
+ "aria-label": p || "Copilot",
36
+ "aria-expanded": t,
37
+ onClick: n,
38
+ onPointerDown: $,
39
+ onPointerMove: f,
40
+ onPointerUp: u,
41
+ onPointerCancel: B,
42
+ children: I
43
+ }
44
+ );
45
+ };
46
+ export {
47
+ C as COPILOT_BALL_ATTRIBUTE,
48
+ w as CopilotBall
49
+ };
50
+ //# sourceMappingURL=CopilotBall.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CopilotBall.js","sources":["../../../../src/components/bik-copilot/CopilotBall.tsx"],"sourcesContent":["import AiStarsIcon from '@src/assets/icons/bik_ai_stars_icon.svg';\nimport ChevronDownIcon from '@src/assets/icons/chevronDown.svg';\nimport React from 'react';\nimport { BallButton } from './CopilotBall.styled';\nimport { CopilotBallProps } from './model';\n\n/**\n * Marks the ball in the DOM so an outside-click handler can tell the ball apart\n * from the rest of the page and not fight the ball's own toggle.\n */\nexport const COPILOT_BALL_ATTRIBUTE = 'data-bik-copilot-ball';\n\n/**\n * The floating ball that opens the copilot panel. Purely presentational — the\n * drag gesture lives in `useDraggableFloater` and is passed in as handlers.\n */\nexport const CopilotBall: React.FC<CopilotBallProps> = ({\n\tisOpen,\n\tonToggle,\n\tposition,\n\tsize,\n\tisDragging,\n\tdraggable,\n\tcolor,\n\tzIndex,\n\ticon,\n\topenIcon,\n\tariaLabel,\n\tonPointerDown,\n\tonPointerMove,\n\tonPointerUp,\n\tonPointerCancel,\n}) => {\n\tconst iconSize = Math.round(size * 0.42);\n\tconst defaultIcon = isOpen ? (\n\t\t<ChevronDownIcon width={iconSize} height={iconSize} />\n\t) : (\n\t\t<AiStarsIcon width={iconSize} height={iconSize} />\n\t);\n\tconst activeIcon = isOpen ? openIcon ?? defaultIcon : icon ?? defaultIcon;\n\n\treturn (\n\t\t<BallButton\n\t\t\ttype=\"button\"\n\t\t\t{...{ [COPILOT_BALL_ATTRIBUTE]: 'true' }}\n\t\t\t$size={size}\n\t\t\t$left={position.x}\n\t\t\t$top={position.y}\n\t\t\t$color={color}\n\t\t\t$zIndex={zIndex}\n\t\t\t$isDragging={isDragging}\n\t\t\t$draggable={draggable}\n\t\t\t/* A disclosure button keeps a stable name and reports its state through\n\t\t\t aria-expanded, so this must not become \"Open/Close copilot\" — that\n\t\t\t would also collide with the panel's own close button. */\n\t\t\taria-label={ariaLabel || 'Copilot'}\n\t\t\taria-expanded={isOpen}\n\t\t\tonClick={onToggle}\n\t\t\tonPointerDown={onPointerDown}\n\t\t\tonPointerMove={onPointerMove}\n\t\t\tonPointerUp={onPointerUp}\n\t\t\tonPointerCancel={onPointerCancel}\n\t\t>\n\t\t\t{activeIcon}\n\t\t</BallButton>\n\t);\n};\n\nexport default CopilotBall;\n"],"names":["COPILOT_BALL_ATTRIBUTE","CopilotBall","isOpen","onToggle","position","size","isDragging","draggable","color","zIndex","icon","openIcon","ariaLabel","onPointerDown","onPointerMove","onPointerUp","onPointerCancel","iconSize","defaultIcon","jsx","ChevronDownIcon","AiStarsIcon","activeIcon","BallButton"],"mappings":";;;;AAUO,MAAMA,IAAyB,yBAMzBC,IAA0C,CAAC;AAAA,EACvD,QAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,QAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,eAAAC;AAAA,EACA,aAAAC;AAAA,EACA,iBAAAC;AACD,MAAM;AACL,QAAMC,IAAW,KAAK,MAAMZ,IAAO,IAAI,GACjCa,IAAchB,IACnB,gBAAAiB,EAACC,GAAA,EAAgB,OAAOH,GAAU,QAAQA,EAAA,CAAU,IAEpD,gBAAAE,EAACE,GAAA,EAAY,OAAOJ,GAAU,QAAQA,GAAU,GAE3CK,IAAapB,IAASS,KAAYO,IAAcR,KAAQQ;AAE9D,SACC,gBAAAC;AAAA,IAACI;AAAA,IAAA;AAAA,MACA,MAAK;AAAA,MACC,CAACvB,CAAsB,GAAG;AAAA,MAChC,OAAOK;AAAA,MACP,OAAOD,EAAS;AAAA,MAChB,MAAMA,EAAS;AAAA,MACf,QAAQI;AAAA,MACR,SAASC;AAAA,MACT,aAAaH;AAAA,MACb,YAAYC;AAAA,MAIZ,cAAYK,KAAa;AAAA,MACzB,iBAAeV;AAAA,MACf,SAASC;AAAA,MACT,eAAAU;AAAA,MACA,eAAAC;AAAA,MACA,aAAAC;AAAA,MACA,iBAAAC;AAAA,MAEC,UAAAM;AAAA,IAAA;AAAA,EAAA;AAGJ;"}
@@ -0,0 +1,9 @@
1
+ export declare const BallButton: import('styled-components').StyledComponent<"button", any, {
2
+ $size: number;
3
+ $left: number;
4
+ $top: number;
5
+ $color: string;
6
+ $zIndex: number;
7
+ $isDragging: boolean;
8
+ $draggable: boolean;
9
+ }, never>;
@@ -0,0 +1,46 @@
1
+ import s from "styled-components";
2
+ const t = s.button`
3
+ position: fixed;
4
+ left: ${(e) => e.$left}px;
5
+ top: ${(e) => e.$top}px;
6
+ width: ${(e) => e.$size}px;
7
+ height: ${(e) => e.$size}px;
8
+ z-index: ${(e) => e.$zIndex};
9
+
10
+ display: flex;
11
+ align-items: center;
12
+ justify-content: center;
13
+ padding: 0;
14
+ border: none;
15
+ border-radius: 50%;
16
+ background: ${(e) => e.$color};
17
+ color: #ffffff;
18
+ box-shadow: ${(e) => e.$isDragging ? "0 12px 32px rgba(40, 3, 78, 0.36)" : "0 6px 20px rgba(40, 3, 78, 0.24)"};
19
+
20
+ cursor: ${(e) => e.$isDragging ? "grabbing" : e.$draggable ? "grab" : "pointer"};
21
+ touch-action: none;
22
+ user-select: none;
23
+ -webkit-user-select: none;
24
+
25
+ /* Position changes animate on release but must track the pointer 1:1 while
26
+ the user is dragging. */
27
+ transition: ${(e) => e.$isDragging ? "box-shadow 0.15s ease, transform 0.15s ease" : "left 0.22s ease, top 0.22s ease, box-shadow 0.15s ease, transform 0.15s ease"};
28
+ transform: ${(e) => e.$isDragging ? "scale(1.06)" : "scale(1)"};
29
+
30
+ &:hover {
31
+ transform: scale(1.06);
32
+ }
33
+
34
+ &:focus-visible {
35
+ outline: 2px solid #ffffff;
36
+ outline-offset: 2px;
37
+ }
38
+
39
+ svg {
40
+ pointer-events: none;
41
+ }
42
+ `;
43
+ export {
44
+ t as BallButton
45
+ };
46
+ //# sourceMappingURL=CopilotBall.styled.js.map