e5aa08b865
Cast session body to Record<string, unknown> instead of as any Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
28 lines
1005 B
TypeScript
28 lines
1005 B
TypeScript
import type { OpencodeClient } from "./types"
|
|
|
|
export async function createSyncSession(
|
|
client: OpencodeClient,
|
|
input: { parentSessionID: string; agentToUse: string; description: string; defaultDirectory: string }
|
|
): Promise<{ ok: true; sessionID: string; parentDirectory: string } | { ok: false; error: string }> {
|
|
const parentSession = client.session.get
|
|
? await client.session.get({ path: { id: input.parentSessionID } }).catch(() => null)
|
|
: null
|
|
const parentDirectory = parentSession?.data?.directory ?? input.defaultDirectory
|
|
|
|
const createResult = await client.session.create({
|
|
body: {
|
|
parentID: input.parentSessionID,
|
|
title: `${input.description} (@${input.agentToUse} subagent)`,
|
|
} as Record<string, unknown>,
|
|
query: {
|
|
directory: parentDirectory,
|
|
},
|
|
})
|
|
|
|
if (createResult.error) {
|
|
return { ok: false, error: `Failed to create session: ${createResult.error}` }
|
|
}
|
|
|
|
return { ok: true, sessionID: createResult.data.id, parentDirectory }
|
|
}
|