@bikdotai/bik-component-library 0.0.823 → 0.0.824
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/cjs/components/adbanner/AdBanner.js.map +1 -0
- package/dist/cjs/components/{banner → adbanner}/Banner.styled.js +13 -9
- package/dist/cjs/components/adbanner/Banner.styled.js.map +1 -0
- package/dist/cjs/components/adbanner/BannerInline.js.map +1 -0
- package/dist/cjs/components/adbanner/BannerWithImage.js.map +1 -0
- package/dist/cjs/components/adbanner/CardBanner.js.map +1 -0
- package/dist/cjs/components/adbanner/CardBannerWithImage.js.map +1 -0
- package/dist/cjs/components/adbanner/model.js.map +1 -0
- package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js +1 -1
- package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
- package/dist/cjs/components/agent-builder/context/AgentBuilderContext.js +1 -1
- package/dist/cjs/components/agent-builder/context/AgentBuilderContext.js.map +1 -1
- package/dist/cjs/components/agent-builder/utils/mentionSerialization.js +2 -2
- package/dist/cjs/components/agent-builder/utils/mentionSerialization.js.map +1 -1
- package/dist/cjs/editor/BikEditor.js +1 -1
- package/dist/cjs/editor/BikEditor.js.map +1 -1
- package/dist/cjs/editor/BikEditor.styles.js +143 -5
- package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
- package/dist/cjs/editor/BikEditor.types.js.map +1 -1
- package/dist/cjs/editor/BikEditor.utils.js +3 -2
- package/dist/cjs/editor/BikEditor.utils.js.map +1 -1
- package/dist/cjs/editor/extensions/buildExtensions.js +3 -1
- package/dist/cjs/editor/extensions/buildExtensions.js.map +1 -1
- package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js +4 -0
- package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -0
- package/dist/cjs/editor/extensions/jsonHighlight/tokenizeJson.js +2 -0
- package/dist/cjs/editor/extensions/jsonHighlight/tokenizeJson.js.map +1 -0
- package/dist/cjs/icons/Actions/Common actions/ProductTour.js +2 -0
- package/dist/cjs/icons/Actions/Common actions/ProductTour.js.map +1 -0
- package/dist/cjs/icons/Actions/Common actions/RestApi.js +2 -0
- package/dist/cjs/icons/Actions/Common actions/RestApi.js.map +1 -0
- package/dist/cjs/icons/Actions/Common actions/Save.js +2 -0
- package/dist/cjs/icons/Actions/Common actions/Save.js.map +1 -0
- package/dist/cjs/icons/Actions/Common actions/Shortcut.js +2 -0
- package/dist/cjs/icons/Actions/Common actions/Shortcut.js.map +1 -0
- package/dist/cjs/icons/BIK AI specific/WandSparkles.js +2 -0
- package/dist/cjs/icons/BIK AI specific/WandSparkles.js.map +1 -0
- package/dist/cjs/icons/BIK AI specific/Webhook.js +2 -0
- package/dist/cjs/icons/BIK AI specific/Webhook.js.map +1 -0
- package/dist/cjs/icons/Informational/Store related/TicketForm.js +2 -0
- package/dist/cjs/icons/Informational/Store related/TicketForm.js.map +1 -0
- package/dist/cjs/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js +2 -0
- package/dist/cjs/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js.map +1 -0
- package/dist/cjs/icons/index.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/esm/components/adbanner/AdBanner.js.map +1 -0
- package/dist/esm/components/{banner → adbanner}/Banner.styled.js +18 -14
- package/dist/esm/components/adbanner/Banner.styled.js.map +1 -0
- package/dist/esm/components/adbanner/BannerInline.js.map +1 -0
- package/dist/esm/components/adbanner/BannerWithImage.js.map +1 -0
- package/dist/esm/components/adbanner/CardBanner.js.map +1 -0
- package/dist/esm/components/adbanner/CardBannerWithImage.js.map +1 -0
- package/dist/esm/components/adbanner/model.js.map +1 -0
- package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js +24 -24
- package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
- package/dist/esm/components/agent-builder/context/AgentBuilderContext.js +98 -101
- package/dist/esm/components/agent-builder/context/AgentBuilderContext.js.map +1 -1
- package/dist/esm/components/agent-builder/utils/mentionSerialization.d.ts +5 -7
- package/dist/esm/components/agent-builder/utils/mentionSerialization.js +40 -37
- package/dist/esm/components/agent-builder/utils/mentionSerialization.js.map +1 -1
- package/dist/esm/editor/BikEditor.js +247 -181
- package/dist/esm/editor/BikEditor.js.map +1 -1
- package/dist/esm/editor/BikEditor.styles.d.ts +9 -0
- package/dist/esm/editor/BikEditor.styles.js +147 -7
- package/dist/esm/editor/BikEditor.styles.js.map +1 -1
- package/dist/esm/editor/BikEditor.types.d.ts +76 -0
- package/dist/esm/editor/BikEditor.types.js.map +1 -1
- package/dist/esm/editor/BikEditor.utils.d.ts +15 -1
- package/dist/esm/editor/BikEditor.utils.js +155 -92
- package/dist/esm/editor/BikEditor.utils.js.map +1 -1
- package/dist/esm/editor/extensions/buildExtensions.d.ts +1 -1
- package/dist/esm/editor/extensions/buildExtensions.js +86 -55
- package/dist/esm/editor/extensions/buildExtensions.js.map +1 -1
- package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.d.ts +14 -0
- package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js +132 -0
- package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -0
- package/dist/esm/editor/extensions/jsonHighlight/tokenizeJson.d.ts +18 -0
- package/dist/esm/editor/extensions/jsonHighlight/tokenizeJson.js +21 -0
- package/dist/esm/editor/extensions/jsonHighlight/tokenizeJson.js.map +1 -0
- package/dist/esm/editor/index.d.ts +1 -1
- package/dist/esm/icons/Actions/Common actions/ProductTour.d.ts +7 -0
- package/dist/esm/icons/Actions/Common actions/ProductTour.js +51 -0
- package/dist/esm/icons/Actions/Common actions/ProductTour.js.map +1 -0
- package/dist/esm/icons/Actions/Common actions/RestApi.d.ts +7 -0
- package/dist/esm/icons/Actions/Common actions/RestApi.js +29 -0
- package/dist/esm/icons/Actions/Common actions/RestApi.js.map +1 -0
- package/dist/esm/icons/Actions/Common actions/Save.d.ts +7 -0
- package/dist/esm/icons/Actions/Common actions/Save.js +40 -0
- package/dist/esm/icons/Actions/Common actions/Save.js.map +1 -0
- package/dist/esm/icons/Actions/Common actions/Shortcut.d.ts +7 -0
- package/dist/esm/icons/Actions/Common actions/Shortcut.js +40 -0
- package/dist/esm/icons/Actions/Common actions/Shortcut.js.map +1 -0
- package/dist/esm/icons/Actions/Common actions/index.d.ts +4 -0
- package/dist/esm/icons/BIK AI specific/WandSparkles.d.ts +7 -0
- package/dist/esm/icons/BIK AI specific/WandSparkles.js +39 -0
- package/dist/esm/icons/BIK AI specific/WandSparkles.js.map +1 -0
- package/dist/esm/icons/BIK AI specific/Webhook.d.ts +7 -0
- package/dist/esm/icons/BIK AI specific/Webhook.js +32 -0
- package/dist/esm/icons/BIK AI specific/Webhook.js.map +1 -0
- package/dist/esm/icons/BIK AI specific/index.d.ts +2 -0
- package/dist/esm/icons/Informational/Store related/TicketForm.d.ts +7 -0
- package/dist/esm/icons/Informational/Store related/TicketForm.js +65 -0
- package/dist/esm/icons/Informational/Store related/TicketForm.js.map +1 -0
- package/dist/esm/icons/Informational/Store related/index.d.ts +1 -0
- package/dist/esm/icons/Legacy - Bikayi specific/Services/LoudSpeaker.d.ts +7 -0
- package/dist/esm/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js +35 -0
- package/dist/esm/icons/Legacy - Bikayi specific/Services/LoudSpeaker.js.map +1 -0
- package/dist/esm/icons/Legacy - Bikayi specific/Services/index.d.ts +1 -0
- package/dist/esm/icons/index.d.ts +4 -4
- package/dist/esm/icons/index.js +284 -268
- package/dist/esm/icons/index.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -2
- package/package.json +1 -1
- package/dist/cjs/components/banner/AdBanner.js.map +0 -1
- package/dist/cjs/components/banner/Banner.styled.js.map +0 -1
- package/dist/cjs/components/banner/BannerInline.js.map +0 -1
- package/dist/cjs/components/banner/BannerWithImage.js.map +0 -1
- package/dist/cjs/components/banner/CardBanner.js.map +0 -1
- package/dist/cjs/components/banner/CardBannerWithImage.js.map +0 -1
- package/dist/cjs/components/banner/model.js.map +0 -1
- package/dist/esm/components/banner/AdBanner.js.map +0 -1
- package/dist/esm/components/banner/Banner.stories.d.ts +0 -39
- package/dist/esm/components/banner/Banner.styled.js.map +0 -1
- package/dist/esm/components/banner/BannerInline.js.map +0 -1
- package/dist/esm/components/banner/BannerWithImage.js.map +0 -1
- package/dist/esm/components/banner/CardBanner.js.map +0 -1
- package/dist/esm/components/banner/CardBannerWithImage.js.map +0 -1
- package/dist/esm/components/banner/model.js.map +0 -1
- /package/dist/cjs/components/{banner → adbanner}/AdBanner.js +0 -0
- /package/dist/cjs/components/{banner → adbanner}/BannerInline.js +0 -0
- /package/dist/cjs/components/{banner → adbanner}/BannerWithImage.js +0 -0
- /package/dist/cjs/components/{banner → adbanner}/CardBanner.js +0 -0
- /package/dist/cjs/components/{banner → adbanner}/CardBannerWithImage.js +0 -0
- /package/dist/cjs/components/{banner → adbanner}/model.js +0 -0
- /package/dist/esm/components/{banner → adbanner}/AdBanner.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/AdBanner.js +0 -0
- /package/dist/esm/components/{banner → adbanner}/Banner.styled.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/BannerInline.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/BannerInline.js +0 -0
- /package/dist/esm/components/{banner → adbanner}/BannerWithImage.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/BannerWithImage.js +0 -0
- /package/dist/esm/components/{banner → adbanner}/CardBanner.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/CardBanner.js +0 -0
- /package/dist/esm/components/{banner → adbanner}/CardBannerWithImage.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/CardBannerWithImage.js +0 -0
- /package/dist/esm/components/{banner → adbanner}/index.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/model.d.ts +0 -0
- /package/dist/esm/components/{banner → adbanner}/model.js +0 -0
|
@@ -6,9 +6,9 @@ import { AgentTool, SubAgentRef } from '../AgentBuilder.model';
|
|
|
6
6
|
* `instructions` string.
|
|
7
7
|
*
|
|
8
8
|
* Firebase stores `instructions` as PLAIN TEXT with inline reference tokens:
|
|
9
|
-
* - `{{subagent:<agentId>}}`
|
|
10
|
-
* - `{{tool:<
|
|
11
|
-
* - `{{<variableName>}}`
|
|
9
|
+
* - `{{subagent:<agentId>}}` — hand-off to another agent
|
|
10
|
+
* - `{{tool:<tool_id>}}` — an action the agent can call
|
|
11
|
+
* - `{{<variableName>}}` — a template variable
|
|
12
12
|
*
|
|
13
13
|
* In the editor those references are inserted via the `@` mention menu (which we
|
|
14
14
|
* populate with BOTH tools and sub-agents). Mention nodes keep their `id` in the
|
|
@@ -18,8 +18,6 @@ import { AgentTool, SubAgentRef } from '../AgentBuilder.model';
|
|
|
18
18
|
export interface MentionKindMeta {
|
|
19
19
|
/** Distinguishes a tool reference from a sub-agent reference. */
|
|
20
20
|
kind: 'tool' | 'subagent';
|
|
21
|
-
/** For tools: the function_key used in the `{{tool:KEY}}` token. */
|
|
22
|
-
functionKey?: string;
|
|
23
21
|
/** Plain item name (no prefix) shown in the picker dropdown rows. */
|
|
24
22
|
plainLabel?: string;
|
|
25
23
|
/** For tools: the source bucket (manifest / shopify / …) the picker groups by. */
|
|
@@ -55,7 +53,7 @@ export declare const buildMentionHtml: (id: string, label: string, kind: 'tool'
|
|
|
55
53
|
export declare const instructionsToEditorHtml: (text: string, mentionItems?: MentionItem[]) => string;
|
|
56
54
|
/**
|
|
57
55
|
* Convert a BikEditor document (from `ref.getJSON()`) into the firebase
|
|
58
|
-
* instructions string, replacing mention nodes with `{{subagent
|
|
59
|
-
* `{{tool
|
|
56
|
+
* instructions string, replacing mention nodes with `{{subagent:<id>}}` /
|
|
57
|
+
* `{{tool:<tool_id>}}` tokens.
|
|
60
58
|
*/
|
|
61
59
|
export declare const editorDocToInstructions: (doc: Record<string, unknown> | null, tools: AgentTool[]) => string;
|
|
@@ -5,64 +5,67 @@ const d = {
|
|
|
5
5
|
}, m = (t, e = "Manifest") => t ? d[t] ?? t : e, k = (t) => {
|
|
6
6
|
const e = t ? String(t) : "";
|
|
7
7
|
return e === "BIK" ? "BIK" : e === "BSP" ? "BSP" : "Manifest";
|
|
8
|
-
},
|
|
8
|
+
}, S = (t, e, n = "Manifest") => [
|
|
9
9
|
...t.map(
|
|
10
|
-
(
|
|
11
|
-
id:
|
|
12
|
-
label: `${m(
|
|
10
|
+
(a) => ({
|
|
11
|
+
id: a.tool_id,
|
|
12
|
+
label: `${m(a.source, n)} : ${a.display_name}`,
|
|
13
13
|
meta: {
|
|
14
14
|
kind: "tool",
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
source: i.source
|
|
15
|
+
plainLabel: a.display_name,
|
|
16
|
+
source: a.source
|
|
18
17
|
}
|
|
19
18
|
})
|
|
20
19
|
),
|
|
21
20
|
...e.map(
|
|
22
|
-
(
|
|
23
|
-
id:
|
|
24
|
-
label: `sub-agent: ${
|
|
25
|
-
meta: { kind: "subagent", plainLabel:
|
|
21
|
+
(a) => ({
|
|
22
|
+
id: a.id,
|
|
23
|
+
label: `sub-agent: ${a.name}`,
|
|
24
|
+
meta: { kind: "subagent", plainLabel: a.name }
|
|
26
25
|
})
|
|
27
26
|
)
|
|
28
|
-
],
|
|
27
|
+
], i = (t) => t.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"), r = (t) => i(t).replace(/"/g, """), c = (t, e, n) => `<span data-type="mentionAgent" class="bik-mention bik-mention--agent" data-id="${r(t)}" data-label="${r(e)}" data-kind="${r(n)}">${i(e)}</span>`, $ = (t, e, n) => c(t, e, n), g = (t) => {
|
|
29
28
|
const e = /* @__PURE__ */ new Map();
|
|
30
29
|
for (const n of t) {
|
|
31
|
-
const
|
|
32
|
-
|
|
30
|
+
const a = n.meta;
|
|
31
|
+
a?.kind === "tool" ? e.set(`tool:${String(n.id)}`, n) : a?.kind === "subagent" && e.set(`subagent:${String(n.id)}`, n);
|
|
33
32
|
}
|
|
34
33
|
return e;
|
|
35
|
-
}, l = /\{\{(tool:[^}]+|subagent:[^}]+)\}\}/g,
|
|
36
|
-
let n = "",
|
|
34
|
+
}, l = /\{\{(tool:[^}]+|subagent:[^}]+)\}\}/g, b = (t, e) => {
|
|
35
|
+
let n = "", a = 0;
|
|
37
36
|
l.lastIndex = 0;
|
|
38
37
|
let o;
|
|
39
38
|
for (; (o = l.exec(t)) !== null; ) {
|
|
40
|
-
n +=
|
|
41
|
-
const
|
|
42
|
-
if (
|
|
43
|
-
const p =
|
|
44
|
-
n += c(String(
|
|
39
|
+
n += i(t.slice(a, o.index));
|
|
40
|
+
const s = e.get(o[1]);
|
|
41
|
+
if (s) {
|
|
42
|
+
const p = s.meta.kind;
|
|
43
|
+
n += c(String(s.id), s.label, p);
|
|
45
44
|
} else
|
|
46
|
-
n +=
|
|
47
|
-
|
|
45
|
+
n += i(o[0]);
|
|
46
|
+
a = l.lastIndex;
|
|
48
47
|
}
|
|
49
|
-
return n +=
|
|
50
|
-
},
|
|
48
|
+
return n += i(t.slice(a)), n.replace(/\n/g, "<br>");
|
|
49
|
+
}, T = (t, e = []) => {
|
|
51
50
|
if (!t)
|
|
52
51
|
return "";
|
|
53
|
-
const n =
|
|
54
|
-
return t.split(/\n{2,}/).map((
|
|
55
|
-
},
|
|
56
|
-
const n = e[t];
|
|
57
|
-
return n ? `{{tool:${n}}}` : `{{subagent:${t}}}`;
|
|
58
|
-
}, u = (t, e) => {
|
|
52
|
+
const n = g(e);
|
|
53
|
+
return t.split(/\n{2,}/).map((a) => `<p>${b(a, n)}</p>`).join("");
|
|
54
|
+
}, f = (t, e, n) => (e ?? (n.has(t) ? "tool" : "subagent")) === "tool" ? `{{tool:${t}}}` : `{{subagent:${t}}}`, u = (t, e) => {
|
|
59
55
|
switch (t.type) {
|
|
60
56
|
case "text":
|
|
61
57
|
return t.text ?? "";
|
|
62
58
|
case "mentionAgent":
|
|
63
59
|
case "mentionTeam": {
|
|
64
60
|
const n = t.attrs?.id;
|
|
65
|
-
|
|
61
|
+
if (n == null)
|
|
62
|
+
return "";
|
|
63
|
+
const a = t.attrs?.kind;
|
|
64
|
+
return f(
|
|
65
|
+
String(n),
|
|
66
|
+
a == null ? null : String(a),
|
|
67
|
+
e
|
|
68
|
+
);
|
|
66
69
|
}
|
|
67
70
|
case "variable":
|
|
68
71
|
return `{{${String(t.attrs?.variableName ?? "")}}}`;
|
|
@@ -75,10 +78,10 @@ const d = {
|
|
|
75
78
|
` : n;
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
|
-
},
|
|
81
|
+
}, y = (t, e) => {
|
|
79
82
|
if (!t)
|
|
80
83
|
return "";
|
|
81
|
-
const n = e.
|
|
84
|
+
const n = new Set(e.map((a) => a.tool_id));
|
|
82
85
|
return u(t, n).replace(
|
|
83
86
|
/\n+$/,
|
|
84
87
|
""
|
|
@@ -87,10 +90,10 @@ const d = {
|
|
|
87
90
|
export {
|
|
88
91
|
d as TOOL_SOURCE_LABELS,
|
|
89
92
|
k as appTypeLabel,
|
|
90
|
-
|
|
93
|
+
S as buildAgentMentionItems,
|
|
91
94
|
$ as buildMentionHtml,
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
y as editorDocToInstructions,
|
|
96
|
+
T as instructionsToEditorHtml,
|
|
94
97
|
m as toolSourceLabel
|
|
95
98
|
};
|
|
96
99
|
//# sourceMappingURL=mentionSerialization.js.map
|
|
@@ -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 { AgentTool, SubAgentRef } from '../AgentBuilder.model';\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:<function_key>}}` — an action the agent can call\n * - `{{<variableName>}}` — a template variable\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 reference from a sub-agent reference. */\n\tkind: 'tool' | 'subagent';\n\t/** For tools: the function_key used in the `{{tool:KEY}}` token. */\n\tfunctionKey?: string;\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}\n\n/** Display labels for the known tool sources (drives picker headers + chip prefix). */\nexport const TOOL_SOURCE_LABELS: Record<string, string> = {\n\tmanifest: 'Manifest',\n\tshopify: 'Shopify',\n\tintegration: 'Integration',\n};\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] ?? 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\tfunctionKey: t.function_key,\n\t\t\t\tplainLabel: t.display_name,\n\t\t\t\tsource: t.source,\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\nconst escapeHtml = (raw: string): string =>\n\traw.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\nconst escapeAttr = (raw: string): string =>\n\tescapeHtml(raw).replace(/\"/g, '"');\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 = (id: string, label: string, kind: string): 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)}\">${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.\n */\nexport const buildMentionHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: 'tool' | 'subagent',\n): string => mentionSpanHtml(id, label, kind);\n\n/** `{{tool:KEY}}` / `{{subagent:ID}}` → the mention item that produced them. */\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\tif (meta?.kind === 'tool' && meta.functionKey) {\n\t\t\tbyToken.set(`tool:${meta.functionKey}`, item);\n\t\t} else if (meta?.kind === 'subagent') {\n\t\t\tbyToken.set(`subagent:${String(item.id)}`, item);\n\t\t}\n\t}\n\treturn byToken;\n};\n\n// Matches the reference tokens we render as chips. Other `{{var}}` tokens fall\n// through untouched (left as literal text for the variable decoration).\nconst REFERENCE_TOKEN = /\\{\\{(tool:[^}]+|subagent:[^}]+)\\}\\}/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 kind = (item.meta as unknown as MentionKindMeta).kind;\n\t\t\tout += mentionSpanHtml(String(item.id), item.label, kind);\n\t\t} else {\n\t\t\t// Tool/sub-agent no longer in the available list → keep the raw token.\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/** Map of mention node id → token, derived from the available tools. */\nconst resolveMentionToken = (\n\tid: string,\n\ttoolKeyById: Record<string, string>,\n): string => {\n\tconst functionKey = toolKeyById[id];\n\tif (functionKey) {\n\t\treturn `{{tool:${functionKey}}}`;\n\t}\n\treturn `{{subagent:${id}}}`;\n};\n\nconst nodeToText = (\n\tnode: ProseMirrorNode,\n\ttoolKeyById: Record<string, string>,\n): 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\treturn id == null ? '' : resolveMentionToken(String(id), toolKeyById);\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\tdefault: {\n\t\t\tconst inner = (node.content ?? [])\n\t\t\t\t.map((child) => nodeToText(child, toolKeyById))\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:KEY}}` 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 toolKeyById = tools.reduce<Record<string, string>>((acc, t) => {\n\t\tacc[t.tool_id] = t.function_key;\n\t\treturn acc;\n\t}, {});\n\treturn nodeToText(doc as unknown as ProseMirrorNode, toolKeyById).replace(\n\t\t/\\n+$/,\n\t\t'',\n\t);\n};\n"],"names":["TOOL_SOURCE_LABELS","toolSourceLabel","source","fallback","appTypeLabel","applicationType","key","buildAgentMentionItems","tools","subAgents","appLabel","t","s","escapeHtml","raw","escapeAttr","mentionSpanHtml","id","label","kind","buildMentionHtml","buildTokenLookup","mentionItems","byToken","item","meta","REFERENCE_TOKEN","inlineToHtml","segment","out","lastIndex","match","instructionsToEditorHtml","text","para","resolveMentionToken","toolKeyById","functionKey","nodeToText","node","inner","child","editorDocToInstructions","doc","acc"],"mappings":"AA+BO,MAAMA,IAA6C;AAAA,EACzD,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AACd,GAGaC,IAAkB,CAC9BC,GACAC,IAAW,eAEND,IAGEF,EAAmBE,CAAM,KAAKA,IAF7BC,GAMIC,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,GAAGV,EAAgBU,EAAE,QAAQD,CAAQ,CAAC,MAAMC,EAAE,YAAY;AAAA,MACjE,MAAM;AAAA,QACL,MAAM;AAAA,QACN,aAAaA,EAAE;AAAA,QACf,YAAYA,EAAE;AAAA,QACd,QAAQA,EAAE;AAAA,MAAA;AAAA,IACX;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;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AAIjC,EAAE,OAAO,IAAIA,EAAE,cACZiC,IACL,CAAA,CAAE;AACL,SAAON,EAAWK,GAAmCP,CAAW,EAAE;AAAA,IACjE;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 { AgentTool, SubAgentRef } from '../AgentBuilder.model';\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 * - `{{<variableName>}}` — a template variable\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 reference from a sub-agent reference. */\n\tkind: 'tool' | 'subagent';\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}\n\n/** Display labels for the known tool sources (drives picker headers + chip prefix). */\nexport const TOOL_SOURCE_LABELS: Record<string, string> = {\n\tmanifest: 'Manifest',\n\tshopify: 'Shopify',\n\tintegration: 'Integration',\n};\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] ?? 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},\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\nconst escapeHtml = (raw: string): string =>\n\traw.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\nconst escapeAttr = (raw: string): string =>\n\tescapeHtml(raw).replace(/\"/g, '"');\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 = (id: string, label: string, kind: string): 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)}\">${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.\n */\nexport const buildMentionHtml = (\n\tid: string,\n\tlabel: string,\n\tkind: 'tool' | 'subagent',\n): string => mentionSpanHtml(id, label, kind);\n\n/** `{{tool:<id>}}` / `{{subagent:<id>}}` → the mention item that produced them. */\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// Both tools and sub-agents are keyed by their 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}\n\t}\n\treturn byToken;\n};\n\n// Matches the reference tokens we render as chips. Other `{{var}}` tokens fall\n// through untouched (left as literal text for the variable decoration).\nconst REFERENCE_TOKEN = /\\{\\{(tool:[^}]+|subagent:[^}]+)\\}\\}/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 kind = (item.meta as unknown as MentionKindMeta).kind;\n\t\t\tout += mentionSpanHtml(String(item.id), item.label, kind);\n\t\t} else {\n\t\t\t// Tool/sub-agent no longer in the available list → keep the raw token.\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. Both tools and sub-agents store their id in the\n * node, so the token value is just that id — the kind only picks the prefix. The\n * node's `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\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\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":["TOOL_SOURCE_LABELS","toolSourceLabel","source","fallback","appTypeLabel","applicationType","key","buildAgentMentionItems","tools","subAgents","appLabel","t","s","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","inner","child","editorDocToInstructions","doc"],"mappings":"AA6BO,MAAMA,IAA6C;AAAA,EACzD,UAAU;AAAA,EACV,SAAS;AAAA,EACT,aAAa;AACd,GAGaC,IAAkB,CAC9BC,GACAC,IAAW,eAEND,IAGEF,EAAmBE,CAAM,KAAKA,IAF7BC,GAMIC,IAAe,CAACC,MAA8C;AAC1E,QAAMC,IAAMD,IAAkB,OAAOA,CAAe,IAAI;AACxD,SAAIC,MAAQ,QACJ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