-
-
Notifications
You must be signed in to change notification settings - Fork 15
Update attachments API to support cells & selection ranges #247
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, makes sense.
Thank you for working on this @dlqqq.
Nice! I have some ideas for how we could improve the attachment architecture for text files and notebooks that will only require minor changes to this PR. We’ll post the ideas later this weekend or Monday. Thanks for working on this. |
Brian raises a good point. Using |
1e80ce3
to
e0eebf7
Compare
@ellisonbg @brichet All comments have been addressed! Thank you both for the code review.
@andrii-i This does introduce some breaking changes to the API you are using in #248, FYI. May be good to try creating a new branch that uses this as its base. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated types and interfaces look good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating it @dlqqq.
I have one requirement below, otherwise it looks good to me.
Co-authored-by: Nicolas Brichet <32258950+brichet@users.noreply.github.com>
TY! Merging. 👍 |
Nice work folks!
…On Wed, Jul 2, 2025 at 11:09 AM David L. Qiu ***@***.***> wrote:
Merged #247 <#247> into
main.
—
Reply to this email directly, view it on GitHub
<#247 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGXUGVBPCVJN43PD4AFAL3GQN5DAVCNFSM6AAAAACAJ67D2GVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJYGQZTOMZQGMYTEMQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Brian E. Granger
Senior Principal Technologist, AWS AI/ML ***@***.***)
On Leave - Professor of Physics and Data Science, Cal Poly
@ellisonbg on GitHub
|
*/ | ||
export interface IAttachment { | ||
export type IAttachment = IFileAttachment | INotebookAttachment; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I missed this change from interface
to type
in the review.
Does it means that other extensions will not be able to extends it anymore, and creates their own attachment object ?
IIUC, only attachment types defined in @jupyter/chat
will now be allowed as attachment.
@dlqqq don't you think that we should/could revert this change ?
I wonder if IFileAttachment
and INotebookAttachment
could not implement IAttachment
, instead of having a type ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be helpful if this API was extensible, but @brichet not sure how it being an interface will help as each document type will likely have different metadata. Can you give more details about how this might work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, the IAttachment
interface (prior to this PR) probably didn't support any type of attachment (e.g. selection
and cells
options).
The attachment could be a minimal interface like
export interface IAttachment {
type: string;
value: string;
content: any; // could be anything that is JSON serializable.
}
Then we would have
export interface IFileAttachment extends IAttachment {
type: 'file';
content: {
mimetype?: string;
selection?: IAttachmentSelection;
};
}
export interface INotebookAttachment extends IAttachment {
type: 'notebook';
content: {
cells?: INotebookAttachmentCell[];
};
}
The attachmentOpenerRegistry
already allows to set a dedicated function for each attachment type.
Maybe we should update this registry to also allow a displayName()
function (e.g. attachmentManagerRegistry
), now that the display name is configurable.
Like that, any attachment that extends this interface would be compatible with the message and input attachments.
Do you think it could work like that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds reasonable, @dlqqq is OOTO for a few days and would love to get his take on this.
Description
This PR updates the attachments API to support attaching individual notebook cells and including selection ranges within both file & cell attachments.
This PR is being opened to prepare the
main
branch for @andrii-i's work, which will allow users to drag & drop notebook cells or selection ranges into the chat. This PR only changes the API, and should not have any user-facing impact in the application.Technical details
Currently, each attachment is assigned an ID based on its
type
andvalue
, and stored in a dictionary within the YChat model. When a user re-attaches a file with the sametype
andvalue
, the matching entry in the attachments is updated, and the same ID is returned. This is defined in theset_attachment()
method.However, consider this scenario:
untitled.txt
and sends the messageuntitled.txt
If the existing logic were used, operation 2) would override the attachment entry added by operation 1). Hence, the
set_attachment()
method has been updated to always create a new ID for attachments w/ selections.