mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
sync
This commit is contained in:
parent
106a6bb08c
commit
3955c9c1b7
6 changed files with 28 additions and 34 deletions
|
|
@ -2,11 +2,13 @@ import { Config } from "../config/config"
|
|||
import z from "zod"
|
||||
import { Provider } from "../provider/provider"
|
||||
import { generateObject, type ModelMessage } from "ai"
|
||||
import PROMPT_GENERATE from "./generate.txt"
|
||||
import { SystemPrompt } from "../session/system"
|
||||
import { Instance } from "../project/instance"
|
||||
import { mergeDeep } from "remeda"
|
||||
|
||||
import PROMPT_GENERATE from "./generate.txt"
|
||||
import PROMPT_COMPACTION from "./prompt/compaction.txt"
|
||||
|
||||
export namespace Agent {
|
||||
export const Info = z
|
||||
.object({
|
||||
|
|
@ -149,6 +151,17 @@ export namespace Agent {
|
|||
mode: "subagent",
|
||||
internal: true,
|
||||
},
|
||||
compaction: {
|
||||
name: "compaction",
|
||||
mode: "primary",
|
||||
internal: true,
|
||||
prompt: PROMPT_COMPACTION,
|
||||
tools: {
|
||||
"*": false,
|
||||
},
|
||||
options: {},
|
||||
permission: agentPermission,
|
||||
},
|
||||
build: {
|
||||
name: "build",
|
||||
tools: { ...defaultTools },
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ import { Identifier } from "../id/id"
|
|||
import { Instance } from "../project/instance"
|
||||
import { Provider } from "../provider/provider"
|
||||
import { MessageV2 } from "./message-v2"
|
||||
import { SystemPrompt } from "./system"
|
||||
import z from "zod"
|
||||
import { SessionPrompt } from "./prompt"
|
||||
import { Flag } from "../flag/flag"
|
||||
|
|
@ -87,16 +86,14 @@ export namespace SessionCompaction {
|
|||
parentID: string
|
||||
messages: MessageV2.WithParts[]
|
||||
sessionID: string
|
||||
model: {
|
||||
providerID: string
|
||||
modelID: string
|
||||
}
|
||||
abort: AbortSignal
|
||||
auto: boolean
|
||||
}) {
|
||||
const userMessage = input.messages.findLast((m) => m.info.id === input.parentID)!.info as MessageV2.User
|
||||
const agent = await Agent.get("compaction")
|
||||
const model = await Provider.getModel(input.model.providerID, input.model.modelID)
|
||||
const system = [...SystemPrompt.compaction(model.providerID)]
|
||||
const model = agent.model
|
||||
? await Provider.getModel(agent.model.providerID, agent.model.modelID)
|
||||
: await Provider.getModel(userMessage.model.providerID, userMessage.model.modelID)
|
||||
const msg = (await Session.updateMessage({
|
||||
id: Identifier.ascending("message"),
|
||||
role: "assistant",
|
||||
|
|
@ -116,7 +113,7 @@ export namespace SessionCompaction {
|
|||
reasoning: 0,
|
||||
cache: { read: 0, write: 0 },
|
||||
},
|
||||
modelID: input.model.modelID,
|
||||
modelID: model.id,
|
||||
providerID: model.providerID,
|
||||
time: {
|
||||
created: Date.now(),
|
||||
|
|
@ -125,16 +122,16 @@ export namespace SessionCompaction {
|
|||
const processor = SessionProcessor.create({
|
||||
assistantMessage: msg,
|
||||
sessionID: input.sessionID,
|
||||
model: model,
|
||||
model,
|
||||
abort: input.abort,
|
||||
})
|
||||
const result = await processor.process({
|
||||
user: input.messages.findLast((m) => m.info.id === input.parentID)!.info as MessageV2.User,
|
||||
user: userMessage,
|
||||
agent,
|
||||
abort: input.abort,
|
||||
sessionID: input.sessionID,
|
||||
tools: {},
|
||||
system,
|
||||
system: [],
|
||||
messages: [
|
||||
...MessageV2.toModelMessage(input.messages),
|
||||
{
|
||||
|
|
@ -158,8 +155,8 @@ export namespace SessionCompaction {
|
|||
time: {
|
||||
created: Date.now(),
|
||||
},
|
||||
agent: input.agent,
|
||||
model: input.model,
|
||||
agent: userMessage.agent,
|
||||
model: userMessage.model,
|
||||
})
|
||||
await Session.updatePart({
|
||||
id: Identifier.ascending("part"),
|
||||
|
|
|
|||
|
|
@ -404,10 +404,6 @@ export namespace SessionPrompt {
|
|||
messages: msgs,
|
||||
parentID: lastUser.id,
|
||||
abort,
|
||||
model: {
|
||||
providerID: model.providerID,
|
||||
modelID: model.id,
|
||||
},
|
||||
sessionID,
|
||||
auto: task.auto,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -130,10 +130,7 @@ export namespace SessionSummary {
|
|||
m.info.role === "assistant" && m.parts.some((p) => p.type === "step-finish" && p.reason !== "tool-calls"),
|
||||
)
|
||||
) {
|
||||
let summary = messages
|
||||
.findLast((m) => m.info.role === "assistant")
|
||||
?.parts.findLast((p) => p.type === "text")?.text
|
||||
if (!summary || diffs.length > 0) {
|
||||
if (diffs.length > 0) {
|
||||
for (const msg of messages) {
|
||||
for (const part of msg.parts) {
|
||||
if (part.type === "tool" && part.state.status === "completed") {
|
||||
|
|
@ -167,10 +164,10 @@ export namespace SessionSummary {
|
|||
},
|
||||
},
|
||||
}).catch(() => {})
|
||||
if (result) summary = result.text
|
||||
if (result) {
|
||||
userMsg.summary.body = result.text
|
||||
}
|
||||
}
|
||||
userMsg.summary.body = summary
|
||||
log.info("body", { body: summary })
|
||||
await Session.updateMessage(userMsg)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -119,15 +119,6 @@ export namespace SystemPrompt {
|
|||
return Promise.all(found).then((result) => result.filter(Boolean))
|
||||
}
|
||||
|
||||
export function compaction(providerID: string) {
|
||||
switch (providerID) {
|
||||
case "anthropic":
|
||||
return [PROMPT_COMPACTION]
|
||||
default:
|
||||
return [PROMPT_COMPACTION]
|
||||
}
|
||||
}
|
||||
|
||||
export function summarize(providerID: string) {
|
||||
switch (providerID) {
|
||||
case "anthropic":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue