-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathupdate_comment.ts
More file actions
133 lines (125 loc) · 3.64 KB
/
Copy pathupdate_comment.ts
File metadata and controls
133 lines (125 loc) · 3.64 KB
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
126
127
128
129
130
131
132
133
import { truncate } from '@sim/utils/string'
import type { IssueCommentResponse, UpdateCommentParams } from '@/tools/github/types'
import { COMMENT_OUTPUT_PROPERTIES, USER_OUTPUT } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
export const updateCommentTool: ToolConfig<UpdateCommentParams, IssueCommentResponse> = {
id: 'github_update_comment',
name: 'GitHub Comment Updater',
description: 'Update an existing comment on a GitHub issue or pull request',
version: '1.0.0',
params: {
owner: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository owner',
},
repo: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Repository name',
},
comment_id: {
type: 'number',
required: true,
visibility: 'user-or-llm',
description: 'Comment ID',
},
body: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Updated comment content',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub API token',
},
},
request: {
url: (params) =>
`https://api.github.com/repos/${params.owner}/${params.repo}/issues/comments/${params.comment_id}`,
method: 'PATCH',
headers: (params) => ({
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${params.apiKey}`,
'X-GitHub-Api-Version': '2022-11-28',
}),
body: (params) => ({
body: params.body,
}),
},
transformResponse: async (response) => {
const data = await response.json()
const content = `Comment #${data.id} updated: "${truncate(data.body, 100)}"`
return {
success: true,
output: {
content,
metadata: {
id: data.id,
html_url: data.html_url,
body: data.body,
created_at: data.created_at,
updated_at: data.updated_at,
user: {
login: data.user.login,
id: data.user.id,
},
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable update confirmation' },
metadata: {
type: 'object',
description: 'Updated comment metadata',
properties: {
id: { type: 'number', description: 'Comment ID' },
html_url: { type: 'string', description: 'GitHub web URL' },
body: { type: 'string', description: 'Updated comment body' },
created_at: { type: 'string', description: 'Creation timestamp' },
updated_at: { type: 'string', description: 'Last update timestamp' },
user: {
type: 'object',
description: 'User who created the comment',
properties: {
login: { type: 'string', description: 'User login' },
id: { type: 'number', description: 'User ID' },
},
},
},
},
},
}
export const updateCommentV2Tool: ToolConfig = {
id: 'github_update_comment_v2',
name: updateCommentTool.name,
description: updateCommentTool.description,
version: '2.0.0',
params: updateCommentTool.params,
request: updateCommentTool.request,
oauth: updateCommentTool.oauth,
transformResponse: async (response: Response) => {
const comment = await response.json()
return {
success: true,
output: {
id: comment.id,
body: comment.body,
html_url: comment.html_url,
user: comment.user,
created_at: comment.created_at,
updated_at: comment.updated_at,
},
}
},
outputs: {
...COMMENT_OUTPUT_PROPERTIES,
user: USER_OUTPUT,
},
}