@mieweb/q 1.0.0 → 1.2.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.
package/dist/universal.js CHANGED
@@ -1,14 +1,14 @@
1
- var p = (i) => {
2
- throw TypeError(i);
1
+ var p = (e) => {
2
+ throw TypeError(e);
3
3
  };
4
- var u = (i, t, o) => t.has(i) || p("Cannot " + o);
5
- var n = (i, t, o) => (u(i, t, "read from private field"), o ? o.call(i) : t.get(i)), h = (i, t, o) => t.has(i) ? p("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(i) : t.set(i, o), a = (i, t, o, d) => (u(i, t, "write to private field"), d ? d.call(i, o) : t.set(i, o), o), m = (i, t, o) => (u(i, t, "access private method"), o);
4
+ var g = (e, o, t) => o.has(e) || p("Cannot " + t);
5
+ var i = (e, o, t) => (g(e, o, "read from private field"), t ? t.call(e) : o.get(e)), a = (e, o, t) => o.has(e) ? p("Cannot add the same private member more than once") : o instanceof WeakSet ? o.add(e) : o.set(e, t), c = (e, o, t, h) => (g(e, o, "write to private field"), h ? h.call(e, t) : o.set(e, t), t), m = (e, o, t) => (g(e, o, "access private method"), t);
6
6
  import { jsx as C } from "react/jsx-runtime";
7
7
  import "react";
8
8
  import { createRoot as w } from "react-dom/client";
9
- import { A as b } from "./AgentConfigGenerator-DLoMdUYG.js";
10
- import { brands as j, generateBrandCSS as q } from "@mieweb/ui";
11
- var f, r, s, c, e, g, l;
9
+ import { A as b } from "./AgentConfigGenerator-DzrPmrXi.js";
10
+ import { brands as N, generateBrandCSS as T } from "@mieweb/ui";
11
+ var f, s, r, d, n, l, u;
12
12
  class x {
13
13
  // tracks latest config from onConfigChange
14
14
  /**
@@ -18,53 +18,57 @@ class x {
18
18
  * @param {object} [options.initialConfig] Pre-populate with an existing agent config.
19
19
  * @param {object} [options.schema] Override the default questionnaire schema.
20
20
  * @param {boolean} [options.showEditor] Show the Config Editor tab (default: true).
21
+ * @param {string[]} [options.secretNames] Secret names already stored by the host.
22
+ * @param {Function} [options.onDiscoverTools] async (server, secrets) => [{ name, description }].
21
23
  */
22
- constructor(t, o = {}) {
23
- h(this, e);
24
- h(this, f);
25
- h(this, r);
26
- h(this, s);
27
- h(this, c, null);
28
- if (a(this, r, typeof t == "string" ? document.querySelector(t) : t), !n(this, r))
29
- throw new Error(`UniversalAgentConfigGenerator: target element not found (${t})`);
30
- a(this, s, { showEditor: !0, ...o }), a(this, f, w(n(this, r))), m(this, e, l).call(this);
24
+ constructor(o, t = {}) {
25
+ a(this, n);
26
+ a(this, f);
27
+ a(this, s);
28
+ a(this, r);
29
+ a(this, d, null);
30
+ if (c(this, s, typeof o == "string" ? document.querySelector(o) : o), !i(this, s))
31
+ throw new Error(`UniversalAgentConfigGenerator: target element not found (${o})`);
32
+ c(this, r, { showEditor: !0, ...t }), c(this, f, w(i(this, s))), m(this, n, u).call(this);
31
33
  }
32
34
  /**
33
35
  * Update any option and re-render.
34
36
  * @param {object} newOptions Partial options to merge.
35
37
  */
36
- update(t) {
37
- a(this, s, { ...n(this, s), ...t }), m(this, e, l).call(this);
38
+ update(o) {
39
+ c(this, r, { ...i(this, r), ...o }), m(this, n, u).call(this);
38
40
  }
39
41
  /**
40
42
  * Unmount the React component and free resources.
41
43
  */
42
44
  destroy() {
43
- n(this, f).unmount();
45
+ i(this, f).unmount();
44
46
  }
45
47
  }
46
- f = new WeakMap(), r = new WeakMap(), s = new WeakMap(), c = new WeakMap(), e = new WeakSet(), // -------------------------------------------------------------------------
48
+ f = new WeakMap(), s = new WeakMap(), r = new WeakMap(), d = new WeakMap(), n = new WeakSet(), // -------------------------------------------------------------------------
47
49
  // Private
48
50
  // -------------------------------------------------------------------------
49
- g = function(t, o) {
50
- n(this, r).dispatchEvent(new CustomEvent(t, { detail: o, bubbles: !0 }));
51
- }, l = function() {
52
- const t = n(this, s);
53
- n(this, f).render(
51
+ l = function(o, t) {
52
+ i(this, s).dispatchEvent(new CustomEvent(o, { detail: t, bubbles: !0 }));
53
+ }, u = function() {
54
+ const o = i(this, r);
55
+ i(this, f).render(
54
56
  /* @__PURE__ */ C(
55
57
  b,
56
58
  {
57
- initialConfig: t.initialConfig,
58
- schema: t.schema,
59
- showEditor: t.showEditor,
60
- onConfigChange: (o) => {
61
- a(this, c, o), m(this, e, g).call(this, "config-change", o);
59
+ initialConfig: o.initialConfig,
60
+ schema: o.schema,
61
+ showEditor: o.showEditor,
62
+ secretNames: o.secretNames,
63
+ onDiscoverTools: o.onDiscoverTools,
64
+ onConfigChange: (t) => {
65
+ c(this, d, t), m(this, n, l).call(this, "config-change", t);
62
66
  },
63
- onDownload: (o, d) => {
64
- m(this, e, g).call(this, "config-download", { content: o, mode: d });
67
+ onDownload: (t, h) => {
68
+ m(this, n, l).call(this, "config-download", { content: t, mode: h });
65
69
  },
66
- onSubmit: (o) => {
67
- m(this, e, g).call(this, "config-submit", { config: n(this, c), yaml: o });
70
+ onSubmit: (t, h) => {
71
+ m(this, n, l).call(this, "config-submit", { config: i(this, d), yaml: t, secrets: h });
68
72
  }
69
73
  }
70
74
  )
@@ -72,6 +76,6 @@ g = function(t, o) {
72
76
  };
73
77
  export {
74
78
  x as UniversalAgentConfigGenerator,
75
- j as brands,
76
- q as generateBrandCSS
79
+ N as brands,
80
+ T as generateBrandCSS
77
81
  };
package/package.json CHANGED
@@ -1,65 +1,69 @@
1
- {
2
- "name": "@mieweb/q",
3
- "version": "1.0.0",
4
- "type": "module",
5
- "description": "React component library for generating and editing BluehIve IVR Agent configuration files",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": "./dist/index.js",
12
- "require": "./dist/index.cjs"
13
- },
14
- "./universal": {
15
- "import": "./dist/universal.js",
16
- "require": "./dist/universal.cjs"
17
- },
18
- "./style.css": "./dist/style.css",
19
- "./tailwind-config": "./tailwind.config.js"
20
- },
21
- "files": [
22
- "dist",
23
- "src/index.css",
24
- "tailwind.config.js",
25
- "postcss.config.js"
26
- ],
27
- "scripts": {
28
- "dev": "vite --open /index.html",
29
- "dev:universal": "vite --open /index.html",
30
- "dev:react": "vite --open /index-react.html",
31
- "build": "vite build",
32
- "build:lib": "vite build --config vite.lib.config.js",
33
- "prepare": "npm run build:lib && npx tailwindcss -i src/index.css -o dist/style.css --minify",
34
- "preview": "vite preview",
35
- "storybook": "storybook dev -p 6006",
36
- "build-storybook": "storybook build"
37
- },
38
- "dependencies": {
39
- "@mieweb/forms-editor": "latest",
40
- "@mieweb/forms-renderer": "latest",
41
- "@mieweb/ui": "^0.2.4",
42
- "@monaco-editor/react": "^4.6.0",
43
- "js-yaml": "^4.1.0",
44
- "lucide-react": "^0.344.0",
45
- "react": "^19.2.4",
46
- "react-dom": "^19.2.4",
47
- "uuid": "^9.0.1"
48
- },
49
- "devDependencies": {
50
- "@storybook/addon-essentials": "^8.5.0",
51
- "@storybook/addon-interactions": "^8.5.0",
52
- "@storybook/addon-links": "^8.5.0",
53
- "@storybook/blocks": "^8.5.0",
54
- "@storybook/react": "^8.5.0",
55
- "@storybook/react-vite": "^8.5.0",
56
- "@types/react": "^18.2.64",
57
- "@types/react-dom": "^18.2.21",
58
- "@vitejs/plugin-react": "^4.2.1",
59
- "autoprefixer": "^10.4.18",
60
- "postcss": "^8.4.35",
61
- "storybook": "^8.5.0",
62
- "tailwindcss": "^3.4.1",
63
- "vite": "^5.1.6"
64
- }
65
- }
1
+ {
2
+ "name": "@mieweb/q",
3
+ "version": "1.2.0",
4
+ "type": "module",
5
+ "description": "React component library for generating and editing BluehIve IVR Agent configuration files",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/mieweb/Q.git"
9
+ },
10
+ "main": "./dist/index.cjs",
11
+ "module": "./dist/index.js",
12
+ "types": "./dist/index.d.ts",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./dist/index.js",
16
+ "require": "./dist/index.cjs"
17
+ },
18
+ "./universal": {
19
+ "import": "./dist/universal.js",
20
+ "require": "./dist/universal.cjs"
21
+ },
22
+ "./style.css": "./dist/style.css",
23
+ "./tailwind-config": "./tailwind.config.js"
24
+ },
25
+ "files": [
26
+ "dist",
27
+ "src/index.css",
28
+ "tailwind.config.js",
29
+ "postcss.config.js"
30
+ ],
31
+ "scripts": {
32
+ "dev": "vite --open /index.html",
33
+ "dev:universal": "vite --open /index.html",
34
+ "dev:react": "vite --open /index-react.html",
35
+ "build": "vite build",
36
+ "build:lib": "vite build --config vite.lib.config.js",
37
+ "prepare": "npm run build:lib && npx tailwindcss -i src/index.css -o dist/style.css --minify",
38
+ "preview": "vite preview",
39
+ "storybook": "storybook dev -p 6006",
40
+ "build-storybook": "storybook build"
41
+ },
42
+ "dependencies": {
43
+ "@mieweb/forms-editor": "latest",
44
+ "@mieweb/forms-renderer": "latest",
45
+ "@mieweb/ui": "^0.2.4",
46
+ "@monaco-editor/react": "^4.6.0",
47
+ "js-yaml": "^4.1.0",
48
+ "lucide-react": "^0.344.0",
49
+ "react": "^19.2.4",
50
+ "react-dom": "^19.2.4",
51
+ "uuid": "^9.0.1"
52
+ },
53
+ "devDependencies": {
54
+ "@storybook/addon-essentials": "^8.5.0",
55
+ "@storybook/addon-interactions": "^8.5.0",
56
+ "@storybook/addon-links": "^8.5.0",
57
+ "@storybook/blocks": "^8.5.0",
58
+ "@storybook/react": "^8.5.0",
59
+ "@storybook/react-vite": "^8.5.0",
60
+ "@types/react": "^18.2.64",
61
+ "@types/react-dom": "^18.2.21",
62
+ "@vitejs/plugin-react": "^4.2.1",
63
+ "autoprefixer": "^10.4.18",
64
+ "postcss": "^8.4.35",
65
+ "storybook": "^8.5.0",
66
+ "tailwindcss": "^3.4.1",
67
+ "vite": "^5.1.6"
68
+ }
69
+ }
package/postcss.config.js CHANGED
@@ -1,6 +1,6 @@
1
- export default {
2
- plugins: {
3
- tailwindcss: {},
4
- autoprefixer: {},
5
- },
6
- };
1
+ export default {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
package/src/index.css CHANGED
@@ -1,65 +1,65 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
4
-
5
- body {
6
- background-color: var(--mieweb-background);
7
- color: var(--mieweb-foreground);
8
- }
9
-
10
- /* Drawer slide-in animation */
11
- @keyframes slide-in-right {
12
- from {
13
- transform: translateX(100%);
14
- }
15
- to {
16
- transform: translateX(0);
17
- }
18
- }
19
-
20
- .animate-slide-in-right {
21
- animation: slide-in-right 0.25s ease-out;
22
- }
23
-
24
- /* Hide the Code tab in the forms-editor drawer */
25
- .animate-slide-in-right [role="tablist"] button:nth-child(2) {
26
- display: none;
27
- }
28
-
29
- /* Widen the forms-renderer internal container to match our layout */
30
- .renderer-container.mie\:max-w-4xl {
31
- max-width: 72rem; /* match max-w-6xl */
32
- }
33
-
34
- /* ============================================================
35
- Brand-safe hover utilities (override inline styles on hover)
36
- ============================================================ */
37
-
38
- /* Ghost button hover — neutral-100 (#f5f5f5) is invisible on white;
39
- override globally to neutral-300 for perceptible hover feedback */
40
- .hover\:bg-neutral-100:hover {
41
- background-color: var(--mieweb-neutral-300, #d4d4d4) !important;
42
- }
43
-
44
- /* Outline button hover — neutral-50 is near-white; bump to neutral-200 */
45
- .hover\:bg-neutral-50:hover {
46
- background-color: var(--mieweb-neutral-200, #e5e5e5) !important;
47
- }
48
-
49
- /* Muted background on hover — for ghost / icon buttons with ivr-hover class */
50
- .ivr-hover:hover {
51
- background-color: var(--mieweb-neutral-300, #d4d4d4) !important;
52
- }
53
-
54
- /* Keep destructive text colour on hover but reveal muted bg */
55
- .ivr-hover-destructive:hover {
56
- background-color: var(--mieweb-neutral-200, #e5e5e5) !important;
57
- color: var(--mieweb-destructive) !important;
58
- }
59
-
60
- /* Tab trigger hover: show a clear muted background + full foreground text */
61
- [role="tab"]:not([data-state="active"]):hover {
62
- background-color: var(--mieweb-neutral-200, #e5e5e5) !important;
63
- color: var(--mieweb-foreground) !important;
64
- cursor: pointer;
65
- }
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+ body {
6
+ background-color: var(--mieweb-background);
7
+ color: var(--mieweb-foreground);
8
+ }
9
+
10
+ /* Drawer slide-in animation */
11
+ @keyframes slide-in-right {
12
+ from {
13
+ transform: translateX(100%);
14
+ }
15
+ to {
16
+ transform: translateX(0);
17
+ }
18
+ }
19
+
20
+ .animate-slide-in-right {
21
+ animation: slide-in-right 0.25s ease-out;
22
+ }
23
+
24
+ /* Hide the Code tab in the forms-editor drawer */
25
+ .animate-slide-in-right [role="tablist"] button:nth-child(2) {
26
+ display: none;
27
+ }
28
+
29
+ /* Widen the forms-renderer internal container to match our layout */
30
+ .renderer-container.mie\:max-w-4xl {
31
+ max-width: 72rem; /* match max-w-6xl */
32
+ }
33
+
34
+ /* ============================================================
35
+ Brand-safe hover utilities (override inline styles on hover)
36
+ ============================================================ */
37
+
38
+ /* Ghost button hover — neutral-100 (#f5f5f5) is invisible on white;
39
+ override globally to neutral-300 for perceptible hover feedback */
40
+ .hover\:bg-neutral-100:hover {
41
+ background-color: var(--mieweb-neutral-300, #d4d4d4) !important;
42
+ }
43
+
44
+ /* Outline button hover — neutral-50 is near-white; bump to neutral-200 */
45
+ .hover\:bg-neutral-50:hover {
46
+ background-color: var(--mieweb-neutral-200, #e5e5e5) !important;
47
+ }
48
+
49
+ /* Muted background on hover — for ghost / icon buttons with ivr-hover class */
50
+ .ivr-hover:hover {
51
+ background-color: var(--mieweb-neutral-300, #d4d4d4) !important;
52
+ }
53
+
54
+ /* Keep destructive text colour on hover but reveal muted bg */
55
+ .ivr-hover-destructive:hover {
56
+ background-color: var(--mieweb-neutral-200, #e5e5e5) !important;
57
+ color: var(--mieweb-destructive) !important;
58
+ }
59
+
60
+ /* Tab trigger hover: show a clear muted background + full foreground text */
61
+ [role="tab"]:not([data-state="active"]):hover {
62
+ background-color: var(--mieweb-neutral-200, #e5e5e5) !important;
63
+ color: var(--mieweb-foreground) !important;
64
+ cursor: pointer;
65
+ }
@@ -1,27 +1,27 @@
1
- /** @type {import('tailwindcss').Config} */
2
- import miewebPreset from '@mieweb/ui/tailwind-preset';
3
-
4
- export default {
5
- presets: [miewebPreset],
6
- content: [
7
- "./index.html",
8
- "./src/**/*.{js,ts,jsx,tsx}",
9
- "./node_modules/@mieweb/ui/dist/**/*.{js,ts,jsx,tsx}",
10
- ],
11
- safelist: [
12
- // Primary button (variant="primary" in @mieweb/ui Button uses these)
13
- 'bg-primary-700', 'hover:bg-primary-800', 'active:bg-primary-900',
14
- // Secondary button
15
- 'bg-neutral-200', 'text-neutral-900', 'hover:bg-neutral-300',
16
- // Ghost button
17
- 'bg-transparent', 'text-neutral-600', 'hover:bg-neutral-100',
18
- // Link button
19
- 'text-primary-700', 'hover:text-primary-800', 'underline-offset-4',
20
- // Outline button
21
- 'border', 'border-neutral-300', 'hover:bg-neutral-50',
22
- ],
23
- theme: {
24
- extend: {},
25
- },
26
- plugins: [],
27
- };
1
+ /** @type {import('tailwindcss').Config} */
2
+ import miewebPreset from '@mieweb/ui/tailwind-preset';
3
+
4
+ export default {
5
+ presets: [miewebPreset],
6
+ content: [
7
+ "./index.html",
8
+ "./src/**/*.{js,ts,jsx,tsx}",
9
+ "./node_modules/@mieweb/ui/dist/**/*.{js,ts,jsx,tsx}",
10
+ ],
11
+ safelist: [
12
+ // Primary button (variant="primary" in @mieweb/ui Button uses these)
13
+ 'bg-primary-700', 'hover:bg-primary-800', 'active:bg-primary-900',
14
+ // Secondary button
15
+ 'bg-neutral-200', 'text-neutral-900', 'hover:bg-neutral-300',
16
+ // Ghost button
17
+ 'bg-transparent', 'text-neutral-600', 'hover:bg-neutral-100',
18
+ // Link button
19
+ 'text-primary-700', 'hover:text-primary-800', 'underline-offset-4',
20
+ // Outline button
21
+ 'border', 'border-neutral-300', 'hover:bg-neutral-50',
22
+ ],
23
+ theme: {
24
+ extend: {},
25
+ },
26
+ plugins: [],
27
+ };
@@ -1,4 +0,0 @@
1
- "use strict";var Ve=Object.create;var re=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Be=Object.getOwnPropertyNames;var De=Object.getPrototypeOf,He=Object.prototype.hasOwnProperty;var Je=(e,n,t,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of Be(n))!He.call(e,o)&&o!==t&&re(e,o,{get:()=>n[o],enumerable:!(i=Ue(n,o))||i.enumerable});return e};var We=(e,n,t)=>(t=e!=null?Ve(De(e)):{},Je(n||!e||!e.__esModule?re(t,"default",{value:e,enumerable:!0}):t,e));const r=require("react/jsx-runtime"),j=require("react"),ne=require("js-yaml"),I=require("lucide-react"),T=require("@mieweb/ui"),Ke=require("@mieweb/forms-renderer"),Ye=require("@monaco-editor/react"),$e="mieforms-v1.0",Qe="Agent Configuration",Ge=[{id:"sec-basic",fieldType:"section",title:"Basic Info",fields:[{id:"_id",fieldType:"text",question:"Config ID (_id)",answer:"",required:!1},{id:"name",fieldType:"text",question:"Name",answer:"New Agent Config",required:!1},{id:"timezone",fieldType:"dropdown",question:"Timezone",answer:"America/New_York",required:!1,options:[{id:"tz-ny",label:"America/New_York",value:"America/New_York"},{id:"tz-chi",label:"America/Chicago",value:"America/Chicago"},{id:"tz-den",label:"America/Denver",value:"America/Denver"},{id:"tz-la",label:"America/Los_Angeles",value:"America/Los_Angeles"},{id:"tz-hon",label:"Pacific/Honolulu",value:"Pacific/Honolulu"},{id:"tz-anc",label:"America/Anchorage",value:"America/Anchorage"},{id:"tz-phx",label:"America/Phoenix",value:"America/Phoenix"}]},{id:"description",fieldType:"text",question:"Description",answer:"Agent Assistant Description",required:!1}]},{id:"sec-telephony",fieldType:"section",title:"Telephony Settings",fields:[{id:"twilio.phoneNumber",fieldType:"text",question:"Twilio Phone Number",answer:"",required:!1},{id:"twilio.accountSid",fieldType:"text",question:"Twilio Account SID",answer:"",required:!1},{id:"twilio.authToken",fieldType:"text",question:"Twilio Auth Token",answer:"",required:!1}]},{id:"sec-office",fieldType:"section",title:"Office Hours",fields:[{id:"officeOpeningTime",fieldType:"dropdown",question:"Opening Time (Hour)",answer:"8",required:!1,configType:"number",options:[{id:"h0",label:"0:00",value:"0"},{id:"h1",label:"1:00",value:"1"},{id:"h2",label:"2:00",value:"2"},{id:"h3",label:"3:00",value:"3"},{id:"h4",label:"4:00",value:"4"},{id:"h5",label:"5:00",value:"5"},{id:"h6",label:"6:00",value:"6"},{id:"h7",label:"7:00",value:"7"},{id:"h8",label:"8:00",value:"8"},{id:"h9",label:"9:00",value:"9"},{id:"h10",label:"10:00",value:"10"},{id:"h11",label:"11:00",value:"11"},{id:"h12",label:"12:00",value:"12"},{id:"h13",label:"13:00",value:"13"},{id:"h14",label:"14:00",value:"14"},{id:"h15",label:"15:00",value:"15"},{id:"h16",label:"16:00",value:"16"},{id:"h17",label:"17:00",value:"17"},{id:"h18",label:"18:00",value:"18"},{id:"h19",label:"19:00",value:"19"},{id:"h20",label:"20:00",value:"20"},{id:"h21",label:"21:00",value:"21"},{id:"h22",label:"22:00",value:"22"},{id:"h23",label:"23:00",value:"23"}]},{id:"officeClosingTime",fieldType:"dropdown",question:"Closing Time (Hour)",answer:"17",required:!1,configType:"number",options:[{id:"h0",label:"0:00",value:"0"},{id:"h1",label:"1:00",value:"1"},{id:"h2",label:"2:00",value:"2"},{id:"h3",label:"3:00",value:"3"},{id:"h4",label:"4:00",value:"4"},{id:"h5",label:"5:00",value:"5"},{id:"h6",label:"6:00",value:"6"},{id:"h7",label:"7:00",value:"7"},{id:"h8",label:"8:00",value:"8"},{id:"h9",label:"9:00",value:"9"},{id:"h10",label:"10:00",value:"10"},{id:"h11",label:"11:00",value:"11"},{id:"h12",label:"12:00",value:"12"},{id:"h13",label:"13:00",value:"13"},{id:"h14",label:"14:00",value:"14"},{id:"h15",label:"15:00",value:"15"},{id:"h16",label:"16:00",value:"16"},{id:"h17",label:"17:00",value:"17"},{id:"h18",label:"18:00",value:"18"},{id:"h19",label:"19:00",value:"19"},{id:"h20",label:"20:00",value:"20"},{id:"h21",label:"21:00",value:"21"},{id:"h22",label:"22:00",value:"22"},{id:"h23",label:"23:00",value:"23"}]},{id:"afterHoursNotice",fieldType:"longtext",question:"After Hours Notice",answer:"Our office is currently closed.",required:!1},{id:"officeHoursHumanNumber",fieldType:"text",question:"Human Handover Number",answer:"",required:!1}]},{id:"sec-webchart",fieldType:"section",title:"WebChart Integration",fields:[{id:"webchart.url",fieldType:"text",question:"WebChart URL",answer:"",required:!1},{id:"webchart.username",fieldType:"text",question:"WebChart Username",answer:"",required:!1},{id:"webchart.password",fieldType:"text",question:"WebChart Password",answer:"",required:!1},{id:"defaultServiceLocation",fieldType:"text",question:"Default Service Location",answer:"",required:!1},{id:"defaultPatientId",fieldType:"text",question:"Default Patient ID",answer:"",required:!1,configType:"number"},{id:"transcript_doc_type",fieldType:"text",question:"Transcript Doc Type",answer:"",required:!1},{id:"defaultPhysicianId",fieldType:"text",question:"Default Physician ID",answer:"",required:!1,configType:"number"},{id:"userId",fieldType:"text",question:"User ID",answer:"",required:!1},{id:"visitType",fieldType:"text",question:"Visit Type",answer:"",required:!1}]},{id:"sec-audio",fieldType:"section",title:"Audio Configuration",fields:[{id:"elevenLabsPronunciationDictionaries",fieldType:"text",question:"ElevenLabs Pronunciation Dictionary IDs (comma-separated)",answer:"",required:!1,configTransform:"elevenLabsDictIds"},{id:"elevenLabsPronunciationDictionaries__versions",fieldType:"text",question:"ElevenLabs Pronunciation Dictionary Version IDs (comma-separated)",answer:"",required:!1,configTransform:"elevenLabsDictVersions"}]},{id:"sec-agent",fieldType:"section",title:"Agent Specific Info",fields:[{id:"welcome",fieldType:"longtext",question:"Welcome Message",answer:"Thank you for calling. How can I help you today?",required:!1},{id:"systemPrompt",fieldType:"longtext",question:"System Prompt",answer:"You are a helpful AI assistant.",required:!1},{id:"disabledGenericTools",fieldType:"check",question:"Enabled Generic Tools",answer:[],required:!1,configTransform:"genericToolsInvert",options:[{id:"gt-hangup",label:"force_hangup_bad_call",value:"force_hangup_bad_call"},{id:"gt-birthdate",label:"validate_birth_date",value:"validate_birth_date"},{id:"gt-goodbye",label:"thanks_for_calling_goodbye",value:"thanks_for_calling_goodbye"},{id:"gt-human",label:"connect_to_a_human",value:"connect_to_a_human"},{id:"gt-multiple",label:"handle_multiple_patients",value:"handle_multiple_patients"},{id:"gt-schedule",label:"schedule_call_later",value:"schedule_call_later"},{id:"gt-objective",label:"mark_objective_complete",value:"mark_objective_complete"}]}]}],W={schemaType:$e,title:Qe,fields:Ge};function de(e){const n=[];for(const t of e||[])t.fieldType==="section"&&Array.isArray(t.fields)?n.push(...de(t.fields)):n.push(t);return n}function Ze(e,n){return n.split(".").reduce(function(t,i){return t?t[i]:void 0},e)}function fe(e,n){const t=de((n||W).fields),i=[];for(const o of t){if(!o.id||o.id.startsWith("sec-")||!o.required)continue;const s=Ze(e,o.id);(s==null||s==="")&&i.push(`${o.text||o.question||o.id} is required`)}return i}function X(e){return ne.dump(e,{lineWidth:-1,forceQuotes:!1,quotingType:'"',noCompatMode:!0,styles:{"!!null":"empty"},replacer:function(n,t){return t===""?null:t}})}function Xe(e){return ne.load(e)}function me(e,n,t,i="yaml",o=""){const s=fe(e);if(s.length>0){alert(`Please fix the following errors before downloading:
2
-
3
- - ${s.join(`
4
- - `)}`);return}const u=i==="json",c=u?o:n,a=u?"application/json":"text/yaml",x=u?"config.json":"config.yaml";if(t){t(c,i);return}const w=new Blob([c],{type:a}),g=URL.createObjectURL(w),b=document.createElement("a");b.href=g,b.download=x,document.body.appendChild(b),b.click(),document.body.removeChild(b),URL.revokeObjectURL(g)}async function he(e){try{await navigator.clipboard.writeText(e),alert("Copied to clipboard!")}catch(n){console.error("Clipboard failed:",n),alert("Failed to copy to clipboard. Please check your browser permissions or try again.")}}let G;const Me=new Uint8Array(16);function et(){if(!G&&(G=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!G))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return G(Me)}const q=[];for(let e=0;e<256;++e)q.push((e+256).toString(16).slice(1));function tt(e,n=0){return q[e[n+0]]+q[e[n+1]]+q[e[n+2]]+q[e[n+3]]+"-"+q[e[n+4]]+q[e[n+5]]+"-"+q[e[n+6]]+q[e[n+7]]+"-"+q[e[n+8]]+q[e[n+9]]+"-"+q[e[n+10]]+q[e[n+11]]+q[e[n+12]]+q[e[n+13]]+q[e[n+14]]+q[e[n+15]]}const nt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),se={randomUUID:nt};function it(e,n,t){if(se.randomUUID&&!e)return se.randomUUID();e=e||{};const i=e.random||(e.rng||et)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,tt(i)}function L(e,n,t){const i=n.split(".");let o=e;for(let s=0;s<i.length-1;s++)(!o[i[s]]||typeof o[i[s]]!="object")&&(o[i[s]]={}),o=o[i[s]];o[i[i.length-1]]=t}function H(e,n){const t=n.split(".");let i=e;for(const o of t){if(i==null)return;i=i[o]}return i}function pe(e,n){if(n==="number"){if(e===""||e==null)return"";const t=Number(e);return isNaN(t)?"":t}return n==="boolean"?typeof e=="boolean"?e:e==="true"||e===!0:e??""}function O(e){return e.id}function ge(e,n){const t=n.split(".");let i=e;for(let o=0;o<t.length-1;o++){if(i==null||typeof i!="object")return;i=i[t[o]]}i!=null&&typeof i=="object"&&delete i[t[t.length-1]]}function oe(e,n,t){const i=n.split("."),o=t.split(".");if(i.length===1&&o.length===1){const c={};for(const a of Object.keys(e))a===i[0]?c[o[0]]=e[a]:c[a]=e[a];return c}if(i.length===o.length&&i.slice(0,-1).join(".")===o.slice(0,-1).join(".")){const c=structuredClone(e);let a=c;for(let y=0;y<i.length-1;y++){if(a[i[y]]==null||typeof a[i[y]]!="object")return e;a=a[i[y]]}const x=i[i.length-1],w=o[o.length-1],g={};for(const y of Object.keys(a))y===x?g[w]=a[y]:g[y]=a[y];let b=c;for(let y=0;y<i.length-2;y++)b=b[i[y]];return b[i[i.length-2]]=g,c}const s=structuredClone(e),u=H(s,n);return ge(s,n),u!==void 0&&L(s,t,u),s}function M(e,n){const t={};for(const i of Object.keys(e||{})){if(!n&&i==="tools")continue;const o=n?n+"."+i:i,s=e[i];s&&typeof s=="object"&&!Array.isArray(s)?Object.assign(t,M(s,o)):t[o]=s}return t}function ee(e,n,t){for(const i of e||[]){if(i.id===n)return i.id=t,!0;if(i.fields&&ee(i.fields,n,t))return!0}return!1}function ve(e,n){if(!Array.isArray(e))return!1;const t=e.findIndex(function(i){return i.id===n});if(t!==-1)return e.splice(t,1),!0;for(const i of e)if(i.fields&&ve(i.fields,n))return!0;return!1}function ye(e,n){for(const t of e||[])if(t.id===n||t.fields&&ye(t.fields,n))return!0;return!1}function rt(e){return e.split(".").pop().replace(/([A-Z])/g," $1").replace(/^(.)/,function(t){return t.toUpperCase()}).trim()}function st(e,n,t){const i=typeof t=="boolean"?"dropdown":"text",o=typeof t=="number"?"number":void 0,s={id:n,fieldType:i,text:rt(n),required:!1};o&&(s.configType=o);const u=n.includes(".")?n.split(".").slice(0,-1).join("."):null;if(u){for(const a of e.fields||[])if(a.fieldType==="section"&&Array.isArray(a.fields)&&!K(a)&&a.fields.some(function(w){return w.id&&w.id.startsWith(u+".")})){a.fields.push(s);return}}const c=(e.fields||[]).filter(function(a){return a.fieldType==="section"&&!K(a)});if(c.length>0){const a=c[c.length-1];a.fields=a.fields||[],a.fields.push(s)}else e.fields=e.fields||[],e.fields.push(s)}function ot(e,n,t){const i=M(e),o=M(n),s=new Set(Object.keys(i)),u=new Set(Object.keys(o)),c=[...s].filter(function(C){return!u.has(C)}),a=[...u].filter(function(C){return!s.has(C)});if(c.length===0&&a.length===0)return t;const x=structuredClone(t),w=new Set,g=new Set;if(c.length>0&&a.length>0){for(const l of c){const f=JSON.stringify(i[l]);for(const p of a)if(!w.has(p)&&JSON.stringify(o[p])===f){ee(x.fields,l,p),w.add(p),g.add(l);break}}const C=c.filter(function(l){return!g.has(l)}),d=a.filter(function(l){return!w.has(l)});C.length===1&&d.length===1&&(ee(x.fields,C[0],d[0]),w.add(d[0]),g.add(C[0]))}const b=a.filter(function(C){return!w.has(C)});for(const C of b)ye(x.fields,C)||st(x,C,o[C]);const y=c.filter(function(C){return!g.has(C)});for(const C of y)ve(x.fields,C);return x}function te(e){const n={};for(const t of e||[]){if(t.fieldType==="section"&&Array.isArray(t.fields)){if(K(t))continue;Object.assign(n,te(t.fields));continue}t.id&&(n[t.id]=t.text||"")}return n}function lt(e,n,t){const i=te(e==null?void 0:e.fields),o=te(n==null?void 0:n.fields),s=new Set(Object.keys(i)),u=new Set(Object.keys(o)),c=[...s].filter(function(d){return!u.has(d)}),a=[...u].filter(function(d){return!s.has(d)});if(c.length===0&&a.length===0)return{config:t,renames:[]};let x=t;const w=[],g=new Set,b=new Set;if(c.length>0&&a.length>0){for(const f of c){const p=i[f];if(p){for(const m of a)if(!g.has(m)&&o[m]===p){x=oe(x,f,m),w.push({oldId:f,newId:m}),g.add(m),b.add(f);break}}}const d=c.filter(function(f){return!b.has(f)}),l=a.filter(function(f){return!g.has(f)});d.length===1&&l.length===1&&(x=oe(x,d[0],l[0]),w.push({oldId:d[0],newId:l[0]}),g.add(l[0]),b.add(d[0]))}const y=a.filter(function(d){return!g.has(d)});if(y.length>0){x===t&&(x=structuredClone(t));for(const d of y)H(x,d)===void 0&&L(x,d,"")}const C=c.filter(function(d){return!b.has(d)});if(C.length>0){x===t&&(x=structuredClone(t));for(const d of C)ge(x,d)}return{config:x,renames:w}}function ie(e){const n=[];for(const t of e||[])K(t)||(t.fieldType==="section"&&Array.isArray(t.fields)?n.push(...ie(t.fields)):n.push(t));return n}function Z(e){const n=e.answer;if(n==null)return"";if(e.fieldType==="dropdown"&&e.options){const t=e.options.find(i=>i.id===n||i.value===n);if(t)return t.value}return n}function le(e){const n=e.answer;return Array.isArray(n)?e.options?n.map(t=>{const i=e.options.find(o=>o.id===t||o.value===t);return i?i.value:t}):n:[]}function be(e){return e.options?e.options.map(n=>n.value):[]}function K(e){return e.fieldType==="section"&&/^sec-tool-\d+$/.test(e.id)}function xe(e){return(e||[]).filter(n=>K(n))}function $(e,n){const t=(e.fields||[]).find(i=>i.id.endsWith("-"+n));return t?Z(t):""}function at(e,n){const t=xe(e.fields||[]),i=[];for(const o of t){const s=$(o,"name"),u=$(o,"description"),c=$(o,"endpoint"),a=$(o,"method"),x=$(o,"params");let w;try{w=x?JSON.parse(x):{type:"object",properties:{},required:[]}}catch{w={type:"object",properties:{},required:[]}}const g={name:s,description:u,inputSchema:w};c&&(g.endpoint=c),a&&a!=="GET"&&(g.method=a),i.push(g)}n.tools=i}function we(e,n){const t=structuredClone(n),i=ie(e.fields||[]);xe(e.fields||[]).length>0&&at(e,t);for(const s of i){const u=s.configTransform;if(u==="genericToolsInvert"){const x=le(s),w=be(s),g=O(s);L(t,g,w.filter(b=>!x.includes(b)));continue}if(u==="elevenLabsDictIds"){const x=(Z(s)||"").split(",").map(y=>y.trim()).filter(Boolean),w=i.find(y=>y.configTransform==="elevenLabsDictVersions"),g=w?(Z(w)||"").split(",").map(y=>y.trim()).filter(Boolean):[],b=O(s);L(t,b,x.map((y,C)=>({pronunciation_dictionary_id:y,version_id:g[C]||""})));continue}if(u==="elevenLabsDictVersions")continue;const c=O(s),a=s.configType||"string";s.fieldType==="check"?L(t,c,le(s)):L(t,c,pe(Z(s),a))}return t}function J(e,n){const t=structuredClone(n);return je(t.fields,e),t}function je(e,n){for(const t of e||[]){if(K(t))continue;if(t.fieldType==="section"&&Array.isArray(t.fields)){je(t.fields,n);continue}const i=t.configTransform;if(i==="genericToolsInvert"){const u=O(t),c=H(n,u)||[],w=be(t).filter(g=>!c.includes(g)).map(function(g){const b=(t.options||[]).find(function(y){return y.value===g});return b?b.id:g});t.selected=w,t.answer=w;continue}if(i==="elevenLabsDictIds"){const u=O(t),c=H(n,u)||[];t.answer=c.map(a=>a.pronunciation_dictionary_id).join(", ");continue}if(i==="elevenLabsDictVersions"){const u=O(t).replace(/__versions$/,""),c=H(n,u)||[];t.answer=c.map(a=>a.version_id).join(", ");continue}const o=O(t),s=H(n,o);if(t.fieldType==="check"){const u=Array.isArray(s)?s:[],c=t.options?u.map(function(a){const x=t.options.find(function(w){return w.value===a||w.id===a});return x?x.id:a}):u;t.selected=c,t.answer=c;continue}if(t.fieldType==="dropdown"&&t.options){const u=t.options.find(c=>c.value===String(s??""));t.selected=u?u.id:null,t.answer=u?u.value:String(s??"");continue}t.answer=s!=null?String(s):""}}function Te(e){const n={_id:it(),tools:[]},t=ie((e==null?void 0:e.fields)||[]);for(const i of t){if(i.id==="_id")continue;const o=i.configTransform;if(o==="genericToolsInvert"){L(n,O(i),[]);continue}if(o==="elevenLabsDictIds"){L(n,O(i),[]);continue}if(o==="elevenLabsDictVersions")continue;const s=O(i),u=i.configType||"string";i.fieldType==="check"?L(n,s,Array.isArray(i.answer)?i.answer:[]):L(n,s,pe(i.answer??"",u))}return n}function ct(e){if(!Array.isArray(e))return e;if(e.length>0&&e[0]&&typeof e[0]=="object"&&"value"in e[0]){var n=e.map(function(t){return t.value});return n.length===1?n[0]:n}return e}function Ce(e,n){n||(n={});for(var t=0;t<(e||[]).length;t++){var i=e[t];i.id&&i.answer!==void 0&&(n[i.id]=ct(i.answer)),i.fields&&Ce(i.fields,n)}return n}function Se(e,n){for(var t=0;t<(e||[]).length;t++){var i=e[t];i.id&&n[i.id]!==void 0&&(i.answer=n[i.id]),i.fields&&Se(i.fields,n)}}function Ae({config:e,schema:n,onConfigChange:t}){const i=n||W,o=j.useRef(null),s=j.useRef(null),u=j.useRef(e),c=j.useRef(i),a=j.useRef(t);u.current=e,c.current=i,a.current=t;const x=j.useMemo(()=>J(e,i),[e,i]),w=j.useCallback(function(){if(o.current)try{var g=o.current.getResponse();if(!g)return;var b=g.fields||g;if(!Array.isArray(b)&&typeof b=="object"&&!b.length&&(b=g.fields),!b)return;var y=Ce(Array.isArray(b)?b:[b]);if(Object.keys(y).length===0)return;var C=structuredClone(c.current);Se(C.fields,y);var d=we(C,u.current);a.current(d)}catch(l){console.error("[FormBuilder] syncConfig error:",l)}},[]);return j.useEffect(function(){var g=s.current;if(!g)return;var b=null;function y(){clearTimeout(b),b=setTimeout(w,50)}return g.addEventListener("input",y),g.addEventListener("change",y),g.addEventListener("click",y),function(){clearTimeout(b),g.removeEventListener("input",y),g.removeEventListener("change",y),g.removeEventListener("click",y)}},[w]),r.jsxs("div",{ref:s,className:"max-w-6xl mx-auto p-6 rounded-lg shadow",style:{background:"var(--mieweb-card)",borderRadius:"var(--mieweb-radius-lg, 0.75rem)"},children:[r.jsx("h2",{className:"text-2xl font-bold mb-6",style:{color:"var(--mieweb-foreground)"},children:"General Configuration"}),r.jsx(Ke.QuestionnaireRenderer,{ref:o,formData:x,hideUnsupportedFields:!0})]})}function Ne({yamlOutput:e,jsonOutput:n,editorMode:t,onEditorModeChange:i,onEditorChange:o,onDownload:s}){return r.jsxs(T.Card,{padding:"none",className:"h-[calc(100vh-10rem)] max-w-full overflow-hidden flex flex-col",children:[r.jsxs("div",{className:"p-2 border-b flex justify-between items-center flex-shrink-0",style:{background:"var(--mieweb-muted)"},children:[r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx("div",{className:"flex rounded gap-1",children:["yaml","json"].map(function(u){var c=t===u;return r.jsx("button",{onClick:function(){i(u)},className:"px-3 h-7 text-sm rounded transition-all "+(c?"":"ivr-hover"),style:c?{background:"var(--mieweb-primary-700, #1786b3)",color:"var(--mieweb-primary-foreground, #fff)",fontWeight:600}:{background:"transparent",color:"var(--mieweb-neutral-600, #525252)"},children:u.toUpperCase()},u)})}),r.jsxs("span",{className:"hidden sm:block text-sm font-medium",style:{color:"var(--mieweb-muted-foreground)"},children:["config.",t]})]}),r.jsxs("div",{className:"flex items-center gap-1",children:[s&&r.jsx(T.Button,{variant:"primary",size:"sm",onClick:function(){s(t)},leftIcon:r.jsx(I.Download,{className:"h-4 w-4"}),"aria-label":`Download config.${t}`,children:r.jsxs("span",{className:"hidden sm:inline",children:["Download .",t]})}),r.jsx(T.Button,{variant:"ghost",size:"icon",onClick:function(){he(t==="yaml"?e:n)},"aria-label":"Copy to clipboard",className:"ivr-hover h-8 w-8",style:{color:"var(--mieweb-muted-foreground)"},children:r.jsx(I.Copy,{className:"h-4 w-4"})})]})]}),r.jsx(Ye,{height:"100%",language:t,value:t==="yaml"?e:n,onChange:function(u){o(u,t)},options:{minimap:{enabled:!1},fontSize:14}},t)]})}const ut=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"object",label:"Object"},{value:"array",label:"Array"}],dt=[{value:"string",label:"String"},{value:"number",label:"Number"},{value:"boolean",label:"Boolean"},{value:"object",label:"Object"}],ae=new Set(["string","number"]);function ce({value:e,onChange:n,size:t,...i}){const[o,s]=j.useState(e);j.useEffect(function(){s(e)},[e]);function u(){if(o!==e){var a=n(o);a===!1&&s(e)}}function c(a){a.key==="Enter"&&a.target.blur()}return r.jsx(T.Input,{...i,size:t||"sm",value:o,onChange:function(a){s(a.target.value)},onBlur:u,onKeyDown:c})}function ue({values:e,onChange:n}){const[t,i]=j.useState((e||[]).join(", "));j.useEffect(function(){i((e||[]).join(", "))},[e]);function o(s){var u=s.split(",").map(function(c){return c.trim()}).filter(function(c){return c!==""});n(u)}return r.jsx(T.Input,{size:"sm",value:t,onChange:function(s){i(s.target.value)},onBlur:function(){o(t)},onKeyDown:function(s){s.key==="Enter"&&s.target.blur()},placeholder:"e.g. dev, staging, prod"})}function ke({config:e,onConfigChange:n}){var C;function t(d){var l=structuredClone(e);d(l),n(l)}function i(){t(function(d){d.tools||(d.tools=[]);for(var l=1;d.tools.some(function(f){return f.name==="tool_"+l});)l++;d.tools.push({name:"tool_"+l,description:"Description of the tool",inputSchema:{type:"object",properties:{},required:[]}})})}function o(d){t(function(l){l.tools.splice(d,1)})}function s(d,l,f){if(l==="name"){var p=e.tools[d].name;if(f!==p){var m=e.tools.some(function(v,_){return _!==d&&v.name===f});if(m)return alert('Tool name "'+f+'" already exists.'),!1}}return t(function(v){v.tools[d].name,v.tools[d][l]=f}),!0}function u(d){t(function(l){var f=l.tools[d];f.inputSchema||(f.inputSchema={type:"object",properties:{},required:[]}),f.inputSchema.properties||(f.inputSchema.properties={});for(var p=1;f.inputSchema.properties["param_"+p];)p++;f.inputSchema.properties["param_"+p]={type:"string",description:"Parameter description"}})}function c(d,l,f,p){if(l!==f){var m=e.tools[d];if(m.inputSchema.properties[f])return alert('Parameter "'+f+'" already exists.'),!1}return t(function(v){var _=v.tools[d],P=_.inputSchema.properties;if(l!==f){var z={};Object.keys(P).forEach(function(k){z[k===l?f:k]=k===l?p:P[k]}),_.inputSchema.properties=z,_.inputSchema.required&&_.inputSchema.required.includes(l)&&(_.inputSchema.required=_.inputSchema.required.map(function(k){return k===l?f:k}))}else P[l]=p}),!0}function a(d,l){t(function(f){var p=f.tools[d];delete p.inputSchema.properties[l],p.inputSchema.required&&(p.inputSchema.required=p.inputSchema.required.filter(function(m){return m!==l}))})}function x(d,l){t(function(f){var p=f.tools[d];p.inputSchema.required||(p.inputSchema.required=[]),p.inputSchema.required.includes(l)?p.inputSchema.required=p.inputSchema.required.filter(function(m){return m!==l}):p.inputSchema.required.push(l)})}function w(d,l,f,p){var m={type:p,description:f.description||""};f.default!==void 0&&(m.default=f.default),p==="array"&&(m.items=f.items||{type:"string"}),ae.has(p)&&f.enum&&(m.enum=f.enum),c(d,l,l,m)}function g(d,l,f,p){c(d,l,l,{...f,items:{type:p}})}function b(d,l,f,p){var m={...f};p?m.enum=[]:delete m.enum,c(d,l,l,m)}function y(d,l,f,p){var m={...f,enum:p};if(m.default!==void 0){var v=p.map(String);v.includes(String(m.default))||(m.default=p.length>0?p[0]:void 0,m.default===void 0&&delete m.default)}c(d,l,l,m)}return r.jsxs("div",{className:"max-w-4xl mx-auto",children:[r.jsxs("div",{className:"flex justify-between items-center mb-6",children:[r.jsx("h2",{className:"text-2xl font-bold",style:{color:"var(--mieweb-foreground)"},children:"Tool Builder"}),r.jsx(T.Button,{variant:"primary",size:"sm",onClick:i,leftIcon:r.jsx(I.Plus,{className:"h-4 w-4"}),children:"Add Tool"})]}),r.jsxs("div",{className:"space-y-4",children:[(C=e.tools)==null?void 0:C.map(function(d,l){var f,p;return r.jsxs(T.Card,{padding:"md",className:"relative",children:[r.jsx(T.Button,{variant:"ghost",size:"icon",onClick:function(){o(l)},className:"absolute top-3 right-3 ivr-hover-destructive",style:{color:"var(--mieweb-destructive)"},"aria-label":"Remove tool",children:r.jsx(I.Trash2,{className:"h-5 w-5"})}),r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-4",children:[r.jsx(ce,{label:"Tool Name",value:d.name,onChange:function(m){return s(l,"name",m)},size:"md"}),r.jsx(T.Input,{label:"Description",size:"md",value:d.description,onChange:function(m){s(l,"description",m.target.value)}})]}),r.jsxs("div",{className:"p-4 rounded-lg border",style:{background:"var(--mieweb-muted)",borderColor:"var(--mieweb-border)",borderRadius:"var(--mieweb-radius-lg, 0.75rem)"},children:[r.jsxs("div",{className:"flex justify-between items-center mb-3",children:[r.jsx("h4",{className:"font-medium text-sm",style:{color:"var(--mieweb-foreground)"},children:"Input Schema Parameters"}),r.jsx(T.Button,{variant:"primary",size:"sm",onClick:function(){u(l)},leftIcon:r.jsx(I.Plus,{className:"h-3 w-3"}),children:"Add Parameter"})]}),r.jsx("div",{className:"space-y-2",children:((f=d.inputSchema)==null?void 0:f.properties)&&Object.entries(d.inputSchema.properties).map(function([m,v],_){var E,R,Y;var P=v.type==="array",z=ae.has(v.type),k=Array.isArray(v.enum);return r.jsxs("div",{className:"rounded border p-2 space-y-2",style:{background:"var(--mieweb-card)",borderColor:"var(--mieweb-border)"},children:[r.jsxs("div",{className:"flex flex-col md:flex-row gap-2 items-start",children:[r.jsx("div",{className:"w-full md:w-36 flex-shrink-0",children:r.jsx(ce,{value:m,onChange:function(S){return c(l,m,S,v)},placeholder:"Name",size:"sm"})}),r.jsx("div",{className:"w-full md:w-28 flex-shrink-0",children:r.jsx(T.Select,{options:ut,value:v.type,onValueChange:function(S){w(l,m,v,S)},size:"sm"})}),P&&r.jsx("div",{className:"w-full md:w-32 flex-shrink-0",children:r.jsx(T.Select,{options:dt,value:((E=v.items)==null?void 0:E.type)||"string",onValueChange:function(S){g(l,m,v,S)},size:"sm"})}),r.jsx("div",{className:"w-full flex-1",children:r.jsx(T.Input,{size:"sm",value:v.description||"",onChange:function(S){c(l,m,m,{...v,description:S.target.value})},placeholder:"Description"})}),r.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0 mt-1 md:mt-0",children:[r.jsx(T.Checkbox,{label:"Req",size:"sm",checked:(R=d.inputSchema.required)==null?void 0:R.includes(m),onChange:function(){x(l,m)}}),r.jsx(T.Checkbox,{label:"Default",size:"sm",checked:v.default!==void 0,onChange:function(S){var D={...v};S.target.checked?P?D.default=[]:k&&v.enum&&v.enum.length>0?D.default=v.enum[0]:D.default="":delete D.default,c(l,m,m,D)}}),r.jsx(T.Button,{variant:"ghost",size:"icon",onClick:function(){a(l,m)},className:"ivr-hover-destructive h-8 w-8",style:{color:"var(--mieweb-destructive)"},"aria-label":"Remove parameter",children:r.jsx(I.Trash2,{className:"h-4 w-4"})})]})]}),v.default!==void 0&&r.jsxs("div",{className:"flex gap-2 items-center pl-1",children:[r.jsx("span",{className:"text-xs w-16 flex-shrink-0",style:{color:"var(--mieweb-muted-foreground)"},children:"Default:"}),r.jsx("div",{className:"flex-1",children:P?r.jsxs("div",{className:"flex gap-2 items-center",children:[r.jsx("div",{className:"flex-1",children:r.jsx(ue,{values:Array.isArray(v.default)?v.default:[],onChange:function(S){c(l,m,m,{...v,default:S})}})}),r.jsx("span",{className:"text-xs whitespace-nowrap",style:{color:"var(--mieweb-muted-foreground)"},children:"comma-separated"})]}):k&&v.enum&&v.enum.length>0?r.jsx(T.Select,{size:"sm",options:v.enum.map(function(S){return{value:String(S),label:String(S)}}),value:String(v.default),onValueChange:function(S){c(l,m,m,{...v,default:S})}}):k?r.jsx("span",{className:"text-xs italic",style:{color:"var(--mieweb-warning)"},children:"Add enum values first to pick a default"}):r.jsx(T.Input,{size:"sm",value:v.default,onChange:function(S){c(l,m,m,{...v,default:S.target.value})},placeholder:"Default value"})})]}),z&&r.jsxs("div",{className:"flex flex-col gap-1 pl-1",children:[r.jsx(T.Checkbox,{label:"Enum — restrict to allowed values",size:"sm",checked:k,onChange:function(S){b(l,m,v,S.target.checked)}}),k&&r.jsxs("div",{className:"flex gap-2 items-start pl-5",children:[r.jsx("div",{className:"flex-1",children:r.jsx(ue,{values:v.enum,onChange:function(S){y(l,m,v,S)}})}),r.jsx("span",{className:"text-xs mt-2 whitespace-nowrap",style:{color:"var(--mieweb-muted-foreground)"},children:"comma-separated"})]}),k&&v.enum&&v.enum.length>0&&r.jsx("div",{className:"pl-5 flex flex-wrap gap-1",children:v.enum.map(function(S){return r.jsx("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:S},S)})})]}),P&&r.jsxs("div",{className:"pl-1 text-xs text-gray-500",children:["Items type: ",r.jsx("span",{className:"font-medium text-gray-700",children:((Y=v.items)==null?void 0:Y.type)||"string"})," ","— the array selector above controls this"]})]},_)})}),(!((p=d.inputSchema)!=null&&p.properties)||Object.keys(d.inputSchema.properties).length===0)&&r.jsx("p",{className:"text-sm text-gray-500 italic",children:"No parameters defined."})]})]},l)}),(!e.tools||e.tools.length===0)&&r.jsx("div",{className:"text-center py-12 text-gray-500",children:"No custom tools defined. Click “Add Tool” to create one."})]})]})}function ft({initialConfig:e,schema:n,onConfigChange:t,onDownload:i,onSubmit:o,showEditor:s=!0}){const[u,c]=j.useState(function(){return e||Te(n||W)}),[a,x]=j.useState("form"),[w,g]=j.useState("yaml"),[b,y]=j.useState(""),[C,d]=j.useState(""),[l,f]=j.useState(n||W),[p,m]=j.useState(!1),[v,_]=j.useState(null),[P,z]=j.useState(0);j.useEffect(function(){if(!v)return;const h=setTimeout(function(){_(null)},5e3);return function(){clearTimeout(h)}},[v]);const k=j.useRef(null),E=j.useRef(null),R=j.useRef(u);R.current=u,j.useEffect(function(){try{y(X(u)),d(JSON.stringify(u,null,2))}catch(h){console.error("Error generating output",h)}},[u]),j.useEffect(function(){try{a==="editor"&&(w==="yaml"?y(X(u)):w==="json"&&d(JSON.stringify(u,null,2)))}catch(h){console.error("Error resetting output on tab change",h)}},[a,w,u]),j.useEffect(function(){t&&t(u)},[u,t]);function Y(h){R.current=h,c(h)}function S(h){if(Array.isArray(h))return h.map(S);if(h!==null&&typeof h=="object"){var N={};for(var A of Object.keys(h))N[A]=S(h[A]);return N}return h===null?"":h}function D(h,N){try{let A;N==="yaml"?(y(h),A=S(ne.load(h))):(d(h),A=JSON.parse(h)),A&&typeof A=="object"&&(f(function(F){return ot(u,A,F)}),c(A),z(function(F){return F+1}))}catch{}}function qe(h){me(u,b,i,h||"yaml",C)}const[Q,Ie]=j.useState(null);j.useEffect(function(){p&&!Q&&import("@mieweb/forms-editor").then(function(h){Ie(function(){return h.QuestionnaireEditor})})},[p,Q]);const _e=j.useCallback(function(){var h;(h=E.current)==null||h.call(E),f(function(N){return J(R.current,N)}),m(!0)},[]),Ee=j.useCallback(function(){var h;(h=E.current)==null||h.call(E),f(function(N){return z(function(A){return A+1}),J(R.current,N)}),m(!1)},[]),Re=new Set(["text","longtext","dropdown","check","section"]);function Pe(h){let N=0;function A(U){return Array.isArray(U)?U.reduce(function(V,B){return B.fieldType&&!Re.has(B.fieldType)?(N++,V):Array.isArray(B.fields)?V.concat([{...B,fields:A(B.fields)}]):V.concat([B])},[]):U}return{filtered:{...h,fields:A(h.fields)},removedCount:N}}const Le=j.useCallback(function(h){const{filtered:N,removedCount:A}=Pe(h);A>0&&_(`${A} unsupported field type${A>1?"s were":" was"} removed. Only Text, Long Text, Dropdown, and Checkbox fields are supported.`),f(function(F){const U=lt(F,N,R.current);return U.config!==R.current&&c(U.config),N})},[]),Oe=j.useCallback(function(){const h=new Blob([JSON.stringify(l,null,2)],{type:"application/json"}),N=URL.createObjectURL(h),A=document.createElement("a");A.href=N,A.download=(l.title||"form-schema").replace(/\s+/g,"-").toLowerCase()+".json",document.body.appendChild(A),A.click(),document.body.removeChild(A),URL.revokeObjectURL(N)},[l]),ze=j.useCallback(function(h){var F;const N=(F=h.target.files)==null?void 0:F[0];if(!N)return;const A=new FileReader;A.onload=function(U){try{const V=JSON.parse(U.target.result);if(!V.fields||!Array.isArray(V.fields)){alert('Invalid schema file: missing "fields" array.');return}f(J(R.current,V)),z(function(B){return B+1})}catch(V){alert("Failed to parse schema file: "+V.message)}},A.readAsText(N),h.target.value=""},[]),Fe=j.useCallback(function(){var h;window.confirm("Reset the form to the default Agent schema? Any custom fields will be lost.")&&((h=E.current)==null||h.call(E),f(J(R.current,W)),z(function(N){return N+1}))},[]);return r.jsx("div",{className:"flex flex-col h-full",style:{fontFamily:"var(--mieweb-font-sans, inherit)"},children:r.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[r.jsx("div",{className:"shadow-sm border-b",style:{background:"var(--mieweb-card)",borderColor:"var(--mieweb-border)"},children:r.jsxs("div",{className:"px-4 flex items-center justify-between gap-2 flex-wrap",children:[r.jsx(T.Tabs,{value:a,onValueChange:function(h){x(h),m(!1)},variant:"underline",children:r.jsxs(T.TabsList,{className:"border-b-0",children:[r.jsxs(T.TabsTrigger,{value:"form",className:"gap-2 px-3 py-3 text-sm",children:[r.jsx(I.Settings,{className:"h-4 w-4"}),r.jsx("span",{className:"hidden sm:inline",children:"Form Builder"})]}),r.jsxs(T.TabsTrigger,{value:"tools",className:"gap-2 px-3 py-3 text-sm",children:[r.jsx(I.Wrench,{className:"h-4 w-4"}),r.jsx("span",{className:"hidden sm:inline",children:"Tool Builder"})]}),s&&r.jsxs(T.TabsTrigger,{value:"editor",className:"gap-2 px-3 py-3 text-sm",children:[r.jsx(I.Code,{className:"h-4 w-4"}),r.jsx("span",{className:"hidden sm:inline",children:"Config Editor"})]})]})}),o&&r.jsx(T.Button,{variant:"primary",size:"sm",onClick:()=>o(b),leftIcon:r.jsx(I.Send,{className:"h-4 w-4"}),className:"my-1 shrink-0",children:r.jsx("span",{className:"hidden sm:inline",children:"Submit"})})]})}),r.jsxs("div",{className:"flex-1 overflow-auto p-4 md:p-6",children:[r.jsxs("div",{style:{display:a==="form"&&!p?"":"none"},children:[r.jsxs("div",{className:"max-w-6xl mx-auto mb-4 flex flex-wrap items-center justify-between gap-2",children:[r.jsx(T.Button,{variant:"primary",size:"sm",onClick:_e,leftIcon:r.jsx(I.Pencil,{className:"h-4 w-4"}),children:"Customize Form"}),r.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[r.jsx(T.Button,{variant:"primary",size:"sm",onClick:Oe,leftIcon:r.jsx(I.Download,{className:"h-4 w-4"}),title:"Export schema as JSON",children:"Export"}),r.jsx(T.Button,{variant:"primary",size:"sm",onClick:function(){var h;(h=k.current)==null||h.click()},leftIcon:r.jsx(I.Upload,{className:"h-4 w-4"}),title:"Import a schema JSON file",children:"Import"}),r.jsx("input",{ref:k,type:"file",accept:".json",className:"hidden",onChange:ze}),r.jsx(T.Button,{variant:"ghost",size:"sm",onClick:Fe,leftIcon:r.jsx(I.RotateCcw,{className:"h-4 w-4"}),style:{color:"var(--mieweb-destructive)"},className:"ivr-hover-destructive",title:"Reset to default Agent schema",children:"Reset"})]})]}),r.jsx(Ae,{config:u,schema:l,onConfigChange:Y,syncRef:E},P)]}),a==="form"&&p&&r.jsxs("div",{className:"max-w-7xl mx-auto",children:[r.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[r.jsx(T.Button,{variant:"ghost",size:"sm",onClick:Ee,leftIcon:r.jsx(I.ArrowLeft,{className:"h-4 w-4"}),children:"Back to Form"}),r.jsxs("span",{className:"text-sm",style:{color:"var(--mieweb-muted-foreground)"},children:["Add, remove, or reorder fields. The field ",r.jsx("code",{className:"text-xs px-1 rounded",style:{background:"var(--mieweb-muted)",color:"var(--mieweb-foreground)"},children:"ID"})," is used as the config key (dot-notation for nesting, e.g. ",r.jsx("code",{className:"text-xs px-1 rounded",style:{background:"var(--mieweb-muted)",color:"var(--mieweb-foreground)"},children:"twilio.phoneNumber"}),")."]})]}),v&&r.jsx(T.Alert,{variant:"warning",dismissible:!0,onDismiss:function(){_(null)},className:"mb-3",children:r.jsx(T.AlertDescription,{children:v})}),r.jsx("div",{className:"rounded-lg shadow p-4 min-h-[600px]",style:{background:"var(--mieweb-card)",borderRadius:"var(--mieweb-radius-lg, 0.75rem)"},children:Q?r.jsx(Q,{initialFormData:l||void 0,onChange:Le}):r.jsx("div",{className:"flex items-center justify-center h-64",style:{color:"var(--mieweb-muted-foreground)"},children:"Loading form editor..."})})]}),a==="editor"&&s&&r.jsx(Ne,{yamlOutput:b,jsonOutput:C,editorMode:w,onEditorModeChange:g,onEditorChange:D,onDownload:qe}),a==="tools"&&r.jsx(ke,{config:u,onConfigChange:Y})]})]})})}exports.AgentConfigGenerator=ft;exports.ConfigEditor=Ne;exports.FormBuilder=Ae;exports.ToolBuilder=ke;exports.configToQuestionnaire=J;exports.configToYaml=X;exports.copyToClipboard=he;exports.defaultSchema=W;exports.deriveDefaultConfig=Te;exports.downloadConfig=me;exports.questionnaireToConfig=we;exports.validateConfig=fe;exports.yamlToConfig=Xe;