@downcity/city 1.1.7 → 1.1.9
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/cli/agent/AgentManager.js +1 -1
- package/bin/cli/agent/AgentManager.js.map +1 -1
- package/bin/cli/agent/AgentReset.js +1 -1
- package/bin/cli/agent/AgentReset.js.map +1 -1
- package/bin/cli/agent/Init.d.ts.map +1 -1
- package/bin/cli/agent/Init.js +4 -2
- package/bin/cli/agent/Init.js.map +1 -1
- package/bin/cli/agent/Run.d.ts.map +1 -1
- package/bin/cli/agent/Run.js +4 -1
- package/bin/cli/agent/Run.js.map +1 -1
- package/bin/cli/control-plane/ControlPlaneInit.js +1 -1
- package/bin/cli/control-plane/ControlPlaneInit.js.map +1 -1
- package/bin/cli/control-plane/ControlPlaneProcess.d.ts.map +1 -1
- package/bin/cli/control-plane/ControlPlaneProcess.js +2 -1
- package/bin/cli/control-plane/ControlPlaneProcess.js.map +1 -1
- package/bin/cli/model/ModelCommandShared.d.ts +1 -1
- package/bin/cli/model/ModelCommandShared.d.ts.map +1 -1
- package/bin/cli/model/ModelCommandShared.js +1 -1
- package/bin/cli/model/ModelCommandShared.js.map +1 -1
- package/bin/cli/model/ModelCreateCommand.js +1 -1
- package/bin/cli/model/ModelCreateCommand.js.map +1 -1
- package/bin/cli/model/ModelManager.js +1 -1
- package/bin/cli/model/ModelManager.js.map +1 -1
- package/bin/cli/model/ModelReadCommand.js +1 -1
- package/bin/cli/model/ModelReadCommand.js.map +1 -1
- package/bin/cli/service/ServiceCommandSupport.d.ts.map +1 -1
- package/bin/cli/service/ServiceCommandSupport.js +2 -1
- package/bin/cli/service/ServiceCommandSupport.js.map +1 -1
- package/bin/cli/shared/ChatAuth.d.ts.map +1 -1
- package/bin/cli/shared/ChatAuth.js +6 -5
- package/bin/cli/shared/ChatAuth.js.map +1 -1
- package/bin/cli/shared/ChatManager.d.ts.map +1 -1
- package/bin/cli/shared/ChatManager.js +11 -7
- package/bin/cli/shared/ChatManager.js.map +1 -1
- package/bin/cli/shared/Env.js +1 -1
- package/bin/cli/shared/Env.js.map +1 -1
- package/bin/cli/shared/Plugins.js +2 -1
- package/bin/cli/shared/Plugins.js.map +1 -1
- package/bin/cli/shared/PublicHostEnv.js +1 -1
- package/bin/cli/shared/PublicHostEnv.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/control/ChannelAccountApiRoutes.d.ts.map +1 -1
- package/bin/control/ChannelAccountApiRoutes.js +2 -1
- package/bin/control/ChannelAccountApiRoutes.js.map +1 -1
- package/bin/control/EnvApiRoutes.js +1 -1
- package/bin/control/EnvApiRoutes.js.map +1 -1
- package/bin/control/ModelApiRoutes.js +1 -1
- package/bin/control/ModelApiRoutes.js.map +1 -1
- package/bin/control/ModelPoolService.js +1 -1
- package/bin/control/ModelPoolService.js.map +1 -1
- package/bin/control/PluginApiRoutes.d.ts.map +1 -1
- package/bin/control/PluginApiRoutes.js +2 -1
- package/bin/control/PluginApiRoutes.js.map +1 -1
- package/bin/control/gateway/AgentActions.d.ts.map +1 -1
- package/bin/control/gateway/AgentActions.js +4 -3
- package/bin/control/gateway/AgentActions.js.map +1 -1
- package/bin/control/gateway/AgentCatalog.js +4 -4
- package/bin/control/gateway/AgentCatalog.js.map +1 -1
- package/bin/http/auth/AuthService.d.ts.map +1 -1
- package/bin/http/auth/AuthService.js +1 -1
- package/bin/http/auth/AuthService.js.map +1 -1
- package/bin/http/auth/AuthStore.js +2 -2
- package/bin/http/auth/AuthStore.js.map +1 -1
- package/bin/platform/PluginLifecycle.d.ts +51 -0
- package/bin/platform/PluginLifecycle.d.ts.map +1 -0
- package/bin/platform/PluginLifecycle.js +98 -0
- package/bin/platform/PluginLifecycle.js.map +1 -0
- package/bin/platform/chatAuthorization/Store.d.ts +31 -0
- package/bin/platform/chatAuthorization/Store.d.ts.map +1 -0
- package/bin/platform/chatAuthorization/Store.js +145 -0
- package/bin/platform/chatAuthorization/Store.js.map +1 -0
- package/bin/platform/store/StoreChannelAccountRepository.d.ts +34 -0
- package/bin/platform/store/StoreChannelAccountRepository.d.ts.map +1 -0
- package/bin/platform/store/StoreChannelAccountRepository.js +198 -0
- package/bin/platform/store/StoreChannelAccountRepository.js.map +1 -0
- package/bin/platform/store/StoreEnvRepository.d.ts +98 -0
- package/bin/platform/store/StoreEnvRepository.d.ts.map +1 -0
- package/bin/platform/store/StoreEnvRepository.js +334 -0
- package/bin/platform/store/StoreEnvRepository.js.map +1 -0
- package/bin/platform/store/StoreModelRepository.d.ts +61 -0
- package/bin/platform/store/StoreModelRepository.d.ts.map +1 -0
- package/bin/platform/store/StoreModelRepository.js +278 -0
- package/bin/platform/store/StoreModelRepository.js.map +1 -0
- package/bin/platform/store/StoreSchema.d.ts +13 -0
- package/bin/platform/store/StoreSchema.d.ts.map +1 -0
- package/bin/platform/store/StoreSchema.js +319 -0
- package/bin/platform/store/StoreSchema.js.map +1 -0
- package/bin/platform/store/StoreSecureSettings.d.ts +33 -0
- package/bin/platform/store/StoreSecureSettings.d.ts.map +1 -0
- package/bin/platform/store/StoreSecureSettings.js +91 -0
- package/bin/platform/store/StoreSecureSettings.js.map +1 -0
- package/bin/platform/store/StoreShared.d.ts +44 -0
- package/bin/platform/store/StoreShared.d.ts.map +1 -0
- package/bin/platform/store/StoreShared.js +40 -0
- package/bin/platform/store/StoreShared.js.map +1 -0
- package/bin/platform/store/crypto.d.ts +24 -0
- package/bin/platform/store/crypto.d.ts.map +1 -0
- package/bin/platform/store/crypto.js +101 -0
- package/bin/platform/store/crypto.js.map +1 -0
- package/bin/platform/store/index.d.ts +230 -0
- package/bin/platform/store/index.d.ts.map +1 -0
- package/bin/platform/store/index.js +360 -0
- package/bin/platform/store/index.js.map +1 -0
- package/bin/platform/store/schema.d.ts +690 -0
- package/bin/platform/store/schema.d.ts.map +1 -0
- package/bin/platform/store/schema.js +81 -0
- package/bin/platform/store/schema.js.map +1 -0
- package/bin/process/registry/AgentHostRuntime.d.ts +9 -1
- package/bin/process/registry/AgentHostRuntime.d.ts.map +1 -1
- package/bin/process/registry/AgentHostRuntime.js +77 -3
- package/bin/process/registry/AgentHostRuntime.js.map +1 -1
- package/package.json +2 -2
- package/src/cli/agent/AgentManager.ts +1 -1
- package/src/cli/agent/AgentReset.ts +1 -1
- package/src/cli/agent/Init.ts +13 -8
- package/src/cli/agent/Run.ts +4 -1
- package/src/cli/control-plane/ControlPlaneInit.ts +1 -1
- package/src/cli/control-plane/ControlPlaneProcess.ts +2 -1
- package/src/cli/model/ModelCommandShared.ts +1 -1
- package/src/cli/model/ModelCreateCommand.ts +1 -1
- package/src/cli/model/ModelManager.ts +1 -1
- package/src/cli/model/ModelReadCommand.ts +1 -1
- package/src/cli/service/ServiceCommandSupport.ts +2 -1
- package/src/cli/shared/ChatAuth.ts +5 -6
- package/src/cli/shared/ChatManager.ts +12 -7
- package/src/cli/shared/Env.ts +1 -1
- package/src/cli/shared/Plugins.ts +1 -1
- package/src/cli/shared/PublicHostEnv.ts +1 -1
- package/src/config/Paths.ts +2 -9
- package/src/control/ChannelAccountApiRoutes.ts +2 -1
- package/src/control/EnvApiRoutes.ts +1 -1
- package/src/control/ModelApiRoutes.ts +1 -1
- package/src/control/ModelPoolService.ts +1 -1
- package/src/control/PluginApiRoutes.ts +4 -2
- package/src/control/gateway/AgentActions.ts +24 -17
- package/src/control/gateway/AgentCatalog.ts +4 -4
- package/src/http/auth/AuthService.ts +1 -1
- package/src/http/auth/AuthStore.ts +2 -2
- package/src/platform/PluginLifecycle.ts +132 -0
- package/src/platform/chatAuthorization/Store.ts +181 -0
- package/src/platform/store/StoreChannelAccountRepository.ts +269 -0
- package/src/platform/store/StoreEnvRepository.ts +452 -0
- package/src/platform/store/StoreModelRepository.ts +324 -0
- package/src/platform/store/StoreSchema.ts +344 -0
- package/src/platform/store/StoreSecureSettings.ts +126 -0
- package/src/platform/store/StoreShared.ts +67 -0
- package/src/platform/store/crypto.ts +112 -0
- package/src/platform/store/index.ts +497 -0
- package/src/platform/store/schema.ts +103 -0
- package/src/process/registry/AgentHostRuntime.ts +79 -3
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 模型存储表结构(drizzle schema)。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - providers 与 models 分表,使用 providerId 做关联。
|
|
6
|
+
* - API Key 以密文字段存储(`apiKeyEncrypted`)。
|
|
7
|
+
*/
|
|
8
|
+
import { index, integer, primaryKey, real, sqliteTable, text, } from "drizzle-orm/sqlite-core";
|
|
9
|
+
export const modelProvidersTable = sqliteTable("model_providers", {
|
|
10
|
+
id: text("id").primaryKey(),
|
|
11
|
+
type: text("type").notNull(),
|
|
12
|
+
baseUrl: text("base_url"),
|
|
13
|
+
apiKeyEncrypted: text("api_key_encrypted"),
|
|
14
|
+
createdAt: text("created_at").notNull(),
|
|
15
|
+
updatedAt: text("updated_at").notNull(),
|
|
16
|
+
});
|
|
17
|
+
export const modelsTable = sqliteTable("models", {
|
|
18
|
+
id: text("id").primaryKey(),
|
|
19
|
+
providerId: text("provider_id").notNull(),
|
|
20
|
+
name: text("name").notNull(),
|
|
21
|
+
temperature: real("temperature"),
|
|
22
|
+
maxTokens: integer("max_tokens"),
|
|
23
|
+
topP: real("top_p"),
|
|
24
|
+
frequencyPenalty: real("frequency_penalty"),
|
|
25
|
+
presencePenalty: real("presence_penalty"),
|
|
26
|
+
anthropicVersion: text("anthropic_version"),
|
|
27
|
+
isPaused: integer("is_paused").notNull().default(0),
|
|
28
|
+
createdAt: text("created_at").notNull(),
|
|
29
|
+
updatedAt: text("updated_at").notNull(),
|
|
30
|
+
}, (table) => ({
|
|
31
|
+
providerIdIdx: index("models_provider_id_idx").on(table.providerId),
|
|
32
|
+
}));
|
|
33
|
+
/**
|
|
34
|
+
* 平台 Env 统一存储表。
|
|
35
|
+
*
|
|
36
|
+
* 关键点(中文)
|
|
37
|
+
* - 全局 env 与 agent env 共用一张表,通过 `scope` + `agentId` 区分。
|
|
38
|
+
* - `agentId` 在 `scope=global` 时固定为空字符串,避免 SQLite 复合主键中的 NULL 语义问题。
|
|
39
|
+
* - value 采用密文存储,解密仅在运行时内存中进行。
|
|
40
|
+
*/
|
|
41
|
+
export const envEntriesTable = sqliteTable("env_entries", {
|
|
42
|
+
scope: text("scope").notNull(),
|
|
43
|
+
agentId: text("agent_id").notNull().default(""),
|
|
44
|
+
key: text("key").notNull(),
|
|
45
|
+
description: text("description"),
|
|
46
|
+
valueEncrypted: text("value_encrypted").notNull(),
|
|
47
|
+
createdAt: text("created_at").notNull(),
|
|
48
|
+
updatedAt: text("updated_at").notNull(),
|
|
49
|
+
}, (table) => ({
|
|
50
|
+
pk: primaryKey({
|
|
51
|
+
columns: [table.scope, table.agentId, table.key],
|
|
52
|
+
name: "env_entries_scope_agent_key_pk",
|
|
53
|
+
}),
|
|
54
|
+
scopeIdx: index("env_entries_scope_idx").on(table.scope),
|
|
55
|
+
agentIdIdx: index("env_entries_agent_id_idx").on(table.agentId),
|
|
56
|
+
}));
|
|
57
|
+
/**
|
|
58
|
+
* Channel Account 表。
|
|
59
|
+
*
|
|
60
|
+
* 关键点(中文)
|
|
61
|
+
* - 各渠道敏感字段独立密文列存储。
|
|
62
|
+
* - `downcity.json` 仅保存 channelAccountId 绑定,不直接保存密钥。
|
|
63
|
+
*/
|
|
64
|
+
export const channelAccountsTable = sqliteTable("channel_accounts", {
|
|
65
|
+
id: text("id").primaryKey(),
|
|
66
|
+
channel: text("channel").notNull(),
|
|
67
|
+
name: text("name").notNull(),
|
|
68
|
+
identity: text("identity"),
|
|
69
|
+
owner: text("owner"),
|
|
70
|
+
creator: text("creator"),
|
|
71
|
+
botTokenEncrypted: text("bot_token_encrypted"),
|
|
72
|
+
appIdEncrypted: text("app_id_encrypted"),
|
|
73
|
+
appSecretEncrypted: text("app_secret_encrypted"),
|
|
74
|
+
domain: text("domain"),
|
|
75
|
+
sandbox: integer("sandbox"),
|
|
76
|
+
createdAt: text("created_at").notNull(),
|
|
77
|
+
updatedAt: text("updated_at").notNull(),
|
|
78
|
+
}, (table) => ({
|
|
79
|
+
channelIdx: index("channel_accounts_channel_idx").on(table.channel),
|
|
80
|
+
}));
|
|
81
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/platform/store/schema.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,KAAK,EACL,OAAO,EACP,UAAU,EACV,IAAI,EACJ,WAAW,EACX,IAAI,GACL,MAAM,yBAAyB,CAAC;AAEjC,MAAM,CAAC,MAAM,mBAAmB,GAAG,WAAW,CAAC,iBAAiB,EAAE;IAChE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC;IACzB,eAAe,EAAE,IAAI,CAAC,mBAAmB,CAAC;IAC1C,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IACvC,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CACpC,QAAQ,EACR;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE;IAC3B,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;IACzC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC;IAChC,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC,OAAO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luginConfigRuntime } from "@downcity/agent";
|
|
2
2
|
/**
|
|
3
3
|
* 创建当前项目的路径能力集合。
|
|
4
4
|
*/
|
|
@@ -7,4 +7,12 @@ export declare function createAgentPathRuntime(projectRoot: string): AgentPathRu
|
|
|
7
7
|
* 创建 plugin 配置持久化能力集合。
|
|
8
8
|
*/
|
|
9
9
|
export declare function createAgentPluginConfigRuntime(projectRoot: string): AgentPluginConfigRuntime;
|
|
10
|
+
/**
|
|
11
|
+
* 创建当前项目的平台能力集合。
|
|
12
|
+
*
|
|
13
|
+
* 关键点(中文)
|
|
14
|
+
* - 这里先暴露 agent 当前已经需要的最小平台读能力。
|
|
15
|
+
* - 具体平台数据仍由 city 自己管理,agent 只消费这一层接口。
|
|
16
|
+
*/
|
|
17
|
+
export declare function createAgentPlatformRuntime(): AgentPlatformRuntime;
|
|
10
18
|
//# sourceMappingURL=AgentHostRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentHostRuntime.d.ts","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"AgentHostRuntime.d.ts","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAazB;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,GAAG,gBAAgB,CAe5E;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAY5F;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,IAAI,oBAAoB,CA0DjE"}
|
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - `main/agent/*` 负责创建这些宿主能力对象,再注入到 AgentRuntime。
|
|
6
6
|
* - services / session / plugins 只消费这些对象,不再直接 import `main/*`。
|
|
7
|
-
* -
|
|
7
|
+
* - 当前由 city 在这里统一装配路径、plugin 配置持久化与平台能力三类宿主对象。
|
|
8
8
|
*/
|
|
9
|
-
import { getCacheDirPath, getDowncityChannelDirPath, getDowncityChannelMetaPath, getDowncityChatHistoryPath, getDowncityDirPath, getDowncityMemoryDailyDirPath, getDowncityMemoryDailyPath,
|
|
9
|
+
import { getCacheDirPath, getDowncityChannelDirPath, getDowncityChannelMetaPath, getDowncityChatHistoryPath, getDowncityDirPath, getDowncityMemoryDailyDirPath, getDowncityMemoryDailyPath, getDowncityMemoryLongTermPath, getDowncitySessionDirPath, getDowncitySessionRootDirPath, } from "../../config/Paths.js";
|
|
10
10
|
import { persistProjectPluginConfig } from "@downcity/agent";
|
|
11
|
+
import { PlatformStore } from "../../platform/store/index.js";
|
|
12
|
+
import { isCityPluginEnabled, setCityPluginEnabled, } from "../../platform/PluginLifecycle.js";
|
|
13
|
+
import { readChatAuthorizationConfigSync, setChatAuthorizationUserRole, writeChatAuthorizationConfig, } from "../../platform/chatAuthorization/Store.js";
|
|
11
14
|
/**
|
|
12
15
|
* 创建当前项目的路径能力集合。
|
|
13
16
|
*/
|
|
@@ -20,7 +23,6 @@ export function createAgentPathRuntime(projectRoot) {
|
|
|
20
23
|
getDowncityChannelDirPath: () => getDowncityChannelDirPath(rootPath),
|
|
21
24
|
getDowncityChannelMetaPath: () => getDowncityChannelMetaPath(rootPath),
|
|
22
25
|
getDowncityChatHistoryPath: (sessionId) => getDowncityChatHistoryPath(rootPath, sessionId),
|
|
23
|
-
getDowncityMemoryIndexPath: () => getDowncityMemoryIndexPath(rootPath),
|
|
24
26
|
getDowncityMemoryLongTermPath: () => getDowncityMemoryLongTermPath(rootPath),
|
|
25
27
|
getDowncityMemoryDailyDirPath: () => getDowncityMemoryDailyDirPath(rootPath),
|
|
26
28
|
getDowncityMemoryDailyPath: (date) => getDowncityMemoryDailyPath(rootPath, date),
|
|
@@ -44,4 +46,76 @@ export function createAgentPluginConfigRuntime(projectRoot) {
|
|
|
44
46
|
},
|
|
45
47
|
};
|
|
46
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* 创建当前项目的平台能力集合。
|
|
51
|
+
*
|
|
52
|
+
* 关键点(中文)
|
|
53
|
+
* - 这里先暴露 agent 当前已经需要的最小平台读能力。
|
|
54
|
+
* - 具体平台数据仍由 city 自己管理,agent 只消费这一层接口。
|
|
55
|
+
*/
|
|
56
|
+
export function createAgentPlatformRuntime() {
|
|
57
|
+
return {
|
|
58
|
+
getGlobalEnv: () => {
|
|
59
|
+
const store = new PlatformStore();
|
|
60
|
+
try {
|
|
61
|
+
return store.getGlobalEnvMapSync();
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
store.close();
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
getAgentEnv: (projectRoot) => {
|
|
68
|
+
const store = new PlatformStore();
|
|
69
|
+
try {
|
|
70
|
+
return store.getAgentEnvMapSync(projectRoot);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
store.close();
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
listModels: () => {
|
|
77
|
+
const store = new PlatformStore();
|
|
78
|
+
try {
|
|
79
|
+
return store.listModels();
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
store.close();
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
listProviders: async () => {
|
|
86
|
+
const store = new PlatformStore();
|
|
87
|
+
try {
|
|
88
|
+
return await store.listProviders();
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
store.close();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
getModel: (modelId) => {
|
|
95
|
+
const store = new PlatformStore();
|
|
96
|
+
try {
|
|
97
|
+
return store.getModel(modelId);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
store.close();
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
getChannelAccount: (channelAccountId) => {
|
|
104
|
+
const store = new PlatformStore();
|
|
105
|
+
try {
|
|
106
|
+
return store.getChannelAccountSync(channelAccountId);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
store.close();
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
readChatAuthorizationConfig: (projectRoot) => readChatAuthorizationConfigSync(projectRoot),
|
|
113
|
+
writeChatAuthorizationConfig,
|
|
114
|
+
setChatAuthorizationUserRole,
|
|
115
|
+
isPluginEnabled: (pluginName) => isCityPluginEnabled(pluginName),
|
|
116
|
+
setPluginEnabled: (pluginName, enabled) => {
|
|
117
|
+
setCityPluginEnabled(pluginName, enabled);
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
47
121
|
//# sourceMappingURL=AgentHostRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentHostRuntime.js","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,EAClB,6BAA6B,EAC7B,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"AgentHostRuntime.js","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,EAClB,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,EAC7B,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAO7D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EACL,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,+BAA+B,CAA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;YACpB,MAAM,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;YAClC,IAAI,CAAC;gBACH,OAAO,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YACjC,CAAC;oBAAS,CAAC;gBACT,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;QACD,iBAAiB,EAAE,CAAC,gBAAgB,EAAE,EAAE;YACtC,MAAM,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;YAClC,IAAI,CAAC;gBACH,OAAO,KAAK,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;YACvD,CAAC;oBAAS,CAAC;gBACT,KAAK,CAAC,KAAK,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;QACD,2BAA2B,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,+BAA+B,CAAC,WAAW,CAAC;QAC1F,4BAA4B;QAC5B,4BAA4B;QAC5B,eAAe,EAAE,CAAC,UAAU,EAAE,EAAE,CAAC,mBAAmB,CAAC,UAAU,CAAC;QAChE,gBAAgB,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,EAAE;YACxC,oBAAoB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@downcity/city",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Downcity City 平台 — CLI、daemon 管理、Console 网关、能力平台",
|
|
6
6
|
"bin": {
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prompts": "^2.4.0",
|
|
37
37
|
"ws": "^8.19.0",
|
|
38
38
|
"zod": "^3.24.0",
|
|
39
|
-
"@downcity/agent": "^1.1.
|
|
39
|
+
"@downcity/agent": "^1.1.8"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/better-sqlite3": "^7.6.13",
|
|
@@ -25,7 +25,7 @@ import { injectAgentContext } from "../shared/IndexSupport.js";
|
|
|
25
25
|
import { prepareForegroundAgent } from "../control-plane/ControlPlaneCommand.js";
|
|
26
26
|
import { CliError } from "../shared/CliError.js";
|
|
27
27
|
import { getDowncityJsonPath } from "@/config/Paths.js";
|
|
28
|
-
import { PlatformStore } from "
|
|
28
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
29
29
|
import type { StartOptions } from "@downcity/agent";
|
|
30
30
|
import type { DowncityConfig } from "@downcity/agent";
|
|
31
31
|
import type { StoredChannelAccount, StoredChannelAccountChannel } from "@downcity/agent";
|
|
@@ -11,7 +11,7 @@ import path from "node:path";
|
|
|
11
11
|
import fs from "fs-extra";
|
|
12
12
|
import prompts from "prompts";
|
|
13
13
|
import { getDowncityJsonPath } from "@/config/Paths.js";
|
|
14
|
-
import { PlatformStore } from "
|
|
14
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
15
15
|
import { emitCliBlock } from "../shared/CliReporter.js";
|
|
16
16
|
import { CliError } from "../shared/CliError.js";
|
|
17
17
|
import { resolveAgentName } from "../shared/IndexSupport.js";
|
package/src/cli/agent/Init.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type { AgentProjectChannel } from "@downcity/agent";
|
|
|
25
25
|
import type { ExecutionBindingConfig } from "@downcity/agent";
|
|
26
26
|
import { emitCliBlock, emitCliList } from "../shared/CliReporter.js";
|
|
27
27
|
import { CliError } from "../shared/CliError.js";
|
|
28
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
28
29
|
|
|
29
30
|
type InitPromptResponse = {
|
|
30
31
|
name?: string;
|
|
@@ -67,7 +68,8 @@ export async function initCommand(
|
|
|
67
68
|
const existingProfileMd = fs.existsSync(getProfileMdPath(projectRoot));
|
|
68
69
|
const existingSoulMd = fs.existsSync(getSoulMdPath(projectRoot));
|
|
69
70
|
const existingShipJson = fs.existsSync(getDowncityJsonPath(projectRoot));
|
|
70
|
-
const
|
|
71
|
+
const platform = createAgentPlatformRuntime();
|
|
72
|
+
const platformModelChoices = await listPlatformModelChoices(platform);
|
|
71
73
|
const platformModelIds = platformModelChoices.map((item) => item.value);
|
|
72
74
|
|
|
73
75
|
// 关键点(中文):已存在的 PROFILE.md 永远不覆盖,只在 downcity.json 已存在时询问覆盖。
|
|
@@ -140,13 +142,16 @@ export async function initCommand(
|
|
|
140
142
|
const selectedChannels = Array.isArray(response.channels)
|
|
141
143
|
? (response.channels as AgentProjectChannel[])
|
|
142
144
|
: [];
|
|
143
|
-
const initResult = await initializeAgentProject(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
const initResult = await initializeAgentProject(
|
|
146
|
+
{
|
|
147
|
+
projectRoot,
|
|
148
|
+
agentName,
|
|
149
|
+
execution,
|
|
150
|
+
channels: selectedChannels,
|
|
151
|
+
forceOverwriteShipJson: allowOverwrite,
|
|
152
|
+
},
|
|
153
|
+
platform,
|
|
154
|
+
);
|
|
150
155
|
|
|
151
156
|
const createdItems: string[] = [];
|
|
152
157
|
const skippedItems: string[] = [];
|
package/src/cli/agent/Run.ts
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import type { StartOptions } from "@downcity/agent";
|
|
26
26
|
import { logger } from "@downcity/agent";
|
|
27
27
|
import { CliError } from "../shared/CliError.js";
|
|
28
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* 前台启动入口(由 `agent start` 前台模式与内部 daemon 子进程复用)。
|
|
@@ -41,7 +42,9 @@ export async function runCommand(
|
|
|
41
42
|
options: StartOptions,
|
|
42
43
|
): Promise<void> {
|
|
43
44
|
// 初始化加载(进程级单例状态:root / config / logger / chat / agents 等)
|
|
44
|
-
await initAgentRuntime(cwd
|
|
45
|
+
await initAgentRuntime(cwd, {
|
|
46
|
+
platform: createAgentPlatformRuntime(),
|
|
47
|
+
});
|
|
45
48
|
// 端口解析(中文):允许 number / string;空值返回 undefined 以便走配置回退链。
|
|
46
49
|
const parsePort = (
|
|
47
50
|
value: string | number | undefined,
|
|
@@ -18,7 +18,7 @@ import { saveJson } from "@/utils/storage.js";
|
|
|
18
18
|
import {
|
|
19
19
|
getPlatformRootDirPath,
|
|
20
20
|
} from "@/process/registry/CityPaths.js";
|
|
21
|
-
import { PlatformStore } from "
|
|
21
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
22
22
|
import { emitCliBlock, emitCliList } from "../shared/CliReporter.js";
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
stopDaemonProcess,
|
|
18
18
|
} from "@/process/daemon/Manager.js";
|
|
19
19
|
import { ensureRuntimeExecutionBindingReady } from "@downcity/agent";
|
|
20
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
20
21
|
import { allocateAvailablePort } from "@/process/daemon/PortAllocator.js";
|
|
21
22
|
import {
|
|
22
23
|
ensureManagedAgentRegistry,
|
|
@@ -468,7 +469,7 @@ export async function prepareForegroundAgent(
|
|
|
468
469
|
|
|
469
470
|
injectAgentContext(cwd);
|
|
470
471
|
const projectRoot = resolve(String(cwd || "."));
|
|
471
|
-
ensureRuntimeExecutionBindingReady(projectRoot);
|
|
472
|
+
ensureRuntimeExecutionBindingReady(projectRoot, createAgentPlatformRuntime());
|
|
472
473
|
|
|
473
474
|
const shouldForeground = options.foreground === true;
|
|
474
475
|
if (!shouldForeground) {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type ModelPreset,
|
|
13
13
|
} from "@/cli/model/preset/ModelPresetManager.js";
|
|
14
14
|
import type { LlmProviderType } from "@downcity/agent";
|
|
15
|
-
import { PlatformStore } from "
|
|
15
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
16
16
|
|
|
17
17
|
const SUPPORTED_PROVIDER_TYPES: readonly LlmProviderType[] = [
|
|
18
18
|
"anthropic",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import prompts from "prompts";
|
|
11
11
|
import type { Command } from "commander";
|
|
12
|
-
import { PlatformStore } from "
|
|
12
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
13
13
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
14
14
|
import {
|
|
15
15
|
discoverProviderModels,
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import prompts from "prompts";
|
|
11
11
|
import { generateText } from "ai";
|
|
12
12
|
import { createModel } from "@downcity/agent";
|
|
13
|
-
import { PlatformStore } from "
|
|
13
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
14
14
|
import { toSafeProviderView } from "./ModelCommandShared.js";
|
|
15
15
|
import {
|
|
16
16
|
discoverProviderModels,
|
|
@@ -20,6 +20,7 @@ import { CliError } from "../shared/CliError.js";
|
|
|
20
20
|
import type { ScheduledJobStatus } from "@downcity/agent";
|
|
21
21
|
import type { ServiceCliBaseOptions } from "@downcity/agent";
|
|
22
22
|
import { parseBoolean } from "../shared/IndexSupport.js";
|
|
23
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
23
24
|
|
|
24
25
|
export function isRegistryEntryRunning(
|
|
25
26
|
entry: { status?: "running" | "stopped" },
|
|
@@ -76,7 +77,7 @@ export async function checkAgentPreflight(
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
// 关键点(中文):提前校验 execution binding,避免"启动成功后秒退"。
|
|
79
|
-
ensureRuntimeExecutionBindingReady(projectRoot);
|
|
80
|
+
ensureRuntimeExecutionBindingReady(projectRoot, createAgentPlatformRuntime());
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
/**
|
|
@@ -12,9 +12,7 @@ import prompts from "prompts";
|
|
|
12
12
|
import type { Command } from "commander";
|
|
13
13
|
import {
|
|
14
14
|
listChatAuthorizationRoles,
|
|
15
|
-
readChatAuthorizationConfigSync,
|
|
16
15
|
resolveAuthorizedUserRole,
|
|
17
|
-
setChatAuthorizationUserRole,
|
|
18
16
|
} from "@downcity/agent";
|
|
19
17
|
import { emitCliBlock } from "./CliReporter.js";
|
|
20
18
|
import { parseBoolean } from "./IndexSupport.js";
|
|
@@ -23,6 +21,8 @@ import {
|
|
|
23
21
|
type ChatAuthorizationChannel,
|
|
24
22
|
type ChatAuthorizationRole,
|
|
25
23
|
} from "@downcity/agent";
|
|
24
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
25
|
+
import { readChatAuthorizationConfigSync } from "@/platform/chatAuthorization/Store.js";
|
|
26
26
|
|
|
27
27
|
type ChatAuthSetOptions = {
|
|
28
28
|
/**
|
|
@@ -141,10 +141,9 @@ export async function runChatAuthSet(params: {
|
|
|
141
141
|
|
|
142
142
|
if (!nextRole) return;
|
|
143
143
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
},
|
|
144
|
+
const platform = createAgentPlatformRuntime();
|
|
145
|
+
await platform.setChatAuthorizationUserRole({
|
|
146
|
+
projectRoot,
|
|
148
147
|
channel: principal.channel,
|
|
149
148
|
userId: principal.userId,
|
|
150
149
|
roleId: nextRole.roleId,
|
|
@@ -21,9 +21,14 @@ import type {
|
|
|
21
21
|
ChatManagerRootAction,
|
|
22
22
|
} from "./ChatManagerTypes.js";
|
|
23
23
|
import { runInteractiveChatAuthSetFlow } from "./ChatAuth.js";
|
|
24
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
24
25
|
|
|
25
26
|
const CHAT_CHANNELS: StoredChannelAccountChannel[] = ["telegram", "feishu", "qq"];
|
|
26
27
|
|
|
28
|
+
function createChannelAccountService(): ChatChannelAccountService {
|
|
29
|
+
return new ChatChannelAccountService(createAgentPlatformRuntime());
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
function isInteractiveTerminal(): boolean {
|
|
28
33
|
return process.stdin.isTTY === true && process.stdout.isTTY === true;
|
|
29
34
|
}
|
|
@@ -44,7 +49,7 @@ function formatCredentialSummary(account: ChatChannelAccountListItem): string {
|
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
async function promptRootAction(): Promise<ChatManagerRootAction | null> {
|
|
47
|
-
const service =
|
|
52
|
+
const service = createChannelAccountService();
|
|
48
53
|
const accounts = await service.list();
|
|
49
54
|
const response = (await prompts({
|
|
50
55
|
type: "select",
|
|
@@ -89,7 +94,7 @@ async function promptRootAction(): Promise<ChatManagerRootAction | null> {
|
|
|
89
94
|
}
|
|
90
95
|
|
|
91
96
|
async function promptChannelAccountAction(): Promise<ChatChannelAccountAction | null> {
|
|
92
|
-
const service =
|
|
97
|
+
const service = createChannelAccountService();
|
|
93
98
|
const accounts = await service.list();
|
|
94
99
|
const response = (await prompts({
|
|
95
100
|
type: "select",
|
|
@@ -134,7 +139,7 @@ async function promptChannelAccountAction(): Promise<ChatChannelAccountAction |
|
|
|
134
139
|
}
|
|
135
140
|
|
|
136
141
|
async function emitChannelAccountList(): Promise<void> {
|
|
137
|
-
const service =
|
|
142
|
+
const service = createChannelAccountService();
|
|
138
143
|
const { items } = await service.list();
|
|
139
144
|
if (items.length === 0) {
|
|
140
145
|
emitCliBlock({
|
|
@@ -177,7 +182,7 @@ async function chooseChannel(): Promise<StoredChannelAccountChannel | null> {
|
|
|
177
182
|
}
|
|
178
183
|
|
|
179
184
|
async function chooseAccount(): Promise<ChatChannelAccountListItem | null> {
|
|
180
|
-
const service =
|
|
185
|
+
const service = createChannelAccountService();
|
|
181
186
|
const { items } = await service.list();
|
|
182
187
|
if (items.length === 0) {
|
|
183
188
|
emitCliBlock({
|
|
@@ -291,7 +296,7 @@ async function addChannelAccount(): Promise<void> {
|
|
|
291
296
|
initial: true,
|
|
292
297
|
})) as { probe?: boolean };
|
|
293
298
|
|
|
294
|
-
const service =
|
|
299
|
+
const service = createChannelAccountService();
|
|
295
300
|
const result = await service.create({
|
|
296
301
|
channel,
|
|
297
302
|
name,
|
|
@@ -319,7 +324,7 @@ async function editChannelAccount(): Promise<void> {
|
|
|
319
324
|
channel: account.channel,
|
|
320
325
|
current: account,
|
|
321
326
|
});
|
|
322
|
-
const service =
|
|
327
|
+
const service = createChannelAccountService();
|
|
323
328
|
await service.upsert({
|
|
324
329
|
id: account.id,
|
|
325
330
|
channel: account.channel,
|
|
@@ -351,7 +356,7 @@ async function removeChannelAccount(): Promise<void> {
|
|
|
351
356
|
|
|
352
357
|
if (response.remove !== true) return;
|
|
353
358
|
|
|
354
|
-
const service =
|
|
359
|
+
const service = createChannelAccountService();
|
|
355
360
|
service.remove(account.id);
|
|
356
361
|
emitCliBlock({
|
|
357
362
|
tone: "success",
|
package/src/cli/shared/Env.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { Command } from "commander";
|
|
11
|
-
import { PlatformStore } from "
|
|
11
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
12
12
|
import type { StoredEnvEntry, StoredEnvScope } from "@downcity/agent";
|
|
13
13
|
import { emitCliBlock, emitCliList } from "./CliReporter.js";
|
|
14
14
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
@@ -17,7 +17,6 @@ import {
|
|
|
17
17
|
findStaticPluginView,
|
|
18
18
|
listStaticPluginViews,
|
|
19
19
|
runLocalPluginAction,
|
|
20
|
-
setCityPluginEnabled,
|
|
21
20
|
} from "@downcity/agent";
|
|
22
21
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
23
22
|
import type { JsonValue } from "@downcity/agent";
|
|
@@ -27,6 +26,7 @@ import type { PluginCliBaseOptions } from "@downcity/agent";
|
|
|
27
26
|
import { emitCliBlock } from "./CliReporter.js";
|
|
28
27
|
import { parseBoolean } from "./IndexSupport.js";
|
|
29
28
|
import { resolveProjectRoot } from "../service/ServiceCommandSupport.js";
|
|
29
|
+
import { setCityPluginEnabled } from "@/platform/PluginLifecycle.js";
|
|
30
30
|
|
|
31
31
|
async function resolvePluginProjectRoot(options: PluginCliBaseOptions): Promise<{
|
|
32
32
|
projectRoot?: string;
|
package/src/config/Paths.ts
CHANGED
|
@@ -111,20 +111,13 @@ export function getDowncityMemoryDailyPath(cwd: string, date: string): string {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
115
|
-
*/
|
|
116
|
-
export function getDowncityMemoryIndexPath(cwd: string): string {
|
|
117
|
-
return path.join(getDowncityMemoryDirPath(cwd), "index.sqlite");
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Service Schedule SQLite 路径。
|
|
114
|
+
* Service Schedule JSONL 路径。
|
|
122
115
|
*
|
|
123
116
|
* 关键点(中文)
|
|
124
117
|
* - 调度任务属于项目 runtime 本地状态,因此放在项目 `.downcity/` 下。
|
|
125
118
|
*/
|
|
126
119
|
export function getDowncityScheduleDbPath(cwd: string): string {
|
|
127
|
-
return path.join(getDowncityDirPath(cwd), "schedule.
|
|
120
|
+
return path.join(getDowncityDirPath(cwd), "schedule.jsonl");
|
|
128
121
|
}
|
|
129
122
|
|
|
130
123
|
export function getDowncityDataDirPath(cwd: string): string {
|
|
@@ -8,13 +8,14 @@
|
|
|
8
8
|
|
|
9
9
|
import type { Hono } from "hono";
|
|
10
10
|
import { ChatChannelAccountService } from "@downcity/agent";
|
|
11
|
+
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* 注册 Channel Account API 路由。
|
|
14
15
|
*/
|
|
15
16
|
export function registerPlatformChannelAccountRoutes(params: { app: Hono }): void {
|
|
16
17
|
const app = params.app;
|
|
17
|
-
const service = new ChatChannelAccountService();
|
|
18
|
+
const service = new ChatChannelAccountService(createAgentPlatformRuntime());
|
|
18
19
|
|
|
19
20
|
app.get("/api/ui/channel-accounts", async (c) => {
|
|
20
21
|
try {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import type { Hono } from "hono";
|
|
10
10
|
import fs from "fs-extra";
|
|
11
11
|
import { getDowncityJsonPath } from "@/config/Paths.js";
|
|
12
|
-
import { PlatformStore } from "
|
|
12
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
13
13
|
import type { PlatformAgentOption } from "@downcity/agent";
|
|
14
14
|
import { ModelPoolService } from "@/control/ModelPoolService.js";
|
|
15
15
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { generateText } from "ai";
|
|
11
11
|
import type { LlmProviderType } from "@downcity/agent";
|
|
12
|
-
import { PlatformStore } from "
|
|
12
|
+
import { PlatformStore } from "@/platform/store/index.js";
|
|
13
13
|
import { createModel } from "@downcity/agent";
|
|
14
14
|
import { discoverProviderModels } from "@/cli/model/ModelSupport.js";
|
|
15
15
|
|