@dsh-mobile/mobile-remote 3.2.6 → 3.3.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/FAQ.md +19 -12
- package/README.md +39 -40
- package/cordis.patch.yml +8 -4
- package/docs/PRIVACY-POLICY.en.md +88 -61
- package/docs/PRIVACY-POLICY.md +88 -61
- package/docs/SUPPORT.md +5 -5
- package/docs/TERMS-OF-SERVICE.en.md +1 -1
- package/docs/TERMS-OF-SERVICE.md +1 -1
- package/docs/USER-GUIDE.zh-CN.md +562 -0
- package/lib/account-usage-query.js +117 -4
- package/lib/assistant-prefs.js +147 -0
- package/lib/auto-config.js +55 -3
- package/lib/backup.js +405 -0
- package/lib/break-reminder.js +133 -0
- package/lib/client.js +57 -11
- package/lib/config.js +94 -5
- package/lib/git-read-bundled-provider.js +12 -3
- package/lib/git-read-service.js +4 -0
- package/lib/host-compat.js +25 -0
- package/lib/http-util.js +6 -2
- package/lib/index.js +987 -74
- package/lib/memory/context.js +76 -0
- package/lib/memory/decay.js +144 -0
- package/lib/memory/extract.js +146 -0
- package/lib/memory/routes.js +198 -0
- package/lib/memory/store.js +667 -0
- package/lib/notify-copy.js +245 -0
- package/lib/permission-guide.js +184 -0
- package/lib/persona-cards.js +362 -0
- package/lib/proactive-material.js +162 -0
- package/lib/proactive.js +369 -0
- package/lib/protected-paths.js +130 -0
- package/lib/protocol.js +35 -0
- package/lib/rate-limit.js +1 -1
- package/lib/relay/connector.js +97 -12
- package/lib/relay/devices.js +14 -0
- package/lib/relay/fingerprint.js +55 -0
- package/lib/relay/identity.js +69 -0
- package/lib/relay/on-demand.js +84 -0
- package/lib/relay/phone.js +87 -12
- package/lib/reminders.js +140 -0
- package/lib/rpc-adapter.js +21 -2
- package/lib/session-rotation.js +198 -0
- package/lib/timeline.js +1 -1
- package/package.json +31 -14
- package/CHANGELOG.md +0 -1336
- package/CONTRIBUTING.md +0 -61
- package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +0 -432
- package/docs/01-PRD.md +0 -148
- package/docs/02-architecture.md +0 -249
- package/docs/03-api.md +0 -882
- package/docs/04-security.md +0 -110
- package/docs/05-test-cases.md +0 -376
- package/docs/06-install-run.md +0 -349
- package/docs/07-user-manual.md +0 -92
- package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +0 -86
- package/docs/09-compatibility.md +0 -201
- package/docs/11-remote-relay-guide.md +0 -85
- package/docs/APP-ENCRYPTION-DESCRIPTION.md +0 -50
- package/docs/APP-ENCRYPTION-DESCRIPTION.pdf +0 -0
- package/docs/APP-REVIEW-NOTES.md +0 -135
- package/docs/BRAND-ASSETS.md +0 -142
- package/docs/STORE-LAUNCH.md +0 -305
- package/docs/STORE-LISTING.md +0 -150
package/lib/reminders.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reminders the user sets (T-32): the "promises and reminders coming due" material of the
|
|
3
|
+
* proactive scheduler (plan §5.7). A small JSON file on this PC, `<state dir>/reminders.json`.
|
|
4
|
+
*
|
|
5
|
+
* Routes (under /m/api):
|
|
6
|
+
* GET /reminders list, soonest first (done ones last)
|
|
7
|
+
* POST /reminders add { text, dueAt (ms), sessionId? }
|
|
8
|
+
* PATCH /reminders/:id { done: true | false }
|
|
9
|
+
* DELETE /reminders/:id delete (for real: the file is rewritten without it)
|
|
10
|
+
*/
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { readBody, sendError, sendJson } from "./http-util.js";
|
|
15
|
+
|
|
16
|
+
export const MAX_REMINDER_TEXT = 500;
|
|
17
|
+
export const MAX_REMINDERS = 500;
|
|
18
|
+
const YEAR_MS = 366 * 24 * 60 * 60_000;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @param {{dir: string, now?: () => number}} e
|
|
22
|
+
*/
|
|
23
|
+
export function createReminderStore({ dir, now = () => Date.now() }) {
|
|
24
|
+
const file = join(dir, "reminders.json");
|
|
25
|
+
let cache = null;
|
|
26
|
+
|
|
27
|
+
const load = () => {
|
|
28
|
+
if (cache) return cache;
|
|
29
|
+
try {
|
|
30
|
+
const raw = JSON.parse(readFileSync(file, "utf8"));
|
|
31
|
+
cache = Array.isArray(raw?.items)
|
|
32
|
+
? raw.items.filter((r) => r && typeof r.id === "string" && typeof r.text === "string" && Number.isFinite(r.dueAt))
|
|
33
|
+
: [];
|
|
34
|
+
} catch {
|
|
35
|
+
cache = [];
|
|
36
|
+
}
|
|
37
|
+
return cache;
|
|
38
|
+
};
|
|
39
|
+
const save = (items) => {
|
|
40
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
41
|
+
const tmp = `${file}.tmp`;
|
|
42
|
+
writeFileSync(tmp, JSON.stringify({ items }, null, 2), { mode: 0o600 });
|
|
43
|
+
renameSync(tmp, file);
|
|
44
|
+
cache = items;
|
|
45
|
+
};
|
|
46
|
+
const sorted = (items) =>
|
|
47
|
+
[...items].sort((a, b) => (a.doneAt ? 1 : 0) - (b.doneAt ? 1 : 0) || a.dueAt - b.dueAt);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
file,
|
|
51
|
+
list: () => sorted(load()).map((r) => ({ ...r })),
|
|
52
|
+
get: (id) => load().find((r) => r.id === id) ?? null,
|
|
53
|
+
/** Throws with `code: "bad-reminder"` on invalid input. */
|
|
54
|
+
add({ text, dueAt, sessionId }) {
|
|
55
|
+
const clean = typeof text === "string" ? text.replace(/\s+/g, " ").trim() : "";
|
|
56
|
+
const bad = (detail) => Object.assign(new Error(detail), { code: "bad-reminder" });
|
|
57
|
+
if (clean === "") throw bad("text 不能为空 / text is required");
|
|
58
|
+
if (clean.length > MAX_REMINDER_TEXT) throw bad(`text 超过 ${MAX_REMINDER_TEXT} 字符 / text is too long`);
|
|
59
|
+
if (!Number.isFinite(dueAt) || Math.abs(dueAt - now()) > YEAR_MS) throw bad("dueAt 必须是一年以内的毫秒时间戳 / dueAt must be a timestamp within a year");
|
|
60
|
+
if (sessionId !== undefined && sessionId !== null && typeof sessionId !== "string") throw bad("sessionId 必须是字符串 / sessionId must be a string");
|
|
61
|
+
const items = load();
|
|
62
|
+
if (items.length >= MAX_REMINDERS) throw bad(`最多 ${MAX_REMINDERS} 条提醒 / at most ${MAX_REMINDERS} reminders`);
|
|
63
|
+
const item = { id: randomUUID(), text: clean, dueAt, ...(sessionId ? { sessionId } : {}), createdAt: now() };
|
|
64
|
+
save([...items, item]);
|
|
65
|
+
return { ...item };
|
|
66
|
+
},
|
|
67
|
+
setDone(id, done) {
|
|
68
|
+
const items = load();
|
|
69
|
+
const at = items.findIndex((r) => r.id === id);
|
|
70
|
+
if (at === -1) return null;
|
|
71
|
+
const next = { ...items[at] };
|
|
72
|
+
if (done) next.doneAt = now();
|
|
73
|
+
else delete next.doneAt;
|
|
74
|
+
save(items.map((r, i) => (i === at ? next : r)));
|
|
75
|
+
return { ...next };
|
|
76
|
+
},
|
|
77
|
+
remove(id) {
|
|
78
|
+
const items = load();
|
|
79
|
+
if (!items.some((r) => r.id === id)) return false;
|
|
80
|
+
save(items.filter((r) => r.id !== id));
|
|
81
|
+
return true;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** HTTP routes for a reminder store. Returns true when it answered the request. */
|
|
87
|
+
export function createReminderRoutes({ store }) {
|
|
88
|
+
return async function handleReminders(req, res, rest, method) {
|
|
89
|
+
if (rest === "/reminders") {
|
|
90
|
+
if (method === "GET" || method === "HEAD") {
|
|
91
|
+
sendJson(res, 200, { ok: true, items: store().list() });
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
if (method === "POST") {
|
|
95
|
+
let body;
|
|
96
|
+
try {
|
|
97
|
+
body = JSON.parse(await readBody(req));
|
|
98
|
+
} catch {
|
|
99
|
+
sendError(res, 400, "bad-request", "请求体不是合法 JSON");
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
try {
|
|
103
|
+
sendJson(res, 200, { ok: true, item: store().add(body ?? {}) });
|
|
104
|
+
} catch (err) {
|
|
105
|
+
sendError(res, 400, err?.code ?? "bad-reminder", err?.message ?? "invalid reminder");
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
sendError(res, 405, "method-not-allowed");
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
const m = /^\/reminders\/([A-Za-z0-9-]{1,64})$/.exec(rest);
|
|
113
|
+
if (!m) return false;
|
|
114
|
+
const id = m[1];
|
|
115
|
+
if (method === "DELETE") {
|
|
116
|
+
if (!store().remove(id)) sendError(res, 404, "reminder-not-found");
|
|
117
|
+
else sendJson(res, 200, { ok: true });
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
if (method === "PATCH") {
|
|
121
|
+
let body;
|
|
122
|
+
try {
|
|
123
|
+
body = JSON.parse(await readBody(req));
|
|
124
|
+
} catch {
|
|
125
|
+
sendError(res, 400, "bad-request", "请求体不是合法 JSON");
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
if (typeof body?.done !== "boolean") {
|
|
129
|
+
sendError(res, 400, "bad-request", "done 必须是 true / false");
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
const item = store().setDone(id, body.done);
|
|
133
|
+
if (!item) sendError(res, 404, "reminder-not-found");
|
|
134
|
+
else sendJson(res, 200, { ok: true, item });
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
sendError(res, 405, "method-not-allowed");
|
|
138
|
+
return true;
|
|
139
|
+
};
|
|
140
|
+
}
|
package/lib/rpc-adapter.js
CHANGED
|
@@ -21,12 +21,18 @@ import { redactPathText } from "./api-helpers.js";
|
|
|
21
21
|
// subagents/list(parentSessionId)、subagents/interruptByParent(childSessionId,parentSessionId,mode)、
|
|
22
22
|
// goals/create(agentId,request{objective,maxGoalRounds?})、goals/{pause,resume,complete}(agentId,ref{id,revision})。
|
|
23
23
|
// mode 在内核里是 z.literal("continuable"),故缺省即该唯一合法值。
|
|
24
|
+
// T-02: DSH 0.2.1-rc.2 replaced interruptByParent(childSessionId, parentSessionId, mode) with
|
|
25
|
+
// interruptByUser(childSessionId) (upgrade guide v0.2.1-rc.2/subagent-user-controls); hosts from
|
|
26
|
+
// 0.2.2-rc.2 on have only the new one. "subagent.interrupt" now names the new endpoint and
|
|
27
|
+
// "subagent.interruptByParent" the old one, which /subagents/interrupt tries only when the host
|
|
28
|
+
// reports the new endpoint as missing (isEndpointUnavailable).
|
|
24
29
|
const goalRefArgs = (p) => ({ agentId: p.sessionId, ref: p.ref });
|
|
25
30
|
export const RPC_ENDPOINT_RENAMES = {
|
|
26
31
|
"session.models": "session/modelCatalog",
|
|
27
32
|
"session.history": "session/control",
|
|
28
33
|
"subagent.list": "subagents/list",
|
|
29
|
-
"subagent.interrupt": "subagents/
|
|
34
|
+
"subagent.interrupt": "subagents/interruptByUser",
|
|
35
|
+
"subagent.interruptByParent": "subagents/interruptByParent",
|
|
30
36
|
"goal.create": "goals/create",
|
|
31
37
|
"goal.pause": "goals/pause",
|
|
32
38
|
"goal.resume": "goals/resume",
|
|
@@ -45,12 +51,25 @@ export const RPC_PAYLOAD_ADAPTER = {
|
|
|
45
51
|
"workspace.archiveSession": (p) => ({ request: p }),
|
|
46
52
|
"settings.update": (p) => ({ ns: p.ns, patch: p.patch, ...(p.expectedRevision === undefined ? {} : { expectedRevision: p.expectedRevision }) }),
|
|
47
53
|
"subagent.list": (p) => ({ parentSessionId: p.parentSessionId }),
|
|
48
|
-
"subagent.interrupt": (p) => ({ childSessionId: p.childSessionId
|
|
54
|
+
"subagent.interrupt": (p) => ({ childSessionId: p.childSessionId }),
|
|
55
|
+
"subagent.interruptByParent": (p) => ({ childSessionId: p.childSessionId, parentSessionId: p.parentSessionId, mode: p.mode ?? "continuable" }),
|
|
49
56
|
"goal.create": (p) => ({ agentId: p.sessionId, request: { objective: p.objective, ...(p.maxGoalRounds === undefined ? {} : { maxGoalRounds: p.maxGoalRounds }) } }),
|
|
50
57
|
"goal.pause": goalRefArgs,
|
|
51
58
|
"goal.resume": goalRefArgs,
|
|
52
59
|
"goal.complete": goalRefArgs,
|
|
53
60
|
};
|
|
61
|
+
/**
|
|
62
|
+
* Gateway error codes that mean "this host has no such endpoint" (as opposed to a failed call):
|
|
63
|
+
* an unknown endpoint, a withdrawn definition, or a service without the method. Only these may
|
|
64
|
+
* trigger a fallback to an older endpoint; any other failure is the real answer.
|
|
65
|
+
*/
|
|
66
|
+
const ENDPOINT_UNAVAILABLE_CODES = new Set([
|
|
67
|
+
"gateway/invocation-unavailable",
|
|
68
|
+
"gateway/definition-unavailable",
|
|
69
|
+
"gateway/method-unavailable",
|
|
70
|
+
]);
|
|
71
|
+
export const isEndpointUnavailable = (err) => ENDPOINT_UNAVAILABLE_CODES.has(err?.code);
|
|
72
|
+
|
|
54
73
|
// 流式端点:只取首帧(如 session/control 基线流),unary invoke 会被网关拒绝
|
|
55
74
|
export const RPC_STREAM_METHODS = new Set(["session.control"]);
|
|
56
75
|
/** v3.1.2:session/control(baseline)中取某会话的投影值(modelSelection/imageLimits 等)。 */
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 会话按天轮换 + 新会话恢复指引(P1-17)。
|
|
3
|
+
*
|
|
4
|
+
* 借鉴的是 `dsh-bili-whale` 的「会话一天一换」:一天的上下文太长之后,模型会开始
|
|
5
|
+
* 把上午的调试细节当成当前任务的约束,用户也要翻很久才找得到今天说的话。
|
|
6
|
+
*
|
|
7
|
+
* **但不自动切。** 自动新建会话会在用户正要接着说「刚才那个 bug」时把上下文断掉,
|
|
8
|
+
* 那种体验比长会话糟糕得多。所以这里只做两件事:
|
|
9
|
+
* 1. 判断「这个会话是不是跨天了、该建议开新的」——`rotationAdvice()`;
|
|
10
|
+
* 2. 开新会话时给出「上次聊到…」的指引——`resumeBrief()`。
|
|
11
|
+
* 切换由用户在界面上按下,插件不替他决定。
|
|
12
|
+
*
|
|
13
|
+
* 与记忆库的分工:记忆库存的是**长期事实**(他偏好短句、项目用 npm),
|
|
14
|
+
* 这里的摘要只覆盖**这一条会话最近聊了什么**,用完即弃,不写库。
|
|
15
|
+
* 两者的寿命不同,混在一起会让"三天前随口一句"变成"长期偏好"。
|
|
16
|
+
*/
|
|
17
|
+
import { localDayKey } from "./proactive.js";
|
|
18
|
+
import { blocksToText } from "./timeline.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 本地日历日的键(`YYYY-MM-DD`)。
|
|
22
|
+
*
|
|
23
|
+
* 直接用 `proactive.js` 的 `localDayKey()`,不另写一份:两处"今天"的定义必须
|
|
24
|
+
* 完全一致,否则主动消息的每日上限与这里的跨天判断会在零点附近出现分歧
|
|
25
|
+
* (一个认为已经是新的一天,另一个还认为昨天)。
|
|
26
|
+
*/
|
|
27
|
+
export function dayKey(at) {
|
|
28
|
+
const d = at instanceof Date ? at : new Date(at);
|
|
29
|
+
if (Number.isNaN(d.getTime())) return "";
|
|
30
|
+
return localDayKey(d);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 判断一条会话是否该建议轮换。纯函数,不读盘不读库。
|
|
35
|
+
*
|
|
36
|
+
* 只在**真跨天**时建议,同一天内不管聊了多久都不建议——同一天的长会话是用户
|
|
37
|
+
* 自己聊出来的,中途劝他换一个只会打断他。唯一额外的触发条件是「跨天且这一轮
|
|
38
|
+
* 已经结束」,因为用户正在等回复时劝他换会话最没有意义。
|
|
39
|
+
*
|
|
40
|
+
* @param {object} e
|
|
41
|
+
* @param {number} e.lastMessageAt 该会话最近一条消息的时间戳(毫秒)
|
|
42
|
+
* @param {Date} [e.now]
|
|
43
|
+
* @param {boolean} [e.busy] 该会话是否正在跑(跑着就不劝)
|
|
44
|
+
* @returns {{shouldRotate: boolean, reason: string, idleDays: number}}
|
|
45
|
+
*/
|
|
46
|
+
export function rotationAdvice({ lastMessageAt, now = new Date(), busy = false } = {}) {
|
|
47
|
+
const last = Number(lastMessageAt);
|
|
48
|
+
// 没有时间戳(新会话、或旧版 App 没上报)时不建议:宁可少劝一次,
|
|
49
|
+
// 也不要在一条刚建的会话上弹「要不要开新会话」。
|
|
50
|
+
if (!Number.isFinite(last) || last <= 0) {
|
|
51
|
+
return { shouldRotate: false, reason: "unknown-last-message", idleDays: 0 };
|
|
52
|
+
}
|
|
53
|
+
if (busy) return { shouldRotate: false, reason: "busy", idleDays: 0 };
|
|
54
|
+
|
|
55
|
+
const lastDay = dayKey(new Date(last));
|
|
56
|
+
const today = dayKey(now);
|
|
57
|
+
if (!lastDay || !today) {
|
|
58
|
+
return { shouldRotate: false, reason: "bad-clock", idleDays: 0 };
|
|
59
|
+
}
|
|
60
|
+
if (lastDay === today) {
|
|
61
|
+
return { shouldRotate: false, reason: "same-day", idleDays: 0 };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 用日历日之差而不是 24 小时差:晚上 11 点聊到凌晨 1 点只隔两小时,
|
|
65
|
+
// 但用户确实跨了一天,新会话对他是「今天」的开始。
|
|
66
|
+
const idleDays = Math.max(1, calendarDaysBetween(lastDay, today));
|
|
67
|
+
return { shouldRotate: true, reason: "crossed-day", idleDays };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 两个 `YYYY-MM-DD` 之间隔了几个日历日。用 UTC 构造避免夏令时造成 23/25 小时。 */
|
|
71
|
+
function calendarDaysBetween(fromKey, toKey) {
|
|
72
|
+
const [fy, fm, fd] = fromKey.split("-").map(Number);
|
|
73
|
+
const [ty, tm, td] = toKey.split("-").map(Number);
|
|
74
|
+
const a = Date.UTC(fy, fm - 1, fd);
|
|
75
|
+
const b = Date.UTC(ty, tm - 1, td);
|
|
76
|
+
return Math.round((b - a) / 86_400_000);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 单条摘要文本的上限。够说清「在做什么」,又不会把整段对话搬进新会话。 */
|
|
80
|
+
export const MAX_LINE_CHARS = 120;
|
|
81
|
+
|
|
82
|
+
/** 最多带几条最近的用户发言。3 条足够让用户认出「哦对,昨天在弄那个」。 */
|
|
83
|
+
export const MAX_LINES = 3;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* 从会话事件里挑出「上次聊到」的几条。
|
|
87
|
+
*
|
|
88
|
+
* **形状很关键**:`sessions.get(id).events` 给的是**原始内核事件**,文本在
|
|
89
|
+
* `data.message.content` 的 blocks 里;而 `/api/history` 下发的是 `summarizeEvent()`
|
|
90
|
+
* 之后的**摘要事件**,文本在 `data.text`。两者都能到这里(活动会话给原始、
|
|
91
|
+
* 休眠会话经 `loadDormantSession` 也可能给原始),所以都要认。
|
|
92
|
+
* 只认其一的话,真实会话会静默提取不到任何片段——空摘要看起来像"昨天没聊什么"。
|
|
93
|
+
*
|
|
94
|
+
* 只取**真人发言**:`message.source.kind === "user"`。系统注入(plugin /
|
|
95
|
+
* agent-instructions / tool)不算「聊到」——它们是内核塞进去的指令,
|
|
96
|
+
* 当成用户说的话会让摘要前言不搭后语。旧内核没有 `source` 时按真人处理。
|
|
97
|
+
*
|
|
98
|
+
* @param {object[]} events 会话事件(原始或已摘要的形状都接受)
|
|
99
|
+
* @param {object} [opts]
|
|
100
|
+
* @param {number} [opts.limit]
|
|
101
|
+
* @returns {string[]} 由旧到新的几条用户发言(已截断、已去重)
|
|
102
|
+
*/
|
|
103
|
+
export function recentUserLines(events, { limit = MAX_LINES } = {}) {
|
|
104
|
+
if (!Array.isArray(events)) return [];
|
|
105
|
+
const lines = [];
|
|
106
|
+
for (const ev of events) {
|
|
107
|
+
if (ev?.type !== "user/message") continue;
|
|
108
|
+
const data = ev.data;
|
|
109
|
+
if (!data || typeof data !== "object") continue;
|
|
110
|
+
// 原始事件的来源标记在 `data.message.source`,摘要事件在 `data.source`。
|
|
111
|
+
const kind = data.message?.source?.kind ?? data.source?.kind;
|
|
112
|
+
if (typeof kind === "string" && kind !== "" && kind !== "user") continue;
|
|
113
|
+
|
|
114
|
+
const text = oneLine(textOf(data));
|
|
115
|
+
if (!text) continue;
|
|
116
|
+
// 同一条重复出现(重试、回放)时只留一次。
|
|
117
|
+
if (lines.includes(text)) continue;
|
|
118
|
+
lines.push(text);
|
|
119
|
+
if (lines.length > limit) lines.shift();
|
|
120
|
+
}
|
|
121
|
+
return lines;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 从一条 user/message 的 `data` 里取出文本。两种形状:
|
|
126
|
+
* - 原始:`data.message.content` 是 blocks 数组 → 用 `blocksToText`
|
|
127
|
+
* - 摘要:`data.text` 已是字符串
|
|
128
|
+
* 其它情况返回空串(宁可少一条,也不要 `[object Object]` 进摘要)。
|
|
129
|
+
*/
|
|
130
|
+
function textOf(data) {
|
|
131
|
+
if (typeof data.text === "string") return data.text;
|
|
132
|
+
const content = data.message?.content;
|
|
133
|
+
if (Array.isArray(content)) return blocksToText(content, { imagePlaceholder: false });
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 压成一行、去空白、截断。摘要里出现换行会让「上次聊到」变成一大段。 */
|
|
138
|
+
function oneLine(raw) {
|
|
139
|
+
if (typeof raw !== "string") return "";
|
|
140
|
+
const flat = raw.replace(/\s+/g, " ").trim();
|
|
141
|
+
if (flat === "") return "";
|
|
142
|
+
return flat.length > MAX_LINE_CHARS ? `${flat.slice(0, MAX_LINE_CHARS)}…` : flat;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 生成新会话开头的「上次聊到…」。
|
|
147
|
+
*
|
|
148
|
+
* 返回的是一段**给模型看**的文本,插在新会话的第一条消息前面。它的措辞要满足两点:
|
|
149
|
+
* - 明确这是**以前**的上下文,不是用户这次的要求;
|
|
150
|
+
* - 明确可能与当前冲突、以当前为准——否则模型会拿昨天的结论硬套今天的事。
|
|
151
|
+
*
|
|
152
|
+
* @param {object} e
|
|
153
|
+
* @param {string[]} [e.lines] `recentUserLines()` 的结果
|
|
154
|
+
* @param {number} [e.idleDays] 隔了几天
|
|
155
|
+
* @param {string} [e.sessionTitle] 旧会话标题(有就用,帮用户确认是哪条)
|
|
156
|
+
* @returns {string} 没有可用内容时返回空串
|
|
157
|
+
*/
|
|
158
|
+
export function resumeBrief({ lines = [], idleDays = 1, sessionTitle = "" } = {}) {
|
|
159
|
+
const usable = (Array.isArray(lines) ? lines : []).filter(
|
|
160
|
+
(l) => typeof l === "string" && l.trim() !== "",
|
|
161
|
+
);
|
|
162
|
+
if (usable.length === 0) return "";
|
|
163
|
+
|
|
164
|
+
const when =
|
|
165
|
+
idleDays <= 1 ? "上一次" : idleDays < 7 ? `${idleDays} 天前` : `${idleDays} 天前`;
|
|
166
|
+
const title =
|
|
167
|
+
typeof sessionTitle === "string" && sessionTitle.trim() !== ""
|
|
168
|
+
? `(会话「${oneLine(sessionTitle)}」)`
|
|
169
|
+
: "";
|
|
170
|
+
|
|
171
|
+
return [
|
|
172
|
+
`【以下是${when}那次对话的结尾片段${title},供你了解上下文】`,
|
|
173
|
+
...usable.map((l) => `- ${l}`),
|
|
174
|
+
"【那是过去的情况,可能与现在不同;与本次对话冲突时以本次为准】",
|
|
175
|
+
].join("\n");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 一次算完「该不该劝换」+「换了之后带什么」。
|
|
180
|
+
*
|
|
181
|
+
* @param {object} e
|
|
182
|
+
* @param {object[]} e.events
|
|
183
|
+
* @param {number} e.lastMessageAt
|
|
184
|
+
* @param {Date} [e.now]
|
|
185
|
+
* @param {boolean} [e.busy]
|
|
186
|
+
* @param {string} [e.sessionTitle]
|
|
187
|
+
*/
|
|
188
|
+
export function buildRotation({ events, lastMessageAt, now = new Date(), busy = false, sessionTitle = "" }) {
|
|
189
|
+
const advice = rotationAdvice({ lastMessageAt, now, busy });
|
|
190
|
+
const lines = recentUserLines(events);
|
|
191
|
+
return {
|
|
192
|
+
...advice,
|
|
193
|
+
lines,
|
|
194
|
+
// 建议轮换但没有可带的片段时,resumeBrief 返回空串——那就单纯开个新会话,
|
|
195
|
+
// 不要塞一段「上次聊到:(空)」进去。
|
|
196
|
+
brief: advice.shouldRotate ? resumeBrief({ lines, idleDays: advice.idleDays, sessionTitle }) : "",
|
|
197
|
+
};
|
|
198
|
+
}
|
package/lib/timeline.js
CHANGED
|
@@ -292,7 +292,7 @@ export function sniffImageType(data) {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
/**
|
|
295
|
-
* 把 SessionEvent 转成移动端摘要(docs/
|
|
295
|
+
* 把 SessionEvent 转成移动端摘要(docs/CONSOLIDATED-DOCUMENTATION.en.md Part 03 §3.6)。
|
|
296
296
|
* 返回 { seq, type, data?, detail? };未识别类型保留 type/seq,详情按需读取。
|
|
297
297
|
*/
|
|
298
298
|
function summarizeEventCore(event) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-mobile/mobile-remote",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(Android
|
|
3
|
+
"version": "3.3.0",
|
|
4
|
+
"description": "DSH Mobile:把 DeepSeek Harness 变成随身控制台——手机远程发消息派活、看进度、收通知、审批决策、管理会话;配套 Flutter App(Android、iPhone / iPad)",
|
|
5
|
+
"homepage": "https://dsh.claud.ing/",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/GamePlayer-1001/dsh.git"
|
|
9
|
+
},
|
|
10
|
+
"bugs": {
|
|
11
|
+
"email": "support@claud.ing",
|
|
12
|
+
"url": "https://dsh.claud.ing/support/"
|
|
13
|
+
},
|
|
5
14
|
"type": "module",
|
|
6
15
|
"scripts": {
|
|
7
16
|
"test": "node --test test/*.js test/*.mjs",
|
|
8
|
-
"check": "node --check lib/index.js && node --check lib/client.js"
|
|
17
|
+
"check": "node --check lib/index.js && node --check lib/client.js",
|
|
18
|
+
"verify:deploy": "node tools/verify-deployment.mjs",
|
|
19
|
+
"gate": "bash scripts/gate.sh",
|
|
20
|
+
"gate:release": "bash scripts/gate.sh --release",
|
|
21
|
+
"compat:weekly": "bash scripts/compat-weekly.sh"
|
|
9
22
|
},
|
|
10
23
|
"main": "lib/index.js",
|
|
11
24
|
"exports": {
|
|
@@ -16,13 +29,14 @@
|
|
|
16
29
|
"files": [
|
|
17
30
|
"lib",
|
|
18
31
|
"cordis.patch.yml",
|
|
19
|
-
"docs",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
32
|
+
"docs/PRIVACY-POLICY.md",
|
|
33
|
+
"docs/PRIVACY-POLICY.en.md",
|
|
34
|
+
"docs/TERMS-OF-SERVICE.md",
|
|
35
|
+
"docs/TERMS-OF-SERVICE.en.md",
|
|
36
|
+
"docs/SUPPORT.md",
|
|
37
|
+
"docs/USER-GUIDE.zh-CN.md",
|
|
22
38
|
"README.md",
|
|
23
39
|
"FAQ.md",
|
|
24
|
-
"CHANGELOG.md",
|
|
25
|
-
"CONTRIBUTING.md",
|
|
26
40
|
"LICENSE"
|
|
27
41
|
],
|
|
28
42
|
"dsh": {
|
|
@@ -32,7 +46,6 @@
|
|
|
32
46
|
"client": {
|
|
33
47
|
"platform": "web",
|
|
34
48
|
"inject": [
|
|
35
|
-
"@deepseek-ai/dsh-client-runtime",
|
|
36
49
|
"@deepseek-ai/dsh-client-ui-settings"
|
|
37
50
|
]
|
|
38
51
|
}
|
|
@@ -46,16 +59,20 @@
|
|
|
46
59
|
],
|
|
47
60
|
"license": "MIT",
|
|
48
61
|
"engines": {
|
|
49
|
-
"node": ">=
|
|
62
|
+
"node": ">=24.9.0",
|
|
63
|
+
"dsh": ">=0.1.0-rc.6 <0.4.0-0"
|
|
50
64
|
},
|
|
51
65
|
"dependencies": {
|
|
52
66
|
"qrcode": "^1.5.4"
|
|
53
67
|
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"ws": "^8.18.0"
|
|
70
|
+
},
|
|
54
71
|
"peerDependencies": {
|
|
55
|
-
"@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <0.
|
|
56
|
-
"@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <0.
|
|
57
|
-
"@deepseek-ai/dsh-sandbox-policy": ">=0.1.0-rc.6 <0.
|
|
58
|
-
"@deepseek-ai/dsh-scope": ">=0.1.0-rc.6 <0.
|
|
72
|
+
"@deepseek-ai/dsh-credentials": ">=0.1.0-rc.6 <0.4.0",
|
|
73
|
+
"@deepseek-ai/dsh-llm": ">=0.1.0-rc.6 <0.4.0",
|
|
74
|
+
"@deepseek-ai/dsh-sandbox-policy": ">=0.1.0-rc.6 <0.4.0",
|
|
75
|
+
"@deepseek-ai/dsh-scope": ">=0.1.0-rc.6 <0.4.0",
|
|
59
76
|
"@deepseek-ai/schemastery": ">=3.18.1",
|
|
60
77
|
"dsh-codex-connect": ">=0.1.0-alpha.4.5"
|
|
61
78
|
},
|