Skip to content

Cancel session#4

Open
saleszera wants to merge 11 commits intomainfrom
cancel-session
Open

Cancel session#4
saleszera wants to merge 11 commits intomainfrom
cancel-session

Conversation

@saleszera
Copy link
Copy Markdown
Owner

CHANGELOG 📝

Note

This pull request introduces a significant refactor and expansion of the ChatKit session management subsystem, adding explicit support for session creation and cancellation operations, and restructuring response handling for clarity and maintainability. The changes also improve endpoint handling and error management.

The most important changes are:

Session Management Refactor & Features:

  • Refactored the Session class to delegate session creation and cancellation to new dedicated classes (Session::Create and Session::Cancel), simplifying the interface and improving separation of concerns. Now, session creation and cancellation are performed via the Create.call and Cancel.call methods, and session state is managed through a single @session attribute. [1] [2] [3]
  • Added new Session::Create, Session::Cancel, and corresponding response and scope classes (Session::Create::Response, Session::Cancel::Response, Session::Cancel::Scope) to encapsulate the logic and data for session creation and cancellation operations. [1] [2] [3] [4] [5]
  • Introduced a new base response class (Session::BaseResponse) and updated response classes to inherit from it, replacing the previous Session::Response.

API Endpoint and Error Handling Improvements:

  • Updated the endpoints in Request::Endpoints to explicitly distinguish between session creation and cancellation, and improved the endpoint method to accept path parameters for dynamic endpoint construction. [1] [2]
  • Enhanced error handling for session operations, providing more specific error classes and clearer error messages for session creation and cancellation failures. [1] [2]

Workflow and Data Handling Adjustments:

  • Improved workflow deserialization and data parsing logic to better handle nil workflow data and avoid unnecessary method indirection in conversation response items. [1] [2] [3] [4] [5]

Other Changes:

  • Removed the vcr gem from the Gemfile, possibly to clean up unused test dependencies.
  • Bumped the gem version to 0.2.0 to reflect these breaking changes and new features.

that's all folks

@saleszera saleszera requested a review from Copilot January 5, 2026 15:12
@saleszera saleszera self-assigned this Jan 5, 2026
@saleszera saleszera added the enhancement New feature or request label Jan 5, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces session cancellation functionality and refactors the session management system by separating creation and cancellation into dedicated operation classes. The changes include a new cancel session endpoint, updated response handling with a base response class, and removal of the VCR test dependency.

  • Introduced Session::Create and Session::Cancel classes to handle session operations explicitly
  • Added session cancellation capability with dedicated response and scope classes
  • Refactored response handling with a new Session::BaseResponse base class

Reviewed changes

Copilot reviewed 43 out of 75 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
lib/chatkit/version.rb Bumped version to 0.2.0 for breaking changes
lib/chatkit/session/create.rb New class encapsulating session creation logic
lib/chatkit/session/cancel.rb New class implementing session cancellation
lib/chatkit/session/base_response.rb Renamed Response to BaseResponse as parent class
lib/chatkit/session/create/response.rb Response class for session creation
lib/chatkit/session/cancel/response.rb Response class with cancellation-specific fields
lib/chatkit/session/cancel/scope.rb New scope class for cancel response data
lib/chatkit/request/endpoints.rb Added cancel endpoint and dynamic path parameter support
lib/chatkit/session/workflow.rb Added nil check guard in deserialize method
lib/chatkit/conversation/response/thread/item/workflow.rb Added nil check in from_event method
spec/chatkit/request/endpoints_spec.rb Updated test for renamed endpoint method
spec/chatkit/client_spec.rb Simplified configuration tests using direct assignment
Gemfile Removed vcr gem dependency
spec/cassettes/* Removed VCR cassette files

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +22 to +29
define_method "#{const_name.to_s.downcase}_endpoint" do |path_params = {}|
if path_params
raise ArgumentError, "Path parameters must be provided as a Hash" unless path_params.is_a?(Hash)

format(ChatKit::Request::Endpoints.const_get(const_name), **path_params)
else
ChatKit::Request::Endpoints.const_get(const_name)
end
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition if path_params will always be true since it defaults to {}. An empty hash is truthy in Ruby, so the else branch at line 28 is unreachable. Change the condition to if path_params.any? or unless path_params.empty? to properly detect when parameters are provided.

Copilot uses AI. Check for mistakes.

private

# Performs the HTTP request to create a session.
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment incorrectly states "create a session" when the method actually cancels a session. Update to "Performs the HTTP request to cancel a session."

Suggested change
# Performs the HTTP request to create a session.
# Performs the HTTP request to cancel a session.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants