chat: reconcile history by canonical message identity

This commit is contained in:
2026-10-19 00:08:30 +01:00
parent 3187b0c06e
commit 7da3d54013
13 changed files with 189 additions and 15 deletions
+10
View File
@@ -82,6 +82,13 @@ func (c *Chat) call(ctx context.Context, method, path string, body any) ([]byte,
// (authenticated, bounded, directory-scoped). The endpoint returns the inbox
// envelope immediately; the reply arrives on Stream.
func (c *Chat) Prompt(ctx context.Context, id, text string) error {
return c.PromptWithMessageID(ctx, id, text, "")
}
// PromptWithMessageID forwards the caller's canonical message id to OpenCode.
// OpenCode persists this id in history, which is the only safe bridge between
// the live user echo and an authoritative history page.
func (c *Chat) PromptWithMessageID(ctx context.Context, id, text, messageID string) error {
if !sessionID.MatchString(id) {
return fmt.Errorf("invalid OpenCode session id")
}
@@ -92,6 +99,9 @@ func (c *Chat) Prompt(ctx context.Context, id, text string) error {
// the same "text" field, so one shape works on both backends without a
// second request format.
body := map[string]any{"text": text}
if messageID != "" {
body["id"] = messageID
}
if _, err := c.call(ctx, "post", "/api/session/"+id+"/prompt", body); err != nil {
return err
}