@xiongtao.xt/tau-plugins 0.42.0 → 0.43.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # 更新记录
2
2
 
3
+ ## 0.43.0
4
+
5
+ - 新增统一 ASR 提供方契约、流式会话、取消与最终结果规则。
6
+ - 新增标准事件与状态语义的 WebSocket,支持鉴权头、生命周期回收及宿主背压。
7
+ - 新增语音识别账号表单与语音输入整理模型用途,桌面和移动共享插件接口。
8
+
3
9
  ## 0.42.0
4
10
 
5
11
  - 元数据按协议提取,多余属性不再阻止构建、安装或宿主请求。
@@ -140,6 +140,7 @@ var PLUGIN_AI_CAPABILITIES = {
140
140
  flashcardGeneration: { name: "\u95EA\u5361\u5236\u4F5C" },
141
141
  aiJudgement: { name: "\u7B54\u6848\u8BC4\u5224" },
142
142
  transcriptionOptimization: { name: "\u8F6C\u5F55\u65AD\u53E5\u4F18\u5316" },
143
+ speechInputRefinement: { name: "\u8BED\u97F3\u8F93\u5165\u6574\u7406" },
143
144
  videoSummary: { name: "\u89C6\u9891\u603B\u7ED3" },
144
145
  videoEbookRewrite: { name: "\u89C6\u9891\u7535\u5B50\u4E66\u91CD\u5199" },
145
146
  vibeLearningImageDescription: { name: "\u56FE\u7247\u7406\u89E3" },
@@ -3,7 +3,7 @@ import {
3
3
  readPluginFilePath,
4
4
  readPluginFiles,
5
5
  readPluginMetadata
6
- } from "./chunk-XCKDPTLI.js";
6
+ } from "./chunk-M3YEVDN4.js";
7
7
 
8
8
  // packages/plugins/src/portable.ts
9
9
  var PORTABLE_PLATFORMS = ["desktop", "android", "ios"];
package/docs/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Tau 插件开发文档
2
2
 
3
- 默认模板使用 SDK 0.42.0、UI 0.5.0,生成格式 3 的同一插件包。中心 v2 支持上传待审,格式 3 普通提交人工批准,具审核权限的作者本人经已绑定仓库 CI 发布可自动批准;平台测试由作者负责,不要求审核者测试或填写验证记录。Android/iOS 正式安装要求客户端至少 0.2.4,并通过中心兼容选版。先读 [API 支持矩阵](api-support.md)、[跨端契约](portability.md)与[快速开始](getting-started.md)。下文桌面领域接口不表示移动端可用。
3
+ 默认模板使用 SDK 0.43.0、UI 0.5.0,生成格式 3 的同一插件包。中心 v2 支持上传待审,格式 3 普通提交人工批准,具审核权限的作者本人经已绑定仓库 CI 发布可自动批准;平台测试由作者负责,不要求审核者测试或填写验证记录。Android/iOS 正式安装要求客户端至少 0.2.4,并通过中心兼容选版。先读 [API 支持矩阵](api-support.md)、[跨端契约](portability.md)与[快速开始](getting-started.md)。下文桌面领域接口不表示移动端可用。
4
4
 
5
5
  Tau 插件用 TypeScript 和 React 编写,打包成一个 ZIP,按声明在兼容的 Tau 宿主运行。插件可以给 Tau 加页面和侧边栏入口,在文档里放自定义块,给 AI 提供工具,接入第三方存储、语音、视频等服务,或者读写用户的卡片和待办。
6
6
 
@@ -31,6 +31,7 @@ Tau 插件用 TypeScript 和 React 编写,打包成一个 ZIP,按声明在
31
31
  | 创建闪卡、打开制卡窗口 | [闪卡](flashcards.md) |
32
32
  | 编译 Tailwind、转换 Markdown、处理音视频 | [编译与转换服务](services.md) |
33
33
  | 运行 Node.js 代码、调用本机程序 | [本机后台](backend.md) |
34
+ | 接入语音识别 | [语音识别](providers/asr.md) |
34
35
  | 接入同步存储、图床、语音、图片生成、视频网站、博客发布目标 | [服务提供方](providers/README.md) |
35
36
  | 开发独立博客站点,读取 Tau 发布的数据 | [站点数据](site-data.md) |
36
37
 
package/docs/ai.md CHANGED
@@ -44,6 +44,7 @@ console.log(result.text);
44
44
  | `flashcardGeneration` | 闪卡制作 |
45
45
  | `aiJudgement` | 答案评判 |
46
46
  | `transcriptionOptimization` | 转录断句优化 |
47
+ | `speechInputRefinement` | 语音输入整理 |
47
48
  | `videoSummary` | 视频总结 |
48
49
  | `videoEbookRewrite` | 视频电子书重写 |
49
50
  | `vibeLearningImageDescription` | 图片理解 |
