Skip to content

[Fleet Execution] API Protocol Alignment: Session Deletion #105

@davideast

Description

@davideast

Objective

Implement the delete() method in SessionClient and the corresponding API request logic to support the DELETE /v1alpha/sessions/{name} endpoint. This ensures the SDK provides full lifecycle management capabilities for sessions, allowing users to programmatically delete sessions.

Code-Level Diagnosis

Code path: packages/core/src/types.ts and packages/core/src/session.ts
Mechanism:

  1. Interface Gap: The SessionClient interface in packages/core/src/types.ts does not include a delete() method.
  2. Implementation Gap: The SessionClientImpl class in packages/core/src/session.ts does not implement the logic to call the DELETE endpoint.
  3. API Capability: The Jules v1alpha API supports deleting sessions via DELETE /v1alpha/sessions/{name}.
    Root cause: The delete operation was not originally scoped or implemented in the initial SDK version.

Current Implementation

// packages/core/src/types.ts
export interface SessionClient {
  readonly id: string;
  // ... other methods like archive, unarchive, but no delete
  archive(): Promise<void>;
  unarchive(): Promise<void>;
}

// packages/core/src/session.ts
export class SessionClientImpl implements SessionClient {
  // ... implementation of other methods
}

Proposed Implementation

Files to modify: packages/core/src/types.ts, packages/core/src/session.ts.

  1. Update types.ts:

    • Add delete(): Promise<void> to the SessionClient interface.
  2. Update session.ts:

    • Implement delete() in SessionClientImpl.
    • The method should send a DELETE request to sessions/{id}.
    • It should presumably also clean up local storage for consistency, or rely on the next sync/fetch to handle 404s (as info() already does). For safety and immediate consistency, explicit deletion from sessionStorage is recommended.

Integration (Before → After)

// packages/core/src/types.ts
export interface SessionClient {
  // ...
  unarchive(): Promise<void>;
+ /**
+  * Deletes the session permanently.
+  */
+ delete(): Promise<void>;
}

// packages/core/src/session.ts
export class SessionClientImpl implements SessionClient {
  // ...
+ async delete(): Promise<void> {
+   await this.request(`sessions/${this.id}`, {
+     method: 'DELETE',
+   });
+   await this.sessionStorage.delete(this.id);
+ }
}

Test Scenarios

  1. Delete Session:
    • Action: Call session.delete().
    • Expected:
      • API request DELETE sessions/{id} is made.
      • Local storage for the session is cleared.
      • Subsequent session.info() calls result in 404/Error (or handled gracefully).

Target Files

  • packages/core/src/types.ts
  • packages/core/src/session.ts
  • packages/core/tests/session.test.ts

Boundary Rules

Restrict your modifications exclusively to the files listed in the Target Files section. Ensure your source changes are entirely backward-compatible if unowned tests outside your boundary fail. Retain all existing file names and locations outside your explicitly declared target list.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions