xiaoyuan-assistant 0.5.45 → 0.5.46
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 +7 -0
- package/XIAOYUAN-BUSINESS-FLOW.md +15 -0
- package/package.json +1 -1
- package/package.json.bak +18 -0
- package/src/components/XiaoyuanAssistant.vue +2 -2
- package/src/context.js +23 -0
- package/src/index.js +7 -11
package/CHANGELOG.md
CHANGED
|
@@ -386,3 +386,10 @@ ls -lh /mnt/data/xiaoyuan-assistant-siliconflow-v0.5.29.zip
|
|
|
386
386
|
- 新增内置 `zh-CN-XiaoxiaoNeural` 本地‘收到指令,请您稍等’MP3。
|
|
387
387
|
- 与 `zh-CN-XiaoyiNeural` 一样优先使用包内静态音频,不请求网络 TTS。
|
|
388
388
|
- voice 切换时按 voice 分别匹配内置本地音频与 IndexedDB 缓存。
|
|
389
|
+
|
|
390
|
+
## v0.5.46 - 修复 NPM 安装后 useXiaoyuan 单例初始化报错
|
|
391
|
+
|
|
392
|
+
- 将运行时 singleton / KEY 提取到独立 `src/context.js`,解除 `src/index.js` 与 `XiaoyuanAssistant.vue` 的循环依赖。
|
|
393
|
+
- 组件内部改为直接从共享 runtime context 获取 `manager / speech / options`。
|
|
394
|
+
- 保留对外 `useXiaoyuan()` API,不改变 `app.use(Xiaoyuan, ...)` 使用方式。
|
|
395
|
+
- 修复部分 Vite/NPM 环境下出现 `请先在 main.js 中 app.use(Xiaoyuan)` 的误报。
|
|
@@ -1212,3 +1212,18 @@ AI 分析开始提示音与数据获取/模型分析并行;多个数据源采
|
|
|
1212
1212
|
## v0.5.45:新增 XiaoxiaoNeural 本地前置提示音
|
|
1213
1213
|
|
|
1214
1214
|
小园现在内置 `zh-CN-XiaoxiaoNeural` 的“收到指令,请您稍等”MP3。当前 voice 命中内置资源时直接播放本地文件;未命中时再查询对应 voice 的 IndexedDB 缓存,仍未命中才请求远程 TTS。
|
|
1215
|
+
|
|
1216
|
+
## v0.5.46 - NPM Runtime Context 稳定性
|
|
1217
|
+
|
|
1218
|
+
### Runtime Context
|
|
1219
|
+
|
|
1220
|
+
小园将全局 runtime singleton 独立到 `src/context.js`,避免入口文件与 Vue 组件互相 import 形成循环依赖。
|
|
1221
|
+
|
|
1222
|
+
初始化流程:
|
|
1223
|
+
1. `main.js` 执行 `app.use(Xiaoyuan, options)`。
|
|
1224
|
+
2. Xiaoyuan 创建 registry、speech、AI、manager。
|
|
1225
|
+
3. runtime 写入共享 context。
|
|
1226
|
+
4. 注册 `XiaoyuanAssistant` 组件。
|
|
1227
|
+
5. Vue 渲染组件时直接从共享 context 读取 runtime,不再反向依赖入口 `index.js`。
|
|
1228
|
+
|
|
1229
|
+
这样可以避免 NPM/Vite 构建场景下 singleton 尚未可见而触发“请先在 main.js 中 app.use(Xiaoyuan)”的误报。
|
package/package.json
CHANGED
package/package.json.bak
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "xiaoyuan-assistant",
|
|
3
|
+
"version": "0.5.45",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"module": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./src/index.js",
|
|
10
|
+
"default": "./src/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./style.css": "./src/styles/index.css"
|
|
13
|
+
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"vue": "^3.3.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {}
|
|
18
|
+
}
|
|
@@ -106,9 +106,9 @@
|
|
|
106
106
|
|
|
107
107
|
<script setup>
|
|
108
108
|
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
109
|
-
import {
|
|
109
|
+
import { useXiaoyuanSingleton } from '../context.js'
|
|
110
110
|
|
|
111
|
-
const { manager, speech, options } =
|
|
111
|
+
const { manager, speech, options } = useXiaoyuanSingleton()
|
|
112
112
|
const wakeWord = options.wakeWord || '你好小园'
|
|
113
113
|
const autoCollapseMs = options.autoCollapseMs ?? 0
|
|
114
114
|
|
package/src/context.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Shared runtime context for Xiaoyuan.
|
|
2
|
+
// Kept in its own module to avoid a circular dependency between
|
|
3
|
+
// src/index.js and components/XiaoyuanAssistant.vue.
|
|
4
|
+
export const KEY = Symbol('xiaoyuan')
|
|
5
|
+
|
|
6
|
+
let singleton = null
|
|
7
|
+
|
|
8
|
+
export function setXiaoyuanSingleton(value) {
|
|
9
|
+
singleton = value
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function getXiaoyuanSingleton() {
|
|
13
|
+
return singleton
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function useXiaoyuanSingleton() {
|
|
17
|
+
if (!singleton) throw new Error('请先在 main.js 中 app.use(Xiaoyuan)')
|
|
18
|
+
return singleton
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function resetXiaoyuanSingleton() {
|
|
22
|
+
singleton = null
|
|
23
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { inject } from 'vue'
|
|
2
1
|
import XiaoyuanAssistant from './components/XiaoyuanAssistant.vue'
|
|
3
2
|
import { Registry } from './core/registry.js'
|
|
4
3
|
import { XiaoyuanManager } from './core/manager.js'
|
|
@@ -7,19 +6,15 @@ import './styles/index.css'
|
|
|
7
6
|
import { createSiliconFlowProvider } from './providers/siliconflow.js'
|
|
8
7
|
import { registerBuiltinFunctions } from './core/builtins.js'
|
|
9
8
|
import { HewoyiTTSProvider } from './voice/hewoyi.js'
|
|
10
|
-
|
|
11
|
-
const KEY = Symbol('xiaoyuan')
|
|
12
|
-
|
|
13
|
-
let singleton = null
|
|
9
|
+
import { KEY, getXiaoyuanSingleton, setXiaoyuanSingleton } from './context.js'
|
|
14
10
|
|
|
15
11
|
export function useXiaoyuan() {
|
|
16
|
-
|
|
17
|
-
return singleton
|
|
12
|
+
return getXiaoyuanSingleton() || (() => { throw new Error('请先在 main.js 中 app.use(Xiaoyuan)') })()
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
const Xiaoyuan = {
|
|
21
16
|
install(app, options = {}) {
|
|
22
|
-
if (
|
|
17
|
+
if (getXiaoyuanSingleton()) return
|
|
23
18
|
|
|
24
19
|
const registry = new Registry()
|
|
25
20
|
registerBuiltinFunctions(registry)
|
|
@@ -83,11 +78,12 @@ const Xiaoyuan = {
|
|
|
83
78
|
createSiliconFlowProvider
|
|
84
79
|
}
|
|
85
80
|
|
|
86
|
-
|
|
81
|
+
const runtime = { api, registry, manager, speech, options: normalizedOptions }
|
|
82
|
+
setXiaoyuanSingleton(runtime)
|
|
87
83
|
|
|
88
84
|
app.config.globalProperties.$xiaoyuan = api
|
|
89
|
-
app.provide(KEY,
|
|
90
|
-
app.provide('xiaoyuan',
|
|
85
|
+
app.provide(KEY, runtime)
|
|
86
|
+
app.provide('xiaoyuan', runtime)
|
|
91
87
|
app.component('XiaoyuanAssistant', XiaoyuanAssistant)
|
|
92
88
|
|
|
93
89
|
if (typeof window !== 'undefined') {
|