improvement(ai): stamp context attachments#9994
Open
Light2Dark wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant UI as Chat UI / Completion Trigger
participant Resolve as resolveChatContext
participant CompResolve as getAICompletionBodyWithAttachments
participant Shared as resolveContextAttachments (NEW)
participant Stamp as stampContextAttachment (NEW)
participant Registry as AI Context Registry
participant Store as Jotai Store
Note over UI,Store: Context attachment resolution (both paths)
UI->>Resolve: User edits message with @-mentions
UI->>CompResolve: "Generate with AI" triggered
Resolve->>Shared: resolveContextAttachments(input)
CompResolve->>Shared: resolveContextAttachments(input)
alt Input contains "@"
Shared->>Store: getAIContextRegistry(store)
Store-->>Shared: registry instance
Shared->>Registry: parseAllContextIds(input)
Registry-->>Shared: contextLocatorIds[]
alt Has context IDs
Shared->>Registry: formatContextForAI(contextIds)
Registry-->>Shared: plain text context
Shared->>Registry: getAttachmentsForContext(contextIds)
alt Success
Registry-->>Shared: FileUIPart[]
Shared->>Stamp: stampContextAttachment(attachment) (for each)
Stamp->>Stamp: Set providerMetadata.marimo.source = "context"
Stamp-->>Shared: Stamped FileUIPart
else Error
Registry-->>Shared: Error
Shared->>Shared: Log error, return no attachments
end
else No context IDs
Shared-->>Resolve: empty result
Shared-->>CompResolve: empty result
end
else No "@" in input
Shared-->>Resolve: empty result
Shared-->>CompResolve: empty result
end
Shared-->>Resolve: { plainText, contextIds, attachments }
Shared-->>CompResolve: { plainText, attachments }
Note over Resolve: Build MarimoContextUIPart
Resolve-->>UI: ResolvedChatContext
Note over CompResolve: Build AICompletionBodyWithAttachments
CompResolve-->>UI: body with context.plainText + attachments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📝 Summary
Follow-up to #9985. That PR introduced two parallel paths for resolving
@-context out of a prompt —resolveChatContext(chat) andgetAICompletionBodyWithAttachmentsOnly the chat path stamped its context-derived file attachments with
providerMetadata.marimo.source = "context". SoisContextAttachment— thepredicate used to dedupe context attachments on message edit — silently
returned
falsefor completion-path attachments. That's a latent footgun and adrift risk between the two code paths.
Why stamp attachments at all?
Some
@-mentions resolve to file attachments (e.g. a cell's image output) thatget appended to the user message alongside files the user uploaded by hand.
Once in the message the two are indistinguishable. The stamp lets
handleMessageEditre-resolve fresh context on edit while dropping only stalecontext attachments and preserving the user's own uploads.
📋 Pre-Review Checklist
✅ Merge Checklist