-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
125 lines (110 loc) · 2.91 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// types from https://github.com/github-technology-partners/copilot-partners/blob/main/docs/request-response-format.md
import { ChatCompletionMessageToolCall } from 'openai/resources'
enum CopilotEventTypes {
copilot_confirmation = 'copilot_confirmation', // send user references
copilot_errors = 'copilot_errors', // send a user a confirmation
copilot_references = 'copilot_references', // send user an error
}
export enum CopilotErrorType {
agent = 'agent',
function = 'function',
reference = 'reference',
}
export enum CopilotErrorCodes {
githubError = '100',
readmeError = '101',
confirmationError = '102',
}
export interface GenerateCopilotErrorArgs {
code: CopilotErrorCodes
identifier?: string
message: string
originalError?: Error
type: CopilotErrorType
}
enum GitHubMessageConfirmationState {
accepted = 'accepted',
dismissed = 'dismissed',
}
export interface GitHubMessageConfirmations {
confirmation: {
id: string
functionName: string
args: Record<string, string>
}
state: GitHubMessageConfirmationState
}
export interface GithubReference {
type: string
data: {
type: string
} & Record<string, unknown>
id: string
is_implicit: boolean
metadata: {
display_name: string
display_icon: string
display_url: string
}
}
export type CopilotMessage = {
content: string
copilot_confirmations?: GitHubMessageConfirmations[]
copilot_references?: GithubReference[]
}
export type GitHubMessage = { role: string } & (
| CopilotMessage
| {
tool_calls?: ChatCompletionMessageToolCall[]
}
| {
name: string
tool_call_id: string
content: string
}
)
export interface GenerateAgentResponseArgs {
customization: Record<string, string>
history: GitHubMessage[]
projectName: string
subdomains: string[]
token: string
}
export type CopilotRequest = {
copilot_thread_id: string
messages: GitHubMessage[]
stop: null | string
top_p: number
temperature: number
max_tokens: number
presence_penalty: number
frequency_penalty: number
copilot_skills: Record<string, string | number>[]
agent: string
}
export class CopilotError extends Error {
code: CopilotErrorCodes
type: CopilotErrorType
identifier: string
originalError: Error | undefined
constructor({ code, type, message, identifier, originalError }: GenerateCopilotErrorArgs) {
super(message)
this.name = 'CopilotError'
this.code = code
this.type = type
this.identifier = identifier || 'error'
this.originalError = originalError
}
generateCopilotError() {
// this format is required by the client
// see: https://github.com/github-technology-partners/copilot-partners/blob/main/docs/copilot-errors.md
return `event: ${CopilotEventTypes.copilot_errors}\ndata: ${JSON.stringify([
{
type: this.type,
code: this.code,
message: this.message,
identifier: this.identifier,
},
])}\n\n`
}
}