@peam-ai/client 0.1.4 → 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,101 +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, inlineButton }?: AskAIChatProps): react_jsx_runtime.JSX.Element;
10
-
11
- interface AskAIDialogProps extends AskAIBaseProps {
12
- }
13
- declare function AskAIDialog({ suggestedPrompts, button, maxMessages, inlineButton }?: AskAIDialogProps): react_jsx_runtime.JSX.Element;
14
-
15
- interface AskAISidepaneProps extends AskAIBaseProps {
16
- }
17
- declare function AskAISidepane({ suggestedPrompts, button, maxMessages, inlineButton, }?: 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
- * Render the button inline instead of as a floating button.
32
- * @default false
31
+ * Configure chat persistence.
32
+ * @default true
33
33
  */
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;
34
45
  inlineButton?: boolean;
46
+ variant?: PeamButtonVariant;
47
+ }
48
+
49
+ type AskAIProps = AskAIRootProps & {
50
+ children?: ReactNode;
35
51
  /**
36
- * Custom button component.
37
- *
38
- * @example
39
- * ```tsx
40
- * <AskAI
41
- * type="dialog"
42
- * button={({ isOpen, toggle, open, close }) => (
43
- * <button onClick={toggle}>
44
- * {isOpen ? 'Close' : 'Open'} AI
45
- * </button>
46
- * )}
47
- * />
48
- * ```
52
+ * When true, reuses an existing {@link AskAIContext} if present.
53
+ * @default true
49
54
  */
50
- button?: (props: {
51
- isOpen: boolean;
52
- toggle: () => void;
53
- open: () => void;
54
- close: () => void;
55
- }) => ReactNode;
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;
56
61
  }
57
- type AskAIProps = ({
58
- type?: 'chat';
59
- } & AskAIChatProps) | ({
60
- type: 'dialog';
61
- } & AskAIDialogProps) | ({
62
- type: 'sidepane';
63
- } & AskAISidepaneProps);
64
- declare function AskAI({ type, ...props }: AskAIProps): react_jsx_runtime.JSX.Element;
65
-
66
- declare const useChatPersistence: () => {
67
- initialMessages: {
68
- timestamp: number;
69
- sequence: number;
70
- id: string;
71
- role: "system" | "user" | "assistant";
72
- metadata?: unknown;
73
- parts: ai.UIMessagePart<ai.UIDataTypes, ai.UITools>[];
74
- }[];
75
- isLoading: boolean;
76
- saveMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => void;
77
- clearMessages: () => Promise<void>;
78
- summary: string | undefined;
79
- lastSummarizedMessageId: string | undefined;
80
- saveSummary: (summaryText: string, lastMessageId: string) => Promise<void>;
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;
81
106
  };
82
107
 
83
- interface ChatProps {
84
- chatPersistence: ReturnType<typeof useChatPersistence>;
85
- suggestedPrompts?: string[];
86
- onClearRef?: (clearFn: () => void) => void;
87
- chatTransport?: HttpChatTransport<UIMessage$1>;
88
- maxMessages?: number;
108
+ interface PromptInputMessage {
109
+ text: string;
110
+ files: FileUIPart[];
89
111
  }
90
- declare const Chat: ({ chatPersistence, suggestedPrompts, onClearRef, chatTransport, maxMessages }: ChatProps) => react_jsx_runtime.JSX.Element;
91
112
 
92
- interface PeamButtonProps {
93
- onClick: () => void;
94
- isOpen: boolean;
95
- inlineButton?: boolean;
96
- className?: string;
97
- showCloseIcon?: boolean;
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;
122
+ isLoading: boolean;
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;
134
+ };
135
+
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);
98
146
  }
99
- declare function PeamButton({ onClick, isOpen, inlineButton, className, showCloseIcon, }: PeamButtonProps): react_jsx_runtime.JSX.Element;
100
147
 
