@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.
- package/CHANGELOG.md +11 -0
- package/build/ask-question/index.d.ts +32 -0
- package/build/ask-question/index.js +37 -0
- package/build/components/ai-control/index.d.ts +49 -0
- package/build/components/ai-control/index.js +53 -0
- package/build/components/ai-control/message.d.ts +30 -0
- package/build/components/ai-control/message.js +44 -0
- package/build/components/ai-status-indicator/index.d.ts +15 -0
- package/build/components/ai-status-indicator/index.js +22 -0
- package/build/components/audio-duration-display/index.d.ts +12 -0
- package/build/components/audio-duration-display/index.js +25 -0
- package/build/components/audio-duration-display/lib/media.d.ts +29 -0
- package/build/components/audio-duration-display/lib/media.js +52 -0
- package/build/components/index.d.ts +4 -0
- package/build/components/index.js +4 -0
- package/build/data-flow/context.d.ts +39 -0
- package/build/data-flow/context.js +22 -0
- package/build/data-flow/index.d.ts +3 -0
- package/build/data-flow/index.js +3 -0
- package/build/data-flow/use-ai-context.d.ts +24 -0
- package/build/data-flow/use-ai-context.js +46 -0
- package/build/data-flow/with-ai-assistant-data.d.ts +10 -0
- package/build/data-flow/with-ai-assistant-data.js +42 -0
- package/build/hooks/use-ai-suggestions/index.d.ts +48 -0
- package/build/hooks/use-ai-suggestions/index.js +214 -0
- package/build/hooks/use-media-recording/index.d.ts +42 -0
- package/build/hooks/use-media-recording/index.js +143 -0
- package/build/icons/ai-assistant.d.ts +2 -0
- package/build/icons/ai-assistant.js +7 -0
- package/build/icons/index.d.ts +7 -0
- package/build/icons/index.js +7 -0
- package/build/icons/mic.d.ts +2 -0
- package/build/icons/mic.js +7 -0
- package/build/icons/origami-plane.d.ts +2 -0
- package/build/icons/origami-plane.js +7 -0
- package/build/icons/player-pause.d.ts +2 -0
- package/build/icons/player-pause.js +7 -0
- package/build/icons/player-play.d.ts +2 -0
- package/build/icons/player-play.js +7 -0
- package/build/icons/player-stop.d.ts +2 -0
- package/build/icons/player-stop.js +7 -0
- package/build/icons/speak-tone.d.ts +2 -0
- package/build/icons/speak-tone.js +7 -0
- package/build/index.d.ts +9 -0
- package/build/index.js +27 -0
- package/build/jwt/index.d.ts +19 -0
- package/build/jwt/index.js +74 -0
- package/build/suggestions-event-source/index.d.ts +55 -0
- package/build/suggestions-event-source/index.js +282 -0
- package/build/types.d.ts +34 -0
- package/build/types.js +27 -0
- package/package.json +22 -15
- package/src/components/ai-control/index.tsx +21 -19
- package/src/components/ai-control/style.scss +3 -3
- package/src/data-flow/context.tsx +3 -3
- package/src/data-flow/with-ai-assistant-data.tsx +42 -39
- package/src/index.ts +32 -0
- package/src/types.ts +17 -0
- package/index.ts +0 -32
- 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
|
|
6
|
+
import React from 'react';
|
|
7
7
|
/**
|
|
8
8
|
* Internal Dependencies
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
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 {
|
|
18
|
-
* @returns {
|
|
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(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
requestSuggestion,
|
|
28
|
+
request: requestSuggestion,
|
|
41
29
|
stopSuggestion,
|
|
42
|
-
} ),
|
|
43
|
-
[
|
|
44
|
-
suggestion,
|
|
45
|
-
requestingError,
|
|
46
|
-
requestingState,
|
|
47
30
|
eventSource,
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
},
|
|
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';
|