@downcity/agent 1.1.6 → 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 +4 -0
- package/bin/host/sdk/Agent.d.ts.map +1 -1
- package/bin/host/sdk/Agent.js +71 -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/host/sdk/SdkSessionSystemComposer.d.ts +11 -2
- package/bin/host/sdk/SdkSessionSystemComposer.d.ts.map +1 -1
- package/bin/host/sdk/SdkSessionSystemComposer.js +19 -2
- package/bin/host/sdk/SdkSessionSystemComposer.js.map +1 -1
- package/bin/host/sdk/Session.d.ts +10 -0
- package/bin/host/sdk/Session.d.ts.map +1 -1
- package/bin/host/sdk/Session.js +8 -0
- package/bin/host/sdk/Session.js.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 +67 -2
- package/src/host/sdk/AgentSdkTypes.ts +10 -0
- package/src/host/sdk/SdkSessionSystemComposer.ts +39 -2
- package/src/host/sdk/Session.ts +18 -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
package/src/host/sdk/Agent.ts
CHANGED
|
@@ -16,6 +16,7 @@ import type { AgentContext } from "@/agent/AgentContextTypes.js";
|
|
|
16
16
|
import type { AgentRuntime } from "@/agent/AgentRuntimeTypes.js";
|
|
17
17
|
import type { DowncityConfig } from "@/shared/types/DowncityConfig.js";
|
|
18
18
|
import type { JsonValue } from "@/shared/types/Json.js";
|
|
19
|
+
import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
|
|
19
20
|
import type {
|
|
20
21
|
Plugin,
|
|
21
22
|
PluginAvailability,
|
|
@@ -43,6 +44,25 @@ import { HookRegistry } from "@/plugin/HookRegistry.js";
|
|
|
43
44
|
import { PluginRegistry } from "@/plugin/PluginRegistry.js";
|
|
44
45
|
import { isPluginEnabled } from "@/plugin/Activation.js";
|
|
45
46
|
|
|
47
|
+
const EMPTY_SDK_PLATFORM: AgentPlatformRuntime = {
|
|
48
|
+
getGlobalEnv: () => ({}),
|
|
49
|
+
getAgentEnv: () => ({}),
|
|
50
|
+
listModels: () => [],
|
|
51
|
+
listProviders: async () => [],
|
|
52
|
+
getModel: () => null,
|
|
53
|
+
getChannelAccount: () => null,
|
|
54
|
+
readChatAuthorizationConfig: () => ({
|
|
55
|
+
roles: {},
|
|
56
|
+
channels: {},
|
|
57
|
+
}),
|
|
58
|
+
writeChatAuthorizationConfig: async (_projectRoot, nextConfig) => nextConfig,
|
|
59
|
+
setChatAuthorizationUserRole: async () => ({
|
|
60
|
+
roles: {},
|
|
61
|
+
channels: {},
|
|
62
|
+
}),
|
|
63
|
+
isPluginEnabled: (pluginName) => pluginName === "auth",
|
|
64
|
+
};
|
|
65
|
+
|
|
46
66
|
function createFallbackSdkConfig(agentId: string): DowncityConfig {
|
|
47
67
|
return {
|
|
48
68
|
name: agentId,
|
|
@@ -67,7 +87,9 @@ export class Agent {
|
|
|
67
87
|
private readonly runtime: AgentRuntime;
|
|
68
88
|
private readonly serviceContext: AgentContext;
|
|
69
89
|
private readonly pluginRegistry: PluginRegistry;
|
|
90
|
+
private readonly pluginSystemProviders: Plugin[];
|
|
70
91
|
private readonly config: DowncityConfig;
|
|
92
|
+
private readonly platform: AgentPlatformRuntime;
|
|
71
93
|
private systems: string[];
|
|
72
94
|
private servicesStartPromise: Promise<void> | null = null;
|
|
73
95
|
|
|
@@ -86,6 +108,7 @@ export class Agent {
|
|
|
86
108
|
|
|
87
109
|
this.logger = new Logger();
|
|
88
110
|
this.logger.bindProjectRoot(this.path);
|
|
111
|
+
this.platform = options.platform || EMPTY_SDK_PLATFORM;
|
|
89
112
|
this.systems = loadStaticSystemPrompts(this.path);
|
|
90
113
|
this.config = this.loadConfig();
|
|
91
114
|
this.services = this.createServiceMap(options.services || []);
|
|
@@ -93,7 +116,10 @@ export class Agent {
|
|
|
93
116
|
for (const service of this.services.values()) {
|
|
94
117
|
service.bindAgent(this.runtime);
|
|
95
118
|
}
|
|
96
|
-
this.
|
|
119
|
+
this.pluginSystemProviders = Array.isArray(options.plugins)
|
|
120
|
+
? [...options.plugins]
|
|
121
|
+
: [];
|
|
122
|
+
this.pluginRegistry = this.createPluginRegistry(this.pluginSystemProviders);
|
|
97
123
|
this.plugins = this.createPluginPort();
|
|
98
124
|
this.serviceContext = this.createServiceContext();
|
|
99
125
|
this.http = new SdkAgentHttpServer(this);
|
|
@@ -189,7 +215,7 @@ export class Agent {
|
|
|
189
215
|
contextResolver: () => this.serviceContext,
|
|
190
216
|
pluginEnabledChecker: (pluginName) => {
|
|
191
217
|
const plugin = pluginRegistryRef?.get(pluginName);
|
|
192
|
-
return plugin ? isPluginEnabled({ plugin }) : false;
|
|
218
|
+
return plugin ? isPluginEnabled({ plugin, context: this.serviceContext }) : false;
|
|
193
219
|
},
|
|
194
220
|
});
|
|
195
221
|
const registry = new PluginRegistry({
|
|
@@ -226,6 +252,41 @@ export class Agent {
|
|
|
226
252
|
};
|
|
227
253
|
}
|
|
228
254
|
|
|
255
|
+
private async loadPluginSystemPrompts(): Promise<string[]> {
|
|
256
|
+
const out: string[] = [];
|
|
257
|
+
for (const plugin of this.pluginSystemProviders) {
|
|
258
|
+
if (typeof plugin.system !== "function") continue;
|
|
259
|
+
try {
|
|
260
|
+
if (!isPluginEnabled({ plugin, context: this.serviceContext })) continue;
|
|
261
|
+
if (typeof plugin.availability === "function") {
|
|
262
|
+
const availability = await plugin.availability(this.serviceContext);
|
|
263
|
+
if (!availability.available) continue;
|
|
264
|
+
}
|
|
265
|
+
const text = String(await plugin.system(this.serviceContext)).trim();
|
|
266
|
+
if (!text) continue;
|
|
267
|
+
out.push(text);
|
|
268
|
+
} catch {
|
|
269
|
+
// 单个 plugin system 失败不应阻断 SDK session 主链路。
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return out;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
private async loadServiceSystemPrompts(): Promise<string[]> {
|
|
276
|
+
const out: string[] = [];
|
|
277
|
+
for (const service of this.services.values()) {
|
|
278
|
+
if (typeof service.system !== "function") continue;
|
|
279
|
+
try {
|
|
280
|
+
const text = String(await service.system(this.serviceContext)).trim();
|
|
281
|
+
if (!text) continue;
|
|
282
|
+
out.push(text);
|
|
283
|
+
} catch {
|
|
284
|
+
// 单个 service system 失败不应阻断 SDK session 主链路。
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
|
|
229
290
|
private createRuntime(): AgentRuntime {
|
|
230
291
|
const runtime = {
|
|
231
292
|
cwd: this.path,
|
|
@@ -237,6 +298,7 @@ export class Agent {
|
|
|
237
298
|
systems: this.systems,
|
|
238
299
|
paths: createAgentPathRuntime(this.path),
|
|
239
300
|
pluginConfig: createAgentPluginConfigRuntime(this.path),
|
|
301
|
+
platform: this.platform,
|
|
240
302
|
model: undefined,
|
|
241
303
|
getSession: (sessionId: string) => {
|
|
242
304
|
return this.getOrCreateSession(sessionId).getServicePort() as never;
|
|
@@ -267,6 +329,7 @@ export class Agent {
|
|
|
267
329
|
systems: this.systems,
|
|
268
330
|
paths: this.runtime.paths,
|
|
269
331
|
pluginConfig: this.runtime.pluginConfig,
|
|
332
|
+
platform: this.platform,
|
|
270
333
|
session: {
|
|
271
334
|
get: (sessionId) => this.getOrCreateSession(sessionId).getServicePort(),
|
|
272
335
|
listExecutingSessionIds: () => this.runtime.listExecutingSessionIds(),
|
|
@@ -347,6 +410,8 @@ export class Agent {
|
|
|
347
410
|
tools: this.tools,
|
|
348
411
|
logger: this.logger,
|
|
349
412
|
getStaticSystemPrompts: () => this.systems,
|
|
413
|
+
getServiceSystemPrompts: () => this.loadServiceSystemPrompts(),
|
|
414
|
+
getPluginSystemPrompts: () => this.loadPluginSystemPrompts(),
|
|
350
415
|
});
|
|
351
416
|
this.sessionsById.set(resolvedSessionId, created);
|
|
352
417
|
return created;
|
|
@@ -12,6 +12,7 @@ import type { BaseService } from "@/service/builtins/BaseService.js";
|
|
|
12
12
|
import type { JsonValue } from "@/shared/types/Json.js";
|
|
13
13
|
import type { Plugin } from "@/shared/types/Plugin.js";
|
|
14
14
|
import type { SessionMessageV1 } from "@/types/session/SessionMessages.js";
|
|
15
|
+
import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* 本地 Agent 构造参数。
|
|
@@ -59,6 +60,15 @@ export interface AgentOptions {
|
|
|
59
60
|
* - 同名 plugin 会直接报错,避免 action / hook / resolve 行为被静默覆盖。
|
|
60
61
|
*/
|
|
61
62
|
plugins?: Plugin[];
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 当前 agent 显式注入的平台能力集合。
|
|
66
|
+
*
|
|
67
|
+
* 关键点(中文)
|
|
68
|
+
* - SDK 侧若不提供,则使用最小空实现。
|
|
69
|
+
* - 推荐由宿主产品显式传入,避免 SDK 本地实例隐式依赖 city。
|
|
70
|
+
*/
|
|
71
|
+
platform?: AgentPlatformRuntime;
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
/**
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 面向 `Agent` SDK 的本地会话执行场景。
|
|
6
|
-
* -
|
|
7
|
-
* - 暂不把 service/plugin system 注入暴露到 SDK 主路径。
|
|
6
|
+
* - 注入静态 PROFILE / SOUL / core prompt、显式注入 service system、显式注册 plugin system 与运行时时钟上下文。
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
9
|
import { SessionSystemComposer } from "@session/composer/system/SessionSystemComposer.js";
|
|
@@ -22,6 +21,16 @@ type SdkSessionSystemComposerOptions = {
|
|
|
22
21
|
* 读取当前生效的静态 system 文本集合。
|
|
23
22
|
*/
|
|
24
23
|
getStaticSystemPrompts: () => string[];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 读取当前显式注册 plugin 的 system 文本集合。
|
|
27
|
+
*/
|
|
28
|
+
getPluginSystemPrompts: () => Promise<string[]>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 读取当前显式注入 service 的 system 文本集合。
|
|
32
|
+
*/
|
|
33
|
+
getServiceSystemPrompts: () => Promise<string[]>;
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
/**
|
|
@@ -32,11 +41,15 @@ export class SdkSessionSystemComposer extends SessionSystemComposer {
|
|
|
32
41
|
|
|
33
42
|
private readonly projectRoot: string;
|
|
34
43
|
private readonly getStaticSystemPrompts: SdkSessionSystemComposerOptions["getStaticSystemPrompts"];
|
|
44
|
+
private readonly getServiceSystemPrompts: SdkSessionSystemComposerOptions["getServiceSystemPrompts"];
|
|
45
|
+
private readonly getPluginSystemPrompts: SdkSessionSystemComposerOptions["getPluginSystemPrompts"];
|
|
35
46
|
|
|
36
47
|
constructor(options: SdkSessionSystemComposerOptions) {
|
|
37
48
|
super();
|
|
38
49
|
this.projectRoot = String(options.projectRoot || "").trim();
|
|
39
50
|
this.getStaticSystemPrompts = options.getStaticSystemPrompts;
|
|
51
|
+
this.getServiceSystemPrompts = options.getServiceSystemPrompts;
|
|
52
|
+
this.getPluginSystemPrompts = options.getPluginSystemPrompts;
|
|
40
53
|
if (!this.projectRoot) {
|
|
41
54
|
throw new Error("SdkSessionSystemComposer requires a non-empty projectRoot");
|
|
42
55
|
}
|
|
@@ -61,9 +74,33 @@ export class SdkSessionSystemComposer extends SessionSystemComposer {
|
|
|
61
74
|
variableMode: "stable",
|
|
62
75
|
},
|
|
63
76
|
);
|
|
77
|
+
const servicePrompts = (await this.getServiceSystemPrompts()).filter((item) =>
|
|
78
|
+
String(item || "").trim(),
|
|
79
|
+
);
|
|
80
|
+
const serviceMessages = await transformPromptsIntoSystemMessages(
|
|
81
|
+
servicePrompts,
|
|
82
|
+
{
|
|
83
|
+
projectPath: this.projectRoot,
|
|
84
|
+
sessionId,
|
|
85
|
+
variableMode: "stable",
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
const pluginPrompts = (await this.getPluginSystemPrompts()).filter((item) =>
|
|
89
|
+
String(item || "").trim(),
|
|
90
|
+
);
|
|
91
|
+
const pluginMessages = await transformPromptsIntoSystemMessages(
|
|
92
|
+
pluginPrompts,
|
|
93
|
+
{
|
|
94
|
+
projectPath: this.projectRoot,
|
|
95
|
+
sessionId,
|
|
96
|
+
variableMode: "stable",
|
|
97
|
+
},
|
|
98
|
+
);
|
|
64
99
|
|
|
65
100
|
return [
|
|
66
101
|
...staticMessages,
|
|
102
|
+
...serviceMessages,
|
|
103
|
+
...pluginMessages,
|
|
67
104
|
{
|
|
68
105
|
role: "system" as const,
|
|
69
106
|
content: buildRuntimeClockSystemPrompt({
|
package/src/host/sdk/Session.ts
CHANGED
|
@@ -73,6 +73,16 @@ type SdkSessionOptions = {
|
|
|
73
73
|
* 读取静态 system 文本集合。
|
|
74
74
|
*/
|
|
75
75
|
getStaticSystemPrompts: () => string[];
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 读取当前 agent 显式注入 service 的 system 文本集合。
|
|
79
|
+
*/
|
|
80
|
+
getServiceSystemPrompts: () => Promise<string[]>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 读取当前 agent 显式注册 plugin 的 system 文本集合。
|
|
84
|
+
*/
|
|
85
|
+
getPluginSystemPrompts: () => Promise<string[]>;
|
|
76
86
|
};
|
|
77
87
|
|
|
78
88
|
/**
|
|
@@ -86,6 +96,8 @@ export class SdkSession {
|
|
|
86
96
|
private readonly tools: Record<string, Tool>;
|
|
87
97
|
private readonly logger: SdkSessionOptions["logger"];
|
|
88
98
|
private readonly getStaticSystemPrompts: SdkSessionOptions["getStaticSystemPrompts"];
|
|
99
|
+
private readonly getServiceSystemPrompts: SdkSessionOptions["getServiceSystemPrompts"];
|
|
100
|
+
private readonly getPluginSystemPrompts: SdkSessionOptions["getPluginSystemPrompts"];
|
|
89
101
|
private readonly historyComposer: JsonlSessionHistoryComposer;
|
|
90
102
|
private readonly coreSession: CoreSession;
|
|
91
103
|
private sessionConfig: AgentSessionConfigSnapshot = {};
|
|
@@ -99,6 +111,8 @@ export class SdkSession {
|
|
|
99
111
|
this.tools = options.tools;
|
|
100
112
|
this.logger = options.logger;
|
|
101
113
|
this.getStaticSystemPrompts = options.getStaticSystemPrompts;
|
|
114
|
+
this.getServiceSystemPrompts = options.getServiceSystemPrompts;
|
|
115
|
+
this.getPluginSystemPrompts = options.getPluginSystemPrompts;
|
|
102
116
|
if (!this.id) {
|
|
103
117
|
throw new Error("SdkSession requires a non-empty sessionId");
|
|
104
118
|
}
|
|
@@ -149,6 +163,8 @@ export class SdkSession {
|
|
|
149
163
|
systemComposer: new SdkSessionSystemComposer({
|
|
150
164
|
projectRoot: this.projectRoot,
|
|
151
165
|
getStaticSystemPrompts: this.getStaticSystemPrompts,
|
|
166
|
+
getServiceSystemPrompts: this.getServiceSystemPrompts,
|
|
167
|
+
getPluginSystemPrompts: this.getPluginSystemPrompts,
|
|
152
168
|
}),
|
|
153
169
|
getTools: () => this.tools,
|
|
154
170
|
});
|
|
@@ -356,6 +372,8 @@ export class SdkSession {
|
|
|
356
372
|
tools: this.tools,
|
|
357
373
|
logger: this.logger,
|
|
358
374
|
getStaticSystemPrompts: this.getStaticSystemPrompts,
|
|
375
|
+
getServiceSystemPrompts: this.getServiceSystemPrompts,
|
|
376
|
+
getPluginSystemPrompts: this.getPluginSystemPrompts,
|
|
359
377
|
});
|
|
360
378
|
await forked.initialize();
|
|
361
379
|
if (this.sessionConfig.model) {
|
package/src/http/Server.ts
CHANGED
|
@@ -21,12 +21,6 @@ import {
|
|
|
21
21
|
import { pluginsRouter } from "@/http/plugins/plugins.js";
|
|
22
22
|
import { staticRouter } from "@/http/static/static.js";
|
|
23
23
|
import { controlRouter } from "@/http/control/ControlRouter.js";
|
|
24
|
-
import { registerAuthRoutes } from "@/http/auth/AuthRoutes.js";
|
|
25
|
-
import { AuthService } from "@/http/auth/AuthService.js";
|
|
26
|
-
import {
|
|
27
|
-
createRouteAuthGuardMiddleware,
|
|
28
|
-
SERVER_AUTH_ROUTE_POLICIES,
|
|
29
|
-
} from "@/http/auth/RoutePolicy.js";
|
|
30
24
|
import {
|
|
31
25
|
listBuiltinPluginRuntimeAuthPolicies,
|
|
32
26
|
registerBuiltinPluginHttpRoutes,
|
|
@@ -60,11 +54,6 @@ export interface ServerInstance {
|
|
|
60
54
|
*/
|
|
61
55
|
export function createServerApp(): Hono {
|
|
62
56
|
const app = new Hono();
|
|
63
|
-
const authService = new AuthService();
|
|
64
|
-
const authPolicies = [
|
|
65
|
-
...SERVER_AUTH_ROUTE_POLICIES,
|
|
66
|
-
...listBuiltinPluginRuntimeAuthPolicies(),
|
|
67
|
-
];
|
|
68
57
|
|
|
69
58
|
app.use("*", logger());
|
|
70
59
|
app.use(
|
|
@@ -75,7 +64,6 @@ export function createServerApp(): Hono {
|
|
|
75
64
|
allowHeaders: ["Content-Type", "Authorization"],
|
|
76
65
|
}),
|
|
77
66
|
);
|
|
78
|
-
app.use("*", createRouteAuthGuardMiddleware(authService, authPolicies));
|
|
79
67
|
|
|
80
68
|
// 关键点(中文):service action 路由在 runtime ready 后再注册,避免命令级 import 副作用。
|
|
81
69
|
ensureServiceActionRoutesRegistered();
|
|
@@ -91,7 +79,6 @@ export function createServerApp(): Hono {
|
|
|
91
79
|
app,
|
|
92
80
|
getContext: getAgentContext,
|
|
93
81
|
});
|
|
94
|
-
registerAuthRoutes({ app, authService });
|
|
95
82
|
|
|
96
83
|
return app;
|
|
97
84
|
}
|
package/src/http/auth/AuthEnv.ts
CHANGED
|
@@ -28,11 +28,6 @@ export function normalizeBearerToken(value: unknown): string | null {
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* 解析本次调用应使用的 token。
|
|
31
|
-
*
|
|
32
|
-
* 优先级(中文)
|
|
33
|
-
* 1. 显式传入 token
|
|
34
|
-
* 2. 用户显式覆盖环境变量 `DC_AUTH_TOKEN`
|
|
35
|
-
* 3. 调用方传入的本地存储 token
|
|
36
31
|
*/
|
|
37
32
|
export function resolveInvocationToken(params: {
|
|
38
33
|
explicitToken?: string;
|
|
@@ -52,10 +47,6 @@ export function resolveInvocationToken(params: {
|
|
|
52
47
|
|
|
53
48
|
/**
|
|
54
49
|
* 从通用子进程环境中剥离 Bearer Token。
|
|
55
|
-
*
|
|
56
|
-
* 关键点(中文)
|
|
57
|
-
* - shell / task script / ACP 等通用执行面不应默认继承任何 HTTP 鉴权信息。
|
|
58
|
-
* - 这样可以强制这些链路优先走 RPC,而不是通过环境变量隐式改走本地 HTTP。
|
|
59
50
|
*/
|
|
60
51
|
export function stripInvocationAuthEnv(targetEnv: NodeJS.ProcessEnv): void {
|
|
61
52
|
delete targetEnv[CLI_AUTH_TOKEN_ENV_KEY];
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
import fs from "fs-extra";
|
|
10
10
|
import { getDowncityJsonPath } from "@/config/Paths.js";
|
|
11
|
-
import { PlatformStore } from "@shared/utils/store/index.js";
|
|
12
11
|
import type { ControlRouteRegistrationParams } from "@/shared/types/ControlRoutes.js";
|
|
13
12
|
import { buildControlRouteAliases } from "@/http/control/CommonHelpers.js";
|
|
14
13
|
|
|
@@ -25,9 +24,8 @@ export function registerControlModelRoutes(
|
|
|
25
24
|
try {
|
|
26
25
|
const agentState = params.getAgentRuntime();
|
|
27
26
|
const agentPrimaryModelId = String(agentState.config.execution?.type === "api" ? agentState.config.execution.modelId || "" : "").trim();
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
const providers = await store.listProviders();
|
|
27
|
+
const models = agentState.platform.listModels();
|
|
28
|
+
const providers = await agentState.platform.listProviders();
|
|
31
29
|
const providerMap = new Map(providers.map((x) => [x.id, x] as const));
|
|
32
30
|
const activeModel = agentPrimaryModelId
|
|
33
31
|
? models.find((x) => x.id === agentPrimaryModelId)
|
|
@@ -43,8 +41,6 @@ export function registerControlModelRoutes(
|
|
|
43
41
|
providerType: String(providerConfig?.type || "").trim(),
|
|
44
42
|
};
|
|
45
43
|
});
|
|
46
|
-
store.close();
|
|
47
|
-
|
|
48
44
|
return c.json({
|
|
49
45
|
success: true,
|
|
50
46
|
model: {
|
|
@@ -74,9 +70,7 @@ export function registerControlModelRoutes(
|
|
|
74
70
|
if (!nextPrimaryModelId) {
|
|
75
71
|
return c.json({ success: false, error: "Missing primaryModelId" }, 400);
|
|
76
72
|
}
|
|
77
|
-
const
|
|
78
|
-
const targetModel = store.getModel(nextPrimaryModelId);
|
|
79
|
-
store.close();
|
|
73
|
+
const targetModel = agentState.platform.getModel(nextPrimaryModelId);
|
|
80
74
|
if (!targetModel) {
|
|
81
75
|
return c.json(
|
|
82
76
|
{ success: false, error: `Model not found: ${nextPrimaryModelId}` },
|
package/src/index.ts
CHANGED
|
@@ -108,9 +108,8 @@ export {
|
|
|
108
108
|
startServiceScheduleRuntime,
|
|
109
109
|
stopServiceScheduleRuntime,
|
|
110
110
|
} from './service/schedule/Runtime.js';
|
|
111
|
-
export { runDueScheduledJobs } from "./service/schedule/Executor.js";
|
|
112
111
|
export { ServiceScheduleStore } from "./service/schedule/Store.js";
|
|
113
|
-
export {
|
|
112
|
+
export { runDueScheduledJobs } from "./service/schedule/Executor.js";
|
|
114
113
|
export {
|
|
115
114
|
normalizeRunAtMsOrThrow,
|
|
116
115
|
parseScheduledRunAtMsOrThrow,
|
|
@@ -121,15 +120,6 @@ export {
|
|
|
121
120
|
resolveAssistantMessageForPersistence,
|
|
122
121
|
} from "./service/builtins/chat/runtime/UserVisibleText.js";
|
|
123
122
|
export { logger, getLogger, type Logger } from "./shared/utils/logger/Logger.js";
|
|
124
|
-
export { PlatformStore, withPlatformStore } from "./shared/utils/store/index.js";
|
|
125
|
-
export { ensurePlatformStoreSchema } from "./shared/utils/store/StoreSchema.js";
|
|
126
|
-
export {
|
|
127
|
-
nowIso,
|
|
128
|
-
normalizeNonEmptyText,
|
|
129
|
-
optionalTrimmedText,
|
|
130
|
-
type PlatformDrizzleDb,
|
|
131
|
-
type PlatformStoreContext,
|
|
132
|
-
} from "./shared/utils/store/StoreShared.js";
|
|
133
123
|
|
|
134
124
|
// 共享协议类型与控制面常量
|
|
135
125
|
export * from "./shared/types/AgentHost.js";
|
|
@@ -157,6 +147,7 @@ export * from "./shared/types/ServiceSchedule.js";
|
|
|
157
147
|
export * from "./shared/types/Services.js";
|
|
158
148
|
export * from "./shared/types/Start.js";
|
|
159
149
|
export * from "./shared/types/Store.js";
|
|
150
|
+
export * from "./shared/types/PluginLifecycle.js";
|
|
160
151
|
export * from "./shared/types/auth/AuthPermission.js";
|
|
161
152
|
export * from "./shared/types/auth/AuthRoute.js";
|
|
162
153
|
export * from "./shared/types/auth/AuthToken.js";
|
|
@@ -209,7 +200,6 @@ export {
|
|
|
209
200
|
listStaticPluginViews,
|
|
210
201
|
toStaticPluginView,
|
|
211
202
|
} from "./plugin/Catalog.js";
|
|
212
|
-
export { setCityPluginEnabled, isCityPluginEnabled } from "./plugin/Lifecycle.js";
|
|
213
203
|
export { runLocalPluginAction, listLocalPlugins, getLocalPluginAvailability } from "./plugin/LocalExecution.js";
|
|
214
204
|
export { registerAllPluginsForCli } from "./plugin/PluginCommand.js";
|
|
215
205
|
export { listBuiltinPluginRuntimeAuthPolicies } from "./plugin/HttpRoutes.js";
|
package/src/model/CreateModel.ts
CHANGED
|
@@ -21,8 +21,8 @@ import { createLlmLoggingFetch } from "@shared/utils/logger/Fetch.js";
|
|
|
21
21
|
import { getLogger } from "@shared/utils/logger/Logger.js";
|
|
22
22
|
import type { DowncityConfig } from "@/shared/types/DowncityConfig.js";
|
|
23
23
|
import type { LlmProviderType } from "@/shared/types/LlmConfig.js";
|
|
24
|
-
import { PlatformStore } from "@shared/utils/store/index.js";
|
|
25
24
|
import { readProjectExecutionBinding } from "@/agent/project/ProjectExecutionBinding.js";
|
|
25
|
+
import type { AgentPlatformRuntime } from "@/shared/types/AgentHost.js";
|
|
26
26
|
|
|
27
27
|
type ModelLogContext = {
|
|
28
28
|
sessionId?: string;
|
|
@@ -149,7 +149,7 @@ function normalizeProviderType(value: unknown): LlmProviderType | null {
|
|
|
149
149
|
export async function createModel(input: {
|
|
150
150
|
config: DowncityConfig;
|
|
151
151
|
getSessionRunScope?: () => ModelLogContext | undefined;
|
|
152
|
-
|
|
152
|
+
platform?: AgentPlatformRuntime;
|
|
153
153
|
projectRoot?: string;
|
|
154
154
|
}): Promise<LanguageModel> {
|
|
155
155
|
const logger = getLogger();
|
|
@@ -174,21 +174,23 @@ export async function createModel(input: {
|
|
|
174
174
|
|
|
175
175
|
const primaryModelId = execution.modelId;
|
|
176
176
|
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
177
|
+
const platform = input.platform;
|
|
178
|
+
const modelConfig = platform?.getModel(primaryModelId) || null;
|
|
179
|
+
const providerConfigs = await (platform?.listProviders?.() || Promise.resolve([]));
|
|
180
|
+
const providerMap = new Map(providerConfigs.map((item) => [item.id, item] as const));
|
|
181
|
+
const providerConfig = modelConfig
|
|
182
|
+
? providerMap.get(String(modelConfig.providerId || "").trim()) || null
|
|
183
|
+
: null;
|
|
184
|
+
if (!modelConfig || !providerConfig) {
|
|
185
|
+
await logger.log("warn", `LLM model config not found in platform runtime: ${primaryModelId}`);
|
|
186
|
+
throw Error(`LLM model config not found in platform runtime: ${primaryModelId}`);
|
|
181
187
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
throw Error(`LLM model config not found in sqlite store: ${primaryModelId}`);
|
|
185
|
-
}
|
|
186
|
-
const selectedModelConfig = resolved.model;
|
|
187
|
-
const selectedProviderConfig = resolved.provider;
|
|
188
|
+
const selectedModelConfig = modelConfig;
|
|
189
|
+
const selectedProviderConfig = providerConfig;
|
|
188
190
|
if (selectedModelConfig.isPaused === true) {
|
|
189
191
|
await logger.log(
|
|
190
192
|
"warn",
|
|
191
|
-
`LLM model is paused in
|
|
193
|
+
`LLM model is paused in platform runtime: ${primaryModelId}`,
|
|
192
194
|
);
|
|
193
195
|
throw Error(`LLM model is paused: ${primaryModelId}`);
|
|
194
196
|
}
|
package/src/plugin/Activation.ts
CHANGED
|
@@ -7,16 +7,20 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type { Plugin } from "@/shared/types/Plugin.js";
|
|
10
|
-
import {
|
|
10
|
+
import type { AgentContext } from "@/agent/AgentContextTypes.js";
|
|
11
|
+
import type { AgentRuntimeBase } from "@/agent/AgentRuntimeTypes.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 读取当前 city 配置下的 plugin 启用态。
|
|
14
15
|
*/
|
|
15
16
|
export function isPluginEnabled(params: {
|
|
16
17
|
plugin: Plugin;
|
|
18
|
+
context?: Pick<AgentContext, "platform">;
|
|
19
|
+
runtime?: Pick<AgentRuntimeBase, "platform">;
|
|
17
20
|
}): boolean {
|
|
18
21
|
const pluginName = String(params.plugin.name || "").trim();
|
|
19
22
|
if (!pluginName) return false;
|
|
20
23
|
if (pluginName === "auth") return true;
|
|
21
|
-
|
|
24
|
+
const platform = params.context?.platform || params.runtime?.platform;
|
|
25
|
+
return platform ? platform.isPluginEnabled(pluginName) : true;
|
|
22
26
|
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
createAgentPathRuntime,
|
|
17
17
|
createAgentPluginConfigRuntime,
|
|
18
18
|
} from "@/host/runtime/AgentHostRuntime.js";
|
|
19
|
+
import { getAgentRuntimeBase } from "@/agent/AgentRuntimeState.js";
|
|
19
20
|
import type { JsonValue } from "@/shared/types/Json.js";
|
|
20
21
|
import type {
|
|
21
22
|
PluginActionResult,
|
|
@@ -38,6 +39,26 @@ export function createLocalPluginCommandContext(projectRoot: string): PluginComm
|
|
|
38
39
|
|
|
39
40
|
defaultLogger.bindProjectRoot(rootPath);
|
|
40
41
|
|
|
42
|
+
const platform = (() => {
|
|
43
|
+
try {
|
|
44
|
+
return getAgentRuntimeBase().platform;
|
|
45
|
+
} catch {
|
|
46
|
+
return {
|
|
47
|
+
getGlobalEnv: () => ({}),
|
|
48
|
+
getAgentEnv: () => ({}),
|
|
49
|
+
listModels: () => [],
|
|
50
|
+
listProviders: async () => [],
|
|
51
|
+
getModel: () => null,
|
|
52
|
+
getChannelAccount: () => null,
|
|
53
|
+
readChatAuthorizationConfig: () => ({ roles: {}, channels: {} }),
|
|
54
|
+
writeChatAuthorizationConfig: async (_projectRoot: string, nextConfig: unknown) =>
|
|
55
|
+
nextConfig as never,
|
|
56
|
+
setChatAuthorizationUserRole: async () => ({ roles: {}, channels: {} }),
|
|
57
|
+
isPluginEnabled: (pluginName: string) => pluginName === "auth",
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
})();
|
|
61
|
+
|
|
41
62
|
return {
|
|
42
63
|
cwd: rootPath,
|
|
43
64
|
rootPath,
|
|
@@ -47,6 +68,7 @@ export function createLocalPluginCommandContext(projectRoot: string): PluginComm
|
|
|
47
68
|
globalEnv,
|
|
48
69
|
paths: createAgentPathRuntime(rootPath),
|
|
49
70
|
pluginConfig: createAgentPluginConfigRuntime(rootPath),
|
|
71
|
+
platform,
|
|
50
72
|
};
|
|
51
73
|
}
|
|
52
74
|
|
|
@@ -78,7 +100,7 @@ export async function getLocalPluginAvailability(
|
|
|
78
100
|
return await plugin.availability(context);
|
|
79
101
|
}
|
|
80
102
|
|
|
81
|
-
const enabled = isPluginEnabled({ plugin });
|
|
103
|
+
const enabled = isPluginEnabled({ plugin, context });
|
|
82
104
|
if (!enabled) {
|
|
83
105
|
return {
|
|
84
106
|
enabled: false,
|
|
@@ -131,7 +153,7 @@ export async function runLocalPluginAction(params: {
|
|
|
131
153
|
}
|
|
132
154
|
|
|
133
155
|
const context = createLocalPluginCommandContext(params.projectRoot);
|
|
134
|
-
const enabled = isPluginEnabled({ plugin });
|
|
156
|
+
const enabled = isPluginEnabled({ plugin, context });
|
|
135
157
|
if (!enabled && action.allowWhenDisabled !== true) {
|
|
136
158
|
return {
|
|
137
159
|
success: false,
|
|
@@ -165,7 +165,7 @@ export class PluginRegistry {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
const context = this.contextResolver();
|
|
168
|
-
const enabled = isPluginEnabled({ plugin });
|
|
168
|
+
const enabled = isPluginEnabled({ plugin, context });
|
|
169
169
|
|
|
170
170
|
if (!enabled) {
|
|
171
171
|
return {
|
|
@@ -217,7 +217,7 @@ export class PluginRegistry {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
const context = this.contextResolver();
|
|
220
|
-
const enabled = isPluginEnabled({ plugin });
|
|
220
|
+
const enabled = isPluginEnabled({ plugin, context });
|
|
221
221
|
if (!enabled && action.allowWhenDisabled !== true) {
|
|
222
222
|
return {
|
|
223
223
|
success: false,
|
|
@@ -14,7 +14,6 @@ import type { JsonObject, JsonValue } from "@/shared/types/Json.js";
|
|
|
14
14
|
import type { AgentPluginConfigRuntime } from "@/shared/types/AgentHost.js";
|
|
15
15
|
import { CHAT_PLUGIN_POINTS } from "@/service/builtins/chat/runtime/PluginPoints.js";
|
|
16
16
|
import { isPluginEnabled } from "@/plugin/Activation.js";
|
|
17
|
-
import { setCityPluginEnabled } from "@/plugin/Lifecycle.js";
|
|
18
17
|
import {
|
|
19
18
|
listVoiceModels,
|
|
20
19
|
resolveVoicePluginModelId,
|
|
@@ -228,7 +227,7 @@ export const asrPlugin: Plugin = {
|
|
|
228
227
|
statusAction: "status",
|
|
229
228
|
},
|
|
230
229
|
async availability(context) {
|
|
231
|
-
if (!isPluginEnabled({ plugin: asrPlugin })) {
|
|
230
|
+
if (!isPluginEnabled({ plugin: asrPlugin, context })) {
|
|
232
231
|
return {
|
|
233
232
|
enabled: false,
|
|
234
233
|
available: false,
|
|
@@ -432,7 +431,7 @@ export const asrPlugin: Plugin = {
|
|
|
432
431
|
},
|
|
433
432
|
},
|
|
434
433
|
execute: async ({ context, payload }) => {
|
|
435
|
-
|
|
434
|
+
context.platform.setPluginEnabled?.("asr", true);
|
|
436
435
|
const nextConfig = {
|
|
437
436
|
...readVoicePluginConfig(context),
|
|
438
437
|
injectPrompt:
|
|
@@ -481,7 +480,7 @@ export const asrPlugin: Plugin = {
|
|
|
481
480
|
},
|
|
482
481
|
},
|
|
483
482
|
execute: async ({ context }) => {
|
|
484
|
-
|
|
483
|
+
context.platform.setPluginEnabled?.("asr", false);
|
|
485
484
|
return {
|
|
486
485
|
success: true,
|
|
487
486
|
data: {
|
|
@@ -629,7 +628,7 @@ export const asrPlugin: Plugin = {
|
|
|
629
628
|
},
|
|
630
629
|
system(context) {
|
|
631
630
|
const config = readVoicePluginConfig(context);
|
|
632
|
-
if (!isPluginEnabled({ plugin: asrPlugin }) || config.injectPrompt !== true) {
|
|
631
|
+
if (!isPluginEnabled({ plugin: asrPlugin, context }) || config.injectPrompt !== true) {
|
|
633
632
|
return "";
|
|
634
633
|
}
|
|
635
634
|
return [
|