@serkanalgur/opencodev2-slim 2.0.4 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +15 -11
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -308,17 +308,21 @@ export default Plugin.define({
|
|
|
308
308
|
|
|
309
309
|
const state = getState(sessionId, config)
|
|
310
310
|
|
|
311
|
-
// Apply pruning
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
for (
|
|
321
|
-
event.messages
|
|
311
|
+
// Apply pruning - work with original OpenCode message format
|
|
312
|
+
// event.messages contains { role, content: Part[], ... } objects
|
|
313
|
+
const wrapped = event.messages.map((m: any) => wrapAsMessageWithParts(m))
|
|
314
|
+
const pruned = pruneMessages(wrapped, config, event.messages.length)
|
|
315
|
+
|
|
316
|
+
// Build a Set of pruned message IDs to keep
|
|
317
|
+
const keepIds = new Set(pruned.map((m) => m.info.id))
|
|
318
|
+
|
|
319
|
+
// Remove duplicates in-place, preserving OpenCode's message format
|
|
320
|
+
for (let i = event.messages.length - 1; i >= 0; i--) {
|
|
321
|
+
const msg = event.messages[i] as any
|
|
322
|
+
const id = msg.id || msg.info?.id
|
|
323
|
+
if (id && !keepIds.has(id)) {
|
|
324
|
+
event.messages.splice(i, 1)
|
|
325
|
+
}
|
|
322
326
|
}
|
|
323
327
|
|
|
324
328
|
// Quick token estimate (sync, ~4 chars per token)
|