@mastra/cursor 0.1.0 → 0.2.0-alpha.0
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/CHANGELOG.md +34 -0
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-sdk-agents.md +168 -4
- package/dist/index.cjs +64 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +39 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +64 -6
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +5 -2
- package/dist/utils.d.ts.map +1 -1
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @mastra/cursor
|
|
2
2
|
|
|
3
|
+
## 0.2.0-alpha.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Added structured output support for Claude and OpenAI SDK agents using their provider-native structured output APIs. Cursor SDK agent calls now fail clearly when structuredOutput is requested because the Cursor TypeScript SDK does not expose a schema-constrained output API. SDK agents now implement provider-native resume through Mastra's existing resumeGenerate/resumeStream methods by accepting provider-specific resumeData with a message payload. Cursor SDK agent options now use the same clear source split as OpenAI: pass either a pre-created agent or SDK options for wrapper-created agents. ([#17580](https://github.com/mastra-ai/mastra/pull/17580))
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
await claudeAgent.resumeGenerate({
|
|
13
|
+
message: 'Continue the task.',
|
|
14
|
+
sessionId: 'claude-session-id',
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
await openAIAgent.resumeStream({
|
|
18
|
+
message: 'Continue the task.',
|
|
19
|
+
previousResponseId: 'resp_123',
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const result = await openAIAgent.generate('Return the answer as JSON.', {
|
|
23
|
+
structuredOutput: {
|
|
24
|
+
schema: z.object({ answer: z.string() }),
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
// result.object has shape { answer: string }
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Claude and OpenAI SDK agents support `structuredOutput` through their native SDK APIs. `CursorSDKAgent` throws a clear error when `structuredOutput` is requested because the Cursor TypeScript SDK does not expose schema-constrained output.
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies [[`575f815`](https://github.com/mastra-ai/mastra/commit/575f815c5c3567b71c0b83cbb7fa98c8253a9d9c), [`306909a`](https://github.com/mastra-ai/mastra/commit/306909a693de77d709b38706e2673c9547d24a28), [`5191af8`](https://github.com/mastra-ai/mastra/commit/5191af80c799eea25357c545fc05d91b3883531d), [`43bd3d4`](https://github.com/mastra-ai/mastra/commit/43bd3d421987463fdf35386a45199c49499ed069), [`e6fa79e`](https://github.com/mastra-ai/mastra/commit/e6fa79ec72a2ddffdd25e85270398951e9d552a4), [`904bcdf`](https://github.com/mastra-ai/mastra/commit/904bcdf7b8004aa7be823f9f70ca63580e47e470), [`7f5ee1d`](https://github.com/mastra-ai/mastra/commit/7f5ee1dca46daee8d2817f2ebe49e6335da81956), [`1e9aab5`](https://github.com/mastra-ai/mastra/commit/1e9aab50ff11e6e88fde4d7cbf512c44a9fe8d61), [`bf8eb6d`](https://github.com/mastra-ai/mastra/commit/bf8eb6d0ec213a403eb9265a594ad283c44ab3dc), [`493a328`](https://github.com/mastra-ai/mastra/commit/493a328f4346a1deeb9f1e2e44c8f2a3a4d7591b), [`029a414`](https://github.com/mastra-ai/mastra/commit/029a4141719793bd3e898a39eb5a0466a55f5f3a), [`b147b29`](https://github.com/mastra-ai/mastra/commit/b147b2907f0cd1aa812efe6d6e3f58d22e66fc88), [`d371ac1`](https://github.com/mastra-ai/mastra/commit/d371ac1d9820afaaf7cfdbc380a475946a994d8f), [`cf182b7`](https://github.com/mastra-ai/mastra/commit/cf182b7fb495767946d9840ef29f19cfa906f31f), [`a049c2a`](https://github.com/mastra-ai/mastra/commit/a049c2a9dfb41d0ee2e7a28874a88cd64fd5669f), [`b147b29`](https://github.com/mastra-ai/mastra/commit/b147b2907f0cd1aa812efe6d6e3f58d22e66fc88), [`2a96528`](https://github.com/mastra-ai/mastra/commit/2a9652848dfa3c5a2426f952e9d93554c26fd90f), [`2656d9c`](https://github.com/mastra-ai/mastra/commit/2656d9c2976d4f3354253bfbbbf9b88a1b2bbf34), [`63e3fe1`](https://github.com/mastra-ai/mastra/commit/63e3fe13cc1ea96f91d7c68aea92f400faf9e4da), [`1d4ce8d`](https://github.com/mastra-ai/mastra/commit/1d4ce8daaa54511f325c1b609d31b8e54009d677), [`8c68372`](https://github.com/mastra-ai/mastra/commit/8c68372e85fe0b066ec12c58bd29ffb93e54c552)]:
|
|
35
|
+
- @mastra/core@1.42.0-alpha.4
|
|
36
|
+
|
|
3
37
|
## 0.1.0
|
|
4
38
|
|
|
5
39
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-cursor
|
|
|
3
3
|
description: Documentation for @mastra/cursor. Use when working with @mastra/cursor APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/cursor"
|
|
6
|
-
version: "0.
|
|
6
|
+
version: "0.2.0-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -16,7 +16,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
16
16
|
|
|
17
17
|
### Docs
|
|
18
18
|
|
|
19
|
-
- [SDK agents](references/docs-agents-sdk-agents.md) - Use Claude Agent SDK
|
|
19
|
+
- [SDK agents](references/docs-agents-sdk-agents.md) - Use Claude Agent SDK, Cursor Agent SDK, and OpenAI Agents SDK agents from Mastra.
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
|
|
@@ -13,6 +13,7 @@ SDK agents let you use other agent SDK frameworks inside Mastra. Use them to reg
|
|
|
13
13
|
|
|
14
14
|
- [Claude Agent SDK](#claude-agent-sdk): Use `@mastra/claude` to register a Claude SDK agent and call it with Mastra `generate()` and `stream()`.
|
|
15
15
|
- [Cursor Agent SDK](#cursor-agent-sdk): Use `@mastra/cursor` to register a Cursor SDK agent and call it with Mastra `generate()` and `stream()`.
|
|
16
|
+
- [OpenAI Agents SDK](#openai-agents-sdk): Use `@mastra/openai` to register an OpenAI SDK agent and call it with Mastra `generate()` and `stream()`.
|
|
16
17
|
|
|
17
18
|
## Claude Agent SDK
|
|
18
19
|
|
|
@@ -154,7 +155,7 @@ export const cursorSDKAgent = new CursorSDKAgent({
|
|
|
154
155
|
sdkOptions: {
|
|
155
156
|
apiKey: process.env.CURSOR_API_KEY,
|
|
156
157
|
model: {
|
|
157
|
-
id: 'gpt-5
|
|
158
|
+
id: 'gpt-5',
|
|
158
159
|
},
|
|
159
160
|
local: {
|
|
160
161
|
cwd: process.cwd(),
|
|
@@ -176,7 +177,7 @@ import { CursorSDKAgent } from '@mastra/cursor'
|
|
|
176
177
|
const cursorAgent = CursorAgent.create({
|
|
177
178
|
apiKey: process.env.CURSOR_API_KEY,
|
|
178
179
|
model: {
|
|
179
|
-
id: 'gpt-5
|
|
180
|
+
id: 'gpt-5',
|
|
180
181
|
},
|
|
181
182
|
local: {
|
|
182
183
|
cwd: process.cwd(),
|
|
@@ -206,7 +207,7 @@ export const cursorSDKAgent = new CursorSDKAgent({
|
|
|
206
207
|
sdkOptions: {
|
|
207
208
|
apiKey: process.env.CURSOR_API_KEY,
|
|
208
209
|
model: {
|
|
209
|
-
id: 'gpt-5
|
|
210
|
+
id: 'gpt-5',
|
|
210
211
|
},
|
|
211
212
|
local: {
|
|
212
213
|
cwd: process.cwd(),
|
|
@@ -216,6 +217,117 @@ export const cursorSDKAgent = new CursorSDKAgent({
|
|
|
216
217
|
})
|
|
217
218
|
```
|
|
218
219
|
|
|
220
|
+
## OpenAI Agents SDK
|
|
221
|
+
|
|
222
|
+
Use `@mastra/openai` to register an OpenAI Agents SDK agent in Mastra while keeping OpenAI-specific agent settings in OpenAI SDK options.
|
|
223
|
+
|
|
224
|
+
### Install OpenAI packages
|
|
225
|
+
|
|
226
|
+
Install the Mastra package and the OpenAI Agents SDK peer dependency:
|
|
227
|
+
|
|
228
|
+
**npm**:
|
|
229
|
+
|
|
230
|
+
```bash
|
|
231
|
+
npm install @mastra/openai @openai/agents zod
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**pnpm**:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
pnpm add @mastra/openai @openai/agents zod
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
**Yarn**:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
yarn add @mastra/openai @openai/agents zod
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
**Bun**:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
bun add @mastra/openai @openai/agents zod
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Set the OpenAI SDK credential:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
export OPENAI_API_KEY="..."
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Create an OpenAI SDK agent
|
|
259
|
+
|
|
260
|
+
Configure OpenAI Agents SDK through `sdkOptions`. `OpenAISDKAgent` creates the OpenAI SDK agent on first use.
|
|
261
|
+
|
|
262
|
+
```typescript
|
|
263
|
+
import { OpenAISDKAgent } from '@mastra/openai'
|
|
264
|
+
|
|
265
|
+
export const openaiSDKAgent = new OpenAISDKAgent({
|
|
266
|
+
id: 'openai-sdk-agent',
|
|
267
|
+
name: 'OpenAI SDK Agent',
|
|
268
|
+
description: 'Use OpenAI Agents SDK through Mastra.',
|
|
269
|
+
sdkOptions: {
|
|
270
|
+
name: 'Repository assistant',
|
|
271
|
+
instructions: 'Answer clearly and cite the relevant files.',
|
|
272
|
+
model: 'gpt-5',
|
|
273
|
+
},
|
|
274
|
+
})
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Use an existing OpenAI SDK agent
|
|
278
|
+
|
|
279
|
+
If your app already creates an OpenAI SDK agent, pass that agent to `OpenAISDKAgent` instead:
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
import { Agent as OpenAIAgent } from '@openai/agents'
|
|
283
|
+
import { OpenAISDKAgent } from '@mastra/openai'
|
|
284
|
+
|
|
285
|
+
const sdkAgent = new OpenAIAgent({
|
|
286
|
+
name: 'Repository assistant',
|
|
287
|
+
instructions: 'Answer clearly and cite the relevant files.',
|
|
288
|
+
model: 'gpt-5',
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
export const openaiSDKAgent = new OpenAISDKAgent({
|
|
292
|
+
id: 'openai-sdk-agent',
|
|
293
|
+
name: 'OpenAI SDK Agent',
|
|
294
|
+
description: 'Use OpenAI Agents SDK through Mastra.',
|
|
295
|
+
agent: sdkAgent,
|
|
296
|
+
})
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Add OpenAI SDK tools
|
|
300
|
+
|
|
301
|
+
OpenAI Agents SDK tools are configured with OpenAI SDK options. Create tools with the OpenAI SDK, then pass them through `sdkOptions.tools`.
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
import { tool } from '@openai/agents'
|
|
305
|
+
import { OpenAISDKAgent } from '@mastra/openai'
|
|
306
|
+
import { z } from 'zod'
|
|
307
|
+
|
|
308
|
+
const getTemperature = tool({
|
|
309
|
+
name: 'get_temperature',
|
|
310
|
+
description: 'Get the current temperature for a city.',
|
|
311
|
+
parameters: z.object({
|
|
312
|
+
city: z.string(),
|
|
313
|
+
}),
|
|
314
|
+
execute: async ({ city }) => {
|
|
315
|
+
return `${city}: 27 C`
|
|
316
|
+
},
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
export const openaiSDKAgent = new OpenAISDKAgent({
|
|
320
|
+
id: 'openai-sdk-agent',
|
|
321
|
+
name: 'OpenAI SDK Agent',
|
|
322
|
+
description: 'Use OpenAI Agents SDK through Mastra.',
|
|
323
|
+
sdkOptions: {
|
|
324
|
+
name: 'Weather assistant',
|
|
325
|
+
model: 'gpt-5',
|
|
326
|
+
tools: [getTemperature],
|
|
327
|
+
},
|
|
328
|
+
})
|
|
329
|
+
```
|
|
330
|
+
|
|
219
331
|
## Register SDK agents
|
|
220
332
|
|
|
221
333
|
Register SDK agents in the Mastra instance like other agents:
|
|
@@ -224,11 +336,13 @@ Register SDK agents in the Mastra instance like other agents:
|
|
|
224
336
|
import { Mastra } from '@mastra/core'
|
|
225
337
|
import { claudeSDKAgent } from './agents/claude-sdk-agent'
|
|
226
338
|
import { cursorSDKAgent } from './agents/cursor-sdk-agent'
|
|
339
|
+
import { openaiSDKAgent } from './agents/openai-sdk-agent'
|
|
227
340
|
|
|
228
341
|
export const mastra = new Mastra({
|
|
229
342
|
agents: {
|
|
230
343
|
claudeSDKAgent,
|
|
231
344
|
cursorSDKAgent,
|
|
345
|
+
openaiSDKAgent,
|
|
232
346
|
},
|
|
233
347
|
})
|
|
234
348
|
```
|
|
@@ -246,11 +360,61 @@ for await (const chunk of stream.textStream) {
|
|
|
246
360
|
}
|
|
247
361
|
```
|
|
248
362
|
|
|
363
|
+
## Resume SDK runs
|
|
364
|
+
|
|
365
|
+
SDK agents support Mastra `resumeGenerate()` and `resumeStream()` with provider-native resume data. Pass the message to continue with and the resume identifier used by the underlying SDK.
|
|
366
|
+
|
|
367
|
+
Claude SDK agents can resume a known session with `sessionId`:
|
|
368
|
+
|
|
369
|
+
```typescript
|
|
370
|
+
const result = await claudeSDKAgent.resumeGenerate({
|
|
371
|
+
message: 'Continue the previous task.',
|
|
372
|
+
sessionId: 'claude-session-id',
|
|
373
|
+
})
|
|
374
|
+
|
|
375
|
+
console.log(result.text)
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
OpenAI SDK agents can resume with a previous response, conversation, or session:
|
|
379
|
+
|
|
380
|
+
```typescript
|
|
381
|
+
const stream = await openaiSDKAgent.resumeStream({
|
|
382
|
+
message: 'Continue the previous task.',
|
|
383
|
+
previousResponseId: 'resp_123',
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
for await (const chunk of stream.textStream) {
|
|
387
|
+
process.stdout.write(chunk)
|
|
388
|
+
}
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
Cursor SDK agents can continue with the wrapped SDK agent. If you need to resume a stored Cursor SDK agent by ID, pass `agentId` in `resumeData`.
|
|
392
|
+
|
|
393
|
+
## Structured output
|
|
394
|
+
|
|
395
|
+
Claude and OpenAI SDK agents support Mastra `structuredOutput` through their provider-native structured output APIs. The validated value is available on `result.object`.
|
|
396
|
+
|
|
397
|
+
```typescript
|
|
398
|
+
import { z } from 'zod'
|
|
399
|
+
|
|
400
|
+
const result = await openaiSDKAgent.generate<{ summary: string }>('Summarize this project.', {
|
|
401
|
+
structuredOutput: {
|
|
402
|
+
schema: z.object({
|
|
403
|
+
summary: z.string(),
|
|
404
|
+
}),
|
|
405
|
+
},
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
console.log(result.object.summary)
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
Cursor SDK agents throw a clear error when `structuredOutput` is requested because the Cursor TypeScript SDK doesn't expose a schema-constrained output API.
|
|
412
|
+
|
|
249
413
|
## Observability
|
|
250
414
|
|
|
251
415
|
SDK agents create Mastra agent and model spans for `generate()` and `stream()` calls. Mastra records SDK-provided usage, tool activity, and provider metadata when the vendor SDK exposes those events.
|
|
252
416
|
|
|
253
|
-
Claude SDK runs can include SDK-estimated cost from the Claude result message. Cursor SDK runs include token usage from Cursor interaction updates.
|
|
417
|
+
Claude SDK runs can include SDK-estimated cost from the Claude result message. Cursor SDK runs include token usage from Cursor interaction updates. OpenAI SDK runs include token usage from OpenAI run state.
|
|
254
418
|
|
|
255
419
|
For storage and dashboard setup, see [Observability](https://mastra.ai/docs/observability/overview).
|
|
256
420
|
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,8 @@ function createCompletedMastraStream({
|
|
|
35
35
|
modelId,
|
|
36
36
|
usage,
|
|
37
37
|
providerMetadata,
|
|
38
|
-
costContext
|
|
38
|
+
costContext,
|
|
39
|
+
object
|
|
39
40
|
}) {
|
|
40
41
|
return new web.ReadableStream({
|
|
41
42
|
start(controller) {
|
|
@@ -60,7 +61,8 @@ function createCompletedMastraStream({
|
|
|
60
61
|
modelId,
|
|
61
62
|
usage,
|
|
62
63
|
providerMetadata,
|
|
63
|
-
costContext
|
|
64
|
+
costContext,
|
|
65
|
+
object
|
|
64
66
|
});
|
|
65
67
|
controller.close();
|
|
66
68
|
}
|
|
@@ -108,7 +110,8 @@ function toFullOutput({
|
|
|
108
110
|
modelId: result.response.modelId,
|
|
109
111
|
usage: toLanguageModelUsage(result.usage),
|
|
110
112
|
providerMetadata: result.providerMetadata,
|
|
111
|
-
costContext: result.costContext
|
|
113
|
+
costContext: result.costContext,
|
|
114
|
+
object: result.object
|
|
112
115
|
});
|
|
113
116
|
return createMastraOutput({
|
|
114
117
|
messages,
|
|
@@ -486,7 +489,8 @@ function enqueueFinishChunks(controller, {
|
|
|
486
489
|
modelId,
|
|
487
490
|
usage,
|
|
488
491
|
providerMetadata,
|
|
489
|
-
costContext
|
|
492
|
+
costContext,
|
|
493
|
+
object
|
|
490
494
|
}) {
|
|
491
495
|
const timestamp = /* @__PURE__ */ new Date();
|
|
492
496
|
const response = {
|
|
@@ -510,6 +514,14 @@ function enqueueFinishChunks(controller, {
|
|
|
510
514
|
providerMetadata
|
|
511
515
|
}
|
|
512
516
|
});
|
|
517
|
+
if (object !== void 0) {
|
|
518
|
+
controller.enqueue({
|
|
519
|
+
type: "object-result",
|
|
520
|
+
runId,
|
|
521
|
+
from: stream.ChunkFrom.AGENT,
|
|
522
|
+
object
|
|
523
|
+
});
|
|
524
|
+
}
|
|
513
525
|
controller.enqueue({
|
|
514
526
|
type: "step-finish",
|
|
515
527
|
runId,
|
|
@@ -650,9 +662,13 @@ var CursorSDKAgent = class extends agent.Agent {
|
|
|
650
662
|
return false;
|
|
651
663
|
}
|
|
652
664
|
async generate(messages, options) {
|
|
665
|
+
assertStructuredOutputUnsupported(options);
|
|
666
|
+
const sdkAgent = await this.resolveCursorAgent();
|
|
667
|
+
return this.generateWithAgent(messages, sdkAgent, options);
|
|
668
|
+
}
|
|
669
|
+
async generateWithAgent(messages, sdkAgent, options) {
|
|
653
670
|
const prompt = promptToText(messages);
|
|
654
671
|
const runId = options?.runId ?? crypto.randomUUID();
|
|
655
|
-
const sdkAgent = await this.resolveCursorAgent();
|
|
656
672
|
const modelId = getCursorModelId(this.options, sdkAgent);
|
|
657
673
|
const requestContext$1 = options?.requestContext ?? new requestContext.RequestContext();
|
|
658
674
|
const instructions = options?.instructions ? promptToText(options.instructions) : void 0;
|
|
@@ -692,9 +708,13 @@ var CursorSDKAgent = class extends agent.Agent {
|
|
|
692
708
|
});
|
|
693
709
|
}
|
|
694
710
|
async stream(messages, options) {
|
|
711
|
+
assertStructuredOutputUnsupported(options);
|
|
712
|
+
const sdkAgent = await this.resolveCursorAgent();
|
|
713
|
+
return this.streamWithAgent(messages, sdkAgent, options);
|
|
714
|
+
}
|
|
715
|
+
async streamWithAgent(messages, sdkAgent, options) {
|
|
695
716
|
const runId = options?.runId ?? crypto.randomUUID();
|
|
696
717
|
const prompt = promptToText(messages);
|
|
697
|
-
const sdkAgent = await this.resolveCursorAgent();
|
|
698
718
|
const modelId = getCursorModelId(this.options, sdkAgent);
|
|
699
719
|
const requestContext$1 = options?.requestContext ?? new requestContext.RequestContext();
|
|
700
720
|
const instructions = options?.instructions ? promptToText(options.instructions) : void 0;
|
|
@@ -726,6 +746,18 @@ var CursorSDKAgent = class extends agent.Agent {
|
|
|
726
746
|
options: telemetry.outputOptions()
|
|
727
747
|
});
|
|
728
748
|
}
|
|
749
|
+
async resumeGenerate(resumeData, options) {
|
|
750
|
+
assertStructuredOutputUnsupported(options);
|
|
751
|
+
const data = validateCursorResumeData(resumeData);
|
|
752
|
+
const sdkAgent = await this.resolveResumeCursorAgent(data);
|
|
753
|
+
return this.generateWithAgent(data.message, sdkAgent, options);
|
|
754
|
+
}
|
|
755
|
+
async resumeStream(resumeData, options) {
|
|
756
|
+
assertStructuredOutputUnsupported(options);
|
|
757
|
+
const data = validateCursorResumeData(resumeData);
|
|
758
|
+
const sdkAgent = await this.resolveResumeCursorAgent(data);
|
|
759
|
+
return this.streamWithAgent(data.message, sdkAgent, options);
|
|
760
|
+
}
|
|
729
761
|
resolveCursorAgent() {
|
|
730
762
|
this.#createdAgent ??= resolveCursorAgent(this.options.agent, this.options).catch((error) => {
|
|
731
763
|
this.#createdAgent = void 0;
|
|
@@ -733,7 +765,33 @@ var CursorSDKAgent = class extends agent.Agent {
|
|
|
733
765
|
});
|
|
734
766
|
return this.#createdAgent;
|
|
735
767
|
}
|
|
768
|
+
async resolveResumeCursorAgent(resumeData) {
|
|
769
|
+
if (!resumeData.agentId) {
|
|
770
|
+
return this.resolveCursorAgent();
|
|
771
|
+
}
|
|
772
|
+
return sdk.Agent.resume(resumeData.agentId, {
|
|
773
|
+
...toCursorCreateOptions(this.options),
|
|
774
|
+
...resumeData.sdkOptions
|
|
775
|
+
});
|
|
776
|
+
}
|
|
736
777
|
};
|
|
778
|
+
function validateCursorResumeData(resumeData) {
|
|
779
|
+
if (!toRecord(resumeData) || !("message" in resumeData)) {
|
|
780
|
+
throw new Error("CursorSDKAgent resumeData must include a message.");
|
|
781
|
+
}
|
|
782
|
+
if (resumeData.agentId !== void 0 && typeof resumeData.agentId !== "string") {
|
|
783
|
+
throw new Error("CursorSDKAgent resumeData.agentId must be a string when provided.");
|
|
784
|
+
}
|
|
785
|
+
return resumeData;
|
|
786
|
+
}
|
|
787
|
+
function assertStructuredOutputUnsupported(options) {
|
|
788
|
+
const structuredOutput = toRecord(toRecord(options)?.structuredOutput);
|
|
789
|
+
if (structuredOutput && "schema" in structuredOutput) {
|
|
790
|
+
throw new Error(
|
|
791
|
+
"CursorSDKAgent does not support structuredOutput because the Cursor TypeScript SDK does not expose a schema-constrained output API."
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
737
795
|
async function runCursorGenerate(prompt, options, agent, telemetry) {
|
|
738
796
|
const usage = createCursorUsageCollector();
|
|
739
797
|
const run = await agent.send(prompt, createCursorSendOptions(options, usage, telemetry));
|