@bikdotai/bik-component-library 0.0.852 → 0.0.853

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.
Files changed (79) hide show
  1. package/dist/cjs/components/agent-builder/AgentBuilder.js +1 -1
  2. package/dist/cjs/components/agent-builder/AgentBuilder.js.map +1 -1
  3. package/dist/cjs/components/agent-builder/components/AgentBuilderFooter.js +1 -1
  4. package/dist/cjs/components/agent-builder/components/AgentBuilderFooter.js.map +1 -1
  5. package/dist/cjs/components/agent-builder/components/AgentBuilderTopBar.js +1 -1
  6. package/dist/cjs/components/agent-builder/components/AgentBuilderTopBar.js.map +1 -1
  7. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js +5 -5
  8. package/dist/cjs/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  9. package/dist/cjs/components/agent-builder/components/GoLiveModal.js +1 -1
  10. package/dist/cjs/components/agent-builder/components/GoLiveModal.js.map +1 -1
  11. package/dist/cjs/components/agent-builder/components/MentionPicker.js +24 -24
  12. package/dist/cjs/components/agent-builder/components/MentionPicker.js.map +1 -1
  13. package/dist/cjs/components/agent-builder/components/RequireVerificationModal.js +1 -1
  14. package/dist/cjs/components/agent-builder/components/RequireVerificationModal.js.map +1 -1
  15. package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js +2 -2
  16. package/dist/cjs/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
  17. package/dist/cjs/components/agent-builder/components/SelectableListSection.js +1 -1
  18. package/dist/cjs/components/agent-builder/components/SelectableListSection.js.map +1 -1
  19. package/dist/cjs/components/agent-builder/constants/tools.js +1 -1
  20. package/dist/cjs/components/agent-builder/constants/tools.js.map +1 -1
  21. package/dist/cjs/components/agent-builder/steps/Step3HowItResponds.js +1 -1
  22. package/dist/cjs/components/agent-builder/steps/Step3HowItResponds.js.map +1 -1
  23. package/dist/cjs/components/agent-builder/utils/sourceIcons.js +1 -1
  24. package/dist/cjs/components/agent-builder/utils/sourceIcons.js.map +1 -1
  25. package/dist/cjs/components/agent-listing/AgentTableRow.js +1 -1
  26. package/dist/cjs/components/agent-listing/AgentTableRow.js.map +1 -1
  27. package/dist/cjs/components/agent-listing/AiAgentsEmptyState.js +1 -1
  28. package/dist/cjs/components/agent-listing/AiAgentsEmptyState.js.map +1 -1
  29. package/dist/cjs/components/zeroState/ZeroState.js +3 -3
  30. package/dist/cjs/components/zeroState/ZeroState.js.map +1 -1
  31. package/dist/cjs/editor/BikEditor.js +1 -1
  32. package/dist/cjs/editor/BikEditor.js.map +1 -1
  33. package/dist/cjs/editor/BikEditor.styles.js +22 -16
  34. package/dist/cjs/editor/BikEditor.styles.js.map +1 -1
  35. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js +3 -3
  36. package/dist/cjs/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -1
  37. package/dist/esm/components/agent-builder/AgentBuilder.js +146 -136
  38. package/dist/esm/components/agent-builder/AgentBuilder.js.map +1 -1
  39. package/dist/esm/components/agent-builder/AgentBuilder.model.d.ts +7 -2
  40. package/dist/esm/components/agent-builder/components/AgentBuilderFooter.d.ts +2 -0
  41. package/dist/esm/components/agent-builder/components/AgentBuilderFooter.js +29 -26
  42. package/dist/esm/components/agent-builder/components/AgentBuilderFooter.js.map +1 -1
  43. package/dist/esm/components/agent-builder/components/AgentBuilderTopBar.js +30 -29
  44. package/dist/esm/components/agent-builder/components/AgentBuilderTopBar.js.map +1 -1
  45. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.d.ts +9 -0
  46. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js +199 -184
  47. package/dist/esm/components/agent-builder/components/CreateSubAgentPanel.js.map +1 -1
  48. package/dist/esm/components/agent-builder/components/GoLiveModal.js +11 -13
  49. package/dist/esm/components/agent-builder/components/GoLiveModal.js.map +1 -1
  50. package/dist/esm/components/agent-builder/components/MentionPicker.js +174 -150
  51. package/dist/esm/components/agent-builder/components/MentionPicker.js.map +1 -1
  52. package/dist/esm/components/agent-builder/components/RequireVerificationModal.js +8 -8
  53. package/dist/esm/components/agent-builder/components/RequireVerificationModal.js.map +1 -1
  54. package/dist/esm/components/agent-builder/components/RestApiToolPanel.js +54 -51
  55. package/dist/esm/components/agent-builder/components/RestApiToolPanel.js.map +1 -1
  56. package/dist/esm/components/agent-builder/components/SelectableListSection.js +73 -69
  57. package/dist/esm/components/agent-builder/components/SelectableListSection.js.map +1 -1
  58. package/dist/esm/components/agent-builder/constants/tools.d.ts +20 -0
  59. package/dist/esm/components/agent-builder/constants/tools.js +34 -23
  60. package/dist/esm/components/agent-builder/constants/tools.js.map +1 -1
  61. package/dist/esm/components/agent-builder/steps/Step3HowItResponds.js +270 -255
  62. package/dist/esm/components/agent-builder/steps/Step3HowItResponds.js.map +1 -1
  63. package/dist/esm/components/agent-builder/utils/sourceIcons.d.ts +6 -6
  64. package/dist/esm/components/agent-builder/utils/sourceIcons.js +21 -19
  65. package/dist/esm/components/agent-builder/utils/sourceIcons.js.map +1 -1
  66. package/dist/esm/components/agent-listing/AgentTableRow.js +26 -23
  67. package/dist/esm/components/agent-listing/AgentTableRow.js.map +1 -1
  68. package/dist/esm/components/agent-listing/AiAgentsEmptyState.js +3 -2
  69. package/dist/esm/components/agent-listing/AiAgentsEmptyState.js.map +1 -1
  70. package/dist/esm/components/zeroState/ZeroState.d.ts +2 -0
  71. package/dist/esm/components/zeroState/ZeroState.js +18 -17
  72. package/dist/esm/components/zeroState/ZeroState.js.map +1 -1
  73. package/dist/esm/editor/BikEditor.js +236 -223
  74. package/dist/esm/editor/BikEditor.js.map +1 -1
  75. package/dist/esm/editor/BikEditor.styles.js +18 -12
  76. package/dist/esm/editor/BikEditor.styles.js.map +1 -1
  77. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js +62 -60
  78. package/dist/esm/editor/extensions/jsonHighlight/JsonHighlightExtension.js.map +1 -1
  79. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../../node_modules/@tiptap/core/dist/index.js"),l=require("@tiptap/pm/state"),d=require("@tiptap/pm/view"),g=require("./tokenizeJson.js"),p={key:"bik-json-key",string:"bik-json-string",number:"bik-json-number",boolean:"bik-json-boolean",null:"bik-json-null",punctuation:"bik-json-punct"};function f(r){return r.trim().length===0?0:r.split(`
