@peam-ai/client 0.1.3 → 0.1.5

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/dist/index.d.mts CHANGED
@@ -1,87 +1,148 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
- import * as ai from 'ai';
4
- import { HttpChatTransport, UIMessage as UIMessage$1 } from 'ai';
5
- import { UIMessage } from '@ai-sdk/react';
2
+ import { HttpChatTransport, UIMessage, FileUIPart, ChatStatus, DefaultChatTransport } from 'ai';
3
+ import * as React from 'react';
4
+ import { ReactNode, ComponentPropsWithoutRef } from 'react';
5
+ import { UIMessage as UIMessage$1 } from '@ai-sdk/react';
6
6
 
7
- interface AskAIChatProps extends AskAIBaseProps {
8
- }
9
- declare function AskAIChat({ suggestedPrompts, button, maxMessages }?: AskAIChatProps): react_jsx_runtime.JSX.Element;
10
-
11
- interface AskAIDialogProps extends AskAIBaseProps {
12
- }
13
- declare function AskAIDialog({ suggestedPrompts, button, maxMessages }?: AskAIDialogProps): react_jsx_runtime.JSX.Element;
14
-
15
- interface AskAISidepaneProps extends AskAIBaseProps {
16
- }
17
- declare function AskAISidepane({ suggestedPrompts, button, maxMessages }?: AskAISidepaneProps): react_jsx_runtime.JSX.Element;
7
+ type ChatPersistenceConfig = boolean | {
8
+ key?: string;
9
+ };
18
10
 
