@rtc-agent/component 0.2.6-rc.1 → 0.2.6

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
@@ -80,6 +80,39 @@ const agent = createRtcAgent({ /* ... */ });
80
80
 
81
81
  ## 用法
82
82
 
83
+ ### 工厂函数(推荐)
84
+
85
+ ```ts
86
+ import { createRtcAgent } from '@rtc-agent/component';
87
+
88
+ const agent = createRtcAgent({
89
+ appLabel: 'My Assistant',
90
+ server: { url: 'https://api.example.com' },
91
+ workerUrl: '/rtc-agent/shared-worker.js',
92
+ auth: {
93
+ getToken: () => localStorage.getItem('token'),
94
+ refreshToken: async () => {
95
+ const res = await fetch('/api/refresh');
96
+ const data = await res.json();
97
+ return { accessToken: data.token };
98
+ },
99
+ userId: 'user-123',
100
+ },
101
+ on: {
102
+ ready: () => console.log('RTC Agent ready'),
103
+ themeChange: ({ theme }) => console.log('Theme:', theme),
104
+ toolCallStart: ({ path, params }) => console.log('Tool call:', path),
105
+ },
106
+ });
107
+
108
+ document.body.appendChild(agent);
109
+
110
+ // 不再需要时销毁
111
+ agent.destroy();
112
+ ```
113
+
114
+ ### HTML 元素
115
+
83
116
  ```html
84
117
  <script type="module">
85
118
  import '@rtc-agent/component';
@@ -115,13 +148,33 @@ RTC Agent 使用 SharedWorker + Comlink 架构实现多 Tab 共享:
115
148
 
116
149
  ### 公开事件
117
150
 
118
- 所有公开事件遵循 `rtc-<domain>-<action>-<past-tense>` 命名模式:
151
+ 所有公开事件遵循 `rtc-agent-<event>` 命名模式:
152
+
153
+ **生命周期事件:**
119
154
 
120
155
  - `rtc-agent-ready` — 组件就绪
156
+ - `rtc-agent-beforeDestroy` — 组件即将销毁
157
+ - `rtc-agent-themeChange` — 主题变化
158
+
159
+ **消息拦截事件:**
160
+
161
+ - `rtc-agent-beforeMessageSend` — 消息发送前(可取消或修改)
162
+
163
+ **工具调用事件:**
164
+
165
+ - `rtc-agent-toolCallStart` — 工具调用开始
166
+ - `rtc-agent-toolCallSuccess` — 工具调用成功
167
+ - `rtc-agent-toolCallError` — 工具调用失败
168
+ - `rtc-agent-toolCallProgress` — 工具调用进度
169
+
170
+ **会话和消息事件:**
171
+
121
172
  - `rtc-session-created` / `rtc-session-switched`
122
173
  - `rtc-message-sent`
174
+
175
+ **认证事件:**
176
+
123
177
  - `rtc-auth-login-requested`
124
- - `rtc-window-minimize` / `rtc-window-maximize` / `rtc-window-restore`
125
178
 
126
179
  ### 控制器访问
127
180