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
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SchemaComponentOptions } from '@nocobase/client';
|
|
3
|
-
import { UserGuideBlock } from './UserGuideBlock';
|
|
4
|
-
import { UserGuideBlockInitializer } from './UserGuideBlockInitializer';
|
|
2
|
+
import { SchemaComponentOptions } from '@nocobase/client';
|
|
3
|
+
import { UserGuideBlock } from './UserGuideBlock';
|
|
4
|
+
import { UserGuideBlockInitializer } from './UserGuideBlockInitializer';
|
|
5
|
+
import { SpaceSelect } from './components/SpaceSelect';
|
|
5
6
|
|
|
6
7
|
export const UserGuideBlockProvider = (props: any) => {
|
|
7
8
|
return (
|
|
8
|
-
<SchemaComponentOptions components={{ UserGuideBlock, UserGuideBlockInitializer }}>
|
|
9
|
-
{props.children}
|
|
10
|
-
</SchemaComponentOptions>
|
|
11
|
-
);
|
|
12
|
-
};
|
|
9
|
+
<SchemaComponentOptions components={{ UserGuideBlock, UserGuideBlockInitializer, SpaceSelect }}>
|
|
10
|
+
{props.children}
|
|
11
|
+
</SchemaComponentOptions>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Select } from 'antd';
|
|
3
|
+
import { useRequest } from '@nocobase/client';
|
|
4
|
+
|
|
5
|
+
function normalizeRecords(response: any) {
|
|
6
|
+
const records = response?.data?.data || response?.data || response || [];
|
|
7
|
+
return Array.isArray(records) ? records : [];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const SpaceSelect = (props: any) => {
|
|
11
|
+
const { data, loading } = useRequest<any>({
|
|
12
|
+
resource: 'aiBuildGuideSpaces',
|
|
13
|
+
action: 'list',
|
|
14
|
+
params: {
|
|
15
|
+
filter: { status: 'completed' },
|
|
16
|
+
pageSize: 100,
|
|
17
|
+
sort: ['-createdAt'],
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const options = normalizeRecords(data).map((item: any) => ({
|
|
22
|
+
label: item.title,
|
|
23
|
+
value: item.id,
|
|
24
|
+
})) || [];
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Select
|
|
28
|
+
{...props}
|
|
29
|
+
loading={loading}
|
|
30
|
+
options={options}
|
|
31
|
+
showSearch
|
|
32
|
+
filterOption={(input, option) =>
|
|
33
|
+
(option?.label as string)?.toLowerCase().includes(input.toLowerCase())
|
|
34
|
+
}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useApp } from '@nocobase/client';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { name } from '../locale/namespace';
|
|
4
|
+
|
|
5
|
+
export const namespace = name;
|
|
6
|
+
|
|
7
|
+
export function useT() {
|
|
8
|
+
const app = useApp();
|
|
9
|
+
return useCallback(
|
|
10
|
+
(str: string, options?: any): string =>
|
|
11
|
+
app.i18n.t(str, { ns: [namespace, 'client'], ...options }) as unknown as string,
|
|
12
|
+
[app.i18n],
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function tStr(key: string) {
|
|
17
|
+
return `{{t(${JSON.stringify(key)}, { ns: ['${namespace}', 'client'], nsMode: 'fallback' })}}`;
|
|
18
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { BlockModel } from '@nocobase/client';
|
|
2
|
-
import { escapeT } from '@nocobase/flow-engine';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { UserGuideBlock } from '../UserGuideBlock';
|
|
2
|
+
import { escapeT } from '@nocobase/flow-engine';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { UserGuideBlock } from '../UserGuideBlock';
|
|
5
|
+
import { SpaceSelect } from '../components/SpaceSelect';
|
|
5
6
|
|
|
6
7
|
export class UserGuideBlockModel extends BlockModel {
|
|
7
8
|
renderComponent() {
|
|
@@ -19,32 +20,21 @@ UserGuideBlockModel.registerFlow({
|
|
|
19
20
|
uiSchema(ctx) {
|
|
20
21
|
const t = ctx.t;
|
|
21
22
|
return {
|
|
22
|
-
spaceId: {
|
|
23
|
-
title: t('Space'),
|
|
24
|
-
type: 'string',
|
|
25
|
-
'x-decorator': 'FormItem',
|
|
26
|
-
'x-component':
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
required: true,
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
},
|
|
42
|
-
async handler(ctx, params) {
|
|
43
|
-
const { spaceId } = params;
|
|
44
|
-
ctx.model.setProps({
|
|
45
|
-
spaceId,
|
|
46
|
-
});
|
|
47
|
-
},
|
|
23
|
+
spaceId: {
|
|
24
|
+
title: t('Space'),
|
|
25
|
+
type: 'string',
|
|
26
|
+
'x-decorator': 'FormItem',
|
|
27
|
+
'x-component': SpaceSelect,
|
|
28
|
+
required: true,
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
},
|
|
32
|
+
async handler(ctx, params) {
|
|
33
|
+
const { spaceId } = params;
|
|
34
|
+
ctx.model.setProps({
|
|
35
|
+
spaceId,
|
|
36
|
+
});
|
|
37
|
+
},
|
|
48
38
|
},
|
|
49
39
|
},
|
|
50
40
|
});
|
package/src/client/plugin.tsx
CHANGED
|
@@ -1,30 +1,53 @@
|
|
|
1
|
-
import { Plugin } from '@nocobase/client';
|
|
2
|
-
import { UserGuideManager } from './UserGuideManager';
|
|
3
|
-
import { UserGuideBlockProvider } from './UserGuideBlockProvider';
|
|
4
|
-
import { UserGuideBlockInitializer } from './UserGuideBlockInitializer';
|
|
5
|
-
import {
|
|
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
|
-
|
|
1
|
+
import { Plugin } from '@nocobase/client';
|
|
2
|
+
import { UserGuideManager } from './UserGuideManager';
|
|
3
|
+
import { UserGuideBlockProvider } from './UserGuideBlockProvider';
|
|
4
|
+
import { UserGuideBlockInitializer } from './UserGuideBlockInitializer';
|
|
5
|
+
import { UserGuideBlock } from './UserGuideBlock';
|
|
6
|
+
import { UserGuideBlockModel } from './models/UserGuideBlockModel';
|
|
7
|
+
import { userGuideBlockSettings } from './schemaSettings';
|
|
8
|
+
import { BuildButton } from './components/BuildButton';
|
|
9
|
+
import { LLMServiceSelect } from './components/LLMServiceSelect';
|
|
10
|
+
import { ModelSelect } from './components/ModelSelect';
|
|
11
|
+
import { StatusTag } from './components/StatusTag';
|
|
12
|
+
import { SpaceSelect } from './components/SpaceSelect';
|
|
13
|
+
import { namespace } from './locale';
|
|
14
|
+
|
|
15
|
+
export class PluginBuildGuideBlockClient extends Plugin {
|
|
16
|
+
async load() {
|
|
17
|
+
this.app.addComponents({
|
|
18
|
+
UserGuideBlock,
|
|
19
|
+
UserGuideBlockInitializer,
|
|
20
|
+
BuildButton,
|
|
21
|
+
LLMServiceSelect,
|
|
22
|
+
ModelSelect,
|
|
23
|
+
StatusTag,
|
|
24
|
+
SpaceSelect,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
this.app.schemaSettingsManager.add(userGuideBlockSettings);
|
|
28
|
+
|
|
29
|
+
this.app.use(UserGuideBlockProvider);
|
|
30
|
+
|
|
31
|
+
this.app.pluginSettingsManager.add('ai-build-guide', {
|
|
32
|
+
icon: 'ReadOutlined',
|
|
33
|
+
title: `{{t("Build Guide Block", { ns: "${namespace}" })}}`,
|
|
34
|
+
Component: UserGuideManager,
|
|
35
|
+
aclSnippet: 'pm.ai-build-guide',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const initializerItem = {
|
|
39
|
+
title: `{{t("User Guide", { ns: "${namespace}" })}}`,
|
|
40
|
+
Component: 'UserGuideBlockInitializer',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
this.app.schemaInitializerManager.addItem('page:addBlock', 'otherBlocks.aiUserGuide', initializerItem);
|
|
44
|
+
this.app.schemaInitializerManager.addItem('popup:common:addBlock', 'otherBlocks.aiUserGuide', initializerItem);
|
|
45
|
+
this.app.schemaInitializerManager.addItem('popup:addNew:addBlock', 'otherBlocks.aiUserGuide', initializerItem);
|
|
46
|
+
|
|
47
|
+
this.flowEngine.registerModels({
|
|
48
|
+
UserGuideBlockModel,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export default PluginBuildGuideBlockClient;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { useFieldSchema } from '@formily/react';
|
|
2
|
+
import { SchemaSettings, useDesignable } from '@nocobase/client';
|
|
3
|
+
import { useT } from './locale';
|
|
4
|
+
import { SpaceSelect } from './components/SpaceSelect';
|
|
5
|
+
|
|
6
|
+
export const userGuideBlockSettings = new SchemaSettings({
|
|
7
|
+
name: 'userGuideBlockSettings',
|
|
8
|
+
items: [
|
|
9
|
+
{
|
|
10
|
+
name: 'selectSpace',
|
|
11
|
+
type: 'modal',
|
|
12
|
+
useComponentProps() {
|
|
13
|
+
const fieldSchema = useFieldSchema();
|
|
14
|
+
const { dn } = useDesignable();
|
|
15
|
+
const t = useT();
|
|
16
|
+
|
|
17
|
+
const currentSpaceId = fieldSchema?.['x-component-props']?.spaceId || '';
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
title: t('Select Space'),
|
|
21
|
+
schema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: {
|
|
24
|
+
spaceId: {
|
|
25
|
+
title: t('Space'),
|
|
26
|
+
type: 'string',
|
|
27
|
+
'x-decorator': 'FormItem',
|
|
28
|
+
'x-component': SpaceSelect,
|
|
29
|
+
default: currentSpaceId,
|
|
30
|
+
required: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
onSubmit({ spaceId }: { spaceId: string }) {
|
|
35
|
+
const componentProps = { ...fieldSchema['x-component-props'], spaceId };
|
|
36
|
+
fieldSchema['x-component-props'] = componentProps;
|
|
37
|
+
dn.emit('patch', {
|
|
38
|
+
schema: {
|
|
39
|
+
'x-uid': fieldSchema['x-uid'],
|
|
40
|
+
'x-component-props': componentProps,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
dn.refresh();
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'divider',
|
|
50
|
+
type: 'divider',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: 'delete',
|
|
54
|
+
type: 'remove',
|
|
55
|
+
useComponentProps() {
|
|
56
|
+
return {
|
|
57
|
+
removeParentsIfNoChildren: true,
|
|
58
|
+
breakRemoveOn: {
|
|
59
|
+
'x-component': 'Grid',
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
});
|