-
Notifications
You must be signed in to change notification settings - Fork 9
Description
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:
- Interface Gap: The
SessionClientinterface inpackages/core/src/types.tsdoes not include adelete()method. - Implementation Gap: The
SessionClientImplclass inpackages/core/src/session.tsdoes not implement the logic to call theDELETEendpoint. - API Capability: The Jules v1alpha API supports deleting sessions via
DELETE /v1alpha/sessions/{name}.
Root cause: Thedeleteoperation 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.
-
Update
types.ts:- Add
delete(): Promise<void>to theSessionClientinterface.
- Add
-
Update
session.ts:- Implement
delete()inSessionClientImpl. - The method should send a
DELETErequest tosessions/{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 fromsessionStorageis recommended.
- Implement
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
- 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).
- API request
- Action: Call
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.