diff options
| author | Dax Raad <[email protected]> | 2025-05-29 14:16:15 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-29 14:16:15 -0400 |
| commit | d398001f96fd1a7438ac2ef07b4b87bb13766b27 (patch) | |
| tree | b01c93fd0a6b7000c3f6198693bacb85fc00250d /js/src/session | |
| parent | e68747a64aa577a3efb77eda0bfb67f16e341906 (diff) | |
| download | opencode-d398001f96fd1a7438ac2ef07b4b87bb13766b27.tar.gz opencode-d398001f96fd1a7438ac2ef07b4b87bb13766b27.zip | |
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 <[email protected]>
Diffstat (limited to 'js/src/session')
| -rw-r--r-- | js/src/session/session.ts | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/js/src/session/session.ts b/js/src/session/session.ts index e773ed297..0de559dbc 100644 --- a/js/src/session/session.ts +++ b/js/src/session/session.ts @@ -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, ); |
