mirror of
https://github.com/aljazceru/opencode.git
synced 2026-01-05 08:54:55 +01:00
Remove React/Ink dependencies and add context window management
- Remove unused React and Ink CLI dependencies to simplify package - Update provider schema to use maxOutputTokens for clarity - Add automatic summarization when approaching context window limits - Simplify message event handling and add cost/token metadata display 🤖 Generated with opencode Co-Authored-By: opencode <noreply@opencode.ai>
This commit is contained in:
@@ -149,11 +149,31 @@ export namespace Session {
|
||||
modelID: string;
|
||||
parts: Message.Part[];
|
||||
}) {
|
||||
using abort = lock(input.sessionID);
|
||||
const l = log.clone().tag("session", input.sessionID);
|
||||
l.info("chatting");
|
||||
const model = await LLM.findModel(input.providerID, input.modelID);
|
||||
let msgs = await messages(input.sessionID);
|
||||
const previous = msgs.at(-1);
|
||||
if (previous?.metadata.assistant) {
|
||||
const tokens =
|
||||
previous.metadata.assistant.tokens.input +
|
||||
previous.metadata.assistant.tokens.output;
|
||||
console.log(tokens);
|
||||
if (
|
||||
tokens >
|
||||
(model.info.contextWindow - (model.info.maxOutputTokens ?? 0)) * 0.9
|
||||
) {
|
||||
await summarize({
|
||||
sessionID: input.sessionID,
|
||||
providerID: input.providerID,
|
||||
modelID: input.modelID,
|
||||
});
|
||||
return chat(input);
|
||||
}
|
||||
}
|
||||
|
||||
using abort = lock(input.sessionID);
|
||||
|
||||
const lastSummary = msgs.findLast(
|
||||
(msg) => msg.metadata.assistant?.summary === true,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user