@syengup/fridaynext-hermes-channel 0.1.0-beta.2 → 0.1.0-beta.4

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 (92) hide show
  1. package/README.md +2 -2
  2. package/install-config.js +67 -0
  3. package/install-runtime.js +18 -9
  4. package/install.js +6 -4
  5. package/package.json +2 -1
  6. package/plugin/README.md +2 -2
  7. package/plugin/fridaynext_plugin/__init__.py +10 -0
  8. package/plugin/fridaynext_plugin/adapter.py +231 -12
  9. package/plugin/fridaynext_plugin/agent_management.py +158 -0
  10. package/plugin/fridaynext_plugin/canonical_control.py +12 -4
  11. package/plugin/fridaynext_plugin/compat_v0225.py +1247 -4
  12. package/plugin/fridaynext_plugin/continuations.py +271 -0
  13. package/plugin/fridaynext_plugin/device-tools-v1.json +302 -0
  14. package/plugin/fridaynext_plugin/device_tools.py +144 -0
  15. package/plugin/fridaynext_plugin/history.py +25 -3
  16. package/plugin/fridaynext_plugin/host.py +7 -4
  17. package/plugin/fridaynext_plugin/media_input.py +56 -9
  18. package/plugin/fridaynext_plugin/message_speech.py +143 -0
  19. package/plugin/fridaynext_plugin/multi_agent.py +221 -0
  20. package/plugin/fridaynext_plugin/reply_context.py +39 -0
  21. package/plugin/fridaynext_plugin/runtime_port.py +23 -1
  22. package/plugin/fridaynext_plugin/scheduled_tasks.py +229 -0
  23. package/plugin/fridaynext_plugin/settings.py +7 -3
  24. package/plugin/fridaynext_plugin/slash_commands.py +163 -0
  25. package/plugin/fridaynext_plugin/stream_bridge.py +83 -26
  26. package/plugin/fridaynext_plugin/stream_projection.py +30 -6
  27. package/plugin/fridaynext_plugin/subagents.py +228 -0
  28. package/plugin/plugin.yaml +11 -0
  29. package/plugin/runtime/dist/commands-routes.js +94 -0
  30. package/plugin/runtime/dist/device-tools-v1.json +302 -0
  31. package/plugin/runtime/dist/hosted-backend.js +293 -25
  32. package/plugin/runtime/dist/hosted-continuations.js +41 -0
  33. package/plugin/runtime/dist/hosted-device-tools.js +82 -0
  34. package/plugin/runtime/dist/hosted-media.js +54 -13
  35. package/plugin/runtime/dist/hosted-stream.js +124 -14
  36. package/plugin/runtime/dist/hosted-subagents.js +78 -0
  37. package/plugin/runtime/dist/platform-service.js +4 -0
  38. package/plugin/runtime/dist/plugin-control.js +10 -6
  39. package/plugin/runtime/dist/scheduled-routes.js +63 -0
  40. package/plugin/runtime/dist/service-host.js +40 -5
  41. package/plugin/runtime/dist/speech-routes.js +111 -0
  42. package/plugin/runtime/dist/tool-presentation.js +399 -0
  43. package/plugin/runtime/node_modules/.package-lock.json +6 -6
  44. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/API.md +125 -5
  45. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/README.md +21 -1
  46. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/history.d.ts +1 -0
  47. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/history.js +3 -0
  48. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/operations.d.ts +136 -0
  49. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/operations.js +105 -0
  50. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/settings-schema.d.ts +3 -0
  51. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/settings-schema.js +45 -0
  52. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/tool-presentation.d.ts +10 -0
  53. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/tool-presentation.js +2 -0
  54. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/types.d.ts +27 -2
  55. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/types.js +1 -0
  56. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/work-context.d.ts +56 -0
  57. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/contract/work-context.js +60 -0
  58. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/device-request/pending-store.js +3 -3
  59. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/index.d.ts +5 -0
  60. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/index.js +5 -0
  61. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/canonical-update-batcher.d.ts +26 -0
  62. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/canonical-update-batcher.js +112 -0
  63. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/channel-kernel.d.ts +4 -1
  64. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/channel-kernel.js +30 -5
  65. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/durable-run-store.d.ts +18 -1
  66. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/durable-run-store.js +187 -51
  67. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/runner.d.ts +1 -0
  68. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/runner.js +52 -2
  69. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/work-context.d.ts +13 -0
  70. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/runtime/work-context.js +73 -0
  71. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/service/channel-service.js +1 -1
  72. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/command-lifecycle.d.ts +47 -0
  73. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/command-lifecycle.js +184 -0
  74. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/controls.d.ts +1 -1
  75. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/controls.js +11 -0
  76. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/messages.js +12 -6
  77. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/operations.d.ts +13 -0
  78. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/operations.js +336 -0
  79. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/runtime.d.ts +1 -0
  80. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/runtime.js +52 -10
  81. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/session-settings.js +38 -6
  82. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/dist/transport/sessions.js +8 -8
  83. package/plugin/runtime/node_modules/@syengup/fridaynext-channel-kit/package.json +6 -7
  84. package/plugin/runtime/node_modules/tslib/README.md +3 -8
  85. package/plugin/runtime/node_modules/tslib/package.json +1 -1
  86. package/plugin/runtime/node_modules/tslib/tslib.d.ts +4 -2
  87. package/plugin/runtime/node_modules/tslib/tslib.es6.js +10 -1
  88. package/plugin/runtime/node_modules/tslib/tslib.es6.mjs +10 -1
  89. package/plugin/runtime/node_modules/tslib/tslib.js +10 -1
  90. package/plugin/runtime/package-lock.json +7 -7
  91. package/plugin/runtime/package.json +1 -1
  92. package/plugin/tools.py +3 -0
