wecool-chat 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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +112 -0
- package/dist/client.d.ts +42 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/components/ChatFooter.d.ts +9 -0
- package/dist/components/ChatFooter.d.ts.map +1 -0
- package/dist/components/ChatHeader.d.ts +7 -0
- package/dist/components/ChatHeader.d.ts.map +1 -0
- package/dist/components/ChatPanel.d.ts +14 -0
- package/dist/components/ChatPanel.d.ts.map +1 -0
- package/dist/components/ChatWidget.d.ts +3 -0
- package/dist/components/ChatWidget.d.ts.map +1 -0
- package/dist/components/FloatButton.d.ts +7 -0
- package/dist/components/FloatButton.d.ts.map +1 -0
- package/dist/components/MessageList.d.ts +8 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/hooks/tool-runner.d.ts +20 -0
- package/dist/hooks/tool-runner.d.ts.map +1 -0
- package/dist/hooks/useChatStream.d.ts +26 -0
- package/dist/hooks/useChatStream.d.ts.map +1 -0
- package/dist/index.css +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +728 -0
- package/dist/sse-parser.d.ts +7 -0
- package/dist/sse-parser.d.ts.map +1 -0
- package/dist/types.d.ts +131 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ChatEvent } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* サーバから送られる SSE ストリームを ChatEvent として yield する generator。
|
|
4
|
+
* 1行ずつバッファしつつ `data:` プレフィックスの JSON を取り出す。
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseChatSSE(stream: ReadableStream<Uint8Array> | null): AsyncGenerator<ChatEvent>;
|
|
7
|
+
//# sourceMappingURL=sse-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sse-parser.d.ts","sourceRoot":"","sources":["../src/sse-parser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;;GAGG;AACH,wBAAuB,YAAY,CACjC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,GACxC,cAAc,CAAC,SAAS,CAAC,CA4B3B"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Schema for tool parameters
|
|
3
|
+
*/
|
|
4
|
+
export interface ToolParameters {
|
|
5
|
+
type: "object";
|
|
6
|
+
properties: Record<string, {
|
|
7
|
+
type: "string" | "number" | "boolean" | "array" | "object";
|
|
8
|
+
description?: string;
|
|
9
|
+
enum?: string[];
|
|
10
|
+
items?: {
|
|
11
|
+
type: string;
|
|
12
|
+
};
|
|
13
|
+
}>;
|
|
14
|
+
required?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Tool definition that can be executed by the LLM
|
|
18
|
+
*/
|
|
19
|
+
export interface Tool {
|
|
20
|
+
/** Unique identifier for the tool */
|
|
21
|
+
name: string;
|
|
22
|
+
/** Human-readable description for the LLM to understand when to use this tool */
|
|
23
|
+
description: string;
|
|
24
|
+
/** JSON Schema defining the expected parameters */
|
|
25
|
+
parameters: ToolParameters;
|
|
26
|
+
/** Function to execute when the LLM calls this tool */
|
|
27
|
+
handler: (args: Record<string, unknown>) => unknown | Promise<unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Tool definition sent to the API (without handler)
|
|
31
|
+
*/
|
|
32
|
+
export interface ToolDefinition {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
parameters: ToolParameters;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Configuration for initializing the chat widget
|
|
39
|
+
*/
|
|
40
|
+
export interface ChatConfig {
|
|
41
|
+
/** API endpoint URL */
|
|
42
|
+
endpoint: string;
|
|
43
|
+
/** API key for authentication */
|
|
44
|
+
apiKey?: string;
|
|
45
|
+
/** List of tools available to the LLM */
|
|
46
|
+
tools: Tool[];
|
|
47
|
+
/** UI language */
|
|
48
|
+
locale?: "ja" | "en";
|
|
49
|
+
/** Callback when a tool is about to be executed */
|
|
50
|
+
onToolExecute?: (toolName: string, args: unknown) => void;
|
|
51
|
+
/** Callback when a tool execution completes */
|
|
52
|
+
onToolResult?: (toolName: string, result: unknown) => void;
|
|
53
|
+
/** Callback when an error occurs */
|
|
54
|
+
onError?: (error: Error) => void;
|
|
55
|
+
/** Timeout in milliseconds for tool handler execution (default: 30000) */
|
|
56
|
+
toolTimeout?: number;
|
|
57
|
+
/** Custom class name for the widget container */
|
|
58
|
+
className?: string;
|
|
59
|
+
/** Placeholder text for the input field */
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Chat message
|
|
64
|
+
*/
|
|
65
|
+
export interface Message {
|
|
66
|
+
id: string;
|
|
67
|
+
role: "user" | "assistant" | "system" | "tool";
|
|
68
|
+
content: string;
|
|
69
|
+
timestamp: number;
|
|
70
|
+
toolCall?: {
|
|
71
|
+
name: string;
|
|
72
|
+
arguments: Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
toolResult?: unknown;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Tool call from the API
|
|
78
|
+
*/
|
|
79
|
+
export interface ToolCall {
|
|
80
|
+
name: string;
|
|
81
|
+
arguments: Record<string, unknown>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* SSE event received from the server
|
|
85
|
+
*/
|
|
86
|
+
export type ChatEvent = {
|
|
87
|
+
type: "thinking";
|
|
88
|
+
status: string;
|
|
89
|
+
} | {
|
|
90
|
+
type: "tool_use";
|
|
91
|
+
toolCallId: string;
|
|
92
|
+
name: string;
|
|
93
|
+
input: Record<string, unknown>;
|
|
94
|
+
} | {
|
|
95
|
+
type: "text";
|
|
96
|
+
content: string;
|
|
97
|
+
} | {
|
|
98
|
+
type: "text_delta";
|
|
99
|
+
delta: string;
|
|
100
|
+
} | {
|
|
101
|
+
type: "error";
|
|
102
|
+
message: string;
|
|
103
|
+
} | {
|
|
104
|
+
type: "done";
|
|
105
|
+
conversationId: string;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Tool result sent back to the server
|
|
109
|
+
*/
|
|
110
|
+
export interface ToolResult {
|
|
111
|
+
toolCallId: string;
|
|
112
|
+
toolName: string;
|
|
113
|
+
toolInput: Record<string, unknown>;
|
|
114
|
+
result: unknown;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Props for ChatWidget component
|
|
118
|
+
*/
|
|
119
|
+
export interface ChatWidgetProps {
|
|
120
|
+
config: Omit<ChatConfig, "tools"> & {
|
|
121
|
+
tools?: Tool[];
|
|
122
|
+
};
|
|
123
|
+
tools?: Tool[];
|
|
124
|
+
/** Whether to show the widget in floating mode */
|
|
125
|
+
floating?: boolean;
|
|
126
|
+
/** Initial open state for floating mode */
|
|
127
|
+
defaultOpen?: boolean;
|
|
128
|
+
/** Position for floating mode */
|
|
129
|
+
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,MAAM,CAChB,MAAM,EACN;QACE,IAAI,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC;QAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,KAAK,CAAC,EAAE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ACnC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,GAAG;QAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAA;KAAE,CAAC;IACvD,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf,kDAAkD;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2CAA2C;IAC3C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAC;CACtE"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wecool-chat",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Drop-in LLM chat widget that executes your JavaScript functions via natural language",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./styles.css": "./dist/index.css"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"!dist/__tests__",
|
|
19
|
+
"README.md",
|
|
20
|
+
"CHANGELOG.md"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc && vite build",
|
|
27
|
+
"lint": "eslint src",
|
|
28
|
+
"test": "vitest run",
|
|
29
|
+
"test:watch": "vitest"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"react": ">=18.0.0",
|
|
33
|
+
"react-dom": ">=18.0.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"lucide-react": "^0.511.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@eslint/js": "^10.0.1",
|
|
40
|
+
"@tailwindcss/vite": "^4.1.18",
|
|
41
|
+
"@testing-library/react": "^16.3.2",
|
|
42
|
+
"@testing-library/user-event": "^14.6.1",
|
|
43
|
+
"@types/react": "^19.2.13",
|
|
44
|
+
"@types/react-dom": "^19.2.3",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^8.58.1",
|
|
46
|
+
"@typescript-eslint/parser": "^8.58.1",
|
|
47
|
+
"@vitejs/plugin-react": "^5.1.3",
|
|
48
|
+
"eslint": "^10.2.0",
|
|
49
|
+
"globals": "^17.4.0",
|
|
50
|
+
"jsdom": "^29.0.2",
|
|
51
|
+
"react": "^19.2.4",
|
|
52
|
+
"react-dom": "^19.2.4",
|
|
53
|
+
"tailwindcss": "^4.1.18",
|
|
54
|
+
"typescript": "^5.9.3",
|
|
55
|
+
"vite": "^7.3.1",
|
|
56
|
+
"vite-plugin-dts": "^4.5.4",
|
|
57
|
+
"vitest": "^4.1.4"
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"llm",
|
|
61
|
+
"chat",
|
|
62
|
+
"ai",
|
|
63
|
+
"tool-calling",
|
|
64
|
+
"function-calling",
|
|
65
|
+
"react"
|
|
66
|
+
],
|
|
67
|
+
"license": "MIT",
|
|
68
|
+
"homepage": "https://demo.wecool.dev",
|
|
69
|
+
"bugs": {
|
|
70
|
+
"email": "wecool.dev@gmail.com"
|
|
71
|
+
},
|
|
72
|
+
"author": "wecool-dev"
|
|
73
|
+
}
|