refactor(tools/call-omo-agent): remove dead code submodules
Delete 3 unused files in call-omo-agent module: - session-completion-poller.ts - session-message-output-extractor.ts - subagent-session-prompter.ts Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
parent
2428a46e6d
commit
1f62fa5b2a
@ -1,76 +0,0 @@
|
|||||||
import type { PluginInput } from "@opencode-ai/plugin"
|
|
||||||
import { log } from "../../shared"
|
|
||||||
|
|
||||||
function getSessionStatusType(statusResult: unknown, sessionID: string): string | null {
|
|
||||||
if (typeof statusResult !== "object" || statusResult === null) return null
|
|
||||||
if (!("data" in statusResult)) return null
|
|
||||||
const data = (statusResult as { data?: unknown }).data
|
|
||||||
if (typeof data !== "object" || data === null) return null
|
|
||||||
const record = data as Record<string, unknown>
|
|
||||||
const entry = record[sessionID]
|
|
||||||
if (typeof entry !== "object" || entry === null) return null
|
|
||||||
const typeValue = (entry as Record<string, unknown>)["type"]
|
|
||||||
return typeof typeValue === "string" ? typeValue : null
|
|
||||||
}
|
|
||||||
|
|
||||||
function getMessagesArray(result: unknown): unknown[] {
|
|
||||||
if (Array.isArray(result)) return result
|
|
||||||
if (typeof result !== "object" || result === null) return []
|
|
||||||
if (!("data" in result)) return []
|
|
||||||
const data = (result as { data?: unknown }).data
|
|
||||||
return Array.isArray(data) ? data : []
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function waitForSessionCompletion(
|
|
||||||
ctx: PluginInput,
|
|
||||||
options: {
|
|
||||||
sessionID: string
|
|
||||||
abortSignal?: AbortSignal
|
|
||||||
maxPollTimeMs: number
|
|
||||||
pollIntervalMs: number
|
|
||||||
stabilityRequired: number
|
|
||||||
},
|
|
||||||
): Promise<{ ok: true } | { ok: false; reason: "aborted" | "timeout" }> {
|
|
||||||
const pollStart = Date.now()
|
|
||||||
let lastMsgCount = 0
|
|
||||||
let stablePolls = 0
|
|
||||||
|
|
||||||
while (Date.now() - pollStart < options.maxPollTimeMs) {
|
|
||||||
if (options.abortSignal?.aborted) {
|
|
||||||
log("[call_omo_agent] Aborted by user")
|
|
||||||
return { ok: false, reason: "aborted" }
|
|
||||||
}
|
|
||||||
|
|
||||||
await new Promise<void>((resolve) => {
|
|
||||||
setTimeout(resolve, options.pollIntervalMs)
|
|
||||||
})
|
|
||||||
|
|
||||||
const statusResult = await ctx.client.session.status()
|
|
||||||
const sessionStatusType = getSessionStatusType(statusResult, options.sessionID)
|
|
||||||
|
|
||||||
if (sessionStatusType && sessionStatusType !== "idle") {
|
|
||||||
stablePolls = 0
|
|
||||||
lastMsgCount = 0
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
const messagesCheck = await ctx.client.session.messages({
|
|
||||||
path: { id: options.sessionID },
|
|
||||||
})
|
|
||||||
const currentMsgCount = getMessagesArray(messagesCheck).length
|
|
||||||
|
|
||||||
if (currentMsgCount > 0 && currentMsgCount === lastMsgCount) {
|
|
||||||
stablePolls++
|
|
||||||
if (stablePolls >= options.stabilityRequired) {
|
|
||||||
log("[call_omo_agent] Session complete", { messageCount: currentMsgCount })
|
|
||||||
return { ok: true }
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
stablePolls = 0
|
|
||||||
lastMsgCount = currentMsgCount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
log("[call_omo_agent] Timeout reached")
|
|
||||||
return { ok: false, reason: "timeout" }
|
|
||||||
}
|
|
||||||
@ -1,93 +0,0 @@
|
|||||||
import { consumeNewMessages, type CursorMessage } from "../../shared/session-cursor"
|
|
||||||
|
|
||||||
type SessionMessagePart = {
|
|
||||||
type: string
|
|
||||||
text?: string
|
|
||||||
content?: unknown
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SessionMessage = CursorMessage & {
|
|
||||||
info?: CursorMessage["info"] & { role?: string }
|
|
||||||
parts?: SessionMessagePart[]
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRole(message: SessionMessage): string | null {
|
|
||||||
const role = message.info?.role
|
|
||||||
return typeof role === "string" ? role : null
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCreatedTime(message: SessionMessage): number {
|
|
||||||
const time = message.info?.time
|
|
||||||
if (typeof time === "number") return time
|
|
||||||
if (typeof time === "string") return Number(time) || 0
|
|
||||||
const created = time?.created
|
|
||||||
if (typeof created === "number") return created
|
|
||||||
if (typeof created === "string") return Number(created) || 0
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
function isRelevantRole(role: string | null): boolean {
|
|
||||||
return role === "assistant" || role === "tool"
|
|
||||||
}
|
|
||||||
|
|
||||||
function extractTextFromParts(parts: SessionMessagePart[] | undefined): string[] {
|
|
||||||
if (!parts) return []
|
|
||||||
const extracted: string[] = []
|
|
||||||
|
|
||||||
for (const part of parts) {
|
|
||||||
if ((part.type === "text" || part.type === "reasoning") && part.text) {
|
|
||||||
extracted.push(part.text)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (part.type !== "tool_result") continue
|
|
||||||
const content = part.content
|
|
||||||
if (typeof content === "string" && content) {
|
|
||||||
extracted.push(content)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if (!Array.isArray(content)) continue
|
|
||||||
for (const block of content) {
|
|
||||||
if (typeof block !== "object" || block === null) continue
|
|
||||||
const record = block as Record<string, unknown>
|
|
||||||
const typeValue = record["type"]
|
|
||||||
const textValue = record["text"]
|
|
||||||
if (
|
|
||||||
(typeValue === "text" || typeValue === "reasoning") &&
|
|
||||||
typeof textValue === "string" &&
|
|
||||||
textValue
|
|
||||||
) {
|
|
||||||
extracted.push(textValue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return extracted
|
|
||||||
}
|
|
||||||
|
|
||||||
export function extractNewSessionOutput(
|
|
||||||
sessionID: string,
|
|
||||||
messages: SessionMessage[],
|
|
||||||
): { output: string; hasNewOutput: boolean } {
|
|
||||||
const relevantMessages = messages.filter((message) =>
|
|
||||||
isRelevantRole(getRole(message)),
|
|
||||||
)
|
|
||||||
if (relevantMessages.length === 0) {
|
|
||||||
return { output: "", hasNewOutput: false }
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedMessages = [...relevantMessages].sort(
|
|
||||||
(a, b) => getCreatedTime(a) - getCreatedTime(b),
|
|
||||||
)
|
|
||||||
const newMessages = consumeNewMessages(sessionID, sortedMessages)
|
|
||||||
if (newMessages.length === 0) {
|
|
||||||
return { output: "", hasNewOutput: false }
|
|
||||||
}
|
|
||||||
|
|
||||||
const chunks: string[] = []
|
|
||||||
for (const message of newMessages) {
|
|
||||||
chunks.push(...extractTextFromParts(message.parts))
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = chunks.filter((text) => text.length > 0).join("\n\n")
|
|
||||||
return { output, hasNewOutput: output.length > 0 }
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
import type { PluginInput } from "@opencode-ai/plugin"
|
|
||||||
import { log, getAgentToolRestrictions } from "../../shared"
|
|
||||||
|
|
||||||
export async function promptSubagentSession(
|
|
||||||
ctx: PluginInput,
|
|
||||||
options: { sessionID: string; agent: string; prompt: string },
|
|
||||||
): Promise<{ ok: true } | { ok: false; error: string }> {
|
|
||||||
try {
|
|
||||||
await ctx.client.session.promptAsync({
|
|
||||||
path: { id: options.sessionID },
|
|
||||||
body: {
|
|
||||||
agent: options.agent,
|
|
||||||
tools: {
|
|
||||||
...getAgentToolRestrictions(options.agent),
|
|
||||||
task: false,
|
|
||||||
question: false,
|
|
||||||
},
|
|
||||||
parts: [{ type: "text", text: options.prompt }],
|
|
||||||
},
|
|
||||||
})
|
|
||||||
return { ok: true }
|
|
||||||
} catch (error) {
|
|
||||||
const errorMessage = error instanceof Error ? error.message : String(error)
|
|
||||||
log("[call_omo_agent] Prompt error", { error: errorMessage })
|
|
||||||
return { ok: false, error: errorMessage }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user