@@ -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 )
@@ -245,16 +245,57 @@ func (g *GPTScript) ReadFileInWorkspace(ctx context.Context, filePath string, op
245
245
return base64 .StdEncoding .DecodeString (out )
246
246
}
247
247
248
+ type ReadFileWithRevisionInWorkspaceResponse struct {
249
+ Content []byte `json:"content"`
250
+ RevisionID string `json:"revisionID"`
251
+ }
252
+
253
+ func (g * GPTScript ) ReadFileWithRevisionInWorkspace (ctx context.Context , filePath string , opts ... ReadFileInWorkspaceOptions ) (* ReadFileWithRevisionInWorkspaceResponse , error ) {
254
+ var opt ReadFileInWorkspaceOptions
255
+ for _ , o := range opts {
256
+ if o .WorkspaceID != "" {
257
+ opt .WorkspaceID = o .WorkspaceID
258
+ }
259
+ }
260
+
261
+ if opt .WorkspaceID == "" {
262
+ opt .WorkspaceID = os .Getenv ("GPTSCRIPT_WORKSPACE_ID" )
263
+ }
264
+
265
+ out , err := g .runBasicCommand (ctx , "workspaces/read-file-with-revision" , map [string ]any {
266
+ "id" : opt .WorkspaceID ,
267
+ "filePath" : filePath ,
268
+ "workspaceTool" : g .globalOpts .WorkspaceTool ,
269
+ "env" : g .globalOpts .Env ,
270
+ })
271
+ if err != nil {
272
+ if strings .HasSuffix (err .Error (), fmt .Sprintf ("not found: %s/%s" , opt .WorkspaceID , filePath )) {
273
+ return nil , newNotFoundInWorkspaceError (opt .WorkspaceID , filePath )
274
+ }
275
+ return nil , err
276
+ }
277
+
278
+ var resp ReadFileWithRevisionInWorkspaceResponse
279
+ err = json .Unmarshal ([]byte (out ), & resp )
280
+ if err != nil {
281
+ return nil , err
282
+ }
283
+
284
+ return & resp , nil
285
+ }
286
+
248
287
type FileInfo struct {
249
288
WorkspaceID string
250
289
Name string
251
290
Size int64
252
291
ModTime time.Time
253
292
MimeType string
293
+ RevisionID string
254
294
}
255
295
256
296
type StatFileInWorkspaceOptions struct {
257
- WorkspaceID string
297
+ WorkspaceID string
298
+ WithLatestRevisionID bool
258
299
}
259
300
260
301
func (g * GPTScript ) StatFileInWorkspace (ctx context.Context , filePath string , opts ... StatFileInWorkspaceOptions ) (FileInfo , error ) {
@@ -263,17 +304,19 @@ func (g *GPTScript) StatFileInWorkspace(ctx context.Context, filePath string, op
263
304
if o .WorkspaceID != "" {
264
305
opt .WorkspaceID = o .WorkspaceID
265
306
}
307
+ opt .WithLatestRevisionID = opt .WithLatestRevisionID || o .WithLatestRevisionID
266
308
}
267
309
268
310
if opt .WorkspaceID == "" {
269
311
opt .WorkspaceID = os .Getenv ("GPTSCRIPT_WORKSPACE_ID" )
270
312
}
271
313
272
314
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 ,
315
+ "id" : opt .WorkspaceID ,
316
+ "filePath" : filePath ,
317
+ "withLatestRevisionID" : opt .WithLatestRevisionID ,
318
+ "workspaceTool" : g .globalOpts .WorkspaceTool ,
319
+ "env" : g .globalOpts .Env ,
277
320
})
278
321
if err != nil {
279
322
if strings .HasSuffix (err .Error (), fmt .Sprintf ("not found: %s/%s" , opt .WorkspaceID , filePath )) {
@@ -291,16 +334,11 @@ func (g *GPTScript) StatFileInWorkspace(ctx context.Context, filePath string, op
291
334
return info , nil
292
335
}
293
336
294
- type RevisionInfo struct {
295
- FileInfo
296
- RevisionID string
297
- }
298
-
299
337
type ListRevisionsForFileInWorkspaceOptions struct {
300
338
WorkspaceID string
301
339
}
302
340
303
- func (g * GPTScript ) ListRevisionsForFileInWorkspace (ctx context.Context , filePath string , opts ... ListRevisionsForFileInWorkspaceOptions ) ([]RevisionInfo , error ) {
341
+ func (g * GPTScript ) ListRevisionsForFileInWorkspace (ctx context.Context , filePath string , opts ... ListRevisionsForFileInWorkspaceOptions ) ([]FileInfo , error ) {
304
342
var opt ListRevisionsForFileInWorkspaceOptions
305
343
for _ , o := range opts {
306
344
if o .WorkspaceID != "" {
@@ -325,7 +363,7 @@ func (g *GPTScript) ListRevisionsForFileInWorkspace(ctx context.Context, filePat
325
363
return nil , err
326
364
}
327
365
328
- var info []RevisionInfo
366
+ var info []FileInfo
329
367
err = json .Unmarshal ([]byte (out ), & info )
330
368
if err != nil {
331
369
return nil , err
0 commit comments