plugin-build-guide-block 1.0.11 → 1.1.2

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 (49) hide show
  1. package/dist/client/components/SpaceSelect.d.ts +2 -0
  2. package/dist/client/index.js +9 -1
  3. package/dist/client/locale.d.ts +3 -0
  4. package/dist/client/models/UserGuideBlockModel.d.ts +3 -3
  5. package/dist/client/schemaSettings.d.ts +2 -0
  6. package/dist/client/schemas/spacesSchema.d.ts +118 -0
  7. package/dist/externalVersion.js +8 -8
  8. package/dist/locale/en-US.json +12 -1
  9. package/dist/locale/namespace.d.ts +6 -0
  10. package/dist/locale/namespace.js +36 -0
  11. package/dist/locale/vi-VN.json +3 -0
  12. package/dist/locale/zh-CN.json +3 -0
  13. package/dist/node_modules/marked/bin/main.js +279 -0
  14. package/dist/node_modules/marked/bin/marked.js +15 -0
  15. package/dist/node_modules/marked/lib/marked.cjs +1 -0
  16. package/dist/node_modules/marked/lib/marked.d.cts +657 -0
  17. package/dist/node_modules/marked/lib/marked.d.ts +657 -0
  18. package/dist/node_modules/marked/lib/marked.esm.js +2432 -0
  19. package/dist/node_modules/marked/lib/marked.umd.js +2456 -0
  20. package/dist/node_modules/marked/man/marked.1 +111 -0
  21. package/dist/node_modules/marked/marked.min.js +6 -0
  22. package/dist/node_modules/marked/package.json +1 -0
  23. package/dist/server/actions/build.js +383 -101
  24. package/dist/server/actions/getMarkdown.d.ts +2 -0
  25. package/dist/server/actions/getMarkdown.js +53 -0
  26. package/dist/server/collections/ai-build-guide-pages.d.ts +2 -0
  27. package/dist/server/collections/ai-build-guide-pages.js +90 -0
  28. package/dist/server/collections/ai-build-guide-spaces.js +42 -0
  29. package/dist/server/plugin.d.ts +3 -0
  30. package/dist/server/plugin.js +58 -13
  31. package/package.json +51 -31
  32. package/src/client/UserGuideBlock.tsx +368 -53
  33. package/src/client/UserGuideBlockProvider.tsx +9 -8
  34. package/src/client/components/SpaceSelect.tsx +37 -0
  35. package/src/client/locale.ts +18 -0
  36. package/src/client/models/UserGuideBlockModel.ts +19 -29
  37. package/src/client/plugin.tsx +53 -30
  38. package/src/client/schemaSettings.ts +65 -0
  39. package/src/client/schemas/spacesSchema.ts +434 -316
  40. package/src/locale/en-US.json +12 -1
  41. package/src/locale/namespace.ts +6 -0
  42. package/src/locale/vi-VN.json +3 -0
  43. package/src/locale/zh-CN.json +3 -0
  44. package/src/server/actions/build.ts +497 -176
  45. package/src/server/actions/getMarkdown.ts +26 -0
  46. package/src/server/collections/ai-build-guide-pages.ts +60 -0
  47. package/src/server/collections/ai-build-guide-spaces.ts +57 -15
  48. package/src/server/plugin.ts +130 -76
  49. package/src/server/collections/.gitkeep +0 -0
@@ -0,0 +1,26 @@
1
+ import { Context, Next } from '@nocobase/actions';
2
+ import { Repository } from '@nocobase/database';
3
+
4
+ export async function getMarkdown(ctx: Context, next: Next) {
5
+ const { filterByTk } = ctx.action.params;
6
+ const { resourceName } = ctx.action;
7
+ const repository = ctx.db.getRepository<any>(resourceName) as Repository;
8
+ const model = await repository.findById(filterByTk);
9
+
10
+ if (!model) {
11
+ ctx.throw(404, 'User Guide not found');
12
+ }
13
+
14
+ if (model.get('status') !== 'completed') {
15
+ ctx.throw(400, 'User Guide is not ready yet');
16
+ }
17
+
18
+ ctx.body = model.get('generatedMarkdown') || '';
19
+ ctx.withoutDataWrapping = true;
20
+
21
+ ctx.set({
22
+ 'Content-Type': 'text/markdown; charset=UTF-8',
23
+ });
24
+
25
+ await next();
26
+ }
@@ -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,23 +28,65 @@ export default defineCollection({
28
28
  type: 'text',
29
29
  name: 'systemPrompt',
30
30
  },
31
- {
32
- type: 'text',
33
- name: 'generatedHtml',
34
- },
35
- {
36
- type: 'string',
37
- name: 'status',
38
- defaultValue: 'draft',
39
- },
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
+ },
40
76
  {
41
77
  type: 'text',
42
78
  name: 'buildLog',
43
79
  },
