plugin-document-understanding 1.1.15 → 1.1.16

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.
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- "use strict";(self.webpackChunkplugin_document_understanding=self.webpackChunkplugin_document_understanding||[]).push([["345"],{824:function(e,t,n){n.r(t),n.d(t,{PluginSettings:function(){return ea},default:function(){return eo}});var r=n(155),l=n.n(r),a=n(59),o=n(694),i=JSON.parse('{"UU":"plugin-document-understanding"}');function u(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[i.UU,"client"]})}}var c=n(375);function s(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e,t){var n,r;return e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"?null!=(n=null==(r=e.data)?void 0:r.data)?n:t:t}function d(e){return s(e,Error)?e.message:String(e)}function p(e){if(!e)return"-";var t=s(e,Date)?e:new Date(e);return Number.isNaN(t.getTime())?"-":t.toLocaleString()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=function(){var e=b(a.Form.useForm(),1)[0],t=(0,o.useFlowContext)().api,n=u(),i=b((0,r.useState)(!0),2),s=i[0],p=i[1],f=b((0,r.useState)(!1),2),y=f[0],E=f[1],v=b((0,r.useState)(),2),S=v[0],w=v[1];return((0,r.useEffect)(function(){var n=!1;return h(function(){var r,l;return g(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,3,4]),[4,t.request({url:"docUnderstanding:getConfig"})];case 1:if(r=a.sent(),n)return[2];return e.setFieldsValue(m(r,{})),[3,4];case 2:return l=a.sent(),n||w(d(l)),[3,4];case 3:return n||p(!1),[7];case 4:return[2]}})})(),function(){n=!0}},[t,e]),s)?l().createElement(a.Spin,{style:{marginTop:40}}):l().createElement(a.Form,{form:e,layout:"vertical",onFinish:function(e){return h(function(){var r;return g(this,function(l){switch(l.label){case 0:E(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,t.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return l.sent(),a.message.success(n("Configuration saved successfully")),[3,5];case 3:return r=l.sent(),a.message.error("".concat(n("Failed to save config"),": ").concat(d(r))),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})()},style:{maxWidth:600}},S&&l().createElement(a.Alert,{message:S,type:"error",showIcon:!0,style:{marginBottom:16}}),l().createElement(a.Alert,{message:n("Service Connection"),description:n("Configure the connection to your external document processing service"),type:"info",showIcon:!0,style:{marginBottom:24}}),l().createElement(a.Form.Item,{name:"baseUrl",label:n("Base URL"),rules:[{required:!0,message:n("Base URL is required")}],help:n("The root URL of your document processing API")},l().createElement(a.Input,{prefix:l().createElement(c.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),l().createElement(a.Form.Item,{name:"authType",label:n("Authentication Type"),initialValue:"none"},l().createElement(a.Select,{options:[{value:"none",label:n("None")},{value:"api_key",label:n("API Key")},{value:"bearer",label:n("Bearer Token")},{value:"custom_header",label:n("Custom Header")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var t=e.getFieldValue("authType");return"none"===t?null:l().createElement(l().Fragment,null,"custom_header"===t&&l().createElement(a.Form.Item,{name:"authHeaderName",label:n("Custom Header Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"X-Api-Key"})),l().createElement(a.Form.Item,{name:"authKey",label:"bearer"===t?n("Bearer Token"):n("API Key"),rules:[{required:!0}]},l().createElement(a.Input.Password,{placeholder:n("Enter key or token")})))}),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"defaultTimeout",label:n("Request Timeout (ms)"),initialValue:3e4},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"defaultRetries",label:n("Default Retries"),initialValue:2},l().createElement(a.InputNumber,{style:{width:"100%"},min:0,max:10})),l().createElement(a.Form.Item,{name:"pollInterval",label:n("Poll Interval (ms)"),initialValue:5e3},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"pollTimeout",label:n("Poll Timeout (ms)"),initialValue:3e5},l().createElement(a.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),l().createElement(a.Form.Item,{name:"webhookSecret",label:n("Webhook Secret"),help:n("Used to verify HMAC-SHA256 signatures on incoming webhook callbacks")},l().createElement(a.Input.Password,{placeholder:n("Optional: secret for webhook signature verification")})),l().createElement(a.Form.Item,null,l().createElement(a.Button,{type:"primary",htmlType:"submit",icon:l().createElement(c.SaveOutlined,null),loading:y},n("Save Configuration"))))};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function S(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){S(a,r,l,o,i,"next",e)}function i(e){S(a,r,l,o,i,"throw",e)}o(void 0)})}}function I(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||k(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||k(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}function T(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var F=a.Input.TextArea,C=function(e){var t=e.value,n=e.onChange,o=u(),i=I((0,r.useState)([]),2),s=i[0],m=i[1],d=(0,r.useRef)(),p=JSON.stringify(null!=t?t:{});(0,r.useEffect)(function(){d.current!==p&&(d.current=p,m(Object.entries(JSON.parse(p)).map(function(e,t){var n=I(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}})))},[p]);var f=function(e){m(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=JSON.stringify(t),null==n||n(t)},y=function(e,t,n){var r,l,a=O(s);a[e]=(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},a[e]),l=l={key:t,value:n},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(l)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),f(a)},h=function(e){f(s.filter(function(t,n){return n!==e}))};return l().createElement("div",null,s.map(function(e,t){return l().createElement(a.Space,{key:e.id,style:{display:"flex",marginBottom:4}},l().createElement(a.Input,{placeholder:o("Header name"),"aria-label":o("Header name"),value:e.key,onChange:function(n){return y(t,n.target.value,e.value)},style:{width:180}}),l().createElement(a.Input,{placeholder:o("Value"),"aria-label":o("Value"),value:e.value,onChange:function(n){return y(t,e.key,n.target.value)},style:{width:220}}),l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),onClick:function(){return h(t)},"aria-label":"".concat(o("Delete")," ").concat(e.key||o("Header name"))}))}),l().createElement(a.Button,{size:"small",type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:function(){return m(O(s).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},o("Add Header")))},x=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=u(),i=I((0,r.useState)(""),2),c=i[0],s=i[1],m=I((0,r.useState)(""),2),d=m[0],p=m[1];return(0,r.useEffect)(function(){if(!t)return void s("");try{s("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){s("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(F,{rows:6,value:c,onChange:function(e){return s(e.target.value)},onBlur:function(){if(!c.trim()){p(""),null==n||n(null);return}try{var e=JSON.parse(c);p(""),null==n||n(e)}catch(e){p(o("Invalid JSON"))}},placeholder:a||"{}",status:d?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),d&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},d))},P=function(){var e=(0,o.useFlowContext)().api,t=u(),n=I((0,r.useState)([]),2),i=n[0],s=n[1],d=I((0,r.useState)(!1),2),p=d[0],f=d[1],y=I((0,r.useState)(!1),2),h=y[0],b=y[1],g=I(a.Form.useForm(),1)[0],E=I((0,r.useState)(null),2),v=E[0],S=E[1],O={sync:t("Synchronous"),polling:t("Polling"),webhook:t("Webhook")},k={multipart:t("Multipart Upload"),base64:t("Base64 in JSON")},P=(0,r.useCallback)(function(){return w(function(){return T(this,function(t){switch(t.label){case 0:f(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,e.request({url:"docUnderstanding:listEndpoints"})];case 2:return s(m(t.sent(),[])),[3,4];case 3:return f(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){P()},[P]);var A=function(e){S(e.id),g.setFieldsValue(e),b(!0)},j=[{title:t("Name"),dataIndex:"name",width:150},{title:t("Subpath"),dataIndex:"subpath",width:200},{title:t("Method"),dataIndex:"method",width:80,render:function(e){return l().createElement(a.Tag,null,e)}},{title:t("Execution"),dataIndex:"executionMode",width:130,render:function(e){return l().createElement(a.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},O[e]||e)}},{title:t("File"),dataIndex:"fileInputMode",width:130,render:function(e){return"none"===e?"-":k[e]||e}},{title:t("Enabled"),dataIndex:"enabled",width:70,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("Action"),width:120,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return A(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this endpoint?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,w(function(){return T(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),P(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){S(null),g.resetFields(),b(!0)}},t("Add Endpoint"))),l().createElement(a.Table,{rowKey:"id",columns:j,dataSource:i,loading:p,size:"small"}),l().createElement(a.Modal,{title:v?t("Edit Endpoint"):t("Add Endpoint"),open:h,onOk:function(){return w(function(){var n;return T(this,function(r){switch(r.label){case 0:return r.trys.push([0,6,,7]),[4,g.validateFields()];case 1:if((n=r.sent()).customHeaders=Object.entries(n.customHeaders||{}).reduce(function(e,t){var n=I(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{}),!v)return[3,3];return[4,e.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:v},data:n})];case 2:return r.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createEndpoint",method:"POST",data:n})];case 4:r.sent(),r.label=5;case 5:return a.message.success(t("Saved")),b(!1),P(),[3,7];case 6:return r.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return b(!1)},okText:t("Save"),cancelText:t("Cancel"),width:680,destroyOnClose:!0},l().createElement(a.Form,{form:g,layout:"vertical",preserve:!1},l().createElement(a.Tabs,{size:"small",items:[{key:"basic",label:t("Basic"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"name",label:t("Unique Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"ocr, classify, extract..."})),l().createElement(a.Form.Item,{name:"subpath",label:t("Subpath"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"/api/v1/ocr"})),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(F,{rows:2,placeholder:t("What this endpoint does")})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"method",label:t("HTTP Method"),initialValue:"POST"},l().createElement(a.Select,{style:{width:120},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"}]})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))))},{key:"file",label:t("File Input"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileInputMode",label:t("File Input Mode"),initialValue:"none"},l().createElement(a.Select,{style:{width:200},options:[{value:"none",label:t("None")},{value:"multipart",label:t("Multipart Upload")},{value:"base64",label:t("Base64 in JSON")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==g.getFieldValue("fileInputMode")?l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileFieldName",label:t("File Field Name"),initialValue:"file"},l().createElement(a.Input,{placeholder:"file",style:{width:200}})),l().createElement(a.Form.Item,{name:"maxFiles",label:t("Max Files"),initialValue:1},l().createElement(a.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"gateway",label:t("Gateway / Discriminator"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"discriminatorField",label:t("Discriminator Field"),help:t("Form field that selects the API sub-case (e.g. mode/type/task/action/process). Sent automatically.")},l().createElement(a.Input,{placeholder:"mode",style:{width:200}})),l().createElement(a.Form.Item,{name:"discriminatorValue",label:t("Discriminator Value"),help:t("Value sent in the discriminator field (e.g. parse, invoice, disbursement).")},l().createElement(a.Input,{placeholder:"parse",style:{width:200}})),l().createElement(a.Form.Item,{name:"syncQueryParam",label:t("Sync Query Param"),help:t("When set, the request appends ?<param>=true to ask for a synchronous response (e.g. sync).")},l().createElement(a.Input,{placeholder:"sync",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractPath",label:t("Task ID Extract Path"),help:t("JSON path of the async task id in the 202 response (e.g. name). Used when the response is 202 even in sync mode.")},l().createElement(a.Input,{placeholder:"name",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractRegex",label:t("Task ID Extract Regex"),help:t("Regex with one capture group to pull the task id from the extracted path value (e.g. operations/([^/]+)).")},l().createElement(a.Input,{placeholder:"operations/([^/]+)",style:{width:240}})))},{key:"async",label:t("Async Config"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"executionMode",label:t("Execution Mode"),initialValue:"sync"},l().createElement(a.Select,{style:{width:200},options:[{value:"sync",label:t("Synchronous")},{value:"polling",label:t("Polling")},{value:"webhook",label:t("Webhook")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=g.getFieldValue("executionMode");return"sync"===e?null:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollTaskIdField",label:t("Task ID Field"),help:t("Field in response containing the async task ID"),initialValue:"task_id"},l().createElement(a.Input,{placeholder:"task_id"})),"polling"===e&&l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollResultSubpath",label:t("Poll Result Subpath"),help:t("URL to poll for result. Use {taskId} as placeholder."),rules:[{required:!0,message:t("Required for polling mode")}]},l().createElement(a.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),l().createElement(a.Form.Item,{name:"pollResultField",label:t("Result Field"),help:t("Field in poll response containing the actual result")},l().createElement(a.Input,{placeholder:"result"})),l().createElement(a.Form.Item,{name:"pollStatusField",label:t("Status Field (optional)"),help:t("Field to check completion status. If empty, any non-null result = complete.")},l().createElement(a.Input,{placeholder:"status"})),l().createElement(a.Form.Item,{name:"pollCompletedValue",label:t("Completed Value"),help:t("Value of status field that means 'done'"),initialValue:"completed"},l().createElement(a.Input,{placeholder:"completed"})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"pollInterval",label:t("Poll Interval (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),l().createElement(a.Form.Item,{name:"pollTimeout",label:t("Poll Timeout (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:t("Schema"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"requestBodySchema",label:t("Request Body Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})),l().createElement(a.Form.Item,{name:"responseSchema",label:t("Response Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:t("Custom Headers"),children:l().createElement(a.Form.Item,{name:"customHeaders",label:t("Additional Headers")},l().createElement(C,null))}]}))))};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){j(a,r,l,o,i,"next",e)}function i(e){j(a,r,l,o,i,"throw",e)}o(void 0)})}}function N(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){N(e,t,n[t])})}return e}function D(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function M(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||z(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||z(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e,t){if(e){if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}}function J(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var q=a.Input.TextArea,_=a.Collapse.Panel,V={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},H=["completed","failed","timeout"],W=function(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)},$=function(e){return JSON.stringify(null!=e?e:{},null,2)},K=function(e){return W(e)?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=M(t,2),r=n[0],l=K(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},L=function(e,t){return W(e)&&W(t)?Object.entries(e).reduce(function(e,t){var n=M(t,2),r=n[0],l=n[1];return D(R({},e),N({},r,L(l,e[r])))},R({},t)):void 0===t?e:t},G=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=e.rows,i=u(),c=M((0,r.useState)(""),2),s=c[0],m=c[1],d=M((0,r.useState)(""),2),p=d[0],f=d[1];return(0,r.useEffect)(function(){if(!t)return void m("");try{m("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){m("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(q,{rows:void 0===o?5:o,value:s,onChange:function(e){return m(e.target.value)},onBlur:function(){if(!s.trim()){f(""),null==n||n(null);return}try{var e=JSON.parse(s);f(""),null==n||n(e)}catch(e){f(i("Invalid JSON"))}},placeholder:a||"{}",status:p?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),p&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},p))},Q=function(e){var t=e.steps,n=e.endpoints,r=e.onChange,o=u(),i=function(e,n){var l,a=U(t),o=e+n;o<0||o>=a.length||(l=[a[o],a[e]],a[e]=l[0],a[o]=l[1],a.forEach(function(e,t){return e.stepOrder=t+1}),r(a))},s=function(e,n,l){var a=U(t);a[e]=D(R({},a[e]),N({},n,l)),r(a)},m=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),r(n)},d=function(){var e;r(U(t).concat([(e=t.length+1,{_key:"new_".concat(Date.now(),"_").concat(Math.random()),stepOrder:e,name:"",endpointId:null,inputMapping:null,outputAlias:"",condition:null,onError:"fail",retryCount:0})]))};return 0===t.length?l().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},l().createElement(a.Empty,{description:o("No steps yet"),imageStyle:{height:40}}),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8}},o("Add First Step"))):l().createElement("div",null,l().createElement(a.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,r){var u=n.find(function(t){return t.id===e.endpointId}),d=l().createElement(a.Space,{size:4,onClick:function(e){return e.stopPropagation()}},l().createElement(a.Button,{size:"small",disabled:0===r,icon:l().createElement(c.ArrowUpOutlined,null),onClick:function(){return i(r,-1)},"aria-label":o("Move step up")}),l().createElement(a.Button,{size:"small",disabled:r===t.length-1,icon:l().createElement(c.ArrowDownOutlined,null),onClick:function(){return i(r,1)},"aria-label":o("Move step down")}),l().createElement(a.Popconfirm,{title:o("Remove step?"),okText:o("Delete"),onConfirm:function(){return m(r)}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":o("Remove step?")}))),p=l().createElement(a.Space,null,l().createElement(a.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),l().createElement("span",null,e.name||o("(unnamed)")),u&&l().createElement(a.Tag,null,u.name),"skip"===e.onError&&l().createElement(a.Tooltip,{title:o("Step can be skipped on error")},l().createElement(a.Tag,{color:"orange"},o("skip on error"))),e.condition&&l().createElement(a.Tooltip,{title:o("Has condition")},l().createElement(a.Tag,{color:"purple"},o("conditional")))),f="step-name-".concat(e._key),y="step-endpoint-".concat(e._key),h="step-alias-".concat(e._key);return l().createElement(_,{key:e._key,header:p,extra:d},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement("div",null,l().createElement("label",{htmlFor:f,style:{fontWeight:500,display:"block",marginBottom:4}},o("Step Name")," *"),l().createElement(a.Input,{id:f,value:e.name,onChange:function(e){return s(r,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),l().createElement("div",null,l().createElement("label",{htmlFor:y,style:{fontWeight:500,display:"block",marginBottom:4}},o("Endpoint")," *"),l().createElement(a.Select,{id:y,value:e.endpointId,onChange:function(e){return s(r,"endpointId",e)},placeholder:o("Select endpoint"),style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),l().createElement("div",null,l().createElement("label",{htmlFor:h,style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("Output Alias")),l().createElement(a.Input,{id:h,value:e.outputAlias,onChange:function(e){return s(r,"outputAlias",e.target.value)},placeholder:"ocr_result"}),l().createElement("div",{style:{color:"#888",fontSize:11}},o("Other steps reference this as"),": $step[",e.outputAlias||e.stepOrder,"].response.field")),l().createElement("div",null,l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("On Error")),l().createElement(a.Space,null,l().createElement(a.Select,{value:e.onError,onChange:function(e){return s(r,"onError",e)},style:{width:120},"aria-label":o("On Error"),options:[{value:"fail",label:o("Fail")},{value:"skip",label:o("Skip")},{value:"retry",label:o("Retry")}]}),"retry"===e.onError&&l().createElement(a.InputNumber,{value:e.retryCount,onChange:function(e){return s(r,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100},"aria-label":o("Retry")})))),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Input Mapping (JSON)"),l().createElement(a.Tooltip,{title:o("Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.inputMapping,onChange:function(e){return s(r,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Condition (optional JSON)"),l().createElement(a.Tooltip,{title:o("Only run this step if the condition matches.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.condition,onChange:function(e){return s(r,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8,width:"100%"}},o("Add Step")))},Y=function(){var e=(0,o.useFlowContext)().api,t=u(),n=M((0,r.useState)([]),2),i=n[0],s=n[1],p=M((0,r.useState)([]),2),f=p[0],y=p[1],h=M((0,r.useState)(!1),2),b=h[0],g=h[1],E=M((0,r.useState)(!1),2),v=E[0],S=E[1],w=M(a.Form.useForm(),1)[0],I=M((0,r.useState)(null),2),O=I[0],k=I[1],T=M((0,r.useState)([]),2),F=T[0],C=T[1],x=M((0,r.useState)(!1),2),P=x[0],A=x[1],j=M((0,r.useState)(null),2),N=j[0],z=j[1],W=M((0,r.useState)("{}"),2),Y=W[0],X=W[1],Z=M((0,r.useState)(""),2),ee=Z[0],et=Z[1],en=M((0,r.useState)(null),2),er=en[0],el=en[1],ea=M((0,r.useState)(!1),2),eo=ea[0],ei=ea[1],eu=(0,r.useRef)(null),ec={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},es=(0,r.useCallback)(function(){return B(function(){var t,n,r;return J(this,function(l){switch(l.label){case 0:g(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,Promise.all([e.request({url:"docUnderstanding:listPipelines"}),e.request({url:"docUnderstanding:listEndpoints"})])];case 2:return n=(t=M.apply(void 0,[l.sent(),2]))[0],r=t[1],s(m(n,[])),y(m(r,[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){es()},[es]),(0,r.useEffect)(function(){return function(){eu.current&&clearInterval(eu.current)}},[]);var em=function(e){k(e.id),w.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),C(U(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){var t;return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:null!=(t=e.inputMapping)?t:null,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),S(!0)},ed=(0,r.useCallback)(function(){eu.current&&(clearInterval(eu.current),eu.current=null)},[]),ep=(0,r.useCallback)(function(t){return B(function(){var n;return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:t}})];case 1:return el(n=m(r.sent(),null)),n&&H.includes(n.status)&&(ed(),ei(!1)),[2,n]}})})()},[e,ed]),ef=(0,r.useCallback)(function(e){ed(),eu.current=setInterval(function(){ep(e).catch(function(e){ed(),ei(!1),a.message.error(d(e)||t("Failed to refresh test job"))})},1500)},[ep,ed,t]),ey=function(e){ed(),z(e),el(null),ei(!1),et(""),X($(K(e.inputSchema))),A(!0)},eh=function(){ed(),A(!1),z(null),el(null),ei(!1)},eb=[{title:t("Name"),dataIndex:"name",width:200},{title:t("Steps"),dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return l().createElement(a.Tag,null,"0 ",t("steps"));var n=U(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return l().createElement(a.Space,{size:2,wrap:!0},n.map(function(e,n){return l().createElement(l().Fragment,{key:e.id},n>0&&l().createElement("span",{style:{color:"#ccc"}},"→"),l().createElement(a.Tag,null,e.name||"".concat(t("Step")," ").concat(e.stepOrder)))}))}},{title:t("Enabled"),dataIndex:"enabled",width:80,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("AI Tool"),width:100,render:function(e,n){var r;return n.enabled?l().createElement(a.Tooltip,{title:"".concat(t("Registered as"),": doc_understanding.").concat(null==(r=n.name)?void 0:r.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},l().createElement(a.Tag,{color:"blue",icon:l().createElement(c.ThunderboltOutlined,null)},t("Active"))):l().createElement(a.Tag,null,t("Inactive"))}},{title:t("Action"),width:190,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.PlayCircleOutlined,null),disabled:!r.enabled,onClick:function(){return ey(r)},"aria-label":"".concat(t("Test")," ").concat(r.name)},t("Test")),l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return em(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this pipeline?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,B(function(){return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),es(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){k(null),w.resetFields(),C([]),S(!0)}},t("Add Pipeline"))),l().createElement(a.Table,{rowKey:"id",columns:eb,dataSource:i,loading:b,size:"small"}),l().createElement(a.Modal,{title:O?t("Edit Pipeline"):t("New Pipeline"),open:v,onOk:function(){return B(function(){var n,r,l,o,i,u,c,s,m;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,6,,7]),[4,w.validateFields()];case 1:n=d.sent(),r=!0,l=!1,o=void 0;try{for(i=F[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){if(!(c=u.value).name)return a.message.error(t("All steps must have a name")),[2];if(!c.endpointId)return a.message.error("".concat(t("Step"),' "').concat(c.name||c.stepOrder,'" ').concat(t("must have an endpoint"))),[2]}}catch(e){l=!0,o=e}finally{try{r||null==i.return||i.return()}finally{if(l)throw o}}if(new Set(s=F.map(function(e){return e.outputAlias}).filter(Boolean)).size!==s.length)return a.message.error(t("Step output aliases must be unique")),[2];if(m=D(R({},n),{steps:F.map(function(e){return D(R({},e.id?{id:e.id}:{}),{stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||void 0,condition:e.condition,onError:e.onError,retryCount:"retry"===e.onError?e.retryCount:0})})}),!O)return[3,3];return[4,e.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:O},data:m})];case 2:return d.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createPipeline",method:"POST",data:m})];case 4:d.sent(),d.label=5;case 5:return a.message.success(t("Saved")),S(!1),es(),[3,7];case 6:return d.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return S(!1)},okText:t("Save"),cancelText:t("Cancel"),width:800,destroyOnClose:!0},l().createElement(a.Form,{form:w,layout:"vertical",preserve:!1},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"name",label:t("Pipeline Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"full_document_processing"})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(q,{rows:2,placeholder:t("What this pipeline does")})),l().createElement(a.Card,{title:t("Pipeline Steps"),size:"small",style:{marginBottom:16},extra:l().createElement(a.Tag,{color:"blue"},F.length," ",t("step(s)"))},l().createElement(Q,{steps:F,endpoints:f,onChange:C})),l().createElement(a.Collapse,{size:"small",ghost:!0},l().createElement(_,{header:t("Advanced: Input Schema & Output Mapping"),key:"advanced"},l().createElement(a.Form.Item,{name:"inputSchema",label:t("Input Schema (JSON Schema)"),help:t("Defines what input this pipeline accepts. Used by AI tool schema.")},l().createElement(G,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),l().createElement(a.Form.Item,{name:"outputMapping",label:t("Output Mapping (JSON)"),help:t("Map final step results to pipeline output. If empty, all step results are returned.")},l().createElement(G,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),l().createElement(a.Modal,{title:N?"".concat(t("Test Playground"),": ").concat(N.name):t("Test Playground"),open:P,onCancel:eh,width:860,destroyOnClose:!0,footer:[l().createElement(a.Button,{key:"close",onClick:eh},t("Close")),(null==er?void 0:er.id)&&l().createElement(a.Button,{key:"refresh",icon:l().createElement(c.ReloadOutlined,null),disabled:eo,onClick:function(){return ep(er.id)}},t("Refresh")),l().createElement(a.Button,{key:"run",type:"primary",icon:l().createElement(c.PlayCircleOutlined,null),loading:eo,onClick:function(){return B(function(){var n,r,l,o,i;return J(this,function(u){switch(u.label){case 0:if(!N)return[2];try{r=Y.trim()?JSON.parse(Y):{},n=L(K(N.inputSchema),r),et("")}catch(e){return et(t("Invalid JSON input")),[2]}ed(),ei(!0),el(null),u.label=1;case 1:return u.trys.push([1,4,,5]),[4,e.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:N.id,input:n}})];case 2:if(!(l=m(u.sent(),{}).jobId))throw Error(t("Pipeline did not return a job ID"));return[4,ep(l)];case 3:return(o=u.sent())&&H.includes(o.status)||ef(l),a.message.success("".concat(t("Test job started"),": #").concat(l)),[3,5];case 4:return i=u.sent(),ei(!1),a.message.error(d(i)||t("Failed to run pipeline test")),[3,5];case 5:return[2]}})})()}},t("Run test"))].filter(Boolean)},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},l().createElement("div",null,l().createElement("label",{htmlFor:"playground-input",style:{fontWeight:500,marginBottom:6,display:"block"}},t("Input JSON")),l().createElement(q,{id:"playground-input",rows:16,value:Y,onChange:function(e){X(e.target.value),ee&&et("")},placeholder:'{ "document_url": "https://..." }',status:ee?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),ee&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:ee,style:{marginTop:8}}),l().createElement(a.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},l().createElement(_,{header:t("Input Schema"),key:"schema"},l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},$(null==N?void 0:N.inputSchema))))),l().createElement("div",null,l().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},l().createElement("span",{style:{fontWeight:500}},t("Result")),(null==er?void 0:er.status)&&l().createElement(a.Tag,{color:V[er.status]||"default"},ec[er.status]||er.status)),er?l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:8},wrap:!0},l().createElement(a.Tag,null,t("Job")," #",er.id),er.currentStep&&l().createElement(a.Tag,null,t("Step")," ",er.currentStep)),er.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:t("Pipeline error"),description:l().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},er.error),style:{marginBottom:12}}),l().createElement("div",{style:{fontWeight:500,marginBottom:4}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==er.finalResult&&null!==er.finalResult?$(er.finalResult):t("(not yet available)")),l().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},t("Step Results")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},er.stepResults?$(er.stepResults):"{}")):l().createElement(a.Empty,{description:t("Run a test to see job output"),imageStyle:{height:48}})))))};function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function ee(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Z(a,r,l,o,i,"next",e)}function i(e){Z(a,r,l,o,i,"throw",e)}o(void 0)})}}function et(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return X(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function en(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var er={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},el=function(){var e=(0,o.useFlowContext)().api,t=u(),n=et((0,r.useState)([]),2),i=n[0],s=n[1],d=et((0,r.useState)([]),2),f=d[0],y=d[1],h=et((0,r.useState)(!1),2),b=h[0],g=h[1],E=et((0,r.useState)(!1),2),v=E[0],S=E[1],w=et((0,r.useState)(null),2),I=w[0],O=w[1],k=et((0,r.useState)(void 0),2),T=k[0],F=k[1],C=et((0,r.useState)(void 0),2),x=C[0],P=C[1],A={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},j=(0,r.useCallback)(function(){return ee(function(){var t;return en(this,function(n){switch(n.label){case 0:g(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},T&&(t.status=T),x&&(t.pipelineId=x),[4,e.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s(m(n.sent(),[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e,T,x]),B=(0,r.useCallback)(function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:listPipelines"})];case 1:return y(m(t.sent(),[])),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})})()},[e]);(0,r.useEffect)(function(){B()},[B]),(0,r.useEffect)(function(){j();var e=setInterval(j,1e4);return function(){return clearInterval(e)}},[j]);var N=new Map(f.map(function(e){return[e.id,e.name]})),R=[{title:t("ID"),dataIndex:"id",width:60},{title:t("Pipeline"),dataIndex:"pipelineId",width:180,render:function(e){return N.get(e)||"#".concat(e)}},{title:t("Status"),dataIndex:"status",width:100,render:function(e){return l().createElement(a.Tag,{color:er[e]||"default"},A[e]||e)}},{title:t("Current Step"),dataIndex:"currentStep",width:90,render:function(e,n){return"completed"===n.status?l().createElement(a.Tag,{color:"success"},t("Done")):"failed"===n.status?l().createElement(a.Tag,{color:"error"},"".concat(t("Step")," ").concat(e)):l().createElement(a.Badge,{status:"processing",text:"".concat(t("Step")," ").concat(e)})}},{title:t("Started"),dataIndex:"startedAt",width:160,render:function(e){return p(e)}},{title:t("Completed"),dataIndex:"completedAt",width:160,render:function(e){return p(e)}},{title:t("Action"),width:80,render:function(n,r){return l().createElement(a.Button,{size:"small",icon:l().createElement(c.EyeOutlined,null),onClick:function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:r.id}})];case 1:return O(m(t.sent(),r)),[3,3];case 2:return t.sent(),O(r),[3,3];case 3:return S(!0),[2]}})})()},"aria-label":"".concat(t("View")," #").concat(r.id)},t("View"))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by status"),"aria-label":t("Filter by status"),value:T,onChange:F,style:{width:160},options:Object.keys(er).map(function(e){return{value:e,label:A[e]}})}),l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by pipeline"),"aria-label":t("Filter by pipeline"),value:x,onChange:P,style:{width:200},options:f.map(function(e){return{value:e.id,label:e.name}})}),l().createElement(a.Button,{icon:l().createElement(c.ReloadOutlined,null),onClick:j},t("Refresh"))),l().createElement(a.Table,{rowKey:"id",columns:R,dataSource:i,loading:b,size:"small",pagination:{pageSize:20}}),l().createElement(a.Drawer,{title:I?"".concat(t("Job")," #").concat(I.id," — ").concat(N.get(I.pipelineId)||t("Unknown")):t("Job Details"),width:640,open:v,onClose:function(){return S(!1)}},I&&l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Space,{wrap:!0},l().createElement(a.Tag,{color:er[I.status]||"default"},A[I.status]||I.status),I.startedAt&&l().createElement("span",null,t("Started"),": ",p(I.startedAt)),I.completedAt&&l().createElement("span",null,t("Completed"),": ",p(I.completedAt)))),I.error&&l().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},l().createElement("strong",{style:{color:"#cf1322"}},t("Error"),":"),l().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},I.error)),l().createElement("h4",null,t("Input")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(I.input,null,2)),l().createElement("h4",{style:{marginTop:16}},t("Step Results")),I.stepResults&&Object.keys(I.stepResults).length>0?Object.entries(I.stepResults).map(function(e){var t=et(e,2),n=t[0],r=t[1];return l().createElement("div",{key:n,style:{marginBottom:8}},l().createElement(a.Tag,{color:"blue"},n),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(r,null,2)))}):l().createElement("div",{style:{color:"#999"}},t("No step results yet")),l().createElement("h4",{style:{marginTop:16}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},I.finalResult?JSON.stringify(I.finalResult,null,2):t("(not yet available)")),I.externalTaskIds&&Object.keys(I.externalTaskIds).length>0&&l().createElement(l().Fragment,null,l().createElement("h4",{style:{marginTop:16}},t("External Task IDs")),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(I.externalTaskIds,null,2))))))},ea=function(){var e=u();return l().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:"100vh"}},l().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},l().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},e("Document Understanding - Pipeline Orchestrator"))),l().createElement("div",{style:{padding:"0 24px 24px"}},l().createElement(a.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:e("Service Config"),children:l().createElement(E,null)},{key:"endpoints",label:e("Endpoints"),children:l().createElement(P,null)},{key:"pipelines",label:e("Pipelines"),children:l().createElement(Y,null)},{key:"jobs",label:e("Jobs history"),children:l().createElement(el,null)}]})))},eo=ea}}]);
10
+ "use strict";(self.webpackChunkplugin_document_understanding=self.webpackChunkplugin_document_understanding||[]).push([["345"],{824:function(e,t,n){n.r(t),n.d(t,{PluginSettings:function(){return ea},default:function(){return eo}});var r=n(155),l=n.n(r),a=n(59),o=n(694),i=JSON.parse('{"UU":"plugin-document-understanding"}');function u(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[i.UU,"client"]})}}var c=n(375);function s(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e,t){var n,r;return e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"?null!=(n=null==(r=e.data)?void 0:r.data)?n:t:t}function d(e){return s(e,Error)?e.message:String(e)}function p(e){if(!e)return"-";var t=s(e,Date)?e:new Date(e);return Number.isNaN(t.getTime())?"-":t.toLocaleString()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=function(){var e=b(a.Form.useForm(),1)[0],t=(0,o.useFlowContext)().api,n=u(),i=b((0,r.useState)(!0),2),s=i[0],p=i[1],f=b((0,r.useState)(!1),2),y=f[0],E=f[1],v=b((0,r.useState)(),2),S=v[0],w=v[1];return((0,r.useEffect)(function(){var n=!1;return h(function(){var r,l;return g(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,3,4]),[4,t.request({url:"docUnderstanding:getConfig"})];case 1:if(r=a.sent(),n)return[2];return e.setFieldsValue(m(r,{})),[3,4];case 2:return l=a.sent(),n||w(d(l)),[3,4];case 3:return n||p(!1),[7];case 4:return[2]}})})(),function(){n=!0}},[t,e]),s)?l().createElement(a.Spin,{style:{marginTop:40}}):l().createElement(a.Form,{form:e,layout:"vertical",onFinish:function(e){return h(function(){var r;return g(this,function(l){switch(l.label){case 0:E(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,t.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return l.sent(),a.message.success(n("Configuration saved successfully")),[3,5];case 3:return r=l.sent(),a.message.error("".concat(n("Failed to save config"),": ").concat(d(r))),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})()},style:{maxWidth:600}},S&&l().createElement(a.Alert,{message:S,type:"error",showIcon:!0,style:{marginBottom:16}}),l().createElement(a.Alert,{message:n("Service Connection"),description:n("Configure the connection to your external document processing service"),type:"info",showIcon:!0,style:{marginBottom:24}}),l().createElement(a.Form.Item,{name:"baseUrl",label:n("Base URL"),rules:[{required:!0,message:n("Base URL is required")}],help:n("The root URL of your document processing API")},l().createElement(a.Input,{prefix:l().createElement(c.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),l().createElement(a.Form.Item,{name:"authType",label:n("Authentication Type"),initialValue:"none"},l().createElement(a.Select,{options:[{value:"none",label:n("None")},{value:"api_key",label:n("API Key")},{value:"bearer",label:n("Bearer Token")},{value:"custom_header",label:n("Custom Header")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var t=e.getFieldValue("authType");return"none"===t?null:l().createElement(l().Fragment,null,"custom_header"===t&&l().createElement(a.Form.Item,{name:"authHeaderName",label:n("Custom Header Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"X-Api-Key"})),l().createElement(a.Form.Item,{name:"authKey",label:"bearer"===t?n("Bearer Token"):n("API Key"),rules:[{required:!0}]},l().createElement(a.Input.Password,{placeholder:n("Enter key or token")})))}),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"defaultTimeout",label:n("Request Timeout (ms)"),initialValue:3e4},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"defaultRetries",label:n("Default Retries"),initialValue:2},l().createElement(a.InputNumber,{style:{width:"100%"},min:0,max:10})),l().createElement(a.Form.Item,{name:"pollInterval",label:n("Poll Interval (ms)"),initialValue:5e3},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"pollTimeout",label:n("Poll Timeout (ms)"),initialValue:3e5},l().createElement(a.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),l().createElement(a.Form.Item,{name:"webhookSecret",label:n("Webhook Secret"),help:n("Used to verify HMAC-SHA256 signatures on incoming webhook callbacks")},l().createElement(a.Input.Password,{placeholder:n("Optional: secret for webhook signature verification")})),l().createElement(a.Form.Item,null,l().createElement(a.Button,{type:"primary",htmlType:"submit",icon:l().createElement(c.SaveOutlined,null),loading:y},n("Save Configuration"))))};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function S(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){S(a,r,l,o,i,"next",e)}function i(e){S(a,r,l,o,i,"throw",e)}o(void 0)})}}function I(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||k(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||k(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}function T(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var F=a.Input.TextArea,C=function(e){var t=e.value,n=e.onChange,o=u(),i=I((0,r.useState)([]),2),s=i[0],m=i[1],d=(0,r.useRef)(),p=JSON.stringify(null!=t?t:{});(0,r.useEffect)(function(){d.current!==p&&(d.current=p,m(Object.entries(JSON.parse(p)).map(function(e,t){var n=I(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}})))},[p]);var f=function(e){m(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=JSON.stringify(t),null==n||n(t)},y=function(e,t,n){var r,l,a=O(s);a[e]=(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},a[e]),l=l={key:t,value:n},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(l)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),f(a)},h=function(e){f(s.filter(function(t,n){return n!==e}))};return l().createElement("div",null,s.map(function(e,t){return l().createElement(a.Space,{key:e.id,style:{display:"flex",marginBottom:4}},l().createElement(a.Input,{placeholder:o("Header name"),"aria-label":o("Header name"),value:e.key,onChange:function(n){return y(t,n.target.value,e.value)},style:{width:180}}),l().createElement(a.Input,{placeholder:o("Value"),"aria-label":o("Value"),value:e.value,onChange:function(n){return y(t,e.key,n.target.value)},style:{width:220}}),l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),onClick:function(){return h(t)},"aria-label":"".concat(o("Delete")," ").concat(e.key||o("Header name"))}))}),l().createElement(a.Button,{size:"small",type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:function(){return m(O(s).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},o("Add Header")))},x=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=u(),i=I((0,r.useState)(""),2),c=i[0],s=i[1],m=I((0,r.useState)(""),2),d=m[0],p=m[1];return(0,r.useEffect)(function(){if(!t)return void s("");try{s("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){s("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(F,{rows:6,value:c,onChange:function(e){return s(e.target.value)},onBlur:function(){if(!c.trim()){p(""),null==n||n(null);return}try{var e=JSON.parse(c);p(""),null==n||n(e)}catch(e){p(o("Invalid JSON"))}},placeholder:a||"{}",status:d?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),d&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},d))},P=function(){var e=(0,o.useFlowContext)().api,t=u(),n=I((0,r.useState)([]),2),i=n[0],s=n[1],d=I((0,r.useState)(!1),2),p=d[0],f=d[1],y=I((0,r.useState)(!1),2),h=y[0],b=y[1],g=I(a.Form.useForm(),1)[0],E=I((0,r.useState)(null),2),v=E[0],S=E[1],O={sync:t("Synchronous"),polling:t("Polling"),webhook:t("Webhook")},k={multipart:t("Multipart Upload"),base64:t("Base64 in JSON")},P=(0,r.useCallback)(function(){return w(function(){return T(this,function(t){switch(t.label){case 0:f(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,e.request({url:"docUnderstanding:listEndpoints"})];case 2:return s(m(t.sent(),[])),[3,4];case 3:return f(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){P()},[P]);var A=function(e){S(e.id),g.setFieldsValue(e),b(!0)},j=[{title:t("Name"),dataIndex:"name",width:150},{title:t("Subpath"),dataIndex:"subpath",width:200},{title:t("Method"),dataIndex:"method",width:80,render:function(e){return l().createElement(a.Tag,null,e)}},{title:t("Execution"),dataIndex:"executionMode",width:130,render:function(e){return l().createElement(a.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},O[e]||e)}},{title:t("File"),dataIndex:"fileInputMode",width:130,render:function(e){return"none"===e?"-":k[e]||e}},{title:t("Enabled"),dataIndex:"enabled",width:70,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("Action"),width:120,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return A(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this endpoint?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,w(function(){return T(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),P(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){S(null),g.resetFields(),b(!0)}},t("Add Endpoint"))),l().createElement(a.Table,{rowKey:"id",columns:j,dataSource:i,loading:p,size:"small"}),l().createElement(a.Modal,{title:v?t("Edit Endpoint"):t("Add Endpoint"),open:h,onOk:function(){return w(function(){var n;return T(this,function(r){switch(r.label){case 0:return r.trys.push([0,6,,7]),[4,g.validateFields()];case 1:if((n=r.sent()).customHeaders=Object.entries(n.customHeaders||{}).reduce(function(e,t){var n=I(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{}),!v)return[3,3];return[4,e.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:v},data:n})];case 2:return r.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createEndpoint",method:"POST",data:n})];case 4:r.sent(),r.label=5;case 5:return a.message.success(t("Saved")),b(!1),P(),[3,7];case 6:return r.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return b(!1)},okText:t("Save"),cancelText:t("Cancel"),width:680,destroyOnClose:!0},l().createElement(a.Form,{form:g,layout:"vertical",preserve:!1},l().createElement(a.Tabs,{size:"small",items:[{key:"basic",label:t("Basic"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"name",label:t("Unique Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"ocr, classify, extract..."})),l().createElement(a.Form.Item,{name:"subpath",label:t("Subpath"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"/api/v1/ocr"})),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(F,{rows:2,placeholder:t("What this endpoint does")})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"method",label:t("HTTP Method"),initialValue:"POST"},l().createElement(a.Select,{style:{width:120},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"}]})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))))},{key:"file",label:t("File Input"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileInputMode",label:t("File Input Mode"),initialValue:"none"},l().createElement(a.Select,{style:{width:200},options:[{value:"none",label:t("None")},{value:"multipart",label:t("Multipart Upload")},{value:"base64",label:t("Base64 in JSON")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==g.getFieldValue("fileInputMode")?l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileFieldName",label:t("File Field Name"),initialValue:"file"},l().createElement(a.Input,{placeholder:"file",style:{width:200}})),l().createElement(a.Form.Item,{name:"maxFiles",label:t("Max Files"),initialValue:1},l().createElement(a.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"gateway",label:t("Gateway / Discriminator"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"discriminatorField",label:t("Discriminator Field"),help:t("Form field that selects the API sub-case (e.g. mode/type/task/action/process). Sent automatically.")},l().createElement(a.Input,{placeholder:"mode",style:{width:200}})),l().createElement(a.Form.Item,{name:"discriminatorValue",label:t("Discriminator Value"),help:t("Value sent in the discriminator field (e.g. parse, invoice, disbursement).")},l().createElement(a.Input,{placeholder:"parse",style:{width:200}})),l().createElement(a.Form.Item,{name:"syncQueryParam",label:t("Sync Query Param"),help:t("When set, the request appends ?<param>=true to ask for a synchronous response (e.g. sync).")},l().createElement(a.Input,{placeholder:"sync",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractPath",label:t("Task ID Extract Path"),help:t("JSON path of the async task id in the 202 response (e.g. name). Used when the response is 202 even in sync mode.")},l().createElement(a.Input,{placeholder:"name",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractRegex",label:t("Task ID Extract Regex"),help:t("Regex with one capture group to pull the task id from the extracted path value (e.g. operations/([^/]+)).")},l().createElement(a.Input,{placeholder:"operations/([^/]+)",style:{width:240}})))},{key:"async",label:t("Async Config"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"executionMode",label:t("Execution Mode"),initialValue:"sync"},l().createElement(a.Select,{style:{width:200},options:[{value:"sync",label:t("Synchronous")},{value:"polling",label:t("Polling")},{value:"webhook",label:t("Webhook")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=g.getFieldValue("executionMode");return"sync"===e?null:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollTaskIdField",label:t("Task ID Field"),help:t("Field in response containing the async task ID"),initialValue:"task_id"},l().createElement(a.Input,{placeholder:"task_id"})),"polling"===e&&l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollResultSubpath",label:t("Poll Result Subpath"),help:t("URL to poll for result. Use {taskId} as placeholder."),rules:[{required:!0,message:t("Required for polling mode")}]},l().createElement(a.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),l().createElement(a.Form.Item,{name:"pollResultField",label:t("Result Field"),help:t("Field in poll response containing the actual result")},l().createElement(a.Input,{placeholder:"result"})),l().createElement(a.Form.Item,{name:"pollStatusField",label:t("Status Field (optional)"),help:t("Field to check completion status. If empty, any non-null result = complete.")},l().createElement(a.Input,{placeholder:"status"})),l().createElement(a.Form.Item,{name:"pollCompletedValue",label:t("Completed Value"),help:t("Value of status field that means 'done'"),initialValue:"completed"},l().createElement(a.Input,{placeholder:"completed"})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"pollInterval",label:t("Poll Interval (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),l().createElement(a.Form.Item,{name:"pollTimeout",label:t("Poll Timeout (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:t("Schema"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"requestBodySchema",label:t("Request Body Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})),l().createElement(a.Form.Item,{name:"responseSchema",label:t("Response Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:t("Custom Headers"),children:l().createElement(a.Form.Item,{name:"customHeaders",label:t("Additional Headers")},l().createElement(C,null))}]}))))};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){j(a,r,l,o,i,"next",e)}function i(e){j(a,r,l,o,i,"throw",e)}o(void 0)})}}function N(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){N(e,t,n[t])})}return e}function D(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function M(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||z(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||z(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e,t){if(e){if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}}function J(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var q=a.Input.TextArea,_=a.Collapse.Panel,V={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},H=["completed","failed","timeout"],W=function(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)},$=function(e){return JSON.stringify(null!=e?e:{},null,2)},K=function(e){return W(e)?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=M(t,2),r=n[0],l=K(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},L=function(e,t){return W(e)&&W(t)?Object.entries(e).reduce(function(e,t){var n=M(t,2),r=n[0],l=n[1];return D(R({},e),N({},r,L(l,e[r])))},R({},t)):void 0===t?e:t},G=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=e.rows,i=u(),c=M((0,r.useState)(""),2),s=c[0],m=c[1],d=M((0,r.useState)(""),2),p=d[0],f=d[1];return(0,r.useEffect)(function(){if(!t)return void m("");try{m("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){m("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(q,{rows:void 0===o?5:o,value:s,onChange:function(e){return m(e.target.value)},onBlur:function(){if(!s.trim()){f(""),null==n||n(null);return}try{var e=JSON.parse(s);f(""),null==n||n(e)}catch(e){f(i("Invalid JSON"))}},placeholder:a||"{}",status:p?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),p&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},p))},Q=function(e){var t=e.steps,n=e.endpoints,r=e.onChange,o=u(),i=function(e,n){var l,a=U(t),o=e+n;o<0||o>=a.length||(l=[a[o],a[e]],a[e]=l[0],a[o]=l[1],a.forEach(function(e,t){return e.stepOrder=t+1}),r(a))},s=function(e,n,l){var a=U(t);a[e]=D(R({},a[e]),N({},n,l)),r(a)},m=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),r(n)},d=function(){var e;r(U(t).concat([(e=t.length+1,{_key:"new_".concat(Date.now(),"_").concat(Math.random()),stepOrder:e,name:"",endpointId:null,inputMapping:null,outputAlias:"",condition:null,onError:"fail",retryCount:0})]))};return 0===t.length?l().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},l().createElement(a.Empty,{description:o("No steps yet"),imageStyle:{height:40}}),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8}},o("Add First Step"))):l().createElement("div",null,l().createElement(a.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,r){var u=n.find(function(t){return t.id===e.endpointId}),d=l().createElement(a.Space,{size:4,onClick:function(e){return e.stopPropagation()}},l().createElement(a.Button,{size:"small",disabled:0===r,icon:l().createElement(c.ArrowUpOutlined,null),onClick:function(){return i(r,-1)},"aria-label":o("Move step up")}),l().createElement(a.Button,{size:"small",disabled:r===t.length-1,icon:l().createElement(c.ArrowDownOutlined,null),onClick:function(){return i(r,1)},"aria-label":o("Move step down")}),l().createElement(a.Popconfirm,{title:o("Remove step?"),okText:o("Delete"),onConfirm:function(){return m(r)}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":o("Remove step?")}))),p=l().createElement(a.Space,null,l().createElement(a.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),l().createElement("span",null,e.name||o("(unnamed)")),u&&l().createElement(a.Tag,null,u.name),"skip"===e.onError&&l().createElement(a.Tooltip,{title:o("Step can be skipped on error")},l().createElement(a.Tag,{color:"orange"},o("skip on error"))),e.condition&&l().createElement(a.Tooltip,{title:o("Has condition")},l().createElement(a.Tag,{color:"purple"},o("conditional")))),f="step-name-".concat(e._key),y="step-endpoint-".concat(e._key),h="step-alias-".concat(e._key);return l().createElement(_,{key:e._key,header:p,extra:d},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement("div",null,l().createElement("label",{htmlFor:f,style:{fontWeight:500,display:"block",marginBottom:4}},o("Step Name")," *"),l().createElement(a.Input,{id:f,value:e.name,onChange:function(e){return s(r,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),l().createElement("div",null,l().createElement("label",{htmlFor:y,style:{fontWeight:500,display:"block",marginBottom:4}},o("Endpoint")," *"),l().createElement(a.Select,{id:y,value:e.endpointId,onChange:function(e){return s(r,"endpointId",e)},placeholder:o("Select endpoint"),style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),l().createElement("div",null,l().createElement("label",{htmlFor:h,style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("Output Alias")),l().createElement(a.Input,{id:h,value:e.outputAlias,onChange:function(e){return s(r,"outputAlias",e.target.value)},placeholder:"ocr_result"}),l().createElement("div",{style:{color:"#888",fontSize:11}},o("Other steps reference this as"),": $step[",e.outputAlias||e.stepOrder,"].response.field")),l().createElement("div",null,l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("On Error")),l().createElement(a.Space,null,l().createElement(a.Select,{value:e.onError,onChange:function(e){return s(r,"onError",e)},style:{width:120},"aria-label":o("On Error"),options:[{value:"fail",label:o("Fail")},{value:"skip",label:o("Skip")},{value:"retry",label:o("Retry")}]}),"retry"===e.onError&&l().createElement(a.InputNumber,{value:e.retryCount,onChange:function(e){return s(r,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100},"aria-label":o("Retry")})))),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Input Mapping (JSON)"),l().createElement(a.Tooltip,{title:o("Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.inputMapping,onChange:function(e){return s(r,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Condition (optional JSON)"),l().createElement(a.Tooltip,{title:o("Only run this step if the condition matches.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.condition,onChange:function(e){return s(r,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8,width:"100%"}},o("Add Step")))},Y=function(){var e=(0,o.useFlowContext)().api,t=u(),n=M((0,r.useState)([]),2),i=n[0],s=n[1],p=M((0,r.useState)([]),2),f=p[0],y=p[1],h=M((0,r.useState)(!1),2),b=h[0],g=h[1],E=M((0,r.useState)(!1),2),v=E[0],S=E[1],w=M(a.Form.useForm(),1)[0],I=M((0,r.useState)(null),2),O=I[0],k=I[1],T=M((0,r.useState)([]),2),F=T[0],C=T[1],x=M((0,r.useState)(!1),2),P=x[0],A=x[1],j=M((0,r.useState)(null),2),N=j[0],z=j[1],W=M((0,r.useState)("{}"),2),Y=W[0],X=W[1],Z=M((0,r.useState)(""),2),ee=Z[0],et=Z[1],en=M((0,r.useState)(null),2),er=en[0],el=en[1],ea=M((0,r.useState)(!1),2),eo=ea[0],ei=ea[1],eu=(0,r.useRef)(null),ec={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},es=(0,r.useCallback)(function(){return B(function(){var t,n,r;return J(this,function(l){switch(l.label){case 0:g(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,Promise.all([e.request({url:"docUnderstanding:listPipelines"}),e.request({url:"docUnderstanding:listEndpoints"})])];case 2:return n=(t=M.apply(void 0,[l.sent(),2]))[0],r=t[1],s(m(n,[])),y(m(r,[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){es()},[es]),(0,r.useEffect)(function(){return function(){eu.current&&clearInterval(eu.current)}},[]);var em=function(e){k(e.id),w.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),C(U(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){var t;return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:null!=(t=e.inputMapping)?t:null,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),S(!0)},ed=(0,r.useCallback)(function(){eu.current&&(clearInterval(eu.current),eu.current=null)},[]),ep=(0,r.useCallback)(function(t){return B(function(){var n;return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:t}})];case 1:return el(n=m(r.sent(),null)),n&&H.includes(n.status)&&(ed(),ei(!1)),[2,n]}})})()},[e,ed]),ef=(0,r.useCallback)(function(e){ed(),eu.current=setInterval(function(){ep(e).catch(function(e){ed(),ei(!1),a.message.error(d(e)||t("Failed to refresh test job"))})},1500)},[ep,ed,t]),ey=function(e){ed(),z(e),el(null),ei(!1),et(""),X($(K(e.inputSchema))),A(!0)},eh=function(){ed(),A(!1),z(null),el(null),ei(!1)},eb=[{title:t("Name"),dataIndex:"name",width:200},{title:t("Steps"),dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return l().createElement(a.Tag,null,"0 ",t("steps"));var n=U(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return l().createElement(a.Space,{size:2,wrap:!0},n.map(function(e,n){return l().createElement(l().Fragment,{key:e.id},n>0&&l().createElement("span",{style:{color:"#ccc"}},"→"),l().createElement(a.Tag,null,e.name||"".concat(t("Step")," ").concat(e.stepOrder)))}))}},{title:t("Enabled"),dataIndex:"enabled",width:80,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("AI Tool"),width:100,render:function(e,n){var r;return n.enabled?l().createElement(a.Tooltip,{title:"".concat(t("Registered as"),": doc_understanding.").concat(null==(r=n.name)?void 0:r.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},l().createElement(a.Tag,{color:"blue",icon:l().createElement(c.ThunderboltOutlined,null)},t("Active"))):l().createElement(a.Tag,null,t("Inactive"))}},{title:t("Action"),width:190,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.PlayCircleOutlined,null),disabled:!r.enabled,onClick:function(){return ey(r)},"aria-label":"".concat(t("Test")," ").concat(r.name)},t("Test")),l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return em(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this pipeline?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,B(function(){return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),es(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){k(null),w.resetFields(),C([]),S(!0)}},t("Add Pipeline"))),l().createElement(a.Table,{rowKey:"id",columns:eb,dataSource:i,loading:b,size:"small"}),l().createElement(a.Modal,{title:O?t("Edit Pipeline"):t("New Pipeline"),open:v,onOk:function(){return B(function(){var n,r,l,o,i,u,c,s,m;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,6,,7]),[4,w.validateFields()];case 1:n=d.sent(),r=!0,l=!1,o=void 0;try{for(i=F[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){if(!(c=u.value).name)return a.message.error(t("All steps must have a name")),[2];if(!c.endpointId)return a.message.error("".concat(t("Step"),' "').concat(c.name||c.stepOrder,'" ').concat(t("must have an endpoint"))),[2]}}catch(e){l=!0,o=e}finally{try{r||null==i.return||i.return()}finally{if(l)throw o}}if(new Set(s=F.map(function(e){return e.outputAlias}).filter(Boolean)).size!==s.length)return a.message.error(t("Step output aliases must be unique")),[2];if(m=D(R({},n),{steps:F.map(function(e){return D(R({},e.id?{id:e.id}:{}),{stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||void 0,condition:e.condition,onError:e.onError,retryCount:"retry"===e.onError?e.retryCount:0})})}),!O)return[3,3];return[4,e.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:O},data:m})];case 2:return d.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createPipeline",method:"POST",data:m})];case 4:d.sent(),d.label=5;case 5:return a.message.success(t("Saved")),S(!1),es(),[3,7];case 6:return d.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return S(!1)},okText:t("Save"),cancelText:t("Cancel"),width:800,destroyOnClose:!0},l().createElement(a.Form,{form:w,layout:"vertical",preserve:!1},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"name",label:t("Pipeline Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"full_document_processing"})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(q,{rows:2,placeholder:t("What this pipeline does")})),l().createElement(a.Card,{title:t("Pipeline Steps"),size:"small",style:{marginBottom:16},extra:l().createElement(a.Tag,{color:"blue"},F.length," ",t("step(s)"))},l().createElement(Q,{steps:F,endpoints:f,onChange:C})),l().createElement(a.Collapse,{size:"small",ghost:!0},l().createElement(_,{header:t("Advanced: Input Schema & Output Mapping"),key:"advanced"},l().createElement(a.Form.Item,{name:"inputSchema",label:t("Input Schema (JSON Schema)"),help:t("Defines what input this pipeline accepts. Used by AI tool schema.")},l().createElement(G,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),l().createElement(a.Form.Item,{name:"outputMapping",label:t("Output Mapping (JSON)"),help:t("Map final step results to pipeline output. If empty, all step results are returned.")},l().createElement(G,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),l().createElement(a.Modal,{title:N?"".concat(t("Test Playground"),": ").concat(N.name):t("Test Playground"),open:P,onCancel:eh,width:860,destroyOnClose:!0,footer:[l().createElement(a.Button,{key:"close",onClick:eh},t("Close")),(null==er?void 0:er.id)&&l().createElement(a.Button,{key:"refresh",icon:l().createElement(c.ReloadOutlined,null),disabled:eo,onClick:function(){return ep(er.id)}},t("Refresh")),l().createElement(a.Button,{key:"run",type:"primary",icon:l().createElement(c.PlayCircleOutlined,null),loading:eo,onClick:function(){return B(function(){var n,r,l,o,i;return J(this,function(u){switch(u.label){case 0:if(!N)return[2];try{r=Y.trim()?JSON.parse(Y):{},n=L(K(N.inputSchema),r),et("")}catch(e){return et(t("Invalid JSON input")),[2]}ed(),ei(!0),el(null),u.label=1;case 1:return u.trys.push([1,4,,5]),[4,e.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:N.id,input:n}})];case 2:if(!(l=m(u.sent(),{}).jobId))throw Error(t("Pipeline did not return a job ID"));return[4,ep(l)];case 3:return(o=u.sent())&&H.includes(o.status)||ef(l),a.message.success("".concat(t("Test job started"),": #").concat(l)),[3,5];case 4:return i=u.sent(),ei(!1),a.message.error(d(i)||t("Failed to run pipeline test")),[3,5];case 5:return[2]}})})()}},t("Run test"))].filter(Boolean)},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},l().createElement("div",null,l().createElement("label",{htmlFor:"playground-input",style:{fontWeight:500,marginBottom:6,display:"block"}},t("Input JSON")),l().createElement(q,{id:"playground-input",rows:16,value:Y,onChange:function(e){X(e.target.value),ee&&et("")},placeholder:'{ "document_url": "https://..." }',status:ee?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),ee&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:ee,style:{marginTop:8}}),l().createElement(a.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},l().createElement(_,{header:t("Input Schema"),key:"schema"},l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},$(null==N?void 0:N.inputSchema))))),l().createElement("div",null,l().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},l().createElement("span",{style:{fontWeight:500}},t("Result")),(null==er?void 0:er.status)&&l().createElement(a.Tag,{color:V[er.status]||"default"},ec[er.status]||er.status)),er?l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:8},wrap:!0},l().createElement(a.Tag,null,t("Job")," #",er.id),er.currentStep&&l().createElement(a.Tag,null,t("Step")," ",er.currentStep)),er.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:t("Pipeline error"),description:l().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},er.error),style:{marginBottom:12}}),l().createElement("div",{style:{fontWeight:500,marginBottom:4}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==er.finalResult&&null!==er.finalResult?$(er.finalResult):t("(not yet available)")),l().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},t("Step Results")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},er.stepResults?$(er.stepResults):"{}")):l().createElement(a.Empty,{description:t("Run a test to see job output"),imageStyle:{height:48}})))))};function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function ee(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Z(a,r,l,o,i,"next",e)}function i(e){Z(a,r,l,o,i,"throw",e)}o(void 0)})}}function et(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return X(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function en(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var er={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},el=function(){var e=(0,o.useFlowContext)().api,t=u(),n=et((0,r.useState)([]),2),i=n[0],s=n[1],d=et((0,r.useState)([]),2),f=d[0],y=d[1],h=et((0,r.useState)(!1),2),b=h[0],g=h[1],E=et((0,r.useState)(!1),2),v=E[0],S=E[1],w=et((0,r.useState)(null),2),I=w[0],O=w[1],k=et((0,r.useState)(void 0),2),T=k[0],F=k[1],C=et((0,r.useState)(void 0),2),x=C[0],P=C[1],A={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},j=(0,r.useCallback)(function(){return ee(function(){var t;return en(this,function(n){switch(n.label){case 0:g(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},T&&(t.status=T),x&&(t.pipelineId=x),[4,e.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s(m(n.sent(),[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e,T,x]),B=(0,r.useCallback)(function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:listPipelines"})];case 1:return y(m(t.sent(),[])),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})})()},[e]);(0,r.useEffect)(function(){B()},[B]),(0,r.useEffect)(function(){j();var e=setInterval(j,1e4);return function(){return clearInterval(e)}},[j]);var N=new Map(f.map(function(e){return[e.id,e.name]})),R=[{title:t("ID"),dataIndex:"id",width:60},{title:t("Pipeline"),dataIndex:"pipelineId",width:180,render:function(e){return N.get(e)||"#".concat(e)}},{title:t("Status"),dataIndex:"status",width:100,render:function(e){return l().createElement(a.Tag,{color:er[e]||"default"},A[e]||e)}},{title:t("Current Step"),dataIndex:"currentStep",width:90,render:function(e,n){return"completed"===n.status?l().createElement(a.Tag,{color:"success"},t("Done")):"failed"===n.status?l().createElement(a.Tag,{color:"error"},"".concat(t("Step")," ").concat(e)):l().createElement(a.Badge,{status:"processing",text:"".concat(t("Step")," ").concat(e)})}},{title:t("Started"),dataIndex:"startedAt",width:160,render:function(e){return p(e)}},{title:t("Completed"),dataIndex:"completedAt",width:160,render:function(e){return p(e)}},{title:t("Action"),width:80,render:function(n,r){return l().createElement(a.Button,{size:"small",icon:l().createElement(c.EyeOutlined,null),onClick:function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:r.id}})];case 1:return O(m(t.sent(),r)),[3,3];case 2:return t.sent(),O(r),[3,3];case 3:return S(!0),[2]}})})()},"aria-label":"".concat(t("View")," #").concat(r.id)},t("View"))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by status"),"aria-label":t("Filter by status"),value:T,onChange:F,style:{width:160},options:Object.keys(er).map(function(e){return{value:e,label:A[e]}})}),l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by pipeline"),"aria-label":t("Filter by pipeline"),value:x,onChange:P,style:{width:200},options:f.map(function(e){return{value:e.id,label:e.name}})}),l().createElement(a.Button,{icon:l().createElement(c.ReloadOutlined,null),onClick:j},t("Refresh"))),l().createElement(a.Table,{rowKey:"id",columns:R,dataSource:i,loading:b,size:"small",pagination:{pageSize:20}}),l().createElement(a.Drawer,{title:I?"".concat(t("Job")," #").concat(I.id," — ").concat(N.get(I.pipelineId)||t("Unknown")):t("Job Details"),width:640,open:v,onClose:function(){return S(!1)}},I&&l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Space,{wrap:!0},l().createElement(a.Tag,{color:er[I.status]||"default"},A[I.status]||I.status),I.startedAt&&l().createElement("span",null,t("Started"),": ",p(I.startedAt)),I.completedAt&&l().createElement("span",null,t("Completed"),": ",p(I.completedAt)))),I.error&&l().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},l().createElement("strong",{style:{color:"#cf1322"}},t("Error"),":"),l().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},I.error)),l().createElement("h4",null,t("Input")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(I.input,null,2)),l().createElement("h4",{style:{marginTop:16}},t("Step Results")),I.stepResults&&Object.keys(I.stepResults).length>0?Object.entries(I.stepResults).map(function(e){var t=et(e,2),n=t[0],r=t[1];return l().createElement("div",{key:n,style:{marginBottom:8}},l().createElement(a.Tag,{color:"blue"},n),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(r,null,2)))}):l().createElement("div",{style:{color:"#999"}},t("No step results yet")),l().createElement("h4",{style:{marginTop:16}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},I.finalResult?JSON.stringify(I.finalResult,null,2):t("(not yet available)")),I.externalTaskIds&&Object.keys(I.externalTaskIds).length>0&&l().createElement(l().Fragment,null,l().createElement("h4",{style:{marginTop:16}},t("External Task IDs")),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(I.externalTaskIds,null,2))))))},ea=function(e){var t=e.embedded,n=void 0!==t&&t,r=u();return l().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:n?void 0:"100vh"}},!n&&l().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},l().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},r("Document Understanding - Pipeline Orchestrator"))),l().createElement("div",{style:{padding:n?0:"0 24px 24px"}},l().createElement(a.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:r("Service Config"),children:l().createElement(E,null)},{key:"endpoints",label:r("Endpoints"),children:l().createElement(P,null)},{key:"pipelines",label:r("Pipelines"),children:l().createElement(Y,null)},{key:"jobs",label:r("Jobs history"),children:l().createElement(el,null)}]})))},eo=ea}}]);
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("antd"),require("@nocobase/client"),require("@ant-design/icons"),require("@nocobase/flow-engine")):"function"==typeof define&&define.amd?define("plugin-document-understanding",["react","antd","@nocobase/client","@ant-design/icons","@nocobase/flow-engine"],t):"object"==typeof exports?exports["plugin-document-understanding"]=t(require("react"),require("antd"),require("@nocobase/client"),require("@ant-design/icons"),require("@nocobase/flow-engine")):e["plugin-document-understanding"]=t(e.react,e.antd,e["@nocobase/client"],e["@ant-design/icons"],e["@nocobase/flow-engine"])}(self,function(e,t,n,r,o){return function(){"use strict";var i,u,c,a={375:function(e){e.exports=r},342:function(e){e.exports=n},694:function(e){e.exports=o},59:function(e){e.exports=t},155:function(t){t.exports=e}},l={};function f(e){var t=l[e];if(void 0!==t)return t.exports;var n=l[e]={exports:{}};return a[e](n,n.exports,f),n.exports}f.m=a,f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},f.d=function(e,t){for(var n in t)f.o(t,n)&&!f.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},f.f={},f.e=function(e){return Promise.all(Object.keys(f.f).reduce(function(t,n){return f.f[n](e,t),t},[]))},f.u=function(e){return""+e+".e6e484fb1974c3d3.js"},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s={},f.l=function(e,t,n,r){if(s[e])return void s[e].push(t);if(void 0!==n)for(var o,i,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var a=u[c];if(a.getAttribute("src")==e||a.getAttribute("data-rspack")=="plugin-document-understanding:"+n){o=a;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,f.nc&&o.setAttribute("nonce",f.nc),o.setAttribute("data-rspack","plugin-document-understanding:"+n),o.src=e),s[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(p);var r=s[e];if(delete s[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},p=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},f.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.g.importScripts&&(p=f.g.location+"");var s,p,d=f.g.document;if(!p&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(p=d.currentScript.src),!p)){var b=d.getElementsByTagName("script");if(b.length)for(var g=b.length-1;g>-1&&(!p||!/^http(s?):/.test(p));)p=b[g--].src}if(!p)throw Error("Automatic publicPath is not supported in this browser");f.p=p.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={889:0},f.f.j=function(e,t){var n=f.o(i,e)?i[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=i[e]=[t,r]});t.push(n[2]=r);var o=f.p+f.u(e),u=Error();f.l(o,function(t){if(f.o(i,e)&&(0!==(n=i[e])&&(i[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;u.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",u.name="ChunkLoadError",u.type=r,u.request=o,n[1](u)}},"chunk-"+e,e)}},u=function(e,t){var n,r,o=t[0],u=t[1],c=t[2],a=0;if(o.some(function(e){return 0!==i[e]})){for(n in u)f.o(u,n)&&(f.m[n]=u[n]);c&&c(f)}for(e&&e(t);a<o.length;a++)r=o[a],f.o(i,r)&&i[r]&&i[r][0](),i[r]=0},(c=self.webpackChunkplugin_document_understanding=self.webpackChunkplugin_document_understanding||[]).forEach(u.bind(null,0)),c.push=u.bind(null,c.push.bind(c));var h={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-document-understanding/dist/client/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-document-understanding/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var u=window.location.pathname||"/",c=u.indexOf(i);e=c>=0?u.slice(0,c+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-document-understanding/dist/client/"}f.p=e}(),!function(){f.r(h),f.d(h,{PluginDocumentUnderstandingClient:function(){return l}});var e=f(155),t=f.n(e),n=f(342);function r(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function o(e,t,n){return(o=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&u(o,n.prototype),o}).apply(null,arguments)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var l=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return e=o,t=arguments,e=i(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],i(this).constructor):e.apply(this,t))}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&u(o,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(u,"next",{value:a(0)}),c(u,"throw",{value:a(1)}),c(u,"return",{value:a(2)}),"function"==typeof Symbol&&c(u,Symbol.iterator,{value:function(){return this}}),u;function a(c){return function(a){var l=[c,a];if(n)throw TypeError("Generator is already executing.");for(;u&&(u=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.add("document-understanding",{title:this.t("Document Understanding"),icon:"FileSearchOutlined",Component:t().lazy(function(){return f.e("345").then(f.bind(f,824))}),aclSnippet:"pm.document-understanding"}),[2]})},function(){var t=this,n=arguments;return new Promise(function(o,i){var u=e.apply(t,n);function c(e){r(u,o,i,c,a,"next",e)}function a(e){r(u,o,i,c,a,"throw",e)}c(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(o.prototype,n),o}(c(n.Plugin));h.default=l}(),h}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("antd"),require("@nocobase/client"),require("@ant-design/icons"),require("@nocobase/flow-engine")):"function"==typeof define&&define.amd?define("plugin-document-understanding",["react","antd","@nocobase/client","@ant-design/icons","@nocobase/flow-engine"],t):"object"==typeof exports?exports["plugin-document-understanding"]=t(require("react"),require("antd"),require("@nocobase/client"),require("@ant-design/icons"),require("@nocobase/flow-engine")):e["plugin-document-understanding"]=t(e.react,e.antd,e["@nocobase/client"],e["@ant-design/icons"],e["@nocobase/flow-engine"])}(self,function(e,t,n,r,o){return function(){"use strict";var i,u,c,a={375:function(e){e.exports=r},342:function(e){e.exports=n},694:function(e){e.exports=o},59:function(e){e.exports=t},155:function(t){t.exports=e}},l={};function f(e){var t=l[e];if(void 0!==t)return t.exports;var n=l[e]={exports:{}};return a[e](n,n.exports,f),n.exports}f.m=a,f.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(t,{a:t}),t},f.d=function(e,t){for(var n in t)f.o(t,n)&&!f.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},f.f={},f.e=function(e){return Promise.all(Object.keys(f.f).reduce(function(t,n){return f.f[n](e,t),t},[]))},f.u=function(e){return""+e+".277fbb2b97424db5.js"},f.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),f.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},s={},f.l=function(e,t,n,r){if(s[e])return void s[e].push(t);if(void 0!==n)for(var o,i,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var a=u[c];if(a.getAttribute("src")==e||a.getAttribute("data-rspack")=="plugin-document-understanding:"+n){o=a;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,f.nc&&o.setAttribute("nonce",f.nc),o.setAttribute("data-rspack","plugin-document-understanding:"+n),o.src=e),s[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(p);var r=s[e];if(delete s[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},p=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},f.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.g.importScripts&&(p=f.g.location+"");var s,p,d=f.g.document;if(!p&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(p=d.currentScript.src),!p)){var b=d.getElementsByTagName("script");if(b.length)for(var g=b.length-1;g>-1&&(!p||!/^http(s?):/.test(p));)p=b[g--].src}if(!p)throw Error("Automatic publicPath is not supported in this browser");f.p=p.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={889:0},f.f.j=function(e,t){var n=f.o(i,e)?i[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=i[e]=[t,r]});t.push(n[2]=r);var o=f.p+f.u(e),u=Error();f.l(o,function(t){if(f.o(i,e)&&(0!==(n=i[e])&&(i[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;u.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",u.name="ChunkLoadError",u.type=r,u.request=o,n[1](u)}},"chunk-"+e,e)}},u=function(e,t){var n,r,o=t[0],u=t[1],c=t[2],a=0;if(o.some(function(e){return 0!==i[e]})){for(n in u)f.o(u,n)&&(f.m[n]=u[n]);c&&c(f)}for(e&&e(t);a<o.length;a++)r=o[a],f.o(i,r)&&i[r]&&i[r][0](),i[r]=0},(c=self.webpackChunkplugin_document_understanding=self.webpackChunkplugin_document_understanding||[]).forEach(u.bind(null,0)),c.push=u.bind(null,c.push.bind(c));var h={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-document-understanding/dist/client/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-document-understanding/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var u=window.location.pathname||"/",c=u.indexOf(i);e=c>=0?u.slice(0,c+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-document-understanding/dist/client/"}f.p=e}(),!function(){f.r(h),f.d(h,{PluginDocumentUnderstandingClient:function(){return l}});var e=f(155),t=f.n(e),n=f(342);function r(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function o(e,t,n){return(o=a()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&u(o,n.prototype),o}).apply(null,arguments)}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,i(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var l=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function o(){var e,t;if(!(this instanceof o))throw TypeError("Cannot call a class as a function");return e=o,t=arguments,e=i(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(e,t||[],i(this).constructor):e.apply(this,t))}return o.prototype=Object.create(e&&e.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),e&&u(o,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(u,"next",{value:a(0)}),c(u,"throw",{value:a(1)}),c(u,"return",{value:a(2)}),"function"==typeof Symbol&&c(u,Symbol.iterator,{value:function(){return this}}),u;function a(c){return function(a){var l=[c,a];if(n)throw TypeError("Generator is already executing.");for(;u&&(u=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.add("document-understanding",{title:this.t("Document Understanding"),icon:"FileSearchOutlined",Component:t().lazy(function(){return f.e("345").then(f.bind(f,824))}),aclSnippet:"pm.document-understanding"}),[2]})},function(){var t=this,n=arguments;return new Promise(function(o,i){var u=e.apply(t,n);function c(e){r(u,o,i,c,a,"next",e)}function a(e){r(u,o,i,c,a,"throw",e)}c(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(o.prototype,n),o}(c(n.Plugin));h.default=l}(),h}()});
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- "use strict";(self.webpackChunkplugin_document_understanding_client_v2=self.webpackChunkplugin_document_understanding_client_v2||[]).push([["345"],{824:function(e,t,n){n.r(t),n.d(t,{PluginSettings:function(){return ea},default:function(){return eo}});var r=n(155),l=n.n(r),a=n(59),o=n(694),i=JSON.parse('{"UU":"plugin-document-understanding"}');function u(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[i.UU,"client"]})}}var c=n(375);function s(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e,t){var n,r;return e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"?null!=(n=null==(r=e.data)?void 0:r.data)?n:t:t}function d(e){return s(e,Error)?e.message:String(e)}function p(e){if(!e)return"-";var t=s(e,Date)?e:new Date(e);return Number.isNaN(t.getTime())?"-":t.toLocaleString()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=function(){var e=b(a.Form.useForm(),1)[0],t=(0,o.useFlowContext)().api,n=u(),i=b((0,r.useState)(!0),2),s=i[0],p=i[1],f=b((0,r.useState)(!1),2),y=f[0],E=f[1],v=b((0,r.useState)(),2),S=v[0],w=v[1];return((0,r.useEffect)(function(){var n=!1;return h(function(){var r,l;return g(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,3,4]),[4,t.request({url:"docUnderstanding:getConfig"})];case 1:if(r=a.sent(),n)return[2];return e.setFieldsValue(m(r,{})),[3,4];case 2:return l=a.sent(),n||w(d(l)),[3,4];case 3:return n||p(!1),[7];case 4:return[2]}})})(),function(){n=!0}},[t,e]),s)?l().createElement(a.Spin,{style:{marginTop:40}}):l().createElement(a.Form,{form:e,layout:"vertical",onFinish:function(e){return h(function(){var r;return g(this,function(l){switch(l.label){case 0:E(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,t.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return l.sent(),a.message.success(n("Configuration saved successfully")),[3,5];case 3:return r=l.sent(),a.message.error("".concat(n("Failed to save config"),": ").concat(d(r))),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})()},style:{maxWidth:600}},S&&l().createElement(a.Alert,{message:S,type:"error",showIcon:!0,style:{marginBottom:16}}),l().createElement(a.Alert,{message:n("Service Connection"),description:n("Configure the connection to your external document processing service"),type:"info",showIcon:!0,style:{marginBottom:24}}),l().createElement(a.Form.Item,{name:"baseUrl",label:n("Base URL"),rules:[{required:!0,message:n("Base URL is required")}],help:n("The root URL of your document processing API")},l().createElement(a.Input,{prefix:l().createElement(c.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),l().createElement(a.Form.Item,{name:"authType",label:n("Authentication Type"),initialValue:"none"},l().createElement(a.Select,{options:[{value:"none",label:n("None")},{value:"api_key",label:n("API Key")},{value:"bearer",label:n("Bearer Token")},{value:"custom_header",label:n("Custom Header")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var t=e.getFieldValue("authType");return"none"===t?null:l().createElement(l().Fragment,null,"custom_header"===t&&l().createElement(a.Form.Item,{name:"authHeaderName",label:n("Custom Header Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"X-Api-Key"})),l().createElement(a.Form.Item,{name:"authKey",label:"bearer"===t?n("Bearer Token"):n("API Key"),rules:[{required:!0}]},l().createElement(a.Input.Password,{placeholder:n("Enter key or token")})))}),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"defaultTimeout",label:n("Request Timeout (ms)"),initialValue:3e4},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"defaultRetries",label:n("Default Retries"),initialValue:2},l().createElement(a.InputNumber,{style:{width:"100%"},min:0,max:10})),l().createElement(a.Form.Item,{name:"pollInterval",label:n("Poll Interval (ms)"),initialValue:5e3},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"pollTimeout",label:n("Poll Timeout (ms)"),initialValue:3e5},l().createElement(a.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),l().createElement(a.Form.Item,{name:"webhookSecret",label:n("Webhook Secret"),help:n("Used to verify HMAC-SHA256 signatures on incoming webhook callbacks")},l().createElement(a.Input.Password,{placeholder:n("Optional: secret for webhook signature verification")})),l().createElement(a.Form.Item,null,l().createElement(a.Button,{type:"primary",htmlType:"submit",icon:l().createElement(c.SaveOutlined,null),loading:y},n("Save Configuration"))))};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function S(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){S(a,r,l,o,i,"next",e)}function i(e){S(a,r,l,o,i,"throw",e)}o(void 0)})}}function I(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||k(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||k(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}function T(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var F=a.Input.TextArea,C=function(e){var t=e.value,n=e.onChange,o=u(),i=I((0,r.useState)([]),2),s=i[0],m=i[1],d=(0,r.useRef)(),p=JSON.stringify(null!=t?t:{});(0,r.useEffect)(function(){d.current!==p&&(d.current=p,m(Object.entries(JSON.parse(p)).map(function(e,t){var n=I(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}})))},[p]);var f=function(e){m(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=JSON.stringify(t),null==n||n(t)},y=function(e,t,n){var r,l,a=O(s);a[e]=(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},a[e]),l=l={key:t,value:n},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(l)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),f(a)},h=function(e){f(s.filter(function(t,n){return n!==e}))};return l().createElement("div",null,s.map(function(e,t){return l().createElement(a.Space,{key:e.id,style:{display:"flex",marginBottom:4}},l().createElement(a.Input,{placeholder:o("Header name"),"aria-label":o("Header name"),value:e.key,onChange:function(n){return y(t,n.target.value,e.value)},style:{width:180}}),l().createElement(a.Input,{placeholder:o("Value"),"aria-label":o("Value"),value:e.value,onChange:function(n){return y(t,e.key,n.target.value)},style:{width:220}}),l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),onClick:function(){return h(t)},"aria-label":"".concat(o("Delete")," ").concat(e.key||o("Header name"))}))}),l().createElement(a.Button,{size:"small",type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:function(){return m(O(s).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},o("Add Header")))},x=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=u(),i=I((0,r.useState)(""),2),c=i[0],s=i[1],m=I((0,r.useState)(""),2),d=m[0],p=m[1];return(0,r.useEffect)(function(){if(!t)return void s("");try{s("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){s("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(F,{rows:6,value:c,onChange:function(e){return s(e.target.value)},onBlur:function(){if(!c.trim()){p(""),null==n||n(null);return}try{var e=JSON.parse(c);p(""),null==n||n(e)}catch(e){p(o("Invalid JSON"))}},placeholder:a||"{}",status:d?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),d&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},d))},P=function(){var e=(0,o.useFlowContext)().api,t=u(),n=I((0,r.useState)([]),2),i=n[0],s=n[1],d=I((0,r.useState)(!1),2),p=d[0],f=d[1],y=I((0,r.useState)(!1),2),h=y[0],b=y[1],g=I(a.Form.useForm(),1)[0],E=I((0,r.useState)(null),2),v=E[0],S=E[1],O={sync:t("Synchronous"),polling:t("Polling"),webhook:t("Webhook")},k={multipart:t("Multipart Upload"),base64:t("Base64 in JSON")},P=(0,r.useCallback)(function(){return w(function(){return T(this,function(t){switch(t.label){case 0:f(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,e.request({url:"docUnderstanding:listEndpoints"})];case 2:return s(m(t.sent(),[])),[3,4];case 3:return f(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){P()},[P]);var A=function(e){S(e.id),g.setFieldsValue(e),b(!0)},j=[{title:t("Name"),dataIndex:"name",width:150},{title:t("Subpath"),dataIndex:"subpath",width:200},{title:t("Method"),dataIndex:"method",width:80,render:function(e){return l().createElement(a.Tag,null,e)}},{title:t("Execution"),dataIndex:"executionMode",width:130,render:function(e){return l().createElement(a.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},O[e]||e)}},{title:t("File"),dataIndex:"fileInputMode",width:130,render:function(e){return"none"===e?"-":k[e]||e}},{title:t("Enabled"),dataIndex:"enabled",width:70,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("Action"),width:120,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return A(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this endpoint?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,w(function(){return T(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),P(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){S(null),g.resetFields(),b(!0)}},t("Add Endpoint"))),l().createElement(a.Table,{rowKey:"id",columns:j,dataSource:i,loading:p,size:"small"}),l().createElement(a.Modal,{title:v?t("Edit Endpoint"):t("Add Endpoint"),open:h,onOk:function(){return w(function(){var n;return T(this,function(r){switch(r.label){case 0:return r.trys.push([0,6,,7]),[4,g.validateFields()];case 1:if((n=r.sent()).customHeaders=Object.entries(n.customHeaders||{}).reduce(function(e,t){var n=I(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{}),!v)return[3,3];return[4,e.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:v},data:n})];case 2:return r.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createEndpoint",method:"POST",data:n})];case 4:r.sent(),r.label=5;case 5:return a.message.success(t("Saved")),b(!1),P(),[3,7];case 6:return r.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return b(!1)},okText:t("Save"),cancelText:t("Cancel"),width:680,destroyOnClose:!0},l().createElement(a.Form,{form:g,layout:"vertical",preserve:!1},l().createElement(a.Tabs,{size:"small",items:[{key:"basic",label:t("Basic"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"name",label:t("Unique Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"ocr, classify, extract..."})),l().createElement(a.Form.Item,{name:"subpath",label:t("Subpath"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"/api/v1/ocr"})),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(F,{rows:2,placeholder:t("What this endpoint does")})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"method",label:t("HTTP Method"),initialValue:"POST"},l().createElement(a.Select,{style:{width:120},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"}]})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))))},{key:"file",label:t("File Input"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileInputMode",label:t("File Input Mode"),initialValue:"none"},l().createElement(a.Select,{style:{width:200},options:[{value:"none",label:t("None")},{value:"multipart",label:t("Multipart Upload")},{value:"base64",label:t("Base64 in JSON")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==g.getFieldValue("fileInputMode")?l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileFieldName",label:t("File Field Name"),initialValue:"file"},l().createElement(a.Input,{placeholder:"file",style:{width:200}})),l().createElement(a.Form.Item,{name:"maxFiles",label:t("Max Files"),initialValue:1},l().createElement(a.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"gateway",label:t("Gateway / Discriminator"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"discriminatorField",label:t("Discriminator Field"),help:t("Form field that selects the API sub-case (e.g. mode/type/task/action/process). Sent automatically.")},l().createElement(a.Input,{placeholder:"mode",style:{width:200}})),l().createElement(a.Form.Item,{name:"discriminatorValue",label:t("Discriminator Value"),help:t("Value sent in the discriminator field (e.g. parse, invoice, disbursement).")},l().createElement(a.Input,{placeholder:"parse",style:{width:200}})),l().createElement(a.Form.Item,{name:"syncQueryParam",label:t("Sync Query Param"),help:t("When set, the request appends ?<param>=true to ask for a synchronous response (e.g. sync).")},l().createElement(a.Input,{placeholder:"sync",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractPath",label:t("Task ID Extract Path"),help:t("JSON path of the async task id in the 202 response (e.g. name). Used when the response is 202 even in sync mode.")},l().createElement(a.Input,{placeholder:"name",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractRegex",label:t("Task ID Extract Regex"),help:t("Regex with one capture group to pull the task id from the extracted path value (e.g. operations/([^/]+)).")},l().createElement(a.Input,{placeholder:"operations/([^/]+)",style:{width:240}})))},{key:"async",label:t("Async Config"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"executionMode",label:t("Execution Mode"),initialValue:"sync"},l().createElement(a.Select,{style:{width:200},options:[{value:"sync",label:t("Synchronous")},{value:"polling",label:t("Polling")},{value:"webhook",label:t("Webhook")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=g.getFieldValue("executionMode");return"sync"===e?null:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollTaskIdField",label:t("Task ID Field"),help:t("Field in response containing the async task ID"),initialValue:"task_id"},l().createElement(a.Input,{placeholder:"task_id"})),"polling"===e&&l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollResultSubpath",label:t("Poll Result Subpath"),help:t("URL to poll for result. Use {taskId} as placeholder."),rules:[{required:!0,message:t("Required for polling mode")}]},l().createElement(a.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),l().createElement(a.Form.Item,{name:"pollResultField",label:t("Result Field"),help:t("Field in poll response containing the actual result")},l().createElement(a.Input,{placeholder:"result"})),l().createElement(a.Form.Item,{name:"pollStatusField",label:t("Status Field (optional)"),help:t("Field to check completion status. If empty, any non-null result = complete.")},l().createElement(a.Input,{placeholder:"status"})),l().createElement(a.Form.Item,{name:"pollCompletedValue",label:t("Completed Value"),help:t("Value of status field that means 'done'"),initialValue:"completed"},l().createElement(a.Input,{placeholder:"completed"})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"pollInterval",label:t("Poll Interval (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),l().createElement(a.Form.Item,{name:"pollTimeout",label:t("Poll Timeout (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:t("Schema"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"requestBodySchema",label:t("Request Body Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})),l().createElement(a.Form.Item,{name:"responseSchema",label:t("Response Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:t("Custom Headers"),children:l().createElement(a.Form.Item,{name:"customHeaders",label:t("Additional Headers")},l().createElement(C,null))}]}))))};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){j(a,r,l,o,i,"next",e)}function i(e){j(a,r,l,o,i,"throw",e)}o(void 0)})}}function N(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){N(e,t,n[t])})}return e}function D(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function M(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||z(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||z(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e,t){if(e){if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}}function J(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var _=a.Input.TextArea,q=a.Collapse.Panel,V={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},H=["completed","failed","timeout"],W=function(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)},$=function(e){return JSON.stringify(null!=e?e:{},null,2)},K=function(e){return W(e)?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=M(t,2),r=n[0],l=K(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},L=function(e,t){return W(e)&&W(t)?Object.entries(e).reduce(function(e,t){var n=M(t,2),r=n[0],l=n[1];return D(R({},e),N({},r,L(l,e[r])))},R({},t)):void 0===t?e:t},G=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=e.rows,i=u(),c=M((0,r.useState)(""),2),s=c[0],m=c[1],d=M((0,r.useState)(""),2),p=d[0],f=d[1];return(0,r.useEffect)(function(){if(!t)return void m("");try{m("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){m("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(_,{rows:void 0===o?5:o,value:s,onChange:function(e){return m(e.target.value)},onBlur:function(){if(!s.trim()){f(""),null==n||n(null);return}try{var e=JSON.parse(s);f(""),null==n||n(e)}catch(e){f(i("Invalid JSON"))}},placeholder:a||"{}",status:p?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),p&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},p))},Q=function(e){var t=e.steps,n=e.endpoints,r=e.onChange,o=u(),i=function(e,n){var l,a=U(t),o=e+n;o<0||o>=a.length||(l=[a[o],a[e]],a[e]=l[0],a[o]=l[1],a.forEach(function(e,t){return e.stepOrder=t+1}),r(a))},s=function(e,n,l){var a=U(t);a[e]=D(R({},a[e]),N({},n,l)),r(a)},m=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),r(n)},d=function(){var e;r(U(t).concat([(e=t.length+1,{_key:"new_".concat(Date.now(),"_").concat(Math.random()),stepOrder:e,name:"",endpointId:null,inputMapping:null,outputAlias:"",condition:null,onError:"fail",retryCount:0})]))};return 0===t.length?l().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},l().createElement(a.Empty,{description:o("No steps yet"),imageStyle:{height:40}}),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8}},o("Add First Step"))):l().createElement("div",null,l().createElement(a.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,r){var u=n.find(function(t){return t.id===e.endpointId}),d=l().createElement(a.Space,{size:4,onClick:function(e){return e.stopPropagation()}},l().createElement(a.Button,{size:"small",disabled:0===r,icon:l().createElement(c.ArrowUpOutlined,null),onClick:function(){return i(r,-1)},"aria-label":o("Move step up")}),l().createElement(a.Button,{size:"small",disabled:r===t.length-1,icon:l().createElement(c.ArrowDownOutlined,null),onClick:function(){return i(r,1)},"aria-label":o("Move step down")}),l().createElement(a.Popconfirm,{title:o("Remove step?"),okText:o("Delete"),onConfirm:function(){return m(r)}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":o("Remove step?")}))),p=l().createElement(a.Space,null,l().createElement(a.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),l().createElement("span",null,e.name||o("(unnamed)")),u&&l().createElement(a.Tag,null,u.name),"skip"===e.onError&&l().createElement(a.Tooltip,{title:o("Step can be skipped on error")},l().createElement(a.Tag,{color:"orange"},o("skip on error"))),e.condition&&l().createElement(a.Tooltip,{title:o("Has condition")},l().createElement(a.Tag,{color:"purple"},o("conditional")))),f="step-name-".concat(e._key),y="step-endpoint-".concat(e._key),h="step-alias-".concat(e._key);return l().createElement(q,{key:e._key,header:p,extra:d},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement("div",null,l().createElement("label",{htmlFor:f,style:{fontWeight:500,display:"block",marginBottom:4}},o("Step Name")," *"),l().createElement(a.Input,{id:f,value:e.name,onChange:function(e){return s(r,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),l().createElement("div",null,l().createElement("label",{htmlFor:y,style:{fontWeight:500,display:"block",marginBottom:4}},o("Endpoint")," *"),l().createElement(a.Select,{id:y,value:e.endpointId,onChange:function(e){return s(r,"endpointId",e)},placeholder:o("Select endpoint"),style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),l().createElement("div",null,l().createElement("label",{htmlFor:h,style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("Output Alias")),l().createElement(a.Input,{id:h,value:e.outputAlias,onChange:function(e){return s(r,"outputAlias",e.target.value)},placeholder:"ocr_result"}),l().createElement("div",{style:{color:"#888",fontSize:11}},o("Other steps reference this as"),": $step[",e.outputAlias||e.stepOrder,"].response.field")),l().createElement("div",null,l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("On Error")),l().createElement(a.Space,null,l().createElement(a.Select,{value:e.onError,onChange:function(e){return s(r,"onError",e)},style:{width:120},"aria-label":o("On Error"),options:[{value:"fail",label:o("Fail")},{value:"skip",label:o("Skip")},{value:"retry",label:o("Retry")}]}),"retry"===e.onError&&l().createElement(a.InputNumber,{value:e.retryCount,onChange:function(e){return s(r,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100},"aria-label":o("Retry")})))),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Input Mapping (JSON)"),l().createElement(a.Tooltip,{title:o("Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.inputMapping,onChange:function(e){return s(r,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Condition (optional JSON)"),l().createElement(a.Tooltip,{title:o("Only run this step if the condition matches.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.condition,onChange:function(e){return s(r,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8,width:"100%"}},o("Add Step")))},Y=function(){var e=(0,o.useFlowContext)().api,t=u(),n=M((0,r.useState)([]),2),i=n[0],s=n[1],p=M((0,r.useState)([]),2),f=p[0],y=p[1],h=M((0,r.useState)(!1),2),b=h[0],g=h[1],E=M((0,r.useState)(!1),2),v=E[0],S=E[1],w=M(a.Form.useForm(),1)[0],I=M((0,r.useState)(null),2),O=I[0],k=I[1],T=M((0,r.useState)([]),2),F=T[0],C=T[1],x=M((0,r.useState)(!1),2),P=x[0],A=x[1],j=M((0,r.useState)(null),2),N=j[0],z=j[1],W=M((0,r.useState)("{}"),2),Y=W[0],X=W[1],Z=M((0,r.useState)(""),2),ee=Z[0],et=Z[1],en=M((0,r.useState)(null),2),er=en[0],el=en[1],ea=M((0,r.useState)(!1),2),eo=ea[0],ei=ea[1],eu=(0,r.useRef)(null),ec={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},es=(0,r.useCallback)(function(){return B(function(){var t,n,r;return J(this,function(l){switch(l.label){case 0:g(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,Promise.all([e.request({url:"docUnderstanding:listPipelines"}),e.request({url:"docUnderstanding:listEndpoints"})])];case 2:return n=(t=M.apply(void 0,[l.sent(),2]))[0],r=t[1],s(m(n,[])),y(m(r,[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){es()},[es]),(0,r.useEffect)(function(){return function(){eu.current&&clearInterval(eu.current)}},[]);var em=function(e){k(e.id),w.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),C(U(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){var t;return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:null!=(t=e.inputMapping)?t:null,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),S(!0)},ed=(0,r.useCallback)(function(){eu.current&&(clearInterval(eu.current),eu.current=null)},[]),ep=(0,r.useCallback)(function(t){return B(function(){var n;return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:t}})];case 1:return el(n=m(r.sent(),null)),n&&H.includes(n.status)&&(ed(),ei(!1)),[2,n]}})})()},[e,ed]),ef=(0,r.useCallback)(function(e){ed(),eu.current=setInterval(function(){ep(e).catch(function(e){ed(),ei(!1),a.message.error(d(e)||t("Failed to refresh test job"))})},1500)},[ep,ed,t]),ey=function(e){ed(),z(e),el(null),ei(!1),et(""),X($(K(e.inputSchema))),A(!0)},eh=function(){ed(),A(!1),z(null),el(null),ei(!1)},eb=[{title:t("Name"),dataIndex:"name",width:200},{title:t("Steps"),dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return l().createElement(a.Tag,null,"0 ",t("steps"));var n=U(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return l().createElement(a.Space,{size:2,wrap:!0},n.map(function(e,n){return l().createElement(l().Fragment,{key:e.id},n>0&&l().createElement("span",{style:{color:"#ccc"}},"→"),l().createElement(a.Tag,null,e.name||"".concat(t("Step")," ").concat(e.stepOrder)))}))}},{title:t("Enabled"),dataIndex:"enabled",width:80,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("AI Tool"),width:100,render:function(e,n){var r;return n.enabled?l().createElement(a.Tooltip,{title:"".concat(t("Registered as"),": doc_understanding.").concat(null==(r=n.name)?void 0:r.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},l().createElement(a.Tag,{color:"blue",icon:l().createElement(c.ThunderboltOutlined,null)},t("Active"))):l().createElement(a.Tag,null,t("Inactive"))}},{title:t("Action"),width:190,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.PlayCircleOutlined,null),disabled:!r.enabled,onClick:function(){return ey(r)},"aria-label":"".concat(t("Test")," ").concat(r.name)},t("Test")),l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return em(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this pipeline?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,B(function(){return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),es(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){k(null),w.resetFields(),C([]),S(!0)}},t("Add Pipeline"))),l().createElement(a.Table,{rowKey:"id",columns:eb,dataSource:i,loading:b,size:"small"}),l().createElement(a.Modal,{title:O?t("Edit Pipeline"):t("New Pipeline"),open:v,onOk:function(){return B(function(){var n,r,l,o,i,u,c,s,m;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,6,,7]),[4,w.validateFields()];case 1:n=d.sent(),r=!0,l=!1,o=void 0;try{for(i=F[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){if(!(c=u.value).name)return a.message.error(t("All steps must have a name")),[2];if(!c.endpointId)return a.message.error("".concat(t("Step"),' "').concat(c.name||c.stepOrder,'" ').concat(t("must have an endpoint"))),[2]}}catch(e){l=!0,o=e}finally{try{r||null==i.return||i.return()}finally{if(l)throw o}}if(new Set(s=F.map(function(e){return e.outputAlias}).filter(Boolean)).size!==s.length)return a.message.error(t("Step output aliases must be unique")),[2];if(m=D(R({},n),{steps:F.map(function(e){return D(R({},e.id?{id:e.id}:{}),{stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||void 0,condition:e.condition,onError:e.onError,retryCount:"retry"===e.onError?e.retryCount:0})})}),!O)return[3,3];return[4,e.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:O},data:m})];case 2:return d.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createPipeline",method:"POST",data:m})];case 4:d.sent(),d.label=5;case 5:return a.message.success(t("Saved")),S(!1),es(),[3,7];case 6:return d.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return S(!1)},okText:t("Save"),cancelText:t("Cancel"),width:800,destroyOnClose:!0},l().createElement(a.Form,{form:w,layout:"vertical",preserve:!1},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"name",label:t("Pipeline Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"full_document_processing"})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(_,{rows:2,placeholder:t("What this pipeline does")})),l().createElement(a.Card,{title:t("Pipeline Steps"),size:"small",style:{marginBottom:16},extra:l().createElement(a.Tag,{color:"blue"},F.length," ",t("step(s)"))},l().createElement(Q,{steps:F,endpoints:f,onChange:C})),l().createElement(a.Collapse,{size:"small",ghost:!0},l().createElement(q,{header:t("Advanced: Input Schema & Output Mapping"),key:"advanced"},l().createElement(a.Form.Item,{name:"inputSchema",label:t("Input Schema (JSON Schema)"),help:t("Defines what input this pipeline accepts. Used by AI tool schema.")},l().createElement(G,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),l().createElement(a.Form.Item,{name:"outputMapping",label:t("Output Mapping (JSON)"),help:t("Map final step results to pipeline output. If empty, all step results are returned.")},l().createElement(G,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),l().createElement(a.Modal,{title:N?"".concat(t("Test Playground"),": ").concat(N.name):t("Test Playground"),open:P,onCancel:eh,width:860,destroyOnClose:!0,footer:[l().createElement(a.Button,{key:"close",onClick:eh},t("Close")),(null==er?void 0:er.id)&&l().createElement(a.Button,{key:"refresh",icon:l().createElement(c.ReloadOutlined,null),disabled:eo,onClick:function(){return ep(er.id)}},t("Refresh")),l().createElement(a.Button,{key:"run",type:"primary",icon:l().createElement(c.PlayCircleOutlined,null),loading:eo,onClick:function(){return B(function(){var n,r,l,o,i;return J(this,function(u){switch(u.label){case 0:if(!N)return[2];try{r=Y.trim()?JSON.parse(Y):{},n=L(K(N.inputSchema),r),et("")}catch(e){return et(t("Invalid JSON input")),[2]}ed(),ei(!0),el(null),u.label=1;case 1:return u.trys.push([1,4,,5]),[4,e.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:N.id,input:n}})];case 2:if(!(l=m(u.sent(),{}).jobId))throw Error(t("Pipeline did not return a job ID"));return[4,ep(l)];case 3:return(o=u.sent())&&H.includes(o.status)||ef(l),a.message.success("".concat(t("Test job started"),": #").concat(l)),[3,5];case 4:return i=u.sent(),ei(!1),a.message.error(d(i)||t("Failed to run pipeline test")),[3,5];case 5:return[2]}})})()}},t("Run test"))].filter(Boolean)},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},l().createElement("div",null,l().createElement("label",{htmlFor:"playground-input",style:{fontWeight:500,marginBottom:6,display:"block"}},t("Input JSON")),l().createElement(_,{id:"playground-input",rows:16,value:Y,onChange:function(e){X(e.target.value),ee&&et("")},placeholder:'{ "document_url": "https://..." }',status:ee?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),ee&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:ee,style:{marginTop:8}}),l().createElement(a.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},l().createElement(q,{header:t("Input Schema"),key:"schema"},l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},$(null==N?void 0:N.inputSchema))))),l().createElement("div",null,l().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},l().createElement("span",{style:{fontWeight:500}},t("Result")),(null==er?void 0:er.status)&&l().createElement(a.Tag,{color:V[er.status]||"default"},ec[er.status]||er.status)),er?l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:8},wrap:!0},l().createElement(a.Tag,null,t("Job")," #",er.id),er.currentStep&&l().createElement(a.Tag,null,t("Step")," ",er.currentStep)),er.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:t("Pipeline error"),description:l().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},er.error),style:{marginBottom:12}}),l().createElement("div",{style:{fontWeight:500,marginBottom:4}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==er.finalResult&&null!==er.finalResult?$(er.finalResult):t("(not yet available)")),l().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},t("Step Results")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},er.stepResults?$(er.stepResults):"{}")):l().createElement(a.Empty,{description:t("Run a test to see job output"),imageStyle:{height:48}})))))};function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function ee(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Z(a,r,l,o,i,"next",e)}function i(e){Z(a,r,l,o,i,"throw",e)}o(void 0)})}}function et(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return X(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function en(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var er={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},el=function(){var e=(0,o.useFlowContext)().api,t=u(),n=et((0,r.useState)([]),2),i=n[0],s=n[1],d=et((0,r.useState)([]),2),f=d[0],y=d[1],h=et((0,r.useState)(!1),2),b=h[0],g=h[1],E=et((0,r.useState)(!1),2),v=E[0],S=E[1],w=et((0,r.useState)(null),2),I=w[0],O=w[1],k=et((0,r.useState)(void 0),2),T=k[0],F=k[1],C=et((0,r.useState)(void 0),2),x=C[0],P=C[1],A={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},j=(0,r.useCallback)(function(){return ee(function(){var t;return en(this,function(n){switch(n.label){case 0:g(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},T&&(t.status=T),x&&(t.pipelineId=x),[4,e.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s(m(n.sent(),[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e,T,x]),B=(0,r.useCallback)(function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:listPipelines"})];case 1:return y(m(t.sent(),[])),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})})()},[e]);(0,r.useEffect)(function(){B()},[B]),(0,r.useEffect)(function(){j();var e=setInterval(j,1e4);return function(){return clearInterval(e)}},[j]);var N=new Map(f.map(function(e){return[e.id,e.name]})),R=[{title:t("ID"),dataIndex:"id",width:60},{title:t("Pipeline"),dataIndex:"pipelineId",width:180,render:function(e){return N.get(e)||"#".concat(e)}},{title:t("Status"),dataIndex:"status",width:100,render:function(e){return l().createElement(a.Tag,{color:er[e]||"default"},A[e]||e)}},{title:t("Current Step"),dataIndex:"currentStep",width:90,render:function(e,n){return"completed"===n.status?l().createElement(a.Tag,{color:"success"},t("Done")):"failed"===n.status?l().createElement(a.Tag,{color:"error"},"".concat(t("Step")," ").concat(e)):l().createElement(a.Badge,{status:"processing",text:"".concat(t("Step")," ").concat(e)})}},{title:t("Started"),dataIndex:"startedAt",width:160,render:function(e){return p(e)}},{title:t("Completed"),dataIndex:"completedAt",width:160,render:function(e){return p(e)}},{title:t("Action"),width:80,render:function(n,r){return l().createElement(a.Button,{size:"small",icon:l().createElement(c.EyeOutlined,null),onClick:function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:r.id}})];case 1:return O(m(t.sent(),r)),[3,3];case 2:return t.sent(),O(r),[3,3];case 3:return S(!0),[2]}})})()},"aria-label":"".concat(t("View")," #").concat(r.id)},t("View"))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by status"),"aria-label":t("Filter by status"),value:T,onChange:F,style:{width:160},options:Object.keys(er).map(function(e){return{value:e,label:A[e]}})}),l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by pipeline"),"aria-label":t("Filter by pipeline"),value:x,onChange:P,style:{width:200},options:f.map(function(e){return{value:e.id,label:e.name}})}),l().createElement(a.Button,{icon:l().createElement(c.ReloadOutlined,null),onClick:j},t("Refresh"))),l().createElement(a.Table,{rowKey:"id",columns:R,dataSource:i,loading:b,size:"small",pagination:{pageSize:20}}),l().createElement(a.Drawer,{title:I?"".concat(t("Job")," #").concat(I.id," — ").concat(N.get(I.pipelineId)||t("Unknown")):t("Job Details"),width:640,open:v,onClose:function(){return S(!1)}},I&&l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Space,{wrap:!0},l().createElement(a.Tag,{color:er[I.status]||"default"},A[I.status]||I.status),I.startedAt&&l().createElement("span",null,t("Started"),": ",p(I.startedAt)),I.completedAt&&l().createElement("span",null,t("Completed"),": ",p(I.completedAt)))),I.error&&l().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},l().createElement("strong",{style:{color:"#cf1322"}},t("Error"),":"),l().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},I.error)),l().createElement("h4",null,t("Input")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(I.input,null,2)),l().createElement("h4",{style:{marginTop:16}},t("Step Results")),I.stepResults&&Object.keys(I.stepResults).length>0?Object.entries(I.stepResults).map(function(e){var t=et(e,2),n=t[0],r=t[1];return l().createElement("div",{key:n,style:{marginBottom:8}},l().createElement(a.Tag,{color:"blue"},n),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(r,null,2)))}):l().createElement("div",{style:{color:"#999"}},t("No step results yet")),l().createElement("h4",{style:{marginTop:16}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},I.finalResult?JSON.stringify(I.finalResult,null,2):t("(not yet available)")),I.externalTaskIds&&Object.keys(I.externalTaskIds).length>0&&l().createElement(l().Fragment,null,l().createElement("h4",{style:{marginTop:16}},t("External Task IDs")),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(I.externalTaskIds,null,2))))))},ea=function(){var e=u();return l().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:"100vh"}},l().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},l().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},e("Document Understanding - Pipeline Orchestrator"))),l().createElement("div",{style:{padding:"0 24px 24px"}},l().createElement(a.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:e("Service Config"),children:l().createElement(E,null)},{key:"endpoints",label:e("Endpoints"),children:l().createElement(P,null)},{key:"pipelines",label:e("Pipelines"),children:l().createElement(Y,null)},{key:"jobs",label:e("Jobs history"),children:l().createElement(el,null)}]})))},eo=ea}}]);
10
+ "use strict";(self.webpackChunkplugin_document_understanding_client_v2=self.webpackChunkplugin_document_understanding_client_v2||[]).push([["345"],{824:function(e,t,n){n.r(t),n.d(t,{PluginSettings:function(){return ea},default:function(){return eo}});var r=n(155),l=n.n(r),a=n(59),o=n(694),i=JSON.parse('{"UU":"plugin-document-understanding"}');function u(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[i.UU,"client"]})}}var c=n(375);function s(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e,t){var n,r;return e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"?null!=(n=null==(r=e.data)?void 0:r.data)?n:t:t}function d(e){return s(e,Error)?e.message:String(e)}function p(e){if(!e)return"-";var t=s(e,Date)?e:new Date(e);return Number.isNaN(t.getTime())?"-":t.toLocaleString()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=function(){var e=b(a.Form.useForm(),1)[0],t=(0,o.useFlowContext)().api,n=u(),i=b((0,r.useState)(!0),2),s=i[0],p=i[1],f=b((0,r.useState)(!1),2),y=f[0],E=f[1],v=b((0,r.useState)(),2),S=v[0],w=v[1];return((0,r.useEffect)(function(){var n=!1;return h(function(){var r,l;return g(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,3,4]),[4,t.request({url:"docUnderstanding:getConfig"})];case 1:if(r=a.sent(),n)return[2];return e.setFieldsValue(m(r,{})),[3,4];case 2:return l=a.sent(),n||w(d(l)),[3,4];case 3:return n||p(!1),[7];case 4:return[2]}})})(),function(){n=!0}},[t,e]),s)?l().createElement(a.Spin,{style:{marginTop:40}}):l().createElement(a.Form,{form:e,layout:"vertical",onFinish:function(e){return h(function(){var r;return g(this,function(l){switch(l.label){case 0:E(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,t.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return l.sent(),a.message.success(n("Configuration saved successfully")),[3,5];case 3:return r=l.sent(),a.message.error("".concat(n("Failed to save config"),": ").concat(d(r))),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})()},style:{maxWidth:600}},S&&l().createElement(a.Alert,{message:S,type:"error",showIcon:!0,style:{marginBottom:16}}),l().createElement(a.Alert,{message:n("Service Connection"),description:n("Configure the connection to your external document processing service"),type:"info",showIcon:!0,style:{marginBottom:24}}),l().createElement(a.Form.Item,{name:"baseUrl",label:n("Base URL"),rules:[{required:!0,message:n("Base URL is required")}],help:n("The root URL of your document processing API")},l().createElement(a.Input,{prefix:l().createElement(c.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),l().createElement(a.Form.Item,{name:"authType",label:n("Authentication Type"),initialValue:"none"},l().createElement(a.Select,{options:[{value:"none",label:n("None")},{value:"api_key",label:n("API Key")},{value:"bearer",label:n("Bearer Token")},{value:"custom_header",label:n("Custom Header")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var t=e.getFieldValue("authType");return"none"===t?null:l().createElement(l().Fragment,null,"custom_header"===t&&l().createElement(a.Form.Item,{name:"authHeaderName",label:n("Custom Header Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"X-Api-Key"})),l().createElement(a.Form.Item,{name:"authKey",label:"bearer"===t?n("Bearer Token"):n("API Key"),rules:[{required:!0}]},l().createElement(a.Input.Password,{placeholder:n("Enter key or token")})))}),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"defaultTimeout",label:n("Request Timeout (ms)"),initialValue:3e4},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"defaultRetries",label:n("Default Retries"),initialValue:2},l().createElement(a.InputNumber,{style:{width:"100%"},min:0,max:10})),l().createElement(a.Form.Item,{name:"pollInterval",label:n("Poll Interval (ms)"),initialValue:5e3},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"pollTimeout",label:n("Poll Timeout (ms)"),initialValue:3e5},l().createElement(a.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),l().createElement(a.Form.Item,{name:"webhookSecret",label:n("Webhook Secret"),help:n("Used to verify HMAC-SHA256 signatures on incoming webhook callbacks")},l().createElement(a.Input.Password,{placeholder:n("Optional: secret for webhook signature verification")})),l().createElement(a.Form.Item,null,l().createElement(a.Button,{type:"primary",htmlType:"submit",icon:l().createElement(c.SaveOutlined,null),loading:y},n("Save Configuration"))))};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function S(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){S(a,r,l,o,i,"next",e)}function i(e){S(a,r,l,o,i,"throw",e)}o(void 0)})}}function I(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||k(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function O(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||k(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}function T(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var F=a.Input.TextArea,C=function(e){var t=e.value,n=e.onChange,o=u(),i=I((0,r.useState)([]),2),s=i[0],m=i[1],d=(0,r.useRef)(),p=JSON.stringify(null!=t?t:{});(0,r.useEffect)(function(){d.current!==p&&(d.current=p,m(Object.entries(JSON.parse(p)).map(function(e,t){var n=I(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}})))},[p]);var f=function(e){m(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=JSON.stringify(t),null==n||n(t)},y=function(e,t,n){var r,l,a=O(s);a[e]=(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},a[e]),l=l={key:t,value:n},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(l)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),f(a)},h=function(e){f(s.filter(function(t,n){return n!==e}))};return l().createElement("div",null,s.map(function(e,t){return l().createElement(a.Space,{key:e.id,style:{display:"flex",marginBottom:4}},l().createElement(a.Input,{placeholder:o("Header name"),"aria-label":o("Header name"),value:e.key,onChange:function(n){return y(t,n.target.value,e.value)},style:{width:180}}),l().createElement(a.Input,{placeholder:o("Value"),"aria-label":o("Value"),value:e.value,onChange:function(n){return y(t,e.key,n.target.value)},style:{width:220}}),l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),onClick:function(){return h(t)},"aria-label":"".concat(o("Delete")," ").concat(e.key||o("Header name"))}))}),l().createElement(a.Button,{size:"small",type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:function(){return m(O(s).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},o("Add Header")))},x=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=u(),i=I((0,r.useState)(""),2),c=i[0],s=i[1],m=I((0,r.useState)(""),2),d=m[0],p=m[1];return(0,r.useEffect)(function(){if(!t)return void s("");try{s("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){s("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(F,{rows:6,value:c,onChange:function(e){return s(e.target.value)},onBlur:function(){if(!c.trim()){p(""),null==n||n(null);return}try{var e=JSON.parse(c);p(""),null==n||n(e)}catch(e){p(o("Invalid JSON"))}},placeholder:a||"{}",status:d?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),d&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},d))},P=function(){var e=(0,o.useFlowContext)().api,t=u(),n=I((0,r.useState)([]),2),i=n[0],s=n[1],d=I((0,r.useState)(!1),2),p=d[0],f=d[1],y=I((0,r.useState)(!1),2),h=y[0],b=y[1],g=I(a.Form.useForm(),1)[0],E=I((0,r.useState)(null),2),v=E[0],S=E[1],O={sync:t("Synchronous"),polling:t("Polling"),webhook:t("Webhook")},k={multipart:t("Multipart Upload"),base64:t("Base64 in JSON")},P=(0,r.useCallback)(function(){return w(function(){return T(this,function(t){switch(t.label){case 0:f(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,e.request({url:"docUnderstanding:listEndpoints"})];case 2:return s(m(t.sent(),[])),[3,4];case 3:return f(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){P()},[P]);var A=function(e){S(e.id),g.setFieldsValue(e),b(!0)},j=[{title:t("Name"),dataIndex:"name",width:150},{title:t("Subpath"),dataIndex:"subpath",width:200},{title:t("Method"),dataIndex:"method",width:80,render:function(e){return l().createElement(a.Tag,null,e)}},{title:t("Execution"),dataIndex:"executionMode",width:130,render:function(e){return l().createElement(a.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},O[e]||e)}},{title:t("File"),dataIndex:"fileInputMode",width:130,render:function(e){return"none"===e?"-":k[e]||e}},{title:t("Enabled"),dataIndex:"enabled",width:70,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("Action"),width:120,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return A(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this endpoint?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,w(function(){return T(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),P(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){S(null),g.resetFields(),b(!0)}},t("Add Endpoint"))),l().createElement(a.Table,{rowKey:"id",columns:j,dataSource:i,loading:p,size:"small"}),l().createElement(a.Modal,{title:v?t("Edit Endpoint"):t("Add Endpoint"),open:h,onOk:function(){return w(function(){var n;return T(this,function(r){switch(r.label){case 0:return r.trys.push([0,6,,7]),[4,g.validateFields()];case 1:if((n=r.sent()).customHeaders=Object.entries(n.customHeaders||{}).reduce(function(e,t){var n=I(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{}),!v)return[3,3];return[4,e.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:v},data:n})];case 2:return r.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createEndpoint",method:"POST",data:n})];case 4:r.sent(),r.label=5;case 5:return a.message.success(t("Saved")),b(!1),P(),[3,7];case 6:return r.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return b(!1)},okText:t("Save"),cancelText:t("Cancel"),width:680,destroyOnClose:!0},l().createElement(a.Form,{form:g,layout:"vertical",preserve:!1},l().createElement(a.Tabs,{size:"small",items:[{key:"basic",label:t("Basic"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"name",label:t("Unique Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"ocr, classify, extract..."})),l().createElement(a.Form.Item,{name:"subpath",label:t("Subpath"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"/api/v1/ocr"})),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(F,{rows:2,placeholder:t("What this endpoint does")})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"method",label:t("HTTP Method"),initialValue:"POST"},l().createElement(a.Select,{style:{width:120},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"}]})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))))},{key:"file",label:t("File Input"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileInputMode",label:t("File Input Mode"),initialValue:"none"},l().createElement(a.Select,{style:{width:200},options:[{value:"none",label:t("None")},{value:"multipart",label:t("Multipart Upload")},{value:"base64",label:t("Base64 in JSON")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==g.getFieldValue("fileInputMode")?l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileFieldName",label:t("File Field Name"),initialValue:"file"},l().createElement(a.Input,{placeholder:"file",style:{width:200}})),l().createElement(a.Form.Item,{name:"maxFiles",label:t("Max Files"),initialValue:1},l().createElement(a.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"gateway",label:t("Gateway / Discriminator"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"discriminatorField",label:t("Discriminator Field"),help:t("Form field that selects the API sub-case (e.g. mode/type/task/action/process). Sent automatically.")},l().createElement(a.Input,{placeholder:"mode",style:{width:200}})),l().createElement(a.Form.Item,{name:"discriminatorValue",label:t("Discriminator Value"),help:t("Value sent in the discriminator field (e.g. parse, invoice, disbursement).")},l().createElement(a.Input,{placeholder:"parse",style:{width:200}})),l().createElement(a.Form.Item,{name:"syncQueryParam",label:t("Sync Query Param"),help:t("When set, the request appends ?<param>=true to ask for a synchronous response (e.g. sync).")},l().createElement(a.Input,{placeholder:"sync",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractPath",label:t("Task ID Extract Path"),help:t("JSON path of the async task id in the 202 response (e.g. name). Used when the response is 202 even in sync mode.")},l().createElement(a.Input,{placeholder:"name",style:{width:200}})),l().createElement(a.Form.Item,{name:"taskIdExtractRegex",label:t("Task ID Extract Regex"),help:t("Regex with one capture group to pull the task id from the extracted path value (e.g. operations/([^/]+)).")},l().createElement(a.Input,{placeholder:"operations/([^/]+)",style:{width:240}})))},{key:"async",label:t("Async Config"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"executionMode",label:t("Execution Mode"),initialValue:"sync"},l().createElement(a.Select,{style:{width:200},options:[{value:"sync",label:t("Synchronous")},{value:"polling",label:t("Polling")},{value:"webhook",label:t("Webhook")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=g.getFieldValue("executionMode");return"sync"===e?null:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollTaskIdField",label:t("Task ID Field"),help:t("Field in response containing the async task ID"),initialValue:"task_id"},l().createElement(a.Input,{placeholder:"task_id"})),"polling"===e&&l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollResultSubpath",label:t("Poll Result Subpath"),help:t("URL to poll for result. Use {taskId} as placeholder."),rules:[{required:!0,message:t("Required for polling mode")}]},l().createElement(a.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),l().createElement(a.Form.Item,{name:"pollResultField",label:t("Result Field"),help:t("Field in poll response containing the actual result")},l().createElement(a.Input,{placeholder:"result"})),l().createElement(a.Form.Item,{name:"pollStatusField",label:t("Status Field (optional)"),help:t("Field to check completion status. If empty, any non-null result = complete.")},l().createElement(a.Input,{placeholder:"status"})),l().createElement(a.Form.Item,{name:"pollCompletedValue",label:t("Completed Value"),help:t("Value of status field that means 'done'"),initialValue:"completed"},l().createElement(a.Input,{placeholder:"completed"})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"pollInterval",label:t("Poll Interval (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),l().createElement(a.Form.Item,{name:"pollTimeout",label:t("Poll Timeout (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:t("Schema"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"requestBodySchema",label:t("Request Body Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})),l().createElement(a.Form.Item,{name:"responseSchema",label:t("Response Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:t("Custom Headers"),children:l().createElement(a.Form.Item,{name:"customHeaders",label:t("Additional Headers")},l().createElement(C,null))}]}))))};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){j(a,r,l,o,i,"next",e)}function i(e){j(a,r,l,o,i,"throw",e)}o(void 0)})}}function N(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){N(e,t,n[t])})}return e}function D(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function M(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||z(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||z(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e,t){if(e){if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}}function J(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var _=a.Input.TextArea,q=a.Collapse.Panel,V={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},H=["completed","failed","timeout"],W=function(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)},$=function(e){return JSON.stringify(null!=e?e:{},null,2)},K=function(e){return W(e)?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=M(t,2),r=n[0],l=K(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},L=function(e,t){return W(e)&&W(t)?Object.entries(e).reduce(function(e,t){var n=M(t,2),r=n[0],l=n[1];return D(R({},e),N({},r,L(l,e[r])))},R({},t)):void 0===t?e:t},G=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=e.rows,i=u(),c=M((0,r.useState)(""),2),s=c[0],m=c[1],d=M((0,r.useState)(""),2),p=d[0],f=d[1];return(0,r.useEffect)(function(){if(!t)return void m("");try{m("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){m("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(_,{rows:void 0===o?5:o,value:s,onChange:function(e){return m(e.target.value)},onBlur:function(){if(!s.trim()){f(""),null==n||n(null);return}try{var e=JSON.parse(s);f(""),null==n||n(e)}catch(e){f(i("Invalid JSON"))}},placeholder:a||"{}",status:p?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),p&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},p))},Q=function(e){var t=e.steps,n=e.endpoints,r=e.onChange,o=u(),i=function(e,n){var l,a=U(t),o=e+n;o<0||o>=a.length||(l=[a[o],a[e]],a[e]=l[0],a[o]=l[1],a.forEach(function(e,t){return e.stepOrder=t+1}),r(a))},s=function(e,n,l){var a=U(t);a[e]=D(R({},a[e]),N({},n,l)),r(a)},m=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),r(n)},d=function(){var e;r(U(t).concat([(e=t.length+1,{_key:"new_".concat(Date.now(),"_").concat(Math.random()),stepOrder:e,name:"",endpointId:null,inputMapping:null,outputAlias:"",condition:null,onError:"fail",retryCount:0})]))};return 0===t.length?l().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},l().createElement(a.Empty,{description:o("No steps yet"),imageStyle:{height:40}}),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8}},o("Add First Step"))):l().createElement("div",null,l().createElement(a.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,r){var u=n.find(function(t){return t.id===e.endpointId}),d=l().createElement(a.Space,{size:4,onClick:function(e){return e.stopPropagation()}},l().createElement(a.Button,{size:"small",disabled:0===r,icon:l().createElement(c.ArrowUpOutlined,null),onClick:function(){return i(r,-1)},"aria-label":o("Move step up")}),l().createElement(a.Button,{size:"small",disabled:r===t.length-1,icon:l().createElement(c.ArrowDownOutlined,null),onClick:function(){return i(r,1)},"aria-label":o("Move step down")}),l().createElement(a.Popconfirm,{title:o("Remove step?"),okText:o("Delete"),onConfirm:function(){return m(r)}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":o("Remove step?")}))),p=l().createElement(a.Space,null,l().createElement(a.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),l().createElement("span",null,e.name||o("(unnamed)")),u&&l().createElement(a.Tag,null,u.name),"skip"===e.onError&&l().createElement(a.Tooltip,{title:o("Step can be skipped on error")},l().createElement(a.Tag,{color:"orange"},o("skip on error"))),e.condition&&l().createElement(a.Tooltip,{title:o("Has condition")},l().createElement(a.Tag,{color:"purple"},o("conditional")))),f="step-name-".concat(e._key),y="step-endpoint-".concat(e._key),h="step-alias-".concat(e._key);return l().createElement(q,{key:e._key,header:p,extra:d},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement("div",null,l().createElement("label",{htmlFor:f,style:{fontWeight:500,display:"block",marginBottom:4}},o("Step Name")," *"),l().createElement(a.Input,{id:f,value:e.name,onChange:function(e){return s(r,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),l().createElement("div",null,l().createElement("label",{htmlFor:y,style:{fontWeight:500,display:"block",marginBottom:4}},o("Endpoint")," *"),l().createElement(a.Select,{id:y,value:e.endpointId,onChange:function(e){return s(r,"endpointId",e)},placeholder:o("Select endpoint"),style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),l().createElement("div",null,l().createElement("label",{htmlFor:h,style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("Output Alias")),l().createElement(a.Input,{id:h,value:e.outputAlias,onChange:function(e){return s(r,"outputAlias",e.target.value)},placeholder:"ocr_result"}),l().createElement("div",{style:{color:"#888",fontSize:11}},o("Other steps reference this as"),": $step[",e.outputAlias||e.stepOrder,"].response.field")),l().createElement("div",null,l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("On Error")),l().createElement(a.Space,null,l().createElement(a.Select,{value:e.onError,onChange:function(e){return s(r,"onError",e)},style:{width:120},"aria-label":o("On Error"),options:[{value:"fail",label:o("Fail")},{value:"skip",label:o("Skip")},{value:"retry",label:o("Retry")}]}),"retry"===e.onError&&l().createElement(a.InputNumber,{value:e.retryCount,onChange:function(e){return s(r,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100},"aria-label":o("Retry")})))),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Input Mapping (JSON)"),l().createElement(a.Tooltip,{title:o("Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.inputMapping,onChange:function(e){return s(r,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Condition (optional JSON)"),l().createElement(a.Tooltip,{title:o("Only run this step if the condition matches.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.condition,onChange:function(e){return s(r,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8,width:"100%"}},o("Add Step")))},Y=function(){var e=(0,o.useFlowContext)().api,t=u(),n=M((0,r.useState)([]),2),i=n[0],s=n[1],p=M((0,r.useState)([]),2),f=p[0],y=p[1],h=M((0,r.useState)(!1),2),b=h[0],g=h[1],E=M((0,r.useState)(!1),2),v=E[0],S=E[1],w=M(a.Form.useForm(),1)[0],I=M((0,r.useState)(null),2),O=I[0],k=I[1],T=M((0,r.useState)([]),2),F=T[0],C=T[1],x=M((0,r.useState)(!1),2),P=x[0],A=x[1],j=M((0,r.useState)(null),2),N=j[0],z=j[1],W=M((0,r.useState)("{}"),2),Y=W[0],X=W[1],Z=M((0,r.useState)(""),2),ee=Z[0],et=Z[1],en=M((0,r.useState)(null),2),er=en[0],el=en[1],ea=M((0,r.useState)(!1),2),eo=ea[0],ei=ea[1],eu=(0,r.useRef)(null),ec={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},es=(0,r.useCallback)(function(){return B(function(){var t,n,r;return J(this,function(l){switch(l.label){case 0:g(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,Promise.all([e.request({url:"docUnderstanding:listPipelines"}),e.request({url:"docUnderstanding:listEndpoints"})])];case 2:return n=(t=M.apply(void 0,[l.sent(),2]))[0],r=t[1],s(m(n,[])),y(m(r,[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){es()},[es]),(0,r.useEffect)(function(){return function(){eu.current&&clearInterval(eu.current)}},[]);var em=function(e){k(e.id),w.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),C(U(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){var t;return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:null!=(t=e.inputMapping)?t:null,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),S(!0)},ed=(0,r.useCallback)(function(){eu.current&&(clearInterval(eu.current),eu.current=null)},[]),ep=(0,r.useCallback)(function(t){return B(function(){var n;return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:t}})];case 1:return el(n=m(r.sent(),null)),n&&H.includes(n.status)&&(ed(),ei(!1)),[2,n]}})})()},[e,ed]),ef=(0,r.useCallback)(function(e){ed(),eu.current=setInterval(function(){ep(e).catch(function(e){ed(),ei(!1),a.message.error(d(e)||t("Failed to refresh test job"))})},1500)},[ep,ed,t]),ey=function(e){ed(),z(e),el(null),ei(!1),et(""),X($(K(e.inputSchema))),A(!0)},eh=function(){ed(),A(!1),z(null),el(null),ei(!1)},eb=[{title:t("Name"),dataIndex:"name",width:200},{title:t("Steps"),dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return l().createElement(a.Tag,null,"0 ",t("steps"));var n=U(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return l().createElement(a.Space,{size:2,wrap:!0},n.map(function(e,n){return l().createElement(l().Fragment,{key:e.id},n>0&&l().createElement("span",{style:{color:"#ccc"}},"→"),l().createElement(a.Tag,null,e.name||"".concat(t("Step")," ").concat(e.stepOrder)))}))}},{title:t("Enabled"),dataIndex:"enabled",width:80,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("AI Tool"),width:100,render:function(e,n){var r;return n.enabled?l().createElement(a.Tooltip,{title:"".concat(t("Registered as"),": doc_understanding.").concat(null==(r=n.name)?void 0:r.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},l().createElement(a.Tag,{color:"blue",icon:l().createElement(c.ThunderboltOutlined,null)},t("Active"))):l().createElement(a.Tag,null,t("Inactive"))}},{title:t("Action"),width:190,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.PlayCircleOutlined,null),disabled:!r.enabled,onClick:function(){return ey(r)},"aria-label":"".concat(t("Test")," ").concat(r.name)},t("Test")),l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return em(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this pipeline?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,B(function(){return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),es(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){k(null),w.resetFields(),C([]),S(!0)}},t("Add Pipeline"))),l().createElement(a.Table,{rowKey:"id",columns:eb,dataSource:i,loading:b,size:"small"}),l().createElement(a.Modal,{title:O?t("Edit Pipeline"):t("New Pipeline"),open:v,onOk:function(){return B(function(){var n,r,l,o,i,u,c,s,m;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,6,,7]),[4,w.validateFields()];case 1:n=d.sent(),r=!0,l=!1,o=void 0;try{for(i=F[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){if(!(c=u.value).name)return a.message.error(t("All steps must have a name")),[2];if(!c.endpointId)return a.message.error("".concat(t("Step"),' "').concat(c.name||c.stepOrder,'" ').concat(t("must have an endpoint"))),[2]}}catch(e){l=!0,o=e}finally{try{r||null==i.return||i.return()}finally{if(l)throw o}}if(new Set(s=F.map(function(e){return e.outputAlias}).filter(Boolean)).size!==s.length)return a.message.error(t("Step output aliases must be unique")),[2];if(m=D(R({},n),{steps:F.map(function(e){return D(R({},e.id?{id:e.id}:{}),{stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||void 0,condition:e.condition,onError:e.onError,retryCount:"retry"===e.onError?e.retryCount:0})})}),!O)return[3,3];return[4,e.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:O},data:m})];case 2:return d.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createPipeline",method:"POST",data:m})];case 4:d.sent(),d.label=5;case 5:return a.message.success(t("Saved")),S(!1),es(),[3,7];case 6:return d.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return S(!1)},okText:t("Save"),cancelText:t("Cancel"),width:800,destroyOnClose:!0},l().createElement(a.Form,{form:w,layout:"vertical",preserve:!1},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"name",label:t("Pipeline Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"full_document_processing"})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(_,{rows:2,placeholder:t("What this pipeline does")})),l().createElement(a.Card,{title:t("Pipeline Steps"),size:"small",style:{marginBottom:16},extra:l().createElement(a.Tag,{color:"blue"},F.length," ",t("step(s)"))},l().createElement(Q,{steps:F,endpoints:f,onChange:C})),l().createElement(a.Collapse,{size:"small",ghost:!0},l().createElement(q,{header:t("Advanced: Input Schema & Output Mapping"),key:"advanced"},l().createElement(a.Form.Item,{name:"inputSchema",label:t("Input Schema (JSON Schema)"),help:t("Defines what input this pipeline accepts. Used by AI tool schema.")},l().createElement(G,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),l().createElement(a.Form.Item,{name:"outputMapping",label:t("Output Mapping (JSON)"),help:t("Map final step results to pipeline output. If empty, all step results are returned.")},l().createElement(G,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),l().createElement(a.Modal,{title:N?"".concat(t("Test Playground"),": ").concat(N.name):t("Test Playground"),open:P,onCancel:eh,width:860,destroyOnClose:!0,footer:[l().createElement(a.Button,{key:"close",onClick:eh},t("Close")),(null==er?void 0:er.id)&&l().createElement(a.Button,{key:"refresh",icon:l().createElement(c.ReloadOutlined,null),disabled:eo,onClick:function(){return ep(er.id)}},t("Refresh")),l().createElement(a.Button,{key:"run",type:"primary",icon:l().createElement(c.PlayCircleOutlined,null),loading:eo,onClick:function(){return B(function(){var n,r,l,o,i;return J(this,function(u){switch(u.label){case 0:if(!N)return[2];try{r=Y.trim()?JSON.parse(Y):{},n=L(K(N.inputSchema),r),et("")}catch(e){return et(t("Invalid JSON input")),[2]}ed(),ei(!0),el(null),u.label=1;case 1:return u.trys.push([1,4,,5]),[4,e.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:N.id,input:n}})];case 2:if(!(l=m(u.sent(),{}).jobId))throw Error(t("Pipeline did not return a job ID"));return[4,ep(l)];case 3:return(o=u.sent())&&H.includes(o.status)||ef(l),a.message.success("".concat(t("Test job started"),": #").concat(l)),[3,5];case 4:return i=u.sent(),ei(!1),a.message.error(d(i)||t("Failed to run pipeline test")),[3,5];case 5:return[2]}})})()}},t("Run test"))].filter(Boolean)},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},l().createElement("div",null,l().createElement("label",{htmlFor:"playground-input",style:{fontWeight:500,marginBottom:6,display:"block"}},t("Input JSON")),l().createElement(_,{id:"playground-input",rows:16,value:Y,onChange:function(e){X(e.target.value),ee&&et("")},placeholder:'{ "document_url": "https://..." }',status:ee?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),ee&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:ee,style:{marginTop:8}}),l().createElement(a.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},l().createElement(q,{header:t("Input Schema"),key:"schema"},l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},$(null==N?void 0:N.inputSchema))))),l().createElement("div",null,l().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},l().createElement("span",{style:{fontWeight:500}},t("Result")),(null==er?void 0:er.status)&&l().createElement(a.Tag,{color:V[er.status]||"default"},ec[er.status]||er.status)),er?l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:8},wrap:!0},l().createElement(a.Tag,null,t("Job")," #",er.id),er.currentStep&&l().createElement(a.Tag,null,t("Step")," ",er.currentStep)),er.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:t("Pipeline error"),description:l().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},er.error),style:{marginBottom:12}}),l().createElement("div",{style:{fontWeight:500,marginBottom:4}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==er.finalResult&&null!==er.finalResult?$(er.finalResult):t("(not yet available)")),l().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},t("Step Results")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},er.stepResults?$(er.stepResults):"{}")):l().createElement(a.Empty,{description:t("Run a test to see job output"),imageStyle:{height:48}})))))};function X(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function ee(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Z(a,r,l,o,i,"next",e)}function i(e){Z(a,r,l,o,i,"throw",e)}o(void 0)})}}function et(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return X(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return X(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function en(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var er={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},el=function(){var e=(0,o.useFlowContext)().api,t=u(),n=et((0,r.useState)([]),2),i=n[0],s=n[1],d=et((0,r.useState)([]),2),f=d[0],y=d[1],h=et((0,r.useState)(!1),2),b=h[0],g=h[1],E=et((0,r.useState)(!1),2),v=E[0],S=E[1],w=et((0,r.useState)(null),2),I=w[0],O=w[1],k=et((0,r.useState)(void 0),2),T=k[0],F=k[1],C=et((0,r.useState)(void 0),2),x=C[0],P=C[1],A={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},j=(0,r.useCallback)(function(){return ee(function(){var t;return en(this,function(n){switch(n.label){case 0:g(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},T&&(t.status=T),x&&(t.pipelineId=x),[4,e.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s(m(n.sent(),[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e,T,x]),B=(0,r.useCallback)(function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:listPipelines"})];case 1:return y(m(t.sent(),[])),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})})()},[e]);(0,r.useEffect)(function(){B()},[B]),(0,r.useEffect)(function(){j();var e=setInterval(j,1e4);return function(){return clearInterval(e)}},[j]);var N=new Map(f.map(function(e){return[e.id,e.name]})),R=[{title:t("ID"),dataIndex:"id",width:60},{title:t("Pipeline"),dataIndex:"pipelineId",width:180,render:function(e){return N.get(e)||"#".concat(e)}},{title:t("Status"),dataIndex:"status",width:100,render:function(e){return l().createElement(a.Tag,{color:er[e]||"default"},A[e]||e)}},{title:t("Current Step"),dataIndex:"currentStep",width:90,render:function(e,n){return"completed"===n.status?l().createElement(a.Tag,{color:"success"},t("Done")):"failed"===n.status?l().createElement(a.Tag,{color:"error"},"".concat(t("Step")," ").concat(e)):l().createElement(a.Badge,{status:"processing",text:"".concat(t("Step")," ").concat(e)})}},{title:t("Started"),dataIndex:"startedAt",width:160,render:function(e){return p(e)}},{title:t("Completed"),dataIndex:"completedAt",width:160,render:function(e){return p(e)}},{title:t("Action"),width:80,render:function(n,r){return l().createElement(a.Button,{size:"small",icon:l().createElement(c.EyeOutlined,null),onClick:function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:r.id}})];case 1:return O(m(t.sent(),r)),[3,3];case 2:return t.sent(),O(r),[3,3];case 3:return S(!0),[2]}})})()},"aria-label":"".concat(t("View")," #").concat(r.id)},t("View"))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by status"),"aria-label":t("Filter by status"),value:T,onChange:F,style:{width:160},options:Object.keys(er).map(function(e){return{value:e,label:A[e]}})}),l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by pipeline"),"aria-label":t("Filter by pipeline"),value:x,onChange:P,style:{width:200},options:f.map(function(e){return{value:e.id,label:e.name}})}),l().createElement(a.Button,{icon:l().createElement(c.ReloadOutlined,null),onClick:j},t("Refresh"))),l().createElement(a.Table,{rowKey:"id",columns:R,dataSource:i,loading:b,size:"small",pagination:{pageSize:20}}),l().createElement(a.Drawer,{title:I?"".concat(t("Job")," #").concat(I.id," — ").concat(N.get(I.pipelineId)||t("Unknown")):t("Job Details"),width:640,open:v,onClose:function(){return S(!1)}},I&&l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Space,{wrap:!0},l().createElement(a.Tag,{color:er[I.status]||"default"},A[I.status]||I.status),I.startedAt&&l().createElement("span",null,t("Started"),": ",p(I.startedAt)),I.completedAt&&l().createElement("span",null,t("Completed"),": ",p(I.completedAt)))),I.error&&l().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},l().createElement("strong",{style:{color:"#cf1322"}},t("Error"),":"),l().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},I.error)),l().createElement("h4",null,t("Input")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(I.input,null,2)),l().createElement("h4",{style:{marginTop:16}},t("Step Results")),I.stepResults&&Object.keys(I.stepResults).length>0?Object.entries(I.stepResults).map(function(e){var t=et(e,2),n=t[0],r=t[1];return l().createElement("div",{key:n,style:{marginBottom:8}},l().createElement(a.Tag,{color:"blue"},n),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(r,null,2)))}):l().createElement("div",{style:{color:"#999"}},t("No step results yet")),l().createElement("h4",{style:{marginTop:16}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},I.finalResult?JSON.stringify(I.finalResult,null,2):t("(not yet available)")),I.externalTaskIds&&Object.keys(I.externalTaskIds).length>0&&l().createElement(l().Fragment,null,l().createElement("h4",{style:{marginTop:16}},t("External Task IDs")),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(I.externalTaskIds,null,2))))))},ea=function(e){var t=e.embedded,n=void 0!==t&&t,r=u();return l().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:n?void 0:"100vh"}},!n&&l().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},l().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},r("Document Understanding - Pipeline Orchestrator"))),l().createElement("div",{style:{padding:n?0:"0 24px 24px"}},l().createElement(a.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:r("Service Config"),children:l().createElement(E,null)},{key:"endpoints",label:r("Endpoints"),children:l().createElement(P,null)},{key:"pipelines",label:r("Pipelines"),children:l().createElement(Y,null)},{key:"jobs",label:r("Jobs history"),children:l().createElement(el,null)}]})))},eo=ea}}]);
@@ -7,4 +7,4 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine")):"function"==typeof define&&define.amd?define("plugin-document-understanding/client-v2",["@nocobase/client-v2","react","antd","@ant-design/icons","@nocobase/flow-engine"],t):"object"==typeof exports?exports["plugin-document-understanding/client-v2"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine")):e["plugin-document-understanding/client-v2"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"])}(self,function(e,t,n,r,o){return function(){"use strict";var i,u,c,a={375:function(e){e.exports=r},485:function(t){t.exports=e},694:function(e){e.exports=o},59:function(e){e.exports=n},155:function(e){e.exports=t}},l={};function s(e){var t=l[e];if(void 0!==t)return t.exports;var n=l[e]={exports:{}};return a[e](n,n.exports,s),n.exports}s.m=a,s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,{a:t}),t},s.d=function(e,t){for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.f={},s.e=function(e){return Promise.all(Object.keys(s.f).reduce(function(t,n){return s.f[n](e,t),t},[]))},s.u=function(e){return""+e+".a8f28526ac21e02a.js"},s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},p={},s.l=function(e,t,n,r){if(p[e])return void p[e].push(t);if(void 0!==n)for(var o,i,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var a=u[c];if(a.getAttribute("src")==e||a.getAttribute("data-rspack")=="plugin-document-understanding/client-v2:"+n){o=a;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,s.nc&&o.setAttribute("nonce",s.nc),o.setAttribute("data-rspack","plugin-document-understanding/client-v2:"+n),o.src=e),p[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(f);var r=p[e];if(delete p[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},f=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},s.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.g.importScripts&&(f=s.g.location+"");var p,f,d=s.g.document;if(!f&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(f=d.currentScript.src),!f)){var b=d.getElementsByTagName("script");if(b.length)for(var g=b.length-1;g>-1&&(!f||!/^http(s?):/.test(f));)f=b[g--].src}if(!f)throw Error("Automatic publicPath is not supported in this browser");s.p=f.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={889:0},s.f.j=function(e,t){var n=s.o(i,e)?i[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=i[e]=[t,r]});t.push(n[2]=r);var o=s.p+s.u(e),u=Error();s.l(o,function(t){if(s.o(i,e)&&(0!==(n=i[e])&&(i[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;u.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",u.name="ChunkLoadError",u.type=r,u.request=o,n[1](u)}},"chunk-"+e,e)}},u=function(e,t){var n,r,o=t[0],u=t[1],c=t[2],a=0;if(o.some(function(e){return 0!==i[e]})){for(n in u)s.o(u,n)&&(s.m[n]=u[n]);c&&c(s)}for(e&&e(t);a<o.length;a++)r=o[a],s.o(i,r)&&i[r]&&i[r][0](),i[r]=0},(c=self.webpackChunkplugin_document_understanding_client_v2=self.webpackChunkplugin_document_understanding_client_v2||[]).forEach(u.bind(null,0)),c.push=u.bind(null,c.push.bind(c));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-document-understanding/dist/client-v2/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-document-understanding/dist/client-v2/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var u=window.location.pathname||"/",c=u.indexOf(i);e=c>=0?u.slice(0,c+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-document-understanding/dist/client-v2/"}s.p=e}(),!function(){s.r(v),s.d(v,{default:function(){return c}});var e=s(485);function t(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function n(e,t,r){return(n=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return n(e,arguments,r(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}var c=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,t;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return e=i,t=arguments,e=r(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,u()?Reflect.construct(e,t||[],r(this).constructor):e.apply(this,t))}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(u,"next",{value:a(0)}),c(u,"throw",{value:a(1)}),c(u,"return",{value:a(2)}),"function"==typeof Symbol&&c(u,Symbol.iterator,{value:function(){return this}}),u;function a(c){return function(a){var l=[c,a];if(n)throw TypeError("Generator is already executing.");for(;u&&(u=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.addMenuItem({key:"document-understanding",title:this.t("Document Understanding"),icon:"FileSearchOutlined",aclSnippet:"pm.".concat(this.options.name||"document-understanding")}),this.pluginSettingsManager.addPageTabItem({menuKey:"document-understanding",key:"index",title:this.t("Document Understanding"),componentLoader:function(){return s.e("345").then(s.bind(s,824))},aclSnippet:"pm.".concat(this.options.name||"document-understanding")}),[2]})},function(){var n=this,r=arguments;return new Promise(function(o,i){var u=e.apply(n,r);function c(e){t(u,o,i,c,a,"next",e)}function a(e){t(u,o,i,c,a,"throw",e)}c(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(i.prototype,n),i}(i(e.Plugin))}(),v}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine")):"function"==typeof define&&define.amd?define("plugin-document-understanding/client-v2",["@nocobase/client-v2","react","antd","@ant-design/icons","@nocobase/flow-engine"],t):"object"==typeof exports?exports["plugin-document-understanding/client-v2"]=t(require("@nocobase/client-v2"),require("react"),require("antd"),require("@ant-design/icons"),require("@nocobase/flow-engine")):e["plugin-document-understanding/client-v2"]=t(e["@nocobase/client-v2"],e.react,e.antd,e["@ant-design/icons"],e["@nocobase/flow-engine"])}(self,function(e,t,n,r,o){return function(){"use strict";var i,u,c,a={375:function(e){e.exports=r},485:function(t){t.exports=e},694:function(e){e.exports=o},59:function(e){e.exports=n},155:function(e){e.exports=t}},l={};function s(e){var t=l[e];if(void 0!==t)return t.exports;var n=l[e]={exports:{}};return a[e](n,n.exports,s),n.exports}s.m=a,s.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return s.d(t,{a:t}),t},s.d=function(e,t){for(var n in t)s.o(t,n)&&!s.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},s.f={},s.e=function(e){return Promise.all(Object.keys(s.f).reduce(function(t,n){return s.f[n](e,t),t},[]))},s.u=function(e){return""+e+".2fa9834b46dd4531.js"},s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},p={},s.l=function(e,t,n,r){if(p[e])return void p[e].push(t);if(void 0!==n)for(var o,i,u=document.getElementsByTagName("script"),c=0;c<u.length;c++){var a=u[c];if(a.getAttribute("src")==e||a.getAttribute("data-rspack")=="plugin-document-understanding/client-v2:"+n){o=a;break}}o||(i=!0,(o=document.createElement("script")).timeout=120,s.nc&&o.setAttribute("nonce",s.nc),o.setAttribute("data-rspack","plugin-document-understanding/client-v2:"+n),o.src=e),p[e]=[t];var l=function(t,n){o.onerror=o.onload=null,clearTimeout(f);var r=p[e];if(delete p[e],o.parentNode&&o.parentNode.removeChild(o),r&&r.forEach(function(e){return e(n)}),t)return t(n)},f=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),i&&document.head.appendChild(o)},s.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.g.importScripts&&(f=s.g.location+"");var p,f,d=s.g.document;if(!f&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(f=d.currentScript.src),!f)){var b=d.getElementsByTagName("script");if(b.length)for(var g=b.length-1;g>-1&&(!f||!/^http(s?):/.test(f));)f=b[g--].src}if(!f)throw Error("Automatic publicPath is not supported in this browser");s.p=f.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={889:0},s.f.j=function(e,t){var n=s.o(i,e)?i[e]:void 0;if(0!==n)if(n)t.push(n[2]);else{var r=new Promise(function(t,r){n=i[e]=[t,r]});t.push(n[2]=r);var o=s.p+s.u(e),u=Error();s.l(o,function(t){if(s.o(i,e)&&(0!==(n=i[e])&&(i[e]=void 0),n)){var r=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;u.message="Loading chunk "+e+" failed.\n("+r+": "+o+")",u.name="ChunkLoadError",u.type=r,u.request=o,n[1](u)}},"chunk-"+e,e)}},u=function(e,t){var n,r,o=t[0],u=t[1],c=t[2],a=0;if(o.some(function(e){return 0!==i[e]})){for(n in u)s.o(u,n)&&(s.m[n]=u[n]);c&&c(s)}for(e&&e(t);a<o.length;a++)r=o[a],s.o(i,r)&&i[r]&&i[r][0](),i[r]=0},(c=self.webpackChunkplugin_document_understanding_client_v2=self.webpackChunkplugin_document_understanding_client_v2||[]).forEach(u.bind(null,0)),c.push=u.bind(null,c.push.bind(c));var v={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var n=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");n.indexOf("/static/plugins/plugin-document-understanding/dist/client-v2/")>=0&&(e=n.replace(/\/[^\/]+$/,"/"))}if(!e){var r=window.__webpack_public_path__||"";r&&("/"!==r.charAt(r.length-1)&&(r+="/"),e=r+"static/plugins/plugin-document-understanding/dist/client-v2/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",i="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var u=window.location.pathname||"/",c=u.indexOf(i);e=c>=0?u.slice(0,c+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-document-understanding/dist/client-v2/"}s.p=e}(),!function(){s.r(v),s.d(v,{default:function(){return c}});var e=s(485);function t(e,t,n,r,o,i,u){try{var c=e[i](u),a=c.value}catch(e){n(e);return}c.done?t(a):Promise.resolve(a).then(r,o)}function n(e,t,r){return(n=u()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var i=new(Function.bind.apply(e,r));return n&&o(i,n.prototype),i}).apply(null,arguments)}function r(e){return(r=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,i)}function i(){return n(e,arguments,r(this).constructor)}return i.prototype=Object.create(e.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),o(i,e)})(e)}function u(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(u=function(){return!!e})()}var c=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,t;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return e=i,t=arguments,e=r(e),function(e,t){var n;if(t&&("object"==((n=t)&&"u">typeof Symbol&&n.constructor===Symbol?"symbol":typeof n)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,u()?Reflect.construct(e,t||[],r(this).constructor):e.apply(this,t))}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),n=[{key:"load",value:function(){var e;return(e=function(){return function(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},u=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(u,"next",{value:a(0)}),c(u,"throw",{value:a(1)}),c(u,"return",{value:a(2)}),"function"==typeof Symbol&&c(u,Symbol.iterator,{value:function(){return this}}),u;function a(c){return function(a){var l=[c,a];if(n)throw TypeError("Generator is already executing.");for(;u&&(u=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=(o=i.trys).length>0&&o[o.length-1])&&(6===l[0]||2===l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=t.call(e,i)}catch(e){l=[6,e],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}}}(this,function(e){return this.pluginSettingsManager.addMenuItem({key:"document-understanding",title:this.t("Document Understanding"),icon:"FileSearchOutlined",aclSnippet:"pm.".concat(this.options.name||"document-understanding")}),this.pluginSettingsManager.addPageTabItem({menuKey:"document-understanding",key:"index",title:this.t("Document Understanding"),componentLoader:function(){return s.e("345").then(s.bind(s,824))},aclSnippet:"pm.".concat(this.options.name||"document-understanding")}),[2]})},function(){var n=this,r=arguments;return new Promise(function(o,i){var u=e.apply(n,r);function c(e){t(u,o,i,c,a,"next",e)}function a(e){t(u,o,i,c,a,"throw",e)}c(void 0)})}).call(this)}}],function(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}(i.prototype,n),i}(i(e.Plugin))}(),v}()});
@@ -18,5 +18,5 @@ module.exports = {
18
18
  "@nocobase/server": "2.2.40",
19
19
  "antd": "5.24.2",
20
20
  "@ant-design/icons": "5.6.1",
21
- "axios": "1.21.0"
21
+ "axios": "1.21.1"
22
22
  };
@@ -1 +1 @@
1
- {"author":"Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)","name":"form-data","description":"A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.","version":"4.0.6","repository":{"type":"git","url":"git://github.com/form-data/form-data.git"},"main":"./lib/form_data","browser":"./lib/browser","typings":"./index.d.ts","scripts":{"pretest":"npm run lint","pretests-only":"rimraf coverage test/tmp","tests-only":"istanbul cover test/run.js","posttests-only":"istanbul report lcov text","test":"npm run tests-only","posttest":"npx npm@'>=10.2' audit --production","lint":"eslint --ext=js,mjs .","report":"istanbul report lcov text","ci-lint":"is-node-modern 8 && npm run lint || is-node-not-modern 8","ci-test":"npm run tests-only && npm run browser && npm run report","predebug":"rimraf coverage test/tmp","debug":"verbose=1 ./test/run.js","browser":"browserify -t browserify-istanbul test/run-browser.js | obake --coverage","check":"istanbul check-coverage coverage/coverage*.json","files":"pkgfiles --sort=name","get-version":"node -e \"console.log(require('./package.json').version)\"","update-readme":"sed -i.bak 's/\\/master\\.svg/\\/v'$(npm --silent run get-version)'.svg/g' README.md","postupdate-readme":"mv README.md.bak READ.ME.md.bak","restore-readme":"mv READ.ME.md.bak README.md","prepublish":"not-in-publish || npm run prepublishOnly","prepack":"npm run update-readme","postpack":"npm run restore-readme","version":"auto-changelog && git add CHANGELOG.md","postversion":"auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""},"engines":{"node":">= 6"},"dependencies":{"asynckit":"^0.4.0","combined-stream":"^1.0.8","es-set-tostringtag":"^2.1.0","hasown":"^2.0.4","mime-types":"^2.1.35"},"devDependencies":{"@ljharb/eslint-config":"^22.2.3","auto-changelog":"^2.6.0","browserify":"^13.3.0","browserify-istanbul":"^2.0.0","coveralls":"^3.1.1","cross-spawn":"^6.0.6","eslint":"^8.57.1","fake":"^0.2.2","far":"^0.0.7","formidable":"^1.2.6","in-publish":"^2.0.1","is-node-modern":"^1.0.0","istanbul":"^0.4.5","js-randomness-predictor":"^3.6.0","obake":"^0.1.2","pkgfiles":"^2.3.2","pre-commit":"^1.2.2","puppeteer":"^1.20.0","request":"~2.87.0","rimraf":"^2.7.1","semver":"^6.3.1","tape":"^5.10.1"},"license":"MIT","auto-changelog":{"output":"CHANGELOG.md","template":"keepachangelog","unreleased":false,"commitLimit":false,"backfillLimit":false,"hideCredit":true},"_lastModified":"2026-11-06T16:17:09.075Z"}
1
+ {"author":"Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)","name":"form-data","description":"A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.","version":"4.0.6","repository":{"type":"git","url":"git://github.com/form-data/form-data.git"},"main":"./lib/form_data","browser":"./lib/browser","typings":"./index.d.ts","scripts":{"pretest":"npm run lint","pretests-only":"rimraf coverage test/tmp","tests-only":"istanbul cover test/run.js","posttests-only":"istanbul report lcov text","test":"npm run tests-only","posttest":"npx npm@'>=10.2' audit --production","lint":"eslint --ext=js,mjs .","report":"istanbul report lcov text","ci-lint":"is-node-modern 8 && npm run lint || is-node-not-modern 8","ci-test":"npm run tests-only && npm run browser && npm run report","predebug":"rimraf coverage test/tmp","debug":"verbose=1 ./test/run.js","browser":"browserify -t browserify-istanbul test/run-browser.js | obake --coverage","check":"istanbul check-coverage coverage/coverage*.json","files":"pkgfiles --sort=name","get-version":"node -e \"console.log(require('./package.json').version)\"","update-readme":"sed -i.bak 's/\\/master\\.svg/\\/v'$(npm --silent run get-version)'.svg/g' README.md","postupdate-readme":"mv README.md.bak READ.ME.md.bak","restore-readme":"mv READ.ME.md.bak README.md","prepublish":"not-in-publish || npm run prepublishOnly","prepack":"npm run update-readme","postpack":"npm run restore-readme","version":"auto-changelog && git add CHANGELOG.md","postversion":"auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""},"engines":{"node":">= 6"},"dependencies":{"asynckit":"^0.4.0","combined-stream":"^1.0.8","es-set-tostringtag":"^2.1.0","hasown":"^2.0.4","mime-types":"^2.1.35"},"devDependencies":{"@ljharb/eslint-config":"^22.2.3","auto-changelog":"^2.6.0","browserify":"^13.3.0","browserify-istanbul":"^2.0.0","coveralls":"^3.1.1","cross-spawn":"^6.0.6","eslint":"^8.57.1","fake":"^0.2.2","far":"^0.0.7","formidable":"^1.2.6","in-publish":"^2.0.1","is-node-modern":"^1.0.0","istanbul":"^0.4.5","js-randomness-predictor":"^3.6.0","obake":"^0.1.2","pkgfiles":"^2.3.2","pre-commit":"^1.2.2","puppeteer":"^1.20.0","request":"~2.87.0","rimraf":"^2.7.1","semver":"^6.3.1","tape":"^5.10.1"},"license":"MIT","auto-changelog":{"output":"CHANGELOG.md","template":"keepachangelog","unreleased":false,"commitLimit":false,"backfillLimit":false,"hideCredit":true},"_lastModified":"2026-11-14T07:21:41.021Z"}
@@ -1 +1 @@
1
- {"name":"mime-types","description":"The ultimate javascript content-type utility.","version":"2.1.35","contributors":["Douglas Christopher Wilson <doug@somethingdoug.com>","Jeremiah Senkpiel <fishrock123@rocketmail.com> (https://searchbeam.jit.su)","Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"],"license":"MIT","keywords":["mime","types"],"repository":"jshttp/mime-types","dependencies":{"mime-db":"1.52.0"},"devDependencies":{"eslint":"7.32.0","eslint-config-standard":"14.1.1","eslint-plugin-import":"2.25.4","eslint-plugin-markdown":"2.2.1","eslint-plugin-node":"11.1.0","eslint-plugin-promise":"5.2.0","eslint-plugin-standard":"4.1.0","mocha":"9.2.2","nyc":"15.1.0"},"files":["HISTORY.md","LICENSE","index.js"],"engines":{"node":">= 0.6"},"scripts":{"lint":"eslint .","test":"mocha --reporter spec test/test.js","test-ci":"nyc --reporter=lcov --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test"},"_lastModified":"2026-11-06T16:17:09.347Z"}
1
+ {"name":"mime-types","description":"The ultimate javascript content-type utility.","version":"2.1.35","contributors":["Douglas Christopher Wilson <doug@somethingdoug.com>","Jeremiah Senkpiel <fishrock123@rocketmail.com> (https://searchbeam.jit.su)","Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"],"license":"MIT","keywords":["mime","types"],"repository":"jshttp/mime-types","dependencies":{"mime-db":"1.52.0"},"devDependencies":{"eslint":"7.32.0","eslint-config-standard":"14.1.1","eslint-plugin-import":"2.25.4","eslint-plugin-markdown":"2.2.1","eslint-plugin-node":"11.1.0","eslint-plugin-promise":"5.2.0","eslint-plugin-standard":"4.1.0","mocha":"9.2.2","nyc":"15.1.0"},"files":["HISTORY.md","LICENSE","index.js"],"engines":{"node":">= 0.6"},"scripts":{"lint":"eslint .","test":"mocha --reporter spec test/test.js","test-ci":"nyc --reporter=lcov --reporter=text npm test","test-cov":"nyc --reporter=html --reporter=text npm test"},"_lastModified":"2026-11-14T07:21:41.279Z"}
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "displayName": "Document Understanding",
4
4
  "displayName.zh-CN": "文档理解",
5
5
  "description": "Configure external document processing endpoints, chain them into pipelines, and expose enabled pipelines as AI tools.",
6
- "version": "1.1.15",
6
+ "version": "1.1.16",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/server/index.js",
9
9
  "files": [
@@ -49,7 +49,7 @@
49
49
  "url": "git+https://github.com/OrgGem/nocobase-beta.git",
50
50
  "directory": "packages/plugins/plugin-document-understanding"
51
51
  },
52
- "gitHead": "e2f4c65d6ef8dcdbd0008b859588220545786b67",
52
+ "gitHead": "17ea36f39a1627b876d55e11a4bb032a6b17e748",
53
53
  "publishConfig": {
54
54
  "access": "public",
55
55
  "registry": "https://registry.npmjs.org/"
@@ -1,3 +1,5 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
1
3
  import React from 'react';
2
4
  import { Tabs } from 'antd';
3
5
  import { useT } from '../locale';
@@ -6,17 +8,19 @@ import { EndpointsTab } from './EndpointsTab';
6
8
  import { PipelinesTab } from './PipelinesTab';
7
9
  import { JobsTab } from './JobsTab';
8
10
 
9
- export const PluginSettings = () => {
11
+ export const PluginSettings = ({ embedded = false }: { embedded?: boolean }) => {
10
12
  const t = useT();
11
13
 
12
14
  return (
13
- <div style={{ backgroundColor: 'var(--nb-box-bg)', minHeight: '100vh' }}>
14
- <div style={{ padding: '16px 24px', backgroundColor: '#fff', borderBottom: '1px solid #f0f0f0' }}>
15
- <h2 style={{ margin: 0, fontSize: 20, fontWeight: 500 }}>
16
- {t('Document Understanding - Pipeline Orchestrator')}
17
- </h2>
18
- </div>
19
- <div style={{ padding: '0 24px 24px' }}>
15
+ <div style={{ backgroundColor: 'var(--nb-box-bg)', minHeight: embedded ? undefined : '100vh' }}>
16
+ {!embedded && (
17
+ <div style={{ padding: '16px 24px', backgroundColor: '#fff', borderBottom: '1px solid #f0f0f0' }}>
18
+ <h2 style={{ margin: 0, fontSize: 20, fontWeight: 500 }}>
19
+ {t('Document Understanding - Pipeline Orchestrator')}
20
+ </h2>
21
+ </div>
22
+ )}
23
+ <div style={{ padding: embedded ? 0 : '0 24px 24px' }}>
20
24
  <Tabs
21
25
  defaultActiveKey="config"
22
26
  items={[
@@ -0,0 +1,39 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ import React from 'react';
4
+ import { render, screen } from '@testing-library/react';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ import { PluginSettings } from '../PluginSettings';
7
+
8
+ vi.mock('../../locale', () => ({ useT: () => (key: string) => key }));
9
+ vi.mock('../ServiceConfigTab', () => ({ ServiceConfigTab: () => <div>Service configuration content</div> }));
10
+ vi.mock('../EndpointsTab', () => ({ EndpointsTab: () => <div>Endpoint content</div> }));
11
+ vi.mock('../PipelinesTab', () => ({ PipelinesTab: () => <div>Pipeline content</div> }));
12
+ vi.mock('../JobsTab', () => ({ JobsTab: () => <div>Job content</div> }));
13
+
14
+ describe('Document Understanding plugin settings layout', () => {
15
+ it('omits the standalone page heading and full-page height when embedded while keeping the settings tabs', () => {
16
+ const view = render(<PluginSettings embedded />);
17
+ const root = view.container.firstElementChild as HTMLElement;
18
+ const content = root.firstElementChild as HTMLElement;
19
+
20
+ expect(screen.queryByRole('heading', { name: 'Document Understanding - Pipeline Orchestrator' })).toBeNull();
21
+ expect(root.style.minHeight).toBe('');
22
+ expect(content.style.padding).toBe('0px');
23
+ expect(screen.getByRole('tab', { name: 'Service Config' })).toBeTruthy();
24
+ expect(screen.getByRole('tab', { name: 'Endpoints' })).toBeTruthy();
25
+ expect(screen.getByRole('tab', { name: 'Pipelines' })).toBeTruthy();
26
+ expect(screen.getByRole('tab', { name: 'Jobs history' })).toBeTruthy();
27
+ });
28
+
29
+ it('keeps the heading, full-page height, and padding in standalone settings', () => {
30
+ const view = render(<PluginSettings />);
31
+ const root = view.container.firstElementChild as HTMLElement;
32
+ const headingWrapper = root.firstElementChild as HTMLElement;
33
+ const content = headingWrapper.nextElementSibling as HTMLElement;
34
+
35
+ expect(screen.getByRole('heading', { name: 'Document Understanding - Pipeline Orchestrator' })).toBeTruthy();
36
+ expect(root.style.minHeight).toBe('100vh');
37
+ expect(content.style.padding).toBe('0px 24px 24px');
38
+ });
39
+ });