feat: migrate tool callers to SDK message finders on SQLite backend
This commit is contained in:
@@ -1,14 +1,33 @@
|
||||
import type { ToolContextWithMetadata } from "./types"
|
||||
import type { OpencodeClient } from "./types"
|
||||
import type { ParentContext } from "./executor-types"
|
||||
import { findNearestMessageWithFields, findFirstMessageWithAgent } from "../../features/hook-message-injector"
|
||||
import {
|
||||
findFirstMessageWithAgent,
|
||||
findFirstMessageWithAgentFromSDK,
|
||||
findNearestMessageWithFields,
|
||||
findNearestMessageWithFieldsFromSDK,
|
||||
} from "../../features/hook-message-injector"
|
||||
import { getSessionAgent } from "../../features/claude-code-session-state"
|
||||
import { log } from "../../shared/logger"
|
||||
import { getMessageDir } from "../../shared"
|
||||
import { getMessageDir } from "../../shared/opencode-message-dir"
|
||||
import { isSqliteBackend } from "../../shared/opencode-storage-detection"
|
||||
|
||||
export function resolveParentContext(ctx: ToolContextWithMetadata): ParentContext {
|
||||
export async function resolveParentContext(
|
||||
ctx: ToolContextWithMetadata,
|
||||
client: OpencodeClient
|
||||
): Promise<ParentContext> {
|
||||
const messageDir = getMessageDir(ctx.sessionID)
|
||||
const prevMessage = messageDir ? findNearestMessageWithFields(messageDir) : null
|
||||
const firstMessageAgent = messageDir ? findFirstMessageWithAgent(messageDir) : null
|
||||
|
||||
const [prevMessage, firstMessageAgent] = isSqliteBackend()
|
||||
? await Promise.all([
|
||||
findNearestMessageWithFieldsFromSDK(client, ctx.sessionID),
|
||||
findFirstMessageWithAgentFromSDK(client, ctx.sessionID),
|
||||
])
|
||||
: [
|
||||
messageDir ? findNearestMessageWithFields(messageDir) : null,
|
||||
messageDir ? findFirstMessageWithAgent(messageDir) : null,
|
||||
]
|
||||
|
||||
const sessionAgent = getSessionAgent(ctx.sessionID)
|
||||
const parentAgent = ctx.agent ?? sessionAgent ?? firstMessageAgent ?? prevMessage?.agent
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ Prompts MUST be in English.`
|
||||
return skillError
|
||||
}
|
||||
|
||||
const parentContext = resolveParentContext(ctx)
|
||||
const parentContext = await resolveParentContext(ctx, options.client)
|
||||
|
||||
if (args.session_id) {
|
||||
if (runInBackground) {
|
||||
|
||||
Reference in New Issue
Block a user