2026-02-14 19:24:30 +09:00
|
|
|
import { findNearestMessageWithFields, findNearestMessageWithFieldsFromSDK } from "../features/hook-message-injector"
|
2026-02-14 17:41:40 +09:00
|
|
|
import { getMessageDir } from "./opencode-message-dir"
|
2026-02-14 19:24:30 +09:00
|
|
|
import { isSqliteBackend } from "./opencode-storage-detection"
|
|
|
|
|
import type { PluginInput } from "@opencode-ai/plugin"
|
2026-01-25 14:52:11 +09:00
|
|
|
|
2026-02-14 19:24:30 +09:00
|
|
|
export async function isCallerOrchestrator(sessionID?: string, client?: PluginInput["client"]): Promise<boolean> {
|
2026-01-25 14:52:11 +09:00
|
|
|
if (!sessionID) return false
|
2026-02-14 19:24:30 +09:00
|
|
|
|
|
|
|
|
// Beta mode: use SDK if client provided
|
|
|
|
|
if (isSqliteBackend() && client) {
|
|
|
|
|
try {
|
|
|
|
|
const nearest = await findNearestMessageWithFieldsFromSDK(client, sessionID)
|
|
|
|
|
return nearest?.agent?.toLowerCase() === "atlas"
|
|
|
|
|
} catch {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stable mode: use JSON files
|
2026-01-25 14:52:11 +09:00
|
|
|
const messageDir = getMessageDir(sessionID)
|
|
|
|
|
if (!messageDir) return false
|
|
|
|
|
const nearest = findNearestMessageWithFields(messageDir)
|
|
|
|
|
return nearest?.agent?.toLowerCase() === "atlas"
|
|
|
|
|
}
|