@@ -0,0 +1,111 @@
1
+ import { HermesError } from "./service-errors.js";
2
+ // 传输上界:1200字符按Mac mini真实edge采样约1.7MB音频,base64约2.3MB,留在UDS 4MB单帧内。
3
+ // Node与Python各自校验一次,不能只信客户端。
4
+ export const MAX_SPEECH_TEXT_LENGTH = 1200;
5
+ // Python音频硬上界2,500,000字节;base64膨胀约4/3,Node只接受其对应的最大帧。
6
+ export const MAX_SPEECH_AUDIO_BASE64_LENGTH = 3_500_000;
7
+ export const SPEECH_ERROR_CODES = new Set([
8
+ "TTS_INPUT_INVALID",
9
+ "TTS_INPUT_TOO_LONG",
10
+ "TTS_UNAVAILABLE",
11
+ "TTS_FAILED",
12
+ "TTS_AUDIO_TOO_LARGE",
13
+ ]);
14
+ const BODY_LIMIT_BYTES = 1024 * 1024;
15
+ const ERROR_STATUS = {
16
+ TTS_INPUT_INVALID: 400,
17
+ TTS_INPUT_TOO_LONG: 400,
18
+ TTS_AUDIO_TOO_LARGE: 502,
19
+ TTS_UNAVAILABLE: 503,
20
+ TTS_FAILED: 503,
21
+ };
22
+ function json(res, status, body) {
23
+ res.statusCode = status;
24
+ res.setHeader("Cache-Control", "no-store");
25
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
26
+ res.end(JSON.stringify(body));
27
+ }
28
+ function token(value) {
29
+ return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/.test(value);
30
+ }
31
+ function mime(value) {
32
+ return typeof value === "string" && /^[A-Za-z0-9][A-Za-z0-9.+-]{0,63}\/[A-Za-z0-9][A-Za-z0-9.+-]{0,63}$/.test(value);
33
+ }
34
+ function base64(value) {
35
+ return value.length % 4 === 0 && /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);
36
+ }
37
+ async function readJSON(req) {
38
+ const chunks = [];
39
+ let size = 0;
40
+ for await (const chunk of req) {
41
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
42
+ size += bytes.length;
43
+ if (size > BODY_LIMIT_BYTES)
44
+ throw new Error("body too large");
45
+ chunks.push(bytes);
46
+ }
47
+ return JSON.parse(Buffer.concat(chunks).toString("utf8"));
48
+ }
49
+ // 扩展路由位于Kit既有attest/身份门禁之后,但ChannelService不会自动校验Bearer;这里显式补上。
50
+ // 只投影受控字段,任何宿主原始异常、路径、凭据或朗读原文都不进入响应。
51
+ export function createSpeechRoutes(options) {
52
+ return async (req, res) => {
53
+ const pathname = new URL(req.url ?? "/", "http://localhost").pathname.replace(/\/+$/, "");
54
+ const isConfig = pathname === "/friday-next/tts/config";
55
+ if (!isConfig && pathname !== "/friday-next/tts/speak")
56
+ return false;
57
+ if (!options.authenticate(req)) {
58
+ json(res, 401, { ok: false, code: "UNAUTHORIZED" });
59
+ return true;
60
+ }
61
+ if (req.method !== (isConfig ? "GET" : "POST")) {
62
+ json(res, 405, { ok: false, code: "METHOD_NOT_ALLOWED" });
63
+ return true;
64
+ }
65
+ if (isConfig) {
66
+ try {
67
+ const value = (await options.backend.speechConfig())?.maxTextLength;
68
+ if (!Number.isSafeInteger(value) || value < 1)
69
+ throw new HermesError("TTS_UNAVAILABLE");
70
+ json(res, 200, { ok: true, maxTextLength: Math.min(value, MAX_SPEECH_TEXT_LENGTH) });
71
+ }
72
+ catch {
73
+ json(res, 503, { ok: false, code: "TTS_UNAVAILABLE", error: "Hermes TTS is unavailable" });
74
+ }
75
+ return true;
76
+ }
77
+ let body;
78
+ try {
79
+ body = await readJSON(req);
80
+ }
81
+ catch {
82
+ body = null;
83
+ }
84
+ const keys = body && typeof body === "object" && !Array.isArray(body) ? Object.keys(body) : [];
85
+ const text = keys.length === 1 && keys[0] === "text" && typeof body.text === "string"
86
+ ? body.text.trim() : "";
87
+ if (!text) {
88
+ json(res, 400, { ok: false, code: "TTS_INPUT_INVALID" });
89
+ return true;
90
+ }
91
+ if ([...text].length > MAX_SPEECH_TEXT_LENGTH) {
92
+ json(res, 400, { ok: false, code: "TTS_INPUT_TOO_LONG" });
93
+ return true;
94
+ }
95
+ try {
96
+ const result = await options.backend.speak(text);
97
+ if (!result || typeof result.audioBase64 !== "string" || !result.audioBase64
98
+ || result.audioBase64.length > MAX_SPEECH_AUDIO_BASE64_LENGTH || !base64(result.audioBase64)
99
+ || !token(result.provider) || !token(result.outputFormat) || !mime(result.mimeType)) {
100
+ throw new HermesError("TTS_FAILED");
101
+ }
102
+ json(res, 200, { ok: true, audioBase64: result.audioBase64, provider: result.provider,
103
+ outputFormat: result.outputFormat, mimeType: result.mimeType });
104
+ }
105
+ catch (error) {
106
+ const code = error instanceof HermesError && ERROR_STATUS[error.code] ? error.code : "TTS_UNAVAILABLE";
107
+ json(res, ERROR_STATUS[code], { ok: false, code });
108
+ }
109
+ return true;
110
+ };
111
+ }
@@ -0,0 +1,399 @@
1
+ const obj = (v) => v && typeof v === "object" && !Array.isArray(v) ? v : {};
2
+ const arr = (v) => Array.isArray(v) ? v : undefined;
3
+ const str = (v) => typeof v === "string" ? v : undefined;
4
+ const integer = (v) => typeof v === "number" && Number.isSafeInteger(v) ? v : undefined;
5
+ const textLines = (s) => s.split(/[\n\r\u0085\u2028\u2029]/).filter(s => s.trim());
6
+ const first = (o, keys) => keys.map(k => str(o[k])).find(s => s?.trim());
7
+ const clean = (s) => {
8
+ let result = s;
9
+ // 与旧展示一致:只剥外部内容标记,不改变正文的行首缩进。
10
+ while (true) {
11
+ const start = result.indexOf("<<<"), end = result.indexOf(">>>", start + 3);
12
+ if (start < 0 || end < 0 || !result.slice(start, end).includes("EXTERNAL_UNTRUSTED_CONTENT"))
13
+ break;
14
+ result = result.slice(0, start) + result.slice(end + 3);
15
+ }
16
+ return result.replace(/^(\s*)Source: Web Search[\s\S]*?---/, "$1").replaceAll("\r", "");
17
+ };
18
+ const line = (s) => textLines(clean(s)).map(s => s.trim()).join(" ");
19
+ const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
20
+ const clip = (s, max) => {
21
+ const parts = [...segmenter.segment(s)].map(p => p.segment);
22
+ return parts.length > max ? parts.slice(0, max).join("") + "…" : s;
23
+ };
24
+ const scalar = (v) => typeof v === "string" ? line(v) || undefined
25
+ : typeof v === "boolean" ? v ? "是" : "否" : typeof v === "number" ? String(v) : undefined;
26
+ const strings = (v) => (arr(v) ?? []).filter((v) => typeof v === "string");
27
+ const joined = (lines, tail = false) => {
28
+ const cleaned = lines.map(clean).filter(s => s.trim());
29
+ return (tail ? cleaned.slice(-30) : cleaned.slice(0, 30)).join("\n").trim();
30
+ };
31
+ const unwrap = (raw) => {
32
+ let text = raw.trim();
33
+ if (!text.startsWith("<untrusted_tool_result") || !text.includes(">"))
34
+ return raw;
35
+ text = text.slice(text.indexOf(">") + 1);
36
+ const close = text.lastIndexOf("</untrusted_tool_result>");
37
+ if (close >= 0)
38
+ text = text.slice(0, close);
39
+ text = text.trim();
40
+ const blank = text.indexOf("\n\n"), paragraph = text.slice(0, blank);
41
+ if (blank >= 0 && (paragraph.includes("untrusted") || paragraph.includes("retrieved from an external source")))
42
+ text = text.slice(blank + 2).trim();
43
+ return text;
44
+ };
45
+ const parse = (raw) => {
46
+ let text = raw.trim();
47
+ if (text.startsWith("```")) {
48
+ const lines = textLines(text);
49
+ if (lines.length >= 2) {
50
+ lines.shift();
51
+ if (lines.at(-1)?.trim().startsWith("```"))
52
+ lines.pop();
53
+ text = lines.join("\n").trim();
54
+ }
55
+ }
56
+ if (!text.startsWith("{") && !text.startsWith("["))
57
+ return undefined;
58
+ try {
59
+ return JSON.parse(text);
60
+ }
61
+ catch {
62
+ return undefined;
63
+ }
64
+ };
65
+ const tailTools = new Set(["terminal", "execute_code", "process_manage", "read_terminal"]);
66
+ const rawTools = new Set(["exec", "read", "write", "edit", "process", "browser", "image", "pdf", "tts", "message", "canvas"]);
67
+ export const hermesStructuredTools = new Set([
68
+ ...tailTools, "read_file", "write_file", "patch", "search_files", "todo", "todo_list", "memory", "session_search",
69
+ "skills_list", "skill_view", "skill_manage", "tool_search", "web_search", "web_extract", "x_search", "clarify",
70
+ "delegate_task", "cronjob_manage", "image_generate", "vision_analyze", "video_analyze", "video_generate", "text_to_speech", "computer_use", "manage_connections",
71
+ ...["navigate", "snapshot", "click", "type", "scroll", "back", "press", "get_images", "vision", "console", "cdp", "dialog", "vault", "exec"].map(s => "browser_" + s),
72
+ ...["show", "list", "complete", "block", "request_review", "request_changes", "heartbeat", "comment", "create", "link", "unblock", "attach", "attach_url", "attachments"].map(s => "kanban_" + s),
73
+ ]);
74
+ const noise = new Set(["success", "ok", "revision", "count", "total_count", "total_available", "truncated", "truncated_lines", "total_lines", "file_size", "position", "api_calls", "duration_seconds", "tool_calls_made", "categories", "verified", "dirs_created", "no_change", "index", "seat", "mtime"]);
75
+ const valueKeys = ["message", "summary", "title", "text", "output", "stdout", "content", "result", "snapshot", "diff", "log", "description", "analysis", "answer", "note", "hint", "warning", "error", "url", "path", "command", "query"];
76
+ const contentKeys = new Set(["content", "text", "output", "stdout", "result", "error", "analysis", "answer", "snapshot", "diff", "log"]);
77
+ const envelope = new Set(["success", "message", "error", "output", "stdout", "content", "result", "results", "data", "todos", "skills", "tools", "matches", "total_count", "exit_code", "responses", "processes", "queries", "files_modified", "bytes_written", "status", "image", "analysis", "summary"]);
78
+ const itemLine = (v) => {
79
+ if (Array.isArray(v))
80
+ return v.map(scalar).filter(Boolean).join(" · ") || undefined;
81
+ if (v && typeof v === "object") {
82
+ const o = obj(v), keys = ["title", "name", "content", "message", "question", "summary", "text", "description", "provider", "account", "path", "url", "src", "alt"];
83
+ return [...new Set(keys.map(k => scalar(o[k])).filter((s) => !!s))].slice(0, 3).join(" · ") || undefined;
84
+ }
85
+ return scalar(v);
86
+ };
87
+ function generic(v) {
88
+ if (Array.isArray(v))
89
+ return v.map(itemLine).filter((s) => !!s).slice(0, 12);
90
+ if (typeof v === "string")
91
+ return textLines(v);
92
+ if (!v || typeof v !== "object") {
93
+ const s = scalar(v);
94
+ return s ? [s] : [];
95
+ }
96
+ const o = obj(v), data = obj(o.data);
97
+ if (Object.keys(o).length <= 3 && Object.keys(data).length)
98
+ return generic(data);
99
+ const lines = [], consumed = new Set();
100
+ for (const key of valueKeys) {
101
+ if (!(key in o))
102
+ continue;
103
+ consumed.add(key);
104
+ const value = o[key];
105
+ if (typeof value === "string" && value.trim())
106
+ lines.push(...(contentKeys.has(key) ? textLines(value) : [line(value)]));
107
+ // 旧 Swift v0 的可选值插值保留,迁移不顺手改变已存在的展示文本。
108
+ else if (typeof value === "number" || typeof value === "boolean")
109
+ lines.push(`${key}: Optional(${JSON.stringify(scalar(value))})`);
110
+ else if (Array.isArray(value)) {
111
+ const parts = value.map(scalar).filter(Boolean).slice(0, 8);
112
+ if (parts.length)
113
+ lines.push(`${key}: ${parts.join(", ")}`);
114
+ }
115
+ }
116
+ for (const key of Object.keys(o).sort()) {
117
+ if (consumed.has(key) || noise.has(key) || key.startsWith("_"))
118
+ continue;
119
+ const value = o[key];
120
+ if (typeof value === "string" && value.trim())
121
+ lines.push(`${key}: ${line(value)}`);
122
+ else if (typeof value === "number" || typeof value === "boolean")
123
+ lines.push(`${key}: Optional(${JSON.stringify(scalar(value))})`);
124
+ else if (Array.isArray(value)) {
125
+ const parts = value.map(scalar).filter(Boolean).slice(0, 8);
126
+ if (parts.length)
127
+ lines.push(`${key}: ${parts.join(", ")}`);
128
+ else {
129
+ const items = value.map(itemLine).filter((s) => !!s).slice(0, 6);
130
+ if (items.length)
131
+ lines.push(key + ":", ...items.map(s => " " + s));
132
+ }
133
+ }
134
+ else if (value && typeof value === "object") {
135
+ const nested = obj(value);
136
+ let parts = [...new Set(["title", "name", "status", "provider", "account", "id", "priority", "assignee"].map(k => scalar(nested[k])).filter(Boolean))];
137
+ if (!parts.length)
138
+ parts = Object.keys(nested).filter(k => !noise.has(k)).sort().map(k => scalar(nested[k])).filter(Boolean);
139
+ if (parts.length)
140
+ lines.push(`${key}: ${parts.slice(0, 4).join(" · ")}`);
141
+ }
142
+ }
143
+ return lines;
144
+ }
145
+ const message = (o) => {
146
+ const error = first(o, ["error", "message"]);
147
+ if (error)
148
+ return [error];
149
+ const summary = first(o, ["summary"]);
150
+ if (summary)
151
+ return textLines(summary).slice(0, 1);
152
+ const status = first(o, ["status"]);
153
+ return status ? [status] : undefined;
154
+ };
155
+ const terminal = (v) => {
156
+ if (typeof v === "string")
157
+ return textLines(v);
158
+ const o = obj(v), output = first(o, ["output", "stdout", "text", "result"]), error = first(o, ["error", "user_summary"]), code = integer(o.exit_code);
159
+ const lines = [...(output ? textLines(output) : []), ...(code !== undefined && code !== 0 ? [`exit ${code}`] : []), ...(error ? textLines(error) : [])];
160
+ return lines.length ? lines : undefined;
161
+ };
162
+ const notices = (o, lines) => {
163
+ for (const key of ["warning", "_warning", "hint", "_hint", "note"]) {
164
+ const s = first(o, [key]);
165
+ if (s && !lines.includes(s))
166
+ lines.push(s);
167
+ }
168
+ for (const s of [str(obj(o.lint).output), str(o.lsp_diagnostics)])
169
+ if (s?.trim())
170
+ lines.push(...textLines(s).slice(0, 6));
171
+ return lines;
172
+ };
173
+ const joinParts = (parts) => parts.filter(s => s?.trim()).join(" · ");
174
+ function render(name, value) {
175
+ const o = obj(value), error = first(o, ["error"]);
176
+ if (["terminal", "execute_code", "read_terminal"].includes(name))
177
+ return terminal(value);
178
+ if (name === "process_manage") {
179
+ const processes = arr(o.processes);
180
+ return processes?.length ? processes.map(p => { const x = obj(p); return joinParts([str(x.status), line(str(x.command) ?? str(x.session_id) ?? "")]); }).filter(Boolean) : terminal(value);
181
+ }
182
+ if (["read_file", "write_file", "patch", "search_files", "memory", "session_search", "web_search", "web_extract", "x_search", "delegate_task", "cronjob_manage", "image_generate", "video_generate", "text_to_speech", "vision_analyze", "skill_view", "skill_manage"].includes(name) && error)
183
+ return [error];
184
+ switch (name) {
185
+ case "read_file": {
186
+ const lines = textLines(str(o.content) ?? ""), hint = first(o, ["hint"]);
187
+ if (hint)
188
+ lines.push(hint);
189
+ if (!lines.length && str(o.mime_type) !== undefined)
190
+ lines.push(String(o.mime_type) + (str(o.dimensions) !== undefined ? " · " + o.dimensions : ""));
191
+ else if (!lines.length && o.is_binary === true)
192
+ lines.push("二进制文件");
193
+ return lines.length ? lines : undefined;
194
+ }
195
+ case "write_file": return notices(o, [integer(o.bytes_written) !== undefined ? `已写入 ${o.bytes_written} 字节` : first(o, ["message"]) ?? "写入成功"]);
196
+ case "patch": {
197
+ const lines = first(o, ["note"]) ? [String(o.note)] : [], counts = [["files_modified", "修改"], ["files_created", "新建"], ["files_deleted", "删除"]].map(([key, label]) => strings(o[key]).length ? `${label} ${strings(o[key]).length} 个文件` : "").filter(Boolean);
198
+ if (counts.length)
199
+ lines.push("已" + counts.join(" · "));
200
+ else if (!lines.length)
201
+ lines.push(o.success === false ? "修改失败" : "修改成功");
202
+ return notices(o, lines);
203
+ }
204
+ case "search_files": {
205
+ const dense = first(o, ["matches_text"]);
206
+ if (dense)
207
+ return textLines(dense);
208
+ const matches = arr(o.matches);
209
+ if (matches?.length)
210
+ return matches.map(m => { const x = obj(m), path = str(x.path) ?? "", n = integer(x.line) ?? integer(x.line_number); return `${path}${n !== undefined ? ":" + n : ""} ${line(str(x.content) ?? "")}`; });
211
+ if (arr(o.files)?.length)
212
+ return strings(o.files);
213
+ return [integer(o.total_count) ? `共 ${o.total_count} 个匹配` : "没有匹配结果"];
214
+ }
215
+ case "todo":
216
+ case "todo_list": {
217
+ const todos = arr(o.todos);
218
+ if (!todos)
219
+ return message(o);
220
+ if (!todos.length)
221
+ return [str(o.message) ?? "暂无待办"];
222
+ return todos.flatMap(t => { const x = obj(t), content = str(x.content); return content === undefined ? [] : [`${{ completed: "[x]", in_progress: "[>]", cancelled: "[~]" }[String(x.status)] ?? "[ ]"} ${line(content)}`]; });
223
+ }
224
+ case "memory": return first(o, ["message"]) ? [String(o.message)] : arr(o.current_entries)?.length ? strings(o.current_entries).map(s => "· " + s) : message(o);
225
+ case "session_search": {
226
+ const messages = arr(o.messages);
227
+ if (messages?.length)
228
+ return [`${line(str(obj(o.session_meta).title) ?? str(o.session_id) ?? "会话")} · ${integer(o.message_count) ?? messages.length} 条消息`, ...messages.slice(0, 4).map(m => { const x = obj(m); return [str(x.role) ?? "", clip(line(str(x.content) ?? ""), 140)].filter(Boolean).join(":"); }).filter(Boolean)];
229
+ const results = arr(o.results);
230
+ if (!results?.length)
231
+ return [str(o.message) ?? "没有找到会话"];
232
+ return results.slice(0, 3).flatMap((r, i) => { const x = obj(r); return [`${i + 1}. ${str(x.title) ?? str(x.session_id) ?? "会话"}${str(x.when) !== undefined ? " · " + x.when : ""}`, ...(first(x, ["snippet"]) ? [" " + line(String(x.snippet))] : [])]; });
233
+ }
234
+ case "skills_list": {
235
+ const skills = arr(o.skills);
236
+ if (!skills)
237
+ return message(o);
238
+ if (!skills.length)
239
+ return [str(o.message) ?? "没有可用技能"];
240
+ return skills.flatMap(s => { const x = obj(s), name = str(x.name), description = str(x.description)?.trim(); return name === undefined ? [] : [name + (description ? " — " + line(description) : "")]; });
241
+ }
242
+ case "tool_search": {
243
+ const results = arr(o.results);
244
+ if (!results?.length)
245
+ return [str(o.message) ?? "没有匹配工具"];
246
+ return results.slice(0, 4).map(r => { const x = obj(r), matches = strings(x.matches); return `${str(x.query) ?? ""} → ${matches.length ? matches.join(", ") : "无匹配"}`; });
247
+ }
248
+ case "web_search": {
249
+ const results = arr(obj(o.data).web) ?? arr(o.results) ?? arr(o.web);
250
+ if (!results?.length)
251
+ return [str(o.message) ?? "没有搜索结果"];
252
+ return results.slice(0, 3).flatMap((r, i) => { if (typeof r === "string" && r.trim())
253
+ return [`${i + 1}. ${line(r)}`]; const x = obj(r), url = first(x, ["url"]), description = str(x.description) ?? str(x.snippet); return [`${i + 1}. ${line(str(x.title) ?? str(x.name) ?? str(x.url) ?? "结果")}`, ...(url ? [" " + url] : []), ...(description?.trim() ? [" " + clip(line(description), 160)] : [])]; });
254
+ }
255
+ case "web_extract":
256
+ case "x_search": {
257
+ const results = arr(o.results);
258
+ if (!results?.length)
259
+ return [str(o.message) ?? "没有提取到内容"];
260
+ return results.slice(0, 3).flatMap((r, i) => { const x = obj(r), url = str(x.url) ?? "", title = str(x.title) ?? url, content = str(x.content) ?? str(x.text) ?? str(x.description); return [`${i + 1}. ${line(!url || title === url ? title : title + " · " + url)}`, ...(content === undefined ? [] : textLines(content).slice(0, 6).map(s => " " + s))]; });
261
+ }
262
+ case "clarify": {
263
+ const responses = arr(o.responses);
264
+ if (!responses?.length)
265
+ return message(o);
266
+ return [...responses.slice(0, 4).map(r => { const x = obj(r); return `${line(str(x.question) ?? "")} → ${first(x, ["user_response"]) ? line(String(x.user_response)) : x.status === "skipped" ? "已跳过" : "未回复"}`; }), ...(first(o, ["notice"]) ? [String(o.notice)] : [])];
267
+ }
268
+ case "delegate_task": {
269
+ const results = arr(o.results);
270
+ if (!results?.length)
271
+ return message(o);
272
+ return results.slice(0, 4).flatMap(r => { const x = obj(r), lines = textLines(str(x.summary) ?? ""); return [joinParts([str(x.status), lines[0]]) || "子任务结束", ...lines.slice(1, 5).map(s => " " + s)]; });
273
+ }
274
+ case "cronjob_manage": {
275
+ const jobs = arr(o.jobs);
276
+ if (jobs?.length)
277
+ return jobs.map(j => { const x = obj(j); return joinParts([line(str(x.name) ?? str(x.job_id) ?? "任务"), str(x.schedule), str(x.state) ?? (x.enabled === false ? "已暂停" : "")]); });
278
+ const job = obj(o.job);
279
+ if (Object.keys(job).length)
280
+ return [joinParts([line(str(job.name) ?? str(job.job_id) ?? "任务"), str(job.schedule), str(job.next_run_at)])];
281
+ return message(o);
282
+ }
283
+ case "image_generate":
284
+ case "video_generate":
285
+ case "text_to_speech": {
286
+ for (const key of ["image", "video", "audio", "url", "path"]) {
287
+ const s = first(o, [key]);
288
+ if (s)
289
+ return [s];
290
+ const nested = obj(o[key]), path = str(nested.url) ?? str(nested.path) ?? str(nested.file);
291
+ if (path)
292
+ return [path];
293
+ }
294
+ return message(o);
295
+ }
296
+ case "skill_view":
297
+ case "vision_analyze": {
298
+ const s = first(o, name === "skill_view" ? ["content", "text", "message"] : ["analysis", "description", "text", "content"]);
299
+ return s ? textLines(s) : message(o);
300
+ }
301
+ case "skill_manage": return message(o);
302
+ default: return undefined;
303
+ }
304
+ }
305
+ function summary(name, v) {
306
+ const o = obj(v), head = () => generic(v)[0];
307
+ if (tailTools.has(name)) {
308
+ const lines = terminal(v), last = lines?.at(-1), code = integer(o.exit_code);
309
+ return last && code !== undefined && code !== 0 ? `${last} · exit ${code}` : last;
310
+ }
311
+ if (name === "read_file")
312
+ return integer(o.total_lines) !== undefined ? `共 ${o.total_lines} 行${o.truncated === true ? " · 已截断" : ""}` : head();
313
+ if (["write_file", "patch", "memory", "skill_view", "skill_manage", "cronjob_manage", "image_generate", "vision_analyze"].includes(name))
314
+ return render(name, v)?.[0] ?? head();
315
+ if (name === "search_files")
316
+ return integer(o.total_count) !== undefined ? `${o.total_count} 个匹配` : `${arr(o.files)?.length ?? 0} 个文件`;
317
+ if (["todo", "todo_list"].includes(name)) {
318
+ const todos = arr(o.todos);
319
+ if (!todos)
320
+ return head();
321
+ const parts = [["in_progress", "进行中"], ["pending", "待办"], ["completed", "完成"], ["cancelled", "取消"]].flatMap(([status, label]) => { const n = todos.filter(t => (str(obj(t).status) ?? "pending") === status).length; return n ? [`${label} ${n}`] : []; });
322
+ return parts.join(" · ") || `${todos.length} 项待办`;
323
+ }
324
+ if (name === "session_search") {
325
+ const messages = arr(o.messages), results = arr(o.results);
326
+ if (messages?.length) {
327
+ const title = str(obj(o.session_meta).title);
328
+ return `${integer(o.message_count) ?? messages.length} 条消息${title !== undefined ? " · " + line(title) : ""}`;
329
+ }
330
+ const title = str(obj(results?.[0]).title);
331
+ return `${results?.length ?? integer(o.count) ?? 0} 个会话${title !== undefined ? " · " + line(title) : ""}`;
332
+ }
333
+ if (name === "skills_list")
334
+ return `${integer(o.count) ?? arr(o.skills)?.length ?? 0} 个技能`;
335
+ if (name === "tool_search") {
336
+ const names = (arr(o.results) ?? []).flatMap(r => strings(obj(r).matches));
337
+ return names.length ? `${names.length} 个匹配 · ${names.slice(0, 3).join(", ")}` : "没有匹配工具";
338
+ }
339
+ if (["web_search", "web_extract", "x_search"].includes(name)) {
340
+ const results = name === "web_search" ? arr(obj(o.data).web) ?? arr(o.results) ?? [] : arr(o.results) ?? [], title = str(obj(results[0]).title);
341
+ return `${results.length}${name === "web_search" ? " 条结果" : " 页"}${title !== undefined ? " · " + line(title) : ""}`;
342
+ }
343
+ return head();
344
+ }
345
+ export function hermesToolPresentation(name, raw) {
346
+ const normalized = name.trim().toLowerCase().replaceAll(/[.-]/g, "_"), text = unwrap(raw), value = parse(text);
347
+ const tail = tailTools.has(normalized) || rawTools.has(normalized) && !["{", "["].includes(raw.trim()[0]);
348
+ let body = text, short;
349
+ if (!rawTools.has(normalized)) {
350
+ const structured = hermesStructuredTools.has(normalized), isEnvelope = Object.keys(obj(value)).some(k => envelope.has(k));
351
+ if (value !== undefined) {
352
+ if (structured || isEnvelope)
353
+ body = joined(render(normalized, value)?.filter(s => s.trim()).length ? render(normalized, value) : generic(value), tail);
354
+ const rendered = summary(normalized, value);
355
+ if (rendered !== undefined)
356
+ short = clip(line(rendered), 180) || undefined;
357
+ else if (structured || isEnvelope)
358
+ short = clip(line(generic(value)[0] ?? ""), 180) || undefined;
359
+ }
360
+ else if (structured) {
361
+ const lines = textLines(text);
362
+ short = clip(line(lines.findLast(s => /[\p{L}\p{N}]/u.test(s)) ?? lines.at(-1) ?? ""), 180) || undefined;
363
+ }
364
+ }
365
+ return { version: 1, kind: tailTools.has(normalized) ? "terminal" : "text", body, ...(short !== undefined ? { summary: short } : {}), viewport: tail ? "tail" : "head" };
366
+ }
367
+ export function toolResultText(value) {
368
+ if (typeof value === "string")
369
+ return value;
370
+ const blocks = arr(obj(value).content), text = blocks?.flatMap(b => obj(b).type === "text" && str(obj(b).text) !== undefined ? [String(obj(b).text)] : []);
371
+ if (text?.length)
372
+ return text.join("\n");
373
+ return JSON.stringify(value, (_key, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : v, 2) ?? "";
374
+ }
375
+ export function presentToolUpdate(update, name) {
376
+ const data = obj(update.data);
377
+ if (update.kind !== "tool" || "toolPresentation" in data)
378
+ return update;
379
+ const result = [data.result, data.output, data.error, data.summary].find(v => v !== undefined && v !== null);
380
+ if (result === undefined)
381
+ return update;
382
+ return { ...update, data: { ...data, toolPresentation: hermesToolPresentation(str(data.name) ?? str(data.toolName) ?? name ?? "tool", toolResultText(result)) } };
383
+ }
384
+ export function presentHistory(rows) {
385
+ const names = new Map();
386
+ for (const row of rows)
387
+ for (const call of arr(row.toolCalls) ?? []) {
388
+ const c = obj(call);
389
+ if (typeof c.id === "string" && typeof c.name === "string")
390
+ names.set(c.id, c.name);
391
+ }
392
+ return rows.map(row => {
393
+ const result = obj(row.toolResult);
394
+ if (!Object.keys(result).length || "toolPresentation" in result || typeof result.text !== "string")
395
+ return row;
396
+ const name = str(result.toolName) ?? (typeof result.toolCallId === "string" ? names.get(result.toolCallId) : undefined);
397
+ return { ...row, toolResult: { ...result, toolPresentation: hermesToolPresentation(name ?? "tool", result.text) } };
398
+ });
399
+ }
@@ -17,9 +17,9 @@
17
17
  }
