Repository navigation
[DERCBOT-2176] Support delta streaming (streamMode) #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
assouktim
wants to merge
5
commits into
master
Choose a base branch
from
feature/stream-delta-and-sse-count
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
55b0ff6
[DERCBOT-2176] Support delta streaming (streamMode)
assouktim 53177a5
Handle stream contract in reducer: discard action, keep validation, a…
assouktim 6a3cd17
Count all SSE frames except partial, requestId filter, replace only d…
assouktim 77701a8
Document the streaming contract
assouktim be10b9b
Apply requestId correlation to idle tabs and after request completion
assouktim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { BotConnectorResponse } from './model/responses'; | ||
|
|
||
| type Metadata = Record<string, string> | undefined; | ||
|
|
||
| /** | ||
| * Streaming contract of the Tock web connector (metadata of a response envelope): | ||
| * - `TOCK_STREAM_RESPONSE=true`: the message replaces the one with the same `RESPONSE_ID`; | ||
| * - `TOCK_STREAM_PARTIAL=true`: transient frame of an answer being generated (never counted, never recorded); | ||
| * - `TOCK_STREAM_REPLACE=<actionId>`: the final message that replaces the streamed bubble, the others are added; | ||
| * - `TOCK_STREAM_DISCARD=true`: the streamed bubble must be removed; | ||
| * - `TOCK_REQUEST_ID`: identifier sent by the client with the question, echoed on every frame. | ||
| */ | ||
| export const isPartialFrame = (metadata: Metadata): boolean => | ||
| metadata?.TOCK_STREAM_PARTIAL === 'true'; | ||
|
|
||
| export const isDiscardFrame = (metadata: Metadata): boolean => | ||
| metadata?.TOCK_STREAM_DISCARD === 'true'; | ||
|
|
||
| /** True for the frames of the contract that designates (or removes) the streamed bubble. */ | ||
| export const usesStreamContract = (metadata: Metadata): boolean => | ||
| isPartialFrame(metadata) || | ||
| isDiscardFrame(metadata) || | ||
| metadata?.TOCK_STREAM_REPLACE !== undefined; | ||
|
|
||
| /** Metadata of a message that must not behave as the streamed bubble (stream flags removed). */ | ||
| export const withoutStreamFlags = ( | ||
| metadata: Record<string, string> | undefined, | ||
| ): Record<string, string> | undefined => { | ||
| if (!metadata) return metadata; | ||
| const { | ||
| TOCK_STREAM_RESPONSE: _response, | ||
| TOCK_STREAM_PARTIAL: _partial, | ||
| TOCK_STREAM_REPLACE: _replace, | ||
| TOCK_STREAM_DISCARD: _discard, | ||
| TOCK_STREAM_MODE: _mode, | ||
| TOCK_STREAM_KEEP: _keep, | ||
| ...rest | ||
| } = metadata; | ||
| return rest; | ||
| }; | ||
|
|
||
| /** Parses TOCK_STREAM_KEEP: a non-negative integer, otherwise undefined. */ | ||
| export const parseKeep = (value: string | undefined): number | undefined => | ||
| value !== undefined && /^\d+$/.test(value) ? Number(value) : undefined; | ||
|
|
||
| /** | ||
| * A frame is correlated to a request (`TOCK_REQUEST_ID`) that this client is not | ||
| * handling, so it must be ignored. The rule is stable for the whole lifetime of a | ||
| * stream: a correlated frame is accepted only while its request is in flight here. | ||
| * | ||
| * It is deliberately NOT gated on `inFlightRequestIds.size > 0`: otherwise an idle | ||
| * tab (no request in flight) would accept a foreign tab's partial frames, then start | ||
| * rejecting the rest the moment it sends its own question — leaving an orphan | ||
| * provisional bubble that is never finalized nor recorded. For the same reason, a late | ||
| * frame arriving after the local request completed (success or error — the id is then | ||
| * removed from the in-flight set) is treated as foreign and dropped, so it cannot | ||
| * revive a closed/errored request. | ||
| * | ||
| * Frames without a request identifier (e.g. notifications) always pass. | ||
| */ | ||
| export const isFrameOfOtherRequest = ( | ||
| botResponse: BotConnectorResponse, | ||
| inFlightRequestIds: ReadonlySet<string>, | ||
| ): boolean => { | ||
| const requestId = botResponse.metadata?.TOCK_REQUEST_ID; | ||
| return !!requestId && !inFlightRequestIds.has(requestId); | ||
| }; | ||
|
|
||
| export const newRequestId = (): string => | ||
| typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function' | ||
| ? crypto.randomUUID() | ||
| : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new field is redundant,
TockOptionsalready contains thenetworksettings through inheritance. Most properties in this specific interface are legacy support.