plugin-build-guide-block 1.0.12 → 1.1.3

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 (35) hide show
  1. package/README.md +16 -74
  2. package/dist/client/components/SpaceSelect.d.ts +2 -0
  3. package/dist/client/index.js +9 -10
  4. package/dist/client/schemas/spacesSchema.d.ts +81 -0
  5. package/dist/externalVersion.js +7 -16
  6. package/dist/index.js +0 -9
  7. package/dist/locale/en-US.json +12 -4
  8. package/dist/locale/namespace.js +0 -9
  9. package/dist/locale/vi-VN.json +12 -4
  10. package/dist/locale/zh-CN.json +12 -4
  11. package/dist/server/actions/build.js +346 -80
  12. package/dist/server/actions/getHtml.js +0 -9
  13. package/dist/server/actions/getMarkdown.js +0 -9
  14. package/dist/server/collections/ai-build-guide-pages.d.ts +2 -0
  15. package/dist/server/collections/ai-build-guide-pages.js +81 -0
  16. package/dist/server/collections/ai-build-guide-spaces.js +33 -9
  17. package/dist/server/index.js +0 -9
  18. package/dist/server/plugin.d.ts +3 -0
  19. package/dist/server/plugin.js +50 -21
  20. package/package.json +1 -1
  21. package/src/client/UserGuideBlock.tsx +368 -53
  22. package/src/client/UserGuideBlockProvider.tsx +9 -8
  23. package/src/client/UserGuideManager.tsx +52 -23
  24. package/src/client/components/SpaceSelect.tsx +37 -0
  25. package/src/client/models/UserGuideBlockModel.ts +19 -29
  26. package/src/client/plugin.tsx +3 -2
  27. package/src/client/schemaSettings.ts +2 -12
  28. package/src/client/schemas/spacesSchema.ts +439 -357
  29. package/src/locale/en-US.json +12 -4
  30. package/src/locale/vi-VN.json +12 -4
  31. package/src/locale/zh-CN.json +12 -4
  32. package/src/server/actions/build.ts +501 -189
  33. package/src/server/collections/ai-build-guide-pages.ts +60 -0
  34. package/src/server/collections/ai-build-guide-spaces.ts +57 -24
  35. package/src/server/plugin.ts +58 -11
@@ -0,0 +1,60 @@
1
+ import { defineCollection } from '@nocobase/database';
2
+
3
+ export default defineCollection({
4
+ name: 'aiBuildGuidePages',
5
+ shared: true,
6
+ dumpRules: 'required',
7
+ migrationRules: ['overwrite', 'schema-only'],
8
+ timestamps: true,
9
+ fields: [
10
+ {
11
+ type: 'uid',
12
+ name: 'id',
13
+ primaryKey: true,
14
+ },
15
+ {
16
+ type: 'belongsTo',
17
+ name: 'space',
18
+ target: 'aiBuildGuideSpaces',
19
+ foreignKey: 'spaceId',
20
+ },
21
+ {
22
+ type: 'integer',
23
+ name: 'sort',
24
+ defaultValue: 0,
25
+ },
26
+ {
27
+ type: 'string',
28
+ name: 'title',
29
+ },
30
+ {
31
+ type: 'string',
32
+ name: 'slug',
33
+ },
34
+ {
35
+ type: 'text',
36
+ name: 'goal',
37
+ },
38
+ {
39
+ type: 'json',
40
+ name: 'planItem',
41
+ },
42
+ {
43
+ type: 'string',
44
+ name: 'status',
45
+ defaultValue: 'pending',
46
+ },
47
+ {
48
+ type: 'text',
49
+ name: 'generatedHtml',
50
+ },
51
+ {
52
+ type: 'text',
53
+ name: 'generatedMarkdown',
54
+ },
55
+ {
56
+ type: 'text',
57
+ name: 'buildLog',
58
+ },
59
+ ],
60
+ });
@@ -28,32 +28,65 @@ 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: 'text',
38
- name: 'generatedHtml',
39
- },
40
- {
41
- type: 'text',
42
- name: 'generatedMarkdown',
43
- },
44
- {
45
- type: 'string',
46
- name: 'status',
47
- defaultValue: 'draft',
48
- },
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
+ },
49
76
  {
50
77
  type: 'text',
51
78
  name: 'buildLog',
52
79
  },