101
- export { AskAI, type AskAIBaseProps, AskAIChat, type AskAIChatProps, AskAIDialog, type AskAIDialogProps, type AskAIProps, AskAISidepane, type AskAISidepaneProps, type AskAIType, Chat, type ChatProps, PeamButton, type PeamButtonProps };
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,101 +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, inlineButton }?: AskAIChatProps): react_jsx_runtime.JSX.Element;
10
-
11
- interface AskAIDialogProps extends AskAIBaseProps {
12
- }
13
- declare function AskAIDialog({ suggestedPrompts, button, maxMessages, inlineButton }?: AskAIDialogProps): react_jsx_runtime.JSX.Element;
14
-
15
- interface AskAISidepaneProps extends AskAIBaseProps {
16
- }
17
- declare function AskAISidepane({ suggestedPrompts, button, maxMessages, inlineButton, }?: 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
- * Render the button inline instead of as a floating button.
32
- * @default false
31
+ * Configure chat persistence.
32
+ * @default true
33
33
  */
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;
34
45
  inlineButton?: boolean;
46
+ variant?: PeamButtonVariant;
47
+ }
48
+
49
+ type AskAIProps = AskAIRootProps & {
50
+ children?: ReactNode;
35
51
  /**
36
- * Custom button component.
37
- *
38
- * @example
39
- * ```tsx
40
- * <AskAI
41
- * type="dialog"
42
- * button={({ isOpen, toggle, open, close }) => (
43
- * <button onClick={toggle}>
44
- * {isOpen ? 'Close' : 'Open'} AI
45
- * </button>
46
- * )}
47
- * />
48
- * ```
52
+ * When true, reuses an existing {@link AskAIContext} if present.
53
+ * @default true
49
54
  */
50
- button?: (props: {
51
- isOpen: boolean;
52
- toggle: () => void;
53
- open: () => void;
54
- close: () => void;
55
- }) => ReactNode;
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;
56
61
  }
57
- type AskAIProps = ({
58
- type?: 'chat';
59
- } & AskAIChatProps) | ({
60
- type: 'dialog';
61
- } & AskAIDialogProps) | ({
62
- type: 'sidepane';
63
- } & AskAISidepaneProps);
64
- declare function AskAI({ type, ...props }: AskAIProps): react_jsx_runtime.JSX.Element;
65
-
66
- declare const useChatPersistence: () => {
67
- initialMessages: {
68
- timestamp: number;
69
- sequence: number;
70
- id: string;
71
- role: "system" | "user" | "assistant";
72
- metadata?: unknown;
73
- parts: ai.UIMessagePart<ai.UIDataTypes, ai.UITools>[];
74
- }[];
75
- isLoading: boolean;
76
- saveMessages: (messages: UIMessage<unknown, ai.UIDataTypes, ai.UITools>[]) => void;
77
- clearMessages: () => Promise<void>;
78
- summary: string | undefined;
79
- lastSummarizedMessageId: string | undefined;
80
- saveSummary: (summaryText: string, lastMessageId: string) => Promise<void>;
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;
81
106
  };
82
107
 
83
- interface ChatProps {
84
- chatPersistence: ReturnType<typeof useChatPersistence>;
85
- suggestedPrompts?: string[];
86
- onClearRef?: (clearFn: () => void) => void;
87
- chatTransport?: HttpChatTransport<UIMessage$1>;
88
- maxMessages?: number;
108
+ interface PromptInputMessage {
109
+ text: string;
110
+ files: FileUIPart[];
89
111
  }
90
- declare const Chat: ({ chatPersistence, suggestedPrompts, onClearRef, chatTransport, maxMessages }: ChatProps) => react_jsx_runtime.JSX.Element;
91
112
 
92
- interface PeamButtonProps {
93
- onClick: () => void;
94
- isOpen: boolean;
95
- inlineButton?: boolean;
96
- className?: string;
97
- showCloseIcon?: boolean;
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;
122
+ isLoading: boolean;
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;
134
+ };
135
+
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);
98
146
  }
99
- declare function PeamButton({ onClick, isOpen, inlineButton, className, showCloseIcon, }: PeamButtonProps): react_jsx_runtime.JSX.Element;
100
147
 
101
- export { AskAI, type AskAIBaseProps, AskAIChat, type AskAIChatProps, AskAIDialog, type AskAIDialogProps, type AskAIProps, AskAISidepane, type AskAISidepaneProps, type AskAIType, Chat, type ChatProps, PeamButton, type PeamButtonProps };
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 };