plugin-build-visualization-block 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +21 -0
- package/client.d.ts +2 -2
- package/client.js +1 -1
- package/dist/client/59.6bac6ada1dacea82.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/385.1e235c5081822f07.js +10 -0
- package/dist/client-v2/59.cdb723e410dac32b.js +10 -0
- package/dist/client-v2/index.js +37 -1
- package/dist/externalVersion.js +12 -7
- package/dist/locale/en-US.json +77 -37
- package/dist/locale/vi-VN.json +58 -40
- package/dist/locale/zh-CN.json +79 -40
- package/dist/node_modules/zod/index.cjs +1 -1
- package/dist/node_modules/zod/package.json +1 -1
- package/dist/server/actions/build.js +7 -704
- package/dist/server/collections/workflow-runs.js +51 -0
- package/dist/server/pipeline/analyzer.js +18 -4
- package/dist/server/plugin.js +17 -20
- package/dist/server/tools/build-visualization-block.js +9 -26
- package/dist/server/workflow-domain.js +209 -0
- package/dist/server/workflow.js +466 -0
- package/dist/shared/blockSpec.js +1 -1
- package/dist/shared/workflow.js +58 -0
- package/package.json +14 -3
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/client/locale.ts +18 -18
- package/src/client/plugin.tsx +11 -0
- package/src/client/workflow.ts +28 -0
- package/src/client-v2/__tests__/buildApi.test.ts +68 -0
- package/src/client-v2/__tests__/modelOptions.test.ts +190 -0
- package/src/client-v2/__tests__/nativeModels.test.ts +77 -0
- package/src/client-v2/buildApi.ts +93 -0
- package/src/client-v2/components/AISelectors.tsx +85 -0
- package/src/client-v2/components/BuildForm.tsx +186 -0
- package/src/client-v2/components/CollectionMultiSelect.tsx +63 -0
- package/src/client-v2/components/NativePreview.tsx +53 -0
- package/src/client-v2/locale.ts +5 -0
- package/src/client-v2/modelOptions.ts +201 -0
- package/src/client-v2/models/BuildVisualizationBlockModel.tsx +95 -0
- package/src/client-v2/nativeBlock.ts +28 -0
- package/src/client-v2/pages/SettingsPage.tsx +77 -0
- package/src/client-v2/plugin.tsx +17 -4
- package/src/client-v2/workflow-fields.tsx +23 -0
- package/src/client-v2/workflow.ts +28 -0
- package/src/locale/en-US.json +77 -37
- package/src/locale/namespace.ts +6 -6
- package/src/locale/vi-VN.json +58 -40
- package/src/locale/zh-CN.json +79 -40
- package/src/server/__tests__/build-action.test.ts +121 -117
- package/src/server/__tests__/plugin.test.ts +19 -34
- package/src/server/actions/build.ts +15 -1031
- package/src/server/collections/workflow-runs.ts +30 -0
- package/src/server/pipeline/analyzer.ts +395 -368
- package/src/server/plugin.ts +26 -35
- package/src/server/tools/build-visualization-block.ts +18 -28
- package/src/server/workflow-domain.ts +235 -0
- package/src/server/workflow.ts +519 -0
- package/src/shared/blockSpec.ts +10 -1
- package/src/shared/workflow.ts +26 -0
- package/dist/client-v2/812.6b4f5e757b898c82.js +0 -10
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# plugin-build-visualization-block
|
|
2
|
+
|
|
3
|
+
Version 0.2.0 routes build/retry and AI-tool requests through the **Build Visualization Block** workflow (`build-visualization`): **Analyze requirement -> Validate specification -> Generate block**. Each stage persists its result in a native workflow job. `aiVisualizationBuildRuns` links the request snapshot to the existing `aiVisualizationBuilds.buildRunId` and the execution history. The existing polling/result API and AI fallback behavior remain available.
|
|
4
|
+
|
|
5
|
+
The former visualization Redis/eventQueue consumer is removed. The workflow workers need access to the selected data sources and configured AI service. Both v1 and v2 clients register the three instructions in the workflow editor.
|
|
6
|
+
|
|
7
|
+
## Native workflow execution
|
|
8
|
+
|
|
9
|
+
Requires `@nocobase/plugin-workflow` 2.2.52 or later in the 2.x fork. At least one application worker must serve `workflow:process`. The plugin provisions one asynchronous collection workflow on startup; it does not re-enable a workflow disabled by an administrator or overwrite an existing version's nodes.
|
|
10
|
+
|
|
11
|
+
Requests and their input snapshots are committed in the same database transaction. NocoBase owns the trigger, execution history, jobs, timeout and continuation. The plugin's 30-second reconciliation checks recover lost admission/resume messages and abandoned pending instructions; it does not subscribe to a separate business queue. SQL leases prevent two workers from committing the same job, and a new run identity fences late results after retry/cancellation. Each worker executes at most two plugin instructions concurrently.
|
|
12
|
+
|
|
13
|
+
By default, executions time out after 30 minutes. Cancellation from the workflow execution screen is mirrored to the plugin record by reconciliation; active work observes it on the next heartbeat (up to 20 seconds). Retry through the plugin creates a new run and execution while retaining the previous history. Use the plugin's retry action for a new attempt; rerunning a terminal execution directly from the workflow screen does not create a new plugin request.
|
|
14
|
+
|
|
15
|
+
Keep the managed business nodes in their original order and keep the collection trigger and workflow key. Administrative nodes may be inserted between them; Visualization resolves its input from the preceding business node. Removing/skipping a required node or changing the trigger prevents the plugin pipeline from completing correctly. These nodes require the request context created by the plugin and are not general-purpose nodes for unrelated workflows.
|
|
16
|
+
|
|
17
|
+
### Upgrade
|
|
18
|
+
|
|
19
|
+
Drain or stop the old plugin workers before upgrading every app/worker instance; do not run the former private queue processor alongside this version. Run the normal NocoBase upgrade to synchronize the new run collection and fields, then restart workers with the workflow plugin enabled. Previously queued/running records without a native run are adopted on startup. Completed legacy records are left intact. Keep existing PageIndex workspaces and visualization records.
|
|
20
|
+
|
|
21
|
+
A worker crash after an external call but before its result is committed can repeat that call during recovery. Database result writes are fenced, but PageIndex/LLM calls are at-least-once and may incur repeated provider usage. Rollback requires stopping new workers and resolving active native runs before reintroducing the old queue consumer.
|
package/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './dist/client';
|
|
2
|
-
export { default } from './dist/client';
|
|
1
|
+
export * from './dist/client';
|
|
2
|
+
export { default } from './dist/client';
|
package/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = require('./dist/client/index.js');
|
|
1
|
+
module.exports = require('./dist/client/index.js');
|
|
@@ -0,0 +1,10 @@
|
|
|
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_build_visualization_block=self.webpackChunkplugin_build_visualization_block||[]).push([["59"],{414:function(e,i,n){n.r(i),n.d(i,{default:function(){return a}});var t=n(155),u=n.n(t),r=n(59),s=n(953),o=n(327);function a(){var e=(0,s.useTranslation)(o.CU).t;return u().createElement(r.Alert,{type:"info",showIcon:!0,message:e("This node processes the request that triggered this workflow. No configuration is required.")})}}}]);
|
package/dist/client/index.js
CHANGED
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("@nocobase/client-v2"),require("@formily/core"),require("react"),require("antd"),require("@nocobase/client"),require("@formily/react"),require("@ant-design/icons")):"function"==typeof define&&define.amd?define("plugin-build-visualization-block",["@nocobase/client-v2","@formily/core","react","antd","@nocobase/client","@formily/react","@ant-design/icons"],t):"object"==typeof exports?exports["plugin-build-visualization-block"]=t(require("@nocobase/client-v2"),require("@formily/core"),require("react"),require("antd"),require("@nocobase/client"),require("@formily/react"),require("@ant-design/icons")):e["plugin-build-visualization-block"]=t(e["@nocobase/client-v2"],e["@formily/core"],e.react,e.antd,e["@nocobase/client"],e["@formily/react"],e["@ant-design/icons"])}(self,function(e,t,r,n,o,a,l){return function(){"use strict";var i={375:function(e){e.exports=l},452:function(e){e.exports=t},230:function(e){e.exports=a},342:function(e){e.exports=o},485:function(t){t.exports=e},59:function(e){e.exports=n},155:function(e){e.exports=r}},u={};function c(e){var t=u[e];if(void 0!==t)return t.exports;var r=u[e]={exports:{}};return i[e](r,r.exports,c),r.exports}c.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return c.d(t,{a:t}),t},c.d=function(e,t){for(var r in t)c.o(t,r)&&!c.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},c.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.g.importScripts&&(s=c.g.location+"");var s,f=c.g.document;if(!s&&f&&(f.currentScript&&"SCRIPT"===f.currentScript.tagName.toUpperCase()&&(s=f.currentScript.src),!s)){var p=f.getElementsByTagName("script");if(p.length)for(var d=p.length-1;d>-1&&(!s||!/^http(s?):/.test(s));)s=p[d--].src}if(!s)throw Error("Automatic publicPath is not supported in this browser");c.p=s.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/");var b={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var r=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");r.indexOf("/static/plugins/plugin-build-visualization-block/dist/client/")>=0&&(e=r.replace(/\/[^\/]+$/,"/"))}if(!e){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),e=n+"static/plugins/plugin-build-visualization-block/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",a="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var l=window.location.pathname||"/",i=l.indexOf(a);e=i>=0?l.slice(0,i+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-build-visualization-block/dist/client/"}c.p=e}(),!function(){c.r(b),c.d(b,{PluginBuildVisualizationBlockClient:function(){return el},default:function(){return ei}});var e=c(342),t=c(375),r=c(59),n=c(155),o=c.n(n),a=c(452),l=c(230),i=c(485);function u(){var e=(0,i.useApp)();return(0,n.useCallback)(function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-build-visualization-block","client"]},r))},[e.i18n])}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function f(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function p(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return s(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return s(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var d=function(e){var t,c,s=u(),d=(0,i.useApp)().apiClient,b=(0,l.useField)(),y=p((0,n.useState)([]),2),v=y[0],m=y[1],h=p((0,n.useState)(!1),2),g=h[0],S=h[1],w=p((0,n.useState)(!1),2),O=w[0],E=w[1];(0,n.useEffect)(function(){var e,t=!0;return(e=function(){var e,r;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(n){switch(n.label){case 0:S(!0),E(!1),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,d.resource("ai").listLLMServices()];case 2:var o,a;if(e=n.sent(),!t)return[2];return m((Array.isArray(a=null==e||null==(o=e.data)?void 0:o.data)?a:[]).filter(function(e){return!!e.name}).map(function(e){return{label:e.title||e.name,value:e.name}})),[3,5];case 3:if(r=n.sent(),!t)return[2];return console.error("Failed to load LLM services:",r),m([]),E(!0),[3,5];case 4:return t&&S(!1),[7];case 5:return[2]}})},function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){f(a,n,o,l,i,"next",e)}function i(e){f(a,n,o,l,i,"throw",e)}l(void 0)})})(),function(){t=!1}},[d]);var j=(0,n.useCallback)(function(e){b.setValue(e);var t=b.query(".model").take();(0,a.isField)(t)&&t.setValue(void 0)},[b]);return o().createElement(r.Select,(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},e),c=c={options:v,loading:g,status:O?"error":void 0,value:b.value,onChange:j,notFoundContent:O?s("Failed to load the list"):void 0,allowClear:!0,showSearch:!0,optionFilterProp:"label"},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(c)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(c)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(c,e))}),t))};function y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function v(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function m(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return y(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return y(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var h=(0,l.observer)(function(e){var t,a,c,s=u(),f=(0,i.useApp)().apiClient,p=(0,l.useField)(),d=(0,l.useForm)(),b=m((0,n.useState)([]),2),y=b[0],h=b[1],g=m((0,n.useState)(!1),2),S=g[0],w=g[1],O=m((0,n.useState)(!1),2),E=O[0],j=O[1],k="string"==typeof(null==(c=d.values)?void 0:c.llmService)?d.values.llmService:void 0;(0,n.useEffect)(function(){var e,t=!0;if(!k){h([]),j(!1);return}return(e=function(){var e,r;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(n){switch(n.label){case 0:w(!0),j(!1),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,f.resource("ai").listModels({llmService:k})];case 2:var o,a;if(e=n.sent(),!t)return[2];return h((Array.isArray(a=null==e||null==(o=e.data)?void 0:o.data)?a:[]).map(function(e){return e.id||e.name}).filter(function(e){return!!e}).map(function(e){return{label:e,value:e}})),[3,5];case 3:if(r=n.sent(),!t)return[2];return console.error("Failed to load models:",r),h([]),j(!0),[3,5];case 4:return t&&w(!1),[7];case 5:return[2]}})},function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){v(a,n,o,l,i,"next",e)}function i(e){v(a,n,o,l,i,"throw",e)}l(void 0)})})(),function(){t=!1}},[f,k]);var C=(0,n.useCallback)(function(e){p.setValue(e)},[p]);return o().createElement(r.Select,(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},e),a=a={options:y,loading:S,status:E?"error":void 0,value:p.value,onChange:C,disabled:!k,notFoundContent:E?s("Failed to load the list"):void 0,allowClear:!0,showSearch:!0,optionFilterProp:"label"},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(a)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(a,e))}),t))}),g="aiVisualizationBuilds",S="aiVisualizationBuildSettings",w=["idle","queued","analyzing","generating","completed","failed"],O=function(t){var a,l=t.value,i=t.onChange,c=t.disabled,s=u(),f=(0,e.useCompile)(),p=(0,e.useDataSourceManager)(),d=(0,e.useACLRoleContext)().parseAction,b=null==l?void 0:l.dataSource,y=null!=(a=null==l?void 0:l.collections)?a:[],v=(0,n.useMemo)(function(){var e;return(null!=(e=null==p?void 0:p.getDataSources())?e:[]).map(function(e){return{label:f(e.displayName)||e.key,value:e.key}})},[p,f]),m=(0,n.useCallback)(function(e){return!!d("".concat(e,":list"))},[d]),h=(0,n.useMemo)(function(){if(!b)return[];var e,t,r=null==p?void 0:p.getDataSource(b);return(null!=(e=null==r||null==(t=r.collectionManager)?void 0:t.getCollections())?e:[]).filter(function(e){return m(e.name)}).map(function(e){return{label:f(e.title)||e.name,value:e.name}})},[p,b,f,m]),g=(0,n.useCallback)(function(e){null==i||i({dataSource:e,collections:[]})},[i]),S=(0,n.useCallback)(function(e){var t=e.slice(0,50);null==i||i({dataSource:b,collections:t})},[i,b]),w=y.length>=50;return o().createElement(r.Space,{direction:"vertical",style:{width:"100%"},size:"small"},o().createElement(r.Select,{"aria-label":s("Data source"),placeholder:s("Data source"),style:{width:"100%"},options:v,value:null!=b?b:v.length?void 0:e.DEFAULT_DATA_SOURCE_KEY,onChange:g,disabled:c,showSearch:!0,optionFilterProp:"label"}),o().createElement(r.Select,{"aria-label":s("Collections"),placeholder:s("Collections"),style:{width:"100%"},mode:"multiple",options:h,value:y,onChange:S,disabled:c||!b,showSearch:!0,optionFilterProp:"label"}),w?o().createElement(r.Typography.Text,{type:"warning"},s("You can select at most {{max}} collections",{max:50})):null)},E={idle:"default",queued:"default",analyzing:"processing",generating:"processing",completed:"success",failed:"error"},j={idle:"Idle",queued:"Queued",analyzing:"Analyzing",generating:"Generating",completed:"Completed",failed:"Failed"},k=Object.keys(E),C=function(e){var t,n=u(),i=(0,l.useField)(),c=(0,a.isField)(i)?i.value:void 0,s=null!=(t=e.value)?t:c;return"string"==typeof s&&k.includes(s)?o().createElement(r.Tag,{color:E[s],"aria-label":n(j[s])},n(j[s])):null},A=function(t){var a=t.schema,l=t.usedFallback,i=t.adjustments,c=t.onInsert,s=t.onRegenerate,f=t.onCancel,p=t.loading,d=u(),b=(0,n.useMemo)(function(){return Array.isArray(i)&&i.every(function(e){return(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&null!==e&&"string"==typeof e.reference&&"string"==typeof e.action})?i:[]},[i]),y=!!a;return o().createElement(r.Space,{direction:"vertical",style:{width:"100%"},size:"middle"},l?o().createElement(r.Alert,{type:"warning",showIcon:!0,message:d("A fallback block was generated")}):null,b.length>0?o().createElement(r.Alert,{type:"info",showIcon:!0,message:d("Some fields were adjusted to match the collection"),description:o().createElement("ul",{style:{margin:0,paddingInlineStart:20}},b.map(function(e,t){return o().createElement("li",{key:"".concat(e.reference,"-").concat(e.action,"-").concat(t)},"remapped"===e.action&&e.replacement?"".concat(e.reference," → ").concat(e.replacement):"".concat(e.reference," → ").concat(e.action))}))}):null,o().createElement("section",{"aria-label":d("Preview")},o().createElement(r.Typography.Title,{level:5,style:{marginTop:0}},d("Preview")),y?o().createElement(e.SchemaComponentOptions,null,o().createElement(e.SchemaComponent,{schema:a})):p?o().createElement(r.Spin,{"aria-label":d("Generating")}):o().createElement(r.Empty,{image:r.Empty.PRESENTED_IMAGE_SIMPLE,description:d("Preview")})),o().createElement(r.Space,null,o().createElement(r.Button,{type:"primary",onClick:function(){return a&&c(a)},disabled:!y||p,"aria-label":d("Insert")},d("Insert")),o().createElement(r.Button,{onClick:s,loading:p,"aria-label":d("Regenerate")},d("Regenerate")),o().createElement(r.Button,{onClick:f,disabled:p,"aria-label":d("Cancel")},d("Cancel"))))};function P(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function I(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function x(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return P(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return P(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 T(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function z(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function F(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){z(a,n,o,l,i,"next",e)}function i(e){z(a,n,o,l,i,"throw",e)}l(void 0)})}}function B(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return M(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return M(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 _(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function D(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function q(e,t){if(e&&(void 0===e?"undefined":_(e))==="object"){var r=e[t];if("string"==typeof r)return r}return""}var L=function(t){var i=t.onInsert,c=t.onClose,s=u(),f=(0,e.useAPIClient)(),p=(0,e.useApp)(),b=(0,n.useMemo)(function(){return(0,a.createForm)()},[]),y=B((0,n.useState)(""),2),v=y[0],m=y[1],E=B((0,n.useState)({collections:[]}),2),j=E[0],k=E[1],P=B((0,n.useState)({}),2),M=P[0],z=P[1],L=B((0,n.useState)(void 0),2),R=L[0],V=L[1],$=B((0,n.useState)(!1),2),G=$[0],U=$[1],N=B((0,n.useState)(!1),2),Y=N[0],K=N[1],Q=function(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=r.intervalMs,a=void 0===o?2e3:o,l=r.enabled,i=void 0===l||l,u=(0,e.useAPIClient)(),c=x((0,n.useState)(void 0),2),s=c[0],f=c[1],p=x((0,n.useState)(void 0),2),d=p[0],b=p[1],y=x((0,n.useState)(!1),2),v=y[0],m=y[1],h=(0,n.useRef)(null),S=(0,n.useRef)(!1);return(0,n.useEffect)(function(){var e=function(){null!==h.current&&(clearInterval(h.current),h.current=null)};if(!i||void 0===t)return e(),m(!1),e;var r=!1,n=function(){var n;return(n=function(){var n,o,a;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(l){var i,c;switch(l.label){case 0:if(S.current)return[2];S.current=!0,m(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,u.resource(g).getResult({filterByTk:t})];case 2:if(n=l.sent(),r)return[2];return(o=function(e){if(e&&(void 0===e?"undefined":T(e))==="object"){var t,r,n,o,a=e.id;if("string"==typeof a||"number"==typeof a)return{id:a,status:"string"==typeof e.status?e.status:"",buildPhase:"string"==typeof(o=e.buildPhase)&&w.includes(o)?e.buildPhase:"idle",blockSchema:null!=(t=e.blockSchema)?t:void 0,blockSpec:null!=(r=e.blockSpec)?r:void 0,adjustments:null!=(n=e.adjustments)?n:void 0,usedFallback:!0===e.usedFallback,errorMessage:"string"==typeof e.errorMessage?e.errorMessage:null}}}(function(e){if(e&&(void 0===e?"undefined":T(e))==="object"){var t=e.data;if(t&&(void 0===t?"undefined":T(t))==="object")return t.data}}(n)))&&(f(o),b(void 0),("completed"===(i=o.buildPhase)||"failed"===i)&&e()),[3,5];case 3:return a=l.sent(),r||b((null!=(c=Error)&&"u">typeof Symbol&&c[Symbol.hasInstance]?!!c[Symbol.hasInstance](a):a instanceof c)?a:Error(String(a))),[3,5];case 4:return S.current=!1,r||m(!1),[7];case 5:return[2]}})},function(){var e=this,t=arguments;return new Promise(function(r,o){var a=n.apply(e,t);function l(e){I(a,r,o,l,i,"next",e)}function i(e){I(a,r,o,l,i,"throw",e)}l(void 0)})})()};return n(),h.current=setInterval(n,a),function(){r=!0,e()}},[u,t,i,a]),{phase:null==s?void 0:s.buildPhase,status:null==s?void 0:s.status,record:s,error:d,loading:v}}(R,{enabled:!!R&&Y}),W=Q.phase,H=Q.record;(0,n.useEffect)(function(){("completed"===W||"failed"===W)&&K(!1)},[W]),(0,n.useEffect)(function(){var e=!0;return F(function(){var t,r,n,o;return D(this,function(a){switch(a.label){case 0:return a.trys.push([0,2,,3]),[4,f.resource(S).publicGet()];case 1:var l,i;if(n=a.sent(),!e)return[2];return k({dataSource:(o={defaultDataSource:"string"==typeof(i=(l=null==(r=n.data)?void 0:r.data)&&(void 0===l?"undefined":_(l))==="object"?l:{}).defaultDataSource?i.defaultDataSource:void 0,defaultCollections:Array.isArray(i.defaultCollections)?i.defaultCollections.filter(function(e){return"string"==typeof e}):[],defaultLLMService:"string"==typeof i.defaultLLMService?i.defaultLLMService:void 0,defaultModel:"string"==typeof i.defaultModel?i.defaultModel:void 0}).defaultDataSource,collections:null!=(t=o.defaultCollections)?t:[]}),b.setValues({llmService:o.defaultLLMService,model:o.defaultModel}),[3,3];case 2:return console.warn("[plugin-build-visualization-block] Failed to load default settings:",a.sent()),[3,3];case 3:return[2]}})})(),function(){e=!1}},[f,b]);var J=(0,n.useMemo)(function(){var e=p.pm;return!!(e.get("ai")||e.get("@nocobase/plugin-ai")||e.get("plugin-ai"))},[p]),X=j.dataSource,Z=(0,n.useMemo)(function(){var e;return null!=(e=j.collections)?e:[]},[j]),ee=(0,n.useCallback)(function(){var e={};v.trim()?v.length>2e3&&(e.requirement=s("Requirement must be at most {{max}} characters",{max:2e3})):e.requirement=s("Requirement description is required"),Z.length<1?e.collections=s("At least one collection is required"):Z.length>50&&(e.collections=s("You can select at most {{max}} collections",{max:50}));var t=q(b.values,"llmService"),r=q(b.values,"model");return t&&r||(e.ai=s("AI service and model are required")),e},[v,Z,b,s]),et=(0,n.useCallback)(function(){return F(function(){var e,t,r;return D(this,function(n){switch(n.label){case 0:if(!J)return[2];if(Object.keys(e=ee()).length>0)return z(e),[2];z({}),t={requirement:v.trim(),dataSource:X,collections:Z,primaryCollection:Z[0],llmService:q(b.values,"llmService"),model:q(b.values,"model")},U(!0),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,f.resource(g).build({values:t})];case 2:if(!(r=function(e){if(e&&(void 0===e?"undefined":_(e))==="object"){var t=e.data;if(t&&(void 0===t?"undefined":_(t))==="object"){var r=t.data;if(r&&(void 0===r?"undefined":_(r))==="object"){var n=r.id;if("string"==typeof n||"number"==typeof n)return String(n)}}}}(n.sent())))return z({submit:s("The requirement could not be saved")}),[2];return V(r),K(!0),[3,5];case 3:return n.sent(),z({submit:s("The requirement could not be saved")}),[3,5];case 4:return U(!1),[7];case 5:return[2]}})})()},[J,ee,v,X,Z,b,f,s]),er=(0,n.useCallback)(function(){return F(function(){return D(this,function(e){switch(e.label){case 0:if(!R)return[2];z({}),U(!0),e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,f.resource(g).retry({filterByTk:R})];case 2:return e.sent(),K(!0),[3,5];case 3:return e.sent(),z({submit:s("The requirement could not be saved")}),[3,5];case 4:return U(!1),[7];case 5:return[2]}})})()},[f,R,s]);return R&&!Y&&"completed"===W&&H?o().createElement(A,{schema:H.blockSchema,usedFallback:H.usedFallback,adjustments:H.adjustments,onInsert:i,onRegenerate:er,onCancel:c,loading:!1}):R&&!Y&&"failed"===W?o().createElement(r.Space,{direction:"vertical",style:{width:"100%"},size:"middle"},o().createElement(r.Alert,{type:"error",showIcon:!0,message:(null==H?void 0:H.errorMessage)||s("The requirement could not be saved")}),o().createElement(r.Space,null,o().createElement(r.Button,{type:"primary",onClick:er,loading:G},s("Retry")),o().createElement(r.Button,{onClick:c},s("Cancel")))):R&&Y?o().createElement(r.Space,{direction:"vertical",align:"center",style:{width:"100%",padding:24},size:"middle"},o().createElement(r.Spin,{"aria-label":s("Generating")}),o().createElement(r.Space,null,o().createElement(C,{value:W}),o().createElement(r.Typography.Text,{type:"secondary"},s("Generating")))):o().createElement(r.Space,{direction:"vertical",style:{width:"100%"},size:"middle"},J?null:o().createElement(r.Alert,{type:"warning",showIcon:!0,message:s("The AI service is unavailable")}),o().createElement("div",null,o().createElement(r.Typography.Text,{strong:!0},s("Requirement")),o().createElement(r.Input.TextArea,{"aria-label":s("Requirement"),placeholder:s("Describe the block you want to build"),value:v,onChange:function(e){return m(e.target.value)},showCount:!0,maxLength:2e3,autoSize:{minRows:3,maxRows:8},status:M.requirement?"error":void 0}),M.requirement?o().createElement(r.Typography.Text,{type:"danger"},M.requirement):null),o().createElement("div",null,o().createElement(r.Typography.Text,{strong:!0},s("Collections")),o().createElement(O,{value:j,onChange:k}),M.collections?o().createElement(r.Typography.Text,{type:"danger"},M.collections):null),o().createElement(l.FormProvider,{form:b},o().createElement("div",null,o().createElement(r.Typography.Text,{strong:!0},s("AI service")),o().createElement(l.Field,{name:"llmService",component:[d,{placeholder:s("AI service"),style:{width:"100%"}}]})),o().createElement("div",null,o().createElement(r.Typography.Text,{strong:!0},s("Model")),o().createElement(l.Field,{name:"model",component:[h,{placeholder:s("Model"),style:{width:"100%"}}]}))),M.ai?o().createElement(r.Typography.Text,{type:"danger"},M.ai):null,M.submit?o().createElement(r.Alert,{type:"error",showIcon:!0,message:M.submit}):null,o().createElement(r.Space,null,o().createElement(r.Button,{type:"primary",onClick:et,loading:G,disabled:!J},s("Build")),o().createElement(r.Button,{onClick:c,disabled:G},s("Cancel"))))};function R(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var V=function(){var a,l,i,c=(0,e.useSchemaInitializerItem)(),s=(0,e.useSchemaInitializer)().insert,f=(0,e.useACLRoleContext)().parseAction,p=u(),d=function(e){if(Array.isArray(e))return e}(a=(0,n.useState)(!1))||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o=[],a=!0,l=!1;try{for(n=n.call(e);!(a=(t=n.next()).done)&&(o.push(t.value),2!==o.length);a=!0);}catch(e){l=!0,r=e}finally{try{a||null==n.return||n.return()}finally{if(l)throw r}}return o}}(a)||function(e){if(e){if("string"==typeof e)return R(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return R(e,2)}}(a)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),b=d[0],y=d[1],v=(0,n.useCallback)(function(){return y(!0)},[]),m=(0,n.useCallback)(function(){return y(!1)},[]),h=(0,n.useCallback)(function(e){y(!1),s(e)},[s]);if(!f||!f("aiVisualizationBuilds:build"))return null;var g=c.title||p("Build Visualization Block");return o().createElement(o().Fragment,null,o().createElement(e.SchemaInitializerItem,(l=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},c),i=i={title:g,icon:o().createElement(t.DashboardOutlined,null),onClick:v},Object.getOwnPropertyDescriptors?Object.defineProperties(l,Object.getOwnPropertyDescriptors(i)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(i)).forEach(function(e){Object.defineProperty(l,e,Object.getOwnPropertyDescriptor(i,e))}),l)),o().createElement(r.Modal,{open:b,title:g,footer:null,destroyOnClose:!0,onCancel:m,width:720},o().createElement(L,{onInsert:h,onClose:m})))};function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function G(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function U(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){G(a,n,o,l,i,"next",e)}function i(e){G(a,n,o,l,i,"throw",e)}l(void 0)})}}function N(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return $(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return $(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 Y(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function K(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function Q(e,t){if(e&&(void 0===e?"undefined":Y(e))==="object"){var r=e[t];return"string"==typeof r&&r.trim()?r.trim():void 0}}var W=function(){var e=(0,i.useApp)().apiClient,t=r.App.useApp().message,c=u(),s=(0,n.useMemo)(function(){return(0,a.createForm)()},[]),f=N((0,n.useState)({collections:[]}),2),p=f[0],b=f[1],y=N((0,n.useState)(!0),2),v=y[0],m=y[1],g=N((0,n.useState)(!0),2),w=g[0],E=g[1],j=N((0,n.useState)(!1),2),k=j[0],C=j[1],A=N((0,n.useState)(!1),2),P=A[0],I=A[1];(0,n.useEffect)(function(){var t=!0;return U(function(){var r,n,o,a,l,i;return K(this,function(u){switch(u.label){case 0:E(!0),I(!1),u.label=1;case 1:return u.trys.push([1,3,4,5]),[4,e.resource(S).publicGet()];case 2:var c,f;if(a=u.sent(),!t)return[2];return b({dataSource:null!=(r=(l={defaultDataSource:"string"==typeof(f=(c=null==(o=a.data)?void 0:o.data)&&(void 0===c?"undefined":Y(c))==="object"?c:{}).defaultDataSource?f.defaultDataSource:void 0,defaultCollections:Array.isArray(f.defaultCollections)?f.defaultCollections.filter(function(e){return"string"==typeof e}):[],defaultLLMService:"string"==typeof f.defaultLLMService?f.defaultLLMService:void 0,defaultModel:"string"==typeof f.defaultModel?f.defaultModel:void 0,enableAITool:!1!==f.enableAITool}).defaultDataSource)?r:void 0,collections:null!=(n=l.defaultCollections)?n:[]}),s.setValues({llmService:l.defaultLLMService,model:l.defaultModel}),m(!1!==l.enableAITool),[3,5];case 3:if(i=u.sent(),!t)return[2];return console.error("[plugin-build-visualization-block] Failed to load settings:",i),I(!0),[3,5];case 4:return t&&E(!1),[7];case 5:return[2]}})})(),function(){t=!1}},[e,s]);var x=(0,n.useCallback)(function(){return U(function(){var r;return K(this,function(n){switch(n.label){case 0:C(!0),n.label=1;case 1:return n.trys.push([1,,3,4]),[4,e.resource(S).update({filterByTk:1,values:{defaultDataSource:p.dataSource,defaultCollections:null!=(r=p.collections)?r:[],defaultLLMService:Q(s.values,"llmService"),defaultModel:Q(s.values,"model"),enableAITool:v}})];case 2:return n.sent(),t.success(c("Saved successfully")),[3,4];case 3:return C(!1),[7];case 4:return[2]}})})()},[e,p,v,s,t,c]);return o().createElement(r.Card,{loading:w},o().createElement(r.Space,{direction:"vertical",size:"middle",style:{width:"100%",maxWidth:720}},P?o().createElement(r.Alert,{type:"error",showIcon:!0,message:c("Failed to load the list")}):null,o().createElement(r.Form,{layout:"vertical"},o().createElement(r.Form.Item,{label:c("Default collections")},o().createElement(O,{value:p,onChange:b})),o().createElement(l.FormProvider,{form:s},o().createElement(r.Form.Item,{label:c("Default AI service")},o().createElement(l.Field,{name:"llmService",component:[d,{style:{width:"100%"}}]})),o().createElement(r.Form.Item,{label:c("Default model")},o().createElement(l.Field,{name:"model",component:[h,{style:{width:"100%"}}]}))),o().createElement(r.Form.Item,{label:c("Enable AI tool")},o().createElement(r.Switch,{checked:v,onChange:m})),o().createElement(r.Button,{type:"primary",loading:k,onClick:x},c("Save")))))};function H(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function J(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){H(a,n,o,l,i,"next",e)}function i(e){H(a,n,o,l,i,"throw",e)}l(void 0)})}}function X(e,t,r){return(X=er()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&ee(o,r.prototype),o}).apply(null,arguments)}function Z(e){return(Z=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function ee(e,t){return(ee=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function et(e){var t="function"==typeof Map?new Map:void 0;return(et=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return X(e,arguments,Z(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),ee(r,e)})(e)}function er(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(er=function(){return!!e})()}function en(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var eo=["page:addBlock","popup:common:addBlock","popup:addNew:addBlock","mobile:addBlock"],ea="dataBlocks.buildVisualizationBlock",el=function(e){var t;if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function r(){var e,t;if(!(this instanceof r))throw TypeError("Cannot call a class as a function");return e=r,t=arguments,e=Z(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,er()?Reflect.construct(e,t||[],Z(this).constructor):e.apply(this,t))}return r.prototype=Object.create(e&&e.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),e&&ee(r,e),t=[{key:"afterAdd",value:function(){return J(function(){var e;return en(this,function(t){e=this.app.pm;try{e.get("@nocobase/plugin-data-visualization")||e.get("plugin-data-visualization")||console.warn("[plugin-build-visualization-block] plugin-data-visualization is not available")}catch(e){console.warn("[plugin-build-visualization-block] plugin-data-visualization is not available")}try{e.get("@nocobase/plugin-ai")||e.get("plugin-ai")||console.warn("[plugin-build-visualization-block] plugin-ai is not available")}catch(e){console.warn("[plugin-build-visualization-block] plugin-ai is not available")}return[2]})}).call(this)}},{key:"load",value:function(){return J(function(){var e;return en(this,function(t){return e=this,this.app.addComponents({BuildVisualizationBlockInitializer:V}),this.app.pluginSettingsManager.add("plugin-build-visualization-block",{icon:"DashboardOutlined",title:this.t("Build Visualization Block"),Component:W,aclSnippet:"pm.plugin-build-visualization-block.settings"}),eo.forEach(function(t){e.app.schemaInitializerManager.addItem(t,ea,{name:"buildVisualizationBlock",title:'{{t("Build Visualization Block", { ns: "plugin-build-visualization-block" })}}',Component:"BuildVisualizationBlockInitializer"})}),[2]})}).call(this)}},{key:"remove",value:function(){return J(function(){var e;return en(this,function(t){return e=this,this.app.pluginSettingsManager.remove("plugin-build-visualization-block"),eo.forEach(function(t){e.app.schemaInitializerManager.removeItem(t,ea)}),[2]})}).call(this)}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(r.prototype,t),r}(et(e.Plugin)),ei=el}(),b}()});
|
|
10
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react-i18next"),require("@nocobase/client-v2"),require("@formily/core"),require("antd"),require("react"),require("@nocobase/client"),require("@formily/react"),require("@ant-design/icons"),require("@nocobase/plugin-workflow/client")):"function"==typeof define&&define.amd?define("plugin-build-visualization-block",["react-i18next","@nocobase/client-v2","@formily/core","antd","react","@nocobase/client","@formily/react","@ant-design/icons","@nocobase/plugin-workflow/client"],t):"object"==typeof exports?exports["plugin-build-visualization-block"]=t(require("react-i18next"),require("@nocobase/client-v2"),require("@formily/core"),require("antd"),require("react"),require("@nocobase/client"),require("@formily/react"),require("@ant-design/icons"),require("@nocobase/plugin-workflow/client")):e["plugin-build-visualization-block"]=t(e["react-i18next"],e["@nocobase/client-v2"],e["@formily/core"],e.antd,e.react,e["@nocobase/client"],e["@formily/react"],e["@ant-design/icons"],e["@nocobase/plugin-workflow/client"])}(self,function(e,t,r,n,o,a,l,i,u){return function(){"use strict";var c,s,f,p={327:function(e,t,r){r.d(t,{CU:function(){return n},an:function(){return o}});var n="plugin-build-visualization-block",o=[{type:"visualization-analyze",title:"Analyze visualization"},{type:"visualization-validate",title:"Validate visualization"},{type:"visualization-generate",title:"Generate visualization"}]},375:function(e){e.exports=i},452:function(e){e.exports=r},230:function(e){e.exports=l},342:function(e){e.exports=a},485:function(e){e.exports=t},990:function(e){e.exports=u},59:function(e){e.exports=n},155:function(e){e.exports=o},953:function(t){t.exports=e}},d={};function b(e){var t=d[e];if(void 0!==t)return t.exports;var r=d[e]={exports:{}};return p[e](r,r.exports,b),r.exports}b.m=p,b.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return b.d(t,{a:t}),t},b.d=function(e,t){for(var r in t)b.o(t,r)&&!b.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},b.f={},b.e=function(e){return Promise.all(Object.keys(b.f).reduce(function(t,r){return b.f[r](e,t),t},[]))},b.u=function(e){return""+e+".6bac6ada1dacea82.js"},b.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),b.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},y={},b.l=function(e,t,r,n){if(y[e])return void y[e].push(t);if(void 0!==r)for(var o,a,l=document.getElementsByTagName("script"),i=0;i<l.length;i++){var u=l[i];if(u.getAttribute("src")==e||u.getAttribute("data-rspack")=="plugin-build-visualization-block:"+r){o=u;break}}o||(a=!0,(o=document.createElement("script")).timeout=120,b.nc&&o.setAttribute("nonce",b.nc),o.setAttribute("data-rspack","plugin-build-visualization-block:"+r),o.src=e),y[e]=[t];var c=function(t,r){o.onerror=o.onload=null,clearTimeout(s);var n=y[e];if(delete y[e],o.parentNode&&o.parentNode.removeChild(o),n&&n.forEach(function(e){return e(r)}),t)return t(r)},s=setTimeout(c.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=c.bind(null,o.onerror),o.onload=c.bind(null,o.onload),a&&document.head.appendChild(o)},b.r=function(e){"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},b.g.importScripts&&(v=b.g.location+"");var y,v,m=b.g.document;if(!v&&m&&(m.currentScript&&"SCRIPT"===m.currentScript.tagName.toUpperCase()&&(v=m.currentScript.src),!v)){var h=m.getElementsByTagName("script");if(h.length)for(var g=h.length-1;g>-1&&(!v||!/^http(s?):/.test(v));)v=h[g--].src}if(!v)throw Error("Automatic publicPath is not supported in this browser");b.p=v.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),c={889:0},b.f.j=function(e,t){var r=b.o(c,e)?c[e]:void 0;if(0!==r)if(r)t.push(r[2]);else{var n=new Promise(function(t,n){r=c[e]=[t,n]});t.push(r[2]=n);var o=b.p+b.u(e),a=Error();b.l(o,function(t){if(b.o(c,e)&&(0!==(r=c[e])&&(c[e]=void 0),r)){var n=t&&("load"===t.type?"missing":t.type),o=t&&t.target&&t.target.src;a.message="Loading chunk "+e+" failed.\n("+n+": "+o+")",a.name="ChunkLoadError",a.type=n,a.request=o,r[1](a)}},"chunk-"+e,e)}},s=function(e,t){var r,n,o=t[0],a=t[1],l=t[2],i=0;if(o.some(function(e){return 0!==c[e]})){for(r in a)b.o(a,r)&&(b.m[r]=a[r]);l&&l(b)}for(e&&e(t);i<o.length;i++)n=o[i],b.o(c,n)&&c[n]&&c[n][0](),c[n]=0},(f=self.webpackChunkplugin_build_visualization_block=self.webpackChunkplugin_build_visualization_block||[]).forEach(s.bind(null,0)),f.push=s.bind(null,f.push.bind(f));var S={};return!function(){var e="",t="u">typeof document?document.currentScript:null;if(t&&t.src){var r=t.src.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"");r.indexOf("/static/plugins/plugin-build-visualization-block/dist/client/")>=0&&(e=r.replace(/\/[^\/]+$/,"/"))}if(!e){var n=window.__webpack_public_path__||"";n&&("/"!==n.charAt(n.length-1)&&(n+="/"),e=n+"static/plugins/plugin-build-visualization-block/dist/client/")}if(!e){var o=window.__nocobase_modern_client_prefix__||"v",a="/"+(o=String(o).replace(/^\/+|\/+$/g,"")||"v")+"/";if(!(e=window.__nocobase_public_path__||"")&&window.location&&window.location.pathname){var l=window.location.pathname||"/",i=l.indexOf(a);e=i>=0?l.slice(0,i+1):"/"}e&&(e=e.replace(RegExp("/"+o+"/?$"),"/")),e||(e="/"),"/"!==e.charAt(e.length-1)&&(e+="/"),e+="static/plugins/plugin-build-visualization-block/dist/client/"}b.p=e}(),!function(){b.r(S),b.d(S,{PluginBuildVisualizationBlockClient:function(){return ep},default:function(){return ed}});var e=b(990),t=b(327);function r(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function a(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(a=function(){return!!e})()}var l=b(342),i=b(375),u=b(59),c=b(155),s=b.n(c),f=b(452),p=b(230),d=b(485);function y(){var e=(0,d.useApp)();return(0,c.useCallback)(function(t,r){return e.i18n.t(t,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({ns:["plugin-build-visualization-block","client"]},r))},[e.i18n])}function v(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function m(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function h(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return v(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return v(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var g=function(e){var t,r,n=y(),o=(0,d.useApp)().apiClient,a=(0,p.useField)(),l=h((0,c.useState)([]),2),i=l[0],b=l[1],v=h((0,c.useState)(!1),2),g=v[0],S=v[1],w=h((0,c.useState)(!1),2),O=w[0],k=w[1];(0,c.useEffect)(function(){var e,t=!0;return(e=function(){var e,r;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(n){switch(n.label){case 0:S(!0),k(!1),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,o.resource("ai").listLLMServices()];case 2:var a,l;if(e=n.sent(),!t)return[2];return b((Array.isArray(l=null==e||null==(a=e.data)?void 0:a.data)?l:[]).filter(function(e){return!!e.name}).map(function(e){return{label:e.title||e.name,value:e.name}})),[3,5];case 3:if(r=n.sent(),!t)return[2];return console.error("Failed to load LLM services:",r),b([]),k(!0),[3,5];case 4:return t&&S(!1),[7];case 5:return[2]}})},function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){m(a,n,o,l,i,"next",e)}function i(e){m(a,n,o,l,i,"throw",e)}l(void 0)})})(),function(){t=!1}},[o]);var E=(0,c.useCallback)(function(e){a.setValue(e);var t=a.query(".model").take();(0,f.isField)(t)&&t.setValue(void 0)},[a]);return s().createElement(u.Select,(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},e),r=r={options:i,loading:g,status:O?"error":void 0,value:a.value,onChange:E,notFoundContent:O?n("Failed to load the list"):void 0,allowClear:!0,showSearch:!0,optionFilterProp:"label"},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t))};function w(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function O(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function k(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return w(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return w(e,t)}}(e,t)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var E=(0,p.observer)(function(e){var t,r,n,o=y(),a=(0,d.useApp)().apiClient,l=(0,p.useField)(),i=(0,p.useForm)(),f=k((0,c.useState)([]),2),b=f[0],v=f[1],m=k((0,c.useState)(!1),2),h=m[0],g=m[1],S=k((0,c.useState)(!1),2),w=S[0],E=S[1],j="string"==typeof(null==(n=i.values)?void 0:n.llmService)?i.values.llmService:void 0;(0,c.useEffect)(function(){var e,t=!0;if(!j){v([]),E(!1);return}return(e=function(){var e,r;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(n){switch(n.label){case 0:g(!0),E(!1),n.label=1;case 1:return n.trys.push([1,3,4,5]),[4,a.resource("ai").listModels({llmService:j})];case 2:var o,l;if(e=n.sent(),!t)return[2];return v((Array.isArray(l=null==e||null==(o=e.data)?void 0:o.data)?l:[]).map(function(e){return e.id||e.name}).filter(function(e){return!!e}).map(function(e){return{label:e,value:e}})),[3,5];case 3:if(r=n.sent(),!t)return[2];return console.error("Failed to load models:",r),v([]),E(!0),[3,5];case 4:return t&&g(!1),[7];case 5:return[2]}})},function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){O(a,n,o,l,i,"next",e)}function i(e){O(a,n,o,l,i,"throw",e)}l(void 0)})})(),function(){t=!1}},[a,j]);var C=(0,c.useCallback)(function(e){l.setValue(e)},[l]);return s().createElement(u.Select,(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},e),r=r={options:b,loading:h,status:w?"error":void 0,value:l.value,onChange:C,disabled:!j,notFoundContent:w?o("Failed to load the list"):void 0,allowClear:!0,showSearch:!0,optionFilterProp:"label"},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t))}),j="aiVisualizationBuilds",C="aiVisualizationBuildSettings",P=["idle","queued","analyzing","generating","completed","failed"],A=function(e){var t,r=e.value,n=e.onChange,o=e.disabled,a=y(),i=(0,l.useCompile)(),f=(0,l.useDataSourceManager)(),p=(0,l.useACLRoleContext)().parseAction,d=null==r?void 0:r.dataSource,b=null!=(t=null==r?void 0:r.collections)?t:[],v=(0,c.useMemo)(function(){var e;return(null!=(e=null==f?void 0:f.getDataSources())?e:[]).map(function(e){return{label:i(e.displayName)||e.key,value:e.key}})},[f,i]),m=(0,c.useCallback)(function(e){return!!p("".concat(e,":list"))},[p]),h=(0,c.useMemo)(function(){if(!d)return[];var e,t,r=null==f?void 0:f.getDataSource(d);return(null!=(e=null==r||null==(t=r.collectionManager)?void 0:t.getCollections())?e:[]).filter(function(e){return m(e.name)}).map(function(e){return{label:i(e.title)||e.name,value:e.name}})},[f,d,i,m]),g=(0,c.useCallback)(function(e){null==n||n({dataSource:e,collections:[]})},[n]),S=(0,c.useCallback)(function(e){var t=e.slice(0,50);null==n||n({dataSource:d,collections:t})},[n,d]),w=b.length>=50;return s().createElement(u.Space,{direction:"vertical",style:{width:"100%"},size:"small"},s().createElement(u.Select,{"aria-label":a("Data source"),placeholder:a("Data source"),style:{width:"100%"},options:v,value:null!=d?d:v.length?void 0:l.DEFAULT_DATA_SOURCE_KEY,onChange:g,disabled:o,showSearch:!0,optionFilterProp:"label"}),s().createElement(u.Select,{"aria-label":a("Collections"),placeholder:a("Collections"),style:{width:"100%"},mode:"multiple",options:h,value:b,onChange:S,disabled:o||!d,showSearch:!0,optionFilterProp:"label"}),w?s().createElement(u.Typography.Text,{type:"warning"},a("You can select at most {{max}} collections",{max:50})):null)},x={idle:"default",queued:"default",analyzing:"processing",generating:"processing",completed:"success",failed:"error"},I={idle:"Idle",queued:"Queued",analyzing:"Analyzing",generating:"Generating",completed:"Completed",failed:"Failed"},T=Object.keys(x),z=function(e){var t,r=y(),n=(0,p.useField)(),o=(0,f.isField)(n)?n.value:void 0,a=null!=(t=e.value)?t:o;return"string"==typeof a&&T.includes(a)?s().createElement(u.Tag,{color:x[a],"aria-label":r(I[a])},r(I[a])):null},M=function(e){var t=e.schema,r=e.usedFallback,n=e.adjustments,o=e.onInsert,a=e.onRegenerate,i=e.onCancel,f=e.loading,p=y(),d=(0,c.useMemo)(function(){return Array.isArray(n)&&n.every(function(e){return(void 0===e?"undefined":e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e)=="object"&&null!==e&&"string"==typeof e.reference&&"string"==typeof e.action})?n:[]},[n]),b=!!t;return s().createElement(u.Space,{direction:"vertical",style:{width:"100%"},size:"middle"},r?s().createElement(u.Alert,{type:"warning",showIcon:!0,message:p("A fallback block was generated")}):null,d.length>0?s().createElement(u.Alert,{type:"info",showIcon:!0,message:p("Some fields were adjusted to match the collection"),description:s().createElement("ul",{style:{margin:0,paddingInlineStart:20}},d.map(function(e,t){return s().createElement("li",{key:"".concat(e.reference,"-").concat(e.action,"-").concat(t)},"remapped"===e.action&&e.replacement?"".concat(e.reference," → ").concat(e.replacement):"".concat(e.reference," → ").concat(e.action))}))}):null,s().createElement("section",{"aria-label":p("Preview")},s().createElement(u.Typography.Title,{level:5,style:{marginTop:0}},p("Preview")),b?s().createElement(l.SchemaComponentOptions,null,s().createElement(l.SchemaComponent,{schema:t})):f?s().createElement(u.Spin,{"aria-label":p("Generating")}):s().createElement(u.Empty,{image:u.Empty.PRESENTED_IMAGE_SIMPLE,description:p("Preview")})),s().createElement(u.Space,null,s().createElement(u.Button,{type:"primary",onClick:function(){return t&&o(t)},disabled:!b||f,"aria-label":p("Insert")},p("Insert")),s().createElement(u.Button,{onClick:a,loading:f,"aria-label":p("Regenerate")},p("Regenerate")),s().createElement(u.Button,{onClick:i,disabled:f,"aria-label":p("Cancel")},p("Cancel"))))};function _(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function F(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function q(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return _(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _(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 B(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function D(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function L(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function R(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){L(a,n,o,l,i,"next",e)}function i(e){L(a,n,o,l,i,"throw",e)}l(void 0)})}}function V(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return D(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return D(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){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function $(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function U(e,t){if(e&&(void 0===e?"undefined":G(e))==="object"){var r=e[t];if("string"==typeof r)return r}return""}var N=function(e){var t=e.onInsert,r=e.onClose,n=y(),o=(0,l.useAPIClient)(),a=(0,l.useApp)(),i=(0,c.useMemo)(function(){return(0,f.createForm)()},[]),d=V((0,c.useState)(""),2),b=d[0],v=d[1],m=V((0,c.useState)({collections:[]}),2),h=m[0],S=m[1],w=V((0,c.useState)({}),2),O=w[0],k=w[1],x=V((0,c.useState)(void 0),2),I=x[0],T=x[1],_=V((0,c.useState)(!1),2),D=_[0],L=_[1],N=V((0,c.useState)(!1),2),Y=N[0],J=N[1],K=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.intervalMs,n=void 0===r?2e3:r,o=t.enabled,a=void 0===o||o,i=(0,l.useAPIClient)(),u=q((0,c.useState)(void 0),2),s=u[0],f=u[1],p=q((0,c.useState)(void 0),2),d=p[0],b=p[1],y=q((0,c.useState)(!1),2),v=y[0],m=y[1],h=(0,c.useRef)(null),g=(0,c.useRef)(!1);return(0,c.useEffect)(function(){var t=function(){null!==h.current&&(clearInterval(h.current),h.current=null)};if(!a||void 0===e)return t(),m(!1),t;var r=!1,o=function(){var n;return(n=function(){var n,o,a;return function(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(l){var u,c;switch(l.label){case 0:if(g.current)return[2];g.current=!0,m(!0),l.label=1;case 1:return l.trys.push([1,3,4,5]),[4,i.resource(j).getResult({filterByTk:e})];case 2:if(n=l.sent(),r)return[2];return(o=function(e){if(e&&(void 0===e?"undefined":B(e))==="object"){var t,r,n,o,a=e.id;if("string"==typeof a||"number"==typeof a)return{id:a,status:"string"==typeof e.status?e.status:"",buildPhase:"string"==typeof(o=e.buildPhase)&&P.includes(o)?e.buildPhase:"idle",blockSchema:null!=(t=e.blockSchema)?t:void 0,blockSpec:null!=(r=e.blockSpec)?r:void 0,adjustments:null!=(n=e.adjustments)?n:void 0,usedFallback:!0===e.usedFallback,errorMessage:"string"==typeof e.errorMessage?e.errorMessage:null}}}(function(e){if(e&&(void 0===e?"undefined":B(e))==="object"){var t=e.data;if(t&&(void 0===t?"undefined":B(t))==="object")return t.data}}(n)))&&(f(o),b(void 0),("completed"===(u=o.buildPhase)||"failed"===u)&&t()),[3,5];case 3:return a=l.sent(),r||b((null!=(c=Error)&&"u">typeof Symbol&&c[Symbol.hasInstance]?!!c[Symbol.hasInstance](a):a instanceof c)?a:Error(String(a))),[3,5];case 4:return g.current=!1,r||m(!1),[7];case 5:return[2]}})},function(){var e=this,t=arguments;return new Promise(function(r,o){var a=n.apply(e,t);function l(e){F(a,r,o,l,i,"next",e)}function i(e){F(a,r,o,l,i,"throw",e)}l(void 0)})})()};return o(),h.current=setInterval(o,n),function(){r=!0,t()}},[i,e,a,n]),{phase:null==s?void 0:s.buildPhase,status:null==s?void 0:s.status,record:s,error:d,loading:v}}(I,{enabled:!!I&&Y}),Q=K.phase,W=K.record;(0,c.useEffect)(function(){("completed"===Q||"failed"===Q)&&J(!1)},[Q]),(0,c.useEffect)(function(){var e=!0;return R(function(){var t,r,n,a;return $(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),[4,o.resource(C).publicGet()];case 1:var u,c;if(n=l.sent(),!e)return[2];return S({dataSource:(a={defaultDataSource:"string"==typeof(c=(u=null==(r=n.data)?void 0:r.data)&&(void 0===u?"undefined":G(u))==="object"?u:{}).defaultDataSource?c.defaultDataSource:void 0,defaultCollections:Array.isArray(c.defaultCollections)?c.defaultCollections.filter(function(e){return"string"==typeof e}):[],defaultLLMService:"string"==typeof c.defaultLLMService?c.defaultLLMService:void 0,defaultModel:"string"==typeof c.defaultModel?c.defaultModel:void 0}).defaultDataSource,collections:null!=(t=a.defaultCollections)?t:[]}),i.setValues({llmService:a.defaultLLMService,model:a.defaultModel}),[3,3];case 2:return console.warn("[plugin-build-visualization-block] Failed to load default settings:",l.sent()),[3,3];case 3:return[2]}})})(),function(){e=!1}},[o,i]);var H=(0,c.useMemo)(function(){var e=a.pm;return!!(e.get("ai")||e.get("@nocobase/plugin-ai")||e.get("plugin-ai"))},[a]),X=h.dataSource,Z=(0,c.useMemo)(function(){var e;return null!=(e=h.collections)?e:[]},[h]),ee=(0,c.useCallback)(function(){var e={};b.trim()?b.length>2e3&&(e.requirement=n("Requirement must be at most {{max}} characters",{max:2e3})):e.requirement=n("Requirement description is required"),Z.length<1?e.collections=n("At least one collection is required"):Z.length>50&&(e.collections=n("You can select at most {{max}} collections",{max:50}));var t=U(i.values,"llmService"),r=U(i.values,"model");return t&&r||(e.ai=n("AI service and model are required")),e},[b,Z,i,n]),et=(0,c.useCallback)(function(){return R(function(){var e,t,r;return $(this,function(a){switch(a.label){case 0:if(!H)return[2];if(Object.keys(e=ee()).length>0)return k(e),[2];k({}),t={requirement:b.trim(),dataSource:X,collections:Z,primaryCollection:Z[0],llmService:U(i.values,"llmService"),model:U(i.values,"model")},L(!0),a.label=1;case 1:return a.trys.push([1,3,4,5]),[4,o.resource(j).build({values:t})];case 2:if(!(r=function(e){if(e&&(void 0===e?"undefined":G(e))==="object"){var t=e.data;if(t&&(void 0===t?"undefined":G(t))==="object"){var r=t.data;if(r&&(void 0===r?"undefined":G(r))==="object"){var n=r.id;if("string"==typeof n||"number"==typeof n)return String(n)}}}}(a.sent())))return k({submit:n("The requirement could not be saved")}),[2];return T(r),J(!0),[3,5];case 3:return a.sent(),k({submit:n("The requirement could not be saved")}),[3,5];case 4:return L(!1),[7];case 5:return[2]}})})()},[H,ee,b,X,Z,i,o,n]),er=(0,c.useCallback)(function(){return R(function(){return $(this,function(e){switch(e.label){case 0:if(!I)return[2];k({}),L(!0),e.label=1;case 1:return e.trys.push([1,3,4,5]),[4,o.resource(j).retry({filterByTk:I})];case 2:return e.sent(),J(!0),[3,5];case 3:return e.sent(),k({submit:n("The requirement could not be saved")}),[3,5];case 4:return L(!1),[7];case 5:return[2]}})})()},[o,I,n]);return I&&!Y&&"completed"===Q&&W?s().createElement(M,{schema:W.blockSchema,usedFallback:W.usedFallback,adjustments:W.adjustments,onInsert:t,onRegenerate:er,onCancel:r,loading:!1}):I&&!Y&&"failed"===Q?s().createElement(u.Space,{direction:"vertical",style:{width:"100%"},size:"middle"},s().createElement(u.Alert,{type:"error",showIcon:!0,message:(null==W?void 0:W.errorMessage)||n("The requirement could not be saved")}),s().createElement(u.Space,null,s().createElement(u.Button,{type:"primary",onClick:er,loading:D},n("Retry")),s().createElement(u.Button,{onClick:r},n("Cancel")))):I&&Y?s().createElement(u.Space,{direction:"vertical",align:"center",style:{width:"100%",padding:24},size:"middle"},s().createElement(u.Spin,{"aria-label":n("Generating")}),s().createElement(u.Space,null,s().createElement(z,{value:Q}),s().createElement(u.Typography.Text,{type:"secondary"},n("Generating")))):s().createElement(u.Space,{direction:"vertical",style:{width:"100%"},size:"middle"},H?null:s().createElement(u.Alert,{type:"warning",showIcon:!0,message:n("The AI service is unavailable")}),s().createElement("div",null,s().createElement(u.Typography.Text,{strong:!0},n("Requirement")),s().createElement(u.Input.TextArea,{"aria-label":n("Requirement"),placeholder:n("Describe the block you want to build"),value:b,onChange:function(e){return v(e.target.value)},showCount:!0,maxLength:2e3,autoSize:{minRows:3,maxRows:8},status:O.requirement?"error":void 0}),O.requirement?s().createElement(u.Typography.Text,{type:"danger"},O.requirement):null),s().createElement("div",null,s().createElement(u.Typography.Text,{strong:!0},n("Collections")),s().createElement(A,{value:h,onChange:S}),O.collections?s().createElement(u.Typography.Text,{type:"danger"},O.collections):null),s().createElement(p.FormProvider,{form:i},s().createElement("div",null,s().createElement(u.Typography.Text,{strong:!0},n("AI service")),s().createElement(p.Field,{name:"llmService",component:[g,{placeholder:n("AI service"),style:{width:"100%"}}]})),s().createElement("div",null,s().createElement(u.Typography.Text,{strong:!0},n("Model")),s().createElement(p.Field,{name:"model",component:[E,{placeholder:n("Model"),style:{width:"100%"}}]}))),O.ai?s().createElement(u.Typography.Text,{type:"danger"},O.ai):null,O.submit?s().createElement(u.Alert,{type:"error",showIcon:!0,message:O.submit}):null,s().createElement(u.Space,null,s().createElement(u.Button,{type:"primary",onClick:et,loading:D,disabled:!H},n("Build")),s().createElement(u.Button,{onClick:r,disabled:D},n("Cancel"))))};function Y(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var J=function(){var e,t,r,n=(0,l.useSchemaInitializerItem)(),o=(0,l.useSchemaInitializer)().insert,a=(0,l.useACLRoleContext)().parseAction,f=y(),p=function(e){if(Array.isArray(e))return e}(e=(0,c.useState)(!1))||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o=[],a=!0,l=!1;try{for(n=n.call(e);!(a=(t=n.next()).done)&&(o.push(t.value),2!==o.length);a=!0);}catch(e){l=!0,r=e}finally{try{a||null==n.return||n.return()}finally{if(l)throw r}}return o}}(e)||function(e){if(e){if("string"==typeof e)return Y(e,2);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return Y(e,2)}}(e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(),d=p[0],b=p[1],v=(0,c.useCallback)(function(){return b(!0)},[]),m=(0,c.useCallback)(function(){return b(!1)},[]),h=(0,c.useCallback)(function(e){b(!1),o(e)},[o]);if(!a||!a("aiVisualizationBuilds:build"))return null;var g=n.title||f("Build Visualization Block");return s().createElement(s().Fragment,null,s().createElement(l.SchemaInitializerItem,(t=function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter(function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable}))),n.forEach(function(t){var n;n=r[t],t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n})}return e}({},n),r=r={title:g,icon:s().createElement(i.DashboardOutlined,null),onClick:v},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t)),s().createElement(u.Modal,{open:d,title:g,footer:null,destroyOnClose:!0,onCancel:m,width:720},s().createElement(N,{onInsert:h,onClose:m})))};function K(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function Q(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function W(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){Q(a,n,o,l,i,"next",e)}function i(e){Q(a,n,o,l,i,"throw",e)}l(void 0)})}}function H(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r,n,o=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=o){var a=[],l=!0,i=!1;try{for(o=o.call(e);!(l=(r=o.next()).done)&&(a.push(r.value),!t||a.length!==t);l=!0);}catch(e){i=!0,n=e}finally{try{l||null==o.return||o.return()}finally{if(i)throw n}}return a}}(e,t)||function(e,t){if(e){if("string"==typeof e)return K(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return K(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 X(e){return e&&"u">typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function Z(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}function ee(e,t){if(e&&(void 0===e?"undefined":X(e))==="object"){var r=e[t];return"string"==typeof r&&r.trim()?r.trim():void 0}}var et=function(){var e=(0,d.useApp)().apiClient,t=u.App.useApp().message,r=y(),n=(0,c.useMemo)(function(){return(0,f.createForm)()},[]),o=H((0,c.useState)({collections:[]}),2),a=o[0],l=o[1],i=H((0,c.useState)(!0),2),b=i[0],v=i[1],m=H((0,c.useState)(!0),2),h=m[0],S=m[1],w=H((0,c.useState)(!1),2),O=w[0],k=w[1],j=H((0,c.useState)(!1),2),P=j[0],x=j[1];(0,c.useEffect)(function(){var t=!0;return W(function(){var r,o,a,i,u,c;return Z(this,function(s){switch(s.label){case 0:S(!0),x(!1),s.label=1;case 1:return s.trys.push([1,3,4,5]),[4,e.resource(C).publicGet()];case 2:var f,p;if(i=s.sent(),!t)return[2];return l({dataSource:null!=(r=(u={defaultDataSource:"string"==typeof(p=(f=null==(a=i.data)?void 0:a.data)&&(void 0===f?"undefined":X(f))==="object"?f:{}).defaultDataSource?p.defaultDataSource:void 0,defaultCollections:Array.isArray(p.defaultCollections)?p.defaultCollections.filter(function(e){return"string"==typeof e}):[],defaultLLMService:"string"==typeof p.defaultLLMService?p.defaultLLMService:void 0,defaultModel:"string"==typeof p.defaultModel?p.defaultModel:void 0,enableAITool:!1!==p.enableAITool}).defaultDataSource)?r:void 0,collections:null!=(o=u.defaultCollections)?o:[]}),n.setValues({llmService:u.defaultLLMService,model:u.defaultModel}),v(!1!==u.enableAITool),[3,5];case 3:if(c=s.sent(),!t)return[2];return console.error("[plugin-build-visualization-block] Failed to load settings:",c),x(!0),[3,5];case 4:return t&&S(!1),[7];case 5:return[2]}})})(),function(){t=!1}},[e,n]);var I=(0,c.useCallback)(function(){return W(function(){var o;return Z(this,function(l){switch(l.label){case 0:k(!0),l.label=1;case 1:return l.trys.push([1,,3,4]),[4,e.resource(C).update({filterByTk:1,values:{defaultDataSource:a.dataSource,defaultCollections:null!=(o=a.collections)?o:[],defaultLLMService:ee(n.values,"llmService"),defaultModel:ee(n.values,"model"),enableAITool:b}})];case 2:return l.sent(),t.success(r("Saved successfully")),[3,4];case 3:return k(!1),[7];case 4:return[2]}})})()},[e,a,b,n,t,r]);return s().createElement(u.Card,{loading:h},s().createElement(u.Space,{direction:"vertical",size:"middle",style:{width:"100%",maxWidth:720}},P?s().createElement(u.Alert,{type:"error",showIcon:!0,message:r("Failed to load the list")}):null,s().createElement(u.Form,{layout:"vertical"},s().createElement(u.Form.Item,{label:r("Default collections")},s().createElement(A,{value:a,onChange:l})),s().createElement(p.FormProvider,{form:n},s().createElement(u.Form.Item,{label:r("Default AI service")},s().createElement(p.Field,{name:"llmService",component:[g,{style:{width:"100%"}}]})),s().createElement(u.Form.Item,{label:r("Default model")},s().createElement(p.Field,{name:"model",component:[E,{style:{width:"100%"}}]}))),s().createElement(u.Form.Item,{label:r("Enable AI tool")},s().createElement(u.Switch,{checked:b,onChange:v})),s().createElement(u.Button,{type:"primary",loading:O,onClick:I},r("Save")))))};function er(e,t,r,n,o,a,l){try{var i=e[a](l),u=i.value}catch(e){r(e);return}i.done?t(u):Promise.resolve(u).then(n,o)}function en(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var a=e.apply(t,r);function l(e){er(a,n,o,l,i,"next",e)}function i(e){er(a,n,o,l,i,"throw",e)}l(void 0)})}}function eo(e,t,r){return(eo=eu()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&el(o,r.prototype),o}).apply(null,arguments)}function ea(e){return(ea=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function el(e,t){return(el=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function ei(e){var t="function"==typeof Map?new Map:void 0;return(ei=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return eo(e,arguments,ea(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),el(r,e)})(e)}function eu(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(eu=function(){return!!e})()}function ec(e,t){var r,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},l=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),i=Object.defineProperty;return i(l,"next",{value:u(0)}),i(l,"throw",{value:u(1)}),i(l,"return",{value:u(2)}),"function"==typeof Symbol&&i(l,Symbol.iterator,{value:function(){return this}}),l;function u(i){return function(u){var c=[i,u];if(r)throw TypeError("Generator is already executing.");for(;l&&(l=0,c[0]&&(a=0)),a;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return a.label++,{value:c[1],done:!1};case 5:a.label++,n=c[1],c=[0];continue;case 7:c=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===c[0]||2===c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){a.label=c[1];break}if(6===c[0]&&a.label<o[1]){a.label=o[1],o=c;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(c);break}o[2]&&a.ops.pop(),a.trys.pop();continue}c=t.call(e,a)}catch(e){c=[6,e],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}var es=["page:addBlock","popup:common:addBlock","popup:addNew:addBlock","mobile:addBlock"],ef="dataBlocks.buildVisualizationBlock",ep=function(l){var i;if("function"!=typeof l&&null!==l)throw TypeError("Super expression must either be null or a function");function u(){var e,t;if(!(this instanceof u))throw TypeError("Cannot call a class as a function");return e=u,t=arguments,e=ea(e),function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,eu()?Reflect.construct(e,t||[],ea(this).constructor):e.apply(this,t))}return u.prototype=Object.create(l&&l.prototype,{constructor:{value:u,writable:!0,configurable:!0}}),l&&el(u,l),i=[{key:"afterAdd",value:function(){return en(function(){var e;return ec(this,function(t){e=this.app.pm;try{e.get("@nocobase/plugin-data-visualization")||e.get("plugin-data-visualization")||console.warn("[plugin-build-visualization-block] plugin-data-visualization is not available")}catch(e){console.warn("[plugin-build-visualization-block] plugin-data-visualization is not available")}try{e.get("@nocobase/plugin-ai")||e.get("plugin-ai")||console.warn("[plugin-build-visualization-block] plugin-ai is not available")}catch(e){console.warn("[plugin-build-visualization-block] plugin-ai is not available")}return[2]})}).call(this)}},{key:"load",value:function(){return en(function(){var l;return ec(this,function(i){return l=this,!function(l){var i=null==(f=l.pm)?void 0:f.get("workflow");if(i){var u=!0,c=!1,s=void 0;try{for(var f,p,d=t.an[Symbol.iterator]();!(u=(p=d.next()).done);u=!0)!function(){var l=p.value,u=function(e){if("function"!=typeof e&&null!==e)throw TypeError("Super expression must either be null or a function");function i(){var e,o,u;if(!(this instanceof i))throw TypeError("Cannot call a class as a function");return o=i,u=arguments,o=n(o),e=function(e,t){var r;if(t&&("object"==((r=t)&&"u">typeof Symbol&&r.constructor===Symbol?"symbol":typeof r)||"function"==typeof t))return t;if(void 0===e)throw ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(this,a()?Reflect.construct(o,u||[],n(this).constructor):o.apply(this,u)),r(e,"type",l.type),r(e,"title","{{t("+JSON.stringify(l.title)+", { ns: "+JSON.stringify(t.CU)+" })}}"),r(e,"group","extended"),r(e,"async",!0),r(e,"FieldsetLoader",function(){return b.e("59").then(b.bind(b,414))}),e}return i.prototype=Object.create(e&&e.prototype,{constructor:{value:i,writable:!0,configurable:!0}}),e&&o(i,e),i}(e.Instruction);i.registerInstruction(l.type,u)}()}catch(e){c=!0,s=e}finally{try{u||null==d.return||d.return()}finally{if(c)throw s}}}}(this.app),this.app.addComponents({BuildVisualizationBlockInitializer:J}),this.app.pluginSettingsManager.add("plugin-build-visualization-block",{icon:"DashboardOutlined",title:this.t("Build Visualization Block"),Component:et,aclSnippet:"pm.plugin-build-visualization-block.settings"}),es.forEach(function(e){l.app.schemaInitializerManager.addItem(e,ef,{name:"buildVisualizationBlock",title:'{{t("Build Visualization Block", { ns: "plugin-build-visualization-block" })}}',Component:"BuildVisualizationBlockInitializer"})}),[2]})}).call(this)}},{key:"remove",value:function(){return en(function(){var e;return ec(this,function(t){return e=this,this.app.pluginSettingsManager.remove("plugin-build-visualization-block"),es.forEach(function(t){e.app.schemaInitializerManager.removeItem(t,ef)}),[2]})}).call(this)}}],function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(u.prototype,i),u}(ei(l.Plugin)),ed=ep}(),S}()});
|
|
@@ -0,0 +1,10 @@
|
|
|
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_build_visualization_block_client_v2=self.webpackChunkplugin_build_visualization_block_client_v2||[]).push([["385"],{144:function(e,t,r){r.r(t),r.d(t,{default:function(){return p}});var n=r(485),l=r(625),o=r(59),a=r(155),u=r.n(a),i=r(284),c=r(456),s=r(667),f=r(515);function m(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function d(e,t,r,n,l,o,a){try{var u=e[o](a),i=u.value}catch(e){r(e);return}u.done?t(i):Promise.resolve(i).then(n,l)}function p(){var e,t=(0,n.useApp)().apiClient,r=(0,f.k)(),a=o.App.useApp().message,p=(function(e){if(Array.isArray(e))return e}(e=o.Form.useForm())||function(e){var t,r,n=null==e?null:"u">typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var l=[],o=!0,a=!1;try{for(n=n.call(e);!(o=(t=n.next()).done)&&(l.push(t.value),1!==l.length);o=!0);}catch(e){a=!0,r=e}finally{try{o||null==n.return||n.return()}finally{if(a)throw r}}return l}}(e)||function(e){if(e){if("string"==typeof e)return m(e,1);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return m(e,1)}}(e)||function(){throw TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}())[0],v=o.Form.useWatch("llmService",p),b=(0,l.useRequest)(function(){return(0,i.M5)(t)},{onSuccess:function(e){return p.setFieldsValue({collections:{dataSource:e.defaultDataSource,collections:e.defaultCollections||[]},llmService:e.defaultLLMService,model:e.defaultModel,enableAITool:!1!==e.enableAITool})}}),y=(0,l.useRequest)(function(e){var n;return(n=function(){var n,l,o;return function(e,t){var r,n,l,o={label:0,sent:function(){if(1&l[0])throw l[1];return l[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),u=Object.defineProperty;return u(a,"next",{value:i(0)}),u(a,"throw",{value:i(1)}),u(a,"return",{value:i(2)}),"function"==typeof Symbol&&u(a,Symbol.iterator,{value:function(){return this}}),a;function i(u){return function(i){var c=[u,i];if(r)throw TypeError("Generator is already executing.");for(;a&&(a=0,c[0]&&(o=0)),o;)try{if(r=1,n&&(l=2&c[0]?n.return:c[0]?n.throw||((l=n.return)&&l.call(n),0):n.next)&&!(l=l.call(n,c[1])).done)return l;switch(n=0,l&&(c=[2&c[0],l.value]),c[0]){case 0:case 1:l=c;break;case 4:return o.label++,{value:c[1],done:!1};case 5:o.label++,n=c[1],c=[0];continue;case 7:c=o.ops.pop(),o.trys.pop();continue;default:if(!(l=(l=o.trys).length>0&&l[l.length-1])&&(6===c[0]||2===c[0])){o=0;continue}if(3===c[0]&&(!l||c[1]>l[0]&&c[1]<l[3])){o.label=c[1];break}if(6===c[0]&&o.label<l[1]){o.label=l[1],l=c;break}if(l&&o.label<l[2]){o.label=l[2],o.ops.push(c);break}l[2]&&o.ops.pop(),o.trys.pop();continue}c=t.call(e,o)}catch(e){c=[6,e],n=0}finally{r=l=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}}}(this,function(u){switch(u.label){case 0:return o={defaultDataSource:null==(n=e.collections)?void 0:n.dataSource,defaultCollections:(null==(l=e.collections)?void 0:l.collections)||[],defaultLLMService:e.llmService,defaultModel:e.model,enableAITool:e.enableAITool},[4,(0,i.DZ)(t,o)];case 1:return u.sent(),a.success(r("Saved successfully")),[2]}})},function(){var e=this,t=arguments;return new Promise(function(r,l){var o=n.apply(e,t);function a(e){d(o,r,l,a,u,"next",e)}function u(e){d(o,r,l,a,u,"throw",e)}a(void 0)})})()},{manual:!0,onError:function(){return a.error(r("Failed to save settings"))}});return u().createElement(o.Card,null,b.error&&u().createElement(o.Alert,{type:"error",showIcon:!0,message:r("Failed to load the list"),action:u().createElement(o.Button,{onClick:b.refresh},r("Retry"))}),u().createElement(o.Form,{form:p,layout:"vertical",style:{maxWidth:720},disabled:b.loading||!!b.error||y.loading,onFinish:function(e){return y.run(e)}},u().createElement(o.Form.Item,{name:"collections",label:r("Default collections")},u().createElement(s.E,null)),u().createElement(o.Form.Item,{name:"llmService",label:r("Default AI service")},u().createElement(c.g,{onChange:function(){return p.setFieldValue("model",void 0)}})),u().createElement(o.Form.Item,{name:"model",label:r("Default model")},u().createElement(c.o,{service:v})),u().createElement(o.Form.Item,{name:"enableAITool",label:r("Enable AI tool"),valuePropName:"checked"},u().createElement(o.Switch,null)),u().createElement(o.Button,{type:"primary",htmlType:"submit",loading:y.loading},r("Save"))))}}}]);
|
|
@@ -0,0 +1,10 @@
|
|
|
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_build_visualization_block_client_v2=self.webpackChunkplugin_build_visualization_block_client_v2||[]).push([["59"],{414:function(e,i,n){n.r(i),n.d(i,{default:function(){return l}});var t=n(155),u=n.n(t),r=n(59),s=n(953),o=n(327);function l(){var e=(0,s.useTranslation)(o.CU).t;return u().createElement(r.Alert,{type:"info",showIcon:!0,message:e("This node processes the request that triggered this workflow. No configuration is required.")})}}}]);
|