-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathcreate_milestone.ts
More file actions
176 lines (164 loc) · 4.71 KB
/
Copy pathcreate_milestone.ts
File metadata and controls
176 lines (164 loc) · 4.71 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { MILESTONE_CREATOR_OUTPUT, MILESTONE_V2_OUTPUT_PROPERTIES } from '@/tools/github/types'
import type { ToolConfig } from '@/tools/types'
interface CreateMilestoneParams {
owner: string
repo: string
title: string
state?: 'open' | 'closed'
description?: string
due_on?: string
apiKey: string
}
interface CreateMilestoneResponse {
success: boolean
output: {
content: string
metadata: {
number: number
title: string
description: string | null
state: string
html_url: string
due_on: string | null
open_issues: number
closed_issues: number
created_at: string
creator: { login: string }
}
}
}
export const createMilestoneTool: ToolConfig<CreateMilestoneParams, CreateMilestoneResponse> = {
id: 'github_create_milestone',
name: 'GitHub Create Milestone',
description: 'Create a milestone in a repository',
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',
},
title: {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Milestone title',
},
state: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'State: open or closed (default: open)',
default: 'open',
},
description: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Milestone description',
},
due_on: {
type: 'string',
required: false,
visibility: 'user-or-llm',
description: 'Due date (ISO 8601 format, e.g., 2024-12-31T23:59:59Z)',
},
apiKey: {
type: 'string',
required: true,
visibility: 'user-only',
description: 'GitHub API token',
},
},
request: {
url: (params) => `https://api.github.com/repos/${params.owner}/${params.repo}/milestones`,
method: 'POST',
headers: (params) => ({
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${params.apiKey}`,
'Content-Type': 'application/json',
'X-GitHub-Api-Version': '2022-11-28',
}),
body: (params) => ({
title: params.title,
state: params.state ?? 'open',
description: params.description,
due_on: params.due_on,
}),
},
transformResponse: async (response) => {
const data = await response.json()
const content = `Created milestone: ${data.title}
Number: ${data.number}
State: ${data.state}
Due: ${data.due_on ?? 'No due date'}
${data.html_url}`
return {
success: true,
output: {
content,
metadata: {
number: data.number,
title: data.title,
description: data.description ?? null,
state: data.state,
html_url: data.html_url,
due_on: data.due_on ?? null,
open_issues: data.open_issues,
closed_issues: data.closed_issues,
created_at: data.created_at,
creator: { login: data.creator?.login ?? 'unknown' },
},
},
}
},
outputs: {
content: { type: 'string', description: 'Human-readable result' },
metadata: {
type: 'object',
description: 'Milestone metadata',
properties: {
number: { type: 'number', description: 'Milestone number' },
title: { type: 'string', description: 'Title' },
description: { type: 'string', description: 'Description', optional: true },
state: { type: 'string', description: 'State' },
html_url: { type: 'string', description: 'Web URL' },
due_on: { type: 'string', description: 'Due date', optional: true },
open_issues: { type: 'number', description: 'Open issues count' },
closed_issues: { type: 'number', description: 'Closed issues count' },
created_at: { type: 'string', description: 'Creation date' },
creator: { type: 'object', description: 'Creator info' },
},
},
},
}
export const createMilestoneV2Tool: ToolConfig<CreateMilestoneParams, any> = {
id: 'github_create_milestone_v2',
name: createMilestoneTool.name,
description: createMilestoneTool.description,
version: '2.0.0',
params: createMilestoneTool.params,
request: createMilestoneTool.request,
transformResponse: async (response: Response) => {
const data = await response.json()
return {
success: true,
output: {
...data,
description: data.description ?? null,
due_on: data.due_on ?? null,
},
}
},
outputs: {
...MILESTONE_V2_OUTPUT_PROPERTIES,
creator: MILESTONE_CREATOR_OUTPUT,
},
}