plugin-build-guide-block 1.1.5 → 1.1.6

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 (41) hide show
  1. package/dist/client/index.js +2 -2
  2. package/dist/externalVersion.js +7 -7
  3. package/dist/node_modules/sanitize-html/index.js +1 -1
  4. package/dist/node_modules/sanitize-html/package.json +1 -1
  5. package/dist/server/actions/build.js +682 -83
  6. package/dist/server/collections/ai-build-guide-spaces.js +20 -0
  7. package/dist/server/plugin.js +21 -19
  8. package/dist/server/tools/search-guides.js +41 -30
  9. package/package.json +2 -2
  10. package/src/client/components/BuildButton.tsx +20 -9
  11. package/src/server/actions/build.ts +768 -86
  12. package/src/server/collections/ai-build-guide-spaces.ts +77 -57
  13. package/src/server/plugin.ts +170 -163
  14. package/src/server/tools/search-guides.ts +113 -95
  15. package/dist/client/UserGuideBlock.d.ts +0 -2
  16. package/dist/client/UserGuideBlockInitializer.d.ts +0 -2
  17. package/dist/client/UserGuideBlockProvider.d.ts +0 -2
  18. package/dist/client/UserGuideManager.d.ts +0 -2
  19. package/dist/client/components/BuildButton.d.ts +0 -2
  20. package/dist/client/components/LLMServiceSelect.d.ts +0 -2
  21. package/dist/client/components/ModelSelect.d.ts +0 -2
  22. package/dist/client/components/SpaceSelect.d.ts +0 -2
  23. package/dist/client/components/StatusTag.d.ts +0 -2
  24. package/dist/client/index.d.ts +0 -1
  25. package/dist/client/locale.d.ts +0 -3
  26. package/dist/client/models/UserGuideBlockModel.d.ts +0 -9
  27. package/dist/client/models/index.d.ts +0 -9
  28. package/dist/client/plugin.d.ts +0 -5
  29. package/dist/client/schemaSettings.d.ts +0 -2
  30. package/dist/client/schemas/spacesSchema.d.ts +0 -437
  31. package/dist/index.d.ts +0 -2
  32. package/dist/locale/namespace.d.ts +0 -6
  33. package/dist/server/actions/build.d.ts +0 -2
  34. package/dist/server/actions/getHtml.d.ts +0 -2
  35. package/dist/server/actions/getMarkdown.d.ts +0 -2
  36. package/dist/server/collections/ai-build-guide-pages.d.ts +0 -2
  37. package/dist/server/collections/ai-build-guide-spaces.d.ts +0 -2
  38. package/dist/server/index.d.ts +0 -2
  39. package/dist/server/plugin.d.ts +0 -16
  40. package/dist/server/tools/index.d.ts +0 -1
  41. package/dist/server/tools/search-guides.d.ts +0 -28
