@bikdotai/bik-component-library 0.0.849-beta.3 → 0.0.849-beta.5
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/agent-builder/components/AddDataPill.js +10 -0
- package/dist/cjs/components/agent-builder/components/AddDataPill.js.map +1 -0
- package/dist/cjs/components/agent-builder/components/ConfigToolPanel.js +1 -1
- package/dist/cjs/components/agent-builder/components/ConfigToolPanel.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/RestApiToolPanel.js +4 -4
- package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js +1 -1
- package/dist/cjs/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
- package/dist/cjs/components/agent-builder/components/VariableTriggerArea.js +10 -4
- package/dist/cjs/components/agent-builder/components/VariableTriggerArea.js.map +1 -1
- package/dist/cjs/components/agent-builder/utils/mentionSerialization.js +4 -4
- 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 +5 -3
- package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
- package/dist/cjs/editor/BikEditor.types.js.map +1 -1
- package/dist/esm/components/agent-builder/components/AddDataPill.d.ts +18 -0
- package/dist/esm/components/agent-builder/components/AddDataPill.js +32 -0
- package/dist/esm/components/agent-builder/components/AddDataPill.js.map +1 -0
- package/dist/esm/components/agent-builder/components/ConfigToolPanel.js +21 -19
- package/dist/esm/components/agent-builder/components/ConfigToolPanel.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionEditor.d.ts +7 -2
- package/dist/esm/components/agent-builder/components/MentionEditor.js +119 -102
- package/dist/esm/components/agent-builder/components/MentionEditor.js.map +1 -1
- package/dist/esm/components/agent-builder/components/MentionField.js +30 -29
- package/dist/esm/components/agent-builder/components/MentionField.js.map +1 -1
- package/dist/esm/components/agent-builder/components/RestApiToolPanel.d.ts +9 -0
- package/dist/esm/components/agent-builder/components/RestApiToolPanel.js +126 -119
- package/dist/esm/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
- package/dist/esm/components/agent-builder/components/ToolInstructionsField.js +20 -19
- package/dist/esm/components/agent-builder/components/ToolInstructionsField.js.map +1 -1
- package/dist/esm/components/agent-builder/components/VariableTriggerArea.d.ts +15 -0
- package/dist/esm/components/agent-builder/components/VariableTriggerArea.js +112 -56
- package/dist/esm/components/agent-builder/components/VariableTriggerArea.js.map +1 -1
- package/dist/esm/components/agent-builder/utils/mentionSerialization.js +26 -20
- package/dist/esm/components/agent-builder/utils/mentionSerialization.js.map +1 -1
- package/dist/esm/editor/BikEditor.js +24 -18
- package/dist/esm/editor/BikEditor.js.map +1 -1
- package/dist/esm/editor/BikEditor.styles.js +5 -3
- package/dist/esm/editor/BikEditor.styles.js.map +1 -1
- package/dist/esm/editor/BikEditor.types.d.ts +9 -0
- package/dist/esm/editor/BikEditor.types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { useState as
|
|
5
|
-
import
|
|
1
|
+
import { jsxs as d, jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import K from "../../../assets/icons/delete.svg.js";
|
|
3
|
+
import Q from "../../../assets/icons/plus.svg.js";
|
|
4
|
+
import { useState as l, useRef as $ } from "react";
|
|
5
|
+
import b from "styled-components";
|
|
6
6
|
import { TitleSmall as u } from "../../TypographyStyle.js";
|
|
7
|
-
import { COLORS as
|
|
7
|
+
import { COLORS as i } from "../../../constants/Theme.js";
|
|
8
8
|
import { FieldBlock as p } from "../AgentBuilder.styled.js";
|
|
9
|
-
import { AGENT_CHAR_LIMITS as
|
|
10
|
-
import { DRAWER_BODY_STYLE as
|
|
11
|
-
import { ToolInstructionsField as
|
|
9
|
+
import { AGENT_CHAR_LIMITS as X } from "../constants/charLimits.js";
|
|
10
|
+
import { DRAWER_BODY_STYLE as Z, DRAWER_HEADER_STYLE as ee, DrawerHeaderText as te } from "./DrawerHeaderText.js";
|
|
11
|
+
import { ToolInstructionsField as re } from "./ToolInstructionsField.js";
|
|
12
12
|
import { VariableTriggerArea as h } from "./VariableTriggerArea.js";
|
|
13
|
-
import { SideModal as
|
|
13
|
+
import { SideModal as oe } from "../../side-modal/SideModal.js";
|
|
14
14
|
import { Input as f } from "../../input/Input.js";
|
|
15
|
-
import { Dropdown as
|
|
16
|
-
import { unwrapDropdownValue as
|
|
17
|
-
import { Button as
|
|
18
|
-
import { BikEditor as
|
|
19
|
-
const
|
|
20
|
-
label:
|
|
21
|
-
value:
|
|
22
|
-
})),
|
|
23
|
-
onClose:
|
|
24
|
-
onSave:
|
|
25
|
-
initial:
|
|
26
|
-
onImprove:
|
|
27
|
-
charLimits:
|
|
28
|
-
zIndex:
|
|
29
|
-
existingNames:
|
|
15
|
+
import { Dropdown as ne } from "../../dropdown/Dropdown.js";
|
|
16
|
+
import { unwrapDropdownValue as ae } from "../../dropdown/utils.js";
|
|
17
|
+
import { Button as se } from "../../button/Button.js";
|
|
18
|
+
import { BikEditor as q } from "../../../editor/BikEditor.js";
|
|
19
|
+
const le = ["GET", "POST", "PUT", "PATCH", "DELETE"], ie = le.map((s) => ({
|
|
20
|
+
label: s,
|
|
21
|
+
value: s
|
|
22
|
+
})), M = (s, y) => (y.textBefore.match(new RegExp('(?<!\\\\)"', "g"))?.length ?? 0) % 2 === 1 ? s : `"${s}"`, Ae = ({
|
|
23
|
+
onClose: s,
|
|
24
|
+
onSave: y,
|
|
25
|
+
initial: n,
|
|
26
|
+
onImprove: N,
|
|
27
|
+
charLimits: I = X,
|
|
28
|
+
zIndex: j,
|
|
29
|
+
existingNames: z = [],
|
|
30
30
|
variablesData: c
|
|
31
31
|
}) => {
|
|
32
|
-
const [
|
|
33
|
-
|
|
34
|
-
), [
|
|
35
|
-
|
|
36
|
-
), [
|
|
37
|
-
|
|
38
|
-
), [
|
|
39
|
-
(o) => o.map((
|
|
40
|
-
),
|
|
41
|
-
(e) => e.trim().toLowerCase() ===
|
|
42
|
-
), O =
|
|
43
|
-
return /* @__PURE__ */
|
|
44
|
-
|
|
32
|
+
const [x, F] = l(n?.name ?? ""), E = $(null), H = $(null), [w, G] = l(n?.instructions ?? ""), [T, B] = l(n?.url ?? "https://"), [g, J] = l(
|
|
33
|
+
n?.method ?? "POST"
|
|
34
|
+
), [k, v] = l(
|
|
35
|
+
n?.headers ?? [{ key: "", value: "" }]
|
|
36
|
+
), [A, U] = l(n?.requestBody ?? ""), [D, W] = l(
|
|
37
|
+
n?.responseSample ?? ""
|
|
38
|
+
), [P, L] = l(!1), S = (e, r) => v(
|
|
39
|
+
(o) => o.map((a, m) => m === e ? { ...a, ...r } : a)
|
|
40
|
+
), Y = () => v((e) => [...e, { key: "", value: "" }]), V = (e) => v((r) => r.filter((o, a) => a !== e)), C = x.trim(), R = C.length > 0 && z.some(
|
|
41
|
+
(e) => e.trim().toLowerCase() === C.toLowerCase()
|
|
42
|
+
), O = C.length > 0 && T.trim().length > 0 && !R;
|
|
43
|
+
return /* @__PURE__ */ d(
|
|
44
|
+
oe,
|
|
45
45
|
{
|
|
46
46
|
header: "Rest API",
|
|
47
47
|
closeOnEscapeKey: !1,
|
|
48
|
-
zIndex:
|
|
48
|
+
zIndex: j,
|
|
49
49
|
headerCustomComponent: /* @__PURE__ */ t(
|
|
50
|
-
|
|
50
|
+
te,
|
|
51
51
|
{
|
|
52
52
|
title: "Rest API",
|
|
53
53
|
subtitle: "Connect to any API endpoint. Define the request and a sample response for the agent to reference."
|
|
54
54
|
}
|
|
55
55
|
),
|
|
56
56
|
width: "431px",
|
|
57
|
-
headerStyle:
|
|
58
|
-
bodyStyle:
|
|
59
|
-
onClose:
|
|
57
|
+
headerStyle: ee,
|
|
58
|
+
bodyStyle: Z,
|
|
59
|
+
onClose: s,
|
|
60
60
|
saveButtonProps: {
|
|
61
61
|
"data-test": "restapi-save",
|
|
62
62
|
buttonText: "Save",
|
|
63
63
|
buttonType: "primary",
|
|
64
64
|
size: "small",
|
|
65
65
|
disabled: !O,
|
|
66
|
-
isLoading:
|
|
66
|
+
isLoading: P,
|
|
67
67
|
onClick: async () => {
|
|
68
|
-
if (!O ||
|
|
68
|
+
if (!O || P)
|
|
69
69
|
return;
|
|
70
70
|
const e = {
|
|
71
|
-
id:
|
|
72
|
-
name:
|
|
73
|
-
instructions:
|
|
74
|
-
url:
|
|
75
|
-
method:
|
|
71
|
+
id: n?.id ?? `restapi_${Date.now().toString(36)}`,
|
|
72
|
+
name: x.trim(),
|
|
73
|
+
instructions: w,
|
|
74
|
+
url: T.trim(),
|
|
75
|
+
method: g,
|
|
76
76
|
// Drop fully-empty header rows.
|
|
77
|
-
headers:
|
|
78
|
-
requestBody:
|
|
79
|
-
responseSample:
|
|
80
|
-
}, r =
|
|
77
|
+
headers: k.filter((o) => o.key.trim() || o.value.trim()),
|
|
78
|
+
requestBody: A,
|
|
79
|
+
responseSample: D
|
|
80
|
+
}, r = y(e);
|
|
81
81
|
if (r && typeof r.then == "function") {
|
|
82
82
|
L(!0);
|
|
83
83
|
try {
|
|
@@ -93,7 +93,7 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
93
93
|
buttonText: "Cancel",
|
|
94
94
|
buttonType: "tertiaryGray",
|
|
95
95
|
size: "small",
|
|
96
|
-
onClick:
|
|
96
|
+
onClick: s
|
|
97
97
|
},
|
|
98
98
|
children: [
|
|
99
99
|
/* @__PURE__ */ t(
|
|
@@ -104,33 +104,34 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
104
104
|
labelText: "Name",
|
|
105
105
|
labelTextBold: !0,
|
|
106
106
|
placeholder: "Enter action name",
|
|
107
|
-
value:
|
|
108
|
-
maxCharLimit:
|
|
109
|
-
state:
|
|
110
|
-
errorMessage:
|
|
111
|
-
onChangeText:
|
|
107
|
+
value: x,
|
|
108
|
+
maxCharLimit: I.name,
|
|
109
|
+
state: R ? "invalid" : void 0,
|
|
110
|
+
errorMessage: R ? "A tool with this name already exists" : void 0,
|
|
111
|
+
onChangeText: F
|
|
112
112
|
}
|
|
113
113
|
),
|
|
114
114
|
/* @__PURE__ */ t(
|
|
115
|
-
|
|
115
|
+
re,
|
|
116
116
|
{
|
|
117
117
|
"data-test": "restapi-instructions",
|
|
118
118
|
label: "Instructions",
|
|
119
|
-
value:
|
|
120
|
-
onChange:
|
|
121
|
-
maxLength:
|
|
119
|
+
value: w,
|
|
120
|
+
onChange: G,
|
|
121
|
+
maxLength: I.instructions,
|
|
122
122
|
placeholder: "Describe how should the LLM generate the rest API",
|
|
123
|
-
onImprove:
|
|
123
|
+
onImprove: N,
|
|
124
124
|
variablesData: c
|
|
125
125
|
}
|
|
126
126
|
),
|
|
127
127
|
/* @__PURE__ */ t(p, { children: /* @__PURE__ */ t(
|
|
128
128
|
h,
|
|
129
129
|
{
|
|
130
|
+
addDataButton: !0,
|
|
130
131
|
variablesData: c,
|
|
131
|
-
onInsert: (e, r) =>
|
|
132
|
-
const
|
|
133
|
-
return `${o.slice(0,
|
|
132
|
+
onInsert: (e, r) => B((o) => {
|
|
133
|
+
const a = r ?? o.length;
|
|
134
|
+
return `${o.slice(0, a)}${e}${o.slice(a)}`;
|
|
134
135
|
}),
|
|
135
136
|
children: /* @__PURE__ */ t(
|
|
136
137
|
f,
|
|
@@ -141,35 +142,35 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
141
142
|
labelTextBold: !0,
|
|
142
143
|
placeholder: "https://",
|
|
143
144
|
type: "url",
|
|
144
|
-
value:
|
|
145
|
-
onChangeText:
|
|
145
|
+
value: T,
|
|
146
|
+
onChangeText: B
|
|
146
147
|
}
|
|
147
148
|
)
|
|
148
149
|
}
|
|
149
150
|
) }),
|
|
150
|
-
/* @__PURE__ */
|
|
151
|
-
/* @__PURE__ */ t(u, { color:
|
|
151
|
+
/* @__PURE__ */ d(p, { children: [
|
|
152
|
+
/* @__PURE__ */ t(u, { color: i.content.primary, children: "HTTP method" }),
|
|
152
153
|
/* @__PURE__ */ t(
|
|
153
|
-
|
|
154
|
+
ne,
|
|
154
155
|
{
|
|
155
156
|
"data-test": "restapi-method",
|
|
156
157
|
size: "small",
|
|
157
158
|
width: "100%",
|
|
158
159
|
dropdownWidth: "399px",
|
|
159
|
-
options:
|
|
160
|
-
defaultOptions: [{ label:
|
|
160
|
+
options: ie,
|
|
161
|
+
defaultOptions: [{ label: g, value: g }],
|
|
161
162
|
onSelect: (e) => {
|
|
162
|
-
const r =
|
|
163
|
-
r &&
|
|
163
|
+
const r = ae(e);
|
|
164
|
+
r && J(r);
|
|
164
165
|
}
|
|
165
166
|
}
|
|
166
167
|
)
|
|
167
168
|
] }),
|
|
168
|
-
/* @__PURE__ */
|
|
169
|
-
/* @__PURE__ */ t(u, { color:
|
|
170
|
-
|
|
169
|
+
/* @__PURE__ */ d(p, { children: [
|
|
170
|
+
/* @__PURE__ */ t(u, { color: i.content.primary, children: "Headers" }),
|
|
171
|
+
k.map((e, r) => (
|
|
171
172
|
// eslint-disable-next-line react/no-array-index-key
|
|
172
|
-
/* @__PURE__ */
|
|
173
|
+
/* @__PURE__ */ d(de, { "data-test": `restapi-header-${r}`, children: [
|
|
173
174
|
/* @__PURE__ */ t(
|
|
174
175
|
f,
|
|
175
176
|
{
|
|
@@ -177,16 +178,17 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
177
178
|
hideInputHeader: !0,
|
|
178
179
|
placeholder: "Enter name",
|
|
179
180
|
value: e.key,
|
|
180
|
-
onChangeText: (o) =>
|
|
181
|
+
onChangeText: (o) => S(r, { key: o })
|
|
181
182
|
}
|
|
182
183
|
),
|
|
183
184
|
/* @__PURE__ */ t(
|
|
184
185
|
h,
|
|
185
186
|
{
|
|
187
|
+
addDataButton: !0,
|
|
186
188
|
variablesData: c,
|
|
187
|
-
onInsert: (o,
|
|
188
|
-
const m =
|
|
189
|
-
|
|
189
|
+
onInsert: (o, a) => {
|
|
190
|
+
const m = a ?? e.value.length;
|
|
191
|
+
S(r, {
|
|
190
192
|
value: `${e.value.slice(0, m)}${o}${e.value.slice(m)}`
|
|
191
193
|
});
|
|
192
194
|
},
|
|
@@ -197,58 +199,60 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
197
199
|
hideInputHeader: !0,
|
|
198
200
|
placeholder: "Enter value",
|
|
199
201
|
value: e.value,
|
|
200
|
-
onChangeText: (o) =>
|
|
202
|
+
onChangeText: (o) => S(r, { value: o })
|
|
201
203
|
}
|
|
202
204
|
)
|
|
203
205
|
}
|
|
204
206
|
),
|
|
205
207
|
/* @__PURE__ */ t(
|
|
206
|
-
|
|
208
|
+
pe,
|
|
207
209
|
{
|
|
208
210
|
type: "button",
|
|
209
211
|
"aria-label": "Remove header",
|
|
210
212
|
"data-test": `restapi-header-remove-${r}`,
|
|
211
|
-
onClick: () =>
|
|
213
|
+
onClick: () => V(r),
|
|
212
214
|
children: /* @__PURE__ */ t(
|
|
213
|
-
|
|
215
|
+
K,
|
|
214
216
|
{
|
|
215
217
|
width: 16,
|
|
216
218
|
height: 16,
|
|
217
|
-
color:
|
|
219
|
+
color: i.content.secondary
|
|
218
220
|
}
|
|
219
221
|
)
|
|
220
222
|
}
|
|
221
223
|
)
|
|
222
224
|
] }, r)
|
|
223
225
|
)),
|
|
224
|
-
/* @__PURE__ */ t(
|
|
225
|
-
|
|
226
|
+
/* @__PURE__ */ t(ce, { children: /* @__PURE__ */ t(
|
|
227
|
+
se,
|
|
226
228
|
{
|
|
227
229
|
"data-test": "restapi-add-header",
|
|
228
230
|
buttonType: "dashRegular",
|
|
229
231
|
size: "small",
|
|
230
|
-
LeadingIcon:
|
|
232
|
+
LeadingIcon: Q,
|
|
231
233
|
buttonText: "Add header",
|
|
232
|
-
onClick:
|
|
234
|
+
onClick: Y
|
|
233
235
|
}
|
|
234
236
|
) })
|
|
235
237
|
] }),
|
|
236
|
-
/* @__PURE__ */
|
|
237
|
-
/* @__PURE__ */ t(u, { color:
|
|
238
|
+
/* @__PURE__ */ d(p, { children: [
|
|
239
|
+
/* @__PURE__ */ t(u, { color: i.content.primary, children: "Request " }),
|
|
238
240
|
/* @__PURE__ */ t(
|
|
239
241
|
h,
|
|
240
242
|
{
|
|
243
|
+
addDataButton: !0,
|
|
241
244
|
variablesData: c,
|
|
242
|
-
|
|
245
|
+
transformToken: M,
|
|
246
|
+
onInsert: (e) => E.current?.insertInlineContent(e),
|
|
243
247
|
children: /* @__PURE__ */ t(
|
|
244
|
-
|
|
248
|
+
q,
|
|
245
249
|
{
|
|
246
|
-
ref:
|
|
250
|
+
ref: E,
|
|
247
251
|
features: { jsonMode: !0 },
|
|
248
|
-
initialContent:
|
|
249
|
-
style:
|
|
252
|
+
initialContent: A,
|
|
253
|
+
style: _,
|
|
250
254
|
placeholder: "Type or paste JSON here",
|
|
251
|
-
onChange: (e) =>
|
|
255
|
+
onChange: (e) => U(e.text),
|
|
252
256
|
minHeight: "120px",
|
|
253
257
|
maxHeight: "240px"
|
|
254
258
|
}
|
|
@@ -256,22 +260,24 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
256
260
|
}
|
|
257
261
|
)
|
|
258
262
|
] }),
|
|
259
|
-
/* @__PURE__ */
|
|
260
|
-
/* @__PURE__ */ t(u, { color:
|
|
263
|
+
/* @__PURE__ */ d(p, { children: [
|
|
264
|
+
/* @__PURE__ */ t(u, { color: i.content.primary, children: "Response " }),
|
|
261
265
|
/* @__PURE__ */ t(
|
|
262
266
|
h,
|
|
263
267
|
{
|
|
268
|
+
addDataButton: !0,
|
|
264
269
|
variablesData: c,
|
|
265
|
-
|
|
270
|
+
transformToken: M,
|
|
271
|
+
onInsert: (e) => H.current?.insertInlineContent(e),
|
|
266
272
|
children: /* @__PURE__ */ t(
|
|
267
|
-
|
|
273
|
+
q,
|
|
268
274
|
{
|
|
269
|
-
ref:
|
|
275
|
+
ref: H,
|
|
270
276
|
features: { jsonMode: !0 },
|
|
271
|
-
style:
|
|
272
|
-
initialContent:
|
|
277
|
+
style: _,
|
|
278
|
+
initialContent: D,
|
|
273
279
|
placeholder: "Type or paste JSON here",
|
|
274
|
-
onChange: (e) =>
|
|
280
|
+
onChange: (e) => W(e.text),
|
|
275
281
|
minHeight: "120px",
|
|
276
282
|
maxHeight: "240px"
|
|
277
283
|
}
|
|
@@ -282,33 +288,34 @@ const se = ["GET", "POST", "PUT", "PATCH", "DELETE"], le = se.map((d) => ({
|
|
|
282
288
|
]
|
|
283
289
|
}
|
|
284
290
|
);
|
|
285
|
-
},
|
|
291
|
+
}, de = b.div`
|
|
286
292
|
display: flex;
|
|
287
293
|
align-items: center;
|
|
288
294
|
gap: 8px;
|
|
289
|
-
`,
|
|
295
|
+
`, ce = b.div`
|
|
290
296
|
display: flex;
|
|
291
|
-
`,
|
|
297
|
+
`, pe = b.button`
|
|
292
298
|
display: inline-flex;
|
|
293
299
|
align-items: center;
|
|
294
300
|
justify-content: center;
|
|
295
301
|
flex-shrink: 0;
|
|
296
302
|
width: 32px;
|
|
297
303
|
height: 32px;
|
|
298
|
-
border: 1px solid ${
|
|
304
|
+
border: 1px solid ${i.stroke.primary};
|
|
299
305
|
border-radius: 4px;
|
|
300
|
-
background: ${
|
|
306
|
+
background: ${i.surface.standard};
|
|
301
307
|
cursor: pointer;
|
|
302
308
|
|
|
303
309
|
&:hover {
|
|
304
|
-
border-color: ${
|
|
310
|
+
border-color: ${i.content.secondary};
|
|
305
311
|
}
|
|
306
|
-
`,
|
|
312
|
+
`, _ = {
|
|
307
313
|
borderRadius: "4px",
|
|
308
314
|
overflow: "hidden"
|
|
309
315
|
};
|
|
310
316
|
export {
|
|
311
|
-
|
|
312
|
-
|
|
317
|
+
_ as JsonFieldBox,
|
|
318
|
+
Ae as RestApiToolPanel,
|
|
319
|
+
M as jsonQuoteToken
|
|
313
320
|
};
|
|
314
321
|
//# sourceMappingURL=RestApiToolPanel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RestApiToolPanel.js","sources":["../../../../../src/components/agent-builder/components/RestApiToolPanel.tsx"],"sourcesContent":["import DeleteIcon from '@src/assets/icons/delete.svg';\nimport PlusIcon from '@src/assets/icons/plus.svg';\nimport { BikEditor, BikEditorRef } from '@src/editor';\nimport React, { useRef, useState } from 'react';\nimport styled from 'styled-components';\nimport { Button } from '@src/components/button';\nimport { Dropdown, unwrapDropdownValue } from '@src/components/dropdown';\nimport { SingleOption } from '@src/components/dropdown/type';\nimport { Input } from '@src/components/input';\nimport { SideModal } from '@src/components/side-modal';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport type { VariableListInterfaceV3 } from '../../variable-picker-v3/model';\nimport {\n\tRestApiHeader,\n\tRestApiMethod,\n\tRestApiToolConfig,\n} from '../AgentBuilder.model';\nimport { FieldBlock } from '../AgentBuilder.styled';\nimport type { AgentCharLimits } from '../constants/charLimits';\nimport { AGENT_CHAR_LIMITS } from '../constants/charLimits';\nimport {\n\tDRAWER_BODY_STYLE,\n\tDRAWER_HEADER_STYLE,\n\tDrawerHeaderText,\n} from './DrawerHeaderText';\nimport { ToolInstructionsField } from './ToolInstructionsField';\nimport { VariableTriggerArea } from './VariableTriggerArea';\n\ninterface RestApiToolPanelProps {\n\tonClose: () => void;\n\t/** Persist the config. A pending promise shows the Save loader. */\n\tonSave: (config: RestApiToolConfig) => void | Promise<void>;\n\t/** Seed values when editing an existing tool. */\n\tinitial?: RestApiToolConfig;\n\t/** Optional \"Improve with AI\" for the instructions field. Omit to hide it. */\n\tonImprove?: (text: string) => Promise<string>;\n\tcharLimits?: AgentCharLimits;\n\t/** SideModal stacking order — raise it when opened over another drawer. */\n\tzIndex?: number;\n\t/** Names of the OTHER tools — a new tool can't reuse one of these. */\n\texistingNames?: string[];\n\t/**\n\t * Variable catalog for the `@` trigger. When non-empty, `@` opens the\n\t * variable picker directly in Instructions / Request URL / header values /\n\t * Request / Response. Absent → the drawer behaves exactly as before.\n\t */\n\tvariablesData?: VariableListInterfaceV3[];\n}\n\nconst METHODS: RestApiMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];\nconst METHOD_OPTIONS: SingleOption[] = METHODS.map((m) => ({\n\tlabel: m,\n\tvalue: m,\n}));\n\n/**\n * Right-side drawer to configure a \"Rest API\" tool: the endpoint the agent can\n * call, plus a JSON request-body template and a sample response. Mount it fresh\n * per open (key it) so `initial` seeds the state. Built on the shared `SideModal`\n * shell and the BikEditor JSON body mode for the Request / Response editors.\n */\nexport const RestApiToolPanel: React.FC<RestApiToolPanelProps> = ({\n\tonClose,\n\tonSave,\n\tinitial,\n\tonImprove,\n\tcharLimits = AGENT_CHAR_LIMITS,\n\tzIndex,\n\texistingNames = [],\n\tvariablesData,\n}) => {\n\tconst [name, setName] = useState(initial?.name ?? '');\n\t// `@`-picked variables insert into the JSON editors at their own cursor.\n\tconst requestEditorRef = useRef<BikEditorRef>(null);\n\tconst responseEditorRef = useRef<BikEditorRef>(null);\n\tconst [instructions, setInstructions] = useState(initial?.instructions ?? '');\n\t// New tools start with the scheme pre-filled so the user only types the host.\n\tconst [url, setUrl] = useState(initial?.url ?? 'https://');\n\tconst [method, setMethod] = useState<RestApiMethod>(\n\t\tinitial?.method ?? 'POST',\n\t);\n\tconst [headers, setHeaders] = useState<RestApiHeader[]>(\n\t\tinitial?.headers ?? [{ key: '', value: '' }],\n\t);\n\tconst [requestBody, setRequestBody] = useState(initial?.requestBody ?? '');\n\tconst [responseSample, setResponseSample] = useState(\n\t\tinitial?.responseSample ?? '',\n\t);\n\tconst [saving, setSaving] = useState(false);\n\n\tconst patchHeader = (i: number, patch: Partial<RestApiHeader>) =>\n\t\tsetHeaders((prev) =>\n\t\t\tprev.map((h, idx) => (idx === i ? { ...h, ...patch } : h)),\n\t\t);\n\tconst addHeader = () =>\n\t\tsetHeaders((prev) => [...prev, { key: '', value: '' }]);\n\tconst removeHeader = (i: number) =>\n\t\tsetHeaders((prev) => prev.filter((_, idx) => idx !== i));\n\n\tconst nameTrimmed = name.trim();\n\t// Case-insensitive: two tools can't share a name (the LLM references them by it).\n\tconst isDuplicateName =\n\t\tnameTrimmed.length > 0 &&\n\t\texistingNames.some(\n\t\t\t(n) => n.trim().toLowerCase() === nameTrimmed.toLowerCase(),\n\t\t);\n\tconst canSave =\n\t\tnameTrimmed.length > 0 && url.trim().length > 0 && !isDuplicateName;\n\n\tconst handleSave = async () => {\n\t\tif (!canSave || saving) {\n\t\t\treturn;\n\t\t}\n\t\tconst config: RestApiToolConfig = {\n\t\t\tid: initial?.id ?? `restapi_${Date.now().toString(36)}`,\n\t\t\tname: name.trim(),\n\t\t\tinstructions,\n\t\t\turl: url.trim(),\n\t\t\tmethod,\n\t\t\t// Drop fully-empty header rows.\n\t\t\theaders: headers.filter((h) => h.key.trim() || h.value.trim()),\n\t\t\trequestBody,\n\t\t\tresponseSample,\n\t\t};\n\t\tconst result = onSave(config);\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetSaving(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} finally {\n\t\t\t\tsetSaving(false);\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (\n\t\t<SideModal\n\t\t\theader=\"Rest API\"\n\t\t\tcloseOnEscapeKey={false}\n\t\t\tzIndex={zIndex}\n\t\t\theaderCustomComponent={\n\t\t\t\t<DrawerHeaderText\n\t\t\t\t\ttitle=\"Rest API\"\n\t\t\t\t\tsubtitle=\"Connect to any API endpoint. Define the request and a sample response for the agent to reference.\"\n\t\t\t\t/>\n\t\t\t}\n\t\t\twidth=\"431px\"\n\t\t\theaderStyle={DRAWER_HEADER_STYLE}\n\t\t\tbodyStyle={DRAWER_BODY_STYLE}\n\t\t\tonClose={onClose}\n\t\t\tsaveButtonProps={{\n\t\t\t\t'data-test': 'restapi-save',\n\t\t\t\tbuttonText: 'Save',\n\t\t\t\tbuttonType: 'primary',\n\t\t\t\tsize: 'small',\n\t\t\t\tdisabled: !canSave,\n\t\t\t\tisLoading: saving,\n\t\t\t\tonClick: handleSave,\n\t\t\t}}\n\t\t\tcancelButtonProps={{\n\t\t\t\t'data-test': 'restapi-cancel',\n\t\t\t\tbuttonText: 'Cancel',\n\t\t\t\tbuttonType: 'tertiaryGray',\n\t\t\t\tsize: 'small',\n\t\t\t\tonClick: onClose,\n\t\t\t}}\n\t\t>\n\t\t\t<Input\n\t\t\t\tdata-test=\"restapi-name\"\n\t\t\t\tvariant=\"small\"\n\t\t\t\tlabelText=\"Name\"\n\t\t\t\tlabelTextBold\n\t\t\t\tplaceholder=\"Enter action name\"\n\t\t\t\tvalue={name}\n\t\t\t\tmaxCharLimit={charLimits.name}\n\t\t\t\tstate={isDuplicateName ? 'invalid' : undefined}\n\t\t\t\terrorMessage={\n\t\t\t\t\tisDuplicateName ? 'A tool with this name already exists' : undefined\n\t\t\t\t}\n\t\t\t\tonChangeText={setName}\n\t\t\t/>\n\n\t\t\t<ToolInstructionsField\n\t\t\t\tdata-test=\"restapi-instructions\"\n\t\t\t\tlabel=\"Instructions\"\n\t\t\t\tvalue={instructions}\n\t\t\t\tonChange={setInstructions}\n\t\t\t\tmaxLength={charLimits.instructions}\n\t\t\t\tplaceholder=\"Describe how should the LLM generate the rest API\"\n\t\t\t\tonImprove={onImprove}\n\t\t\t\tvariablesData={variablesData}\n\t\t\t/>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<VariableTriggerArea\n\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\tonInsert={(token, caret) =>\n\t\t\t\t\t\tsetUrl((u) => {\n\t\t\t\t\t\t\tconst at = caret ?? u.length;\n\t\t\t\t\t\t\treturn `${u.slice(0, at)}${token}${u.slice(at)}`;\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<Input\n\t\t\t\t\t\tdata-test=\"restapi-url\"\n\t\t\t\t\t\tvariant=\"small\"\n\t\t\t\t\t\tlabelText=\"Request URL\"\n\t\t\t\t\t\tlabelTextBold\n\t\t\t\t\t\tplaceholder=\"https://\"\n\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\tvalue={url}\n\t\t\t\t\t\tonChangeText={setUrl}\n\t\t\t\t\t/>\n\t\t\t\t</VariableTriggerArea>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>HTTP method</TitleSmall>\n\t\t\t\t<Dropdown\n\t\t\t\t\tdata-test=\"restapi-method\"\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\twidth=\"100%\"\n\t\t\t\t\tdropdownWidth=\"399px\"\n\t\t\t\t\toptions={METHOD_OPTIONS}\n\t\t\t\t\tdefaultOptions={[{ label: method, value: method }]}\n\t\t\t\t\tonSelect={(opt) => {\n\t\t\t\t\t\tconst v = unwrapDropdownValue(opt);\n\t\t\t\t\t\tif (v) {\n\t\t\t\t\t\t\tsetMethod(v as RestApiMethod);\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Headers</TitleSmall>\n\t\t\t\t{headers.map((h, i) => (\n\t\t\t\t\t// eslint-disable-next-line react/no-array-index-key\n\t\t\t\t\t<HeaderRow key={i} data-test={`restapi-header-${i}`}>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\tvariant=\"small\"\n\t\t\t\t\t\t\thideInputHeader\n\t\t\t\t\t\t\tplaceholder=\"Enter name\"\n\t\t\t\t\t\t\tvalue={h.key}\n\t\t\t\t\t\t\tonChangeText={(v) => patchHeader(i, { key: v })}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<VariableTriggerArea\n\t\t\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\t\t\tonInsert={(token, caret) => {\n\t\t\t\t\t\t\t\tconst at = caret ?? h.value.length;\n\t\t\t\t\t\t\t\tpatchHeader(i, {\n\t\t\t\t\t\t\t\t\tvalue: `${h.value.slice(0, at)}${token}${h.value.slice(at)}`,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\t\tvariant=\"small\"\n\t\t\t\t\t\t\t\thideInputHeader\n\t\t\t\t\t\t\t\tplaceholder=\"Enter value\"\n\t\t\t\t\t\t\t\tvalue={h.value}\n\t\t\t\t\t\t\t\tonChangeText={(v) => patchHeader(i, { value: v })}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</VariableTriggerArea>\n\t\t\t\t\t\t<IconBtn\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\taria-label=\"Remove header\"\n\t\t\t\t\t\t\tdata-test={`restapi-header-remove-${i}`}\n\t\t\t\t\t\t\tonClick={() => removeHeader(i)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<DeleteIcon\n\t\t\t\t\t\t\t\twidth={16}\n\t\t\t\t\t\t\t\theight={16}\n\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</IconBtn>\n\t\t\t\t\t</HeaderRow>\n\t\t\t\t))}\n\t\t\t\t<AddHeaderRow>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdata-test=\"restapi-add-header\"\n\t\t\t\t\t\tbuttonType=\"dashRegular\"\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tLeadingIcon={PlusIcon}\n\t\t\t\t\t\tbuttonText=\"Add header\"\n\t\t\t\t\t\tonClick={addHeader}\n\t\t\t\t\t/>\n\t\t\t\t</AddHeaderRow>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Request </TitleSmall>\n\t\t\t\t<VariableTriggerArea\n\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\tonInsert={(token) =>\n\t\t\t\t\t\trequestEditorRef.current?.insertInlineContent(token)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<BikEditor\n\t\t\t\t\t\tref={requestEditorRef}\n\t\t\t\t\t\tfeatures={{ jsonMode: true }}\n\t\t\t\t\t\tinitialContent={requestBody}\n\t\t\t\t\t\tstyle={JsonFieldBox}\n\t\t\t\t\t\tplaceholder=\"Type or paste JSON here\"\n\t\t\t\t\t\tonChange={(c) => setRequestBody(c.text)}\n\t\t\t\t\t\tminHeight=\"120px\"\n\t\t\t\t\t\tmaxHeight=\"240px\"\n\t\t\t\t\t/>\n\t\t\t\t</VariableTriggerArea>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Response </TitleSmall>\n\t\t\t\t<VariableTriggerArea\n\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\tonInsert={(token) =>\n\t\t\t\t\t\tresponseEditorRef.current?.insertInlineContent(token)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<BikEditor\n\t\t\t\t\t\tref={responseEditorRef}\n\t\t\t\t\t\tfeatures={{ jsonMode: true }}\n\t\t\t\t\t\tstyle={JsonFieldBox}\n\t\t\t\t\t\tinitialContent={responseSample}\n\t\t\t\t\t\tplaceholder=\"Type or paste JSON here\"\n\t\t\t\t\t\tonChange={(c) => setResponseSample(c.text)}\n\t\t\t\t\t\tminHeight=\"120px\"\n\t\t\t\t\t\tmaxHeight=\"240px\"\n\t\t\t\t\t/>\n\t\t\t\t</VariableTriggerArea>\n\t\t\t</FieldBlock>\n\t\t</SideModal>\n\t);\n};\n\nconst HeaderRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n`;\n\nconst AddHeaderRow = styled.div`\n\tdisplay: flex;\n`;\n\nconst IconBtn = styled.button`\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\tflex-shrink: 0;\n\twidth: 32px;\n\theight: 32px;\n\tborder: 1px solid ${COLORS.stroke.primary};\n\tborder-radius: 4px;\n\tbackground: ${COLORS.surface.standard};\n\tcursor: pointer;\n\n\t&:hover {\n\t\tborder-color: ${COLORS.content.secondary};\n\t}\n`;\n\nexport const JsonFieldBox = {\n\tborderRadius: '4px',\n\toverflow: 'hidden',\n};\n"],"names":["METHODS","METHOD_OPTIONS","m","RestApiToolPanel","onClose","onSave","initial","onImprove","charLimits","AGENT_CHAR_LIMITS","zIndex","existingNames","variablesData","name","setName","useState","requestEditorRef","useRef","responseEditorRef","instructions","setInstructions","url","setUrl","method","setMethod","headers","setHeaders","requestBody","setRequestBody","responseSample","setResponseSample","saving","setSaving","patchHeader","i","patch","prev","h","idx","addHeader","removeHeader","_","nameTrimmed","isDuplicateName","n","canSave","jsxs","SideModal","jsx","DrawerHeaderText","DRAWER_HEADER_STYLE","DRAWER_BODY_STYLE","config","result","Input","ToolInstructionsField","FieldBlock","VariableTriggerArea","token","caret","u","at","TitleSmall","COLORS","Dropdown","opt","v","unwrapDropdownValue","HeaderRow","IconBtn","DeleteIcon","AddHeaderRow","Button","PlusIcon","BikEditor","JsonFieldBox","c","styled"],"mappings":";;;;;;;;;;;;;;;;;;AAkDA,MAAMA,KAA2B,CAAC,OAAO,QAAQ,OAAO,SAAS,QAAQ,GACnEC,KAAiCD,GAAQ,IAAI,CAACE,OAAO;AAAA,EAC1D,OAAOA;AAAA,EACP,OAAOA;AACR,EAAE,GAQWC,KAAoD,CAAC;A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A,kBACtC,WAAU;AAAA,kBACV,WAAU;AAAA,gBAAA;AAAA,cAAA;AAAA,YACX;AAAA,UAAA;AAAA,QACD,GACD;AAAA,0BAECpB,GAAA,EACA,UAAA;AAAA,UAAA,gBAAAR,EAACc,GAAA,EAAW,OAAOC,EAAO,QAAQ,SAAS,UAAA,aAAS;AAAA,UACpD,gBAAAf;AAAA,YAACS;AAAA,YAAA;AAAA,cACA,eAAA7C;AAAA,cACA,UAAU,CAAC8C,MACVxC,EAAkB,SAAS,oBAAoBwC,CAAK;AAAA,cAGrD,UAAA,gBAAAV;AAAA,gBAAC0B;AAAA,gBAAA;AAAA,kBACA,KAAKxD;AAAA,kBACL,UAAU,EAAE,UAAU,GAAA;AAAA,kBACtB,OAAOyD;AAAA,kBACP,gBAAgB9C;AAAA,kBAChB,aAAY;AAAA,kBACZ,UAAU,CAAC+C,MAAM9C,EAAkB8C,EAAE,IAAI;AAAA,kBACzC,WAAU;AAAA,kBACV,WAAU;AAAA,gBAAA;AAAA,cAAA;AAAA,YACX;AAAA,UAAA;AAAA,QACD,EAAA,CACD;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAGH,GAEMR,KAAYS,EAAO;AAAA;AAAA;AAAA;AAAA,GAMnBN,KAAeM,EAAO;AAAA;AAAA,GAItBR,KAAUQ,EAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOFd,EAAO,OAAO,OAAO;AAAA;AAAA,eAE3BA,EAAO,QAAQ,QAAQ;AAAA;AAAA;AAAA;AAAA,kBAIpBA,EAAO,QAAQ,SAAS;AAAA;AAAA,GAI7BY,IAAe;AAAA,EAC3B,cAAc;AAAA,EACd,UAAU;AACX;"}
|
|
1
|
+
{"version":3,"file":"RestApiToolPanel.js","sources":["../../../../../src/components/agent-builder/components/RestApiToolPanel.tsx"],"sourcesContent":["import DeleteIcon from '@src/assets/icons/delete.svg';\nimport PlusIcon from '@src/assets/icons/plus.svg';\nimport { BikEditor, BikEditorRef } from '@src/editor';\nimport React, { useRef, useState } from 'react';\nimport styled from 'styled-components';\nimport { Button } from '@src/components/button';\nimport { Dropdown, unwrapDropdownValue } from '@src/components/dropdown';\nimport { SingleOption } from '@src/components/dropdown/type';\nimport { Input } from '@src/components/input';\nimport { SideModal } from '@src/components/side-modal';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport type { VariableListInterfaceV3 } from '../../variable-picker-v3/model';\nimport {\n\tRestApiHeader,\n\tRestApiMethod,\n\tRestApiToolConfig,\n} from '../AgentBuilder.model';\nimport { FieldBlock } from '../AgentBuilder.styled';\nimport type { AgentCharLimits } from '../constants/charLimits';\nimport { AGENT_CHAR_LIMITS } from '../constants/charLimits';\nimport {\n\tDRAWER_BODY_STYLE,\n\tDRAWER_HEADER_STYLE,\n\tDrawerHeaderText,\n} from './DrawerHeaderText';\nimport { ToolInstructionsField } from './ToolInstructionsField';\nimport { VariableTriggerArea } from './VariableTriggerArea';\n\ninterface RestApiToolPanelProps {\n\tonClose: () => void;\n\t/** Persist the config. A pending promise shows the Save loader. */\n\tonSave: (config: RestApiToolConfig) => void | Promise<void>;\n\t/** Seed values when editing an existing tool. */\n\tinitial?: RestApiToolConfig;\n\t/** Optional \"Improve with AI\" for the instructions field. Omit to hide it. */\n\tonImprove?: (text: string) => Promise<string>;\n\tcharLimits?: AgentCharLimits;\n\t/** SideModal stacking order — raise it when opened over another drawer. */\n\tzIndex?: number;\n\t/** Names of the OTHER tools — a new tool can't reuse one of these. */\n\texistingNames?: string[];\n\t/**\n\t * Variable catalog for the `@` trigger. When non-empty, `@` opens the\n\t * variable picker directly in Instructions / Request URL / header values /\n\t * Request / Response. Absent → the drawer behaves exactly as before.\n\t */\n\tvariablesData?: VariableListInterfaceV3[];\n}\n\nconst METHODS: RestApiMethod[] = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'];\nconst METHOD_OPTIONS: SingleOption[] = METHODS.map((m) => ({\n\tlabel: m,\n\tvalue: m,\n}));\n\n/**\n * Keep the Request / Response bodies valid JSON: wrap the picked token in\n * quotes (`\"email\": \"{{variable:customer.email}}\"`) — unless the `@` was typed\n * inside a string literal already (odd number of unescaped `\"` before it, e.g.\n * `\"Bearer @`), where the bare token interpolates into the existing string.\n */\nexport const jsonQuoteToken = (\n\ttoken: string,\n\tctx: { textBefore: string },\n): string => {\n\tconst quotes = ctx.textBefore.match(/(?<!\\\\)\"/g)?.length ?? 0;\n\treturn quotes % 2 === 1 ? token : `\"${token}\"`;\n};\n\n/**\n * Right-side drawer to configure a \"Rest API\" tool: the endpoint the agent can\n * call, plus a JSON request-body template and a sample response. Mount it fresh\n * per open (key it) so `initial` seeds the state. Built on the shared `SideModal`\n * shell and the BikEditor JSON body mode for the Request / Response editors.\n */\nexport const RestApiToolPanel: React.FC<RestApiToolPanelProps> = ({\n\tonClose,\n\tonSave,\n\tinitial,\n\tonImprove,\n\tcharLimits = AGENT_CHAR_LIMITS,\n\tzIndex,\n\texistingNames = [],\n\tvariablesData,\n}) => {\n\tconst [name, setName] = useState(initial?.name ?? '');\n\t// `@`-picked variables insert into the JSON editors at their own cursor.\n\tconst requestEditorRef = useRef<BikEditorRef>(null);\n\tconst responseEditorRef = useRef<BikEditorRef>(null);\n\tconst [instructions, setInstructions] = useState(initial?.instructions ?? '');\n\t// New tools start with the scheme pre-filled so the user only types the host.\n\tconst [url, setUrl] = useState(initial?.url ?? 'https://');\n\tconst [method, setMethod] = useState<RestApiMethod>(\n\t\tinitial?.method ?? 'POST',\n\t);\n\tconst [headers, setHeaders] = useState<RestApiHeader[]>(\n\t\tinitial?.headers ?? [{ key: '', value: '' }],\n\t);\n\tconst [requestBody, setRequestBody] = useState(initial?.requestBody ?? '');\n\tconst [responseSample, setResponseSample] = useState(\n\t\tinitial?.responseSample ?? '',\n\t);\n\tconst [saving, setSaving] = useState(false);\n\n\tconst patchHeader = (i: number, patch: Partial<RestApiHeader>) =>\n\t\tsetHeaders((prev) =>\n\t\t\tprev.map((h, idx) => (idx === i ? { ...h, ...patch } : h)),\n\t\t);\n\tconst addHeader = () =>\n\t\tsetHeaders((prev) => [...prev, { key: '', value: '' }]);\n\tconst removeHeader = (i: number) =>\n\t\tsetHeaders((prev) => prev.filter((_, idx) => idx !== i));\n\n\tconst nameTrimmed = name.trim();\n\t// Case-insensitive: two tools can't share a name (the LLM references them by it).\n\tconst isDuplicateName =\n\t\tnameTrimmed.length > 0 &&\n\t\texistingNames.some(\n\t\t\t(n) => n.trim().toLowerCase() === nameTrimmed.toLowerCase(),\n\t\t);\n\tconst canSave =\n\t\tnameTrimmed.length > 0 && url.trim().length > 0 && !isDuplicateName;\n\n\tconst handleSave = async () => {\n\t\tif (!canSave || saving) {\n\t\t\treturn;\n\t\t}\n\t\tconst config: RestApiToolConfig = {\n\t\t\tid: initial?.id ?? `restapi_${Date.now().toString(36)}`,\n\t\t\tname: name.trim(),\n\t\t\tinstructions,\n\t\t\turl: url.trim(),\n\t\t\tmethod,\n\t\t\t// Drop fully-empty header rows.\n\t\t\theaders: headers.filter((h) => h.key.trim() || h.value.trim()),\n\t\t\trequestBody,\n\t\t\tresponseSample,\n\t\t};\n\t\tconst result = onSave(config);\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetSaving(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} finally {\n\t\t\t\tsetSaving(false);\n\t\t\t}\n\t\t}\n\t};\n\n\treturn (\n\t\t<SideModal\n\t\t\theader=\"Rest API\"\n\t\t\tcloseOnEscapeKey={false}\n\t\t\tzIndex={zIndex}\n\t\t\theaderCustomComponent={\n\t\t\t\t<DrawerHeaderText\n\t\t\t\t\ttitle=\"Rest API\"\n\t\t\t\t\tsubtitle=\"Connect to any API endpoint. Define the request and a sample response for the agent to reference.\"\n\t\t\t\t/>\n\t\t\t}\n\t\t\twidth=\"431px\"\n\t\t\theaderStyle={DRAWER_HEADER_STYLE}\n\t\t\tbodyStyle={DRAWER_BODY_STYLE}\n\t\t\tonClose={onClose}\n\t\t\tsaveButtonProps={{\n\t\t\t\t'data-test': 'restapi-save',\n\t\t\t\tbuttonText: 'Save',\n\t\t\t\tbuttonType: 'primary',\n\t\t\t\tsize: 'small',\n\t\t\t\tdisabled: !canSave,\n\t\t\t\tisLoading: saving,\n\t\t\t\tonClick: handleSave,\n\t\t\t}}\n\t\t\tcancelButtonProps={{\n\t\t\t\t'data-test': 'restapi-cancel',\n\t\t\t\tbuttonText: 'Cancel',\n\t\t\t\tbuttonType: 'tertiaryGray',\n\t\t\t\tsize: 'small',\n\t\t\t\tonClick: onClose,\n\t\t\t}}\n\t\t>\n\t\t\t<Input\n\t\t\t\tdata-test=\"restapi-name\"\n\t\t\t\tvariant=\"small\"\n\t\t\t\tlabelText=\"Name\"\n\t\t\t\tlabelTextBold\n\t\t\t\tplaceholder=\"Enter action name\"\n\t\t\t\tvalue={name}\n\t\t\t\tmaxCharLimit={charLimits.name}\n\t\t\t\tstate={isDuplicateName ? 'invalid' : undefined}\n\t\t\t\terrorMessage={\n\t\t\t\t\tisDuplicateName ? 'A tool with this name already exists' : undefined\n\t\t\t\t}\n\t\t\t\tonChangeText={setName}\n\t\t\t/>\n\n\t\t\t<ToolInstructionsField\n\t\t\t\tdata-test=\"restapi-instructions\"\n\t\t\t\tlabel=\"Instructions\"\n\t\t\t\tvalue={instructions}\n\t\t\t\tonChange={setInstructions}\n\t\t\t\tmaxLength={charLimits.instructions}\n\t\t\t\tplaceholder=\"Describe how should the LLM generate the rest API\"\n\t\t\t\tonImprove={onImprove}\n\t\t\t\tvariablesData={variablesData}\n\t\t\t/>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<VariableTriggerArea\n\t\t\t\t\taddDataButton\n\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\tonInsert={(token, caret) =>\n\t\t\t\t\t\tsetUrl((u) => {\n\t\t\t\t\t\t\tconst at = caret ?? u.length;\n\t\t\t\t\t\t\treturn `${u.slice(0, at)}${token}${u.slice(at)}`;\n\t\t\t\t\t\t})\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<Input\n\t\t\t\t\t\tdata-test=\"restapi-url\"\n\t\t\t\t\t\tvariant=\"small\"\n\t\t\t\t\t\tlabelText=\"Request URL\"\n\t\t\t\t\t\tlabelTextBold\n\t\t\t\t\t\tplaceholder=\"https://\"\n\t\t\t\t\t\ttype=\"url\"\n\t\t\t\t\t\tvalue={url}\n\t\t\t\t\t\tonChangeText={setUrl}\n\t\t\t\t\t/>\n\t\t\t\t</VariableTriggerArea>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>HTTP method</TitleSmall>\n\t\t\t\t<Dropdown\n\t\t\t\t\tdata-test=\"restapi-method\"\n\t\t\t\t\tsize=\"small\"\n\t\t\t\t\twidth=\"100%\"\n\t\t\t\t\tdropdownWidth=\"399px\"\n\t\t\t\t\toptions={METHOD_OPTIONS}\n\t\t\t\t\tdefaultOptions={[{ label: method, value: method }]}\n\t\t\t\t\tonSelect={(opt) => {\n\t\t\t\t\t\tconst v = unwrapDropdownValue(opt);\n\t\t\t\t\t\tif (v) {\n\t\t\t\t\t\t\tsetMethod(v as RestApiMethod);\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t/>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Headers</TitleSmall>\n\t\t\t\t{headers.map((h, i) => (\n\t\t\t\t\t// eslint-disable-next-line react/no-array-index-key\n\t\t\t\t\t<HeaderRow key={i} data-test={`restapi-header-${i}`}>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\tvariant=\"small\"\n\t\t\t\t\t\t\thideInputHeader\n\t\t\t\t\t\t\tplaceholder=\"Enter name\"\n\t\t\t\t\t\t\tvalue={h.key}\n\t\t\t\t\t\t\tonChangeText={(v) => patchHeader(i, { key: v })}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<VariableTriggerArea\n\t\t\t\t\t\t\taddDataButton\n\t\t\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\t\t\tonInsert={(token, caret) => {\n\t\t\t\t\t\t\t\tconst at = caret ?? h.value.length;\n\t\t\t\t\t\t\t\tpatchHeader(i, {\n\t\t\t\t\t\t\t\t\tvalue: `${h.value.slice(0, at)}${token}${h.value.slice(at)}`,\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\t\tvariant=\"small\"\n\t\t\t\t\t\t\t\thideInputHeader\n\t\t\t\t\t\t\t\tplaceholder=\"Enter value\"\n\t\t\t\t\t\t\t\tvalue={h.value}\n\t\t\t\t\t\t\t\tonChangeText={(v) => patchHeader(i, { value: v })}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</VariableTriggerArea>\n\t\t\t\t\t\t<IconBtn\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\taria-label=\"Remove header\"\n\t\t\t\t\t\t\tdata-test={`restapi-header-remove-${i}`}\n\t\t\t\t\t\t\tonClick={() => removeHeader(i)}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<DeleteIcon\n\t\t\t\t\t\t\t\twidth={16}\n\t\t\t\t\t\t\t\theight={16}\n\t\t\t\t\t\t\t\tcolor={COLORS.content.secondary}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</IconBtn>\n\t\t\t\t\t</HeaderRow>\n\t\t\t\t))}\n\t\t\t\t<AddHeaderRow>\n\t\t\t\t\t<Button\n\t\t\t\t\t\tdata-test=\"restapi-add-header\"\n\t\t\t\t\t\tbuttonType=\"dashRegular\"\n\t\t\t\t\t\tsize=\"small\"\n\t\t\t\t\t\tLeadingIcon={PlusIcon}\n\t\t\t\t\t\tbuttonText=\"Add header\"\n\t\t\t\t\t\tonClick={addHeader}\n\t\t\t\t\t/>\n\t\t\t\t</AddHeaderRow>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Request </TitleSmall>\n\t\t\t\t<VariableTriggerArea\n\t\t\t\t\taddDataButton\n\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\ttransformToken={jsonQuoteToken}\n\t\t\t\t\tonInsert={(token) =>\n\t\t\t\t\t\trequestEditorRef.current?.insertInlineContent(token)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<BikEditor\n\t\t\t\t\t\tref={requestEditorRef}\n\t\t\t\t\t\tfeatures={{ jsonMode: true }}\n\t\t\t\t\t\tinitialContent={requestBody}\n\t\t\t\t\t\tstyle={JsonFieldBox}\n\t\t\t\t\t\tplaceholder=\"Type or paste JSON here\"\n\t\t\t\t\t\tonChange={(c) => setRequestBody(c.text)}\n\t\t\t\t\t\tminHeight=\"120px\"\n\t\t\t\t\t\tmaxHeight=\"240px\"\n\t\t\t\t\t/>\n\t\t\t\t</VariableTriggerArea>\n\t\t\t</FieldBlock>\n\n\t\t\t<FieldBlock>\n\t\t\t\t<TitleSmall color={COLORS.content.primary}>Response </TitleSmall>\n\t\t\t\t<VariableTriggerArea\n\t\t\t\t\taddDataButton\n\t\t\t\t\tvariablesData={variablesData}\n\t\t\t\t\ttransformToken={jsonQuoteToken}\n\t\t\t\t\tonInsert={(token) =>\n\t\t\t\t\t\tresponseEditorRef.current?.insertInlineContent(token)\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<BikEditor\n\t\t\t\t\t\tref={responseEditorRef}\n\t\t\t\t\t\tfeatures={{ jsonMode: true }}\n\t\t\t\t\t\tstyle={JsonFieldBox}\n\t\t\t\t\t\tinitialContent={responseSample}\n\t\t\t\t\t\tplaceholder=\"Type or paste JSON here\"\n\t\t\t\t\t\tonChange={(c) => setResponseSample(c.text)}\n\t\t\t\t\t\tminHeight=\"120px\"\n\t\t\t\t\t\tmaxHeight=\"240px\"\n\t\t\t\t\t/>\n\t\t\t\t</VariableTriggerArea>\n\t\t\t</FieldBlock>\n\t\t</SideModal>\n\t);\n};\n\nconst HeaderRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n`;\n\nconst AddHeaderRow = styled.div`\n\tdisplay: flex;\n`;\n\nconst IconBtn = styled.button`\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\tflex-shrink: 0;\n\twidth: 32px;\n\theight: 32px;\n\tborder: 1px solid ${COLORS.stroke.primary};\n\tborder-radius: 4px;\n\tbackground: ${COLORS.surface.standard};\n\tcursor: pointer;\n\n\t&:hover {\n\t\tborder-color: ${COLORS.content.secondary};\n\t}\n`;\n\nexport const JsonFieldBox = {\n\tborderRadius: '4px',\n\toverflow: 'hidden',\n};\n"],"names":["METHODS","METHOD_OPTIONS","m","jsonQuoteToken","token","ctx","RestApiToolPanel","onClose","onSave","initial","onImprove","charLimits","AGENT_CHAR_LIMITS","zIndex","existingNames","variablesData","name","setName","useState","requestEditorRef","useRef","responseEditorRef","instructions","setInstructions","url","setUrl","method","setMethod","headers","setHeaders","requestBody","setRequestBody","responseSample","setResponseSample","saving","setSaving","patchHeader","i","patch","prev","h","idx","addHeader","removeHeader","_","nameTrimmed","isDuplicateName","n","canSave","jsxs","SideModal","jsx","DrawerHeaderText","DRAWER_HEADER_STYLE","DRAWER_BODY_STYLE","config","result","Input","ToolInstructionsField","FieldBlock","VariableTriggerArea","caret","u","at","TitleSmall","COLORS","Dropdown","opt","v","unwrapDropdownValue","HeaderRow","IconBtn","DeleteIcon","AddHeaderRow","Button","PlusIcon","BikEditor","JsonFieldBox","c","styled"],"mappings":";;;;;;;;;;;;;;;;;;AAkDA,MAAMA,KAA2B,CAAC,OAAO,QAAQ,OAAO,SAAS,QAAQ,GACnEC,KAAiCD,GAAQ,IAAI,CAACE,OAAO;AAAA,EAC1D,OAAOA;AAAA,EACP,OAAOA;AACR,EAAE,GAQWC,IAAiB,CAC7BC,GACAC,OAEeA,E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B,cAAc;AAAA,EACd,UAAU;AACX;"}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import { jsx as o, jsxs as g } from "react/jsx-runtime";
|
|
2
|
-
import { useState as
|
|
2
|
+
import { useState as a } from "react";
|
|
3
3
|
import T from "styled-components";
|
|
4
4
|
import { TitleSmall as v } from "../../TypographyStyle.js";
|
|
5
5
|
import { COLORS as w } from "../../../constants/Theme.js";
|
|
6
|
-
import { FieldBlock as
|
|
7
|
-
import { MentionEditor as
|
|
6
|
+
import { FieldBlock as B, AiTextAreaShell as E, AiTextAreaInput as F } from "../AgentBuilder.styled.js";
|
|
7
|
+
import { MentionEditor as k } from "./MentionEditor.js";
|
|
8
8
|
import { Button as b } from "../../button/Button.js";
|
|
9
9
|
import j from "../../../icons/BIK AI specific/WandSparkles.js";
|
|
10
10
|
const q = ({
|
|
11
|
-
label:
|
|
11
|
+
label: m,
|
|
12
12
|
value: t,
|
|
13
13
|
onChange: e,
|
|
14
|
-
maxLength:
|
|
15
|
-
placeholder:
|
|
16
|
-
minHeight:
|
|
14
|
+
maxLength: l,
|
|
15
|
+
placeholder: d,
|
|
16
|
+
minHeight: c = "120px",
|
|
17
17
|
onImprove: i,
|
|
18
18
|
variablesData: p,
|
|
19
19
|
...r
|
|
20
20
|
}) => {
|
|
21
|
-
const [x, f] =
|
|
21
|
+
const [x, f] = a(!1), [n, u] = a(!1), [I, A] = a(0), h = (p?.length ?? 0) > 0, S = async () => {
|
|
22
22
|
if (!(!i || n || t.trim().length === 0)) {
|
|
23
23
|
u(!0);
|
|
24
24
|
try {
|
|
@@ -41,31 +41,32 @@ const q = ({
|
|
|
41
41
|
}
|
|
42
42
|
) }) : void 0;
|
|
43
43
|
return h ? /* @__PURE__ */ o(
|
|
44
|
-
|
|
44
|
+
k,
|
|
45
45
|
{
|
|
46
46
|
"data-test": r["data-test"],
|
|
47
|
-
label:
|
|
47
|
+
label: m,
|
|
48
48
|
value: t,
|
|
49
49
|
onChange: e,
|
|
50
|
-
maxLength:
|
|
51
|
-
placeholder:
|
|
52
|
-
minHeight:
|
|
50
|
+
maxLength: l,
|
|
51
|
+
placeholder: d,
|
|
52
|
+
minHeight: c,
|
|
53
53
|
resetKey: `improve-${I}`,
|
|
54
54
|
mentionItems: [],
|
|
55
55
|
tools: [],
|
|
56
56
|
variablesData: p,
|
|
57
|
+
addDataButton: !0,
|
|
57
58
|
action: y
|
|
58
59
|
}
|
|
59
|
-
) : /* @__PURE__ */ g(
|
|
60
|
-
/* @__PURE__ */ o(v, { color: w.content.primary, children:
|
|
61
|
-
/* @__PURE__ */ g(
|
|
60
|
+
) : /* @__PURE__ */ g(B, { children: [
|
|
61
|
+
/* @__PURE__ */ o(v, { color: w.content.primary, children: m }),
|
|
62
|
+
/* @__PURE__ */ g(E, { focused: x, minHeight: c, children: [
|
|
62
63
|
/* @__PURE__ */ o(
|
|
63
|
-
|
|
64
|
+
F,
|
|
64
65
|
{
|
|
65
66
|
"data-test": r["data-test"],
|
|
66
67
|
value: t,
|
|
67
|
-
placeholder:
|
|
68
|
-
maxLength:
|
|
68
|
+
placeholder: d,
|
|
69
|
+
maxLength: l,
|
|
69
70
|
onFocus: () => f(!0),
|
|
70
71
|
onBlur: () => f(!1),
|
|
71
72
|
onChange: (s) => e(s.target.value)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolInstructionsField.js","sources":["../../../../../src/components/agent-builder/components/ToolInstructionsField.tsx"],"sourcesContent":["import { WandSparkles } from '@src/icons';\nimport React, { useState } from 'react';\nimport styled from 'styled-components';\nimport { Button } from '@src/components/button';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport type { VariableListInterfaceV3 } from '../../variable-picker-v3/model';\nimport {\n\tAiTextAreaInput,\n\tAiTextAreaShell,\n\tFieldBlock,\n} from '../AgentBuilder.styled';\nimport { MentionEditor } from './MentionEditor';\n\ninterface ToolInstructionsFieldProps {\n\tlabel: string;\n\tvalue: string;\n\tonChange: (value: string) => void;\n\tmaxLength: number;\n\tplaceholder?: string;\n\tminHeight?: string;\n\t/** \"Improve with AI\" — resolves with rewritten text. Omit to hide the button. */\n\tonImprove?: (text: string) => Promise<string>;\n\t/**\n\t * Variable catalog. When non-empty the field upgrades from a plain textarea\n\t * to a variables-only `@` mention editor: typing `@` opens the variable\n\t * categories directly (Variables is the sole category, so the picker skips\n\t * the Tools / Sub-agent root), and picks render as chips persisted as\n\t * `{{variable:<name>}}` tokens.\n\t */\n\tvariablesData?: VariableListInterfaceV3[];\n\t'data-test'?: string;\n}\n\n/**\n * A labelled multiline field with an inline \"Improve with AI\" action pinned to\n * the bottom-left of the box (Figma: Rest API / Handover-to-email drawers). The\n * button is hidden when `onImprove` is omitted.\n */\nexport const ToolInstructionsField: React.FC<ToolInstructionsFieldProps> = ({\n\tlabel,\n\tvalue,\n\tonChange,\n\tmaxLength,\n\tplaceholder,\n\tminHeight = '120px',\n\tonImprove,\n\tvariablesData,\n\t...rest\n}) => {\n\tconst [focused, setFocused] = useState(false);\n\tconst [improving, setImproving] = useState(false);\n\t// Bumped when \"Improve with AI\" replaces the text externally — the mention\n\t// editor only reads `value` on (re)mount, so it must be remounted.\n\tconst [editorEpoch, setEditorEpoch] = useState(0);\n\n\tconst withVariables = (variablesData?.length ?? 0) > 0;\n\n\tconst handleImprove = async () => {\n\t\tif (!onImprove || improving || value.trim().length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tsetImproving(true);\n\t\ttry {\n\t\t\tonChange(await onImprove(value));\n\t\t\tif (withVariables) {\n\t\t\t\tsetEditorEpoch((e) => e + 1);\n\t\t\t}\n\t\t} finally {\n\t\t\tsetImproving(false);\n\t\t}\n\t};\n\n\tconst improveAction = onImprove ? (\n\t\t<ImproveRow>\n\t\t\t<Button\n\t\t\t\tdata-test={`${rest['data-test'] ?? 'tool'}-improve`}\n\t\t\t\tbuttonType=\"ai\"\n\t\t\t\tsize=\"small\"\n\t\t\t\tLeadingIcon={WandSparkles}\n\t\t\t\tbuttonText=\"Improve with AI\"\n\t\t\t\tisLoading={improving}\n\t\t\t\tdisabled={improving || value.trim().length === 0}\n\t\t\t\tonClick={handleImprove}\n\t\t\t/>\n\t\t</ImproveRow>\n\t) : undefined;\n\n\t// Variables enabled → the mention-editor variant. `mentionItems` / tool\n\t// hooks stay empty so Variables is the picker's ONLY category and `@` lands\n\t// straight in the variable list.\n\tif (withVariables) {\n\t\treturn (\n\t\t\t<MentionEditor\n\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\tlabel={label}\n\t\t\t\tvalue={value}\n\t\t\t\tonChange={onChange}\n\t\t\t\tmaxLength={maxLength}\n\t\t\t\tplaceholder={placeholder}\n\t\t\t\tminHeight={minHeight}\n\t\t\t\tresetKey={`improve-${editorEpoch}`}\n\t\t\t\tmentionItems={[]}\n\t\t\t\ttools={[]}\n\t\t\t\tvariablesData={variablesData}\n\t\t\t\taction={improveAction}\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<FieldBlock>\n\t\t\t<TitleSmall color={COLORS.content.primary}>{label}</TitleSmall>\n\t\t\t<AiTextAreaShell focused={focused} minHeight={minHeight}>\n\t\t\t\t<AiTextAreaInput\n\t\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tmaxLength={maxLength}\n\t\t\t\t\tonFocus={() => setFocused(true)}\n\t\t\t\t\tonBlur={() => setFocused(false)}\n\t\t\t\t\tonChange={(e) => onChange(e.target.value)}\n\t\t\t\t/>\n\t\t\t\t{improveAction}\n\t\t\t</AiTextAreaShell>\n\t\t</FieldBlock>\n\t);\n};\n\nconst ImproveRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n`;\n"],"names":["ToolInstructionsField","label","value","onChange","maxLength","placeholder","minHeight","onImprove","variablesData","rest","focused","setFocused","useState","improving","setImproving","editorEpoch","setEditorEpoch","withVariables","handleImprove","e","improveAction","jsx","ImproveRow","Button","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A,MACA,WAAAC;AAAA,MACA,aAAAC;AAAA,MACA,WAAAC;AAAA,MACA,UAAU,WAAWS,CAAW;AAAA,MAChC,cAAc,CAAA;AAAA,MACd,OAAO,CAAA;AAAA,MACP,eAAAP;AAAA,
|
|
1
|
+
{"version":3,"file":"ToolInstructionsField.js","sources":["../../../../../src/components/agent-builder/components/ToolInstructionsField.tsx"],"sourcesContent":["import { WandSparkles } from '@src/icons';\nimport React, { useState } from 'react';\nimport styled from 'styled-components';\nimport { Button } from '@src/components/button';\nimport { TitleSmall } from '@src/components/TypographyStyle';\nimport { COLORS } from '@src/constants/Theme';\nimport type { VariableListInterfaceV3 } from '../../variable-picker-v3/model';\nimport {\n\tAiTextAreaInput,\n\tAiTextAreaShell,\n\tFieldBlock,\n} from '../AgentBuilder.styled';\nimport { MentionEditor } from './MentionEditor';\n\ninterface ToolInstructionsFieldProps {\n\tlabel: string;\n\tvalue: string;\n\tonChange: (value: string) => void;\n\tmaxLength: number;\n\tplaceholder?: string;\n\tminHeight?: string;\n\t/** \"Improve with AI\" — resolves with rewritten text. Omit to hide the button. */\n\tonImprove?: (text: string) => Promise<string>;\n\t/**\n\t * Variable catalog. When non-empty the field upgrades from a plain textarea\n\t * to a variables-only `@` mention editor: typing `@` opens the variable\n\t * categories directly (Variables is the sole category, so the picker skips\n\t * the Tools / Sub-agent root), and picks render as chips persisted as\n\t * `{{variable:<name>}}` tokens.\n\t */\n\tvariablesData?: VariableListInterfaceV3[];\n\t'data-test'?: string;\n}\n\n/**\n * A labelled multiline field with an inline \"Improve with AI\" action pinned to\n * the bottom-left of the box (Figma: Rest API / Handover-to-email drawers). The\n * button is hidden when `onImprove` is omitted.\n */\nexport const ToolInstructionsField: React.FC<ToolInstructionsFieldProps> = ({\n\tlabel,\n\tvalue,\n\tonChange,\n\tmaxLength,\n\tplaceholder,\n\tminHeight = '120px',\n\tonImprove,\n\tvariablesData,\n\t...rest\n}) => {\n\tconst [focused, setFocused] = useState(false);\n\tconst [improving, setImproving] = useState(false);\n\t// Bumped when \"Improve with AI\" replaces the text externally — the mention\n\t// editor only reads `value` on (re)mount, so it must be remounted.\n\tconst [editorEpoch, setEditorEpoch] = useState(0);\n\n\tconst withVariables = (variablesData?.length ?? 0) > 0;\n\n\tconst handleImprove = async () => {\n\t\tif (!onImprove || improving || value.trim().length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tsetImproving(true);\n\t\ttry {\n\t\t\tonChange(await onImprove(value));\n\t\t\tif (withVariables) {\n\t\t\t\tsetEditorEpoch((e) => e + 1);\n\t\t\t}\n\t\t} finally {\n\t\t\tsetImproving(false);\n\t\t}\n\t};\n\n\tconst improveAction = onImprove ? (\n\t\t<ImproveRow>\n\t\t\t<Button\n\t\t\t\tdata-test={`${rest['data-test'] ?? 'tool'}-improve`}\n\t\t\t\tbuttonType=\"ai\"\n\t\t\t\tsize=\"small\"\n\t\t\t\tLeadingIcon={WandSparkles}\n\t\t\t\tbuttonText=\"Improve with AI\"\n\t\t\t\tisLoading={improving}\n\t\t\t\tdisabled={improving || value.trim().length === 0}\n\t\t\t\tonClick={handleImprove}\n\t\t\t/>\n\t\t</ImproveRow>\n\t) : undefined;\n\n\t// Variables enabled → the mention-editor variant. `mentionItems` / tool\n\t// hooks stay empty so Variables is the picker's ONLY category and `@` lands\n\t// straight in the variable list.\n\tif (withVariables) {\n\t\treturn (\n\t\t\t<MentionEditor\n\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\tlabel={label}\n\t\t\t\tvalue={value}\n\t\t\t\tonChange={onChange}\n\t\t\t\tmaxLength={maxLength}\n\t\t\t\tplaceholder={placeholder}\n\t\t\t\tminHeight={minHeight}\n\t\t\t\tresetKey={`improve-${editorEpoch}`}\n\t\t\t\tmentionItems={[]}\n\t\t\t\ttools={[]}\n\t\t\t\tvariablesData={variablesData}\n\t\t\t\t// Drawers get the same focused-field \"+ Add data\" affordance as the\n\t\t\t\t// main Step-3 editors.\n\t\t\t\taddDataButton\n\t\t\t\taction={improveAction}\n\t\t\t/>\n\t\t);\n\t}\n\n\treturn (\n\t\t<FieldBlock>\n\t\t\t<TitleSmall color={COLORS.content.primary}>{label}</TitleSmall>\n\t\t\t<AiTextAreaShell focused={focused} minHeight={minHeight}>\n\t\t\t\t<AiTextAreaInput\n\t\t\t\t\tdata-test={rest['data-test']}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tplaceholder={placeholder}\n\t\t\t\t\tmaxLength={maxLength}\n\t\t\t\t\tonFocus={() => setFocused(true)}\n\t\t\t\t\tonBlur={() => setFocused(false)}\n\t\t\t\t\tonChange={(e) => onChange(e.target.value)}\n\t\t\t\t/>\n\t\t\t\t{improveAction}\n\t\t\t</AiTextAreaShell>\n\t\t</FieldBlock>\n\t);\n};\n\nconst ImproveRow = styled.div`\n\tdisplay: flex;\n\talign-items: center;\n`;\n"],"names":["ToolInstructionsField","label","value","onChange","maxLength","placeholder","minHeight","onImprove","variablesData","rest","focused","setFocused","useState","improving","setImproving","editorEpoch","setEditorEpoch","withVariables","handleImprove","e","improveAction","jsx","ImproveRow","Button","WandSparkles","MentionEditor","FieldBlock","TitleSmall","COLORS","jsxs","AiTextAreaShell","AiTextAreaInput","styled"],"mappings":";;;;;;;;;AAuCO,MAAMA,IAA8D,CAAC;AAAA,EAC3E,OAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,WAAAC,IAAY;AAAA,EACZ,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,GAAGC;AACJ,MAAM;AACL,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAWC,CAAY,IAAIF,EAAS,EAAK,GAG1C,CAACG,GAAaC,CAAc,IAAIJ,EAAS,CAAC,GAE1CK,KAAiBT,GAAe,UAAU,KAAK,GAE/CU,IAAgB,YAAY;AACjC,QAAI,GAACX,KAAaM,KAAaX,EAAM,KAAA,EAAO,WAAW,IAGvD;AAAA,MAAAY,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