@downcity/agent 1.1.7 → 1.1.8
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/bin/agent/AgentContext.d.ts.map +1 -1
- package/bin/agent/AgentContext.js +1 -0
- package/bin/agent/AgentContext.js.map +1 -1
- package/bin/agent/AgentContextTypes.d.ts +5 -1
- package/bin/agent/AgentContextTypes.d.ts.map +1 -1
- package/bin/agent/AgentRuntime.d.ts +6 -1
- package/bin/agent/AgentRuntime.d.ts.map +1 -1
- package/bin/agent/AgentRuntime.js +22 -3
- package/bin/agent/AgentRuntime.js.map +1 -1
- package/bin/agent/AgentRuntimeState.d.ts.map +1 -1
- package/bin/agent/AgentRuntimeState.js +58 -2
- package/bin/agent/AgentRuntimeState.js.map +1 -1
- package/bin/agent/AgentRuntimeTypes.d.ts +5 -1
- package/bin/agent/AgentRuntimeTypes.d.ts.map +1 -1
- package/bin/agent/project/AgentInitializer.d.ts +3 -2
- package/bin/agent/project/AgentInitializer.d.ts.map +1 -1
- package/bin/agent/project/AgentInitializer.js +34 -44
- package/bin/agent/project/AgentInitializer.js.map +1 -1
- package/bin/config/Config.d.ts.map +1 -1
- package/bin/config/Config.js +2 -21
- package/bin/config/Config.js.map +1 -1
- package/bin/config/Paths.d.ts +1 -5
- package/bin/config/Paths.d.ts.map +1 -1
- package/bin/config/Paths.js +2 -8
- package/bin/config/Paths.js.map +1 -1
- package/bin/host/daemon/ProjectSetup.d.ts +2 -1
- package/bin/host/daemon/ProjectSetup.d.ts.map +1 -1
- package/bin/host/daemon/ProjectSetup.js +14 -21
- package/bin/host/daemon/ProjectSetup.js.map +1 -1
- package/bin/host/runtime/AgentHostRuntime.d.ts.map +1 -1
- package/bin/host/runtime/AgentHostRuntime.js +1 -2
- package/bin/host/runtime/AgentHostRuntime.js.map +1 -1
- package/bin/host/runtime/CityPaths.d.ts +0 -3
- package/bin/host/runtime/CityPaths.d.ts.map +1 -1
- package/bin/host/runtime/CityPaths.js +0 -3
- package/bin/host/runtime/CityPaths.js.map +1 -1
- package/bin/host/sdk/Agent.d.ts +1 -0
- package/bin/host/sdk/Agent.d.ts.map +1 -1
- package/bin/host/sdk/Agent.js +24 -2
- package/bin/host/sdk/Agent.js.map +1 -1
- package/bin/host/sdk/AgentSdkTypes.d.ts +9 -0
- package/bin/host/sdk/AgentSdkTypes.d.ts.map +1 -1
- package/bin/http/Server.d.ts.map +1 -1
- package/bin/http/Server.js +1 -11
- package/bin/http/Server.js.map +1 -1
- package/bin/http/auth/AuthEnv.d.ts +0 -9
- package/bin/http/auth/AuthEnv.d.ts.map +1 -1
- package/bin/http/auth/AuthEnv.js +0 -9
- package/bin/http/auth/AuthEnv.js.map +1 -1
- package/bin/http/auth/CliAuthStateStore.d.ts +0 -4
- package/bin/http/auth/CliAuthStateStore.d.ts.map +1 -1
- package/bin/http/auth/CliAuthStateStore.js +0 -4
- package/bin/http/auth/CliAuthStateStore.js.map +1 -1
- package/bin/http/control/ModelRoutes.d.ts.map +1 -1
- package/bin/http/control/ModelRoutes.js +3 -8
- package/bin/http/control/ModelRoutes.js.map +1 -1
- package/bin/index.d.ts +2 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -6
- package/bin/index.js.map +1 -1
- package/bin/model/CreateModel.d.ts +2 -2
- package/bin/model/CreateModel.d.ts.map +1 -1
- package/bin/model/CreateModel.js +13 -12
- package/bin/model/CreateModel.js.map +1 -1
- package/bin/plugin/Activation.d.ts +4 -0
- package/bin/plugin/Activation.d.ts.map +1 -1
- package/bin/plugin/Activation.js +2 -2
- package/bin/plugin/Activation.js.map +1 -1
- package/bin/plugin/LocalExecution.d.ts.map +1 -1
- package/bin/plugin/LocalExecution.js +23 -2
- package/bin/plugin/LocalExecution.js.map +1 -1
- package/bin/plugin/PluginRegistry.js +2 -2
- package/bin/plugin/PluginRegistry.js.map +1 -1
- package/bin/plugins/asr/Plugin.d.ts.map +1 -1
- package/bin/plugins/asr/Plugin.js +4 -5
- package/bin/plugins/asr/Plugin.js.map +1 -1
- package/bin/plugins/auth/Plugin.d.ts.map +1 -1
- package/bin/plugins/auth/Plugin.js +1 -0
- package/bin/plugins/auth/Plugin.js.map +1 -1
- package/bin/plugins/auth/runtime/AuthorizationConfig.d.ts +4 -4
- package/bin/plugins/auth/runtime/AuthorizationConfig.d.ts.map +1 -1
- package/bin/plugins/auth/runtime/AuthorizationConfig.js +28 -26
- package/bin/plugins/auth/runtime/AuthorizationConfig.js.map +1 -1
- package/bin/plugins/auth/runtime/AuthorizationPolicy.d.ts +2 -0
- package/bin/plugins/auth/runtime/AuthorizationPolicy.d.ts.map +1 -1
- package/bin/plugins/auth/runtime/AuthorizationPolicy.js +3 -2
- package/bin/plugins/auth/runtime/AuthorizationPolicy.js.map +1 -1
- package/bin/plugins/auth/runtime/AuthorizationStore.d.ts +1 -1
- package/bin/plugins/auth/runtime/AuthorizationStore.d.ts.map +1 -1
- package/bin/plugins/auth/runtime/AuthorizationStore.js +3 -4
- package/bin/plugins/auth/runtime/AuthorizationStore.js.map +1 -1
- package/bin/plugins/skill/Plugin.js +2 -2
- package/bin/plugins/skill/Plugin.js.map +1 -1
- package/bin/plugins/tts/Plugin.d.ts.map +1 -1
- package/bin/plugins/tts/Plugin.js +4 -5
- package/bin/plugins/tts/Plugin.js.map +1 -1
- package/bin/plugins/web/Plugin.d.ts.map +1 -1
- package/bin/plugins/web/Plugin.js +4 -5
- package/bin/plugins/web/Plugin.js.map +1 -1
- package/bin/plugins/workboard/Plugin.js +2 -2
- package/bin/plugins/workboard/Plugin.js.map +1 -1
- package/bin/service/builtins/chat/accounts/ChannelAccountService.d.ts +4 -1
- package/bin/service/builtins/chat/accounts/ChannelAccountService.d.ts.map +1 -1
- package/bin/service/builtins/chat/accounts/ChannelAccountService.js +64 -91
- package/bin/service/builtins/chat/accounts/ChannelAccountService.js.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelActions.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelActions.js +11 -18
- package/bin/service/builtins/chat/runtime/ChatChannelActions.js.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelCore.d.ts.map +1 -1
- package/bin/service/builtins/chat/runtime/ChatChannelCore.js +9 -17
- package/bin/service/builtins/chat/runtime/ChatChannelCore.js.map +1 -1
- package/bin/service/builtins/memory/Action.d.ts +1 -5
- package/bin/service/builtins/memory/Action.d.ts.map +1 -1
- package/bin/service/builtins/memory/Action.js +4 -42
- package/bin/service/builtins/memory/Action.js.map +1 -1
- package/bin/service/builtins/memory/MemoryService.d.ts.map +1 -1
- package/bin/service/builtins/memory/MemoryService.js +2 -32
- package/bin/service/builtins/memory/MemoryService.js.map +1 -1
- package/bin/service/builtins/memory/runtime/Search.d.ts +7 -3
- package/bin/service/builtins/memory/runtime/Search.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/Search.js +220 -16
- package/bin/service/builtins/memory/runtime/Search.js.map +1 -1
- package/bin/service/builtins/memory/runtime/Store.d.ts +9 -50
- package/bin/service/builtins/memory/runtime/Store.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/Store.js +10 -130
- package/bin/service/builtins/memory/runtime/Store.js.map +1 -1
- package/bin/service/builtins/memory/runtime/Writer.d.ts.map +1 -1
- package/bin/service/builtins/memory/runtime/Writer.js +1 -2
- package/bin/service/builtins/memory/runtime/Writer.js.map +1 -1
- package/bin/service/builtins/memory/types/Memory.d.ts +3 -57
- package/bin/service/builtins/memory/types/Memory.d.ts.map +1 -1
- package/bin/service/schedule/Store.d.ts +22 -25
- package/bin/service/schedule/Store.d.ts.map +1 -1
- package/bin/service/schedule/Store.js +172 -154
- package/bin/service/schedule/Store.js.map +1 -1
- package/bin/session/composer/system/default/SystemDomain.d.ts.map +1 -1
- package/bin/session/composer/system/default/SystemDomain.js +1 -0
- package/bin/session/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/shared/types/AgentHost.d.ts +120 -4
- package/bin/shared/types/AgentHost.d.ts.map +1 -1
- package/bin/shared/types/Plugin.d.ts +5 -1
- package/bin/shared/types/Plugin.d.ts.map +1 -1
- package/package.json +1 -4
- package/src/agent/AgentContext.ts +1 -0
- package/src/agent/AgentContextTypes.ts +5 -0
- package/src/agent/AgentRuntime.ts +32 -3
- package/src/agent/AgentRuntimeState.ts +66 -2
- package/src/agent/AgentRuntimeTypes.ts +5 -0
- package/src/agent/project/AgentInitializer.ts +40 -42
- package/src/config/Config.ts +2 -17
- package/src/config/Paths.ts +2 -9
- package/src/host/daemon/ProjectSetup.ts +19 -21
- package/src/host/runtime/AgentHostRuntime.ts +0 -2
- package/src/host/runtime/CityPaths.ts +0 -3
- package/src/host/sdk/Agent.ts +26 -2
- package/src/host/sdk/AgentSdkTypes.ts +10 -0
- package/src/http/Server.ts +0 -13
- package/src/http/auth/AuthEnv.ts +0 -9
- package/src/http/auth/CliAuthStateStore.ts +0 -4
- package/src/http/control/ModelRoutes.ts +3 -9
- package/src/index.ts +2 -12
- package/src/model/CreateModel.ts +15 -13
- package/src/plugin/Activation.ts +6 -2
- package/src/plugin/LocalExecution.ts +24 -2
- package/src/plugin/PluginRegistry.ts +2 -2
- package/src/plugins/asr/Plugin.ts +4 -5
- package/src/plugins/auth/Plugin.ts +1 -0
- package/src/plugins/auth/runtime/AuthorizationConfig.ts +47 -37
- package/src/plugins/auth/runtime/AuthorizationPolicy.ts +5 -2
- package/src/plugins/auth/runtime/AuthorizationStore.ts +6 -5
- package/src/plugins/skill/Plugin.ts +2 -2
- package/src/plugins/tts/Plugin.ts +4 -5
- package/src/plugins/web/Plugin.ts +4 -5
- package/src/plugins/workboard/Plugin.ts +2 -2
- package/src/service/builtins/chat/accounts/ChannelAccountService.ts +42 -62
- package/src/service/builtins/chat/runtime/ChatChannelActions.ts +12 -18
- package/src/service/builtins/chat/runtime/ChatChannelCore.ts +9 -14
- package/src/service/builtins/memory/Action.ts +6 -47
- package/src/service/builtins/memory/MemoryService.ts +1 -33
- package/src/service/builtins/memory/runtime/Search.ts +256 -16
- package/src/service/builtins/memory/runtime/Store.ts +13 -185
- package/src/service/builtins/memory/runtime/Writer.ts +1 -2
- package/src/service/builtins/memory/types/Memory.ts +2 -59
- package/src/service/schedule/Store.ts +215 -175
- package/src/session/composer/system/default/SystemDomain.ts +1 -0
- package/src/shared/types/AgentHost.ts +138 -4
- package/src/shared/types/Plugin.ts +5 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/http/auth/AuthMiddleware.d.ts +0 -36
- package/bin/http/auth/AuthMiddleware.d.ts.map +0 -1
- package/bin/http/auth/AuthMiddleware.js +0 -37
- package/bin/http/auth/AuthMiddleware.js.map +0 -1
- package/bin/http/auth/AuthRoutes.d.ts +0 -17
- package/bin/http/auth/AuthRoutes.d.ts.map +0 -1
- package/bin/http/auth/AuthRoutes.js +0 -78
- package/bin/http/auth/AuthRoutes.js.map +0 -1
- package/bin/http/auth/AuthService.d.ts +0 -119
- package/bin/http/auth/AuthService.d.ts.map +0 -1
- package/bin/http/auth/AuthService.js +0 -307
- package/bin/http/auth/AuthService.js.map +0 -1
- package/bin/http/auth/AuthStore.d.ts +0 -165
- package/bin/http/auth/AuthStore.d.ts.map +0 -1
- package/bin/http/auth/AuthStore.js +0 -442
- package/bin/http/auth/AuthStore.js.map +0 -1
- package/bin/http/auth/RoutePolicy.d.ts +0 -30
- package/bin/http/auth/RoutePolicy.d.ts.map +0 -1
- package/bin/http/auth/RoutePolicy.js +0 -229
- package/bin/http/auth/RoutePolicy.js.map +0 -1
- package/bin/plugin/Lifecycle.d.ts +0 -33
- package/bin/plugin/Lifecycle.d.ts.map +0 -1
- package/bin/plugin/Lifecycle.js +0 -102
- package/bin/plugin/Lifecycle.js.map +0 -1
- package/bin/service/builtins/memory/runtime/Indexer.d.ts +0 -71
- package/bin/service/builtins/memory/runtime/Indexer.d.ts.map +0 -1
- package/bin/service/builtins/memory/runtime/Indexer.js +0 -345
- package/bin/service/builtins/memory/runtime/Indexer.js.map +0 -1
- package/bin/service/schedule/Schema.d.ts +0 -171
- package/bin/service/schedule/Schema.d.ts.map +0 -1
- package/bin/service/schedule/Schema.js +0 -26
- package/bin/service/schedule/Schema.js.map +0 -1
- package/bin/shared/utils/store/StoreChannelAccountRepository.d.ts +0 -34
- package/bin/shared/utils/store/StoreChannelAccountRepository.d.ts.map +0 -1
- package/bin/shared/utils/store/StoreChannelAccountRepository.js +0 -198
- package/bin/shared/utils/store/StoreChannelAccountRepository.js.map +0 -1
- package/bin/shared/utils/store/StoreEnvRepository.d.ts +0 -98
- package/bin/shared/utils/store/StoreEnvRepository.d.ts.map +0 -1
- package/bin/shared/utils/store/StoreEnvRepository.js +0 -334
- package/bin/shared/utils/store/StoreEnvRepository.js.map +0 -1
- package/bin/shared/utils/store/StoreModelRepository.d.ts +0 -61
- package/bin/shared/utils/store/StoreModelRepository.d.ts.map +0 -1
- package/bin/shared/utils/store/StoreModelRepository.js +0 -278
- package/bin/shared/utils/store/StoreModelRepository.js.map +0 -1
- package/bin/shared/utils/store/StoreSchema.d.ts +0 -13
- package/bin/shared/utils/store/StoreSchema.d.ts.map +0 -1
- package/bin/shared/utils/store/StoreSchema.js +0 -319
- package/bin/shared/utils/store/StoreSchema.js.map +0 -1
- package/bin/shared/utils/store/StoreSecureSettings.d.ts +0 -33
- package/bin/shared/utils/store/StoreSecureSettings.d.ts.map +0 -1
- package/bin/shared/utils/store/StoreSecureSettings.js +0 -91
- package/bin/shared/utils/store/StoreSecureSettings.js.map +0 -1
- package/bin/shared/utils/store/StoreShared.d.ts +0 -44
- package/bin/shared/utils/store/StoreShared.d.ts.map +0 -1
- package/bin/shared/utils/store/StoreShared.js +0 -40
- package/bin/shared/utils/store/StoreShared.js.map +0 -1
- package/bin/shared/utils/store/crypto.d.ts +0 -24
- package/bin/shared/utils/store/crypto.d.ts.map +0 -1
- package/bin/shared/utils/store/crypto.js +0 -101
- package/bin/shared/utils/store/crypto.js.map +0 -1
- package/bin/shared/utils/store/index.d.ts +0 -230
- package/bin/shared/utils/store/index.d.ts.map +0 -1
- package/bin/shared/utils/store/index.js +0 -360
- package/bin/shared/utils/store/index.js.map +0 -1
- package/bin/shared/utils/store/schema.d.ts +0 -690
- package/bin/shared/utils/store/schema.d.ts.map +0 -1
- package/bin/shared/utils/store/schema.js +0 -81
- package/bin/shared/utils/store/schema.js.map +0 -1
- package/src/http/auth/AuthMiddleware.ts +0 -61
- package/src/http/auth/AuthRoutes.ts +0 -100
- package/src/http/auth/AuthService.ts +0 -367
- package/src/http/auth/AuthStore.ts +0 -572
- package/src/http/auth/RoutePolicy.ts +0 -255
- package/src/plugin/Lifecycle.ts +0 -116
- package/src/service/builtins/memory/runtime/Indexer.ts +0 -466
- package/src/service/schedule/Schema.ts +0 -34
- package/src/shared/utils/store/StoreChannelAccountRepository.ts +0 -269
- package/src/shared/utils/store/StoreEnvRepository.ts +0 -452
- package/src/shared/utils/store/StoreModelRepository.ts +0 -324
- package/src/shared/utils/store/StoreSchema.ts +0 -344
- package/src/shared/utils/store/StoreSecureSettings.ts +0 -126
- package/src/shared/utils/store/StoreShared.ts +0 -67
- package/src/shared/utils/store/crypto.ts +0 -112
- package/src/shared/utils/store/index.ts +0 -497
- package/src/shared/utils/store/schema.ts +0 -103
|
@@ -1,255 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 统一账户路由策略与全局守卫。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 这里负责把“哪些接口需要登录、需要什么权限”集中配置。
|
|
6
|
-
* - 当系统还没有任何统一账户用户时,受保护接口默认放行,避免首次 bootstrap 被锁死。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { MiddlewareHandler } from "hono";
|
|
10
|
-
import type { AuthRoutePolicy } from "@/shared/types/auth/AuthRoute.js";
|
|
11
|
-
import type { AuthPermissionKey } from "@/shared/types/auth/AuthPermission.js";
|
|
12
|
-
import { isAuthError as isAuthDomainError } from "./AuthError.js";
|
|
13
|
-
import type { AuthService } from "./AuthService.js";
|
|
14
|
-
import { AUTH_PRINCIPAL_CONTEXT_KEY, type AuthMiddlewareVariables } from "./AuthMiddleware.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Server 侧路由权限矩阵。
|
|
18
|
-
*/
|
|
19
|
-
export const SERVER_AUTH_ROUTE_POLICIES: AuthRoutePolicy[] = [
|
|
20
|
-
{ path: "/api/auth/*", method: "*", requireAuth: false },
|
|
21
|
-
{ path: "/health", method: "GET", requireAuth: false },
|
|
22
|
-
{
|
|
23
|
-
path: "/api/execute",
|
|
24
|
-
method: "POST",
|
|
25
|
-
requireAuth: true,
|
|
26
|
-
anyPermissions: ["agent.execute"],
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
path: "/api/services/list",
|
|
30
|
-
method: "GET",
|
|
31
|
-
requireAuth: true,
|
|
32
|
-
anyPermissions: ["service.read"],
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
path: "/api/services/control",
|
|
36
|
-
method: "POST",
|
|
37
|
-
requireAuth: true,
|
|
38
|
-
anyPermissions: ["service.write"],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
path: "/api/services/command",
|
|
42
|
-
method: "POST",
|
|
43
|
-
requireAuth: true,
|
|
44
|
-
anyPermissions: ["service.write"],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
path: "/api/plugins/list",
|
|
48
|
-
method: "GET",
|
|
49
|
-
requireAuth: true,
|
|
50
|
-
anyPermissions: ["plugin.read"],
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
path: "/api/plugins/availability",
|
|
54
|
-
method: "POST",
|
|
55
|
-
requireAuth: true,
|
|
56
|
-
anyPermissions: ["plugin.read"],
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
path: "/api/plugins/action",
|
|
60
|
-
method: "POST",
|
|
61
|
-
requireAuth: true,
|
|
62
|
-
anyPermissions: ["plugin.write"],
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
path: "/api/control/authorization",
|
|
66
|
-
method: "GET",
|
|
67
|
-
requireAuth: true,
|
|
68
|
-
anyPermissions: ["auth.read"],
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
path: "/api/control/authorization/config",
|
|
72
|
-
method: "POST",
|
|
73
|
-
requireAuth: true,
|
|
74
|
-
anyPermissions: ["auth.write"],
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
path: "/api/control/authorization/action",
|
|
78
|
-
method: "POST",
|
|
79
|
-
requireAuth: true,
|
|
80
|
-
anyPermissions: ["auth.write"],
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
path: "/api/control/*",
|
|
84
|
-
method: "*",
|
|
85
|
-
requireAuth: true,
|
|
86
|
-
},
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 控制面网关侧路由权限矩阵。
|
|
91
|
-
*/
|
|
92
|
-
export const CONTROL_PLANE_AUTH_ROUTE_POLICIES: AuthRoutePolicy[] = [
|
|
93
|
-
{ path: "/api/auth/*", method: "*", requireAuth: false },
|
|
94
|
-
{ path: "/health", method: "GET", requireAuth: false },
|
|
95
|
-
{
|
|
96
|
-
path: "/api/ui/agents",
|
|
97
|
-
method: "GET",
|
|
98
|
-
requireAuth: true,
|
|
99
|
-
anyPermissions: ["agent.read"],
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
path: "/api/ui/agents/create",
|
|
103
|
-
method: "POST",
|
|
104
|
-
requireAuth: true,
|
|
105
|
-
anyPermissions: ["agent.write"],
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
path: "/api/ui/agents/start",
|
|
109
|
-
method: "POST",
|
|
110
|
-
requireAuth: true,
|
|
111
|
-
anyPermissions: ["agent.write"],
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
path: "/api/ui/agents/restart",
|
|
115
|
-
method: "POST",
|
|
116
|
-
requireAuth: true,
|
|
117
|
-
anyPermissions: ["agent.write"],
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
path: "/api/ui/agents/stop",
|
|
121
|
-
method: "POST",
|
|
122
|
-
requireAuth: true,
|
|
123
|
-
anyPermissions: ["agent.write"],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
path: "/api/ui/model*",
|
|
127
|
-
method: "*",
|
|
128
|
-
requireAuth: true,
|
|
129
|
-
anyPermissions: ["model.read"],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
path: "/api/ui/env*",
|
|
133
|
-
method: "*",
|
|
134
|
-
requireAuth: true,
|
|
135
|
-
anyPermissions: ["env.read"],
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
path: "/api/ui/channel*",
|
|
139
|
-
method: "*",
|
|
140
|
-
requireAuth: true,
|
|
141
|
-
anyPermissions: ["channel.read"],
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
path: "/api/ui/plugins*",
|
|
145
|
-
method: "*",
|
|
146
|
-
requireAuth: true,
|
|
147
|
-
anyPermissions: ["plugin.read"],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
path: "/api/ui/*",
|
|
151
|
-
method: "*",
|
|
152
|
-
requireAuth: true,
|
|
153
|
-
},
|
|
154
|
-
];
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 根据路径与方法解析匹配的策略。
|
|
158
|
-
*/
|
|
159
|
-
export function resolveAuthRoutePolicy(
|
|
160
|
-
path: string,
|
|
161
|
-
method: string,
|
|
162
|
-
policies: AuthRoutePolicy[],
|
|
163
|
-
): AuthRoutePolicy | null {
|
|
164
|
-
const normalizedPath = String(path || "").trim() || "/";
|
|
165
|
-
const normalizedMethod = String(method || "GET").trim().toUpperCase();
|
|
166
|
-
for (const policy of policies) {
|
|
167
|
-
if (!matchesMethod(policy.method, normalizedMethod)) continue;
|
|
168
|
-
if (!matchesPath(policy.path, normalizedPath)) continue;
|
|
169
|
-
return policy;
|
|
170
|
-
}
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* 创建全局路由鉴权中间件。
|
|
176
|
-
*/
|
|
177
|
-
export function createRouteAuthGuardMiddleware(
|
|
178
|
-
authService: AuthService,
|
|
179
|
-
policies: AuthRoutePolicy[] = SERVER_AUTH_ROUTE_POLICIES,
|
|
180
|
-
): MiddlewareHandler<{ Variables: AuthMiddlewareVariables }> {
|
|
181
|
-
return async (c, next) => {
|
|
182
|
-
const policy = resolveAuthRoutePolicy(c.req.path, c.req.method, policies);
|
|
183
|
-
if (!policy || policy.requireAuth !== true) {
|
|
184
|
-
await next();
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (!authService.hasLocalCliAccess()) {
|
|
188
|
-
await next();
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
const principal = authService.authenticateBearerHeader(
|
|
193
|
-
c.req.header("authorization"),
|
|
194
|
-
);
|
|
195
|
-
ensurePermissions(principal.permissions, policy.anyPermissions);
|
|
196
|
-
c.set(AUTH_PRINCIPAL_CONTEXT_KEY, principal);
|
|
197
|
-
await next();
|
|
198
|
-
} catch (error) {
|
|
199
|
-
if (isRouteGuardError(error)) {
|
|
200
|
-
return c.json(
|
|
201
|
-
{ success: false, error: error.message },
|
|
202
|
-
error.status as 200,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
return c.json({ success: false, error: String(error) }, 500);
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function matchesMethod(expectedMethod: string, actualMethod: string): boolean {
|
|
211
|
-
const expected = String(expectedMethod || "*").trim().toUpperCase();
|
|
212
|
-
return expected === "*" || expected === actualMethod;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function matchesPath(patternInput: string, actualPath: string): boolean {
|
|
216
|
-
const pattern = String(patternInput || "").trim();
|
|
217
|
-
if (!pattern) return false;
|
|
218
|
-
if (pattern.endsWith("*")) {
|
|
219
|
-
const prefix = pattern.slice(0, -1);
|
|
220
|
-
return actualPath.startsWith(prefix);
|
|
221
|
-
}
|
|
222
|
-
return actualPath === pattern;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function ensurePermissions(
|
|
226
|
-
userPermissions: AuthPermissionKey[],
|
|
227
|
-
anyPermissions: AuthRoutePolicy["anyPermissions"],
|
|
228
|
-
): void {
|
|
229
|
-
if (!anyPermissions || anyPermissions.length === 0) return;
|
|
230
|
-
if (anyPermissions.some((permission) => userPermissions.includes(permission))) return;
|
|
231
|
-
throw new ErrorWithStatus("Permission denied", 403);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
class ErrorWithStatus extends Error {
|
|
235
|
-
readonly status: number;
|
|
236
|
-
|
|
237
|
-
constructor(message: string, status: number) {
|
|
238
|
-
super(message);
|
|
239
|
-
this.name = "AuthPermissionError";
|
|
240
|
-
this.status = status;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function isAuthErrorLike(error: unknown): error is { message: string; status: number } {
|
|
245
|
-
return (
|
|
246
|
-
typeof error === "object" &&
|
|
247
|
-
error !== null &&
|
|
248
|
-
"status" in error &&
|
|
249
|
-
typeof (error as { status?: unknown }).status === "number"
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function isRouteGuardError(error: unknown): error is { message: string; status: number } {
|
|
254
|
-
return isAuthDomainError(error) || isAuthErrorLike(error);
|
|
255
|
-
}
|
package/src/plugin/Lifecycle.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin 生命周期配置模块。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - Plugin enable/disable 属于 city 级全局配置,不再写入 agent `downcity.json`。
|
|
6
|
-
* - 当前实现把 lifecycle 配置存入 PlatformStore 的统一 JSON 设置。
|
|
7
|
-
* - 默认策略:除显式关闭外,内建 plugin 视为启用。
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { PlatformStore } from "@/shared/utils/store/index.js";
|
|
11
|
-
import type {
|
|
12
|
-
CityPluginLifecycleConfig,
|
|
13
|
-
CityPluginLifecycleItem,
|
|
14
|
-
} from "@/shared/types/PluginLifecycle.js";
|
|
15
|
-
|
|
16
|
-
const PLUGIN_LIFECYCLE_SETTING_KEY = "plugins.lifecycle";
|
|
17
|
-
|
|
18
|
-
function normalizeLifecycleItem(input: unknown): CityPluginLifecycleItem | null {
|
|
19
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) return null;
|
|
20
|
-
const record = input as Record<string, unknown>;
|
|
21
|
-
if (typeof record.enabled !== "boolean") return null;
|
|
22
|
-
const updatedAt = String(record.updatedAt || "").trim() || new Date().toISOString();
|
|
23
|
-
return {
|
|
24
|
-
enabled: record.enabled,
|
|
25
|
-
updatedAt,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function normalizeLifecycleConfig(input: unknown): CityPluginLifecycleConfig {
|
|
30
|
-
if (!input || typeof input !== "object" || Array.isArray(input)) return {};
|
|
31
|
-
const out: CityPluginLifecycleConfig = {};
|
|
32
|
-
for (const [pluginName, raw] of Object.entries(input as Record<string, unknown>)) {
|
|
33
|
-
const key = String(pluginName || "").trim();
|
|
34
|
-
if (!key) continue;
|
|
35
|
-
const item = normalizeLifecycleItem(raw);
|
|
36
|
-
if (!item) continue;
|
|
37
|
-
out[key] = item;
|
|
38
|
-
}
|
|
39
|
-
return out;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 读取当前 city 级 plugin lifecycle 配置。
|
|
44
|
-
*/
|
|
45
|
-
export function readCityPluginLifecycleConfig(): CityPluginLifecycleConfig {
|
|
46
|
-
const store = new PlatformStore();
|
|
47
|
-
try {
|
|
48
|
-
return normalizeLifecycleConfig(
|
|
49
|
-
store.getSecureSettingJsonSync<CityPluginLifecycleConfig>(
|
|
50
|
-
PLUGIN_LIFECYCLE_SETTING_KEY,
|
|
51
|
-
),
|
|
52
|
-
);
|
|
53
|
-
} finally {
|
|
54
|
-
store.close();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 写入完整 city 级 plugin lifecycle 配置。
|
|
60
|
-
*/
|
|
61
|
-
export function writeCityPluginLifecycleConfig(
|
|
62
|
-
value: CityPluginLifecycleConfig,
|
|
63
|
-
): CityPluginLifecycleConfig {
|
|
64
|
-
const normalized = normalizeLifecycleConfig(value);
|
|
65
|
-
const store = new PlatformStore();
|
|
66
|
-
try {
|
|
67
|
-
store.setSecureSettingJsonSync(PLUGIN_LIFECYCLE_SETTING_KEY, normalized);
|
|
68
|
-
return normalized;
|
|
69
|
-
} finally {
|
|
70
|
-
store.close();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 读取单个 plugin 的 city 级 lifecycle 状态。
|
|
76
|
-
*/
|
|
77
|
-
export function readCityPluginLifecycleItem(
|
|
78
|
-
pluginName: string,
|
|
79
|
-
): CityPluginLifecycleItem | null {
|
|
80
|
-
const key = String(pluginName || "").trim();
|
|
81
|
-
if (!key) return null;
|
|
82
|
-
return readCityPluginLifecycleConfig()[key] || null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* 读取单个 plugin 是否启用。
|
|
87
|
-
*
|
|
88
|
-
* 关键点(中文)
|
|
89
|
-
* - 除显式关闭外,一律默认启用。
|
|
90
|
-
*/
|
|
91
|
-
export function isCityPluginEnabled(pluginName: string): boolean {
|
|
92
|
-
const item = readCityPluginLifecycleItem(pluginName);
|
|
93
|
-
if (!item) return true;
|
|
94
|
-
return item.enabled === true;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* 设置单个 plugin 的 city 级启用态。
|
|
99
|
-
*/
|
|
100
|
-
export function setCityPluginEnabled(
|
|
101
|
-
pluginName: string,
|
|
102
|
-
enabled: boolean,
|
|
103
|
-
): CityPluginLifecycleConfig {
|
|
104
|
-
const key = String(pluginName || "").trim();
|
|
105
|
-
if (!key) {
|
|
106
|
-
throw new Error("pluginName is required");
|
|
107
|
-
}
|
|
108
|
-
const current = readCityPluginLifecycleConfig();
|
|
109
|
-
return writeCityPluginLifecycleConfig({
|
|
110
|
-
...current,
|
|
111
|
-
[key]: {
|
|
112
|
-
enabled,
|
|
113
|
-
updatedAt: new Date().toISOString(),
|
|
114
|
-
},
|
|
115
|
-
});
|
|
116
|
-
}
|