+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
130 lines
4.9 KiB
TypeScript
130 lines
4.9 KiB
TypeScript
import { expect, test } from "bun:test"
|
|
import { LLMClient, LLMEvent, Model, type LLMRequest } from "@opencode-ai/llm"
|
|
import { OpenAIChat } from "@opencode-ai/llm/protocols"
|
|
import { Config } from "@opencode-ai/core/config"
|
|
import { Database } from "@opencode-ai/core/database/database"
|
|
import { AppNodeBuilder } from "@opencode-ai/core/effect/app-node-builder"
|
|
import { llmClient } from "@opencode-ai/core/effect/app-node-platform"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { EventV2 } from "@opencode-ai/core/event"
|
|
import { EventTable } from "@opencode-ai/core/event/sql"
|
|
import { SessionCompaction } from "@opencode-ai/core/session/compaction"
|
|
import { SessionEvent } from "@opencode-ai/core/session/event"
|
|
import { SessionMessage } from "@opencode-ai/core/session/message"
|
|
import { SessionProjector } from "@opencode-ai/core/session/projector"
|
|
import { SessionRunnerModel } from "@opencode-ai/core/session/runner/model"
|
|
import { SessionTable } from "@opencode-ai/core/session/sql"
|
|
import { SessionStore } from "@opencode-ai/core/session/store"
|
|
import { SessionV2 } from "@opencode-ai/core/session"
|
|
import { Project } from "@opencode-ai/core/project"
|
|
import { ProjectTable } from "@opencode-ai/core/project/sql"
|
|
import { AbsolutePath } from "@opencode-ai/core/schema"
|
|
import { DateTime, Effect, Layer, Stream } from "effect"
|
|
import { asc, eq } from "drizzle-orm"
|
|
import { testEffect } from "./lib/effect"
|
|
|
|
let requests: LLMRequest[] = []
|
|
const model = Model.make({
|
|
id: "summary-model",
|
|
provider: "test",
|
|
route: OpenAIChat.route.with({ limits: { context: 10_000, output: 1_000 } }),
|
|
})
|
|
const client = Layer.mock(LLMClient.Service)({
|
|
prepare: () => Effect.die("unused"),
|
|
stream: (request: LLMRequest) => {
|
|
requests.push(request)
|
|
return Stream.make(LLMEvent.textDelta({ id: "summary", text: "manual summary" }))
|
|
},
|
|
generate: () => Effect.die("unused"),
|
|
})
|
|
const config = Layer.mock(Config.Service)({ entries: () => Effect.succeed([]) })
|
|
const models = Layer.mock(SessionRunnerModel.Service)({ resolve: () => Effect.succeed(model) })
|
|
const it = testEffect(
|
|
AppNodeBuilder.build(
|
|
LayerNode.group([Database.node, EventV2.node, SessionProjector.node, SessionStore.node, SessionCompaction.node]),
|
|
[
|
|
[llmClient, client],
|
|
[Config.node, config],
|
|
[SessionRunnerModel.node, models],
|
|
],
|
|
),
|
|
)
|
|
|
|
test("compaction describes tool media without embedding base64", () => {
|
|
const base64 = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAAB"
|
|
const serialized = SessionCompaction.serializeToolContent([
|
|
{ type: "text", text: "Image read successfully" },
|
|
{
|
|
type: "file",
|
|
uri: `data:image/png;base64,${base64}`,
|
|
mime: "image/png",
|
|
name: "pixel.png",
|
|
},
|
|
])
|
|
|
|
expect(serialized).toBe("Image read successfully\n[Attached image/png: pixel.png]")
|
|
expect(serialized).not.toContain(base64)
|
|
})
|
|
|
|
it.effect("manual compaction summarizes short context instead of no-op", () =>
|
|
Effect.gen(function* () {
|
|
requests = []
|
|
const db = (yield* Database.Service).db
|
|
const compaction = yield* SessionCompaction.Service
|
|
const store = yield* SessionStore.Service
|
|
const sessionID = SessionV2.ID.make("ses_manual_compaction")
|
|
const userMessage = {
|
|
id: SessionMessage.ID.create(),
|
|
type: "user" as const,
|
|
text: "Manual compaction should include this short conversation.",
|
|
time: { created: DateTime.makeUnsafe(0) },
|
|
}
|
|
yield* db
|
|
.insert(ProjectTable)
|
|
.values({ id: Project.ID.global, worktree: AbsolutePath.make("/project"), sandboxes: [] })
|
|
.onConflictDoNothing()
|
|
.run()
|
|
.pipe(Effect.orDie)
|
|
yield* db
|
|
.insert(SessionTable)
|
|
.values({
|
|
id: sessionID,
|
|
project_id: Project.ID.global,
|
|
slug: "manual-compaction",
|
|
directory: "/project",
|
|
title: "Manual compaction",
|
|
version: "test",
|
|
})
|
|
.run()
|
|
.pipe(Effect.orDie)
|
|
|
|
const session = yield* store
|
|
.get(sessionID)
|
|
.pipe(
|
|
Effect.flatMap((session) =>
|
|
session ? Effect.succeed(session) : Effect.die("manual compaction test session missing"),
|
|
),
|
|
)
|
|
|
|
expect(yield* compaction.compactManual({ session, messages: [userMessage] })).toBe(true)
|
|
|
|
expect(requests).toHaveLength(1)
|
|
expect(JSON.stringify(requests[0]?.messages)).toContain("Manual compaction should include this short conversation.")
|
|
expect(yield* store.context(sessionID)).toMatchObject([
|
|
{ type: "compaction", reason: "manual", summary: "manual summary", recent: "" },
|
|
])
|
|
expect(
|
|
yield* db
|
|
.select({ type: EventTable.type })
|
|
.from(EventTable)
|
|
.where(eq(EventTable.aggregate_id, sessionID))
|
|
.orderBy(asc(EventTable.seq))
|
|
.all()
|
|
.pipe(Effect.orDie),
|
|
).toEqual([
|
|
{ type: EventV2.versionedType(SessionEvent.Compaction.Started.type, 1) },
|
|
{ type: EventV2.versionedType(SessionEvent.Compaction.Ended.type, 1) },
|
|
])
|
|
}),
|
|
)
|