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
SessionClient interface in packages/core/src/types.ts does not include a delete() method.
- Implementation Gap: The
SessionClientImpl class in packages/core/src/session.ts does not implement the logic to call the DELETE endpoint.
- 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.
-
Update types.ts:
- Add
delete(): Promise<void> to the SessionClient interface.
-
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
- 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.
Objective
Implement the
delete()method inSessionClientand the corresponding API request logic to support theDELETE /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.tsandpackages/core/src/session.tsMechanism:
SessionClientinterface inpackages/core/src/types.tsdoes not include adelete()method.SessionClientImplclass inpackages/core/src/session.tsdoes not implement the logic to call theDELETEendpoint.DELETE /v1alpha/sessions/{name}.Root cause: The
deleteoperation was not originally scoped or implemented in the initial SDK version.Current Implementation
Proposed Implementation
Files to modify:
packages/core/src/types.ts,packages/core/src/session.ts.Update
types.ts:delete(): Promise<void>to theSessionClientinterface.Update
session.ts:delete()inSessionClientImpl.DELETErequest tosessions/{id}.info()already does). For safety and immediate consistency, explicit deletion fromsessionStorageis 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
session.delete().DELETE sessions/{id}is made.session.info()calls result in 404/Error (or handled gracefully).Target Files
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.