Skip to content

Commit ad724d1

Browse files
authored
chore: update attachment types to include selection support
1 parent c20c421 commit ad724d1

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

nodejs/src/types.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -803,13 +803,30 @@ export interface MessageOptions {
803803
prompt: string;
804804

805805
/**
806-
* File or directory attachments
807-
*/
808-
attachments?: Array<{
809-
type: "file" | "directory";
810-
path: string;
811-
displayName?: string;
812-
}>;
806+
* File, directory, or selection attachments
807+
*/
808+
attachments?: Array<
809+
| {
810+
type: "file";
811+
path: string;
812+
displayName?: string;
813+
}
814+
| {
815+
type: "directory";
816+
path: string;
817+
displayName?: string;
818+
}
819+
| {
820+
type: "selection";
821+
filePath: string;
822+
displayName: string;
823+
selection?: {
824+
start: { line: number; character: number };
825+
end: { line: number; character: number };
826+
};
827+
text?: string;
828+
}
829+
>;
813830

814831
/**
815832
* Message delivery mode

python/copilot/types.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,45 @@
2626
LogLevel = Literal["none", "error", "warning", "info", "debug", "all"]
2727

2828

29-
# Attachment type
30-
class Attachment(TypedDict):
31-
type: Literal["file", "directory"]
29+
# Selection range for text attachments
30+
class SelectionRange(TypedDict):
31+
line: int
32+
character: int
33+
34+
35+
class Selection(TypedDict):
36+
start: SelectionRange
37+
end: SelectionRange
38+
39+
40+
# Attachment types - discriminated union based on 'type' field
41+
class FileAttachment(TypedDict):
42+
"""File attachment."""
43+
type: Literal["file"]
44+
path: str
45+
displayName: NotRequired[str]
46+
47+
48+
class DirectoryAttachment(TypedDict):
49+
"""Directory attachment."""
50+
type: Literal["directory"]
3251
path: str
3352
displayName: NotRequired[str]
3453

3554

55+
class SelectionAttachment(TypedDict):
56+
"""Selection attachment with text from a file."""
57+
type: Literal["selection"]
58+
filePath: str
59+
displayName: str
60+
selection: NotRequired[Selection]
61+
text: NotRequired[str]
62+
63+
64+
# Attachment type - union of all attachment types
65+
Attachment = Union[FileAttachment, DirectoryAttachment, SelectionAttachment]
66+
67+
3668
# Options for creating a CopilotClient
3769
class CopilotClientOptions(TypedDict, total=False):
3870
"""Options for creating a CopilotClient"""

0 commit comments

Comments
 (0)