@sciol/xyzen 0.3.9 → 0.3.10

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 CHANGED
@@ -1,110 +1,187 @@
1
- # 如何使用 Xyzen
1
+ # Xyzen React Component
2
2
 
3
- Xyzen 是一个现代化、轻量级且可扩展的 React 聊天组件。它提供了一个功能齐全的侧边栏,可以轻松集成到任何 React 应用中。
3
+ Xyzen is a modern, lightweight, and extensible chat component for React. It provides a full-featured sidebar that can be easily integrated into any React application.
4
4
 
5
- ## 安装
5
+ ## Getting Started with Integration
6
6
 
7
- 使用 yarn npm 安装 Xyzen:
7
+ To use the Xyzen component in your own project, you need to deploy the backend service first, then integrate the frontend component.
8
8
 
9
- ```bash
10
- yarn add @sciol/xyzen@latest
11
- ```
9
+ ### Step 1: Deploy the Backend
12
10
 
13
- 或者
11
+ The Xyzen component requires a running backend service to handle chat logic and LLM connections.
14
12
 
15
- ```bash
16
- npm install @sciol/xyzen
17
- ```
13
+ 1. Clone the Xyzen repository:
14
+
15
+ ```bash
16
+ git clone https://github.com/ScienceOL/Xyzen.git
17
+ cd Xyzen
18
+ ```
19
+
20
+ 2. Deploy the backend using the one-click setup script:
21
+
22
+ **On Unix/Linux/macOS:**
23
+
24
+ ```bash
25
+ ./launch/dev.sh
26
+ ```
27
+
28
+ **On Windows (PowerShell):**
29
+
30
+ ```powershell
31
+ .\launch\dev.ps1
32
+ ```
33
+
34
+ This script will automatically set up all required services (PostgreSQL, Mosquitto, Casdoor) and start the backend.
35
+
36
+ 3. Configure LLM provider settings by creating a `.env.dev` file in the `docker` directory with the following keys:
37
+
38
+ ```env
39
+ XYZEN_LLM_PROVIDER=azure_openai
40
+ XYZEN_LLM_KEY=<Your-LLM-API-Key>
41
+ XYZEN_LLM_ENDPOINT=<Your-LLM-Endpoint>
42
+ XYZEN_LLM_VERSION=<Your-LLM-API-Version>
43
+ XYZEN_LLM_DEPLOYMENT=<Your-LLM-Deployment-Name>
44
+ ```
45
+
46
+ The backend will be available at `http://localhost:48196` by default, with API endpoints under `/xyzen/api`, `/xyzen/ws`, and `/xyzen/mcp`.
47
+
48
+ ### Step 2: Install and Integrate the Frontend Component
49
+
50
+ 1. Install the Xyzen component in your React project:
51
+
52
+ ```bash
53
+ yarn add @sciol/xyzen
54
+ ```
55
+
56
+ or
57
+
58
+ ```bash
59
+ npm install @sciol/xyzen
60
+ ```
61
+
62
+ 2. Add the `Xyzen` component to your application layout:
63
+
64
+ In your root layout file (e.g., `App.tsx` or `Layout.tsx`), import and render the `Xyzen` component with the `backendUrl` prop pointing to your deployed backend:
65
+
66
+ ```tsx
67
+ // src/App.tsx
68
+ import { Xyzen, useXyzen } from "@sciol/xyzen";
69
+ import "@sciol/xyzen/dist/style.css"; // Import the CSS
70
+
71
+ function App() {
72
+ const { openXyzen } = useXyzen();
73
+
74
+ return (
75
+ <div>
76
+ <header>
77
+ <h1>My Application</h1>
78
+ <button onClick={openXyzen}>Open Chat</button>
79
+ </header>
80
+ <main>{/* Your application content */}</main>
81
+ <Xyzen backendUrl="http://localhost:48196" />
82
+ </div>
83
+ );
84
+ }
85
+
86
+ export default App;
87
+ ```
88
+
89
+ **Note:** The `backendUrl` should point to the base URL of your Xyzen backend deployment. The component will automatically handle endpoints like `/xyzen/api`, `/xyzen/ws`, and `/xyzen/mcp`.
90
+
91
+ 3. Control the Xyzen panel from any component:
92
+
93
+ Use the `useXyzen` hook to control the sidebar's visibility:
94
+
95
+ ```tsx
96
+ import { useXyzen } from "@sciol/xyzen";
97
+
98
+ function MyComponent() {
99
+ const { isXyzenOpen, toggleXyzen, openXyzen, closeXyzen } = useXyzen();
100
+
101
+ return (
102
+ <div>
103
+ <p>The chat panel is currently {isXyzenOpen ? "open" : "closed"}.</p>
104
+ <button onClick={toggleXyzen}>Toggle Chat</button>
105
+ <button onClick={openXyzen}>Open Chat</button>
106
+ <button onClick={closeXyzen}>Close Chat</button>
107
+ </div>
108
+ );
109
+ }
110
+ ```
18
111
 