18
18
  },
19
19
  "node_modules/@syengup/fridaynext-channel-kit": {
20
- "version": "0.1.4-beta.6",
21
- "resolved": "https://registry.npmjs.org/@syengup/fridaynext-channel-kit/-/fridaynext-channel-kit-0.1.4-beta.6.tgz",
22
- "integrity": "sha512-mfli/aY0/M8NmDkBPhfQdMf+f2yfZNP12JD4QpyCersfZGLSFDN/aDpthcu4Wh0nuyK/RL/oKVFzbUZi3RzYEA==",
20
+ "version": "0.2.0-beta.9",
21
+ "resolved": "https://registry.npmjs.org/@syengup/fridaynext-channel-kit/-/fridaynext-channel-kit-0.2.0-beta.9.tgz",
22
+ "integrity": "sha512-pqMVzR5rmNlamdmvFdEW9DGyJd66/cWFvtFdsNByfGiJLk3lnR/wONR/f9JSKtSxvoY2onPxSU9H2uYgm7ZxwQ==",
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
25
  "node-app-attest": "1.0.1"
@@ -366,9 +366,9 @@
366
366
  }
367
367
  },
368
368
  "node_modules/tslib": {
369
- "version": "2.8.1",
370
- "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
371
- "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
369
+ "version": "2.9.1",
370
+ "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.9.1.tgz",
371
+ "integrity": "sha512-a4Ux9VKuIMHsOS7ENbEq6hK2ZGYIT27Rtl0E4eD9KqwxhKiQeMZE/9xb3IdYwWaSOyIBQLExhQgXDTYoiCxnWA==",
372
372
  "license": "0BSD"
373
373
  },
374
374
  "node_modules/which-module": {