@xiaoqiong0v0/opencode-browser-tool 1.11.1 → 1.12.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.
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `type`(向当前焦点插入文本,不清空)的纯逻辑:文本校验、`@file:` 解析、输出格式化。
3
+ *
4
+ * 文件读取与 containment 由调用方注入(`index.ts` 复用 `evaluate` 的 `readEvalFile`),
5
+ * 这里不含任何 IO,便于 `tests/unit/type-text.test.mjs` 直接调用 dist 产物。
6
+ * 上限与 Rust 侧 `keyboard.rs` 的 `TYPE_TEXT_MAX_BYTES` 同口径(8 KiB,按字节计)。
7
+ */
8
+ import { tf } from "../i18n/index.js";
9
+ /** 单次插入文本上限(字节;0 长度之外的入参超过即拒绝) */
10
+ export const TYPE_TEXT_MAX_BYTES = 8 * 1024;
11
+ /** `--text` 的文件引用前缀(与 `evaluate` 的 `@file:` 同形) */
12
+ export const TYPE_FILE_PREFIX = "@file:";
13
+ /**
14
+ * 校验待插入文本。
15
+ *
16
+ * @param text 实际要插入的文本(`@file:` 已解析后的内容)
17
+ * @returns `required`=空文本;`too_large`=超过 8 KiB;`null`=通过
18
+ */
19
+ export function typeTextIssue(text) {
20
+ if (text.length === 0)
21
+ return "required";
22
+ if (Buffer.byteLength(text, "utf-8") > TYPE_TEXT_MAX_BYTES)
23
+ return "too_large";
24
+ return null;
25
+ }
26
+ /**
27
+ * 解析 `--text`:`@file:<path>` 交给注入的读取器(与 `evaluate` 同一套 containment),
28
+ * 其余一律视为内联文本。
29
+ *
30
+ * @param raw 模型传入的原始 `--text` 值
31
+ * @param readFile 文件读取器(越界 / 超限 / 读失败都返回 `{error}`,由调用方复用 `readEvalFile`)
32
+ * @returns 插入文本,或可直接回模型的错误文案
33
+ */
34
+ export function resolveTypeText(raw, readFile) {
35
+ if (!raw.startsWith(TYPE_FILE_PREFIX))
36
+ return { text: raw };
37
+ const path = raw.slice(TYPE_FILE_PREFIX.length).trim();
38
+ if (!path)
39
+ return { error: tf("cli.err.type_text_required") };
40
+ const read = readFile(path);
41
+ if ("error" in read)
42
+ return { error: read.error };
43
+ return { text: read.content };
44
+ }
45
+ /**
46
+ * 渲染 `type` 的成功输出。
47
+ *
48
+ * @param inserted 服务端回报的插入字符数
49
+ * @param selector 本次显式聚焦的选择器(空串表示沿用当前焦点)
50
+ * @param entered 是否补发了 Enter
51
+ * @returns `typed N char(s) into <selector|focused element>[ + Enter]`
52
+ */
53
+ export function formatTypeOutput(inserted, selector, entered) {
54
+ const target = selector || tf("cli.out.type.focused");
55
+ const suffix = entered ? tf("cli.out.type.enter") : "";
56
+ return tf("cli.out.type", { n: inserted, target }) + suffix;
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiaoqiong0v0/opencode-browser-tool",
3
- "version": "1.11.1",
3
+ "version": "1.12.0",
4
4
  "description": "opencode 浏览器工具插件:WebView2 外壳渲染 + 零注入视觉元素选取面板",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {