@nocobase/server 2.0.0-beta.9 → 2.0.0
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/lib/aes-encryptor.d.ts +1 -0
- package/lib/aes-encryptor.js +8 -5
- package/lib/ai/create-docs-index.d.ts +13 -0
- package/lib/ai/create-docs-index.js +892 -0
- package/lib/app-supervisor/app-options-factory.d.ts +80 -0
- package/lib/app-supervisor/app-options-factory.js +91 -0
- package/lib/app-supervisor/condition-registry.d.ts +18 -0
- package/lib/app-supervisor/condition-registry.js +60 -0
- package/lib/app-supervisor/db-creator.d.ts +16 -0
- package/lib/app-supervisor/db-creator.js +163 -0
- package/lib/app-supervisor/db-drivers.d.ts +11 -0
- package/lib/app-supervisor/db-drivers.js +52 -0
- package/lib/app-supervisor/index.d.ts +161 -0
- package/lib/app-supervisor/index.js +690 -0
- package/lib/app-supervisor/main-only-adapter.d.ts +37 -0
- package/lib/app-supervisor/main-only-adapter.js +156 -0
- package/lib/app-supervisor/types.d.ts +161 -0
- package/lib/app-supervisor/types.js +24 -0
- package/lib/application.d.ts +3 -1
- package/lib/application.js +10 -6
- package/lib/commands/ai.d.ts +11 -0
- package/lib/commands/ai.js +40 -0
- package/lib/commands/console.js +1 -1
- package/lib/commands/index.js +2 -0
- package/lib/commands/install.js +2 -0
- package/lib/commands/start.js +3 -0
- package/lib/commands/upgrade.js +2 -0
- package/lib/gateway/errors.js +1 -1
- package/lib/gateway/index.js +64 -15
- package/lib/gateway/ipc-socket-server.js +1 -1
- package/lib/gateway/ws-server.js +3 -2
- package/lib/helper.js +20 -3
- package/lib/plugin-manager/deps.js +1 -1
- package/lib/plugin-manager/plugin-manager.js +2 -0
- package/lib/plugin.d.ts +5 -0
- package/lib/plugin.js +25 -0
- package/lib/redis-connection-manager.d.ts +15 -5
- package/lib/redis-connection-manager.js +117 -24
- package/package.json +18 -17
- package/lib/app-supervisor.d.ts +0 -74
- package/lib/app-supervisor.js +0 -338
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
import Application from '../application';
|
|
10
|
+
import type { AppDiscoveryAdapter, AppProcessAdapter, AppStatus, GetAppOptions } from './types';
|
|
11
|
+
import type { AppSupervisor } from './index';
|
|
12
|
+
/** Minimal single-process adapter only for booting the main application. */
|
|
13
|
+
export declare class MainOnlyAdapter implements AppDiscoveryAdapter, AppProcessAdapter {
|
|
14
|
+
protected readonly supervisor: AppSupervisor;
|
|
15
|
+
readonly name: string;
|
|
16
|
+
app: Application;
|
|
17
|
+
status: AppStatus;
|
|
18
|
+
appErrors: Record<string, Error>;
|
|
19
|
+
constructor(supervisor: AppSupervisor);
|
|
20
|
+
getApp(appName: string, options?: GetAppOptions): Promise<Application<import("../application").DefaultState, import("../application").DefaultContext>>;
|
|
21
|
+
bootstrapApp(appName: string): Promise<void>;
|
|
22
|
+
addApp(app: Application): Application<import("../application").DefaultState, import("../application").DefaultContext>;
|
|
23
|
+
getApps(): Application<import("../application").DefaultState, import("../application").DefaultContext>[];
|
|
24
|
+
hasApp(appName: string): boolean;
|
|
25
|
+
startApp(appName: string): Promise<void>;
|
|
26
|
+
stopApp(appName: string): Promise<void>;
|
|
27
|
+
removeApp(appName: string): Promise<void>;
|
|
28
|
+
upgradeApp(appName: string): Promise<void>;
|
|
29
|
+
removeAllApps(): Promise<void>;
|
|
30
|
+
setAppStatus(appName: string, status: AppStatus, options?: {}): void;
|
|
31
|
+
getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus;
|
|
32
|
+
hasAppError(appName: string): boolean;
|
|
33
|
+
setAppError(appName: string, error: Error): void;
|
|
34
|
+
clearAppError(appName: string): void;
|
|
35
|
+
setAppLastSeenAt(): void;
|
|
36
|
+
getAppLastSeenAt(appName: string): any;
|
|
37
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var main_only_adapter_exports = {};
|
|
29
|
+
__export(main_only_adapter_exports, {
|
|
30
|
+
MainOnlyAdapter: () => MainOnlyAdapter
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(main_only_adapter_exports);
|
|
33
|
+
const _MainOnlyAdapter = class _MainOnlyAdapter {
|
|
34
|
+
constructor(supervisor) {
|
|
35
|
+
this.supervisor = supervisor;
|
|
36
|
+
this.name = "main-only";
|
|
37
|
+
}
|
|
38
|
+
name;
|
|
39
|
+
app;
|
|
40
|
+
status;
|
|
41
|
+
appErrors = {};
|
|
42
|
+
async getApp(appName, options = {}) {
|
|
43
|
+
if (appName !== "main") {
|
|
44
|
+
this.supervisor.logger.warn(`only main app is supported`, { method: "getApp", appName });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!options.withOutBootStrap) {
|
|
48
|
+
await this.bootstrapApp(appName);
|
|
49
|
+
}
|
|
50
|
+
return this.app;
|
|
51
|
+
}
|
|
52
|
+
async bootstrapApp(appName) {
|
|
53
|
+
if (appName !== "main" || !this.app) {
|
|
54
|
+
this.setAppStatus(appName, "not_found");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const status = this.getAppStatus("main");
|
|
58
|
+
if (this.hasApp(appName) && status && status !== "preparing") {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.setAppStatus("main", "initializing");
|
|
62
|
+
this.setAppStatus("main", "initialized");
|
|
63
|
+
}
|
|
64
|
+
addApp(app) {
|
|
65
|
+
if (app.name !== "main") {
|
|
66
|
+
this.supervisor.logger.warn(`only main app is supported`, { method: "addApp" });
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (this.app) {
|
|
70
|
+
throw new Error(`app ${app.name} already exists`);
|
|
71
|
+
}
|
|
72
|
+
this.app = app;
|
|
73
|
+
if (!this.status || this.status === "not_found") {
|
|
74
|
+
this.setAppStatus(app.name, "preparing");
|
|
75
|
+
}
|
|
76
|
+
return app;
|
|
77
|
+
}
|
|
78
|
+
getApps() {
|
|
79
|
+
return [this.app];
|
|
80
|
+
}
|
|
81
|
+
hasApp(appName) {
|
|
82
|
+
if (appName !== "main") {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return !!this.app;
|
|
86
|
+
}
|
|
87
|
+
async startApp(appName) {
|
|
88
|
+
if (appName !== "main") {
|
|
89
|
+
this.supervisor.logger.warn(`only main app is supported`, { method: "startApp" });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const app = await this.getApp(appName, { withOutBootStrap: true });
|
|
93
|
+
await (app == null ? void 0 : app.runCommand("start", "--quickstart"));
|
|
94
|
+
}
|
|
95
|
+
async stopApp(appName) {
|
|
96
|
+
if (appName !== "main") {
|
|
97
|
+
this.supervisor.logger.warn(`only main app is supported`, { method: "stopApp" });
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
await this.app.runCommand("stop");
|
|
101
|
+
}
|
|
102
|
+
async removeApp(appName) {
|
|
103
|
+
if (appName !== "main") {
|
|
104
|
+
this.supervisor.logger.warn(`only main app is supported`, { method: "removeApp" });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (!this.app) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
await this.app.runCommand("destroy");
|
|
111
|
+
}
|
|
112
|
+
async upgradeApp(appName) {
|
|
113
|
+
if (appName !== "main") {
|
|
114
|
+
this.supervisor.logger.warn(`only main app is supported`, { method: "upgrade" });
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!this.app) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
await this.app.runCommand("upgrade");
|
|
121
|
+
}
|
|
122
|
+
async removeAllApps() {
|
|
123
|
+
return this.removeApp("main");
|
|
124
|
+
}
|
|
125
|
+
setAppStatus(appName, status, options = {}) {
|
|
126
|
+
if (this.status === status) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.status = status;
|
|
130
|
+
this.supervisor.emit("appStatusChanged", { appName, status, options });
|
|
131
|
+
}
|
|
132
|
+
getAppStatus(appName, defaultStatus) {
|
|
133
|
+
return this.status ?? defaultStatus ?? null;
|
|
134
|
+
}
|
|
135
|
+
hasAppError(appName) {
|
|
136
|
+
return !!this.appErrors[appName];
|
|
137
|
+
}
|
|
138
|
+
setAppError(appName, error) {
|
|
139
|
+
this.appErrors[appName] = error;
|
|
140
|
+
this.supervisor.emit("appError", { appName, error });
|
|
141
|
+
}
|
|
142
|
+
clearAppError(appName) {
|
|
143
|
+
this.appErrors[appName] = null;
|
|
144
|
+
}
|
|
145
|
+
setAppLastSeenAt() {
|
|
146
|
+
}
|
|
147
|
+
getAppLastSeenAt(appName) {
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
__name(_MainOnlyAdapter, "MainOnlyAdapter");
|
|
152
|
+
let MainOnlyAdapter = _MainOnlyAdapter;
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
MainOnlyAdapter
|
|
156
|
+
});
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
/// <reference types="node" />
|
|
10
|
+
/// <reference types="node" />
|
|
11
|
+
import { IDatabaseOptions, Transaction, Transactionable } from '@nocobase/database';
|
|
12
|
+
import type Application from '../application';
|
|
13
|
+
import type { AppSupervisor } from './index';
|
|
14
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
15
|
+
/**
|
|
16
|
+
* Options accepted by discovery adapter when loading an application.
|
|
17
|
+
*/
|
|
18
|
+
export type GetAppOptions = {
|
|
19
|
+
withOutBootStrap?: boolean;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Parameters supplied to a bootstrapper when a sub-application is being started.
|
|
24
|
+
*/
|
|
25
|
+
export type BootOptions = {
|
|
26
|
+
appName: string;
|
|
27
|
+
options: Record<string, any>;
|
|
28
|
+
appSupervisor: AppSupervisor;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Callback used by process adapters to lazily initialize applications.
|
|
32
|
+
*/
|
|
33
|
+
export type AppBootstrapper = (bootOptions: BootOptions) => Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* All supported lifecycle states of a managed application.
|
|
36
|
+
*/
|
|
37
|
+
export type AppStatus = 'preparing' | 'initializing' | 'initialized' | 'running' | 'commanding' | 'stopped' | 'error' | 'not_found';
|
|
38
|
+
/**
|
|
39
|
+
* Metadata representing a deployable environment (container, pod, VM, etc.).
|
|
40
|
+
*/
|
|
41
|
+
export type EnvironmentInfo = {
|
|
42
|
+
name: string;
|
|
43
|
+
url?: string;
|
|
44
|
+
proxyUrl?: string;
|
|
45
|
+
available?: boolean;
|
|
46
|
+
appVersion?: string;
|
|
47
|
+
lastHeartbeatAt?: number;
|
|
48
|
+
};
|
|
49
|
+
export type BootstrapLock = {
|
|
50
|
+
acquire: () => Promise<boolean>;
|
|
51
|
+
release: () => Promise<void>;
|
|
52
|
+
};
|
|
53
|
+
export type AppModelOptions = {
|
|
54
|
+
dbConnType?: 'new_database' | 'new_connection' | 'new_schema' | string;
|
|
55
|
+
database?: IDatabaseOptions;
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
};
|
|
58
|
+
export type AppModel = {
|
|
59
|
+
name: string;
|
|
60
|
+
cname?: string;
|
|
61
|
+
environment?: string;
|
|
62
|
+
environments?: string[];
|
|
63
|
+
options: AppModelOptions;
|
|
64
|
+
};
|
|
65
|
+
export type ProcessCommand = {
|
|
66
|
+
requestId: string;
|
|
67
|
+
appName: string;
|
|
68
|
+
action: 'create' | 'start' | 'stop' | 'remove' | string;
|
|
69
|
+
environments: string[];
|
|
70
|
+
payload?: Record<string, any>;
|
|
71
|
+
};
|
|
72
|
+
export type AppDbCreatorOptions = Transactionable & {
|
|
73
|
+
app: Application;
|
|
74
|
+
appOptions: AppModelOptions;
|
|
75
|
+
};
|
|
76
|
+
export type AppDbCreator = (options: AppDbCreatorOptions) => Promise<void>;
|
|
77
|
+
export type AppOptionsFactory = (appName: string, mainApp: Application, options?: AppModelOptions) => any;
|
|
78
|
+
/**
|
|
79
|
+
* Abstraction for discovering applications across deployment environments.
|
|
80
|
+
*/
|
|
81
|
+
export type AppStatusesResult = Record<string, AppStatus | Record<string, AppStatus> | null>;
|
|
82
|
+
export interface AppDiscoveryAdapter {
|
|
83
|
+
readonly name: string;
|
|
84
|
+
readonly environmentName?: string;
|
|
85
|
+
readonly environmentUrl?: string;
|
|
86
|
+
readonly environmentProxyUrl?: string;
|
|
87
|
+
readonly appStatus?: Record<string, AppStatus>;
|
|
88
|
+
readonly lastSeenAt?: Map<string, number>;
|
|
89
|
+
/**
|
|
90
|
+
* Update the "last seen at" timestamp for an application.
|
|
91
|
+
*/
|
|
92
|
+
setAppLastSeenAt(appName: string): void | Promise<void>;
|
|
93
|
+
getAppLastSeenAt(appName: string): number | null | Promise<number | null>;
|
|
94
|
+
/**
|
|
95
|
+
* Read the cached lifecycle status for a given application.
|
|
96
|
+
*/
|
|
97
|
+
getAppStatus(appName: string, defaultStatus?: AppStatus): Promise<AppStatus | null> | AppStatus | null;
|
|
98
|
+
/**
|
|
99
|
+
* Persist an application's lifecycle status back to the discovery backend.
|
|
100
|
+
*/
|
|
101
|
+
setAppStatus(appName: string, status: AppStatus, options?: Record<string, any>): void | Promise<void>;
|
|
102
|
+
clearAppStatus?(appName: string): void | Promise<void>;
|
|
103
|
+
loadAppModels?(mainApp: Application): Promise<void>;
|
|
104
|
+
getAppsStatuses?(appNames?: string[]): Promise<AppStatusesResult> | AppStatusesResult;
|
|
105
|
+
addAutoStartApps?(environmentName: string, appName: string[]): Promise<void>;
|
|
106
|
+
getAutoStartApps?(environmentName: string): Promise<string[]>;
|
|
107
|
+
removeAutoStartApps?(environmentName: string, appNames: string[]): Promise<void>;
|
|
108
|
+
addAppModel?(appModel: AppModel): Promise<void>;
|
|
109
|
+
getAppModel?(appName: string): Promise<AppModel>;
|
|
110
|
+
removeAppModel?(appName: string): Promise<void>;
|
|
111
|
+
getAppNameByCName?(cname: string): Promise<string | null>;
|
|
112
|
+
registerEnvironment?(environment: EnvironmentInfo): Promise<boolean>;
|
|
113
|
+
unregisterEnvironment?(): Promise<void>;
|
|
114
|
+
listEnvironments?(): Promise<EnvironmentInfo[]>;
|
|
115
|
+
getEnvironment?(environmentName: string): Promise<EnvironmentInfo | null>;
|
|
116
|
+
heartbeatEnvironment?(): Promise<void>;
|
|
117
|
+
getBootstrapLock?(appName: string): Promise<BootstrapLock | null> | BootstrapLock | null;
|
|
118
|
+
proxyWeb?(appName: string, req: IncomingMessage, res: ServerResponse): Promise<boolean>;
|
|
119
|
+
proxyWs?(req: IncomingMessage, socket: any, head: Buffer): Promise<boolean>;
|
|
120
|
+
dispose?(): Promise<void>;
|
|
121
|
+
}
|
|
122
|
+
export interface AppProcessAdapter {
|
|
123
|
+
readonly name: string;
|
|
124
|
+
readonly apps?: Record<string, Application>;
|
|
125
|
+
readonly appErrors?: Record<string, Error>;
|
|
126
|
+
readonly lastMaintainingMessage?: Record<string, string>;
|
|
127
|
+
readonly statusBeforeCommanding?: Record<string, AppStatus>;
|
|
128
|
+
addApp(app: Application): void;
|
|
129
|
+
getApp(appName: string, options?: GetAppOptions): Promise<Application>;
|
|
130
|
+
hasApp(appName: string): boolean;
|
|
131
|
+
bootstrapApp(appName: string): Promise<void>;
|
|
132
|
+
getApps?(): Application[];
|
|
133
|
+
createApp?(options: {
|
|
134
|
+
appModel: AppModel;
|
|
135
|
+
mainApp?: Application;
|
|
136
|
+
transaction?: Transaction;
|
|
137
|
+
}, context?: {
|
|
138
|
+
requestId: string;
|
|
139
|
+
}): Promise<void>;
|
|
140
|
+
startApp?(appName: string, context?: {
|
|
141
|
+
requestId: string;
|
|
142
|
+
}): Promise<void>;
|
|
143
|
+
stopApp?(appName: string, context?: {
|
|
144
|
+
requestId: string;
|
|
145
|
+
}): Promise<void>;
|
|
146
|
+
removeApp?(appName: string, context?: {
|
|
147
|
+
requestId: string;
|
|
148
|
+
}): Promise<void>;
|
|
149
|
+
upgradeApp?(appName: string, context?: {
|
|
150
|
+
requestId: string;
|
|
151
|
+
}): Promise<void>;
|
|
152
|
+
removeAllApps?(): Promise<void>;
|
|
153
|
+
setAppError?(appName: string, error: Error): void;
|
|
154
|
+
hasAppError?(appName: string): boolean;
|
|
155
|
+
clearAppError?(appName: string): void;
|
|
156
|
+
}
|
|
157
|
+
export interface AppCommandAdapter {
|
|
158
|
+
dispatchCommand(command: ProcessCommand): Promise<void>;
|
|
159
|
+
registerCommandHandler(mainApp: Application): void;
|
|
160
|
+
dispose?(): Promise<void>;
|
|
161
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
|
+
var types_exports = {};
|
|
24
|
+
module.exports = __toCommonJS(types_exports);
|
package/lib/application.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/databas
|
|
|
15
15
|
import { Logger, LoggerOptions, RequestLoggerOptions, SystemLogger, SystemLoggerOptions } from '@nocobase/logger';
|
|
16
16
|
import { ResourceOptions, Resourcer } from '@nocobase/resourcer';
|
|
17
17
|
import { Telemetry, TelemetryOptions } from '@nocobase/telemetry';
|
|
18
|
+
import { AIManager } from '@nocobase/ai';
|
|
18
19
|
import { LockManager, LockManagerOptions } from '@nocobase/lock-manager';
|
|
19
20
|
import { AsyncEmitter, ToposortOptions } from '@nocobase/utils';
|
|
20
21
|
import { Command, CommandOptions, ParseOptions } from 'commander';
|
|
@@ -180,6 +181,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
180
181
|
redisConnectionManager: RedisConnectionManager;
|
|
181
182
|
workerIdAllocator: WorkerIdAllocator;
|
|
182
183
|
snowflakeIdGenerator: SnowflakeIdGenerator;
|
|
184
|
+
aiManager: AIManager;
|
|
183
185
|
pubSubManager: PubSubManager;
|
|
184
186
|
syncMessageManager: SyncMessageManager;
|
|
185
187
|
requestLogger: Logger;
|
|
@@ -279,7 +281,7 @@ export declare class Application<StateT = DefaultState, ContextT = DefaultContex
|
|
|
279
281
|
/**
|
|
280
282
|
* @internal
|
|
281
283
|
*/
|
|
282
|
-
setMaintaining(_maintainingCommandStatus: MaintainingCommandStatus): void
|
|
284
|
+
setMaintaining(_maintainingCommandStatus: MaintainingCommandStatus): Promise<void>;
|
|
283
285
|
/**
|
|
284
286
|
* @internal
|
|
285
287
|
*/
|
package/lib/application.js
CHANGED
|
@@ -49,6 +49,7 @@ var import_data_source_manager = require("@nocobase/data-source-manager");
|
|
|
49
49
|
var import_database = __toESM(require("@nocobase/database"));
|
|
50
50
|
var import_logger = require("@nocobase/logger");
|
|
51
51
|
var import_telemetry = require("@nocobase/telemetry");
|
|
52
|
+
var import_ai = require("@nocobase/ai");
|
|
52
53
|
var import_lock_manager = require("@nocobase/lock-manager");
|
|
53
54
|
var import_snowflake_id = require("@nocobase/snowflake-id");
|
|
54
55
|
var import_utils = require("@nocobase/utils");
|
|
@@ -128,6 +129,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
128
129
|
redisConnectionManager;
|
|
129
130
|
workerIdAllocator;
|
|
130
131
|
snowflakeIdGenerator;
|
|
132
|
+
aiManager;
|
|
131
133
|
pubSubManager;
|
|
132
134
|
syncMessageManager;
|
|
133
135
|
requestLogger;
|
|
@@ -316,9 +318,9 @@ const _Application = class _Application extends import_koa.default {
|
|
|
316
318
|
/**
|
|
317
319
|
* @internal
|
|
318
320
|
*/
|
|
319
|
-
setMaintaining(_maintainingCommandStatus) {
|
|
321
|
+
async setMaintaining(_maintainingCommandStatus) {
|
|
320
322
|
this._maintainingCommandStatus = _maintainingCommandStatus;
|
|
321
|
-
this.
|
|
323
|
+
await this.emitAsync("maintaining", _maintainingCommandStatus);
|
|
322
324
|
if (_maintainingCommandStatus.status == "command_end") {
|
|
323
325
|
this._maintaining = false;
|
|
324
326
|
return;
|
|
@@ -610,7 +612,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
610
612
|
await this.pm.loadCommands();
|
|
611
613
|
}
|
|
612
614
|
const command = await this.cli.parseAsync(argv, options);
|
|
613
|
-
this.setMaintaining({
|
|
615
|
+
await this.setMaintaining({
|
|
614
616
|
status: "command_end",
|
|
615
617
|
command: this.activatedCommand
|
|
616
618
|
});
|
|
@@ -621,7 +623,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
621
623
|
name: "unknown"
|
|
622
624
|
};
|
|
623
625
|
}
|
|
624
|
-
this.setMaintaining({
|
|
626
|
+
await this.setMaintaining({
|
|
625
627
|
status: "command_error",
|
|
626
628
|
command: this.activatedCommand,
|
|
627
629
|
error
|
|
@@ -843,11 +845,11 @@ const _Application = class _Application extends import_koa.default {
|
|
|
843
845
|
this.activatedCommand = {
|
|
844
846
|
name: (0, import_helper.getCommandFullName)(actionCommand)
|
|
845
847
|
};
|
|
846
|
-
this.setMaintaining({
|
|
848
|
+
await this.setMaintaining({
|
|
847
849
|
status: "command_begin",
|
|
848
850
|
command: this.activatedCommand
|
|
849
851
|
});
|
|
850
|
-
this.setMaintaining({
|
|
852
|
+
await this.setMaintaining({
|
|
851
853
|
status: "command_running",
|
|
852
854
|
command: this.activatedCommand
|
|
853
855
|
});
|
|
@@ -917,6 +919,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
917
919
|
this._env = new import_environment.Environment();
|
|
918
920
|
this._cli = this.createCLI();
|
|
919
921
|
this._i18n = (0, import_helper.createI18n)(options);
|
|
922
|
+
this.aiManager = new import_ai.AIManager(this);
|
|
920
923
|
this.pubSubManager = (0, import_pub_sub_manager.createPubSubManager)(this, options.pubSubManager);
|
|
921
924
|
this.syncMessageManager = new import_sync_message_manager.SyncMessageManager(this, options.syncMessageManager);
|
|
922
925
|
this.eventQueue = new import_event_queue.EventQueue(this, options.eventQueue);
|
|
@@ -981,6 +984,7 @@ const _Application = class _Application extends import_koa.default {
|
|
|
981
984
|
for (const callback of _Application.staticCommands) {
|
|
982
985
|
callback(this);
|
|
983
986
|
}
|
|
987
|
+
this.aiManager = new import_ai.AIManager(this);
|
|
984
988
|
}
|
|
985
989
|
createMainDataSource(options) {
|
|
986
990
|
const mainDataSourceInstance = new import_main_data_source.MainDataSource({
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import type Application from '../application';
|
|
10
|
+
declare const _default: (app: Application) => void;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
+
var __export = (target, all) => {
|
|
16
|
+
for (var name in all)
|
|
17
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
+
};
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var ai_exports = {};
|
|
29
|
+
__export(ai_exports, {
|
|
30
|
+
default: () => ai_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(ai_exports);
|
|
33
|
+
var import_create_docs_index = require("../ai/create-docs-index");
|
|
34
|
+
var ai_default = /* @__PURE__ */ __name((app) => {
|
|
35
|
+
const ai = app.command("ai");
|
|
36
|
+
ai.command("create-docs-index").option("--pkg [pkg]", "Generate docs index for the specified plugin package (comma separated).").action(async (...cliArgs) => {
|
|
37
|
+
const [opts] = cliArgs;
|
|
38
|
+
await (0, import_create_docs_index.createDocsIndex)(app, opts);
|
|
39
|
+
});
|
|
40
|
+
}, "default");
|
package/lib/commands/console.js
CHANGED
|
@@ -31,9 +31,9 @@ __export(console_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(console_exports);
|
|
33
33
|
/* istanbul ignore file -- @preserve */
|
|
34
|
-
const REPL = require("repl");
|
|
35
34
|
var console_default = /* @__PURE__ */ __name((app) => {
|
|
36
35
|
app.command("console").preload().action(async () => {
|
|
36
|
+
const REPL = require("repl");
|
|
37
37
|
await app.start();
|
|
38
38
|
const repl = REPL.start("nocobase > ").context.app = app;
|
|
39
39
|
repl.on("exit", async function(err) {
|
package/lib/commands/index.js
CHANGED
|
@@ -54,6 +54,7 @@ var import_stop = __toESM(require("./stop"));
|
|
|
54
54
|
var import_upgrade = __toESM(require("./upgrade"));
|
|
55
55
|
var import_console = __toESM(require("./console"));
|
|
56
56
|
var import_repair = __toESM(require("./repair"));
|
|
57
|
+
var import_ai = __toESM(require("./ai"));
|
|
57
58
|
/* istanbul ignore file -- @preserve */
|
|
58
59
|
function registerCli(app) {
|
|
59
60
|
(0, import_console.default)(app);
|
|
@@ -70,6 +71,7 @@ function registerCli(app) {
|
|
|
70
71
|
(0, import_start.default)(app);
|
|
71
72
|
(0, import_refresh.default)(app);
|
|
72
73
|
(0, import_repair.default)(app);
|
|
74
|
+
(0, import_ai.default)(app);
|
|
73
75
|
app.command("build").argument("[packages...]");
|
|
74
76
|
app.command("clean");
|
|
75
77
|
app.command("dev").usage("[options]").option("-p, --port [port]").option("--client").option("--server");
|
package/lib/commands/install.js
CHANGED
|
@@ -30,12 +30,14 @@ __export(install_exports, {
|
|
|
30
30
|
default: () => install_default
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(install_exports);
|
|
33
|
+
var import_create_docs_index = require("../ai/create-docs-index");
|
|
33
34
|
/* istanbul ignore file -- @preserve */
|
|
34
35
|
var install_default = /* @__PURE__ */ __name((app) => {
|
|
35
36
|
app.command("install").ipc().auth().option("-f, --force").option("-c, --clean").option("--lang <lang>").action(async (options) => {
|
|
36
37
|
if (options.lang) {
|
|
37
38
|
process.env.INIT_APP_LANG = options.lang;
|
|
38
39
|
}
|
|
40
|
+
await (0, import_create_docs_index.createDocsIndex)(app);
|
|
39
41
|
await app.install(options);
|
|
40
42
|
const reinstall = options.clean || options.force;
|
|
41
43
|
app.log.info(`app ${reinstall ? "reinstalled" : "installed"} successfully [v${app.getVersion()}]`);
|
package/lib/commands/start.js
CHANGED
|
@@ -42,6 +42,7 @@ __export(start_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(start_exports);
|
|
43
43
|
var import_fs_extra = __toESM(require("fs-extra"));
|
|
44
44
|
var import_path = require("path");
|
|
45
|
+
var import_create_docs_index = require("../ai/create-docs-index");
|
|
45
46
|
var import_application_not_install = require("../errors/application-not-install");
|
|
46
47
|
/* istanbul ignore file -- @preserve */
|
|
47
48
|
var start_default = /* @__PURE__ */ __name((app) => {
|
|
@@ -52,6 +53,7 @@ var start_default = /* @__PURE__ */ __name((app) => {
|
|
|
52
53
|
if (upgrading) {
|
|
53
54
|
if (!process.env.VITEST) {
|
|
54
55
|
if (await app.isInstalled()) {
|
|
56
|
+
await (0, import_create_docs_index.createDocsIndex)(app);
|
|
55
57
|
await app.upgrade();
|
|
56
58
|
}
|
|
57
59
|
}
|
|
@@ -60,6 +62,7 @@ var start_default = /* @__PURE__ */ __name((app) => {
|
|
|
60
62
|
} catch (error) {
|
|
61
63
|
}
|
|
62
64
|
} else if (options.quickstart) {
|
|
65
|
+
await (0, import_create_docs_index.createDocsIndex)(app);
|
|
63
66
|
if (await app.isInstalled()) {
|
|
64
67
|
await app.upgrade({ quickstart: true });
|
|
65
68
|
} else {
|
package/lib/commands/upgrade.js
CHANGED
|
@@ -30,9 +30,11 @@ __export(upgrade_exports, {
|
|
|
30
30
|
default: () => upgrade_default
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(upgrade_exports);
|
|
33
|
+
var import_create_docs_index = require("../ai/create-docs-index");
|
|
33
34
|
/* istanbul ignore file -- @preserve */
|
|
34
35
|
var upgrade_default = /* @__PURE__ */ __name((app) => {
|
|
35
36
|
app.command("upgrade").ipc().auth().action(async (options) => {
|
|
37
|
+
await (0, import_create_docs_index.createDocsIndex)(app);
|
|
36
38
|
await app.upgrade(options);
|
|
37
39
|
app.log.info(`\u2728 NocoBase has been upgraded to v${app.getVersion()}`);
|
|
38
40
|
});
|
package/lib/gateway/errors.js
CHANGED
|
@@ -100,7 +100,7 @@ const errors = {
|
|
|
100
100
|
},
|
|
101
101
|
APP_STOPPED: {
|
|
102
102
|
status: 503,
|
|
103
|
-
message: /* @__PURE__ */ __name(({ app }) => `application ${getAppName(app)} is stopped`, "message"),
|
|
103
|
+
message: /* @__PURE__ */ __name(({ app, appName }) => `application ${appName || getAppName(app)} is stopped`, "message"),
|
|
104
104
|
maintaining: true
|
|
105
105
|
},
|
|
106
106
|
APP_INITIALIZED: {
|