Skip to content

Sync features: Lex streaming, transcript updates, and agent metrics#309

Merged
saipreetham16 merged 7 commits intomasterfrom
sleburu/sync-internal-lex-streaming
Feb 6, 2026
Merged

Sync features: Lex streaming, transcript updates, and agent metrics#309
saipreetham16 merged 7 commits intomasterfrom
sleburu/sync-internal-lex-streaming

Conversation

@saipreetham16
Copy link
Contributor

Sync features: Lex streaming, transcript updates, and agent metrics


Overview

Adding support for Lex streaming responses, real-time transcript tracking, and agent-specific metrics.

Changes Summary

Customer-Facing Features

  • Lex Streaming Support: Bot responses are now stitched from streaming chunks before being displayed
  • Transcript Updates: New onTranscriptUpdated event provides real-time transcript state with message statuses
  • Workflow Events: Added support for workflow cancellation events

Developer Features

  • TypeScript Types: Added MessageProcessingStatus type definition
  • Agent Metrics: Track connection errors for agent sessions (excludes 4xx client errors)
  • Enhanced Metadata: Messages now include MessageCompleted, ChunkNumber, and MessageProcessingStatus fields

Commits Included

  1. Add partial message stitching (93a3ea4)

    • Handles bot messages sent in chunks
    • Stitches partial messages before emitting to UI
    • Prevents flickering/incomplete messages in chat widget
  2. Add transcriptUpdated event (e871068)

    • New chatSession.onTranscriptUpdated() callback
    • Provides full transcript state with message statuses
    • Auto-fetches 100 messages on connection
    • Tracks message lifecycle: SENDING → SENT → DELIVERED → READ
  3. Add workflow cancelled event (a73ec52)

    • Adds workflowCanceled content type constant
    • Enables handling of workflow cancellation events from Connect flows
  4. Support Lex streaming for transcriptUpdated (86ca9f6)

    • Fixes transcript tracking for partial/streaming messages
    • Tracks stitched messages instead of individual chunks
    • Adds MessageCompleted and ChunkNumber to TypeScript types
  5. Add agent metrics (f2c5177)

    • Track AGENT_CREATE_PARTICIPANT_ERROR_RATE metric
    • Track AGENT_GET_CONNECTION_TOKEN_ERROR_RATE metric
    • Agent-session specific, doesn't affect customer sessions
  6. Add MessageProcessingStatus TypeScript type (80b9daa)

    • Adds interface for message processing states: PROCESSING, FAILED, REJECTED
    • Improves TypeScript support for message metadata
  7. Update default max results for transcript (5b94790)

    • Increases auto-fetch from 15 to 100 messages on connection
    • Improves initial transcript completeness
  8. Exclude 4xx errors from agent error metric (91e963f)

    • Only tracks 5xx and network errors as service failures
    • 4xx errors are client errors, not service issues

Testing

Automated Tests

  • All 279 unit tests passing
  • No breaking changes to existing APIs

Manual Testing

  • Partial message stitching verified with Lex bot
  • Transcript updates fire correctly on all events
  • Message metadata fields populated correctly
  • No console errors in customer or agent sessions

Test Coverage

  • Partial message stitching: PartialMessageUtil.spec.js
  • Transcript updates: chatController.transcript.spec.js, internalTranscriptUtils.spec.js
  • Agent metrics: connectionDetailsProvider.spec.js

Breaking Changes

None. All changes are backward compatible.

API Changes

New APIs

// New event subscription
chatSession.onTranscriptUpdated((event) => {
  console.log(event.data.transcript); // Array of messages with statuses
  console.log(event.data.previousTranscriptNextToken); // Pagination token
});

New TypeScript Types

interface MessageProcessingStatus {
  readonly PROCESSING: "PROCESSING";
  readonly FAILED: "FAILED";
  readonly REJECTED: "REJECTED";
}

interface MessageMetadata {
  MessageProcessingStatus?: MessageProcessingStatus[keyof MessageProcessingStatus];
  MessageCompleted?: boolean;
  ChunkNumber?: number;
}

