GeezerVison is showing github.com — fix(session): support assistant message content updates by nexxeln · Pull Request #45015 · anomalyco/opencode
fix(session): support assistant message content updates
#45015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement . We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ts
(3)
All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
refactor(session): use specific message update errors
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit a4162b9c8a6051c263fa44b77bb6019cb66dfdf8
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -139,11 +139,27 @@ export class CompactionConflictError extends Schema.TaggedError<CompactionConfli
export class BusyError extends Schema.TaggedError<BusyError>()("Session.BusyError", {
sessionID: SessionSchema.ID,
}) {}
export class MessageUpdateError extends Schema.TaggedError<MessageUpdateError>()("Session.MessageUpdateError", {
sessionID: SessionSchema.ID,
messageID: SessionMessage.ID,
reason: Schema.Literals(["not_assistant", "incomplete", "unfinished_tool"]),
}) {}
export class MessageNotAssistantError extends Schema.TaggedError<MessageNotAssistantError>()(
"Session.MessageNotAssistantError",
{
sessionID: SessionSchema.ID,
messageID: SessionMessage.ID,
},
) {}
export class MessageIncompleteError extends Schema.TaggedError<MessageIncompleteError>()(
"Session.MessageIncompleteError",
{
sessionID: SessionSchema.ID,
messageID: SessionMessage.ID,
},
) {}
export class MessageToolIncompleteError extends Schema.TaggedError<MessageToolIncompleteError>()(
"Session.MessageToolIncompleteError",
{
sessionID: SessionSchema.ID,
messageID: SessionMessage.ID,
},
) {}
export class InboxConflictError extends Schema.TaggedError<InboxConflictError>()("Session.InboxConflictError", {
sessionID: SessionSchema.ID,
inboxID: SessionMessage.ID,
Expand Down
Expand Up
@@ -202,7 +218,15 @@ export interface Interface {
readonly sessionID: SessionSchema.ID
readonly messageID: SessionMessage.ID
readonly content: readonly SessionMessage.AssistantContent[]
}) => Effect.Effect<SessionMessage.Assistant, NotFoundError | MessageNotFoundError | BusyError | MessageUpdateError>
}) => Effect.Effect<
SessionMessage.Assistant,
| NotFoundError
| MessageNotFoundError
| BusyError
| MessageNotAssistantError
| MessageIncompleteError
| MessageToolIncompleteError
>
readonly context: (
sessionID: SessionSchema.ID,
) => Effect.Effect<SessionMessage.Info[], NotFoundError | MessageDecodeError>
Expand Down
Expand Up
@@ -576,28 +600,16 @@ const layer = Layer.effect(
const message = yield* result.message(input)
if (!message) return yield* new MessageNotFoundError({ sessionID: input.sessionID, messageID: input.messageID })
if (message.type !== "assistant")
return yield* new MessageUpdateError({
sessionID: input.sessionID,
messageID: input.messageID,
reason: "not_assistant",
})
return yield* new MessageNotAssistantError({ sessionID: input.sessionID, messageID: input.messageID })
if (!message.time.completed)
return yield* new MessageUpdateError({
sessionID: input.sessionID,
messageID: input.messageID,
reason: "incomplete",
})
return yield* new MessageIncompleteError({ sessionID: input.sessionID, messageID: input.messageID })
if (
input.content.some(
(content) =>
content.type === "tool" && (content.state.status === "streaming" || content.state.status === "running"),
)
)
return yield* new MessageUpdateError({
sessionID: input.sessionID,
messageID: input.messageID,
reason: "unfinished_tool",
})
return yield* new MessageToolIncompleteError({ sessionID: input.sessionID, messageID: input.messageID })
yield* bus.publish(SessionEvent.MessageContentUpdated, {
sessionID: input.sessionID,
messageID: input.messageID,
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -206,14 +206,12 @@ describe("Session.updateMessage", () => {
expect(
yield* Effect.flip(session.updateMessage({ sessionID: created.id, messageID: syntheticID, content: [] })),
).toEqual(
new Session.MessageUpdateError({ sessionID: created.id, messageID: syntheticID, reason: "not_assistant" }),
)
).toEqual(new Session.MessageNotAssistantError({ sessionID: created.id, messageID: syntheticID }))
const messageID = SessionMessage.ID.create()
yield* start(bus, created.id, messageID)
expect(yield* Effect.flip(session.updateMessage({ sessionID: created.id, messageID, content: [] }))).toEqual(
new Session.MessageUpdateError ({ sessionID: created.id, messageID, reason: "incomplete" }),
new Session.MessageIncompleteError ({ sessionID: created.id, messageID }),
)
yield* complete(bus, created.id, messageID)
Expand All
@@ -226,7 +224,7 @@ describe("Session.updateMessage", () => {
})
expect(
yield* Effect.flip(session.updateMessage({ sessionID: created.id, messageID, content: [unfinished] })),
).toEqual(new Session.MessageUpdateError ({ sessionID: created.id, messageID, reason: "unfinished_tool" }))
).toEqual(new Session.MessageToolIncompleteError ({ sessionID: created.id, messageID }))
}),
)
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -644,18 +644,17 @@ export const SessionHandler = HttpApiBuilder.group(Api, "server.session", (handl
}),
),
Effect.catchTag("Session.BusyError", busySession),
Effect.catchTag("Session.MessageUpdateError", (error) =>
Effect.fail(
error.reason === "incomplete"
? new ConflictError({ message: "Assistant message is incomplete", resource: error.messageID })
: new InvalidRequestError({
message:
error.reason === "not_assistant"
? "Only assistant messages can be updated"
: "Tool content must be completed",
field: error.reason === "not_assistant" ? "messageID" : "content",
}),
),
Effect.catchTag(
"Session.MessageNotAssistantError",
() => new InvalidRequestError({ message: "Only assistant messages can be updated", field: "messageID" }),
),
Effect.catchTag(
"Session.MessageIncompleteError",
(error) => new ConflictError({ message: "Assistant message is incomplete", resource: error.messageID }),
),
Effect.catchTag(
"Session.MessageToolIncompleteError",
() => new InvalidRequestError({ message: "Tool content must be completed", field: "content" }),
),
)
return { data: message }
Expand Down
Loading
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.