Skip to content

Commit 7425a1e

Browse files
add agent and model
1 parent eae0f96 commit 7425a1e

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ export namespace SessionPrompt {
266266
using _ = defer(() => cancel(sessionID))
267267

268268
let step = 0
269+
let sessionAgent: string | undefined
270+
let sessionModel: { providerID: string; modelID: string } | undefined
269271
const session = await Session.get(sessionID)
270272
while (true) {
271273
SessionStatus.set(sessionID, { type: "busy" })
@@ -291,6 +293,8 @@ export namespace SessionPrompt {
291293
}
292294

293295
if (!lastUser) throw new Error("No user message found in stream. This should never happen.")
296+
sessionAgent = lastUser.agent
297+
sessionModel = lastUser.model
294298
if (
295299
lastAssistant?.finish &&
296300
!["tool-calls", "unknown"].includes(lastAssistant.finish) &&
@@ -626,13 +630,19 @@ export namespace SessionPrompt {
626630
// Allow plugins to optionally resume this session before it completes
627631
const sessionInfo = await Session.get(sessionID)
628632
const beforeIdleOutput = { resumePrompt: undefined as string | undefined }
629-
await Plugin.trigger("session.before.idle", { sessionID, parentSessionID: sessionInfo?.parentID }, beforeIdleOutput)
633+
await Plugin.trigger(
634+
"session.before.idle",
635+
{ sessionID, parentSessionID: sessionInfo?.parentID, agent: sessionAgent, model: sessionModel },
636+
beforeIdleOutput,
637+
)
630638

631639
if (beforeIdleOutput.resumePrompt) {
632640
log.info("resuming session", { sessionID })
633641
delete state()[sessionID]
634642
await prompt({
635643
sessionID,
644+
agent: sessionAgent,
645+
model: sessionModel,
636646
parts: [{ type: "text", text: beforeIdleOutput.resumePrompt }],
637647
})
638648
}

‎packages/plugin/src/index.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ export interface Hooks {
217217
) => Promise<void>
218218

219219
"session.before.idle"?: (
220-
input: { sessionID: string; parentSessionID?: string },
220+
input: {
221+
sessionID: string
222+
parentSessionID?: string
223+
agent?: string
224+
model?: { providerID: string; modelID: string }
225+
},
221226
output: { resumePrompt?: string },
222227
) => Promise<void>
223228
}

0 commit comments

Comments
 (0)