1- import type { ListArtifactsParams , ListArtifactsResponse } from '@/tools/cursor/types'
1+ import type {
2+ ArtifactMetadata ,
3+ ListArtifactsParams ,
4+ ListArtifactsResponse ,
5+ } from '@/tools/cursor/types'
26import { CURSOR_CREDENTIAL_OAUTH } from '@/tools/shared/saved-credentials'
37import type { ToolConfig } from '@/tools/types'
8+ import { safeUrlPathSegment } from '@/tools/url-path'
9+
10+ /** Maps Cursor's `{ absolutePath, sizeBytes, updatedAt }` artifacts, also filling the original `path`/`size` names. */
11+ function mapArtifacts ( raw : unknown ) : ArtifactMetadata [ ] {
12+ if ( ! Array . isArray ( raw ) ) return [ ]
13+ return raw . map ( ( item : Record < string , unknown > | null ) => {
14+ const absolutePath = typeof item ?. absolutePath === 'string' ? item . absolutePath : ''
15+ const sizeBytes = typeof item ?. sizeBytes === 'number' ? item . sizeBytes : null
16+ return {
17+ absolutePath,
18+ sizeBytes,
19+ updatedAt : typeof item ?. updatedAt === 'string' ? item . updatedAt : null ,
20+ path : absolutePath ,
21+ size : sizeBytes ,
22+ }
23+ } )
24+ }
425
526const listArtifactsBase = {
627 params : {
@@ -19,7 +40,7 @@ const listArtifactsBase = {
1940 } ,
2041 request : {
2142 url : ( params : ListArtifactsParams ) =>
22- `https://api.cursor.com/v0/agents/${ params . agentId . trim ( ) } /artifacts` ,
43+ `https://api.cursor.com/v0/agents/${ safeUrlPathSegment ( params . agentId , 'agentId' ) } /artifacts` ,
2344 method : 'GET' ,
2445 headers : ( params : ListArtifactsParams ) => ( {
2546 Authorization : `Basic ${ Buffer . from ( `${ params . apiKey } :` ) . toString ( 'base64' ) } ` ,
@@ -38,7 +59,7 @@ export const listArtifactsTool: ToolConfig<ListArtifactsParams, ListArtifactsRes
3859
3960 transformResponse : async ( response ) => {
4061 const data = await response . json ( )
41- const artifacts = data . artifacts ?? [ ]
62+ const artifacts = mapArtifacts ( data . artifacts )
4263
4364 return {
4465 success : true ,
@@ -63,8 +84,30 @@ export const listArtifactsTool: ToolConfig<ListArtifactsParams, ListArtifactsRes
6384 items : {
6485 type : 'object' ,
6586 properties : {
66- path : { type : 'string' , description : 'Artifact file path' } ,
67- size : { type : 'number' , description : 'File size in bytes' , optional : true } ,
87+ absolutePath : {
88+ type : 'string' ,
89+ description :
90+ 'Absolute artifact path on the agent filesystem; pass it to Download Artifact' ,
91+ } ,
92+ sizeBytes : {
93+ type : 'number' ,
94+ description : 'File size in bytes' ,
95+ optional : true ,
96+ nullable : true ,
97+ } ,
98+ updatedAt : {
99+ type : 'string' ,
100+ description : 'ISO 8601 time the artifact was last updated' ,
101+ nullable : true ,
102+ optional : true ,
103+ } ,
104+ path : { type : 'string' , description : 'Artifact file path (same as absolutePath)' } ,
105+ size : {
106+ type : 'number' ,
107+ description : 'File size in bytes (same as sizeBytes)' ,
108+ nullable : true ,
109+ optional : true ,
110+ } ,
68111 } ,
69112 } ,
70113 } ,
@@ -76,26 +119,27 @@ export const listArtifactsTool: ToolConfig<ListArtifactsParams, ListArtifactsRes
76119interface ListArtifactsV2Response {
77120 success : boolean
78121 output : {
79- artifacts : Array < { path : string ; size ?: number } >
122+ artifacts : ArtifactMetadata [ ]
80123 }
81124}
82125
83126export const listArtifactsV2Tool : ToolConfig < ListArtifactsParams , ListArtifactsV2Response > = {
84127 ...listArtifactsBase ,
85128 id : 'cursor_list_artifacts_v2' ,
86129 name : 'Cursor List Artifacts' ,
87- description : 'List generated artifact files for a cloud agent. Returns API-aligned fields only.' ,
130+ description :
131+ 'List generated artifact files for a cloud agent. Returns the API fields plus `path` and `size` aliases.' ,
88132 version : '2.0.0' ,
89133 oauth : CURSOR_CREDENTIAL_OAUTH ,
90134
91135 transformResponse : async ( response ) => {
92136 const data = await response . json ( )
93- const artifacts = data . artifacts ?? [ ]
137+ const artifacts = mapArtifacts ( data . artifacts )
94138
95139 return {
96140 success : true ,
97141 output : {
98- artifacts : Array . isArray ( artifacts ) ? artifacts : [ ] ,
142+ artifacts,
99143 } ,
100144 }
101145 } ,
@@ -107,8 +151,30 @@ export const listArtifactsV2Tool: ToolConfig<ListArtifactsParams, ListArtifactsV
107151 items : {
108152 type : 'object' ,
109153 properties : {
110- path : { type : 'string' , description : 'Artifact file path' } ,
111- size : { type : 'number' , description : 'File size in bytes' , optional : true } ,
154+ absolutePath : {
155+ type : 'string' ,
156+ description :
157+ 'Absolute artifact path on the agent filesystem; pass it to Download Artifact' ,
158+ } ,
159+ sizeBytes : {
160+ type : 'number' ,
161+ description : 'File size in bytes' ,
162+ optional : true ,
163+ nullable : true ,
164+ } ,
165+ updatedAt : {
166+ type : 'string' ,
167+ description : 'ISO 8601 time the artifact was last updated' ,
168+ nullable : true ,
169+ optional : true ,
170+ } ,
171+ path : { type : 'string' , description : 'Artifact file path (same as absolutePath)' } ,
172+ size : {
173+ type : 'number' ,
174+ description : 'File size in bytes (same as sizeBytes)' ,
175+ nullable : true ,
176+ optional : true ,
177+ } ,
112178 } ,
113179 } ,
114180 } ,
0 commit comments