Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions apps/docs/content/docs/integrations/cursor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ Permanently delete a cloud agent. Returns API-aligned fields only.

### Cursor List Artifacts

List generated artifact files for a cloud agent. Returns API-aligned fields only.
List generated artifact files for a cloud agent. Returns the API fields plus `path` and `size` aliases.

<ReferenceDetails>

Expand All @@ -197,8 +197,11 @@ List generated artifact files for a cloud agent. Returns API-aligned fields only
| Parameter | Type | Description |
| --------- | ---- | ----------- |
| `artifacts` | array | List of artifact files |
| ↳ `path` | string | Artifact file path |
| ↳ `size` | number | File size in bytes |
| ↳ `absolutePath` | string | Absolute artifact path on the agent filesystem; pass it to Download Artifact |
| ↳ `sizeBytes` | number | File size in bytes |
| ↳ `updatedAt` | string | ISO 8601 time the artifact was last updated |
| ↳ `path` | string | Artifact file path \(same as absolutePath\) |
| ↳ `size` | number | File size in bytes \(same as sizeBytes\) |

</ReferenceDetails>

Expand All @@ -213,7 +216,7 @@ Download a generated artifact file from a cloud agent. Returns the file for exec
| Parameter | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `agentId` | string | Yes | Unique identifier for the cloud agent \(e.g., bc_abc123\) |
| `path` | string | Yes | Absolute path of the artifact to download \(e.g., /src/index.ts\) |
| `path` | string | Yes | Absolute artifact path from List Artifacts \(e.g., /opt/cursor/artifacts/screenshot.png\) |

#### Output

