@@ -57,7 +57,6 @@ import {
|
57 | 57 | import { listThinkingLevelOptions } from "../auto-reply/thinking.js"; |
58 | 58 | import { getRuntimeConfig } from "../config/io.js"; |
59 | 59 | import { resolveAgentModelFallbackValues } from "../config/model-input.js"; |
60 | | -import { resolveStateDir } from "../config/paths.js"; |
61 | 60 | import { |
62 | 61 | buildGroupDisplayName, |
63 | 62 | getSessionStoreCacheVersion, |
@@ -93,6 +92,7 @@ import {
|
93 | 92 | import { normalizeSessionDeliveryFields } from "../utils/delivery-context.shared.js"; |
94 | 93 | import type { ModelCostConfig } from "../utils/usage-format.js"; |
95 | 94 | import { estimateUsageCost, resolveModelCostConfig } from "../utils/usage-format.js"; |
| 95 | +import { listGatewayAgentIds } from "./agent-list.js"; |
96 | 96 | import { |
97 | 97 | resolveSessionStoreAgentId, |
98 | 98 | resolveSessionStoreKey, |
@@ -1214,42 +1214,6 @@ function isStorePathTemplate(store?: string): boolean {
|
1214 | 1214 | return typeof store === "string" && store.includes("{agentId}"); |
1215 | 1215 | } |
1216 | 1216 | |
1217 | | -function listExistingAgentIdsFromDisk(): string[] { |
1218 | | -const root = resolveStateDir(); |
1219 | | -const agentsDir = path.join(root, "agents"); |
1220 | | -try { |
1221 | | -const entries = fs.readdirSync(agentsDir, { withFileTypes: true }); |
1222 | | -return entries |
1223 | | -.filter((entry) => entry.isDirectory()) |
1224 | | -.map((entry) => normalizeAgentId(entry.name)) |
1225 | | -.filter(Boolean); |
1226 | | -} catch { |
1227 | | -return []; |
1228 | | -} |
1229 | | -} |
1230 | | - |
1231 | | -function listConfiguredAgentIds(cfg: OpenClawConfig): string[] { |
1232 | | -const ids = new Set<string>(); |
1233 | | -const defaultId = normalizeAgentId(resolveDefaultAgentId(cfg)); |
1234 | | -ids.add(defaultId); |
1235 | | - |
1236 | | -for (const entry of cfg.agents?.list ?? []) { |
1237 | | -if (entry?.id) { |
1238 | | -ids.add(normalizeAgentId(entry.id)); |
1239 | | -} |
1240 | | -} |
1241 | | - |
1242 | | -for (const id of listExistingAgentIdsFromDisk()) { |
1243 | | -ids.add(id); |
1244 | | -} |
1245 | | - |
1246 | | -const sorted = Array.from(ids).filter(Boolean); |
1247 | | -sorted.sort((a, b) => a.localeCompare(b)); |
1248 | | -return sorted.includes(defaultId) |
1249 | | - ? [defaultId, ...sorted.filter((id) => id !== defaultId)] |
1250 | | - : sorted; |
1251 | | -} |
1252 | | - |
1253 | 1217 | function normalizeFallbackList(values: readonly string[]): string[] { |
1254 | 1218 | const out: string[] = []; |
1255 | 1219 | const seen = new Set<string>(); |
@@ -1330,7 +1294,7 @@ export function listAgentsForGateway(
|
1330 | 1294 | .filter(Boolean), |
1331 | 1295 | ); |
1332 | 1296 | const allowedIds = explicitIds.size > 0 ? new Set([...explicitIds, defaultId]) : null; |
1333 | | -let agentIds = listConfiguredAgentIds(cfg).filter((id) => |
| 1297 | +let agentIds = listGatewayAgentIds(cfg).filter((id) => |
1334 | 1298 | allowedIds ? allowedIds.has(id) : true, |
1335 | 1299 | ); |
1336 | 1300 | if (mainKey && !agentIds.includes(mainKey) && (!allowedIds || allowedIds.has(mainKey))) { |
|