@watasu/sdk 0.1.53 → 0.1.66

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/README.md CHANGED
@@ -156,6 +156,15 @@ await sbx.files.writeFiles([
156
156
  { path: '/workspace/project/a.txt', data: 'alpha' },
157
157
  { path: '/workspace/project/b.bin', data: new Uint8Array([0, 1, 2]) },
158
158
  ])
159
+ const patch = await sbx.files.applyDiff(
160
+ `*** Begin Patch
161
+ *** Update File: /workspace/project/a.txt
162
+ @@
163
+ -alpha
164
+ +beta
165
+ *** End Patch`
166
+ )
167
+ console.log(patch.status)
159
168
 
160
169
  const watcher = sbx.files.watchDir('/workspace/project')
161
170
  watcher.addEventListener((event) => {
@@ -68,6 +68,41 @@ export interface FilesystemWriteOpts extends FilesystemRequestOpts {
68
68
  useOctetStream?: boolean;
69
69
  metadata?: Record<string, string>;
70
70
  }
71
+ export interface ApplyDiffOpts extends FilesystemRequestOpts {
72
+ cwd?: string;
73
+ }
74
+ export interface ApplyDiffFailedHunk {
75
+ index: number;
76
+ oldStart: number;
77
+ }
78
+ export interface ApplyDiffFailure {
79
+ path: string;
80
+ error: string;
81
+ failedHunk?: ApplyDiffFailedHunk;
82
+ }
83
+ export interface ApplyDiffFileSummary {
84
+ path: string;
85
+ sourcePath?: string;
86
+ kind: string;
87
+ added: number;
88
+ removed: number;
89
+ }
90
+ export interface ApplyDiffSummary {
91
+ requested: number;
92
+ applied: number;
93
+ failed: number;
94
+ }
95
+ export interface ApplyDiffReport {
96
+ status: 'applied' | 'partial' | 'failed' | string;
97
+ parsedDiffBlocks: number;
98
+ patches: number;
99
+ files: ApplyDiffFileSummary[];
100
+ summary: ApplyDiffSummary;
101
+ applied: string[];
102
+ failed: ApplyDiffFailure[];
103
+ touched: string[];
104
+ raw: Record<string, unknown>;
105
+ }
71
106
  /** Live filesystem watcher. Call `stop()` to close the local watch stream. */
72
107
  export declare class WatchHandle {
73
108
  private readonly socket;
@@ -130,6 +165,8 @@ export declare class Filesystem {
130
165
  remove(path: string, opts?: FilesystemRequestOpts): Promise<void>;
131
166
  /** Move or rename a file. */
132
167
  rename(oldPath: string, newPath: string, opts?: FilesystemRequestOpts): Promise<EntryInfo>;
168
+ /** Apply a git-style unified diff or Codex apply_patch payload inside the sandbox. */
169
+ applyDiff(diff: string, opts?: ApplyDiffOpts): Promise<ApplyDiffReport>;
133
170
  /** Create a directory. */
134
171
  makeDir(path: string, opts?: FilesystemRequestOpts): Promise<boolean>;
135
172
  /** Start watching a directory for filesystem events. */
@@ -183,6 +183,17 @@ export class Filesystem {
183
183
  });
184
184
  return entryInfo(payload.file ?? payload);
185
185
  }
186
+ /** Apply a git-style unified diff or Codex apply_patch payload inside the sandbox. */
187
+ async applyDiff(diff, opts = {}) {
188
+ const payload = await this.dataPlane.postJson('/runtime/v1/files/apply_diff', {
189
+ ...requestOpts(opts),
190
+ json: {
191
+ diff,
192
+ ...(opts.cwd ? { cwd: opts.cwd } : {}),
193
+ },
194
+ });
195
+ return applyDiffReport(payload);
196
+ }
186
197
  /** Create a directory. */
187
198
  async makeDir(path, opts = {}) {
188
199
  await this.dataPlane.postJson(withQuery('/runtime/v1/directories', { path }), opts);
@@ -312,6 +323,60 @@ function filesystemEvent(value) {
312
323
  raw: item,
313
324
  };
314
325
  }
326
+ function applyDiffReport(value) {
327
+ const item = value && typeof value === 'object' ? value : {};
328
+ return {
329
+ status: String(item.status ?? ''),
330
+ parsedDiffBlocks: requiredNumber(item.parsed_diff_blocks),
331
+ patches: requiredNumber(item.patches),
332
+ files: Array.isArray(item.files) ? item.files.map(applyDiffFileSummary) : [],
333
+ summary: applyDiffSummary(item.summary),
334
+ applied: stringArray(item.applied),
335
+ failed: Array.isArray(item.failed) ? item.failed.map(applyDiffFailure) : [],
336
+ touched: stringArray(item.touched),
337
+ raw: item,
338
+ };
339
+ }
340
+ function applyDiffSummary(value) {
341
+ const item = value && typeof value === 'object' ? value : {};
342
+ return {
343
+ requested: requiredNumber(item.requested),
344
+ applied: requiredNumber(item.applied),
345
+ failed: requiredNumber(item.failed),
346
+ };
347
+ }
348
+ function applyDiffFileSummary(value) {
349
+ const item = value && typeof value === 'object' ? value : {};
350
+ return {
351
+ path: String(item.path ?? ''),
352
+ sourcePath: typeof item.source_path === 'string' ? item.source_path : undefined,
353
+ kind: String(item.kind ?? ''),
354
+ added: requiredNumber(item.added),
355
+ removed: requiredNumber(item.removed),
356
+ };
357
+ }
358
+ function applyDiffFailure(value) {
359
+ const item = value && typeof value === 'object' ? value : {};
360
+ const failedHunk = item.failed_hunk && typeof item.failed_hunk === 'object'
361
+ ? item.failed_hunk
362
+ : undefined;
363
+ return {
364
+ path: String(item.path ?? ''),
365
+ error: String(item.error ?? ''),
366
+ failedHunk: failedHunk
367
+ ? {
368
+ index: requiredNumber(failedHunk.index),
369
+ oldStart: requiredNumber(failedHunk.old_start),
370
+ }
371
+ : undefined,
372
+ };
373
+ }
374
+ function requiredNumber(value) {
375
+ return typeof value === 'number' && Number.isFinite(value) ? value : 0;
376
+ }
377
+ function stringArray(value) {
378
+ return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
379
+ }
315
380
  function normalizeEventType(value) {
316
381
  if (value === 'delete')
317
382
  return FilesystemEventType.REMOVE;
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ export type { CommandConnectOpts, CommandRequestOpts, CommandResult, CommandStar
12
12
  export { Process, ProcessManager, ProcessMessage, ProcessOutput } from './process.js';
13
13
  export type { ProcessOpts } from './process.js';
14
14
  export { FileType, Filesystem, FilesystemEventType, FilesystemWatcher, WatchHandle, } from './filesystem.js';
15
- export type { EntryInfo, FilesystemEvent, FilesystemReadOpts, FilesystemRequestOpts, FilesystemWriteOpts, WatchOpts, WriteData, WriteEntry, WriteInfo, } from './filesystem.js';
15
+ export type { ApplyDiffFailure, ApplyDiffFailedHunk, ApplyDiffFileSummary, ApplyDiffOpts, ApplyDiffReport, ApplyDiffSummary, EntryInfo, FilesystemEvent, FilesystemReadOpts, FilesystemRequestOpts, FilesystemWriteOpts, WatchOpts, WriteData, WriteEntry, WriteInfo, } from './filesystem.js';
16
16
  export { Git } from './git.js';
17
17
  export type { GitAddOpts, GitAuthOpts, GitBranches, GitBranchOpts, GitCloneOpts, GitCommandResult, GitConfigScope, GitConfigOpts, GitConfigureUserOpts, GitCredentialOpts, GitCommitOpts, GitDangerouslyAuthenticateOpts, GitDeleteBranchOpts, GitFileStatus, GitInitOpts, GitPullOpts, GitPushOpts, GitRemoteAddOpts, GitResetMode, GitResetOpts, GitRestoreOpts, GitRequestOpts, GitStatus, } from './git.js';
18
18
  export { Pty } from './pty.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@watasu/sdk",
3
- "version": "0.1.53",
3
+ "version": "0.1.66",
4
4
  "type": "module",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "description": "TypeScript SDK for Watasu",