@@ -28,65 +28,85 @@ export default defineCollection({
28
28
  type: 'text',
29
29
  name: 'systemPrompt',
30
30
  },
31
- {
32
- type: 'string',
33
- name: 'outputFormat',
34
- defaultValue: 'html',
35
- },
36
- {
37
- type: 'integer',
38
- name: 'targetChapterCount',
39
- defaultValue: 5,
40
- },
41
- {
42
- type: 'text',
43
- name: 'chapterGuidance',
44
- },
45
- {
46
- type: 'text',
47
- name: 'generatedHtml',
48
- },
49
- {
50
- type: 'text',
51
- name: 'generatedMarkdown',
52
- },
53
- {
54
- type: 'json',
55
- name: 'planJson',
56
- },
57
- {
58
- type: 'string',
59
- name: 'buildPhase',
60
- defaultValue: 'idle',
61
- },
62
- {
63
- type: 'integer',
64
- name: 'pageCount',
65
- defaultValue: 0,
66
- },
67
- {
68
- type: 'string',
69
- name: 'sourceHash',
70
- },
71
- {
72
- type: 'string',
73
- name: 'status',
74
- defaultValue: 'draft',
75
- },
31
+ {
32
+ type: 'string',
33
+ name: 'outputFormat',
34
+ defaultValue: 'html',
35
+ },
36
+ {
37
+ type: 'integer',
38
+ name: 'targetChapterCount',
39
+ defaultValue: 5,
40
+ },
41
+ {
42
+ type: 'text',
43
+ name: 'chapterGuidance',
44
+ },
45
+ {
46
+ type: 'text',
47
+ name: 'generatedHtml',
48
+ },
49
+ {
50
+ type: 'text',
51
+ name: 'generatedMarkdown',
52
+ },
53
+ {
54
+ type: 'json',
55
+ name: 'planJson',
56
+ },
57
+ {
58
+ type: 'string',
59
+ name: 'buildPhase',
60
+ defaultValue: 'idle',
61
+ },
62
+ {
63
+ type: 'string',
64
+ name: 'buildRunId',
65
+ },
66
+ {
67
+ type: 'date',
68
+ name: 'buildQueuedAt',
69
+ },
70
+ {
71
+ type: 'date',
72
+ name: 'buildStartedAt',
73
+ },
74
+ {
75
+ type: 'date',
76
+ name: 'buildHeartbeatAt',
77
+ },
78
+ {
79
+ type: 'string',
80
+ name: 'buildWorkerId',
81
+ },
82
+ {
83
+ type: 'integer',
84
+ name: 'pageCount',
85
+ defaultValue: 0,
86
+ },
87
+ {
88
+ type: 'string',
89
+ name: 'sourceHash',
90
+ },
91
+ {
92
+ type: 'string',
93
+ name: 'status',
94
+ defaultValue: 'draft',
95
+ },
76
96
  {
77
97
  type: 'text',
78
98
  name: 'buildLog',
79
99
  },
80
100
  {
81
- type: 'belongsToMany',
82
- name: 'documents',
83
- target: 'attachments',
84
- },
85
- {
86
- type: 'hasMany',
87
- name: 'pages',
88
- target: 'aiBuildGuidePages',
89
- foreignKey: 'spaceId',
90
- },
91
- ],
92
- });
101
+ type: 'belongsToMany',
102
+ name: 'documents',
103
+ target: 'attachments',
104
+ },
105
+ {
106
+ type: 'hasMany',
107
+ name: 'pages',
108
+ target: 'aiBuildGuidePages',
109
+ foreignKey: 'spaceId',
110
+ },
111
+ ],
112
+ });
@@ -1,163 +1,170 @@
1
- import { InstallOptions, Plugin } from '@nocobase/server';
2
- import { resolve } from 'path';
3
- import { build } from './actions/build';
4
- import { getHtml } from './actions/getHtml';
5
- import { getMarkdown } from './actions/getMarkdown';
6
- import { searchBuildGuidesTool } from './tools';
7
-
8
- export class PluginBuildGuideBlockServer extends Plugin {
9
- private readonly schemaCollections = ['aiBuildGuideSpaces', 'aiBuildGuidePages'];
10
-
11
- afterAdd() {}
12
-
13
- beforeLoad() {}
14
-
15
- async load() {
16
- await this.db.import({
17
- directory: resolve(__dirname, 'collections'),
18
- });
19
-
20
- this.app.resourceManager.registerActionHandlers({
21
- 'aiBuildGuideSpaces:build': build,
22
- 'aiBuildGuideSpaces:getHtml': getHtml,
23
- 'aiBuildGuideSpaces:getMarkdown': getMarkdown,
24
- });
25
-
26
- this.app.acl.allow('aiBuildGuideSpaces', 'getHtml', 'loggedIn');
27
- this.app.acl.allow('aiBuildGuideSpaces', 'getMarkdown', 'loggedIn');
28
- this.app.acl.registerSnippet({
29
- name: 'pm.ai-build-guide',
30
- actions: [
31
- 'aiBuildGuideSpaces:create',
32
- 'aiBuildGuideSpaces:update',
33
- 'aiBuildGuideSpaces:destroy',
34
- 'aiBuildGuideSpaces:list',
35
- 'aiBuildGuideSpaces:get',
36
- 'aiBuildGuideSpaces:build',
37
- 'aiBuildGuidePages:list',
38
- 'aiBuildGuidePages:get',
39
- ],
40
- });
41
-
42
- // Recover stale "building" status after server restart
43
- this.app.on('afterStart', async () => {
44
- try {
45
- const repo = this.db.getRepository('aiBuildGuideSpaces');
46
- await repo.update({
47
- filter: { status: 'building' },
48
- values: {
49
- status: 'error',
50
- buildPhase: 'error',
51
- buildLog: 'Build interrupted by server restart',
52
- },
53
- });
54
- const pageRepo = this.db.getRepository('aiBuildGuidePages');
55
- await pageRepo.update({
56
- filter: { status: 'building' },
57
- values: {
58
- status: 'error',
59
- buildLog: 'Build interrupted by server restart',
60
- },
61
- });
62
- } catch (err) {
63
- this.app.logger.warn('[plugin-build-guide-block] Failed to recover stale builds', err);
64
- }
65
- });
66
-
67
- this.registerAITools();
68
- }
69
-
70
- private registerAITools() {
71
- const toolsManager = (this.app as any).aiManager?.toolsManager;
72
- if (!toolsManager) {
73
- this.app.logger.warn('[plugin-build-guide-block] aiManager.toolsManager is not available; skipping tool registration');
74
- return;
75
- }
76
-
77
- const tools = [searchBuildGuidesTool];
78
- toolsManager.registerTools(
79
- tools.map((item: any) => {
80
- const name = `${item.groupName}-${item.tool.name}`;
81
- return {
82
- scope: 'CUSTOM',
83
- defaultPermission: item.tool.execution === 'backend' ? 'ALLOW' : 'ASK',
84
- execution: item.tool.execution,
85
- introduction: {
86
- title: item.tool.title,
87
- about: item.tool.description,
88
- },
89
- definition: {
90
- name,
91
- description: item.tool.description,
92
- schema: item.tool.schema,
93
- },
94
- invoke: item.tool.invoke,
95
- };
96
- }),
97
- );
98
- }
99
-
100
- private async ensureCollectionSchema(collectionName: string) {
101
- const collection = this.db.getCollection(collectionName);
102
- if (!collection) {
103
- this.app.logger.warn(`[plugin-build-guide-block] Collection "${collectionName}" is not registered`);
104
- return;
105
- }
106
-
107
- const queryInterface = this.db.sequelize.getQueryInterface();
108
- const tableName = collection.getTableNameWithSchema();
109
- let columns: Record<string, any> | null = null;
110
-
111
- try {
112
- columns = await queryInterface.describeTable(tableName);
113
- } catch (error) {
114
- await collection.model.sync();
115
- columns = await queryInterface.describeTable(tableName);
116
- }
117
-
118
- const attributes = collection.model.rawAttributes as Record<string, any>;
119
- for (const [attributeName, attribute] of Object.entries(attributes)) {
120
- const columnName = attribute.field || attributeName;
121
- if (columns[columnName]) {
122
- continue;
123
- }
124
-
125
- const columnDefinition = { ...attribute };
126
- delete columnDefinition.Model;
127
- delete columnDefinition.fieldName;
128
-
129
- await queryInterface.addColumn(tableName, columnName, columnDefinition);
130
- columns[columnName] = columnDefinition;
131
- this.app.logger.info(`[plugin-build-guide-block] Added missing column "${columnName}" to "${collectionName}"`);
132
- }
133
- }
134
-
135
- private async ensureSchema() {
136
- for (const collectionName of this.schemaCollections) {
137
- await this.ensureCollectionSchema(collectionName);
138
- }
139
-
140
- const repo = this.db.getRepository<any>('collections');
141
- if (repo) {
142
- for (const collectionName of this.schemaCollections) {
143
- await repo.db2cm(collectionName);
144
- }
145
- }
146
- }
147
-
148
- async install(options?: InstallOptions) {
149
- await this.ensureSchema();
150
- }
151
-
152
- async upgrade() {
153
- await this.ensureSchema();
154
- }
155
-
156
- async afterEnable() {}
157
-
158
- async afterDisable() {}
159
-
160
- async remove() {}
161
- }
162
-
163
- export default PluginBuildGuideBlockServer;
1
+ import { InstallOptions, Plugin } from '@nocobase/server';
2
+ import { resolve } from 'path';
3
+ import { build, recoverInterruptedBuilds, registerBuildGuideQueue, unregisterBuildGuideQueue } from './actions/build';
4
+ import { getHtml } from './actions/getHtml';
5
+ import { getMarkdown } from './actions/getMarkdown';
6
+ import { searchBuildGuidesTool } from './tools';
7
+
8
+ export class PluginBuildGuideBlockServer extends Plugin {
9
+ private readonly schemaCollections = ['aiBuildGuideSpaces', 'aiBuildGuidePages'];
10
+
11
+ afterAdd() {}
12
+
13
+ beforeLoad() {}
14
+
15
+ async load() {
16
+ await this.db.import({
17
+ directory: resolve(__dirname, 'collections'),
18
+ });
19
+ await this.ensureSchema();
20
+
21
+ this.app.resourceManager.registerActionHandlers({
22
+ 'aiBuildGuideSpaces:build': build,
23
+ 'aiBuildGuideSpaces:getHtml': getHtml,
24
+ 'aiBuildGuideSpaces:getMarkdown': getMarkdown,
25
+ });
26
+
27
+ this.app.acl.allow('aiBuildGuideSpaces', 'getHtml', 'loggedIn');
28
+ this.app.acl.allow('aiBuildGuideSpaces', 'getMarkdown', 'loggedIn');
29
+ this.app.acl.registerSnippet({
30
+ name: 'pm.ai-build-guide',
31
+ actions: [
32
+ 'aiBuildGuideSpaces:create',
33
+ 'aiBuildGuideSpaces:update',
34
+ 'aiBuildGuideSpaces:destroy',
35
+ 'aiBuildGuideSpaces:list',
36
+ 'aiBuildGuideSpaces:get',
37
+ 'aiBuildGuideSpaces:build',
38
+ 'aiBuildGuidePages:list',
39
+ 'aiBuildGuidePages:get',
40
+ ],
41
+ });
42
+
43
+ registerBuildGuideQueue(this.app);
44
+
45
+ // Resume builds that were interrupted before their worker finished.
46
+ this.app.on('afterStart', async () => {
47
+ try {
48
+ await recoverInterruptedBuilds(this.app);
49
+ } catch (err) {
50
+ this.app.logger.warn('[plugin-build-guide-block] Failed to recover interrupted builds', err);
51
+ }
52
+ });
53
+ this.app.on('beforeStop', () => {
54
+ unregisterBuildGuideQueue(this.app);
55
+ });
56
+ this.app.on('beforeDestroy', () => {
57
+ unregisterBuildGuideQueue(this.app);
58
+ });
59
+
60
+ this.registerAITools();
61
+ }
62
+
63
+ private registerAITools() {
64
+ const toolsManager = (this.app as any).aiManager?.toolsManager;
65
+ if (!toolsManager) {
66
+ this.app.logger.warn(
67
+ '[plugin-build-guide-block] aiManager.toolsManager is not available; skipping tool registration',
68
+ );
69
+ return;
70
+ }
71
+
72
+ const tools = [searchBuildGuidesTool];
73
+ toolsManager.registerTools(
74
+ tools.map((item: any) => {
75
+ const name = `${item.groupName}-${item.tool.name}`;
76
+ return {
77
+ scope: 'CUSTOM',
78
+ defaultPermission: item.tool.execution === 'backend' ? 'ALLOW' : 'ASK',
79
+ execution: item.tool.execution,
80
+ introduction: {
81
+ title: item.tool.title,
82
+ about: item.tool.description,
83
+ },
84
+ definition: {
85
+ name,
86
+ description: item.tool.description,
87
+ schema: item.tool.schema,
88
+ },
89
+ invoke: item.tool.invoke,
90
+ };
91
+ }),
92
+ );
93
+ }
94
+
95
+ private async ensureCollectionSchema(collectionName: string) {
96
+ const collection = this.db.getCollection(collectionName);
97
+ if (!collection) {
98
+ this.app.logger.warn(`[plugin-build-guide-block] Collection "${collectionName}" is not registered`);
99
+ return;
100
+ }
101
+
102
+ const queryInterface = this.db.sequelize.getQueryInterface();
103
+ const tableName = collection.getTableNameWithSchema();
104
+ let columns: Record<string, any> | null = null;
105
+
106
+ try {
107
+ columns = await queryInterface.describeTable(tableName);
108
+ } catch (error) {
109
+ await collection.model.sync();
110
+ columns = await queryInterface.describeTable(tableName);
111
+ }
112
+
113
+ const attributes = collection.model.rawAttributes as Record<string, any>;
114
+ for (const [attributeName, attribute] of Object.entries(attributes)) {
115
+ const columnName = attribute.field || attributeName;
116
+ if (columns[columnName]) {
117
+ continue;
118
+ }
119
+
120
+ const columnDefinition = { ...attribute };
121
+ delete columnDefinition.Model;
122
+ delete columnDefinition.fieldName;
123
+
124
+ await queryInterface.addColumn(tableName, columnName, columnDefinition);
125
+ columns[columnName] = columnDefinition;
126
+ this.app.logger.info(`[plugin-build-guide-block] Added missing column "${columnName}" to "${collectionName}"`);
127
+ }
128
+ }
129
+
130
+ private async ensureSchema() {
131
+ for (const collectionName of this.schemaCollections) {
132
+ await this.ensureCollectionSchema(collectionName);
133
+ }
134
+
135
+ const repo = this.db.getRepository<any>('collections');
136
+ if (repo) {
137
+ for (const collectionName of this.schemaCollections) {
138
+ await repo.db2cm(collectionName);
139
+ }
140
+ }
141
+ }
142
+
143
+ async install(options?: InstallOptions) {
144
+ await this.ensureSchema();
145
+ }
146
+
147
+ async upgrade() {
148
+ await this.ensureSchema();
149
+ }
150
+
151
+ async afterEnable() {}
152
+
153
+ async beforeDisable() {
154
+ unregisterBuildGuideQueue(this.app);
155
+ }
156
+
157
+ async afterDisable() {
158
+ unregisterBuildGuideQueue(this.app);
159
+ }
160
+
161
+ async beforeUnload() {
162
+ unregisterBuildGuideQueue(this.app);
163
+ }
164
+
165
+ async remove() {
166
+ unregisterBuildGuideQueue(this.app);
167
+ }
168
+ }
169
+
170
+ export default PluginBuildGuideBlockServer;