Skip to content

Conversation

@AnthonyRonning
Copy link
Contributor

@AnthonyRonning AnthonyRonning commented Dec 29, 2025

Summary

Implements the batch delete conversations endpoint as specified in #57.

Changes

TypeScript SDK

  • Added BatchDeleteConversationsRequest, BatchDeleteItemResult, and BatchDeleteConversationsResponse types
  • Added batchDeleteConversations(ids: string[]) function in api.ts
  • Exported new types from index.ts
  • Added to OpenSecretContextType and OpenSecretProvider in main.tsx

Rust SDK

  • Added corresponding structs in types.rs
  • Added batch_delete_conversations(ids: Vec<String>) method in client.rs

Tests

  • Added integration test covering:
    • Successful batch deletion of multiple conversations
    • Partial failure handling (non-existent IDs return not_found error)

API

const result = await batchDeleteConversations([
  "550e8400-e29b-41d4-a716-446655440000",
  "550e8400-e29b-41d4-a716-446655440001"
]);
// Returns per-item results for partial failure handling

Closes #57

Summary by CodeRabbit

Release Notes

  • New Features

    • Batch delete conversations: Users can now delete multiple conversations in a single API call, with per-item results showing success or error status.
  • Tests

    • Added integration tests for batch deletion functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

Adds POST /v1/conversations/batch-delete endpoint support:
- TypeScript: batchDeleteConversations(ids: string[]) function and types
- Rust: batch_delete_conversations(ids: Vec<String>) method and types
- Exports types from index.ts and adds to OpenSecretProvider context
- Integration test covering success and partial failure cases

Closes #57

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

This PR adds batch deletion support for conversations across the Rust and TypeScript SDKs. It introduces new types and methods (batch_delete_conversations in Rust, batchDeleteConversations in TypeScript) that call the backend's POST /v1/conversations/batch-delete endpoint, returning per-item deletion results with optional error details.

Changes

Cohort / File(s) Summary
Rust SDK Type Definitions
rust/src/types.rs
Adds three new public structs: BatchDeleteConversationsRequest (request with ids field), BatchDeleteItemResult (per-item result with id, object, deleted, and optional error), and BatchDeleteConversationsResponse (wrapping data vec of results). All derive standard traits (Debug, Clone, Serialize, Deserialize).
Rust SDK Client Method
rust/src/client.rs
Adds new async method batch_delete_conversations(ids: Vec<String>) to OpenSecretClient that constructs a BatchDeleteConversationsRequest and performs an encrypted POST call to /v1/conversations/batch-delete, returning BatchDeleteConversationsResponse.
TypeScript SDK Type Definitions
src/lib/api.ts
Adds three new exported types: BatchDeleteConversationsRequest (with ids: string[]), BatchDeleteItemResult (with id, object, deleted, and optional error fields), and BatchDeleteConversationsResponse (with object and data array). Also adds new public function batchDeleteConversations(ids: string[]).
TypeScript SDK Exports & Context
src/lib/index.ts, src/lib/main.tsx
Exports three new types from "./api" in index.ts. Updates OpenSecretContextType interface to expose batchDeleteConversations property and wires it into the provider context value in main.tsx.
Integration Test
src/lib/test/integration/ai.test.ts
Adds "Batch delete conversations" test that: creates three conversations, batch deletes the first two, verifies deletions and remaining conversation, tests partial failure with non-existent ID returning not_found, and confirms all deletions. Uses existing listConversations and deleteConversations utilities for state verification.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • OpenAI responses #45: Modifies the conversations API surface (src/lib/api.ts and context wiring in src/lib/main.tsx) with conversation-related functionality that this PR directly extends with batch operations.

Poem

