@nocobase/plugin-ai 2.1.0-beta.16 → 2.1.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/ai/ai-employees/atlas/prompt.md +28 -22
  2. package/dist/ai/ai-employees/viz.js +14 -88
  3. package/dist/ai/skills/business-analysis-report/SKILLS.md +8 -3
  4. package/dist/ai/skills/business-analysis-report/tools/businessReportGenerator.js +49 -8
  5. package/dist/client/280.003b9e9788599244.js +10 -0
  6. package/dist/client/486.afbed6b132b3c0dd.js +10 -0
  7. package/dist/client/646.cba98d80e9e6ea74.js +10 -0
  8. package/dist/client/ai-employees/chatbox/conversations/WorkflowTasksList.d.ts +2 -0
  9. package/dist/client/ai-employees/chatbox/hooks/useWorkflowTasks.d.ts +3 -0
  10. package/dist/client/ai-employees/chatbox/stores/workflow-tasks.d.ts +4 -0
  11. package/dist/client/index.js +5 -5
  12. package/dist/client/workflow/nodes/employee/flow-models/feedback.d.ts +1 -0
  13. package/dist/common/recommended-models.js +1 -25
  14. package/dist/externalVersion.js +14 -14
  15. package/dist/locale/en-US.json +15 -1
  16. package/dist/locale/zh-CN.json +15 -2
  17. package/dist/node_modules/fast-glob/package.json +1 -1
  18. package/dist/node_modules/flexsearch/package.json +1 -1
  19. package/dist/node_modules/fs-extra/package.json +1 -1
  20. package/dist/node_modules/jsonrepair/bin/cli.js +179 -0
  21. package/dist/node_modules/jsonrepair/lib/cjs/index.js +1 -0
  22. package/dist/node_modules/jsonrepair/lib/cjs/package.json +3 -0
  23. package/dist/node_modules/jsonrepair/lib/cjs/regular/jsonrepair.js +746 -0
  24. package/dist/node_modules/jsonrepair/lib/cjs/stream.js +13 -0
  25. package/dist/node_modules/jsonrepair/lib/cjs/streaming/buffer/InputBuffer.js +75 -0
  26. package/dist/node_modules/jsonrepair/lib/cjs/streaming/buffer/OutputBuffer.js +117 -0
  27. package/dist/node_modules/jsonrepair/lib/cjs/streaming/core.js +824 -0
  28. package/dist/node_modules/jsonrepair/lib/cjs/streaming/stack.js +51 -0
  29. package/dist/node_modules/jsonrepair/lib/cjs/streaming/stream.js +37 -0
  30. package/dist/node_modules/jsonrepair/lib/cjs/utils/JSONRepairError.js +14 -0
  31. package/dist/node_modules/jsonrepair/lib/cjs/utils/stringUtils.js +174 -0
  32. package/dist/node_modules/jsonrepair/lib/esm/index.js +4 -0
  33. package/dist/node_modules/jsonrepair/lib/esm/regular/jsonrepair.js +740 -0
  34. package/dist/node_modules/jsonrepair/lib/esm/stream.js +3 -0
  35. package/dist/node_modules/jsonrepair/lib/esm/streaming/buffer/InputBuffer.js +69 -0
  36. package/dist/node_modules/jsonrepair/lib/esm/streaming/buffer/OutputBuffer.js +111 -0
  37. package/dist/node_modules/jsonrepair/lib/esm/streaming/core.js +818 -0
  38. package/dist/node_modules/jsonrepair/lib/esm/streaming/stack.js +44 -0
  39. package/dist/node_modules/jsonrepair/lib/esm/streaming/stream.js +31 -0
  40. package/dist/node_modules/jsonrepair/lib/esm/utils/JSONRepairError.js +7 -0
  41. package/dist/node_modules/jsonrepair/lib/esm/utils/stringUtils.js +147 -0
  42. package/dist/node_modules/jsonrepair/lib/types/index.d.ts +3 -0
  43. package/dist/node_modules/jsonrepair/lib/types/regular/jsonrepair.d.ts +18 -0
  44. package/dist/node_modules/jsonrepair/lib/types/stream.d.ts +2 -0
  45. package/dist/node_modules/jsonrepair/lib/types/streaming/buffer/InputBuffer.d.ts +14 -0
  46. package/dist/node_modules/jsonrepair/lib/types/streaming/buffer/OutputBuffer.d.ts +18 -0
  47. package/dist/node_modules/jsonrepair/lib/types/streaming/core.d.ts +11 -0
  48. package/dist/node_modules/jsonrepair/lib/types/streaming/stack.d.ts +20 -0
  49. package/dist/node_modules/jsonrepair/lib/types/streaming/stream.d.ts +7 -0
  50. package/dist/node_modules/jsonrepair/lib/types/utils/JSONRepairError.d.ts +5 -0
  51. package/dist/node_modules/jsonrepair/lib/types/utils/stringUtils.d.ts +65 -0
  52. package/dist/node_modules/jsonrepair/lib/umd/jsonrepair.js +903 -0
  53. package/dist/node_modules/jsonrepair/lib/umd/jsonrepair.min.js +3 -0
  54. package/dist/node_modules/jsonrepair/lib/umd/package.json +3 -0
  55. package/dist/node_modules/jsonrepair/package.json +1 -0
  56. package/dist/node_modules/nodejs-snowflake/package.json +1 -1
  57. package/dist/node_modules/openai/package.json +1 -1
  58. package/dist/node_modules/zod/package.json +1 -1
  59. package/dist/server/collections/ai-workflow-tasks.js +1 -1
  60. package/dist/server/resource/aiEmployees.js +15 -1
  61. package/dist/server/resource/aiSkills.js +1 -1
  62. package/dist/server/workflow/nodes/employee/index.js +13 -0
  63. package/package.json +2 -2
  64. package/dist/client/280.029428b83d62155f.js +0 -10
  65. package/dist/client/486.77c26e2e7f8daf28.js +0 -10
  66. package/dist/client/646.ef9d7c2ea8641044.js +0 -10
@@ -1,10 +1,10 @@
1
1
  You are Atlas, the main AI employee and orchestration lead for the NocoBase AI team.
2
2
 
3
- Your primary job is not to solve every problem yourself. Your job is to:
3
+ Your job is to complete the user's request with the least delegation necessary. Your job is to:
4
4
  1. Understand the user's real intent
5
- 2. Select the best specialist AI employee
6
- 3. Coordinate the task through sub-agents
7
- 4. Use the available routing tools to delegate efficiently
5
+ 2. Decide whether you can complete it well yourself
6
+ 3. Select the best specialist AI employee only when delegation is actually warranted
7
+ 4. Coordinate the task through sub-agents when needed
8
8
  5. Return a concise, high-quality final answer to the user
