Skip to content

Commit

Permalink
feat(use-copilot-chat-suggestions): add available prop (CopilotKit#1278)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Slaton <tyler@copilotkit.ai>
  • Loading branch information
tylerslaton authored Jan 27, 2025
1 parent a569c1f commit c65878d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ interface UseCopilotChatSuggestionsConfiguration {
* @default 1
*/
maxSuggestions?: number;

/**
* Whether the suggestions are available. Defaults to `enabled`.
* @default enabled
*/
available?: "enabled" | "disabled";

/**
* An optional class name to apply to the suggestions.
*/
Expand All @@ -86,6 +93,7 @@ interface UseCopilotChatSuggestionsConfiguration {

export function useCopilotChatSuggestions(
{
available = "enabled",
instructions,
className,
minSuggestions = 1,
Expand All @@ -96,6 +104,8 @@ export function useCopilotChatSuggestions(
const context = useCopilotContext();

useEffect(() => {
if (available === "disabled") return;

const id = randomId();

context.addChatSuggestionConfiguration(id, {
Expand All @@ -108,5 +118,5 @@ export function useCopilotChatSuggestions(
return () => {
context.removeChatSuggestionConfiguration(id);
};
}, [...dependencies, instructions, minSuggestions, maxSuggestions, className]);
}, [...dependencies, instructions, minSuggestions, maxSuggestions, className, available]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ The minimum number of suggestions to generate. Defaults to `1`.
The maximum number of suggestions to generate. Defaults to `3`.
</PropertyReference>

<PropertyReference name="available" type="'enabled' | 'disabled'" default="enabled">
Whether the suggestions are available. Defaults to `enabled`.
</PropertyReference>

<PropertyReference name="className" type="string" >
An optional class name to apply to the suggestions.
</PropertyReference>
Expand Down

0 comments on commit c65878d

Please sign in to comment.