-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
449 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
--- | ||
"@assistant-ui/react-playground": patch | ||
"@assistant-ui/react": patch | ||
--- | ||
|
||
feat: Feedback Primtives, UI and Adapter |
This file contains 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 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 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 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 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 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 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 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
19 changes: 19 additions & 0 deletions
19
packages/react/src/primitive-hooks/actionBar/useActionBarFeedbackNegative.tsx
This file contains 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,19 @@ | ||
import { useCallback } from "react"; | ||
import { useThreadActions } from "../../context/react/ThreadContext"; | ||
import { useMessageStore, useMessageUtilsStore } from "../../context"; | ||
|
||
export const useActionBarFeedbackNegative = () => { | ||
const threadActions = useThreadActions(); | ||
const messageStore = useMessageStore(); | ||
const messageUtilsStore = useMessageUtilsStore(); | ||
|
||
const callback = useCallback(() => { | ||
threadActions.submitFeedback({ | ||
messageId: messageStore.getState().message.id, | ||
type: "negative", | ||
}); | ||
messageUtilsStore.getState().setSubmittedFeedback("negative"); | ||
}, [messageStore, messageUtilsStore, threadActions]); | ||
|
||
return callback; | ||
}; |
19 changes: 19 additions & 0 deletions
19
packages/react/src/primitive-hooks/actionBar/useActionBarFeedbackPositive.tsx
This file contains 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,19 @@ | ||
import { useCallback } from "react"; | ||
import { useThreadActions } from "../../context/react/ThreadContext"; | ||
import { useMessageStore, useMessageUtilsStore } from "../../context"; | ||
|
||
export const useActionBarFeedbackPositive = () => { | ||
const threadActions = useThreadActions(); | ||
const messageStore = useMessageStore(); | ||
const messageUtilsStore = useMessageUtilsStore(); | ||
|
||
const callback = useCallback(() => { | ||
threadActions.submitFeedback({ | ||
messageId: messageStore.getState().message.id, | ||
type: "positive", | ||
}); | ||
messageUtilsStore.getState().setSubmittedFeedback("positive"); | ||
}, [messageStore, messageUtilsStore, threadActions]); | ||
|
||
return callback; | ||
}; |
This file contains 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 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 |
---|---|---|
@@ -1,17 +1,34 @@ | ||
"use client"; | ||
|
||
import { forwardRef } from "react"; | ||
import { useActionBarCopy } from "../../primitive-hooks/actionBar/useActionBarCopy"; | ||
import { | ||
ActionButtonProps, | ||
createActionButton, | ||
} from "../../utils/createActionButton"; | ||
import { ActionButtonProps } from "../../utils/createActionButton"; | ||
import { composeEventHandlers } from "@radix-ui/primitive"; | ||
import { Primitive } from "@radix-ui/react-primitive"; | ||
import { useMessageUtils } from "../../context"; | ||
|
||
export type ActionBarPrimitiveCopyProps = ActionButtonProps< | ||
typeof useActionBarCopy | ||
>; | ||
|
||
export const ActionBarPrimitiveCopy = createActionButton( | ||
"ActionBarPrimitive.Copy", | ||
useActionBarCopy, | ||
["copiedDuration"], | ||
); | ||
export const ActionBarPrimitiveCopy = forwardRef< | ||
HTMLButtonElement, | ||
Partial<ActionBarPrimitiveCopyProps> | ||
>(({ copiedDuration, onClick, disabled, ...props }, forwardedRef) => { | ||
const isCopied = useMessageUtils((u) => u.isCopied); | ||
const callback = useActionBarCopy({ copiedDuration }); | ||
return ( | ||
<Primitive.button | ||
type="button" | ||
{...(isCopied ? { "data-copied": "true" } : {})} | ||
{...props} | ||
ref={forwardedRef} | ||
disabled={disabled || !callback} | ||
onClick={composeEventHandlers(onClick, () => { | ||
callback?.(); | ||
})} | ||
/> | ||
); | ||
}); | ||
|
||
ActionBarPrimitiveCopy.displayName = "ActionBarPrimitive.Copy"; |
Oops, something went wrong.