Expand Down
6 changes: 5 additions & 1 deletion apps/sim/blocks/blocks/cursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,11 @@ export const CursorV2Block: BlockConfig = {
agents: { type: 'json', description: 'Array of agent objects (list operation)' },
nextCursor: { type: 'string', description: 'Pagination cursor (list operation)' },
messages: { type: 'json', description: 'Conversation messages (get conversation operation)' },
artifacts: { type: 'json', description: 'List of artifact files (list artifacts operation)' },
artifacts: {
type: 'json',
description:
'Artifact files [{absolutePath, sizeBytes, updatedAt, path, size}] (list artifacts operation)',
},
file: { type: 'file', description: 'Downloaded artifact file (download artifact operation)' },
models: { type: 'json', description: 'Available model names (list models operation)' },
repositories: {
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/cursor/add_followup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import type { AddFollowupParams, AddFollowupResponse } from '@/tools/cursor/types'
import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

const addFollowupBase = {
params: {
Expand Down Expand Up @@ -46,7 +47,7 @@ const addFollowupBase = {
),
},
url: (params: AddFollowupParams) =>
`https://api.cursor.com/v0/agents/${params.agentId.trim()}/followup`,
`https://api.cursor.com/v0/agents/${safeUrlPathSegment(params.agentId, 'agentId')}/followup`,
method: 'POST',
headers: (params: AddFollowupParams) => ({
'Content-Type': 'application/json',
Expand Down
53 changes: 53 additions & 0 deletions apps/sim/tools/cursor/cursor.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { describe, expect, it } from 'vitest'
import { deleteAgentV2Tool } from '@/tools/cursor/delete_agent'
import { listArtifactsTool, listArtifactsV2Tool } from '@/tools/cursor/list_artifacts'

const artifactsResponse = () =>
new Response(
JSON.stringify({
artifacts: [
{
absolutePath: '/opt/cursor/artifacts/screenshot.png',
sizeBytes: 12345,
updatedAt: '2024-01-15T11:02:00.000Z',
},
],
})
)

const expectedArtifact = {
absolutePath: '/opt/cursor/artifacts/screenshot.png',
sizeBytes: 12345,
updatedAt: '2024-01-15T11:02:00.000Z',
path: '/opt/cursor/artifacts/screenshot.png',
size: 12345,
}

describe('cursor list artifacts', () => {
it('fills path and size from the absolutePath and sizeBytes Cursor returns', async () => {
const v2 = await listArtifactsV2Tool.transformResponse?.(artifactsResponse())
expect(v2?.output.artifacts).toEqual([expectedArtifact])

const v1 = await listArtifactsTool.transformResponse?.(artifactsResponse())
expect(v1?.output.metadata.artifacts).toEqual([expectedArtifact])
})
})

describe('cursor agent path segments', () => {
const deleteUrl = (agentId: string) => {
const url = deleteAgentV2Tool.request.url
if (typeof url !== 'function') throw new Error('expected a url builder')
return url({ apiKey: 'k', agentId })
}

it.each(['..', '.', 'bc_1/../me'])(
'rejects agent id %j before a DELETE can leave the agent route',
(id) => {
expect(() => deleteUrl(id)).toThrow(/agentId/)
}
)

it('leaves ordinary ids unchanged', () => {
expect(deleteUrl(' bc_abc123 ')).toBe('https://api.cursor.com/v0/agents/bc_abc123')
})
})
4 changes: 3 additions & 1 deletion apps/sim/tools/cursor/delete_agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DeleteAgentParams, DeleteAgentResponse } from '@/tools/cursor/types'
import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

const deleteAgentBase = {
params: {
Expand All @@ -18,7 +19,8 @@ const deleteAgentBase = {
},
},
request: {
url: (params: DeleteAgentParams) => `https://api.cursor.com/v0/agents/${params.agentId.trim()}`,
url: (params: DeleteAgentParams) =>
`https://api.cursor.com/v0/agents/${safeUrlPathSegment(params.agentId, 'agentId')}`,
method: 'DELETE',
headers: (params: DeleteAgentParams) => ({
Authorization: `Basic ${Buffer.from(`${params.apiKey}:`).toString('base64')}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/cursor/download_artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const downloadArtifactBase = {
type: 'string',
required: true,
visibility: 'user-or-llm',
description: 'Absolute path of the artifact to download (e.g., /src/index.ts)',
description:
'Absolute artifact path from List Artifacts (e.g., /opt/cursor/artifacts/screenshot.png)',
},
},
operation: {
Expand Down
4 changes: 3 additions & 1 deletion apps/sim/tools/cursor/get_agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GetAgentParams, GetAgentResponse } from '@/tools/cursor/types'
import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

const getAgentBase = {
params: {
Expand All @@ -18,7 +19,8 @@ const getAgentBase = {
},
},
request: {
url: (params: GetAgentParams) => `https://api.cursor.com/v0/agents/${params.agentId.trim()}`,
url: (params: GetAgentParams) =>
`https://api.cursor.com/v0/agents/${safeUrlPathSegment(params.agentId, 'agentId')}`,
method: 'GET',
headers: (params: GetAgentParams) => ({
Authorization: `Basic ${Buffer.from(`${params.apiKey}:`).toString('base64')}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/cursor/get_conversation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { GetConversationParams, GetConversationResponse } from '@/tools/cursor/types'
import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

const getConversationBase = {
params: {
Expand All @@ -19,7 +20,7 @@ const getConversationBase = {
},
request: {
url: (params: GetConversationParams) =>
`https://api.cursor.com/v0/agents/${params.agentId.trim()}/conversation`,
`https://api.cursor.com/v0/agents/${safeUrlPathSegment(params.agentId, 'agentId')}/conversation`,
method: 'GET',
headers: (params: GetConversationParams) => ({
Authorization: `Basic ${Buffer.from(`${params.apiKey}:`).toString('base64')}`,
Expand Down
88 changes: 77 additions & 11 deletions apps/sim/tools/cursor/list_artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
import type { ListArtifactsParams, ListArtifactsResponse } from '@/tools/cursor/types'
import type {
ArtifactMetadata,
ListArtifactsParams,
ListArtifactsResponse,
} from '@/tools/cursor/types'
import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

/** Maps Cursor's `{ absolutePath, sizeBytes, updatedAt }` artifacts, also filling the original `path`/`size` names. */
function mapArtifacts(raw: unknown): ArtifactMetadata[] {
if (!Array.isArray(raw)) return []
return raw.map((item: Record<string, unknown> | null) => {
const absolutePath = typeof item?.absolutePath === 'string' ? item.absolutePath : ''
const sizeBytes = typeof item?.sizeBytes === 'number' ? item.sizeBytes : null
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
return {
absolutePath,
sizeBytes,
updatedAt: typeof item?.updatedAt === 'string' ? item.updatedAt : null,
path: absolutePath,
size: sizeBytes,
}
})
}

const listArtifactsBase = {
params: {
Expand All @@ -19,7 +40,7 @@ const listArtifactsBase = {
},
request: {
url: (params: ListArtifactsParams) =>
`https://api.cursor.com/v0/agents/${params.agentId.trim()}/artifacts`,
`https://api.cursor.com/v0/agents/${safeUrlPathSegment(params.agentId, 'agentId')}/artifacts`,
method: 'GET',
headers: (params: ListArtifactsParams) => ({
Authorization: `Basic ${Buffer.from(`${params.apiKey}:`).toString('base64')}`,
Expand All @@ -38,7 +59,7 @@ export const listArtifactsTool: ToolConfig<ListArtifactsParams, ListArtifactsRes

transformResponse: async (response) => {
const data = await response.json()
const artifacts = data.artifacts ?? []
const artifacts = mapArtifacts(data.artifacts)

return {
success: true,
Expand All @@ -63,8 +84,30 @@ export const listArtifactsTool: ToolConfig<ListArtifactsParams, ListArtifactsRes
items: {
type: 'object',
properties: {
path: { type: 'string', description: 'Artifact file path' },
size: { type: 'number', description: 'File size in bytes', optional: true },
absolutePath: {
type: 'string',
description:
'Absolute artifact path on the agent filesystem; pass it to Download Artifact',
},
sizeBytes: {
type: 'number',
description: 'File size in bytes',
optional: true,
nullable: true,
},
updatedAt: {
type: 'string',
description: 'ISO 8601 time the artifact was last updated',
nullable: true,
optional: true,
},
path: { type: 'string', description: 'Artifact file path (same as absolutePath)' },
size: {
type: 'number',
description: 'File size in bytes (same as sizeBytes)',
nullable: true,
optional: true,
},
},
},
},
Expand All @@ -76,26 +119,27 @@ export const listArtifactsTool: ToolConfig<ListArtifactsParams, ListArtifactsRes
interface ListArtifactsV2Response {
success: boolean
output: {
artifacts: Array<{ path: string; size?: number }>
artifacts: ArtifactMetadata[]
Comment thread
waleedlatif1 marked this conversation as resolved.
Resolved
}
}

export const listArtifactsV2Tool: ToolConfig<ListArtifactsParams, ListArtifactsV2Response> = {
...listArtifactsBase,
id: 'cursor_list_artifacts_v2',
name: 'Cursor List Artifacts',
description: 'List generated artifact files for a cloud agent. Returns API-aligned fields only.',
description:
'List generated artifact files for a cloud agent. Returns the API fields plus `path` and `size` aliases.',
version: '2.0.0',
oauth: CURSOR_CREDENTIAL_OAUTH,

transformResponse: async (response) => {
const data = await response.json()
const artifacts = data.artifacts ?? []
const artifacts = mapArtifacts(data.artifacts)

return {
success: true,
output: {
artifacts: Array.isArray(artifacts) ? artifacts : [],
artifacts,
},
}
},
Expand All @@ -107,8 +151,30 @@ export const listArtifactsV2Tool: ToolConfig<ListArtifactsParams, ListArtifactsV
items: {
type: 'object',
properties: {
path: { type: 'string', description: 'Artifact file path' },
size: { type: 'number', description: 'File size in bytes', optional: true },
absolutePath: {
type: 'string',
description:
'Absolute artifact path on the agent filesystem; pass it to Download Artifact',
},
sizeBytes: {
type: 'number',
description: 'File size in bytes',
optional: true,
nullable: true,
},
updatedAt: {
type: 'string',
description: 'ISO 8601 time the artifact was last updated',
nullable: true,
optional: true,
},
path: { type: 'string', description: 'Artifact file path (same as absolutePath)' },
size: {
type: 'number',
description: 'File size in bytes (same as sizeBytes)',
nullable: true,
optional: true,
},
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/cursor/stop_agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { StopAgentParams, StopAgentResponse } from '@/tools/cursor/types'
import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'

const stopAgentBase = {
params: {
Expand All @@ -19,7 +20,7 @@ const stopAgentBase = {
},
request: {
url: (params: StopAgentParams) =>
`https://api.cursor.com/v0/agents/${params.agentId.trim()}/stop`,
`https://api.cursor.com/v0/agents/${safeUrlPathSegment(params.agentId, 'agentId')}/stop`,
method: 'POST',
headers: (params: StopAgentParams) => ({
Authorization: `Basic ${Buffer.from(`${params.apiKey}:`).toString('base64')}`,
Expand Down
9 changes: 7 additions & 2 deletions apps/sim/tools/cursor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,14 @@ export interface ListArtifactsParams extends BaseCursorParams {
agentId: string
}

interface ArtifactMetadata {
export interface ArtifactMetadata {
absolutePath: string
sizeBytes: number | null
updatedAt: string | null
/** Same as `absolutePath`; kept for workflows that read the original output name. */
path: string
size?: number
/** Same as `sizeBytes`; kept for workflows that read the original output name. */
size: number | null
}

export interface ListArtifactsResponse extends ToolResponse {
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/devin/append_session_tags.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DEVIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { DevinAppendSessionTagsParams, DevinSessionTagsResponse } from './types'
import { normalizeTags } from './utils'

Expand Down Expand Up @@ -42,7 +43,7 @@ export const devinAppendSessionTagsTool: ToolConfig<

request: {
url: (params) =>
`https://api.devin.ai/v3/organizations/${params.orgId.trim()}/sessions/${params.sessionId.trim()}/tags`,
`https://api.devin.ai/v3/organizations/${safeUrlPathSegment(params.orgId, 'orgId')}/sessions/${safeUrlPathSegment(params.sessionId, 'sessionId')}/tags`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
Expand Down
3 changes: 2 additions & 1 deletion apps/sim/tools/devin/archive_session.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DEVIN_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
import type { ToolConfig } from '@/tools/types'
import { safeUrlPathSegment } from '@/tools/url-path'
import type { DevinArchiveSessionParams, DevinArchiveSessionResponse } from './types'
import { DEVIN_SESSION_OUTPUT_PROPERTIES } from './types'

Expand Down Expand Up @@ -37,7 +38,7 @@ export const devinArchiveSessionTool: ToolConfig<

request: {
url: (params) =>
`https://api.devin.ai/v3/organizations/${params.orgId.trim()}/sessions/${params.sessionId.trim()}/archive`,
`https://api.devin.ai/v3/organizations/${safeUrlPathSegment(params.orgId, 'orgId')}/sessions/${safeUrlPathSegment(params.sessionId, 'sessionId')}/archive`,
method: 'POST',
headers: (params) => ({
Authorization: `Bearer ${params.apiKey}`,
Expand Down
Loading
Loading