plugin-build-ui-template 1.0.1

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.
@@ -0,0 +1,114 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var ai_build_ui_template_spaces_exports = {};
28
+ __export(ai_build_ui_template_spaces_exports, {
29
+ default: () => ai_build_ui_template_spaces_default
30
+ });
31
+ module.exports = __toCommonJS(ai_build_ui_template_spaces_exports);
32
+ var import_database = require("@nocobase/database");
33
+ var ai_build_ui_template_spaces_default = (0, import_database.defineCollection)({
34
+ name: "aiBuildUiTemplateSpaces",
35
+ shared: true,
36
+ dumpRules: "required",
37
+ migrationRules: ["overwrite", "schema-only"],
38
+ timestamps: true,
39
+ fields: [
40
+ {
41
+ type: "uid",
42
+ name: "id",
43
+ primaryKey: true
44
+ },
45
+ {
46
+ type: "string",
47
+ name: "title"
48
+ },
49
+ {
50
+ type: "string",
51
+ name: "llmService"
52
+ },
53
+ {
54
+ type: "string",
55
+ name: "model"
56
+ },
57
+ {
58
+ type: "text",
59
+ name: "systemPrompt"
60
+ },
61
+ {
62
+ type: "text",
63
+ name: "promptRequirements"
64
+ },
65
+ {
66
+ type: "string",
67
+ name: "type",
68
+ defaultValue: "block"
69
+ // 'block' or 'popup'
70
+ },
71
+ {
72
+ type: "string",
73
+ name: "targetCollection"
74
+ },
75
+ {
76
+ type: "string",
77
+ name: "buildPhase",
78
+ defaultValue: "idle"
79
+ },
80
+ {
81
+ type: "string",
82
+ name: "buildRunId"
83
+ },
84
+ {
85
+ type: "date",
86
+ name: "buildQueuedAt"
87
+ },
88
+ {
89
+ type: "date",
90
+ name: "buildStartedAt"
91
+ },
92
+ {
93
+ type: "date",
94
+ name: "buildHeartbeatAt"
95
+ },
96
+ {
97
+ type: "string",
98
+ name: "buildWorkerId"
99
+ },
100
+ {
101
+ type: "string",
102
+ name: "templateUid"
103
+ },
104
+ {
105
+ type: "string",
106
+ name: "status",
107
+ defaultValue: "draft"
108
+ },
109
+ {
110
+ type: "text",
111
+ name: "buildLog"
112
+ }
113
+ ]
114
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __create = Object.create;
11
+ var __defProp = Object.defineProperty;
12
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
13
+ var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __export = (target, all) => {
17
+ for (var name in all)
18
+ __defProp(target, name, { get: all[name], enumerable: true });
19
+ };
20
+ var __copyProps = (to, from, except, desc) => {
21
+ if (from && typeof from === "object" || typeof from === "function") {
22
+ for (let key of __getOwnPropNames(from))
23
+ if (!__hasOwnProp.call(to, key) && key !== except)
24
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
25
+ }
26
+ return to;
27
+ };
28
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
29
+ // If the importer is in node compatibility mode or this is not an ESM
30
+ // file that has been converted to a CommonJS file using a Babel-
31
+ // compatible transform (i.e. "__esModule" has not been set), then set
32
+ // "default" to the CommonJS "module.exports" for node compatibility.
33
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
34
+ mod
35
+ ));
36
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
37
+ var server_exports = {};
38
+ __export(server_exports, {
39
+ default: () => import_plugin.default,
40
+ namespace: () => namespace
41
+ });
42
+ module.exports = __toCommonJS(server_exports);
43
+ var import_plugin = __toESM(require("./plugin"));
44
+ const namespace = "plugin-build-ui-template";
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ namespace
48
+ });
@@ -0,0 +1,128 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __export = (target, all) => {
15
+ for (var name in all)
16
+ __defProp(target, name, { get: all[name], enumerable: true });
17
+ };
18
+ var __copyProps = (to, from, except, desc) => {
19
+ if (from && typeof from === "object" || typeof from === "function") {
20
+ for (let key of __getOwnPropNames(from))
21
+ if (!__hasOwnProp.call(to, key) && key !== except)
22
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
+ }
24
+ return to;
25
+ };
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
27
+ var plugin_exports = {};
28
+ __export(plugin_exports, {
29
+ PluginBuildUITemplateServer: () => PluginBuildUITemplateServer,
30
+ default: () => plugin_default
31
+ });
32
+ module.exports = __toCommonJS(plugin_exports);
33
+ var import_server = require("@nocobase/server");
34
+ var import_path = require("path");
35
+ var import_build = require("./actions/build");
36
+ class PluginBuildUITemplateServer extends import_server.Plugin {
37
+ schemaCollections = ["aiBuildUiTemplateSpaces"];
38
+ async load() {
39
+ await this.db.import({
40
+ directory: (0, import_path.resolve)(__dirname, "collections")
41
+ });
42
+ await this.ensureSchema();
43
+ this.app.resourceManager.registerActionHandlers({
44
+ "aiBuildUiTemplateSpaces:build": import_build.build
45
+ });
46
+ this.app.acl.registerSnippet({
47
+ name: "pm.ai-build-ui-template",
48
+ actions: ["aiBuildUiTemplateSpaces:*"]
49
+ });
50
+ (0, import_build.registerBuildTemplateQueue)(this.app);
51
+ this.app.on("afterStart", async () => {
52
+ try {
53
+ await (0, import_build.recoverInterruptedBuilds)(this.app);
54
+ } catch (err) {
55
+ this.app.logger.warn("[plugin-build-ui-template] Failed to recover interrupted builds", err);
56
+ }
57
+ });
58
+ this.app.on("beforeStop", () => {
59
+ (0, import_build.unregisterBuildTemplateQueue)(this.app);
60
+ });
61
+ this.app.on("beforeDestroy", () => {
62
+ (0, import_build.unregisterBuildTemplateQueue)(this.app);
63
+ });
64
+ }
65
+ async ensureCollectionSchema(collectionName) {
66
+ const collection = this.db.getCollection(collectionName);
67
+ if (!collection) {
68
+ this.app.logger.warn(`[plugin-build-ui-template] Collection "${collectionName}" is not registered`);
69
+ return;
70
+ }
71
+ const queryInterface = this.db.sequelize.getQueryInterface();
72
+ const tableName = collection.getTableNameWithSchema();
73
+ let columns = null;
74
+ try {
75
+ columns = await queryInterface.describeTable(tableName);
76
+ } catch (error) {
77
+ await collection.model.sync();
78
+ columns = await queryInterface.describeTable(tableName);
79
+ }
80
+ const attributes = collection.model.rawAttributes;
81
+ for (const [attributeName, attribute] of Object.entries(attributes)) {
82
+ const columnName = attribute.field || attributeName;
83
+ if (columns[columnName]) {
84
+ continue;
85
+ }
86
+ const columnDefinition = { ...attribute };
87
+ delete columnDefinition.Model;
88
+ delete columnDefinition.fieldName;
89
+ await queryInterface.addColumn(tableName, columnName, columnDefinition);
90
+ columns[columnName] = columnDefinition;
91
+ this.app.logger.info(`[plugin-build-ui-template] Added missing column "${columnName}" to "${collectionName}"`);
92
+ }
93
+ }
94
+ async ensureSchema() {
95
+ for (const collectionName of this.schemaCollections) {
96
+ await this.ensureCollectionSchema(collectionName);
97
+ }
98
+ const repo = this.db.getRepository("collections");
99
+ if (repo) {
100
+ for (const collectionName of this.schemaCollections) {
101
+ await repo.db2cm(collectionName);
102
+ }
103
+ }
104
+ }
105
+ async install(options) {
106
+ await this.ensureSchema();
107
+ }
108
+ async upgrade() {
109
+ await this.ensureSchema();
110
+ }
111
+ async beforeDisable() {
112
+ (0, import_build.unregisterBuildTemplateQueue)(this.app);
113
+ }
114
+ async afterDisable() {
115
+ (0, import_build.unregisterBuildTemplateQueue)(this.app);
116
+ }
117
+ async beforeUnload() {
118
+ (0, import_build.unregisterBuildTemplateQueue)(this.app);
119
+ }
120
+ async remove() {
121
+ (0, import_build.unregisterBuildTemplateQueue)(this.app);
122
+ }
123
+ }
124
+ var plugin_default = PluginBuildUITemplateServer;
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ PluginBuildUITemplateServer
128
+ });
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "plugin-build-ui-template",
3
+ "displayName": "Build UI Template",
4
+ "displayName.vi-VN": "Khối tạo giao diện",
5
+ "displayName.zh-CN": "构建UI模板",
6
+ "description": "Generate standard UI Block and Popup templates using AI, saving directly to plugin-ui-templates.",
7
+ "description.vi-VN": "Tạo block và popup template bằng AI, lưu trực tiếp vào plugin-ui-templates.",
8
+ "version": "1.0.1",
9
+ "license": "Apache-2.0",
10
+ "keywords": [
11
+ "ai",
12
+ "ui",
13
+ "templates",
14
+ "nocobase-plugin"
15
+ ],
16
+ "main": "dist/server/index.js",
17
+ "files": [
18
+ "dist",
19
+ "src",
20
+ "client.js",
21
+ "server.js",
22
+ "client.d.ts",
23
+ "server.d.ts",
24
+ "client-v2.js",
25
+ "client-v2.d.ts"
26
+ ],
27
+ "dependencies": {},
28
+ "devDependencies": {},
29
+ "peerDependencies": {
30
+ "@nocobase/client": "2.x",
31
+ "@nocobase/server": "2.x",
32
+ "@nocobase/database": "2.x",
33
+ "@nocobase/test": "2.x",
34
+ "@nocobase/plugin-ai": "2.x",
35
+ "@nocobase/plugin-ui-templates": "2.x",
36
+ "@nocobase/plugin-flow-engine": "2.x",
37
+ "@langchain/core": "*",
38
+ "axios": "*",
39
+ "@nocobase/client-v2": "2.x",
40
+ "@nocobase/flow-engine": "2.x"
41
+ },
42
+ "nocobase": {
43
+ "supportedVersions": [
44
+ "2.x"
45
+ ],
46
+ "editionLevel": 0
47
+ }
48
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');