mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-10 11:24:59 +01:00
add parent id to assistant messages
This commit is contained in:
@@ -109,6 +109,7 @@ export namespace SessionCompaction {
|
||||
const msg = (await Session.updateMessage({
|
||||
id: Identifier.ascending("message"),
|
||||
role: "assistant",
|
||||
parentID: toSummarize.findLast((m) => m.info.role === "user")?.info.id!,
|
||||
sessionID: input.sessionID,
|
||||
system,
|
||||
mode: "build",
|
||||
|
||||
@@ -278,6 +278,7 @@ export namespace MessageV2 {
|
||||
])
|
||||
.optional(),
|
||||
system: z.string().array(),
|
||||
parentID: z.string(),
|
||||
modelID: z.string(),
|
||||
providerID: z.string(),
|
||||
mode: z.string(),
|
||||
@@ -346,6 +347,7 @@ export namespace MessageV2 {
|
||||
if (v1.role === "assistant") {
|
||||
const info: Assistant = {
|
||||
id: v1.id,
|
||||
parentID: "",
|
||||
sessionID: v1.metadata.sessionID,
|
||||
role: "assistant",
|
||||
time: {
|
||||
|
||||
@@ -235,7 +235,7 @@ export namespace SessionPrompt {
|
||||
modelID: model.info.id,
|
||||
})
|
||||
step++
|
||||
await processor.next()
|
||||
await processor.next(msgs.findLast((m) => m.info.role === "user")?.info.id!)
|
||||
await using _ = defer(async () => {
|
||||
await processor.end()
|
||||
})
|
||||
@@ -900,9 +900,10 @@ export namespace SessionPrompt {
|
||||
let snapshot: string | undefined
|
||||
let blocked = false
|
||||
|
||||
async function createMessage() {
|
||||
async function createMessage(parentID: string) {
|
||||
const msg: MessageV2.Info = {
|
||||
id: Identifier.ascending("message"),
|
||||
parentID,
|
||||
role: "assistant",
|
||||
system: input.system,
|
||||
mode: input.agent,
|
||||
@@ -938,11 +939,11 @@ export namespace SessionPrompt {
|
||||
assistantMsg = undefined
|
||||
}
|
||||
},
|
||||
async next() {
|
||||
async next(parentID: string) {
|
||||
if (assistantMsg) {
|
||||
throw new Error("end previous assistant message first")
|
||||
}
|
||||
assistantMsg = await createMessage()
|
||||
assistantMsg = await createMessage(parentID)
|
||||
return assistantMsg
|
||||
},
|
||||
get message() {
|
||||
@@ -1424,6 +1425,7 @@ export namespace SessionPrompt {
|
||||
const msg: MessageV2.Assistant = {
|
||||
id: Identifier.ascending("message"),
|
||||
sessionID: input.sessionID,
|
||||
parentID: userMsg.id,
|
||||
system: [],
|
||||
mode: input.agent,
|
||||
cost: 0,
|
||||
@@ -1696,6 +1698,7 @@ export namespace SessionPrompt {
|
||||
const assistantMsg: MessageV2.Assistant = {
|
||||
id: Identifier.ascending("message"),
|
||||
sessionID: input.sessionID,
|
||||
parentID: userMsg.id,
|
||||
system: [],
|
||||
mode: agentName,
|
||||
cost: 0,
|
||||
|
||||
Reference in New Issue
Block a user