19
- type AskAIType = 'chat' | 'dialog' | 'sidepane';
20
- interface AskAIBaseProps {
11
+ interface AskAIRootProps {
12
+ children?: ReactNode;
13
+ /**
14
+ * API endpoint for handling AI requests.
15
+ * @default '/api/peam'
16
+ */
17
+ endpoint?: string;
18
+ /**
19
+ * Controlled open state.
20
+ */
21
+ open?: boolean;
21
22
  /**
22
- * Array of suggested prompts to display to the user.
23
+ * Uncontrolled initial open state.
23
24
  */
24
- suggestedPrompts?: string[];
25
+ defaultOpen?: boolean;
25
26
  /**
26
- * Maximum number of messages to keep in context before summarizing.
27
- * @default 10
27
+ * Override the default chat transport.
28
28
  */
29
- maxMessages?: number;
29
+ chatTransport?: HttpChatTransport<UIMessage>;
30
30
  /**
31
- * Custom button component.
32
- *
33
- * @example
34
- * ```tsx
35
- * <AskAI
36
- * type="dialog"
37
- * button={({ isOpen, toggle, open, close }) => (
38
- * <button onClick={toggle}>
39
- * {isOpen ? 'Close' : 'Open'} AI
40
- * </button>
41
- * )}
42
- * />
43
- * ```
31
+ * Configure chat persistence.
32
+ * @default true
44
33
  */
45
- button?: (props: {
46
- isOpen: boolean;
47
- toggle: () => void;
48
- open: () => void;
49
- close: () => void;
50
- }) => ReactNode;
34
+ persistence?: ChatPersistenceConfig;
35
+ }
36
+
37
+ type AskAIProviderProps = AskAIRootProps;
38
+ declare function AskAIProvider(props: AskAIRootProps): react_jsx_runtime.JSX.Element;
39
+
40
+ type PeamButtonVariant = 'icon' | 'iconLabel';
41
+
42
+ interface AskAITriggerProps extends ComponentPropsWithoutRef<'button'> {
43
+ asChild?: boolean;
44
+ children?: ReactNode;
45
+ inlineButton?: boolean;
46
+ variant?: PeamButtonVariant;
47
+ }
48
+
49
+ type AskAIProps = AskAIRootProps & {
50
+ children?: ReactNode;
51
+ /**
52
+ * When true, reuses an existing {@link AskAIContext} if present.
53
+ * @default true
54
+ */
55
+ reuseContext?: boolean;
56
+ } & ComponentPropsWithoutRef<'div'>;
57
+ declare function AskAI$1({ children, className, reuseContext, endpoint, open, defaultOpen, chatTransport, persistence, ...divProps }: AskAIProps): react_jsx_runtime.JSX.Element;
58
+
59
+ interface AskAIChatProps extends ComponentPropsWithoutRef<'div'> {
60
+ children?: ReactNode;
51
61
  }
52
- type AskAIProps = ({
53
- type?: 'chat';
54
- } & AskAIChatProps) | ({
55
- type: 'dialog';
56
- } & AskAIDialogProps) | ({
57
- type: 'sidepane';
58
- } & AskAISidepaneProps);
59
- declare function AskAI({ type, ...props }: AskAIProps): react_jsx_runtime.JSX.Element;
60
-
61
- declare const useChatPersistence: () => {
62
- initialMessages: {
63
- timestamp: number;
64
- sequence: number;
65
- id: string;
66
- role: "system" | "user" | "assistant";
67
- metadata?: unknown;
68
- parts: ai.UIMessagePart<ai.UIDataTypes, ai.UITools>[];
69
- }[];
62
+ declare function AskAIChat({ children, className, ...props }: AskAIChatProps): react_jsx_runtime.JSX.Element | null;
63
+
64
+ interface AskAIDialogProps extends ComponentPropsWithoutRef<'div'> {
65
+ children?: ReactNode;
66
+ }
67
+ declare function AskAIDialog({ children, className, ...props }: AskAIDialogProps): react_jsx_runtime.JSX.Element | null;
68
+
69
+ interface AskAIHeaderProps extends ComponentPropsWithoutRef<'div'> {
70
+ heading?: ReactNode;
71
+ closeLabel?: string;
72
+ }
73
+ declare function AskAIHeader({ heading, closeLabel, ...props }: AskAIHeaderProps): react_jsx_runtime.JSX.Element;
74
+
75
+ type AskAIInlineProps = ComponentPropsWithoutRef<'div'>;
76
+ declare function AskAIInline({ className, ...props }: AskAIInlineProps): react_jsx_runtime.JSX.Element;
77
+
78
+ type AskAIInputProps = ComponentPropsWithoutRef<'div'>;
79
+ declare function AskAIInput({ className, ...props }: AskAIInputProps): react_jsx_runtime.JSX.Element;
80
+
81
+ type AskAIMessagesProps = ComponentPropsWithoutRef<'div'>;
82
+ declare function AskAIMessages({ className, ...props }: AskAIMessagesProps): react_jsx_runtime.JSX.Element;
83
+
84
+ interface AskAISidepaneProps extends ComponentPropsWithoutRef<'div'> {
85
+ children?: ReactNode;
86
+ }
87
+ declare function AskAISidepane({ children, className, ...props }: AskAISidepaneProps): react_jsx_runtime.JSX.Element | null;
88
+
89
+ interface AskAISuggestionsProps extends ComponentPropsWithoutRef<'div'> {
90
+ prompts?: string[];
91
+ onPromptClick?: (prompt: string) => void;
92
+ onlyWhenEmpty?: boolean;
93
+ }
94
+ declare function AskAISuggestions({ prompts, onPromptClick, onlyWhenEmpty, className, ...props }: AskAISuggestionsProps): react_jsx_runtime.JSX.Element | null;
95
+
96
+ declare const AskAI: typeof AskAI$1 & {
97
+ Trigger: React.ForwardRefExoticComponent<AskAITriggerProps & React.RefAttributes<HTMLButtonElement>>;
98
+ Header: typeof AskAIHeader;
99
+ Dialog: typeof AskAIDialog;
100
+ Chat: typeof AskAIChat;
101
+ Sidepane: typeof AskAISidepane;
102
+ Inline: typeof AskAIInline;
103
+ Messages: typeof AskAIMessages;
104
+ Suggestions: typeof AskAISuggestions;
105
+ Input: typeof AskAIInput;
106
+ };
107
+
108
+ interface PromptInputMessage {
109
+ text: string;
110
+ files: FileUIPart[];
111
+ }
112
+
113
+ interface AskAIContextValue {
114
+ open: boolean;
115
+ setOpen: (open: boolean) => void;
116
+ toggleOpen: () => void;
117
+ input: string;
118
+ setInput: (value: string, options?: AskAIActionOptions) => void;
119
+ messages: UIMessage[];
120
+ status: ChatStatus;
121
+ error: Error | undefined;
70
122
  isLoading: boolean;
71
- saveMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => void;
72
- clearMessages: () => Promise<void>;
73
- summary: string | undefined;
74
- lastSummarizedMessageId: string | undefined;
75
- saveSummary: (summaryText: string, lastMessageId: string) => Promise<void>;
123
+ sendMessage: (message: {
124
+ text: string;
125
+ }, options?: AskAIActionOptions) => void;
126
+ handleSubmit: (message: PromptInputMessage) => void;
127
+ regenerate: (options?: {
128
+ messageId?: string;
129
+ }) => void;
130
+ clearMessages: () => void | Promise<void>;
131
+ }
132
+ type AskAIActionOptions = {
133
+ open?: boolean;
76
134
  };
77
135
 
78
- interface ChatProps {
79
- chatPersistence: ReturnType<typeof useChatPersistence>;
80
- suggestedPrompts?: string[];
81
- onClearRef?: (clearFn: () => void) => void;
82
- chatTransport?: HttpChatTransport<UIMessage$1>;
83
- maxMessages?: number;
136
+ declare function useAskAI(): AskAIContextValue;
137
+
138
+ interface BoundedChatTransportOptions {
139
+ endpoint: string;
140
+ }
141
+ /**
142
+ * Custom chat transport that implements bounded context.
143
+ */
144
+ declare class BoundedChatTransport extends DefaultChatTransport<UIMessage$1> {
145
+ constructor({ endpoint }: BoundedChatTransportOptions);
84
146
  }
85
- declare const Chat: ({ chatPersistence, suggestedPrompts, onClearRef, chatTransport, maxMessages }: ChatProps) => react_jsx_runtime.JSX.Element;
86
147
 
87
- export { AskAI, type AskAIBaseProps, AskAIChat, type AskAIChatProps, AskAIDialog, type AskAIDialogProps, type AskAIProps, AskAISidepane, type AskAISidepaneProps, type AskAIType, Chat, type ChatProps };
148
+ export { AskAI, type AskAIChatProps, type AskAIDialogProps, type AskAIHeaderProps, type AskAIInlineProps, type AskAIInputProps, type AskAIMessagesProps, type AskAIProps, AskAIProvider, type AskAIProviderProps, type AskAISidepaneProps, type AskAISuggestionsProps, BoundedChatTransport, useAskAI };
package/dist/index.d.ts CHANGED
@@ -1,87 +1,148 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode } from 'react';
3
- import * as ai from 'ai';
4
- import { HttpChatTransport, UIMessage as UIMessage$1 } from 'ai';
5
- import { UIMessage } from '@ai-sdk/react';
2
+ import { HttpChatTransport, UIMessage, FileUIPart, ChatStatus, DefaultChatTransport } from 'ai';
3
+ import * as React from 'react';
4
+ import { ReactNode, ComponentPropsWithoutRef } from 'react';
5
+ import { UIMessage as UIMessage$1 } from '@ai-sdk/react';
6
6
 
7
- interface AskAIChatProps extends AskAIBaseProps {
8
- }
9
- declare function AskAIChat({ suggestedPrompts, button, maxMessages }?: AskAIChatProps): react_jsx_runtime.JSX.Element;
10
-
11
- interface AskAIDialogProps extends AskAIBaseProps {
12
- }
13
- declare function AskAIDialog({ suggestedPrompts, button, maxMessages }?: AskAIDialogProps): react_jsx_runtime.JSX.Element;
14
-
15
- interface AskAISidepaneProps extends AskAIBaseProps {
16
- }
17
- declare function AskAISidepane({ suggestedPrompts, button, maxMessages }?: AskAISidepaneProps): react_jsx_runtime.JSX.Element;
7
+ type ChatPersistenceConfig = boolean | {
8
+ key?: string;
9
+ };
18
10
 
19
- type AskAIType = 'chat' | 'dialog' | 'sidepane';
20
- interface AskAIBaseProps {
11
+ interface AskAIRootProps {
12
+ children?: ReactNode;
13
+ /**
14
+ * API endpoint for handling AI requests.
15
+ * @default '/api/peam'
16
+ */
17
+ endpoint?: string;
18
+ /**
19
+ * Controlled open state.
20
+ */
21
+ open?: boolean;
21
22
  /**
22
- * Array of suggested prompts to display to the user.
23
+ * Uncontrolled initial open state.
23
24
  */
24
- suggestedPrompts?: string[];
25
+ defaultOpen?: boolean;
25
26
  /**
26
- * Maximum number of messages to keep in context before summarizing.
27
- * @default 10
27
+ * Override the default chat transport.
28
28
  */
29
- maxMessages?: number;
29
+ chatTransport?: HttpChatTransport<UIMessage>;
30
30
  /**
31
- * Custom button component.
32
- *
33
- * @example
34
- * ```tsx
35
- * <AskAI
36
- * type="dialog"
37
- * button={({ isOpen, toggle, open, close }) => (
38
- * <button onClick={toggle}>
39
- * {isOpen ? 'Close' : 'Open'} AI
40
- * </button>
41
- * )}
42
- * />
43
- * ```
31
+ * Configure chat persistence.
32
+ * @default true
44
33
  */
45
- button?: (props: {
46
- isOpen: boolean;
47
- toggle: () => void;
48
- open: () => void;
49
- close: () => void;
50
- }) => ReactNode;
34
+ persistence?: ChatPersistenceConfig;
35
+ }
36
+
37
+ type AskAIProviderProps = AskAIRootProps;
38
+ declare function AskAIProvider(props: AskAIRootProps): react_jsx_runtime.JSX.Element;
39
+
40
+ type PeamButtonVariant = 'icon' | 'iconLabel';
41
+
42
+ interface AskAITriggerProps extends ComponentPropsWithoutRef<'button'> {
43
+ asChild?: boolean;
44
+ children?: ReactNode;
45
+ inlineButton?: boolean;
46
+ variant?: PeamButtonVariant;
47
+ }
48
+
49
+ type AskAIProps = AskAIRootProps & {
50
+ children?: ReactNode;
51
+ /**
52
+ * When true, reuses an existing {@link AskAIContext} if present.
53
+ * @default true
54
+ */
55
+ reuseContext?: boolean;
56
+ } & ComponentPropsWithoutRef<'div'>;
57
+ declare function AskAI$1({ children, className, reuseContext, endpoint, open, defaultOpen, chatTransport, persistence, ...divProps }: AskAIProps): react_jsx_runtime.JSX.Element;
58
+
59
+ interface AskAIChatProps extends ComponentPropsWithoutRef<'div'> {
60
+ children?: ReactNode;
51
61
  }
52
- type AskAIProps = ({
53
- type?: 'chat';
54
- } & AskAIChatProps) | ({
55
- type: 'dialog';
56
- } & AskAIDialogProps) | ({
57
- type: 'sidepane';
58
- } & AskAISidepaneProps);
59
- declare function AskAI({ type, ...props }: AskAIProps): react_jsx_runtime.JSX.Element;
60
-
61
- declare const useChatPersistence: () => {
62
- initialMessages: {
63
- timestamp: number;
64
- sequence: number;
65
- id: string;
66
- role: "system" | "user" | "assistant";
67
- metadata?: unknown;
68
- parts: ai.UIMessagePart<ai.UIDataTypes, ai.UITools>[];
69
- }[];
62
+ declare function AskAIChat({ children, className, ...props }: AskAIChatProps): react_jsx_runtime.JSX.Element | null;
63
+
64
+ interface AskAIDialogProps extends ComponentPropsWithoutRef<'div'> {
65
+ children?: ReactNode;
66
+ }
67
+ declare function AskAIDialog({ children, className, ...props }: AskAIDialogProps): react_jsx_runtime.JSX.Element | null;
68
+
69
+ interface AskAIHeaderProps extends ComponentPropsWithoutRef<'div'> {
70
+ heading?: ReactNode;
71
+ closeLabel?: string;
72
+ }
73
+ declare function AskAIHeader({ heading, closeLabel, ...props }: AskAIHeaderProps): react_jsx_runtime.JSX.Element;
74
+
75
+ type AskAIInlineProps = ComponentPropsWithoutRef<'div'>;
76
+ declare function AskAIInline({ className, ...props }: AskAIInlineProps): react_jsx_runtime.JSX.Element;
77
+
78
+ type AskAIInputProps = ComponentPropsWithoutRef<'div'>;
79
+ declare function AskAIInput({ className, ...props }: AskAIInputProps): react_jsx_runtime.JSX.Element;
80
+
81
+ type AskAIMessagesProps = ComponentPropsWithoutRef<'div'>;
82
+ declare function AskAIMessages({ className, ...props }: AskAIMessagesProps): react_jsx_runtime.JSX.Element;
83
+
84
+ interface AskAISidepaneProps extends ComponentPropsWithoutRef<'div'> {
85
+ children?: ReactNode;
86
+ }
87
+ declare function AskAISidepane({ children, className, ...props }: AskAISidepaneProps): react_jsx_runtime.JSX.Element | null;
88
+
89
+ interface AskAISuggestionsProps extends ComponentPropsWithoutRef<'div'> {
90
+ prompts?: string[];
91
+ onPromptClick?: (prompt: string) => void;
92
+ onlyWhenEmpty?: boolean;
93
+ }
94
+ declare function AskAISuggestions({ prompts, onPromptClick, onlyWhenEmpty, className, ...props }: AskAISuggestionsProps): react_jsx_runtime.JSX.Element | null;
95
+
96
+ declare const AskAI: typeof AskAI$1 & {
97
+ Trigger: React.ForwardRefExoticComponent<AskAITriggerProps & React.RefAttributes<HTMLButtonElement>>;
98
+ Header: typeof AskAIHeader;
99
+ Dialog: typeof AskAIDialog;
100
+ Chat: typeof AskAIChat;
101
+ Sidepane: typeof AskAISidepane;
102
+ Inline: typeof AskAIInline;
103
+ Messages: typeof AskAIMessages;
104
+ Suggestions: typeof AskAISuggestions;
105
+ Input: typeof AskAIInput;
106
+ };
107
+
108
+ interface PromptInputMessage {
109
+ text: string;
110
+ files: FileUIPart[];
111
+ }
112
+
113
+ interface AskAIContextValue {
114
+ open: boolean;
115
+ setOpen: (open: boolean) => void;
116
+ toggleOpen: () => void;
117
+ input: string;
118
+ setInput: (value: string, options?: AskAIActionOptions) => void;
119
+ messages: UIMessage[];
120
+ status: ChatStatus;
121
+ error: Error | undefined;
70
122
  isLoading: boolean;
71
- saveMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => void;
72
- clearMessages: () => Promise<void>;
73
- summary: string | undefined;
74
- lastSummarizedMessageId: string | undefined;
75
- saveSummary: (summaryText: string, lastMessageId: string) => Promise<void>;
123
+ sendMessage: (message: {
124
+ text: string;
125
+ }, options?: AskAIActionOptions) => void;
126
+ handleSubmit: (message: PromptInputMessage) => void;
127
+ regenerate: (options?: {
128
+ messageId?: string;
129
+ }) => void;
130
+ clearMessages: () => void | Promise<void>;
131
+ }
132
+ type AskAIActionOptions = {
133
+ open?: boolean;
76
134
  };
77
135
 
78
- interface ChatProps {
79
- chatPersistence: ReturnType<typeof useChatPersistence>;
80
- suggestedPrompts?: string[];
81
- onClearRef?: (clearFn: () => void) => void;
82
- chatTransport?: HttpChatTransport<UIMessage$1>;
83
- maxMessages?: number;
136
+ declare function useAskAI(): AskAIContextValue;
137
+
138
+ interface BoundedChatTransportOptions {
139
+ endpoint: string;
140
+ }
141
+ /**
142
+ * Custom chat transport that implements bounded context.
143
+ */
144
+ declare class BoundedChatTransport extends DefaultChatTransport<UIMessage$1> {
145
+ constructor({ endpoint }: BoundedChatTransportOptions);
84
146
  }
85
- declare const Chat: ({ chatPersistence, suggestedPrompts, onClearRef, chatTransport, maxMessages }: ChatProps) => react_jsx_runtime.JSX.Element;
86
147
 
87
- export { AskAI, type AskAIBaseProps, AskAIChat, type AskAIChatProps, AskAIDialog, type AskAIDialogProps, type AskAIProps, AskAISidepane, type AskAISidepaneProps, type AskAIType, Chat, type ChatProps };
148
+ export { AskAI, type AskAIChatProps, type AskAIDialogProps, type AskAIHeaderProps, type AskAIInlineProps, type AskAIInputProps, type AskAIMessagesProps, type AskAIProps, AskAIProvider, type AskAIProviderProps, type AskAISidepaneProps, type AskAISuggestionsProps, BoundedChatTransport, useAskAI };