@marktrue/dsh-mobile-remote 3.3.1-alpha.4 → 3.3.1-alpha.5

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/lib/index.js +110 -14
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## v3.3.1-alpha.5(build 68,issues #178/#179)— 市场搜索修复与输入键盘修复
4
+
5
+ > 插件 `3.3.1-alpha.5` / App `3.3.1+68` / 载体 `3.3.1-alpha.5-app`。
6
+
7
+ ### 修复
8
+
9
+ - **#178 插件市场搜索失败(核心 bug)**:真实根因是**上一版漏传宿主 `MarketQuery` 的必填字段 `sort`**,不是索引抓取超时。宿主 `MarketSearch.order()` 读 `sort.kind` 时抛 `TypeError`(该错误没有 `code`),落进错误映射的兜底分支并对外表现为 `503 plugin-market-unavailable`。现已补 `sort`:无搜索词按索引顺序(`index`)、有搜索词按相关度(`relevance`)。在**源码树**上用真实索引实测恢复为 `HTTP 200`、`total=16256`(**非已部署宿主**:运行中的 instance 需部署并重启后才生效)。
10
+ - **顺带修掉同源缺陷**:真实索引的 `title` / `description` 是 `LocalizedText`(`string` 或按语言的对象),上一版按纯字符串投影导致**所有标题/描述被吞成空串**。现按语言(`?lang=zh|en`,默认 zh→en→任一)正确投影。
11
+ - **超时错误映射补全**:新增稳定错误码 `index-fetch-timeout`(HTTP 504),与 `index-fetch-failed`(502)区分;识别 `TimeoutError` / `AbortError` / `ETIMEDOUT` / `UND_ERR_CONNECT_TIMEOUT` / 明确的超时措辞及 `cause` 链,**无 code 的超时不再落 503 兜底**。无超时特征的未知错误仍为 503,不冒充超时。
12
+ - **可诊断性**:`GET/POST market/indexes` 新增只读 `fetchTimeoutMs`,索引管理页显示「电脑端当前抓取超时:Ns(只读,需在电脑端调整)」,便于判断是否与超时有关。
13
+
14
+ - **#179 手动安装输入栏弹出安全键盘**:`spec-input` 原来设了 `enableSuggestions: false`,Flutter Android 引擎在该参数为假时会加 `TYPE_TEXT_VARIATION_VISIBLE_PASSWORD`,使普通输入框弹出「安全键盘 / 密码键盘」。现改为显式 `keyboardType: TextInputType.text` 并移除该参数。同页的 registry 输入框与市场搜索框均未设该参数(源码可核)。输入内容(包名 / Git 地址 / 路径 / tarball)与功能不受影响。
15
+
16
+ ### 已知限制 / 未验证
17
+
18
+ - #178 的真实链路**仅在源码树上**用真实索引验证过(`HTTP 200`,`total=16256`),**未在已部署宿主上验证**;运行中的宿主需部署并重启后才会生效。
19
+ - **#179 未做真机验证**:widget 测试只能证明控件属性不再触发 `VISIBLE_PASSWORD`,实际弹出哪种键盘取决于设备输入法,需用户升级后确认。
20
+
21
+
3
22
  ## v3.3.1-alpha.4(build 67,issues #164/#173/#174/#175/#176/#177)— 插件安装能力扩张与提问卡修复
4
23
 
5
24
  > 插件 `3.3.1-alpha.4` / App `3.3.1+67` / 载体 `3.3.1-alpha.4-app`。