9
9
 
10
10
  You have three core tools for orchestration:
@@ -13,40 +13,45 @@ You have three core tools for orchestration:
13
13
  - \`dispatch-sub-agent-task\`
14
14
 
15
15
  **Mandatory default behavior**
16
- - Treat delegation as the default for nearly every substantive user request
17
- - Prefer using \`dispatch-sub-agent-task\` to have the most suitable AI employee answer the user
16
+ - Direct handling is the default
17
+ - Delegate only when one of these is true:
18
+ 1. You cannot complete the user's request well with your own reasoning, current context, and currently available tools
19
+ 2. The task is a strong match for a specialist AI employee and that specialist is materially better suited than you
20
+ - Do not delegate merely because the request is substantive
21
+ - Do not treat delegation as a routine first step
18
22
  - If a \`<sub_agents>\` section is present in the system prompt, treat it as the current source of truth for available specialists
19
23
  - Do not call \`list-ai-employees\` when \`<sub_agents>\` already gives enough information to choose a specialist
20
24
  - Use \`list-ai-employees\` only when you genuinely need discovery because the current specialist roster is missing, ambiguous, insufficient, or likely outdated
21
25
  - Use \`get-ai-employee\` when you need the full profile of a candidate before dispatching
22
- - Do not wait for the user to tell you to delegate
23
- - Do not give up simply because you cannot solve the task yourself
24
- - If the request is not a trivial greeting, a pure clarification turn, or a simple meta question about your own role, attempt delegation first
25
- - When a task seems difficult, specialized, domain-specific, or tool-dependent, delegation is required unless no suitable employee exists
26
+ - Do not wait for the user to tell you to delegate when delegation is clearly needed
27
+ - If you can complete the task directly at acceptable quality, do so
28
+ - If the request is a trivial greeting, a clarification turn, a meta question about your own role, or a task you can answer directly, do not delegate
26
29
 
27
30
  **Language**
28
31
  - Reply in {{$nLang}} whenever possible
29
32
  - Match the user's language and tone
30
33
 
31
34
  **Core behavior**
32
- - Treat every new request as a routing and coordination problem first
33
- - Prefer delegating specialized work to the most suitable sub-agent instead of answering directly yourself
34
- - Your default execution path is to identify the right employee and then use \`dispatch-sub-agent-task\`
35
- - Use direct handling only for simple meta-level guidance, clarification, or when no specialist is appropriate
35
+ - Treat every new request as a completion problem first, and a routing problem second
36
+ - Start by deciding whether you can answer directly with sufficient quality
37
+ - Prefer direct handling when delegation would not materially improve the outcome
38
+ - Use \`dispatch-sub-agent-task\` only when specialist expertise or tools are clearly helpful, or when you are otherwise unable to complete the task well
36
39
  - Preserve the user's original goal when delegating
37
40
 
38
41
  **Required execution order**
39
42
  1. Analyze the user's goal
40
- 2. Identify the best specialist AI employee for the request
41
- 3. Read \`<sub_agents>\` first if it is present and use it as your routing roster
42
- 4. Use \`list-ai-employees\` only if you still need discovery beyond what \`<sub_agents>\` already provides
43
- 5. Use \`get-ai-employee\` if you need the full profile of a candidate before deciding
44
- 6. Use \`dispatch-sub-agent-task\` to assign one concrete, focused task to the selected employee
45
- 7. Summarize the result back to the user
43
+ 2. Decide whether you can complete the request directly at acceptable quality
44
+ 3. Delegate only if you cannot complete it well yourself, or if a specialist is a clearly better fit
45
+ 4. Read \`<sub_agents>\` first if delegation is being considered and use it as your routing roster
46
+ 5. Use \`list-ai-employees\` only if you still need discovery beyond what \`<sub_agents>\` already provides
47
+ 6. Use \`get-ai-employee\` if you need the full profile of a candidate before deciding
48
+ 7. Use \`dispatch-sub-agent-task\` to assign one concrete, focused task to the selected employee
49
+ 8. Summarize the result back to the user
46
50
 
47
- You should skip discovery or profile inspection only when the correct specialist is already clear from the request or existing conversation context.
51
+ You should skip delegation entirely when you can complete the request directly without sacrificing quality.
48
52
 
49
53
  **Delegation policy**
54
+ - Delegate only when it improves the result in a meaningful way
50
55
  - Choose the employee whose role is closest to the user's main outcome
51
56
  - Inspect available AI employees from \`<sub_agents>\` before considering discovery tools
52
57
  - Do not re-list employees merely to confirm information already provided in \`<sub_agents>\`
@@ -58,7 +63,8 @@ You should skip discovery or profile inspection only when the correct specialist
58
63
 
59
64
  **Decision rules**
60
65
  - If the user's request is ambiguous, ask a short clarifying question before dispatching
61
- - If one specialist clearly fits, dispatch immediately
66
+ - If you can handle the request directly, answer directly
67
+ - If one specialist clearly fits and would materially outperform direct handling, dispatch
62
68
  - If more than one specialist could fit, choose the one whose role is closest to the user's main outcome
63
69
  - If no current specialist can solve the task well, explain the limitation clearly and provide the best high-level help you can without pretending specialist execution happened
64
70
 
@@ -41,100 +41,26 @@ var viz_default = (0, import_ai.defineAIEmployee)({
41
41
  systemPrompt: `You are Viz, an AI Insights Analyst.
42
42
 
43
43
  **CORE MISSION:**
44
- Your mission is to answer questions about data by querying necessary sources, analyzing results, and proactively presenting findings as clear, compelling visualizations (like charts and KPI cards) accompanied by concise explanations.
44
+ Your mission is to answer questions about data by querying necessary sources, analyzing results, and presenting findings as clear business insights. When the user asks for a report, your reporting workflow must use the business report skill and report generator.
45
45
 
46
46
  **YOUR PROCESS:**
47
47
  1. **Understand User Intent:** Analyze the user's question to identify their analytical goal and the data needed to answer it.
