plugin-document-understanding 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/345.e6e484fb1974c3d3.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/345.a8f28526ac21e02a.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +7 -7
- package/dist/locale/en-US.json +182 -171
- package/dist/locale/vi-VN.json +182 -171
- package/dist/locale/zh-CN.json +182 -171
- package/dist/node_modules/form-data/lib/form_data.js +3 -3
- package/dist/node_modules/form-data/package.json +1 -1
- package/dist/server/collections/endpoints.js +5 -0
- package/dist/server/collections/jobs.js +13 -0
- package/dist/server/dugate-seed.js +411 -0
- package/dist/server/plugin.js +6 -0
- package/dist/server/services/AsyncJobManager.js +87 -31
- package/dist/server/services/DocumentUnderstandingService.js +48 -5
- package/dist/server/services/ExternalApiClient.js +38 -5
- package/dist/server/services/PipelineExecutor.js +115 -36
- package/package.json +1 -1
- package/src/client-v2/components/EndpointsTab.tsx +51 -0
- package/src/locale/en-US.json +182 -171
- package/src/locale/vi-VN.json +182 -171
- package/src/locale/zh-CN.json +182 -171
- package/src/server/__tests__/cluster-safety.test.ts +259 -0
- package/src/server/__tests__/dugate-integration.test.ts +221 -0
- package/src/server/collections/endpoints.ts +5 -0
- package/src/server/collections/jobs.ts +13 -0
- package/src/server/dugate-seed.ts +491 -0
- package/src/server/plugin.ts +143 -134
- package/src/server/services/AsyncJobManager.ts +98 -32
- package/src/server/services/DocumentUnderstandingService.ts +50 -4
- package/src/server/services/ExternalApiClient.ts +40 -5
- package/src/server/services/PipelineExecutor.ts +593 -477
- package/src/server/types.ts +90 -78
- package/dist/client/345.17f88ffb846ec69b.js +0 -10
- package/dist/client-v2/345.1e0c321d30702aa1.js +0 -10
package/src/server/types.ts
CHANGED
|
@@ -1,78 +1,90 @@
|
|
|
1
|
-
export interface ServiceConfig {
|
|
2
|
-
id?: number;
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
authType: 'api_key' | 'bearer' | 'custom_header' | 'none';
|
|
5
|
-
authKey?: string;
|
|
6
|
-
authHeaderName?: string;
|
|
7
|
-
defaultTimeout: number;
|
|
8
|
-
defaultRetries: number;
|
|
9
|
-
pollInterval: number;
|
|
10
|
-
pollTimeout: number;
|
|
11
|
-
webhookSecret?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type ClientServiceConfig = Omit<ServiceConfig, 'authKey' | 'webhookSecret'> & {
|
|
15
|
-
hasAuthKey: boolean;
|
|
16
|
-
hasWebhookSecret: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export interface EndpointDef {
|
|
20
|
-
id: number;
|
|
21
|
-
name: string;
|
|
22
|
-
subpath: string;
|
|
23
|
-
method: 'GET' | 'POST' | 'PUT';
|
|
24
|
-
description?: string;
|
|
25
|
-
requestBodySchema?: any;
|
|
26
|
-
responseSchema?: any;
|
|
27
|
-
fileInputMode: 'none' | 'multipart' | 'base64';
|
|
28
|
-
fileFieldName?: string;
|
|
29
|
-
maxFiles: number;
|
|
30
|
-
executionMode: 'sync' | 'polling' | 'webhook';
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface
|
|
67
|
-
id: number;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
export interface ServiceConfig {
|
|
2
|
+
id?: number;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
authType: 'api_key' | 'bearer' | 'custom_header' | 'none';
|
|
5
|
+
authKey?: string;
|
|
6
|
+
authHeaderName?: string;
|
|
7
|
+
defaultTimeout: number;
|
|
8
|
+
defaultRetries: number;
|
|
9
|
+
pollInterval: number;
|
|
10
|
+
pollTimeout: number;
|
|
11
|
+
webhookSecret?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ClientServiceConfig = Omit<ServiceConfig, 'authKey' | 'webhookSecret'> & {
|
|
15
|
+
hasAuthKey: boolean;
|
|
16
|
+
hasWebhookSecret: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export interface EndpointDef {
|
|
20
|
+
id: number;
|
|
21
|
+
name: string;
|
|
22
|
+
subpath: string;
|
|
23
|
+
method: 'GET' | 'POST' | 'PUT';
|
|
24
|
+
description?: string;
|
|
25
|
+
requestBodySchema?: any;
|
|
26
|
+
responseSchema?: any;
|
|
27
|
+
fileInputMode: 'none' | 'multipart' | 'base64';
|
|
28
|
+
fileFieldName?: string;
|
|
29
|
+
maxFiles: number;
|
|
30
|
+
executionMode: 'sync' | 'polling' | 'webhook';
|
|
31
|
+
/** Discriminator field name sent in the request body/query (e.g. DUGate 'mode'/'type'/'task'/'action'/'process'). */
|
|
32
|
+
discriminatorField?: string;
|
|
33
|
+
/** Discriminator value for this endpoint (e.g. DUGate 'parse', 'invoice', 'disbursement'). */
|
|
34
|
+
discriminatorValue?: string;
|
|
35
|
+
/** When set, the request also appends '?sync=true' (DUGate synchronous mode). */
|
|
36
|
+
syncQueryParam?: string;
|
|
37
|
+
/** For 'sync' mode: DUGate returns 202 with a task ID. Extract the task ID with this path (e.g. 'name') or regex. */
|
|
38
|
+
taskIdExtractPath?: string;
|
|
39
|
+
/** For 'sync' mode: regex used to extract the task ID from a string field (e.g. 'operations/([^/]+)'). */
|
|
40
|
+
taskIdExtractRegex?: string;
|
|
41
|
+
pollResultSubpath?: string;
|
|
42
|
+
pollTaskIdField?: string;
|
|
43
|
+
pollResultField?: string;
|
|
44
|
+
pollInterval?: number;
|
|
45
|
+
pollTimeout?: number;
|
|
46
|
+
pollStatusField?: string;
|
|
47
|
+
pollCompletedValue?: string;
|
|
48
|
+
customHeaders?: Record<string, string>;
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PipelineStepDef {
|
|
53
|
+
id: number;
|
|
54
|
+
pipelineId: number;
|
|
55
|
+
endpointId: number;
|
|
56
|
+
stepOrder: number;
|
|
57
|
+
name: string;
|
|
58
|
+
inputMapping?: Record<string, any>;
|
|
59
|
+
outputAlias?: string;
|
|
60
|
+
condition?: any;
|
|
61
|
+
onError: 'fail' | 'skip' | 'retry';
|
|
62
|
+
retryCount: number;
|
|
63
|
+
endpoint: EndpointDef; // Associated endpoint
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface PipelineDef {
|
|
67
|
+
id: number;
|
|
68
|
+
name: string;
|
|
69
|
+
description?: string;
|
|
70
|
+
inputSchema?: any;
|
|
71
|
+
outputMapping?: Record<string, any>;
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
steps: PipelineStepDef[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface JobState {
|
|
77
|
+
id: number;
|
|
78
|
+
pipelineId: number;
|
|
79
|
+
status: 'pending' | 'running' | 'polling' | 'completed' | 'failed' | 'timeout';
|
|
80
|
+
input: any;
|
|
81
|
+
currentStep: number;
|
|
82
|
+
stepResults: Record<string, any>;
|
|
83
|
+
finalResult?: any;
|
|
84
|
+
error?: string;
|
|
85
|
+
externalTaskIds: Record<string, string>;
|
|
86
|
+
startedAt?: Date;
|
|
87
|
+
completedAt?: Date;
|
|
88
|
+
ownedBy?: string;
|
|
89
|
+
leaseExpiresAt?: Date | null;
|
|
90
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
"use strict";(self.webpackChunkplugin_document_understanding=self.webpackChunkplugin_document_understanding||[]).push([["345"],{824:function(e,t,n){n.r(t),n.d(t,{PluginSettings:function(){return ea},default:function(){return eo}});var r=n(155),l=n.n(r),a=n(59),o=n(694),i=JSON.parse('{"UU":"plugin-document-understanding"}');function u(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[i.UU,"client"]})}}var c=n(375);function s(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e,t){var n,r;return e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"?null!=(n=null==(r=e.data)?void 0:r.data)?n:t:t}function d(e){return s(e,Error)?e.message:String(e)}function p(e){if(!e)return"-";var t=s(e,Date)?e:new Date(e);return Number.isNaN(t.getTime())?"-":t.toLocaleString()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=function(){var e=b(a.Form.useForm(),1)[0],t=(0,o.useFlowContext)().api,n=u(),i=b((0,r.useState)(!0),2),s=i[0],p=i[1],f=b((0,r.useState)(!1),2),y=f[0],E=f[1],v=b((0,r.useState)(),2),S=v[0],w=v[1];return((0,r.useEffect)(function(){var n=!1;return h(function(){var r,l;return g(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,3,4]),[4,t.request({url:"docUnderstanding:getConfig"})];case 1:if(r=a.sent(),n)return[2];return e.setFieldsValue(m(r,{})),[3,4];case 2:return l=a.sent(),n||w(d(l)),[3,4];case 3:return n||p(!1),[7];case 4:return[2]}})})(),function(){n=!0}},[t,e]),s)?l().createElement(a.Spin,{style:{marginTop:40}}):l().createElement(a.Form,{form:e,layout:"vertical",onFinish:function(e){return h(function(){var r;return g(this,function(l){switch(l.label){case 0:E(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,t.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return l.sent(),a.message.success(n("Configuration saved successfully")),[3,5];case 3:return r=l.sent(),a.message.error("".concat(n("Failed to save config"),": ").concat(d(r))),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})()},style:{maxWidth:600}},S&&l().createElement(a.Alert,{message:S,type:"error",showIcon:!0,style:{marginBottom:16}}),l().createElement(a.Alert,{message:n("Service Connection"),description:n("Configure the connection to your external document processing service"),type:"info",showIcon:!0,style:{marginBottom:24}}),l().createElement(a.Form.Item,{name:"baseUrl",label:n("Base URL"),rules:[{required:!0,message:n("Base URL is required")}],help:n("The root URL of your document processing API")},l().createElement(a.Input,{prefix:l().createElement(c.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),l().createElement(a.Form.Item,{name:"authType",label:n("Authentication Type"),initialValue:"none"},l().createElement(a.Select,{options:[{value:"none",label:n("None")},{value:"api_key",label:n("API Key")},{value:"bearer",label:n("Bearer Token")},{value:"custom_header",label:n("Custom Header")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var t=e.getFieldValue("authType");return"none"===t?null:l().createElement(l().Fragment,null,"custom_header"===t&&l().createElement(a.Form.Item,{name:"authHeaderName",label:n("Custom Header Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"X-Api-Key"})),l().createElement(a.Form.Item,{name:"authKey",label:"bearer"===t?n("Bearer Token"):n("API Key"),rules:[{required:!0}]},l().createElement(a.Input.Password,{placeholder:n("Enter key or token")})))}),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"defaultTimeout",label:n("Request Timeout (ms)"),initialValue:3e4},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"defaultRetries",label:n("Default Retries"),initialValue:2},l().createElement(a.InputNumber,{style:{width:"100%"},min:0,max:10})),l().createElement(a.Form.Item,{name:"pollInterval",label:n("Poll Interval (ms)"),initialValue:5e3},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"pollTimeout",label:n("Poll Timeout (ms)"),initialValue:3e5},l().createElement(a.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),l().createElement(a.Form.Item,{name:"webhookSecret",label:n("Webhook Secret"),help:n("Used to verify HMAC-SHA256 signatures on incoming webhook callbacks")},l().createElement(a.Input.Password,{placeholder:n("Optional: secret for webhook signature verification")})),l().createElement(a.Form.Item,null,l().createElement(a.Button,{type:"primary",htmlType:"submit",icon:l().createElement(c.SaveOutlined,null),loading:y},n("Save Configuration"))))};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function S(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){S(a,r,l,o,i,"next",e)}function i(e){S(a,r,l,o,i,"throw",e)}o(void 0)})}}function O(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||k(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||k(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}function T(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var C=a.Input.TextArea,F=function(e){var t=e.value,n=e.onChange,o=u(),i=O((0,r.useState)([]),2),s=i[0],m=i[1],d=(0,r.useRef)(),p=JSON.stringify(null!=t?t:{});(0,r.useEffect)(function(){d.current!==p&&(d.current=p,m(Object.entries(JSON.parse(p)).map(function(e,t){var n=O(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}})))},[p]);var f=function(e){m(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=JSON.stringify(t),null==n||n(t)},y=function(e,t,n){var r,l,a=I(s);a[e]=(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},a[e]),l=l={key:t,value:n},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(l)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),f(a)},h=function(e){f(s.filter(function(t,n){return n!==e}))};return l().createElement("div",null,s.map(function(e,t){return l().createElement(a.Space,{key:e.id,style:{display:"flex",marginBottom:4}},l().createElement(a.Input,{placeholder:o("Header name"),"aria-label":o("Header name"),value:e.key,onChange:function(n){return y(t,n.target.value,e.value)},style:{width:180}}),l().createElement(a.Input,{placeholder:o("Value"),"aria-label":o("Value"),value:e.value,onChange:function(n){return y(t,e.key,n.target.value)},style:{width:220}}),l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),onClick:function(){return h(t)},"aria-label":"".concat(o("Delete")," ").concat(e.key||o("Header name"))}))}),l().createElement(a.Button,{size:"small",type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:function(){return m(I(s).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},o("Add Header")))},x=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=u(),i=O((0,r.useState)(""),2),c=i[0],s=i[1],m=O((0,r.useState)(""),2),d=m[0],p=m[1];return(0,r.useEffect)(function(){if(!t)return void s("");try{s("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){s("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(C,{rows:6,value:c,onChange:function(e){return s(e.target.value)},onBlur:function(){if(!c.trim()){p(""),null==n||n(null);return}try{var e=JSON.parse(c);p(""),null==n||n(e)}catch(e){p(o("Invalid JSON"))}},placeholder:a||"{}",status:d?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),d&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},d))},P=function(){var e=(0,o.useFlowContext)().api,t=u(),n=O((0,r.useState)([]),2),i=n[0],s=n[1],d=O((0,r.useState)(!1),2),p=d[0],f=d[1],y=O((0,r.useState)(!1),2),h=y[0],b=y[1],g=O(a.Form.useForm(),1)[0],E=O((0,r.useState)(null),2),v=E[0],S=E[1],I={sync:t("Synchronous"),polling:t("Polling"),webhook:t("Webhook")},k={multipart:t("Multipart Upload"),base64:t("Base64 in JSON")},P=(0,r.useCallback)(function(){return w(function(){return T(this,function(t){switch(t.label){case 0:f(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,e.request({url:"docUnderstanding:listEndpoints"})];case 2:return s(m(t.sent(),[])),[3,4];case 3:return f(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){P()},[P]);var A=function(e){S(e.id),g.setFieldsValue(e),b(!0)},j=[{title:t("Name"),dataIndex:"name",width:150},{title:t("Subpath"),dataIndex:"subpath",width:200},{title:t("Method"),dataIndex:"method",width:80,render:function(e){return l().createElement(a.Tag,null,e)}},{title:t("Execution"),dataIndex:"executionMode",width:130,render:function(e){return l().createElement(a.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},I[e]||e)}},{title:t("File"),dataIndex:"fileInputMode",width:130,render:function(e){return"none"===e?"-":k[e]||e}},{title:t("Enabled"),dataIndex:"enabled",width:70,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("Action"),width:120,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return A(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this endpoint?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,w(function(){return T(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),P(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){S(null),g.resetFields(),b(!0)}},t("Add Endpoint"))),l().createElement(a.Table,{rowKey:"id",columns:j,dataSource:i,loading:p,size:"small"}),l().createElement(a.Modal,{title:v?t("Edit Endpoint"):t("Add Endpoint"),open:h,onOk:function(){return w(function(){var n;return T(this,function(r){switch(r.label){case 0:return r.trys.push([0,6,,7]),[4,g.validateFields()];case 1:if((n=r.sent()).customHeaders=Object.entries(n.customHeaders||{}).reduce(function(e,t){var n=O(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{}),!v)return[3,3];return[4,e.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:v},data:n})];case 2:return r.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createEndpoint",method:"POST",data:n})];case 4:r.sent(),r.label=5;case 5:return a.message.success(t("Saved")),b(!1),P(),[3,7];case 6:return r.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return b(!1)},okText:t("Save"),cancelText:t("Cancel"),width:680,destroyOnClose:!0},l().createElement(a.Form,{form:g,layout:"vertical",preserve:!1},l().createElement(a.Tabs,{size:"small",items:[{key:"basic",label:t("Basic"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"name",label:t("Unique Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"ocr, classify, extract..."})),l().createElement(a.Form.Item,{name:"subpath",label:t("Subpath"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"/api/v1/ocr"})),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(C,{rows:2,placeholder:t("What this endpoint does")})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"method",label:t("HTTP Method"),initialValue:"POST"},l().createElement(a.Select,{style:{width:120},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"}]})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))))},{key:"file",label:t("File Input"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileInputMode",label:t("File Input Mode"),initialValue:"none"},l().createElement(a.Select,{style:{width:200},options:[{value:"none",label:t("None")},{value:"multipart",label:t("Multipart Upload")},{value:"base64",label:t("Base64 in JSON")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==g.getFieldValue("fileInputMode")?l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileFieldName",label:t("File Field Name"),initialValue:"file"},l().createElement(a.Input,{placeholder:"file",style:{width:200}})),l().createElement(a.Form.Item,{name:"maxFiles",label:t("Max Files"),initialValue:1},l().createElement(a.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"async",label:t("Async Config"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"executionMode",label:t("Execution Mode"),initialValue:"sync"},l().createElement(a.Select,{style:{width:200},options:[{value:"sync",label:t("Synchronous")},{value:"polling",label:t("Polling")},{value:"webhook",label:t("Webhook")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=g.getFieldValue("executionMode");return"sync"===e?null:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollTaskIdField",label:t("Task ID Field"),help:t("Field in response containing the async task ID"),initialValue:"task_id"},l().createElement(a.Input,{placeholder:"task_id"})),"polling"===e&&l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollResultSubpath",label:t("Poll Result Subpath"),help:t("URL to poll for result. Use {taskId} as placeholder."),rules:[{required:!0,message:t("Required for polling mode")}]},l().createElement(a.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),l().createElement(a.Form.Item,{name:"pollResultField",label:t("Result Field"),help:t("Field in poll response containing the actual result")},l().createElement(a.Input,{placeholder:"result"})),l().createElement(a.Form.Item,{name:"pollStatusField",label:t("Status Field (optional)"),help:t("Field to check completion status. If empty, any non-null result = complete.")},l().createElement(a.Input,{placeholder:"status"})),l().createElement(a.Form.Item,{name:"pollCompletedValue",label:t("Completed Value"),help:t("Value of status field that means 'done'"),initialValue:"completed"},l().createElement(a.Input,{placeholder:"completed"})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"pollInterval",label:t("Poll Interval (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),l().createElement(a.Form.Item,{name:"pollTimeout",label:t("Poll Timeout (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:t("Schema"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"requestBodySchema",label:t("Request Body Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})),l().createElement(a.Form.Item,{name:"responseSchema",label:t("Response Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:t("Custom Headers"),children:l().createElement(a.Form.Item,{name:"customHeaders",label:t("Additional Headers")},l().createElement(F,null))}]}))))};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){j(a,r,l,o,i,"next",e)}function i(e){j(a,r,l,o,i,"throw",e)}o(void 0)})}}function N(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){N(e,t,n[t])})}return e}function M(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function D(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||z(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||z(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e,t){if(e){if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}}function J(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var _=a.Input.TextArea,q=a.Collapse.Panel,V={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},H=["completed","failed","timeout"],W=function(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)},$=function(e){return JSON.stringify(null!=e?e:{},null,2)},K=function(e){return W(e)?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=D(t,2),r=n[0],l=K(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},L=function(e,t){return W(e)&&W(t)?Object.entries(e).reduce(function(e,t){var n=D(t,2),r=n[0],l=n[1];return M(R({},e),N({},r,L(l,e[r])))},R({},t)):void 0===t?e:t},G=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=e.rows,i=u(),c=D((0,r.useState)(""),2),s=c[0],m=c[1],d=D((0,r.useState)(""),2),p=d[0],f=d[1];return(0,r.useEffect)(function(){if(!t)return void m("");try{m("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){m("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(_,{rows:void 0===o?5:o,value:s,onChange:function(e){return m(e.target.value)},onBlur:function(){if(!s.trim()){f(""),null==n||n(null);return}try{var e=JSON.parse(s);f(""),null==n||n(e)}catch(e){f(i("Invalid JSON"))}},placeholder:a||"{}",status:p?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),p&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},p))},Y=function(e){var t=e.steps,n=e.endpoints,r=e.onChange,o=u(),i=function(e,n){var l,a=U(t),o=e+n;o<0||o>=a.length||(l=[a[o],a[e]],a[e]=l[0],a[o]=l[1],a.forEach(function(e,t){return e.stepOrder=t+1}),r(a))},s=function(e,n,l){var a=U(t);a[e]=M(R({},a[e]),N({},n,l)),r(a)},m=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),r(n)},d=function(){var e;r(U(t).concat([(e=t.length+1,{_key:"new_".concat(Date.now(),"_").concat(Math.random()),stepOrder:e,name:"",endpointId:null,inputMapping:null,outputAlias:"",condition:null,onError:"fail",retryCount:0})]))};return 0===t.length?l().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},l().createElement(a.Empty,{description:o("No steps yet"),imageStyle:{height:40}}),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8}},o("Add First Step"))):l().createElement("div",null,l().createElement(a.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,r){var u=n.find(function(t){return t.id===e.endpointId}),d=l().createElement(a.Space,{size:4,onClick:function(e){return e.stopPropagation()}},l().createElement(a.Button,{size:"small",disabled:0===r,icon:l().createElement(c.ArrowUpOutlined,null),onClick:function(){return i(r,-1)},"aria-label":o("Move step up")}),l().createElement(a.Button,{size:"small",disabled:r===t.length-1,icon:l().createElement(c.ArrowDownOutlined,null),onClick:function(){return i(r,1)},"aria-label":o("Move step down")}),l().createElement(a.Popconfirm,{title:o("Remove step?"),okText:o("Delete"),onConfirm:function(){return m(r)}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":o("Remove step?")}))),p=l().createElement(a.Space,null,l().createElement(a.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),l().createElement("span",null,e.name||o("(unnamed)")),u&&l().createElement(a.Tag,null,u.name),"skip"===e.onError&&l().createElement(a.Tooltip,{title:o("Step can be skipped on error")},l().createElement(a.Tag,{color:"orange"},o("skip on error"))),e.condition&&l().createElement(a.Tooltip,{title:o("Has condition")},l().createElement(a.Tag,{color:"purple"},o("conditional")))),f="step-name-".concat(e._key),y="step-endpoint-".concat(e._key),h="step-alias-".concat(e._key);return l().createElement(q,{key:e._key,header:p,extra:d},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement("div",null,l().createElement("label",{htmlFor:f,style:{fontWeight:500,display:"block",marginBottom:4}},o("Step Name")," *"),l().createElement(a.Input,{id:f,value:e.name,onChange:function(e){return s(r,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),l().createElement("div",null,l().createElement("label",{htmlFor:y,style:{fontWeight:500,display:"block",marginBottom:4}},o("Endpoint")," *"),l().createElement(a.Select,{id:y,value:e.endpointId,onChange:function(e){return s(r,"endpointId",e)},placeholder:o("Select endpoint"),style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),l().createElement("div",null,l().createElement("label",{htmlFor:h,style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("Output Alias")),l().createElement(a.Input,{id:h,value:e.outputAlias,onChange:function(e){return s(r,"outputAlias",e.target.value)},placeholder:"ocr_result"}),l().createElement("div",{style:{color:"#888",fontSize:11}},o("Other steps reference this as"),": $step[",e.outputAlias||e.stepOrder,"].response.field")),l().createElement("div",null,l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("On Error")),l().createElement(a.Space,null,l().createElement(a.Select,{value:e.onError,onChange:function(e){return s(r,"onError",e)},style:{width:120},"aria-label":o("On Error"),options:[{value:"fail",label:o("Fail")},{value:"skip",label:o("Skip")},{value:"retry",label:o("Retry")}]}),"retry"===e.onError&&l().createElement(a.InputNumber,{value:e.retryCount,onChange:function(e){return s(r,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100},"aria-label":o("Retry")})))),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Input Mapping (JSON)"),l().createElement(a.Tooltip,{title:o("Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.inputMapping,onChange:function(e){return s(r,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Condition (optional JSON)"),l().createElement(a.Tooltip,{title:o("Only run this step if the condition matches.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.condition,onChange:function(e){return s(r,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8,width:"100%"}},o("Add Step")))},X=function(){var e=(0,o.useFlowContext)().api,t=u(),n=D((0,r.useState)([]),2),i=n[0],s=n[1],p=D((0,r.useState)([]),2),f=p[0],y=p[1],h=D((0,r.useState)(!1),2),b=h[0],g=h[1],E=D((0,r.useState)(!1),2),v=E[0],S=E[1],w=D(a.Form.useForm(),1)[0],O=D((0,r.useState)(null),2),I=O[0],k=O[1],T=D((0,r.useState)([]),2),C=T[0],F=T[1],x=D((0,r.useState)(!1),2),P=x[0],A=x[1],j=D((0,r.useState)(null),2),N=j[0],z=j[1],W=D((0,r.useState)("{}"),2),X=W[0],Q=W[1],Z=D((0,r.useState)(""),2),ee=Z[0],et=Z[1],en=D((0,r.useState)(null),2),er=en[0],el=en[1],ea=D((0,r.useState)(!1),2),eo=ea[0],ei=ea[1],eu=(0,r.useRef)(null),ec={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},es=(0,r.useCallback)(function(){return B(function(){var t,n,r;return J(this,function(l){switch(l.label){case 0:g(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,Promise.all([e.request({url:"docUnderstanding:listPipelines"}),e.request({url:"docUnderstanding:listEndpoints"})])];case 2:return n=(t=D.apply(void 0,[l.sent(),2]))[0],r=t[1],s(m(n,[])),y(m(r,[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){es()},[es]),(0,r.useEffect)(function(){return function(){eu.current&&clearInterval(eu.current)}},[]);var em=function(e){k(e.id),w.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),F(U(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){var t;return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:null!=(t=e.inputMapping)?t:null,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),S(!0)},ed=(0,r.useCallback)(function(){eu.current&&(clearInterval(eu.current),eu.current=null)},[]),ep=(0,r.useCallback)(function(t){return B(function(){var n;return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:t}})];case 1:return el(n=m(r.sent(),null)),n&&H.includes(n.status)&&(ed(),ei(!1)),[2,n]}})})()},[e,ed]),ef=(0,r.useCallback)(function(e){ed(),eu.current=setInterval(function(){ep(e).catch(function(e){ed(),ei(!1),a.message.error(d(e)||t("Failed to refresh test job"))})},1500)},[ep,ed,t]),ey=function(e){ed(),z(e),el(null),ei(!1),et(""),Q($(K(e.inputSchema))),A(!0)},eh=function(){ed(),A(!1),z(null),el(null),ei(!1)},eb=[{title:t("Name"),dataIndex:"name",width:200},{title:t("Steps"),dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return l().createElement(a.Tag,null,"0 ",t("steps"));var n=U(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return l().createElement(a.Space,{size:2,wrap:!0},n.map(function(e,n){return l().createElement(l().Fragment,{key:e.id},n>0&&l().createElement("span",{style:{color:"#ccc"}},"→"),l().createElement(a.Tag,null,e.name||"".concat(t("Step")," ").concat(e.stepOrder)))}))}},{title:t("Enabled"),dataIndex:"enabled",width:80,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("AI Tool"),width:100,render:function(e,n){var r;return n.enabled?l().createElement(a.Tooltip,{title:"".concat(t("Registered as"),": doc_understanding.").concat(null==(r=n.name)?void 0:r.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},l().createElement(a.Tag,{color:"blue",icon:l().createElement(c.ThunderboltOutlined,null)},t("Active"))):l().createElement(a.Tag,null,t("Inactive"))}},{title:t("Action"),width:190,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.PlayCircleOutlined,null),disabled:!r.enabled,onClick:function(){return ey(r)},"aria-label":"".concat(t("Test")," ").concat(r.name)},t("Test")),l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return em(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this pipeline?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,B(function(){return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),es(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){k(null),w.resetFields(),F([]),S(!0)}},t("Add Pipeline"))),l().createElement(a.Table,{rowKey:"id",columns:eb,dataSource:i,loading:b,size:"small"}),l().createElement(a.Modal,{title:I?t("Edit Pipeline"):t("New Pipeline"),open:v,onOk:function(){return B(function(){var n,r,l,o,i,u,c,s,m;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,6,,7]),[4,w.validateFields()];case 1:n=d.sent(),r=!0,l=!1,o=void 0;try{for(i=C[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){if(!(c=u.value).name)return a.message.error(t("All steps must have a name")),[2];if(!c.endpointId)return a.message.error("".concat(t("Step"),' "').concat(c.name||c.stepOrder,'" ').concat(t("must have an endpoint"))),[2]}}catch(e){l=!0,o=e}finally{try{r||null==i.return||i.return()}finally{if(l)throw o}}if(new Set(s=C.map(function(e){return e.outputAlias}).filter(Boolean)).size!==s.length)return a.message.error(t("Step output aliases must be unique")),[2];if(m=M(R({},n),{steps:C.map(function(e){return M(R({},e.id?{id:e.id}:{}),{stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||void 0,condition:e.condition,onError:e.onError,retryCount:"retry"===e.onError?e.retryCount:0})})}),!I)return[3,3];return[4,e.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:I},data:m})];case 2:return d.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createPipeline",method:"POST",data:m})];case 4:d.sent(),d.label=5;case 5:return a.message.success(t("Saved")),S(!1),es(),[3,7];case 6:return d.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return S(!1)},okText:t("Save"),cancelText:t("Cancel"),width:800,destroyOnClose:!0},l().createElement(a.Form,{form:w,layout:"vertical",preserve:!1},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"name",label:t("Pipeline Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"full_document_processing"})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(_,{rows:2,placeholder:t("What this pipeline does")})),l().createElement(a.Card,{title:t("Pipeline Steps"),size:"small",style:{marginBottom:16},extra:l().createElement(a.Tag,{color:"blue"},C.length," ",t("step(s)"))},l().createElement(Y,{steps:C,endpoints:f,onChange:F})),l().createElement(a.Collapse,{size:"small",ghost:!0},l().createElement(q,{header:t("Advanced: Input Schema & Output Mapping"),key:"advanced"},l().createElement(a.Form.Item,{name:"inputSchema",label:t("Input Schema (JSON Schema)"),help:t("Defines what input this pipeline accepts. Used by AI tool schema.")},l().createElement(G,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),l().createElement(a.Form.Item,{name:"outputMapping",label:t("Output Mapping (JSON)"),help:t("Map final step results to pipeline output. If empty, all step results are returned.")},l().createElement(G,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),l().createElement(a.Modal,{title:N?"".concat(t("Test Playground"),": ").concat(N.name):t("Test Playground"),open:P,onCancel:eh,width:860,destroyOnClose:!0,footer:[l().createElement(a.Button,{key:"close",onClick:eh},t("Close")),(null==er?void 0:er.id)&&l().createElement(a.Button,{key:"refresh",icon:l().createElement(c.ReloadOutlined,null),disabled:eo,onClick:function(){return ep(er.id)}},t("Refresh")),l().createElement(a.Button,{key:"run",type:"primary",icon:l().createElement(c.PlayCircleOutlined,null),loading:eo,onClick:function(){return B(function(){var n,r,l,o,i;return J(this,function(u){switch(u.label){case 0:if(!N)return[2];try{r=X.trim()?JSON.parse(X):{},n=L(K(N.inputSchema),r),et("")}catch(e){return et(t("Invalid JSON input")),[2]}ed(),ei(!0),el(null),u.label=1;case 1:return u.trys.push([1,4,,5]),[4,e.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:N.id,input:n}})];case 2:if(!(l=m(u.sent(),{}).jobId))throw Error(t("Pipeline did not return a job ID"));return[4,ep(l)];case 3:return(o=u.sent())&&H.includes(o.status)||ef(l),a.message.success("".concat(t("Test job started"),": #").concat(l)),[3,5];case 4:return i=u.sent(),ei(!1),a.message.error(d(i)||t("Failed to run pipeline test")),[3,5];case 5:return[2]}})})()}},t("Run test"))].filter(Boolean)},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},l().createElement("div",null,l().createElement("label",{htmlFor:"playground-input",style:{fontWeight:500,marginBottom:6,display:"block"}},t("Input JSON")),l().createElement(_,{id:"playground-input",rows:16,value:X,onChange:function(e){Q(e.target.value),ee&&et("")},placeholder:'{ "document_url": "https://..." }',status:ee?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),ee&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:ee,style:{marginTop:8}}),l().createElement(a.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},l().createElement(q,{header:t("Input Schema"),key:"schema"},l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},$(null==N?void 0:N.inputSchema))))),l().createElement("div",null,l().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},l().createElement("span",{style:{fontWeight:500}},t("Result")),(null==er?void 0:er.status)&&l().createElement(a.Tag,{color:V[er.status]||"default"},ec[er.status]||er.status)),er?l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:8},wrap:!0},l().createElement(a.Tag,null,t("Job")," #",er.id),er.currentStep&&l().createElement(a.Tag,null,t("Step")," ",er.currentStep)),er.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:t("Pipeline error"),description:l().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},er.error),style:{marginBottom:12}}),l().createElement("div",{style:{fontWeight:500,marginBottom:4}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==er.finalResult&&null!==er.finalResult?$(er.finalResult):t("(not yet available)")),l().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},t("Step Results")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},er.stepResults?$(er.stepResults):"{}")):l().createElement(a.Empty,{description:t("Run a test to see job output"),imageStyle:{height:48}})))))};function Q(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function ee(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Z(a,r,l,o,i,"next",e)}function i(e){Z(a,r,l,o,i,"throw",e)}o(void 0)})}}function et(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return Q(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 Q(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function en(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var er={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},el=function(){var e=(0,o.useFlowContext)().api,t=u(),n=et((0,r.useState)([]),2),i=n[0],s=n[1],d=et((0,r.useState)([]),2),f=d[0],y=d[1],h=et((0,r.useState)(!1),2),b=h[0],g=h[1],E=et((0,r.useState)(!1),2),v=E[0],S=E[1],w=et((0,r.useState)(null),2),O=w[0],I=w[1],k=et((0,r.useState)(void 0),2),T=k[0],C=k[1],F=et((0,r.useState)(void 0),2),x=F[0],P=F[1],A={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},j=(0,r.useCallback)(function(){return ee(function(){var t;return en(this,function(n){switch(n.label){case 0:g(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},T&&(t.status=T),x&&(t.pipelineId=x),[4,e.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s(m(n.sent(),[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e,T,x]),B=(0,r.useCallback)(function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:listPipelines"})];case 1:return y(m(t.sent(),[])),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})})()},[e]);(0,r.useEffect)(function(){B()},[B]),(0,r.useEffect)(function(){j();var e=setInterval(j,1e4);return function(){return clearInterval(e)}},[j]);var N=new Map(f.map(function(e){return[e.id,e.name]})),R=[{title:t("ID"),dataIndex:"id",width:60},{title:t("Pipeline"),dataIndex:"pipelineId",width:180,render:function(e){return N.get(e)||"#".concat(e)}},{title:t("Status"),dataIndex:"status",width:100,render:function(e){return l().createElement(a.Tag,{color:er[e]||"default"},A[e]||e)}},{title:t("Current Step"),dataIndex:"currentStep",width:90,render:function(e,n){return"completed"===n.status?l().createElement(a.Tag,{color:"success"},t("Done")):"failed"===n.status?l().createElement(a.Tag,{color:"error"},"".concat(t("Step")," ").concat(e)):l().createElement(a.Badge,{status:"processing",text:"".concat(t("Step")," ").concat(e)})}},{title:t("Started"),dataIndex:"startedAt",width:160,render:function(e){return p(e)}},{title:t("Completed"),dataIndex:"completedAt",width:160,render:function(e){return p(e)}},{title:t("Action"),width:80,render:function(n,r){return l().createElement(a.Button,{size:"small",icon:l().createElement(c.EyeOutlined,null),onClick:function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:r.id}})];case 1:return I(m(t.sent(),r)),[3,3];case 2:return t.sent(),I(r),[3,3];case 3:return S(!0),[2]}})})()},"aria-label":"".concat(t("View")," #").concat(r.id)},t("View"))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by status"),"aria-label":t("Filter by status"),value:T,onChange:C,style:{width:160},options:Object.keys(er).map(function(e){return{value:e,label:A[e]}})}),l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by pipeline"),"aria-label":t("Filter by pipeline"),value:x,onChange:P,style:{width:200},options:f.map(function(e){return{value:e.id,label:e.name}})}),l().createElement(a.Button,{icon:l().createElement(c.ReloadOutlined,null),onClick:j},t("Refresh"))),l().createElement(a.Table,{rowKey:"id",columns:R,dataSource:i,loading:b,size:"small",pagination:{pageSize:20}}),l().createElement(a.Drawer,{title:O?"".concat(t("Job")," #").concat(O.id," — ").concat(N.get(O.pipelineId)||t("Unknown")):t("Job Details"),width:640,open:v,onClose:function(){return S(!1)}},O&&l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Space,{wrap:!0},l().createElement(a.Tag,{color:er[O.status]||"default"},A[O.status]||O.status),O.startedAt&&l().createElement("span",null,t("Started"),": ",p(O.startedAt)),O.completedAt&&l().createElement("span",null,t("Completed"),": ",p(O.completedAt)))),O.error&&l().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},l().createElement("strong",{style:{color:"#cf1322"}},t("Error"),":"),l().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},O.error)),l().createElement("h4",null,t("Input")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(O.input,null,2)),l().createElement("h4",{style:{marginTop:16}},t("Step Results")),O.stepResults&&Object.keys(O.stepResults).length>0?Object.entries(O.stepResults).map(function(e){var t=et(e,2),n=t[0],r=t[1];return l().createElement("div",{key:n,style:{marginBottom:8}},l().createElement(a.Tag,{color:"blue"},n),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(r,null,2)))}):l().createElement("div",{style:{color:"#999"}},t("No step results yet")),l().createElement("h4",{style:{marginTop:16}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},O.finalResult?JSON.stringify(O.finalResult,null,2):t("(not yet available)")),O.externalTaskIds&&Object.keys(O.externalTaskIds).length>0&&l().createElement(l().Fragment,null,l().createElement("h4",{style:{marginTop:16}},t("External Task IDs")),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(O.externalTaskIds,null,2))))))},ea=function(){var e=u();return l().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:"100vh"}},l().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},l().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},e("Document Understanding - Pipeline Orchestrator"))),l().createElement("div",{style:{padding:"0 24px 24px"}},l().createElement(a.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:e("Service Config"),children:l().createElement(E,null)},{key:"endpoints",label:e("Endpoints"),children:l().createElement(P,null)},{key:"pipelines",label:e("Pipelines"),children:l().createElement(X,null)},{key:"jobs",label:e("Jobs history"),children:l().createElement(el,null)}]})))},eo=ea}}]);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
"use strict";(self.webpackChunkplugin_document_understanding_client_v2=self.webpackChunkplugin_document_understanding_client_v2||[]).push([["345"],{824:function(e,t,n){n.r(t),n.d(t,{PluginSettings:function(){return ea},default:function(){return eo}});var r=n(155),l=n.n(r),a=n(59),o=n(694),i=JSON.parse('{"UU":"plugin-document-understanding"}');function u(){var e=(0,o.useFlowEngine)();return function(t){return e.context.t(t,{ns:[i.UU,"client"]})}}var c=n(375);function s(e,t){return null!=t&&"u">typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function m(e,t){var n,r;return e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"?null!=(n=null==(r=e.data)?void 0:r.data)?n:t:t}function d(e){return s(e,Error)?e.message:String(e)}function p(e){if(!e)return"-";var t=s(e,Date)?e:new Date(e);return Number.isNaN(t.getTime())?"-":t.toLocaleString()}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function y(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function h(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){y(a,r,l,o,i,"next",e)}function i(e){y(a,r,l,o,i,"throw",e)}o(void 0)})}}function b(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return f(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return f(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function g(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var E=function(){var e=b(a.Form.useForm(),1)[0],t=(0,o.useFlowContext)().api,n=u(),i=b((0,r.useState)(!0),2),s=i[0],p=i[1],f=b((0,r.useState)(!1),2),y=f[0],E=f[1],v=b((0,r.useState)(),2),S=v[0],w=v[1];return((0,r.useEffect)(function(){var n=!1;return h(function(){var r,l;return g(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,3,4]),[4,t.request({url:"docUnderstanding:getConfig"})];case 1:if(r=a.sent(),n)return[2];return e.setFieldsValue(m(r,{})),[3,4];case 2:return l=a.sent(),n||w(d(l)),[3,4];case 3:return n||p(!1),[7];case 4:return[2]}})})(),function(){n=!0}},[t,e]),s)?l().createElement(a.Spin,{style:{marginTop:40}}):l().createElement(a.Form,{form:e,layout:"vertical",onFinish:function(e){return h(function(){var r;return g(this,function(l){switch(l.label){case 0:E(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,t.request({url:"docUnderstanding:updateConfig",method:"POST",data:e})];case 2:return l.sent(),a.message.success(n("Configuration saved successfully")),[3,5];case 3:return r=l.sent(),a.message.error("".concat(n("Failed to save config"),": ").concat(d(r))),[3,5];case 4:return E(!1),[7];case 5:return[2]}})})()},style:{maxWidth:600}},S&&l().createElement(a.Alert,{message:S,type:"error",showIcon:!0,style:{marginBottom:16}}),l().createElement(a.Alert,{message:n("Service Connection"),description:n("Configure the connection to your external document processing service"),type:"info",showIcon:!0,style:{marginBottom:24}}),l().createElement(a.Form.Item,{name:"baseUrl",label:n("Base URL"),rules:[{required:!0,message:n("Base URL is required")}],help:n("The root URL of your document processing API")},l().createElement(a.Input,{prefix:l().createElement(c.LinkOutlined,null),placeholder:"http://my-ocr-service:8000"})),l().createElement(a.Form.Item,{name:"authType",label:n("Authentication Type"),initialValue:"none"},l().createElement(a.Select,{options:[{value:"none",label:n("None")},{value:"api_key",label:n("API Key")},{value:"bearer",label:n("Bearer Token")},{value:"custom_header",label:n("Custom Header")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["authType"]},function(){var t=e.getFieldValue("authType");return"none"===t?null:l().createElement(l().Fragment,null,"custom_header"===t&&l().createElement(a.Form.Item,{name:"authHeaderName",label:n("Custom Header Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"X-Api-Key"})),l().createElement(a.Form.Item,{name:"authKey",label:"bearer"===t?n("Bearer Token"):n("API Key"),rules:[{required:!0}]},l().createElement(a.Input.Password,{placeholder:n("Enter key or token")})))}),l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"defaultTimeout",label:n("Request Timeout (ms)"),initialValue:3e4},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"defaultRetries",label:n("Default Retries"),initialValue:2},l().createElement(a.InputNumber,{style:{width:"100%"},min:0,max:10})),l().createElement(a.Form.Item,{name:"pollInterval",label:n("Poll Interval (ms)"),initialValue:5e3},l().createElement(a.InputNumber,{style:{width:"100%"},min:1e3,step:1e3})),l().createElement(a.Form.Item,{name:"pollTimeout",label:n("Poll Timeout (ms)"),initialValue:3e5},l().createElement(a.InputNumber,{style:{width:"100%"},min:5e3,step:5e3}))),l().createElement(a.Form.Item,{name:"webhookSecret",label:n("Webhook Secret"),help:n("Used to verify HMAC-SHA256 signatures on incoming webhook callbacks")},l().createElement(a.Input.Password,{placeholder:n("Optional: secret for webhook signature verification")})),l().createElement(a.Form.Item,null,l().createElement(a.Button,{type:"primary",htmlType:"submit",icon:l().createElement(c.SaveOutlined,null),loading:y},n("Save Configuration"))))};function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function S(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function w(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){S(a,r,l,o,i,"next",e)}function i(e){S(a,r,l,o,i,"throw",e)}o(void 0)})}}function O(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||k(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function I(e){return function(e){if(Array.isArray(e))return v(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||k(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function k(e,t){if(e){if("string"==typeof e)return v(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return v(e,t)}}function T(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var C=a.Input.TextArea,F=function(e){var t=e.value,n=e.onChange,o=u(),i=O((0,r.useState)([]),2),s=i[0],m=i[1],d=(0,r.useRef)(),p=JSON.stringify(null!=t?t:{});(0,r.useEffect)(function(){d.current!==p&&(d.current=p,m(Object.entries(JSON.parse(p)).map(function(e,t){var n=O(e,2),r=n[0],l=n[1];return{id:"".concat(r,"_").concat(t),key:r,value:String(null!=l?l:"")}})))},[p]);var f=function(e){m(e);var t=e.reduce(function(e,t){var n=t.key.trim();return n&&(e[n]=t.value),e},{});d.current=JSON.stringify(t),null==n||n(t)},y=function(e,t,n){var r,l,a=I(s);a[e]=(r=function(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){var r;r=n[t],t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r})}return e}({},a[e]),l=l={key:t,value:n},Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(l)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(l)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(l,e))}),r),f(a)},h=function(e){f(s.filter(function(t,n){return n!==e}))};return l().createElement("div",null,s.map(function(e,t){return l().createElement(a.Space,{key:e.id,style:{display:"flex",marginBottom:4}},l().createElement(a.Input,{placeholder:o("Header name"),"aria-label":o("Header name"),value:e.key,onChange:function(n){return y(t,n.target.value,e.value)},style:{width:180}}),l().createElement(a.Input,{placeholder:o("Value"),"aria-label":o("Value"),value:e.value,onChange:function(n){return y(t,e.key,n.target.value)},style:{width:220}}),l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),onClick:function(){return h(t)},"aria-label":"".concat(o("Delete")," ").concat(e.key||o("Header name"))}))}),l().createElement(a.Button,{size:"small",type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:function(){return m(I(s).concat([{id:"new_".concat(Date.now(),"_").concat(Math.random()),key:"",value:""}]))}},o("Add Header")))},x=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=u(),i=O((0,r.useState)(""),2),c=i[0],s=i[1],m=O((0,r.useState)(""),2),d=m[0],p=m[1];return(0,r.useEffect)(function(){if(!t)return void s("");try{s("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){s("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(C,{rows:6,value:c,onChange:function(e){return s(e.target.value)},onBlur:function(){if(!c.trim()){p(""),null==n||n(null);return}try{var e=JSON.parse(c);p(""),null==n||n(e)}catch(e){p(o("Invalid JSON"))}},placeholder:a||"{}",status:d?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),d&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},d))},P=function(){var e=(0,o.useFlowContext)().api,t=u(),n=O((0,r.useState)([]),2),i=n[0],s=n[1],d=O((0,r.useState)(!1),2),p=d[0],f=d[1],y=O((0,r.useState)(!1),2),h=y[0],b=y[1],g=O(a.Form.useForm(),1)[0],E=O((0,r.useState)(null),2),v=E[0],S=E[1],I={sync:t("Synchronous"),polling:t("Polling"),webhook:t("Webhook")},k={multipart:t("Multipart Upload"),base64:t("Base64 in JSON")},P=(0,r.useCallback)(function(){return w(function(){return T(this,function(t){switch(t.label){case 0:f(!0),t.label=1;case 1:return t.trys.push([1,,3,4]),[4,e.request({url:"docUnderstanding:listEndpoints"})];case 2:return s(m(t.sent(),[])),[3,4];case 3:return f(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){P()},[P]);var A=function(e){S(e.id),g.setFieldsValue(e),b(!0)},j=[{title:t("Name"),dataIndex:"name",width:150},{title:t("Subpath"),dataIndex:"subpath",width:200},{title:t("Method"),dataIndex:"method",width:80,render:function(e){return l().createElement(a.Tag,null,e)}},{title:t("Execution"),dataIndex:"executionMode",width:130,render:function(e){return l().createElement(a.Tag,{color:{sync:"green",polling:"blue",webhook:"purple"}[e]},I[e]||e)}},{title:t("File"),dataIndex:"fileInputMode",width:130,render:function(e){return"none"===e?"-":k[e]||e}},{title:t("Enabled"),dataIndex:"enabled",width:70,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("Action"),width:120,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return A(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this endpoint?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,w(function(){return T(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deleteEndpoint",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),P(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){S(null),g.resetFields(),b(!0)}},t("Add Endpoint"))),l().createElement(a.Table,{rowKey:"id",columns:j,dataSource:i,loading:p,size:"small"}),l().createElement(a.Modal,{title:v?t("Edit Endpoint"):t("Add Endpoint"),open:h,onOk:function(){return w(function(){var n;return T(this,function(r){switch(r.label){case 0:return r.trys.push([0,6,,7]),[4,g.validateFields()];case 1:if((n=r.sent()).customHeaders=Object.entries(n.customHeaders||{}).reduce(function(e,t){var n=O(t,2),r=n[0],l=n[1],a=r.trim();return a&&(e[a]=l),e},{}),!v)return[3,3];return[4,e.request({url:"docUnderstanding:updateEndpoint",method:"POST",params:{filterByTk:v},data:n})];case 2:return r.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createEndpoint",method:"POST",data:n})];case 4:r.sent(),r.label=5;case 5:return a.message.success(t("Saved")),b(!1),P(),[3,7];case 6:return r.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return b(!1)},okText:t("Save"),cancelText:t("Cancel"),width:680,destroyOnClose:!0},l().createElement(a.Form,{form:g,layout:"vertical",preserve:!1},l().createElement(a.Tabs,{size:"small",items:[{key:"basic",label:t("Basic"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"name",label:t("Unique Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"ocr, classify, extract..."})),l().createElement(a.Form.Item,{name:"subpath",label:t("Subpath"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"/api/v1/ocr"})),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(C,{rows:2,placeholder:t("What this endpoint does")})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"method",label:t("HTTP Method"),initialValue:"POST"},l().createElement(a.Select,{style:{width:120},options:[{value:"GET",label:"GET"},{value:"POST",label:"POST"},{value:"PUT",label:"PUT"}]})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))))},{key:"file",label:t("File Input"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileInputMode",label:t("File Input Mode"),initialValue:"none"},l().createElement(a.Select,{style:{width:200},options:[{value:"none",label:t("None")},{value:"multipart",label:t("Multipart Upload")},{value:"base64",label:t("Base64 in JSON")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["fileInputMode"]},function(){return"none"!==g.getFieldValue("fileInputMode")?l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"fileFieldName",label:t("File Field Name"),initialValue:"file"},l().createElement(a.Input,{placeholder:"file",style:{width:200}})),l().createElement(a.Form.Item,{name:"maxFiles",label:t("Max Files"),initialValue:1},l().createElement(a.InputNumber,{min:1,max:20,style:{width:120}}))):null}))},{key:"async",label:t("Async Config"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"executionMode",label:t("Execution Mode"),initialValue:"sync"},l().createElement(a.Select,{style:{width:200},options:[{value:"sync",label:t("Synchronous")},{value:"polling",label:t("Polling")},{value:"webhook",label:t("Webhook")}]})),l().createElement(a.Form.Item,{noStyle:!0,dependencies:["executionMode"]},function(){var e=g.getFieldValue("executionMode");return"sync"===e?null:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollTaskIdField",label:t("Task ID Field"),help:t("Field in response containing the async task ID"),initialValue:"task_id"},l().createElement(a.Input,{placeholder:"task_id"})),"polling"===e&&l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"pollResultSubpath",label:t("Poll Result Subpath"),help:t("URL to poll for result. Use {taskId} as placeholder."),rules:[{required:!0,message:t("Required for polling mode")}]},l().createElement(a.Input,{placeholder:"/api/v1/tasks/{taskId}/result"})),l().createElement(a.Form.Item,{name:"pollResultField",label:t("Result Field"),help:t("Field in poll response containing the actual result")},l().createElement(a.Input,{placeholder:"result"})),l().createElement(a.Form.Item,{name:"pollStatusField",label:t("Status Field (optional)"),help:t("Field to check completion status. If empty, any non-null result = complete.")},l().createElement(a.Input,{placeholder:"status"})),l().createElement(a.Form.Item,{name:"pollCompletedValue",label:t("Completed Value"),help:t("Value of status field that means 'done'"),initialValue:"completed"},l().createElement(a.Input,{placeholder:"completed"})),l().createElement(a.Space,{size:"large"},l().createElement(a.Form.Item,{name:"pollInterval",label:t("Poll Interval (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:1e3,step:1e3,placeholder:"5000",style:{width:150}})),l().createElement(a.Form.Item,{name:"pollTimeout",label:t("Poll Timeout (ms)"),help:t("Override default")},l().createElement(a.InputNumber,{min:5e3,step:5e3,placeholder:"300000",style:{width:150}})))))}))},{key:"schema",label:t("Schema"),children:l().createElement(l().Fragment,null,l().createElement(a.Form.Item,{name:"requestBodySchema",label:t("Request Body Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})),l().createElement(a.Form.Item,{name:"responseSchema",label:t("Response Schema (JSON Schema)")},l().createElement(x,{placeholder:'{ "type": "object", "properties": { ... } }'})))},{key:"headers",label:t("Custom Headers"),children:l().createElement(a.Form.Item,{name:"customHeaders",label:t("Additional Headers")},l().createElement(F,null))}]}))))};function A(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function j(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function B(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){j(a,r,l,o,i,"next",e)}function i(e){j(a,r,l,o,i,"throw",e)}o(void 0)})}}function N(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){N(e,t,n[t])})}return e}function M(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t})(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function D(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||z(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function U(e){return function(e){if(Array.isArray(e))return A(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||z(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function z(e,t){if(e){if("string"==typeof e)return A(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if("Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return A(e,t)}}function J(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var _=a.Input.TextArea,q=a.Collapse.Panel,V={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},H=["completed","failed","timeout"],W=function(e){return!!e&&(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&!Array.isArray(e)},$=function(e){return JSON.stringify(null!=e?e:{},null,2)},K=function(e){return W(e)?Object.prototype.hasOwnProperty.call(e,"default")?e.default:"object"===e.type||e.properties?Object.entries(e.properties||{}).reduce(function(e,t){var n=D(t,2),r=n[0],l=K(n[1]);return void 0!==l&&(e[r]=l),e},{}):"array"===e.type?[]:void 0:{}},L=function(e,t){return W(e)&&W(t)?Object.entries(e).reduce(function(e,t){var n=D(t,2),r=n[0],l=n[1];return M(R({},e),N({},r,L(l,e[r])))},R({},t)):void 0===t?e:t},G=function(e){var t=e.value,n=e.onChange,a=e.placeholder,o=e.rows,i=u(),c=D((0,r.useState)(""),2),s=c[0],m=c[1],d=D((0,r.useState)(""),2),p=d[0],f=d[1];return(0,r.useEffect)(function(){if(!t)return void m("");try{m("string"==typeof t?JSON.stringify(JSON.parse(t),null,2):JSON.stringify(t,null,2))}catch(e){m("string"==typeof t?t:"")}},[t]),l().createElement("div",null,l().createElement(_,{rows:void 0===o?5:o,value:s,onChange:function(e){return m(e.target.value)},onBlur:function(){if(!s.trim()){f(""),null==n||n(null);return}try{var e=JSON.parse(s);f(""),null==n||n(e)}catch(e){f(i("Invalid JSON"))}},placeholder:a||"{}",status:p?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),p&&l().createElement("div",{role:"alert",style:{color:"#ff4d4f",fontSize:12}},p))},Y=function(e){var t=e.steps,n=e.endpoints,r=e.onChange,o=u(),i=function(e,n){var l,a=U(t),o=e+n;o<0||o>=a.length||(l=[a[o],a[e]],a[e]=l[0],a[o]=l[1],a.forEach(function(e,t){return e.stepOrder=t+1}),r(a))},s=function(e,n,l){var a=U(t);a[e]=M(R({},a[e]),N({},n,l)),r(a)},m=function(e){var n=t.filter(function(t,n){return n!==e});n.forEach(function(e,t){return e.stepOrder=t+1}),r(n)},d=function(){var e;r(U(t).concat([(e=t.length+1,{_key:"new_".concat(Date.now(),"_").concat(Math.random()),stepOrder:e,name:"",endpointId:null,inputMapping:null,outputAlias:"",condition:null,onError:"fail",retryCount:0})]))};return 0===t.length?l().createElement("div",{style:{textAlign:"center",padding:"20px 0"}},l().createElement(a.Empty,{description:o("No steps yet"),imageStyle:{height:40}}),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8}},o("Add First Step"))):l().createElement("div",null,l().createElement(a.Collapse,{size:"small",defaultActiveKey:t.map(function(e){return e._key})},t.map(function(e,r){var u=n.find(function(t){return t.id===e.endpointId}),d=l().createElement(a.Space,{size:4,onClick:function(e){return e.stopPropagation()}},l().createElement(a.Button,{size:"small",disabled:0===r,icon:l().createElement(c.ArrowUpOutlined,null),onClick:function(){return i(r,-1)},"aria-label":o("Move step up")}),l().createElement(a.Button,{size:"small",disabled:r===t.length-1,icon:l().createElement(c.ArrowDownOutlined,null),onClick:function(){return i(r,1)},"aria-label":o("Move step down")}),l().createElement(a.Popconfirm,{title:o("Remove step?"),okText:o("Delete"),onConfirm:function(){return m(r)}},l().createElement(a.Button,{size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":o("Remove step?")}))),p=l().createElement(a.Space,null,l().createElement(a.Badge,{count:e.stepOrder,style:{backgroundColor:"#1677ff"}}),l().createElement("span",null,e.name||o("(unnamed)")),u&&l().createElement(a.Tag,null,u.name),"skip"===e.onError&&l().createElement(a.Tooltip,{title:o("Step can be skipped on error")},l().createElement(a.Tag,{color:"orange"},o("skip on error"))),e.condition&&l().createElement(a.Tooltip,{title:o("Has condition")},l().createElement(a.Tag,{color:"purple"},o("conditional")))),f="step-name-".concat(e._key),y="step-endpoint-".concat(e._key),h="step-alias-".concat(e._key);return l().createElement(q,{key:e._key,header:p,extra:d},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement("div",null,l().createElement("label",{htmlFor:f,style:{fontWeight:500,display:"block",marginBottom:4}},o("Step Name")," *"),l().createElement(a.Input,{id:f,value:e.name,onChange:function(e){return s(r,"name",e.target.value)},placeholder:"OCR, Classify, Extract..."})),l().createElement("div",null,l().createElement("label",{htmlFor:y,style:{fontWeight:500,display:"block",marginBottom:4}},o("Endpoint")," *"),l().createElement(a.Select,{id:y,value:e.endpointId,onChange:function(e){return s(r,"endpointId",e)},placeholder:o("Select endpoint"),style:{width:"100%"},options:n.map(function(e){return{value:e.id,label:"".concat(e.name," (").concat(e.method," ").concat(e.subpath,")")}})})),l().createElement("div",null,l().createElement("label",{htmlFor:h,style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("Output Alias")),l().createElement(a.Input,{id:h,value:e.outputAlias,onChange:function(e){return s(r,"outputAlias",e.target.value)},placeholder:"ocr_result"}),l().createElement("div",{style:{color:"#888",fontSize:11}},o("Other steps reference this as"),": $step[",e.outputAlias||e.stepOrder,"].response.field")),l().createElement("div",null,l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4,marginTop:12}},o("On Error")),l().createElement(a.Space,null,l().createElement(a.Select,{value:e.onError,onChange:function(e){return s(r,"onError",e)},style:{width:120},"aria-label":o("On Error"),options:[{value:"fail",label:o("Fail")},{value:"skip",label:o("Skip")},{value:"retry",label:o("Retry")}]}),"retry"===e.onError&&l().createElement(a.InputNumber,{value:e.retryCount,onChange:function(e){return s(r,"retryCount",e||0)},min:1,max:10,addonBefore:"x",style:{width:100},"aria-label":o("Retry")})))),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Input Mapping (JSON)"),l().createElement(a.Tooltip,{title:o("Map endpoint input fields. Use $input.field, $step[alias].response.field, $files, or literal values.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.inputMapping,onChange:function(e){return s(r,"inputMapping",e)},placeholder:'{ "text": "$step[ocr_result].response.text", "lang": "vi" }',rows:3})),l().createElement("div",{style:{marginTop:12}},l().createElement("label",{style:{fontWeight:500,display:"block",marginBottom:4}},o("Condition (optional JSON)"),l().createElement(a.Tooltip,{title:o("Only run this step if the condition matches.")},l().createElement("span",{style:{fontWeight:"normal",color:"#888",marginLeft:6,cursor:"help"}},"?"))),l().createElement(G,{value:e.condition,onChange:function(e){return s(r,"condition",e)},placeholder:'{ "field": "$step[classify].response.type", "op": "eq", "value": "invoice" }',rows:2})))})),l().createElement(a.Button,{type:"dashed",icon:l().createElement(c.PlusOutlined,null),onClick:d,style:{marginTop:8,width:"100%"}},o("Add Step")))},X=function(){var e=(0,o.useFlowContext)().api,t=u(),n=D((0,r.useState)([]),2),i=n[0],s=n[1],p=D((0,r.useState)([]),2),f=p[0],y=p[1],h=D((0,r.useState)(!1),2),b=h[0],g=h[1],E=D((0,r.useState)(!1),2),v=E[0],S=E[1],w=D(a.Form.useForm(),1)[0],O=D((0,r.useState)(null),2),I=O[0],k=O[1],T=D((0,r.useState)([]),2),C=T[0],F=T[1],x=D((0,r.useState)(!1),2),P=x[0],A=x[1],j=D((0,r.useState)(null),2),N=j[0],z=j[1],W=D((0,r.useState)("{}"),2),X=W[0],Q=W[1],Z=D((0,r.useState)(""),2),ee=Z[0],et=Z[1],en=D((0,r.useState)(null),2),er=en[0],el=en[1],ea=D((0,r.useState)(!1),2),eo=ea[0],ei=ea[1],eu=(0,r.useRef)(null),ec={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},es=(0,r.useCallback)(function(){return B(function(){var t,n,r;return J(this,function(l){switch(l.label){case 0:g(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,Promise.all([e.request({url:"docUnderstanding:listPipelines"}),e.request({url:"docUnderstanding:listEndpoints"})])];case 2:return n=(t=D.apply(void 0,[l.sent(),2]))[0],r=t[1],s(m(n,[])),y(m(r,[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e]);(0,r.useEffect)(function(){es()},[es]),(0,r.useEffect)(function(){return function(){eu.current&&clearInterval(eu.current)}},[]);var em=function(e){k(e.id),w.setFieldsValue({name:e.name,description:e.description,enabled:e.enabled,inputSchema:e.inputSchema,outputMapping:e.outputMapping}),F(U(e.steps||[]).sort(function(e,t){return e.stepOrder-t.stepOrder}).map(function(e){var t;return{_key:"srv_".concat(e.id),id:e.id,stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:null!=(t=e.inputMapping)?t:null,outputAlias:e.outputAlias||"",condition:e.condition,onError:e.onError||"fail",retryCount:e.retryCount||0}})),S(!0)},ed=(0,r.useCallback)(function(){eu.current&&(clearInterval(eu.current),eu.current=null)},[]),ep=(0,r.useCallback)(function(t){return B(function(){var n;return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:t}})];case 1:return el(n=m(r.sent(),null)),n&&H.includes(n.status)&&(ed(),ei(!1)),[2,n]}})})()},[e,ed]),ef=(0,r.useCallback)(function(e){ed(),eu.current=setInterval(function(){ep(e).catch(function(e){ed(),ei(!1),a.message.error(d(e)||t("Failed to refresh test job"))})},1500)},[ep,ed,t]),ey=function(e){ed(),z(e),el(null),ei(!1),et(""),Q($(K(e.inputSchema))),A(!0)},eh=function(){ed(),A(!1),z(null),el(null),ei(!1)},eb=[{title:t("Name"),dataIndex:"name",width:200},{title:t("Steps"),dataIndex:"steps",width:300,render:function(e){if(!e||0===e.length)return l().createElement(a.Tag,null,"0 ",t("steps"));var n=U(e).sort(function(e,t){return e.stepOrder-t.stepOrder});return l().createElement(a.Space,{size:2,wrap:!0},n.map(function(e,n){return l().createElement(l().Fragment,{key:e.id},n>0&&l().createElement("span",{style:{color:"#ccc"}},"→"),l().createElement(a.Tag,null,e.name||"".concat(t("Step")," ").concat(e.stepOrder)))}))}},{title:t("Enabled"),dataIndex:"enabled",width:80,render:function(e){return e?l().createElement(a.Tag,{color:"success"},t("Yes")):l().createElement(a.Tag,null,t("No"))}},{title:t("AI Tool"),width:100,render:function(e,n){var r;return n.enabled?l().createElement(a.Tooltip,{title:"".concat(t("Registered as"),": doc_understanding.").concat(null==(r=n.name)?void 0:r.toLowerCase().replace(/[^a-z0-9_]/g,"_"))},l().createElement(a.Tag,{color:"blue",icon:l().createElement(c.ThunderboltOutlined,null)},t("Active"))):l().createElement(a.Tag,null,t("Inactive"))}},{title:t("Action"),width:190,render:function(n,r){return l().createElement(a.Space,null,l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.PlayCircleOutlined,null),disabled:!r.enabled,onClick:function(){return ey(r)},"aria-label":"".concat(t("Test")," ").concat(r.name)},t("Test")),l().createElement(a.Button,{type:"link",size:"small",icon:l().createElement(c.EditOutlined,null),onClick:function(){return em(r)},"aria-label":"".concat(t("Edit")," ").concat(r.name)},t("Edit")),l().createElement(a.Popconfirm,{title:t("Delete this pipeline?"),okText:t("Delete"),onConfirm:function(){var n;return n=r.id,B(function(){return J(this,function(r){switch(r.label){case 0:return[4,e.request({url:"docUnderstanding:deletePipeline",method:"POST",params:{filterByTk:n}})];case 1:return r.sent(),a.message.success(t("Deleted")),es(),[2]}})})()}},l().createElement(a.Button,{type:"link",size:"small",danger:!0,icon:l().createElement(c.DeleteOutlined,null),"aria-label":"".concat(t("Delete")," ").concat(r.name)},t("Delete"))))}}];return l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Button,{type:"primary",icon:l().createElement(c.PlusOutlined,null),onClick:function(){k(null),w.resetFields(),F([]),S(!0)}},t("Add Pipeline"))),l().createElement(a.Table,{rowKey:"id",columns:eb,dataSource:i,loading:b,size:"small"}),l().createElement(a.Modal,{title:I?t("Edit Pipeline"):t("New Pipeline"),open:v,onOk:function(){return B(function(){var n,r,l,o,i,u,c,s,m;return J(this,function(d){switch(d.label){case 0:return d.trys.push([0,6,,7]),[4,w.validateFields()];case 1:n=d.sent(),r=!0,l=!1,o=void 0;try{for(i=C[Symbol.iterator]();!(r=(u=i.next()).done);r=!0){if(!(c=u.value).name)return a.message.error(t("All steps must have a name")),[2];if(!c.endpointId)return a.message.error("".concat(t("Step"),' "').concat(c.name||c.stepOrder,'" ').concat(t("must have an endpoint"))),[2]}}catch(e){l=!0,o=e}finally{try{r||null==i.return||i.return()}finally{if(l)throw o}}if(new Set(s=C.map(function(e){return e.outputAlias}).filter(Boolean)).size!==s.length)return a.message.error(t("Step output aliases must be unique")),[2];if(m=M(R({},n),{steps:C.map(function(e){return M(R({},e.id?{id:e.id}:{}),{stepOrder:e.stepOrder,name:e.name,endpointId:e.endpointId,inputMapping:e.inputMapping,outputAlias:e.outputAlias||void 0,condition:e.condition,onError:e.onError,retryCount:"retry"===e.onError?e.retryCount:0})})}),!I)return[3,3];return[4,e.request({url:"docUnderstanding:updatePipeline",method:"POST",params:{filterByTk:I},data:m})];case 2:return d.sent(),[3,5];case 3:return[4,e.request({url:"docUnderstanding:createPipeline",method:"POST",data:m})];case 4:d.sent(),d.label=5;case 5:return a.message.success(t("Saved")),S(!1),es(),[3,7];case 6:return d.sent(),[3,7];case 7:return[2]}})})()},onCancel:function(){return S(!1)},okText:t("Save"),cancelText:t("Cancel"),width:800,destroyOnClose:!0},l().createElement(a.Form,{form:w,layout:"vertical",preserve:!1},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0 16px"}},l().createElement(a.Form.Item,{name:"name",label:t("Pipeline Name"),rules:[{required:!0}]},l().createElement(a.Input,{placeholder:"full_document_processing"})),l().createElement(a.Form.Item,{name:"enabled",label:t("Enabled"),valuePropName:"checked",initialValue:!0},l().createElement(a.Switch,null))),l().createElement(a.Form.Item,{name:"description",label:t("Description")},l().createElement(_,{rows:2,placeholder:t("What this pipeline does")})),l().createElement(a.Card,{title:t("Pipeline Steps"),size:"small",style:{marginBottom:16},extra:l().createElement(a.Tag,{color:"blue"},C.length," ",t("step(s)"))},l().createElement(Y,{steps:C,endpoints:f,onChange:F})),l().createElement(a.Collapse,{size:"small",ghost:!0},l().createElement(q,{header:t("Advanced: Input Schema & Output Mapping"),key:"advanced"},l().createElement(a.Form.Item,{name:"inputSchema",label:t("Input Schema (JSON Schema)"),help:t("Defines what input this pipeline accepts. Used by AI tool schema.")},l().createElement(G,{placeholder:'{ "type": "object", "properties": { "document_url": { "type": "string" } }, "required": ["document_url"] }'})),l().createElement(a.Form.Item,{name:"outputMapping",label:t("Output Mapping (JSON)"),help:t("Map final step results to pipeline output. If empty, all step results are returned.")},l().createElement(G,{placeholder:'{ "text": "$step[ocr_result].response.text", "category": "$step[classify].response.category" }'})))))),l().createElement(a.Modal,{title:N?"".concat(t("Test Playground"),": ").concat(N.name):t("Test Playground"),open:P,onCancel:eh,width:860,destroyOnClose:!0,footer:[l().createElement(a.Button,{key:"close",onClick:eh},t("Close")),(null==er?void 0:er.id)&&l().createElement(a.Button,{key:"refresh",icon:l().createElement(c.ReloadOutlined,null),disabled:eo,onClick:function(){return ep(er.id)}},t("Refresh")),l().createElement(a.Button,{key:"run",type:"primary",icon:l().createElement(c.PlayCircleOutlined,null),loading:eo,onClick:function(){return B(function(){var n,r,l,o,i;return J(this,function(u){switch(u.label){case 0:if(!N)return[2];try{r=X.trim()?JSON.parse(X):{},n=L(K(N.inputSchema),r),et("")}catch(e){return et(t("Invalid JSON input")),[2]}ed(),ei(!0),el(null),u.label=1;case 1:return u.trys.push([1,4,,5]),[4,e.request({url:"docUnderstanding:executePipeline",method:"POST",data:{pipelineId:N.id,input:n}})];case 2:if(!(l=m(u.sent(),{}).jobId))throw Error(t("Pipeline did not return a job ID"));return[4,ep(l)];case 3:return(o=u.sent())&&H.includes(o.status)||ef(l),a.message.success("".concat(t("Test job started"),": #").concat(l)),[3,5];case 4:return i=u.sent(),ei(!1),a.message.error(d(i)||t("Failed to run pipeline test")),[3,5];case 5:return[2]}})})()}},t("Run test"))].filter(Boolean)},l().createElement("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1fr) minmax(0, 1fr)",gap:16}},l().createElement("div",null,l().createElement("label",{htmlFor:"playground-input",style:{fontWeight:500,marginBottom:6,display:"block"}},t("Input JSON")),l().createElement(_,{id:"playground-input",rows:16,value:X,onChange:function(e){Q(e.target.value),ee&&et("")},placeholder:'{ "document_url": "https://..." }',status:ee?"error":void 0,style:{fontFamily:"monospace",fontSize:12}}),ee&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:ee,style:{marginTop:8}}),l().createElement(a.Collapse,{size:"small",ghost:!0,style:{marginTop:12}},l().createElement(q,{header:t("Input Schema"),key:"schema"},l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},$(null==N?void 0:N.inputSchema))))),l().createElement("div",null,l().createElement("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:6}},l().createElement("span",{style:{fontWeight:500}},t("Result")),(null==er?void 0:er.status)&&l().createElement(a.Tag,{color:V[er.status]||"default"},ec[er.status]||er.status)),er?l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:8},wrap:!0},l().createElement(a.Tag,null,t("Job")," #",er.id),er.currentStep&&l().createElement(a.Tag,null,t("Step")," ",er.currentStep)),er.error&&l().createElement(a.Alert,{type:"error",showIcon:!0,message:t("Pipeline error"),description:l().createElement("pre",{style:{margin:0,whiteSpace:"pre-wrap"}},er.error),style:{marginBottom:12}}),l().createElement("div",{style:{fontWeight:500,marginBottom:4}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:220,overflow:"auto"}},void 0!==er.finalResult&&null!==er.finalResult?$(er.finalResult):t("(not yet available)")),l().createElement("div",{style:{fontWeight:500,margin:"12px 0 4px"}},t("Step Results")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:260,overflow:"auto"}},er.stepResults?$(er.stepResults):"{}")):l().createElement(a.Empty,{description:t("Run a test to see job output"),imageStyle:{height:48}})))))};function Q(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function Z(e,t,n,r,l,a,o){try{var i=e[a](o),u=i.value}catch(e){n(e);return}i.done?t(u):Promise.resolve(u).then(r,l)}function ee(e){return function(){var t=this,n=arguments;return new Promise(function(r,l){var a=e.apply(t,n);function o(e){Z(a,r,l,o,i,"next",e)}function i(e){Z(a,r,l,o,i,"throw",e)}o(void 0)})}}function et(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n,r,l=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=l){var a=[],o=!0,i=!1;try{for(l=l.call(e);!(o=(n=l.next()).done)&&(a.push(n.value),!t||a.length!==t);o=!0);}catch(e){i=!0,r=e}finally{try{o||null==l.return||l.return()}finally{if(i)throw r}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return Q(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 Q(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function en(e,t){var n,r,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(o,"next",{value:u(0)}),i(o,"throw",{value:u(1)}),i(o,"return",{value:u(2)}),"function"==typeof Symbol&&i(o,Symbol.iterator,{value:function(){return this}}),o;function u(i){return function(u){var c=[i,u];if(n)throw TypeError("Generator is already executing.");for(;o&&(o=0,c[0]&&(a=0)),a;)try{if(n=1,r&&(l=2&c[0]?r.return:c[0]?r.throw||((l=r.return)&&l.call(r),0):r.next)&&!(l=l.call(r,c[1])).done)return l;switch(r=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,r=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(l=(l=a.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){a.label=c[1];break}if(6===c[0]&&a.label<l[1]){a.label=l[1],l=c;break}if(l&&a.label<l[2]){a.label=l[2],a.ops.push(c);break}l[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],r=0}finally{n=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var er={pending:"default",running:"processing",polling:"processing",completed:"success",failed:"error",timeout:"error"},el=function(){var e=(0,o.useFlowContext)().api,t=u(),n=et((0,r.useState)([]),2),i=n[0],s=n[1],d=et((0,r.useState)([]),2),f=d[0],y=d[1],h=et((0,r.useState)(!1),2),b=h[0],g=h[1],E=et((0,r.useState)(!1),2),v=E[0],S=E[1],w=et((0,r.useState)(null),2),O=w[0],I=w[1],k=et((0,r.useState)(void 0),2),T=k[0],C=k[1],F=et((0,r.useState)(void 0),2),x=F[0],P=F[1],A={pending:t("Pending"),running:t("Running"),polling:t("Polling"),completed:t("Completed"),failed:t("Failed"),timeout:t("Timeout")},j=(0,r.useCallback)(function(){return ee(function(){var t;return en(this,function(n){switch(n.label){case 0:g(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),t={},T&&(t.status=T),x&&(t.pipelineId=x),[4,e.request({url:"docUnderstanding:listJobs",params:{filter:Object.keys(t).length>0?t:void 0}})];case 2:return s(m(n.sent(),[])),[3,4];case 3:return g(!1),[7];case 4:return[2]}})})()},[e,T,x]),B=(0,r.useCallback)(function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:listPipelines"})];case 1:return y(m(t.sent(),[])),[3,3];case 2:return t.sent(),[3,3];case 3:return[2]}})})()},[e]);(0,r.useEffect)(function(){B()},[B]),(0,r.useEffect)(function(){j();var e=setInterval(j,1e4);return function(){return clearInterval(e)}},[j]);var N=new Map(f.map(function(e){return[e.id,e.name]})),R=[{title:t("ID"),dataIndex:"id",width:60},{title:t("Pipeline"),dataIndex:"pipelineId",width:180,render:function(e){return N.get(e)||"#".concat(e)}},{title:t("Status"),dataIndex:"status",width:100,render:function(e){return l().createElement(a.Tag,{color:er[e]||"default"},A[e]||e)}},{title:t("Current Step"),dataIndex:"currentStep",width:90,render:function(e,n){return"completed"===n.status?l().createElement(a.Tag,{color:"success"},t("Done")):"failed"===n.status?l().createElement(a.Tag,{color:"error"},"".concat(t("Step")," ").concat(e)):l().createElement(a.Badge,{status:"processing",text:"".concat(t("Step")," ").concat(e)})}},{title:t("Started"),dataIndex:"startedAt",width:160,render:function(e){return p(e)}},{title:t("Completed"),dataIndex:"completedAt",width:160,render:function(e){return p(e)}},{title:t("Action"),width:80,render:function(n,r){return l().createElement(a.Button,{size:"small",icon:l().createElement(c.EyeOutlined,null),onClick:function(){return ee(function(){return en(this,function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,e.request({url:"docUnderstanding:getJobStatus",params:{filterByTk:r.id}})];case 1:return I(m(t.sent(),r)),[3,3];case 2:return t.sent(),I(r),[3,3];case 3:return S(!0),[2]}})})()},"aria-label":"".concat(t("View")," #").concat(r.id)},t("View"))}}];return l().createElement("div",null,l().createElement(a.Space,{style:{marginBottom:16},wrap:!0},l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by status"),"aria-label":t("Filter by status"),value:T,onChange:C,style:{width:160},options:Object.keys(er).map(function(e){return{value:e,label:A[e]}})}),l().createElement(a.Select,{allowClear:!0,placeholder:t("Filter by pipeline"),"aria-label":t("Filter by pipeline"),value:x,onChange:P,style:{width:200},options:f.map(function(e){return{value:e.id,label:e.name}})}),l().createElement(a.Button,{icon:l().createElement(c.ReloadOutlined,null),onClick:j},t("Refresh"))),l().createElement(a.Table,{rowKey:"id",columns:R,dataSource:i,loading:b,size:"small",pagination:{pageSize:20}}),l().createElement(a.Drawer,{title:O?"".concat(t("Job")," #").concat(O.id," — ").concat(N.get(O.pipelineId)||t("Unknown")):t("Job Details"),width:640,open:v,onClose:function(){return S(!1)}},O&&l().createElement("div",null,l().createElement("div",{style:{marginBottom:16}},l().createElement(a.Space,{wrap:!0},l().createElement(a.Tag,{color:er[O.status]||"default"},A[O.status]||O.status),O.startedAt&&l().createElement("span",null,t("Started"),": ",p(O.startedAt)),O.completedAt&&l().createElement("span",null,t("Completed"),": ",p(O.completedAt)))),O.error&&l().createElement("div",{style:{background:"#fff2f0",border:"1px solid #ffccc7",borderRadius:6,padding:12,marginBottom:16}},l().createElement("strong",{style:{color:"#cf1322"}},t("Error"),":"),l().createElement("pre",{style:{margin:"4px 0 0",whiteSpace:"pre-wrap",color:"#cf1322"}},O.error)),l().createElement("h4",null,t("Input")),l().createElement("pre",{style:{background:"#f5f5f5",padding:12,borderRadius:6,fontSize:12,maxHeight:200,overflow:"auto"}},JSON.stringify(O.input,null,2)),l().createElement("h4",{style:{marginTop:16}},t("Step Results")),O.stepResults&&Object.keys(O.stepResults).length>0?Object.entries(O.stepResults).map(function(e){var t=et(e,2),n=t[0],r=t[1];return l().createElement("div",{key:n,style:{marginBottom:8}},l().createElement(a.Tag,{color:"blue"},n),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11,maxHeight:150,overflow:"auto",marginTop:4}},JSON.stringify(r,null,2)))}):l().createElement("div",{style:{color:"#999"}},t("No step results yet")),l().createElement("h4",{style:{marginTop:16}},t("Final Result")),l().createElement("pre",{style:{background:"#f0f5ff",padding:12,borderRadius:6,fontSize:12,maxHeight:300,overflow:"auto"}},O.finalResult?JSON.stringify(O.finalResult,null,2):t("(not yet available)")),O.externalTaskIds&&Object.keys(O.externalTaskIds).length>0&&l().createElement(l().Fragment,null,l().createElement("h4",{style:{marginTop:16}},t("External Task IDs")),l().createElement("pre",{style:{background:"#f5f5f5",padding:8,borderRadius:4,fontSize:11}},JSON.stringify(O.externalTaskIds,null,2))))))},ea=function(){var e=u();return l().createElement("div",{style:{backgroundColor:"var(--nb-box-bg)",minHeight:"100vh"}},l().createElement("div",{style:{padding:"16px 24px",backgroundColor:"#fff",borderBottom:"1px solid #f0f0f0"}},l().createElement("h2",{style:{margin:0,fontSize:20,fontWeight:500}},e("Document Understanding - Pipeline Orchestrator"))),l().createElement("div",{style:{padding:"0 24px 24px"}},l().createElement(a.Tabs,{defaultActiveKey:"config",items:[{key:"config",label:e("Service Config"),children:l().createElement(E,null)},{key:"endpoints",label:e("Endpoints"),children:l().createElement(P,null)},{key:"pipelines",label:e("Pipelines"),children:l().createElement(X,null)},{key:"jobs",label:e("Jobs history"),children:l().createElement(el,null)}]})))},eo=ea}}]);
|