plugin-document-understanding 1.1.1 → 1.1.3

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
- !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):"function"==typeof define&&define.amd?define("plugin-document-understanding",["react","@nocobase/client","@ant-design/icons","antd"],t):"object"==typeof exports?exports["plugin-document-understanding"]=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):e["plugin-document-understanding"]=t(e.react,e["@nocobase/client"],e["@ant-design/icons"],e.antd)}(self,function(e,t,n,r){return function(){"use strict";var l={482:function(e){e.exports=n},772:function(e){e.exports=t},721:function(e){e.exports=r},156:function(t){t.exports=e}},a={};function o(e){var t=a[e];if(void 0!==t)return t.exports;var n=a[e]={exports:{}};return l[e](n,n.exports,o),n.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return!function(){o.r(i),o.d(i,{default:function(){return el}});var e=o(772),t={},n=o(156),r=o.n(n),l=o(721),a=o(482);function u(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 c(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 s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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 u(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 u(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.")}()}var d=function(){var t,o,i=s(l.Form.useForm(),1)[0],u=(0,e.useAPIClient)(),d=s((0,n.useState)(!0),2),p=d[0],m=d[1],f=s((0,n.useState)(!1),2),y=f[0],h=f[1];(0,n.useEffect)(function(){u.request({url:"docUnderstanding:getConfig"}).then(function(e){var t=e.data;i.setFieldsValue((null==t?void 0:t.data)||{}),m(!1)}).catch(function(){return m(!1)})},[]);var b=(t=function(e){return function(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(t){switch(t.label){case 0:h(!0),t.label=1;case 1:return t.trys.push([1,3,4,5]),[4,u.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return t.sent(),l.message.success("Configuration saved successfully"),[3,5];case 3:return t.sent(),l.message.error("Failed to save config"),[3,5];case 4:return h(!1),[7];case 5:return[2]}})},o=function(){var e=this,n=arguments;return new Promise(function(r,l){var a=t.apply(e,n);function o(e){c(a,r,l,o,i,"next",e)}function i(e){c(a,r,l,o,i,"throw",e)}o(void 0)})},function(e){return o.apply(this,arguments)});return p?r().createElement(l.Spin,{style:{marginTop:40}}):r().createElement(l.Form,{form:i,layout:"vertical",onFinish:b,style:{maxWidth:600}},r().createElement(l.Alert,{message:"Service Connection",description:"Configure the connection to your external document processing service. All endpoints will use this base URL and authentication.",type:"info",showIcon:!0,style:{marginBottom:24}}),r().createElement(l.Form.Item,{name:"baseUrl",label:"Base URL",rules:[{required:!0,message:"Base URL is required"}],help:"The root URL of your document processing API"},r().createElement(l.Input,{prefix:r().createElement(a.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),r().createElement(l.Form.Item,{name:"authType",label:"Authentication Type",initialValue:"none"},r().createElement(l.Select,null,r().createElement(l.Select.Option,{value:"none"},"None"),r().createElement(l.Select.Option,{value:"api_key"},"API Key"),r().createElement(l.Select.Option,{value:"bearer"},"Bearer Token"),r().createElement(l.Select.Option,{value:"custom_header"},"Custom Header"))),r().createElement(l.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var e=i.getFieldValue("authType");return"none"===e?null:r().createElement(r().Fragment,null,"custom_header"===e&&r().createElement(l.Form.Item,{name:"authHeaderName",label:"Custom Header Name",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"X-Api-Key"})),r().createElement(l.Form.Item,{name:"authKey",label:"bearer"===e?"Bearer Token":"API Key",rules:[{required:!0}]},r().createElement(l.Input.Password,{placeholder:"Enter key or token"})))}),r().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},r().createElement(l.Form.Item,{name:"defaultTimeout",label:"Request Timeout (ms)",initialValue:3e4},r().createElement(l.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),r().createElement(l.Form.Item,{name:"defaultRetries",label:"Default Retries",initialValue:2},r().createElement(l.InputNumber,{style:{width:"100%"},min:0,max:10})),r().createElement(l.Form.Item,{name:"pollInterval",label:"Poll Interval (ms)",initialValue:5e3},r().createElement(l.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),r().createElement(l.Form.Item,{name:"pollTimeout",label:"Poll Timeout (ms)",initialValue:3e5},r().createElement(l.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),r().createElement(l.Form.Item,{name:"webhookSecret",label:"Webhook Secret",help:"Used to verify HMAC-SHA256 signatures on incoming webhook callbacks"},r().createElement(l.Input.Password,{placeholder:"Optional: secret for webhook signature verification"})),r().createElement(l.Form.Item,null,r().createElement(l.Button,{type:"primary",htmlType:"submit",icon:r().createElement(a.SaveOutlined,null),loading:y},"Save Configuration")))};function p(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 m(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 f(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){m(a,r,l,o,i,"next",e)}function i(e){m(a,r,l,o,i,"throw",e)}o(void 0)})}}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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)||b(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 h(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||b(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 b(e,t){if(e){if("string"==typeof e)return p(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 p(e,t)}}function g(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var v=l.Input.TextArea,E=function(e){var t=e.value,o=void 0===t?{}:t,i=e.onChange,u=y((0,n.useState)([]),2),c=u[0],s=u[1],d=(0,n.useRef)(!1);(0,n.useEffect)(function(){if(d.current){d.current=!1;return}s(Object.entries(o||{}).map(function(e,t){var n=y(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}}))},[o]);var p=function(e){s(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=!0,null==i||i(t)},m=function(e,t,n){var r,l,a=h(c);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,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),p(a)},f=function(e){p(c.filter(function(t,n){return n!==e}))};return r().createElement("div",null,c.map(function(e,t){return r().createElement(l.Space,{key:e.id,style:{display:"flex",marginBottom:4}},r().createElement(l.Input,{placeholder:"Header name",value:e.key,onChange:function(n){return m(t,n.target.value,e.value)},style:{width:180}}),r().createElement(l.Input,{placeholder:"Value",value:e.value,onChange:function(n){return m(t,e.key,n.target.value)},style:{width:220}}),r().createElement(l.Button,{size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null),onClick:function(){return f(t)}}))}),r().createElement(l.Button,{size:"small",type:"dashed",icon:r().createElement(a.PlusOutlined,null),onClick:function(){return s(h(c).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},"Add Header"))},S=function(e){var t=e.value,l=e.onChange,a=e.placeholder,o=y((0,n.useState)(""),2),i=o[0],u=o[1],c=y((0,n.useState)(""),2),s=c[0],d=c[1];return(0,n.useEffect)(function(){if(!t)return void u("");try{u("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){u("string"==typeof t?t:"")}},[t]),r().createElement("div",null,r().createElement(v,{rows:6,value:i,onChange:function(e){return u(e.target.value)},onBlur:function(){if(!i.trim()){d(""),null==l||l(null);return}try{var e=JSON.parse(i);d(""),null==l||l(e)}catch(e){d("Invalid JSON")}},placeholder:a||"{}",style:{fontFamily:"monospace",fontSize:12}}),s&&r().createElement("div",{style:{color:"#ff4d4f",fontSize:12}},s))},w=function(){var t,o,i=(0,e.useAPIClient)(),u=y((0,n.useState)([]),2),c=u[0],s=u[1],d=y((0,n.useState)(!1),2),p=d[0],m=d[1],h=y((0,n.useState)(!1),2),b=h[0],w=h[1],O=y(l.Form.useForm(),1)[0],I=y((0,n.useState)(null),2),k=I[0],T=I[1],x=(0,n.useCallback)(f(function(){var e;return g(this,function(t){switch(t.label){case 0:m(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,i.request({url:"docUnderstanding:listEndpoints"})];case 2:return s((null==(e=t.sent().data)?void 0:e.data)||[]),[3,4];case 3:return m(!1),[7];case 4:return[2]}})}),[i]);(0,n.useEffect)(function(){x()},[x]);var C=function(e){T(e.id),O.setFieldsValue(e),w(!0)},P=(t=f(function(e){return g(this,function(t){switch(t.label){case 0:return[4,i.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:e}})];case 1:return t.sent(),l.message.success("Deleted"),x(),[2]}})}),function(e){return t.apply(this,arguments)}),F=(o=f(function(){var e;return g(this,function(t){switch(t.label){case 0:return t.trys.push([0,6,,7]),[4,O.validateFields()];case 1:if((e=t.sent()).customHeaders=A(e.customHeaders),!k)return[3,3];return[4,i.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:k},data:e})];case 2:return t.sent(),[3,5];case 3:return[4,i.request({url:"docUnderstanding:createEndpoint",method:"POST",data:e})];case 4:t.sent(),t.label=5;case 5:return l.message.success("Saved"),w(!1),x(),[3,7];case 6:return t.sent(),[3,7];case 7:return[2]}})}),function(){return o.apply(this,arguments)}),A=function(e){return Object.entries(e||{}).reduce(function(e,t){var n=y(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{})},j=[{title:"Name",dataIndex:"name",width:150},{title:"Subpath",dataIndex:"subpath",width:200},{title:"Method",dataIndex:"method",width:80,render:function(e){return r().createElement(l.Tag,null,e)}},{title:"Execution",dataIndex:"executionMode",width:100,render:function(e){return r().createElement(l.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},e)}},{title:"File",dataIndex:"fileInputMode",width:90,render:function(e){return"none"===e?"-":e}},{title:"Enabled",dataIndex:"enabled",width:70,render:function(e){return e?r().createElement(l.Tag,{color:"success"},"Yes"):r().createElement(l.Tag,null,"No")}},{title:"Action",width:120,render:function(e,t){return r().createElement(l.Space,null,r().createElement(l.Button,{type:"link",size:"small",icon:r().createElement(a.EditOutlined,null),onClick:function(){return C(t)}},"Edit"),r().createElement(l.Popconfirm,{title:"Delete this endpoint?",onConfirm:function(){return P(t.id)}},r().createElement(l.Button,{type:"link",size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)},"Delete")))}}];return r().createElement("div",null,r().createElement("div",{style:{marginBottom:16}},r().createElement(l.Button,{type:"primary",icon:r().createElement(a.PlusOutlined,null),onClick:function(){T(null),O.resetFields(),w(!0)}},"Add Endpoint")),r().createElement(l.Table,{rowKey:"id",columns:j,dataSource:c,loading:p,size:"small"}),r().createElement(l.Modal,{title:k?"Edit Endpoint":"Add Endpoint",open:b,onOk:F,onCancel:function(){return w(!1)},width:680,destroyOnClose:!0},r().createElement(l.Form,{form:O,layout:"vertical",preserve:!1},r().createElement(l.Tabs,{size:"small",items:[{key:"basic",label:"Basic",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"name",label:"Unique Name",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"ocr, classify, extract..."})),r().createElement(l.Form.Item,{name:"subpath",label:"Subpath",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"/api/v1/ocr"})),r().createElement(l.Form.Item,{name:"description",label:"Description"},r().createElement(v,{rows:2,placeholder:"What this endpoint does"})),r().createElement(l.Space,{size:"large"},r().createElement(l.Form.Item,{name:"method",label:"HTTP Method",initialValue:"POST"},r().createElement(l.Select,{style:{width:120}},r().createElement(l.Select.Option,{value:"GET"},"GET"),r().createElement(l.Select.Option,{value:"POST"},"POST"),r().createElement(l.Select.Option,{value:"PUT"},"PUT"))),r().createElement(l.Form.Item,{name:"enabled",label:"Enabled",valuePropName:"checked",initialValue:!0},r().createElement(l.Switch,null))))},{key:"file",label:"File Input",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"fileInputMode",label:"File Input Mode",initialValue:"none"},r().createElement(l.Select,{style:{width:200}},r().createElement(l.Select.Option,{value:"none"},"None"),r().createElement(l.Select.Option,{value:"multipart"},"Multipart Upload"),r().createElement(l.Select.Option,{value:"base64"},"Base64 in JSON"))),r().createElement(l.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==O.getFieldValue("fileInputMode")?r().createElement(l.Form.Item,{name:"maxFiles",label:"Max Files",initialValue:1},r().createElement(l.InputNumber,{min:1,max:20,style:{width:120}})):null}))},{key:"async",label:"Async Config",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"executionMode",label:"Execution Mode",initialValue:"sync"},r().createElement(l.Select,{style:{width:200}},r().createElement(l.Select.Option,{value:"sync"},"Synchronous"),r().createElement(l.Select.Option,{value:"polling"},"Polling"),r().createElement(l.Select.Option,{value:"webhook"},"Webhook"))),r().createElement(l.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=O.getFieldValue("executionMode");return"sync"===e?null:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"pollTaskIdField",label:"Task ID Field",help:"Field in response containing the async task ID",initialValue:"task_id"},r().createElement(l.Input,{placeholder:"task_id"})),"polling"===e&&r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"pollResultSubpath",label:"Poll Result Subpath",help:"URL to poll for result. Use {taskId} as placeholder.",rules:[{required:!0,message:"Required for polling mode"}]},r().createElement(l.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),r().createElement(l.Form.Item,{name:"pollResultField",label:"Result Field",help:"Field in poll response containing the actual result"},r().createElement(l.Input,{placeholder:"result"})),r().createElement(l.Form.Item,{name:"pollStatusField",label:"Status Field (optional)",help:"Field to check completion status. If empty, any non-null result = complete."},r().createElement(l.Input,{placeholder:"status"})),r().createElement(l.Form.Item,{name:"pollCompletedValue",label:"Completed Value",help:"Value of status field that means 'done'",initialValue:"completed"},r().createElement(l.Input,{placeholder:"completed"})),r().createElement(l.Space,{size:"large"},r().createElement(l.Form.Item,{name:"pollInterval",label:"Poll Interval (ms)",help:"Override default"},r().createElement(l.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),r().createElement(l.Form.Item,{name:"pollTimeout",label:"Poll Timeout (ms)",help:"Override default"},r().createElement(l.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:"Schema",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"requestBodySchema",label:"Request Body Schema (JSON Schema)"},r().createElement(S,{placeholder:'{ "type": "object", "properties": { ... } }'})),r().createElement(l.Form.Item,{name:"responseSchema",label:"Response Schema (JSON Schema)"},r().createElement(S,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:"Custom Headers",children:r().createElement(l.Form.Item,{name:"customHeaders",label:"Additional Headers"},r().createElement(E,null))}]}))))};function O(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 I(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 k(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){I(a,r,l,o,i,"next",e)}function i(e){I(a,r,l,o,i,"throw",e)}o(void 0)})}}function T(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(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){T(e,t,n[t])})}return e}function C(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function P(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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)||j(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 F(e){return function(e){if(Array.isArray(e))return O(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||j(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 A(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function j(e,t){if(e){if("string"==typeof e)return O(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 O(e,t)}}function B(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var R=l.Input.TextArea,N=l.Collapse.Panel,M={pending:{color:"default",label:"Pending"},running:{color:"processing",label:"Running"},polling:{color:"processing",label:"Polling"},completed:{color:"success",label:"Completed"},failed:{color:"error",label:"Failed"},timeout:{color:"error",label:"Timeout"}},q=function(e){var t,n,r;return null!=(r=null!=(n=null==e||null==(t=e.data)?void 0:t.data)?n:null==e?void 0:e.data)?r:e},z=function(e){return JSON.stringify(null!=e?e:{},null,2)},D=function(e){return e&&(void 0===e?"undefined":A(e))==="object"?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=P(t,2),r=n[0],l=D(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},U=function(e,t){return e&&t&&(void 0===e?"undefined":A(e))==="object"&&(void 0===t?"undefined":A(t))==="object"&&!Array.isArray(e)&&!Array.isArray(t)?Object.entries(e).reduce(function(e,t){var n=P(t,2),r=n[0],l=n[1];return C(x({},e),T({},r,U(l,e[r])))},x({},t)):void 0===t?e:t},_=function(e){var t=e.value,l=e.onChange,a=e.placeholder,o=e.rows,i=P((0,n.useState)(""),2),u=i[0],c=i[1],s=P((0,n.useState)(""),2),d=s[0],p=s[1];return(0,n.useEffect)(function(){if(!t)return void c("");try{c("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){c("string"==typeof t?t:"")}},[t]),r().createElement("div",null,r().createElement(R,{rows:void 0===o?5:o,value:u,onChange:function(e){return c(e.target.value)},onBlur:function(){if(!u.trim()){p(""),null==l||l(null);return}try{var e=JSON.parse(u);p(""),null==l||l(e)}catch(e){p("Invalid JSON")}},placeholder:a||"{}",style:{fontFamily:"monospace",fontSize:12}}),d&&r().createElement("div",{style:{color:"#ff4d4f",fontSize:12}},d))},J=function(e){var t=e.steps,n=e.endpoints,o=e.onChange,i=function(e,n){var r,l=F(t),a=e+n;a<0||a>=l.length||(r=[l[a],l[e]],l[e]=r[0],l[a]=r[1],l.forEach(function(e,t){return e.stepOrder=t+1}),o(l))},u=function(e,n,r){var l=F(t);l[e][n]=r,o(l)},c=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),o(n)},s=function(){var e;o(F(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?r().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},r().createElement(l.Empty,{description:"No steps yet",imageStyle:{height:40}}),r().createElement(l.Button,{type:"dashed",icon:r().createElement(a.PlusOutlined,null),onClick:s,style:{marginTop:8}},"Add First Step")):r().createElement("div",null,r().createElement(l.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,o){var s=n.find(function(t){return t.id===e.endpointId}),d=r().createElement(l.Space,{size:4,onClick:function(e){return e.stopPropagation()}},r().createElement(l.Button,{size:"small",disabled:0===o,icon:r().createElement(a.ArrowUpOutlined,null),onClick:function(){return i(o,-1)}}),r().createElement(l.Button,{size:"small",disabled:o===t.length-1,icon:r().createElement(a.ArrowDownOutlined,null),onClick:function(){return i(o,1)}}),r().createElement(l.Popconfirm,{title:"Remove step?",onConfirm:function(){return c(o)}},r().createElement(l.Button,{size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)}))),p=r().createElement(l.Space,null,r().createElement(l.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),r().createElement("span",null,e.name||"(unnamed)"),s&&r().createElement(l.Tag,null,s.name),"skip"===e.onError&&r().createElement(l.Tooltip,{title:"Step can be skipped on error"},r().createElement(l.Tag,{color:"orange"},"skip on error")),e.condition&&r().createElement(l.Tooltip,{title:"Has condition"},r().createElement(l.Tag,{color:"purple"},"conditional")));return r().createElement(N,{key:e._key,header:p,extra:d},r().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Step Name *"),r().createElement(l.Input,{value:e.name,onChange:function(e){return u(o,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Endpoint *"),r().createElement(l.Select,{value:e.endpointId,onChange:function(e){return u(o,"endpointId",e)},placeholder:"Select endpoint",style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},"Output Alias"),r().createElement(l.Input,{value:e.outputAlias,onChange:function(e){return u(o,"outputAlias",e.target.value)},placeholder:"ocr_result"}),r().createElement("div",{style:{color:"#888",fontSize:11}},"Other steps reference this as: $step[",e.outputAlias||e.stepOrder,"].response.field")),r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},"On Error"),r().createElement(l.Space,null,r().createElement(l.Select,{value:e.onError,onChange:function(e){return u(o,"onError",e)},style:{width:120}},r().createElement(l.Select.Option,{value:"fail"},"Fail"),r().createElement(l.Select.Option,{value:"skip"},"Skip"),r().createElement(l.Select.Option,{value:"retry"},"Retry")),"retry"===e.onError&&r().createElement(l.InputNumber,{value:e.retryCount,onChange:function(e){return u(o,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100}})))),r().createElement("div",{style:{marginTop:12}},r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Input Mapping (JSON)",r().createElement(l.Tooltip,{title:"Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values."},r().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),r().createElement(_,{value:e.inputMapping,onChange:function(e){return u(o,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),r().createElement("div",{style:{marginTop:12}},r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Condition (optional JSON)",r().createElement(l.Tooltip,{title:'Only run this step if condition matches. Format: { "field": "$step[x].response.y", "op": "eq", "value": "..." }'},r().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),r().createElement(_,{value:e.condition,onChange:function(e){return u(o,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),r().createElement(l.Button,{type:"dashed",icon:r().createElement(a.PlusOutlined,null),onClick:s,style:{marginTop:8,width:"100%"}},"Add Step"))},V=function(){var t,o,i,u,c,s,d=(0,e.useAPIClient)(),p=P((0,n.useState)([]),2),m=p[0],f=p[1],y=P((0,n.useState)([]),2),h=y[0],b=y[1],g=P((0,n.useState)(!1),2),v=g[0],E=g[1],S=P((0,n.useState)(!1),2),w=S[0],O=S[1],I=P(l.Form.useForm(),1)[0],T=P((0,n.useState)(null),2),A=T[0],j=T[1],V=P((0,n.useState)([]),2),H=V[0],W=V[1],L=P((0,n.useState)(!1),2),$=L[0],K=L[1],G=P((0,n.useState)(null),2),Y=G[0],X=G[1],Q=P((0,n.useState)("{}"),2),Z=Q[0],ee=Q[1],et=P((0,n.useState)(""),2),en=et[0],er=et[1],el=P((0,n.useState)(null),2),ea=el[0],eo=el[1],ei=P((0,n.useState)(!1),2),eu=ei[0],ec=ei[1],es=(0,n.useRef)(null),ed=(0,n.useCallback)(k(function(){var e,t,n,r,l;return B(this,function(a){switch(a.label){case 0:E(!0),a.label=1;case 1:return a.trys.push([1,,3,4]),[4,Promise.all([d.request({url:"docUnderstanding:listPipelines"}),d.request({url:"docUnderstanding:listEndpoints"})])];case 2:return r=(n=P.apply(void 0,[a.sent(),2]))[0],l=n[1],f((null==(e=r.data)?void 0:e.data)||[]),b((null==(t=l.data)?void 0:t.data)||[]),[3,4];case 3:return E(!1),[7];case 4:return[2]}})}),[d]);(0,n.useEffect)(function(){ed()},[ed]),(0,n.useEffect)(function(){return function(){es.current&&clearInterval(es.current)}},[]);var ep=function(e){j(e.id),I.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),W(F(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),O(!0)},em=(t=k(function(e){return B(this,function(t){switch(t.label){case 0:return[4,d.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:e}})];case 1:return t.sent(),l.message.success("Deleted"),ed(),[2]}})}),function(e){return t.apply(this,arguments)}),ef=(0,n.useCallback)(function(){es.current&&(clearInterval(es.current),es.current=null)},[]),ey=(0,n.useCallback)((o=k(function(e){var t;return B(this,function(n){switch(n.label){case 0:return[4,d.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:e}})];case 1:return eo(t=q(n.sent())),["completed","failed","timeout"].includes(null==t?void 0:t.status)&&(ef(),ec(!1)),[2,t]}})}),function(e){return o.apply(this,arguments)}),[d,ef]),eh=(0,n.useCallback)(function(e){ef(),es.current=setInterval(function(){ey(e).catch(function(e){ef(),ec(!1),l.message.error((null==e?void 0:e.message)||"Failed to refresh test job")})},1500)},[ey,ef]),eb=function(e){ef(),X(e),eo(null),ec(!1),er(""),ee(z(D(e.inputSchema))),K(!0)},eg=function(){ef(),K(!1),X(null),eo(null),ec(!1)},ev=(i=k(function(){var e,t,n,r,a,o;return B(this,function(i){switch(i.label){case 0:if(!Y)return[2];try{t=Z.trim()?JSON.parse(Z):{},e=U(D(Y.inputSchema),t),er("")}catch(e){return er("Invalid JSON input"),[2]}ef(),ec(!0),eo(null),i.label=1;case 1:return i.trys.push([1,4,,5]),[4,d.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:Y.id,input:e}})];case 2:if(!(r=null==(n=q(i.sent()))?void 0:n.jobId))throw Error("Pipeline did not return a job ID");return[4,ey(r)];case 3:return["completed","failed","timeout"].includes(null==(a=i.sent())?void 0:a.status)||eh(r),l.message.success("Test job #".concat(r," started")),[3,5];case 4:return o=i.sent(),ec(!1),l.message.error((null==o?void 0:o.message)||"Failed to run pipeline test"),[3,5];case 5:return[2]}})}),function(){return i.apply(this,arguments)}),eE=(u=k(function(){var e,t,n,r,a,o,i,u,c;return B(this,function(s){switch(s.label){case 0:return s.trys.push([0,6,,7]),[4,I.validateFields()];case 1:e=s.sent(),t=!0,n=!1,r=void 0;try{for(a=H[Symbol.iterator]();!(t=(o=a.next()).done);t=!0){if(!(i=o.value).name)return l.message.error("All steps must have a name"),[2];if(!i.endpointId)return l.message.error('Step "'.concat(i.name||i.stepOrder,'" must have an endpoint')),[2]}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}if(new Set(u=H.map(function(e){return e.outputAlias}).filter(Boolean)).size!==u.length)return l.message.error("Step output aliases must be unique"),[2];if(c=C(x({},e),{steps:H.map(function(e){return C(x({},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})})}),!A)return[3,3];return[4,d.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:A},data:c})];case 2:return s.sent(),[3,5];case 3:return[4,d.request({url:"docUnderstanding:createPipeline",method:"POST",data:c})];case 4:s.sent(),s.label=5;case 5:return l.message.success("Saved"),O(!1),ed(),[3,7];case 6:return s.sent(),[3,7];case 7:return[2]}})}),function(){return u.apply(this,arguments)}),eS=[{title:"Name",dataIndex:"name",width:200},{title:"Steps",dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return r().createElement(l.Tag,null,"0 steps");var t=F(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return r().createElement(l.Space,{size:2,wrap:!0},t.map(function(e,t){return r().createElement(r().Fragment,{key:e.id},t>0&&r().createElement("span",{style:{color:"#ccc"}},"→"),r().createElement(l.Tag,null,e.name||"Step ".concat(e.stepOrder)))}))}},{title:"Enabled",dataIndex:"enabled",width:80,render:function(e){return e?r().createElement(l.Tag,{color:"success"},"Yes"):r().createElement(l.Tag,null,"No")}},{title:"AI Tool",width:100,render:function(e,t){var n;return t.enabled?r().createElement(l.Tooltip,{title:"Registered as: doc_understanding.".concat(null==(n=t.name)?void 0:n.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},r().createElement(l.Tag,{color:"blue",icon:r().createElement(a.ThunderboltOutlined,null)},"Active")):r().createElement(l.Tag,null,"Inactive")}},{title:"Action",width:190,render:function(e,t){return r().createElement(l.Space,null,r().createElement(l.Button,{type:"link",size:"small",icon:r().createElement(a.PlayCircleOutlined,null),disabled:!t.enabled,onClick:function(){return eb(t)}},"Test"),r().createElement(l.Button,{type:"link",size:"small",icon:r().createElement(a.EditOutlined,null),onClick:function(){return ep(t)}},"Edit"),r().createElement(l.Popconfirm,{title:"Delete this pipeline?",onConfirm:function(){return em(t.id)}},r().createElement(l.Button,{type:"link",size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)},"Delete")))}}];return r().createElement("div",null,r().createElement("div",{style:{marginBottom:16}},r().createElement(l.Button,{type:"primary",icon:r().createElement(a.PlusOutlined,null),onClick:function(){j(null),I.resetFields(),W([]),O(!0)}},"Add Pipeline")),r().createElement(l.Table,{rowKey:"id",columns:eS,dataSource:m,loading:v,size:"small"}),r().createElement(l.Modal,{title:A?"Edit Pipeline":"New Pipeline",open:w,onOk:eE,onCancel:function(){return O(!1)},width:800,destroyOnClose:!0},r().createElement(l.Form,{form:I,layout:"vertical",preserve:!1},r().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},r().createElement(l.Form.Item,{name:"name",label:"Pipeline Name",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"full_document_processing"})),r().createElement(l.Form.Item,{name:"enabled",label:"Enabled",valuePropName:"checked",initialValue:!0},r().createElement(l.Switch,null))),r().createElement(l.Form.Item,{name:"description",label:"Description"},r().createElement(R,{rows:2,placeholder:"What this pipeline does"})),r().createElement(l.Card,{title:"Pipeline Steps",size:"small",style:{marginBottom:16},extra:r().createElement(l.Tag,{color:"blue"},H.length," step(s)")},r().createElement(J,{steps:H,endpoints:h,onChange:W})),r().createElement(l.Collapse,{size:"small",ghost:!0},r().createElement(N,{header:"Advanced: Input Schema & Output Mapping",key:"advanced"},r().createElement(l.Form.Item,{name:"inputSchema",label:"Input Schema (JSON Schema)",help:"Defines what input this pipeline accepts. Used by AI tool schema."},r().createElement(_,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),r().createElement(l.Form.Item,{name:"outputMapping",label:"Output Mapping (JSON)",help:"Map final step results to pipeline output. If empty, all step results are returned."},r().createElement(_,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),r().createElement(l.Modal,{title:Y?"Test Playground: ".concat(Y.name):"Test Playground",open:$,onCancel:eg,width:860,destroyOnClose:!0,footer:[r().createElement(l.Button,{key:"close",onClick:eg},"Close"),(null==ea?void 0:ea.id)&&r().createElement(l.Button,{key:"refresh",icon:r().createElement(a.ReloadOutlined,null),disabled:eu,onClick:function(){return ey(ea.id)}},"Refresh"),r().createElement(l.Button,{key:"run",type:"primary",icon:r().createElement(a.PlayCircleOutlined,null),loading:eu,onClick:ev},"Run test")].filter(Boolean)},r().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},r().createElement("div",null,r().createElement("div",{style:{fontWeight:500,marginBottom:6}},"Input JSON"),r().createElement(R,{rows:16,value:Z,onChange:function(e){ee(e.target.value),en&&er("")},placeholder:'{ "document_url": "https://..." }',style:{fontFamily:"monospace",fontSize:12}}),en&&r().createElement(l.Alert,{type:"error",showIcon:!0,message:en,style:{marginTop:8}}),r().createElement(l.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},r().createElement(N,{header:"Input Schema",key:"schema"},r().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},z(null==Y?void 0:Y.inputSchema))))),r().createElement("div",null,r().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},r().createElement("span",{style:{fontWeight:500}},"Result"),(null==ea?void 0:ea.status)&&r().createElement(l.Tag,{color:(null==(c=M[ea.status])?void 0:c.color)||"default"},(null==(s=M[ea.status])?void 0:s.label)||ea.status)),ea?r().createElement("div",null,r().createElement(l.Space,{style:{marginBottom:8},wrap:!0},r().createElement(l.Tag,null,"Job #",ea.id),ea.currentStep&&r().createElement(l.Tag,null,"Step ",ea.currentStep)),ea.error&&r().createElement(l.Alert,{type:"error",showIcon:!0,message:"Pipeline error",description:r().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},ea.error),style:{marginBottom:12}}),r().createElement("div",{style:{fontWeight:500,marginBottom:4}},"Final Result"),r().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==ea.finalResult&&null!==ea.finalResult?z(ea.finalResult):"(not yet available)"),r().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},"Step Results"),r().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},ea.stepResults?z(ea.stepResults):"{}")):r().createElement(l.Empty,{description:"Run a test to see job output",imageStyle:{height:48}})))))};function H(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 W(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 L(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){W(a,r,l,o,i,"next",e)}function i(e){W(a,r,l,o,i,"throw",e)}o(void 0)})}}function $(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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 H(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 H(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 K(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var G={pending:{color:"default",label:"Pending"},running:{color:"processing",label:"Running"},polling:{color:"processing",label:"Polling"},completed:{color:"success",label:"Completed"},failed:{color:"error",label:"Failed"},timeout:{color:"error",label:"Timeout"}},Y=function(){var t,o,i=(0,e.useAPIClient)(),u=$((0,n.useState)([]),2),c=u[0],s=u[1],d=$((0,n.useState)([]),2),p=d[0],m=d[1],f=$((0,n.useState)(!1),2),y=f[0],h=f[1],b=$((0,n.useState)(!1),2),g=b[0],v=b[1],E=$((0,n.useState)(null),2),S=E[0],w=E[1],O=$((0,n.useState)(void 0),2),I=O[0],k=O[1],T=$((0,n.useState)(void 0),2),x=T[0],C=T[1],P=(0,n.useCallback)(L(function(){var e,t;return K(this,function(n){switch(n.label){case 0:h(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},I&&(t.status=I),x&&(t.pipelineId=x),[4,i.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s((null==(e=n.sent().data)?void 0:e.data)||[]),[3,4];case 3:return h(!1),[7];case 4:return[2]}})}),[i,I,x]),F=(0,n.useCallback)(L(function(){var e;return K(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,i.request({url:"docUnderstanding:listPipelines"})];case 1:return m((null==(e=t.sent().data)?void 0:e.data)||[]),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})}),[i]);(0,n.useEffect)(function(){F()},[F]),(0,n.useEffect)(function(){P();var e=setInterval(P,1e4);return function(){return clearInterval(e)}},[P]);var A=new Map(p.map(function(e){return[e.id,e.name]})),j=(t=L(function(e){var t;return K(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,i.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:e.id}})];case 1:return w((null==(t=n.sent().data)?void 0:t.data)||e),[3,3];case 2:return n.sent(),w(e),[3,3];case 3:return v(!0),[2]}})}),function(e){return t.apply(this,arguments)}),B=[{title:"ID",dataIndex:"id",width:60},{title:"Pipeline",dataIndex:"pipelineId",width:180,render:function(e){return A.get(e)||"#".concat(e)}},{title:"Status",dataIndex:"status",width:100,render:function(e){var t=G[e]||{color:"default",label:e};return r().createElement(l.Tag,{color:t.color},t.label)}},{title:"Current Step",dataIndex:"currentStep",width:90,render:function(e,t){return"completed"===t.status?r().createElement(l.Tag,{color:"success"},"Done"):"failed"===t.status?r().createElement(l.Tag,{color:"error"},"Step ",e):r().createElement(l.Badge,{status:"processing",text:"Step ".concat(e)})}},{title:"Started",dataIndex:"startedAt",width:160,render:function(e){return e?new Date(e).toLocaleString():"-"}},{title:"Completed",dataIndex:"completedAt",width:160,render:function(e){return e?new Date(e).toLocaleString():"-"}},{title:"Action",width:80,render:function(e,t){return r().createElement(l.Button,{size:"small",icon:r().createElement(a.EyeOutlined,null),onClick:function(){return j(t)}},"View")}}];return r().createElement("div",null,r().createElement(l.Space,{style:{marginBottom:16},wrap:!0},r().createElement(l.Select,{allowClear:!0,placeholder:"Filter by status",value:I,onChange:k,style:{width:160},options:Object.entries(G).map(function(e){var t=$(e,2);return{value:t[0],label:t[1].label}})}),r().createElement(l.Select,{allowClear:!0,placeholder:"Filter by pipeline",value:x,onChange:C,style:{width:200},options:p.map(function(e){return{value:e.id,label:e.name}})}),r().createElement(l.Button,{icon:r().createElement(a.ReloadOutlined,null),onClick:P},"Refresh")),r().createElement(l.Table,{rowKey:"id",columns:B,dataSource:c,loading:y,size:"small",pagination:{pageSize:20}}),r().createElement(l.Drawer,{title:S?"Job #".concat(S.id," — ").concat(A.get(S.pipelineId)||"Unknown"):"Job Details",width:640,open:g,onClose:function(){return v(!1)}},S&&r().createElement("div",null,r().createElement("div",{style:{marginBottom:16}},r().createElement(l.Space,null,r().createElement(l.Tag,{color:null==(o=G[S.status])?void 0:o.color},S.status),S.startedAt&&r().createElement("span",null,"Started: ",new Date(S.startedAt).toLocaleString()),S.completedAt&&r().createElement("span",null,"Completed: ",new Date(S.completedAt).toLocaleString()))),S.error&&r().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},r().createElement("strong",{style:{color:"#cf1322"}},"Error:"),r().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},S.error)),r().createElement("h4",null,"Input"),r().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(S.input,null,2)),r().createElement("h4",{style:{marginTop:16}},"Step Results"),S.stepResults&&Object.keys(S.stepResults).length>0?Object.entries(S.stepResults).map(function(e){var t=$(e,2),n=t[0],a=t[1];return r().createElement("div",{key:n,style:{marginBottom:8}},r().createElement(l.Tag,{color:"blue"},n),r().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(a,null,2)))}):r().createElement("div",{style:{color:"#999"}},"No step results yet"),r().createElement("h4",{style:{marginTop:16}},"Final Result"),r().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},S.finalResult?JSON.stringify(S.finalResult,null,2):"(not yet available)"),S.externalTaskIds&&Object.keys(S.externalTaskIds).length>0&&r().createElement(r().Fragment,null,r().createElement("h4",{style:{marginTop:16}},"External Task IDs"),r().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(S.externalTaskIds,null,2))))))},X=function(){return r().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:"100vh"}},r().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},r().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},"Document Understanding - Pipeline Orchestrator")),r().createElement("div",{style:{padding:"0 24px 24px"}},r().createElement(l.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:"Service Config",children:r().createElement(d,null)},{key:"endpoints",label:"Endpoints",children:r().createElement(w,null)},{key:"pipelines",label:"Pipelines",children:r().createElement(V,null)},{key:"jobs",label:"Jobs history",children:r().createElement(Y,null)}]})))};function Q(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 Z(e,t,n){return(Z=er()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var l=new(Function.bind.apply(e,r));return n&&et(l,n.prototype),l}).apply(null,arguments)}function ee(e){return(ee=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function et(e,t){return(et=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function en(e){var t="function"==typeof Map?new Map:void 0;return(en=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 Z(e,arguments,ee(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),et(n,e)})(e)}function er(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(er=function(){return!!e})()}var el=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=ee(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=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,er()?Reflect.construct(e,t||[],ee(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&et(r,e),n=[{key:"load",value:function(){var e,n=this;return(e=function(){var e;return function(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(r){return null==(e=n.flowEngine)||e.registerModels(t),n.app.pluginSettingsManager.add("document-understanding",{title:n.t("Document Understanding"),icon:"FileSearchOutlined",Component:X,aclSnippet:"pm.document-understanding"}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Q(a,r,l,o,i,"next",e)}function i(e){Q(a,r,l,o,i,"throw",e)}o(void 0)})})()}}],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)}}(r.prototype,n),r}(en(e.Plugin))}(),i}()});
10
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):"function"==typeof define&&define.amd?define("plugin-document-understanding",["react","@nocobase/client","@ant-design/icons","antd"],t):"object"==typeof exports?exports["plugin-document-understanding"]=t(require("react"),require("@nocobase/client"),require("@ant-design/icons"),require("antd")):e["plugin-document-understanding"]=t(e.react,e["@nocobase/client"],e["@ant-design/icons"],e.antd)}(self,function(e,t,n,r){return function(){"use strict";var l={482:function(e){e.exports=n},772:function(e){e.exports=t},721:function(e){e.exports=r},156:function(t){t.exports=e}},a={};function o(e){var t=a[e];if(void 0!==t)return t.exports;var n=a[e]={exports:{}};return l[e](n,n.exports,o),n.exports}o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,{a:t}),t},o.d=function(e,t){for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var i={};return!function(){o.r(i),o.d(i,{default:function(){return el}});var e=o(772),t={},n=o(156),r=o.n(n),l=o(721),a=o(482);function u(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 c(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 s(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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 u(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 u(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.")}()}var d=function(){var t,o,i=s(l.Form.useForm(),1)[0],u=(0,e.useAPIClient)(),d=s((0,n.useState)(!0),2),p=d[0],m=d[1],f=s((0,n.useState)(!1),2),y=f[0],h=f[1];(0,n.useEffect)(function(){u.request({url:"docUnderstanding:getConfig"}).then(function(e){var t=e.data;i.setFieldsValue((null==t?void 0:t.data)||{}),m(!1)}).catch(function(){return m(!1)})},[]);var b=(t=function(e){return function(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(t){switch(t.label){case 0:h(!0),t.label=1;case 1:return t.trys.push([1,3,4,5]),[4,u.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return t.sent(),l.message.success("Configuration saved successfully"),[3,5];case 3:return t.sent(),l.message.error("Failed to save config"),[3,5];case 4:return h(!1),[7];case 5:return[2]}})},o=function(){var e=this,n=arguments;return new Promise(function(r,l){var a=t.apply(e,n);function o(e){c(a,r,l,o,i,"next",e)}function i(e){c(a,r,l,o,i,"throw",e)}o(void 0)})},function(e){return o.apply(this,arguments)});return p?r().createElement(l.Spin,{style:{marginTop:40}}):r().createElement(l.Form,{form:i,layout:"vertical",onFinish:b,style:{maxWidth:600}},r().createElement(l.Alert,{message:"Service Connection",description:"Configure the connection to your external document processing service. All endpoints will use this base URL and authentication.",type:"info",showIcon:!0,style:{marginBottom:24}}),r().createElement(l.Form.Item,{name:"baseUrl",label:"Base URL",rules:[{required:!0,message:"Base URL is required"}],help:"The root URL of your document processing API"},r().createElement(l.Input,{prefix:r().createElement(a.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),r().createElement(l.Form.Item,{name:"authType",label:"Authentication Type",initialValue:"none"},r().createElement(l.Select,null,r().createElement(l.Select.Option,{value:"none"},"None"),r().createElement(l.Select.Option,{value:"api_key"},"API Key"),r().createElement(l.Select.Option,{value:"bearer"},"Bearer Token"),r().createElement(l.Select.Option,{value:"custom_header"},"Custom Header"))),r().createElement(l.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var e=i.getFieldValue("authType");return"none"===e?null:r().createElement(r().Fragment,null,"custom_header"===e&&r().createElement(l.Form.Item,{name:"authHeaderName",label:"Custom Header Name",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"X-Api-Key"})),r().createElement(l.Form.Item,{name:"authKey",label:"bearer"===e?"Bearer Token":"API Key",rules:[{required:!0}]},r().createElement(l.Input.Password,{placeholder:"Enter key or token"})))}),r().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},r().createElement(l.Form.Item,{name:"defaultTimeout",label:"Request Timeout (ms)",initialValue:3e4},r().createElement(l.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),r().createElement(l.Form.Item,{name:"defaultRetries",label:"Default Retries",initialValue:2},r().createElement(l.InputNumber,{style:{width:"100%"},min:0,max:10})),r().createElement(l.Form.Item,{name:"pollInterval",label:"Poll Interval (ms)",initialValue:5e3},r().createElement(l.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),r().createElement(l.Form.Item,{name:"pollTimeout",label:"Poll Timeout (ms)",initialValue:3e5},r().createElement(l.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),r().createElement(l.Form.Item,{name:"webhookSecret",label:"Webhook Secret",help:"Used to verify HMAC-SHA256 signatures on incoming webhook callbacks"},r().createElement(l.Input.Password,{placeholder:"Optional: secret for webhook signature verification"})),r().createElement(l.Form.Item,null,r().createElement(l.Button,{type:"primary",htmlType:"submit",icon:r().createElement(a.SaveOutlined,null),loading:y},"Save Configuration")))};function p(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 m(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 f(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){m(a,r,l,o,i,"next",e)}function i(e){m(a,r,l,o,i,"throw",e)}o(void 0)})}}function y(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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)||b(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 h(e){return function(e){if(Array.isArray(e))return p(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||b(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 b(e,t){if(e){if("string"==typeof e)return p(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 p(e,t)}}function g(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var v=l.Input.TextArea,E=function(e){var t=e.value,o=void 0===t?{}:t,i=e.onChange,u=y((0,n.useState)([]),2),c=u[0],s=u[1],d=(0,n.useRef)(!1);(0,n.useEffect)(function(){if(d.current){d.current=!1;return}s(Object.entries(o||{}).map(function(e,t){var n=y(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}}))},[o]);var p=function(e){s(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=!0,null==i||i(t)},m=function(e,t,n){var r,l,a=h(c);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,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),p(a)},f=function(e){p(c.filter(function(t,n){return n!==e}))};return r().createElement("div",null,c.map(function(e,t){return r().createElement(l.Space,{key:e.id,style:{display:"flex",marginBottom:4}},r().createElement(l.Input,{placeholder:"Header name",value:e.key,onChange:function(n){return m(t,n.target.value,e.value)},style:{width:180}}),r().createElement(l.Input,{placeholder:"Value",value:e.value,onChange:function(n){return m(t,e.key,n.target.value)},style:{width:220}}),r().createElement(l.Button,{size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null),onClick:function(){return f(t)}}))}),r().createElement(l.Button,{size:"small",type:"dashed",icon:r().createElement(a.PlusOutlined,null),onClick:function(){return s(h(c).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},"Add Header"))},S=function(e){var t=e.value,l=e.onChange,a=e.placeholder,o=y((0,n.useState)(""),2),i=o[0],u=o[1],c=y((0,n.useState)(""),2),s=c[0],d=c[1];return(0,n.useEffect)(function(){if(!t)return void u("");try{u("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){u("string"==typeof t?t:"")}},[t]),r().createElement("div",null,r().createElement(v,{rows:6,value:i,onChange:function(e){return u(e.target.value)},onBlur:function(){if(!i.trim()){d(""),null==l||l(null);return}try{var e=JSON.parse(i);d(""),null==l||l(e)}catch(e){d("Invalid JSON")}},placeholder:a||"{}",style:{fontFamily:"monospace",fontSize:12}}),s&&r().createElement("div",{style:{color:"#ff4d4f",fontSize:12}},s))},w=function(){var t,o,i=(0,e.useAPIClient)(),u=y((0,n.useState)([]),2),c=u[0],s=u[1],d=y((0,n.useState)(!1),2),p=d[0],m=d[1],h=y((0,n.useState)(!1),2),b=h[0],w=h[1],O=y(l.Form.useForm(),1)[0],I=y((0,n.useState)(null),2),k=I[0],T=I[1],x=(0,n.useCallback)(f(function(){var e;return g(this,function(t){switch(t.label){case 0:m(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,i.request({url:"docUnderstanding:listEndpoints"})];case 2:return s((null==(e=t.sent().data)?void 0:e.data)||[]),[3,4];case 3:return m(!1),[7];case 4:return[2]}})}),[i]);(0,n.useEffect)(function(){x()},[x]);var C=function(e){T(e.id),O.setFieldsValue(e),w(!0)},P=(t=f(function(e){return g(this,function(t){switch(t.label){case 0:return[4,i.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:e}})];case 1:return t.sent(),l.message.success("Deleted"),x(),[2]}})}),function(e){return t.apply(this,arguments)}),F=(o=f(function(){var e;return g(this,function(t){switch(t.label){case 0:return t.trys.push([0,6,,7]),[4,O.validateFields()];case 1:if((e=t.sent()).customHeaders=A(e.customHeaders),!k)return[3,3];return[4,i.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:k},data:e})];case 2:return t.sent(),[3,5];case 3:return[4,i.request({url:"docUnderstanding:createEndpoint",method:"POST",data:e})];case 4:t.sent(),t.label=5;case 5:return l.message.success("Saved"),w(!1),x(),[3,7];case 6:return t.sent(),[3,7];case 7:return[2]}})}),function(){return o.apply(this,arguments)}),A=function(e){return Object.entries(e||{}).reduce(function(e,t){var n=y(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{})},j=[{title:"Name",dataIndex:"name",width:150},{title:"Subpath",dataIndex:"subpath",width:200},{title:"Method",dataIndex:"method",width:80,render:function(e){return r().createElement(l.Tag,null,e)}},{title:"Execution",dataIndex:"executionMode",width:100,render:function(e){return r().createElement(l.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},e)}},{title:"File",dataIndex:"fileInputMode",width:90,render:function(e){return"none"===e?"-":e}},{title:"Enabled",dataIndex:"enabled",width:70,render:function(e){return e?r().createElement(l.Tag,{color:"success"},"Yes"):r().createElement(l.Tag,null,"No")}},{title:"Action",width:120,render:function(e,t){return r().createElement(l.Space,null,r().createElement(l.Button,{type:"link",size:"small",icon:r().createElement(a.EditOutlined,null),onClick:function(){return C(t)}},"Edit"),r().createElement(l.Popconfirm,{title:"Delete this endpoint?",onConfirm:function(){return P(t.id)}},r().createElement(l.Button,{type:"link",size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)},"Delete")))}}];return r().createElement("div",null,r().createElement("div",{style:{marginBottom:16}},r().createElement(l.Button,{type:"primary",icon:r().createElement(a.PlusOutlined,null),onClick:function(){T(null),O.resetFields(),w(!0)}},"Add Endpoint")),r().createElement(l.Table,{rowKey:"id",columns:j,dataSource:c,loading:p,size:"small"}),r().createElement(l.Modal,{title:k?"Edit Endpoint":"Add Endpoint",open:b,onOk:F,onCancel:function(){return w(!1)},width:680,destroyOnClose:!0},r().createElement(l.Form,{form:O,layout:"vertical",preserve:!1},r().createElement(l.Tabs,{size:"small",items:[{key:"basic",label:"Basic",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"name",label:"Unique Name",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"ocr, classify, extract..."})),r().createElement(l.Form.Item,{name:"subpath",label:"Subpath",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"/api/v1/ocr"})),r().createElement(l.Form.Item,{name:"description",label:"Description"},r().createElement(v,{rows:2,placeholder:"What this endpoint does"})),r().createElement(l.Space,{size:"large"},r().createElement(l.Form.Item,{name:"method",label:"HTTP Method",initialValue:"POST"},r().createElement(l.Select,{style:{width:120}},r().createElement(l.Select.Option,{value:"GET"},"GET"),r().createElement(l.Select.Option,{value:"POST"},"POST"),r().createElement(l.Select.Option,{value:"PUT"},"PUT"))),r().createElement(l.Form.Item,{name:"enabled",label:"Enabled",valuePropName:"checked",initialValue:!0},r().createElement(l.Switch,null))))},{key:"file",label:"File Input",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"fileInputMode",label:"File Input Mode",initialValue:"none"},r().createElement(l.Select,{style:{width:200}},r().createElement(l.Select.Option,{value:"none"},"None"),r().createElement(l.Select.Option,{value:"multipart"},"Multipart Upload"),r().createElement(l.Select.Option,{value:"base64"},"Base64 in JSON"))),r().createElement(l.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==O.getFieldValue("fileInputMode")?r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"fileFieldName",label:"File Field Name",initialValue:"file"},r().createElement(l.Input,{placeholder:"file",style:{width:200}})),r().createElement(l.Form.Item,{name:"maxFiles",label:"Max Files",initialValue:1},r().createElement(l.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"async",label:"Async Config",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"executionMode",label:"Execution Mode",initialValue:"sync"},r().createElement(l.Select,{style:{width:200}},r().createElement(l.Select.Option,{value:"sync"},"Synchronous"),r().createElement(l.Select.Option,{value:"polling"},"Polling"),r().createElement(l.Select.Option,{value:"webhook"},"Webhook"))),r().createElement(l.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=O.getFieldValue("executionMode");return"sync"===e?null:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"pollTaskIdField",label:"Task ID Field",help:"Field in response containing the async task ID",initialValue:"task_id"},r().createElement(l.Input,{placeholder:"task_id"})),"polling"===e&&r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"pollResultSubpath",label:"Poll Result Subpath",help:"URL to poll for result. Use {taskId} as placeholder.",rules:[{required:!0,message:"Required for polling mode"}]},r().createElement(l.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),r().createElement(l.Form.Item,{name:"pollResultField",label:"Result Field",help:"Field in poll response containing the actual result"},r().createElement(l.Input,{placeholder:"result"})),r().createElement(l.Form.Item,{name:"pollStatusField",label:"Status Field (optional)",help:"Field to check completion status. If empty, any non-null result = complete."},r().createElement(l.Input,{placeholder:"status"})),r().createElement(l.Form.Item,{name:"pollCompletedValue",label:"Completed Value",help:"Value of status field that means 'done'",initialValue:"completed"},r().createElement(l.Input,{placeholder:"completed"})),r().createElement(l.Space,{size:"large"},r().createElement(l.Form.Item,{name:"pollInterval",label:"Poll Interval (ms)",help:"Override default"},r().createElement(l.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),r().createElement(l.Form.Item,{name:"pollTimeout",label:"Poll Timeout (ms)",help:"Override default"},r().createElement(l.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:"Schema",children:r().createElement(r().Fragment,null,r().createElement(l.Form.Item,{name:"requestBodySchema",label:"Request Body Schema (JSON Schema)"},r().createElement(S,{placeholder:'{ "type": "object", "properties": { ... } }'})),r().createElement(l.Form.Item,{name:"responseSchema",label:"Response Schema (JSON Schema)"},r().createElement(S,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:"Custom Headers",children:r().createElement(l.Form.Item,{name:"customHeaders",label:"Additional Headers"},r().createElement(E,null))}]}))))};function O(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 I(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 k(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){I(a,r,l,o,i,"next",e)}function i(e){I(a,r,l,o,i,"throw",e)}o(void 0)})}}function T(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function x(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){T(e,t,n[t])})}return e}function C(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n.push.apply(n,r)}return n})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function P(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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)||j(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 F(e){return function(e){if(Array.isArray(e))return O(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||j(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 A(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function j(e,t){if(e){if("string"==typeof e)return O(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 O(e,t)}}function B(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var R=l.Input.TextArea,N=l.Collapse.Panel,M={pending:{color:"default",label:"Pending"},running:{color:"processing",label:"Running"},polling:{color:"processing",label:"Polling"},completed:{color:"success",label:"Completed"},failed:{color:"error",label:"Failed"},timeout:{color:"error",label:"Timeout"}},q=function(e){var t,n,r;return null!=(r=null!=(n=null==e||null==(t=e.data)?void 0:t.data)?n:null==e?void 0:e.data)?r:e},z=function(e){return JSON.stringify(null!=e?e:{},null,2)},D=function(e){return e&&(void 0===e?"undefined":A(e))==="object"?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=P(t,2),r=n[0],l=D(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},U=function(e,t){return e&&t&&(void 0===e?"undefined":A(e))==="object"&&(void 0===t?"undefined":A(t))==="object"&&!Array.isArray(e)&&!Array.isArray(t)?Object.entries(e).reduce(function(e,t){var n=P(t,2),r=n[0],l=n[1];return C(x({},e),T({},r,U(l,e[r])))},x({},t)):void 0===t?e:t},_=function(e){var t=e.value,l=e.onChange,a=e.placeholder,o=e.rows,i=P((0,n.useState)(""),2),u=i[0],c=i[1],s=P((0,n.useState)(""),2),d=s[0],p=s[1];return(0,n.useEffect)(function(){if(!t)return void c("");try{c("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){c("string"==typeof t?t:"")}},[t]),r().createElement("div",null,r().createElement(R,{rows:void 0===o?5:o,value:u,onChange:function(e){return c(e.target.value)},onBlur:function(){if(!u.trim()){p(""),null==l||l(null);return}try{var e=JSON.parse(u);p(""),null==l||l(e)}catch(e){p("Invalid JSON")}},placeholder:a||"{}",style:{fontFamily:"monospace",fontSize:12}}),d&&r().createElement("div",{style:{color:"#ff4d4f",fontSize:12}},d))},J=function(e){var t=e.steps,n=e.endpoints,o=e.onChange,i=function(e,n){var r,l=F(t),a=e+n;a<0||a>=l.length||(r=[l[a],l[e]],l[e]=r[0],l[a]=r[1],l.forEach(function(e,t){return e.stepOrder=t+1}),o(l))},u=function(e,n,r){var l=F(t);l[e][n]=r,o(l)},c=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),o(n)},s=function(){var e;o(F(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?r().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},r().createElement(l.Empty,{description:"No steps yet",imageStyle:{height:40}}),r().createElement(l.Button,{type:"dashed",icon:r().createElement(a.PlusOutlined,null),onClick:s,style:{marginTop:8}},"Add First Step")):r().createElement("div",null,r().createElement(l.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,o){var s=n.find(function(t){return t.id===e.endpointId}),d=r().createElement(l.Space,{size:4,onClick:function(e){return e.stopPropagation()}},r().createElement(l.Button,{size:"small",disabled:0===o,icon:r().createElement(a.ArrowUpOutlined,null),onClick:function(){return i(o,-1)}}),r().createElement(l.Button,{size:"small",disabled:o===t.length-1,icon:r().createElement(a.ArrowDownOutlined,null),onClick:function(){return i(o,1)}}),r().createElement(l.Popconfirm,{title:"Remove step?",onConfirm:function(){return c(o)}},r().createElement(l.Button,{size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)}))),p=r().createElement(l.Space,null,r().createElement(l.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),r().createElement("span",null,e.name||"(unnamed)"),s&&r().createElement(l.Tag,null,s.name),"skip"===e.onError&&r().createElement(l.Tooltip,{title:"Step can be skipped on error"},r().createElement(l.Tag,{color:"orange"},"skip on error")),e.condition&&r().createElement(l.Tooltip,{title:"Has condition"},r().createElement(l.Tag,{color:"purple"},"conditional")));return r().createElement(N,{key:e._key,header:p,extra:d},r().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Step Name *"),r().createElement(l.Input,{value:e.name,onChange:function(e){return u(o,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Endpoint *"),r().createElement(l.Select,{value:e.endpointId,onChange:function(e){return u(o,"endpointId",e)},placeholder:"Select endpoint",style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},"Output Alias"),r().createElement(l.Input,{value:e.outputAlias,onChange:function(e){return u(o,"outputAlias",e.target.value)},placeholder:"ocr_result"}),r().createElement("div",{style:{color:"#888",fontSize:11}},"Other steps reference this as: $step[",e.outputAlias||e.stepOrder,"].response.field")),r().createElement("div",null,r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},"On Error"),r().createElement(l.Space,null,r().createElement(l.Select,{value:e.onError,onChange:function(e){return u(o,"onError",e)},style:{width:120}},r().createElement(l.Select.Option,{value:"fail"},"Fail"),r().createElement(l.Select.Option,{value:"skip"},"Skip"),r().createElement(l.Select.Option,{value:"retry"},"Retry")),"retry"===e.onError&&r().createElement(l.InputNumber,{value:e.retryCount,onChange:function(e){return u(o,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100}})))),r().createElement("div",{style:{marginTop:12}},r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Input Mapping (JSON)",r().createElement(l.Tooltip,{title:"Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values."},r().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),r().createElement(_,{value:e.inputMapping,onChange:function(e){return u(o,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),r().createElement("div",{style:{marginTop:12}},r().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},"Condition (optional JSON)",r().createElement(l.Tooltip,{title:'Only run this step if condition matches. Format: { "field": "$step[x].response.y", "op": "eq", "value": "..." }'},r().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),r().createElement(_,{value:e.condition,onChange:function(e){return u(o,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),r().createElement(l.Button,{type:"dashed",icon:r().createElement(a.PlusOutlined,null),onClick:s,style:{marginTop:8,width:"100%"}},"Add Step"))},V=function(){var t,o,i,u,c,s,d=(0,e.useAPIClient)(),p=P((0,n.useState)([]),2),m=p[0],f=p[1],y=P((0,n.useState)([]),2),h=y[0],b=y[1],g=P((0,n.useState)(!1),2),v=g[0],E=g[1],S=P((0,n.useState)(!1),2),w=S[0],O=S[1],I=P(l.Form.useForm(),1)[0],T=P((0,n.useState)(null),2),A=T[0],j=T[1],V=P((0,n.useState)([]),2),H=V[0],W=V[1],L=P((0,n.useState)(!1),2),$=L[0],K=L[1],G=P((0,n.useState)(null),2),Y=G[0],X=G[1],Q=P((0,n.useState)("{}"),2),Z=Q[0],ee=Q[1],et=P((0,n.useState)(""),2),en=et[0],er=et[1],el=P((0,n.useState)(null),2),ea=el[0],eo=el[1],ei=P((0,n.useState)(!1),2),eu=ei[0],ec=ei[1],es=(0,n.useRef)(null),ed=(0,n.useCallback)(k(function(){var e,t,n,r,l;return B(this,function(a){switch(a.label){case 0:E(!0),a.label=1;case 1:return a.trys.push([1,,3,4]),[4,Promise.all([d.request({url:"docUnderstanding:listPipelines"}),d.request({url:"docUnderstanding:listEndpoints"})])];case 2:return r=(n=P.apply(void 0,[a.sent(),2]))[0],l=n[1],f((null==(e=r.data)?void 0:e.data)||[]),b((null==(t=l.data)?void 0:t.data)||[]),[3,4];case 3:return E(!1),[7];case 4:return[2]}})}),[d]);(0,n.useEffect)(function(){ed()},[ed]),(0,n.useEffect)(function(){return function(){es.current&&clearInterval(es.current)}},[]);var ep=function(e){j(e.id),I.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),W(F(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),O(!0)},em=(t=k(function(e){return B(this,function(t){switch(t.label){case 0:return[4,d.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:e}})];case 1:return t.sent(),l.message.success("Deleted"),ed(),[2]}})}),function(e){return t.apply(this,arguments)}),ef=(0,n.useCallback)(function(){es.current&&(clearInterval(es.current),es.current=null)},[]),ey=(0,n.useCallback)((o=k(function(e){var t;return B(this,function(n){switch(n.label){case 0:return[4,d.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:e}})];case 1:return eo(t=q(n.sent())),["completed","failed","timeout"].includes(null==t?void 0:t.status)&&(ef(),ec(!1)),[2,t]}})}),function(e){return o.apply(this,arguments)}),[d,ef]),eh=(0,n.useCallback)(function(e){ef(),es.current=setInterval(function(){ey(e).catch(function(e){ef(),ec(!1),l.message.error((null==e?void 0:e.message)||"Failed to refresh test job")})},1500)},[ey,ef]),eb=function(e){ef(),X(e),eo(null),ec(!1),er(""),ee(z(D(e.inputSchema))),K(!0)},eg=function(){ef(),K(!1),X(null),eo(null),ec(!1)},ev=(i=k(function(){var e,t,n,r,a,o;return B(this,function(i){switch(i.label){case 0:if(!Y)return[2];try{t=Z.trim()?JSON.parse(Z):{},e=U(D(Y.inputSchema),t),er("")}catch(e){return er("Invalid JSON input"),[2]}ef(),ec(!0),eo(null),i.label=1;case 1:return i.trys.push([1,4,,5]),[4,d.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:Y.id,input:e}})];case 2:if(!(r=null==(n=q(i.sent()))?void 0:n.jobId))throw Error("Pipeline did not return a job ID");return[4,ey(r)];case 3:return["completed","failed","timeout"].includes(null==(a=i.sent())?void 0:a.status)||eh(r),l.message.success("Test job #".concat(r," started")),[3,5];case 4:return o=i.sent(),ec(!1),l.message.error((null==o?void 0:o.message)||"Failed to run pipeline test"),[3,5];case 5:return[2]}})}),function(){return i.apply(this,arguments)}),eE=(u=k(function(){var e,t,n,r,a,o,i,u,c;return B(this,function(s){switch(s.label){case 0:return s.trys.push([0,6,,7]),[4,I.validateFields()];case 1:e=s.sent(),t=!0,n=!1,r=void 0;try{for(a=H[Symbol.iterator]();!(t=(o=a.next()).done);t=!0){if(!(i=o.value).name)return l.message.error("All steps must have a name"),[2];if(!i.endpointId)return l.message.error('Step "'.concat(i.name||i.stepOrder,'" must have an endpoint')),[2]}}catch(e){n=!0,r=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw r}}if(new Set(u=H.map(function(e){return e.outputAlias}).filter(Boolean)).size!==u.length)return l.message.error("Step output aliases must be unique"),[2];if(c=C(x({},e),{steps:H.map(function(e){return C(x({},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})})}),!A)return[3,3];return[4,d.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:A},data:c})];case 2:return s.sent(),[3,5];case 3:return[4,d.request({url:"docUnderstanding:createPipeline",method:"POST",data:c})];case 4:s.sent(),s.label=5;case 5:return l.message.success("Saved"),O(!1),ed(),[3,7];case 6:return s.sent(),[3,7];case 7:return[2]}})}),function(){return u.apply(this,arguments)}),eS=[{title:"Name",dataIndex:"name",width:200},{title:"Steps",dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return r().createElement(l.Tag,null,"0 steps");var t=F(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return r().createElement(l.Space,{size:2,wrap:!0},t.map(function(e,t){return r().createElement(r().Fragment,{key:e.id},t>0&&r().createElement("span",{style:{color:"#ccc"}},"→"),r().createElement(l.Tag,null,e.name||"Step ".concat(e.stepOrder)))}))}},{title:"Enabled",dataIndex:"enabled",width:80,render:function(e){return e?r().createElement(l.Tag,{color:"success"},"Yes"):r().createElement(l.Tag,null,"No")}},{title:"AI Tool",width:100,render:function(e,t){var n;return t.enabled?r().createElement(l.Tooltip,{title:"Registered as: doc_understanding.".concat(null==(n=t.name)?void 0:n.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},r().createElement(l.Tag,{color:"blue",icon:r().createElement(a.ThunderboltOutlined,null)},"Active")):r().createElement(l.Tag,null,"Inactive")}},{title:"Action",width:190,render:function(e,t){return r().createElement(l.Space,null,r().createElement(l.Button,{type:"link",size:"small",icon:r().createElement(a.PlayCircleOutlined,null),disabled:!t.enabled,onClick:function(){return eb(t)}},"Test"),r().createElement(l.Button,{type:"link",size:"small",icon:r().createElement(a.EditOutlined,null),onClick:function(){return ep(t)}},"Edit"),r().createElement(l.Popconfirm,{title:"Delete this pipeline?",onConfirm:function(){return em(t.id)}},r().createElement(l.Button,{type:"link",size:"small",danger:!0,icon:r().createElement(a.DeleteOutlined,null)},"Delete")))}}];return r().createElement("div",null,r().createElement("div",{style:{marginBottom:16}},r().createElement(l.Button,{type:"primary",icon:r().createElement(a.PlusOutlined,null),onClick:function(){j(null),I.resetFields(),W([]),O(!0)}},"Add Pipeline")),r().createElement(l.Table,{rowKey:"id",columns:eS,dataSource:m,loading:v,size:"small"}),r().createElement(l.Modal,{title:A?"Edit Pipeline":"New Pipeline",open:w,onOk:eE,onCancel:function(){return O(!1)},width:800,destroyOnClose:!0},r().createElement(l.Form,{form:I,layout:"vertical",preserve:!1},r().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},r().createElement(l.Form.Item,{name:"name",label:"Pipeline Name",rules:[{required:!0}]},r().createElement(l.Input,{placeholder:"full_document_processing"})),r().createElement(l.Form.Item,{name:"enabled",label:"Enabled",valuePropName:"checked",initialValue:!0},r().createElement(l.Switch,null))),r().createElement(l.Form.Item,{name:"description",label:"Description"},r().createElement(R,{rows:2,placeholder:"What this pipeline does"})),r().createElement(l.Card,{title:"Pipeline Steps",size:"small",style:{marginBottom:16},extra:r().createElement(l.Tag,{color:"blue"},H.length," step(s)")},r().createElement(J,{steps:H,endpoints:h,onChange:W})),r().createElement(l.Collapse,{size:"small",ghost:!0},r().createElement(N,{header:"Advanced: Input Schema & Output Mapping",key:"advanced"},r().createElement(l.Form.Item,{name:"inputSchema",label:"Input Schema (JSON Schema)",help:"Defines what input this pipeline accepts. Used by AI tool schema."},r().createElement(_,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),r().createElement(l.Form.Item,{name:"outputMapping",label:"Output Mapping (JSON)",help:"Map final step results to pipeline output. If empty, all step results are returned."},r().createElement(_,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),r().createElement(l.Modal,{title:Y?"Test Playground: ".concat(Y.name):"Test Playground",open:$,onCancel:eg,width:860,destroyOnClose:!0,footer:[r().createElement(l.Button,{key:"close",onClick:eg},"Close"),(null==ea?void 0:ea.id)&&r().createElement(l.Button,{key:"refresh",icon:r().createElement(a.ReloadOutlined,null),disabled:eu,onClick:function(){return ey(ea.id)}},"Refresh"),r().createElement(l.Button,{key:"run",type:"primary",icon:r().createElement(a.PlayCircleOutlined,null),loading:eu,onClick:ev},"Run test")].filter(Boolean)},r().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},r().createElement("div",null,r().createElement("div",{style:{fontWeight:500,marginBottom:6}},"Input JSON"),r().createElement(R,{rows:16,value:Z,onChange:function(e){ee(e.target.value),en&&er("")},placeholder:'{ "document_url": "https://..." }',style:{fontFamily:"monospace",fontSize:12}}),en&&r().createElement(l.Alert,{type:"error",showIcon:!0,message:en,style:{marginTop:8}}),r().createElement(l.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},r().createElement(N,{header:"Input Schema",key:"schema"},r().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},z(null==Y?void 0:Y.inputSchema))))),r().createElement("div",null,r().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},r().createElement("span",{style:{fontWeight:500}},"Result"),(null==ea?void 0:ea.status)&&r().createElement(l.Tag,{color:(null==(c=M[ea.status])?void 0:c.color)||"default"},(null==(s=M[ea.status])?void 0:s.label)||ea.status)),ea?r().createElement("div",null,r().createElement(l.Space,{style:{marginBottom:8},wrap:!0},r().createElement(l.Tag,null,"Job #",ea.id),ea.currentStep&&r().createElement(l.Tag,null,"Step ",ea.currentStep)),ea.error&&r().createElement(l.Alert,{type:"error",showIcon:!0,message:"Pipeline error",description:r().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},ea.error),style:{marginBottom:12}}),r().createElement("div",{style:{fontWeight:500,marginBottom:4}},"Final Result"),r().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==ea.finalResult&&null!==ea.finalResult?z(ea.finalResult):"(not yet available)"),r().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},"Step Results"),r().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},ea.stepResults?z(ea.stepResults):"{}")):r().createElement(l.Empty,{description:"Run a test to see job output",imageStyle:{height:48}})))))};function H(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 W(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 L(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){W(a,r,l,o,i,"next",e)}function i(e){W(a,r,l,o,i,"throw",e)}o(void 0)})}}function $(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"undefined"!=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 H(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 H(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 K(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}var G={pending:{color:"default",label:"Pending"},running:{color:"processing",label:"Running"},polling:{color:"processing",label:"Polling"},completed:{color:"success",label:"Completed"},failed:{color:"error",label:"Failed"},timeout:{color:"error",label:"Timeout"}},Y=function(){var t,o,i=(0,e.useAPIClient)(),u=$((0,n.useState)([]),2),c=u[0],s=u[1],d=$((0,n.useState)([]),2),p=d[0],m=d[1],f=$((0,n.useState)(!1),2),y=f[0],h=f[1],b=$((0,n.useState)(!1),2),g=b[0],v=b[1],E=$((0,n.useState)(null),2),S=E[0],w=E[1],O=$((0,n.useState)(void 0),2),I=O[0],k=O[1],T=$((0,n.useState)(void 0),2),x=T[0],C=T[1],P=(0,n.useCallback)(L(function(){var e,t;return K(this,function(n){switch(n.label){case 0:h(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},I&&(t.status=I),x&&(t.pipelineId=x),[4,i.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s((null==(e=n.sent().data)?void 0:e.data)||[]),[3,4];case 3:return h(!1),[7];case 4:return[2]}})}),[i,I,x]),F=(0,n.useCallback)(L(function(){var e;return K(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,i.request({url:"docUnderstanding:listPipelines"})];case 1:return m((null==(e=t.sent().data)?void 0:e.data)||[]),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})}),[i]);(0,n.useEffect)(function(){F()},[F]),(0,n.useEffect)(function(){P();var e=setInterval(P,1e4);return function(){return clearInterval(e)}},[P]);var A=new Map(p.map(function(e){return[e.id,e.name]})),j=(t=L(function(e){var t;return K(this,function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,i.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:e.id}})];case 1:return w((null==(t=n.sent().data)?void 0:t.data)||e),[3,3];case 2:return n.sent(),w(e),[3,3];case 3:return v(!0),[2]}})}),function(e){return t.apply(this,arguments)}),B=[{title:"ID",dataIndex:"id",width:60},{title:"Pipeline",dataIndex:"pipelineId",width:180,render:function(e){return A.get(e)||"#".concat(e)}},{title:"Status",dataIndex:"status",width:100,render:function(e){var t=G[e]||{color:"default",label:e};return r().createElement(l.Tag,{color:t.color},t.label)}},{title:"Current Step",dataIndex:"currentStep",width:90,render:function(e,t){return"completed"===t.status?r().createElement(l.Tag,{color:"success"},"Done"):"failed"===t.status?r().createElement(l.Tag,{color:"error"},"Step ",e):r().createElement(l.Badge,{status:"processing",text:"Step ".concat(e)})}},{title:"Started",dataIndex:"startedAt",width:160,render:function(e){return e?new Date(e).toLocaleString():"-"}},{title:"Completed",dataIndex:"completedAt",width:160,render:function(e){return e?new Date(e).toLocaleString():"-"}},{title:"Action",width:80,render:function(e,t){return r().createElement(l.Button,{size:"small",icon:r().createElement(a.EyeOutlined,null),onClick:function(){return j(t)}},"View")}}];return r().createElement("div",null,r().createElement(l.Space,{style:{marginBottom:16},wrap:!0},r().createElement(l.Select,{allowClear:!0,placeholder:"Filter by status",value:I,onChange:k,style:{width:160},options:Object.entries(G).map(function(e){var t=$(e,2);return{value:t[0],label:t[1].label}})}),r().createElement(l.Select,{allowClear:!0,placeholder:"Filter by pipeline",value:x,onChange:C,style:{width:200},options:p.map(function(e){return{value:e.id,label:e.name}})}),r().createElement(l.Button,{icon:r().createElement(a.ReloadOutlined,null),onClick:P},"Refresh")),r().createElement(l.Table,{rowKey:"id",columns:B,dataSource:c,loading:y,size:"small",pagination:{pageSize:20}}),r().createElement(l.Drawer,{title:S?"Job #".concat(S.id," — ").concat(A.get(S.pipelineId)||"Unknown"):"Job Details",width:640,open:g,onClose:function(){return v(!1)}},S&&r().createElement("div",null,r().createElement("div",{style:{marginBottom:16}},r().createElement(l.Space,null,r().createElement(l.Tag,{color:null==(o=G[S.status])?void 0:o.color},S.status),S.startedAt&&r().createElement("span",null,"Started: ",new Date(S.startedAt).toLocaleString()),S.completedAt&&r().createElement("span",null,"Completed: ",new Date(S.completedAt).toLocaleString()))),S.error&&r().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},r().createElement("strong",{style:{color:"#cf1322"}},"Error:"),r().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},S.error)),r().createElement("h4",null,"Input"),r().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(S.input,null,2)),r().createElement("h4",{style:{marginTop:16}},"Step Results"),S.stepResults&&Object.keys(S.stepResults).length>0?Object.entries(S.stepResults).map(function(e){var t=$(e,2),n=t[0],a=t[1];return r().createElement("div",{key:n,style:{marginBottom:8}},r().createElement(l.Tag,{color:"blue"},n),r().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(a,null,2)))}):r().createElement("div",{style:{color:"#999"}},"No step results yet"),r().createElement("h4",{style:{marginTop:16}},"Final Result"),r().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},S.finalResult?JSON.stringify(S.finalResult,null,2):"(not yet available)"),S.externalTaskIds&&Object.keys(S.externalTaskIds).length>0&&r().createElement(r().Fragment,null,r().createElement("h4",{style:{marginTop:16}},"External Task IDs"),r().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(S.externalTaskIds,null,2))))))},X=function(){return r().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:"100vh"}},r().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},r().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},"Document Understanding - Pipeline Orchestrator")),r().createElement("div",{style:{padding:"0 24px 24px"}},r().createElement(l.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:"Service Config",children:r().createElement(d,null)},{key:"endpoints",label:"Endpoints",children:r().createElement(w,null)},{key:"pipelines",label:"Pipelines",children:r().createElement(V,null)},{key:"jobs",label:"Jobs history",children:r().createElement(Y,null)}]})))};function Q(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 Z(e,t,n){return(Z=er()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var l=new(Function.bind.apply(e,r));return n&&et(l,n.prototype),l}).apply(null,arguments)}function ee(e){return(ee=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function et(e,t){return(et=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function en(e){var t="function"==typeof Map?new Map:void 0;return(en=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 Z(e,arguments,ee(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),et(n,e)})(e)}function er(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(er=function(){return!!e})()}var el=function(e){var n;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=ee(e),function(e,t){var n;if(t&&("object"==((n=t)&&"undefined"!=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,er()?Reflect.construct(e,t||[],ee(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&et(r,e),n=[{key:"load",value:function(){var e,n=this;return(e=function(){var e;return function(e,t){var n,r,l,a,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]};return a={next:i(0),throw:i(1),return:i(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function i(a){return function(i){var u=[a,i];if(n)throw TypeError("Generator is already executing.");for(;o;)try{if(n=1,r&&(l=2&u[0]?r.return:u[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,u[1])).done)return l;switch(r=0,l&&(u=[2&u[0],l.value]),u[0]){case 0:case 1:l=u;break;case 4:return o.label++,{value:u[1],done:!1};case 5:o.label++,r=u[1],u=[0];continue;case 7:u=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===u[0]||2===u[0])){o=0;continue}if(3===u[0]&&(!l||u[1]>l[0]&&u[1]<l[3])){o.label=u[1];break}if(6===u[0]&&o.label<l[1]){o.label=l[1],l=u;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(u);break}l[2]&&o.ops.pop(),o.trys.pop();continue}u=t.call(e,o)}catch(e){u=[6,e],r=0}finally{n=l=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}(this,function(r){return null==(e=n.flowEngine)||e.registerModels(t),n.app.pluginSettingsManager.add("document-understanding",{title:n.t("Document Understanding"),icon:"FileSearchOutlined",Component:X,aclSnippet:"pm.document-understanding"}),[2]})},function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Q(a,r,l,o,i,"next",e)}function i(e){Q(a,r,l,o,i,"throw",e)}o(void 0)})})()}}],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)}}(r.prototype,n),r}(en(e.Plugin))}(),i}()});
@@ -8,13 +8,13 @@
8
8
  */
9
9
 
10
10
  module.exports = {
11
- "@nocobase/flow-engine": "2.0.49",
12
- "@nocobase/client": "2.0.49",
13
- "@nocobase/actions": "2.0.49",
14
- "@nocobase/server": "2.0.49",
11
+ "@nocobase/flow-engine": "2.0.55",
12
+ "@nocobase/client": "2.0.55",
13
+ "@nocobase/actions": "2.0.55",
14
+ "@nocobase/server": "2.0.55",
15
15
  "react": "18.2.0",
16
16
  "antd": "5.24.2",
17
17
  "@ant-design/icons": "5.6.1",
18
- "@nocobase/database": "2.0.49",
19
- "axios": "1.16.0"
18
+ "@nocobase/database": "2.0.55",
19
+ "axios": "1.16.1"
20
20
  };
@@ -85,12 +85,45 @@ const defineActions = (plugin) => {
85
85
  await next();
86
86
  },
87
87
  async executePipeline(ctx, next) {
88
- var _a, _b;
88
+ var _a, _b, _c;
89
89
  const { values } = ctx.action.params;
90
90
  const pipelineId = values == null ? void 0 : values.pipelineId;
91
91
  const input = (values == null ? void 0 : values.input) || {};
92
92
  const userId = (_b = (_a = ctx.state) == null ? void 0 : _a.currentUser) == null ? void 0 : _b.id;
93
- ctx.body = await service.executePipeline(pipelineId, input, [], userId);
93
+ const multipartFiles = [];
94
+ const filesObj = ctx.request.files || ((_c = ctx.request.body) == null ? void 0 : _c.files);
95
+ if (filesObj) {
96
+ const addFile = (key, file) => {
97
+ const filePath = file.path || file.filepath;
98
+ const fileName = file.name || file.originalFilename || "file";
99
+ const mimeType = file.type || file.mimetype || "application/octet-stream";
100
+ if (filePath) {
101
+ try {
102
+ const buffer = require("fs").readFileSync(filePath);
103
+ multipartFiles.push({
104
+ fieldName: key,
105
+ buffer,
106
+ filename: fileName,
107
+ mimeType
108
+ });
109
+ } catch (err) {
110
+ console.error("Failed to read uploaded multipart file:", err);
111
+ }
112
+ }
113
+ };
114
+ if (typeof filesObj === "object") {
115
+ for (const [key, value] of Object.entries(filesObj)) {
116
+ if (Array.isArray(value)) {
117
+ for (const f of value) {
118
+ addFile(key, f);
119
+ }
120
+ } else {
121
+ addFile(key, value);
122
+ }
123
+ }
124
+ }
125
+ }
126
+ ctx.body = await service.executePipeline(pipelineId, input, multipartFiles, userId);
94
127
  await next();
95
128
  },
96
129
  async getJobStatus(ctx, next) {
@@ -106,8 +139,19 @@ const defineActions = (plugin) => {
106
139
  async webhookCallback(ctx, next) {
107
140
  const signature = ctx.request.headers["x-webhook-signature"];
108
141
  const { values } = ctx.action.params;
109
- await service.handleWebhook(values || ctx.request.body, signature);
110
- ctx.body = { received: true };
142
+ try {
143
+ await service.handleWebhook(values || ctx.request.body, signature);
144
+ ctx.body = { received: true };
145
+ } catch (err) {
146
+ console.error("Webhook callback error:", err.message);
147
+ if (err.message.includes("signature")) {
148
+ ctx.status = 401;
149
+ ctx.body = { error: err.message };
150
+ } else {
151
+ ctx.status = 400;
152
+ ctx.body = { error: err.message };
153
+ }
154
+ }
111
155
  await next();
112
156
  }
113
157
  };
@@ -40,6 +40,7 @@ var endpoints_default = {
40
40
  { type: "json", name: "requestBodySchema" },
41
41
  { type: "json", name: "responseSchema" },
42
42
  { type: "string", name: "fileInputMode", length: 20 },
43
+ { type: "string", name: "fileFieldName", length: 100, defaultValue: "file" },
43
44
  { type: "integer", name: "maxFiles", defaultValue: 1 },
44
45
  { type: "string", name: "executionMode", length: 20 },
45
46
  { type: "string", name: "pollResultSubpath", length: 500 },
@@ -1,9 +1,6 @@
1
1
  import { Plugin } from '@nocobase/server';
2
2
  import { DocumentUnderstandingService } from './services/DocumentUnderstandingService';
3
3
  export declare class PluginDocumentUnderstandingServer extends Plugin {
4
- app: any;
5
- db: any;
6
- name: string;
7
4
  service: DocumentUnderstandingService;
8
5
  afterAdd(): Promise<void>;
9
6
  beforeLoad(): Promise<void>;
@@ -12,6 +12,10 @@ export declare class AsyncJobManager {
12
12
  onJobError: (jobId: number, error: string) => Promise<void>;
13
13
  });
14
14
  startPolling(jobId: number, endpoint: EndpointDef, taskId: string, customInterval?: number, customTimeout?: number): Promise<void>;
15
+ /**
16
+ * Transition pending and running jobs to failed state during startup.
17
+ */
18
+ cleanupStuckJobs(): Promise<void>;
15
19
  /**
16
20
  * Recover polling jobs that were in-flight when server restarted.
17
21
  * Call this during service initialization.
@@ -79,6 +79,27 @@ class AsyncJobManager {
79
79
  }, interval);
80
80
  this.intervals.set(jobId, timer);
81
81
  }
82
+ /**
83
+ * Transition pending and running jobs to failed state during startup.
84
+ */
85
+ async cleanupStuckJobs() {
86
+ const jobsRepo = this.db.getRepository("doc_understanding_jobs");
87
+ const stuckJobs = await jobsRepo.find({
88
+ filter: {
89
+ status: ["pending", "running"]
90
+ }
91
+ });
92
+ for (const job of stuckJobs) {
93
+ await jobsRepo.update({
94
+ filterByTk: job.id,
95
+ values: {
96
+ status: "failed",
97
+ error: "Server restarted during execution",
98
+ completedAt: /* @__PURE__ */ new Date()
99
+ }
100
+ });
101
+ }
102
+ }
82
103
  /**
83
104
  * Recover polling jobs that were in-flight when server restarted.
84
105
  * Call this during service initialization.
@@ -84,6 +84,7 @@ class DocumentUnderstandingService {
84
84
  }
85
85
  });
86
86
  this.pipelineExecutor = new import_PipelineExecutor.PipelineExecutor(this.db, this.apiClient, this.jobManager);
87
+ await this.jobManager.cleanupStuckJobs();
87
88
  await this.jobManager.recoverPollingJobs();
88
89
  this.initialized = true;
89
90
  }
@@ -13,6 +13,7 @@ export declare class PipelineExecutor {
13
13
  private apiClient;
14
14
  private jobManager;
15
15
  constructor(db: Database, apiClient: ExternalApiClient, jobManager: AsyncJobManager);
16
+ private resolveFile;
16
17
  execute(pipelineId: number, input: Record<string, any>, files?: FileInput[], userId?: number): Promise<JobState>;
17
18
  private runSteps;
18
19
  resumeFromStep(jobId: number, asyncResult: any): Promise<void>;
@@ -38,6 +38,126 @@ class PipelineExecutor {
38
38
  this.apiClient = apiClient;
39
39
  this.jobManager = jobManager;
40
40
  }
41
+ async resolveFile(urlOrPath, fieldName = "file") {
42
+ if (!urlOrPath || typeof urlOrPath !== "string") return null;
43
+ try {
44
+ let isLocal = false;
45
+ let absolutePath = "";
46
+ if (urlOrPath.startsWith("/") || urlOrPath.startsWith("storage/") || urlOrPath.includes("/uploads/")) {
47
+ let cleanedPath = urlOrPath;
48
+ if (urlOrPath.startsWith("/")) {
49
+ cleanedPath = urlOrPath.slice(1);
50
+ }
51
+ const pathOptions = [
52
+ require("path").resolve(process.cwd(), cleanedPath),
53
+ require("path").resolve(process.cwd(), "storage", cleanedPath),
54
+ require("path").resolve(process.cwd(), "storage/uploads", cleanedPath.replace(/^uploads\//, ""))
55
+ ];
56
+ for (const p of pathOptions) {
57
+ if (require("fs").existsSync(p) && require("fs").statSync(p).isFile()) {
58
+ isLocal = true;
59
+ absolutePath = p;
60
+ break;
61
+ }
62
+ }
63
+ }
64
+ if (isLocal) {
65
+ const fs = require("fs");
66
+ const path = require("path");
67
+ const buffer = fs.readFileSync(absolutePath);
68
+ const filename = path.basename(absolutePath);
69
+ let mimeLookup = (filePath) => "application/octet-stream";
70
+ try {
71
+ const mime = require("mime-types");
72
+ mimeLookup = (filePath) => mime.lookup(filePath) || "application/octet-stream";
73
+ } catch (e) {
74
+ mimeLookup = (filePath) => {
75
+ const ext = path.extname(filePath).toLowerCase();
76
+ const map = {
77
+ ".pdf": "application/pdf",
78
+ ".doc": "application/msword",
79
+ ".docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
80
+ ".xls": "application/vnd.ms-excel",
81
+ ".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
82
+ ".png": "image/png",
83
+ ".jpg": "image/jpeg",
84
+ ".jpeg": "image/jpeg",
85
+ ".txt": "text/plain",
86
+ ".json": "application/json"
87
+ };
88
+ return map[ext] || "application/octet-stream";
89
+ };
90
+ }
91
+ const mimeType = mimeLookup(absolutePath);
92
+ return {
93
+ fieldName,
94
+ buffer,
95
+ filename,
96
+ mimeType
97
+ };
98
+ }
99
+ if (urlOrPath.startsWith("http://") || urlOrPath.startsWith("https://")) {
100
+ const axios = require("axios");
101
+ const path = require("path");
102
+ const response = await axios.get(urlOrPath, { responseType: "arraybuffer" });
103
+ const buffer = Buffer.from(response.data);
104
+ let filename = "file";
105
+ const disposition = response.headers["content-disposition"];
106
+ if (disposition && disposition.includes("filename=")) {
107
+ const match = disposition.match(/filename="?([^";]+)"?/);
108
+ if (match && match[1]) {
109
+ filename = match[1];
110
+ }
111
+ } else {
112
+ try {
113
+ const urlObj = new URL(urlOrPath);
114
+ const base = path.basename(urlObj.pathname);
115
+ if (base && base.includes(".")) {
116
+ filename = base;
117
+ }
118
+ } catch (e) {
119
+ }
120
+ }
121
+ const contentType = response.headers["content-type"] || "application/octet-stream";
122
+ const mimeType = contentType.split(";")[0].trim();
123
+ if (!filename.includes(".")) {
124
+ let mimeExtension = (mime) => "";
125
+ try {
126
+ const mimeLib = require("mime-types");
127
+ mimeExtension = (mime) => mimeLib.extension(mime) || "";
128
+ } catch (e) {
129
+ mimeExtension = (mime) => {
130
+ const map = {
131
+ "application/pdf": "pdf",
132
+ "application/msword": "doc",
133
+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
134
+ "application/vnd.ms-excel": "xls",
135
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
136
+ "image/png": "png",
137
+ "image/jpeg": "jpg",
138
+ "text/plain": "txt",
139
+ "application/json": "json"
140
+ };
141
+ return map[mime] || "";
142
+ };
143
+ }
144
+ const ext = mimeExtension(mimeType);
145
+ if (ext) {
146
+ filename = `${filename}.${ext}`;
147
+ }
148
+ }
149
+ return {
150
+ fieldName,
151
+ buffer,
152
+ filename,
153
+ mimeType
154
+ };
155
+ }
156
+ } catch (err) {
157
+ console.error(`Failed to resolve file URL/path "${urlOrPath}":`, err.message);
158
+ }
159
+ return null;
160
+ }
41
161
  async execute(pipelineId, input, files = [], userId) {
42
162
  const pipelineRepo = this.db.getRepository("doc_understanding_pipelines");
43
163
  const jobsRepo = this.db.getRepository("doc_understanding_jobs");
@@ -59,9 +179,63 @@ class PipelineExecutor {
59
179
  createdById: userId
60
180
  }
61
181
  });
182
+ const resolvedFiles = [];
183
+ const tryAddFile = async (urlOrPath, fieldName = "file") => {
184
+ const resolved = await this.resolveFile(urlOrPath, fieldName);
185
+ if (resolved) {
186
+ resolvedFiles.push(resolved);
187
+ }
188
+ };
189
+ if (Array.isArray(files)) {
190
+ for (const f of files) {
191
+ if (f && typeof f === "object") {
192
+ if (f.buffer) {
193
+ resolvedFiles.push(f);
194
+ } else if (f.url) {
195
+ await tryAddFile(f.url, f.fieldName || "file");
196
+ }
197
+ }
198
+ }
199
+ }
200
+ const urlFields = ["file_url", "file_urls", "file", "files"];
201
+ for (const key of urlFields) {
202
+ const val = input[key];
203
+ if (!val) continue;
204
+ if (typeof val === "string") {
205
+ if (val.startsWith("http://") || val.startsWith("https://") || val.startsWith("/") || val.startsWith("storage/")) {
206
+ await tryAddFile(val, "file");
207
+ } else if (val.includes(",")) {
208
+ const urls = val.split(",").map((s) => s.trim());
209
+ for (const u of urls) {
210
+ if (u.startsWith("http://") || u.startsWith("https://") || u.startsWith("/") || u.startsWith("storage/")) {
211
+ await tryAddFile(u, "file");
212
+ }
213
+ }
214
+ }
215
+ } else if (Array.isArray(val)) {
216
+ for (const item of val) {
217
+ if (typeof item === "string") {
218
+ if (item.startsWith("http://") || item.startsWith("https://") || item.startsWith("/") || item.startsWith("storage/")) {
219
+ await tryAddFile(item, "file");
220
+ }
221
+ } else if (item && typeof item === "object" && item.url) {
222
+ await tryAddFile(item.url, "file");
223
+ }
224
+ }
225
+ } else if (val && typeof val === "object" && val.url) {
226
+ await tryAddFile(val.url, "file");
227
+ }
228
+ }
229
+ if (resolvedFiles.length === 0 && files && files.length > 0) {
230
+ for (const f of files) {
231
+ if (f.buffer) {
232
+ resolvedFiles.push(f);
233
+ }
234
+ }
235
+ }
62
236
  const context = {
63
237
  input,
64
- files,
238
+ files: resolvedFiles,
65
239
  stepResults: {},
66
240
  jobId: job.id
67
241
  };
@@ -90,10 +264,15 @@ class PipelineExecutor {
90
264
  let lastError = null;
91
265
  while (retries >= 0 && !success) {
92
266
  try {
267
+ const fileFieldName = step.endpoint.fileFieldName || "file";
268
+ const mappedFiles = context.files ? context.files.map((f) => ({
269
+ ...f,
270
+ fieldName: fileFieldName
271
+ })) : [];
93
272
  const result = await this.apiClient.call({
94
273
  endpoint: step.endpoint,
95
274
  body: mappedBody,
96
- files: context.files
275
+ files: mappedFiles
97
276
  });
98
277
  if (step.endpoint.executionMode === "sync") {
99
278
  context.stepResults[step.outputAlias || step.stepOrder.toString()] = result.data;
@@ -19,6 +19,7 @@ export interface EndpointDef {
19
19
  requestBodySchema?: any;
20
20
  responseSchema?: any;
21
21
  fileInputMode: 'none' | 'multipart' | 'base64';
22
+ fileFieldName?: string;
22
23
  maxFiles: number;
23
24
  executionMode: 'sync' | 'polling' | 'webhook';
24
25
  pollResultSubpath?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plugin-document-understanding",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "main": "dist/server/index.js",
5
5
  "dependencies": {
6
6
  "axios": "^1.6.0"
@@ -13,4 +13,4 @@
13
13
  "@nocobase/plugin-ai": "2.x",
14
14
  "@langchain/core": "^0.3.0"
15
15
  }
16
- }
16
+ }