This pull request primarily involves changes to enhance error handling and improve code quality in the sdk/js/packages/client and sdk/js/samples/react directories. The key changes include the introduction of a new utility function isErrorResponse for error handling, updates to the AIChatProtocolClient class, and refactoring of the Chat component in the React sample.
Error handling enhancements:
sdk/js/packages/client/src/client.ts: Removed the isErrorResponse function and imported it from error.js instead. Also, changed the return type of getStreamContent from Promise<any> to Promise<unknown> and updated the handleFailedRequest function to accept status as a string and body as unknown. [1][2][3][4]
sdk/js/samples/react/src/Chat.tsx: Refactored the Chat component to handle AIChatError and display error messages. Also, made formatting changes for code consistency. [1][2][3]
This pull request primarily involves changes to enhance error handling and improve code quality in the
sdk/js/packages/client
andsdk/js/samples/react
directories. The key changes include the introduction of a new utility functionisErrorResponse
for error handling, updates to theAIChatProtocolClient
class, and refactoring of theChat
component in the React sample.Error handling enhancements:
sdk/js/packages/client/src/client.ts
: Removed theisErrorResponse
function and imported it fromerror.js
instead. Also, changed the return type ofgetStreamContent
fromPromise<any>
toPromise<unknown>
and updated thehandleFailedRequest
function to acceptstatus
as astring
andbody
asunknown
. [1] [2] [3] [4]sdk/js/packages/client/src/util/error.ts
: Introduced a new utility functionisErrorResponse
to check if a response is an error response.sdk/js/packages/client/src/util/ndjson.ts
: Imported theisErrorResponse
function and used it to throw an error if a parsed line from a stream is an error response. [1] [2]sdk/js/packages/client/test/util/ndjson.shared.test.ts
: Added tests to check if an exception is thrown when the stream contains anAIChatErrorResponse
. [1] [2]Code quality improvements:
sdk/js/samples/react/package.json
: Added a new script for code formatting using Prettier and updated dependencies. [1] [2]sdk/js/samples/react/src/App.tsx
: Minor formatting changes for code consistency.sdk/js/samples/react/src/Chat.tsx
: Refactored theChat
component to handleAIChatError
and display error messages. Also, made formatting changes for code consistency. [1] [2] [3]sdk/js/samples/react/src/main.tsx
: Minor formatting changes for code consistency.sdk/js/samples/react/vite.config.ts
: Added a proxy configuration for the Vite server.sdk/js/samples/server/package.json
: Updated the version of@microsoft/ai-chat-protocol
in the devDependencies.