plugin-build-guide-block 1.1.5 → 1.1.7
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/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/dist/client/index.js +2 -2
- package/dist/client-v2/73.6b8b2eda7d969c69.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +9 -8
- package/dist/node_modules/sanitize-html/index.js +2 -2
- package/dist/node_modules/sanitize-html/package.json +1 -1
- package/dist/server/actions/build.js +687 -85
- package/dist/server/collections/ai-build-guide-spaces.js +20 -0
- package/dist/server/plugin.js +21 -19
- package/dist/server/tools/search-guides.js +41 -30
- package/package.json +7 -3
- package/src/client/components/BuildButton.tsx +20 -9
- package/src/client-v2/plugin.tsx +24 -0
- package/src/server/actions/build.ts +774 -88
- package/src/server/collections/ai-build-guide-spaces.ts +77 -57
- package/src/server/plugin.ts +170 -163
- package/src/server/tools/search-guides.ts +113 -95
- package/dist/client/UserGuideBlock.d.ts +0 -2
- package/dist/client/UserGuideBlockInitializer.d.ts +0 -2
- package/dist/client/UserGuideBlockProvider.d.ts +0 -2
- package/dist/client/UserGuideManager.d.ts +0 -2
- package/dist/client/components/BuildButton.d.ts +0 -2
- package/dist/client/components/LLMServiceSelect.d.ts +0 -2
- package/dist/client/components/ModelSelect.d.ts +0 -2
- package/dist/client/components/SpaceSelect.d.ts +0 -2
- package/dist/client/components/StatusTag.d.ts +0 -2
- package/dist/client/locale.d.ts +0 -3
- package/dist/client/models/UserGuideBlockModel.d.ts +0 -9
- package/dist/client/models/index.d.ts +0 -9
- package/dist/client/plugin.d.ts +0 -5
- package/dist/client/schemaSettings.d.ts +0 -2
- package/dist/client/schemas/spacesSchema.d.ts +0 -437
- package/dist/index.d.ts +0 -2
- package/dist/locale/namespace.d.ts +0 -6
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.cjs +0 -34
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.js +0 -34
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.cjs +0 -35
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.d.ts +0 -56
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.js +0 -35
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.native.js +0 -26
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/package.json +0 -12
- package/dist/node_modules/sanitize-html/node_modules/nanoid/bin/nanoid.cjs +0 -55
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.cjs +0 -34
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.js +0 -34
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.cjs +0 -45
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.cts +0 -91
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.ts +0 -91
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.js +0 -45
- package/dist/node_modules/sanitize-html/node_modules/nanoid/nanoid.js +0 -1
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.cjs +0 -21
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.d.ts +0 -33
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.js +0 -21
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/package.json +0 -6
- package/dist/node_modules/sanitize-html/node_modules/nanoid/package.json +0 -88
- package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.cjs +0 -3
- package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.js +0 -3
- package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/package.json +0 -6
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.d.ts +0 -115
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.js +0 -25
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.d.ts +0 -67
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.js +0 -13
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.d.ts +0 -452
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.js +0 -439
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.d.ts +0 -248
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.js +0 -100
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.d.ts +0 -148
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.js +0 -24
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.d.ts +0 -68
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.js +0 -33
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.d.ts +0 -9
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.js +0 -54
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.d.ts +0 -194
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.js +0 -248
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.d.ts +0 -190
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.js +0 -550
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.d.ts +0 -57
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.js +0 -58
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/map-generator.js +0 -359
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.d.ts +0 -46
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.js +0 -135
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.d.ts +0 -536
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.js +0 -381
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.d.ts +0 -9
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.js +0 -42
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parser.js +0 -610
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.mts +0 -72
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.ts +0 -441
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.js +0 -101
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.d.ts +0 -81
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.js +0 -142
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.d.ts +0 -115
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.js +0 -67
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.d.ts +0 -206
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.js +0 -42
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.d.ts +0 -86
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.js +0 -61
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.d.ts +0 -113
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.js +0 -27
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.d.ts +0 -46
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.js +0 -353
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.d.ts +0 -9
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.js +0 -11
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/symbols.js +0 -5
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/terminal-highlight.js +0 -70
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/tokenize.js +0 -266
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warn-once.js +0 -13
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.d.ts +0 -147
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.js +0 -37
- package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid +0 -15
- package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid.cmd +0 -7
- package/dist/node_modules/sanitize-html/node_modules/postcss/package.json +0 -88
- package/dist/server/actions/build.d.ts +0 -2
- package/dist/server/actions/getHtml.d.ts +0 -2
- package/dist/server/actions/getMarkdown.d.ts +0 -2
- package/dist/server/collections/ai-build-guide-pages.d.ts +0 -2
- package/dist/server/collections/ai-build-guide-spaces.d.ts +0 -2
- package/dist/server/index.d.ts +0 -2
- package/dist/server/plugin.d.ts +0 -16
- package/dist/server/tools/index.d.ts +0 -1
- package/dist/server/tools/search-guides.d.ts +0 -28
- /package/{dist/client/index.d.ts → src/client-v2/index.tsx} +0 -0
|
@@ -89,6 +89,26 @@ var ai_build_guide_spaces_default = (0, import_database.defineCollection)({
|
|
|
89
89
|
name: "buildPhase",
|
|
90
90
|
defaultValue: "idle"
|
|
91
91
|
},
|
|
92
|
+
{
|
|
93
|
+
type: "string",
|
|
94
|
+
name: "buildRunId"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
type: "date",
|
|
98
|
+
name: "buildQueuedAt"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
type: "date",
|
|
102
|
+
name: "buildStartedAt"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
type: "date",
|
|
106
|
+
name: "buildHeartbeatAt"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
type: "string",
|
|
110
|
+
name: "buildWorkerId"
|
|
111
|
+
},
|
|
92
112
|
{
|
|
93
113
|
type: "integer",
|
|
94
114
|
name: "pageCount",
|
package/dist/server/plugin.js
CHANGED
|
@@ -46,6 +46,7 @@ class PluginBuildGuideBlockServer extends import_server.Plugin {
|
|
|
46
46
|
await this.db.import({
|
|
47
47
|
directory: (0, import_path.resolve)(__dirname, "collections")
|
|
48
48
|
});
|
|
49
|
+
await this.ensureSchema();
|
|
49
50
|
this.app.resourceManager.registerActionHandlers({
|
|
50
51
|
"aiBuildGuideSpaces:build": import_build.build,
|
|
51
52
|
"aiBuildGuideSpaces:getHtml": import_getHtml.getHtml,
|
|
@@ -66,36 +67,29 @@ class PluginBuildGuideBlockServer extends import_server.Plugin {
|
|
|
66
67
|
"aiBuildGuidePages:get"
|
|
67
68
|
]
|
|
68
69
|
});
|
|
70
|
+
(0, import_build.registerBuildGuideQueue)(this.app);
|
|
69
71
|
this.app.on("afterStart", async () => {
|
|
70
72
|
try {
|
|
71
|
-
|
|
72
|
-
await repo.update({
|
|
73
|
-
filter: { status: "building" },
|
|
74
|
-
values: {
|
|
75
|
-
status: "error",
|
|
76
|
-
buildPhase: "error",
|
|
77
|
-
buildLog: "Build interrupted by server restart"
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
const pageRepo = this.db.getRepository("aiBuildGuidePages");
|
|
81
|
-
await pageRepo.update({
|
|
82
|
-
filter: { status: "building" },
|
|
83
|
-
values: {
|
|
84
|
-
status: "error",
|
|
85
|
-
buildLog: "Build interrupted by server restart"
|
|
86
|
-
}
|
|
87
|
-
});
|
|
73
|
+
await (0, import_build.recoverInterruptedBuilds)(this.app);
|
|
88
74
|
} catch (err) {
|
|
89
|
-
this.app.logger.warn("[plugin-build-guide-block] Failed to recover
|
|
75
|
+
this.app.logger.warn("[plugin-build-guide-block] Failed to recover interrupted builds", err);
|
|
90
76
|
}
|
|
91
77
|
});
|
|
78
|
+
this.app.on("beforeStop", () => {
|
|
79
|
+
(0, import_build.unregisterBuildGuideQueue)(this.app);
|
|
80
|
+
});
|
|
81
|
+
this.app.on("beforeDestroy", () => {
|
|
82
|
+
(0, import_build.unregisterBuildGuideQueue)(this.app);
|
|
83
|
+
});
|
|
92
84
|
this.registerAITools();
|
|
93
85
|
}
|
|
94
86
|
registerAITools() {
|
|
95
87
|
var _a;
|
|
96
88
|
const toolsManager = (_a = this.app.aiManager) == null ? void 0 : _a.toolsManager;
|
|
97
89
|
if (!toolsManager) {
|
|
98
|
-
this.app.logger.warn(
|
|
90
|
+
this.app.logger.warn(
|
|
91
|
+
"[plugin-build-guide-block] aiManager.toolsManager is not available; skipping tool registration"
|
|
92
|
+
);
|
|
99
93
|
return;
|
|
100
94
|
}
|
|
101
95
|
const tools = [import_tools.searchBuildGuidesTool];
|
|
@@ -168,9 +162,17 @@ class PluginBuildGuideBlockServer extends import_server.Plugin {
|
|
|
168
162
|
}
|
|
169
163
|
async afterEnable() {
|
|
170
164
|
}
|
|
165
|
+
async beforeDisable() {
|
|
166
|
+
(0, import_build.unregisterBuildGuideQueue)(this.app);
|
|
167
|
+
}
|
|
171
168
|
async afterDisable() {
|
|
169
|
+
(0, import_build.unregisterBuildGuideQueue)(this.app);
|
|
170
|
+
}
|
|
171
|
+
async beforeUnload() {
|
|
172
|
+
(0, import_build.unregisterBuildGuideQueue)(this.app);
|
|
172
173
|
}
|
|
173
174
|
async remove() {
|
|
175
|
+
(0, import_build.unregisterBuildGuideQueue)(this.app);
|
|
174
176
|
}
|
|
175
177
|
}
|
|
176
178
|
var plugin_default = PluginBuildGuideBlockServer;
|
|
@@ -30,6 +30,10 @@ __export(search_guides_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(search_guides_exports);
|
|
32
32
|
var import_zod = require("zod");
|
|
33
|
+
function getValue(record, key) {
|
|
34
|
+
var _a;
|
|
35
|
+
return ((_a = record == null ? void 0 : record.get) == null ? void 0 : _a.call(record, key)) ?? (record == null ? void 0 : record[key]);
|
|
36
|
+
}
|
|
33
37
|
var search_guides_default = {
|
|
34
38
|
groupName: "plugin-build-guide",
|
|
35
39
|
tool: {
|
|
@@ -38,57 +42,61 @@ var search_guides_default = {
|
|
|
38
42
|
description: "Search for available user guides, documentation, or read a specific guide page. Use this to help users find information in the build guide block.",
|
|
39
43
|
execution: "backend",
|
|
40
44
|
schema: import_zod.z.object({
|
|
41
|
-
action: import_zod.z.enum(["list_spaces", "search_pages", "read_page"]).describe(
|
|
45
|
+
action: import_zod.z.enum(["list_spaces", "search_pages", "read_page"]).describe(
|
|
46
|
+
"The action to perform: list_spaces (find available guide books), search_pages (search for pages across all or specific spaces), read_page (read the full content of a specific page)"
|
|
47
|
+
),
|
|
42
48
|
query: import_zod.z.string().optional().describe("Search keyword for finding spaces or pages. Required for search_pages."),
|
|
43
49
|
pageId: import_zod.z.string().optional().describe("The ID of the page to read. Required for read_page.")
|
|
44
50
|
}),
|
|
45
51
|
invoke: async (args, ctx) => {
|
|
46
|
-
var _a;
|
|
47
52
|
const { action, query, pageId } = args;
|
|
48
53
|
const { db } = ctx.app;
|
|
49
54
|
const spaceRepo = db.getRepository("aiBuildGuideSpaces");
|
|
50
55
|
const pageRepo = db.getRepository("aiBuildGuidePages");
|
|
51
56
|
try {
|
|
52
57
|
if (action === "list_spaces") {
|
|
58
|
+
const filter = { status: "completed" };
|
|
59
|
+
if (query) {
|
|
60
|
+
filter.title = { $iLike: `%${query}%` };
|
|
61
|
+
}
|
|
53
62
|
const spaces = await spaceRepo.find({
|
|
54
|
-
filter
|
|
63
|
+
filter,
|
|
55
64
|
fields: ["id", "title", "chapterGuidance", "pageCount"],
|
|
56
65
|
limit: 20
|
|
57
66
|
});
|
|
58
67
|
return {
|
|
59
68
|
status: "success",
|
|
60
69
|
content: spaces.map((s) => ({
|
|
61
|
-
id: s
|
|
62
|
-
title: s
|
|
63
|
-
description: s
|
|
64
|
-
pageCount: s
|
|
70
|
+
id: getValue(s, "id"),
|
|
71
|
+
title: getValue(s, "title"),
|
|
72
|
+
description: getValue(s, "chapterGuidance"),
|
|
73
|
+
pageCount: getValue(s, "pageCount")
|
|
65
74
|
}))
|
|
66
75
|
};
|
|
67
76
|
}
|
|
68
77
|
if (action === "search_pages") {
|
|
78
|
+
const filter = { status: "completed" };
|
|
79
|
+
if (query) {
|
|
80
|
+
filter.$or = [
|
|
81
|
+
{ title: { $iLike: `%${query}%` } },
|
|
82
|
+
{ goal: { $iLike: `%${query}%` } },
|
|
83
|
+
{ generatedMarkdown: { $iLike: `%${query}%` } }
|
|
84
|
+
];
|
|
85
|
+
}
|
|
69
86
|
const pages = await pageRepo.find({
|
|
70
|
-
filter
|
|
71
|
-
$or: [
|
|
72
|
-
{ title: { $iLike: `%${query}%` } },
|
|
73
|
-
{ goal: { $iLike: `%${query}%` } },
|
|
74
|
-
{ generatedMarkdown: { $iLike: `%${query}%` } }
|
|
75
|
-
]
|
|
76
|
-
} : {},
|
|
87
|
+
filter,
|
|
77
88
|
fields: ["id", "title", "slug", "goal", "spaceId"],
|
|
78
89
|
limit: 10,
|
|
79
|
-
appends: ["space(id,title)"]
|
|
90
|
+
appends: ["space(id,title,status)"]
|
|
80
91
|
});
|
|
81
92
|
return {
|
|
82
93
|
status: "success",
|
|
83
|
-
content: pages.map((p) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
spaceName: (_a2 = p.space) == null ? void 0 : _a2.title
|
|
90
|
-
};
|
|
91
|
-
})
|
|
94
|
+
content: pages.filter((p) => getValue(getValue(p, "space"), "status") === "completed").map((p) => ({
|
|
95
|
+
id: getValue(p, "id"),
|
|
96
|
+
title: getValue(p, "title"),
|
|
97
|
+
goal: getValue(p, "goal"),
|
|
98
|
+
spaceName: getValue(getValue(p, "space"), "title")
|
|
99
|
+
}))
|
|
92
100
|
};
|
|
93
101
|
}
|
|
94
102
|
if (action === "read_page") {
|
|
@@ -96,19 +104,22 @@ var search_guides_default = {
|
|
|
96
104
|
return { status: "error", content: "pageId is required for read_page action" };
|
|
97
105
|
}
|
|
98
106
|
const page = await pageRepo.findById(pageId, {
|
|
99
|
-
appends: ["space(id,title)"]
|
|
107
|
+
appends: ["space(id,title,status)"]
|
|
100
108
|
});
|
|
101
109
|
if (!page) {
|
|
102
110
|
return { status: "error", content: `Page with ID ${pageId} not found.` };
|
|
103
111
|
}
|
|
112
|
+
if (getValue(page, "status") !== "completed" || getValue(getValue(page, "space"), "status") !== "completed") {
|
|
113
|
+
return { status: "error", content: `Page with ID ${pageId} is not completed.` };
|
|
114
|
+
}
|
|
104
115
|
return {
|
|
105
116
|
status: "success",
|
|
106
117
|
content: {
|
|
107
|
-
id: page
|
|
108
|
-
title: page
|
|
109
|
-
spaceName: (
|
|
110
|
-
goal: page
|
|
111
|
-
markdown: page
|
|
118
|
+
id: getValue(page, "id"),
|
|
119
|
+
title: getValue(page, "title"),
|
|
120
|
+
spaceName: getValue(getValue(page, "space"), "title"),
|
|
121
|
+
goal: getValue(page, "goal"),
|
|
122
|
+
markdown: getValue(page, "generatedMarkdown")
|
|
112
123
|
}
|
|
113
124
|
};
|
|
114
125
|
}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"displayName.zh-CN": "构建指南区块",
|
|
6
6
|
"description": "Generate user guides, tutorials and help books from documents using AI, then render the result as a block (HTML or Markdown).",
|
|
7
7
|
"description.vi-VN": "Tạo hướng dẫn người dùng, tutorial và help book từ tài liệu bằng AI, hiển thị kết quả dưới dạng block (HTML hoặc Markdown).",
|
|
8
|
-
"version": "1.1.
|
|
8
|
+
"version": "1.1.7",
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"ai",
|
|
@@ -21,7 +21,9 @@
|
|
|
21
21
|
"client.js",
|
|
22
22
|
"server.js",
|
|
23
23
|
"client.d.ts",
|
|
24
|
-
"server.d.ts"
|
|
24
|
+
"server.d.ts",
|
|
25
|
+
"client-v2.js",
|
|
26
|
+
"client-v2.d.ts"
|
|
25
27
|
],
|
|
26
28
|
"dependencies": {
|
|
27
29
|
"dompurify": "^3.1.2",
|
|
@@ -40,7 +42,9 @@
|
|
|
40
42
|
"@nocobase/plugin-ai": "2.x",
|
|
41
43
|
"@nocobase/plugin-file-manager": "2.x",
|
|
42
44
|
"@langchain/core": "*",
|
|
43
|
-
"axios": "*"
|
|
45
|
+
"axios": "*",
|
|
46
|
+
"@nocobase/client-v2": "2.x",
|
|
47
|
+
"@nocobase/flow-engine": "2.x"
|
|
44
48
|
},
|
|
45
49
|
"nocobase": {
|
|
46
50
|
"supportedVersions": [
|
|
@@ -5,7 +5,8 @@ import { PlayCircleOutlined } from '@ant-design/icons';
|
|
|
5
5
|
import { useTranslation } from 'react-i18next';
|
|
6
6
|
|
|
7
7
|
const POLL_INTERVAL_MS = 3000;
|
|
8
|
-
const
|
|
8
|
+
const STILL_RUNNING_AFTER_MS = 5 * 60 * 1000;
|
|
9
|
+
const SLOW_POLL_INTERVAL_MS = 10000;
|
|
9
10
|
|
|
10
11
|
export const BuildButton = () => {
|
|
11
12
|
const [loading, setLoading] = useState(false);
|
|
@@ -14,11 +15,11 @@ export const BuildButton = () => {
|
|
|
14
15
|
const { t } = useTranslation();
|
|
15
16
|
const record = useCollectionRecordData();
|
|
16
17
|
const { refresh } = useDataBlockRequest();
|
|
17
|
-
const timerRef = useRef<ReturnType<typeof
|
|
18
|
+
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
18
19
|
|
|
19
20
|
const stopPolling = useCallback(() => {
|
|
20
21
|
if (timerRef.current) {
|
|
21
|
-
|
|
22
|
+
clearTimeout(timerRef.current);
|
|
22
23
|
timerRef.current = null;
|
|
23
24
|
}
|
|
24
25
|
setLoading(false);
|
|
@@ -36,14 +37,13 @@ export const BuildButton = () => {
|
|
|
36
37
|
});
|
|
37
38
|
message.success(t('Build started'));
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
pollCount++;
|
|
40
|
+
const startedAt = Date.now();
|
|
41
|
+
let stillRunningNotified = false;
|
|
42
|
+
const poll = async () => {
|
|
43
43
|
try {
|
|
44
44
|
const res = await api.resource('aiBuildGuideSpaces').get({ filterByTk: record.id });
|
|
45
45
|
const status = res?.data?.data?.status;
|
|
46
|
-
if (status !== 'building'
|
|
46
|
+
if (status !== 'building') {
|
|
47
47
|
stopPolling();
|
|
48
48
|
refresh?.();
|
|
49
49
|
if (status === 'completed') {
|
|
@@ -51,12 +51,23 @@ export const BuildButton = () => {
|
|
|
51
51
|
} else if (status === 'error') {
|
|
52
52
|
message.error(t('Build failed'));
|
|
53
53
|
}
|
|
54
|
+
return;
|
|
54
55
|
}
|
|
56
|
+
|
|
57
|
+
const elapsed = Date.now() - startedAt;
|
|
58
|
+
if (elapsed >= STILL_RUNNING_AFTER_MS && !stillRunningNotified) {
|
|
59
|
+
stillRunningNotified = true;
|
|
60
|
+
message.info(t('Build is still running'));
|
|
61
|
+
}
|
|
62
|
+
const nextPollDelay = elapsed >= STILL_RUNNING_AFTER_MS ? SLOW_POLL_INTERVAL_MS : POLL_INTERVAL_MS;
|
|
63
|
+
timerRef.current = setTimeout(poll, nextPollDelay);
|
|
55
64
|
} catch {
|
|
56
65
|
stopPolling();
|
|
57
66
|
refresh?.();
|
|
58
67
|
}
|
|
59
|
-
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
timerRef.current = setTimeout(poll, POLL_INTERVAL_MS);
|
|
60
71
|
} catch (err: any) {
|
|
61
72
|
console.error(err);
|
|
62
73
|
message.error(err?.response?.data?.error?.message || t('Build failed'));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Plugin, Application } from '@nocobase/client-v2';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
|
|
4
|
+
export class PluginBuildGuideBlockClient extends Plugin<Record<string, never>, Application> {
|
|
5
|
+
async load() {
|
|
6
|
+
this.pluginSettingsManager.addMenuItem({
|
|
7
|
+
key: 'ai-build-guide',
|
|
8
|
+
title: this.t('Build Guide Block'),
|
|
9
|
+
icon: 'ReadOutlined',
|
|
10
|
+
aclSnippet: 'pm.ai-build-guide',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
this.pluginSettingsManager.addPageTabItem({
|
|
14
|
+
menuKey: 'ai-build-guide',
|
|
15
|
+
key: 'index',
|
|
16
|
+
title: this.t('Build Guide Block'),
|
|
17
|
+
|
|
18
|
+
componentLoader: () => import('../client/UserGuideManager').then(m => ({ default: m.UserGuideManager })),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default PluginBuildGuideBlockClient;
|