-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.go
More file actions
300 lines (260 loc) · 9.3 KB
/
Copy pathtypes.go
File metadata and controls
300 lines (260 loc) · 9.3 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package cursor
import (
"encoding/json"
"time"
)
const (
defaultBaseURL = "https://api.cursor.com"
defaultUserAgent = "cursor-go-sdk"
)
// Bool returns a pointer to b. It is useful for optional API booleans.
func Bool(b bool) *bool {
return &b
}
// String returns a pointer to s.
func String(s string) *string {
return &s
}
// Int returns a pointer to i.
func Int(i int) *int {
return &i
}
// AgentOptions configure the high-level cloud Agent facade.
//
// The public Cloud Agents REST API creates the durable agent together with the
// first prompt. When InitialPrompt is empty, CreateAgent returns a lazy handle
// and the first Send call creates the cloud agent.
type AgentOptions struct {
APIKey string
BaseURL string
HTTPClient HTTPDoer
UserAgent string
WaitInterval time.Duration
Name string
Model ModelSelection
Cloud CloudOptions
MCPServers map[string]MCPServerConfig
Agents map[string]AgentDefinition
AgentID string
InitialPrompt *SDKUserMessage
}
// CloudOptions describe the cloud runtime configuration.
type CloudOptions struct {
Env *AgentEnv
Repos []Repo
BranchName string
AutoGenerateBranch *bool
AutoCreatePR *bool
SkipReviewerRequest *bool
EnvVars map[string]string
WorkOnCurrentBranch *bool
}
// AgentEnv identifies the environment used by a cloud agent.
type AgentEnv struct {
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
}
// Repo configures a Git repository for a cloud agent.
type Repo struct {
URL string `json:"url,omitempty"`
StartingRef string `json:"startingRef,omitempty"`
PRURL string `json:"prUrl,omitempty"`
}
// PromptInput is the REST prompt shape accepted by the Cloud Agents API.
type PromptInput struct {
Text string `json:"text"`
Images []string `json:"images,omitempty"`
}
// SDKUserMessage is the TypeScript-style message shape. For the REST-backed
// cloud SDK, images with Data are sent as base64 strings. URL images are
// rejected because the documented REST API accepts base64 image inputs.
type SDKUserMessage struct {
Text string `json:"text"`
Images []SDKImage `json:"images,omitempty"`
}
// SDKImageDimension optionally describes an image size.
type SDKImageDimension struct {
Width int `json:"width"`
Height int `json:"height"`
}
// SDKImage is the TypeScript-style image input shape.
type SDKImage struct {
URL string `json:"url,omitempty"`
Data string `json:"data,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Dimension *SDKImageDimension `json:"dimension,omitempty"`
}
// ModelSelection selects a Cursor model and optional model-specific params.
type ModelSelection struct {
ID string `json:"id,omitempty"`
Params []ModelParameterValue `json:"params,omitempty"`
}
// ModelParameterValue is a selected per-model parameter value.
type ModelParameterValue struct {
ID string `json:"id"`
Value string `json:"value"`
}
// ModelParameterDefinition describes available values for a model parameter.
type ModelParameterDefinition struct {
ID string `json:"id"`
DisplayName string `json:"displayName,omitempty"`
Values []ModelParamChoice `json:"values,omitempty"`
}
// ModelParamChoice is one allowed value for a model parameter.
type ModelParamChoice struct {
Value string `json:"value"`
DisplayName string `json:"displayName,omitempty"`
}
// ModelVariant is a preset collection of model parameters.
type ModelVariant struct {
Params []ModelParameterValue `json:"params,omitempty"`
DisplayName string `json:"displayName"`
Description string `json:"description,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
}
// ModelListItem is returned by ListModels. It accepts both the richer
// TypeScript SDK catalog shape and the REST beta's string-only examples.
type ModelListItem struct {
ID string `json:"id"`
DisplayName string `json:"displayName,omitempty"`
Description string `json:"description,omitempty"`
Parameters []ModelParameterDefinition `json:"parameters,omitempty"`
Variants []ModelVariant `json:"variants,omitempty"`
}
// UnmarshalJSON accepts either "model-id" or a full model object.
func (m *ModelListItem) UnmarshalJSON(data []byte) error {
var id string
if err := json.Unmarshal(data, &id); err == nil {
m.ID = id
return nil
}
type modelListItem ModelListItem
var item modelListItem
if err := json.Unmarshal(data, &item); err != nil {
return err
}
*m = ModelListItem(item)
return nil
}
// MCPServerConfig mirrors the TypeScript SDK option shape. The public REST API
// may ignore or reject fields it does not yet support.
type MCPServerConfig struct {
Type string `json:"type,omitempty"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
Env map[string]string `json:"env,omitempty"`
CWD string `json:"cwd,omitempty"`
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Auth *MCPAuth `json:"auth,omitempty"`
}
// MCPAuth describes OAuth settings for an MCP server.
type MCPAuth struct {
ClientID string `json:"CLIENT_ID"`
ClientSecret string `json:"CLIENT_SECRET,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}
// AgentDefinition mirrors the TypeScript SDK subagent option shape.
type AgentDefinition struct {
Description string `json:"description"`
Prompt string `json:"prompt"`
Model json.RawMessage `json:"model,omitempty"`
MCPServers json.RawMessage `json:"mcpServers,omitempty"`
}
// AgentStatus is the durable agent lifecycle status.
type AgentStatus string
const (
AgentStatusActive AgentStatus = "ACTIVE"
AgentStatusArchived AgentStatus = "ARCHIVED"
)
// AgentInfo is durable cloud agent metadata.
type AgentInfo struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Summary string `json:"summary,omitempty"`
Status AgentStatus `json:"status,omitempty"`
Env *AgentEnv `json:"env,omitempty"`
Repos []Repo `json:"repos,omitempty"`
BranchName string `json:"branchName,omitempty"`
AutoGenerateBranch bool `json:"autoGenerateBranch,omitempty"`
AutoCreatePR bool `json:"autoCreatePR,omitempty"`
URL string `json:"url,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
LatestRunID string `json:"latestRunId,omitempty"`
Archived bool `json:"archived,omitempty"`
}
// AgentID returns the stable agent identifier.
func (a AgentInfo) AgentID() string {
return a.ID
}
// RunStatus is a cloud run lifecycle status.
type RunStatus string
const (
RunStatusCreating RunStatus = "CREATING"
RunStatusRunning RunStatus = "RUNNING"
RunStatusFinished RunStatus = "FINISHED"
RunStatusError RunStatus = "ERROR"
RunStatusCancelled RunStatus = "CANCELLED"
RunStatusExpired RunStatus = "EXPIRED"
)
// Terminal reports whether the status is terminal.
func (s RunStatus) Terminal() bool {
switch s {
case RunStatusFinished, RunStatusError, RunStatusCancelled, RunStatusExpired,
RunStatus("finished"), RunStatus("error"), RunStatus("cancelled"):
return true
default:
return false
}
}
// RunGitInfo contains cloud git metadata when the API returns it.
type RunGitInfo struct {
Branches []RunGitBranch `json:"branches,omitempty"`
}
// RunGitBranch describes a branch or PR created by a cloud run.
type RunGitBranch struct {
RepoURL string `json:"repoUrl,omitempty"`
Branch string `json:"branch,omitempty"`
PRURL string `json:"prUrl,omitempty"`
}
// RunResult is returned by Run.Wait.
type RunResult struct {
ID string `json:"id"`
AgentID string `json:"agentId,omitempty"`
Status RunStatus `json:"status"`
Result string `json:"result,omitempty"`
Model *ModelSelection `json:"model,omitempty"`
DurationMS int64 `json:"durationMs,omitempty"`
Git RunGitInfo `json:"git,omitempty"`
CreatedAt string `json:"createdAt,omitempty"`
UpdatedAt string `json:"updatedAt,omitempty"`
}
// Artifact is an agent-scoped file produced under the artifacts/ directory.
type Artifact struct {
Path string `json:"path"`
SizeBytes int64 `json:"sizeBytes"`
UpdatedAt string `json:"updatedAt"`
}
// ArtifactDownload contains a temporary presigned artifact URL.
type ArtifactDownload struct {
URL string `json:"url"`
ExpiresAt string `json:"expiresAt"`
}
// Repository describes a GitHub repository connected to Cursor.
type Repository struct {
URL string `json:"url"`
}
// User describes the API key owner.
type User struct {
APIKeyName string `json:"apiKeyName"`
CreatedAt string `json:"createdAt"`
UserEmail string `json:"userEmail,omitempty"`
}
// SubToken identifies a short-lived user-scoped worker token.
type SubToken struct {
AccessToken string `json:"accessToken"`
ExpiresAt string `json:"expiresAt"`
UserID int `json:"userId"`
TeamID int `json:"teamId"`
}