New Constants

CONTENT_TYPE.workflowCanceled
AGENT_CREATE_PARTICIPANT_ERROR_RATE
AGENT_GET_CONNECTION_TOKEN_ERROR_RATE
MESSAGE_STATUS.SENDING | SENT | DELIVERED | READ | FAILED | UNKNOWN

Screen.Recording.2026-01-30.at.10.32.46.PM.mov

- Add PartialMessageUtil for handling bot partial messages
- Integrate partial message stitching in chatController
- Add rehydration support in getTranscript
- Add comprehensive test coverage

Internal commit: 93a3ea4
- Add InternalTranscriptUtils for transcript management
- Add TRANSCRIPT_UPDATED event and MESSAGE_STATUS constants
- Integrate transcript tracking in sendMessage, getTranscript, and incoming messages
- Add auto-fetch transcript on connection when transcriptUpdateEnabled
- Add onTranscriptUpdated callback to chatSession
- Add TypeScript definitions for transcript events
- Add comprehensive test coverage


Internal commit: e871068
- Add workflowCanceled content type constant
- Enables handling of workflow cancellation events from Connect


Internal commit: a73ec52
- Move transcript update to track stitched messages correctly
- Add MessageCompleted and ChunkNumber to MessageMetadata TypeScript types
- Fixes transcript tracking for partial/streaming messages from Lex


Internal commit: 86ca9f6
Commit 5 (f2c5177): Agent getConnectionToken and createParticipantConnection metrics
- Add AGENT_CREATE_PARTICIPANT_ERROR_RATE metric constant
- Add AGENT_GET_CONNECTION_TOKEN_ERROR_RATE metric constant
- Track agent session errors in connectionDetailsProvider
- Add _isAgentSession() helper method

Commit 6 (80b9daa): TypeScript type for MessageProcessingStatus
- Add MessageProcessingStatus interface (PROCESSING, FAILED, REJECTED)
- Add MessageProcessingStatus to MessageMetadata type definition


Internal commits: f2c5177, 80b9daa
Commit 7 (5b94790): Update default max results for onTranscriptUpdated
- Already applied in commit 2 (maxResults: 100)

Commit 8 (91e963f): Exclude 4xx errors from AGENT_CREATE_PARTICIPANT_ERROR_RATE
- Only track 5xx and network errors as failures
- 4xx errors are client errors, not service failures


Internal commits: 5b94790, 91e963f
@saipreetham16 saipreetham16 requested a review from a team as a code owner January 31, 2026 07:38
@saipreetham16 saipreetham16 requested review from haomingli2020, mliao95 and palna26 and removed request for a team January 31, 2026 07:38
}
})
.catch( error => {
if (this._isAgentSession() && !error?.statusCode?.toString().startsWith("4")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you check if this metric is suppose to only be for default CCP agents or it should include custom CCP as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The AGENT_CREATE_PARTICIPANT_ERROR_RATE metric is to monitor agent sessions (both default CCP and custom CCP). logic:

  • this._isAgentSession() - Filters for agent sessions (vs customer)
  • !error?.statusCode?.toString().startsWith("4") - Excludes 4xx client errors
  • Tracks server-side connectivity issues affecting agents

This is will monitoring agent connection health across all CCP implementations.

this.controller.subscribe(CHAT_EVENTS.CHAT_REHYDRATED, callback);
}

onTranscriptUpdated(callback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add this event to the readme

@haomingli2020
Copy link
Collaborator

Changes LGTM, the only thing I noticed in the video is that the chat window doesn't scroll automatically to the bottom when the partial messages continue to come from lex, is that the desired behavior ? (for both internal package and this repo).

@saipreetham16
Copy link
Contributor Author

Changes LGTM, the only thing I noticed in the video is that the chat window doesn't scroll automatically to the bottom when the partial messages continue to come from lex, is that the desired behavior ? (for both internal package and this repo).

This is expected for longer responses now, will create a backlog for this.

@saipreetham16 saipreetham16 merged commit 8cb8a21 into master Feb 6, 2026
6 checks passed
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.

3 participants