53
80
  {
54
- type: 'belongsToMany',
55
- name: 'documents',
56
- target: 'attachments',
57
- },
58
- ],
59
- });
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
+ });
@@ -5,6 +5,8 @@ import { getHtml } from './actions/getHtml';
5
5
  import { getMarkdown } from './actions/getMarkdown';
6
6
 
7
7
  export class PluginBuildGuideBlockServer extends Plugin {
8
+ private readonly schemaCollections = ['aiBuildGuideSpaces', 'aiBuildGuidePages'];
9
+
8
10
  afterAdd() {}
9
11
 
10
12
  beforeLoad() {}
@@ -31,6 +33,8 @@ export class PluginBuildGuideBlockServer extends Plugin {
31
33
  'aiBuildGuideSpaces:list',
32
34
  'aiBuildGuideSpaces:get',
33
35
  'aiBuildGuideSpaces:build',
36
+ 'aiBuildGuidePages:list',
37
+ 'aiBuildGuidePages:get',
34
38
  ],
35
39
  });
36
40
 
@@ -39,6 +43,15 @@ export class PluginBuildGuideBlockServer extends Plugin {
39
43
  try {
40
44
  const repo = this.db.getRepository('aiBuildGuideSpaces');
41
45
  await repo.update({
46
+ filter: { status: 'building' },
47
+ values: {
48
+ status: 'error',
49
+ buildPhase: 'error',
50
+ buildLog: 'Build interrupted by server restart',
51
+ },
52
+ });
53
+ const pageRepo = this.db.getRepository('aiBuildGuidePages');
54
+ await pageRepo.update({
42
55
  filter: { status: 'building' },
43
56
  values: {
44
57
  status: 'error',
@@ -51,28 +64,62 @@ export class PluginBuildGuideBlockServer extends Plugin {
51
64
  });
52
65
  }
53
66
 
54
- async install(options?: InstallOptions) {
55
- const collection = this.db.getCollection('aiBuildGuideSpaces');
56
- if (collection) {
67
+ private async ensureCollectionSchema(collectionName: string) {
68
+ const collection = this.db.getCollection(collectionName);
69
+ if (!collection) {
70
+ this.app.logger.warn(`[plugin-build-guide-block] Collection "${collectionName}" is not registered`);
71
+ return;
72
+ }
73
+
74
+ const queryInterface = this.db.sequelize.getQueryInterface();
75
+ const tableName = collection.getTableNameWithSchema();
76
+ let columns: Record<string, any> | null = null;
77
+
78
+ try {
79
+ columns = await queryInterface.describeTable(tableName);
80
+ } catch (error) {
57
81
  await collection.model.sync();
82
+ columns = await queryInterface.describeTable(tableName);
58
83
  }
59
- const repo = this.db.getRepository<any>('collections');
60
- if (repo) {
61
- await repo.db2cm('aiBuildGuideSpaces');
84
+
85
+ const attributes = collection.model.rawAttributes as Record<string, any>;
86
+ for (const [attributeName, attribute] of Object.entries(attributes)) {
87
+ const columnName = attribute.field || attributeName;
88
+ if (columns[columnName]) {
89
+ continue;
90
+ }
91
+
92
+ const columnDefinition = { ...attribute };
93
+ delete columnDefinition.Model;
94
+ delete columnDefinition.fieldName;
95
+
96
+ await queryInterface.addColumn(tableName, columnName, columnDefinition);
97
+ columns[columnName] = columnDefinition;
98
+ this.app.logger.info(`[plugin-build-guide-block] Added missing column "${columnName}" to "${collectionName}"`);
62
99
  }
63
100
  }
64
101
 
65
- async upgrade() {
66
- const collection = this.db.getCollection('aiBuildGuideSpaces');
67
- if (collection) {
68
- await collection.model.sync();
102
+ private async ensureSchema() {
103
+ for (const collectionName of this.schemaCollections) {
104
+ await this.ensureCollectionSchema(collectionName);
69
105
  }
106
+
70
107
  const repo = this.db.getRepository<any>('collections');
71
108
  if (repo) {
72
- await repo.db2cm('aiBuildGuideSpaces');
109
+ for (const collectionName of this.schemaCollections) {
110
+ await repo.db2cm(collectionName);
111
+ }
73
112
  }
74
113
  }
75
114
 
115
+ async install(options?: InstallOptions) {
116
+ await this.ensureSchema();
117
+ }
118
+
119
+ async upgrade() {
120
+ await this.ensureSchema();
121
+ }
122
+
76
123
  async afterEnable() {}
77
124
 
78
125
  async afterDisable() {}