@bikdotai/bik-component-library 0.0.821-beta.8 → 0.0.821
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/assets/icons/Shopify.svg.js +2 -0
- package/dist/cjs/assets/icons/Shopify.svg.js.map +1 -0
- package/dist/cjs/components/agent-builder/AgentBuilder.js +1 -1
- package/dist/cjs/components/agent-builder/AgentBuilder.js.map +1 -1
- package/dist/cjs/components/agent-builder/AgentBuilder.styled.js +57 -23
- package/dist/cjs/components/agent-builder/AgentBuilder.styled.js.map +1 -1
- 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/components/GoLiveModal.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/MentionEditor.js +1 -1
- package/dist/cjs/components/agent-builder/components/MentionEditor.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/MentionField.js +1 -1
- package/dist/cjs/components/agent-builder/components/MentionField.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/MentionPicker.js +37 -6
- package/dist/cjs/components/agent-builder/components/MentionPicker.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/SelectableListSection.js +1 -1
- package/dist/cjs/components/agent-builder/components/SelectableListSection.js.map +1 -1
- package/dist/cjs/components/agent-builder/constants/charLimits.js +1 -1
- package/dist/cjs/components/agent-builder/constants/charLimits.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/steps/Step2WhenItStepsIn.js +1 -1
- package/dist/cjs/components/agent-builder/steps/Step2WhenItStepsIn.js.map +1 -1
- package/dist/cjs/components/agent-builder/steps/Step3HowItResponds.js +1 -1
- package/dist/cjs/components/agent-builder/steps/Step3HowItResponds.js.map +1 -1
- package/dist/cjs/components/agent-builder/utils/mentionSerialization.js +1 -1
- package/dist/cjs/components/agent-builder/utils/mentionSerialization.js.map +1 -1
- package/dist/cjs/components/agent-builder/utils/sourceIcons.js +2 -0
- package/dist/cjs/components/agent-builder/utils/sourceIcons.js.map +1 -0
- package/dist/cjs/components/agent-listing/AgentListing.js +1 -1
- package/dist/cjs/components/agent-listing/AgentListing.js.map +1 -1
- package/dist/cjs/components/agent-listing/AgentListingFilters.js +1 -1
- package/dist/cjs/components/agent-listing/AgentListingFilters.js.map +1 -1
- package/dist/cjs/editor/BikEditor.types.js.map +1 -1
- package/dist/cjs/editor/extensions/mention/MentionDropdown.js +1 -1
- package/dist/cjs/editor/extensions/mention/MentionDropdown.js.map +1 -1
- package/dist/cjs/editor/extensions/mention/MentionExtension.js +1 -1
- package/dist/cjs/editor/extensions/mention/MentionExtension.js.map +1 -1
- package/dist/esm/assets/icons/Shopify.svg.js +6 -0
- package/dist/esm/assets/icons/Shopify.svg.js.map +1 -0
- package/dist/esm/components/agent-builder/AgentBuilder.js +47 -47
- package/dist/esm/components/agent-builder/AgentBuilder.js.map +1 -1
- package/dist/esm/components/agent-builder/AgentBuilder.model.d.ts +1 -1
- package/dist/esm/components/agent-builder/AgentBuilder.styled.d.ts +6 -0
- package/dist/esm/components/agent-builder/AgentBuilder.styled.js +82 -42
- package/dist/esm/components/agent-builder/AgentBuilder.styled.js.map +1 -1
- package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js +84 -76
- package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
- package/dist/esm/components/agent-builder/components/GoLiveModal.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionEditor.d.ts +6 -0
- package/dist/esm/components/agent-builder/components/MentionEditor.js +31 -30
- package/dist/esm/components/agent-builder/components/MentionEditor.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionField.js +40 -37
- package/dist/esm/components/agent-builder/components/MentionField.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionPicker.d.ts +6 -1
- package/dist/esm/components/agent-builder/components/MentionPicker.js +202 -101
- package/dist/esm/components/agent-builder/components/MentionPicker.js.map +1 -1
- package/dist/esm/components/agent-builder/components/SelectableListSection.d.ts +18 -2
- package/dist/esm/components/agent-builder/components/SelectableListSection.js +159 -91
- package/dist/esm/components/agent-builder/components/SelectableListSection.js.map +1 -1
- package/dist/esm/components/agent-builder/constants/charLimits.d.ts +1 -1
- package/dist/esm/components/agent-builder/constants/charLimits.js +1 -1
- package/dist/esm/components/agent-builder/constants/charLimits.js.map +1 -1
- package/dist/esm/components/agent-builder/context/AgentBuilderContext.d.ts +7 -0
- package/dist/esm/components/agent-builder/context/AgentBuilderContext.js +107 -99
- package/dist/esm/components/agent-builder/context/AgentBuilderContext.js.map +1 -1
- package/dist/esm/components/agent-builder/steps/Step2WhenItStepsIn.js +7 -7
- package/dist/esm/components/agent-builder/steps/Step2WhenItStepsIn.js.map +1 -1
- package/dist/esm/components/agent-builder/steps/Step3HowItResponds.js +131 -106
- package/dist/esm/components/agent-builder/steps/Step3HowItResponds.js.map +1 -1
- package/dist/esm/components/agent-builder/utils/mentionSerialization.js +2 -2
- package/dist/esm/components/agent-builder/utils/mentionSerialization.js.map +1 -1
- package/dist/esm/components/agent-builder/utils/sourceIcons.d.ts +10 -0
- package/dist/esm/components/agent-builder/utils/sourceIcons.js +10 -0
- package/dist/esm/components/agent-builder/utils/sourceIcons.js.map +1 -0
- package/dist/esm/components/agent-listing/AgentListing.js +108 -101
- package/dist/esm/components/agent-listing/AgentListing.js.map +1 -1
- package/dist/esm/components/agent-listing/AgentListing.model.d.ts +8 -0
- package/dist/esm/components/agent-listing/AgentListingFilters.d.ts +2 -0
- package/dist/esm/components/agent-listing/AgentListingFilters.js +37 -33
- package/dist/esm/components/agent-listing/AgentListingFilters.js.map +1 -1
- package/dist/esm/editor/BikEditor.types.d.ts +7 -0
- package/dist/esm/editor/BikEditor.types.js.map +1 -1
- package/dist/esm/editor/extensions/mention/MentionDropdown.d.ts +2 -0
- package/dist/esm/editor/extensions/mention/MentionDropdown.js +21 -20
- package/dist/esm/editor/extensions/mention/MentionDropdown.js.map +1 -1
- package/dist/esm/editor/extensions/mention/MentionExtension.js +66 -55
- package/dist/esm/editor/extensions/mention/MentionExtension.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,193 +1,218 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
import { TitleSmall as
|
|
4
|
-
import { COLORS as
|
|
5
|
-
import { Step3Grid as
|
|
6
|
-
import { CreateSubAgentPanel as
|
|
1
|
+
import { jsxs as c, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import q, { useState as C, useRef as J, useCallback as A, useEffect as Q } from "react";
|
|
3
|
+
import { TitleSmall as w } from "../../TypographyStyle.js";
|
|
4
|
+
import { COLORS as O } from "../../../constants/Theme.js";
|
|
5
|
+
import { Step3Grid as V, Step3Main as X, Step3Side as Y, SideSection as Z } from "../AgentBuilder.styled.js";
|
|
6
|
+
import { CreateSubAgentPanel as ee } from "../components/CreateSubAgentPanel.js";
|
|
7
7
|
import { MentionField as x } from "../components/MentionField.js";
|
|
8
|
-
import { SelectableListSection as
|
|
9
|
-
import { StepSectionHeader as
|
|
10
|
-
import { AGENT_CHAR_LIMITS as
|
|
11
|
-
import { STEP_DEFINITIONS as
|
|
12
|
-
import { useAgentBuilderContext as
|
|
13
|
-
import { appTypeLabel as
|
|
14
|
-
import {
|
|
15
|
-
|
|
8
|
+
import { SelectableListSection as E } from "../components/SelectableListSection.js";
|
|
9
|
+
import { StepSectionHeader as te } from "../components/StepSectionHeader.js";
|
|
10
|
+
import { AGENT_CHAR_LIMITS as R } from "../constants/charLimits.js";
|
|
11
|
+
import { STEP_DEFINITIONS as ne } from "../constants/steps.js";
|
|
12
|
+
import { useAgentBuilderContext as oe } from "../context/AgentBuilderContext.js";
|
|
13
|
+
import { toolSourceLabel as ae, appTypeLabel as le } from "../utils/mentionSerialization.js";
|
|
14
|
+
import { SOURCE_ICONS as L } from "../utils/sourceIcons.js";
|
|
15
|
+
import { Dropdown as se } from "../../dropdown/Dropdown.js";
|
|
16
|
+
const ie = (n) => {
|
|
17
|
+
const a = L[n];
|
|
18
|
+
return a ? q.createElement(a.Icon, { width: a.w, height: a.h }) : void 0;
|
|
19
|
+
}, _ = (n) => ({
|
|
20
|
+
label: n.display_name,
|
|
21
|
+
value: n.tool_id,
|
|
22
|
+
leadingIcon: ie(n.source ?? "manifest")
|
|
23
|
+
}), k = ne[2], Te = () => {
|
|
16
24
|
const {
|
|
17
25
|
value: n,
|
|
18
|
-
patch:
|
|
19
|
-
updateField:
|
|
20
|
-
removeReference:
|
|
21
|
-
availableTools:
|
|
26
|
+
patch: a,
|
|
27
|
+
updateField: M,
|
|
28
|
+
removeReference: I,
|
|
29
|
+
availableTools: u,
|
|
22
30
|
availableSubAgents: N,
|
|
23
|
-
availableModels:
|
|
24
|
-
applicationType:
|
|
25
|
-
insertMention:
|
|
26
|
-
onCreateSubAgent:
|
|
27
|
-
onFetchSubAgent:
|
|
28
|
-
onUpdateSubAgent:
|
|
29
|
-
onImproveSubAgent:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
availableModels: f,
|
|
32
|
+
applicationType: P,
|
|
33
|
+
insertMention: d,
|
|
34
|
+
onCreateSubAgent: i,
|
|
35
|
+
onFetchSubAgent: p,
|
|
36
|
+
onUpdateSubAgent: h,
|
|
37
|
+
onImproveSubAgent: H,
|
|
38
|
+
registerSubAgentCreator: S
|
|
39
|
+
} = oe(), [s, m] = C(null), g = J(0), [G, T] = C([]), b = /* @__PURE__ */ new Map();
|
|
40
|
+
N.forEach((e) => b.set(e.id, e)), G.forEach((e) => b.set(e.id, e));
|
|
41
|
+
const F = Array.from(b.values()), v = A(() => {
|
|
42
|
+
g.current += 1, m({ key: g.current, title: "Create sub-agent" });
|
|
43
|
+
}, []);
|
|
44
|
+
Q(() => {
|
|
45
|
+
if (i)
|
|
46
|
+
return S(v), () => S(null);
|
|
47
|
+
}, [S, v, i]);
|
|
48
|
+
const K = A(
|
|
35
49
|
async (e) => {
|
|
36
|
-
if (!
|
|
50
|
+
if (!p)
|
|
37
51
|
return;
|
|
38
|
-
const t = await
|
|
39
|
-
|
|
40
|
-
key:
|
|
52
|
+
const t = await p(e);
|
|
53
|
+
g.current += 1, m({
|
|
54
|
+
key: g.current,
|
|
41
55
|
title: "Edit sub-agent",
|
|
42
56
|
editingId: e,
|
|
43
57
|
initial: t
|
|
44
58
|
});
|
|
45
59
|
},
|
|
46
|
-
[
|
|
47
|
-
),
|
|
60
|
+
[p]
|
|
61
|
+
), j = A(
|
|
48
62
|
async (e) => {
|
|
49
|
-
if (
|
|
50
|
-
if (
|
|
51
|
-
const t = await
|
|
52
|
-
|
|
53
|
-
...
|
|
63
|
+
if (s?.editingId) {
|
|
64
|
+
if (h) {
|
|
65
|
+
const t = await h(s.editingId, e);
|
|
66
|
+
T((o) => [
|
|
67
|
+
...o.filter((r) => r.id !== t.id),
|
|
54
68
|
t
|
|
55
69
|
]);
|
|
56
70
|
}
|
|
57
|
-
} else if (
|
|
58
|
-
const t = await
|
|
59
|
-
|
|
71
|
+
} else if (i) {
|
|
72
|
+
const t = await i(e);
|
|
73
|
+
T((o) => [...o, t]), a({ subagents: [...n.subagents, t.id] }), d("subagent", t.id, `sub-agent: ${t.name}`);
|
|
60
74
|
}
|
|
61
|
-
|
|
75
|
+
m(null);
|
|
62
76
|
},
|
|
63
77
|
[
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
d,
|
|
78
|
+
s,
|
|
79
|
+
h,
|
|
67
80
|
i,
|
|
81
|
+
a,
|
|
68
82
|
n.subagents,
|
|
69
|
-
|
|
83
|
+
d
|
|
70
84
|
]
|
|
71
|
-
),
|
|
72
|
-
const t =
|
|
73
|
-
return t ? {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
})),
|
|
79
|
-
const t =
|
|
85
|
+
), B = n.tools.map((e) => {
|
|
86
|
+
const t = u.find((o) => o.tool_id === e);
|
|
87
|
+
return t ? {
|
|
88
|
+
id: e,
|
|
89
|
+
label: t.display_name,
|
|
90
|
+
icon: L[t.source ?? "manifest"]
|
|
91
|
+
} : null;
|
|
92
|
+
}).filter((e) => e !== null), D = u.map(_), U = (() => {
|
|
93
|
+
const e = [], t = /* @__PURE__ */ new Map();
|
|
94
|
+
return u.forEach((o) => {
|
|
95
|
+
const r = o.source ?? "manifest";
|
|
96
|
+
t.has(r) || (t.set(r, []), e.push(r)), t.get(r)?.push(_(o));
|
|
97
|
+
}), e.map((o) => ({
|
|
98
|
+
source: o,
|
|
99
|
+
label: ae(o),
|
|
100
|
+
options: t.get(o) ?? []
|
|
101
|
+
}));
|
|
102
|
+
})(), z = n.subagents.map((e) => {
|
|
103
|
+
const t = b.get(e);
|
|
80
104
|
return t ? { id: e, label: t.name } : null;
|
|
81
|
-
}).filter((e) => e !== null),
|
|
105
|
+
}).filter((e) => e !== null), W = F.map((e) => ({
|
|
82
106
|
label: e.name,
|
|
83
107
|
value: e.id
|
|
84
|
-
})),
|
|
108
|
+
})), $ = f.map((e) => ({
|
|
85
109
|
label: e.label,
|
|
86
110
|
value: e.value,
|
|
87
111
|
selected: e.value === n.model
|
|
88
|
-
})),
|
|
89
|
-
return /* @__PURE__ */
|
|
90
|
-
/* @__PURE__ */
|
|
91
|
-
/* @__PURE__ */
|
|
92
|
-
/* @__PURE__ */
|
|
93
|
-
/* @__PURE__ */
|
|
112
|
+
})), y = f.find((e) => e.value === n.model);
|
|
113
|
+
return /* @__PURE__ */ c("div", { className: "bik-agent-step bik-agent-step--response", children: [
|
|
114
|
+
/* @__PURE__ */ l(te, { title: k.title, helper: k.helper }),
|
|
115
|
+
/* @__PURE__ */ c(V, { children: [
|
|
116
|
+
/* @__PURE__ */ c(X, { children: [
|
|
117
|
+
/* @__PURE__ */ l(
|
|
94
118
|
x,
|
|
95
119
|
{
|
|
96
120
|
fieldKey: "instructions",
|
|
97
121
|
"data-test": "agent-instructions",
|
|
98
122
|
label: "Instructions",
|
|
99
|
-
maxLength:
|
|
123
|
+
maxLength: R.instructions,
|
|
100
124
|
placeholder: "Write what this agent should do. Type @ to reference a tool or sub-agent.",
|
|
101
125
|
minHeight: "200px"
|
|
102
126
|
}
|
|
103
127
|
),
|
|
104
|
-
/* @__PURE__ */
|
|
128
|
+
/* @__PURE__ */ l(
|
|
105
129
|
x,
|
|
106
130
|
{
|
|
107
131
|
fieldKey: "guardrail",
|
|
108
132
|
"data-test": "agent-guardrail",
|
|
109
133
|
label: "Guardrails",
|
|
110
|
-
maxLength:
|
|
134
|
+
maxLength: R.guardrail,
|
|
111
135
|
placeholder: "Things this agent must never do. Type @ to reference a tool or sub-agent.",
|
|
112
136
|
minHeight: "140px"
|
|
113
137
|
}
|
|
114
138
|
)
|
|
115
139
|
] }),
|
|
116
|
-
/* @__PURE__ */
|
|
117
|
-
/* @__PURE__ */
|
|
118
|
-
|
|
140
|
+
/* @__PURE__ */ c(Y, { children: [
|
|
141
|
+
/* @__PURE__ */ l(
|
|
142
|
+
E,
|
|
119
143
|
{
|
|
120
144
|
title: "Tools",
|
|
121
145
|
helper: "Actions this agent can take while responding.",
|
|
122
146
|
dataTestPrefix: "agent-tools",
|
|
123
|
-
items:
|
|
124
|
-
addableOptions:
|
|
147
|
+
items: B,
|
|
148
|
+
addableOptions: D,
|
|
149
|
+
sourceGroups: U,
|
|
125
150
|
emptyText: "No tools added yet.",
|
|
126
151
|
onAdd: (e) => {
|
|
127
|
-
|
|
152
|
+
d("tool", e), n.tools.includes(e) || a({ tools: [...n.tools, e] });
|
|
128
153
|
},
|
|
129
|
-
onRemove: (e) =>
|
|
154
|
+
onRemove: (e) => I("tool", e)
|
|
130
155
|
}
|
|
131
156
|
),
|
|
132
|
-
/* @__PURE__ */
|
|
133
|
-
|
|
157
|
+
/* @__PURE__ */ l(
|
|
158
|
+
E,
|
|
134
159
|
{
|
|
135
160
|
title: "Sub-agents",
|
|
136
161
|
helper: "Other agents this agent can hand off the conversation to.",
|
|
137
162
|
dataTestPrefix: "agent-subagents",
|
|
138
|
-
items:
|
|
139
|
-
addableOptions:
|
|
163
|
+
items: z,
|
|
164
|
+
addableOptions: W,
|
|
140
165
|
emptyText: "No sub-agents added yet.",
|
|
141
166
|
onAdd: (e) => {
|
|
142
|
-
|
|
167
|
+
d("subagent", e), n.subagents.includes(e) || a({ subagents: [...n.subagents, e] });
|
|
143
168
|
},
|
|
144
|
-
onRemove: (e) =>
|
|
145
|
-
onConfigure:
|
|
146
|
-
createOption:
|
|
169
|
+
onRemove: (e) => I("subagent", e),
|
|
170
|
+
onConfigure: p ? K : void 0,
|
|
171
|
+
createOption: i ? { label: "Create new", onSelect: v } : void 0
|
|
147
172
|
}
|
|
148
173
|
),
|
|
149
|
-
|
|
150
|
-
/* @__PURE__ */
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
-
|
|
174
|
+
f.length > 0 && /* @__PURE__ */ c(Z, { children: [
|
|
175
|
+
/* @__PURE__ */ l(w, { color: O.content.primary, children: "Advanced settings" }),
|
|
176
|
+
/* @__PURE__ */ l(w, { color: O.content.secondary, children: "Select AI model" }),
|
|
177
|
+
/* @__PURE__ */ l(
|
|
178
|
+
se,
|
|
154
179
|
{
|
|
155
180
|
"data-test": "agent-model",
|
|
156
181
|
size: "small",
|
|
157
182
|
width: "100%",
|
|
158
183
|
placeHolder: "Select model",
|
|
159
|
-
options:
|
|
160
|
-
defaultOptions:
|
|
184
|
+
options: $,
|
|
185
|
+
defaultOptions: y ? [
|
|
161
186
|
{
|
|
162
|
-
label:
|
|
163
|
-
value:
|
|
187
|
+
label: y.label,
|
|
188
|
+
value: y.value
|
|
164
189
|
}
|
|
165
190
|
] : void 0,
|
|
166
191
|
onSelect: (e) => {
|
|
167
|
-
const
|
|
168
|
-
|
|
192
|
+
const o = (Array.isArray(e) ? e[0] : e)?.value;
|
|
193
|
+
o && M("model", o);
|
|
169
194
|
}
|
|
170
195
|
}
|
|
171
196
|
)
|
|
172
197
|
] })
|
|
173
198
|
] })
|
|
174
199
|
] }),
|
|
175
|
-
|
|
176
|
-
|
|
200
|
+
s && /* @__PURE__ */ l(
|
|
201
|
+
ee,
|
|
177
202
|
{
|
|
178
|
-
title:
|
|
179
|
-
initial:
|
|
180
|
-
availableTools:
|
|
181
|
-
appLabel:
|
|
182
|
-
onImprove:
|
|
183
|
-
onClose: () =>
|
|
184
|
-
onSave:
|
|
203
|
+
title: s.title,
|
|
204
|
+
initial: s.initial,
|
|
205
|
+
availableTools: u,
|
|
206
|
+
appLabel: le(P),
|
|
207
|
+
onImprove: H,
|
|
208
|
+
onClose: () => m(null),
|
|
209
|
+
onSave: j
|
|
185
210
|
},
|
|
186
|
-
|
|
211
|
+
s.key
|
|
187
212
|
)
|
|
188
213
|
] });
|
|
189
214
|
};
|
|
190
215
|
export {
|
|
191
|
-
|
|
216
|
+
Te as Step3HowItResponds
|
|
192
217
|
};
|
|
193
218
|
//# sourceMappingURL=Step3HowItResponds.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Step3HowItResponds.js","sources":["../../../../../src/components/agent-builder/steps/Step3HowItResponds.tsx"],"sourcesContent":["import React, { useCallback, useRef, useState } from 'react';\nimport { Dropdown } from '@src/components/dropdown';\nimport { SingleOption } from '@src/components/dropdown/type';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport { SubAgentDraft, SubAgentRef } from '../AgentBuilder.model';\nimport {\n\tSideSection,\n\tStep3Grid,\n\tStep3Main,\n\tStep3Side,\n} from '../AgentBuilder.styled';\nimport { CreateSubAgentPanel } from '../components/CreateSubAgentPanel';\nimport { MentionField } from '../components/MentionField';\nimport {\n\tSelectableItem,\n\tSelectableListSection,\n} from '../components/SelectableListSection';\nimport { StepSectionHeader } from '../components/StepSectionHeader';\nimport { AGENT_CHAR_LIMITS } from '../constants/charLimits';\nimport { STEP_DEFINITIONS } from '../constants/steps';\nimport { useAgentBuilderContext } from '../context/AgentBuilderContext';\nimport { appTypeLabel } from '../utils/mentionSerialization';\n\nconst STEP = STEP_DEFINITIONS[2];\n\n/** Drawer state — null when closed; `key` remounts it fresh per open. */\ninterface SubAgentPanelState {\n\tkey: number;\n\ttitle: string;\n\teditingId?: string;\n\tinitial?: SubAgentDraft;\n}\n\nexport const Step3HowItResponds: React.FC = () => {\n\tconst {\n\t\tvalue,\n\t\tpatch,\n\t\tupdateField,\n\t\tremoveReference,\n\t\tavailableTools,\n\t\tavailableSubAgents,\n\t\tavailableModels,\n\t\tapplicationType,\n\t\tinsertMention,\n\t\tonCreateSubAgent,\n\t\tonFetchSubAgent,\n\t\tonUpdateSubAgent,\n\t\tonImproveSubAgent,\n\t} = useAgentBuilderContext();\n\n\tconst [panel, setPanel] = useState<SubAgentPanelState | null>(null);\n\tconst panelKeyRef = useRef(0);\n\t// Sub-agents created / edited in this session, so a chip resolves (and reflects\n\t// a renamed sub-agent) before the consumer refreshes `availableSubAgents`.\n\tconst [createdSubAgents, setCreatedSubAgents] = useState<SubAgentRef[]>([]);\n\t// Created/edited refs take precedence over the consumer-supplied list.\n\tconst subAgentById = new Map<string, SubAgentRef>();\n\tavailableSubAgents.forEach((s) => subAgentById.set(s.id, s));\n\tcreatedSubAgents.forEach((s) => subAgentById.set(s.id, s));\n\tconst knownSubAgents = Array.from(subAgentById.values());\n\n\tconst openCreate = useCallback(() => {\n\t\tpanelKeyRef.current += 1;\n\t\tsetPanel({ key: panelKeyRef.current, title: 'Create sub-agent' });\n\t}, []);\n\n\tconst openConfigure = useCallback(\n\t\tasync (id: string) => {\n\t\t\tif (!onFetchSubAgent) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst data = await onFetchSubAgent(id);\n\t\t\tpanelKeyRef.current += 1;\n\t\t\tsetPanel({\n\t\t\t\tkey: panelKeyRef.current,\n\t\t\t\ttitle: 'Edit sub-agent',\n\t\t\t\teditingId: id,\n\t\t\t\tinitial: data,\n\t\t\t});\n\t\t},\n\t\t[onFetchSubAgent],\n\t);\n\n\tconst handlePanelSave = useCallback(\n\t\tasync (draft: SubAgentDraft) => {\n\t\t\tif (panel?.editingId) {\n\t\t\t\tif (onUpdateSubAgent) {\n\t\t\t\t\tconst ref = await onUpdateSubAgent(panel.editingId, draft);\n\t\t\t\t\tsetCreatedSubAgents((prev) => [\n\t\t\t\t\t\t...prev.filter((s) => s.id !== ref.id),\n\t\t\t\t\t\tref,\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t} else if (onCreateSubAgent) {\n\t\t\t\tconst ref = await onCreateSubAgent(draft);\n\t\t\t\tsetCreatedSubAgents((prev) => [...prev, ref]);\n\t\t\t\tpatch({ subagents: [...value.subagents, ref.id] });\n\t\t\t\tinsertMention('subagent', ref.id, `sub-agent: ${ref.name}`);\n\t\t\t}\n\t\t\tsetPanel(null);\n\t\t},\n\t\t[\n\t\t\tpanel,\n\t\t\tonUpdateSubAgent,\n\t\t\tonCreateSubAgent,\n\t\t\tpatch,\n\t\t\tvalue.subagents,\n\t\t\tinsertMention,\n\t\t],\n\t);\n\n\tconst toolItems: SelectableItem[] = value.tools\n\t\t.map((id): SelectableItem | null => {\n\t\t\tconst tool = availableTools.find((t) => t.tool_id === id);\n\t\t\treturn tool ? { id, label: tool.displayName } : null;\n\t\t})\n\t\t.filter((x): x is SelectableItem => x !== null);\n\n\t// All tools are offered (even already-added ones) so a tool can be referenced\n\t// again in the text; the chip list below still shows each only once.\n\tconst toolOptions: SingleOption[] = availableTools.map((t) => ({\n\t\tlabel: t.displayName,\n\t\tvalue: t.tool_id,\n\t\tsubText: t.description,\n\t}));\n\n\tconst subAgentItems: SelectableItem[] = value.subagents\n\t\t.map((id): SelectableItem | null => {\n\t\t\tconst sub = subAgentById.get(id);\n\t\t\treturn sub ? { id, label: sub.name } : null;\n\t\t})\n\t\t.filter((x): x is SelectableItem => x !== null);\n\n\tconst subAgentOptions: SingleOption[] = knownSubAgents.map((s) => ({\n\t\tlabel: s.name,\n\t\tvalue: s.id,\n\t}));\n\n\tconst modelOptions: SingleOption[] = availableModels.map((m) => ({\n\t\tlabel: m.label,\n\t\tvalue: m.value,\n\t\tselected: m.value === value.model,\n\t}));\n\tconst selectedModel = availableModels.find((m) => m.value === value.model);\n\n\treturn (\n\t\t<div className=\"bik-agent-step bik-agent-step--response\">\n\t\t\t<StepSectionHeader title={STEP.title} helper={STEP.helper} />\n\n\t\t\t<Step3Grid>\n\t\t\t\t<Step3Main>\n\t\t\t\t\t<MentionField\n\t\t\t\t\t\tfieldKey=\"instructions\"\n\t\t\t\t\t\tdata-test=\"agent-instructions\"\n\t\t\t\t\t\tlabel=\"Instructions\"\n\t\t\t\t\t\tmaxLength={AGENT_CHAR_LIMITS.instructions}\n\t\t\t\t\t\tplaceholder=\"Write what this agent should do. Type @ to reference a tool or sub-agent.\"\n\t\t\t\t\t\tminHeight=\"200px\"\n\t\t\t\t\t/>\n\n\t\t\t\t\t<MentionField\n\t\t\t\t\t\tfieldKey=\"guardrail\"\n\t\t\t\t\t\tdata-test=\"agent-guardrail\"\n\t\t\t\t\t\tlabel=\"Guardrails\"\n\t\t\t\t\t\tmaxLength={AGENT_CHAR_LIMITS.guardrail}\n\t\t\t\t\t\tplaceholder=\"Things this agent must never do. Type @ to reference a tool or sub-agent.\"\n\t\t\t\t\t\tminHeight=\"140px\"\n\t\t\t\t\t/>\n\t\t\t\t</Step3Main>\n\n\t\t\t\t<Step3Side>\n\t\t\t\t\t<SelectableListSection\n\t\t\t\t\t\ttitle=\"Tools\"\n\t\t\t\t\t\thelper=\"Actions this agent can take while responding.\"\n\t\t\t\t\t\tdataTestPrefix=\"agent-tools\"\n\t\t\t\t\t\titems={toolItems}\n\t\t\t\t\t\taddableOptions={toolOptions}\n\t\t\t\t\t\temptyText=\"No tools added yet.\"\n\t\t\t\t\t\tonAdd={(id) => {\n\t\t\t\t\t\t\t// Always drop a chip at the cursor; keep the list deduped.\n\t\t\t\t\t\t\tinsertMention('tool', id);\n\t\t\t\t\t\t\tif (!value.tools.includes(id)) {\n\t\t\t\t\t\t\t\tpatch({ tools: [...value.tools, id] });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonRemove={(id) => removeReference('tool', id)}\n\t\t\t\t\t/>\n\n\t\t\t\t\t<SelectableListSection\n\t\t\t\t\t\ttitle=\"Sub-agents\"\n\t\t\t\t\t\thelper=\"Other agents this agent can hand off the conversation to.\"\n\t\t\t\t\t\tdataTestPrefix=\"agent-subagents\"\n\t\t\t\t\t\titems={subAgentItems}\n\t\t\t\t\t\taddableOptions={subAgentOptions}\n\t\t\t\t\t\temptyText=\"No sub-agents added yet.\"\n\t\t\t\t\t\tonAdd={(id) => {\n\t\t\t\t\t\t\tinsertMention('subagent', id);\n\t\t\t\t\t\t\tif (!value.subagents.includes(id)) {\n\t\t\t\t\t\t\t\tpatch({ subagents: [...value.subagents, id] });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonRemove={(id) => removeReference('subagent', id)}\n\t\t\t\t\t\tonConfigure={onFetchSubAgent ? openConfigure : undefined}\n\t\t\t\t\t\tcreateOption={\n\t\t\t\t\t\t\tonCreateSubAgent\n\t\t\t\t\t\t\t\t? { label: 'Create new', onSelect: openCreate }\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\n\t\t\t\t\t{availableModels.length > 0 && (\n\t\t\t\t\t\t<SideSection>\n\t\t\t\t\t\t\t<TitleSmall color={COLORS.content.primary}>\n\t\t\t\t\t\t\t\tAdvanced settings\n\t\t\t\t\t\t\t</TitleSmall>\n\t\t\t\t\t\t\t<TitleSmall color={COLORS.content.secondary}>\n\t\t\t\t\t\t\t\tSelect AI model\n\t\t\t\t\t\t\t</TitleSmall>\n\t\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\t\tdata-test=\"agent-model\"\n\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\twidth=\"100%\"\n\t\t\t\t\t\t\t\tplaceHolder=\"Select model\"\n\t\t\t\t\t\t\t\toptions={modelOptions}\n\t\t\t\t\t\t\t\tdefaultOptions={\n\t\t\t\t\t\t\t\t\tselectedModel\n\t\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlabel: selectedModel.label,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: selectedModel.value,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelect={(opt) => {\n\t\t\t\t\t\t\t\t\tconst single = Array.isArray(opt) ? opt[0] : opt;\n\t\t\t\t\t\t\t\t\tconst v = (single as SingleOption)?.value;\n\t\t\t\t\t\t\t\t\tif (v) {\n\t\t\t\t\t\t\t\t\t\tupdateField('model', v);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</SideSection>\n\t\t\t\t\t)}\n\t\t\t\t</Step3Side>\n\t\t\t</Step3Grid>\n\n\t\t\t{panel && (\n\t\t\t\t<CreateSubAgentPanel\n\t\t\t\t\tkey={panel.key}\n\t\t\t\t\ttitle={panel.title}\n\t\t\t\t\tinitial={panel.initial}\n\t\t\t\t\tavailableTools={availableTools}\n\t\t\t\t\tappLabel={appTypeLabel(applicationType)}\n\t\t\t\t\tonImprove={onImproveSubAgent}\n\t\t\t\t\tonClose={() => setPanel(null)}\n\t\t\t\t\tonSave={handlePanelSave}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n"],"names":["STEP","STEP_DEFINITIONS","Step3HowItResponds","value","patch","updateField","removeReference","availableTools","availableSubAgents","availableModels","applicationType","insertMention","onCreateSubAgent","onFetchSubAgent","onUpdateSubAgent","onImproveSubAgent","useAgentBuilderContext","panel","setPanel","useState","panelKeyRef","useRef","createdSubAgents","setCreatedSubAgents","subAgentById","s","knownSubAgents","openCreate","useCallback","openConfigure","id","data","handlePanelSave","draft","ref","prev","toolItems","tool","t","x","toolOptions","subAgentItems","sub","subAgentOptions","modelOptions","m","selectedModel","jsxs","jsx","StepSectionHeader","Step3Grid","Step3Main","MentionField","AGENT_CHAR_LIMITS","Step3Side","SelectableListSection","SideSection","TitleSmall","COLORS","Dropdown","opt","v","CreateSubAgentPanel","appTypeLabel"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAMA,IAAOC,EAAiB,CAAC,GAUlBC,KAA+B,MAAM;AACjD,QAAM;AAAA,IACL,OAAAC;AAAA,IACA,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,mBAAAC;AAAA,EAAA,IACGC,EAAA,GAEE,CAACC,GAAOC,CAAQ,IAAIC,EAAoC,IAAI,GAC5DC,IAAcC,EAAO,CAAC,GAGtB,CAACC,GAAkBC,CAAmB,IAAIJ,EAAwB,CAAA,CAAE,GAEpEK,wBAAmB,IAAA;AACzB,EAAAhB,EAAmB,QAAQ,CAACiB,MAAMD,EAAa,IAAIC,EAAE,IAAIA,CAAC,CAAC,GAC3DH,EAAiB,QAAQ,CAACG,MAAMD,EAAa,IAAIC,EAAE,IAAIA,CAAC,CAAC;AACzD,QAAMC,IAAiB,MAAM,KAAKF,EAAa,QAAQ,GAEjDG,IAAaC,EAAY,MAAM;AACpC,IAAAR,EAAY,WAAW,GACvBF,EAAS,EAAE,KAAKE,EAAY,SAAS,OAAO,oBAAoB;AAAA,EACjE,GAAG,CA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;AAAA,YAAA;AAAA,cACA,aAAU;AAAA,cACV,MAAK;AAAA,cACL,OAAM;AAAA,cACN,aAAY;AAAA,cACZ,SAASf;AAAA,cACT,gBACCE,IACG;AAAA,gBACA;AAAA,kBACC,OAAOA,EAAc;AAAA,kBACrB,OAAOA,EAAc;AAAA,gBAAA;AAAA,cACtB,IAEA;AAAA,cAEJ,UAAU,CAACc,MAAQ;AAElB,sBAAMC,KADS,MAAM,QAAQD,CAAG,IAAIA,EAAI,CAAC,IAAIA,IACT;AACpC,gBAAIC,KACHxD,EAAY,SAASwD,CAAC;AAAA,cAExB;AAAA,YAAA;AAAA,UAAA;AAAA,QACD,EAAA,CACD;AAAA,MAAA,EAAA,CAEF;AAAA,IAAA,GACD;AAAA,IAEC5C,KACA,gBAAA+B;AAAA,MAACc;AAAA,MAAA;AAAA,QAEA,OAAO7C,EAAM;AAAA,QACb,SAASA,EAAM;AAAA,QACf,gBAAAV;AAAA,QACA,UAAUwD,EAAarD,CAAe;AAAA,QACtC,WAAWK;AAAA,QACX,SAAS,MAAMG,EAAS,IAAI;AAAA,QAC5B,QAAQc;AAAA,MAAA;AAAA,MAPHf,EAAM;AAAA,IAAA;AAAA,EAQZ,GAEF;AAEF;"}
|
|
1
|
+
{"version":3,"file":"Step3HowItResponds.js","sources":["../../../../../src/components/agent-builder/steps/Step3HowItResponds.tsx"],"sourcesContent":["import React, { useCallback, useEffect, useRef, useState } from 'react';\nimport { Dropdown } from '@src/components/dropdown';\nimport { SingleOption } from '@src/components/dropdown/type';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport { AgentTool, SubAgentDraft, SubAgentRef } from '../AgentBuilder.model';\nimport {\n\tSideSection,\n\tStep3Grid,\n\tStep3Main,\n\tStep3Side,\n} from '../AgentBuilder.styled';\nimport { CreateSubAgentPanel } from '../components/CreateSubAgentPanel';\nimport { MentionField } from '../components/MentionField';\nimport {\n\tSelectableItem,\n\tSelectableListSection,\n\tSourceGroup,\n} from '../components/SelectableListSection';\nimport { StepSectionHeader } from '../components/StepSectionHeader';\nimport { AGENT_CHAR_LIMITS } from '../constants/charLimits';\nimport { STEP_DEFINITIONS } from '../constants/steps';\nimport { useAgentBuilderContext } from '../context/AgentBuilderContext';\nimport { appTypeLabel, toolSourceLabel } from '../utils/mentionSerialization';\nimport { SOURCE_ICONS } from '../utils/sourceIcons';\n\n/** Source brand glyph for a tool, as a dropdown leadingIcon element. */\nconst toolIconEl = (source: string): JSX.Element | undefined => {\n\tconst ic = SOURCE_ICONS[source];\n\treturn ic\n\t\t? React.createElement(ic.Icon, { width: ic.w, height: ic.h })\n\t\t: undefined;\n};\n\n/** Dropdown option for a tool: icon left of the name, no description. */\nconst toolOption = (t: AgentTool): SingleOption => ({\n\tlabel: t.display_name,\n\tvalue: t.tool_id,\n\tleadingIcon: toolIconEl(t.source ?? 'manifest'),\n});\n\nconst STEP = STEP_DEFINITIONS[2];\n\n/** Drawer state — null when closed; `key` remounts it fresh per open. */\ninterface SubAgentPanelState {\n\tkey: number;\n\ttitle: string;\n\teditingId?: string;\n\tinitial?: SubAgentDraft;\n}\n\nexport const Step3HowItResponds: React.FC = () => {\n\tconst {\n\t\tvalue,\n\t\tpatch,\n\t\tupdateField,\n\t\tremoveReference,\n\t\tavailableTools,\n\t\tavailableSubAgents,\n\t\tavailableModels,\n\t\tapplicationType,\n\t\tinsertMention,\n\t\tonCreateSubAgent,\n\t\tonFetchSubAgent,\n\t\tonUpdateSubAgent,\n\t\tonImproveSubAgent,\n\t\tregisterSubAgentCreator,\n\t} = useAgentBuilderContext();\n\n\tconst [panel, setPanel] = useState<SubAgentPanelState | null>(null);\n\tconst panelKeyRef = useRef(0);\n\t// Sub-agents created / edited in this session, so a chip resolves (and reflects\n\t// a renamed sub-agent) before the consumer refreshes `availableSubAgents`.\n\tconst [createdSubAgents, setCreatedSubAgents] = useState<SubAgentRef[]>([]);\n\t// Created/edited refs take precedence over the consumer-supplied list.\n\tconst subAgentById = new Map<string, SubAgentRef>();\n\tavailableSubAgents.forEach((s) => subAgentById.set(s.id, s));\n\tcreatedSubAgents.forEach((s) => subAgentById.set(s.id, s));\n\tconst knownSubAgents = Array.from(subAgentById.values());\n\n\tconst openCreate = useCallback(() => {\n\t\tpanelKeyRef.current += 1;\n\t\tsetPanel({ key: panelKeyRef.current, title: 'Create sub-agent' });\n\t}, []);\n\n\t// Let the `@` picker's \"Create new\" row open this step's drawer.\n\tuseEffect(() => {\n\t\tif (!onCreateSubAgent) {\n\t\t\treturn;\n\t\t}\n\t\tregisterSubAgentCreator(openCreate);\n\t\treturn () => registerSubAgentCreator(null);\n\t}, [registerSubAgentCreator, openCreate, onCreateSubAgent]);\n\n\tconst openConfigure = useCallback(\n\t\tasync (id: string) => {\n\t\t\tif (!onFetchSubAgent) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst data = await onFetchSubAgent(id);\n\t\t\tpanelKeyRef.current += 1;\n\t\t\tsetPanel({\n\t\t\t\tkey: panelKeyRef.current,\n\t\t\t\ttitle: 'Edit sub-agent',\n\t\t\t\teditingId: id,\n\t\t\t\tinitial: data,\n\t\t\t});\n\t\t},\n\t\t[onFetchSubAgent],\n\t);\n\n\tconst handlePanelSave = useCallback(\n\t\tasync (draft: SubAgentDraft) => {\n\t\t\tif (panel?.editingId) {\n\t\t\t\tif (onUpdateSubAgent) {\n\t\t\t\t\tconst ref = await onUpdateSubAgent(panel.editingId, draft);\n\t\t\t\t\tsetCreatedSubAgents((prev) => [\n\t\t\t\t\t\t...prev.filter((s) => s.id !== ref.id),\n\t\t\t\t\t\tref,\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t} else if (onCreateSubAgent) {\n\t\t\t\tconst ref = await onCreateSubAgent(draft);\n\t\t\t\tsetCreatedSubAgents((prev) => [...prev, ref]);\n\t\t\t\tpatch({ subagents: [...value.subagents, ref.id] });\n\t\t\t\tinsertMention('subagent', ref.id, `sub-agent: ${ref.name}`);\n\t\t\t}\n\t\t\tsetPanel(null);\n\t\t},\n\t\t[\n\t\t\tpanel,\n\t\t\tonUpdateSubAgent,\n\t\t\tonCreateSubAgent,\n\t\t\tpatch,\n\t\t\tvalue.subagents,\n\t\t\tinsertMention,\n\t\t],\n\t);\n\n\tconst toolItems: SelectableItem[] = value.tools\n\t\t.map((id): SelectableItem | null => {\n\t\t\tconst tool = availableTools.find((t) => t.tool_id === id);\n\t\t\treturn tool\n\t\t\t\t? {\n\t\t\t\t\t\tid,\n\t\t\t\t\t\tlabel: tool.display_name,\n\t\t\t\t\t\ticon: SOURCE_ICONS[tool.source ?? 'manifest'],\n\t\t\t\t }\n\t\t\t\t: null;\n\t\t})\n\t\t.filter((x): x is SelectableItem => x !== null);\n\n\t// All tools are offered (even already-added ones) so a tool can be referenced\n\t// again in the text; the chip list below still shows each only once.\n\tconst toolOptions: SingleOption[] = availableTools.map(toolOption);\n\n\t// Group tools by source (Manifest / Shopify / …) for the empty-state buttons.\n\tconst toolSourceGroups: SourceGroup[] = (() => {\n\t\tconst order: string[] = [];\n\t\tconst bySource = new Map<string, SingleOption[]>();\n\t\tavailableTools.forEach((t) => {\n\t\t\tconst src = t.source ?? 'manifest';\n\t\t\tif (!bySource.has(src)) {\n\t\t\t\tbySource.set(src, []);\n\t\t\t\torder.push(src);\n\t\t\t}\n\t\t\tbySource.get(src)?.push(toolOption(t));\n\t\t});\n\t\treturn order.map((src) => ({\n\t\t\tsource: src,\n\t\t\tlabel: toolSourceLabel(src),\n\t\t\toptions: bySource.get(src) ?? [],\n\t\t}));\n\t})();\n\n\tconst subAgentItems: SelectableItem[] = value.subagents\n\t\t.map((id): SelectableItem | null => {\n\t\t\tconst sub = subAgentById.get(id);\n\t\t\treturn sub ? { id, label: sub.name } : null;\n\t\t})\n\t\t.filter((x): x is SelectableItem => x !== null);\n\n\tconst subAgentOptions: SingleOption[] = knownSubAgents.map((s) => ({\n\t\tlabel: s.name,\n\t\tvalue: s.id,\n\t}));\n\n\tconst modelOptions: SingleOption[] = availableModels.map((m) => ({\n\t\tlabel: m.label,\n\t\tvalue: m.value,\n\t\tselected: m.value === value.model,\n\t}));\n\tconst selectedModel = availableModels.find((m) => m.value === value.model);\n\n\treturn (\n\t\t<div className=\"bik-agent-step bik-agent-step--response\">\n\t\t\t<StepSectionHeader title={STEP.title} helper={STEP.helper} />\n\n\t\t\t<Step3Grid>\n\t\t\t\t<Step3Main>\n\t\t\t\t\t<MentionField\n\t\t\t\t\t\tfieldKey=\"instructions\"\n\t\t\t\t\t\tdata-test=\"agent-instructions\"\n\t\t\t\t\t\tlabel=\"Instructions\"\n\t\t\t\t\t\tmaxLength={AGENT_CHAR_LIMITS.instructions}\n\t\t\t\t\t\tplaceholder=\"Write what this agent should do. Type @ to reference a tool or sub-agent.\"\n\t\t\t\t\t\tminHeight=\"200px\"\n\t\t\t\t\t/>\n\n\t\t\t\t\t<MentionField\n\t\t\t\t\t\tfieldKey=\"guardrail\"\n\t\t\t\t\t\tdata-test=\"agent-guardrail\"\n\t\t\t\t\t\tlabel=\"Guardrails\"\n\t\t\t\t\t\tmaxLength={AGENT_CHAR_LIMITS.guardrail}\n\t\t\t\t\t\tplaceholder=\"Things this agent must never do. Type @ to reference a tool or sub-agent.\"\n\t\t\t\t\t\tminHeight=\"140px\"\n\t\t\t\t\t/>\n\t\t\t\t</Step3Main>\n\n\t\t\t\t<Step3Side>\n\t\t\t\t\t<SelectableListSection\n\t\t\t\t\t\ttitle=\"Tools\"\n\t\t\t\t\t\thelper=\"Actions this agent can take while responding.\"\n\t\t\t\t\t\tdataTestPrefix=\"agent-tools\"\n\t\t\t\t\t\titems={toolItems}\n\t\t\t\t\t\taddableOptions={toolOptions}\n\t\t\t\t\t\tsourceGroups={toolSourceGroups}\n\t\t\t\t\t\temptyText=\"No tools added yet.\"\n\t\t\t\t\t\tonAdd={(id) => {\n\t\t\t\t\t\t\t// Always drop a chip at the cursor; keep the list deduped.\n\t\t\t\t\t\t\tinsertMention('tool', id);\n\t\t\t\t\t\t\tif (!value.tools.includes(id)) {\n\t\t\t\t\t\t\t\tpatch({ tools: [...value.tools, id] });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonRemove={(id) => removeReference('tool', id)}\n\t\t\t\t\t/>\n\n\t\t\t\t\t<SelectableListSection\n\t\t\t\t\t\ttitle=\"Sub-agents\"\n\t\t\t\t\t\thelper=\"Other agents this agent can hand off the conversation to.\"\n\t\t\t\t\t\tdataTestPrefix=\"agent-subagents\"\n\t\t\t\t\t\titems={subAgentItems}\n\t\t\t\t\t\taddableOptions={subAgentOptions}\n\t\t\t\t\t\temptyText=\"No sub-agents added yet.\"\n\t\t\t\t\t\tonAdd={(id) => {\n\t\t\t\t\t\t\tinsertMention('subagent', id);\n\t\t\t\t\t\t\tif (!value.subagents.includes(id)) {\n\t\t\t\t\t\t\t\tpatch({ subagents: [...value.subagents, id] });\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonRemove={(id) => removeReference('subagent', id)}\n\t\t\t\t\t\tonConfigure={onFetchSubAgent ? openConfigure : undefined}\n\t\t\t\t\t\tcreateOption={\n\t\t\t\t\t\t\tonCreateSubAgent\n\t\t\t\t\t\t\t\t? { label: 'Create new', onSelect: openCreate }\n\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\n\t\t\t\t\t{availableModels.length > 0 && (\n\t\t\t\t\t\t<SideSection>\n\t\t\t\t\t\t\t<TitleSmall color={COLORS.content.primary}>\n\t\t\t\t\t\t\t\tAdvanced settings\n\t\t\t\t\t\t\t</TitleSmall>\n\t\t\t\t\t\t\t<TitleSmall color={COLORS.content.secondary}>\n\t\t\t\t\t\t\t\tSelect AI model\n\t\t\t\t\t\t\t</TitleSmall>\n\t\t\t\t\t\t\t<Dropdown\n\t\t\t\t\t\t\t\tdata-test=\"agent-model\"\n\t\t\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\t\t\twidth=\"100%\"\n\t\t\t\t\t\t\t\tplaceHolder=\"Select model\"\n\t\t\t\t\t\t\t\toptions={modelOptions}\n\t\t\t\t\t\t\t\tdefaultOptions={\n\t\t\t\t\t\t\t\t\tselectedModel\n\t\t\t\t\t\t\t\t\t\t? [\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tlabel: selectedModel.label,\n\t\t\t\t\t\t\t\t\t\t\t\t\tvalue: selectedModel.value,\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t ]\n\t\t\t\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tonSelect={(opt) => {\n\t\t\t\t\t\t\t\t\tconst single = Array.isArray(opt) ? opt[0] : opt;\n\t\t\t\t\t\t\t\t\tconst v = (single as SingleOption)?.value;\n\t\t\t\t\t\t\t\t\tif (v) {\n\t\t\t\t\t\t\t\t\t\tupdateField('model', v);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</SideSection>\n\t\t\t\t\t)}\n\t\t\t\t</Step3Side>\n\t\t\t</Step3Grid>\n\n\t\t\t{panel && (\n\t\t\t\t<CreateSubAgentPanel\n\t\t\t\t\tkey={panel.key}\n\t\t\t\t\ttitle={panel.title}\n\t\t\t\t\tinitial={panel.initial}\n\t\t\t\t\tavailableTools={availableTools}\n\t\t\t\t\tappLabel={appTypeLabel(applicationType)}\n\t\t\t\t\tonImprove={onImproveSubAgent}\n\t\t\t\t\tonClose={() => setPanel(null)}\n\t\t\t\t\tonSave={handlePanelSave}\n\t\t\t\t/>\n\t\t\t)}\n\t\t</div>\n\t);\n};\n"],"names":["toolIconEl","source","ic","SOURCE_ICONS","React","toolOption","t","STEP","STEP_DEFINITIONS","Step3HowItResponds","value","patch","updateField","removeReference","availableTools","availableSubAgents","availableModels","applicationType","insertMention","onCreateSubAgent","onFetchSubAgent","onUpdateSubAgent","onImproveSubAgent","registerSubAgentCreator","useAgentBuilderContext","panel","setPanel","useState","panelKeyRef","useRef","createdSubAgents","setCreatedSubAgents","subAgentById","s","knownSubAgents","openCreate","useCallback","useEffect","openConfigure","id","data","handlePanelSave","draft","ref","prev","toolItems","tool","x","toolOptions","toolSourceGroups","order","bySource","src","toolSourceLabel","subAgentItems","sub","subAgentOptions","modelOptions","m","selectedModel","jsxs","jsx","StepSectionHeader","Step3Grid","Step3Main","MentionField","AGENT_CHAR_LIMITS","Step3Side","SelectableListSection","SideSection","TitleSmall","COLORS","Dropdown","opt","v","CreateSubAgentPanel","appTypeLabel"],"mappings":";;;;;;;;;;;;;;;AA2BA,MAAMA,KAAa,CAACC,MAA4C;AAC/D,QAAMC,IAAKC,EAAaF,CAAM;AAC9B,SAAOC,IACJE,EAAM,cAAcF,EAAG,MAAM,EAAE,OAAOA,EAAG,GAAG,QAAQA,EAAG,EAAA,CAAG,IAC1D;AACJ,GAGMG,IAAa,CAACC,OAAgC;AAAA,EACnD,OAAOA,EAAE;AAAA,EACT,OAAOA,EAAE;AAAA,EACT,aAAaN,GAAWM,EAAE,UAAU,UAAU;AAC/C,IAEMC,IAAOC,GAAiB,CAAC,GAUlBC,KAA+B,MAAM;AACjD,QAAM;AAAA,IACL,OAAAC;AAAA,IACA,OAAAC;AAAA,IACA,aAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,oBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,eAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,yBAAAC;AAAA,EAAA,IACGC,GAAA,GAEE,CAACC,GAAOC,CAAQ,IAAIC,EAAoC,IAAI,GAC5DC,IAAcC,EAAO,CAAC,GAGtB,CAACC,GAAkBC,CAAmB,IAAIJ,EAAwB,CAAA,CAAE,GAEpEK,wBAAmB,IA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BAAMC,KADS,MAAM,QAAQD,CAAG,IAAIA,EAAI,CAAC,IAAIA,IACT;AACpC,gBAAIC,KACH9D,EAAY,SAAS8D,CAAC;AAAA,cAExB;AAAA,YAAA;AAAA,UAAA;AAAA,QACD,EAAA,CACD;AAAA,MAAA,EAAA,CAEF;AAAA,IAAA,GACD;AAAA,IAECjD,KACA,gBAAAoC;AAAA,MAACc;AAAA,MAAA;AAAA,QAEA,OAAOlD,EAAM;AAAA,QACb,SAASA,EAAM;AAAA,QACf,gBAAAX;AAAA,QACA,UAAU8D,GAAa3D,CAAe;AAAA,QACtC,WAAWK;AAAA,QACX,SAAS,MAAMI,EAAS,IAAI;AAAA,QAC5B,QAAQe;AAAA,MAAA;AAAA,MAPHhB,EAAM;AAAA,IAAA;AAAA,EAQZ,GAEF;AAEF;"}
|
|
@@ -9,11 +9,11 @@ const d = {
|
|
|
9
9
|
...t.map(
|
|
10
10
|
(i) => ({
|
|
11
11
|
id: i.tool_id,
|
|
12
|
-
label: `${m(i.source, n)} : ${i.
|
|
12
|
+
label: `${m(i.source, n)} : ${i.display_name}`,
|
|
13
13
|
meta: {
|
|
14
14
|
kind: "tool",
|
|
15
15
|
functionKey: i.function_key,
|
|
16
|
-
plainLabel: i.
|
|
16
|
+
plainLabel: i.display_name,
|
|
17
17
|
source: i.source
|
|
18
18
|
}
|
|
19
19
|
})
|
|
@@ -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.displayName}`,\n\t\t\tmeta: {\n\t\t\t\tkind: 'tool',\n\t\t\t\tfunctionKey: t.function_key,\n\t\t\t\tplainLabel: t.displayName,\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,WAAW;AAAA,MAChE,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;AAAA,IAAK;AAAA,EAC9C;AAEF,GAEMC,IAAa,CAACC,MACnBA,EAAI,Q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ON,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:<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,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A,IACR,SAAS;AACR,YAAMC,KAASD,EAAK,WAAW,CAAA,GAC7B,IAAI,CAACE,MAAUH,EAAWG,GAAOL,CAAW,CAAC,EAC7C,KAAK,EAAE;AAGT,aADoB,CAAC,aAAa,WAAW,YAAY,YAAY,EAClD,SAASG,EAAK,IAAI,IAAI,GAAGC,CAAK;AAAA,IAAOA;AAAA,IACzD;AAAA,EAAA;AAEF,GAOaE,IAA0B,CACtCC,GACAnC,MACY;AACZ,MAAI,CAACmC;AACJ,WAAO;AAER,QAAMP,IAAc5B,EAAM,OAA+B,CAACoC,GAAKjC,OAC9DiC,EAAIjC,EAAE,OAAO,IAAIA,EAAE,cACZiC,IACL,CAAA,CAAE;AACL,SAAON,EAAWK,GAAmCP,CAAW,EAAE;AAAA,IACjE;AAAA,IACA;AAAA,EAAA;AAEF;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export type IconComp = React.FunctionComponent<React.SVGAttributes<SVGElement>>;
|
|
3
|
+
/** Brand glyph for a tool source, with its own size so each keeps its aspect ratio. */
|
|
4
|
+
export interface SourceIcon {
|
|
5
|
+
Icon: IconComp;
|
|
6
|
+
w: number;
|
|
7
|
+
h: number;
|
|
8
|
+
}
|
|
9
|
+
/** Per-source brand glyph — shared by the `@` picker and the Tools source buttons. */
|
|
10
|
+
export declare const SOURCE_ICONS: Record<string, SourceIcon>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import o from "../../../assets/icons/ManifestGlass.svg.js";
|
|
2
|
+
import f from "../../../assets/icons/Shopify.svg.js";
|
|
3
|
+
const t = {
|
|
4
|
+
manifest: { Icon: o, w: 24, h: 24 },
|
|
5
|
+
shopify: { Icon: f, w: 21, h: 24 }
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
t as SOURCE_ICONS
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=sourceIcons.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sourceIcons.js","sources":["../../../../../src/components/agent-builder/utils/sourceIcons.ts"],"sourcesContent":["import ManifestGlass from '@src/assets/icons/ManifestGlass.svg';\nimport Shopify from '@src/assets/icons/Shopify.svg';\nimport type React from 'react';\n\nexport type IconComp = React.FunctionComponent<React.SVGAttributes<SVGElement>>;\n\n/** Brand glyph for a tool source, with its own size so each keeps its aspect ratio. */\nexport interface SourceIcon {\n\tIcon: IconComp;\n\tw: number;\n\th: number;\n}\n\n/** Per-source brand glyph — shared by the `@` picker and the Tools source buttons. */\nexport const SOURCE_ICONS: Record<string, SourceIcon> = {\n\tmanifest: { Icon: ManifestGlass, w: 24, h: 24 },\n\tshopify: { Icon: Shopify, w: 21, h: 24 },\n};\n"],"names":["SOURCE_ICONS","ManifestGlass","Shopify"],"mappings":";;AAcO,MAAMA,IAA2C;AAAA,EACvD,UAAU,EAAE,MAAMC,GAAe,GAAG,IAAI,GAAG,GAAA;AAAA,EAC3C,SAAS,EAAE,MAAMC,GAAS,GAAG,IAAI,GAAG,GAAA;AACrC;"}
|