19
- ## 快速上手
112
+ ## Local Development
20
113
 
21
- `Xyzen` 组件开箱即用。它通过 `zustand` store 管理自己的状态。你可以通过 `useXyzen` hook 与其进行交互。
114
+ To contribute to or modify the Xyzen web client source code, follow these steps.
22
115
 
23
- 以下是如何将其集成到你的应用中的基本示例:
116
+ ### Prerequisites
24
117
 
25
- 1. **在你的应用布局中添加 `Xyzen` 组件**
118
+ - Node.js with Yarn (via Corepack)
119
+ - A running instance of the Xyzen backend service (see "Deploy the Backend" above)
26
120
 
27
- 在你的根布局文件(例如 `App.tsx` 或 `Layout.tsx`)中,导入并渲染 `Xyzen` 组件。
121
+ ### Setup
28
122
 
29
- ```tsx
30
- // src/App.tsx
31
- import { Xyzen, useXyzen } from "@sciol/xyzen";
123
+ 1. Navigate to the web directory:
32
124
 
33
- function App() {
34
- const { openXyzen } = useXyzen();
125
+ ```bash
126
+ cd web
127
+ ```
35
128
 
36
- return (
37
- <div>
38
- <header>
39
- <h1>我的应用</h1>
40
- <button onClick={openXyzen}>打开聊天</button>
41
- </header>
42
- <main>{/* 你的应用内容 */}</main>
43
- <Xyzen />
44
- </div>
45
- );
46
- }
129
+ 2. Enable Corepack to manage Yarn:
47
130
 
48
- export default App;
49
- ```
131
+ ```bash
132
+ corepack enable
133
+ ```
50
134
 
51
- 2. **控制 Xyzen 面板**
135
+ 3. Install dependencies using Yarn:
52
136
 
53
- 使用 `useXyzen` hook 来控制侧边栏的可见性。
137
+ ```bash
138
+ yarn install
139
+ ```
54
140
 
55
- ```tsx
56
- import { useXyzen } from "@sciol/xyzen";
141
+ 4. Run the development server:
57
142
 
58
- function MyComponent() {
59
- const { isXyzenOpen, toggleXyzen, openXyzen, closeXyzen } = useXyzen();
143
+ ```bash
144
+ yarn dev
145
+ ```
60
146
 
61
- return (
62
- <div>
63
- <p>聊天面板当前是 {isXyzenOpen ? "打开" : "关闭"} 状态。</p>
64
- <button onClick={toggleXyzen}>切换聊天</button>
65
- <button onClick={openXyzen}>打开聊天</button>
66
- <button onClick={closeXyzen}>关闭聊天</button>
67
- </div>
68
- );
69
- }
70
- ```
147
+ The frontend will be available at `http://localhost:32233` and will connect to the local backend service.
71
148
 
72
149
  ## `useXyzen` Store API
73
150
 
74
- `useXyzen` hook 提供了访问 Xyzen 状态和操作的接口。
151
+ The `useXyzen` hook provides access to the Xyzen state and actions.
75
152
 
76
- ### 状态 (State)
153
+ ### State
77
154
 
78
- - `isXyzenOpen: boolean`: 侧边栏是否打开。
79
- - `panelWidth: number`: 侧边栏的当前宽度。
80
- - `activeChatChannel: string | null`: 当前活动的聊天频道 ID
81
- - `user: User | null`: 当前用户信息。
82
- - `activeTabIndex: number`: 当前活动的标签页索引。
83
- - `theme: 'light' | 'dark' | 'system'`: 当前主题。
84
- - `chatHistory: ChatHistoryItem[]`: 聊天历史记录列表。
85
- - `chatHistoryLoading: boolean`: 聊天历史是否正在加载。
86
- - `channels: Record<string, ChatChannel>`: 聊天频道的映射表。
87
- - `assistants: Assistant[]`: 可用的助手列表。
155
+ - `isXyzenOpen: boolean`: Whether the sidebar is open.
156
+ - `panelWidth: number`: The current width of the sidebar.
157
+ - `activeChatChannel: string | null`: The ID of the currently active chat channel.
158
+ - `user: User | null`: The current user information.
159
+ - `activeTabIndex: number`: The index of the currently active tab.
160
+ - `theme: 'light' | 'dark' | 'system'`: The current theme.
161
+ - `chatHistory: ChatHistoryItem[]`: The list of chat history items.
162
+ - `chatHistoryLoading: boolean`: Whether the chat history is being loaded.
163
+ - `channels: Record<string, ChatChannel>`: A map of chat channels.
164
+ - `assistants: Assistant[]`: The list of available assistants.
88
165
 
89
- ### 操作 (Actions)
166
+ ### Actions
90
167
 
