-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Pull based capabilities from adapter #5679
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
base: main
Are you sure you want to change the base?
Pull based capabilities from adapter #5679
Conversation
| | Capability | Type | Description | | ||
| |------------|------|-------------| | ||
| | `voiceConfiguration` | `{ sampleRate: number, chunkIntervalMs: number }` | Audio settings for Speech-to-Speech | |
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.
Format and sort.
| @@ -0,0 +1,85 @@ | |||
| # Capabilities | |||
|
|
|||
| Web Chat supports dynamic capability discovery from adapters. Capabilities allow adapters to expose configuration values that WebChat components can consume and react to changes. | |||
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.
| Web Chat supports dynamic capability discovery from adapters. Capabilities allow adapters to expose configuration values that WebChat components can consume and react to changes. | |
| Web Chat supports dynamic capability discovery from adapters. Capabilities allow adapters to expose configuration values that Web Chat components can consume and react to changes. |
| const prevValue = prevCapabilities[key]; | ||
|
|
||
| if (fetchedValue) { | ||
| if (prevValue !== undefined && isEqual(prevValue, fetchedValue)) { |
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.
Because it just happened no one assigned window.undefined = 1.
| if (prevValue !== undefined && isEqual(prevValue, fetchedValue)) { | |
| if (typeof prevValue !== 'undefined' && isEqual(prevValue, fetchedValue)) { |
| @@ -0,0 +1,17 @@ | |||
| import { isForbiddenPropertyName } from 'botframework-webchat-core'; | |||
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.
Add a comment.
// TODO: [P2] Move this file to `base` packagee| { | ||
| key: 'voiceConfiguration', | ||
| getterName: 'getVoiceConfiguration' | ||
| } |
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.
Later. Add a Valibot schema.
| * - This ensures consumers using selectors only re-render when their capability changes | ||
| */ | ||
| const CapabilitiesComposer = memo(({ children }: Props) => { | ||
| const [activities] = useActivities(); |
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.
Very soon, we need to move to directLine.addEventListener('capabilitieschange') instead of waiting for "event activities with type capabilitiesChanged".
| ), | ||
| EMPTY_CAPABILITIES | ||
| ); | ||
|
|
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.
Sooner, update to use EventTarget than activity$.
const CapabilitiesComposer = ({ chatAdapter, children }) => {
function getAllCapabilities() { ... } // Call getVoiceConfiguration() and return as { voiceConfiguration: {} }.
const [value, setValue] = useState(() => getAllCapabilities(chatAdapter), [chatAdapter]);
useEffect(() => {
const handleCapabilitiesChange = () => {
setValue(getAllCapabilities(chatAdapter)); // Setter in useEffect is unevitable for EventTarget.
};
chatAdapter.addEventListener('capabilitieschange', handleCapabilitiesChange);
return () => chatAdapter.removeEventListener('capabilitieschange', handleCapabilitiesChange);
}, [chatAdapter]);
return <Context value={value}>{children}</Context>;
};
compulim
left a comment
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.
Coupling between this PR and the S2S PR:
showMicrophoneButtonchunkDurationInMs/sampleRate
Changelog Entry
Description
Introduces a Capabilities system that enables WebChat to dynamically discover and consume capabilities from chat adapters at runtime.
This allows adapters(directline, ccv2 etc..) to expose configuration such as voice settings without requiring WebChat to have compile-time knowledge of specific adapter implementations. The system follows a pull-based model where adapters expose getter functions and emit events when capabilities change.
Design
Pull-Based Architecture
getVoiceConfiguration()) to provide capability valuescapabilitiesChangedevents as a "nudge" to signal WebChat should re-fetch capabilitiesPure Derivation Pattern
useReduceMemoto derive capabilities from the activity streamcapabilitiesChangedevent is detected in activitiesReference Stability
Specific Changes
CapabilitiesComposercomponent that provides capabilities contextuseCapabilities(selector)hook for consuming capabilities with selector patternfetchCapabilitiesFromAdapterutility to pull capabilities from adapter getterscapabilityRegistryto map capability keys to adapter getter namesCapabilitiesandVoiceConfigurationtypescapabilitiesChangedeventsuseCapabilitieshook frombotframework-webchat/hooksetCapability(getterName, value, options)helper to test emulatoruseCapabilities.htmltest covering initial fetch, event-driven updates, and reference stabilityCAPABILITIES.mddocumentationCHANGELOG.mdReview Checklist
z-index)package.jsonandpackage-lock.jsonreviewed