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.
Files changed (123) hide show
  1. package/client-v2.d.ts +2 -0
  2. package/client-v2.js +1 -0
  3. package/dist/client/index.js +2 -2
  4. package/dist/client-v2/73.6b8b2eda7d969c69.js +10 -0
  5. package/dist/client-v2/index.js +10 -0
  6. package/dist/externalVersion.js +9 -8
  7. package/dist/node_modules/sanitize-html/index.js +2 -2
  8. package/dist/node_modules/sanitize-html/package.json +1 -1
  9. package/dist/server/actions/build.js +687 -85
  10. package/dist/server/collections/ai-build-guide-spaces.js +20 -0
  11. package/dist/server/plugin.js +21 -19
  12. package/dist/server/tools/search-guides.js +41 -30
  13. package/package.json +7 -3
  14. package/src/client/components/BuildButton.tsx +20 -9
  15. package/src/client-v2/plugin.tsx +24 -0
  16. package/src/server/actions/build.ts +774 -88
  17. package/src/server/collections/ai-build-guide-spaces.ts +77 -57
  18. package/src/server/plugin.ts +170 -163
  19. package/src/server/tools/search-guides.ts +113 -95
  20. package/dist/client/UserGuideBlock.d.ts +0 -2
  21. package/dist/client/UserGuideBlockInitializer.d.ts +0 -2
  22. package/dist/client/UserGuideBlockProvider.d.ts +0 -2
  23. package/dist/client/UserGuideManager.d.ts +0 -2
  24. package/dist/client/components/BuildButton.d.ts +0 -2
  25. package/dist/client/components/LLMServiceSelect.d.ts +0 -2
  26. package/dist/client/components/ModelSelect.d.ts +0 -2
  27. package/dist/client/components/SpaceSelect.d.ts +0 -2
  28. package/dist/client/components/StatusTag.d.ts +0 -2
  29. package/dist/client/locale.d.ts +0 -3
  30. package/dist/client/models/UserGuideBlockModel.d.ts +0 -9
  31. package/dist/client/models/index.d.ts +0 -9
  32. package/dist/client/plugin.d.ts +0 -5
  33. package/dist/client/schemaSettings.d.ts +0 -2
  34. package/dist/client/schemas/spacesSchema.d.ts +0 -437
  35. package/dist/index.d.ts +0 -2
  36. package/dist/locale/namespace.d.ts +0 -6
  37. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.cjs +0 -34
  38. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.js +0 -34
  39. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.cjs +0 -35
  40. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.d.ts +0 -56
  41. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.js +0 -35
  42. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.native.js +0 -26
  43. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/package.json +0 -12
  44. package/dist/node_modules/sanitize-html/node_modules/nanoid/bin/nanoid.cjs +0 -55
  45. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.cjs +0 -34
  46. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.js +0 -34
  47. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.cjs +0 -45
  48. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.cts +0 -91
  49. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.ts +0 -91
  50. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.js +0 -45
  51. package/dist/node_modules/sanitize-html/node_modules/nanoid/nanoid.js +0 -1
  52. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.cjs +0 -21
  53. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.d.ts +0 -33
  54. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.js +0 -21
  55. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/package.json +0 -6
  56. package/dist/node_modules/sanitize-html/node_modules/nanoid/package.json +0 -88
  57. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.cjs +0 -3
  58. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.js +0 -3
  59. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/package.json +0 -6
  60. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.d.ts +0 -115
  61. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.js +0 -25
  62. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.d.ts +0 -67
  63. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.js +0 -13
  64. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.d.ts +0 -452
  65. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.js +0 -439
  66. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.d.ts +0 -248
  67. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.js +0 -100
  68. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.d.ts +0 -148
  69. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.js +0 -24
  70. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.d.ts +0 -68
  71. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.js +0 -33
  72. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.d.ts +0 -9
  73. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.js +0 -54
  74. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.d.ts +0 -194
  75. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.js +0 -248
  76. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.d.ts +0 -190
  77. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.js +0 -550
  78. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.d.ts +0 -57
  79. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.js +0 -58
  80. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/map-generator.js +0 -359
  81. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.d.ts +0 -46
  82. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.js +0 -135
  83. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.d.ts +0 -536
  84. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.js +0 -381
  85. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.d.ts +0 -9
  86. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.js +0 -42
  87. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parser.js +0 -610
  88. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.mts +0 -72
  89. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.ts +0 -441
  90. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.js +0 -101
  91. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.d.ts +0 -81
  92. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.js +0 -142
  93. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.d.ts +0 -115
  94. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.js +0 -67
  95. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.d.ts +0 -206
  96. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.js +0 -42
  97. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.d.ts +0 -86
  98. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.js +0 -61
  99. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.d.ts +0 -113
  100. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.js +0 -27
  101. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.d.ts +0 -46
  102. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.js +0 -353
  103. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.d.ts +0 -9
  104. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.js +0 -11
  105. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/symbols.js +0 -5
  106. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/terminal-highlight.js +0 -70
  107. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/tokenize.js +0 -266
  108. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warn-once.js +0 -13
  109. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.d.ts +0 -147
  110. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.js +0 -37
  111. package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid +0 -15
  112. package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid.cmd +0 -7
  113. package/dist/node_modules/sanitize-html/node_modules/postcss/package.json +0 -88
  114. package/dist/server/actions/build.d.ts +0 -2
  115. package/dist/server/actions/getHtml.d.ts +0 -2
  116. package/dist/server/actions/getMarkdown.d.ts +0 -2
  117. package/dist/server/collections/ai-build-guide-pages.d.ts +0 -2
  118. package/dist/server/collections/ai-build-guide-spaces.d.ts +0 -2
  119. package/dist/server/index.d.ts +0 -2
  120. package/dist/server/plugin.d.ts +0 -16
  121. package/dist/server/tools/index.d.ts +0 -1
  122. package/dist/server/tools/search-guides.d.ts +0 -28
  123. /package/{dist/client/index.d.ts → src/client-v2/index.tsx} +0 -0
@@ -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;