@automattic/jetpack-ai-client 0.1.16 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/build/ask-question/index.d.ts +32 -0
  3. package/build/ask-question/index.js +37 -0
  4. package/build/components/ai-control/index.d.ts +49 -0
  5. package/build/components/ai-control/index.js +53 -0
  6. package/build/components/ai-control/message.d.ts +30 -0
  7. package/build/components/ai-control/message.js +44 -0
  8. package/build/components/ai-status-indicator/index.d.ts +15 -0
  9. package/build/components/ai-status-indicator/index.js +22 -0
  10. package/build/components/audio-duration-display/index.d.ts +12 -0
  11. package/build/components/audio-duration-display/index.js +25 -0
  12. package/build/components/audio-duration-display/lib/media.d.ts +29 -0
  13. package/build/components/audio-duration-display/lib/media.js +52 -0
  14. package/build/components/index.d.ts +4 -0
  15. package/build/components/index.js +4 -0
  16. package/build/data-flow/context.d.ts +39 -0
  17. package/build/data-flow/context.js +22 -0
  18. package/build/data-flow/index.d.ts +3 -0
  19. package/build/data-flow/index.js +3 -0
  20. package/build/data-flow/use-ai-context.d.ts +24 -0
  21. package/build/data-flow/use-ai-context.js +46 -0
  22. package/build/data-flow/with-ai-assistant-data.d.ts +10 -0
  23. package/build/data-flow/with-ai-assistant-data.js +42 -0
  24. package/build/hooks/use-ai-suggestions/index.d.ts +48 -0
  25. package/build/hooks/use-ai-suggestions/index.js +214 -0
  26. package/build/hooks/use-media-recording/index.d.ts +42 -0
  27. package/build/hooks/use-media-recording/index.js +143 -0
  28. package/build/icons/ai-assistant.d.ts +2 -0
  29. package/build/icons/ai-assistant.js +7 -0
  30. package/build/icons/index.d.ts +7 -0
  31. package/build/icons/index.js +7 -0
  32. package/build/icons/mic.d.ts +2 -0
  33. package/build/icons/mic.js +7 -0
  34. package/build/icons/origami-plane.d.ts +2 -0
  35. package/build/icons/origami-plane.js +7 -0
  36. package/build/icons/player-pause.d.ts +2 -0
  37. package/build/icons/player-pause.js +7 -0
  38. package/build/icons/player-play.d.ts +2 -0
  39. package/build/icons/player-play.js +7 -0
  40. package/build/icons/player-stop.d.ts +2 -0
  41. package/build/icons/player-stop.js +7 -0
  42. package/build/icons/speak-tone.d.ts +2 -0
  43. package/build/icons/speak-tone.js +7 -0
  44. package/build/index.d.ts +9 -0
  45. package/build/index.js +27 -0
  46. package/build/jwt/index.d.ts +19 -0
  47. package/build/jwt/index.js +74 -0
  48. package/build/suggestions-event-source/index.d.ts +55 -0
  49. package/build/suggestions-event-source/index.js +282 -0
  50. package/build/types.d.ts +34 -0
  51. package/build/types.js +27 -0
  52. package/package.json +22 -15
  53. package/src/components/ai-control/index.tsx +21 -19
  54. package/src/components/ai-control/style.scss +3 -3
  55. package/src/data-flow/context.tsx +3 -3
  56. package/src/data-flow/with-ai-assistant-data.tsx +42 -39
  57. package/src/index.ts +32 -0
  58. package/src/types.ts +17 -0
  59. package/index.ts +0 -32
  60. package/src/global.d.ts +0 -9
@@ -3,59 +3,62 @@
3
3
  */
4
4
  import { createHigherOrderComponent } from '@wordpress/compose';
5
5
  import { useMemo } from '@wordpress/element';
6
- import React, { ReactNode } from 'react';
6
+ import React from 'react';
7
7
  /**
8
8
  * Internal Dependencies
9
9
  */
10
- import { useAiSuggestions } from '../../';
10
+ import useAiSuggestions from '../hooks/use-ai-suggestions';
11
11
  import { AiDataContextProvider } from '.';
12
12
 
13
13
  /**
14
14
  * High Order Component that provides the
15
15
  * AI Assistant Data context to the wrapped component.
16
16
  *
17
- * @param {ReactNode} WrappedComponent - component to wrap.
18
- * @returns {ReactNode} Wrapped component, with the AI Assistant Data context.
17
+ * @param {React.ReactElement} WrappedComponent - component to wrap.
18
+ * @returns {React.ReactElement} Wrapped component, with the AI Assistant Data context.
19
19
  */
