mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-11 16:52:16 +03:00
refactor(core): avoid redundant payload decoding in session inbox and prompt (#57946)
This commit is contained in:
committed by
GitHub
Unverified
parent
7456ad872e
commit
7012c9dbf3
@@ -75,8 +75,8 @@ function matches<Type extends Item["type"]>(
|
||||
|
||||
const fromRow = (row: typeof SessionInboxTable.$inferSelect): Info => {
|
||||
const base = {
|
||||
id: SessionMessage.ID.make(row.id),
|
||||
sessionID: SessionSchema.ID.make(row.session_id),
|
||||
id: row.id,
|
||||
sessionID: row.session_id,
|
||||
time: { created: DateTime.makeUnsafe(row.time_created) },
|
||||
}
|
||||
if (row.type === "compaction")
|
||||
@@ -230,7 +230,7 @@ export const make = Effect.fn("SessionInbox.make")(function* () {
|
||||
return yield* admit({
|
||||
id: input.id,
|
||||
sessionID: input.sessionID,
|
||||
item: { type: "compaction", payload: {}, delivery: Delivery.make(input.delivery) },
|
||||
item: { type: "compaction", payload: {}, delivery: input.delivery },
|
||||
})
|
||||
}),
|
||||
)
|
||||
@@ -473,17 +473,17 @@ const publish = Effect.fn("SessionInbox.publish")(function* (
|
||||
yield* Effect.forEach(
|
||||
rows,
|
||||
(row) => {
|
||||
const entry = fromRow(row)
|
||||
if (entry.type === "compaction") return Effect.die(new LifecycleConflict({ id: entry.id }))
|
||||
if (row.type !== "move" && row.type !== "user" && row.type !== "synthetic")
|
||||
return Effect.die(new LifecycleConflict({ id: row.id }))
|
||||
return bus
|
||||
.publish(SessionEvent.InboxDelivered, {
|
||||
sessionID,
|
||||
inboxID: entry.id,
|
||||
inboxID: row.id,
|
||||
})
|
||||
.pipe(
|
||||
Effect.catchDefect((defect) =>
|
||||
defect instanceof LifecycleConflict
|
||||
? promotedFromMessage(db, sessionID, entry.id, entry.delivery).pipe(
|
||||
? promotedFromMessage(db, sessionID, row.id, row.delivery).pipe(
|
||||
Effect.flatMap((stored) => (stored !== undefined ? Effect.void : Effect.die(defect))),
|
||||
Effect.orDie,
|
||||
)
|
||||
|
||||
@@ -19,6 +19,8 @@ export interface Adapter {
|
||||
|
||||
type DraftAssistant = WritableDraft<SessionMessage.Assistant>
|
||||
|
||||
const decodeAssistantContent = Schema.decodeUnknownSync(Schema.Array(SessionMessage.AssistantContent))
|
||||
|
||||
const projectTerminalSnapshot = (draft: DraftAssistant, event: SessionEvent.Step.Ended | SessionEvent.Step.Failed) => {
|
||||
if (event.data.snapshot || event.data.files)
|
||||
draft.snapshot = {
|
||||
@@ -85,9 +87,7 @@ export function update(adapter: Adapter, event: SessionEvent.DurableEvent) {
|
||||
"session.unarchived": () => Effect.void,
|
||||
"session.message.content.updated": (event) =>
|
||||
updateOwnedAssistant(event.data.messageID, (draft) => {
|
||||
draft.content = castDraft(
|
||||
Schema.decodeUnknownSync(Schema.Array(SessionMessage.AssistantContent))(event.data.content),
|
||||
)
|
||||
draft.content = castDraft(decodeAssistantContent(event.data.content))
|
||||
}),
|
||||
"session.usage.recorded": () => Effect.void,
|
||||
"session.agent.selected": (event) =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export * as SessionPrompt from "./prompt.js"
|
||||
|
||||
import { Base64, FileAttachment, Prompt } from "@opencode/schema/prompt"
|
||||
import { Base64, FileAttachment } from "@opencode/schema/prompt"
|
||||
import { PromptInput } from "@opencode/schema/prompt-input"
|
||||
import { SessionInbox } from "@opencode/schema/session-inbox"
|
||||
import type { Session } from "@opencode/schema/session"
|
||||
@@ -77,15 +77,13 @@ export const prepare = Effect.fn("SessionPrompt.prepare")(function* (request: {
|
||||
return {
|
||||
type: "user",
|
||||
payload: SessionInbox.UserPayload.make({
|
||||
...Prompt.make({
|
||||
text: input.text,
|
||||
agents: input.agents,
|
||||
files,
|
||||
skills: selected?.length ? selected : undefined,
|
||||
}),
|
||||
text: input.text,
|
||||
agents: input.agents,
|
||||
files,
|
||||
skills: selected?.length ? selected : undefined,
|
||||
metadata: event.metadata,
|
||||
}),
|
||||
delivery: SessionInbox.Delivery.make(event.delivery),
|
||||
delivery: event.delivery,
|
||||
} satisfies SessionInbox.Item
|
||||
}).pipe(instances.provide(request.session))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user