2
- `).length}class m{dom;contentDOM;gutter;constructor(n){const t=document.createElement("pre"),e=document.createElement("div");e.className="bik-json-gutter",e.contentEditable="false";const o=document.createElement("code");t.appendChild(e),t.appendChild(o),this.dom=t,this.contentDOM=o,this.gutter=e,this.renderGutter(n)}renderGutter(n){const t=f(n.textContent);if(this.gutter.childElementCount===t)return;const e=[];for(let o=1;o<=t;o++){const s=document.createElement("span");s.className="bik-json-lineno",s.textContent=String(o),e.push(s)}this.gutter.replaceChildren(...e)}update(n){return n.type.name!=="codeBlock"?!1:(this.renderGutter(n),!0)}ignoreMutation(n){return this.gutter===n.target||this.gutter.contains(n.target)}}const k=h.Extension.create({name:"jsonHighlight",priority:1e3,addKeyboardShortcuts(){return{Backspace:()=>{const{selection:r}=this.editor.state,{empty:n,$from:t}=r;return n&&t.parent.type.name==="codeBlock"&&t.parentOffset===0}}},addProseMirrorPlugins(){return[new l.Plugin({key:new l.PluginKey("jsonHighlightGuard"),appendTransaction(r,n,t){if(!r.some(u=>u.docChanged))return null;const{doc:e,schema:o}=t,s=o.nodes.codeBlock;if(!s||e.childCount===1&&e.firstChild?.type===s)return null;let i=!1;if(e.forEach(u=>{u.type===s&&(i=!0)}),i)return null;const a=e.textBetween(0,e.content.size,`
3
- `),c=t.tr;return c.replaceWith(0,e.content.size,s.create(null,a?o.text(a):null)),c.setSelection(l.TextSelection.create(c.doc,1)),c}}),new l.Plugin({key:new l.PluginKey("jsonHighlight"),props:{nodeViews:{codeBlock:r=>new m(r)},handlePaste(r,n){const t=n.clipboardData?.getData("text/plain");if(!t||!t.trim())return!1;let e;try{e=JSON.parse(t)}catch{return!1}const o=JSON.stringify(e,null,2);if(o===t)return!1;const{state:s,dispatch:i}=r,{from:a,to:c}=s.selection;return i(s.tr.insertText(o,a,c).scrollIntoView()),!0},decorations(r){const n=[];return r.doc.descendants((t,e)=>{if(t.type.name!=="codeBlock")return;const o=t.textContent;if(o.length===0)return;const s=e+1;for(const i of g.tokenizeJson(o))n.push(d.Decoration.inline(s+i.start,s+i.end,{class:p[i.type]}))}),d.DecorationSet.create(r.doc,n)}}})]}});exports.JsonHighlightExtension=k;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("../../../node_modules/@tiptap/core/dist/index.js"),a=require("@tiptap/pm/state"),d=require("@tiptap/pm/view"),g=require("./tokenizeJson.js"),p={key:"bik-json-key",string:"bik-json-string",number:"bik-json-number",boolean:"bik-json-boolean",null:"bik-json-null",punctuation:"bik-json-punct"};function m(o){return o.trim().length===0?0:o.split(`
2
+ `).length}class f{dom;contentDOM;gutter;constructor(e){const t=document.createElement("pre"),n=document.createElement("div");n.className="bik-json-gutter",n.contentEditable="false";const r=document.createElement("code");t.appendChild(n),t.appendChild(r),this.dom=t,this.contentDOM=r,this.gutter=n,this.renderGutter(e)}renderGutter(e){const t=m(e.textContent);if(this.gutter.childElementCount===t)return;const r=Math.max(2,String(Math.max(t,1)).length)*.6+1.1;this.gutter.style.width=`${r}em`,this.dom.style.paddingLeft=`${r+.7}em`;const s=[];for(let i=1;i<=t;i++){const c=document.createElement("span");c.className="bik-json-lineno",c.textContent=String(i),s.push(c)}this.gutter.replaceChildren(...s)}update(e){return e.type.name!=="codeBlock"?!1:(this.renderGutter(e),!0)}ignoreMutation(e){return this.gutter===e.target||this.gutter.contains(e.target)}}const k=h.Extension.create({name:"jsonHighlight",priority:1e3,addKeyboardShortcuts(){return{Backspace:()=>{const{selection:o}=this.editor.state,{empty:e,$from:t}=o;return e&&t.parent.type.name==="codeBlock"&&t.parentOffset===0}}},addProseMirrorPlugins(){return[new a.Plugin({key:new a.PluginKey("jsonHighlightGuard"),appendTransaction(o,e,t){if(!o.some(u=>u.docChanged))return null;const{doc:n,schema:r}=t,s=r.nodes.codeBlock;if(!s||n.childCount===1&&n.firstChild?.type===s)return null;let i=!1;if(n.forEach(u=>{u.type===s&&(i=!0)}),i)return null;const c=n.textBetween(0,n.content.size,`
3
+ `),l=t.tr;return l.replaceWith(0,n.content.size,s.create(null,c?r.text(c):null)),l.setSelection(a.TextSelection.create(l.doc,1)),l}}),new a.Plugin({key:new a.PluginKey("jsonHighlight"),props:{nodeViews:{codeBlock:o=>new f(o)},handlePaste(o,e){const t=e.clipboardData?.getData("text/plain");if(!t||!t.trim())return!1;let n;try{n=JSON.parse(t)}catch{return!1}const r=JSON.stringify(n,null,2);if(r===t)return!1;const{state:s,dispatch:i}=o,{from:c,to:l}=s.selection;return i(s.tr.insertText(r,c,l).scrollIntoView()),!0},decorations(o){const e=[];return o.doc.descendants((t,n)=>{if(t.type.name!=="codeBlock")return;const r=t.textContent;if(r.length===0)return;const s=n+1;for(const i of g.tokenizeJson(r))e.push(d.Decoration.inline(s+i.start,s+i.end,{class:p[i.type]}))}),d.DecorationSet.create(o.doc,e)}}})]}});exports.JsonHighlightExtension=k;
4
4
  //# sourceMappingURL=JsonHighlightExtension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"JsonHighlightExtension.js","sources":["../../../../../src/editor/extensions/jsonHighlight/JsonHighlightExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state';\nimport type { NodeView } from '@tiptap/pm/view';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\nimport { JsonTokenType, tokenizeJson } from './tokenizeJson';\n\nconst CLASS_BY_TYPE: Record<JsonTokenType, string> = {\n\tkey: 'bik-json-key',\n\tstring: 'bik-json-string',\n\tnumber: 'bik-json-number',\n\tboolean: 'bik-json-boolean',\n\tnull: 'bik-json-null',\n\tpunctuation: 'bik-json-punct',\n};\n\n/**\n * Visual line count of a code block's text (0 → no gutter). Whitespace-only\n * content counts as 0: that's exactly when BikEditor shows the placeholder\n * overlay (`jsonEmpty = !text.trim()`), so the gutter must be empty too —\n * otherwise a blank field shows a stray \"1\" behind the placeholder.\n */\nfunction lineCount(text: string): number {\n\treturn text.trim().length === 0 ? 0 : text.split('\\n').length;\n}\n\n/**\n * Node view for the JSON `codeBlock` that renders the line-number gutter as a\n * `contenteditable=false` sibling of the editable `<code>` — NOT as ProseMirror\n * widget decorations.\n *\n * Why: widget decorations are re-inserted into the content flow on every\n * decoration recompute (i.e. every keystroke). Re-inserting a node next to the\n * caret reset the contenteditable selection to the line start, so typing a JSON\n * key and then its `:` dropped the caret to the start of the line (MAP-7286).\n * A node view lets us update the gutter DOM independently of `contentDOM`, so\n * the caret is never touched — and we only rebuild it when the line count\n * actually changes.\n */\nclass JsonCodeBlockView implements NodeView {\n\tdom: HTMLPreElement;\n\tcontentDOM: HTMLElement;\n\tprivate gutter: HTMLElement;\n\n\tconstructor(node: ProseMirrorNode) {\n\t\tconst pre = document.createElement('pre');\n\t\tconst gutter = document.createElement('div');\n\t\tgutter.className = 'bik-json-gutter';\n\t\tgutter.contentEditable = 'false';\n\t\tconst code = document.createElement('code');\n\t\t// Gutter is absolutely positioned into the reserved left padding, so its\n\t\t// order relative to <code> doesn't affect the code layout.\n\t\tpre.appendChild(gutter);\n\t\tpre.appendChild(code);\n\n\t\tthis.dom = pre;\n\t\tthis.contentDOM = code;\n\t\tthis.gutter = gutter;\n\t\tthis.renderGutter(node);\n\t}\n\n\tprivate renderGutter(node: ProseMirrorNode): void {\n\t\tconst count = lineCount(node.textContent);\n\t\t// Nothing to do while the line count is unchanged — this is the common case\n\t\t// (typing within a line) and skipping it avoids touching the gutter DOM.\n\t\tif (this.gutter.childElementCount === count) {\n\t\t\treturn;\n\t\t}\n\t\tconst numbers: HTMLElement[] = [];\n\t\tfor (let n = 1; n <= count; n++) {\n\t\t\tconst span = document.createElement('span');\n\t\t\tspan.className = 'bik-json-lineno';\n\t\t\tspan.textContent = String(n);\n\t\t\tnumbers.push(span);\n\t\t}\n\t\tthis.gutter.replaceChildren(...numbers);\n\t}\n\n\tupdate(node: ProseMirrorNode): boolean {\n\t\tif (node.type.name !== 'codeBlock') {\n\t\t\treturn false;\n\t\t}\n\t\tthis.renderGutter(node);\n\t\treturn true;\n\t}\n\n\t// The gutter is ours to manage — never let ProseMirror parse it as content.\n\tignoreMutation(mutation: MutationRecord | { target: Node }): boolean {\n\t\treturn (\n\t\t\tthis.gutter === mutation.target || this.gutter.contains(mutation.target)\n\t\t);\n\t}\n}\n\n/**\n * Colours JSON tokens inside `codeBlock` nodes and renders a line-number gutter\n * (via {@link JsonCodeBlockView}). A code block stores its whole multi-line body\n * in a single text node, so token offsets map 1:1 onto document positions\n * (`nodeStart + offset`) — no cross-node bookkeeping needed.\n *\n * Purely decorative: the document text is never rewritten, so undo/redo,\n * character count and the cursor all behave exactly as with plain text.\n */\nexport const JsonHighlightExtension = Extension.create({\n\tname: 'jsonHighlight',\n\t// Above CodeBlock (default 100) so our Backspace handler runs first and can\n\t// veto CodeBlock's own \"clearNodes at start\" shortcut (which would lift the\n\t// block to a paragraph).\n\tpriority: 1000,\n\taddKeyboardShortcuts() {\n\t\treturn {\n\t\t\t// In JSON mode the document is a single code block. A Backspace at its very\n\t\t\t// start would lift it to a plain paragraph (killing the highlight, the\n\t\t\t// line-number gutter and the monospace font). There's nothing to delete\n\t\t\t// before the caret there anyway, so swallow it. Mid-text Backspace (and\n\t\t\t// deleting a leading `\\n` from line 2+) still works — those have\n\t\t\t// parentOffset > 0.\n\t\t\tBackspace: () => {\n\t\t\t\tconst { selection } = this.editor.state;\n\t\t\t\tconst { empty, $from } = selection;\n\t\t\t\treturn (\n\t\t\t\t\tempty &&\n\t\t\t\t\t$from.parent.type.name === 'codeBlock' &&\n\t\t\t\t\t$from.parentOffset === 0\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t},\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlightGuard'),\n\t\t\t\t// jsonMode invariant: the whole document is ONE codeBlock. Several\n\t\t\t\t// default Backspace paths can lift it to a plain paragraph — and one\n\t\t\t\t// of them, TipTap core's `clearDocument` appendTransaction (fired when\n\t\t\t\t// the whole doc is selected then deleted, e.g. Cmd-A → Backspace),\n\t\t\t\t// runs AFTER our Backspace shortcut, so a keymap veto can't stop it.\n\t\t\t\t// A paragraph has no gutter and no monospace rule, so the line numbers\n\t\t\t\t// and font vanish. Re-wrap the content back into a codeBlock whenever\n\t\t\t\t// something lifts it, restoring the invariant.\n\t\t\t\tappendTransaction(transactions, _oldState, newState) {\n\t\t\t\t\tif (!transactions.some((tr) => tr.docChanged)) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst { doc, schema } = newState;\n\t\t\t\t\tconst codeBlock = schema.nodes['codeBlock'];\n\t\t\t\t\tif (!codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// Common case: already a single codeBlock → nothing to do.\n\t\t\t\t\tif (doc.childCount === 1 && doc.firstChild?.type === codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// If a codeBlock survives anywhere, leave it alone (don't fight\n\t\t\t\t\t// legitimate multi-node edits that shouldn't happen in jsonMode).\n\t\t\t\t\tlet hasCodeBlock = false;\n\t\t\t\t\tdoc.forEach((node) => {\n\t\t\t\t\t\tif (node.type === codeBlock) {\n\t\t\t\t\t\t\thasCodeBlock = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (hasCodeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// A lift happened: rebuild a single codeBlock from the text\n\t\t\t\t\t// (block boundaries preserved as newlines, matching JSON lines).\n\t\t\t\t\tconst text = doc.textBetween(0, doc.content.size, '\\n');\n\t\t\t\t\tconst tr = newState.tr;\n\t\t\t\t\ttr.replaceWith(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tdoc.content.size,\n\t\t\t\t\t\tcodeBlock.create(null, text ? schema.text(text) : null),\n\t\t\t\t\t);\n\t\t\t\t\ttr.setSelection(TextSelection.create(tr.doc, 1));\n\t\t\t\t\treturn tr;\n\t\t\t\t},\n\t\t\t}),\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlight'),\n\t\t\t\tprops: {\n\t\t\t\t\t// The gutter is a node view, not a widget decoration — see\n\t\t\t\t\t// JsonCodeBlockView for why (MAP-7286).\n\t\t\t\t\tnodeViews: {\n\t\t\t\t\t\tcodeBlock: (node) => new JsonCodeBlockView(node),\n\t\t\t\t\t},\n\t\t\t\t\t// Paste beautify: if the clipboard text is valid JSON, drop in a\n\t\t\t\t\t// pretty-printed version (2-space indent, matching the Beautify\n\t\t\t\t\t// button) instead of the raw blob. Non-JSON pastes fall through to\n\t\t\t\t\t// the default handler untouched.\n\t\t\t\t\thandlePaste(view, event) {\n\t\t\t\t\t\tconst raw = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!raw || !raw.trim()) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet value: unknown;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tvalue = JSON.parse(raw);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst pretty = JSON.stringify(value, null, 2);\n\t\t\t\t\t\t// No-op if it was already beautified (avoids a redundant tx).\n\t\t\t\t\t\tif (pretty === raw) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { state, dispatch } = view;\n\t\t\t\t\t\tconst { from, to } = state.selection;\n\t\t\t\t\t\tdispatch(state.tr.insertText(pretty, from, to).scrollIntoView());\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t\t// Inline token colours only. Recolouring an inline span does not\n\t\t\t\t\t// disturb the caret (unlike the old gutter widgets).\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tstate.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (node.type.name !== 'codeBlock') return;\n\t\t\t\t\t\t\tconst text = node.textContent;\n\t\t\t\t\t\t\tif (text.length === 0) return;\n\t\t\t\t\t\t\t// +1: step past the code-block node boundary into its text.\n\t\t\t\t\t\t\tconst base = pos + 1;\n\t\t\t\t\t\t\tfor (const tok of tokenizeJson(text)) {\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.inline(base + tok.start, base + tok.end, {\n\t\t\t\t\t\t\t\t\t\tclass: CLASS_BY_TYPE[tok.type],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn DecorationSet.create(state.doc, decorations);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["CLASS_BY_TYPE","lineCount","text","JsonCodeBlockView","node","pre","gutter","code","count","numbers","n","span","mutation","JsonHighlightExtension","Extension","selection","empty","$from","Plugin","PluginKey","transactions","_oldState","newState","tr","doc","schema","codeBlock","hasCodeBlock","TextSelection","view","event","raw","value","pretty","state","dispatch","from","to","decorations","pos","base","tok","tokenizeJson","Decoration","DecorationSet"],"mappings":"8OAOMA,EAA+C,CACpD,IAAK,eACL,OAAQ,kBACR,OAAQ,kBACR,QAAS,mBACT,KAAM,gBACN,YAAa,gBACd,EAQA,SAASC,EAAUC,EAAsB,CACxC,OAAOA,EAAK,OAAO,SAAW,EAAI,EAAIA,EAAK,MAAM;AAAA,CAAI,EAAE,MACxD,CAeA,MAAMC,CAAs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MC,CAAE,EAAE,gBAAgB,EACxD,EACR,EAGA,YAAYH,EAAO,CAClB,MAAMI,EAA4B,CAAA,EAClC,OAAAJ,EAAM,IAAI,YAAY,CAAC9B,EAAMmC,IAAQ,CACpC,GAAInC,EAAK,KAAK,OAAS,YAAa,OACpC,MAAMF,EAAOE,EAAK,YAClB,GAAIF,EAAK,SAAW,EAAG,OAEvB,MAAMsC,EAAOD,EAAM,EACnB,UAAWE,KAAOC,eAAaxC,CAAI,EAClCoC,EAAY,KACXK,EAAAA,WAAW,OAAOH,EAAOC,EAAI,MAAOD,EAAOC,EAAI,IAAK,CACnD,MAAOzC,EAAcyC,EAAI,IAAI,CAAA,CAC7B,CAAA,CAGJ,CAAC,EACMG,EAAAA,cAAc,OAAOV,EAAM,IAAKI,CAAW,CACnD,CAAA,CACD,CACA,CAAA,CAEH,CACD,CAAC"}
1
+ {"version":3,"file":"JsonHighlightExtension.js","sources":["../../../../../src/editor/extensions/jsonHighlight/JsonHighlightExtension.ts"],"sourcesContent":["import { Extension } from '@tiptap/core';\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model';\nimport { Plugin, PluginKey, TextSelection } from '@tiptap/pm/state';\nimport type { NodeView } from '@tiptap/pm/view';\nimport { Decoration, DecorationSet } from '@tiptap/pm/view';\nimport { JsonTokenType, tokenizeJson } from './tokenizeJson';\n\nconst CLASS_BY_TYPE: Record<JsonTokenType, string> = {\n\tkey: 'bik-json-key',\n\tstring: 'bik-json-string',\n\tnumber: 'bik-json-number',\n\tboolean: 'bik-json-boolean',\n\tnull: 'bik-json-null',\n\tpunctuation: 'bik-json-punct',\n};\n\n/**\n * Visual line count of a code block's text (0 → no gutter). Whitespace-only\n * content counts as 0: that's exactly when BikEditor shows the placeholder\n * overlay (`jsonEmpty = !text.trim()`), so the gutter must be empty too —\n * otherwise a blank field shows a stray \"1\" behind the placeholder.\n */\nfunction lineCount(text: string): number {\n\treturn text.trim().length === 0 ? 0 : text.split('\\n').length;\n}\n\n/**\n * Node view for the JSON `codeBlock` that renders the line-number gutter as a\n * `contenteditable=false` sibling of the editable `<code>` — NOT as ProseMirror\n * widget decorations.\n *\n * Why: widget decorations are re-inserted into the content flow on every\n * decoration recompute (i.e. every keystroke). Re-inserting a node next to the\n * caret reset the contenteditable selection to the line start, so typing a JSON\n * key and then its `:` dropped the caret to the start of the line (MAP-7286).\n * A node view lets us update the gutter DOM independently of `contentDOM`, so\n * the caret is never touched — and we only rebuild it when the line count\n * actually changes.\n */\nclass JsonCodeBlockView implements NodeView {\n\tdom: HTMLPreElement;\n\tcontentDOM: HTMLElement;\n\tprivate gutter: HTMLElement;\n\n\tconstructor(node: ProseMirrorNode) {\n\t\tconst pre = document.createElement('pre');\n\t\tconst gutter = document.createElement('div');\n\t\tgutter.className = 'bik-json-gutter';\n\t\tgutter.contentEditable = 'false';\n\t\tconst code = document.createElement('code');\n\t\t// Gutter is absolutely positioned into the reserved left padding, so its\n\t\t// order relative to <code> doesn't affect the code layout.\n\t\tpre.appendChild(gutter);\n\t\tpre.appendChild(code);\n\n\t\tthis.dom = pre;\n\t\tthis.contentDOM = code;\n\t\tthis.gutter = gutter;\n\t\tthis.renderGutter(node);\n\t}\n\n\tprivate renderGutter(node: ProseMirrorNode): void {\n\t\tconst count = lineCount(node.textContent);\n\t\t// Nothing to do while the line count is unchanged — this is the common case\n\t\t// (typing within a line) and skipping it avoids touching the gutter DOM.\n\t\tif (this.gutter.childElementCount === count) {\n\t\t\treturn;\n\t\t}\n\t\t// Reserve only as much left space as the widest line number needs. Floored\n\t\t// at 2 digits so JSON up to 99 lines (virtually all of it) keeps a stable\n\t\t// compact gutter; 100+ / 1000+ lines widen it (and the code's left padding)\n\t\t// a step at a time instead of always paying for 5 digits.\n\t\tconst digits = Math.max(2, String(Math.max(count, 1)).length);\n\t\tconst gutterEm = digits * 0.6 + 1.1;\n\t\tthis.gutter.style.width = `${gutterEm}em`;\n\t\tthis.dom.style.paddingLeft = `${gutterEm + 0.7}em`;\n\t\tconst numbers: HTMLElement[] = [];\n\t\tfor (let n = 1; n <= count; n++) {\n\t\t\tconst span = document.createElement('span');\n\t\t\tspan.className = 'bik-json-lineno';\n\t\t\tspan.textContent = String(n);\n\t\t\tnumbers.push(span);\n\t\t}\n\t\tthis.gutter.replaceChildren(...numbers);\n\t}\n\n\tupdate(node: ProseMirrorNode): boolean {\n\t\tif (node.type.name !== 'codeBlock') {\n\t\t\treturn false;\n\t\t}\n\t\tthis.renderGutter(node);\n\t\treturn true;\n\t}\n\n\t// The gutter is ours to manage — never let ProseMirror parse it as content.\n\tignoreMutation(mutation: MutationRecord | { target: Node }): boolean {\n\t\treturn (\n\t\t\tthis.gutter === mutation.target || this.gutter.contains(mutation.target)\n\t\t);\n\t}\n}\n\n/**\n * Colours JSON tokens inside `codeBlock` nodes and renders a line-number gutter\n * (via {@link JsonCodeBlockView}). A code block stores its whole multi-line body\n * in a single text node, so token offsets map 1:1 onto document positions\n * (`nodeStart + offset`) — no cross-node bookkeeping needed.\n *\n * Purely decorative: the document text is never rewritten, so undo/redo,\n * character count and the cursor all behave exactly as with plain text.\n */\nexport const JsonHighlightExtension = Extension.create({\n\tname: 'jsonHighlight',\n\t// Above CodeBlock (default 100) so our Backspace handler runs first and can\n\t// veto CodeBlock's own \"clearNodes at start\" shortcut (which would lift the\n\t// block to a paragraph).\n\tpriority: 1000,\n\taddKeyboardShortcuts() {\n\t\treturn {\n\t\t\t// In JSON mode the document is a single code block. A Backspace at its very\n\t\t\t// start would lift it to a plain paragraph (killing the highlight, the\n\t\t\t// line-number gutter and the monospace font). There's nothing to delete\n\t\t\t// before the caret there anyway, so swallow it. Mid-text Backspace (and\n\t\t\t// deleting a leading `\\n` from line 2+) still works — those have\n\t\t\t// parentOffset > 0.\n\t\t\tBackspace: () => {\n\t\t\t\tconst { selection } = this.editor.state;\n\t\t\t\tconst { empty, $from } = selection;\n\t\t\t\treturn (\n\t\t\t\t\tempty &&\n\t\t\t\t\t$from.parent.type.name === 'codeBlock' &&\n\t\t\t\t\t$from.parentOffset === 0\n\t\t\t\t);\n\t\t\t},\n\t\t};\n\t},\n\taddProseMirrorPlugins() {\n\t\treturn [\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlightGuard'),\n\t\t\t\t// jsonMode invariant: the whole document is ONE codeBlock. Several\n\t\t\t\t// default Backspace paths can lift it to a plain paragraph — and one\n\t\t\t\t// of them, TipTap core's `clearDocument` appendTransaction (fired when\n\t\t\t\t// the whole doc is selected then deleted, e.g. Cmd-A → Backspace),\n\t\t\t\t// runs AFTER our Backspace shortcut, so a keymap veto can't stop it.\n\t\t\t\t// A paragraph has no gutter and no monospace rule, so the line numbers\n\t\t\t\t// and font vanish. Re-wrap the content back into a codeBlock whenever\n\t\t\t\t// something lifts it, restoring the invariant.\n\t\t\t\tappendTransaction(transactions, _oldState, newState) {\n\t\t\t\t\tif (!transactions.some((tr) => tr.docChanged)) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\tconst { doc, schema } = newState;\n\t\t\t\t\tconst codeBlock = schema.nodes['codeBlock'];\n\t\t\t\t\tif (!codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// Common case: already a single codeBlock → nothing to do.\n\t\t\t\t\tif (doc.childCount === 1 && doc.firstChild?.type === codeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// If a codeBlock survives anywhere, leave it alone (don't fight\n\t\t\t\t\t// legitimate multi-node edits that shouldn't happen in jsonMode).\n\t\t\t\t\tlet hasCodeBlock = false;\n\t\t\t\t\tdoc.forEach((node) => {\n\t\t\t\t\t\tif (node.type === codeBlock) {\n\t\t\t\t\t\t\thasCodeBlock = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t\tif (hasCodeBlock) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\t\t\t\t\t// A lift happened: rebuild a single codeBlock from the text\n\t\t\t\t\t// (block boundaries preserved as newlines, matching JSON lines).\n\t\t\t\t\tconst text = doc.textBetween(0, doc.content.size, '\\n');\n\t\t\t\t\tconst tr = newState.tr;\n\t\t\t\t\ttr.replaceWith(\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tdoc.content.size,\n\t\t\t\t\t\tcodeBlock.create(null, text ? schema.text(text) : null),\n\t\t\t\t\t);\n\t\t\t\t\ttr.setSelection(TextSelection.create(tr.doc, 1));\n\t\t\t\t\treturn tr;\n\t\t\t\t},\n\t\t\t}),\n\t\t\tnew Plugin({\n\t\t\t\tkey: new PluginKey('jsonHighlight'),\n\t\t\t\tprops: {\n\t\t\t\t\t// The gutter is a node view, not a widget decoration — see\n\t\t\t\t\t// JsonCodeBlockView for why (MAP-7286).\n\t\t\t\t\tnodeViews: {\n\t\t\t\t\t\tcodeBlock: (node) => new JsonCodeBlockView(node),\n\t\t\t\t\t},\n\t\t\t\t\t// Paste beautify: if the clipboard text is valid JSON, drop in a\n\t\t\t\t\t// pretty-printed version (2-space indent, matching the Beautify\n\t\t\t\t\t// button) instead of the raw blob. Non-JSON pastes fall through to\n\t\t\t\t\t// the default handler untouched.\n\t\t\t\t\thandlePaste(view, event) {\n\t\t\t\t\t\tconst raw = event.clipboardData?.getData('text/plain');\n\t\t\t\t\t\tif (!raw || !raw.trim()) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlet value: unknown;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tvalue = JSON.parse(raw);\n\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst pretty = JSON.stringify(value, null, 2);\n\t\t\t\t\t\t// No-op if it was already beautified (avoids a redundant tx).\n\t\t\t\t\t\tif (pretty === raw) {\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tconst { state, dispatch } = view;\n\t\t\t\t\t\tconst { from, to } = state.selection;\n\t\t\t\t\t\tdispatch(state.tr.insertText(pretty, from, to).scrollIntoView());\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t},\n\t\t\t\t\t// Inline token colours only. Recolouring an inline span does not\n\t\t\t\t\t// disturb the caret (unlike the old gutter widgets).\n\t\t\t\t\tdecorations(state) {\n\t\t\t\t\t\tconst decorations: Decoration[] = [];\n\t\t\t\t\t\tstate.doc.descendants((node, pos) => {\n\t\t\t\t\t\t\tif (node.type.name !== 'codeBlock') return;\n\t\t\t\t\t\t\tconst text = node.textContent;\n\t\t\t\t\t\t\tif (text.length === 0) return;\n\t\t\t\t\t\t\t// +1: step past the code-block node boundary into its text.\n\t\t\t\t\t\t\tconst base = pos + 1;\n\t\t\t\t\t\t\tfor (const tok of tokenizeJson(text)) {\n\t\t\t\t\t\t\t\tdecorations.push(\n\t\t\t\t\t\t\t\t\tDecoration.inline(base + tok.start, base + tok.end, {\n\t\t\t\t\t\t\t\t\t\tclass: CLASS_BY_TYPE[tok.type],\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn DecorationSet.create(state.doc, decorations);\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t}),\n\t\t];\n\t},\n});\n"],"names":["CLASS_BY_TYPE","lineCount","text","JsonCodeBlockView","node","pre","gutter","code","count","gutterEm","numbers","n","span","mutation","JsonHighlightExtension","Extension","selection","empty","$from","Plugin","PluginKey","transactions","_oldState","newState","tr","doc","schema","codeBlock","hasCodeBlock","TextSelection","view","event","raw","value","pretty","state","dispatch","from","to","decorations","pos","base","tok","tokenizeJson","Decoration","DecorationSet"],"mappings":"8OAOMA,EAA+C,CACpD,IAAK,eACL,OAAQ,kBACR,OAAQ,kBACR,QAAS,mBACT,KAAM,gBACN,YAAa,gBACd,EAQA,SAASC,EAAUC,EAAsB,CACxC,OAAOA,EAAK,OAAO,SAAW,EAAI,EAAIA,EAAK,MAAM;A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CACA,MAAME,EAAS,KAAK,UAAUD,EAAO,KAAM,CAAC,EAE5C,GAAIC,IAAWF,EACd,MAAO,GAER,KAAM,CAAE,MAAAG,EAAO,SAAAC,CAAA,EAAaN,EACtB,CAAE,KAAAO,EAAM,GAAAC,CAAA,EAAOH,EAAM,UAC3B,OAAAC,EAASD,EAAM,GAAG,WAAWD,EAAQG,EAAMC,CAAE,EAAE,gBAAgB,EACxD,EACR,EAGA,YAAYH,EAAO,CAClB,MAAMI,EAA4B,CAAA,EAClC,OAAAJ,EAAM,IAAI,YAAY,CAAC/B,EAAMoC,IAAQ,CACpC,GAAIpC,EAAK,KAAK,OAAS,YAAa,OACpC,MAAMF,EAAOE,EAAK,YAClB,GAAIF,EAAK,SAAW,EAAG,OAEvB,MAAMuC,EAAOD,EAAM,EACnB,UAAWE,KAAOC,eAAazC,CAAI,EAClCqC,EAAY,KACXK,EAAAA,WAAW,OAAOH,EAAOC,EAAI,MAAOD,EAAOC,EAAI,IAAK,CACnD,MAAO1C,EAAc0C,EAAI,IAAI,CAAA,CAC7B,CAAA,CAGJ,CAAC,EACMG,EAAAA,cAAc,OAAOV,EAAM,IAAKI,CAAW,CACnD,CAAA,CACD,CACA,CAAA,CAEH,CACD,CAAC"}
@@ -1,157 +1,166 @@
1
1
  import { jsx as o, jsxs as h } from "react/jsx-runtime";
2
- import { useState as c, useCallback as t } from "react";
3
- import { COLORS as ie } from "../../constants/Theme.js";
4
- import { BuilderRoot as se, Main as le, Rail as ce, Content as de, ContentCard as ue, StepScroll as ge } from "./AgentBuilder.styled.js";
5
- import { AgentBuilderFooter as fe } from "./components/AgentBuilderFooter.js";
6
- import { AgentBuilderTopBar as me } from "./components/AgentBuilderTopBar.js";
7
- import { DiscardModal as he } from "./components/DiscardModal.js";
8
- import { GoLiveModal as ve } from "./components/GoLiveModal.js";
9
- import { StepRail as pe } from "./components/StepRail.js";
10
- import { UndoToast as Se } from "./components/UndoToast.js";
11
- import { AgentBuilderProvider as be, useAgentBuilderContext as Ce } from "./context/AgentBuilderContext.js";
12
- import { Step1About as Ae } from "./steps/Step1About.js";
13
- import { Step2WhenItStepsIn as Le } from "./steps/Step2WhenItStepsIn.js";
14
- import { Step3HowItResponds as De } from "./steps/Step3HowItResponds.js";
15
- import { Step4HandoverRules as Te } from "./steps/Step4HandoverRules.js";
16
- import { Spinner as ye } from "../spinner/Spinner.js";
17
- const Be = () => {
18
- const { activeStep: d } = Ce();
2
+ import { useState as i, useCallback as t } from "react";
3
+ import { COLORS as le } from "../../constants/Theme.js";
4
+ import { BuilderRoot as ce, Main as de, Rail as ue, Content as fe, ContentCard as ge, StepScroll as me } from "./AgentBuilder.styled.js";
5
+ import { AgentBuilderFooter as he } from "./components/AgentBuilderFooter.js";
6
+ import { AgentBuilderTopBar as pe } from "./components/AgentBuilderTopBar.js";
7
+ import { DiscardModal as ve } from "./components/DiscardModal.js";
8
+ import { GoLiveModal as Se } from "./components/GoLiveModal.js";
9
+ import { StepRail as be } from "./components/StepRail.js";
10
+ import { UndoToast as Ce } from "./components/UndoToast.js";
11
+ import { AgentBuilderProvider as Ae, useAgentBuilderContext as Le } from "./context/AgentBuilderContext.js";
12
+ import { Step1About as ye } from "./steps/Step1About.js";
13
+ import { Step2WhenItStepsIn as De } from "./steps/Step2WhenItStepsIn.js";
14
+ import { Step3HowItResponds as Te } from "./steps/Step3HowItResponds.js";
15
+ import { Step4HandoverRules as Be } from "./steps/Step4HandoverRules.js";
16
+ import { Spinner as we } from "../spinner/Spinner.js";
17
+ const Ge = () => {
18
+ const { activeStep: d } = Le();
19
19
  switch (d) {
20
20
  case "about":
21
- return /* @__PURE__ */ o(Ae, {});
21
+ return /* @__PURE__ */ o(ye, {});
22
22
  case "trigger":
23
- return /* @__PURE__ */ o(Le, {});
24
- case "response":
25
23
  return /* @__PURE__ */ o(De, {});
26
- case "handover":
24
+ case "response":
27
25
  return /* @__PURE__ */ o(Te, {});
26
+ case "handover":
27
+ return /* @__PURE__ */ o(Be, {});
28
28
  default:
29
29
  return null;
30
30
  }
31
- }, Ge = (d) => {
31
+ }, Ie = (d) => {
32
32
  const {
33
33
  config: P,
34
- onChange: v,
34
+ onChange: p,
35
35
  onStepChange: u,
36
- onDiscard: p,
37
- onSaveDraft: r,
36
+ onDiscard: v,
37
+ onSaveDraft: s,
38
38
  onPublish: S,
39
- onBack: g,
40
- onTestAgent: f,
39
+ onBack: f,
40
+ onTestAgent: g,
41
41
  onGoToDashboard: m,
42
- onCreateSubAgent: i,
43
- onFetchSubAgent: w,
44
- onUpdateSubAgent: M,
45
- onImproveSubAgent: k,
46
- onImproveToolInstructions: R,
47
- onConnectIntegration: x,
48
- ...j
42
+ onCreateSubAgent: r,
43
+ onFetchSubAgent: M,
44
+ onUpdateSubAgent: k,
45
+ onImproveSubAgent: R,
46
+ onImproveToolInstructions: x,
47
+ onConnectIntegration: j,
48
+ ...H
49
49
  } = d, {
50
- value: s,
51
- activeStep: H,
52
- availableTools: F,
53
- availableSubAgents: N,
54
- availableIntents: O = [],
55
- availableModels: U = [],
56
- configToolTemplates: z,
57
- integrationStatus: E,
58
- validation: W,
59
- applicationType: $,
60
- charLimits: q,
50
+ value: l,
51
+ activeStep: F,
52
+ availableTools: N,
53
+ availableSubAgents: O,
54
+ availableIntents: U = [],
55
+ availableModels: z = [],
56
+ configToolTemplates: E,
57
+ integrationStatus: W,
58
+ validation: $,
59
+ applicationType: q,
60
+ charLimits: J,
61
61
  isSaving: b,
62
62
  isPublishing: C,
63
- isLoading: J,
64
- footerHint: K = "Changes don’t affect customers until you go live",
65
- disableStepNavigation: Q,
63
+ isLoading: K,
64
+ footerHint: Q = "Changes don’t affect customers until you go live",
65
+ disableStepNavigation: V,
66
66
  debugLog: A
67
- } = P, [L, a] = c(null), [D, T] = c(!1), [V, l] = c(!1), [y, B] = c(!1), e = t(
68
- (n, ...re) => {
69
- A && console.log(`[AgentBuilder] ${n}`, ...re);
67
+ } = P, [L, a] = i(null), [y, D] = i(!1), [X, T] = i(!1), [Y, c] = i(!1), [B, w] = i(!1), n = t(
68
+ (e, ...re) => {
69
+ A && console.log(`[AgentBuilder] ${e}`, ...re);
70
70
  },
71
71
  [A]
72
- ), X = t(
73
- (n) => {
74
- e("onChange", n), v(n);
72
+ ), Z = t(
73
+ (e) => {
74
+ n("onChange", e), p(e);
75
75
  },
76
- [e, v]
77
- ), Y = t(
78
- (n) => {
79
- e("onStepChange", n), u?.(n);
76
+ [n, p]
77
+ ), _ = t(
78
+ (e) => {
79
+ n("onStepChange", e), u?.(e);
80
80
  },
81
- [e, u]
82
- ), Z = t(() => (e("onSaveDraft"), r()), [e, r]), _ = t(() => (e("onPublish"), S()), [e, S]), ee = t(() => {
83
- e("onBack"), l(!0);
84
- }, [e]), ne = t(() => {
85
- e("onDiscardAndLeave"), l(!1), p();
86
- }, [e, p]), G = t(async () => {
87
- e("onSaveDraftAndLeave");
88
- const n = r();
89
- if (n && typeof n.then == "function") {
90
- B(!0);
81
+ [n, u]
82
+ ), ee = t(() => (n("onSaveDraft"), s()), [n, s]), ne = t(() => (n("onPublish"), S()), [n, S]), oe = t(() => {
83
+ n("onBack"), c(!0);
84
+ }, [n]), te = t(() => {
85
+ n("onDiscardAndLeave"), c(!1), v();
86
+ }, [n, v]), G = t(async () => {
87
+ n("onSaveDraftAndLeave");
88
+ const e = s();
89
+ if (e && typeof e.then == "function") {
90
+ w(!0);
91
91
  try {
92
- await n;
92
+ await e;
93
93
  } finally {
94
- B(!1);
94
+ w(!1);
95
95
  }
96
96
  }
97
- l(!1), g?.();
98
- }, [e, r, g]), oe = t(() => {
99
- e("onTestAgent"), f?.();
100
- }, [e, f]), I = t(() => {
101
- e("onGoToDashboard"), m?.();
102
- }, [e, m]), te = t(
103
- (n) => (e("onCreateSubAgent", n), i ? i(n) : Promise.reject(new Error("onCreateSubAgent not provided"))),
104
- [e, i]
105
- ), ae = async () => {
106
- e("onGoLiveConfirm");
107
- const n = _();
108
- if (n && typeof n.then == "function") {
97
+ c(!1), f?.();
98
+ }, [n, s, f]), ae = t(async () => {
99
+ n("onTestAgent");
100
+ const e = g?.();
101
+ if (e && typeof e.then == "function") {
109
102
  T(!0);
110
103
  try {
111
- await n, a("success");
104
+ await e;
112
105
  } finally {
113
106
  T(!1);
114
107
  }
108
+ }
109
+ }, [n, g]), I = t(() => {
110
+ n("onGoToDashboard"), m?.();
111
+ }, [n, m]), ie = t(
112
+ (e) => (n("onCreateSubAgent", e), r ? r(e) : Promise.reject(new Error("onCreateSubAgent not provided"))),
113
+ [n, r]
114
+ ), se = async () => {
115
+ n("onGoLiveConfirm");
116
+ const e = ne();
117
+ if (e && typeof e.then == "function") {
118
+ D(!0);
119
+ try {
120
+ await e, a("success");
121
+ } finally {
122
+ D(!1);
123
+ }
115
124
  } else
116
125
  a("success");
117
126
  };
118
127
  return /* @__PURE__ */ o(
119
- be,
128
+ Ae,
120
129
  {
121
- value: s,
122
- onChange: X,
123
- activeStep: H,
124
- onStepChange: u ? Y : void 0,
125
- availableTools: F,
126
- availableSubAgents: N,
127
- availableIntents: O,
128
- availableModels: U,
129
- configToolTemplates: z,
130
- integrationStatus: E,
131
- onConnectIntegration: x,
132
- validation: W,
133
- applicationType: $,
134
- charLimits: q,
135
- disableStepNavigation: Q,
136
- onCreateSubAgent: i ? te : void 0,
137
- onFetchSubAgent: w,
138
- onUpdateSubAgent: M,
139
- onImproveSubAgent: k,
140
- onImproveToolInstructions: R,
141
- children: /* @__PURE__ */ h(se, { "data-test": j["data-test"] ?? "agent-builder", children: [
130
+ value: l,
131
+ onChange: Z,
132
+ activeStep: F,
133
+ onStepChange: u ? _ : void 0,
134
+ availableTools: N,
135
+ availableSubAgents: O,
136
+ availableIntents: U,
137
+ availableModels: z,
138
+ configToolTemplates: E,
139
+ integrationStatus: W,
140
+ onConnectIntegration: j,
141
+ validation: $,
142
+ applicationType: q,
143
+ charLimits: J,
144
+ disableStepNavigation: V,
145
+ onCreateSubAgent: r ? ie : void 0,
146
+ onFetchSubAgent: M,
147
+ onUpdateSubAgent: k,
148
+ onImproveSubAgent: R,
149
+ onImproveToolInstructions: x,
150
+ children: /* @__PURE__ */ h(ce, { "data-test": H["data-test"] ?? "agent-builder", children: [
142
151
  /* @__PURE__ */ o(
143
- me,
152
+ pe,
144
153
  {
145
- name: s.name,
146
- status: s.status,
147
- onBack: g ? ee : void 0,
154
+ name: l.name,
155
+ status: l.status,
156
+ onBack: f ? oe : void 0,
148
157
  onSaveDraft: G,
149
- isSaving: b || y
158
+ isSaving: b || B
150
159
  }
151
160
  ),
152
- /* @__PURE__ */ h(le, { children: [
153
- /* @__PURE__ */ o(ce, { children: /* @__PURE__ */ o(pe, {}) }),
154
- /* @__PURE__ */ o(de, { children: J ? /* @__PURE__ */ o(
161
+ /* @__PURE__ */ h(de, { children: [
162
+ /* @__PURE__ */ o(ue, { children: /* @__PURE__ */ o(be, {}) }),
163
+ /* @__PURE__ */ o(fe, { children: K ? /* @__PURE__ */ o(
155
164
  "div",
156
165
  {
157
166
  style: {
@@ -160,57 +169,58 @@ const Be = () => {
160
169
  justifyContent: "center",
161
170
  height: "100%"
162
171
  },
163
- children: /* @__PURE__ */ o(ye, { size: "large", color: ie.stroke.brand })
172
+ children: /* @__PURE__ */ o(we, { size: "large", color: le.stroke.brand })
164
173
  }
165
- ) : /* @__PURE__ */ h(ue, { children: [
166
- /* @__PURE__ */ o(ge, { children: /* @__PURE__ */ o(Be, {}) }),
174
+ ) : /* @__PURE__ */ h(ge, { children: [
175
+ /* @__PURE__ */ o(me, { children: /* @__PURE__ */ o(Ge, {}) }),
167
176
  /* @__PURE__ */ o(
168
- fe,
177
+ he,
169
178
  {
170
- footerHint: K,
171
- onTestAgent: f ? oe : void 0,
179
+ footerHint: Q,
180
+ onTestAgent: g ? ae : void 0,
181
+ isTesting: X,
172
182
  onGoLive: () => {
173
- e("onGoLive"), a("confirm");
183
+ n("onGoLive"), a("confirm");
174
184
  },
175
- isPublishing: C || D
185
+ isPublishing: C || y
176
186
  }
177
187
  )
178
188
  ] }) })
179
189
  ] }),
180
190
  /* @__PURE__ */ o(
181
- ve,
191
+ Se,
182
192
  {
183
193
  mode: L,
184
194
  onClose: () => {
185
- const n = L === "success";
186
- a(null), n && I();
195
+ const e = L === "success";
196
+ a(null), e && I();
187
197
  },
188
- onConfirm: ae,
198
+ onConfirm: se,
189
199
  onSaveDraft: () => {
190
- a(null), Z();
200
+ a(null), ee();
191
201
  },
192
202
  onGoToDashboard: m ? I : void 0,
193
- isPublishing: C || D
203
+ isPublishing: C || y
194
204
  }
195
205
  ),
196
206
  /* @__PURE__ */ o(
197
- he,
207
+ ve,
198
208
  {
199
- open: V,
200
- onClose: () => l(!1),
201
- onDiscard: ne,
209
+ open: Y,
210
+ onClose: () => c(!1),
211
+ onDiscard: te,
202
212
  onSaveDraft: G,
203
- disableSaveDraft: !s.name.trim(),
204
- isSaving: b || y
213
+ disableSaveDraft: !l.name.trim(),
214
+ isSaving: b || B
205
215
  }
206
216
  ),
207
- /* @__PURE__ */ o(Se, {})
217
+ /* @__PURE__ */ o(Ce, {})
208
218
  ] })
209
219
  }
210
220
  );
211
221
  };
212
- Ge.displayName = "AgentBuilder";
222
+ Ie.displayName = "AgentBuilder";
213
223
  export {
214
- Ge as AgentBuilder
224
+ Ie as AgentBuilder
215
225
  };
216
226
  //# sourceMappingURL=AgentBuilder.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AgentBuilder.js","sources":["../../../../src/components/agent-builder/AgentBuilder.tsx"],"sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { Spinner } from '@src/components/spinner';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tAgentBuilderProps,\n\tAgentValue,\n\tSubAgentDraft,\n} from './AgentBuilder.model';\nimport {\n\tBuilderRoot,\n\tContent,\n\tContentCard,\n\tMain,\n\tRail,\n\tStepScroll,\n} from './AgentBuilder.styled';\nimport { AgentBuilderFooter } from './components/AgentBuilderFooter';\nimport { AgentBuilderTopBar } from './components/AgentBuilderTopBar';\nimport { DiscardModal } from './components/DiscardModal';\nimport { GoLiveModal, GoLiveModalMode } from './components/GoLiveModal';\nimport { StepRail } from './components/StepRail';\nimport { UndoToast } from './components/UndoToast';\nimport {\n\tAgentBuilderProvider,\n\tuseAgentBuilderContext,\n} from './context/AgentBuilderContext';\nimport { Step1About } from './steps/Step1About';\nimport { Step2WhenItStepsIn } from './steps/Step2WhenItStepsIn';\nimport { Step3HowItResponds } from './steps/Step3HowItResponds';\nimport { Step4HandoverRules } from './steps/Step4HandoverRules';\n\nconst StepContent: React.FC = () => {\n\tconst { activeStep } = useAgentBuilderContext();\n\tswitch (activeStep) {\n\t\tcase 'about':\n\t\t\treturn <Step1About />;\n\t\tcase 'trigger':\n\t\t\treturn <Step2WhenItStepsIn />;\n\t\tcase 'response':\n\t\t\treturn <Step3HowItResponds />;\n\t\tcase 'handover':\n\t\t\treturn <Step4HandoverRules />;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n};\n\n/**\n * 4-step creation/edit wizard body for an AI agent. Presentational and\n * controlled — the consumer owns the `value`, persistence and routing.\n *\n * @example\n * <AgentBuilder\n * value={agent}\n * onChange={(patch) => setAgent({ ...agent, ...patch })}\n * availableTools={tools}\n * availableSubAgents={subAgents}\n * onDiscard={() => router.back()}\n * onSaveDraft={saveDraft}\n * onPublish={publish}\n * />\n */\nexport const AgentBuilder: React.FC<AgentBuilderProps> = (props) => {\n\tconst {\n\t\tconfig,\n\t\tonChange,\n\t\tonStepChange,\n\t\tonDiscard,\n\t\tonSaveDraft,\n\t\tonPublish,\n\t\tonBack,\n\t\tonTestAgent,\n\t\tonGoToDashboard,\n\t\tonCreateSubAgent,\n\t\tonFetchSubAgent,\n\t\tonUpdateSubAgent,\n\t\tonImproveSubAgent,\n\t\tonImproveToolInstructions,\n\t\tonConnectIntegration,\n\t\t...rest\n\t} = props;\n\tconst {\n\t\tvalue,\n\t\tactiveStep,\n\t\tavailableTools,\n\t\tavailableSubAgents,\n\t\tavailableIntents = [],\n\t\tavailableModels = [],\n\t\tconfigToolTemplates,\n\t\tintegrationStatus,\n\t\tvalidation,\n\t\tapplicationType,\n\t\tcharLimits,\n\t\tisSaving,\n\t\tisPublishing,\n\t\tisLoading,\n\t\tfooterHint = 'Changes don’t affect customers until you go live',\n\t\tdisableStepNavigation,\n\t\tdebugLog,\n\t} = config;\n\n\tconst [modalMode, setModalMode] = useState<GoLiveModalMode>(null);\n\tconst [publishingLocal, setPublishingLocal] = useState(false);\n\t// Back was pressed → confirm leaving (save draft / discard) before navigating.\n\tconst [showLeaveConfirm, setShowLeaveConfirm] = useState(false);\n\tconst [savingAndLeaving, setSavingAndLeaving] = useState(false);\n\n\t// Gated debug logging: each handler logs at its start only when `debugLog`.\n\tconst logAction = useCallback(\n\t\t(action: string, ...args: unknown[]) => {\n\t\t\tif (debugLog) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(`[AgentBuilder] ${action}`, ...args);\n\t\t\t}\n\t\t},\n\t\t[debugLog],\n\t);\n\n\tconst handleChange = useCallback(\n\t\t(patch: Partial<AgentValue>) => {\n\t\t\tlogAction('onChange', patch);\n\t\t\tonChange(patch);\n\t\t},\n\t\t[logAction, onChange],\n\t);\n\tconst handleStepChange = useCallback(\n\t\t(step: Parameters<NonNullable<typeof onStepChange>>[0]) => {\n\t\t\tlogAction('onStepChange', step);\n\t\t\tonStepChange?.(step);\n\t\t},\n\t\t[logAction, onStepChange],\n\t);\n\tconst handleSaveDraft = useCallback(() => {\n\t\tlogAction('onSaveDraft');\n\t\treturn onSaveDraft();\n\t}, [logAction, onSaveDraft]);\n\tconst handlePublish = useCallback(() => {\n\t\tlogAction('onPublish');\n\t\treturn onPublish();\n\t}, [logAction, onPublish]);\n\t// Back opens the \"Save as draft?\" confirmation rather than leaving directly.\n\tconst handleBack = useCallback(() => {\n\t\tlogAction('onBack');\n\t\tsetShowLeaveConfirm(true);\n\t}, [logAction]);\n\n\t// Modal \"Discard\" defers to the parent's discard handler (same as the top bar).\n\tconst handleDiscardAndLeave = useCallback(() => {\n\t\tlogAction('onDiscardAndLeave');\n\t\tsetShowLeaveConfirm(false);\n\t\tonDiscard();\n\t}, [logAction, onDiscard]);\n\n\tconst handleSaveDraftAndLeave = useCallback(async () => {\n\t\tlogAction('onSaveDraftAndLeave');\n\t\tconst result = onSaveDraft();\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetSavingAndLeaving(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} finally {\n\t\t\t\tsetSavingAndLeaving(false);\n\t\t\t}\n\t\t}\n\t\tsetShowLeaveConfirm(false);\n\t\tonBack?.();\n\t}, [logAction, onSaveDraft, onBack]);\n\tconst handleTestAgent = useCallback(() => {\n\t\tlogAction('onTestAgent');\n\t\tonTestAgent?.();\n\t}, [logAction, onTestAgent]);\n\tconst handleGoToDashboard = useCallback(() => {\n\t\tlogAction('onGoToDashboard');\n\t\tonGoToDashboard?.();\n\t}, [logAction, onGoToDashboard]);\n\tconst handleCreateSubAgent = useCallback(\n\t\t(draft: SubAgentDraft) => {\n\t\t\tlogAction('onCreateSubAgent', draft);\n\t\t\treturn onCreateSubAgent\n\t\t\t\t? onCreateSubAgent(draft)\n\t\t\t\t: Promise.reject(new Error('onCreateSubAgent not provided'));\n\t\t},\n\t\t[logAction, onCreateSubAgent],\n\t);\n\n\tconst handleConfirmGoLive = async () => {\n\t\tlogAction('onGoLiveConfirm');\n\t\tconst result = handlePublish();\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetPublishingLocal(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t\tsetModalMode('success');\n\t\t\t} finally {\n\t\t\t\tsetPublishingLocal(false);\n\t\t\t}\n\t\t} else {\n\t\t\tsetModalMode('success');\n\t\t}\n\t};\n\n\treturn (\n\t\t<AgentBuilderProvider\n\t\t\tvalue={value}\n\t\t\tonChange={handleChange}\n\t\t\tactiveStep={activeStep}\n\t\t\tonStepChange={onStepChange ? handleStepChange : undefined}\n\t\t\tavailableTools={availableTools}\n\t\t\tavailableSubAgents={availableSubAgents}\n\t\t\tavailableIntents={availableIntents}\n\t\t\tavailableModels={availableModels}\n\t\t\tconfigToolTemplates={configToolTemplates}\n\t\t\tintegrationStatus={integrationStatus}\n\t\t\tonConnectIntegration={onConnectIntegration}\n\t\t\tvalidation={validation}\n\t\t\tapplicationType={applicationType}\n\t\t\tcharLimits={charLimits}\n\t\t\tdisableStepNavigation={disableStepNavigation}\n\t\t\tonCreateSubAgent={onCreateSubAgent ? handleCreateSubAgent : undefined}\n\t\t\tonFetchSubAgent={onFetchSubAgent}\n\t\t\tonUpdateSubAgent={onUpdateSubAgent}\n\t\t\tonImproveSubAgent={onImproveSubAgent}\n\t\t\tonImproveToolInstructions={onImproveToolInstructions}\n\t\t>\n\t\t\t<BuilderRoot data-test={rest['data-test'] ?? 'agent-builder'}>\n\t\t\t\t<AgentBuilderTopBar\n\t\t\t\t\tname={value.name}\n\t\t\t\t\tstatus={value.status}\n\t\t\t\t\tonBack={onBack ? handleBack : undefined}\n\t\t\t\t\tonSaveDraft={handleSaveDraftAndLeave}\n\t\t\t\t\tisSaving={isSaving || savingAndLeaving}\n\t\t\t\t/>\n\n\t\t\t\t<Main>\n\t\t\t\t\t<Rail>\n\t\t\t\t\t\t<StepRail />\n\t\t\t\t\t</Rail>\n\t\t\t\t\t<Content>\n\t\t\t\t\t\t{isLoading ? (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\t\t\t\talignItems: 'center',\n\t\t\t\t\t\t\t\t\tjustifyContent: 'center',\n\t\t\t\t\t\t\t\t\theight: '100%',\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Spinner size=\"large\" color={COLORS.stroke.brand} />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<ContentCard>\n\t\t\t\t\t\t\t\t<StepScroll>\n\t\t\t\t\t\t\t\t\t<StepContent />\n\t\t\t\t\t\t\t\t</StepScroll>\n\t\t\t\t\t\t\t\t<AgentBuilderFooter\n\t\t\t\t\t\t\t\t\tfooterHint={footerHint}\n\t\t\t\t\t\t\t\t\tonTestAgent={onTestAgent ? handleTestAgent : undefined}\n\t\t\t\t\t\t\t\t\tonGoLive={() => {\n\t\t\t\t\t\t\t\t\t\tlogAction('onGoLive');\n\t\t\t\t\t\t\t\t\t\tsetModalMode('confirm');\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tisPublishing={isPublishing || publishingLocal}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ContentCard>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</Content>\n\t\t\t\t</Main>\n\n\t\t\t\t<GoLiveModal\n\t\t\t\t\tmode={modalMode}\n\t\t\t\t\tonClose={() => {\n\t\t\t\t\t\tconst wasSuccess = modalMode === 'success';\n\t\t\t\t\t\tsetModalMode(null);\n\t\t\t\t\t\tif (wasSuccess) {\n\t\t\t\t\t\t\thandleGoToDashboard();\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t\tonConfirm={handleConfirmGoLive}\n\t\t\t\t\tonSaveDraft={() => {\n\t\t\t\t\t\tsetModalMode(null);\n\t\t\t\t\t\thandleSaveDraft();\n\t\t\t\t\t}}\n\t\t\t\t\tonGoToDashboard={onGoToDashboard ? handleGoToDashboard : undefined}\n\t\t\t\t\tisPublishing={isPublishing || publishingLocal}\n\t\t\t\t/>\n\n\t\t\t\t<DiscardModal\n\t\t\t\t\topen={showLeaveConfirm}\n\t\t\t\t\tonClose={() => setShowLeaveConfirm(false)}\n\t\t\t\t\tonDiscard={handleDiscardAndLeave}\n\t\t\t\t\tonSaveDraft={handleSaveDraftAndLeave}\n\t\t\t\t\tdisableSaveDraft={!value.name.trim()}\n\t\t\t\t\tisSaving={isSaving || savingAndLeaving}\n\t\t\t\t/>\n\n\t\t\t\t<UndoToast />\n\t\t\t</BuilderRoot>\n\t\t</AgentBuilderProvider>\n\t);\n};\n\nAgentBuilder.displayName = 'AgentBuilder';\n"],"names":["StepContent","activeStep","useAgentBuilderContext","Step1About","Step2WhenItStepsIn","Step3HowItResponds","Step4HandoverRules","AgentBuilder","props","config","onChange","onStepChange","onDiscard","onSaveDraft","onPublish","onBack","onTestAgent","onGoToDashboard","onCreateSubAgent","onFetchSubAgent","onUpdateSubAgent","onImproveSubAgent","onImproveToolInstructions","onConnectIntegration","rest","value","availableTools","availableSubAgents","availableIntents","availableModels","configToolTemplates","integrationStatus","validation","applicationType","charLimits","isSaving","isPublishing","isLoading","footerHint","disableStepNavigation","debugLog","modalMode","setModalMode","useState","publishingLocal","setPublishingLocal","showLeaveConfirm","setShowLeaveConfirm","savingAndLeaving","setSavingAndLeaving","logAction","useCallback","action","args","handleChange","patch","handleStepChange","step","handleSaveDraft","handlePublish","handleBack","handleDiscardAndLeave","handleSaveDraftAndLeave","result","handleTestAgent","handleGoToDashboard","handleCreateSubAgent","draft","handleConfirmGoLive","jsx","AgentBuilderProvider","BuilderRoot","AgentBuilderTopBar","Main","Rail","StepRail","Content","Spinner","COLORS","ContentCard","StepScroll","AgentBuilderFooter","GoLiveModal","wasSuccess","DiscardModal","UndoToast"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAMA,KAAwB,MAAM;AACnC,QAAM,EAAE,YAAAC,EAAA,IAAeC,GAAA;AACvB,UAAQD,GAAA;AAAA,IACP,KAAK;AACJ,+BAAQE,IAAA,EAAW;AAAA,IACpB,KAAK;AACJ,+BAAQC,IAAA,EAAmB;AAAA,IAC5B,KAAK;AACJ,+BAAQC,IAAA,EAAmB;AAAA,IAC5B,KAAK;AACJ,+BAAQC,IAAA,EAAmB;AAAA,IAC5B;AACC,aAAO;AAAA,EAAA;AAEV,GAiBaC,KAA4C,CAACC,MAAU;AACnE,QAAM;AAAA,IACL,QAAAC;AAAA,IACA,UAAAC;AAAA,IAC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;AAAA,QAAA;AAAA,0BAGtBqC,IAAA,CAAA,CAAU;AAAA,MAAA,EAAA,CACZ;AAAA,IAAA;AAAA,EAAA;AAGH;AAEA9E,GAAa,cAAc;"}
1
+ {"version":3,"file":"AgentBuilder.js","sources":["../../../../src/components/agent-builder/AgentBuilder.tsx"],"sourcesContent":["import React, { useCallback, useState } from 'react';\nimport { Spinner } from '@src/components/spinner';\nimport { COLORS } from '@src/constants/Theme';\nimport {\n\tAgentBuilderProps,\n\tAgentValue,\n\tSubAgentDraft,\n} from './AgentBuilder.model';\nimport {\n\tBuilderRoot,\n\tContent,\n\tContentCard,\n\tMain,\n\tRail,\n\tStepScroll,\n} from './AgentBuilder.styled';\nimport { AgentBuilderFooter } from './components/AgentBuilderFooter';\nimport { AgentBuilderTopBar } from './components/AgentBuilderTopBar';\nimport { DiscardModal } from './components/DiscardModal';\nimport { GoLiveModal, GoLiveModalMode } from './components/GoLiveModal';\nimport { StepRail } from './components/StepRail';\nimport { UndoToast } from './components/UndoToast';\nimport {\n\tAgentBuilderProvider,\n\tuseAgentBuilderContext,\n} from './context/AgentBuilderContext';\nimport { Step1About } from './steps/Step1About';\nimport { Step2WhenItStepsIn } from './steps/Step2WhenItStepsIn';\nimport { Step3HowItResponds } from './steps/Step3HowItResponds';\nimport { Step4HandoverRules } from './steps/Step4HandoverRules';\n\nconst StepContent: React.FC = () => {\n\tconst { activeStep } = useAgentBuilderContext();\n\tswitch (activeStep) {\n\t\tcase 'about':\n\t\t\treturn <Step1About />;\n\t\tcase 'trigger':\n\t\t\treturn <Step2WhenItStepsIn />;\n\t\tcase 'response':\n\t\t\treturn <Step3HowItResponds />;\n\t\tcase 'handover':\n\t\t\treturn <Step4HandoverRules />;\n\t\tdefault:\n\t\t\treturn null;\n\t}\n};\n\n/**\n * 4-step creation/edit wizard body for an AI agent. Presentational and\n * controlled — the consumer owns the `value`, persistence and routing.\n *\n * @example\n * <AgentBuilder\n * value={agent}\n * onChange={(patch) => setAgent({ ...agent, ...patch })}\n * availableTools={tools}\n * availableSubAgents={subAgents}\n * onDiscard={() => router.back()}\n * onSaveDraft={saveDraft}\n * onPublish={publish}\n * />\n */\nexport const AgentBuilder: React.FC<AgentBuilderProps> = (props) => {\n\tconst {\n\t\tconfig,\n\t\tonChange,\n\t\tonStepChange,\n\t\tonDiscard,\n\t\tonSaveDraft,\n\t\tonPublish,\n\t\tonBack,\n\t\tonTestAgent,\n\t\tonGoToDashboard,\n\t\tonCreateSubAgent,\n\t\tonFetchSubAgent,\n\t\tonUpdateSubAgent,\n\t\tonImproveSubAgent,\n\t\tonImproveToolInstructions,\n\t\tonConnectIntegration,\n\t\t...rest\n\t} = props;\n\tconst {\n\t\tvalue,\n\t\tactiveStep,\n\t\tavailableTools,\n\t\tavailableSubAgents,\n\t\tavailableIntents = [],\n\t\tavailableModels = [],\n\t\tconfigToolTemplates,\n\t\tintegrationStatus,\n\t\tvalidation,\n\t\tapplicationType,\n\t\tcharLimits,\n\t\tisSaving,\n\t\tisPublishing,\n\t\tisLoading,\n\t\tfooterHint = 'Changes don’t affect customers until you go live',\n\t\tdisableStepNavigation,\n\t\tdebugLog,\n\t} = config;\n\n\tconst [modalMode, setModalMode] = useState<GoLiveModalMode>(null);\n\tconst [publishingLocal, setPublishingLocal] = useState(false);\n\t// True while onTestAgent's async work (e.g. save-as-draft before the test\n\t// modal opens) is in flight — loads + disables the Test agent button.\n\tconst [testingLocal, setTestingLocal] = useState(false);\n\t// Back was pressed → confirm leaving (save draft / discard) before navigating.\n\tconst [showLeaveConfirm, setShowLeaveConfirm] = useState(false);\n\tconst [savingAndLeaving, setSavingAndLeaving] = useState(false);\n\n\t// Gated debug logging: each handler logs at its start only when `debugLog`.\n\tconst logAction = useCallback(\n\t\t(action: string, ...args: unknown[]) => {\n\t\t\tif (debugLog) {\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.log(`[AgentBuilder] ${action}`, ...args);\n\t\t\t}\n\t\t},\n\t\t[debugLog],\n\t);\n\n\tconst handleChange = useCallback(\n\t\t(patch: Partial<AgentValue>) => {\n\t\t\tlogAction('onChange', patch);\n\t\t\tonChange(patch);\n\t\t},\n\t\t[logAction, onChange],\n\t);\n\tconst handleStepChange = useCallback(\n\t\t(step: Parameters<NonNullable<typeof onStepChange>>[0]) => {\n\t\t\tlogAction('onStepChange', step);\n\t\t\tonStepChange?.(step);\n\t\t},\n\t\t[logAction, onStepChange],\n\t);\n\tconst handleSaveDraft = useCallback(() => {\n\t\tlogAction('onSaveDraft');\n\t\treturn onSaveDraft();\n\t}, [logAction, onSaveDraft]);\n\tconst handlePublish = useCallback(() => {\n\t\tlogAction('onPublish');\n\t\treturn onPublish();\n\t}, [logAction, onPublish]);\n\t// Back opens the \"Save as draft?\" confirmation rather than leaving directly.\n\tconst handleBack = useCallback(() => {\n\t\tlogAction('onBack');\n\t\tsetShowLeaveConfirm(true);\n\t}, [logAction]);\n\n\t// Modal \"Discard\" defers to the parent's discard handler (same as the top bar).\n\tconst handleDiscardAndLeave = useCallback(() => {\n\t\tlogAction('onDiscardAndLeave');\n\t\tsetShowLeaveConfirm(false);\n\t\tonDiscard();\n\t}, [logAction, onDiscard]);\n\n\tconst handleSaveDraftAndLeave = useCallback(async () => {\n\t\tlogAction('onSaveDraftAndLeave');\n\t\tconst result = onSaveDraft();\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetSavingAndLeaving(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} finally {\n\t\t\t\tsetSavingAndLeaving(false);\n\t\t\t}\n\t\t}\n\t\tsetShowLeaveConfirm(false);\n\t\tonBack?.();\n\t}, [logAction, onSaveDraft, onBack]);\n\tconst handleTestAgent = useCallback(async () => {\n\t\tlogAction('onTestAgent');\n\t\tconst result = onTestAgent?.();\n\t\t// A new agent saves as draft before the test modal opens — that's slow, so\n\t\t// disable + load the button until it settles (prevents double-triggering).\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetTestingLocal(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} finally {\n\t\t\t\tsetTestingLocal(false);\n\t\t\t}\n\t\t}\n\t}, [logAction, onTestAgent]);\n\tconst handleGoToDashboard = useCallback(() => {\n\t\tlogAction('onGoToDashboard');\n\t\tonGoToDashboard?.();\n\t}, [logAction, onGoToDashboard]);\n\tconst handleCreateSubAgent = useCallback(\n\t\t(draft: SubAgentDraft) => {\n\t\t\tlogAction('onCreateSubAgent', draft);\n\t\t\treturn onCreateSubAgent\n\t\t\t\t? onCreateSubAgent(draft)\n\t\t\t\t: Promise.reject(new Error('onCreateSubAgent not provided'));\n\t\t},\n\t\t[logAction, onCreateSubAgent],\n\t);\n\n\tconst handleConfirmGoLive = async () => {\n\t\tlogAction('onGoLiveConfirm');\n\t\tconst result = handlePublish();\n\t\tif (result && typeof (result as Promise<void>).then === 'function') {\n\t\t\tsetPublishingLocal(true);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t\tsetModalMode('success');\n\t\t\t} finally {\n\t\t\t\tsetPublishingLocal(false);\n\t\t\t}\n\t\t} else {\n\t\t\tsetModalMode('success');\n\t\t}\n\t};\n\n\treturn (\n\t\t<AgentBuilderProvider\n\t\t\tvalue={value}\n\t\t\tonChange={handleChange}\n\t\t\tactiveStep={activeStep}\n\t\t\tonStepChange={onStepChange ? handleStepChange : undefined}\n\t\t\tavailableTools={availableTools}\n\t\t\tavailableSubAgents={availableSubAgents}\n\t\t\tavailableIntents={availableIntents}\n\t\t\tavailableModels={availableModels}\n\t\t\tconfigToolTemplates={configToolTemplates}\n\t\t\tintegrationStatus={integrationStatus}\n\t\t\tonConnectIntegration={onConnectIntegration}\n\t\t\tvalidation={validation}\n\t\t\tapplicationType={applicationType}\n\t\t\tcharLimits={charLimits}\n\t\t\tdisableStepNavigation={disableStepNavigation}\n\t\t\tonCreateSubAgent={onCreateSubAgent ? handleCreateSubAgent : undefined}\n\t\t\tonFetchSubAgent={onFetchSubAgent}\n\t\t\tonUpdateSubAgent={onUpdateSubAgent}\n\t\t\tonImproveSubAgent={onImproveSubAgent}\n\t\t\tonImproveToolInstructions={onImproveToolInstructions}\n\t\t>\n\t\t\t<BuilderRoot data-test={rest['data-test'] ?? 'agent-builder'}>\n\t\t\t\t<AgentBuilderTopBar\n\t\t\t\t\tname={value.name}\n\t\t\t\t\tstatus={value.status}\n\t\t\t\t\tonBack={onBack ? handleBack : undefined}\n\t\t\t\t\tonSaveDraft={handleSaveDraftAndLeave}\n\t\t\t\t\tisSaving={isSaving || savingAndLeaving}\n\t\t\t\t/>\n\n\t\t\t\t<Main>\n\t\t\t\t\t<Rail>\n\t\t\t\t\t\t<StepRail />\n\t\t\t\t\t</Rail>\n\t\t\t\t\t<Content>\n\t\t\t\t\t\t{isLoading ? (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tdisplay: 'flex',\n\t\t\t\t\t\t\t\t\talignItems: 'center',\n\t\t\t\t\t\t\t\t\tjustifyContent: 'center',\n\t\t\t\t\t\t\t\t\theight: '100%',\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<Spinner size=\"large\" color={COLORS.stroke.brand} />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<ContentCard>\n\t\t\t\t\t\t\t\t<StepScroll>\n\t\t\t\t\t\t\t\t\t<StepContent />\n\t\t\t\t\t\t\t\t</StepScroll>\n\t\t\t\t\t\t\t\t<AgentBuilderFooter\n\t\t\t\t\t\t\t\t\tfooterHint={footerHint}\n\t\t\t\t\t\t\t\t\tonTestAgent={onTestAgent ? handleTestAgent : undefined}\n\t\t\t\t\t\t\t\t\tisTesting={testingLocal}\n\t\t\t\t\t\t\t\t\tonGoLive={() => {\n\t\t\t\t\t\t\t\t\t\tlogAction('onGoLive');\n\t\t\t\t\t\t\t\t\t\tsetModalMode('confirm');\n\t\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t\t\tisPublishing={isPublishing || publishingLocal}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</ContentCard>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</Content>\n\t\t\t\t</Main>\n\n\t\t\t\t<GoLiveModal\n\t\t\t\t\tmode={modalMode}\n\t\t\t\t\tonClose={() => {\n\t\t\t\t\t\tconst wasSuccess = modalMode === 'success';\n\t\t\t\t\t\tsetModalMode(null);\n\t\t\t\t\t\tif (wasSuccess) {\n\t\t\t\t\t\t\thandleGoToDashboard();\n\t\t\t\t\t\t}\n\t\t\t\t\t}}\n\t\t\t\t\tonConfirm={handleConfirmGoLive}\n\t\t\t\t\tonSaveDraft={() => {\n\t\t\t\t\t\tsetModalMode(null);\n\t\t\t\t\t\thandleSaveDraft();\n\t\t\t\t\t}}\n\t\t\t\t\tonGoToDashboard={onGoToDashboard ? handleGoToDashboard : undefined}\n\t\t\t\t\tisPublishing={isPublishing || publishingLocal}\n\t\t\t\t/>\n\n\t\t\t\t<DiscardModal\n\t\t\t\t\topen={showLeaveConfirm}\n\t\t\t\t\tonClose={() => setShowLeaveConfirm(false)}\n\t\t\t\t\tonDiscard={handleDiscardAndLeave}\n\t\t\t\t\tonSaveDraft={handleSaveDraftAndLeave}\n\t\t\t\t\tdisableSaveDraft={!value.name.trim()}\n\t\t\t\t\tisSaving={isSaving || savingAndLeaving}\n\t\t\t\t/>\n\n\t\t\t\t<UndoToast />\n\t\t\t</BuilderRoot>\n\t\t</AgentBuilderProvider>\n\t);\n};\n\nAgentBuilder.displayName = 'AgentBuilder';\n"],"names":["StepContent","activeStep","useAgentBuilderContext","Step1About","Step2WhenItStepsIn","Step3HowItResponds","Step4HandoverRules","AgentBuilder","props","config","onChange","onStepChange","onDiscard","onSaveDraft","onPublish","onBack","onTestAgent","onGoToDashboard","onCreateSubAgent","onFetchSubAgent","onUpdateSubAgent","onImproveSubAgent","onImproveToolInstructions","onConnectIntegration","rest","value","availableTools","availableSubAgents","availableIntents","availableModels","configToolTemplates","integrationStatus","validation","applicationType","charLimits","isSaving","isPublishing","isLoading","footerHint","disableStepNavigation","debugLog","modalMode","setModalMode","useState","publishingLocal","setPublishingLocal","testingLocal","setTestingLocal","showLeaveConfirm","setShowLeaveConfirm","savingAndLeaving","setSavingAndLeaving","logAction","useCallback","action","args","handleChange","patch","handleStepChange","step","handleSaveDraft","handlePublish","handleBack","handleDiscardAndLeave","handleSaveDraftAndLeave","result","handleTestAgent","handleGoToDashboard","handleCreateSubAgent","draft","handleConfirmGoLive","jsx","AgentBuilderProvider","BuilderRoot","AgentBuilderTopBar","Main","Rail","StepRail","Content","Spinner","COLORS","ContentCard","StepScroll","AgentBuilderFooter","GoLiveModal","wasSuccess","DiscardModal","UndoToast"],"mappings":";;;;;;;;;;;;;;;;AA+BA,MAAMA,KAAwB,MAAM;AACnC,QAAM,EAAE,YAAAC,EAAA,IAAeC,GAAA;AACvB,UAAQD,GAAA;AAAA,IACP,KAAK;AACJ,+BAAQE,IAAA,EAAW;AAAA,IACpB,KAAK;AACJ,+BAAQC,IAAA,EAAmB;AAAA,IAC5B,KAAK;AACJ,+BAAQC,IAAA,EAAmB;AAAA,IAC5B,KAAK;AACJ,+BAAQC,IAAA,EAAmB;AAAA,IAC5B;AACC,aAAO;AAAA,EAAA;AAEV,GAiBaC,KAA4C,CAACC,MAAU;AACnE,QAAM;AAAA,IACL,QAAAC;AAAA,IACA,UAAAC;AAAA,IACA,cAAAC;AAAA,IACA,WAAAC;AAAA,IACA,aAAAC;AAAA,IACA,WAAAC;AAAA,IACA,QAAAC;AAAA,IACA,aAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,iBAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,mBAAAC;AAAA,IACA,2BAAAC;AAAA,IACA,sBAAAC;AAAA,IACA,GAAGC;AAAA,EAAA,IACAhB,GACE;AAAA,IACL,OAAAiB;AAAA,IACA,YAAAxB;AAA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A,IAAA;AAAA,EAAA;AAGH;AAEAhF,GAAa,cAAc;"}
@@ -278,8 +278,13 @@ export interface AgentBuilderProps {
278
278
  onPublish: () => void | Promise<void>;
279
279
  /** Back arrow in the top bar (e.g. return to listing). */
280
280
  onBack?: () => void;
281
- /** Trigger a test run of the agent (top-bar "Test" action). Omit to hide it. */
282
- onTestAgent?: () => void;
281
+ /**
282
+ * Trigger a test run of the agent (last-step "Test agent" action). Omit to
283
+ * hide it. If it returns a promise (e.g. a new agent is saved as draft before
284
+ * the test modal opens), the button shows a loader and stays disabled until it
285
+ * settles, so a slow save can't be double-triggered.
286
+ */
287
+ onTestAgent?: () => void | Promise<void>;
283
288
  /** After a successful go-live, navigate to the dashboard. Drives the success modal CTA. */
284
289
  onGoToDashboard?: () => void;
285
290
  /**
@@ -2,6 +2,8 @@ import { default as React } from 'react';
2
2
  interface AgentBuilderFooterProps {
3
3
  footerHint: string;
4
4
  onTestAgent?: () => void;
5
+ /** Loader + disabled on the Test agent button while its action is in flight. */
6
+ isTesting?: boolean;
5
7
  /** Opens the go-live confirmation. */
6
8
  onGoLive: () => void;
7
9
  isPublishing?: boolean;