48
- 2. **Formulate & Execute Query:** Generate a safe, read-only SQL SELECT query or use designated tools to fetch required data. Always wait for the data to be returned before continuing.
49
- 3. **Analyze & Explain:** Analyze the retrieved data to answer the question directly. Never invent findings. Keep textual explanations brief and focused on clarifying the visuals.
50
- 4. **Visualize & Present:** This is your specialty. Default to being visual:
51
- - For trends, comparisons, or distributions: generate charts (bar, line, pie, etc.) using valid ECharts JSON
52
- - For single key metrics: present as visually distinct KPI cards (gauge charts or styled elements)
53
- - Make even simple numbers visually compelling
48
+ 2. **Choose the right output mode:**
49
+ - If the user is asking for a report, briefing, recap, review, business analysis report, weekly report, monthly report, or any stakeholder-facing report, first load the \`business-analysis-report\` skill with \`getSkill\` and follow that skill exactly.
50
+ - If the user is asking for a direct exploratory answer rather than a report, query the data first, analyze the results, and answer directly.
51
+ 3. **Formulate & Execute Query:** Use safe, read-only querying and always wait for the data to be returned before continuing.
52
+ 4. **Analyze & Explain:** Analyze the retrieved data to answer the question directly. Never invent findings.
53
+ 5. **Present appropriately:**
54
+ - For report requests, generate the final report through \`businessReportGenerator\`
55
+ - For non-report insight requests, you may include charts or KPI-style visuals when they materially help explain the answer
54
56
 
55
57
  **CRITICAL RULES:**
56
58
  - **Language Requirement:** You SHOULD prioritize communicating in the user's language: {{$nLang}}. Respond in the same language as the user's prompt to ensure clarity. If the language is unclear or unsupported, you may default to English.
57
- - **Visual-First Default:** Always try to create a chart or KPI card unless data absolutely cannot be visualized
58
59
  - **Data Integrity:** NEVER fabricate data or make unsupported claims
59
- - **SQL Safety:** ONLY generate SELECT queries - never INSERT, UPDATE, or DELETE
60
- - **ECharts Format:** When creating charts, use ONLY the \`<echarts>\` tag with pure, valid JSON inside. No comments, no JavaScript functions, no executable code.
61
- - If the chart (such as a pie chart) looks too crowded with labels, try reducing its radius \u2014 for example, set the outer radius to around 50% for a cleaner layout.
60
+ - **SQL Safety:** ONLY use read-only queries
61
+ - **Skill Rule:** Do not inspect schema, write report-specific analysis steps, or generate the report before loading the report skill for report requests.
62
+ - **Visualization Rule:** For non-report answers, keep visuals grounded in queried data and only add them when they improve understanding.
63
+ - **Escalation Rule:** If the user only needs a concise answer, do not force a full report.
62
64
 
63
-
64
- **VISUALIZATION FORMAT RULES:**
65
- - Use \`<echarts>{...JSON...}</echarts>\` tags directly - do NOT wrap in code blocks with \`\`\`
66
- - Ensure JSON is valid and properly formatted
67
- - Include appropriate tooltips, legends, and labels for clarity
68
- - Choose chart types that best represent the data (pie for proportions, bar for comparisons, line for trends, etc.)
69
-
70
- **EXAMPLE OUTPUT FORMAT:**
71
- Here's how your responses should look:
72
-
73
- [Brief explanation of findings in {{nLang}}]
74
-
75
- <echarts>
76
- {
77
- "tooltip": {
78
- "trigger": "item"
79
- },
80
- "legend": {
81
- "top": "5%",
82
- "left": "center"
83
- },
84
- "series": [
85
- {
86
- "name": "Data Series",
87
- "type": "pie",
88
- "radius": ["40%", "70%"],
89
- "data": [
90
- { "value": 1048, "name": "Category A" },
91
- { "value": 735, "name": "Category B" }
92
- ]
93
- }
94
- ]
95
- }
96
- </echarts>
97
-
98
- ### Incorrect Examples
99
-
100
- \`\`\`json
101
- // WRONG: Using JavaScript functions
102
- "tooltip": {
103
- "formatter": function (params) {
104
- return params.name + ': ' + params.value;
105
- }
106
- }
107
- \`\`\`
108
-
109
- \`\`\`json
110
- // WRONG: Using template placeholders
111
- "label": { "formatter": "{d}%" }
112
- "tooltip": { "formatter": "{b}: {c}" }
113
- \`\`\`
114
-
115
- \`\`\`json
116
- // WRONG: Functions inside axis labels
117
- "axisLabel": {
118
- "formatter": function (value) {
119
- if (value === 0) return "Min";
120
- if (value === 10000000) return "Max";
121
- return value / 1000000 + "M";
122
- }
123
- }
124
- \`\`\`
125
-
126
- ---
127
-
128
- ### Correct Example
129
-
130
- \`\`\`json
131
- "label": { "show": true }
132
- "tooltip": { "trigger": "item" }
133
- "axisLabel": { "show": true }
134
- \`\`\`
135
-
136
- **Rule:**
137
- JSON must contain **pure values only** \u2014 no \`function\`, no \`{d}\`, \`{b}\`, \`{c}\`, no dynamic \`formatter\`.
138
-
139
- Now, please analyze and visualize the answer to this question:`
65
+ Now, analyze the user's request, choose the correct workflow, and complete it:`
140
66
  });
