@automattic/jetpack-ai-client 0.1.1 → 0.1.3
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 +34 -0
- package/README.md +18 -96
- package/index.ts +5 -0
- package/package.json +12 -9
- package/src/ask-question/index.ts +0 -4
- package/src/components/ai-control/Readme.md +29 -0
- package/src/components/ai-control/index.tsx +101 -60
- package/src/components/ai-control/message.tsx +86 -0
- package/src/components/ai-control/stories/index.stories.tsx +27 -1
- package/src/components/ai-control/style.scss +58 -12
- package/src/components/ai-status-indicator/Readme.md +11 -0
- package/src/components/ai-status-indicator/index.tsx +43 -0
- package/src/components/ai-status-indicator/stories/index.mdx +25 -0
- package/src/components/ai-status-indicator/stories/index.stories.tsx +84 -0
- package/src/components/ai-status-indicator/style.scss +50 -0
- package/src/data-flow/Readme.md +2 -0
- package/src/data-flow/context.tsx +4 -2
- package/src/data-flow/use-ai-context.ts +18 -3
- package/src/hooks/use-ai-suggestions/Readme.md +1 -1
- package/src/hooks/use-ai-suggestions/index.ts +15 -11
- package/src/suggestions-event-source/index.ts +48 -2
- package/src/types.ts +29 -1
package/src/types.ts
CHANGED
|
@@ -3,13 +3,15 @@ export const ERROR_QUOTA_EXCEEDED = 'error_quota_exceeded' as const;
|
|
|
3
3
|
export const ERROR_MODERATION = 'error_moderation' as const;
|
|
4
4
|
export const ERROR_NETWORK = 'error_network' as const;
|
|
5
5
|
export const ERROR_UNCLEAR_PROMPT = 'error_unclear_prompt' as const;
|
|
6
|
+
export const ERROR_RESPONSE = 'error_response' as const;
|
|
6
7
|
|
|
7
8
|
export type SuggestionErrorCode =
|
|
8
9
|
| typeof ERROR_SERVICE_UNAVAILABLE
|
|
9
10
|
| typeof ERROR_QUOTA_EXCEEDED
|
|
10
11
|
| typeof ERROR_MODERATION
|
|
11
12
|
| typeof ERROR_NETWORK
|
|
12
|
-
| typeof ERROR_UNCLEAR_PROMPT
|
|
13
|
+
| typeof ERROR_UNCLEAR_PROMPT
|
|
14
|
+
| typeof ERROR_RESPONSE;
|
|
13
15
|
|
|
14
16
|
/*
|
|
15
17
|
* Prompt types
|
|
@@ -22,3 +24,29 @@ export type PromptItemProps = {
|
|
|
22
24
|
export type PromptMessagesProp = Array< PromptItemProps >;
|
|
23
25
|
|
|
24
26
|
export type PromptProp = PromptMessagesProp | string;
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Data Flow types
|
|
30
|
+
*/
|
|
31
|
+
export type { UseAiContextOptions } from './data-flow/use-ai-context';
|
|
32
|
+
export type { RequestingErrorProps } from './hooks/use-ai-suggestions';
|
|
33
|
+
|
|
34
|
+
/*
|
|
35
|
+
* Requests types
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
const REQUESTING_STATE_INIT = 'init' as const;
|
|
39
|
+
const REQUESTING_STATE_REQUESTING = 'requesting' as const;
|
|
40
|
+
const REQUESTING_STATE_SUGGESTING = 'suggesting' as const;
|
|
41
|
+
const REQUESTING_STATE_DONE = 'done' as const;
|
|
42
|
+
const REQUESTING_STATE_ERROR = 'error' as const;
|
|
43
|
+
|
|
44
|
+
export const REQUESTING_STATES = [
|
|
45
|
+
REQUESTING_STATE_INIT,
|
|
46
|
+
REQUESTING_STATE_REQUESTING,
|
|
47
|
+
REQUESTING_STATE_SUGGESTING,
|
|
48
|
+
REQUESTING_STATE_DONE,
|
|
49
|
+
REQUESTING_STATE_ERROR,
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
export type RequestingStateProp = ( typeof REQUESTING_STATES )[ number ];
|