91
- - `toggleXyzen()`: 切换侧边栏的打开/关闭状态。
92
- - `openXyzen()`: 打开侧边栏。
93
- - `closeXyzen()`: 关闭侧边栏。
94
- - `setPanelWidth(width: number)`: 设置侧边栏的宽度。
95
- - `setActiveChatChannel(channelUUID: string | null)`: 设置当前活动的聊天频道。
96
- - `setTabIndex(index: number)`: 设置活动的标签页。
97
- - `setTheme(theme: Theme)`: 设置主题。
98
- - `fetchChatHistory(): Promise<void>`: 异步获取聊天历史记录。
99
- - `togglePinChat(chatId: string)`: 切换聊天的置顶状态。
100
- - `sendMessage(payload: { channelUUID: string; message: string })`: 发送消息到指定频道。
101
- - `createDefaultChannel()`: 创建一个新的默认聊天频道。
168
+ - `toggleXyzen()`: Toggles the open/closed state of the sidebar.
169
+ - `openXyzen()`: Opens the sidebar.
170
+ - `closeXyzen()`: Closes the sidebar.
171
+ - `setPanelWidth(width: number)`: Sets the width of the sidebar.
172
+ - `setActiveChatChannel(channelUUID: string | null)`: Sets the currently active chat channel.
173
+ - `setTabIndex(index: number)`: Sets the active tab.
174
+ - `setTheme(theme: Theme)`: Sets the theme.
175
+ - `fetchChatHistory(): Promise<void>`: Fetches the chat history asynchronously.
176
+ - `togglePinChat(chatId: string)`: Toggles the pinned state of a chat.
177
+ - `sendMessage(payload: { channelUUID: string; message: string })`: Sends a message to a specified channel.
178
+ - `createDefaultChannel()`: Creates a new default chat channel。
102
179
 
103
- ## 自定义
180
+ ## Customization
104
181
 
105
- Xyzen 设计为易于扩展。你可以利用 `useXyzen` store 中的状态和操作来构建自定义功能或与其他组件集成。
182
+ Xyzen is designed to be extensible. You can leverage the state and actions in the `useXyzen` store to build custom functionality or integrate with other components.
106
183
 
107
- 例如,你可以创建一个按钮,不仅可以打开 Xyzen,还可以切换到特定的标签页:
184
+ For example, you could create a button that not only opens Xyzen but also switches to a specific tab:
108
185
 
109
186
  ```tsx
110
187
  import { useXyzen } from "@sciol/xyzen";
@@ -1,7 +1,8 @@
1
1
  interface SessionHistoryProps {
2
+ context?: "chat" | "workshop";
2
3
  isOpen: boolean;
3
4
  onClose: () => void;
4
5
  onSelectTopic?: (topicId: string) => void;
5
6
  }
6
- export default function SessionHistory({ isOpen, onClose, onSelectTopic, }: SessionHistoryProps): import("react/jsx-runtime").JSX.Element;
7
+ export default function SessionHistory({ context, isOpen, onClose, onSelectTopic, }: SessionHistoryProps): import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -5,6 +5,10 @@ export interface ChatSlice {
5
5
  chatHistory: ChatHistoryItem[];
6
6
  chatHistoryLoading: boolean;
7
7
  channels: Record<string, ChatChannel>;
8
+ activeWorkshopChannel: string | null;
9
+ workshopHistory: ChatHistoryItem[];
10
+ workshopHistoryLoading: boolean;
11
+ workshopChannels: Record<string, ChatChannel>;
8
12
  notification: {
9
13
  isOpen: boolean;
10
14
  title: string;
@@ -24,6 +28,17 @@ export interface ChatSlice {
24
28
  updateTopicName: (topicId: string, newName: string) => Promise<void>;
25
29
  deleteTopic: (topicId: string) => Promise<void>;
26
30
  clearSessionTopics: (sessionId: string) => Promise<void>;
31
+ setActiveWorkshopChannel: (channelUUID: string | null) => void;
32
+ fetchWorkshopHistory: () => Promise<void>;
33
+ togglePinWorkshopChat: (chatId: string) => void;
34
+ activateWorkshopChannel: (topicId: string) => Promise<void>;
35
+ connectToWorkshopChannel: (sessionId: string, topicId: string) => void;
36
+ disconnectFromWorkshopChannel: () => void;
37
+ sendWorkshopMessage: (message: string) => void;
38
+ createDefaultWorkshopChannel: (agentId?: string) => Promise<void>;
39
+ updateWorkshopTopicName: (topicId: string, newName: string) => Promise<void>;
40
+ deleteWorkshopTopic: (topicId: string) => Promise<void>;
41
+ clearWorkshopSessionTopics: (sessionId: string) => Promise<void>;
27
42
  confirmToolCall: (channelId: string, toolCallId: string) => void;
28
43
  cancelToolCall: (channelId: string, toolCallId: string) => void;
29
44
  showNotification: (title: string, message: string, type?: "info" | "warning" | "error" | "success", actionLabel?: string, onAction?: () => void) => void;