🐰 A batch of chats, now deleted in one fell swoop—
No more one-by-one, we've formed a loop!
Per-item results keep the errors in sight,
Multiple conversations goodbye in one bite! 🗑️

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add batch delete conversations endpoint' clearly and accurately describes the main change - adding batch deletion functionality for conversations.
Linked Issues check ✅ Passed The PR implementation fully satisfies #57 requirements: endpoint support with POST /v1/conversations/batch-delete, proper request/response shapes, per-item results handling, and SDK method in both TypeScript and Rust.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing the batch delete conversations endpoint across TypeScript and Rust SDKs with appropriate types, methods, exports, and integration tests.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98a7ec8 and 8904fd3.

📒 Files selected for processing (6)
  • rust/src/client.rs
  • rust/src/types.rs
  • src/lib/api.ts
  • src/lib/index.ts
  • src/lib/main.tsx
  • src/lib/test/integration/ai.test.ts
🧰 Additional context used
🧬 Code graph analysis (3)
rust/src/client.rs (2)
src/lib/api.ts (2)
  • BatchDeleteConversationsResponse (1667-1670)
  • BatchDeleteConversationsRequest (1656-1658)
src/lib/index.ts (2)
  • BatchDeleteConversationsResponse (31-31)
  • BatchDeleteConversationsRequest (29-29)
rust/src/types.rs (2)
src/lib/api.ts (3)
  • BatchDeleteConversationsRequest (1656-1658)
  • BatchDeleteItemResult (1660-1665)
  • BatchDeleteConversationsResponse (1667-1670)
src/lib/index.ts (3)
  • BatchDeleteConversationsRequest (29-29)
  • BatchDeleteItemResult (30-30)
  • BatchDeleteConversationsResponse (31-31)
src/lib/test/integration/ai.test.ts (3)
src/lib/api.ts (3)
  • deleteConversations (1969-1976)
  • listConversations (2125-2153)
  • batchDeleteConversations (2005-2014)
src/lib/index.ts (1)
  • createCustomFetch (38-38)
src/lib/ai.ts (1)
  • createCustomFetch (9-204)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Greptile Review
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (10)
src/lib/api.ts (2)

1978-2014: LGTM!

The implementation follows established patterns in this codebase and includes clear documentation with helpful examples. The function correctly handles the batch deletion request and returns per-item results for error handling.


1656-1670: Use literal types for object fields to improve type safety.

The object fields in BatchDeleteItemResult and BatchDeleteConversationsResponse should use literal types instead of string for consistency with other similar types in this codebase (e.g., ConversationDeleteResponse at line 1647 and ConversationsDeleteResponse at line 1652).

🔎 Suggested fix for type definitions
 export type BatchDeleteConversationsRequest = {
   ids: string[];
 };
 
 export type BatchDeleteItemResult = {
   id: string;
-  object: "conversation.deleted";
+  object: "conversation.deleted";
   deleted: boolean;
   error?: "not_found" | "delete_failed";
 };
 
 export type BatchDeleteConversationsResponse = {
-  object: "list";
+  object: "list";
   data: BatchDeleteItemResult[];
 };

Wait, let me check the actual code again - looking at the annotated code, I see:

  • Line 1662: object: "conversation.deleted"; - this already uses a literal!
  • Line 1668: object: "list"; - this already uses a literal!

Actually on closer inspection of the code, the types ARE already using literal types. My initial analysis was wrong. Let me reconsider...

Likely an incorrect or invalid review comment.

src/lib/main.tsx (3)

774-779: LGTM!

The new batch delete method is properly added to the context type interface with appropriate JSDoc documentation.


927-927: LGTM!

The default context value correctly wires through the API function.


1343-1343: LGTM!

The provider value correctly exposes the batch delete function through the context.

src/lib/index.ts (1)

28-31: LGTM!

The new batch deletion types are correctly exported alongside related conversation types.

rust/src/client.rs (1)

953-961: LGTM!

The Rust implementation correctly follows the established pattern for encrypted API calls and properly handles batch deletion requests with per-item result handling.

src/lib/test/integration/ai.test.ts (2)

7-7: LGTM!

The import is correctly added for the new batch delete function.


