mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix: preserve agent context during compaction (#4556)
This commit is contained in:
parent
e018e16898
commit
416f2964b5
3 changed files with 17 additions and 3 deletions
|
|
@ -813,8 +813,18 @@ export namespace Server {
|
|||
async (c) => {
|
||||
const id = c.req.valid("param").id
|
||||
const body = c.req.valid("json")
|
||||
const msgs = await Session.messages({ sessionID: id })
|
||||
let currentAgent = "build"
|
||||
for (let i = msgs.length - 1; i >= 0; i--) {
|
||||
const info = msgs[i].info
|
||||
if (info.role === "user") {
|
||||
currentAgent = info.agent || "build"
|
||||
break
|
||||
}
|
||||
}
|
||||
await SessionCompaction.create({
|
||||
sessionID: id,
|
||||
agent: currentAgent,
|
||||
model: {
|
||||
providerID: body.providerID,
|
||||
modelID: body.modelID,
|
||||
|
|
|
|||
|
|
@ -92,6 +92,7 @@ export namespace SessionCompaction {
|
|||
providerID: string
|
||||
modelID: string
|
||||
}
|
||||
agent: string
|
||||
abort: AbortSignal
|
||||
}) {
|
||||
const model = await Provider.getModel(input.model.providerID, input.model.modelID)
|
||||
|
|
@ -101,7 +102,7 @@ export namespace SessionCompaction {
|
|||
role: "assistant",
|
||||
parentID: input.parentID,
|
||||
sessionID: input.sessionID,
|
||||
mode: "build",
|
||||
mode: input.agent,
|
||||
summary: true,
|
||||
path: {
|
||||
cwd: Instance.directory,
|
||||
|
|
@ -199,7 +200,7 @@ export namespace SessionCompaction {
|
|||
time: {
|
||||
created: Date.now(),
|
||||
},
|
||||
agent: "build",
|
||||
agent: input.agent,
|
||||
model: input.model,
|
||||
})
|
||||
await Session.updatePart({
|
||||
|
|
@ -222,6 +223,7 @@ export namespace SessionCompaction {
|
|||
export const create = fn(
|
||||
z.object({
|
||||
sessionID: Identifier.schema("session"),
|
||||
agent: z.string(),
|
||||
model: z.object({
|
||||
providerID: z.string(),
|
||||
modelID: z.string(),
|
||||
|
|
@ -233,7 +235,7 @@ export namespace SessionCompaction {
|
|||
role: "user",
|
||||
model: input.model,
|
||||
sessionID: input.sessionID,
|
||||
agent: "build",
|
||||
agent: input.agent,
|
||||
time: {
|
||||
created: Date.now(),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -398,6 +398,7 @@ export namespace SessionPrompt {
|
|||
messages: msgs,
|
||||
parentID: lastUser.id,
|
||||
abort,
|
||||
agent: lastUser.agent,
|
||||
model: {
|
||||
providerID: model.providerID,
|
||||
modelID: model.modelID,
|
||||
|
|
@ -416,6 +417,7 @@ export namespace SessionPrompt {
|
|||
) {
|
||||
await SessionCompaction.create({
|
||||
sessionID,
|
||||
agent: lastUser.agent,
|
||||
model: lastUser.model,
|
||||
})
|
||||
continue
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue