@mieweb/q 1.0.0

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.
@@ -0,0 +1,1903 @@
1
+ import { jsxs as x, jsx as r } from "react/jsx-runtime";
2
+ import { useRef as B, useMemo as De, useCallback as W, useEffect as H, useState as E } from "react";
3
+ import se from "js-yaml";
4
+ import { Download as be, Copy as Be, Plus as ue, Trash2 as de, Settings as He, Wrench as Je, Code as We, Send as Ke, Pencil as Ye, Upload as $e, RotateCcw as Qe, ArrowLeft as Ge } from "lucide-react";
5
+ import { Card as we, Button as j, Input as Z, Select as te, Checkbox as ie, Tabs as Ze, TabsList as Xe, TabsTrigger as re, Alert as Me, AlertDescription as en } from "@mieweb/ui";
6
+ import { QuestionnaireRenderer as nn } from "@mieweb/forms-renderer";
7
+ import tn from "@monaco-editor/react";
8
+ const rn = "mieforms-v1.0", on = "Agent Configuration", ln = [
9
+ {
10
+ id: "sec-basic",
11
+ fieldType: "section",
12
+ title: "Basic Info",
13
+ fields: [
14
+ {
15
+ id: "_id",
16
+ fieldType: "text",
17
+ question: "Config ID (_id)",
18
+ answer: "",
19
+ required: !1
20
+ },
21
+ {
22
+ id: "name",
23
+ fieldType: "text",
24
+ question: "Name",
25
+ answer: "New Agent Config",
26
+ required: !1
27
+ },
28
+ {
29
+ id: "timezone",
30
+ fieldType: "dropdown",
31
+ question: "Timezone",
32
+ answer: "America/New_York",
33
+ required: !1,
34
+ options: [
35
+ {
36
+ id: "tz-ny",
37
+ label: "America/New_York",
38
+ value: "America/New_York"
39
+ },
40
+ {
41
+ id: "tz-chi",
42
+ label: "America/Chicago",
43
+ value: "America/Chicago"
44
+ },
45
+ {
46
+ id: "tz-den",
47
+ label: "America/Denver",
48
+ value: "America/Denver"
49
+ },
50
+ {
51
+ id: "tz-la",
52
+ label: "America/Los_Angeles",
53
+ value: "America/Los_Angeles"
54
+ },
55
+ {
56
+ id: "tz-hon",
57
+ label: "Pacific/Honolulu",
58
+ value: "Pacific/Honolulu"
59
+ },
60
+ {
61
+ id: "tz-anc",
62
+ label: "America/Anchorage",
63
+ value: "America/Anchorage"
64
+ },
65
+ {
66
+ id: "tz-phx",
67
+ label: "America/Phoenix",
68
+ value: "America/Phoenix"
69
+ }
70
+ ]
71
+ },
72
+ {
73
+ id: "description",
74
+ fieldType: "text",
75
+ question: "Description",
76
+ answer: "Agent Assistant Description",
77
+ required: !1
78
+ }
79
+ ]
80
+ },
81
+ {
82
+ id: "sec-telephony",
83
+ fieldType: "section",
84
+ title: "Telephony Settings",
85
+ fields: [
86
+ {
87
+ id: "twilio.phoneNumber",
88
+ fieldType: "text",
89
+ question: "Twilio Phone Number",
90
+ answer: "",
91
+ required: !1
92
+ },
93
+ {
94
+ id: "twilio.accountSid",
95
+ fieldType: "text",
96
+ question: "Twilio Account SID",
97
+ answer: "",
98
+ required: !1
99
+ },
100
+ {
101
+ id: "twilio.authToken",
102
+ fieldType: "text",
103
+ question: "Twilio Auth Token",
104
+ answer: "",
105
+ required: !1
106
+ }
107
+ ]
108
+ },
109
+ {
110
+ id: "sec-office",
111
+ fieldType: "section",
112
+ title: "Office Hours",
113
+ fields: [
114
+ {
115
+ id: "officeOpeningTime",
116
+ fieldType: "dropdown",
117
+ question: "Opening Time (Hour)",
118
+ answer: "8",
119
+ required: !1,
120
+ configType: "number",
121
+ options: [
122
+ {
123
+ id: "h0",
124
+ label: "0:00",
125
+ value: "0"
126
+ },
127
+ {
128
+ id: "h1",
129
+ label: "1:00",
130
+ value: "1"
131
+ },
132
+ {
133
+ id: "h2",
134
+ label: "2:00",
135
+ value: "2"
136
+ },
137
+ {
138
+ id: "h3",
139
+ label: "3:00",
140
+ value: "3"
141
+ },
142
+ {
143
+ id: "h4",
144
+ label: "4:00",
145
+ value: "4"
146
+ },
147
+ {
148
+ id: "h5",
149
+ label: "5:00",
150
+ value: "5"
151
+ },
152
+ {
153
+ id: "h6",
154
+ label: "6:00",
155
+ value: "6"
156
+ },
157
+ {
158
+ id: "h7",
159
+ label: "7:00",
160
+ value: "7"
161
+ },
162
+ {
163
+ id: "h8",
164
+ label: "8:00",
165
+ value: "8"
166
+ },
167
+ {
168
+ id: "h9",
169
+ label: "9:00",
170
+ value: "9"
171
+ },
172
+ {
173
+ id: "h10",
174
+ label: "10:00",
175
+ value: "10"
176
+ },
177
+ {
178
+ id: "h11",
179
+ label: "11:00",
180
+ value: "11"
181
+ },
182
+ {
183
+ id: "h12",
184
+ label: "12:00",
185
+ value: "12"
186
+ },
187
+ {
188
+ id: "h13",
189
+ label: "13:00",
190
+ value: "13"
191
+ },
192
+ {
193
+ id: "h14",
194
+ label: "14:00",
195
+ value: "14"
196
+ },
197
+ {
198
+ id: "h15",
199
+ label: "15:00",
200
+ value: "15"
201
+ },
202
+ {
203
+ id: "h16",
204
+ label: "16:00",
205
+ value: "16"
206
+ },
207
+ {
208
+ id: "h17",
209
+ label: "17:00",
210
+ value: "17"
211
+ },
212
+ {
213
+ id: "h18",
214
+ label: "18:00",
215
+ value: "18"
216
+ },
217
+ {
218
+ id: "h19",
219
+ label: "19:00",
220
+ value: "19"
221
+ },
222
+ {
223
+ id: "h20",
224
+ label: "20:00",
225
+ value: "20"
226
+ },
227
+ {
228
+ id: "h21",
229
+ label: "21:00",
230
+ value: "21"
231
+ },
232
+ {
233
+ id: "h22",
234
+ label: "22:00",
235
+ value: "22"
236
+ },
237
+ {
238
+ id: "h23",
239
+ label: "23:00",
240
+ value: "23"
241
+ }
242
+ ]
243
+ },
244
+ {
245
+ id: "officeClosingTime",
246
+ fieldType: "dropdown",
247
+ question: "Closing Time (Hour)",
248
+ answer: "17",
249
+ required: !1,
250
+ configType: "number",
251
+ options: [
252
+ {
253
+ id: "h0",
254
+ label: "0:00",
255
+ value: "0"
256
+ },
257
+ {
258
+ id: "h1",
259
+ label: "1:00",
260
+ value: "1"
261
+ },
262
+ {
263
+ id: "h2",
264
+ label: "2:00",
265
+ value: "2"
266
+ },
267
+ {
268
+ id: "h3",
269
+ label: "3:00",
270
+ value: "3"
271
+ },
272
+ {
273
+ id: "h4",
274
+ label: "4:00",
275
+ value: "4"
276
+ },
277
+ {
278
+ id: "h5",
279
+ label: "5:00",
280
+ value: "5"
281
+ },
282
+ {
283
+ id: "h6",
284
+ label: "6:00",
285
+ value: "6"
286
+ },
287
+ {
288
+ id: "h7",
289
+ label: "7:00",
290
+ value: "7"
291
+ },
292
+ {
293
+ id: "h8",
294
+ label: "8:00",
295
+ value: "8"
296
+ },
297
+ {
298
+ id: "h9",
299
+ label: "9:00",
300
+ value: "9"
301
+ },
302
+ {
303
+ id: "h10",
304
+ label: "10:00",
305
+ value: "10"
306
+ },
307
+ {
308
+ id: "h11",
309
+ label: "11:00",
310
+ value: "11"
311
+ },
312
+ {
313
+ id: "h12",
314
+ label: "12:00",
315
+ value: "12"
316
+ },
317
+ {
318
+ id: "h13",
319
+ label: "13:00",
320
+ value: "13"
321
+ },
322
+ {
323
+ id: "h14",
324
+ label: "14:00",
325
+ value: "14"
326
+ },
327
+ {
328
+ id: "h15",
329
+ label: "15:00",
330
+ value: "15"
331
+ },
332
+ {
333
+ id: "h16",
334
+ label: "16:00",
335
+ value: "16"
336
+ },
337
+ {
338
+ id: "h17",
339
+ label: "17:00",
340
+ value: "17"
341
+ },
342
+ {
343
+ id: "h18",
344
+ label: "18:00",
345
+ value: "18"
346
+ },
347
+ {
348
+ id: "h19",
349
+ label: "19:00",
350
+ value: "19"
351
+ },
352
+ {
353
+ id: "h20",
354
+ label: "20:00",
355
+ value: "20"
356
+ },
357
+ {
358
+ id: "h21",
359
+ label: "21:00",
360
+ value: "21"
361
+ },
362
+ {
363
+ id: "h22",
364
+ label: "22:00",
365
+ value: "22"
366
+ },
367
+ {
368
+ id: "h23",
369
+ label: "23:00",
370
+ value: "23"
371
+ }
372
+ ]
373
+ },
374
+ {
375
+ id: "afterHoursNotice",
376
+ fieldType: "longtext",
377
+ question: "After Hours Notice",
378
+ answer: "Our office is currently closed.",
379
+ required: !1
380
+ },
381
+ {
382
+ id: "officeHoursHumanNumber",
383
+ fieldType: "text",
384
+ question: "Human Handover Number",
385
+ answer: "",
386
+ required: !1
387
+ }
388
+ ]
389
+ },
390
+ {
391
+ id: "sec-webchart",
392
+ fieldType: "section",
393
+ title: "WebChart Integration",
394
+ fields: [
395
+ {
396
+ id: "webchart.url",
397
+ fieldType: "text",
398
+ question: "WebChart URL",
399
+ answer: "",
400
+ required: !1
401
+ },
402
+ {
403
+ id: "webchart.username",
404
+ fieldType: "text",
405
+ question: "WebChart Username",
406
+ answer: "",
407
+ required: !1
408
+ },
409
+ {
410
+ id: "webchart.password",
411
+ fieldType: "text",
412
+ question: "WebChart Password",
413
+ answer: "",
414
+ required: !1
415
+ },
416
+ {
417
+ id: "defaultServiceLocation",
418
+ fieldType: "text",
419
+ question: "Default Service Location",
420
+ answer: "",
421
+ required: !1
422
+ },
423
+ {
424
+ id: "defaultPatientId",
425
+ fieldType: "text",
426
+ question: "Default Patient ID",
427
+ answer: "",
428
+ required: !1,
429
+ configType: "number"
430
+ },
431
+ {
432
+ id: "transcript_doc_type",
433
+ fieldType: "text",
434
+ question: "Transcript Doc Type",
435
+ answer: "",
436
+ required: !1
437
+ },
438
+ {
439
+ id: "defaultPhysicianId",
440
+ fieldType: "text",
441
+ question: "Default Physician ID",
442
+ answer: "",
443
+ required: !1,
444
+ configType: "number"
445
+ },
446
+ {
447
+ id: "userId",
448
+ fieldType: "text",
449
+ question: "User ID",
450
+ answer: "",
451
+ required: !1
452
+ },
453
+ {
454
+ id: "visitType",
455
+ fieldType: "text",
456
+ question: "Visit Type",
457
+ answer: "",
458
+ required: !1
459
+ }
460
+ ]
461
+ },
462
+ {
463
+ id: "sec-audio",
464
+ fieldType: "section",
465
+ title: "Audio Configuration",
466
+ fields: [
467
+ {
468
+ id: "elevenLabsPronunciationDictionaries",
469
+ fieldType: "text",
470
+ question: "ElevenLabs Pronunciation Dictionary IDs (comma-separated)",
471
+ answer: "",
472
+ required: !1,
473
+ configTransform: "elevenLabsDictIds"
474
+ },
475
+ {
476
+ id: "elevenLabsPronunciationDictionaries__versions",
477
+ fieldType: "text",
478
+ question: "ElevenLabs Pronunciation Dictionary Version IDs (comma-separated)",
479
+ answer: "",
480
+ required: !1,
481
+ configTransform: "elevenLabsDictVersions"
482
+ }
483
+ ]
484
+ },
485
+ {
486
+ id: "sec-agent",
487
+ fieldType: "section",
488
+ title: "Agent Specific Info",
489
+ fields: [
490
+ {
491
+ id: "welcome",
492
+ fieldType: "longtext",
493
+ question: "Welcome Message",
494
+ answer: "Thank you for calling. How can I help you today?",
495
+ required: !1
496
+ },
497
+ {
498
+ id: "systemPrompt",
499
+ fieldType: "longtext",
500
+ question: "System Prompt",
501
+ answer: "You are a helpful AI assistant.",
502
+ required: !1
503
+ },
504
+ {
505
+ id: "disabledGenericTools",
506
+ fieldType: "check",
507
+ question: "Enabled Generic Tools",
508
+ answer: [],
509
+ required: !1,
510
+ configTransform: "genericToolsInvert",
511
+ options: [
512
+ {
513
+ id: "gt-hangup",
514
+ label: "force_hangup_bad_call",
515
+ value: "force_hangup_bad_call"
516
+ },
517
+ {
518
+ id: "gt-birthdate",
519
+ label: "validate_birth_date",
520
+ value: "validate_birth_date"
521
+ },
522
+ {
523
+ id: "gt-goodbye",
524
+ label: "thanks_for_calling_goodbye",
525
+ value: "thanks_for_calling_goodbye"
526
+ },
527
+ {
528
+ id: "gt-human",
529
+ label: "connect_to_a_human",
530
+ value: "connect_to_a_human"
531
+ },
532
+ {
533
+ id: "gt-multiple",
534
+ label: "handle_multiple_patients",
535
+ value: "handle_multiple_patients"
536
+ },
537
+ {
538
+ id: "gt-schedule",
539
+ label: "schedule_call_later",
540
+ value: "schedule_call_later"
541
+ },
542
+ {
543
+ id: "gt-objective",
544
+ label: "mark_objective_complete",
545
+ value: "mark_objective_complete"
546
+ }
547
+ ]
548
+ }
549
+ ]
550
+ }
551
+ ], X = {
552
+ schemaType: rn,
553
+ title: on,
554
+ fields: ln
555
+ };
556
+ function Te(e) {
557
+ const t = [];
558
+ for (const n of e || [])
559
+ n.fieldType === "section" && Array.isArray(n.fields) ? t.push(...Te(n.fields)) : t.push(n);
560
+ return t;
561
+ }
562
+ function an(e, t) {
563
+ return t.split(".").reduce(function(n, i) {
564
+ return n ? n[i] : void 0;
565
+ }, e);
566
+ }
567
+ function sn(e, t) {
568
+ const n = Te((t || X).fields), i = [];
569
+ for (const a of n) {
570
+ if (!a.id || a.id.startsWith("sec-") || !a.required) continue;
571
+ const o = an(e, a.id);
572
+ (o == null || o === "") && i.push(`${a.text || a.question || a.id} is required`);
573
+ }
574
+ return i;
575
+ }
576
+ function fe(e) {
577
+ return se.dump(e, {
578
+ lineWidth: -1,
579
+ forceQuotes: !1,
580
+ quotingType: '"',
581
+ noCompatMode: !0,
582
+ styles: { "!!null": "empty" },
583
+ replacer: function(t, n) {
584
+ return n === "" ? null : n;
585
+ }
586
+ });
587
+ }
588
+ function Rn(e) {
589
+ return se.load(e);
590
+ }
591
+ function cn(e, t, n, i = "yaml", a = "") {
592
+ const o = sn(e);
593
+ if (o.length > 0) {
594
+ alert(`Please fix the following errors before downloading:
595
+
596
+ - ${o.join(`
597
+ - `)}`);
598
+ return;
599
+ }
600
+ const u = i === "json", c = u ? a : t, s = u ? "application/json" : "text/yaml", w = u ? "config.json" : "config.yaml";
601
+ if (n) {
602
+ n(c, i);
603
+ return;
604
+ }
605
+ const T = new Blob([c], { type: s }), v = URL.createObjectURL(T), b = document.createElement("a");
606
+ b.href = v, b.download = w, document.body.appendChild(b), b.click(), document.body.removeChild(b), URL.revokeObjectURL(v);
607
+ }
608
+ async function un(e) {
609
+ try {
610
+ await navigator.clipboard.writeText(e), alert("Copied to clipboard!");
611
+ } catch (t) {
612
+ console.error("Clipboard failed:", t), alert("Failed to copy to clipboard. Please check your browser permissions or try again.");
613
+ }
614
+ }
615
+ let ee;
616
+ const dn = new Uint8Array(16);
617
+ function fn() {
618
+ if (!ee && (ee = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto), !ee))
619
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
620
+ return ee(dn);
621
+ }
622
+ const q = [];
623
+ for (let e = 0; e < 256; ++e)
624
+ q.push((e + 256).toString(16).slice(1));
625
+ function mn(e, t = 0) {
626
+ return q[e[t + 0]] + q[e[t + 1]] + q[e[t + 2]] + q[e[t + 3]] + "-" + q[e[t + 4]] + q[e[t + 5]] + "-" + q[e[t + 6]] + q[e[t + 7]] + "-" + q[e[t + 8]] + q[e[t + 9]] + "-" + q[e[t + 10]] + q[e[t + 11]] + q[e[t + 12]] + q[e[t + 13]] + q[e[t + 14]] + q[e[t + 15]];
627
+ }
628
+ const hn = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), me = {
629
+ randomUUID: hn
630
+ };
631
+ function pn(e, t, n) {
632
+ if (me.randomUUID && !e)
633
+ return me.randomUUID();
634
+ e = e || {};
635
+ const i = e.random || (e.rng || fn)();
636
+ return i[6] = i[6] & 15 | 64, i[8] = i[8] & 63 | 128, mn(i);
637
+ }
638
+ function O(e, t, n) {
639
+ const i = t.split(".");
640
+ let a = e;
641
+ for (let o = 0; o < i.length - 1; o++)
642
+ (!a[i[o]] || typeof a[i[o]] != "object") && (a[i[o]] = {}), a = a[i[o]];
643
+ a[i[i.length - 1]] = n;
644
+ }
645
+ function K(e, t) {
646
+ const n = t.split(".");
647
+ let i = e;
648
+ for (const a of n) {
649
+ if (i == null) return;
650
+ i = i[a];
651
+ }
652
+ return i;
653
+ }
654
+ function xe(e, t) {
655
+ if (t === "number") {
656
+ if (e === "" || e == null) return "";
657
+ const n = Number(e);
658
+ return isNaN(n) ? "" : n;
659
+ }
660
+ return t === "boolean" ? typeof e == "boolean" ? e : e === "true" || e === !0 : e ?? "";
661
+ }
662
+ function R(e) {
663
+ return e.id;
664
+ }
665
+ function Ae(e, t) {
666
+ const n = t.split(".");
667
+ let i = e;
668
+ for (let a = 0; a < n.length - 1; a++) {
669
+ if (i == null || typeof i != "object") return;
670
+ i = i[n[a]];
671
+ }
672
+ i != null && typeof i == "object" && delete i[n[n.length - 1]];
673
+ }
674
+ function he(e, t, n) {
675
+ const i = t.split("."), a = n.split(".");
676
+ if (i.length === 1 && a.length === 1) {
677
+ const c = {};
678
+ for (const s of Object.keys(e))
679
+ s === i[0] ? c[a[0]] = e[s] : c[s] = e[s];
680
+ return c;
681
+ }
682
+ if (i.length === a.length && i.slice(0, -1).join(".") === a.slice(0, -1).join(".")) {
683
+ const c = structuredClone(e);
684
+ let s = c;
685
+ for (let y = 0; y < i.length - 1; y++) {
686
+ if (s[i[y]] == null || typeof s[i[y]] != "object")
687
+ return e;
688
+ s = s[i[y]];
689
+ }
690
+ const w = i[i.length - 1], T = a[a.length - 1], v = {};
691
+ for (const y of Object.keys(s))
692
+ y === w ? v[T] = s[y] : v[y] = s[y];
693
+ let b = c;
694
+ for (let y = 0; y < i.length - 2; y++)
695
+ b = b[i[y]];
696
+ return b[i[i.length - 2]] = v, c;
697
+ }
698
+ const o = structuredClone(e), u = K(o, t);
699
+ return Ae(o, t), u !== void 0 && O(o, n, u), o;
700
+ }
701
+ function oe(e, t) {
702
+ const n = {};
703
+ for (const i of Object.keys(e || {})) {
704
+ if (!t && i === "tools") continue;
705
+ const a = t ? t + "." + i : i, o = e[i];
706
+ o && typeof o == "object" && !Array.isArray(o) ? Object.assign(n, oe(o, a)) : n[a] = o;
707
+ }
708
+ return n;
709
+ }
710
+ function le(e, t, n) {
711
+ for (const i of e || []) {
712
+ if (i.id === t)
713
+ return i.id = n, !0;
714
+ if (i.fields && le(i.fields, t, n))
715
+ return !0;
716
+ }
717
+ return !1;
718
+ }
719
+ function Ce(e, t) {
720
+ if (!Array.isArray(e)) return !1;
721
+ const n = e.findIndex(function(i) {
722
+ return i.id === t;
723
+ });
724
+ if (n !== -1)
725
+ return e.splice(n, 1), !0;
726
+ for (const i of e)
727
+ if (i.fields && Ce(i.fields, t)) return !0;
728
+ return !1;
729
+ }
730
+ function Se(e, t) {
731
+ for (const n of e || [])
732
+ if (n.id === t || n.fields && Se(n.fields, t)) return !0;
733
+ return !1;
734
+ }
735
+ function vn(e) {
736
+ return e.split(".").pop().replace(/([A-Z])/g, " $1").replace(/^(.)/, function(n) {
737
+ return n.toUpperCase();
738
+ }).trim();
739
+ }
740
+ function gn(e, t, n) {
741
+ const i = typeof n == "boolean" ? "dropdown" : "text", a = typeof n == "number" ? "number" : void 0, o = { id: t, fieldType: i, text: vn(t), required: !1 };
742
+ a && (o.configType = a);
743
+ const u = t.includes(".") ? t.split(".").slice(0, -1).join(".") : null;
744
+ if (u) {
745
+ for (const s of e.fields || [])
746
+ if (s.fieldType === "section" && Array.isArray(s.fields) && !Y(s) && s.fields.some(function(T) {
747
+ return T.id && T.id.startsWith(u + ".");
748
+ })) {
749
+ s.fields.push(o);
750
+ return;
751
+ }
752
+ }
753
+ const c = (e.fields || []).filter(function(s) {
754
+ return s.fieldType === "section" && !Y(s);
755
+ });
756
+ if (c.length > 0) {
757
+ const s = c[c.length - 1];
758
+ s.fields = s.fields || [], s.fields.push(o);
759
+ } else
760
+ e.fields = e.fields || [], e.fields.push(o);
761
+ }
762
+ function yn(e, t, n) {
763
+ const i = oe(e), a = oe(t), o = new Set(Object.keys(i)), u = new Set(Object.keys(a)), c = [...o].filter(function(A) {
764
+ return !u.has(A);
765
+ }), s = [...u].filter(function(A) {
766
+ return !o.has(A);
767
+ });
768
+ if (c.length === 0 && s.length === 0) return n;
769
+ const w = structuredClone(n), T = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Set();
770
+ if (c.length > 0 && s.length > 0) {
771
+ for (const l of c) {
772
+ const f = JSON.stringify(i[l]);
773
+ for (const p of s)
774
+ if (!T.has(p) && JSON.stringify(a[p]) === f) {
775
+ le(w.fields, l, p), T.add(p), v.add(l);
776
+ break;
777
+ }
778
+ }
779
+ const A = c.filter(function(l) {
780
+ return !v.has(l);
781
+ }), d = s.filter(function(l) {
782
+ return !T.has(l);
783
+ });
784
+ A.length === 1 && d.length === 1 && (le(w.fields, A[0], d[0]), T.add(d[0]), v.add(A[0]));
785
+ }
786
+ const b = s.filter(function(A) {
787
+ return !T.has(A);
788
+ });
789
+ for (const A of b)
790
+ Se(w.fields, A) || gn(w, A, a[A]);
791
+ const y = c.filter(function(A) {
792
+ return !v.has(A);
793
+ });
794
+ for (const A of y)
795
+ Ce(w.fields, A);
796
+ return w;
797
+ }
798
+ function ae(e) {
799
+ const t = {};
800
+ for (const n of e || []) {
801
+ if (n.fieldType === "section" && Array.isArray(n.fields)) {
802
+ if (Y(n)) continue;
803
+ Object.assign(t, ae(n.fields));
804
+ continue;
805
+ }
806
+ n.id && (t[n.id] = n.text || "");
807
+ }
808
+ return t;
809
+ }
810
+ function bn(e, t, n) {
811
+ const i = ae(e == null ? void 0 : e.fields), a = ae(t == null ? void 0 : t.fields), o = new Set(Object.keys(i)), u = new Set(Object.keys(a)), c = [...o].filter(function(d) {
812
+ return !u.has(d);
813
+ }), s = [...u].filter(function(d) {
814
+ return !o.has(d);
815
+ });
816
+ if (c.length === 0 && s.length === 0)
817
+ return { config: n, renames: [] };
818
+ let w = n;
819
+ const T = [], v = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Set();
820
+ if (c.length > 0 && s.length > 0) {
821
+ for (const f of c) {
822
+ const p = i[f];
823
+ if (p) {
824
+ for (const m of s)
825
+ if (!v.has(m) && a[m] === p) {
826
+ w = he(w, f, m), T.push({ oldId: f, newId: m }), v.add(m), b.add(f);
827
+ break;
828
+ }
829
+ }
830
+ }
831
+ const d = c.filter(function(f) {
832
+ return !b.has(f);
833
+ }), l = s.filter(function(f) {
834
+ return !v.has(f);
835
+ });
836
+ d.length === 1 && l.length === 1 && (w = he(w, d[0], l[0]), T.push({ oldId: d[0], newId: l[0] }), v.add(l[0]), b.add(d[0]));
837
+ }
838
+ const y = s.filter(function(d) {
839
+ return !v.has(d);
840
+ });
841
+ if (y.length > 0) {
842
+ w === n && (w = structuredClone(n));
843
+ for (const d of y)
844
+ K(w, d) === void 0 && O(w, d, "");
845
+ }
846
+ const A = c.filter(function(d) {
847
+ return !b.has(d);
848
+ });
849
+ if (A.length > 0) {
850
+ w === n && (w = structuredClone(n));
851
+ for (const d of A)
852
+ Ae(w, d);
853
+ }
854
+ return { config: w, renames: T };
855
+ }
856
+ function ce(e) {
857
+ const t = [];
858
+ for (const n of e || [])
859
+ Y(n) || (n.fieldType === "section" && Array.isArray(n.fields) ? t.push(...ce(n.fields)) : t.push(n));
860
+ return t;
861
+ }
862
+ function ne(e) {
863
+ const t = e.answer;
864
+ if (t == null) return "";
865
+ if (e.fieldType === "dropdown" && e.options) {
866
+ const n = e.options.find((i) => i.id === t || i.value === t);
867
+ if (n) return n.value;
868
+ }
869
+ return t;
870
+ }
871
+ function pe(e) {
872
+ const t = e.answer;
873
+ return Array.isArray(t) ? e.options ? t.map((n) => {
874
+ const i = e.options.find((a) => a.id === n || a.value === n);
875
+ return i ? i.value : n;
876
+ }) : t : [];
877
+ }
878
+ function Ne(e) {
879
+ return e.options ? e.options.map((t) => t.value) : [];
880
+ }
881
+ function Y(e) {
882
+ return e.fieldType === "section" && /^sec-tool-\d+$/.test(e.id);
883
+ }
884
+ function ke(e) {
885
+ return (e || []).filter((t) => Y(t));
886
+ }
887
+ function Q(e, t) {
888
+ const n = (e.fields || []).find((i) => i.id.endsWith("-" + t));
889
+ return n ? ne(n) : "";
890
+ }
891
+ function wn(e, t) {
892
+ const n = ke(e.fields || []), i = [];
893
+ for (const a of n) {
894
+ const o = Q(a, "name"), u = Q(a, "description"), c = Q(a, "endpoint"), s = Q(a, "method"), w = Q(a, "params");
895
+ let T;
896
+ try {
897
+ T = w ? JSON.parse(w) : { type: "object", properties: {}, required: [] };
898
+ } catch {
899
+ T = { type: "object", properties: {}, required: [] };
900
+ }
901
+ const v = { name: o, description: u, inputSchema: T };
902
+ c && (v.endpoint = c), s && s !== "GET" && (v.method = s), i.push(v);
903
+ }
904
+ t.tools = i;
905
+ }
906
+ function Tn(e, t) {
907
+ const n = structuredClone(t), i = ce(e.fields || []);
908
+ ke(e.fields || []).length > 0 && wn(e, n);
909
+ for (const o of i) {
910
+ const u = o.configTransform;
911
+ if (u === "genericToolsInvert") {
912
+ const w = pe(o), T = Ne(o), v = R(o);
913
+ O(n, v, T.filter((b) => !w.includes(b)));
914
+ continue;
915
+ }
916
+ if (u === "elevenLabsDictIds") {
917
+ const w = (ne(o) || "").split(",").map((y) => y.trim()).filter(Boolean), T = i.find((y) => y.configTransform === "elevenLabsDictVersions"), v = T ? (ne(T) || "").split(",").map((y) => y.trim()).filter(Boolean) : [], b = R(o);
918
+ O(n, b, w.map((y, A) => ({
919
+ pronunciation_dictionary_id: y,
920
+ version_id: v[A] || ""
921
+ })));
922
+ continue;
923
+ }
924
+ if (u === "elevenLabsDictVersions")
925
+ continue;
926
+ const c = R(o), s = o.configType || "string";
927
+ o.fieldType === "check" ? O(n, c, pe(o)) : O(n, c, xe(ne(o), s));
928
+ }
929
+ return n;
930
+ }
931
+ function G(e, t) {
932
+ const n = structuredClone(t);
933
+ return qe(n.fields, e), n;
934
+ }
935
+ function qe(e, t) {
936
+ for (const n of e || []) {
937
+ if (Y(n))
938
+ continue;
939
+ if (n.fieldType === "section" && Array.isArray(n.fields)) {
940
+ qe(n.fields, t);
941
+ continue;
942
+ }
943
+ const i = n.configTransform;
944
+ if (i === "genericToolsInvert") {
945
+ const u = R(n), c = K(t, u) || [], T = Ne(n).filter((v) => !c.includes(v)).map(function(v) {
946
+ const b = (n.options || []).find(function(y) {
947
+ return y.value === v;
948
+ });
949
+ return b ? b.id : v;
950
+ });
951
+ n.selected = T, n.answer = T;
952
+ continue;
953
+ }
954
+ if (i === "elevenLabsDictIds") {
955
+ const u = R(n), c = K(t, u) || [];
956
+ n.answer = c.map((s) => s.pronunciation_dictionary_id).join(", ");
957
+ continue;
958
+ }
959
+ if (i === "elevenLabsDictVersions") {
960
+ const u = R(n).replace(/__versions$/, ""), c = K(t, u) || [];
961
+ n.answer = c.map((s) => s.version_id).join(", ");
962
+ continue;
963
+ }
964
+ const a = R(n), o = K(t, a);
965
+ if (n.fieldType === "check") {
966
+ const u = Array.isArray(o) ? o : [], c = n.options ? u.map(function(s) {
967
+ const w = n.options.find(function(T) {
968
+ return T.value === s || T.id === s;
969
+ });
970
+ return w ? w.id : s;
971
+ }) : u;
972
+ n.selected = c, n.answer = c;
973
+ continue;
974
+ }
975
+ if (n.fieldType === "dropdown" && n.options) {
976
+ const u = n.options.find((c) => c.value === String(o ?? ""));
977
+ n.selected = u ? u.id : null, n.answer = u ? u.value : String(o ?? "");
978
+ continue;
979
+ }
980
+ n.answer = o != null ? String(o) : "";
981
+ }
982
+ }
983
+ function xn(e) {
984
+ const t = {
985
+ _id: pn(),
986
+ tools: []
987
+ }, n = ce((e == null ? void 0 : e.fields) || []);
988
+ for (const i of n) {
989
+ if (i.id === "_id") continue;
990
+ const a = i.configTransform;
991
+ if (a === "genericToolsInvert") {
992
+ O(t, R(i), []);
993
+ continue;
994
+ }
995
+ if (a === "elevenLabsDictIds") {
996
+ O(t, R(i), []);
997
+ continue;
998
+ }
999
+ if (a === "elevenLabsDictVersions")
1000
+ continue;
1001
+ const o = R(i), u = i.configType || "string";
1002
+ i.fieldType === "check" ? O(t, o, Array.isArray(i.answer) ? i.answer : []) : O(t, o, xe(i.answer ?? "", u));
1003
+ }
1004
+ return t;
1005
+ }
1006
+ function An(e) {
1007
+ if (!Array.isArray(e)) return e;
1008
+ if (e.length > 0 && e[0] && typeof e[0] == "object" && "value" in e[0]) {
1009
+ var t = e.map(function(n) {
1010
+ return n.value;
1011
+ });
1012
+ return t.length === 1 ? t[0] : t;
1013
+ }
1014
+ return e;
1015
+ }
1016
+ function _e(e, t) {
1017
+ t || (t = {});
1018
+ for (var n = 0; n < (e || []).length; n++) {
1019
+ var i = e[n];
1020
+ i.id && i.answer !== void 0 && (t[i.id] = An(i.answer)), i.fields && _e(i.fields, t);
1021
+ }
1022
+ return t;
1023
+ }
1024
+ function Ie(e, t) {
1025
+ for (var n = 0; n < (e || []).length; n++) {
1026
+ var i = e[n];
1027
+ i.id && t[i.id] !== void 0 && (i.answer = t[i.id]), i.fields && Ie(i.fields, t);
1028
+ }
1029
+ }
1030
+ function Cn({ config: e, schema: t, onConfigChange: n }) {
1031
+ const i = t || X, a = B(null), o = B(null), u = B(e), c = B(i), s = B(n);
1032
+ u.current = e, c.current = i, s.current = n;
1033
+ const w = De(
1034
+ () => G(e, i),
1035
+ [e, i]
1036
+ ), T = W(function() {
1037
+ if (a.current)
1038
+ try {
1039
+ var v = a.current.getResponse();
1040
+ if (!v) return;
1041
+ var b = v.fields || v;
1042
+ if (!Array.isArray(b) && typeof b == "object" && !b.length && (b = v.fields), !b) return;
1043
+ var y = _e(Array.isArray(b) ? b : [b]);
1044
+ if (Object.keys(y).length === 0) return;
1045
+ var A = structuredClone(c.current);
1046
+ Ie(A.fields, y);
1047
+ var d = Tn(A, u.current);
1048
+ s.current(d);
1049
+ } catch (l) {
1050
+ console.error("[FormBuilder] syncConfig error:", l);
1051
+ }
1052
+ }, []);
1053
+ return H(function() {
1054
+ var v = o.current;
1055
+ if (!v) return;
1056
+ var b = null;
1057
+ function y() {
1058
+ clearTimeout(b), b = setTimeout(T, 50);
1059
+ }
1060
+ return v.addEventListener("input", y), v.addEventListener("change", y), v.addEventListener("click", y), function() {
1061
+ clearTimeout(b), v.removeEventListener("input", y), v.removeEventListener("change", y), v.removeEventListener("click", y);
1062
+ };
1063
+ }, [T]), /* @__PURE__ */ x("div", { ref: o, className: "max-w-6xl mx-auto p-6 rounded-lg shadow", style: { background: "var(--mieweb-card)", borderRadius: "var(--mieweb-radius-lg, 0.75rem)" }, children: [
1064
+ /* @__PURE__ */ r("h2", { className: "text-2xl font-bold mb-6", style: { color: "var(--mieweb-foreground)" }, children: "General Configuration" }),
1065
+ /* @__PURE__ */ r(
1066
+ nn,
1067
+ {
1068
+ ref: a,
1069
+ formData: w,
1070
+ hideUnsupportedFields: !0
1071
+ }
1072
+ )
1073
+ ] });
1074
+ }
1075
+ function Sn({
1076
+ yamlOutput: e,
1077
+ jsonOutput: t,
1078
+ editorMode: n,
1079
+ onEditorModeChange: i,
1080
+ onEditorChange: a,
1081
+ onDownload: o
1082
+ }) {
1083
+ return /* @__PURE__ */ x(
1084
+ we,
1085
+ {
1086
+ padding: "none",
1087
+ className: "h-[calc(100vh-10rem)] max-w-full overflow-hidden flex flex-col",
1088
+ children: [
1089
+ /* @__PURE__ */ x("div", { className: "p-2 border-b flex justify-between items-center flex-shrink-0", style: { background: "var(--mieweb-muted)" }, children: [
1090
+ /* @__PURE__ */ x("div", { className: "flex items-center gap-2", children: [
1091
+ /* @__PURE__ */ r("div", { className: "flex rounded gap-1", children: ["yaml", "json"].map(function(u) {
1092
+ var c = n === u;
1093
+ return /* @__PURE__ */ r(
1094
+ "button",
1095
+ {
1096
+ onClick: function() {
1097
+ i(u);
1098
+ },
1099
+ className: "px-3 h-7 text-sm rounded transition-all " + (c ? "" : "ivr-hover"),
1100
+ style: c ? { background: "var(--mieweb-primary-700, #1786b3)", color: "var(--mieweb-primary-foreground, #fff)", fontWeight: 600 } : { background: "transparent", color: "var(--mieweb-neutral-600, #525252)" },
1101
+ children: u.toUpperCase()
1102
+ },
1103
+ u
1104
+ );
1105
+ }) }),
1106
+ /* @__PURE__ */ x("span", { className: "hidden sm:block text-sm font-medium", style: { color: "var(--mieweb-muted-foreground)" }, children: [
1107
+ "config.",
1108
+ n
1109
+ ] })
1110
+ ] }),
1111
+ /* @__PURE__ */ x("div", { className: "flex items-center gap-1", children: [
1112
+ o && /* @__PURE__ */ r(
1113
+ j,
1114
+ {
1115
+ variant: "primary",
1116
+ size: "sm",
1117
+ onClick: function() {
1118
+ o(n);
1119
+ },
1120
+ leftIcon: /* @__PURE__ */ r(be, { className: "h-4 w-4" }),
1121
+ "aria-label": `Download config.${n}`,
1122
+ children: /* @__PURE__ */ x("span", { className: "hidden sm:inline", children: [
1123
+ "Download .",
1124
+ n
1125
+ ] })
1126
+ }
1127
+ ),
1128
+ /* @__PURE__ */ r(
1129
+ j,
1130
+ {
1131
+ variant: "ghost",
1132
+ size: "icon",
1133
+ onClick: function() {
1134
+ un(n === "yaml" ? e : t);
1135
+ },
1136
+ "aria-label": "Copy to clipboard",
1137
+ className: "ivr-hover h-8 w-8",
1138
+ style: { color: "var(--mieweb-muted-foreground)" },
1139
+ children: /* @__PURE__ */ r(Be, { className: "h-4 w-4" })
1140
+ }
1141
+ )
1142
+ ] })
1143
+ ] }),
1144
+ /* @__PURE__ */ r(
1145
+ tn,
1146
+ {
1147
+ height: "100%",
1148
+ language: n,
1149
+ value: n === "yaml" ? e : t,
1150
+ onChange: function(u) {
1151
+ a(u, n);
1152
+ },
1153
+ options: { minimap: { enabled: !1 }, fontSize: 14 }
1154
+ },
1155
+ n
1156
+ )
1157
+ ]
1158
+ }
1159
+ );
1160
+ }
1161
+ const Nn = [
1162
+ { value: "string", label: "String" },
1163
+ { value: "number", label: "Number" },
1164
+ { value: "boolean", label: "Boolean" },
1165
+ { value: "object", label: "Object" },
1166
+ { value: "array", label: "Array" }
1167
+ ], kn = [
1168
+ { value: "string", label: "String" },
1169
+ { value: "number", label: "Number" },
1170
+ { value: "boolean", label: "Boolean" },
1171
+ { value: "object", label: "Object" }
1172
+ ], ve = /* @__PURE__ */ new Set(["string", "number"]);
1173
+ function ge({ value: e, onChange: t, size: n, ...i }) {
1174
+ const [a, o] = E(e);
1175
+ H(function() {
1176
+ o(e);
1177
+ }, [e]);
1178
+ function u() {
1179
+ if (a !== e) {
1180
+ var s = t(a);
1181
+ s === !1 && o(e);
1182
+ }
1183
+ }
1184
+ function c(s) {
1185
+ s.key === "Enter" && s.target.blur();
1186
+ }
1187
+ return /* @__PURE__ */ r(
1188
+ Z,
1189
+ {
1190
+ ...i,
1191
+ size: n || "sm",
1192
+ value: a,
1193
+ onChange: function(s) {
1194
+ o(s.target.value);
1195
+ },
1196
+ onBlur: u,
1197
+ onKeyDown: c
1198
+ }
1199
+ );
1200
+ }
1201
+ function ye({ values: e, onChange: t }) {
1202
+ const [n, i] = E((e || []).join(", "));
1203
+ H(function() {
1204
+ i((e || []).join(", "));
1205
+ }, [e]);
1206
+ function a(o) {
1207
+ var u = o.split(",").map(function(c) {
1208
+ return c.trim();
1209
+ }).filter(function(c) {
1210
+ return c !== "";
1211
+ });
1212
+ t(u);
1213
+ }
1214
+ return /* @__PURE__ */ r(
1215
+ Z,
1216
+ {
1217
+ size: "sm",
1218
+ value: n,
1219
+ onChange: function(o) {
1220
+ i(o.target.value);
1221
+ },
1222
+ onBlur: function() {
1223
+ a(n);
1224
+ },
1225
+ onKeyDown: function(o) {
1226
+ o.key === "Enter" && o.target.blur();
1227
+ },
1228
+ placeholder: "e.g. dev, staging, prod"
1229
+ }
1230
+ );
1231
+ }
1232
+ function qn({ config: e, onConfigChange: t }) {
1233
+ var A;
1234
+ function n(d) {
1235
+ var l = structuredClone(e);
1236
+ d(l), t(l);
1237
+ }
1238
+ function i() {
1239
+ n(function(d) {
1240
+ d.tools || (d.tools = []);
1241
+ for (var l = 1; d.tools.some(function(f) {
1242
+ return f.name === "tool_" + l;
1243
+ }); )
1244
+ l++;
1245
+ d.tools.push({
1246
+ name: "tool_" + l,
1247
+ description: "Description of the tool",
1248
+ inputSchema: { type: "object", properties: {}, required: [] }
1249
+ });
1250
+ });
1251
+ }
1252
+ function a(d) {
1253
+ n(function(l) {
1254
+ l.tools.splice(d, 1);
1255
+ });
1256
+ }
1257
+ function o(d, l, f) {
1258
+ if (l === "name") {
1259
+ var p = e.tools[d].name;
1260
+ if (f !== p) {
1261
+ var m = e.tools.some(function(g, _) {
1262
+ return _ !== d && g.name === f;
1263
+ });
1264
+ if (m)
1265
+ return alert('Tool name "' + f + '" already exists.'), !1;
1266
+ }
1267
+ }
1268
+ return n(function(g) {
1269
+ g.tools[d].name, g.tools[d][l] = f;
1270
+ }), !0;
1271
+ }
1272
+ function u(d) {
1273
+ n(function(l) {
1274
+ var f = l.tools[d];
1275
+ f.inputSchema || (f.inputSchema = { type: "object", properties: {}, required: [] }), f.inputSchema.properties || (f.inputSchema.properties = {});
1276
+ for (var p = 1; f.inputSchema.properties["param_" + p]; )
1277
+ p++;
1278
+ f.inputSchema.properties["param_" + p] = {
1279
+ type: "string",
1280
+ description: "Parameter description"
1281
+ };
1282
+ });
1283
+ }
1284
+ function c(d, l, f, p) {
1285
+ if (l !== f) {
1286
+ var m = e.tools[d];
1287
+ if (m.inputSchema.properties[f])
1288
+ return alert('Parameter "' + f + '" already exists.'), !1;
1289
+ }
1290
+ return n(function(g) {
1291
+ var _ = g.tools[d], L = _.inputSchema.properties;
1292
+ if (l !== f) {
1293
+ var z = {};
1294
+ Object.keys(L).forEach(function(k) {
1295
+ z[k === l ? f : k] = k === l ? p : L[k];
1296
+ }), _.inputSchema.properties = z, _.inputSchema.required && _.inputSchema.required.includes(l) && (_.inputSchema.required = _.inputSchema.required.map(function(k) {
1297
+ return k === l ? f : k;
1298
+ }));
1299
+ } else
1300
+ L[l] = p;
1301
+ }), !0;
1302
+ }
1303
+ function s(d, l) {
1304
+ n(function(f) {
1305
+ var p = f.tools[d];
1306
+ delete p.inputSchema.properties[l], p.inputSchema.required && (p.inputSchema.required = p.inputSchema.required.filter(function(m) {
1307
+ return m !== l;
1308
+ }));
1309
+ });
1310
+ }
1311
+ function w(d, l) {
1312
+ n(function(f) {
1313
+ var p = f.tools[d];
1314
+ p.inputSchema.required || (p.inputSchema.required = []), p.inputSchema.required.includes(l) ? p.inputSchema.required = p.inputSchema.required.filter(function(m) {
1315
+ return m !== l;
1316
+ }) : p.inputSchema.required.push(l);
1317
+ });
1318
+ }
1319
+ function T(d, l, f, p) {
1320
+ var m = { type: p, description: f.description || "" };
1321
+ f.default !== void 0 && (m.default = f.default), p === "array" && (m.items = f.items || { type: "string" }), ve.has(p) && f.enum && (m.enum = f.enum), c(d, l, l, m);
1322
+ }
1323
+ function v(d, l, f, p) {
1324
+ c(d, l, l, {
1325
+ ...f,
1326
+ items: { type: p }
1327
+ });
1328
+ }
1329
+ function b(d, l, f, p) {
1330
+ var m = { ...f };
1331
+ p ? m.enum = [] : delete m.enum, c(d, l, l, m);
1332
+ }
1333
+ function y(d, l, f, p) {
1334
+ var m = { ...f, enum: p };
1335
+ if (m.default !== void 0) {
1336
+ var g = p.map(String);
1337
+ g.includes(String(m.default)) || (m.default = p.length > 0 ? p[0] : void 0, m.default === void 0 && delete m.default);
1338
+ }
1339
+ c(d, l, l, m);
1340
+ }
1341
+ return /* @__PURE__ */ x("div", { className: "max-w-4xl mx-auto", children: [
1342
+ /* @__PURE__ */ x("div", { className: "flex justify-between items-center mb-6", children: [
1343
+ /* @__PURE__ */ r("h2", { className: "text-2xl font-bold", style: { color: "var(--mieweb-foreground)" }, children: "Tool Builder" }),
1344
+ /* @__PURE__ */ r(
1345
+ j,
1346
+ {
1347
+ variant: "primary",
1348
+ size: "sm",
1349
+ onClick: i,
1350
+ leftIcon: /* @__PURE__ */ r(ue, { className: "h-4 w-4" }),
1351
+ children: "Add Tool"
1352
+ }
1353
+ )
1354
+ ] }),
1355
+ /* @__PURE__ */ x("div", { className: "space-y-4", children: [
1356
+ (A = e.tools) == null ? void 0 : A.map(function(d, l) {
1357
+ var f, p;
1358
+ return /* @__PURE__ */ x(we, { padding: "md", className: "relative", children: [
1359
+ /* @__PURE__ */ r(
1360
+ j,
1361
+ {
1362
+ variant: "ghost",
1363
+ size: "icon",
1364
+ onClick: function() {
1365
+ a(l);
1366
+ },
1367
+ className: "absolute top-3 right-3 ivr-hover-destructive",
1368
+ style: { color: "var(--mieweb-destructive)" },
1369
+ "aria-label": "Remove tool",
1370
+ children: /* @__PURE__ */ r(de, { className: "h-5 w-5" })
1371
+ }
1372
+ ),
1373
+ /* @__PURE__ */ x("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4 mb-4", children: [
1374
+ /* @__PURE__ */ r(
1375
+ ge,
1376
+ {
1377
+ label: "Tool Name",
1378
+ value: d.name,
1379
+ onChange: function(m) {
1380
+ return o(l, "name", m);
1381
+ },
1382
+ size: "md"
1383
+ }
1384
+ ),
1385
+ /* @__PURE__ */ r(
1386
+ Z,
1387
+ {
1388
+ label: "Description",
1389
+ size: "md",
1390
+ value: d.description,
1391
+ onChange: function(m) {
1392
+ o(l, "description", m.target.value);
1393
+ }
1394
+ }
1395
+ )
1396
+ ] }),
1397
+ /* @__PURE__ */ x("div", { className: "p-4 rounded-lg border", style: { background: "var(--mieweb-muted)", borderColor: "var(--mieweb-border)", borderRadius: "var(--mieweb-radius-lg, 0.75rem)" }, children: [
1398
+ /* @__PURE__ */ x("div", { className: "flex justify-between items-center mb-3", children: [
1399
+ /* @__PURE__ */ r("h4", { className: "font-medium text-sm", style: { color: "var(--mieweb-foreground)" }, children: "Input Schema Parameters" }),
1400
+ /* @__PURE__ */ r(
1401
+ j,
1402
+ {
1403
+ variant: "primary",
1404
+ size: "sm",
1405
+ onClick: function() {
1406
+ u(l);
1407
+ },
1408
+ leftIcon: /* @__PURE__ */ r(ue, { className: "h-3 w-3" }),
1409
+ children: "Add Parameter"
1410
+ }
1411
+ )
1412
+ ] }),
1413
+ /* @__PURE__ */ r("div", { className: "space-y-2", children: ((f = d.inputSchema) == null ? void 0 : f.properties) && Object.entries(d.inputSchema.properties).map(function([m, g], _) {
1414
+ var I, P, $;
1415
+ var L = g.type === "array", z = ve.has(g.type), k = Array.isArray(g.enum);
1416
+ return /* @__PURE__ */ x("div", { className: "rounded border p-2 space-y-2", style: { background: "var(--mieweb-card)", borderColor: "var(--mieweb-border)" }, children: [
1417
+ /* @__PURE__ */ x("div", { className: "flex flex-col md:flex-row gap-2 items-start", children: [
1418
+ /* @__PURE__ */ r("div", { className: "w-full md:w-36 flex-shrink-0", children: /* @__PURE__ */ r(
1419
+ ge,
1420
+ {
1421
+ value: m,
1422
+ onChange: function(C) {
1423
+ return c(l, m, C, g);
1424
+ },
1425
+ placeholder: "Name",
1426
+ size: "sm"
1427
+ }
1428
+ ) }),
1429
+ /* @__PURE__ */ r("div", { className: "w-full md:w-28 flex-shrink-0", children: /* @__PURE__ */ r(
1430
+ te,
1431
+ {
1432
+ options: Nn,
1433
+ value: g.type,
1434
+ onValueChange: function(C) {
1435
+ T(l, m, g, C);
1436
+ },
1437
+ size: "sm"
1438
+ }
1439
+ ) }),
1440
+ L && /* @__PURE__ */ r("div", { className: "w-full md:w-32 flex-shrink-0", children: /* @__PURE__ */ r(
1441
+ te,
1442
+ {
1443
+ options: kn,
1444
+ value: ((I = g.items) == null ? void 0 : I.type) || "string",
1445
+ onValueChange: function(C) {
1446
+ v(l, m, g, C);
1447
+ },
1448
+ size: "sm"
1449
+ }
1450
+ ) }),
1451
+ /* @__PURE__ */ r("div", { className: "w-full flex-1", children: /* @__PURE__ */ r(
1452
+ Z,
1453
+ {
1454
+ size: "sm",
1455
+ value: g.description || "",
1456
+ onChange: function(C) {
1457
+ c(l, m, m, { ...g, description: C.target.value });
1458
+ },
1459
+ placeholder: "Description"
1460
+ }
1461
+ ) }),
1462
+ /* @__PURE__ */ x("div", { className: "flex items-center gap-3 flex-shrink-0 mt-1 md:mt-0", children: [
1463
+ /* @__PURE__ */ r(
1464
+ ie,
1465
+ {
1466
+ label: "Req",
1467
+ size: "sm",
1468
+ checked: (P = d.inputSchema.required) == null ? void 0 : P.includes(m),
1469
+ onChange: function() {
1470
+ w(l, m);
1471
+ }
1472
+ }
1473
+ ),
1474
+ /* @__PURE__ */ r(
1475
+ ie,
1476
+ {
1477
+ label: "Default",
1478
+ size: "sm",
1479
+ checked: g.default !== void 0,
1480
+ onChange: function(C) {
1481
+ var J = { ...g };
1482
+ C.target.checked ? L ? J.default = [] : k && g.enum && g.enum.length > 0 ? J.default = g.enum[0] : J.default = "" : delete J.default, c(l, m, m, J);
1483
+ }
1484
+ }
1485
+ ),
1486
+ /* @__PURE__ */ r(
1487
+ j,
1488
+ {
1489
+ variant: "ghost",
1490
+ size: "icon",
1491
+ onClick: function() {
1492
+ s(l, m);
1493
+ },
1494
+ className: "ivr-hover-destructive h-8 w-8",
1495
+ style: { color: "var(--mieweb-destructive)" },
1496
+ "aria-label": "Remove parameter",
1497
+ children: /* @__PURE__ */ r(de, { className: "h-4 w-4" })
1498
+ }
1499
+ )
1500
+ ] })
1501
+ ] }),
1502
+ g.default !== void 0 && /* @__PURE__ */ x("div", { className: "flex gap-2 items-center pl-1", children: [
1503
+ /* @__PURE__ */ r("span", { className: "text-xs w-16 flex-shrink-0", style: { color: "var(--mieweb-muted-foreground)" }, children: "Default:" }),
1504
+ /* @__PURE__ */ r("div", { className: "flex-1", children: L ? /* @__PURE__ */ x("div", { className: "flex gap-2 items-center", children: [
1505
+ /* @__PURE__ */ r("div", { className: "flex-1", children: /* @__PURE__ */ r(
1506
+ ye,
1507
+ {
1508
+ values: Array.isArray(g.default) ? g.default : [],
1509
+ onChange: function(C) {
1510
+ c(l, m, m, { ...g, default: C });
1511
+ }
1512
+ }
1513
+ ) }),
1514
+ /* @__PURE__ */ r("span", { className: "text-xs whitespace-nowrap", style: { color: "var(--mieweb-muted-foreground)" }, children: "comma-separated" })
1515
+ ] }) : k && g.enum && g.enum.length > 0 ? (
1516
+ /* Enum active with values → dropdown constrained to enum */
1517
+ /* @__PURE__ */ r(
1518
+ te,
1519
+ {
1520
+ size: "sm",
1521
+ options: g.enum.map(function(C) {
1522
+ return { value: String(C), label: String(C) };
1523
+ }),
1524
+ value: String(g.default),
1525
+ onValueChange: function(C) {
1526
+ c(l, m, m, { ...g, default: C });
1527
+ }
1528
+ }
1529
+ )
1530
+ ) : k ? /* @__PURE__ */ r("span", { className: "text-xs italic", style: { color: "var(--mieweb-warning)" }, children: "Add enum values first to pick a default" }) : /* @__PURE__ */ r(
1531
+ Z,
1532
+ {
1533
+ size: "sm",
1534
+ value: g.default,
1535
+ onChange: function(C) {
1536
+ c(l, m, m, { ...g, default: C.target.value });
1537
+ },
1538
+ placeholder: "Default value"
1539
+ }
1540
+ ) })
1541
+ ] }),
1542
+ z && /* @__PURE__ */ x("div", { className: "flex flex-col gap-1 pl-1", children: [
1543
+ /* @__PURE__ */ r(
1544
+ ie,
1545
+ {
1546
+ label: "Enum — restrict to allowed values",
1547
+ size: "sm",
1548
+ checked: k,
1549
+ onChange: function(C) {
1550
+ b(l, m, g, C.target.checked);
1551
+ }
1552
+ }
1553
+ ),
1554
+ k && /* @__PURE__ */ x("div", { className: "flex gap-2 items-start pl-5", children: [
1555
+ /* @__PURE__ */ r("div", { className: "flex-1", children: /* @__PURE__ */ r(
1556
+ ye,
1557
+ {
1558
+ values: g.enum,
1559
+ onChange: function(C) {
1560
+ y(l, m, g, C);
1561
+ }
1562
+ }
1563
+ ) }),
1564
+ /* @__PURE__ */ r("span", { className: "text-xs mt-2 whitespace-nowrap", style: { color: "var(--mieweb-muted-foreground)" }, children: "comma-separated" })
1565
+ ] }),
1566
+ k && g.enum && g.enum.length > 0 && /* @__PURE__ */ r("div", { className: "pl-5 flex flex-wrap gap-1", children: g.enum.map(function(C) {
1567
+ return /* @__PURE__ */ r("span", { className: "inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium", style: { background: "var(--mieweb-primary-100, #b3e6f6)", color: "var(--mieweb-primary-700, #1786b3)" }, children: C }, C);
1568
+ }) })
1569
+ ] }),
1570
+ L && /* @__PURE__ */ x("div", { className: "pl-1 text-xs text-gray-500", children: [
1571
+ "Items type: ",
1572
+ /* @__PURE__ */ r("span", { className: "font-medium text-gray-700", children: (($ = g.items) == null ? void 0 : $.type) || "string" }),
1573
+ " ",
1574
+ "— the array selector above controls this"
1575
+ ] })
1576
+ ] }, _);
1577
+ }) }),
1578
+ (!((p = d.inputSchema) != null && p.properties) || Object.keys(d.inputSchema.properties).length === 0) && /* @__PURE__ */ r("p", { className: "text-sm text-gray-500 italic", children: "No parameters defined." })
1579
+ ] })
1580
+ ] }, l);
1581
+ }),
1582
+ (!e.tools || e.tools.length === 0) && /* @__PURE__ */ r("div", { className: "text-center py-12 text-gray-500", children: "No custom tools defined. Click “Add Tool” to create one." })
1583
+ ] })
1584
+ ] });
1585
+ }
1586
+ function zn({
1587
+ initialConfig: e,
1588
+ schema: t,
1589
+ onConfigChange: n,
1590
+ onDownload: i,
1591
+ onSubmit: a,
1592
+ showEditor: o = !0
1593
+ }) {
1594
+ const [u, c] = E(function() {
1595
+ return e || xn(t || X);
1596
+ }), [s, w] = E("form"), [T, v] = E("yaml"), [b, y] = E(""), [A, d] = E(""), [l, f] = E(t || X), [p, m] = E(!1), [g, _] = E(null), [L, z] = E(0);
1597
+ H(function() {
1598
+ if (!g) return;
1599
+ const h = setTimeout(function() {
1600
+ _(null);
1601
+ }, 5e3);
1602
+ return function() {
1603
+ clearTimeout(h);
1604
+ };
1605
+ }, [g]);
1606
+ const k = B(null), I = B(null), P = B(u);
1607
+ P.current = u, H(function() {
1608
+ try {
1609
+ y(fe(u)), d(JSON.stringify(u, null, 2));
1610
+ } catch (h) {
1611
+ console.error("Error generating output", h);
1612
+ }
1613
+ }, [u]), H(function() {
1614
+ try {
1615
+ s === "editor" && (T === "yaml" ? y(fe(u)) : T === "json" && d(JSON.stringify(u, null, 2)));
1616
+ } catch (h) {
1617
+ console.error("Error resetting output on tab change", h);
1618
+ }
1619
+ }, [s, T, u]), H(function() {
1620
+ n && n(u);
1621
+ }, [u, n]);
1622
+ function $(h) {
1623
+ P.current = h, c(h);
1624
+ }
1625
+ function C(h) {
1626
+ if (Array.isArray(h)) return h.map(C);
1627
+ if (h !== null && typeof h == "object") {
1628
+ var N = {};
1629
+ for (var S of Object.keys(h))
1630
+ N[S] = C(h[S]);
1631
+ return N;
1632
+ }
1633
+ return h === null ? "" : h;
1634
+ }
1635
+ function J(h, N) {
1636
+ try {
1637
+ let S;
1638
+ N === "yaml" ? (y(h), S = C(se.load(h))) : (d(h), S = JSON.parse(h)), S && typeof S == "object" && (f(function(F) {
1639
+ return yn(u, S, F);
1640
+ }), c(S), z(function(F) {
1641
+ return F + 1;
1642
+ }));
1643
+ } catch {
1644
+ }
1645
+ }
1646
+ function Ee(h) {
1647
+ cn(u, b, i, h || "yaml", A);
1648
+ }
1649
+ const [M, je] = E(null);
1650
+ H(function() {
1651
+ p && !M && import("@mieweb/forms-editor").then(function(h) {
1652
+ je(function() {
1653
+ return h.QuestionnaireEditor;
1654
+ });
1655
+ });
1656
+ }, [p, M]);
1657
+ const Pe = W(function() {
1658
+ var h;
1659
+ (h = I.current) == null || h.call(I), f(function(N) {
1660
+ return G(P.current, N);
1661
+ }), m(!0);
1662
+ }, []), Le = W(function() {
1663
+ var h;
1664
+ (h = I.current) == null || h.call(I), f(function(N) {
1665
+ return z(function(S) {
1666
+ return S + 1;
1667
+ }), G(P.current, N);
1668
+ }), m(!1);
1669
+ }, []), Oe = /* @__PURE__ */ new Set(["text", "longtext", "dropdown", "check", "section"]);
1670
+ function Re(h) {
1671
+ let N = 0;
1672
+ function S(U) {
1673
+ return Array.isArray(U) ? U.reduce(function(V, D) {
1674
+ return D.fieldType && !Oe.has(D.fieldType) ? (N++, V) : Array.isArray(D.fields) ? V.concat([{ ...D, fields: S(D.fields) }]) : V.concat([D]);
1675
+ }, []) : U;
1676
+ }
1677
+ return { filtered: { ...h, fields: S(h.fields) }, removedCount: N };
1678
+ }
1679
+ const ze = W(function(h) {
1680
+ const { filtered: N, removedCount: S } = Re(h);
1681
+ S > 0 && _(
1682
+ `${S} unsupported field type${S > 1 ? "s were" : " was"} removed. Only Text, Long Text, Dropdown, and Checkbox fields are supported.`
1683
+ ), f(function(F) {
1684
+ const U = bn(F, N, P.current);
1685
+ return U.config !== P.current && c(U.config), N;
1686
+ });
1687
+ }, []), Fe = W(function() {
1688
+ const h = new Blob([JSON.stringify(l, null, 2)], { type: "application/json" }), N = URL.createObjectURL(h), S = document.createElement("a");
1689
+ S.href = N, S.download = (l.title || "form-schema").replace(/\s+/g, "-").toLowerCase() + ".json", document.body.appendChild(S), S.click(), document.body.removeChild(S), URL.revokeObjectURL(N);
1690
+ }, [l]), Ve = W(function(h) {
1691
+ var F;
1692
+ const N = (F = h.target.files) == null ? void 0 : F[0];
1693
+ if (!N) return;
1694
+ const S = new FileReader();
1695
+ S.onload = function(U) {
1696
+ try {
1697
+ const V = JSON.parse(U.target.result);
1698
+ if (!V.fields || !Array.isArray(V.fields)) {
1699
+ alert('Invalid schema file: missing "fields" array.');
1700
+ return;
1701
+ }
1702
+ f(G(P.current, V)), z(function(D) {
1703
+ return D + 1;
1704
+ });
1705
+ } catch (V) {
1706
+ alert("Failed to parse schema file: " + V.message);
1707
+ }
1708
+ }, S.readAsText(N), h.target.value = "";
1709
+ }, []), Ue = W(function() {
1710
+ var h;
1711
+ window.confirm("Reset the form to the default Agent schema? Any custom fields will be lost.") && ((h = I.current) == null || h.call(I), f(G(P.current, X)), z(function(N) {
1712
+ return N + 1;
1713
+ }));
1714
+ }, []);
1715
+ return /* @__PURE__ */ r("div", { className: "flex flex-col h-full", style: { fontFamily: "var(--mieweb-font-sans, inherit)" }, children: /* @__PURE__ */ x("div", { className: "flex-1 flex flex-col overflow-hidden", children: [
1716
+ /* @__PURE__ */ r("div", { className: "shadow-sm border-b", style: { background: "var(--mieweb-card)", borderColor: "var(--mieweb-border)" }, children: /* @__PURE__ */ x("div", { className: "px-4 flex items-center justify-between gap-2 flex-wrap", children: [
1717
+ /* @__PURE__ */ r(
1718
+ Ze,
1719
+ {
1720
+ value: s,
1721
+ onValueChange: function(h) {
1722
+ w(h), m(!1);
1723
+ },
1724
+ variant: "underline",
1725
+ children: /* @__PURE__ */ x(Xe, { className: "border-b-0", children: [
1726
+ /* @__PURE__ */ x(re, { value: "form", className: "gap-2 px-3 py-3 text-sm", children: [
1727
+ /* @__PURE__ */ r(He, { className: "h-4 w-4" }),
1728
+ /* @__PURE__ */ r("span", { className: "hidden sm:inline", children: "Form Builder" })
1729
+ ] }),
1730
+ /* @__PURE__ */ x(re, { value: "tools", className: "gap-2 px-3 py-3 text-sm", children: [
1731
+ /* @__PURE__ */ r(Je, { className: "h-4 w-4" }),
1732
+ /* @__PURE__ */ r("span", { className: "hidden sm:inline", children: "Tool Builder" })
1733
+ ] }),
1734
+ o && /* @__PURE__ */ x(re, { value: "editor", className: "gap-2 px-3 py-3 text-sm", children: [
1735
+ /* @__PURE__ */ r(We, { className: "h-4 w-4" }),
1736
+ /* @__PURE__ */ r("span", { className: "hidden sm:inline", children: "Config Editor" })
1737
+ ] })
1738
+ ] })
1739
+ }
1740
+ ),
1741
+ a && /* @__PURE__ */ r(
1742
+ j,
1743
+ {
1744
+ variant: "primary",
1745
+ size: "sm",
1746
+ onClick: () => a(b),
1747
+ leftIcon: /* @__PURE__ */ r(Ke, { className: "h-4 w-4" }),
1748
+ className: "my-1 shrink-0",
1749
+ children: /* @__PURE__ */ r("span", { className: "hidden sm:inline", children: "Submit" })
1750
+ }
1751
+ )
1752
+ ] }) }),
1753
+ /* @__PURE__ */ x("div", { className: "flex-1 overflow-auto p-4 md:p-6", children: [
1754
+ /* @__PURE__ */ x("div", { style: { display: s === "form" && !p ? "" : "none" }, children: [
1755
+ /* @__PURE__ */ x("div", { className: "max-w-6xl mx-auto mb-4 flex flex-wrap items-center justify-between gap-2", children: [
1756
+ /* @__PURE__ */ r(
1757
+ j,
1758
+ {
1759
+ variant: "primary",
1760
+ size: "sm",
1761
+ onClick: Pe,
1762
+ leftIcon: /* @__PURE__ */ r(Ye, { className: "h-4 w-4" }),
1763
+ children: "Customize Form"
1764
+ }
1765
+ ),
1766
+ /* @__PURE__ */ x("div", { className: "flex items-center gap-1.5 flex-wrap", children: [
1767
+ /* @__PURE__ */ r(
1768
+ j,
1769
+ {
1770
+ variant: "primary",
1771
+ size: "sm",
1772
+ onClick: Fe,
1773
+ leftIcon: /* @__PURE__ */ r(be, { className: "h-4 w-4" }),
1774
+ title: "Export schema as JSON",
1775
+ children: "Export"
1776
+ }
1777
+ ),
1778
+ /* @__PURE__ */ r(
1779
+ j,
1780
+ {
1781
+ variant: "primary",
1782
+ size: "sm",
1783
+ onClick: function() {
1784
+ var h;
1785
+ (h = k.current) == null || h.click();
1786
+ },
1787
+ leftIcon: /* @__PURE__ */ r($e, { className: "h-4 w-4" }),
1788
+ title: "Import a schema JSON file",
1789
+ children: "Import"
1790
+ }
1791
+ ),
1792
+ /* @__PURE__ */ r(
1793
+ "input",
1794
+ {
1795
+ ref: k,
1796
+ type: "file",
1797
+ accept: ".json",
1798
+ className: "hidden",
1799
+ onChange: Ve
1800
+ }
1801
+ ),
1802
+ /* @__PURE__ */ r(
1803
+ j,
1804
+ {
1805
+ variant: "ghost",
1806
+ size: "sm",
1807
+ onClick: Ue,
1808
+ leftIcon: /* @__PURE__ */ r(Qe, { className: "h-4 w-4" }),
1809
+ style: { color: "var(--mieweb-destructive)" },
1810
+ className: "ivr-hover-destructive",
1811
+ title: "Reset to default Agent schema",
1812
+ children: "Reset"
1813
+ }
1814
+ )
1815
+ ] })
1816
+ ] }),
1817
+ /* @__PURE__ */ r(
1818
+ Cn,
1819
+ {
1820
+ config: u,
1821
+ schema: l,
1822
+ onConfigChange: $,
1823
+ syncRef: I
1824
+ },
1825
+ L
1826
+ )
1827
+ ] }),
1828
+ s === "form" && p && /* @__PURE__ */ x("div", { className: "max-w-7xl mx-auto", children: [
1829
+ /* @__PURE__ */ x("div", { className: "mb-4 flex items-center gap-3", children: [
1830
+ /* @__PURE__ */ r(
1831
+ j,
1832
+ {
1833
+ variant: "ghost",
1834
+ size: "sm",
1835
+ onClick: Le,
1836
+ leftIcon: /* @__PURE__ */ r(Ge, { className: "h-4 w-4" }),
1837
+ children: "Back to Form"
1838
+ }
1839
+ ),
1840
+ /* @__PURE__ */ x("span", { className: "text-sm", style: { color: "var(--mieweb-muted-foreground)" }, children: [
1841
+ "Add, remove, or reorder fields. The field ",
1842
+ /* @__PURE__ */ r("code", { className: "text-xs px-1 rounded", style: { background: "var(--mieweb-muted)", color: "var(--mieweb-foreground)" }, children: "ID" }),
1843
+ " is used as the config key (dot-notation for nesting, e.g. ",
1844
+ /* @__PURE__ */ r("code", { className: "text-xs px-1 rounded", style: { background: "var(--mieweb-muted)", color: "var(--mieweb-foreground)" }, children: "twilio.phoneNumber" }),
1845
+ ")."
1846
+ ] })
1847
+ ] }),
1848
+ g && /* @__PURE__ */ r(
1849
+ Me,
1850
+ {
1851
+ variant: "warning",
1852
+ dismissible: !0,
1853
+ onDismiss: function() {
1854
+ _(null);
1855
+ },
1856
+ className: "mb-3",
1857
+ children: /* @__PURE__ */ r(en, { children: g })
1858
+ }
1859
+ ),
1860
+ /* @__PURE__ */ r("div", { className: "rounded-lg shadow p-4 min-h-[600px]", style: { background: "var(--mieweb-card)", borderRadius: "var(--mieweb-radius-lg, 0.75rem)" }, children: M ? /* @__PURE__ */ r(
1861
+ M,
1862
+ {
1863
+ initialFormData: l || void 0,
1864
+ onChange: ze
1865
+ }
1866
+ ) : /* @__PURE__ */ r("div", { className: "flex items-center justify-center h-64", style: { color: "var(--mieweb-muted-foreground)" }, children: "Loading form editor..." }) })
1867
+ ] }),
1868
+ s === "editor" && o && /* @__PURE__ */ r(
1869
+ Sn,
1870
+ {
1871
+ yamlOutput: b,
1872
+ jsonOutput: A,
1873
+ editorMode: T,
1874
+ onEditorModeChange: v,
1875
+ onEditorChange: J,
1876
+ onDownload: Ee
1877
+ }
1878
+ ),
1879
+ s === "tools" && /* @__PURE__ */ r(
1880
+ qn,
1881
+ {
1882
+ config: u,
1883
+ onConfigChange: $
1884
+ }
1885
+ )
1886
+ ] })
1887
+ ] }) });
1888
+ }
1889
+ export {
1890
+ zn as A,
1891
+ Sn as C,
1892
+ Cn as F,
1893
+ qn as T,
1894
+ fe as a,
1895
+ un as b,
1896
+ G as c,
1897
+ X as d,
1898
+ xn as e,
1899
+ cn as f,
1900
+ Tn as q,
1901
+ sn as v,
1902
+ Rn as y
1903
+ };