@aiti-ai/aiti-msg-share 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +82 -2
- package/client/src/index.js +618 -0
- package/dist/aiti-msg-share-client.mjs +3122 -0
- package/docs/README.zh-CN.md +83 -0
- package/icon.svg +1 -0
- package/icons/share-2.svg +1 -0
- package/index.ts +534 -0
- package/lib/share-core.mjs +116 -0
- package/package.json +29 -4
- package/skills/configure-target/SKILL.md +56 -0
- package/skills/import-sxcu/SKILL.md +30 -0
- package/skills/index.json +1 -0
- package/skills/troubleshoot/SKILL.md +35 -0
- package/test/share-core.test.mjs +50 -0
- package/tools/build-client.mjs +10 -0
- package/tools/deploy.mjs +32 -0
|
@@ -0,0 +1,618 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* aiti-msg-share client — share dialog, target manager and host entry points.
|
|
3
|
+
*
|
|
4
|
+
* Renders via ctx.h and the host's dialogs slot (data-ext-float contract).
|
|
5
|
+
* Other extensions call our service: aiti-msg-share.openShare(payload).
|
|
6
|
+
* QR codes are generated here (browser side) with qrcode — the provider package
|
|
7
|
+
* stops at URL generation.
|
|
8
|
+
*/
|
|
9
|
+
import QRCode from "qrcode";
|
|
10
|
+
|
|
11
|
+
const RECENT_KEY = "pi-web:recent-share-targets";
|
|
12
|
+
const API = (path) => `/api/extensions/aiti-msg-share/${path}`;
|
|
13
|
+
|
|
14
|
+
/** i18n lookup via host ctx.t (extman pattern); {param} interpolation. */
|
|
15
|
+
let tFn = null;
|
|
16
|
+
function kindLabel(k) { return shareT("share.kind." + k); }
|
|
17
|
+
function shareT(key, params) {
|
|
18
|
+
if (!tFn) return key;
|
|
19
|
+
try {
|
|
20
|
+
const raw = tFn(key, params);
|
|
21
|
+
if (!params) return raw;
|
|
22
|
+
return raw.replace(/\{(\w+)\}/g, (_m, k) => String(params[k] ?? ""));
|
|
23
|
+
} catch { return key; }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let h = null;
|
|
27
|
+
let ctxRef = null;
|
|
28
|
+
let apiUrlFn = null;
|
|
29
|
+
const state = {
|
|
30
|
+
open: false, manager: false, loading: true,
|
|
31
|
+
targets: [], history: [],
|
|
32
|
+
payload: null, kind: "message", text: "", rawText: "", baseText: "", title: "", tags: "",
|
|
33
|
+
// Which page-context fields get prepended to the shared content (multi-select).
|
|
34
|
+
stamp: { os: true, browser: true, url: true, sessionId: false, sessionName: false },
|
|
35
|
+
targetId: null, meta: {}, redact: true, redactHits: [],
|
|
36
|
+
result: null, busy: false, error: "", errorDetail: "", errorCode: "", errorTarget: "", errorProvider: "", search: "", probe: [],
|
|
37
|
+
editing: null, form: {},
|
|
38
|
+
};
|
|
39
|
+
const listeners = new Set();
|
|
40
|
+
|
|
41
|
+
function api(path) {
|
|
42
|
+
// Use the host's apiUrl() (basePath-aware, /dev-safe) when available; fall back
|
|
43
|
+
// to the absolute extension API path otherwise.
|
|
44
|
+
return apiUrlFn ? apiUrlFn(`/api/extensions/aiti-msg-share/${path}`) : API(path);
|
|
45
|
+
}
|
|
46
|
+
async function getJSON(path, opts) {
|
|
47
|
+
let r, data;
|
|
48
|
+
try {
|
|
49
|
+
r = await fetch(api(path), opts);
|
|
50
|
+
} catch (e) {
|
|
51
|
+
const err = new Error(`无法连接 pi-web 服务:${e?.message || e}`);
|
|
52
|
+
err.detail = String(e?.message || e);
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
data = await r.json().catch(() => ({}));
|
|
56
|
+
if (!r.ok || data.ok === false) {
|
|
57
|
+
const err = new Error(data.error || `HTTP ${r.status} (${api(path)})`);
|
|
58
|
+
err.detail = data.detail || `${r.status} ${api(path)}`;
|
|
59
|
+
err.kind = data.errorCode || data.errorKind;
|
|
60
|
+
err.targetId = data.errorTarget;
|
|
61
|
+
err.providerLabel = data.providerLabel;
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function recentGet() {
|
|
68
|
+
try { return JSON.parse(window.localStorage.getItem(RECENT_KEY) || "[]"); } catch { return []; }
|
|
69
|
+
}
|
|
70
|
+
function recentAdd(id) {
|
|
71
|
+
if (!id) return;
|
|
72
|
+
const next = [id, ...recentGet().filter((x) => x !== id)].slice(0, 10);
|
|
73
|
+
try { window.localStorage.setItem(RECENT_KEY, JSON.stringify(next)); } catch {}
|
|
74
|
+
}
|
|
75
|
+
function recentClear() { try { window.localStorage.removeItem(RECENT_KEY); } catch {} }
|
|
76
|
+
|
|
77
|
+
function set(partial) { Object.assign(state, partial); emit(); }
|
|
78
|
+
|
|
79
|
+
/** Pick a target for the pending share and return to the share dialog. */
|
|
80
|
+
function chooseTarget(id) {
|
|
81
|
+
recentAdd(id);
|
|
82
|
+
set({ targetId: id, manager: false, editing: null, error: "", errorDetail: "" });
|
|
83
|
+
}
|
|
84
|
+
function emit() { listeners.forEach((fn) => fn()); }
|
|
85
|
+
|
|
86
|
+
// Content-kind labels resolved via shareT() at render time; status uses icons only.
|
|
87
|
+
const STATUS_ICONS = { recent: "🕘", recommended: "★", dead: "⚠", legacy: "⚠" };
|
|
88
|
+
const CFG_BADGE = {
|
|
89
|
+
anonymous: { icon: "🟢", key: "share.cfg.anonymous", color: "var(--accent, #4d8dff)" },
|
|
90
|
+
ready: { icon: "✓", key: "share.cfg.ready", color: "var(--accent, #4d8dff)" },
|
|
91
|
+
"needs-setup": { icon: "🟠", key: "share.cfg.needs", color: "#d9a13c" },
|
|
92
|
+
dead: { icon: "💀", key: "share.cfg.dead", color: "var(--text-muted, #8b909b)" },
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const ICONS = {
|
|
96
|
+
share: '<circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.6" y1="10.5" x2="15.4" y2="6.5"/><line x1="8.6" y1="13.5" x2="15.4" y2="17.5"/>',
|
|
97
|
+
close: '<path d="M18 6 6 18M6 6l12 12"/>',
|
|
98
|
+
gear: '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.7 1.7 0 0 0 .3 1.9l.1.1-2.8 2.8-.1-.1a1.7 1.7 0 0 0-1.9-.3 1.7 1.7 0 0 0-1 1.6V21h-4v-.1A1.7 1.7 0 0 0 8.9 19a1.7 1.7 0 0 0-1.9.3l-.1.1L4.1 16.6l.1-.1a1.7 1.7 0 0 0 .3-1.9A1.7 1.7 0 0 0 3 13.5H3v-3h.1a1.7 1.7 0 0 0 1.6-1 1.7 1.7 0 0 0-.3-1.9L4.3 7.5 7.1 4.7l.1.1a1.7 1.7 0 0 0 1.9.3h.1a1.7 1.7 0 0 0 1-1.6V3h4v.1a1.7 1.7 0 0 0 1 1.6 1.7 1.7 0 0 0 1.9-.3l.1-.1 2.8 2.8-.1.1a1.7 1.7 0 0 0-.3 1.9v.1a1.7 1.7 0 0 0 1.6 1H21v4h-.1a1.7 1.7 0 0 0-1.6 1z"/>',
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
function icon(name, size = 13) {
|
|
102
|
+
const markup = ICONS[name];
|
|
103
|
+
if (!markup) return null;
|
|
104
|
+
// The glyphs mix circles/lines/paths, so the markup must land in the DOM as
|
|
105
|
+
//-is (a single <path d> wrapper would render nothing — that was the bug that
|
|
106
|
+
// made the share icon invisible on the message buttons).
|
|
107
|
+
return h("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor",
|
|
108
|
+
strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true",
|
|
109
|
+
dangerouslySetInnerHTML: { __html: markup } });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Share icon handed to topic consumers (session-manager more-menu, editor
|
|
113
|
+
// toolbars, msg-smart popover): { svg } = inner markup of a 24×24 line icon,
|
|
114
|
+
// the same form manifest declarative icons use; consumers without {svg}
|
|
115
|
+
// support ignore it and keep their text label.
|
|
116
|
+
const SHARE_ICON = { svg: ICONS.share };
|
|
117
|
+
|
|
118
|
+
function btn(label, onClick, opts = {}) {
|
|
119
|
+
return h("button", {
|
|
120
|
+
type: "button", onClick,
|
|
121
|
+
title: opts.title || label,
|
|
122
|
+
style: { border: "1px solid " + (opts.primary ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"),
|
|
123
|
+
background: opts.primary ? "var(--accent, #4d8dff)" : "var(--bg-hover, #25272c)", color: opts.primary ? "#fff" : "var(--text, #d8dade)",
|
|
124
|
+
borderRadius: 7, padding: "5px 12px", fontSize: 12, cursor: "pointer", opacity: opts.disabled ? 0.5 : 1 },
|
|
125
|
+
disabled: opts.disabled,
|
|
126
|
+
}, label);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Open the share dialog with a payload (also the cross-extension service). */
|
|
130
|
+
function openShare(payload = {}) {
|
|
131
|
+
const kind = payload.kind || "message";
|
|
132
|
+
const raw = payload.text || "";
|
|
133
|
+
set({ open: true, manager: false, payload, kind,
|
|
134
|
+
text: raw, rawText: raw, baseText: raw, title: payload.title || "",
|
|
135
|
+
tags: payload.tags || "", targetId: payload.targetId || null,
|
|
136
|
+
result: null, error: "", errorDetail: "", errorCode: "", errorTarget: "", errorProvider: "", redact: true, redactHits: [] });
|
|
137
|
+
void refresh();
|
|
138
|
+
// Compose from scratch so the page-info stamp reflects this dialog's context.
|
|
139
|
+
void refreshPreview();
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function refresh(force = false) {
|
|
144
|
+
set({ loading: true });
|
|
145
|
+
try {
|
|
146
|
+
const [catalog, history, probe] = await Promise.all([
|
|
147
|
+
getJSON("catalog"), getJSON("history"), getJSON("probe", { method: "POST" }).catch(() => ({ services: [] })),
|
|
148
|
+
]);
|
|
149
|
+
const targets = catalog.targets || [];
|
|
150
|
+
set({ targets, history: history.items || [], probe: probe.services || [], loading: false,
|
|
151
|
+
targetId: state.targetId || targets.find((t) => t.recommended)?.id || targets[0]?.id });
|
|
152
|
+
if (force) await getJSON("refresh", { method: "POST" }).catch(() => {});
|
|
153
|
+
} catch (e) { set({ loading: false, error: e.message, errorDetail: e.detail || "catalog/history" }); }
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function targetCard(target, selected, badge) {
|
|
157
|
+
const disabled = target.status === "dead" || target.enabled === false;
|
|
158
|
+
return h("button", { type: "button", key: target.id, disabled,
|
|
159
|
+
onClick: () => set({ targetId: target.id, error: "" }),
|
|
160
|
+
title: target.note || target.name,
|
|
161
|
+
style: { display: "inline-flex", alignItems: "center", gap: 5, padding: "4px 9px",
|
|
162
|
+
border: "1px solid " + (selected ? "var(--accent, #4d8dff)" : "var(--border, #34363c)"), borderRadius: 8,
|
|
163
|
+
background: selected ? "rgba(77, 141, 255, 0.15)" : "var(--bg-hover, #25272c)", color: disabled ? "var(--text-muted, #8b909b)" : "var(--text, #d8dade)",
|
|
164
|
+
fontSize: 12, cursor: "pointer", opacity: disabled ? 0.45 : 1 } },
|
|
165
|
+
h("span", null, STATUS_ICONS[badge] || "🔗"),
|
|
166
|
+
target.name || target.id,
|
|
167
|
+
...(target.kinds?.length ? [h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10 } },
|
|
168
|
+
target.kinds.map(kindLabel).join("/"))] : []),
|
|
169
|
+
...(() => { const b = CFG_BADGE[target.configState]; return b
|
|
170
|
+
? [h("span", { title: shareT(b.key), style: { fontSize: 10 } }, b.icon)] : []; })());
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function targetSection() {
|
|
174
|
+
const recent = recentGet();
|
|
175
|
+
const t = state.targets;
|
|
176
|
+
const byId = new Map(t.map((x) => [x.id, x]));
|
|
177
|
+
const recentItems = recent.map((id) => byId.get(id)).filter(Boolean).slice(0, 5);
|
|
178
|
+
// Targets the user has configured (saved) are always visible here.
|
|
179
|
+
const mine = t.filter((x) => x.custom && !recent.includes(x.id));
|
|
180
|
+
const recs = t.filter((x) => x.recommended && !recent.includes(x.id) && !x.custom).slice(0, 8);
|
|
181
|
+
const shown = [];
|
|
182
|
+
for (const item of recentItems) shown.push(targetCard(item, state.targetId === item.id, "recent"));
|
|
183
|
+
for (const item of mine) shown.push(targetCard(item, state.targetId === item.id, null));
|
|
184
|
+
for (const item of recs) shown.push(targetCard(item, state.targetId === item.id, "recommended"));
|
|
185
|
+
// Currently selected but not in any of the above (picked from the manager).
|
|
186
|
+
const sel = byId.get(state.targetId);
|
|
187
|
+
if (sel && !recent.includes(sel.id) && !sel.custom && !sel.recommended) {
|
|
188
|
+
shown.unshift(targetCard(sel, true, null));
|
|
189
|
+
}
|
|
190
|
+
shown.push(h("button", { type: "button", onClick: () => set({ manager: true }),
|
|
191
|
+
style: { border: "1px dashed var(--border, #34363c)", background: "none", color: "var(--text-muted, #8b909b)",
|
|
192
|
+
borderRadius: 8, padding: "4px 10px", fontSize: 12, cursor: "pointer" } }, shareT("share.more")));
|
|
193
|
+
return h("div", null,
|
|
194
|
+
h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, marginBottom: 5 } }, shareT("share.targets")),
|
|
195
|
+
h("div", { style: { display: "flex", flexWrap: "wrap", gap: 6 } }, ...shown));
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Collect page context for the optional "page info" stamp. */
|
|
199
|
+
function pageInfo() {
|
|
200
|
+
const ua = (typeof navigator !== "undefined" && navigator.userAgent) || "";
|
|
201
|
+
let os = "";
|
|
202
|
+
if (/Windows NT 10|Windows NT 11/.test(ua)) os = "Windows 10/11";
|
|
203
|
+
else if (/Windows/.test(ua)) os = "Windows";
|
|
204
|
+
else if (/Mac OS X|Macintosh/.test(ua)) os = "macOS";
|
|
205
|
+
else if (/Android/.test(ua)) os = "Android";
|
|
206
|
+
else if (/iPhone|iPad|iPod/.test(ua)) os = "iOS";
|
|
207
|
+
else if (/Linux/.test(ua)) os = "Linux";
|
|
208
|
+
let browser = "";
|
|
209
|
+
const b = (re, name) => { const m = ua.match(re); if (m) browser = name + " " + (m[1] || ""); };
|
|
210
|
+
b(/Edg\/([\d.]+)/, "Edge");
|
|
211
|
+
if (!browser) b(/OPR\/([\d.]+)/, "Opera");
|
|
212
|
+
if (!browser) b(/Chrome\/([\d.]+)/, "Chrome");
|
|
213
|
+
if (!browser) b(/Firefox\/([\d.]+)/, "Firefox");
|
|
214
|
+
if (!browser) b(/Version\/([\d.]+).*Safari/, "Safari");
|
|
215
|
+
const svc = ctxRef?.getExtService?.("pi-web.session");
|
|
216
|
+
const cur = (() => { try { return svc?.get?.() ?? svc; } catch { return null; } })();
|
|
217
|
+
const sessionId = state.payload?.sessionId || cur?.requestedId || cur?.id
|
|
218
|
+
|| (typeof location !== "undefined" ? new URL(location.href).searchParams.get("session") : "") || "";
|
|
219
|
+
const sessionName = cur?.name || state.payload?.sessionName || state.payload?.title
|
|
220
|
+
|| (typeof document !== "undefined" ? String(document.title || "").replace(/\s*[·|-]\s*Pi Web.*$/i, "").trim() : "");
|
|
221
|
+
return { os, browser, url: typeof location !== "undefined" ? location.href : "", sessionId, sessionName };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const STAMP_LABELS = { os: "share.pi.os", browser: "share.pi.browser", url: "share.pi.url", sessionId: "share.pi.sessionId", sessionName: "share.pi.sessionName" };
|
|
225
|
+
|
|
226
|
+
/** Build the stamp block from the selected fields. */
|
|
227
|
+
function stampBlock(stamp = state.stamp) {
|
|
228
|
+
const info = pageInfo();
|
|
229
|
+
const lines = [];
|
|
230
|
+
for (const key of Object.keys(STAMP_LABELS)) {
|
|
231
|
+
if (!stamp?.[key]) continue;
|
|
232
|
+
const value = info[key];
|
|
233
|
+
if (!value) continue;
|
|
234
|
+
lines.push(`> **${shareT(STAMP_LABELS[key])}**: ${value}`);
|
|
235
|
+
}
|
|
236
|
+
return lines.length ? lines.join("\n") + "\n\n" : "";
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/** Final text = stamp block + base text. */
|
|
240
|
+
function composeText() {
|
|
241
|
+
return stampBlock() + (state.baseText ?? "");
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Render a localized error message from the server's stable errorCode. */
|
|
245
|
+
function errorText() {
|
|
246
|
+
const code = state.errorCode || "";
|
|
247
|
+
const name = state.errorProvider || (state.targets.find((t) => t.id === state.errorTarget)?.name) || state.errorTarget || "";
|
|
248
|
+
const rawDetail = state.errorDetail || "";
|
|
249
|
+
// Provider errors can carry stack traces; keep the first meaningful chunk.
|
|
250
|
+
const detail = rawDetail.length > 220 ? rawDetail.slice(0, 220) + "…" : rawDetail;
|
|
251
|
+
const key = {
|
|
252
|
+
network: "share.err.network", timeout: "share.err.timeout", incomplete: "share.err.incomplete",
|
|
253
|
+
auth: "share.err.auth", tooLarge: "share.err.tooLarge", unavailable: "share.err.unavailable",
|
|
254
|
+
disabled: "share.err.disabled", unknownTarget: "share.err.unknownTarget",
|
|
255
|
+
noSession: "share.err.noSession", imageFetch: "share.err.imageFetch", endpoint: "share.err.endpoint",
|
|
256
|
+
badRequest: "share.err.badRequest", badSxcu: "share.err.badSxcu", noProbe: "share.err.noProbe",
|
|
257
|
+
forbidden: "share.err.forbidden",
|
|
258
|
+
}[code];
|
|
259
|
+
if (key) return shareT(key, { name, detail });
|
|
260
|
+
return state.error || shareT("share.err.generic", { detail });
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** Rebuild the preview after stamp/redact changes. */
|
|
264
|
+
async function refreshPreview() {
|
|
265
|
+
const raw = composeText();
|
|
266
|
+
set({ rawText: raw });
|
|
267
|
+
await applyRedaction(raw, state.redact);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Checkbox group for page-context stamping (rendered in the preview header). */
|
|
271
|
+
function stampToggles() {
|
|
272
|
+
return h("span", { style: { display: "flex", flexWrap: "wrap", gap: 8, alignItems: "center" } },
|
|
273
|
+
...Object.keys(STAMP_LABELS).map((key) => h("label", { key, title: shareT(STAMP_LABELS[key]),
|
|
274
|
+
style: { display: "flex", gap: 3, alignItems: "center", cursor: "pointer", fontSize: 10,
|
|
275
|
+
color: state.stamp[key] ? "var(--accent, #4d8dff)" : "var(--text-muted, #8b909b)" } },
|
|
276
|
+
h("input", { type: "checkbox", checked: !!state.stamp[key],
|
|
277
|
+
onChange: (e) => {
|
|
278
|
+
set({ stamp: { ...state.stamp, [key]: e.target.checked } });
|
|
279
|
+
void refreshPreview();
|
|
280
|
+
} }),
|
|
281
|
+
shareT(STAMP_LABELS[key]))));
|
|
282
|
+
}
|
|
283
|
+
async function applyRedaction(raw, redact) {
|
|
284
|
+
try {
|
|
285
|
+
const r = await getJSON("preview-redact", { method: "POST",
|
|
286
|
+
headers: { "content-type": "application/json" },
|
|
287
|
+
body: JSON.stringify({ text: raw, redact }) });
|
|
288
|
+
set({ text: r.text, redactHits: r.hits || [], redact });
|
|
289
|
+
} catch (e) {
|
|
290
|
+
// Server unavailable → keep showing raw text with no redaction claim.
|
|
291
|
+
set({ text: raw, redactHits: [], redact });
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function previewSection() {
|
|
296
|
+
return h("div", null,
|
|
297
|
+
// Header row: label | page-info multi-select | redact toggle
|
|
298
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: 10, marginBottom: 5, flexWrap: "wrap" } },
|
|
299
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11 } }, shareT("share.preview")),
|
|
300
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, opacity: 0.8 } }, shareT("share.pageInfo") + ":"),
|
|
301
|
+
stampToggles(),
|
|
302
|
+
h("label", { title: shareT("share.redactAuto"),
|
|
303
|
+
style: { marginLeft: "auto", display: "flex", gap: 5, alignItems: "center", cursor: "pointer",
|
|
304
|
+
fontSize: 11, color: state.redactHits.length ? "#d9a13c" : "var(--text-muted, #8b909b)" } },
|
|
305
|
+
h("input", { type: "checkbox", checked: state.redact, onChange: (e) => {
|
|
306
|
+
set({ redact: e.target.checked });
|
|
307
|
+
void applyRedaction(state.rawText, e.target.checked);
|
|
308
|
+
} }), shareT("share.redactToggle"),
|
|
309
|
+
state.redactHits.length ? ` (${state.redactHits.reduce((a, b) => a + b.count, 0)})` : "")),
|
|
310
|
+
h("textarea", { value: state.text, onInput: (e) => {
|
|
311
|
+
const v = e.target.value;
|
|
312
|
+
// Direct edits replace the body; the stamp block (if any) stays as typed.
|
|
313
|
+
set({ text: v, rawText: v, baseText: v, redactHits: [] });
|
|
314
|
+
},
|
|
315
|
+
style: { width: "100%", minHeight: 100, resize: "vertical", background: "var(--bg-hover, #25272c)",
|
|
316
|
+
border: "1px solid var(--border, #34363c)", color: "var(--text, #d8dade)", borderRadius: 8, padding: 9,
|
|
317
|
+
font: "12px/1.6 ui-monospace, Consolas, monospace" } }),
|
|
318
|
+
...(state.redactHits.length ? [h("div", { style: { color: "#d9a13c", fontSize: 11, marginTop: 4 } },
|
|
319
|
+
"🛡 " + state.redactHits.map((x) => `${x.rule}×${x.count}`).join(" · "))] : []));
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function resultSection() {
|
|
323
|
+
const r = state.result;
|
|
324
|
+
const rurl = r.url;
|
|
325
|
+
const isDeep = /^(joplin|obsidian|siyuan):/.test(rurl);
|
|
326
|
+
return h("div", { style: { border: "1px solid #3fbf6e55", background: "#3fbf6e10", borderRadius: 9,
|
|
327
|
+
padding: 11, display: "flex", gap: 12, alignItems: "center" } },
|
|
328
|
+
h("div", { style: { flex: 1, minWidth: 0 } },
|
|
329
|
+
h("a", { href: rurl, target: "_blank", rel: "noopener noreferrer", title: shareT("share.openInNewTab") || rurl,
|
|
330
|
+
style: { color: "var(--accent, #4d8dff)", fontFamily: "monospace", fontSize: 12, wordBreak: "break-all",
|
|
331
|
+
textDecoration: "none", cursor: "pointer" },
|
|
332
|
+
onMouseEnter: (e) => { e.currentTarget.style.textDecoration = "underline"; },
|
|
333
|
+
onMouseLeave: (e) => { e.currentTarget.style.textDecoration = "none"; } }, rurl),
|
|
334
|
+
h("div", { style: { display: "flex", gap: 7, marginTop: 9, flexWrap: "wrap" } },
|
|
335
|
+
btn(shareT("share.copy"), () => navigator.clipboard?.writeText(rurl).catch(() => {})),
|
|
336
|
+
!isDeep && typeof navigator !== "undefined" && navigator.share
|
|
337
|
+
? btn(shareT("share.system"), () => navigator.share({ url: rurl, title: state.title }).catch(() => {})) : null,
|
|
338
|
+
r.extra?.rawUrl ? h("a", { href: r.extra.rawUrl, target: "_blank", rel: "noopener",
|
|
339
|
+
style: { fontSize: 12, color: "var(--accent, #4d8dff)" } }, shareT("share.raw")) : null,
|
|
340
|
+
r.extra?.deletionUrl ? h("a", { href: r.extra.deletionUrl, target: "_blank", rel: "noopener",
|
|
341
|
+
style: { fontSize: 12, color: "#e05d5d" } }, shareT("share.delete")) : null)),
|
|
342
|
+
h("canvas", { ref: (el) => { if (el && !isDeep) QRCode.toCanvas(el, rurl, { width: 84, margin: 1 }).catch(() => {}); },
|
|
343
|
+
style: { display: isDeep ? "none" : "block", width: 84, height: 84, background: "#fff", borderRadius: 6, padding: 4 } }));
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function doShare() {
|
|
347
|
+
if (!state.targetId || state.busy) return;
|
|
348
|
+
set({ busy: true, error: "" });
|
|
349
|
+
try {
|
|
350
|
+
// The textarea already shows the redacted text (preview-redact ran on load/toggle),
|
|
351
|
+
// so upload exactly what the user sees; no second redaction on the server.
|
|
352
|
+
const body = { ...(state.payload || {}), targetId: state.targetId, kind: state.kind,
|
|
353
|
+
text: state.text, title: state.title, tags: state.tags, redact: false };
|
|
354
|
+
const r = await getJSON("share", { method: "POST", headers: { "content-type": "application/json" },
|
|
355
|
+
body: JSON.stringify(body) });
|
|
356
|
+
recentAdd(state.targetId);
|
|
357
|
+
set({ result: r, busy: false, redactHits: r.hits || [] });
|
|
358
|
+
} catch (e) {
|
|
359
|
+
set({ busy: false, error: e.message, errorDetail: e.detail || api("share"),
|
|
360
|
+
errorCode: e.kind || "", errorTarget: e.targetId || "", errorProvider: e.providerLabel || "" });
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Dialog component: React-managed re-render via a subscription + tick. */
|
|
365
|
+
let dialogBodyEl = null;
|
|
366
|
+
function ShareDialogHost() {
|
|
367
|
+
const [, setTick] = ctxRef.useState(0);
|
|
368
|
+
ctxRef.useEffect(() => {
|
|
369
|
+
const fn = () => setTick((n) => n + 1);
|
|
370
|
+
listeners.add(fn);
|
|
371
|
+
return () => listeners.delete(fn);
|
|
372
|
+
}, []);
|
|
373
|
+
const result = state.result;
|
|
374
|
+
ctxRef.useEffect(() => {
|
|
375
|
+
// When a share result arrives, scroll the body to reveal the URL/QR block.
|
|
376
|
+
if (result && dialogBodyEl) {
|
|
377
|
+
try { dialogBodyEl.scrollTop = dialogBodyEl.scrollHeight; } catch (e) {}
|
|
378
|
+
}
|
|
379
|
+
}, [result]);
|
|
380
|
+
return shareDialog();
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function shareDialog() {
|
|
384
|
+
if (!state.open) return null;
|
|
385
|
+
if (state.manager) return managerDialog();
|
|
386
|
+
const head = h("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "10px 14px", flexShrink: 0,
|
|
387
|
+
borderBottom: "1px solid var(--border, #34363c)", background: "var(--bg-hover, #25272c)", borderRadius: "9px 9px 0 0" } },
|
|
388
|
+
h("span", { style: { fontWeight: 600 } }, shareT("share.action")),
|
|
389
|
+
h("span", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11 } }, shareT("share.subtitle", { kind: state.kind, chars: state.text.length })),
|
|
390
|
+
h("div", { style: { flex: 1 } }),
|
|
391
|
+
h("button", { type: "button", onClick: () => set({ open: false }),
|
|
392
|
+
style: { background: "none", border: "none", color: "var(--text-muted, #8b909b)", cursor: "pointer", fontSize: 14 } }, "✕"));
|
|
393
|
+
const body = h("div", { ref: (el) => { dialogBodyEl = el; },
|
|
394
|
+
style: { padding: "12px 14px", display: "flex", flexDirection: "column", gap: 12, flex: 1, minHeight: 0, overflowY: "auto" } },
|
|
395
|
+
previewSection(), targetSection(),
|
|
396
|
+
h("div", { style: { display: "grid", gridTemplateColumns: "1fr 1fr", gap: 9 } },
|
|
397
|
+
h("input", { value: state.title, placeholder: shareT("share.titleField"), onInput: (e) => set({ title: e.target.value }),
|
|
398
|
+
style: { background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", color: "var(--text, #d8dade)", borderRadius: 7, padding: "6px 9px", fontSize: 12 } }),
|
|
399
|
+
h("input", { value: state.tags, placeholder: shareT("share.tagsField"), onInput: (e) => set({ tags: e.target.value }),
|
|
400
|
+
style: { background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", color: "var(--text, #d8dade)", borderRadius: 7, padding: "6px 9px", fontSize: 12 } })),
|
|
401
|
+
state.error ? h("div", { style: { border: "1px solid #e05d5d66", background: "#e05d5d18", borderRadius: 8,
|
|
402
|
+
padding: "8px 10px", color: "#e05d5d", fontSize: 12, userSelect: "text", cursor: "text", wordBreak: "break-word" } },
|
|
403
|
+
errorText(),
|
|
404
|
+
state.errorDetail && state.errorDetail !== errorText()
|
|
405
|
+
? h("div", { style: { fontSize: 10, opacity: 0.75, marginTop: 4, fontFamily: "monospace" } }, state.errorDetail) : null,
|
|
406
|
+
state.errorTarget ? h("div", { style: { marginTop: 6 } },
|
|
407
|
+
h("button", { type: "button", onClick: () => set({ manager: true, editing: state.errorTarget } ),
|
|
408
|
+
style: { border: "1px solid #e05d5d", background: "none", color: "#e05d5d", borderRadius: 6,
|
|
409
|
+
padding: "3px 9px", fontSize: 11, cursor: "pointer" } }, shareT("share.fixTarget"))) : null) : null,
|
|
410
|
+
state.result ? resultSection() : null);
|
|
411
|
+
// Footer is pinned outside the scroll area so the action buttons never clip.
|
|
412
|
+
const footer = h("div", { style: { display: "flex", justifyContent: "flex-end", gap: 8, flexShrink: 0,
|
|
413
|
+
padding: "10px 14px", borderTop: "1px solid var(--border, #34363c)", background: "var(--bg-hover, #25272c)" } },
|
|
414
|
+
btn(shareT("share.manage"), () => set({ manager: true,
|
|
415
|
+
...(state.errorTarget ? { editing: state.errorTarget } : {}) })),
|
|
416
|
+
btn(state.busy ? shareT("share.uploading") : shareT("share.action"), doShare, { primary: true, disabled: state.busy }));
|
|
417
|
+
return h("div", { "data-ext-float": "1", "data-ext-float-w": "640", "data-ext-float-h": "520",
|
|
418
|
+
style: { background: "var(--bg-panel, #1e2021)", border: "1px solid var(--border, #34363c)", borderRadius: 10,
|
|
419
|
+
boxShadow: "0 14px 44px #000a", overflow: "hidden", font: "13px/1.5 system-ui, sans-serif", color: "var(--text, #d8dade)",
|
|
420
|
+
display: "flex", flexDirection: "column", maxHeight: "88vh" } }, head, body, footer);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
function managerDialog() {
|
|
424
|
+
const q = state.search.toLowerCase();
|
|
425
|
+
const groups = { recent: [], recommended: [], all: [] };
|
|
426
|
+
const recentIds = recentGet();
|
|
427
|
+
for (const t of state.targets) {
|
|
428
|
+
if (q && !(t.name || t.id).toLowerCase().includes(q)) continue;
|
|
429
|
+
if (recentIds.includes(t.id)) groups.recent.push(t);
|
|
430
|
+
else if (t.recommended) groups.recommended.push(t);
|
|
431
|
+
else groups.all.push(t);
|
|
432
|
+
}
|
|
433
|
+
const item = (t) => h("div", { key: t.id, onClick: () => set({ editing: t.id,
|
|
434
|
+
form: { ...((t.values && !Array.isArray(t.values)) ? t.values : {}) } }),
|
|
435
|
+
style: { display: "flex", alignItems: "center", gap: 7, padding: "5px 8px", borderRadius: 7, cursor: "pointer",
|
|
436
|
+
background: state.editing === t.id ? "rgba(77, 141, 255, 0.15)" : "none", opacity: t.status === "dead" ? 0.5 : 1 } },
|
|
437
|
+
h("span", null, t.status === "dead" ? "💀" : t.category === "archive" ? "📓" : "🔗"),
|
|
438
|
+
h("div", { style: { flex: 1, minWidth: 0 } },
|
|
439
|
+
h("div", { style: { fontSize: 12, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" } }, t.name || t.id),
|
|
440
|
+
h("div", { style: { fontSize: 10, color: "var(--text-muted, #8b909b)" } }, (t.kinds || []).map(kindLabel).join("/") + (t.note ? " · " + t.note : ""))),
|
|
441
|
+
(() => { const b = CFG_BADGE[t.configState]; return b ? h("span", { title: shareT(b.key),
|
|
442
|
+
style: { color: b.color, fontSize: 9, whiteSpace: "nowrap", flexShrink: 0 } }, b.icon) : null; })(),
|
|
443
|
+
t.recommended ? h("span", { style: { color: "var(--accent, #4d8dff)", fontSize: 10 } }, "★") : null,
|
|
444
|
+
// "Use" closes the loop: pick this target for the pending share and return to it.
|
|
445
|
+
t.status !== "dead" && t.configState !== "needs-setup"
|
|
446
|
+
? h("button", { type: "button", title: shareT("share.useTarget"),
|
|
447
|
+
onClick: (e) => { e.stopPropagation(); chooseTarget(t.id); },
|
|
448
|
+
style: { border: "1px solid var(--accent, #4d8dff)", background: state.targetId === t.id ? "var(--accent, #4d8dff)" : "none",
|
|
449
|
+
color: state.targetId === t.id ? "#fff" : "var(--accent, #4d8dff)", borderRadius: 6, padding: "2px 8px",
|
|
450
|
+
fontSize: 10, cursor: "pointer", flexShrink: 0 } }, shareT("share.use"))
|
|
451
|
+
: h("button", { type: "button", title: shareT("share.setupFirst"),
|
|
452
|
+
onClick: (e) => { e.stopPropagation(); set({ editing: t.id, form: {} }); },
|
|
453
|
+
style: { border: "1px solid #d9a13c", background: "none", color: "#d9a13c", borderRadius: 6,
|
|
454
|
+
padding: "2px 8px", fontSize: 10, cursor: "pointer", flexShrink: 0 } }, shareT("share.setup")),
|
|
455
|
+
);
|
|
456
|
+
const edit = state.targets.find((t) => t.id === state.editing);
|
|
457
|
+
const fields = edit?.fields || [];
|
|
458
|
+
const form = edit ? h("div", { style: { flex: 1, padding: 14, display: "flex", flexDirection: "column", gap: 12, overflowY: "auto" } },
|
|
459
|
+
h("div", { style: { fontWeight: 600 } }, edit.name || edit.id),
|
|
460
|
+
edit.note ? h("div", { style: { fontSize: 11, color: "var(--text-muted, #8b909b)" } }, edit.note) : null,
|
|
461
|
+
...fields.map((f) => {
|
|
462
|
+
const key = typeof f === "string" ? f : f.key;
|
|
463
|
+
const label = typeof f === "string" ? f : (f.label || f.key);
|
|
464
|
+
const type = typeof f === "string" ? "password" : (f.type || "text");
|
|
465
|
+
const hint = typeof f === "string" ? "" : (f.hint || "");
|
|
466
|
+
const opts = typeof f === "string" ? null : f.options;
|
|
467
|
+
return h("div", null,
|
|
468
|
+
h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, marginBottom: 3 } }, label + (f.required ? " *" : "")),
|
|
469
|
+
opts ? h("select", { value: state.form[key] ?? edit.values?.[key] ?? opts[0]?.value ?? "",
|
|
470
|
+
onChange: (e) => set({ form: { ...state.form, [key]: e.target.value } }),
|
|
471
|
+
style: { width: "100%", background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", borderRadius: 7, padding: "6px 9px", color: "var(--text, #d8dade)" } },
|
|
472
|
+
...opts.map((o) => h("option", { value: o.value }, o.label)))
|
|
473
|
+
: h("input", { type: type === "password" ? "password" : "text", value: state.form[key] ?? "",
|
|
474
|
+
placeholder: edit.values?.[key] ? shareT("share.notSet") + " " + edit.values[key] : (hint || label),
|
|
475
|
+
onInput: (e) => set({ form: { ...state.form, [key]: e.target.value } }),
|
|
476
|
+
style: { width: "100%", background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", borderRadius: 7, padding: "6px 9px", color: "var(--text, #d8dade)" } }),
|
|
477
|
+
hint ? h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 10, marginTop: 3 } }, hint) : null);
|
|
478
|
+
}),
|
|
479
|
+
fields.length === 0 ? h("div", { style: { fontSize: 12, color: "var(--text-muted, #8b909b)" } },
|
|
480
|
+
shareT("share.noSetup")) : null,
|
|
481
|
+
...(edit.custom ? [btn(shareT("share.deleteTarget"), () => void getJSON(`targets?id=${encodeURIComponent(edit.id)}`, { method: "DELETE" }).then(() => refresh()), { title: shareT("share.delete") })] : []),
|
|
482
|
+
btn(shareT("share.saveTest"), async () => {
|
|
483
|
+
try {
|
|
484
|
+
const saved = await getJSON("targets", { method: "POST", headers: { "content-type": "application/json" },
|
|
485
|
+
body: JSON.stringify({ id: edit.id, provider: edit.provider, name: edit.name, values: { ...edit.values, ...state.form } }) });
|
|
486
|
+
const probe = await getJSON("targets/test", { method: "POST", headers: { "content-type": "application/json" },
|
|
487
|
+
body: JSON.stringify({ provider: edit.provider, values: { ...edit.values, ...state.form } }) });
|
|
488
|
+
set({ error: probe.ok ? shareT("share.testOk") : shareT("share.testFail", { detail: probe.detail || "" }) });
|
|
489
|
+
void refresh(); void saved;
|
|
490
|
+
} catch (e) { set({ error: e.message }); }
|
|
491
|
+
}),
|
|
492
|
+
// After configuring, jump straight back into the share flow with this target.
|
|
493
|
+
btn(shareT("share.saveUse"), async () => {
|
|
494
|
+
try {
|
|
495
|
+
await getJSON("targets", { method: "POST", headers: { "content-type": "application/json" },
|
|
496
|
+
body: JSON.stringify({ id: edit.id, provider: edit.provider, name: edit.name, values: { ...edit.values, ...state.form } }) });
|
|
497
|
+
void refresh();
|
|
498
|
+
chooseTarget(edit.id);
|
|
499
|
+
} catch (e) { set({ error: e.message }); }
|
|
500
|
+
}, { primary: true })) : h("div", { style: { flex: 1, padding: 20, color: "var(--text-muted, #8b909b)" } }, shareT("share.selectTarget"));
|
|
501
|
+
const localProbe = state.probe.length
|
|
502
|
+
? h("div", { style: { background: "#3fbf6e10", border: "1px solid #3fbf6e44", borderRadius: 7, padding: "6px 9px", fontSize: 11, color: "var(--accent, #4d8dff)" } },
|
|
503
|
+
shareT("share.probeDetected", { ports: state.probe.map((p) => ":" + p.port).join(", ") })) : null;
|
|
504
|
+
return h("div", { "data-ext-float": "1", "data-ext-float-w": "820", "data-ext-float-h": "560",
|
|
505
|
+
style: { display: "flex", flexDirection: "column", maxHeight: "88vh", background: "var(--bg-panel, #1e2021)", border: "1px solid var(--border, #34363c)",
|
|
506
|
+
borderRadius: 10, boxShadow: "0 14px 44px #000a", overflow: "hidden", color: "var(--text, #d8dade)", font: "13px/1.5 system-ui" } },
|
|
507
|
+
h("div", { style: { display: "flex", alignItems: "center", gap: 8, padding: "10px 14px", background: "var(--bg-hover, #25272c)", borderBottom: "1px solid var(--border, #34363c)" } },
|
|
508
|
+
// Return to the share flow without losing the pending content.
|
|
509
|
+
h("button", { type: "button", title: shareT("share.backToShare"), onClick: () => set({ manager: false }),
|
|
510
|
+
style: { background: "none", border: "none", color: "var(--accent, #4d8dff)", cursor: "pointer", fontSize: 14 } }, "←"),
|
|
511
|
+
h("span", { style: { fontWeight: 600 } }, shareT("share.targets")),
|
|
512
|
+
h("div", { style: { flex: 1 } }),
|
|
513
|
+
btn("⟳", () => void refresh(true), { title: shareT("share.refresh") }),
|
|
514
|
+
h("button", { type: "button", onClick: () => set({ manager: false, open: false }),
|
|
515
|
+
style: { background: "none", border: "none", color: "var(--text-muted, #8b909b)", cursor: "pointer" } }, "✕")),
|
|
516
|
+
localProbe,
|
|
517
|
+
h("div", { style: { display: "flex", flex: 1, minHeight: 0 } },
|
|
518
|
+
h("div", { style: { width: 300, borderRight: "1px solid var(--border, #34363c)", display: "flex", flexDirection: "column" } },
|
|
519
|
+
h("div", { style: { padding: 8 } }, h("input", { value: state.search, placeholder: shareT("share.search"),
|
|
520
|
+
onInput: (e) => set({ search: e.target.value }),
|
|
521
|
+
style: { width: "100%", background: "var(--bg-hover, #25272c)", border: "1px solid var(--border, #34363c)", borderRadius: 7, padding: "6px 9px", color: "var(--text, #d8dade)", fontSize: 12 } })),
|
|
522
|
+
h("div", { style: { overflow: "auto", flex: 1, padding: "0 8px 10px" } },
|
|
523
|
+
groups.recent.length ? h("div", null, h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "6px" } }, shareT("share.recent")), ...groups.recent.map(item)) : null,
|
|
524
|
+
groups.recommended.length ? h("div", null, h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "6px" } }, shareT("share.recommended")), ...groups.recommended.map(item)) : null,
|
|
525
|
+
h("div", null, h("div", { style: { color: "var(--text-muted, #8b909b)", fontSize: 11, padding: "6px" } }, shareT("share.allTargets", { n: state.targets.length })), ...groups.all.map(item))),
|
|
526
|
+
h("div", { style: { borderTop: "1px solid var(--border, #34363c)", padding: 8, display: "flex", gap: 6 } },
|
|
527
|
+
btn(shareT("share.importSxcu"), () => {
|
|
528
|
+
const text = window.prompt(shareT("share.importPrompt"));
|
|
529
|
+
if (!text) return;
|
|
530
|
+
void getJSON("import-sxcu", { method: "POST", headers: { "content-type": "application/json" },
|
|
531
|
+
body: JSON.stringify({ config: text }) }).then(() => refresh()).catch((e) => set({ error: e.message }));
|
|
532
|
+
}),
|
|
533
|
+
btn(shareT("share.clearRecent"), () => { recentClear(); emit(); }))),
|
|
534
|
+
form),
|
|
535
|
+
state.error ? h("div", { style: { padding: "6px 14px", color: "var(--accent, #4d8dff)", fontSize: 11 } }, state.error) : null);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export default function register(ctx) {
|
|
539
|
+
h = ctx.h;
|
|
540
|
+
ctxRef = ctx;
|
|
541
|
+
tFn = typeof ctx.t === "function" ? ctx.t.bind(ctx) : null;
|
|
542
|
+
if (typeof ctx.apiUrl === "function") apiUrlFn = ctx.apiUrl.bind(ctx);
|
|
543
|
+
|
|
544
|
+
ctx.registerItems("dialogs", [{ id: "aiti-msg-share-dialog", render: () => ShareDialogHost() }]);
|
|
545
|
+
|
|
546
|
+
const shareAction = (label) => (props) => h("button", {
|
|
547
|
+
type: "button", title: label,
|
|
548
|
+
onClick: () => openShare({ kind: "message", text: props?.text || "", sessionId: props?.sessionId }),
|
|
549
|
+
style: { display: "inline-flex", alignItems: "center", gap: 4, padding: "3px 8px", height: 22,
|
|
550
|
+
border: "none", background: "none", borderRadius: 5, color: "var(--text-dim, #8b909b)", cursor: "pointer", fontSize: 11 },
|
|
551
|
+
}, icon("share", 12), label);
|
|
552
|
+
ctx.registerItems("userMessageActions", [{ id: "aiti-msg-share-user", render: shareAction(shareT("share.action")) }]);
|
|
553
|
+
// Assistant messages mount the same share button at both ends (meta.placement):
|
|
554
|
+
// long replies put one end off-screen, so top (meta row) + bottom carry identical buttons.
|
|
555
|
+
ctx.registerItems("assistantMessageActions", [
|
|
556
|
+
{ id: "aiti-msg-share-assistant", render: shareAction(shareT("share.action")) },
|
|
557
|
+
{ id: "aiti-msg-share-assistant-top", render: shareAction(shareT("share.action")), meta: { placement: "top" } },
|
|
558
|
+
]);
|
|
559
|
+
// Session row share lives in session-manager's ⋯ more-menu, not as a bare row
|
|
560
|
+
// button (too many row actions). Registered via that extension's topic contract.
|
|
561
|
+
// (sessionRowActions intentionally not used here.)
|
|
562
|
+
ctx.registerItems("commands", [{ id: "aiti-msg-share.center", render: () => null,
|
|
563
|
+
meta: { label: shareT("share.center"), onClick: () => openShare({ kind: "session" }) } }]);
|
|
564
|
+
|
|
565
|
+
if (typeof ctx.registerExtService === "function") {
|
|
566
|
+
ctx.registerExtService("aiti-msg-share.openShare", (payload) => openShare(payload));
|
|
567
|
+
}
|
|
568
|
+
// msg-smart extension points (topic contracts defined by that extension).
|
|
569
|
+
// Topic registration avoids hard-coded share buttons in msg-smart.
|
|
570
|
+
if (typeof ctx.registerTopicItem === "function") {
|
|
571
|
+
// aiti-editor extension points (contracts defined by that extension):
|
|
572
|
+
// image preview toolbar + file toolbar. No hard-coded share button in editor.
|
|
573
|
+
ctx.registerTopicItem("editor-image-action", {
|
|
574
|
+
id: "aiti-msg-share-image",
|
|
575
|
+
label: shareT("share.action"),
|
|
576
|
+
icon: SHARE_ICON,
|
|
577
|
+
onClick: (img) => openShare({ kind: "image", imageSrc: img.src, filename: img.alt || "image" }),
|
|
578
|
+
});
|
|
579
|
+
ctx.registerTopicItem("editor-file-action", {
|
|
580
|
+
id: "aiti-msg-share-file",
|
|
581
|
+
label: shareT("share.action"),
|
|
582
|
+
icon: SHARE_ICON,
|
|
583
|
+
onClick: (file) => file.selectionText
|
|
584
|
+
? openShare({ kind: "selection", text: file.selectionText, title: file.filePath?.split("/").pop() })
|
|
585
|
+
: openShare({ kind: "file", filePath: file.filePath, filename: file.filePath?.split("/").pop() }),
|
|
586
|
+
});
|
|
587
|
+
// session-manager's ⋯ more-menu action (contract: session-row-menu-action).
|
|
588
|
+
ctx.registerTopicItem("session-row-menu-action", {
|
|
589
|
+
id: "aiti-msg-share-session",
|
|
590
|
+
label: shareT("share.session"),
|
|
591
|
+
title: shareT("share.sessionTip"),
|
|
592
|
+
icon: SHARE_ICON,
|
|
593
|
+
match: () => true,
|
|
594
|
+
onClick: (sess) => openShare({ kind: "session", sessionId: sess?.id,
|
|
595
|
+
session: sess, title: sess?.name || sess?.title || "" }),
|
|
596
|
+
});
|
|
597
|
+
// File card's first-row action (file recognition).
|
|
598
|
+
ctx.registerTopicItem("msg-file-action", {
|
|
599
|
+
id: "aiti-msg-share-file",
|
|
600
|
+
label: shareT("share.action"),
|
|
601
|
+
title: shareT("share.fileTip"),
|
|
602
|
+
icon: SHARE_ICON,
|
|
603
|
+
type: "share",
|
|
604
|
+
match: (abs, isDir) => !isDir,
|
|
605
|
+
onClick: (abs) => openShare({ kind: "file", filePath: abs, filename: abs.split("/").pop() }),
|
|
606
|
+
});
|
|
607
|
+
// Top-row popover action: rendered in the first row after the new-session button
|
|
608
|
+
// (paragraph / code-line / selection cards). Signature: onClick(text, cwd).
|
|
609
|
+
ctx.registerTopicItem("msg-popover-top-action", {
|
|
610
|
+
id: "aiti-msg-share-popover",
|
|
611
|
+
label: shareT("share.action"),
|
|
612
|
+
title: shareT("share.content"),
|
|
613
|
+
icon: SHARE_ICON,
|
|
614
|
+
onClick: (text) => { if (text && text.trim()) openShare({ kind: "selection", text }); },
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
void ctxRef;
|
|
618
|
+
}
|