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.
- package/dist/client/components/SpaceSelect.d.ts +2 -0
- package/dist/client/index.js +9 -1
- package/dist/client/locale.d.ts +3 -0
- package/dist/client/models/UserGuideBlockModel.d.ts +3 -3
- package/dist/client/schemaSettings.d.ts +2 -0
- package/dist/client/schemas/spacesSchema.d.ts +118 -0
- package/dist/externalVersion.js +8 -8
- package/dist/locale/en-US.json +12 -1
- package/dist/locale/namespace.d.ts +6 -0
- package/dist/locale/namespace.js +36 -0
- package/dist/locale/vi-VN.json +3 -0
- package/dist/locale/zh-CN.json +3 -0
- package/dist/node_modules/marked/bin/main.js +279 -0
- package/dist/node_modules/marked/bin/marked.js +15 -0
- package/dist/node_modules/marked/lib/marked.cjs +1 -0
- package/dist/node_modules/marked/lib/marked.d.cts +657 -0
- package/dist/node_modules/marked/lib/marked.d.ts +657 -0
- package/dist/node_modules/marked/lib/marked.esm.js +2432 -0
- package/dist/node_modules/marked/lib/marked.umd.js +2456 -0
- package/dist/node_modules/marked/man/marked.1 +111 -0
- package/dist/node_modules/marked/marked.min.js +6 -0
- package/dist/node_modules/marked/package.json +1 -0
- package/dist/server/actions/build.js +383 -101
- package/dist/server/actions/getMarkdown.d.ts +2 -0
- package/dist/server/actions/getMarkdown.js +53 -0
- package/dist/server/collections/ai-build-guide-pages.d.ts +2 -0
- package/dist/server/collections/ai-build-guide-pages.js +90 -0
- package/dist/server/collections/ai-build-guide-spaces.js +42 -0
- package/dist/server/plugin.d.ts +3 -0
- package/dist/server/plugin.js +58 -13
- package/package.json +51 -31
- package/src/client/UserGuideBlock.tsx +368 -53
- package/src/client/UserGuideBlockProvider.tsx +9 -8
- package/src/client/components/SpaceSelect.tsx +37 -0
- package/src/client/locale.ts +18 -0
- package/src/client/models/UserGuideBlockModel.ts +19 -29
- package/src/client/plugin.tsx +53 -30
- package/src/client/schemaSettings.ts +65 -0
- package/src/client/schemas/spacesSchema.ts +434 -316
- package/src/locale/en-US.json +12 -1
- package/src/locale/namespace.ts +6 -0
- package/src/locale/vi-VN.json +3 -0
- package/src/locale/zh-CN.json +3 -0
- package/src/server/actions/build.ts +497 -176
- package/src/server/actions/getMarkdown.ts +26 -0
- package/src/server/collections/ai-build-guide-pages.ts +60 -0
- package/src/server/collections/ai-build-guide-spaces.ts +57 -15
- package/src/server/plugin.ts +130 -76
- 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: '
|
|
33
|
-
name: '
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
+
});
|
package/src/server/plugin.ts
CHANGED
|
@@ -1,76 +1,130 @@
|
|
|
1
|
-
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
2
|
-
import
|
|
3
|
-
import { build } from './actions/build';
|
|
4
|
-
import { getHtml } from './actions/getHtml';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|