open-ask-ai 0.1.0
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/README.md +236 -0
- package/dist/index.cjs.js +609 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.esm.js +584 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.umd.js +30676 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/types/components/chat/ChatContainer.d.ts +16 -0
- package/dist/types/components/ui/Button.d.ts +10 -0
- package/dist/types/components/widget/Drawer.d.ts +13 -0
- package/dist/types/components/widget/Trigger.d.ts +8 -0
- package/dist/types/components/widget/Widget.d.ts +2 -0
- package/dist/types/core/api/client.d.ts +21 -0
- package/dist/types/core/hooks/index.d.ts +3 -0
- package/dist/types/core/hooks/useChat.d.ts +17 -0
- package/dist/types/core/hooks/useSSE.d.ts +12 -0
- package/dist/types/core/hooks/useSession.d.ts +13 -0
- package/dist/types/core/types/index.d.ts +69 -0
- package/dist/types/index.d.ts +6 -0
- package/package.json +67 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { WidgetTexts, Message } from '@/core/types';
|
|
3
|
+
interface ChatContainerProps {
|
|
4
|
+
texts?: WidgetTexts;
|
|
5
|
+
exampleQuestions?: string[];
|
|
6
|
+
onMessage?: (message: any) => void;
|
|
7
|
+
onError?: (error: Error) => void;
|
|
8
|
+
messages: Message[];
|
|
9
|
+
isStreaming: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
sendMessage: (text: string) => Promise<void>;
|
|
12
|
+
input: string;
|
|
13
|
+
setInput: React.Dispatch<React.SetStateAction<string>>;
|
|
14
|
+
}
|
|
15
|
+
export declare function ChatContainer({ texts, exampleQuestions, onMessage, onError, messages, isStreaming, error, sendMessage, input, setInput, }: ChatContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
type ButtonVariant = 'default' | 'outline' | 'ghost' | 'icon';
|
|
3
|
+
type ButtonSize = 'default' | 'sm' | 'lg' | 'icon';
|
|
4
|
+
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
5
|
+
asChild?: boolean;
|
|
6
|
+
variant?: ButtonVariant;
|
|
7
|
+
size?: ButtonSize;
|
|
8
|
+
}
|
|
9
|
+
declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
|
|
10
|
+
export { Button };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface DrawerProps {
|
|
3
|
+
isOpen: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
position?: 'right' | 'left';
|
|
6
|
+
width?: number | string;
|
|
7
|
+
title?: string;
|
|
8
|
+
closeAriaLabel?: string;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
theme?: 'light' | 'dark';
|
|
11
|
+
}
|
|
12
|
+
export declare function Drawer({ isOpen, onClose, position, width, title, closeAriaLabel, children, theme, }: DrawerProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SessionResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* API client for Ask AI widget
|
|
4
|
+
* Supports dynamic API URL configuration
|
|
5
|
+
*/
|
|
6
|
+
export declare class APIClient {
|
|
7
|
+
private baseUrl;
|
|
8
|
+
constructor(baseUrl: string);
|
|
9
|
+
/**
|
|
10
|
+
* Create a new session
|
|
11
|
+
*/
|
|
12
|
+
createSession(): Promise<SessionResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Delete a session
|
|
15
|
+
*/
|
|
16
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Ask a question and return the SSE stream response
|
|
19
|
+
*/
|
|
20
|
+
askQuestion(sessionId: string, question: string, system?: string): Promise<Response>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Message } from '../types';
|
|
2
|
+
import type { APIClient } from '../api/client';
|
|
3
|
+
interface UseChatOptions {
|
|
4
|
+
apiClient: APIClient;
|
|
5
|
+
systemPrompt?: string;
|
|
6
|
+
}
|
|
7
|
+
interface UseChatReturn {
|
|
8
|
+
messages: Message[];
|
|
9
|
+
isStreaming: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
sessionError: Error | null;
|
|
12
|
+
isCreatingSession: boolean;
|
|
13
|
+
sendMessage: (text: string) => Promise<void>;
|
|
14
|
+
clearMessages: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function useChat({ apiClient, systemPrompt }: UseChatOptions): UseChatReturn;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SSEData } from '../types';
|
|
2
|
+
interface UseSSEOptions {
|
|
3
|
+
onConnected?: () => void;
|
|
4
|
+
onMessage?: (data: SSEData) => void;
|
|
5
|
+
onDone?: () => void;
|
|
6
|
+
onError?: (error: Error) => void;
|
|
7
|
+
}
|
|
8
|
+
interface UseSSEReturn {
|
|
9
|
+
handleSSEStream: (response: Response) => Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function useSSE(options?: UseSSEOptions): UseSSEReturn;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { APIClient } from '../api/client';
|
|
2
|
+
interface UseSessionOptions {
|
|
3
|
+
apiClient: APIClient;
|
|
4
|
+
}
|
|
5
|
+
interface UseSessionReturn {
|
|
6
|
+
sessionId: string | null;
|
|
7
|
+
isCreating: boolean;
|
|
8
|
+
error: Error | null;
|
|
9
|
+
initializeSession: () => Promise<string>;
|
|
10
|
+
recreateSession: () => Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function useSession({ apiClient }: UseSessionOptions): UseSessionReturn;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export interface Message {
|
|
2
|
+
id: string;
|
|
3
|
+
role: 'user' | 'assistant';
|
|
4
|
+
content: string;
|
|
5
|
+
timestamp: number;
|
|
6
|
+
isStreaming?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ChatState {
|
|
9
|
+
messages: Message[];
|
|
10
|
+
isStreaming: boolean;
|
|
11
|
+
error: Error | null;
|
|
12
|
+
}
|
|
13
|
+
export interface SessionResponse {
|
|
14
|
+
sessionId: string;
|
|
15
|
+
expiresIn: number;
|
|
16
|
+
}
|
|
17
|
+
export interface SSEEvent {
|
|
18
|
+
event: string;
|
|
19
|
+
data: any;
|
|
20
|
+
}
|
|
21
|
+
export interface SSEConnectedData {
|
|
22
|
+
type: 'connected';
|
|
23
|
+
}
|
|
24
|
+
export interface SSEAnswerData {
|
|
25
|
+
type: 'answer';
|
|
26
|
+
text: string;
|
|
27
|
+
sessionId: string;
|
|
28
|
+
}
|
|
29
|
+
export interface SSEDoneData {
|
|
30
|
+
type: 'done';
|
|
31
|
+
}
|
|
32
|
+
export interface SSEErrorData {
|
|
33
|
+
type: 'error';
|
|
34
|
+
error: string;
|
|
35
|
+
}
|
|
36
|
+
export type SSEData = SSEConnectedData | SSEAnswerData | SSEDoneData | SSEErrorData;
|
|
37
|
+
export interface WidgetTexts {
|
|
38
|
+
triggerButtonText?: string;
|
|
39
|
+
triggerButtonAriaLabel?: string;
|
|
40
|
+
drawerTitle?: string;
|
|
41
|
+
drawerCloseAriaLabel?: string;
|
|
42
|
+
welcomeMessage?: string;
|
|
43
|
+
exampleQuestionsTitle?: string;
|
|
44
|
+
inputPlaceholder?: string;
|
|
45
|
+
sendButtonAriaLabel?: string;
|
|
46
|
+
loadingText?: string;
|
|
47
|
+
errorText?: string;
|
|
48
|
+
retryButtonText?: string;
|
|
49
|
+
}
|
|
50
|
+
export interface WidgetProps {
|
|
51
|
+
apiUrl: string;
|
|
52
|
+
drawerPosition?: 'right' | 'left';
|
|
53
|
+
drawerWidth?: number | string;
|
|
54
|
+
theme?: 'light' | 'dark';
|
|
55
|
+
texts?: WidgetTexts;
|
|
56
|
+
exampleQuestions?: string[];
|
|
57
|
+
systemPrompt?: string;
|
|
58
|
+
hotkey?: string;
|
|
59
|
+
enableHotkey?: boolean;
|
|
60
|
+
onOpen?: () => void;
|
|
61
|
+
onClose?: () => void;
|
|
62
|
+
onMessage?: (message: Message) => void;
|
|
63
|
+
onError?: (error: Error) => void;
|
|
64
|
+
className?: string;
|
|
65
|
+
style?: React.CSSProperties;
|
|
66
|
+
children?: React.ReactElement<{
|
|
67
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
68
|
+
}>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Widget as AskAIWidget } from './components/widget/Widget';
|
|
2
|
+
export type { Message, WidgetProps, WidgetTexts, } from './core/types';
|
|
3
|
+
export { APIClient } from './core/api/client';
|
|
4
|
+
export { useChat, useSession, useSSE, } from './core/hooks';
|
|
5
|
+
import './styles/variables.css';
|
|
6
|
+
import './styles/globals.css';
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "open-ask-ai",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "AI-powered Q&A widget for documentation sites",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs.js",
|
|
7
|
+
"module": "./dist/index.esm.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.esm.js",
|
|
12
|
+
"require": "./dist/index.cjs.js",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "npm run build:types && npm run build:rollup",
|
|
21
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
22
|
+
"build:rollup": "rollup -c rollup.config.js",
|
|
23
|
+
"typecheck": "tsc --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
27
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@radix-ui/react-dialog": "^1.1.3",
|
|
31
|
+
"@radix-ui/react-scroll-area": "^1.2.2",
|
|
32
|
+
"@radix-ui/react-slot": "^1.1.1",
|
|
33
|
+
"lucide-react": "^0.563.0",
|
|
34
|
+
"react-markdown": "^10.1.0",
|
|
35
|
+
"remark-gfm": "^4.0.1"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@rollup/plugin-commonjs": "^28.0.2",
|
|
39
|
+
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
40
|
+
"@rollup/plugin-typescript": "^12.1.2",
|
|
41
|
+
"@types/node": "^22.10.5",
|
|
42
|
+
"@types/react": "^19.0.10",
|
|
43
|
+
"@types/react-dom": "^19.0.3",
|
|
44
|
+
"autoprefixer": "^10.4.20",
|
|
45
|
+
"postcss": "^8.5.1",
|
|
46
|
+
"postcss-prefix-selector": "^1.16.1",
|
|
47
|
+
"react": "^19.0.0",
|
|
48
|
+
"react-dom": "^19.0.0",
|
|
49
|
+
"rollup": "^4.30.1",
|
|
50
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
51
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
52
|
+
"typescript": "^5.9.3"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"ai",
|
|
56
|
+
"chatbot",
|
|
57
|
+
"documentation",
|
|
58
|
+
"widget",
|
|
59
|
+
"react"
|
|
60
|
+
],
|
|
61
|
+
"author": "",
|
|
62
|
+
"license": "MIT",
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": ""
|
|
66
|
+
}
|
|
67
|
+
}
|