@ai-sdk/harness-cursor 1.0.46 → 1.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,464 +1,406 @@
1
- // src/cursor-harness.ts
2
- import {
3
- commonTool
4
- } from "@ai-sdk/harness";
1
+ import { commonTool } from "@ai-sdk/harness";
5
2
  import { createACP } from "@ai-sdk/harness-acp";
6
- import { tool } from "@ai-sdk/provider-utils";
3
+ import { isRecord, safeParseJSON, tool } from "@ai-sdk/provider-utils";
7
4
  import { z } from "zod/v4";
8
-
9
- // src/version.ts
10
- var VERSION = true ? "1.0.46" : "0.0.0-test";
11
-
12
- // src/cursor-subscription.ts
13
- import { readFile } from "fs/promises";
14
- import { homedir } from "os";
15
- import { join } from "path";
16
- import {
17
- getJwtExpiresAt,
18
- isAccessTokenExpiringSoon,
19
- isHarnessAuthenticationEnvironment,
20
- isLinux,
21
- isMacOS,
22
- isWindows,
23
- readMacOSKeychainPassword,
24
- shouldResolveNativeSubscription
25
- } from "@ai-sdk/harness/utils";
26
- import { isRecord, safeParseJSON } from "@ai-sdk/provider-utils";
27
- async function resolveCursorSubscriptionEnvironment({
28
- auth,
29
- env
30
- }) {
31
- if (isHarnessAuthenticationEnvironment(auth)) return auth;
32
- if (!shouldResolveNativeSubscription({
33
- auth,
34
- env,
35
- hasDirectCredential: env.CURSOR_API_KEY != null
36
- })) {
37
- return env;
38
- }
39
- const subscription = await readCursorSubscription({ env });
40
- return subscription == null ? env : { ...env, CURSOR_API_KEY: subscription };
5
+ import { readFile } from "node:fs/promises";
6
+ import { homedir } from "node:os";
7
+ import { join } from "node:path";
8
+ import { getJwtExpiresAt, isAccessTokenExpiringSoon, isHarnessAuthenticationEnvironment, isLinux, isMacOS, isWindows, readMacOSKeychainPassword, shouldResolveNativeSubscription } from "@ai-sdk/harness/utils";
9
+ //#region src/version.ts
10
+ const VERSION = "1.0.48";
11
+ //#endregion
12
+ //#region src/cursor-subscription.ts
13
+ async function resolveCursorSubscriptionEnvironment({ auth, env }) {
14
+ if (isHarnessAuthenticationEnvironment(auth)) return auth;
15
+ if (!shouldResolveNativeSubscription({
16
+ auth,
17
+ env,
18
+ hasDirectCredential: env.CURSOR_API_KEY != null
19
+ })) return env;
20
+ const subscription = await readCursorSubscription({ env });
21
+ return subscription == null ? env : {
22
+ ...env,
23
+ CURSOR_API_KEY: subscription
24
+ };
41
25
  }
42
- async function readCursorSubscription({
43
- env = process.env,
44
- homeDirectory = homedir(),
45
- platform = process.platform
46
- } = {}) {
47
- if (env.AGENT_CLI_CREDENTIAL_STORE === "memory") return void 0;
48
- const authPath = resolveCursorAuthPath({ env, homeDirectory, platform });
49
- const text = await readFile(authPath, "utf8").catch(() => void 0);
50
- const fileCredential = text == null ? void 0 : await parseAccessToken(text);
51
- const accessToken = fileCredential ?? (isMacOS(platform) && env.AGENT_CLI_CREDENTIAL_STORE !== "file" ? await readMacOSKeychainPassword({
52
- service: "cursor-access-token",
53
- account: "cursor-user"
54
- }) : void 0);
55
- if (accessToken == null) return void 0;
56
- const expiresAt = await getJwtExpiresAt({ token: accessToken });
57
- if (expiresAt != null && isAccessTokenExpiringSoon({ expiresAt })) {
58
- throw new Error(
59
- "Cursor subscription access token is expiring soon. Run Cursor login again."
60
- );
61
- }
62
- return accessToken;
26
+ async function readCursorSubscription({ env = process.env, homeDirectory = homedir(), platform = process.platform } = {}) {
27
+ if (env.AGENT_CLI_CREDENTIAL_STORE === "memory") return void 0;
28
+ const authPath = resolveCursorAuthPath({
29
+ env,
30
+ homeDirectory,
31
+ platform
32
+ });
33
+ const text = await readFile(authPath, "utf8").catch(() => void 0);
34
+ const accessToken = (text == null ? void 0 : await parseAccessToken(text)) ?? (isMacOS(platform) && env.AGENT_CLI_CREDENTIAL_STORE !== "file" ? await readMacOSKeychainPassword({
35
+ service: "cursor-access-token",
36
+ account: "cursor-user"
37
+ }) : void 0);
38
+ if (accessToken == null) return void 0;
39
+ const expiresAt = await getJwtExpiresAt({ token: accessToken });
40
+ if (expiresAt != null && isAccessTokenExpiringSoon({ expiresAt })) throw new Error("Cursor subscription access token is expiring soon. Run Cursor login again.");
41
+ return accessToken;
63
42
  }
64
- function resolveCursorAuthPath({
65
- env,
66
- homeDirectory,
67
- platform
68
- }) {
69
- if (isWindows(platform)) {
70
- return join(
71
- env.APPDATA ?? join(homeDirectory, "AppData", "Roaming"),
72
- "Cursor",
73
- "auth.json"
74
- );
75
- }
76
- if (isLinux(platform)) {
77
- return join(
78
- env.XDG_CONFIG_HOME ?? join(homeDirectory, ".config"),
79
- "cursor",
80
- "auth.json"
81
- );
82
- }
83
- return join(homeDirectory, ".cursor", "auth.json");
43
+ function resolveCursorAuthPath({ env, homeDirectory, platform }) {
44
+ if (isWindows(platform)) return join(env.APPDATA ?? join(homeDirectory, "AppData", "Roaming"), "Cursor", "auth.json");
45
+ if (isLinux(platform)) return join(env.XDG_CONFIG_HOME ?? join(homeDirectory, ".config"), "cursor", "auth.json");
46
+ return join(homeDirectory, ".cursor", "auth.json");
84
47
  }
85
48
  async function parseAccessToken(text) {
86
- const parsed = await safeParseJSON({ text });
87
- if (!parsed.success || !isRecord(parsed.value)) return void 0;
88
- return typeof parsed.value.accessToken === "string" ? parsed.value.accessToken : void 0;
49
+ const parsed = await safeParseJSON({ text });
50
+ if (!parsed.success || !isRecord(parsed.value)) return void 0;
51
+ return typeof parsed.value.accessToken === "string" ? parsed.value.accessToken : void 0;
89
52
  }
90
-
91
- // src/cursor-harness.ts
92
- var CURSOR_CLIENT_APP = `ai-sdk-harness-cursor/${VERSION}`;
93
- var CURSOR_BUILTIN_TOOLS = {
94
- bash: {
95
- ...commonTool("bash", {
96
- nativeName: "shellToolCall",
97
- toolUseKind: "bash",
98
- inputSchema: z.looseObject({ command: z.string() })
99
- }),
100
- title: "Terminal"
101
- },
102
- delete: {
103
- ...tool({
104
- title: "Delete",
105
- inputSchema: z.looseObject({ path: z.string() })
106
- }),
107
- nativeName: "deleteToolCall",
108
- toolUseKind: "edit"
109
- },
110
- glob: {
111
- ...commonTool("glob", {
112
- nativeName: "globToolCall",
113
- toolUseKind: "readonly",
114
- inputSchema: z.looseObject({ pattern: z.string() })
115
- }),
116
- title: "Find"
117
- },
118
- grep: {
119
- ...commonTool("grep", {
120
- nativeName: "grepToolCall",
121
- toolUseKind: "readonly",
122
- inputSchema: z.looseObject({
123
- pattern: z.string(),
124
- path: z.string().optional()
125
- })
126
- }),
127
- title: "grep"
128
- },
129
- read: {
130
- ...tool({
131
- title: "Read",
132
- inputSchema: z.looseObject({ path: z.string() })
133
- }),
134
- nativeName: "readToolCall",
135
- toolUseKind: "readonly"
136
- },
137
- updateTodos: {
138
- ...tool({
139
- title: "Update TODOs",
140
- inputSchema: z.looseObject({
141
- _toolName: z.literal("updateTodos"),
142
- todos: z.array(
143
- z.looseObject({
144
- id: z.string(),
145
- content: z.string(),
146
- status: z.string()
147
- })
148
- ).optional()
149
- })
150
- }),
151
- nativeName: "updateTodosToolCall"
152
- },
153
- readTodos: {
154
- ...tool({
155
- title: "Read TODOs",
156
- inputSchema: z.looseObject({})
157
- }),
158
- nativeName: "readTodosToolCall",
159
- toolUseKind: "readonly"
160
- },
161
- edit: {
162
- ...tool({
163
- title: "Edit",
164
- inputSchema: z.looseObject({ path: z.string() })
165
- }),
166
- nativeName: "editToolCall",
167
- toolUseKind: "edit"
168
- },
169
- ls: {
170
- ...tool({
171
- title: "List",
172
- inputSchema: z.looseObject({ path: z.string() })
173
- }),
174
- nativeName: "lsToolCall",
175
- toolUseKind: "readonly"
176
- },
177
- readLints: {
178
- ...tool({
179
- title: "Read Lints",
180
- inputSchema: z.looseObject({ paths: z.array(z.string()) })
181
- }),
182
- nativeName: "readLintsToolCall",
183
- toolUseKind: "readonly"
184
- },
185
- semanticSearch: {
186
- ...tool({
187
- title: "Codebase Search",
188
- inputSchema: z.looseObject({ query: z.string() })
189
- }),
190
- nativeName: "semSearchToolCall",
191
- toolUseKind: "readonly"
192
- },
193
- createPlan: {
194
- ...tool({
195
- title: "Create Plan",
196
- inputSchema: z.looseObject({
197
- _toolName: z.literal("createPlan"),
198
- name: z.string().optional(),
199
- plan: z.string().optional()
200
- })
201
- }),
202
- nativeName: "createPlanToolCall"
203
- },
204
- webSearch: {
205
- ...tool({
206
- title: "Web Search",
207
- inputSchema: z.looseObject({ searchTerm: z.string() })
208
- }),
209
- nativeName: "webSearchToolCall",
210
- toolUseKind: "readonly"
211
- },
212
- task: {
213
- ...tool({
214
- title: "Task",
215
- inputSchema: z.looseObject({
216
- _toolName: z.literal("task"),
217
- prompt: z.string().optional(),
218
- description: z.string().optional(),
219
- subagentType: z.unknown().optional()
220
- })
221
- }),
222
- nativeName: "taskToolCall"
223
- },
224
- listMcpResources: {
225
- ...tool({
226
- title: "List MCP Resources",
227
- inputSchema: z.looseObject({ server: z.string().optional() })
228
- }),
229
- nativeName: "listMcpResourcesToolCall",
230
- toolUseKind: "readonly"
231
- },
232
- readMcpResource: {
233
- ...tool({
234
- title: "Fetch MCP Resource",
235
- inputSchema: z.looseObject({
236
- server: z.string().optional(),
237
- uri: z.string().optional(),
238
- downloadPath: z.string().optional()
239
- })
240
- }),
241
- nativeName: "readMcpResourceToolCall",
242
- toolUseKind: "readonly"
243
- },
244
- applyAgentDiff: {
245
- ...tool({
246
- title: "Apply Agent Diff",
247
- inputSchema: z.looseObject({ path: z.string().optional() })
248
- }),
249
- nativeName: "applyAgentDiffToolCall",
250
- toolUseKind: "edit"
251
- },
252
- fetch: {
253
- ...tool({
254
- title: "Fetch",
255
- inputSchema: z.looseObject({ url: z.string() })
256
- }),
257
- nativeName: "fetchToolCall",
258
- toolUseKind: "readonly"
259
- },
260
- switchMode: {
261
- ...tool({
262
- title: "Switch Mode",
263
- inputSchema: z.looseObject({
264
- targetModeId: z.string(),
265
- explanation: z.string().optional()
266
- })
267
- }),
268
- nativeName: "switchModeToolCall"
269
- },
270
- generateImage: {
271
- ...tool({
272
- title: "Generate Image",
273
- inputSchema: z.looseObject({
274
- _toolName: z.literal("generateImage"),
275
- description: z.string().optional(),
276
- filename: z.string().optional()
277
- })
278
- }),
279
- nativeName: "generateImageToolCall"
280
- },
281
- recordScreen: {
282
- ...tool({
283
- title: "Record Screen",
284
- inputSchema: z.looseObject({})
285
- }),
286
- nativeName: "recordScreenToolCall"
287
- },
288
- computerUse: {
289
- ...tool({
290
- title: "Computer Use",
291
- inputSchema: z.looseObject({
292
- action: z.string().optional(),
293
- coordinate: z.unknown().optional(),
294
- text: z.string().optional()
295
- })
296
- }),
297
- nativeName: "computerUseToolCall",
298
- toolUseKind: "bash"
299
- },
300
- writeShellStdin: {
301
- ...tool({
302
- title: "Write to stdin",
303
- inputSchema: z.looseObject({
304
- shellId: z.number().optional(),
305
- chars: z.string().optional()
306
- })
307
- }),
308
- nativeName: "writeShellStdinToolCall",
309
- toolUseKind: "bash"
310
- },
311
- reflect: {
312
- ...tool({
313
- title: "Reflect",
314
- inputSchema: z.looseObject({ reflection: z.string().optional() })
315
- }),
316
- nativeName: "reflectToolCall",
317
- toolUseKind: "readonly"
318
- },
319
- setupVmEnvironment: {
320
- ...tool({
321
- title: "Setup VM Environment",
322
- inputSchema: z.looseObject({})
323
- }),
324
- nativeName: "setupVmEnvironmentToolCall",
325
- toolUseKind: "bash"
326
- },
327
- replaceEnv: {
328
- ...tool({
329
- title: "Replace Environment",
330
- inputSchema: z.looseObject({})
331
- }),
332
- nativeName: "replaceEnvToolCall",
333
- toolUseKind: "bash"
334
- },
335
- startGrindExecution: {
336
- ...tool({
337
- title: "Start Grind Execution",
338
- inputSchema: z.looseObject({})
339
- }),
340
- nativeName: "startGrindExecutionToolCall",
341
- toolUseKind: "bash"
342
- },
343
- startGrindPlanning: {
344
- ...tool({
345
- title: "Start Grind Planning",
346
- inputSchema: z.looseObject({})
347
- }),
348
- nativeName: "startGrindPlanningToolCall",
349
- toolUseKind: "readonly"
350
- },
351
- webFetch: {
352
- ...tool({
353
- title: "Web Fetch",
354
- inputSchema: z.looseObject({ url: z.string() })
355
- }),
356
- nativeName: "webFetchToolCall",
357
- toolUseKind: "readonly"
358
- },
359
- reportBugfixResults: {
360
- ...tool({
361
- title: "Report Bugfix Results",
362
- inputSchema: z.looseObject({})
363
- }),
364
- nativeName: "reportBugfixResultsToolCall"
365
- }
53
+ //#endregion
54
+ //#region src/cursor-harness.ts
55
+ const CURSOR_CLIENT_APP = `ai-sdk-harness-cursor/${VERSION}`;
56
+ const CURSOR_BUILTIN_TOOLS = {
57
+ bash: {
58
+ ...commonTool("bash", {
59
+ nativeName: "shellToolCall",
60
+ toolUseKind: "bash",
61
+ inputSchema: z.looseObject({ command: z.string() })
62
+ }),
63
+ title: "Terminal"
64
+ },
65
+ delete: {
66
+ ...tool({
67
+ title: "Delete",
68
+ inputSchema: z.looseObject({ path: z.string() })
69
+ }),
70
+ nativeName: "deleteToolCall",
71
+ toolUseKind: "edit"
72
+ },
73
+ glob: {
74
+ ...commonTool("glob", {
75
+ nativeName: "globToolCall",
76
+ toolUseKind: "readonly",
77
+ inputSchema: z.looseObject({ pattern: z.string() })
78
+ }),
79
+ title: "Find"
80
+ },
81
+ grep: {
82
+ ...commonTool("grep", {
83
+ nativeName: "grepToolCall",
84
+ toolUseKind: "readonly",
85
+ inputSchema: z.looseObject({
86
+ pattern: z.string(),
87
+ path: z.string().optional()
88
+ })
89
+ }),
90
+ title: "grep"
91
+ },
92
+ read: {
93
+ ...tool({
94
+ title: "Read",
95
+ inputSchema: z.looseObject({ path: z.string() })
96
+ }),
97
+ nativeName: "readToolCall",
98
+ toolUseKind: "readonly"
99
+ },
100
+ updateTodos: {
101
+ ...tool({
102
+ title: "Update TODOs",
103
+ inputSchema: z.looseObject({
104
+ _toolName: z.literal("updateTodos"),
105
+ todos: z.array(z.looseObject({
106
+ id: z.string(),
107
+ content: z.string(),
108
+ status: z.string()
109
+ })).optional()
110
+ })
111
+ }),
112
+ nativeName: "updateTodosToolCall"
113
+ },
114
+ readTodos: {
115
+ ...tool({
116
+ title: "Read TODOs",
117
+ inputSchema: z.looseObject({})
118
+ }),
119
+ nativeName: "readTodosToolCall",
120
+ toolUseKind: "readonly"
121
+ },
122
+ edit: {
123
+ ...tool({
124
+ title: "Edit",
125
+ inputSchema: z.looseObject({ path: z.string() })
126
+ }),
127
+ nativeName: "editToolCall",
128
+ toolUseKind: "edit"
129
+ },
130
+ ls: {
131
+ ...tool({
132
+ title: "List",
133
+ inputSchema: z.looseObject({ path: z.string() })
134
+ }),
135
+ nativeName: "lsToolCall",
136
+ toolUseKind: "readonly"
137
+ },
138
+ readLints: {
139
+ ...tool({
140
+ title: "Read Lints",
141
+ inputSchema: z.looseObject({ paths: z.array(z.string()) })
142
+ }),
143
+ nativeName: "readLintsToolCall",
144
+ toolUseKind: "readonly"
145
+ },
146
+ semanticSearch: {
147
+ ...tool({
148
+ title: "Codebase Search",
149
+ inputSchema: z.looseObject({ query: z.string() })
150
+ }),
151
+ nativeName: "semSearchToolCall",
152
+ toolUseKind: "readonly"
153
+ },
154
+ createPlan: {
155
+ ...tool({
156
+ title: "Create Plan",
157
+ inputSchema: z.looseObject({
158
+ _toolName: z.literal("createPlan"),
159
+ name: z.string().optional(),
160
+ plan: z.string().optional()
161
+ })
162
+ }),
163
+ nativeName: "createPlanToolCall"
164
+ },
165
+ webSearch: {
166
+ ...tool({
167
+ title: "Web Search",
168
+ inputSchema: z.looseObject({ searchTerm: z.string() })
169
+ }),
170
+ nativeName: "webSearchToolCall",
171
+ toolUseKind: "readonly"
172
+ },
173
+ task: {
174
+ ...tool({
175
+ title: "Task",
176
+ inputSchema: z.looseObject({
177
+ _toolName: z.literal("task"),
178
+ prompt: z.string().optional(),
179
+ description: z.string().optional(),
180
+ subagentType: z.unknown().optional()
181
+ })
182
+ }),
183
+ nativeName: "taskToolCall"
184
+ },
185
+ listMcpResources: {
186
+ ...tool({
187
+ title: "List MCP Resources",
188
+ inputSchema: z.looseObject({ server: z.string().optional() })
189
+ }),
190
+ nativeName: "listMcpResourcesToolCall",
191
+ toolUseKind: "readonly"
192
+ },
193
+ readMcpResource: {
194
+ ...tool({
195
+ title: "Fetch MCP Resource",
196
+ inputSchema: z.looseObject({
197
+ server: z.string().optional(),
198
+ uri: z.string().optional(),
199
+ downloadPath: z.string().optional()
200
+ })
201
+ }),
202
+ nativeName: "readMcpResourceToolCall",
203
+ toolUseKind: "readonly"
204
+ },
205
+ applyAgentDiff: {
206
+ ...tool({
207
+ title: "Apply Agent Diff",
208
+ inputSchema: z.looseObject({ path: z.string().optional() })
209
+ }),
210
+ nativeName: "applyAgentDiffToolCall",
211
+ toolUseKind: "edit"
212
+ },
213
+ fetch: {
214
+ ...tool({
215
+ title: "Fetch",
216
+ inputSchema: z.looseObject({ url: z.string() })
217
+ }),
218
+ nativeName: "fetchToolCall",
219
+ toolUseKind: "readonly"
220
+ },
221
+ switchMode: {
222
+ ...tool({
223
+ title: "Switch Mode",
224
+ inputSchema: z.looseObject({
225
+ targetModeId: z.string(),
226
+ explanation: z.string().optional()
227
+ })
228
+ }),
229
+ nativeName: "switchModeToolCall"
230
+ },
231
+ generateImage: {
232
+ ...tool({
233
+ title: "Generate Image",
234
+ inputSchema: z.looseObject({
235
+ _toolName: z.literal("generateImage"),
236
+ description: z.string().optional(),
237
+ filename: z.string().optional()
238
+ })
239
+ }),
240
+ nativeName: "generateImageToolCall"
241
+ },
242
+ recordScreen: {
243
+ ...tool({
244
+ title: "Record Screen",
245
+ inputSchema: z.looseObject({})
246
+ }),
247
+ nativeName: "recordScreenToolCall"
248
+ },
249
+ computerUse: {
250
+ ...tool({
251
+ title: "Computer Use",
252
+ inputSchema: z.looseObject({
253
+ action: z.string().optional(),
254
+ coordinate: z.unknown().optional(),
255
+ text: z.string().optional()
256
+ })
257
+ }),
258
+ nativeName: "computerUseToolCall",
259
+ toolUseKind: "bash"
260
+ },
261
+ writeShellStdin: {
262
+ ...tool({
263
+ title: "Write to stdin",
264
+ inputSchema: z.looseObject({
265
+ shellId: z.number().optional(),
266
+ chars: z.string().optional()
267
+ })
268
+ }),
269
+ nativeName: "writeShellStdinToolCall",
270
+ toolUseKind: "bash"
271
+ },
272
+ reflect: {
273
+ ...tool({
274
+ title: "Reflect",
275
+ inputSchema: z.looseObject({ reflection: z.string().optional() })
276
+ }),
277
+ nativeName: "reflectToolCall",
278
+ toolUseKind: "readonly"
279
+ },
280
+ setupVmEnvironment: {
281
+ ...tool({
282
+ title: "Setup VM Environment",
283
+ inputSchema: z.looseObject({})
284
+ }),
285
+ nativeName: "setupVmEnvironmentToolCall",
286
+ toolUseKind: "bash"
287
+ },
288
+ replaceEnv: {
289
+ ...tool({
290
+ title: "Replace Environment",
291
+ inputSchema: z.looseObject({})
292
+ }),
293
+ nativeName: "replaceEnvToolCall",
294
+ toolUseKind: "bash"
295
+ },
296
+ startGrindExecution: {
297
+ ...tool({
298
+ title: "Start Grind Execution",
299
+ inputSchema: z.looseObject({})
300
+ }),
301
+ nativeName: "startGrindExecutionToolCall",
302
+ toolUseKind: "bash"
303
+ },
304
+ startGrindPlanning: {
305
+ ...tool({
306
+ title: "Start Grind Planning",
307
+ inputSchema: z.looseObject({})
308
+ }),
309
+ nativeName: "startGrindPlanningToolCall",
310
+ toolUseKind: "readonly"
311
+ },
312
+ webFetch: {
313
+ ...tool({
314
+ title: "Web Fetch",
315
+ inputSchema: z.looseObject({ url: z.string() })
316
+ }),
317
+ nativeName: "webFetchToolCall",
318
+ toolUseKind: "readonly"
319
+ },
320
+ reportBugfixResults: {
321
+ ...tool({
322
+ title: "Report Bugfix Results",
323
+ inputSchema: z.looseObject({})
324
+ }),
325
+ nativeName: "reportBugfixResultsToolCall"
326
+ }
366
327
  };
367
328
  function createCursor(settings = {}) {
368
- const clientAppSegments = CURSOR_CLIENT_APP.split("/");
369
- const clientAppVersion = clientAppSegments.pop();
370
- if (settings.auth === "direct" || settings.auth === "ai-gateway") {
371
- warnCursorAuthenticationConfiguration({ auth: settings.auth });
372
- }
373
- return createACP({
374
- auth: settings.auth,
375
- resolveAuthenticationEnvironment: resolveCursorSubscriptionEnvironment,
376
- credentialForwarding: settings.credentialForwarding,
377
- port: settings.port,
378
- portEndpoint: settings.portEndpoint,
379
- startupTimeoutMs: settings.startupTimeoutMs,
380
- reconnect: settings.reconnect,
381
- mcpServers: settings.mcpServers,
382
- isMcpToolCall: (toolCall) => {
383
- const rawInput = toolCall.rawInput;
384
- return isRecord2(rawInput) && typeof rawInput.providerIdentifier === "string" && typeof rawInput.toolName === "string" && isRecord2(rawInput.args);
385
- },
386
- mintBridgeToken: settings.mintBridgeToken,
387
- version: "v1",
388
- harnessId: "cursor",
389
- builtinTools: CURSOR_BUILTIN_TOOLS,
390
- clientApp: {
391
- name: clientAppSegments.join("/"),
392
- version: clientAppVersion
393
- },
394
- source: {
395
- type: "install-command",
396
- command: "curl https://cursor.com/install -fsS | bash"
397
- },
398
- executable: "agent",
399
- args: ["--disable-auto-update", "acp"],
400
- modelMapping: {
401
- type: "session-config-option",
402
- path: "model"
403
- },
404
- clientCapabilities: {
405
- _meta: { parameterizedModelPicker: true }
406
- },
407
- credentialEnv: ["CURSOR_API_KEY"],
408
- credentialBrokering: ({ env, sandboxEnv, headers }) => {
409
- const transformations = [];
410
- if (env.CURSOR_API_KEY && sandboxEnv?.CURSOR_API_KEY) {
411
- transformations.push({
412
- match: {
413
- host: "api2.cursor.sh",
414
- path: { exact: "/auth/exchange_user_api_key" },
415
- method: ["POST"],
416
- headers: [
417
- {
418
- key: { exact: "Authorization" },
419
- value: {
420
- exact: `Bearer ${sandboxEnv.CURSOR_API_KEY}`
421
- }
422
- }
423
- ]
424
- },
425
- transform: {
426
- headers: {
427
- Authorization: `Bearer ${env.CURSOR_API_KEY}`
428
- }
429
- }
430
- });
431
- }
432
- if (headers != null) {
433
- transformations.push({
434
- match: settings.auth === "ai-gateway" ? {
435
- host: "ai-gateway.vercel.sh",
436
- path: { startsWith: "/cursor/v1" }
437
- } : { host: "api2.cursor.sh" },
438
- transform: { headers }
439
- });
440
- }
441
- return transformations;
442
- }
443
- });
329
+ const clientAppSegments = CURSOR_CLIENT_APP.split("/");
330
+ const clientAppVersion = clientAppSegments.pop();
331
+ if (settings.auth === "direct" || settings.auth === "ai-gateway") warnCursorAuthenticationConfiguration({ auth: settings.auth });
332
+ return createACP({
333
+ auth: settings.auth,
334
+ resolveAuthenticationEnvironment: resolveCursorSubscriptionEnvironment,
335
+ credentialForwarding: settings.credentialForwarding,
336
+ port: settings.port,
337
+ portEndpoint: settings.portEndpoint,
338
+ startupTimeoutMs: settings.startupTimeoutMs,
339
+ reconnect: settings.reconnect,
340
+ mcpServers: settings.mcpServers,
341
+ isMcpToolCall: (toolCall) => {
342
+ const rawInput = toolCall.rawInput;
343
+ return isRecord$1(rawInput) && typeof rawInput.providerIdentifier === "string" && typeof rawInput.toolName === "string" && isRecord$1(rawInput.args);
344
+ },
345
+ mintBridgeToken: settings.mintBridgeToken,
346
+ version: "v1",
347
+ harnessId: "cursor",
348
+ builtinTools: CURSOR_BUILTIN_TOOLS,
349
+ clientApp: {
350
+ name: clientAppSegments.join("/"),
351
+ version: clientAppVersion
352
+ },
353
+ source: {
354
+ type: "install-command",
355
+ command: "curl https://cursor.com/install -fsS | bash"
356
+ },
357
+ executable: "agent",
358
+ args: ["--disable-auto-update", "acp"],
359
+ modelMapping: {
360
+ type: "session-config-option",
361
+ path: "model"
362
+ },
363
+ clientCapabilities: { _meta: { parameterizedModelPicker: true } },
364
+ credentialEnv: ["CURSOR_API_KEY"],
365
+ credentialBrokering: ({ env, sandboxEnv, headers }) => {
366
+ const transformations = [];
367
+ if (env.CURSOR_API_KEY && sandboxEnv?.CURSOR_API_KEY) transformations.push({
368
+ match: {
369
+ host: "api2.cursor.sh",
370
+ path: { exact: "/auth/exchange_user_api_key" },
371
+ method: ["POST"],
372
+ headers: [{
373
+ key: { exact: "Authorization" },
374
+ value: { exact: `Bearer ${sandboxEnv.CURSOR_API_KEY}` }
375
+ }]
376
+ },
377
+ transform: { headers: { Authorization: `Bearer ${env.CURSOR_API_KEY}` } }
378
+ });
379
+ if (headers != null) transformations.push({
380
+ match: settings.auth === "ai-gateway" ? {
381
+ host: "ai-gateway.vercel.sh",
382
+ path: { startsWith: "/cursor/v1" }
383
+ } : { host: "api2.cursor.sh" },
384
+ transform: { headers }
385
+ });
386
+ return transformations;
387
+ }
388
+ });
444
389
  }
445
- function warnCursorAuthenticationConfiguration({
446
- auth
447
- }) {
448
- const detail = auth === "ai-gateway" ? "Configure an AI Gateway API key as Cursor's OpenAI API key and set Override OpenAI Base URL to https://ai-gateway.vercel.sh/cursor/v1." : "Configure Cursor to use its direct model-provider routing.";
449
- console.warn(
450
- `[cursor] auth: ${JSON.stringify(auth)} cannot configure Cursor provider authentication. ${detail} CURSOR_API_KEY is still required for Cursor CLI authentication.`
451
- );
390
+ function warnCursorAuthenticationConfiguration({ auth }) {
391
+ const detail = auth === "ai-gateway" ? "Configure an AI Gateway API key as Cursor's OpenAI API key and set Override OpenAI Base URL to https://ai-gateway.vercel.sh/cursor/v1." : "Configure Cursor to use its direct model-provider routing.";
392
+ console.warn(`[cursor] auth: ${JSON.stringify(auth)} cannot configure Cursor provider authentication. ${detail} CURSOR_API_KEY is still required for Cursor CLI authentication.`);
452
393
  }
453
- function isRecord2(value) {
454
- return value != null && typeof value === "object" && !Array.isArray(value);
394
+ function isRecord$1(value) {
395
+ return value != null && typeof value === "object" && !Array.isArray(value);
455
396
  }
397
+ //#endregion
398
+ //#region src/index.ts
399
+ /**
400
+ * Default Cursor harness instance. Equivalent to `createCursor()`.
401
+ */
402
+ const cursor = createCursor();
403
+ //#endregion
404
+ export { VERSION, createCursor, cursor };
456
405
 
457
- // src/index.ts
458
- var cursor = createCursor();
459
- export {
460
- VERSION,
461
- createCursor,
462
- cursor
463
- };
464
406
  //# sourceMappingURL=index.js.map