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.
- package/dist/client/index.js +2 -2
- package/dist/externalVersion.js +7 -7
- package/dist/node_modules/sanitize-html/index.js +1 -1
- package/dist/node_modules/sanitize-html/package.json +1 -1
- package/dist/server/actions/build.js +682 -83
- package/dist/server/collections/ai-build-guide-spaces.js +20 -0
- package/dist/server/plugin.js +21 -19
- package/dist/server/tools/search-guides.js +41 -30
- package/package.json +2 -2
- package/src/client/components/BuildButton.tsx +20 -9
- package/src/server/actions/build.ts +768 -86
- package/src/server/collections/ai-build-guide-spaces.ts +77 -57
- package/src/server/plugin.ts +170 -163
- package/src/server/tools/search-guides.ts +113 -95
- package/dist/client/UserGuideBlock.d.ts +0 -2
- package/dist/client/UserGuideBlockInitializer.d.ts +0 -2
- package/dist/client/UserGuideBlockProvider.d.ts +0 -2
- package/dist/client/UserGuideManager.d.ts +0 -2
- package/dist/client/components/BuildButton.d.ts +0 -2
- package/dist/client/components/LLMServiceSelect.d.ts +0 -2
- package/dist/client/components/ModelSelect.d.ts +0 -2
- package/dist/client/components/SpaceSelect.d.ts +0 -2
- package/dist/client/components/StatusTag.d.ts +0 -2
- package/dist/client/index.d.ts +0 -1
- package/dist/client/locale.d.ts +0 -3
- package/dist/client/models/UserGuideBlockModel.d.ts +0 -9
- package/dist/client/models/index.d.ts +0 -9
- package/dist/client/plugin.d.ts +0 -5
- package/dist/client/schemaSettings.d.ts +0 -2
- package/dist/client/schemas/spacesSchema.d.ts +0 -437
- package/dist/index.d.ts +0 -2
- package/dist/locale/namespace.d.ts +0 -6
- package/dist/server/actions/build.d.ts +0 -2
- package/dist/server/actions/getHtml.d.ts +0 -2
- package/dist/server/actions/getMarkdown.d.ts +0 -2
- package/dist/server/collections/ai-build-guide-pages.d.ts +0 -2
- package/dist/server/collections/ai-build-guide-spaces.d.ts +0 -2
- package/dist/server/index.d.ts +0 -2
- package/dist/server/plugin.d.ts +0 -16
- package/dist/server/tools/index.d.ts +0 -1
- 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: '
|
|
64
|
-
name: '
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
});
|
package/src/server/plugin.ts
CHANGED
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
'aiBuildGuideSpaces:
|
|
23
|
-
'aiBuildGuideSpaces:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.app.acl.allow('aiBuildGuideSpaces', '
|
|
28
|
-
this.app.acl.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'aiBuildGuideSpaces:
|
|
33
|
-
'aiBuildGuideSpaces:
|
|
34
|
-
'aiBuildGuideSpaces:
|
|
35
|
-
'aiBuildGuideSpaces:
|
|
36
|
-
'aiBuildGuideSpaces:
|
|
37
|
-
'
|
|
38
|
-
'aiBuildGuidePages:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.app
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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;
|