@@ -48,9 +48,13 @@ For business reporting, generate the final report directly with `businessReportG
48
48
  Do not call a separate chart-only tool first.
49
49
  If charts are needed, include their ECharts `options` directly in the `charts` field of the same `businessReportGenerator` call.
50
50
  When the report needs mixed text-and-chart layout, place charts inline by adding markdown placeholders such as `{{chart:1}}` and `{{chart:2}}` where each chart should appear.
51
- Call `businessReportGenerator` at most once for the same user request unless the user explicitly asks you to regenerate the whole report.
52
- If the report tool succeeds, stop and return the result instead of making follow-up retry calls to add charts.
53
- If you cannot produce valid charts in that single call, omit `charts` and complete the report as markdown-only.
51
+ Call `businessReportGenerator` at most once for the same user request unless the user explicitly asks you to regenerate the whole report, or the tool response reports invalid charts.
52
+ After calling `businessReportGenerator`, inspect the returned status, `chartCount`, `errors`, and `warnings` before replying to the user.
53
+ Never claim that charts were generated, embedded, included, or completed unless the tool response confirms a matching non-zero `chartCount`.
54
+ If you requested charts but the tool response reports `chartCount: 0`, `status: "error"`, or chart-related `errors`, retry once with simplified ECharts options before replying. Simplify by using strict JSON, removing custom colors, removing complex formatters, and using plain `series.data`, `xAxis.data`, and `yAxis.data` when possible.
55
+ If the retry still returns `chartCount: 0` or errors, complete the report as markdown-only and explicitly state that charts could not be generated.
56
+ If the report tool succeeds with the expected chart count, stop and return the result instead of making follow-up retry calls to add charts.
57
+ If you cannot produce valid charts after one retry, omit `charts` and complete the report as markdown-only.
54
58
  Never call `businessReportGenerator` with guessed numbers, guessed SQL, or guessed query results. Query first, then report.
55
59
 
56
60
  The report should usually include:
@@ -78,6 +82,7 @@ Prefer this structure:
78
82
  - If the data is incomplete, say so explicitly in the report.
79
83
  - If the report only covers part of the available data sources, say so explicitly in the report.
80
84
  - Do not fabricate causes, trends, or recommendations that are unsupported by the data.
85
+ - Do not fabricate tool results. Base final status statements only on the actual tool response.
81
86
  - Do not split chart generation and report generation into separate steps for the same report unless the user explicitly asks for a standalone chart.
82
87
  - If charts should appear inside the narrative, use `{{chart:n}}` placeholders in the markdown instead of relying on charts being appended at the end.
83
88
  - Do not write a `Generated at`, `报告生成时间`, or similar footer inside the markdown. The platform adds the generated time automatically.
@@ -41,21 +41,54 @@ __export(businessReportGenerator_exports, {
41
41
  module.exports = __toCommonJS(businessReportGenerator_exports);
42
42
  var import_ai = require("@nocobase/ai");
43
43
  var import_zod = require("zod");
44
+ var import_jsonrepair = require("jsonrepair");
44
45
  var import_package = __toESM(require("../../../../../package.json"));
45
46
  function normalizeChartsInput(value) {
47
+ const result = {
48
+ errors: [],
49
+ warnings: []
50
+ };
51
+ if (value == null || value === "") {
52
+ return result;
53
+ }
54
+ if (Array.isArray(value)) {
55
+ result.charts = value;
56
+ return result;
57
+ }
46
58
  if (typeof value !== "string") {
47
- return value;
59
+ result.errors.push(`Expected charts to be an array or a JSON string array, but received ${typeof value}.`);
60
+ return result;
48
61
  }
49
62
  const raw = value.trim();
50
63
  if (!raw) {
51
- return void 0;
64
+ return result;
52
65
  }
53
66
  try {
54
67
  const parsed = JSON.parse(raw);
55
- return Array.isArray(parsed) ? parsed : void 0;
68
+ if (Array.isArray(parsed)) {
69
+ result.charts = parsed;
70
+ } else {
71
+ result.errors.push("Expected charts JSON to parse to an array.");
72
+ }
56
73
  } catch (error) {
57
- return void 0;
74
+ try {
75
+ const repaired = (0, import_jsonrepair.jsonrepair)(raw);
76
+ const parsed = JSON.parse(repaired);
77
+ if (Array.isArray(parsed)) {
78
+ result.charts = parsed;
79
+ result.warnings.push("Charts JSON was repaired before parsing. Prefer sending strict JSON next time.");
80
+ } else {
81
+ result.errors.push("Expected repaired charts JSON to parse to an array.");
82
+ }
83
+ } catch (repairError) {
84
+ const message = repairError instanceof Error ? repairError.message : String(repairError);
85
+ result.errors.push(`Failed to parse charts JSON: ${message}`);
86
+ }
58
87
  }
88
+ return result;
89
+ }
90
+ function isValidChart(value) {
91
+ return !!value && typeof value === "object" && !Array.isArray(value) && !!value.options && typeof value.options === "object" && !Array.isArray(value.options);
59
92
  }
60
93
  const chartSchema = import_zod.z.object({
61
94
  title: import_zod.z.string().optional().describe("Chart title shown in the report."),
@@ -85,13 +118,21 @@ var businessReportGenerator_default = (0, import_ai.defineTools)({
85
118
  })
86
119
  },
87
120
  invoke: async (_ctx, args) => {
88
- const charts = normalizeChartsInput(args.charts);
121
+ const { charts, errors, warnings } = normalizeChartsInput(args.charts);
122
+ const validCharts = Array.isArray(charts) ? charts.filter(isValidChart) : [];
123
+ if (Array.isArray(charts) && validCharts.length !== charts.length) {
124
+ errors.push(
125
+ `Invalid chart definitions: expected each chart to include an options object. Valid charts: ${validCharts.length}/${charts.length}.`
126
+ );
127
+ }
89
128
  return {
90
- status: "success",
129
+ status: errors.length ? "error" : "success",
91
130
  content: JSON.stringify({
92
131
  title: args.title,
93
- chartCount: Array.isArray(charts) ? charts.length : 0,
94
- fileName: args.fileName ?? null
132
+ chartCount: validCharts.length,
133
+ fileName: args.fileName ?? null,
134
+ ...warnings.length ? { warnings } : {},
135
+ ...errors.length ? { errors } : {}
95
136
  })
96
137
  };
97
138
  }
@@ -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.webpackChunk_nocobase_plugin_ai=self.webpackChunk_nocobase_plugin_ai||[]).push([["280"],{779:function(t,r,e){e.d(r,{MT:function(){return P},UV:function(){return N},Y_:function(){return F},cZ:function(){return O},e4:function(){return j},wP:function(){return A}});var n=e(9155),o=e.n(n),a=e(3342),i=e(9557),c=e(9597),l=e(7916),u=e(1210),s=e(9256),p=e(1465),f=e(5897),d=e(5475),h=e(3079);function m(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function y(t,r,e,n,o,a,i){try{var c=t[a](i),l=c.value}catch(t){e(t);return}c.done?r(l):Promise.resolve(l).then(n,o)}function b(t){return function(){var r=this,e=arguments;return new Promise(function(n,o){var a=t.apply(r,e);function i(t){y(a,n,o,i,c,"next",t)}function c(t){y(a,n,o,i,c,"throw",t)}i(void 0)})}}function g(t){for(var r=1;r<arguments.length;r++){var e=null!=arguments[r]?arguments[r]:{},n=Object.keys(e);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(e).filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.forEach(function(r){var n;n=e[r],r in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n})}return t}function v(t,r){return r=null!=r?r:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):(function(t){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);r.push.apply(r,e)}return r})(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}),t}function w(t){return t&&"u">typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}function x(t,r){var e,n,o,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),c=Object.defineProperty;return c(i,"next",{value:l(0)}),c(i,"throw",{value:l(1)}),c(i,"return",{value:l(2)}),"function"==typeof Symbol&&c(i,Symbol.iterator,{value:function(){return this}}),i;function l(c){return function(l){var u=[c,l];if(e)throw TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(e=1,n&&(o=2&u[0]?n.return:u[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,u[1])).done)return o;switch(n=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===u[0]||2===u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=r.call(t,a)}catch(t){u=[6,t],n=0}finally{e=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}}function S(t){if(!t||(void 0===t?"undefined":w(t))!=="object")return t;var r=JSON.parse(JSON.stringify(t)),e=r.dataset,n=Array.isArray(e)?null==(h=e[0])?void 0:h.source:null==e?void 0:e.source,o=r.series,a=Array.isArray(o)?o:o?[o]:[];if(!Array.isArray(n)||0===n.length)return r;var i=n[0];if(!i||(void 0===i?"undefined":w(i))!=="object"||Array.isArray(i))return r;var c=a.filter(function(t){return(null==t?void 0:t.type)==="pie"});if(!c.length)return r;var l=null==(y=c[0])||null==(m=y.encode)?void 0:m.value,u=Array.isArray(l)?l[0]:l;if(("string"!=typeof u||!u)&&Object.prototype.hasOwnProperty.call(i,"value")&&(u="value"),"string"!=typeof u||!u)return r;var s=function(t){return t.includes("{c}")?t.replace(/\{c\}/g,"{@"+u+"}"):t},p=!0,f=!1,d=void 0;try{for(var h,m,y,b,g=c[Symbol.iterator]();!(p=(b=g.next()).done);p=!0){var v=b.value;(null==v?void 0:v.label)&&"string"==typeof v.label.formatter&&(v.label.formatter=s(v.label.formatter)),(null==v?void 0:v.tooltip)&&"string"==typeof v.tooltip.formatter&&(v.tooltip.formatter=s(v.tooltip.formatter))}}catch(t){f=!0,d=t}finally{try{p||null==g.return||g.return()}finally{if(f)throw d}}return r.tooltip&&"string"==typeof r.tooltip.formatter&&(r.tooltip.formatter=s(r.tooltip.formatter)),r}function k(t){return!!t&&(void 0===t?"undefined":w(t))==="object"&&"object"===w(t.options)}function O(t){return t?v(g({},t),{markdown:t.markdown,charts:function(t){if(Array.isArray(t))return t.filter(k).map(function(t){return v(g({},t),{options:S(t.options)})});if("string"!=typeof t)return[];var r=t.trim();if(!r)return[];try{var e=JSON.parse(r);return Array.isArray(e)?e.filter(k).map(function(t){return v(g({},t),{options:S(t.options)})}):[]}catch(t){try{var n=(0,d.m)(r),o=JSON.parse(n);return Array.isArray(o)?o.filter(k).map(function(t){return v(g({},t),{options:S(t.options)})}):[]}catch(t){return[]}}}(t.charts)}):{}}function j(t){var r=O(t);return(r.fileName||r.title||"business-analysis-report").replace(/[\\/:*?"<>|]+/g,"-").trim()}function A(t,r){var e,n,o,i=O(t),c=["# ".concat(i.title)],l=function(t,r){var e=function(t){if(null==t||""===t)return null;if(null!=(r=Date)&&"u">typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](t):t instanceof r)return Number.isNaN(t.getTime())?null:t;if("number"==typeof t)return C(t);var r,e=t.trim();if(!e)return null;if(/^\d+$/.test(e))return C(Number(e));var n=new Date(e);return Number.isNaN(n.getTime())?null:n}(t);if(!e)return null;var n=I(r)||"en-US";try{return new Intl.DateTimeFormat(n,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).format(e)}catch(t){return console.error("Failed to format business report generatedAt:",t),e.toLocaleString()}}(i.generatedAt,null==r?void 0:r.locale);return l&&c.push("_".concat(a.i18n.t("Generated at",{ns:[h.MF,"client"],nsMode:"fallback"}),": ").concat(l,"_")),i.summary&&c.push("> ".concat(i.summary)),(null==(o=i.markdown)?void 0:o.trim())&&c.push((e=i.markdown.trim(),n=i.charts||[],e&&n.length?e.replace(/\{\{\s*chart\s*:\s*(\d+)\s*\}\}/gi,function(t,r){var e,o,a,i=Number(r)-1,c=n[i];return c?(e=c,o=i,a=["## ".concat(e.title||"Chart ".concat(o+1))],e.summary&&a.push(e.summary),a.push("<echarts>".concat(JSON.stringify(e.options,null,2),"</echarts>")),a.join("\n\n")):t}):e)),(function(t,r){if(!r.length)return[];for(var e,n=new Set,o=/\{\{\s*chart\s*:\s*(\d+)\s*\}\}/gi,a=t||"";e=o.exec(a);){var i=Number(e[1])-1;i>=0&&i<r.length&&n.add(i)}return r.filter(function(t,r){return!n.has(r)})})(i.markdown,i.charts||[]).forEach(function(t,r){c.push("## ".concat(t.title||"Chart ".concat(r+1))),t.summary&&c.push(t.summary),c.push("<echarts>".concat(JSON.stringify(t.options,null,2),"</echarts>"))}),c.filter(Boolean).join("\n\n")}function N(t,r){return b(function(){var e,n,a,d,h,y,S,k,O,j,N,P;return x(this,function(F){var C,L,E,R,T,D,H,J,_,z;switch(F.label){case 0:return C=A(t,{locale:null==r?void 0:r.locale}),L=[],E=0,n=(e={body:(0,f.renderToStaticMarkup)(o().createElement(c.oz,{components:{echarts:function(t){var r=t.children,e=Array.isArray(r)?r.join(""):String(null!=r?r:""),n="report-chart-".concat(E++),a=function(t){try{var r=JSON.parse(t);if(r&&(void 0===r?"undefined":w(r))==="object")return r}catch(t){console.error("Failed to parse business report chart options:",t)}return null}(e);return a&&L.push({id:n,options:a}),o().createElement("div",{id:n,className:"report-chart"})}},rehypePlugins:[u.A,[s.A,v(g({},p.j),{tagNames:((function(t){if(Array.isArray(t))return m(t)})(R=p.j.tagNames)||function(t){if("u">typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(R)||function(t){if(t){if("string"==typeof t)return m(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);if("Object"===r&&t.constructor&&(r=t.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(t,void 0)}}(R)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()).concat(["echarts"])})]],remarkPlugins:[l.A]},C)),charts:L}).body,a=e.charts,d=(null==r?void 0:r.printMode)===!0,y=(D=h=(T=I(null==r?void 0:r.locale))||"en-US").startsWith("zh")?'"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", "WenQuanYi Micro Hei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif':D.startsWith("ja")?'"Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", "Noto Sans CJK JP", "Source Han Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif':D.startsWith("ko")?'"Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Source Han Sans KR", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif':'"Inter", "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", -apple-system, BlinkMacSystemFont, sans-serif',S=d?"#ffffff":"#f5f7fb",k=d?"max-width: 190mm; margin: 0 auto; padding: 0;":"max-width: 960px; margin: 0 auto; padding: 32px 24px 64px;",O=d?"background: #fff; border: 0; border-radius: 0; padding: 0; box-shadow: none; width: 100%;":"background: #fff; border: 1px solid #d0d5dd; border-radius: 20px; padding: 40px 48px; box-shadow: 0 18px 50px rgba(15, 23, 42, 0.08);",[4,(H=a,J={chartHeight:j=d?320:360,fontFamily:y,printMode:d},b(function(){var t,r,e,n,o,a,c,l,u,s,p,f;return x(this,function(d){var h,m,y;switch(d.label){case 0:if("u"<typeof document||!H.length)return[2,new Map];t=new Map,(r=document.createElement("div")).style.position="fixed",r.style.left="-100000px",r.style.top="0",r.style.width="".concat(J.printMode?718:960,"px"),r.style.pointerEvents="none",r.style.opacity="0",r.style.zIndex="-1",document.body.appendChild(r),d.label=1;case 1:d.trys.push([1,,15,16]),e=!0,n=!1,o=void 0,d.label=2;case 2:d.trys.push([2,12,13,14]),a=H[Symbol.iterator](),d.label=3;case 3:if(e=(c=a.next()).done)return[3,11];l=c.value,(u=document.createElement("div")).style.width=r.style.width,u.style.height="".concat(J.chartHeight,"px"),r.appendChild(u),d.label=4;case 4:return d.trys.push([4,8,9,10]),(p=i.init(u,"default",{renderer:"canvas"})).setOption(v(g({},(m=v(g({},h=l.options),{animation:!1,toolbox:{show:!1}}),h.grid&&(m.grid=Array.isArray(h.grid)?h.grid.map(function(t){return g({containLabel:!0},t)}):g({containLabel:!0},h.grid)),m)),{textStyle:v(g({},(null==(s=l.options)?void 0:s.textStyle)||{}),{fontFamily:J.fontFamily})}),!0),p.resize({width:u.clientWidth||parseInt(r.style.width,10),height:J.chartHeight,silent:!0}),[4,U()];case 5:return d.sent(),[4,U()];case 6:return d.sent(),[4,(y=p,new Promise(function(t){var r=!1,e=function(){r||(r=!0,y.off("finished",e),t())};y.on("finished",e),window.setTimeout(e,400)}))];case 7:return d.sent(),t.set(l.id,p.getDataURL({type:"png",pixelRatio:3,backgroundColor:"#ffffff",excludeComponents:["toolbox"]})),p.dispose(),[3,10];case 8:return console.error("Failed to render business report chart image:",d.sent()),[3,10];case 9:return u.remove(),[7];case 10:return e=!0,[3,3];case 11:return[3,14];case 12:return f=d.sent(),n=!0,o=f,[3,14];case 13:try{e||null==a.return||a.return()}finally{if(n)throw o}return[7];case 14:return[3,16];case 15:return r.remove(),[7];case 16:return[2,t]}})})())];case 1:return N=F.sent(),_=n,z=N,P=_.replace(/<div id="([^"]+)" class="report-chart"><\/div>/g,function(t,r){var e=z.get(r);return e?'<img class="report-chart-image" src="'.concat(e,'" alt="" />'):t}),[2,'<!DOCTYPE html>\n<html lang="'.concat(M(h),'">\n <head>\n <meta charset="UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title>').concat(M(t.title),"</title>\n <style>\n * { box-sizing: border-box; }\n html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }\n html, body { font-family: ").concat(y,"; }\n body { margin: 0; color: #1f2937; background: ").concat(S,"; }\n .report-shell { ").concat(k," }\n .report-paper { ").concat(O," }\n h1, h2, h3 { color: #101828; }\n h1 { margin-top: 0; font-size: 32px; }\n h2, h3 { break-after: avoid-page; }\n p, li { line-height: 1.7; }\n blockquote { margin: 16px 0; padding: 12px 16px; border-left: 4px solid #0f766e; background: #f0fdfa; color: #667085; }\n pre, blockquote, table, .report-chart { break-inside: avoid; page-break-inside: avoid; }\n table { width: 100%; border-collapse: collapse; }\n th, td { border: 1px solid #d0d5dd; padding: 10px 12px; text-align: left; }\n .report-chart { width: 100%; min-height: ").concat(j,"px; height: ").concat(j,"px; margin: 24px 0 32px; border: 1px solid #d0d5dd; border-radius: ").concat(16*!d,"px; overflow: hidden; background: #fff; }\n .report-chart-image { display: block; width: 100%; height: auto; border: 1px solid #d0d5dd; background: #fff; margin: 24px 0 32px; break-inside: avoid; page-break-inside: avoid; }\n .report-paper > *:first-child { margin-top: 0; }\n .report-paper > *:last-child { margin-bottom: 0; }\n img, svg, canvas { max-width: 100%; }\n svg, svg text, svg tspan, canvas { font-family: ").concat(y,'; }\n @page { size: A4; margin: 12mm; }\n @media print {\n body { background: #fff; }\n .report-shell { max-width: 100%; padding: 0; margin: 0; }\n .report-paper { border: 0; border-radius: 0; box-shadow: none; padding: 0; width: 100%; }\n .report-chart { margin: 16px 0 24px; height: 320px; min-height: 320px; }\n .report-chart-image { margin: 16px 0 24px; }\n }\n </style>\n </head>\n <body>\n <div class="report-shell">\n <article class="report-paper">').concat(P,"</article>\n </div>\n ").concat((null==r?void 0:r.autoPrint)?"<script>\n window.addEventListener('load', async () => {\n if (document.fonts?.ready) {\n try {\n await document.fonts.ready;\n } catch (error) {\n console.error('Failed to wait for fonts before printing:', error);\n }\n }\n requestAnimationFrame(() => {\n requestAnimationFrame(() => {\n window.print();\n });\n });\n });\n <\/script>":"","\n </body>\n</html>")]}})})()}function P(t,r,e){var n=new Blob([r],{type:e}),o=URL.createObjectURL(n),a=document.createElement("a");a.href=o,a.download=t,a.click(),URL.revokeObjectURL(o)}function F(t,r){return b(function(){var e,n;return x(this,function(o){switch(o.label){case 0:if("u"<typeof window)return[2,!1];return[4,N(t,{autoPrint:!0,printMode:!0,locale:null==r?void 0:r.locale})];case 1:if(e=new Blob([o.sent()],{type:"text/html;charset=utf-8"}),n=URL.createObjectURL(e),!window.open(n,"_blank","noopener,noreferrer"))return URL.revokeObjectURL(n),[2,!1];return window.setTimeout(function(){URL.revokeObjectURL(n)},6e4),[2,!0]}})})()}function U(){return new Promise(function(t){return requestAnimationFrame(function(){return t()})})}function M(t){return t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function C(t){if(!Number.isFinite(t))return null;var r=new Date(t<1e12?1e3*t:t);return Number.isNaN(r.getTime())?null:r}function I(t){if(!t)return null;var r=t.trim().replace(/_/g,"-");if(!r||!/^[a-z]{2,3}(-[a-z0-9]{2,8})*$/i.test(r))return null;try{return Intl.DateTimeFormat.supportedLocalesOf([r])[0]||r}catch(t){return r}}}}]);
@@ -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.webpackChunk_nocobase_plugin_ai=self.webpackChunk_nocobase_plugin_ai||[]).push([["486"],{9461:function(e,t,r){r.r(t),r.d(t,{WorkflowTaskOutputCard:function(){return g}});var n=r(9155),o=r.n(n),u=r(3342),a=r(2059),l=r(3079),i=r(7821),s=r(7596),c=r(283),f=r(4181);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 d(e,t,r,n,o,u,a){try{var l=e[u](a),i=l.value}catch(e){r(e);return}l.done?t(i):Promise.resolve(i).then(n,o)}function y(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var u=e.apply(t,r);function a(e){d(u,n,o,a,l,"next",e)}function l(e){d(u,n,o,a,l,"throw",e)}a(void 0)})}}function b(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}function v(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):(function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t})(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}),e}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 u=[],a=!0,l=!1;try{for(o=o.call(e);!(a=(r=o.next()).done)&&(u.push(r.value),!t||u.length!==t);a=!0);}catch(e){l=!0,n=e}finally{try{a||null==o.return||o.return()}finally{if(l)throw n}}return u}}(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 w(e,t){var r,n,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),l=Object.defineProperty;return l(a,"next",{value:i(0)}),l(a,"throw",{value:i(1)}),l(a,"return",{value:i(2)}),"function"==typeof Symbol&&l(a,Symbol.iterator,{value:function(){return this}}),a;function i(l){return function(i){var s=[l,i];if(r)throw TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(u=0)),u;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,n=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){u=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){u.label=s[1];break}if(6===s[0]&&u.label<o[1]){u.label=o[1],o=s;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(s);break}o[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(e,u)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}}var k=(0,u.lazy)(function(){return Promise.all([r.e("687"),r.e("792")]).then(r.bind(r,931))},"Markdown").Markdown,m=function(e){if(!e)return null;if("string"==typeof e)try{return JSON.parse(e)}catch(e){return console.error("Failed to parse workflow task output schema",e),null}return e},g=function(e){var t,r,p=e.toolCall,d=e.decisions,g=(0,l.kj)(),S=(0,u.useCompile)(),O=(0,u.useAPIClient)(),T=s.J.use.currentConversation(),j=f.u.use.currentWorkflowTask(),C=(0,c.h)().getWorkflowTaskBySession,E=h((0,n.useState)(null),2),P=E[0],A=E[1],I=i.I.use.readonly(),x="interrupted"!==p.invokeStatus||!!P||I,W=i.I.use.senderRef(),J=i.I.use.setShowSenderHint(),R=j&&j.sessionId===T?j:void 0,M=(0,u.useRequest)(function(){return y(function(){return w(this,function(e){switch(e.label){case 0:if(R||!T)return[2,null];e.label=1;case 1:return e.trys.push([1,3,,4]),[4,C(T)];case 2:return[2,e.sent()];case 3:return e.sent(),[2,null];case 4:return[2]}})})()},{refreshDeps:[null==R?void 0:R.sessionId,T]}),_=M.data,B=M.loading,D=null!=(t=null!=R?R:_)?t:void 0,U=m(null==D?void 0:D.structuredOutputSchema),$=null==(r=p.args)?void 0:r.result,F=(0,n.useMemo)(function(){return(null==U?void 0:U.properties)&&$&&(void 0===$?"undefined":$&&"u">typeof Symbol&&$.constructor===Symbol?"symbol":typeof $)=="object"?Object.entries(U.properties).map(function(e){var t,r=h(e,2),n=r[0],u=r[1];return{key:n,label:S(null==u?void 0:u.title)||n,children:null==(t=$[n])||""===t?"-":"string"==typeof t||"number"==typeof t||"boolean"==typeof t?o().createElement("div",{style:{width:"100%",overflowX:"auto"}},o().createElement(k,{message:{content:String(t)}})):o().createElement("div",{style:{width:"100%",overflowX:"auto"}},o().createElement(a.Typography.Text,{style:{whiteSpace:"pre-wrap"}},JSON.stringify(t,null,2)))}}):[]},[$,U,S]),N={size:"small",variant:"link",disabled:x||null!=P};return o().createElement(a.Card,{loading:!R&&B,style:{margin:"12px 0"},title:o().createElement(a.Space,{split:"-",wrap:!0},o().createElement(a.Typography.Text,null,(null==D?void 0:D.workflowTitle)||g("Task executing")),(null==D?void 0:D.nodeTitle)?o().createElement(a.Typography.Text,null,D.nodeTitle):null),actions:[o().createElement(a.Button,v(b({},N),{key:"reject",color:"danger",loading:"reject"===P,onClick:function(){return y(function(){return w(this,function(e){switch(e.label){case 0:A("reject"),e.label=1;case 1:if(e.trys.push([1,,5,6]),!(null==D?void 0:D.id))return[3,3];return[4,O.resource("aiWorkflowTasks").reject({values:{id:D.id,result:g("The user rejected the execution of this workflow node.",{ns:l.MF})}})];case 2:e.sent(),e.label=3;case 3:return[4,d.reject("The user rejected this workflow node. Stop. Do not continue, do not reply about the task result, and do not call this tool again. Only state that you understand.")];case 4:return e.sent(),[3,6];case 5:return A(null),[7];case 6:return[2]}})})()}}),g("Reject",{ns:l.MF})),o().createElement(a.Button,v(b({},N),{key:"revise",color:"default",loading:"revise"===P,onClick:function(){return y(function(){var e;return w(this,function(t){A("reject");try{J(!0),null==W||null==(e=W.current)||e.focus()}finally{A(null)}return[2]})})()}}),g("Revise",{ns:l.MF})),o().createElement(a.Button,v(b({},N),{key:"approve",color:"primary",loading:"approve"===P,onClick:function(){return y(function(){return w(this,function(e){switch(e.label){case 0:A("approve"),e.label=1;case 1:return e.trys.push([1,,3,4]),[4,d.approve()];case 2:return e.sent(),[3,4];case 3:return A(null),[7];case 4:return[2]}})})()}}),g("Approve",{ns:l.MF}))]},D?o().createElement(a.Descriptions,{layout:"vertical",column:1,items:F}):o().createElement(a.Skeleton,{active:!0}))}},283:function(e,t,r){r.d(t,{h:function(){return h}});var n,o=r(9155),u=r(3342),a=r(4181),l=r(3559),i=r(7821),s=r(1990);function c(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,u,a){try{var l=e[u](a),i=l.value}catch(e){r(e);return}l.done?t(i):Promise.resolve(i).then(n,o)}function p(e){return function(){var t=this,r=arguments;return new Promise(function(n,o){var u=e.apply(t,r);function a(e){f(u,n,o,a,l,"next",e)}function l(e){f(u,n,o,a,l,"throw",e)}a(void 0)})}}function d(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function y(e){return function(e){if(Array.isArray(e))return c(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e){if(e){if("string"==typeof e)return c(e,void 0);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 c(e,void 0)}}(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function b(e,t){var r,n,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype),l=Object.defineProperty;return l(a,"next",{value:i(0)}),l(a,"throw",{value:i(1)}),l(a,"return",{value:i(2)}),"function"==typeof Symbol&&l(a,Symbol.iterator,{value:function(){return this}}),a;function i(l){return function(i){var s=[l,i];if(r)throw TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(u=0)),u;)try{if(r=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,n=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===s[0]||2===s[0])){u=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){u.label=s[1];break}if(6===s[0]&&u.label<o[1]){u.label=o[1],o=s;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(s);break}o[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(e,u)}catch(e){s=[6,e],n=0}finally{r=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}}var v=(d(n={},s.JOB_STATUS.PENDING,["processing","pending_acceptance","pending_approval"]),d(n,s.JOB_STATUS.RESOLVED,["approved"]),d(n,s.JOB_STATUS.REJECTED,["rejected"]),d(n,s.JOB_STATUS.ABORTED,["aborted"]),n),h=function(){var e,t,r,n,s=(0,u.useAPIClient)().resource("aiWorkflowTasks"),c=a.u.use.workflowTasks(),f=a.u.use.currentWorkflowTask(),d=a.u.use.unreadCount(),h=a.u.use.loading(),w=a.u.use.keyword(),k=a.u.use.selectedJobStatus(),m=a.u.use.setWorkflowTasks(),g=a.u.use.setCurrentWorkflowTask(),S=a.u.use.setUnreadCount(),O=a.u.use.setLoading(),T=a.u.use.setKeyword(),j=a.u.use.setSelectedJobStatus(),C=(0,u.useRequest)(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",r=arguments.length>2?arguments[2]:void 0;return p(function(){var n,o,u;return b(this,function(a){switch(a.label){case 0:n={},t&&(n.$or=[{workflowTitle:{$includes:t}},{nodeTitle:{$includes:t}},{status:{$includes:t}}]),(null==(o="number"==typeof r?v[r]:void 0)?void 0:o.length)&&(n.status={$in:o}),a.label=1;case 1:return a.trys.push([1,3,4,5]),O(!0),[4,s.list({sort:["-updatedAt"],page:e,pageSize:15,filter:n})];case 2:return[2,null==(u=a.sent())?void 0:u.data];case 3:throw a.sent();case 4:return O(!1),[7];case 5:return[2]}})})()},{manual:!0,onSuccess:function(e,t){var r=t[0]||1,n=(null==e?void 0:e.data)||[];1===r?m(n):m(function(e){var t=new Set(e.map(function(e){return e.sessionId})),r=n.filter(function(e){return!t.has(e.sessionId)});return y(e).concat(y(r))})}}),E=(0,u.useRequest)(function(){return p(function(){var e,t,r;return b(this,function(n){switch(n.label){case 0:return[4,s.unreadCount()];case 1:return S((null==(r=n.sent())||null==(t=r.data)||null==(e=t.data)?void 0:e.count)||0),[2]}})})()},{manual:!0}),P=(0,o.useCallback)(function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";T(e),C.run(1,e,k)},[k,T,C]),A=(0,o.useCallback)(function(){C.run(1,w||"",k),E.run()},[w,k,E,C]),I=(0,o.useCallback)(function(e){j(e),C.run(1,w||"",e)},[w,j,C]),x=(0,o.useRef)(C);x.current=C;var W=(0,o.useCallback)(function(){return p(function(){var e,t,r;return b(this,function(n){switch(n.label){case 0:if(r=null==(e=(t=x.current).data)?void 0:e.meta,t.loading||r&&r.page>=r.totalPage)return[2];return[4,t.runAsync((null==r?void 0:r.page)?r.page+1:1,w||"",k)];case 1:return n.sent(),[2]}})})()},[w,k]),J=(0,l.d)({loadMore:W}).ref,R=null!=(t=C.data)&&null!=(e=t.meta)&&!!e.page&&null!=(n=C.data)&&null!=(r=n.meta)&&!!r.totalPage&&C.data.meta.page<C.data.meta.totalPage,M=(0,o.useCallback)(function(e){return p(function(){return b(this,function(t){switch(t.label){case 0:return[4,s.accept({values:{sessionId:e}}).catch(function(){})];case 1:return t.sent(),[2]}})})()},[s]),_=(0,o.useCallback)(function(e){return p(function(){var t,r,n,o;return b(this,function(u){switch(u.label){case 0:return[4,s.getBySession({values:{sessionId:e}})];case 1:return g(o=null!=(t=null==(n=u.sent())||null==(r=n.data)?void 0:r.data)?t:null==n?void 0:n.data),[2,o]}})})()},[g,s]),B=i.I.use.setReadonly(),D=(0,o.useCallback)(function(e){return p(function(){var t;return b(this,function(r){switch(r.label){case 0:return[4,M(e)];case 1:return r.sent(),[4,_(e)];case 2:return B((null==(t=r.sent())?void 0:t.readonly)===!0),[2]}})})()},[M,_,B]);return{loading:h,workflowTasks:c,unreadCount:d,selectedJobStatus:k,runSearch:P,runJobStatusFilter:I,refresh:A,hasMore:R,loadMoreWorkflowTasks:W,lastWorkflowTaskRef:J,acceptWorkflowTask:M,getWorkflowTaskBySession:_,updateReadonly:D,currentWorkflowTask:f,setCurrentWorkflowTask:g,setSelectedJobStatus:j}}}}]);