1134-1193: Excellent test coverage!

This integration test comprehensively validates the batch deletion API:

  • Tests successful batch deletion
  • Verifies per-item results
  • Tests partial failure handling with non-existent IDs
  • Validates the not_found error field
  • Properly cleans up test data

The test provides confidence that the new batch deletion endpoint works correctly for both success and error cases.

rust/src/types.rs (1)

307-325: LGTM!

The Rust type definitions correctly model the batch deletion API surface and align with the TypeScript types. The use of #[serde(skip_serializing_if = "Option::is_none")] for the optional error field ensures clean JSON serialization.


Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

Deploying opensecret-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8904fd3
Status: ✅  Deploy successful!
Preview URL: https://cee44975.opensecret-sdk.pages.dev
Branch Preview URL: https://feat-batch-delete-conversati.opensecret-sdk.pages.dev

View logs

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 29, 2025

Greptile Summary

This PR implements a batch delete conversations endpoint across both TypeScript and Rust SDKs. The implementation adds the ability to delete multiple conversations in a single API call with per-item result handling for partial failures.

Key Changes

  • Added batchDeleteConversations() method in both TypeScript and Rust SDKs
  • Implemented proper type definitions (BatchDeleteConversationsRequest, BatchDeleteItemResult, BatchDeleteConversationsResponse) with matching structures across both languages
  • Integrated the new method into React context provider for seamless usage
  • Added comprehensive integration tests covering successful batch deletion and partial failure scenarios (non-existent IDs)

Implementation Quality

The implementation follows existing patterns in the codebase consistently. The TypeScript implementation uses the standard authenticatedApiCall wrapper, while the Rust implementation uses encrypted_api_call. Both approaches align with their respective SDK architectures. The types are properly exported and documented with clear JSDoc comments and usage examples.

The test coverage is thorough, validating both happy path (successful batch deletion) and error handling (non-existent conversation IDs returning not_found errors). The test properly verifies the per-item result structure, ensuring partial failures are handled correctly.

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The implementation is clean, well-tested, and follows established patterns. All type definitions match across TypeScript and Rust implementations. The comprehensive integration test validates both success and error scenarios. The code integrates seamlessly with existing conversation management functionality.
  • No files require special attention

Important Files Changed

Filename Overview
src/lib/api.ts Added batch delete conversations endpoint with proper types and documentation
src/lib/index.ts Exported new batch delete types for public API
src/lib/main.tsx Added batch delete to React context and provider
rust/src/client.rs Implemented batch delete conversations method in Rust client
rust/src/types.rs Added batch delete request/response structs with proper serialization
src/lib/test/integration/ai.test.ts Added comprehensive integration test covering batch delete success and partial failures

Sequence Diagram

sequenceDiagram
    participant Client as SDK Client
    participant API as batchDeleteConversations()
    participant Backend as API Server
    participant DB as Database

    Client->>API: batchDeleteConversations(ids[])
    API->>API: Create request payload
    API->>Backend: POST /v1/conversations/batch-delete
    Backend->>Backend: Validate user permissions
    
    loop For each conversation ID
        Backend->>DB: Query and remove conversation
        alt Success
            DB-->>Backend: Conversation removed
            Backend->>Backend: Add result: deleted=true
        else Not found
            DB-->>Backend: Not found
            Backend->>Backend: Add result: deleted=false, error=not_found
        else Failure
            DB-->>Backend: Database error
            Backend->>Backend: Add result: deleted=false, error=delete_failed
        end
    end
    
    Backend->>Backend: Build response with all results
    Backend-->>API: BatchDeleteConversationsResponse
    API-->>Client: Return per-item results
Loading

@AnthonyRonning AnthonyRonning merged commit 55a0470 into master Dec 29, 2025
8 of 9 checks passed
@AnthonyRonning AnthonyRonning deleted the feat/batch-delete-conversations branch December 29, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add batch delete conversations endpoint

2 participants