2026-03-29 04:02:13 +00:00
|
|
|
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
|
|
|
|
|
2025-12-09 16:27:46 +09:00
|
|
|
export const subagentSessions = new Set<string>()
|
2026-02-19 04:41:00 +02:00
|
|
|
export const syncSubagentSessions = new Set<string>()
|
2025-12-09 16:27:46 +09:00
|
|
|
|
2026-01-17 16:57:31 +09:00
|
|
|
let _mainSessionID: string | undefined
|
2025-12-09 16:27:46 +09:00
|
|
|
|
|
|
|
|
export function setMainSession(id: string | undefined) {
|
2026-01-17 16:57:31 +09:00
|
|
|
_mainSessionID = id
|
2025-12-09 16:27:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getMainSessionID(): string | undefined {
|
2026-01-17 16:57:31 +09:00
|
|
|
return _mainSessionID
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-27 21:13:44 +09:00
|
|
|
const registeredAgentNames = new Set<string>()
|
|
|
|
|
|
|
|
|
|
export function registerAgentName(name: string): void {
|
2026-03-29 04:02:13 +00:00
|
|
|
const normalizedName = name.toLowerCase()
|
|
|
|
|
registeredAgentNames.add(normalizedName)
|
|
|
|
|
|
|
|
|
|
const configKey = getAgentConfigKey(name).toLowerCase()
|
|
|
|
|
if (configKey !== normalizedName) {
|
|
|
|
|
registeredAgentNames.add(configKey)
|
|
|
|
|
}
|
2026-03-27 21:13:44 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function isAgentRegistered(name: string): boolean {
|
|
|
|
|
return registeredAgentNames.has(name.toLowerCase())
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-17 16:57:31 +09:00
|
|
|
/** @internal For testing only */
|
|
|
|
|
export function _resetForTesting(): void {
|
|
|
|
|
_mainSessionID = undefined
|
|
|
|
|
subagentSessions.clear()
|
2026-02-19 04:41:00 +02:00
|
|
|
syncSubagentSessions.clear()
|
2026-01-28 14:33:14 +09:00
|
|
|
sessionAgentMap.clear()
|
2026-03-27 21:13:44 +09:00
|
|
|
registeredAgentNames.clear()
|
2025-12-09 16:27:46 +09:00
|
|
|
}
|
2026-01-13 07:39:25 +07:00
|
|
|
|
|
|
|
|
const sessionAgentMap = new Map<string, string>()
|
|
|
|
|
|
|
|
|
|
export function setSessionAgent(sessionID: string, agent: string): void {
|
|
|
|
|
if (!sessionAgentMap.has(sessionID)) {
|
|
|
|
|
sessionAgentMap.set(sessionID, agent)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function updateSessionAgent(sessionID: string, agent: string): void {
|
|
|
|
|
sessionAgentMap.set(sessionID, agent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getSessionAgent(sessionID: string): string | undefined {
|
|
|
|
|
return sessionAgentMap.get(sessionID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function clearSessionAgent(sessionID: string): void {
|
|
|
|
|
sessionAgentMap.delete(sessionID)
|
|
|
|
|
}
|