Skip to content
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

Jetpack AI: Add fair usage message on Extension AI Control #39103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Jetpack AI: support fair usage messaging on the Extension AI Control component.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import React, { forwardRef } from 'react';
/**
* Internal dependencies
*/
import { GuidelineMessage, ErrorMessage, UpgradeMessage } from '../message/index.js';
import {
GuidelineMessage,
ErrorMessage,
UpgradeMessage,
FairUsageLimitMessage,
} from '../message/index.js';
import AIControl from './ai-control.js';
import './style.scss';
/**
Expand All @@ -31,6 +36,7 @@ type ExtensionAIControlProps = {
error?: RequestingErrorProps;
requestsRemaining?: number;
showUpgradeMessage?: boolean;
showFairUsageMessage?: boolean;
upgradeUrl?: string;
wrapperRef?: React.MutableRefObject< HTMLDivElement | null >;
onChange?: ( newValue: string ) => void;
Expand Down Expand Up @@ -62,6 +68,7 @@ export function ExtensionAIControl(
error,
requestsRemaining,
showUpgradeMessage = false,
showFairUsageMessage = false,
upgradeUrl,
wrapperRef,
onChange,
Expand Down Expand Up @@ -215,6 +222,8 @@ export function ExtensionAIControl(
upgradeUrl={ upgradeUrl }
/>
);
} else if ( showFairUsageMessage ) {
message = <FairUsageLimitMessage />;
} else if ( showUpgradeMessage ) {
message = (
<UpgradeMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const DefaultArgs = {
error: null,
requestsRemaining: null,
showUpgradeMessage: false,
showFairUsageMessage: false,
onChange: action( 'onChange' ),
onSend: action( 'onSend' ),
onStop: action( 'onStop' ),
Expand Down
20 changes: 20 additions & 0 deletions projects/js-packages/ai-client/src/components/message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import { ExternalLink, Button } from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { Icon, check, arrowRight } from '@wordpress/icons';
import clsx from 'clsx';
Expand Down Expand Up @@ -114,6 +115,25 @@ export function GuidelineMessage(): React.ReactElement {
);
}

/**
* React component to render a fair usage limit message.
*
* @return {React.ReactElement } - Message component.
*/
export function FairUsageLimitMessage(): React.ReactElement {
const message = __(
"You've reached this month's request limit, per our <link>fair usage policy</link>",
'jetpack-ai-client'
);
const element = createInterpolateElement( message, {
link: (
<ExternalLink href="https://jetpack.com/redirect/?source=ai-assistant-fair-usage-policy" />
),
} );

return <Message severity={ MESSAGE_SEVERITY_WARNING }>{ element }</Message>;
}

/**
* React component to render an upgrade message for free tier users
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Jetpack AI: support fair usage messaging on the Extension AI Control component.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export default function AiAssistantInput( {
[ requireUpgrade, requestingState ]
);

/**
* Show the fair usage message when the site is on the unlimited tier and was flagged as requireUpgrade.
*/
const showFairUsageMessage = useMemo( () => {
return requireUpgrade && currentTier?.value === 1;
}, [ requireUpgrade, currentTier ] );

const handleSend = useCallback( () => {
tracks.recordEvent( 'jetpack_ai_assistant_extension_generate', {
block_type: blockType,
Expand Down Expand Up @@ -165,6 +172,7 @@ export default function AiAssistantInput( {
error={ requestingError }
requestsRemaining={ requestsRemaining }
showUpgradeMessage={ showUpgradeMessage }
showFairUsageMessage={ showFairUsageMessage }
upgradeUrl={ checkoutUrl }
onChange={ setValue }
onSend={ handleSend }
Expand Down
Loading