agent-loft 0.2.42 → 0.2.44

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.
@@ -901,3 +901,274 @@ a.att-file:hover {
901
901
  color: var(--fg);
902
902
  background: var(--bg-hover);
903
903
  }
904
+
905
+ /* ---------- 回复里提到的文件:能点开预览(views/file-preview.js) ---------- */
906
+ .md a.file-link {
907
+ color: var(--link);
908
+ text-decoration: none;
909
+ border-bottom: 1px dashed currentColor;
910
+ cursor: pointer;
911
+ }
912
+
913
+ .md a.file-link:hover {
914
+ border-bottom-style: solid;
915
+ }
916
+
917
+ .md a.file-link code {
918
+ color: inherit;
919
+ }
920
+
921
+ .md a.file-link.file-img {
922
+ border: 0;
923
+ display: inline-block;
924
+ }
925
+
926
+ .md a.file-link.file-img img {
927
+ max-width: min(100%, 420px);
928
+ max-height: 320px;
929
+ border-radius: 8px;
930
+ border: 1px solid var(--border);
931
+ display: block;
932
+ }
933
+
934
+ .file-viewer {
935
+ position: fixed;
936
+ inset: 0;
937
+ z-index: 60;
938
+ background: rgba(0, 0, 0, 0.55);
939
+ display: flex;
940
+ align-items: center;
941
+ justify-content: center;
942
+ padding: 24px;
943
+ animation: fade-in 0.12s ease-out;
944
+ }
945
+
946
+ .fv-panel {
947
+ background: var(--bg);
948
+ border-radius: 14px;
949
+ box-shadow: var(--shadow);
950
+ width: min(1000px, 100%);
951
+ height: min(88vh, 100%);
952
+ display: flex;
953
+ flex-direction: column;
954
+ overflow: hidden;
955
+ }
956
+
957
+ .fv-head {
958
+ display: flex;
959
+ align-items: center;
960
+ gap: 10px;
961
+ padding: 10px 12px 10px 16px;
962
+ border-bottom: 1px solid var(--border);
963
+ }
964
+
965
+ .fv-title {
966
+ flex: 1;
967
+ min-width: 0;
968
+ }
969
+
970
+ .fv-name {
971
+ font-weight: 600;
972
+ font-size: 15px;
973
+ overflow: hidden;
974
+ text-overflow: ellipsis;
975
+ white-space: nowrap;
976
+ }
977
+
978
+ .fv-sub {
979
+ color: var(--fg-soft);
980
+ font-size: 12px;
981
+ overflow: hidden;
982
+ text-overflow: ellipsis;
983
+ white-space: nowrap;
984
+ }
985
+
986
+ .fv-actions {
987
+ display: flex;
988
+ gap: 8px;
989
+ }
990
+
991
+ .fv-actions .btn {
992
+ padding: 5px 12px;
993
+ font-size: 13px;
994
+ text-decoration: none;
995
+ color: inherit;
996
+ }
997
+
998
+ .fv-body {
999
+ flex: 1;
1000
+ min-height: 0;
1001
+ overflow: auto;
1002
+ display: flex;
1003
+ flex-direction: column;
1004
+ }
1005
+
1006
+ .fv-loading,
1007
+ .fv-empty {
1008
+ margin: auto;
1009
+ display: flex;
1010
+ flex-direction: column;
1011
+ align-items: center;
1012
+ gap: 14px;
1013
+ color: var(--fg-soft);
1014
+ padding: 24px;
1015
+ text-align: center;
1016
+ }
1017
+
1018
+ .fv-empty .btn {
1019
+ text-decoration: none;
1020
+ color: inherit;
1021
+ }
1022
+
1023
+ .fv-img,
1024
+ .fv-media {
1025
+ margin: auto;
1026
+ max-width: 100%;
1027
+ max-height: 100%;
1028
+ object-fit: contain;
1029
+ display: block;
1030
+ }
1031
+
1032
+ .fv-img {
1033
+ padding: 12px;
1034
+ box-sizing: border-box;
1035
+ }
1036
+
1037
+ .fv-media {
1038
+ background: #000;
1039
+ }
1040
+
1041
+ .fv-audio {
1042
+ margin: auto;
1043
+ width: min(480px, 90%);
1044
+ }
1045
+
1046
+ .fv-frame {
1047
+ flex: 1;
1048
+ border: 0;
1049
+ width: 100%;
1050
+ background: #fff;
1051
+ }
1052
+
1053
+ .fv-code {
1054
+ margin: 0;
1055
+ padding: 14px 16px;
1056
+ font-family: var(--mono);
1057
+ font-size: 13px;
1058
+ line-height: 1.55;
1059
+ background: var(--code-bg);
1060
+ flex: 1;
1061
+ white-space: pre;
1062
+ tab-size: 4;
1063
+ }
1064
+
1065
+ .fv-code code.hljs {
1066
+ background: transparent;
1067
+ padding: 0;
1068
+ }
1069
+
1070
+ .fv-doc {
1071
+ padding: 16px 24px;
1072
+ max-width: 820px;
1073
+ width: 100%;
1074
+ box-sizing: border-box;
1075
+ margin: 0 auto;
1076
+ }
1077
+
1078
+ .fv-cut {
1079
+ padding: 6px 16px;
1080
+ font-size: 12px;
1081
+ color: var(--fg-soft);
1082
+ background: var(--bg-soft);
1083
+ border-bottom: 1px solid var(--border);
1084
+ }
1085
+
1086
+ @media (max-width: 768px) {
1087
+ .file-viewer {
1088
+ padding: 0;
1089
+ }
1090
+
1091
+ .fv-panel {
1092
+ width: 100%;
1093
+ height: 100%;
1094
+ border-radius: 0;
1095
+ padding-top: env(safe-area-inset-top);
1096
+ padding-bottom: env(safe-area-inset-bottom);
1097
+ }
1098
+
1099
+ .fv-head {
1100
+ flex-wrap: wrap;
1101
+ }
1102
+
1103
+ .fv-actions {
1104
+ order: 3;
1105
+ width: 100%;
1106
+ }
1107
+ }
1108
+
1109
+ /* ---------- Codex visualize 画的图表:嵌在回复里(views/file-preview.js) ---------- */
1110
+ .md .viz {
1111
+ margin: 0.8em 0;
1112
+ }
1113
+
1114
+ .viz-frame {
1115
+ display: block;
1116
+ width: 100%;
1117
+ height: 320px;
1118
+ border: 0;
1119
+ background: transparent;
1120
+ /* 和页面一样跟着系统深浅色走:配色方案不一致时浏览器会给 iframe 垫一层不透明的底 */
1121
+ color-scheme: light dark;
1122
+ }
1123
+
1124
+ .viz-loading {
1125
+ height: 120px;
1126
+ display: flex;
1127
+ align-items: center;
1128
+ justify-content: center;
1129
+ }
1130
+
1131
+ .viz-actions {
1132
+ display: flex;
1133
+ justify-content: flex-end;
1134
+ gap: 4px;
1135
+ margin-top: 2px;
1136
+ }
1137
+
1138
+ .md .viz-btn {
1139
+ font-size: 12px;
1140
+ color: var(--fg-soft);
1141
+ background: none;
1142
+ border: 0;
1143
+ padding: 2px 6px;
1144
+ border-radius: 6px;
1145
+ text-decoration: none;
1146
+ cursor: pointer;
1147
+ }
1148
+
1149
+ .md .viz-btn:hover {
1150
+ background: var(--bg-hover);
1151
+ color: var(--fg);
1152
+ }
1153
+
1154
+ .viz-error {
1155
+ font-size: 13px;
1156
+ color: var(--fg-soft);
1157
+ padding: 10px 12px;
1158
+ border: 1px dashed var(--border);
1159
+ border-radius: 10px;
1160
+ }
1161
+
1162
+ .viz-path {
1163
+ font-family: var(--mono);
1164
+ font-size: 12px;
1165
+ margin-top: 2px;
1166
+ word-break: break-all;
1167
+ }
1168
+
1169
+ .fv-frame.fv-html {
1170
+ background: transparent;
1171
+ color-scheme: light dark;
1172
+ padding: 12px 16px;
1173
+ box-sizing: border-box;
1174
+ }
package/web/lib/dom.js CHANGED
@@ -59,6 +59,7 @@ export const ICON = {
59
59
  pointer: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 3l14 7-6 2-2 6Z"/></svg>',
60
60
  hand: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 11V5a1.5 1.5 0 0 1 3 0v5"/><path d="M12 10V4a1.5 1.5 0 0 1 3 0v6"/><path d="M15 10V6a1.5 1.5 0 0 1 3 0v8a7 7 0 0 1-7 7h-.5a6 6 0 0 1-4.6-2.2L3.4 15a1.6 1.6 0 0 1 2.4-2.1L9 15.5V11"/></svg>',
61
61
  help: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="9"/><path d="M9.5 9.2a2.6 2.6 0 0 1 5 .9c0 1.7-2.5 2.3-2.5 3.9M12 17h.01"/></svg>',
62
+ gauge: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m12 14 4-4"/><path d="M3.34 19a10 10 0 1 1 17.32 0"/></svg>',
62
63
  maximize: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/></svg>',
63
64
  restore: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 14h6v6M20 10h-6V4M14 10l7-7M3 21l7-7"/></svg>',
64
65
  laptop: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="5" width="16" height="11" rx="1.5"/><path d="M2 19h20"/></svg>',
@@ -7,9 +7,9 @@ import { h, toast } from "./dom.js";
7
7
 
8
8
  marked.setOptions({ gfm: true, breaks: true });
9
9
 
10
- export function renderMarkdown(text) {
10
+ export function renderMarkdown(text, opts) {
11
11
  const div = h("div", { class: "md" });
12
- patchMarkdown(div, text);
12
+ patchMarkdown(div, text, opts);
13
13
  return div;
14
14
  }
15
15
 
@@ -17,9 +17,10 @@ export function renderMarkdown(text) {
17
17
  * 把 div 里的 markdown 更新成 text,只重画变了的块(段落、列表、代码块…)。
18
18
  * 流式输出时前面的块不再变,每帧只需重画最后一两块;选中的文字、代码块的横向滚动也不会被冲掉。
19
19
  * live = 还在输出:最后一块随时会变,先不高亮,等它定下来再高亮。
20
+ * enhance(box):每块画好后再加工一下(比如把回复里的文件路径变成能点开的)。
20
21
  * 按块拼起来和整段解析的结果一样(marked 的 parser 本来就是逐块拼接的)。
21
22
  */
22
- export function patchMarkdown(div, text, { live = false } = {}) {
23
+ export function patchMarkdown(div, text, { live = false, enhance } = {}) {
23
24
  const tokens = marked.lexer(text ?? "");
24
25
  const links = JSON.stringify(tokens.links ?? {});
25
26
  // 引用式链接的定义可能在后面才出现(流式输出时地址还会一点点变长),会影响前面的块:定义变了就整个重画
@@ -52,6 +53,7 @@ export function patchMarkdown(div, text, { live = false } = {}) {
52
53
  const box = document.createElement("div");
53
54
  box.innerHTML = DOMPurify.sanitize(marked.parser(chunk), { ADD_ATTR: ["target"] });
54
55
  decorate(box, final);
56
+ enhance?.(box);
55
57
  const nodes = [...box.childNodes];
56
58
  div.append(...nodes);
57
59
  blocks.push({ raw: raws[i], final, nodes });
@@ -12,9 +12,20 @@ import { createTouch } from "./desktop-touch.js";
12
12
  // 进来时不自动连,点了「连接」才连(Linux 上会起 x11vnc)。
13
13
  // 离开远程控制页时连接不断,画面在后台照常更新;断线了自己重连,点了「断开」才不连。
14
14
  // 手机上:触摸事件由 desktop-touch.js 接管(触控板 / 触摸两种模式、双指本地放大),下面多一排按键。
15
+ // 画质:除了「原画」,服务端都会把画面缩小、压成 JPEG 再发过来(vnc-transcode.ts),换画质要重连。
16
+
17
+ /** 画质档位:和服务端 DESKTOP_QUALITIES 对应,original 是原样转发 */
18
+ const QUALITIES = [
19
+ ["smooth", "流畅", "长边 1280,最省流量"],
20
+ ["standard", "标准", "长边 1920"],
21
+ ["high", "高清", "长边 2560"],
22
+ ["original", "原画", "不缩放、无损,很费流量,只适合局域网"],
23
+ ];
24
+ const savedQuality = localStorage.getItem("aim.deskQuality");
15
25
 
16
26
  const D = {
17
27
  rfb: null,
28
+ quality: QUALITIES.some(([id]) => id === savedQuality) ? savedQuality : "standard",
18
29
  /** idle / connecting / connected / error */
19
30
  state: "idle",
20
31
  message: "",
@@ -100,7 +111,7 @@ async function connect() {
100
111
  // 等密码的这会儿里点了断开,或者又发起了一次连接(切回前台、点了重连):这次作罢
101
112
  if (!D.want || D.rfb) return;
102
113
  const proto = location.protocol === "https:" ? "wss" : "ws";
103
- const rfb = new RFB(D.screen, `${proto}://${location.host}/ws/desktop`, { credentials: { password }, shared: true, wsProtocols: [] });
114
+ const rfb = new RFB(D.screen, `${proto}://${location.host}/ws/desktop?q=${D.quality}`, { credentials: { password }, shared: true, wsProtocols: [] });
104
115
  D.rfb = rfb;
105
116
  rfb.scaleViewport = D.fit;
106
117
  // 不裁剪:原始大小时 noVNC 的画面容器自己出滚动条
@@ -293,6 +304,7 @@ function renderTools() {
293
304
  tool("剪贴板", "clipboard", openClipboard, { disabled: !on }),
294
305
  tool("发送按键", "command", (e) => openKeysMenu(e.currentTarget), { disabled: !on || D.viewOnly }),
295
306
  tool(D.viewOnly ? "只看(点一下恢复控制)" : "只看不控制", "eye", toggleViewOnly, { on: D.viewOnly }),
307
+ tool(`画质:${QUALITIES.find(([id]) => id === D.quality)[1]}`, "gauge", (e) => openQualityMenu(e.currentTarget)),
296
308
  // 手机上靠双指放大,不切原始大小
297
309
  isTouch ? null : tool(D.fit ? "原始大小" : "缩放到窗口", D.fit ? "maximize" : "restore", toggleFit),
298
310
  tool("全屏", "expand", () => setFull(true)),
@@ -348,6 +360,25 @@ function toggleViewOnly() {
348
360
  renderTools();
349
361
  }
350
362
 
363
+ /** 选画质:存下来,连着的话马上按新画质重连 */
364
+ function openQualityMenu(anchor) {
365
+ const r = anchor.getBoundingClientRect();
366
+ showMenu(
367
+ { x: r.right - 240, y: r.bottom + 4 },
368
+ QUALITIES.map(([id, name, hint]) => ({
369
+ label: `${id === D.quality ? "✓ " : "  "}${name} · ${hint}`,
370
+ onclick: () => {
371
+ if (id === D.quality) return;
372
+ D.quality = id;
373
+ localStorage.setItem("aim.deskQuality", id);
374
+ renderTools();
375
+ toast(`画质:${name}`);
376
+ if (D.want) reconnect();
377
+ },
378
+ })),
379
+ );
380
+ }
381
+
351
382
  function toggleFit() {
352
383
  D.fit = !D.fit;
353
384
  localStorage.setItem("aim.deskFit", D.fit ? "1" : "0");