20
- const withAiDataProvider = createHigherOrderComponent( ( WrappedComponent: ReactNode ) => {
21
- return props => {
22
- // Connect with the AI Assistant communication layer.
23
- const {
24
- suggestion,
25
- error: requestingError,
26
- requestingState,
27
- request: requestSuggestion,
28
- stopSuggestion,
29
- eventSource,
30
- } = useAiSuggestions();
31
-
32
- // Build the context value to pass to the ai assistant data provider.
33
- const dataContextValue = useMemo(
34
- () => ( {
20
+ const withAiDataProvider = createHigherOrderComponent(
21
+ ( WrappedComponent: React.ComponentType ) => {
22
+ return props => {
23
+ // Connect with the AI Assistant communication layer.
24
+ const {
35
25
  suggestion,
36
- requestingError,
26
+ error: requestingError,
37
27
  requestingState,
38
- eventSource,
39
-
40
- requestSuggestion,
28
+ request: requestSuggestion,
41
29
  stopSuggestion,
42
- } ),
43
- [
44
- suggestion,
45
- requestingError,
46
- requestingState,
47
30
  eventSource,
48
- requestSuggestion,
49
- stopSuggestion,
50
- ]
51
- );
31
+ } = useAiSuggestions();
32
+
33
+ // Build the context value to pass to the ai assistant data provider.
34
+ const dataContextValue = useMemo(
35
+ () => ( {
36
+ suggestion,
37
+ requestingError,
38
+ requestingState,
39
+ eventSource,
40
+
41
+ requestSuggestion,
42
+ stopSuggestion,
43
+ } ),
44
+ [
45
+ suggestion,
46
+ requestingError,
47
+ requestingState,
48
+ eventSource,
49
+ requestSuggestion,
50
+ stopSuggestion,
51
+ ]
52
+ );
52
53
 
53
- return (
54
- <AiDataContextProvider value={ dataContextValue }>
55
- <WrappedComponent { ...props } />
56
- </AiDataContextProvider>
57
- );
58
- };
59
- }, 'withAiDataProvider' );
54
+ return (
55
+ <AiDataContextProvider value={ dataContextValue }>
56
+ <WrappedComponent { ...props } />
57
+ </AiDataContextProvider>
58
+ );
59
+ };
60
+ },
61
+ 'withAiDataProvider'
62
+ );
60
63
 
61
64
  export default withAiDataProvider;
package/src/index.ts ADDED
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Core library exports
3
+ */
4
+ export { default as requestJwt } from './jwt';
5
+ export { default as SuggestionsEventSource } from './suggestions-event-source';
6
+ export { default as askQuestion } from './ask-question';
7
+
8
+ /*
9
+ * Hooks
10
+ */
11
+ export { default as useAiSuggestions } from './hooks/use-ai-suggestions';
12
+ export { default as useMediaRecording } from './hooks/use-media-recording';
13
+
14
+ /*
15
+ * Components: Icons
16
+ */
17
+ export * from './icons';
18
+
19
+ /*
20
+ * Components
21
+ */
22
+ export * from './components';
23
+
24
+ /*
25
+ * Contexts
26
+ */
27
+ export * from './data-flow';
28
+
29
+ /*
30
+ * Types
31
+ */
32
+ export * from './types';
package/src/types.ts CHANGED
@@ -60,3 +60,20 @@ export const AI_MODEL_GPT_3_5_Turbo_16K = 'gpt-3.5-turbo-16k' as const;
60
60
  export const AI_MODEL_GPT_4 = 'gpt-4' as const;
61
61
 
62
62
  export type AiModelTypeProp = typeof AI_MODEL_GPT_3_5_Turbo_16K | typeof AI_MODEL_GPT_4;
63
+
64
+ // Connection initial state
65
+ // @todo: it should be provided by the connection package
66
+ interface JPConnectionInitialState {
67
+ apiNonce: string;
68
+ siteSuffix: string;
69
+ connectionStatus: {
70
+ isActive: boolean;
71
+ };
72
+ }
73
+
74
+ // Global
75
+ declare global {
76
+ interface Window {
77
+ JP_CONNECTION_INITIAL_STATE: JPConnectionInitialState;
78
+ }
79
+ }
package/index.ts DELETED
@@ -1,32 +0,0 @@
1
- /*
2
- * Core library exports
3
- */
4
- export { default as requestJwt } from './src/jwt';
5
- export { default as SuggestionsEventSource } from './src/suggestions-event-source';
6
- export { default as askQuestion } from './src/ask-question';
7
-
8
- /*
9
- * Hooks
10
- */
11
- export { default as useAiSuggestions } from './src/hooks/use-ai-suggestions';
12
- export { default as useMediaRecording } from './src/hooks/use-media-recording';
13
-
14
- /*
15
- * Components: Icons
16
- */
17
- export * from './src/icons';
18
-
19
- /*
20
- * Components
21
- */
22
- export * from './src/components';
23
-
24
- /*
25
- * Contexts
26
- */
27
- export * from './src/data-flow';
28
-
29
- /*
30
- * Types
31
- */
32
- export * from './src/types';
package/src/global.d.ts DELETED
@@ -1,9 +0,0 @@
1
- export declare global {
2
- interface Window {
3
- JP_CONNECTION_INITIAL_STATE: {
4
- apiNonce: string;
5
- siteSuffix: string;
6
- siteId: string;
7
- };
8
- }
9
- }