Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/opencode/src/session/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Question } from "@/question"
import { errorMessage } from "@/util/error"
import { isRecord } from "@/util/record"
import { EventV2Bridge } from "@/event-v2-bridge"
import { SessionEvent } from "@opencode-ai/core/session/event"
import { Database } from "@opencode-ai/core/database/database"
import { Usage, type LLMEvent } from "@opencode-ai/llm"

Expand Down Expand Up @@ -514,15 +515,24 @@ const layer = Layer.effect(
if (!ctx.currentText) return
// oxlint-disable-next-line no-self-assign -- reactivity trigger
ctx.currentText.text = ctx.currentText.text
ctx.currentText.text = (yield* plugin.trigger(
const textCompleteV1 = yield* plugin.trigger(
"experimental.text.complete",
{
sessionID: ctx.sessionID,
messageID: ctx.assistantMessage.id,
partID: ctx.currentText.id,
},
{ text: ctx.currentText.text },
)).text
)
const textCompleteV2 = yield* events.waterfall(SessionEvent.Text.Complete, [
(_e, next) =>
Effect.gen(function* () {
const downstream = yield* next()
const downstreamText = (downstream as { text?: string } | undefined)?.text
return { text: downstreamText ?? textCompleteV1.text }
}),
])
ctx.currentText.text = (textCompleteV2 as { text: string }).text
{
const end = Date.now()
ctx.currentText.time = { start: ctx.currentText.time?.start ?? end, end }
Expand Down
18 changes: 18 additions & 0 deletions packages/schema/src/session-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,24 @@ export namespace Text {
},
})
export type Ended = typeof Ended.Type

/**
* Live waterfall fired when a text part's stream completes, before the
* final value is persisted. Listeners return `{ text }` to transform the
* final text or throw to veto. This is the V2 replacement for the legacy
* V1 `experimental.text.complete` hook and gives plugins proper
* `next()`-based mutation semantics.
*/
export const Complete = Event.define({
type: "session.next.text.complete",
schema: {
...Base,
messageID: SessionMessage.ID,
partID: Schema.String,
text: Schema.String,
},
})
export type Complete = typeof Complete.Type
}

export namespace Reasoning {
Expand Down
Loading