44
80
  {
45
- type: 'belongsToMany',
46
- name: 'documents',
47
- target: 'attachments',
48
- },
49
- ],
50
- });
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
+ });
@@ -1,76 +1,130 @@
1
- import { InstallOptions, Plugin } from '@nocobase/server';
2
- import path from 'path';
3
- import { build } from './actions/build';
4
- import { getHtml } from './actions/getHtml';
5
-
6
- export class PluginBuildGuideBlockServer extends Plugin {
7
- afterAdd() {}
8
-
9
- beforeLoad() {}
10
-
11
- async load() {
12
- this.app.resourceManager.registerActionHandlers({
13
- 'aiBuildGuideSpaces:build': build,
14
- 'aiBuildGuideSpaces:getHtml': getHtml,
15
- });
16
-
17
- this.app.acl.allow('aiBuildGuideSpaces', 'getHtml', 'loggedIn');
18
- this.app.acl.registerSnippet({
19
- name: 'pm.ai-build-guide',
20
- actions: [
21
- 'aiBuildGuideSpaces:create',
22
- 'aiBuildGuideSpaces:update',
23
- 'aiBuildGuideSpaces:destroy',
24
- 'aiBuildGuideSpaces:list',
25
- 'aiBuildGuideSpaces:get',
26
- 'aiBuildGuideSpaces:build',
27
- ],
28
- });
29
-
30
- // Recover stale "building" status after server restart
31
- this.app.on('afterStart', async () => {
32
- try {
33
- const repo = this.db.getRepository('aiBuildGuideSpaces');
34
- await repo.update({
35
- filter: { status: 'building' },
36
- values: {
37
- status: 'error',
38
- buildLog: 'Build interrupted by server restart',
39
- },
40
- });
41
- } catch (err) {
42
- this.app.logger.warn('[plugin-build-guide-block] Failed to recover stale builds', err);
43
- }
44
- });
45
- }
46
-
47
- async install(options?: InstallOptions) {
48
- const collection = this.db.getCollection('aiBuildGuideSpaces');
49
- if (collection) {
50
- await collection.model.sync();
51
- }
52
- const repo = this.db.getRepository<any>('collections');
53
- if (repo) {
54
- await repo.db2cm('aiBuildGuideSpaces');
55
- }
56
- }
57
-
58
- async upgrade() {
59
- const collection = this.db.getCollection('aiBuildGuideSpaces');
60
- if (collection) {
61
- await collection.model.sync();
62
- }
63
- const repo = this.db.getRepository<any>('collections');
64
- if (repo) {
65
- await repo.db2cm('aiBuildGuideSpaces');
66
- }
67
- }
68
-
69
- async afterEnable() {}
70
-
71
- async afterDisable() {}
72
-
73
- async remove() {}
74
- }
75
-
76
- export default PluginBuildGuideBlockServer;
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
+
7
+ export class PluginBuildGuideBlockServer extends Plugin {
8
+ private readonly schemaCollections = ['aiBuildGuideSpaces', 'aiBuildGuidePages'];
9
+
10
+ afterAdd() {}
11
+
12
+ beforeLoad() {}
13
+
14
+ async load() {
15
+ await this.db.import({
16
+ directory: resolve(__dirname, 'collections'),
17
+ });
18
+
19
+ this.app.resourceManager.registerActionHandlers({
20
+ 'aiBuildGuideSpaces:build': build,
21
+ 'aiBuildGuideSpaces:getHtml': getHtml,
22
+ 'aiBuildGuideSpaces:getMarkdown': getMarkdown,
23
+ });
24
+
25
+ this.app.acl.allow('aiBuildGuideSpaces', 'getHtml', 'loggedIn');
26
+ this.app.acl.allow('aiBuildGuideSpaces', 'getMarkdown', 'loggedIn');
27
+ this.app.acl.registerSnippet({
28
+ name: 'pm.ai-build-guide',
29
+ actions: [
30
+ 'aiBuildGuideSpaces:create',
31
+ 'aiBuildGuideSpaces:update',
32
+ 'aiBuildGuideSpaces:destroy',
33
+ 'aiBuildGuideSpaces:list',
34
+ 'aiBuildGuideSpaces:get',
35
+ 'aiBuildGuideSpaces:build',
36
+ 'aiBuildGuidePages:list',
37
+ 'aiBuildGuidePages:get',
38
+ ],
39
+ });
40
+
41
+ // Recover stale "building" status after server restart
42
+ this.app.on('afterStart', async () => {
43
+ try {
44
+ const repo = this.db.getRepository('aiBuildGuideSpaces');
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({
55
+ filter: { status: 'building' },
56
+ values: {
57
+ status: 'error',
58
+ buildLog: 'Build interrupted by server restart',
59
+ },
60
+ });
61
+ } catch (err) {
62
+ this.app.logger.warn('[plugin-build-guide-block] Failed to recover stale builds', err);
63
+ }
64
+ });
65
+ }
66
+
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) {
81
+ await collection.model.sync();
82
+ columns = await queryInterface.describeTable(tableName);
83
+ }
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}"`);
99
+ }
100
+ }
101
+
102
+ private async ensureSchema() {
103
+ for (const collectionName of this.schemaCollections) {
104
+ await this.ensureCollectionSchema(collectionName);
105
+ }
106
+
107
+ const repo = this.db.getRepository<any>('collections');
108
+ if (repo) {
109
+ for (const collectionName of this.schemaCollections) {
110
+ await repo.db2cm(collectionName);
111
+ }
112
+ }
113
+ }
114
+
115
+ async install(options?: InstallOptions) {
116
+ await this.ensureSchema();
117
+ }
118
+
119
+ async upgrade() {
120
+ await this.ensureSchema();
121
+ }
122
+
123
+ async afterEnable() {}
124
+
125
+ async afterDisable() {}
126
+
127
+ async remove() {}
128
+ }
129
+
130
+ export default PluginBuildGuideBlockServer;
File without changes