@@ -167,3 +168,5 @@ for await (const event of model.stream({
167
168
  通过 `signal` 取消时,也可能抛出标准的 `AbortError`。
168
169
 
169
170
  遇到额度不足、拒绝授权这类错误后,不要自动循环重试。不要在模块顶层调用 AI;在 `activate` 中也不要等待 AI 请求完成,以免拖慢插件启用。
171
+
172
+ `speechInputRefinement`(SDK 0.43.0 / 桌面 0.59.5)引用应用分配的语音整理模型,不是发起录音的接口。宿主听写整理本身不依赖插件,也不向整理模型授予工具;移动端尚未接入这一 LLM 执行能力。
@@ -37,6 +37,12 @@
37
37
  | `context.tts`、`context.images`、`context.video`、`context.publish` | 领域提供方已接 | 未接 | 未接 | 本轮不扩大其他业务领域 |
38
38
  | `context.backend` | 格式 2 独立后台与授权已接 | 格式 3 不支持 | 格式 3 不支持 | Node、子进程、本机程序使用独立的桌面后台包 |
39
39
 
40
+ ## ASR 与 WebSocket
41
+
42
+ SDK 0.43.0 的 `context.asr`、`context.websocket` 与 `settings target: "asr"` 已接桌面 0.59.5、Android/iOS 0.2.7 宿主源码。移动插件使用同一注册、配置和事件接口,音频由宿主采集,插件不访问麦克风。设备与真实云端账号验收单独记录;Windows 原生识别仍待验证,不影响插件契约。
43
+
44
+ ASR 支持能力探测、可取消的流式会话与可选文件任务;提供方必须真实声明能力,Seed 当前仅流式。WebSocket 的工厂仅扩展鉴权头和 signal,连接保留标准事件、状态、同步 send/close;详见 [WebSocket 契约](websocket.md)。聊天和搜索只在最终结果后写入草稿;桌面可选 AI 整理复用现有模型配置,移动暂使用原文。
45
+
40
46
  ## 正文、UI 与交互
41
47
 
42
48
  | 能力 | 已实现范围 | 作者需要适配 | 宿主未接或待验收 |
@@ -12,7 +12,7 @@ pnpm install --frozen-lockfile
12
12
  pnpm build
13
13
  ```
14
14
 
15
- SDK 0.42.0 已发布到 npm,直接使用上述冻结安装与构建命令,无需本地 tarball。SDK 发布不代表插件或 APP 已发布;客户端要求以清单和支持矩阵为准。
15
+ SDK 0.43.0 已发布到 npm,直接使用上述冻结安装与构建命令,无需本地 tarball。SDK 发布不代表插件或 APP 已发布;客户端要求以清单和支持矩阵为准。
16
16
 
17
17
  3. 构建生成 `dist/<插件ID>-<版本>.zip`;再次安装可用 `pnpm install --frozen-lockfile`。
18
18
  4. 在目标宿主验证后按发布指南上传待审;格式 3 普通提交人工审核,具审核权限的作者本人通过已绑定仓库 CI 发布可自动批准。移动用户从应用内中心安装,首次安装保存启用意图,重开应用生效;桌面 0.59.1 支持格式 3 中心安装,首次安装后需在已安装页启用并重启。install:local 不把格式 3 写进旧桌面正式目录。
@@ -40,3 +40,7 @@ SDK 0.42.0 已发布到 npm,直接使用上述冻结安装与构建命令,
40
40
  4. 更新 README,构建后在目标宿主验收启用、保存、停用与恢复。
41
41
 
42
42
  契约见[跨端开发](portability.md),生命周期见[插件组成](plugin-basics.md)。仓库外构建只证明作者闭环,不替代宿主和真机验收。
43
+
44
+ ## 开发语音识别插件
45
+
46
+ ASR 与标准 WebSocket 需要 SDK 0.43.0、桌面 0.59.5 或移动 0.2.7。模板已使用 npm 的 SDK 0.43.0;冻结安装、构建后再在目标宿主验证。接口见 [语音识别](providers/asr.md) 与 [WebSocket](websocket.md)。SDK 可安装不代表客户端已经发行,最低客户端版本与平台分发仍由插件清单控制。
@@ -4,7 +4,7 @@
4
4
 
5
5
  一个 SDK、一套模板、同一插件 ID/版本对应同一 ZIP。普通页面直接使用公共 API;宿主在加载前检查兼容性。具体宿主实现范围见 [API 支持矩阵](api-support.md),SDK 类型存在不等于所有接口都已在移动端接入。
6
6
 
7
- 格式 3 也承载仅桌面的插件。使用业务数据、视频、语音、图片生成或博客发布等桌面能力时,只声明 desktop;不要增加尚未实现对应 API 的移动目标。白板插件继续使用 whiteboardExtensions,作者清单不重复填写白板类型,也不声明白板能力标签。宿主从实际定义识别静态贡献,作者只声明 desktop,安装兼容性统一由平台和最低客户端版本决定。
7
+ 格式 3 也承载仅桌面的插件。使用业务数据、视频、语音合成、图片生成或博客发布等桌面能力时,只声明 desktop;不要增加尚未实现对应 API 的移动目标。白板插件继续使用 whiteboardExtensions,作者清单不重复填写白板类型,也不声明白板能力标签。宿主从实际定义识别静态贡献,作者只声明 desktop,安装兼容性统一由平台和最低客户端版本决定。
8
8
 
9
9
  ## 作者清单
10
10
 
@@ -108,3 +108,7 @@ React、SDK 与公共 UI 由宿主提供,其他浏览器依赖随包构建;
108
108
  ## 验证
109
109
 
110
110
  仓库外构建验证依赖闭包、类型和包格式;设备联调验证安装、启用、插入、编辑、保存、取消、只读与重启恢复。两者分别记录,模拟器不能替代真机、最低系统、平板与性能验收。发布 SDK、插件和客户端分别遵循明确发行授权。
111
+
112
+ ## 语音输入提供方
113
+
114
+ ASR 与语音合成是独立注册。语音输入插件使用 `context.asr.register` 和 `settings target: "asr"`,账号通过 `asrConfig.save(value, modelId)` 保存;麦克风、重采样、输入目标、提交守卫由宿主管理。SDK 0.43.0 要求 ASR 目标最低桌面 0.59.5、移动 0.2.7。`context.websocket.connect` 同步返回标准 WebSocket 接口形状,鉴权头和任务 signal 为第三参扩展;两端的发送背压、关闭握手和插件生命周期由宿主统一处理。详见 [WebSocket](websocket.md)。
@@ -6,6 +6,7 @@ Tau 的一些功能允许用户选择背后的服务:同步到哪个存储、
6
6
  | ---------------------- | ---------------------------------------- | ---------------------------- |
7
7
  | [同步存储](sync.md) | 把笔记库同步到你接入的存储服务 | 设置 · 同步 |
8
8
  | [资源上传](upload.md) | 把编辑器里的图片、附件上传到你接入的存储 | 设置 · 资源存储 |
9
+ | [语音识别](asr.md) | 将语音转为输入草稿 | 设置 · 语音输入 |
9
10
  | [语音合成](tts.md) | 用你接入的服务朗读、生成播客、复刻音色 | 设置 · 语音 |
10
11
  | [图片生成](images.md) | 用你接入的模型生成和编辑图片 | 设置 · 图片生成 |
11
12
  | [视频来源](video.md) | 从你接入的视频网站或服务添加视频 | 设置 · 账号与连接 · 在线视频 |
@@ -69,6 +70,7 @@ context.settings.register({
69
70
  | --------- | ------------------ | ---------------------- |
70
71
  | `sync` | `syncConfig` | `save(value)` |
71
72
  | `upload` | `uploadConfig` | `save(value)` |
73
+ | `asr` | `asrConfig` | `save(value, modelId)` |
72
74
  | `tts` | `ttsConfig` | `save(value, models)` |
73
75
  | `images` | `imageConfig` | `save(value, modelId)` |
74
76
  | `video` | `videoConfig` | `save(value)` |
@@ -85,7 +87,7 @@ context.settings.register({
85
87
 
86
88
  ### 3. 网络请求与取消
87
89
 
88
- - 请求统一用 [`context.fetch`](../storage-and-network.md#网络请求)。
90
+ - HTTP 请求使用 `context.fetch`,双向连接使用 `context.websocket`,见[存储与网络](/docs/storage-and-network.md)。
89
91
  - 提供方的方法会收到 `signal`,把它传给 `context.fetch`。重试前的等待、轮询也要响应取消。
90
92
  - 自己设置超时时,用 `AbortSignal.any([signal, AbortSignal.timeout(ms)])` 组合,不要丢掉 Tau 传入的 `signal`。
91
93
  - 取消后不要把 `AbortError` 当成可重试的错误。
@@ -0,0 +1,41 @@
1
+ # 语音识别提供方
2
+
3
+ 使用 SDK 0.43.0,目标最低桌面 0.59.5、Android/iOS 0.2.7。宿主版本与 SDK 的正式发布状态分开检查。默认模板使用 npm 的 SDK 0.43.0 和正式锁文件;直接冻结安装后开发,不需要本机 SDK 路径。
4
+
5
+ ## 注册与配置
6
+
7
+ ```ts
8
+ context.asr.register({
9
+ id: context.pluginId,
10
+ name: "我的语音识别",
11
+ create: (config, modelId) => createRecognition(context.websocket, config, modelId),
12
+ });
13
+ context.settings.register({
14
+ id: "asr",
15
+ title: "识别账号",
16
+ target: "asr",
17
+ component: RecognitionSettings,
18
+ });
19
+ ```
20
+
21
+ `createRecognition` 返回 `ASRInstance`,同步固定配置,不联网、不录音。配置表单接收 `PluginSettingsProps.asrConfig`(value、modelId、save);用 `save(value, modelId)` 保存账号。保存不等于选用,用户需在宿主设置中明确选择,失败不回退到云端或其他账号。凭据不要写入 `context.storage`。
22
+
23
+ ## 引擎契约
24
+
25
+ - `probe({ input, language, ... }, signal)` 返回真实可用性与能力;不下载资源、不申请麦克风。状态包括 ready、needs-config、needs-assets、unsupported、unavailable。
26
+ - 实时引擎实现 `openStream(request, options)`,返回 `write(frame)`、`endInput()`、`cancel()`、`result`。文件引擎实现 `transcribeFile`;未实现的方法不声明支持,不能把停止后转录包装成实时结果。
27
+ - 输入是协商采样率、单声道、显式小端 PCM Int16。每帧 seq 与 startSample 连续递增;宿主负责采集和重采样。不要在插件访问 getUserMedia 或使用 Node 音频模块。
28
+ - 事件通过 options.onEvent 交付;使用 `createASRStreamSession` 管理任务序号、有限队列、结束、取消与尾句超时。临时文字是当前快照的修订,不是追加片段;已确认段不得再次改写。
29
+ - `endInput()` 停止接受新音频并排空已排队帧;驱动 finish 发送厂商结束标记,然后等待服务器最终结果。`result` 只在确认最终文本后成功。分句 final 与任务完成是不同状态。
30
+ - `cancel()` 中止音频和网络并清理资源;插件停用同样取消进行中任务。不把断线或取消包装成成功、空结果或不完整草稿。
31
+ - 麦克风授权、单会话互斥、页面离开、草稿冲突、最终文字写入由宿主负责。插件只识别,不自动发送聊天或执行搜索。
32
+
33
+ ## 网络与背压
34
+
35
+ 使用 [WebSocket](/docs/websocket.md) 的标准事件接口。`send()` 返回 void,`close()` 发起关闭握手,二者均不是识别任务的完成信号。插件在 open 后发送,在 message 中解析并校验厂商协议,在 error/非预期 close 时令任务失败。设置 binaryType = "arraybuffer" 处理二进制协议。
36
+
37
+ 每个会话传入任务 signal,宿主自动合并插件生命周期。背压由宿主负责;插件不引入 send Promise、receive 拉取接口或额外流控协议。JSON、压缩包、序号与时戳仍需插件自己校验。
38
+
39
+ ## 验证清单
40
+
41
+ 类型检查、插件构建、中文临时修订、结束尾帧、空音频、服务器最终标记、连接中取消、录音中停用、断线与额度错误。分别记录桌面、Android、iOS 的设备验证与未验证范围;仅声明平台和通过编译不能替代真实设备及账号验证。
@@ -62,3 +62,7 @@ const data: unknown = await response.json();
62
62
  - 响应数据先校验再使用,尤其是写入存储之前。
63
63
  - 不要把私人的 API Key 写进源码。需要用户自己的凭据时,让用户在设置中填写。
64
64
  - 能读到的用户数据都可以通过网络发送出去。只在功能确实需要时这样做,并在 README 里向用户说明。
65
+
66
+ ## WebSocket
67
+
68
+ 实时双向通信使用 `context.websocket.connect(url, protocols?, { headers, signal })`。它同步返回连接,标准事件、状态和 send/close 保持不变,背压由宿主处理。详见 [WebSocket](websocket.md)。ASR 插件的完整接入见 [语音识别](providers/asr.md)。需要 SDK 0.43.0 和对应新版宿主;默认计数器模板保留已发布 SDK 基线,开发未发布接口按快速开始的候选包流程验证。
@@ -0,0 +1,39 @@
1
+ <!-- 由 scripts/plugins/sync-author-docs.mjs 从 packages/plugins/docs/websocket.md 生成,请勿单独编辑。 -->
2
+
3
+ # WebSocket
4
+
5
+ `context.websocket.connect(url, protocols?, options?)` 同步返回标准 `WebSocket` 接口形状的连接。SDK 0.43.0 对应桌面 0.59.5、移动 0.2.7 的宿主实现;这不代表这些版本已发布。插件无需引入 Node.js `ws`,同一代码用于桌面、Android 与 iOS。
6
+
7
+ ```ts
8
+ const socket = context.websocket.connect("wss://api.example.com/stream", [], {
9
+ headers: { Authorization: `Bearer ${token}` },
10
+ signal: taskSignal,
11
+ });
12
+ socket.binaryType = "arraybuffer";
13
+ socket.addEventListener("open", () => socket.send("开始"));
14
+ socket.addEventListener("message", event => consume(event.data));
15
+ socket.addEventListener("error", () => reportConnectionFailure());
16
+ socket.addEventListener("close", event => finish(event.code, event.reason, event.wasClean));
17
+ // 完成业务协议后再关闭;close 不能代替 ASR 的结束输入标记。
18
+ socket.close(1000, "完成");
19
+ ```
20
+
21
+ ## 标准语义
22
+
23
+ - 返回时为 `CONNECTING`;握手成功后进入 `OPEN` 并发送 `open`。`onopen/onmessage/onerror/onclose` 与 `addEventListener/removeEventListener` 均可使用。
24
+ - `url`、`readyState`、`protocol`、`extensions`、`bufferedAmount` 只读;实例提供 `CONNECTING/OPEN/CLOSING/CLOSED` 常量。
25
+ - `send(string | Blob | ArrayBuffer | ArrayBufferView)` 同步返回 `void`,连接中调用抛 `InvalidStateError`。关闭中或已关闭时丢弃数据;`bufferedAmount` 仍计入该次字节数。缓冲区在调用时复制,异步发送不受调用方后续修改影响。
26
+ - `bufferedAmount` 是已接收、尚未交给原生发送层完成的应用字节数,**不是服务器已接收或已识别的证明**。宿主保持消息顺序、限额和发送排空;插件不轮询背压或等待非标准发送 Promise。
27
+ - `binaryType` 默认为 `blob`,可改为 `arraybuffer`。文本消息始终为字符串。`message.data` 的类型按投递时的 `binaryType` 决定。
28
+ - `close(code?, reason?)` 同步返回 `void`,切换到 `CLOSING`,排空此前的发送后发起关闭握手。关闭码允许 1000 或 3000–4999;原因最多 123 个 UTF-8 字节。错误参数同步抛异常,重复关闭不重复握手。
29
+ - 正常关闭传递服务端关闭码、原因与 `wasClean`。握手失败、断线、队列溢出、生命周期取消发送 `error`,随后一次 `close`(1006、空原因、`wasClean: false`)。底层异常不会包含鉴权头或服务器正文。
30
+
31
+ ## 宿主扩展与边界
32
+
33
+ 仅工厂的第三个参数扩展 `headers` 和 `signal`。`protocols` 与标准构造器的第二参数一致。插件停用、工作区失效自动取消所有连接,任务 `signal` 可提前结束单次连接。生命周期取消直接释放连接,不保证发送剩余数据;正常结束使用业务结束标记、等待最终结果,再 `close()`。
34
+
35
+ 网络由原生层执行,不是浏览器的全局构造器实例:不要依赖 `instanceof WebSocket`、浏览器 Cookie、CORS 或浏览器扩展。宿主不自动携带浏览器 Cookie,不重连、不跟随重定向。允许 `wss`,仅本机测试允许 `ws`;`https/http` 转换为对应 WebSocket 协议后应用同一限制。地址禁止凭据和片段。鉴权头禁止换行以及覆盖 Host、Connection、Upgrade、Sec-WebSocket-*;子协议走 `protocols`。
36
+
37
+ 宿主每连接单消息上限 1 MiB,收发各自有界排队(最多 2 MiB),空消息也计入最多 256 条等待消息的限制(移动原生收包队列为 2 条),每宿主窗口最多 32 个连接,握手与关闭排空各限 10 秒。超限使连接失败,不静默丢语音帧、不自动重试带鉴权的请求。
38
+
39
+ 规范依据:[WHATWG WebSockets](https://websockets.spec.whatwg.org/)。此适配遵循上述事件、状态、发送与关闭语义,不宣称实现完整浏览器网络环境或通过全部 Web 平台一致性测试。
package/package.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  isPluginPermission,
13
13
  validateBackendManifest,
14
14
  validatePluginManifest
15
- } from "./client/chunk-XCKDPTLI.js";
15
+ } from "./client/chunk-M3YEVDN4.js";
16
16
  export {
17
17
  PLUGIN_AI_CAPABILITIES,
18
18
  PLUGIN_CATEGORIES,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiongtao.xt/tau-plugins",
3
- "version": "0.42.0",
3
+ "version": "0.43.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
package/portable.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  readPortablePluginManifest,
7
7
  validatePortableDistributionManifest,
8
8
  validatePortablePluginManifest
9
- } from "./client/chunk-666OM7IO.js";
10
- import "./client/chunk-XCKDPTLI.js";
9
+ } from "./client/chunk-X6MBLKAL.js";
10
+ import "./client/chunk-M3YEVDN4.js";
11
11
  export {
12
12
  PORTABLE_PLATFORMS,
13
13
  PORTABLE_SHARED_MODULES,
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  PORTABLE_SHARED_MODULES,
3
3
  readPortablePluginManifest
4
- } from "./client/chunk-666OM7IO.js";
4
+ } from "./client/chunk-X6MBLKAL.js";
5
5
  import {
6
6
  PLUGIN_SHARED_MODULES,
7
7
  validatePluginManifest
8
- } from "./client/chunk-XCKDPTLI.js";
8
+ } from "./client/chunk-M3YEVDN4.js";
9
9
 
10
10
  // packages/db-schema/content-resources.ts
11
11
  var CONTENT_RESOURCE_KINDS = [
@@ -0,0 +1,11 @@
1
+ import type { ASRAudioFormat, ASRAudioFrame } from "./types";
2
+ export declare const ASR_WORKLET_SOURCE = "\nclass TauCapture extends AudioWorkletProcessor {\n constructor(options) {\n super();\n this.rate = options.processorOptions.rate;\n this.ratio = sampleRate / this.rate;\n this.remaining = this.ratio; this.sum = 0;\n this.capacity = Math.max(1, Math.round(this.rate / 5));\n this.buffer = new ArrayBuffer(this.capacity * 2);\n this.view = new DataView(this.buffer); this.count = 0;\n this.pending = 0; this.stopped = false;\n this.port.onmessage = ({data}) => {\n if (data === 'ack') this.pending = Math.max(0, this.pending - 1);\n if (data === 'stop' && !this.stopped) {\n if (this.remaining < this.ratio) this.sample(this.sum / (this.ratio - this.remaining));\n this.flush(); this.stopped = true; this.port.postMessage({type:'stopped'});\n }\n };\n }\n sample(value) {\n const clipped = Math.max(-1, Math.min(1, value));\n this.view.setInt16(this.count * 2, Math.round(clipped * (clipped < 0 ? 32768 : 32767)), true);\n this.count++;\n if (this.count === this.capacity) this.flush();\n }\n flush() {\n if (!this.count || this.stopped) return;\n if (this.pending >= 10) { this.stopped = true; this.port.postMessage({type:'overflow'}); return; }\n const data = this.count === this.capacity ? this.buffer : this.buffer.slice(0, this.count * 2);\n this.port.postMessage({type:'frame', data}, [data]); this.pending++;\n this.buffer = new ArrayBuffer(this.capacity * 2); this.view = new DataView(this.buffer); this.count = 0;\n }\n process(inputs) {\n if (this.stopped) return false;\n const channels = inputs[0]; if (!channels?.length) return true;\n for (let index = 0; index < channels[0].length; index++) {\n let value = 0; for (const channel of channels) value += channel[index]; value /= channels.length;\n let left = 1;\n while (left > 1e-9 && !this.stopped) {\n const weight = Math.min(left, this.remaining);\n this.sum += value * weight; this.remaining -= weight; left -= weight;\n if (this.remaining <= 1e-9) { this.sample(this.sum / this.ratio); this.sum = 0; this.remaining = this.ratio; }\n }\n if (this.stopped) break;\n }\n return !this.stopped;\n }\n}\nregisterProcessor('tau-asr-capture', TauCapture);\n";
3
+ export interface MicrophoneCapture {
4
+ stop(): Promise<void>;
5
+ cancel(): Promise<void>;
6
+ }
7
+ /** 在用户点击的同步阶段创建并唤醒 AudioContext,权限与采集稍后才开始。 */
8
+ export declare function prepareMicrophone(signal: AbortSignal, onError: (error: unknown) => void): {
9
+ cancel: () => Promise<void>;
10
+ start(format: ASRAudioFormat, write: (frame: ASRAudioFrame) => Promise<void>): Promise<MicrophoneCapture>;
11
+ };
@@ -0,0 +1,9 @@
1
+ export type ASRErrorCode = "cancelled" | "unsupported" | "invalid-input" | "needs-assets" | "unavailable" | "busy" | "timeout" | "protocol" | "internal";
2
+ export declare class ASRError extends Error {
3
+ readonly code: ASRErrorCode;
4
+ constructor(code: ASRErrorCode, message: string);
5
+ }
6
+ export declare function asrAbortError(): ASRError;
7
+ export declare function throwIfASRAborted(signal: AbortSignal): void;
8
+ /** 停止等待后仍观察原任务拒绝,资源释放由驱动的 dispose 负责。 */
9
+ export declare function waitForASR<T>(promise: Promise<T>, signal: AbortSignal): Promise<T>;
@@ -0,0 +1,8 @@
1
+ export * from "./types";
2
+ export * from "./errors";
3
+ export * from "./reducer";
4
+ export * from "./task";
5
+ export * from "./stream";
6
+ export * from "./capture";
7
+ export * from "./input";
8
+ export * from "./refinement";
@@ -0,0 +1,30 @@
1
+ import type { ASREvent, ASRStreamSession, ASRTranscript } from "./types";
2
+ export interface SpeechInputSession {
3
+ result: Promise<ASRTranscript>;
4
+ stop(): Promise<void>;
5
+ cancel(): Promise<void>;
6
+ }
7
+ export interface SpeechInputService {
8
+ start(options: {
9
+ signal: AbortSignal;
10
+ onPreview(text: string): void;
11
+ }): Promise<SpeechInputSession>;
12
+ }
13
+ export interface SpeechInputSetting {
14
+ active: "native" | "plugin";
15
+ language: string;
16
+ refinement?: import("./refinement").SpeechRefinementPreferences;
17
+ plugin: {
18
+ id: string;
19
+ configurations: Record<string, {
20
+ modelId: string;
21
+ config: unknown;
22
+ }>;
23
+ };
24
+ }
25
+ export declare function defaultSpeechInputSetting(): SpeechInputSetting;
26
+ export declare function createSpeechInputService(open: (taskId: string, signal: AbortSignal, onEvent: (event: ASREvent) => void) => Promise<{
27
+ session: ASRStreamSession;
28
+ format: import("./types").ASRAudioFormat;
29
+ release(): Promise<void>;
30
+ }>): SpeechInputService;
@@ -0,0 +1,14 @@
1
+ import type { ASREvent, ASRSegment, ASRTranscript } from "./types";
2
+ export declare function validateTranscript(result: ASRTranscript): void;
3
+ export declare class ASRTranscriptReducer {
4
+ private readonly taskId;
5
+ private seq;
6
+ private revision;
7
+ private segments;
8
+ constructor(taskId: string);
9
+ getSnapshot(): {
10
+ revision: number;
11
+ segments: readonly ASRSegment[];
12
+ };
13
+ apply(event: ASREvent): boolean;
14
+ }
@@ -0,0 +1,21 @@
1
+ import type { ASRTranscript } from "./types";
2
+ export interface SpeechRefinementPreferences {
3
+ style: "light" | "paragraphs";
4
+ instructions: string;
5
+ }
6
+ export declare const DEFAULT_SPEECH_REFINEMENT: SpeechRefinementPreferences;
7
+ export declare function validateSpeechRefinementPreferences(value: unknown): SpeechRefinementPreferences;
8
+ export type SpeechRefiner = (text: string, options: {
9
+ signal: AbortSignal;
10
+ onPreview(text: string): void;
11
+ }) => Promise<string>;
12
+ export interface SpeechRefinementResult {
13
+ original: ASRTranscript;
14
+ text: string;
15
+ status: "original" | "refined" | "fallback";
16
+ }
17
+ /** 整理与原始时间轴分开;取消整个会话不交付原文,其他失败才降级。 */
18
+ export declare function refineSpeechInput(transcript: ASRTranscript, refine: SpeechRefiner | undefined, options: {
19
+ signal: AbortSignal;
20
+ onPreview(text: string): void;
21
+ }, timeoutMs?: number): Promise<SpeechRefinementResult>;
@@ -0,0 +1,12 @@
1
+ import type { ASRAudioFormat, ASRAudioFrame, ASREventPayload, ASRRunOptions, ASRStreamSession, ASRTranscript } from "./types";
2
+ export declare function validateASRAudioFormat(format: ASRAudioFormat): void;
3
+ export interface ASRStreamDriver {
4
+ write(frame: ASRAudioFrame, signal: AbortSignal): Promise<void>;
5
+ finish(signal: AbortSignal, emit: (event: ASREventPayload) => void): Promise<ASRTranscript>;
6
+ dispose(): Promise<void>;
7
+ }
8
+ /** 驱动可在 write 中交付实时事件;finish 发送结束标记并等待最终结果。 */
9
+ export declare function createASRStreamSession(options: ASRRunOptions, format: ASRAudioFormat, connect: (signal: AbortSignal, emit: (event: ASREventPayload) => void) => Promise<ASRStreamDriver>, limits?: {
10
+ maxBufferedMs: number;
11
+ tailTimeoutMs: number;
12
+ }): ASRStreamSession;
@@ -0,0 +1,2 @@
1
+ import type { ASREventPayload, ASRRunOptions, ASRTask, ASRTranscript } from "./types";
2
+ export declare function createASRTask<T extends ASRTranscript>(options: ASRRunOptions, execute: (signal: AbortSignal, emit: (payload: ASREventPayload) => void) => Promise<T>): ASRTask<T>;
@@ -0,0 +1,108 @@
1
+ export interface ASRWord {
2
+ text: string;
3
+ startMs: number;
4
+ endMs: number;
5
+ }
6
+ export interface ASRSegment {
7
+ id: string;
8
+ text: string;
9
+ final: boolean;
10
+ startMs?: number;
11
+ endMs?: number;
12
+ speakerId?: string;
13
+ }
14
+ export interface ASRTranscript {
15
+ text: string;
16
+ segments?: readonly ASRSegment[];
17
+ words?: readonly ASRWord[];
18
+ language?: string;
19
+ durationMs?: number;
20
+ }
21
+ export interface ASRAudioFormat {
22
+ encoding: "pcm-s16le";
23
+ sampleRateHz: number;
24
+ channels: 1;
25
+ }
26
+ export interface ASRAudioFrame {
27
+ seq: number;
28
+ startSample: number;
29
+ data: Uint8Array;
30
+ }
31
+ export interface ASRAudioFile {
32
+ name: string;
33
+ mimeType: string;
34
+ sizeBytes: number;
35
+ open(signal: AbortSignal): Promise<ReadableStream<Uint8Array>>;
36
+ }
37
+ export interface ASRRequest {
38
+ language: string;
39
+ }
40
+ export interface ASRFileRequest extends ASRRequest {
41
+ audio: ASRAudioFile;
42
+ }
43
+ export interface ASRStreamRequest extends ASRRequest {
44
+ format: ASRAudioFormat;
45
+ }
46
+ export interface ASRProbeRequest extends ASRRequest {
47
+ input: "file" | "stream";
48
+ }
49
+ export interface ASRAvailability {
50
+ state: "ready" | "needs-permission" | "needs-assets" | "needs-config" | "unavailable" | "unsupported";
51
+ reason?: string;
52
+ execution: "device" | "remote" | "unknown";
53
+ textUpdates: "partial" | "segments" | "final-only";
54
+ timestamps: "none" | "segment" | "word";
55
+ speakerLabels: boolean;
56
+ acceptedAudio?: {
57
+ streamFormats?: readonly ASRAudioFormat[];
58
+ fileMimeTypes?: readonly string[];
59
+ };
60
+ maxDurationMs?: number;
61
+ }
62
+ export type ASREventPayload = {
63
+ type: "segments";
64
+ baseRevision: number;
65
+ revision: number;
66
+ startIndex: number;
67
+ deleteCount: number;
68
+ segments: readonly ASRSegment[];
69
+ } | {
70
+ type: "progress";
71
+ stage: "uploading" | "recognizing";
72
+ fraction?: number;
73
+ message?: string;
74
+ };
75
+ export type ASREvent = {
76
+ taskId: string;
77
+ seq: number;
78
+ } & ASREventPayload;
79
+ export interface ASRRunOptions {
80
+ taskId: string;
81
+ signal: AbortSignal;
82
+ onEvent: (event: ASREvent) => void;
83
+ }
84
+ export interface ASRTask<T extends ASRTranscript = ASRTranscript> {
85
+ readonly result: Promise<T>;
86
+ /** 等待底层资源清理;完成后调用不会撤回已经交付的结果。 */
87
+ cancel(): Promise<void>;
88
+ }
89
+ export interface ASRStreamSession extends ASRTask {
90
+ write(frame: ASRAudioFrame): Promise<void>;
91
+ /** 停止接收并排空已接受帧;最终识别结果仍从 result 取得。 */
92
+ endInput(): Promise<void>;
93
+ }
94
+ export interface ASRInstance {
95
+ probe(request: ASRProbeRequest, signal: AbortSignal): Promise<ASRAvailability>;
96
+ transcribeFile?(request: ASRFileRequest, options: ASRRunOptions): Promise<ASRTask>;
97
+ openStream?(request: ASRStreamRequest, options: ASRRunOptions): Promise<ASRStreamSession>;
98
+ }
99
+ export declare const MAC_NATIVE_ASR_DEFAULTS: Readonly<{
100
+ vad: "medium";
101
+ format: Readonly<{
102
+ encoding: "pcm-s16le";
103
+ sampleRateHz: 16000;
104
+ channels: 1;
105
+ }>;
106
+ tailTimeoutMs: 10000;
107
+ maxBufferedMs: 2000;
108
+ }>;
@@ -25,6 +25,9 @@ export declare const PLUGIN_AI_CAPABILITIES: {
25
25
  readonly transcriptionOptimization: {
26
26
  readonly name: "转录断句优化";
27
27
  };
28
+ readonly speechInputRefinement: {
29
+ readonly name: "语音输入整理";
30
+ };
28
31
  readonly videoSummary: {
29
32
  readonly name: "视频总结";
30
33
  };
@@ -0,0 +1,13 @@
1
+ import type { ASRInstance } from "../../asr/src/index";
2
+ import type { Disposable, JsonValue } from "./contract";
3
+ export interface ASRProviderDefinition {
4
+ id: string;
5
+ name: string;
6
+ /** 固定本次账号与模型,不在创建时联网或录音。 */
7
+ create(config: JsonValue, modelId: string): ASRInstance;
8
+ }
9
+ export interface PluginASR {
10
+ register(definition: ASRProviderDefinition): Disposable;
11
+ }
12
+ export type { ASRWord, ASRSegment, ASRTranscript, ASRAudioFormat, ASRAudioFrame, ASRAudioFile, ASRRequest, ASRFileRequest, ASRStreamRequest, ASRProbeRequest, ASRAvailability, ASREventPayload, ASREvent, ASRRunOptions, ASRTask, ASRStreamSession, ASRInstance, ASRStreamDriver, ASRErrorCode, } from "../../asr/src/index";
13
+ export { ASRError, createASRStreamSession, createASRTask, throwIfASRAborted } from "../../asr/src/index";
@@ -11,6 +11,8 @@ import type { PluginSettings } from "./settings";
11
11
  import type { PluginSync } from "./sync";
12
12
  import type { PluginUpload } from "./upload";
13
13
  import type { PluginTTS } from "./tts";
14
+ import type { PluginASR } from "./asr";
15
+ import type { PluginWebSocket } from "./websocket";
14
16
  import type { PluginImages } from "./images";
15
17
  import type { PluginVideo } from "./video";
16
18
  import type { PluginPublish } from "./publish";
@@ -65,6 +67,8 @@ export interface PluginContext {
65
67
  readonly sync: PluginSync;
66
68
  readonly upload: PluginUpload;
67
69
  readonly tts: PluginTTS;
70
+ readonly asr: PluginASR;
71
+ readonly websocket: PluginWebSocket;
68
72
  readonly images: PluginImages;
69
73
  readonly video: PluginVideo;
70
74
  readonly publish: PluginPublish;
@@ -55,3 +55,5 @@ export type { PluginPageContext, PluginPageDefinition, PluginPageHandle, PluginP
55
55
  export declare function definePlugin(definition: Omit<PluginDefinition, "apiVersion" | "create"> & Partial<Pick<PluginDefinition, "create">>): PluginDefinition;
56
56
  export type { PluginAI, PluginAIFeature, PluginAIRequest, PluginAIResult, PluginAIEvent, PluginAIFeatures, PluginAICapability, PluginAICapabilityClient, PluginAICapabilityRequest, PluginAIImage, PluginAIMessage, } from "./ai";
57
57
  export { PLUGIN_AI_CAPABILITIES, isPluginAICapability } from "./ai";
58
+ export * from "./asr";
59
+ export type * from "./websocket";
@@ -1,4 +1,4 @@
1
- export declare const PLUGIN_PERMISSIONS: readonly ["cards:read", "cards:write", "cards:delete", "articles:read", "articles:write", "articles:delete", "documents:read", "documents:write", "documents:delete", "whiteboards:read", "whiteboards:write", "whiteboards:delete", "projects:read", "projects:write", "projects:delete", "todos:read", "todos:write", "todos:delete", "calendar:read", "calendar:write", "calendar:delete", "notebooks:read", "materials:read", "chats:read", "flashcards:read", "flashcards:write", ...("ai:chat" | "ai:titleSummary" | "ai:webClip" | "ai:podcastGeneration" | "ai:flashcardGeneration" | "ai:aiJudgement" | "ai:transcriptionOptimization" | "ai:videoSummary" | "ai:videoEbookRewrite" | "ai:vibeLearningImageDescription" | "ai:contentMetadata" | "ai:contentInsights")[]];
1
+ export declare const PLUGIN_PERMISSIONS: readonly ["cards:read", "cards:write", "cards:delete", "articles:read", "articles:write", "articles:delete", "documents:read", "documents:write", "documents:delete", "whiteboards:read", "whiteboards:write", "whiteboards:delete", "projects:read", "projects:write", "projects:delete", "todos:read", "todos:write", "todos:delete", "calendar:read", "calendar:write", "calendar:delete", "notebooks:read", "materials:read", "chats:read", "flashcards:read", "flashcards:write", ...("ai:chat" | "ai:titleSummary" | "ai:webClip" | "ai:podcastGeneration" | "ai:flashcardGeneration" | "ai:aiJudgement" | "ai:transcriptionOptimization" | "ai:speechInputRefinement" | "ai:videoSummary" | "ai:videoEbookRewrite" | "ai:vibeLearningImageDescription" | "ai:contentMetadata" | "ai:contentInsights")[]];
2
2
  export type PluginPermission = (typeof PLUGIN_PERMISSIONS)[number];
3
3
  export declare const isPluginPermission: (value: unknown) => value is PluginPermission;
4
4
  /** granted:可直接调用;prompt:调用时会询问用户;denied:本次运行已拒绝或已被阻止 */
@@ -13,6 +13,11 @@ export interface PluginSettingsProps {
13
13
  readonly modelId: string;
14
14
  save(value: JsonValue, modelId: string): Promise<void>;
15
15
  };
16
+ readonly asrConfig?: {
17
+ readonly value: JsonValue;
18
+ readonly modelId: string;
19
+ save(value: JsonValue, modelId: string): Promise<void>;
20
+ };
16
21
  readonly ttsConfig?: {
17
22
  readonly instanceId: string;
18
23
  readonly value: JsonValue;
@@ -43,7 +48,7 @@ export interface PluginSettingsDefinition {
43
48
  title: string;
44
49
  description?: string;
45
50
  /** 提供方配置表单挂载到对应宿主设置;普通插件设置省略。 */
46
- target?: "sync" | "upload" | "tts" | "images" | "video" | "publish";
51
+ target?: "sync" | "upload" | "tts" | "asr" | "images" | "video" | "publish";
47
52
  component: ComponentType<PluginSettingsProps>;
48
53
  }
49
54
  export interface PluginSettingsHandle extends Disposable {
@@ -0,0 +1,9 @@
1
+ /** 由宿主创建、符合浏览器 WebSocket 事件和方法契约的连接。 */
2
+ export type PluginSocket = WebSocket;
3
+ export interface PluginSocketOptions {
4
+ headers?: Readonly<Record<string, string>>;
5
+ signal?: AbortSignal;
6
+ }
7
+ export interface PluginWebSocket {
8
+ connect(url: string, protocols?: string | string[], options?: PluginSocketOptions): PluginSocket;
9
+ }