@@ -147,9 +147,9 @@ func (g *GPTScript) RemoveAll(ctx context.Context, opts ...RemoveAllOptions) err
147
147
}
148
148
149
149
type WriteFileInWorkspaceOptions struct {
150
- WorkspaceID string
151
- CreateRevision * bool
152
- LatestRevision string
150
+ WorkspaceID string
151
+ CreateRevision * bool
152
+ LatestRevisionID string
153
153
}
154
154
155
155
func (g * GPTScript ) WriteFileInWorkspace (ctx context.Context , filePath string , contents []byte , opts ... WriteFileInWorkspaceOptions ) error {
@@ -161,8 +161,8 @@ func (g *GPTScript) WriteFileInWorkspace(ctx context.Context, filePath string, c
161
161
if o .CreateRevision != nil {
162
162
opt .CreateRevision = o .CreateRevision
163
163
}
164
- if o .LatestRevision != "" {
165
- opt .LatestRevision = o .LatestRevision
164
+ if o .LatestRevisionID != "" {
165
+ opt .LatestRevisionID = o .LatestRevisionID
166
166
}
167
167
}
168
168
@@ -171,13 +171,13 @@ func (g *GPTScript) WriteFileInWorkspace(ctx context.Context, filePath string, c
171
171
}
172
172
173
173
_ , err := g .runBasicCommand (ctx , "workspaces/write-file" , map [string ]any {
174
- "id" : opt .WorkspaceID ,
175
- "contents" : base64 .StdEncoding .EncodeToString (contents ),
176
- "filePath" : filePath ,
177
- "createRevision" : opt .CreateRevision ,
178
- "latestRevision " : opt .LatestRevision ,
179
- "workspaceTool" : g .globalOpts .WorkspaceTool ,
180
- "env" : g .globalOpts .Env ,
174
+ "id" : opt .WorkspaceID ,
175
+ "contents" : base64 .StdEncoding .EncodeToString (contents ),
176
+ "filePath" : filePath ,
177
+ "createRevision" : opt .CreateRevision ,
178
+ "latestRevisionID " : opt .LatestRevisionID ,
179
+ "workspaceTool" : g .globalOpts .WorkspaceTool ,
180
+ "env" : g .globalOpts .Env ,
181
181
})
182
182
183
183
return parsePossibleConflictInWorkspaceError (err )
@@ -214,26 +214,34 @@ func (g *GPTScript) DeleteFileInWorkspace(ctx context.Context, filePath string,
214
214
}
215
215
216
216
type ReadFileInWorkspaceOptions struct {
217
- WorkspaceID string
217
+ WorkspaceID string
218
+ WithLatestRevisionID bool
218
219
}
219
220
220
- func (g * GPTScript ) ReadFileInWorkspace (ctx context.Context , filePath string , opts ... ReadFileInWorkspaceOptions ) ([]byte , error ) {
221
+ type ReadFileInWorkspaceResponse struct {
222
+ Content []byte `json:"content"`
223
+ RevisionID string `json:"revisionID"`
224
+ }
225
+
226
+ func (g * GPTScript ) ReadFileInWorkspace (ctx context.Context , filePath string , opts ... ReadFileInWorkspaceOptions ) (* ReadFileInWorkspaceResponse , error ) {
221
227
var opt ReadFileInWorkspaceOptions
222
228
for _ , o := range opts {
223
229
if o .WorkspaceID != "" {
224
230
opt .WorkspaceID = o .WorkspaceID
225
231
}
232
+ opt .WithLatestRevisionID = opt .WithLatestRevisionID || o .WithLatestRevisionID
226
233
}
227
234
228
235
if opt .WorkspaceID == "" {
229
236
opt .WorkspaceID = os .Getenv ("GPTSCRIPT_WORKSPACE_ID" )
230
237
}
231
238
232
239
out , err := g .runBasicCommand (ctx , "workspaces/read-file" , map [string ]any {
233
- "id" : opt .WorkspaceID ,
234
- "filePath" : filePath ,
235
- "workspaceTool" : g .globalOpts .WorkspaceTool ,
236
- "env" : g .globalOpts .Env ,
240
+ "id" : opt .WorkspaceID ,
241
+ "filePath" : filePath ,
242
+ "withLatestRevisionID" : opt .WithLatestRevisionID ,
243
+ "workspaceTool" : g .globalOpts .WorkspaceTool ,
244
+ "env" : g .globalOpts .Env ,
237
245
})
238
246
if err != nil {
239
247
if strings .HasSuffix (err .Error (), fmt .Sprintf ("not found: %s/%s" , opt .WorkspaceID , filePath )) {
@@ -242,7 +250,13 @@ func (g *GPTScript) ReadFileInWorkspace(ctx context.Context, filePath string, op
242
250
return nil , err
243
251
}
244
252
245
- return base64 .StdEncoding .DecodeString (out )
253
+ var resp ReadFileInWorkspaceResponse
254
+ err = json .Unmarshal ([]byte (out ), & resp )
255
+ if err != nil {
256
+ return nil , err
257
+ }
258
+
259
+ return & resp , nil
246
260
}
247
261
248
262
type FileInfo struct {
@@ -251,10 +265,12 @@ type FileInfo struct {
251
265
Size int64
252
266
ModTime time.Time
253
267
MimeType string
268
+ RevisionID string
254
269
}
255
270
256
271
type StatFileInWorkspaceOptions struct {
257
- WorkspaceID string
272
+ WorkspaceID string
273
+ WithLatestRevisionID bool
258
274
}
259
275
260
276
func (g * GPTScript ) StatFileInWorkspace (ctx context.Context , filePath string , opts ... StatFileInWorkspaceOptions ) (FileInfo , error ) {
@@ -263,17 +279,19 @@ func (g *GPTScript) StatFileInWorkspace(ctx context.Context, filePath string, op
263
279
if o .WorkspaceID != "" {
264
280
opt .WorkspaceID = o .WorkspaceID
265
281
}
282
+ opt .WithLatestRevisionID = opt .WithLatestRevisionID || o .WithLatestRevisionID
266
283
}
267
284
268
285
if opt .WorkspaceID == "" {
269
286
opt .WorkspaceID = os .Getenv ("GPTSCRIPT_WORKSPACE_ID" )
270
287
}
271
288
272
289
out , err := g .runBasicCommand (ctx , "workspaces/stat-file" , map [string ]any {
273
- "id" : opt .WorkspaceID ,
274
- "filePath" : filePath ,
275
- "workspaceTool" : g .globalOpts .WorkspaceTool ,
276
- "env" : g .globalOpts .Env ,
290
+ "id" : opt .WorkspaceID ,
291
+ "filePath" : filePath ,
292
+ "withLatestRevisionID" : opt .WithLatestRevisionID ,
293
+ "workspaceTool" : g .globalOpts .WorkspaceTool ,
294
+ "env" : g .globalOpts .Env ,
277
295
})
278
296
if err != nil {
279
297
if strings .HasSuffix (err .Error (), fmt .Sprintf ("not found: %s/%s" , opt .WorkspaceID , filePath )) {
@@ -291,16 +309,11 @@ func (g *GPTScript) StatFileInWorkspace(ctx context.Context, filePath string, op
291
309
return info , nil
292
310
}
293
311
294
- type RevisionInfo struct {
295
- FileInfo
296
- RevisionID string
297
- }
298
-
299
312
type ListRevisionsForFileInWorkspaceOptions struct {
300
313
WorkspaceID string
301
314
}
302
315
303
- func (g * GPTScript ) ListRevisionsForFileInWorkspace (ctx context.Context , filePath string , opts ... ListRevisionsForFileInWorkspaceOptions ) ([]RevisionInfo , error ) {
316
+ func (g * GPTScript ) ListRevisionsForFileInWorkspace (ctx context.Context , filePath string , opts ... ListRevisionsForFileInWorkspaceOptions ) ([]FileInfo , error ) {
304
317
var opt ListRevisionsForFileInWorkspaceOptions
305
318
for _ , o := range opts {
306
319
if o .WorkspaceID != "" {
@@ -325,7 +338,7 @@ func (g *GPTScript) ListRevisionsForFileInWorkspace(ctx context.Context, filePat
325
338
return nil , err
326
339
}
327
340
328
- var info []RevisionInfo
341
+ var info []FileInfo
329
342
err = json .Unmarshal ([]byte (out ), & info )
330
343
if err != nil {
331
344
return nil , err
0 commit comments