@zhin.js/host-http 1.2.0 → 1.2.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.
- package/lib/console-plugin-rpc.d.ts +8 -1
- package/lib/console-plugin-rpc.js +12 -27
- package/lib/console-rpc.d.ts +0 -4
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/package.json +2 -2
- package/src/console-plugin-rpc.ts +13 -27
- package/src/console-rpc.ts +0 -5
- package/src/index.ts +1 -1
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { RuntimeConsoleRpcContext, RuntimeConsoleRpcMessage, RuntimeConsoleRpcReply } from './console-rpc.js';
|
|
2
|
+
/**
|
|
3
|
+
* Refusal of the global plugin switch (`plugin:set-enabled`, `feature.set-enabled` at `global`)
|
|
4
|
+
* by an instance: the switch is a gateway transaction (stop → write `disable_plugins` → start,
|
|
5
|
+
* rollback on failure) and is never written by the instance itself (ADR 0054 §4).
|
|
6
|
+
*/
|
|
7
|
+
export declare const PLUGIN_SWITCH_REQUIRES_GATEWAY = "\u63D2\u4EF6\u5168\u5C40\u542F\u505C\u7531\u7BA1\u7406\u7F51\u5173\u6267\u884C\uFF08\u505C\u6B62\u5B9E\u4F8B \u2192 \u5199\u5165 disable_plugins \u2192 \u542F\u52A8\uFF0C\u5931\u8D25\u56DE\u6EDA\uFF09\uFF1A\u8BF7\u5728 zhin start \u542F\u52A8\u7684 Console \u4E2D\u64CD\u4F5C\uFF0C\u6216\u8FD0\u884C zhin enable / zhin disable <\u63D2\u4EF6>";
|
|
2
8
|
/**
|
|
3
9
|
* Dispatches the plugin-management slice; undefined means the type belongs elsewhere. Package
|
|
4
10
|
* installs / updates / uninstalls are not handled in the instance: they are gateway dependency
|
|
5
|
-
* transactions (`gateway.packages.*`, ADR 0054 §4) that stop the instance first
|
|
11
|
+
* transactions (`gateway.packages.*`, ADR 0054 §4) that stop the instance first, and so is the
|
|
12
|
+
* global plugin switch (`plugin:set-enabled`, refused here).
|
|
6
13
|
*/
|
|
7
14
|
export declare function dispatchPluginConsoleRpc(type: string, message: RuntimeConsoleRpcMessage, ctx: RuntimeConsoleRpcContext): Promise<RuntimeConsoleRpcReply | undefined>;
|
|
@@ -1,39 +1,24 @@
|
|
|
1
1
|
import { PLUGIN_RPC } from '@zhin.js/console-protocol';
|
|
2
|
+
/**
|
|
3
|
+
* Refusal of the global plugin switch (`plugin:set-enabled`, `feature.set-enabled` at `global`)
|
|
4
|
+
* by an instance: the switch is a gateway transaction (stop → write `disable_plugins` → start,
|
|
5
|
+
* rollback on failure) and is never written by the instance itself (ADR 0054 §4).
|
|
6
|
+
*/
|
|
7
|
+
export const PLUGIN_SWITCH_REQUIRES_GATEWAY = '插件全局启停由管理网关执行(停止实例 → 写入 disable_plugins → 启动,失败回滚):请在 zhin start 启动的 Console 中操作,或运行 zhin enable / zhin disable <插件>';
|
|
2
8
|
/**
|
|
3
9
|
* Dispatches the plugin-management slice; undefined means the type belongs elsewhere. Package
|
|
4
10
|
* installs / updates / uninstalls are not handled in the instance: they are gateway dependency
|
|
5
|
-
* transactions (`gateway.packages.*`, ADR 0054 §4) that stop the instance first
|
|
11
|
+
* transactions (`gateway.packages.*`, ADR 0054 §4) that stop the instance first, and so is the
|
|
12
|
+
* global plugin switch (`plugin:set-enabled`, refused here).
|
|
6
13
|
*/
|
|
7
14
|
export async function dispatchPluginConsoleRpc(type, message, ctx) {
|
|
8
15
|
const requestId = message.requestId;
|
|
9
16
|
try {
|
|
10
17
|
switch (type) {
|
|
11
|
-
case PLUGIN_RPC.SET_ENABLED:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return { requestId, error: 'instanceKey and boolean enabled are required' };
|
|
16
|
-
}
|
|
17
|
-
if (!ctx.setPluginEnabled) {
|
|
18
|
-
return { requestId, error: 'Plugin lifecycle management is not configured' };
|
|
19
|
-
}
|
|
20
|
-
const lifecycle = await ctx.setPluginEnabled(instanceKey, enabled);
|
|
21
|
-
ctx.publishEvent?.('plugin:lifecycle-updated', { instanceKey, enabled });
|
|
22
|
-
if (ctx.requestRestart) {
|
|
23
|
-
setTimeout(() => void Promise.resolve(ctx.requestRestart?.()).catch(() => undefined), 500);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
requestId,
|
|
27
|
-
data: {
|
|
28
|
-
success: true,
|
|
29
|
-
instanceKey,
|
|
30
|
-
enabled,
|
|
31
|
-
disabled: lifecycle.disabled,
|
|
32
|
-
restartRequired: true,
|
|
33
|
-
message: `${instanceKey} 已${enabled ? '启用' : '停用'},Host 正在重启`,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
18
|
+
case PLUGIN_RPC.SET_ENABLED:
|
|
19
|
+
// Global plugin on / off is a management gateway transaction (ADR 0054 §4): the gateway
|
|
20
|
+
// answers it before forwarding. Reaching the instance means no gateway is in front.
|
|
21
|
+
return { requestId, error: PLUGIN_SWITCH_REQUIRES_GATEWAY };
|
|
37
22
|
case PLUGIN_RPC.INSPECT:
|
|
38
23
|
case PLUGIN_RPC.APPLY:
|
|
39
24
|
case PLUGIN_RPC.PLAN_VERIFICATION:
|
package/lib/console-rpc.d.ts
CHANGED
|
@@ -166,10 +166,6 @@ export type RuntimeConsoleRpcContext = {
|
|
|
166
166
|
/** Full-scope project read (`config:get-project`); masked unless `reveal`. */
|
|
167
167
|
readProjectConfig?(request: import('@zhin.js/console-protocol').ConsoleConfigProjectReadRequest): Promise<import('@zhin.js/console-protocol').ConsoleConfigProjectRead>;
|
|
168
168
|
applyConfig?(expectedRevision: string): Promise<import('@zhin.js/console-protocol').ConsoleConfigApplyResult>;
|
|
169
|
-
/** Persist a declared child Plugin lifecycle state. Takes effect after restart. */
|
|
170
|
-
setPluginEnabled?(instanceKey: string, enabled: boolean): Promise<Readonly<{
|
|
171
|
-
disabled: readonly string[];
|
|
172
|
-
}>>;
|
|
173
169
|
/** Read-only install planning shared by Console Web and CLI surfaces. */
|
|
174
170
|
pluginManagement?: PluginManagementPort;
|
|
175
171
|
validatePluginConfig?(pluginName: string, data: unknown): Promise<PluginConfigValidation>;
|
package/lib/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { buildOpenApiDocument, patternToOpenApiPath, routeRequiresBearerAuth, ty
|
|
|
11
11
|
export { HttpBodyError, readBodyBytes, readJsonBody, readTextBody, type HttpBodyReadOptions, } from './json-body.js';
|
|
12
12
|
export { createResponseStream, emptyResponse, jsonResponse, SSE_HEADERS, type HttpResponseStream, type HttpResponseStreamOptions, } from '@zhin.js/host-http-contract';
|
|
13
13
|
export { dispatchRuntimeConsoleRpc, pickRpcReply, type RuntimeConsolePage, type RuntimeConsoleRpcContext, type RuntimeConsoleRpcMessage, type RuntimeConsoleRpcReply, type RuntimeEndpointSendInput, type PluginInstallPlan, type PluginUninstallPlan, type PluginUpdatePlan, type PluginManagementPort, type PluginManagementState, type PluginVerificationResult, type PluginVerificationPlan, type PluginConfigValidation, } from './console-rpc.js';
|
|
14
|
-
export { dispatchPluginConsoleRpc } from './console-plugin-rpc.js';
|
|
14
|
+
export { dispatchPluginConsoleRpc, PLUGIN_SWITCH_REQUIRES_GATEWAY } from './console-plugin-rpc.js';
|
|
15
15
|
export { buildProjectFileTree, FILE_MANAGER_ALLOWED, FILE_MANAGER_BLOCKED, isProjectPathAllowed, listEnvFiles, readProjectFile, saveProjectFile, type FileTreeNode, } from './project-files.js';
|
|
16
16
|
export { registerConsoleRestPages, type ConsoleAgentIntrospection, type ConsoleAgentRuntime, type ConsoleAgentSessionTree, type ConsoleRestCtx, type ConsoleRestPagesOptions, } from './console-rest-pages.js';
|
|
17
17
|
export { dispatchExtendedConsoleRpc, type ConsoleRpcExtendedCtx, type ConsoleScheduleEngine, type ConsoleWorkroomProfileControlPort, type ConsoleWorkroomKnowledgeControlPort, type ExtendedRpcResult, } from './console-rpc-extended/index.js';
|
package/lib/index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { buildOpenApiDocument, patternToOpenApiPath, routeRequiresBearerAuth, }
|
|
|
10
10
|
export { HttpBodyError, readBodyBytes, readJsonBody, readTextBody, } from './json-body.js';
|
|
11
11
|
export { createResponseStream, emptyResponse, jsonResponse, SSE_HEADERS, } from '@zhin.js/host-http-contract';
|
|
12
12
|
export { dispatchRuntimeConsoleRpc, pickRpcReply, } from './console-rpc.js';
|
|
13
|
-
export { dispatchPluginConsoleRpc } from './console-plugin-rpc.js';
|
|
13
|
+
export { dispatchPluginConsoleRpc, PLUGIN_SWITCH_REQUIRES_GATEWAY } from './console-plugin-rpc.js';
|
|
14
14
|
export { buildProjectFileTree, FILE_MANAGER_ALLOWED, FILE_MANAGER_BLOCKED, isProjectPathAllowed, listEnvFiles, readProjectFile, saveProjectFile, } from './project-files.js';
|
|
15
15
|
export { registerConsoleRestPages, } from './console-rest-pages.js';
|
|
16
16
|
export { dispatchExtendedConsoleRpc, } from './console-rpc-extended/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/host-http",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Minimal HTTP and WebSocket host for Plugin Runtime (no Koa)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
],
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"ws": "^8.21.1",
|
|
28
|
-
"@zhin.js/console-protocol": "1.2.
|
|
28
|
+
"@zhin.js/console-protocol": "1.2.1",
|
|
29
29
|
"@zhin.js/host-http-contract": "1.2.0",
|
|
30
30
|
"@zhin.js/logger": "1.1.3",
|
|
31
31
|
"@zhin.js/schedule": "1.1.5",
|
|
@@ -5,10 +5,18 @@ import type {
|
|
|
5
5
|
RuntimeConsoleRpcReply,
|
|
6
6
|
} from './console-rpc.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Refusal of the global plugin switch (`plugin:set-enabled`, `feature.set-enabled` at `global`)
|
|
10
|
+
* by an instance: the switch is a gateway transaction (stop → write `disable_plugins` → start,
|
|
11
|
+
* rollback on failure) and is never written by the instance itself (ADR 0054 §4).
|
|
12
|
+
*/
|
|
13
|
+
export const PLUGIN_SWITCH_REQUIRES_GATEWAY = '插件全局启停由管理网关执行(停止实例 → 写入 disable_plugins → 启动,失败回滚):请在 zhin start 启动的 Console 中操作,或运行 zhin enable / zhin disable <插件>';
|
|
14
|
+
|
|
8
15
|
/**
|
|
9
16
|
* Dispatches the plugin-management slice; undefined means the type belongs elsewhere. Package
|
|
10
17
|
* installs / updates / uninstalls are not handled in the instance: they are gateway dependency
|
|
11
|
-
* transactions (`gateway.packages.*`, ADR 0054 §4) that stop the instance first
|
|
18
|
+
* transactions (`gateway.packages.*`, ADR 0054 §4) that stop the instance first, and so is the
|
|
19
|
+
* global plugin switch (`plugin:set-enabled`, refused here).
|
|
12
20
|
*/
|
|
13
21
|
export async function dispatchPluginConsoleRpc(
|
|
14
22
|
type: string,
|
|
@@ -18,32 +26,10 @@ export async function dispatchPluginConsoleRpc(
|
|
|
18
26
|
const requestId = message.requestId as number | string | undefined;
|
|
19
27
|
try {
|
|
20
28
|
switch (type) {
|
|
21
|
-
case PLUGIN_RPC.SET_ENABLED:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return { requestId, error: 'instanceKey and boolean enabled are required' };
|
|
26
|
-
}
|
|
27
|
-
if (!ctx.setPluginEnabled) {
|
|
28
|
-
return { requestId, error: 'Plugin lifecycle management is not configured' };
|
|
29
|
-
}
|
|
30
|
-
const lifecycle = await ctx.setPluginEnabled(instanceKey, enabled);
|
|
31
|
-
ctx.publishEvent?.('plugin:lifecycle-updated', { instanceKey, enabled });
|
|
32
|
-
if (ctx.requestRestart) {
|
|
33
|
-
setTimeout(() => void Promise.resolve(ctx.requestRestart?.()).catch(() => undefined), 500);
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
requestId,
|
|
37
|
-
data: {
|
|
38
|
-
success: true,
|
|
39
|
-
instanceKey,
|
|
40
|
-
enabled,
|
|
41
|
-
disabled: lifecycle.disabled,
|
|
42
|
-
restartRequired: true,
|
|
43
|
-
message: `${instanceKey} 已${enabled ? '启用' : '停用'},Host 正在重启`,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
29
|
+
case PLUGIN_RPC.SET_ENABLED:
|
|
30
|
+
// Global plugin on / off is a management gateway transaction (ADR 0054 §4): the gateway
|
|
31
|
+
// answers it before forwarding. Reaching the instance means no gateway is in front.
|
|
32
|
+
return { requestId, error: PLUGIN_SWITCH_REQUIRES_GATEWAY };
|
|
47
33
|
case PLUGIN_RPC.INSPECT:
|
|
48
34
|
case PLUGIN_RPC.APPLY:
|
|
49
35
|
case PLUGIN_RPC.PLAN_VERIFICATION:
|
package/src/console-rpc.ts
CHANGED
|
@@ -187,11 +187,6 @@ export type RuntimeConsoleRpcContext = {
|
|
|
187
187
|
/** Full-scope project read (`config:get-project`); masked unless `reveal`. */
|
|
188
188
|
readProjectConfig?(request: import('@zhin.js/console-protocol').ConsoleConfigProjectReadRequest): Promise<import('@zhin.js/console-protocol').ConsoleConfigProjectRead>;
|
|
189
189
|
applyConfig?(expectedRevision: string): Promise<import('@zhin.js/console-protocol').ConsoleConfigApplyResult>;
|
|
190
|
-
/** Persist a declared child Plugin lifecycle state. Takes effect after restart. */
|
|
191
|
-
setPluginEnabled?(
|
|
192
|
-
instanceKey: string,
|
|
193
|
-
enabled: boolean,
|
|
194
|
-
): Promise<Readonly<{ disabled: readonly string[] }>>;
|
|
195
190
|
/** Read-only install planning shared by Console Web and CLI surfaces. */
|
|
196
191
|
pluginManagement?: PluginManagementPort;
|
|
197
192
|
validatePluginConfig?(pluginName: string, data: unknown): Promise<PluginConfigValidation>;
|
package/src/index.ts
CHANGED
|
@@ -109,7 +109,7 @@ export {
|
|
|
109
109
|
type PluginVerificationPlan,
|
|
110
110
|
type PluginConfigValidation,
|
|
111
111
|
} from './console-rpc.js';
|
|
112
|
-
export { dispatchPluginConsoleRpc } from './console-plugin-rpc.js';
|
|
112
|
+
export { dispatchPluginConsoleRpc, PLUGIN_SWITCH_REQUIRES_GATEWAY } from './console-plugin-rpc.js';
|
|
113
113
|
export {
|
|
114
114
|
buildProjectFileTree,
|
|
115
115
|
FILE_MANAGER_ALLOWED,
|