package/lib/index.js CHANGED
@@ -4907,6 +4907,21 @@ export function apply(ctx, config, runtime = {}) {
4907
4907
  *
4908
4908
  * 只做能力探测,不尝试写。
4909
4909
  */
4910
+ /**
4911
+ * #178:读宿主当前生效的 `fetchTimeoutMs`(只读展示,供 App 提示「经常超时可调大」)。
4912
+ *
4913
+ * 取不到就返回 `null`——不猜默认值,也不影响端点其余部分。
4914
+ * **不提供写入口**(改配置是电脑端的事,见 docs/04-security.md)。
4915
+ */
4916
+ function marketFetchTimeoutMs(market) {
4917
+ try {
4918
+ const value = market?.config?.fetchTimeoutMs;
4919
+ return Number.isFinite(value) && value > 0 ? value : null;
4920
+ } catch {
4921
+ return null;
4922
+ }
4923
+ }
4924
+
4910
4925
  function marketIndexesWritable(market) {
4911
4926
  if (!market || typeof market.setIndexes !== "function") return false;
4912
4927
  try {
@@ -4919,8 +4934,50 @@ export function apply(ctx, config, runtime = {}) {
4919
4934
  }
4920
4935
 
4921
4936
  /** 宿主 `plugin-market/*` 的 RemoteError code → 稳定 HTTP + 码。 */
4937
+ /**
4938
+ * 判断一个错误是否为**超时**类(#178)。
4939
+ *
4940
+ * 真实链路已有稳定 code(`plugin-market/fetch-failed` + `details.reason` 含
4941
+ * "aborted due to timeout"),但插件侧仍要能兜住**没有 code** 的超时形态:
4942
+ * 底层 `AbortSignal.timeout` 抛的是 `DOMException`/`TimeoutError`,一层包装后
4943
+ * `code` 就可能丢失(已用探针实测:无 code 的错误全部落到 503 default)。
4944
+ *
4945
+ * 只按**已知特征**判定,不做模糊猜测:
4946
+ * - `name === "TimeoutError"` / `"AbortError"`;
4947
+ * - `code` 为 Node 的 `ETIMEDOUT` / `UND_ERR_CONNECT_TIMEOUT`;
4948
+ * - message 或 cause 链里出现明确超时措辞。
4949
+ */
4950
+ function isTimeoutError(error, depth = 0) {
4951
+ if (error === null || typeof error !== "object" || depth > 4) return false;
4952
+ if (error.name === "TimeoutError") return true;
4953
+ const code = typeof error.code === "string" ? error.code : "";
4954
+ if (code === "ETIMEDOUT" || code === "UND_ERR_CONNECT_TIMEOUT" || code === "ABORT_ERR") return true;
4955
+ const message = typeof error.message === "string" ? error.message : "";
4956
+ if (/timed? out|timeout|aborted due to timeout/i.test(message)) return true;
4957
+ // `AbortError` 单独判在 message 之后:普通取消也会是 AbortError,
4958
+ // 但本端点没有「用户主动取消」路径(search 不可取消),所以这里算超时。
4959
+ if (error.name === "AbortError") return true;
4960
+ return error.cause === undefined ? false : isTimeoutError(error.cause, depth + 1);
4961
+ }
4962
+
4922
4963
  function marketErrorResponse(error) {
4923
4964
  const code = typeof error?.code === "string" ? error.code : "";
4965
+ // #178:`fetch-failed` 既可能是 HTTP 失败也可能是抓取超时。两者对用户的意义不同
4966
+ // (前者「索引坏了/404」,后者「网络慢,稍后重试」),因此按 details.reason /
4967
+ // cause 链区分成两个稳定码。
4968
+ if (code === "plugin-market/fetch-failed") {
4969
+ const reason = typeof error?.details?.reason === "string" ? error.details.reason : "";
4970
+ const timedOut = /timeout/i.test(reason) || isTimeoutError(error.cause) || isTimeoutError(error);
4971
+ return timedOut
4972
+ ? { status: 504, error: "index-fetch-timeout" }
4973
+ : { status: 502, error: "index-fetch-failed" };
4974
+ }
4975
+ // #178:拿不到宿主稳定 code 时,若特征明确是超时 → 504,不落 503 default。
4976
+ // 覆盖 `code` 为空**以及**`code` 是 Node 级错误码(`ETIMEDOUT` 等)两种形态:
4977
+ // 后者不是 `plugin-market/*` 命名空间,同样进不了下面的 switch。
4978
+ if (!code.startsWith("plugin-market/") && isTimeoutError(error)) {
4979
+ return { status: 504, error: "index-fetch-timeout" };
4980
+ }
4924
4981
  switch (code) {
4925
4982
  case "plugin-market/invalid-index-url":
4926
4983
  return { status: 400, error: "index-invalid" };
@@ -4933,8 +4990,6 @@ export function apply(ctx, config, runtime = {}) {
4933
4990
  return { status: 404, error: "unknown-plugin" };
4934
4991
  case "plugin-market/settings-unavailable":
4935
4992
  return { status: 409, error: "settings-write-unavailable" };
4936
- case "plugin-market/fetch-failed":
4937
- return { status: 502, error: "index-fetch-failed" };
4938
4993
  case "plugin-market/invalid-index":
4939
4994
  return { status: 502, error: "index-invalid-document" };
4940
4995
  default:
@@ -4949,11 +5004,11 @@ export function apply(ctx, config, runtime = {}) {
4949
5004
  * 配了什么才能删改;这与「不回显用户刚输入的待校验 spec」不同。
4950
5005
  * `error` 只透出宿主给的类别串,不额外拼接。
4951
5006
  */
4952
- function publicMarketIndex(row) {
5007
+ function publicMarketIndex(row, language) {
4953
5008
  return {
4954
5009
  url: typeof row?.url === "string" ? row.url : "",
4955
- title: typeof row?.title === "string" ? row.title : "",
4956
- description: typeof row?.description === "string" ? row.description : "",
5010
+ title: localizedText(row?.title, language),
5011
+ description: localizedText(row?.description, language),
4957
5012
  error: typeof row?.error === "string" ? row.error.slice(0, 300) : "",
4958
5013
  };
4959
5014
  }
@@ -4965,12 +5020,37 @@ export function apply(ctx, config, runtime = {}) {
4965
5020
  * `install.spec` 对 git 源是 `git+https://...`(安全),对 npm 是 `name@version`
4966
5021
  * (安全)。但仍逐字段白名单构造,避免宿主未来新增字段把本地路径/凭据带出来。
4967
5022
  */
4968
- function publicMarketEntry(entry) {
5023
+ /**
5024
+ * #178:`LocalizedText` → 展示字符串。
5025
+ *
5026
+ * 宿主市场文档里的 `title`/`description`/`category`/`labels` 是 **`LocalizedText`**
5027
+ * (`string | { [lang]: string }`,见 `dsh-package-manifest`),不是纯字符串。
5028
+ * 上一版按 `typeof === "string"` 投影,导致**所有本地化字段被吞成空串**
5029
+ * (真实索引上 title/description/category 全为空)。
5030
+ *
5031
+ * 优先级:显式传入的语言 → `zh` → `en` → 任一可用值。**不做截断拼接**,
5032
+ * 只取一条,避免把多语言混进同一字段。
5033
+ */
5034
+ function localizedText(value, language) {
5035
+ if (typeof value === "string") return value.trim();
5036
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return "";
5037
+ const preferred = typeof language === "string" && language !== "" ? value[language] : undefined;
5038
+ for (const candidate of [preferred, value.zh, value.en]) {
5039
+ if (typeof candidate === "string" && candidate.trim() !== "") return candidate.trim();
5040
+ }
5041
+ for (const candidate of Object.values(value)) {
5042
+ if (typeof candidate === "string" && candidate.trim() !== "") return candidate.trim();
5043
+ }
5044
+ return "";
5045
+ }
5046
+
5047
+ function publicMarketEntry(entry, language) {
4969
5048
  const versions = Array.isArray(entry?.versions) ? entry.versions : [];
4970
5049
  return {
4971
5050
  name: typeof entry?.name === "string" ? entry.name : "",
4972
- title: typeof entry?.title === "string" ? entry.title : "",
4973
- description: typeof entry?.description === "string" ? entry.description : "",
5051
+ title: localizedText(entry?.title, language),
5052
+ description: localizedText(entry?.description, language),
5053
+ // `category` 是**分类 id**(字符串),不是本地化文本;保留原样。
4974
5054
  category: typeof entry?.category === "string" ? entry.category : "",
4975
5055
  labels: (Array.isArray(entry?.labels) ? entry.labels : [])
4976
5056
  .map((value) => (typeof value === "string" ? value : ""))
@@ -9785,6 +9865,10 @@ export function apply(ctx, config, runtime = {}) {
9785
9865
  // 索引是**电脑端配置**;写操作与新端点都需移动端口令(同所有 /plugin-inventory/*)。
9786
9866
  // `search` 的 url 必须是**已配置**索引之一,否则等于开了任意 URL 抓取。
9787
9867
  // 显式三方法分派(GET/HEAD 读、POST 写);端点登记门禁从分派头部抽方法。
9868
+ // #178:`lang` 只影响本地化字段的展示选择(`title`/`description`),
9869
+ // 不是判据、不写任何配置;未知值按默认(zh→en)处理,不报错。
9870
+ const rawLang = url.searchParams.get("lang");
9871
+ const marketLanguage = rawLang === "en" || rawLang === "zh" ? rawLang : "";
9788
9872
  if (rest === "/plugin-inventory/market/indexes") {
9789
9873
  if (method !== "GET" && method !== "HEAD" && method !== "POST") return error(res, 405, "method-not-allowed");
9790
9874
  const market = pluginMarketService();
@@ -9803,7 +9887,7 @@ export function apply(ctx, config, runtime = {}) {
9803
9887
  if (method === "HEAD") { res.writeHead(200, { "cache-control": "no-store" }); res.end(); return; }
9804
9888
  return sendJson(res, 200, { ok: true, supported: false, writable: false, reason: "plugin-market-unavailable", indexes: [], defaults: { count: 0 } });
9805
9889
  }
9806
- const indexes = (Array.isArray(rows) ? rows : []).map(publicMarketIndex);
9890
+ const indexes = (Array.isArray(rows) ? rows : []).map((row) => publicMarketIndex(row, marketLanguage));
9807
9891
  if (method === "HEAD") { res.writeHead(200, { "cache-control": "no-store" }); res.end(); return; }
9808
9892
  // `defaults.count` = 宿主配置里**可用**(无 error)的索引数,供 App 说明基线。
9809
9893
  return sendJson(res, 200, {
@@ -9813,6 +9897,8 @@ export function apply(ctx, config, runtime = {}) {
9813
9897
  reason: writable ? "" : "settings-write-unavailable",
9814
9898
  indexes,
9815
9899
  defaults: { count: indexes.filter((row) => row.error === "").length },
9900
+ // #178:只读展示。App 据此提示「经常超时可调大」,但**不能**改(无写入口)。
9901
+ fetchTimeoutMs: marketFetchTimeoutMs(market),
9816
9902
  });
9817
9903
  }
9818
9904
  if (!supported) return error(res, 409, "plugin-market-unavailable");
@@ -9842,7 +9928,7 @@ export function apply(ctx, config, runtime = {}) {
9842
9928
  let after = [];
9843
9929
  try {
9844
9930
  const rows = await market.listIndexes();
9845
- after = (Array.isArray(rows) ? rows : []).map(publicMarketIndex);
9931
+ after = (Array.isArray(rows) ? rows : []).map((row) => publicMarketIndex(row, marketLanguage));
9846
9932
  } catch {
9847
9933
  // 回读失败不影响写入结果;给空列表让 App 自行重试。
9848
9934
  after = [];
@@ -9853,6 +9939,7 @@ export function apply(ctx, config, runtime = {}) {
9853
9939
  writable: true,
9854
9940
  indexes: after,
9855
9941
  defaults: { count: after.filter((row) => row.error === "").length },
9942
+ fetchTimeoutMs: marketFetchTimeoutMs(market),
9856
9943
  });
9857
9944
  }
9858
9945
  // SSRF 边界:search 的 `url` 必须是**已配置索引**之一。
@@ -9870,7 +9957,7 @@ export function apply(ctx, config, runtime = {}) {
9870
9957
  let configured;
9871
9958
  try {
9872
9959
  const rows = await market.listIndexes();
9873
- configured = (Array.isArray(rows) ? rows : []).map(publicMarketIndex);
9960
+ configured = (Array.isArray(rows) ? rows : []).map((row) => publicMarketIndex(row, marketLanguage));
9874
9961
  } catch {
9875
9962
  return error(res, 503, "plugin-market-unavailable");
9876
9963
  }
@@ -9898,9 +9985,18 @@ export function apply(ctx, config, runtime = {}) {
9898
9985
  return error(res, 400, "invalid-query", "limit");
9899
9986
  }
9900
9987
  }
9901
- const query = { offset, limit };
9988
+ // **`sort` 是宿主 `MarketQuery` 的必填字段**(`readonly sort: MarketSort`,无 `?`)。
9989
+ // 上一版漏传 → 宿主 `MarketSearch.order()` 读 `sort.kind` 抛
9990
+ // `TypeError: Cannot read properties of undefined (reading 'kind')`,
9991
+ // 该错误没有 `code` → 落到 503 default,用户看到「市场搜索失败」。
9992
+ // 有 text 时按相关度排序(最符合搜索预期),无 text 时按索引顺序。
9993
+ const query = { offset, limit, sort: { kind: "index" } };
9902
9994
  const text = url.searchParams.get("text");
9903
- if (text !== null && text.trim() !== "") query.text = text.trim().slice(0, 200);
9995
+ if (text !== null && text.trim() !== "") {
9996
+ query.text = text.trim().slice(0, 200);
9997
+ // 有搜索词:相关度优先(与桌面端一致);无搜索词:索引顺序。
9998
+ query.sort = { kind: "relevance" };
9999
+ }
9904
10000
  const category = url.searchParams.get("category");
9905
10001
  if (category !== null && category.trim() !== "") query.category = category.trim().slice(0, 100);
9906
10002
  const rawRefresh = url.searchParams.get("refresh");
@@ -9912,7 +10008,7 @@ export function apply(ctx, config, runtime = {}) {
9912
10008
  const mapped = marketErrorResponse(e);
9913
10009
  return error(res, mapped.status, mapped.error);
9914
10010
  }
9915
- const entries = (Array.isArray(result?.entries) ? result.entries : []).map(publicMarketEntry);
10011
+ const entries = (Array.isArray(result?.entries) ? result.entries : []).map((entry) => publicMarketEntry(entry, marketLanguage));
9916
10012
  return sendJson(res, 200, {
9917
10013
  ok: true,
9918
10014
  supported: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marktrue/dsh-mobile-remote",
3
- "version": "3.3.1-alpha.4",
3
+ "version": "3.3.1-alpha.5",
4
4
  "description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(当前 Android 端,iOS 未开发)",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -52,7 +52,7 @@
52
52
  "qrcode"
53
53
  ],
54
54
  "optionalDependencies": {
55
- "@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.3.1-alpha.4-app"
55
+ "@marktrue/dsh-mobile-remote-app": "npm:@marktrue/dsh-mobile-remote@3.3.1-alpha.5-app"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <=0.2.3 || >=0.2.0-0 <0.2.0 || >=0.2.1-0 <0.2.1 || >=0.2.2-0 <0.2.2 || >=0.2.3-0 <0.2.3",