Skip to content

Commit

Permalink
Merge branch 'trunk' into explore/wp-e2e-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
manzoorwanijk committed Dec 31, 2024
2 parents e46400d + b296ca1 commit 6b59388
Show file tree
Hide file tree
Showing 82 changed files with 2,332 additions and 1,009 deletions.
1,525 changes: 1,020 additions & 505 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion projects/js-packages/ai-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.25.4] - 2024-12-30
### Added
- AI Client: Add thumbs feedback on AI Assistant. [#40728]

### Changed
- AI Client: Move prompt types and update thumbs feedback event. [#40746]

## [0.25.3] - 2024-12-23
### Added
- Jetpack AI: Add thumbs up/down component to AI logo generator [#40610]
- Jetpack AI: Add thumbs up/down component to AI logo generator. [#40610]

## [0.25.2] - 2024-12-16
### Changed
Expand Down Expand Up @@ -487,6 +494,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- AI Client: stop using smart document visibility handling on the fetchEventSource library, so it does not restart the completion when changing tabs. [#32004]
- Updated package dependencies. [#31468] [#31659] [#31785]

[0.25.4]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.3...v0.25.4
[0.25.3]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.2...v0.25.3
[0.25.2]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.1...v0.25.2
[0.25.1]: https://github.com/Automattic/jetpack-ai-client/compare/v0.25.0...v0.25.1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Jetpack AI: Switch tracking data to camel_case to maintain Tracks' required property format

This file was deleted.

2 changes: 1 addition & 1 deletion projects/js-packages/ai-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": false,
"name": "@automattic/jetpack-ai-client",
"version": "0.25.3",
"version": "0.25.4",
"description": "A JS client for consuming Jetpack AI services",
"homepage": "https://github.com/Automattic/jetpack/tree/HEAD/projects/js-packages/ai-client/#readme",
"bugs": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type BlockAIControlProps = {
showRemove?: boolean;
banner?: ReactElement;
error?: ReactElement;
lastAction?: string;
};

const debug = debugFactory( 'jetpack-ai-client:block-ai-control' );
Expand Down Expand Up @@ -77,6 +78,7 @@ export function BlockAIControl(
showRemove = false,
banner = null,
error = null,
lastAction,
}: BlockAIControlProps,
ref: React.MutableRefObject< HTMLInputElement >
): ReactElement {
Expand Down Expand Up @@ -261,9 +263,12 @@ export function BlockAIControl(
! editRequest &&
( customFooter || (
<GuidelineMessage
showAIFeedbackThumbs={ true }
ratedItem={ 'ai-assistant' }
prompt={ value }
aiFeedbackThumbsOptions={ {
showAIFeedbackThumbs: true,
ratedItem: 'ai-assistant',
prompt: lastAction,
block: 'ai-assistant',
} }
/>
) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type ExtensionAIControlProps = {
onUndo?: () => void;
onUpgrade?: ( event: MouseEvent< HTMLButtonElement > ) => void;
onTryAgain?: () => void;
lastAction?: string;
blockType: string;
};

/**
Expand Down Expand Up @@ -78,6 +80,8 @@ export function ExtensionAIControl(
onUndo,
onUpgrade,
onTryAgain,
lastAction,
blockType,
}: ExtensionAIControlProps,
ref: React.MutableRefObject< HTMLInputElement >
): ReactElement {
Expand All @@ -86,8 +90,6 @@ export function ExtensionAIControl(
const [ lastValue, setLastValue ] = useState( value || null );
const promptUserInputRef = useRef( null );
const isDone = value?.length <= 0 && state === 'done';
const [ initialPlaceholder ] = useState( placeholder );
const [ prompt, setPrompt ] = useState( null );

// Pass the ref to forwardRef.
useImperativeHandle( ref, () => promptUserInputRef.current );
Expand All @@ -98,16 +100,8 @@ export function ExtensionAIControl(
}
}, [ editRequest ] );

useEffect( () => {
if ( placeholder !== initialPlaceholder ) {
// The prompt is used to determine if there was a toolbar action
setPrompt( placeholder );
}
}, [ placeholder ] );

const sendHandler = useCallback( () => {
setLastValue( value );
setPrompt( value );
setEditRequest( false );
onSend?.( value );
}, [ onSend, value ] );
Expand Down Expand Up @@ -246,9 +240,12 @@ export function ExtensionAIControl(
} else if ( showGuideLine ) {
message = isDone ? (
<GuidelineMessage
showAIFeedbackThumbs={ true }
ratedItem={ 'ai-assistant' }
prompt={ prompt }
aiFeedbackThumbsOptions={ {
showAIFeedbackThumbs: true,
ratedItem: 'ai-assistant',
prompt: lastAction,
block: blockType,
} }
/>
) : (
<GuidelineMessage />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type AiFeedbackThumbsProps = {
mediaLibraryId?: number;
prompt?: string;
revisedPrompt?: string;
block?: string | null;
};
onRate?: ( rating: string ) => void;
};
Expand Down Expand Up @@ -95,9 +96,10 @@ export default function AiFeedbackThumbs( {
tracks.recordEvent( 'jetpack_ai_feedback', {
type: feature,
rating: aiRating,
mediaLibraryId: options.mediaLibraryId || null,
media_library_id: options.mediaLibraryId || null,
prompt: options.prompt || null,
revisedPrompt: options.revisedPrompt || null,
revised_prompt: options.revisedPrompt || null,
block: options.block || null,
} );
}
};
Expand Down
43 changes: 27 additions & 16 deletions projects/js-packages/ai-client/src/components/message/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ export type MessageSeverityProp =
| typeof MESSAGE_SEVERITY_INFO
| null;

type RateProps = {
type AiFeedbackThumbsOptions = {
showAIFeedbackThumbs?: boolean;
ratedItem?: string;
prompt?: string;
block?: string | null;
onRate?: ( rating: string ) => void;
};

export type MessageProps = {
icon?: React.ReactNode;
severity?: MessageSeverityProp;
showAIFeedbackThumbs?: boolean;
aiFeedbackThumbsOptions?: AiFeedbackThumbsOptions;
children: React.ReactNode;
} & RateProps;
};

export type GuidelineMessageProps = {
showAIFeedbackThumbs?: boolean;
} & RateProps;
aiFeedbackThumbsOptions?: AiFeedbackThumbsOptions;
};

export type OnUpgradeClick = ( event?: React.MouseEvent< HTMLButtonElement > ) => void;

Expand Down Expand Up @@ -81,10 +83,13 @@ const messageIconsMap = {
export default function Message( {
severity = MESSAGE_SEVERITY_INFO,
icon = null,
showAIFeedbackThumbs = false,
ratedItem = '',
prompt = '',
onRate = () => {},
aiFeedbackThumbsOptions = {
showAIFeedbackThumbs: false,
ratedItem: '',
prompt: '',
block: null,
onRate: () => {},
},
children,
}: MessageProps ): React.ReactElement {
return (
Expand All @@ -98,15 +103,16 @@ export default function Message( {
<Icon icon={ messageIconsMap[ severity ] || icon } />
) }
{ <div className="jetpack-ai-assistant__message-content">{ children }</div> }
{ showAIFeedbackThumbs && (
{ aiFeedbackThumbsOptions.showAIFeedbackThumbs && aiFeedbackThumbsOptions.prompt && (
<AiFeedbackThumbs
disabled={ false }
ratedItem={ ratedItem }
ratedItem={ aiFeedbackThumbsOptions.ratedItem }
feature="ai-assistant"
options={ {
prompt,
prompt: aiFeedbackThumbsOptions.prompt,
block: aiFeedbackThumbsOptions.block,
} }
onRate={ onRate }
onRate={ aiFeedbackThumbsOptions.onRate }
/>
) }
</div>
Expand All @@ -133,11 +139,16 @@ function LearnMoreLink(): React.ReactElement {
* @return {React.ReactElement} - Message component.
*/
export function GuidelineMessage( {
showAIFeedbackThumbs = false,
...props
aiFeedbackThumbsOptions = {
showAIFeedbackThumbs: false,
ratedItem: '',
prompt: '',
block: null,
onRate: () => {},
},
}: GuidelineMessageProps ): React.ReactElement {
return (
<Message showAIFeedbackThumbs={ showAIFeedbackThumbs } { ...props }>
<Message aiFeedbackThumbsOptions={ aiFeedbackThumbsOptions }>
<span>
{ __( 'AI-generated content could be inaccurate or biased.', 'jetpack-ai-client' ) }
</span>
Expand Down
116 changes: 116 additions & 0 deletions projects/js-packages/ai-client/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

// Mappings
export const LANGUAGE_MAP = {
en: {
label: __( 'English', 'jetpack-ai-client' ),
},
es: {
label: __( 'Spanish', 'jetpack-ai-client' ),
},
fr: {
label: __( 'French', 'jetpack-ai-client' ),
},
de: {
label: __( 'German', 'jetpack-ai-client' ),
},
it: {
label: __( 'Italian', 'jetpack-ai-client' ),
},
pt: {
label: __( 'Portuguese', 'jetpack-ai-client' ),
},
ru: {
label: __( 'Russian', 'jetpack-ai-client' ),
},
zh: {
label: __( 'Chinese', 'jetpack-ai-client' ),
},
ja: {
label: __( 'Japanese', 'jetpack-ai-client' ),
},
ar: {
label: __( 'Arabic', 'jetpack-ai-client' ),
},
hi: {
label: __( 'Hindi', 'jetpack-ai-client' ),
},
ko: {
label: __( 'Korean', 'jetpack-ai-client' ),
},
};
export const PROMPT_TONES_MAP = {
formal: {
label: __( 'Formal', 'jetpack-ai-client' ),
emoji: '🎩',
},
informal: {
label: __( 'Informal', 'jetpack-ai-client' ),
emoji: '😊',
},
optimistic: {
label: __( 'Optimistic', 'jetpack-ai-client' ),
emoji: '😃',
},
humorous: {
label: __( 'Humorous', 'jetpack-ai-client' ),
emoji: '😂',
},
serious: {
label: __( 'Serious', 'jetpack-ai-client' ),
emoji: '😐',
},
skeptical: {
label: __( 'Skeptical', 'jetpack-ai-client' ),
emoji: '🤨',
},
empathetic: {
label: __( 'Empathetic', 'jetpack-ai-client' ),
emoji: '💗',
},
confident: {
label: __( 'Confident', 'jetpack-ai-client' ),
emoji: '😎',
},
passionate: {
label: __( 'Passionate', 'jetpack-ai-client' ),
emoji: '❤️',
},
provocative: {
label: __( 'Provocative', 'jetpack-ai-client' ),
emoji: '🔥',
},
};

// Prompt types
export const PROMPT_TYPE_SUMMARY_BY_TITLE = 'titleSummary' as const;
export const PROMPT_TYPE_CONTINUE = 'continue' as const;
export const PROMPT_TYPE_SIMPLIFY = 'simplify' as const;
export const PROMPT_TYPE_CORRECT_SPELLING = 'correctSpelling' as const;
export const PROMPT_TYPE_GENERATE_TITLE = 'generateTitle' as const;
export const PROMPT_TYPE_MAKE_LONGER = 'makeLonger' as const;
export const PROMPT_TYPE_MAKE_SHORTER = 'makeShorter' as const;
export const PROMPT_TYPE_CHANGE_TONE = 'changeTone' as const;
export const PROMPT_TYPE_SUMMARIZE = 'summarize' as const;
export const PROMPT_TYPE_CHANGE_LANGUAGE = 'changeLanguage' as const;
export const PROMPT_TYPE_USER_PROMPT = 'userPrompt' as const;
export const PROMPT_TYPE_JETPACK_FORM_CUSTOM_PROMPT = 'jetpackFormCustomPrompt' as const;
export const PROMPT_TYPE_TRANSFORM_LIST_TO_TABLE = 'transformListToTable' as const;
export const PROMPT_TYPE_WRITE_POST_FROM_LIST = 'writePostFromList' as const;

// Human-readable labels
export const TRANSLATE_LABEL = __( 'Translate', 'jetpack-ai-client' );
export const TONE_LABEL = __( 'Change tone', 'jetpack-ai-client' );
export const CORRECT_SPELLING_LABEL = __( 'Correct spelling and grammar', 'jetpack-ai-client' );
export const SIMPLIFY_LABEL = __( 'Simplify', 'jetpack-ai-client' );
export const SUMMARIZE_LABEL = __( 'Summarize', 'jetpack-ai-client' );
export const MAKE_SHORTER_LABEL = __( 'Make shorter', 'jetpack-ai-client' );
export const MAKE_LONGER_LABEL = __( 'Expand', 'jetpack-ai-client' );
export const TURN_LIST_INTO_TABLE_LABEL = __( 'Turn list into a table', 'jetpack-ai-client' );
export const WRITE_POST_FROM_LIST_LABEL = __( 'Write a post from this list', 'jetpack-ai-client' );
export const GENERATE_TITLE_LABEL = __( 'Generate a post title', 'jetpack-ai-client' );
export const SUMMARY_BASED_ON_TITLE_LABEL = __( 'Summary based on title', 'jetpack-ai-client' );
export const CONTINUE_LABEL = __( 'Continue writing', 'jetpack-ai-client' );
5 changes: 5 additions & 0 deletions projects/js-packages/ai-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ export * from './types.js';
*/
export * from './libs/index.js';

/*
* Constants
*/
export * from './constants.js';

/*
* Logo Generator
*/
Expand Down
2 changes: 2 additions & 0 deletions projects/js-packages/ai-client/src/libs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export {
} from './markdown/index.js';

export type { RenderHTMLRules } from './markdown/index.js';

export { mapActionToHumanText } from './map-action-to-human-text.js';
Loading

0 comments on commit 6b59388

Please sign in to comment.