@clagentic/console 1.0.0-beta.1
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/CREDITS.md +3 -0
- package/LICENSE +21 -0
- package/README.md +250 -0
- package/bin/cli.js +2812 -0
- package/lib/agents-favorites.js +164 -0
- package/lib/agents.js +282 -0
- package/lib/ask-user-mcp-server.js +120 -0
- package/lib/browser-mcp-server.js +484 -0
- package/lib/build-user-env.js +63 -0
- package/lib/certs/fullchain.pem +47 -0
- package/lib/certs/privkey.pem +5 -0
- package/lib/cli-sessions.js +265 -0
- package/lib/codex-defaults.js +18 -0
- package/lib/config.js +332 -0
- package/lib/crisis-safety.js +60 -0
- package/lib/daemon-projects.js +164 -0
- package/lib/daemon.js +1602 -0
- package/lib/dm.js +128 -0
- package/lib/ipc.js +125 -0
- package/lib/ipv4-only.js +39 -0
- package/lib/mcp-local.js +385 -0
- package/lib/notes.js +141 -0
- package/lib/os-users.js +529 -0
- package/lib/pages.js +1325 -0
- package/lib/project-connection.js +302 -0
- package/lib/project-external-trigger.js +236 -0
- package/lib/project-file-watch.js +120 -0
- package/lib/project-filesystem.js +528 -0
- package/lib/project-http.js +753 -0
- package/lib/project-image.js +95 -0
- package/lib/project-knowledge.js +88 -0
- package/lib/project-loop.js +1304 -0
- package/lib/project-mcp.js +374 -0
- package/lib/project-memory.js +39 -0
- package/lib/project-notifications.js +262 -0
- package/lib/project-sessions.js +1581 -0
- package/lib/project-user-mention.js +193 -0
- package/lib/project-user-message.js +628 -0
- package/lib/project.js +1303 -0
- package/lib/public/app.js +1031 -0
- package/lib/public/apple-touch-icon.png +0 -0
- package/lib/public/claude-code-avatar.png +0 -0
- package/lib/public/codex-avatar.png +0 -0
- package/lib/public/console-icon.png +0 -0
- package/lib/public/css/admin.css +736 -0
- package/lib/public/css/agent-picker.css +119 -0
- package/lib/public/css/base.css +235 -0
- package/lib/public/css/channel-layout.css +441 -0
- package/lib/public/css/command-palette.css +559 -0
- package/lib/public/css/debate.css +1609 -0
- package/lib/public/css/diff.css +139 -0
- package/lib/public/css/filebrowser.css +1976 -0
- package/lib/public/css/highlight.css +144 -0
- package/lib/public/css/home-hub.css +545 -0
- package/lib/public/css/icon-strip.css +1856 -0
- package/lib/public/css/input.css +1349 -0
- package/lib/public/css/loop.css +1248 -0
- package/lib/public/css/mention.css +317 -0
- package/lib/public/css/menus.css +857 -0
- package/lib/public/css/messages.css +1833 -0
- package/lib/public/css/mobile-nav.css +1332 -0
- package/lib/public/css/notifications-center.css +296 -0
- package/lib/public/css/overlays.css +1273 -0
- package/lib/public/css/playbook.css +264 -0
- package/lib/public/css/profile.css +397 -0
- package/lib/public/css/rewind.css +671 -0
- package/lib/public/css/scheduler-modal.css +1495 -0
- package/lib/public/css/scheduler.css +1420 -0
- package/lib/public/css/server-settings.css +909 -0
- package/lib/public/css/session-search.css +159 -0
- package/lib/public/css/sidebar.css +2012 -0
- package/lib/public/css/skills.css +789 -0
- package/lib/public/css/sticky-notes.css +854 -0
- package/lib/public/css/stt.css +155 -0
- package/lib/public/css/title-bar.css +674 -0
- package/lib/public/css/tooltip.css +67 -0
- package/lib/public/css/user-settings.css +702 -0
- package/lib/public/emoji-data.json +1 -0
- package/lib/public/favicon-banded-32.png +0 -0
- package/lib/public/favicon-banded.png +0 -0
- package/lib/public/favicon-dark.svg +32 -0
- package/lib/public/favicon.svg +32 -0
- package/lib/public/icon-192.png +0 -0
- package/lib/public/icon-512.png +0 -0
- package/lib/public/icon-banded-76.png +0 -0
- package/lib/public/icon-banded-96.png +0 -0
- package/lib/public/icon-mono.svg +25 -0
- package/lib/public/icons/email/gmail.svg +7 -0
- package/lib/public/icons/email/outlook.svg +35 -0
- package/lib/public/icons/email/yahoo.svg +1 -0
- package/lib/public/index.html +1946 -0
- package/lib/public/manifest.json +27 -0
- package/lib/public/markdown-worker.js +43 -0
- package/lib/public/marked.min.js +6 -0
- package/lib/public/modules/admin.js +954 -0
- package/lib/public/modules/agent-picker.js +429 -0
- package/lib/public/modules/app-connection.js +216 -0
- package/lib/public/modules/app-cursors.js +492 -0
- package/lib/public/modules/app-dm.js +265 -0
- package/lib/public/modules/app-favicon.js +231 -0
- package/lib/public/modules/app-header.js +242 -0
- package/lib/public/modules/app-home-hub.js +432 -0
- package/lib/public/modules/app-loop-ui.js +691 -0
- package/lib/public/modules/app-loop-wizard.js +439 -0
- package/lib/public/modules/app-messages.js +1415 -0
- package/lib/public/modules/app-misc.js +463 -0
- package/lib/public/modules/app-notifications.js +651 -0
- package/lib/public/modules/app-panels.js +1061 -0
- package/lib/public/modules/app-projects.js +875 -0
- package/lib/public/modules/app-rate-limit.js +529 -0
- package/lib/public/modules/app-rendering.js +739 -0
- package/lib/public/modules/app-skills-install.js +285 -0
- package/lib/public/modules/avatar.js +36 -0
- package/lib/public/modules/command-palette.js +491 -0
- package/lib/public/modules/console-logo.js +162 -0
- package/lib/public/modules/context-sources.js +365 -0
- package/lib/public/modules/diff.js +412 -0
- package/lib/public/modules/dom-refs.js +21 -0
- package/lib/public/modules/emoji-picker.js +222 -0
- package/lib/public/modules/events.js +21 -0
- package/lib/public/modules/filebrowser.js +1966 -0
- package/lib/public/modules/fileicons.js +172 -0
- package/lib/public/modules/icons.js +80 -0
- package/lib/public/modules/input.js +1102 -0
- package/lib/public/modules/longpress.js +74 -0
- package/lib/public/modules/markdown.js +486 -0
- package/lib/public/modules/mcp-ui.js +295 -0
- package/lib/public/modules/mention.js +1093 -0
- package/lib/public/modules/notifications.js +613 -0
- package/lib/public/modules/playbook.js +578 -0
- package/lib/public/modules/profile.js +594 -0
- package/lib/public/modules/project-settings.js +849 -0
- package/lib/public/modules/project-switcher.js +375 -0
- package/lib/public/modules/qrcode.js +87 -0
- package/lib/public/modules/rewind.js +381 -0
- package/lib/public/modules/scheduler-config.js +1611 -0
- package/lib/public/modules/scheduler-history.js +131 -0
- package/lib/public/modules/scheduler.js +1689 -0
- package/lib/public/modules/server-settings.js +842 -0
- package/lib/public/modules/session-search.js +456 -0
- package/lib/public/modules/settings-defaults.js +253 -0
- package/lib/public/modules/sidebar-mobile.js +1425 -0
- package/lib/public/modules/sidebar-projects.js +2022 -0
- package/lib/public/modules/sidebar-sessions.js +1548 -0
- package/lib/public/modules/sidebar-users.js +449 -0
- package/lib/public/modules/sidebar.js +348 -0
- package/lib/public/modules/skills.js +793 -0
- package/lib/public/modules/state.js +3 -0
- package/lib/public/modules/sticky-notes.js +1221 -0
- package/lib/public/modules/store.js +34 -0
- package/lib/public/modules/stt.js +266 -0
- package/lib/public/modules/terminal.js +987 -0
- package/lib/public/modules/theme.js +812 -0
- package/lib/public/modules/tool-palette.js +562 -0
- package/lib/public/modules/tools.js +2285 -0
- package/lib/public/modules/tooltip.js +150 -0
- package/lib/public/modules/user-settings.js +544 -0
- package/lib/public/modules/utils.js +56 -0
- package/lib/public/modules/ws-ref.js +26 -0
- package/lib/public/style.css +34 -0
- package/lib/public/sw.js +159 -0
- package/lib/push.js +149 -0
- package/lib/scheduler.js +471 -0
- package/lib/sdk-bridge.js +1792 -0
- package/lib/sdk-message-processor.js +740 -0
- package/lib/sdk-message-queue.js +42 -0
- package/lib/sdk-skill-discovery.js +131 -0
- package/lib/sdk-worker.js +677 -0
- package/lib/server-admin.js +712 -0
- package/lib/server-auth.js +737 -0
- package/lib/server-dm.js +170 -0
- package/lib/server-palette.js +104 -0
- package/lib/server-settings.js +553 -0
- package/lib/server-skills.js +280 -0
- package/lib/server.js +1390 -0
- package/lib/session-search.js +693 -0
- package/lib/sessions.js +946 -0
- package/lib/smtp.js +221 -0
- package/lib/terminal-manager.js +219 -0
- package/lib/terminal.js +39 -0
- package/lib/themes/ayu-light.json +9 -0
- package/lib/themes/catppuccin-latte.json +9 -0
- package/lib/themes/catppuccin-mocha.json +9 -0
- package/lib/themes/clagentic-dark.json +10 -0
- package/lib/themes/clagentic-light.json +10 -0
- package/lib/themes/dracula.json +9 -0
- package/lib/themes/everforest-light.json +9 -0
- package/lib/themes/everforest.json +9 -0
- package/lib/themes/github-light.json +9 -0
- package/lib/themes/gruvbox-dark.json +9 -0
- package/lib/themes/gruvbox-light.json +9 -0
- package/lib/themes/monokai.json +9 -0
- package/lib/themes/nord-light.json +9 -0
- package/lib/themes/nord.json +9 -0
- package/lib/themes/one-dark.json +9 -0
- package/lib/themes/one-light.json +9 -0
- package/lib/themes/rose-pine-dawn.json +9 -0
- package/lib/themes/rose-pine.json +9 -0
- package/lib/themes/solarized-dark.json +9 -0
- package/lib/themes/solarized-light.json +9 -0
- package/lib/themes/tokyo-night-light.json +9 -0
- package/lib/themes/tokyo-night.json +9 -0
- package/lib/updater.js +124 -0
- package/lib/user-presence.js +92 -0
- package/lib/users-auth.js +146 -0
- package/lib/users-permissions.js +118 -0
- package/lib/users-preferences.js +254 -0
- package/lib/users.js +465 -0
- package/lib/utils.js +64 -0
- package/lib/worktree.js +134 -0
- package/lib/ws-schema.js +464 -0
- package/lib/yoke/adapters/claude-worker.js +759 -0
- package/lib/yoke/adapters/claude.js +1599 -0
- package/lib/yoke/adapters/codex.js +1559 -0
- package/lib/yoke/codex-app-server.js +352 -0
- package/lib/yoke/index.js +319 -0
- package/lib/yoke/instructions.js +61 -0
- package/lib/yoke/interface.js +98 -0
- package/lib/yoke/mcp-bridge-server.js +302 -0
- package/lib/yoke/package.json +7 -0
- package/package.json +72 -0
|
@@ -0,0 +1,1093 @@
|
|
|
1
|
+
import { userAvatarUrl } from './avatar.js';
|
|
2
|
+
import { renderMarkdown, highlightCodeBlocks } from './markdown.js';
|
|
3
|
+
import { escapeHtml, copyToClipboard } from './utils.js';
|
|
4
|
+
import { iconHtml, refreshIcons } from './icons.js';
|
|
5
|
+
import { store } from './store.js';
|
|
6
|
+
|
|
7
|
+
var ctx;
|
|
8
|
+
|
|
9
|
+
// --- State ---
|
|
10
|
+
var mentionActive = false; // @ autocomplete is visible
|
|
11
|
+
var mentionAtIdx = -1; // position of the @ in input
|
|
12
|
+
var mentionFiltered = []; // filtered candidate list (mates + users)
|
|
13
|
+
var mentionActiveIdx = -1; // highlighted item in dropdown
|
|
14
|
+
// "kind" = "mate" | "user". Both keep the same chip UX so most existing code
|
|
15
|
+
// branches only on the kind at send time. Variable names retain "Mate" prefix
|
|
16
|
+
// for backwards compatibility with consumers like input.js / app-messages.js.
|
|
17
|
+
var selectedMateKind = null; // "mate" | "user" | null
|
|
18
|
+
var selectedMateId = null; // mate id OR user id
|
|
19
|
+
var selectedMateName = null; // display name
|
|
20
|
+
var selectedMateColor = null; // avatar color for sticky re-apply
|
|
21
|
+
var selectedMateAvatar = null; // avatar src for sticky re-apply
|
|
22
|
+
|
|
23
|
+
// Streaming state
|
|
24
|
+
var currentMentionEl = null; // current mention response DOM element
|
|
25
|
+
var mentionFullText = ""; // accumulated response text
|
|
26
|
+
var mentionStreamBuffer = ""; // stream smoothing buffer
|
|
27
|
+
var mentionDrainTimer = null;
|
|
28
|
+
var activeMentionMeta = null; // { mateId, mateName, avatarColor, avatarStyle, avatarSeed } for reconnect
|
|
29
|
+
var mentionMenuBound = false;
|
|
30
|
+
var mentionCandidatesCache = null;
|
|
31
|
+
var mentionCandidatesCacheKey = "";
|
|
32
|
+
|
|
33
|
+
// --- Init ---
|
|
34
|
+
export function initMention(_ctx) {
|
|
35
|
+
ctx = _ctx;
|
|
36
|
+
if (!mentionMenuBound) {
|
|
37
|
+
mentionMenuBound = true;
|
|
38
|
+
document.addEventListener("click", function (e) {
|
|
39
|
+
var menuEl = document.getElementById("mention-menu");
|
|
40
|
+
if (!menuEl || !menuEl.contains(e.target)) return;
|
|
41
|
+
|
|
42
|
+
var closeBtn = e.target.closest(".mention-close-btn");
|
|
43
|
+
if (closeBtn) {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
hideMentionMenu();
|
|
47
|
+
clearMentionState();
|
|
48
|
+
if (ctx && ctx.inputEl) {
|
|
49
|
+
ctx.inputEl.value = ctx.inputEl.value.replace(/@\S*$/, "");
|
|
50
|
+
ctx.inputEl.focus();
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var item = e.target.closest(".mention-item");
|
|
56
|
+
if (!item) return;
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
e.stopPropagation();
|
|
59
|
+
selectMentionItem(parseInt(item.dataset.idx, 10));
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// --- @ detection ---
|
|
65
|
+
// Called from input.js on each input event.
|
|
66
|
+
// Returns { active, query, startIdx } if @ mention is being typed.
|
|
67
|
+
export function checkForMention(value, cursorPos) {
|
|
68
|
+
// Look backwards from cursor to find an unmatched @
|
|
69
|
+
var i = cursorPos - 1;
|
|
70
|
+
while (i >= 0) {
|
|
71
|
+
var ch = value.charAt(i);
|
|
72
|
+
if (ch === "@") {
|
|
73
|
+
// @ must be at start of input or preceded by whitespace
|
|
74
|
+
if (i === 0 || /\s/.test(value.charAt(i - 1))) {
|
|
75
|
+
var query = value.substring(i + 1, cursorPos);
|
|
76
|
+
// Don't activate if query contains whitespace (user moved past mention)
|
|
77
|
+
if (/\s/.test(query)) break;
|
|
78
|
+
return { active: true, query: query, startIdx: i };
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
if (/\s/.test(ch)) break; // whitespace before finding @ means no mention
|
|
83
|
+
i--;
|
|
84
|
+
}
|
|
85
|
+
return { active: false, query: "", startIdx: -1 };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// --- Autocomplete dropdown ---
|
|
89
|
+
// Build the unified candidate list of mates + users. Each candidate is
|
|
90
|
+
// normalized to { kind, id, name, color, avatarSrc, vendor, bio, primary, raw }.
|
|
91
|
+
// Plain @mention targets. Vendor-only entries with no persona or memory; the
|
|
92
|
+
// server-side handler (lib/project-mate-interaction.js) recognises these IDs
|
|
93
|
+
// and routes them through the matching vendor adapter directly.
|
|
94
|
+
var PLAIN_MENTION_CANDIDATES = [
|
|
95
|
+
{
|
|
96
|
+
kind: "mate",
|
|
97
|
+
id: "plain:claude",
|
|
98
|
+
name: "Claude Code",
|
|
99
|
+
color: "#cc785c",
|
|
100
|
+
avatarSrc: "/claude-code-avatar.png",
|
|
101
|
+
vendor: "claude",
|
|
102
|
+
bio: "Plain Claude Code, no persona, no memory",
|
|
103
|
+
primary: false,
|
|
104
|
+
plain: true,
|
|
105
|
+
raw: null,
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
kind: "mate",
|
|
109
|
+
id: "plain:codex",
|
|
110
|
+
name: "Codex",
|
|
111
|
+
color: "#10a37f",
|
|
112
|
+
avatarSrc: "/codex-avatar.png",
|
|
113
|
+
vendor: "codex",
|
|
114
|
+
bio: "Plain Codex, no persona, no memory",
|
|
115
|
+
primary: false,
|
|
116
|
+
plain: true,
|
|
117
|
+
raw: null,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
function buildMentionCandidates() {
|
|
122
|
+
var allUsers = ctx.allUsers ? ctx.allUsers() : [];
|
|
123
|
+
var myId = ctx.myUserId ? ctx.myUserId() : null;
|
|
124
|
+
var sessionVendor = store.get('currentVendor') || "claude";
|
|
125
|
+
var cacheKey = JSON.stringify({
|
|
126
|
+
myId: myId || "",
|
|
127
|
+
sessionVendor: sessionVendor,
|
|
128
|
+
users: allUsers.map(function (u) {
|
|
129
|
+
return [
|
|
130
|
+
u && u.id || "",
|
|
131
|
+
u && (u.displayName || u.username) || "",
|
|
132
|
+
u && u.username || "",
|
|
133
|
+
u && u.avatarColor || "",
|
|
134
|
+
u && u.avatarStyle || "",
|
|
135
|
+
u && u.avatarSeed || ""
|
|
136
|
+
];
|
|
137
|
+
})
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
if (mentionCandidatesCache && mentionCandidatesCacheKey === cacheKey) {
|
|
141
|
+
return mentionCandidatesCache;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
var candidates = [];
|
|
145
|
+
|
|
146
|
+
// Plain vendor mentions (always available, regardless of Mates toggle).
|
|
147
|
+
// Hide the plain entry that matches the current session's vendor: there is
|
|
148
|
+
// no point asking Claude for a second opinion while you are already in a
|
|
149
|
+
// Claude session, and likewise for Codex.
|
|
150
|
+
for (var pi = 0; pi < PLAIN_MENTION_CANDIDATES.length; pi++) {
|
|
151
|
+
if (PLAIN_MENTION_CANDIDATES[pi].vendor === sessionVendor) continue;
|
|
152
|
+
candidates.push(PLAIN_MENTION_CANDIDATES[pi]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Users: every other signed-in user (always available).
|
|
156
|
+
// We use the cached user list pushed by the server in projects_updated.
|
|
157
|
+
for (var ui = 0; ui < allUsers.length; ui++) {
|
|
158
|
+
var u = allUsers[ui];
|
|
159
|
+
if (!u || !u.id) continue;
|
|
160
|
+
if (myId && u.id === myId) continue; // never @-mention yourself
|
|
161
|
+
candidates.push({
|
|
162
|
+
kind: "user",
|
|
163
|
+
id: u.id,
|
|
164
|
+
name: u.displayName || u.username || "User",
|
|
165
|
+
color: u.avatarColor || "#7c3aed",
|
|
166
|
+
// Build dicebear url from style+seed; matches userAvatarUrl shape.
|
|
167
|
+
avatarSrc: "https://api.dicebear.com/7.x/" + (u.avatarStyle || "thumbs") + "/svg?seed=" + encodeURIComponent(u.avatarSeed || u.username || u.id),
|
|
168
|
+
vendor: null,
|
|
169
|
+
bio: u.username ? "@" + u.username : "",
|
|
170
|
+
primary: false,
|
|
171
|
+
raw: u,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
mentionCandidatesCache = candidates;
|
|
176
|
+
mentionCandidatesCacheKey = cacheKey;
|
|
177
|
+
return candidates;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function showMentionMenu(query) {
|
|
181
|
+
var candidates = buildMentionCandidates();
|
|
182
|
+
if (candidates.length === 0) {
|
|
183
|
+
hideMentionMenu();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var lowerQuery = (query || "").toLowerCase();
|
|
188
|
+
mentionFiltered = candidates.filter(function (c) {
|
|
189
|
+
if (!lowerQuery) return true;
|
|
190
|
+
if (c.name.toLowerCase().indexOf(lowerQuery) !== -1) return true;
|
|
191
|
+
if (c.kind === "user" && c.raw && c.raw.username && c.raw.username.toLowerCase().indexOf(lowerQuery) !== -1) return true;
|
|
192
|
+
return false;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (mentionFiltered.length === 0) {
|
|
196
|
+
hideMentionMenu();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
mentionActive = true;
|
|
201
|
+
mentionActiveIdx = 0;
|
|
202
|
+
|
|
203
|
+
var menuEl = document.getElementById("mention-menu");
|
|
204
|
+
if (!menuEl) return;
|
|
205
|
+
|
|
206
|
+
menuEl.innerHTML = '<div class="mention-hint">Mention a Mate or teammate — the coding agent stays out of this exchange until your next message<button class="mention-close-btn" aria-label="Close">×</button></div>' +
|
|
207
|
+
mentionFiltered.map(function (c, i) {
|
|
208
|
+
var vendorIcons = { claude: "/claude-code-avatar.png", codex: "/codex-avatar.png" };
|
|
209
|
+
var vendorBadge = (c.kind === "mate" && vendorIcons[c.vendor]) ? '<img class="mention-item-vendor-badge" src="' + vendorIcons[c.vendor] + '" alt="' + escapeHtml(c.vendor) + '">' : '';
|
|
210
|
+
var kindBadge = c.kind === "user"
|
|
211
|
+
? ' <span class="mention-item-badge mention-item-badge-user">USER</span>'
|
|
212
|
+
: (c.plain ? ' <span class="mention-item-badge">PLAIN</span>'
|
|
213
|
+
: (c.primary ? ' <span class="mention-item-badge">SYSTEM</span>' : ''));
|
|
214
|
+
return '<div class="mention-item' + (i === 0 ? ' active' : '') + '" data-idx="' + i + '">' +
|
|
215
|
+
'<div class="mention-item-avatar-wrap"><img class="mention-item-avatar" src="' + escapeHtml(c.avatarSrc) + '" width="24" height="24" />' + vendorBadge + '</div>' +
|
|
216
|
+
'<div class="mention-item-info">' +
|
|
217
|
+
'<span class="mention-item-name">' + escapeHtml(c.name) + kindBadge + '</span>' +
|
|
218
|
+
(c.bio ? '<span class="mention-item-bio">' + escapeHtml(c.bio) + '</span>' : '') +
|
|
219
|
+
'</div>' +
|
|
220
|
+
'<span class="mention-item-dot" style="background:' + escapeHtml(c.color) + '"></span>' +
|
|
221
|
+
'</div>';
|
|
222
|
+
}).join("");
|
|
223
|
+
menuEl.classList.add("visible");
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function hideMentionMenu() {
|
|
227
|
+
if (!mentionActive && mentionFiltered.length === 0) return; // already hidden
|
|
228
|
+
mentionActive = false;
|
|
229
|
+
mentionActiveIdx = -1;
|
|
230
|
+
mentionFiltered = [];
|
|
231
|
+
var menuEl = document.getElementById("mention-menu");
|
|
232
|
+
if (menuEl) {
|
|
233
|
+
menuEl.classList.remove("visible");
|
|
234
|
+
menuEl.innerHTML = "";
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function isMentionMenuVisible() {
|
|
239
|
+
return mentionActive && mentionFiltered.length > 0;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function mentionMenuKeydown(e) {
|
|
243
|
+
if (!mentionActive || mentionFiltered.length === 0) return false;
|
|
244
|
+
|
|
245
|
+
if (e.key === "ArrowDown") {
|
|
246
|
+
e.preventDefault();
|
|
247
|
+
mentionActiveIdx = (mentionActiveIdx + 1) % mentionFiltered.length;
|
|
248
|
+
updateMentionHighlight();
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
if (e.key === "ArrowUp") {
|
|
252
|
+
e.preventDefault();
|
|
253
|
+
mentionActiveIdx = (mentionActiveIdx - 1 + mentionFiltered.length) % mentionFiltered.length;
|
|
254
|
+
updateMentionHighlight();
|
|
255
|
+
return true;
|
|
256
|
+
}
|
|
257
|
+
if (e.key === "Tab" || (e.key === "Enter" && !e.shiftKey)) {
|
|
258
|
+
e.preventDefault();
|
|
259
|
+
selectMentionItem(mentionActiveIdx);
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
if (e.key === "Escape") {
|
|
263
|
+
e.preventDefault();
|
|
264
|
+
hideMentionMenu();
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function selectMentionItem(idx) {
|
|
271
|
+
if (idx < 0 || idx >= mentionFiltered.length) return;
|
|
272
|
+
var c = mentionFiltered[idx];
|
|
273
|
+
// mentionFiltered now holds normalized candidates ({ kind, id, name, color, avatarSrc, ... }).
|
|
274
|
+
var avatarSrc = c.avatarSrc;
|
|
275
|
+
|
|
276
|
+
selectedMateKind = c.kind;
|
|
277
|
+
selectedMateId = c.id;
|
|
278
|
+
selectedMateName = c.name;
|
|
279
|
+
selectedMateColor = c.color;
|
|
280
|
+
selectedMateAvatar = avatarSrc;
|
|
281
|
+
|
|
282
|
+
// Remove the @query text from the textarea, keep remaining text
|
|
283
|
+
if (ctx.inputEl && mentionAtIdx >= 0) {
|
|
284
|
+
var val = ctx.inputEl.value;
|
|
285
|
+
var cursorPos = ctx.inputEl.selectionStart;
|
|
286
|
+
var before = val.substring(0, mentionAtIdx);
|
|
287
|
+
var after = val.substring(cursorPos);
|
|
288
|
+
ctx.inputEl.value = (before + after).trim();
|
|
289
|
+
ctx.inputEl.selectionStart = ctx.inputEl.selectionEnd = 0;
|
|
290
|
+
ctx.inputEl.focus();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Show visual chip in input area
|
|
294
|
+
showInputMentionChip(selectedMateName, selectedMateColor, avatarSrc);
|
|
295
|
+
|
|
296
|
+
hideMentionMenu();
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function ensureChipContrast(hex) {
|
|
300
|
+
if (!hex || hex.charAt(0) !== "#") return hex;
|
|
301
|
+
var r = parseInt(hex.substring(1, 3), 16);
|
|
302
|
+
var g = parseInt(hex.substring(3, 5), 16);
|
|
303
|
+
var b = parseInt(hex.substring(5, 7), 16);
|
|
304
|
+
// Relative luminance (sRGB)
|
|
305
|
+
var lum = (0.299 * r + 0.587 * g + 0.114 * b) / 255;
|
|
306
|
+
var isDark = document.documentElement.classList.contains("dark") ||
|
|
307
|
+
document.body.classList.contains("dark-mode");
|
|
308
|
+
if (isDark) {
|
|
309
|
+
// Dark mode: lighten if too dark
|
|
310
|
+
return lum < 0.4 ? color_mix_lighten(r, g, b, 0.35) : hex;
|
|
311
|
+
}
|
|
312
|
+
// Light mode: darken if too bright
|
|
313
|
+
return lum > 0.55 ? color_mix_darken(r, g, b, 0.4) : hex;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function color_mix_darken(r, g, b, amount) {
|
|
317
|
+
var f = 1 - amount;
|
|
318
|
+
return "#" + [Math.round(r * f), Math.round(g * f), Math.round(b * f)]
|
|
319
|
+
.map(function (v) { return v.toString(16).padStart(2, "0"); }).join("");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function color_mix_lighten(r, g, b, amount) {
|
|
323
|
+
return "#" + [Math.round(r + (255 - r) * amount), Math.round(g + (255 - g) * amount), Math.round(b + (255 - b) * amount)]
|
|
324
|
+
.map(function (v) { return v.toString(16).padStart(2, "0"); }).join("");
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Saved textarea placeholder so we can restore it when the chip is removed.
|
|
328
|
+
// Set on first chip show, cleared on chip removal.
|
|
329
|
+
var savedInputPlaceholder = null;
|
|
330
|
+
|
|
331
|
+
function showInputMentionChip(name, color, avatarSrc) {
|
|
332
|
+
removeInputMentionChip();
|
|
333
|
+
var textColor = ensureChipContrast(color);
|
|
334
|
+
var chip = document.createElement("div");
|
|
335
|
+
chip.id = "input-mention-chip";
|
|
336
|
+
chip.innerHTML =
|
|
337
|
+
'<img class="input-mention-chip-avatar" src="' + escapeHtml(avatarSrc) + '" width="18" height="18" />' +
|
|
338
|
+
'<span class="input-mention-chip-name" style="color:' + escapeHtml(textColor) + '">@' + escapeHtml(name) + '</span>' +
|
|
339
|
+
'<button class="input-mention-chip-remove" type="button" aria-label="Remove mention">×</button>';
|
|
340
|
+
chip.style.setProperty("--chip-color", color);
|
|
341
|
+
|
|
342
|
+
// Insert before the textarea wrapper inside input-row
|
|
343
|
+
var inputRow = document.getElementById("input-row");
|
|
344
|
+
var textareaWrap = document.getElementById("input-textarea-wrap");
|
|
345
|
+
if (inputRow && textareaWrap) {
|
|
346
|
+
inputRow.insertBefore(chip, textareaWrap);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// Swap the textarea placeholder so the user sees "Ask @{name}..." instead of
|
|
350
|
+
// the session-vendor placeholder ("Message Claude Code...") while a mention
|
|
351
|
+
// is queued. Save the original once so re-shows don't clobber it.
|
|
352
|
+
if (ctx && ctx.inputEl) {
|
|
353
|
+
if (savedInputPlaceholder === null) {
|
|
354
|
+
savedInputPlaceholder = ctx.inputEl.placeholder || "";
|
|
355
|
+
}
|
|
356
|
+
ctx.inputEl.placeholder = "Ask @" + name + "...";
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
chip.querySelector(".input-mention-chip-remove").addEventListener("click", function (e) {
|
|
360
|
+
e.preventDefault();
|
|
361
|
+
e.stopPropagation();
|
|
362
|
+
removeMentionChip();
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function removeInputMentionChip() {
|
|
367
|
+
var existing = document.getElementById("input-mention-chip");
|
|
368
|
+
if (existing) existing.remove();
|
|
369
|
+
if (ctx && ctx.inputEl && savedInputPlaceholder !== null) {
|
|
370
|
+
ctx.inputEl.placeholder = savedInputPlaceholder;
|
|
371
|
+
savedInputPlaceholder = null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export function removeMentionChip() {
|
|
376
|
+
removeInputMentionChip();
|
|
377
|
+
selectedMateKind = null;
|
|
378
|
+
selectedMateId = null;
|
|
379
|
+
selectedMateName = null;
|
|
380
|
+
selectedMateColor = null;
|
|
381
|
+
selectedMateAvatar = null;
|
|
382
|
+
if (ctx.inputEl) ctx.inputEl.focus();
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
function updateMentionHighlight() {
|
|
386
|
+
var menuEl = document.getElementById("mention-menu");
|
|
387
|
+
if (!menuEl) return;
|
|
388
|
+
menuEl.querySelectorAll(".mention-item").forEach(function (el, i) {
|
|
389
|
+
el.classList.toggle("active", i === mentionActiveIdx);
|
|
390
|
+
});
|
|
391
|
+
var activeEl = menuEl.querySelector(".mention-item.active");
|
|
392
|
+
if (activeEl) activeEl.scrollIntoView({ block: "nearest" });
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// Store the @ position when check detects mention
|
|
396
|
+
export function setMentionAtIdx(idx) {
|
|
397
|
+
mentionAtIdx = idx;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// --- Mention send ---
|
|
401
|
+
// Returns { kind, mateId, userId, mateName, text } if input has an @mention, or null.
|
|
402
|
+
// `mateId` and `userId` are kept as separate fields so call sites can dispatch
|
|
403
|
+
// to the right server message type without inspecting `kind` (legacy callers
|
|
404
|
+
// that only read `mateId` keep working for mate mentions).
|
|
405
|
+
export function parseMentionFromInput(text) {
|
|
406
|
+
if (!selectedMateId || !selectedMateName) return null;
|
|
407
|
+
// The chip is shown separately; textarea contains only the message text
|
|
408
|
+
var mentionText = (text || "").trim();
|
|
409
|
+
if (!mentionText) return null;
|
|
410
|
+
var kind = selectedMateKind || "mate";
|
|
411
|
+
return {
|
|
412
|
+
kind: kind,
|
|
413
|
+
mateId: kind === "mate" ? selectedMateId : null,
|
|
414
|
+
userId: kind === "user" ? selectedMateId : null,
|
|
415
|
+
mateName: selectedMateName,
|
|
416
|
+
text: mentionText,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
export function clearMentionState() {
|
|
421
|
+
selectedMateKind = null;
|
|
422
|
+
selectedMateId = null;
|
|
423
|
+
selectedMateName = null;
|
|
424
|
+
selectedMateColor = null;
|
|
425
|
+
selectedMateAvatar = null;
|
|
426
|
+
mentionAtIdx = -1;
|
|
427
|
+
removeInputMentionChip();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// Re-apply the same mention after sending (sticky mention).
|
|
431
|
+
// Keeps the chip visible so the next message also goes to the same target.
|
|
432
|
+
export function stickyReapplyMention() {
|
|
433
|
+
if (!selectedMateId || !selectedMateName) return;
|
|
434
|
+
var kind = selectedMateKind;
|
|
435
|
+
var id = selectedMateId;
|
|
436
|
+
var name = selectedMateName;
|
|
437
|
+
var color = selectedMateColor || "#6c5ce7";
|
|
438
|
+
var avatarSrc = selectedMateAvatar || "";
|
|
439
|
+
// Reset index but keep selection
|
|
440
|
+
mentionAtIdx = -1;
|
|
441
|
+
removeInputMentionChip();
|
|
442
|
+
selectedMateKind = kind;
|
|
443
|
+
selectedMateId = id;
|
|
444
|
+
selectedMateName = name;
|
|
445
|
+
selectedMateColor = color;
|
|
446
|
+
selectedMateAvatar = avatarSrc;
|
|
447
|
+
showInputMentionChip(name, color, avatarSrc);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// Send a mate @mention. Existing call sites keep using this verbatim.
|
|
451
|
+
export function sendMention(mateId, text, pastes, images) {
|
|
452
|
+
if (!ctx.ws || !ctx.connected) return;
|
|
453
|
+
var payload = { type: "mention", mateId: mateId, text: text };
|
|
454
|
+
if (pastes && pastes.length > 0) payload.pastes = pastes;
|
|
455
|
+
if (images && images.length > 0) payload.images = images;
|
|
456
|
+
ctx.ws.send(JSON.stringify(payload));
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Send a user-to-user @mention. Server stores it in session.history, broadcasts
|
|
460
|
+
// to other session viewers, fires an alarm-center notification + push for the
|
|
461
|
+
// target user, and queues the transcript for the next coding-agent turn.
|
|
462
|
+
export function sendUserMention(userId, text, pastes, images) {
|
|
463
|
+
if (!ctx.ws || !ctx.connected) return;
|
|
464
|
+
var payload = { type: "user_mention", targetUserId: userId, text: text };
|
|
465
|
+
if (pastes && pastes.length > 0) payload.pastes = pastes;
|
|
466
|
+
if (images && images.length > 0) payload.images = images;
|
|
467
|
+
ctx.ws.send(JSON.stringify(payload));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// --- Mention response rendering ---
|
|
471
|
+
|
|
472
|
+
// Recreate the mention block if it was lost (e.g. session switch)
|
|
473
|
+
function ensureMentionBlock() {
|
|
474
|
+
if (currentMentionEl && currentMentionEl.parentNode) {
|
|
475
|
+
// If other elements (e.g. permission requests) were added after the mention
|
|
476
|
+
// block, move it to the bottom to maintain chronological order.
|
|
477
|
+
var parent = currentMentionEl.parentNode;
|
|
478
|
+
if (parent.lastElementChild !== currentMentionEl) {
|
|
479
|
+
parent.appendChild(currentMentionEl);
|
|
480
|
+
if (ctx.scrollToBottom) ctx.scrollToBottom();
|
|
481
|
+
}
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
if (!activeMentionMeta) return;
|
|
485
|
+
// Recreate from saved meta
|
|
486
|
+
handleMentionStart(activeMentionMeta);
|
|
487
|
+
// Re-render any accumulated text
|
|
488
|
+
if (mentionFullText) {
|
|
489
|
+
var contentEl = currentMentionEl.querySelector(".mention-content");
|
|
490
|
+
if (contentEl) {
|
|
491
|
+
contentEl.innerHTML = renderMarkdown(mentionFullText);
|
|
492
|
+
highlightCodeBlocks(contentEl);
|
|
493
|
+
}
|
|
494
|
+
// Hide activity bar since we have text
|
|
495
|
+
var bar = currentMentionEl.querySelector(".mention-activity-bar");
|
|
496
|
+
if (bar) bar.style.display = "none";
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export function handleMentionStart(msg) {
|
|
501
|
+
// Save meta for potential reconnect after session switch
|
|
502
|
+
activeMentionMeta = {
|
|
503
|
+
mateId: msg.mateId,
|
|
504
|
+
mateName: msg.mateName,
|
|
505
|
+
avatarColor: msg.avatarColor,
|
|
506
|
+
avatarStyle: msg.avatarStyle,
|
|
507
|
+
avatarSeed: msg.avatarSeed,
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
var avatarSrc = buildMentionAvatarUrl(msg);
|
|
511
|
+
|
|
512
|
+
if (isDmLayout()) {
|
|
513
|
+
// DM-style: render as DM-style assistant message (Mate DM or Wide view)
|
|
514
|
+
currentMentionEl = document.createElement("div");
|
|
515
|
+
currentMentionEl.className = "msg-assistant msg-mention-dm";
|
|
516
|
+
|
|
517
|
+
var avi = document.createElement("img");
|
|
518
|
+
avi.className = "dm-bubble-avatar dm-bubble-avatar-mate";
|
|
519
|
+
avi.src = avatarSrc;
|
|
520
|
+
currentMentionEl.appendChild(avi);
|
|
521
|
+
|
|
522
|
+
var contentWrap = document.createElement("div");
|
|
523
|
+
contentWrap.className = "dm-bubble-content";
|
|
524
|
+
|
|
525
|
+
var header = document.createElement("div");
|
|
526
|
+
header.className = "dm-bubble-header";
|
|
527
|
+
var nameSpan = document.createElement("span");
|
|
528
|
+
nameSpan.className = "dm-bubble-name";
|
|
529
|
+
nameSpan.style.color = msg.avatarColor || "#6c5ce7";
|
|
530
|
+
nameSpan.textContent = msg.mateName || "Mate";
|
|
531
|
+
header.appendChild(nameSpan);
|
|
532
|
+
|
|
533
|
+
var badge = document.createElement("span");
|
|
534
|
+
badge.className = "mention-badge";
|
|
535
|
+
badge.textContent = "@MENTION";
|
|
536
|
+
header.appendChild(badge);
|
|
537
|
+
|
|
538
|
+
var stopBtn = document.createElement("button");
|
|
539
|
+
stopBtn.className = "mention-stop-btn";
|
|
540
|
+
stopBtn.title = "Stop";
|
|
541
|
+
stopBtn.textContent = "Stop";
|
|
542
|
+
stopBtn.addEventListener("click", function () {
|
|
543
|
+
if (ctx.ws && ctx.connected) {
|
|
544
|
+
ctx.ws.send(JSON.stringify({ type: "mention_stop", mateId: msg.mateId }));
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
header.appendChild(stopBtn);
|
|
548
|
+
contentWrap.appendChild(header);
|
|
549
|
+
|
|
550
|
+
// Activity indicator
|
|
551
|
+
var activityDiv = document.createElement("div");
|
|
552
|
+
activityDiv.className = "activity-inline mention-activity-bar";
|
|
553
|
+
activityDiv.innerHTML =
|
|
554
|
+
'<span class="activity-icon">' + iconHtml("sparkles") + '</span>' +
|
|
555
|
+
'<span class="activity-text">Thinking...</span>';
|
|
556
|
+
contentWrap.appendChild(activityDiv);
|
|
557
|
+
|
|
558
|
+
// Content area for streamed markdown
|
|
559
|
+
var contentDiv = document.createElement("div");
|
|
560
|
+
contentDiv.className = "md-content mention-content";
|
|
561
|
+
contentDiv.dir = "auto";
|
|
562
|
+
contentWrap.appendChild(contentDiv);
|
|
563
|
+
|
|
564
|
+
currentMentionEl.appendChild(contentWrap);
|
|
565
|
+
} else {
|
|
566
|
+
// Project chat: mention block style
|
|
567
|
+
currentMentionEl = document.createElement("div");
|
|
568
|
+
currentMentionEl.className = "msg-mention";
|
|
569
|
+
currentMentionEl.style.setProperty("--mention-color", msg.avatarColor || "#6c5ce7");
|
|
570
|
+
|
|
571
|
+
var header = document.createElement("div");
|
|
572
|
+
header.className = "mention-header";
|
|
573
|
+
|
|
574
|
+
var avatar = document.createElement("img");
|
|
575
|
+
avatar.className = "mention-avatar";
|
|
576
|
+
avatar.src = avatarSrc;
|
|
577
|
+
avatar.width = 20;
|
|
578
|
+
avatar.height = 20;
|
|
579
|
+
header.appendChild(avatar);
|
|
580
|
+
|
|
581
|
+
var nameSpan = document.createElement("span");
|
|
582
|
+
nameSpan.className = "mention-name";
|
|
583
|
+
nameSpan.textContent = msg.mateName || "Mate";
|
|
584
|
+
header.appendChild(nameSpan);
|
|
585
|
+
|
|
586
|
+
var stopBtn = document.createElement("button");
|
|
587
|
+
stopBtn.className = "mention-stop-btn";
|
|
588
|
+
stopBtn.title = "Stop";
|
|
589
|
+
stopBtn.textContent = "Stop";
|
|
590
|
+
stopBtn.addEventListener("click", function () {
|
|
591
|
+
if (ctx.ws && ctx.connected) {
|
|
592
|
+
ctx.ws.send(JSON.stringify({ type: "mention_stop", mateId: msg.mateId }));
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
header.appendChild(stopBtn);
|
|
596
|
+
|
|
597
|
+
currentMentionEl.appendChild(header);
|
|
598
|
+
|
|
599
|
+
// Activity indicator
|
|
600
|
+
var activityDiv = document.createElement("div");
|
|
601
|
+
activityDiv.className = "activity-inline mention-activity-bar";
|
|
602
|
+
activityDiv.innerHTML =
|
|
603
|
+
'<span class="activity-icon">' + iconHtml("sparkles") + '</span>' +
|
|
604
|
+
'<span class="activity-text">Thinking...</span>';
|
|
605
|
+
currentMentionEl.appendChild(activityDiv);
|
|
606
|
+
|
|
607
|
+
// Content area for streamed markdown
|
|
608
|
+
var contentDiv = document.createElement("div");
|
|
609
|
+
contentDiv.className = "md-content mention-content";
|
|
610
|
+
contentDiv.dir = "auto";
|
|
611
|
+
currentMentionEl.appendChild(contentDiv);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
mentionFullText = "";
|
|
615
|
+
mentionStreamBuffer = "";
|
|
616
|
+
|
|
617
|
+
if (ctx.messagesEl) {
|
|
618
|
+
ctx.messagesEl.appendChild(currentMentionEl);
|
|
619
|
+
refreshIcons();
|
|
620
|
+
if (ctx.scrollToBottom) ctx.scrollToBottom();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
export function handleMentionActivity(msg) {
|
|
625
|
+
ensureMentionBlock();
|
|
626
|
+
if (!currentMentionEl) return;
|
|
627
|
+
var bar = currentMentionEl.querySelector(".mention-activity-bar");
|
|
628
|
+
if (msg.activity) {
|
|
629
|
+
// Show or update activity
|
|
630
|
+
if (!bar) {
|
|
631
|
+
bar = document.createElement("div");
|
|
632
|
+
bar.className = "activity-inline mention-activity-bar";
|
|
633
|
+
bar.innerHTML =
|
|
634
|
+
'<span class="activity-icon">' + iconHtml("sparkles") + '</span>' +
|
|
635
|
+
'<span class="activity-text"></span>';
|
|
636
|
+
var contentEl = currentMentionEl.querySelector(".mention-content");
|
|
637
|
+
if (contentEl) {
|
|
638
|
+
currentMentionEl.insertBefore(bar, contentEl);
|
|
639
|
+
} else {
|
|
640
|
+
currentMentionEl.appendChild(bar);
|
|
641
|
+
}
|
|
642
|
+
refreshIcons();
|
|
643
|
+
}
|
|
644
|
+
var textEl = bar.querySelector(".activity-text");
|
|
645
|
+
if (textEl) {
|
|
646
|
+
textEl.textContent = msg.activity === "thinking" ? "Thinking..." : msg.activity;
|
|
647
|
+
}
|
|
648
|
+
bar.style.display = "";
|
|
649
|
+
} else {
|
|
650
|
+
if (bar) bar.style.display = "none";
|
|
651
|
+
}
|
|
652
|
+
if (ctx.scrollToBottom) ctx.scrollToBottom();
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
export function handleMentionStream(msg) {
|
|
656
|
+
ensureMentionBlock();
|
|
657
|
+
if (!currentMentionEl) return;
|
|
658
|
+
|
|
659
|
+
// Hide activity bar on first text delta
|
|
660
|
+
var bar = currentMentionEl.querySelector(".mention-activity-bar");
|
|
661
|
+
if (bar) bar.style.display = "none";
|
|
662
|
+
|
|
663
|
+
mentionStreamBuffer += msg.delta;
|
|
664
|
+
if (!mentionDrainTimer) {
|
|
665
|
+
mentionDrainTimer = requestAnimationFrame(drainMentionStream);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
function drainMentionStream() {
|
|
670
|
+
mentionDrainTimer = null;
|
|
671
|
+
if (!currentMentionEl || mentionStreamBuffer.length === 0) return;
|
|
672
|
+
|
|
673
|
+
var len = mentionStreamBuffer.length;
|
|
674
|
+
var n;
|
|
675
|
+
if (len > 200) n = Math.ceil(len / 4);
|
|
676
|
+
else if (len > 80) n = 8;
|
|
677
|
+
else if (len > 30) n = 5;
|
|
678
|
+
else if (len > 10) n = 2;
|
|
679
|
+
else n = 1;
|
|
680
|
+
|
|
681
|
+
var chunk = mentionStreamBuffer.slice(0, n);
|
|
682
|
+
mentionStreamBuffer = mentionStreamBuffer.slice(n);
|
|
683
|
+
mentionFullText += chunk;
|
|
684
|
+
|
|
685
|
+
var contentEl = currentMentionEl.querySelector(".mention-content");
|
|
686
|
+
if (contentEl) {
|
|
687
|
+
contentEl.innerHTML = renderMarkdown(mentionFullText);
|
|
688
|
+
highlightCodeBlocks(contentEl);
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
if (ctx.scrollToBottom) ctx.scrollToBottom();
|
|
692
|
+
|
|
693
|
+
if (mentionStreamBuffer.length > 0) {
|
|
694
|
+
mentionDrainTimer = requestAnimationFrame(drainMentionStream);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function flushMentionStream() {
|
|
699
|
+
if (mentionDrainTimer) {
|
|
700
|
+
cancelAnimationFrame(mentionDrainTimer);
|
|
701
|
+
mentionDrainTimer = null;
|
|
702
|
+
}
|
|
703
|
+
if (mentionStreamBuffer.length > 0) {
|
|
704
|
+
mentionFullText += mentionStreamBuffer;
|
|
705
|
+
mentionStreamBuffer = "";
|
|
706
|
+
}
|
|
707
|
+
if (currentMentionEl) {
|
|
708
|
+
var contentEl = currentMentionEl.querySelector(".mention-content");
|
|
709
|
+
if (contentEl) {
|
|
710
|
+
contentEl.innerHTML = renderMarkdown(mentionFullText);
|
|
711
|
+
highlightCodeBlocks(contentEl);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
export function handleMentionDone(msg) {
|
|
717
|
+
flushMentionStream();
|
|
718
|
+
if (currentMentionEl) {
|
|
719
|
+
var bar = currentMentionEl.querySelector(".mention-activity-bar");
|
|
720
|
+
if (bar) bar.style.display = "none";
|
|
721
|
+
// Remove stop button
|
|
722
|
+
var stopBtn = currentMentionEl.querySelector(".mention-stop-btn");
|
|
723
|
+
if (stopBtn) stopBtn.remove();
|
|
724
|
+
// Add copy handler so user can "click to grab this"
|
|
725
|
+
if (ctx.addCopyHandler && mentionFullText) {
|
|
726
|
+
ctx.addCopyHandler(currentMentionEl, mentionFullText);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
currentMentionEl = null;
|
|
730
|
+
activeMentionMeta = null;
|
|
731
|
+
mentionFullText = "";
|
|
732
|
+
if (ctx.scrollToBottom) ctx.scrollToBottom();
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
export function handleMentionError(msg) {
|
|
736
|
+
flushMentionStream();
|
|
737
|
+
if (currentMentionEl) {
|
|
738
|
+
var bar = currentMentionEl.querySelector(".mention-activity-bar");
|
|
739
|
+
if (bar) bar.style.display = "none";
|
|
740
|
+
var stopBtn = currentMentionEl.querySelector(".mention-stop-btn");
|
|
741
|
+
if (stopBtn) stopBtn.remove();
|
|
742
|
+
var contentEl = currentMentionEl.querySelector(".mention-content");
|
|
743
|
+
if (contentEl) {
|
|
744
|
+
contentEl.innerHTML = '<div class="mention-error">Error: ' + escapeHtml(msg.error || "Unknown error") + '</div>';
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
currentMentionEl = null;
|
|
748
|
+
activeMentionMeta = null;
|
|
749
|
+
mentionFullText = "";
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// --- Helpers ---
|
|
753
|
+
function isWideView() {
|
|
754
|
+
return document.body.classList.contains("wide-view");
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
function isDmLayout() {
|
|
758
|
+
return isWideView();
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function getMyAvatarSrc() {
|
|
762
|
+
if (document.body.dataset.myAvatarUrl) return document.body.dataset.myAvatarUrl;
|
|
763
|
+
var myUser = null;
|
|
764
|
+
try { myUser = JSON.parse(localStorage.getItem("clagentic_my_user") || localStorage.getItem("clay_my_user") || "null"); } catch (e) {}
|
|
765
|
+
return userAvatarUrl(myUser || {}, 36);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
function getMyDisplayName() {
|
|
769
|
+
if (document.body.dataset.myDisplayName) return document.body.dataset.myDisplayName;
|
|
770
|
+
var myUser = null;
|
|
771
|
+
try { myUser = JSON.parse(localStorage.getItem("clagentic_my_user") || localStorage.getItem("clay_my_user") || "null"); } catch (e) {}
|
|
772
|
+
return (myUser && (myUser.displayName || myUser.username)) || "Me";
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function timeStr() {
|
|
776
|
+
var now = new Date();
|
|
777
|
+
return String(now.getHours()).padStart(2, "0") + ":" + String(now.getMinutes()).padStart(2, "0");
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
function buildMentionAvatarUrl(meta) {
|
|
781
|
+
return "https://api.dicebear.com/7.x/" + (meta.avatarStyle || "bottts") + "/svg?seed=" + encodeURIComponent(meta.avatarSeed || meta.mateId);
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
function buildUserAvatarUrlFromEntry(entry, who) {
|
|
785
|
+
// who = "from" | "target"
|
|
786
|
+
var style = entry[who + "AvatarStyle"] || "thumbs";
|
|
787
|
+
var seed = entry[who + "AvatarSeed"] || entry[who === "from" ? "fromName" : "targetName"] || entry[who === "from" ? "from" : "targetUserId"];
|
|
788
|
+
return "https://api.dicebear.com/7.x/" + style + "/svg?seed=" + encodeURIComponent(seed || "user");
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// Render a user-to-user @mention bubble (live receive AND history replay).
|
|
792
|
+
// Shape mirrors renderMentionUser (the user-side @mate render) but tags the
|
|
793
|
+
// target user explicitly so it's clear who the side conversation is between.
|
|
794
|
+
// `entry` shape:
|
|
795
|
+
// { type: "user_mention", from, fromName, targetUserId, targetName,
|
|
796
|
+
// targetUsername?, targetAvatarStyle?, targetAvatarSeed?,
|
|
797
|
+
// text, pastes?, images?, _ts? }
|
|
798
|
+
export function renderUserMention(entry) {
|
|
799
|
+
var div = document.createElement("div");
|
|
800
|
+
div.className = "msg-user msg-user-mention";
|
|
801
|
+
|
|
802
|
+
var bubble = document.createElement("div");
|
|
803
|
+
bubble.className = "bubble";
|
|
804
|
+
bubble.dir = "auto";
|
|
805
|
+
|
|
806
|
+
// Images
|
|
807
|
+
if (entry.images && entry.images.length > 0) {
|
|
808
|
+
var imgRow = document.createElement("div");
|
|
809
|
+
imgRow.className = "bubble-images";
|
|
810
|
+
for (var ii = 0; ii < entry.images.length; ii++) {
|
|
811
|
+
var img = document.createElement("img");
|
|
812
|
+
if (entry.images[ii].url) {
|
|
813
|
+
img.src = entry.images[ii].url;
|
|
814
|
+
} else if (entry.images[ii].data) {
|
|
815
|
+
img.src = "data:" + entry.images[ii].mediaType + ";base64," + entry.images[ii].data;
|
|
816
|
+
}
|
|
817
|
+
img.loading = "lazy";
|
|
818
|
+
img.className = "bubble-img";
|
|
819
|
+
img.addEventListener("click", function () {
|
|
820
|
+
if (ctx.showImageModal) ctx.showImageModal(this.src);
|
|
821
|
+
});
|
|
822
|
+
img.addEventListener("error", function () {
|
|
823
|
+
var placeholder = document.createElement("div");
|
|
824
|
+
placeholder.className = "bubble-img-expired";
|
|
825
|
+
placeholder.textContent = "Image deleted";
|
|
826
|
+
this.parentNode.replaceChild(placeholder, this);
|
|
827
|
+
});
|
|
828
|
+
imgRow.appendChild(img);
|
|
829
|
+
}
|
|
830
|
+
bubble.appendChild(imgRow);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// Pastes
|
|
834
|
+
if (entry.pastes && entry.pastes.length > 0) {
|
|
835
|
+
var pasteRow = document.createElement("div");
|
|
836
|
+
pasteRow.className = "bubble-pastes";
|
|
837
|
+
for (var pi = 0; pi < entry.pastes.length; pi++) {
|
|
838
|
+
(function (pasteText) {
|
|
839
|
+
var chip = document.createElement("div");
|
|
840
|
+
chip.className = "bubble-paste";
|
|
841
|
+
var preview = pasteText.substring(0, 60).replace(/\n/g, " ");
|
|
842
|
+
if (pasteText.length > 60) preview += "...";
|
|
843
|
+
chip.innerHTML = '<span class="bubble-paste-preview">' + escapeHtml(preview) + '</span><span class="bubble-paste-label">PASTED</span>';
|
|
844
|
+
chip.addEventListener("click", function (e) {
|
|
845
|
+
e.stopPropagation();
|
|
846
|
+
if (ctx.showPasteModal) ctx.showPasteModal(pasteText);
|
|
847
|
+
});
|
|
848
|
+
pasteRow.appendChild(chip);
|
|
849
|
+
})(entry.pastes[pi]);
|
|
850
|
+
}
|
|
851
|
+
bubble.appendChild(pasteRow);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
var targetName = entry.targetName || "user";
|
|
855
|
+
var fromName = entry.fromName || "Someone";
|
|
856
|
+
var textEl = document.createElement("span");
|
|
857
|
+
textEl.innerHTML =
|
|
858
|
+
'<span class="mention-chip mention-chip-user">@' + escapeHtml(targetName) + '</span> ' +
|
|
859
|
+
escapeHtml(entry.text || "");
|
|
860
|
+
bubble.appendChild(textEl);
|
|
861
|
+
|
|
862
|
+
// Sender avatar (from)
|
|
863
|
+
var avi = document.createElement("img");
|
|
864
|
+
avi.className = "dm-bubble-avatar dm-bubble-avatar-me";
|
|
865
|
+
avi.src = buildUserAvatarUrlFromEntry(entry, "from");
|
|
866
|
+
div.appendChild(avi);
|
|
867
|
+
|
|
868
|
+
var contentWrap = document.createElement("div");
|
|
869
|
+
contentWrap.className = "dm-bubble-content";
|
|
870
|
+
|
|
871
|
+
var header = document.createElement("div");
|
|
872
|
+
header.className = "dm-bubble-header";
|
|
873
|
+
var nameSpan = document.createElement("span");
|
|
874
|
+
nameSpan.className = "dm-bubble-name";
|
|
875
|
+
nameSpan.textContent = fromName;
|
|
876
|
+
header.appendChild(nameSpan);
|
|
877
|
+
|
|
878
|
+
var sideTag = document.createElement("span");
|
|
879
|
+
sideTag.className = "mention-badge mention-badge-user";
|
|
880
|
+
sideTag.textContent = "@" + targetName.toUpperCase();
|
|
881
|
+
sideTag.title = "Side conversation with " + targetName + ". The coding agent will see this on the next message.";
|
|
882
|
+
header.appendChild(sideTag);
|
|
883
|
+
|
|
884
|
+
var ts = document.createElement("span");
|
|
885
|
+
ts.className = "dm-bubble-time";
|
|
886
|
+
ts.textContent = timeStr();
|
|
887
|
+
header.appendChild(ts);
|
|
888
|
+
|
|
889
|
+
contentWrap.appendChild(header);
|
|
890
|
+
contentWrap.appendChild(bubble);
|
|
891
|
+
div.appendChild(contentWrap);
|
|
892
|
+
|
|
893
|
+
if (ctx.addToMessages) ctx.addToMessages(div);
|
|
894
|
+
else if (ctx.messagesEl) ctx.messagesEl.appendChild(div);
|
|
895
|
+
refreshIcons();
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// --- History replay: render saved mention entries ---
|
|
899
|
+
export function renderMentionUser(entry) {
|
|
900
|
+
// Render user message with @mention indicator
|
|
901
|
+
var div = document.createElement("div");
|
|
902
|
+
div.className = "msg-user";
|
|
903
|
+
|
|
904
|
+
var bubble = document.createElement("div");
|
|
905
|
+
bubble.className = "bubble";
|
|
906
|
+
bubble.dir = "auto";
|
|
907
|
+
|
|
908
|
+
// Render images (same pattern as addUserMessage in app.js)
|
|
909
|
+
if (entry.images && entry.images.length > 0) {
|
|
910
|
+
var imgRow = document.createElement("div");
|
|
911
|
+
imgRow.className = "bubble-images";
|
|
912
|
+
for (var ii = 0; ii < entry.images.length; ii++) {
|
|
913
|
+
var img = document.createElement("img");
|
|
914
|
+
if (entry.images[ii].url) {
|
|
915
|
+
img.src = entry.images[ii].url;
|
|
916
|
+
} else if (entry.images[ii].data) {
|
|
917
|
+
img.src = "data:" + entry.images[ii].mediaType + ";base64," + entry.images[ii].data;
|
|
918
|
+
}
|
|
919
|
+
img.loading = "lazy";
|
|
920
|
+
img.className = "bubble-img";
|
|
921
|
+
img.addEventListener("click", function () {
|
|
922
|
+
if (ctx.showImageModal) ctx.showImageModal(this.src);
|
|
923
|
+
});
|
|
924
|
+
img.addEventListener("error", function () {
|
|
925
|
+
var placeholder = document.createElement("div");
|
|
926
|
+
placeholder.className = "bubble-img-expired";
|
|
927
|
+
placeholder.textContent = "Image deleted";
|
|
928
|
+
this.parentNode.replaceChild(placeholder, this);
|
|
929
|
+
});
|
|
930
|
+
imgRow.appendChild(img);
|
|
931
|
+
}
|
|
932
|
+
bubble.appendChild(imgRow);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// Render pastes
|
|
936
|
+
if (entry.pastes && entry.pastes.length > 0) {
|
|
937
|
+
var pasteRow = document.createElement("div");
|
|
938
|
+
pasteRow.className = "bubble-pastes";
|
|
939
|
+
for (var pi = 0; pi < entry.pastes.length; pi++) {
|
|
940
|
+
(function (pasteText) {
|
|
941
|
+
var chip = document.createElement("div");
|
|
942
|
+
chip.className = "bubble-paste";
|
|
943
|
+
var preview = pasteText.substring(0, 60).replace(/\n/g, " ");
|
|
944
|
+
if (pasteText.length > 60) preview += "...";
|
|
945
|
+
chip.innerHTML = '<span class="bubble-paste-preview">' + escapeHtml(preview) + '</span><span class="bubble-paste-label">PASTED</span>';
|
|
946
|
+
chip.addEventListener("click", function (e) {
|
|
947
|
+
e.stopPropagation();
|
|
948
|
+
if (ctx.showPasteModal) ctx.showPasteModal(pasteText);
|
|
949
|
+
});
|
|
950
|
+
pasteRow.appendChild(chip);
|
|
951
|
+
})(entry.pastes[pi]);
|
|
952
|
+
}
|
|
953
|
+
bubble.appendChild(pasteRow);
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
var textEl = document.createElement("span");
|
|
957
|
+
textEl.innerHTML = '<span class="mention-chip">@' + escapeHtml(entry.mateName || "Mate") + '</span> ' + escapeHtml(entry.text || "");
|
|
958
|
+
bubble.appendChild(textEl);
|
|
959
|
+
|
|
960
|
+
// Always render avatar + header structure (CSS controls visibility)
|
|
961
|
+
var avi = document.createElement("img");
|
|
962
|
+
avi.className = "dm-bubble-avatar dm-bubble-avatar-me";
|
|
963
|
+
avi.src = getMyAvatarSrc();
|
|
964
|
+
div.appendChild(avi);
|
|
965
|
+
|
|
966
|
+
var contentWrap = document.createElement("div");
|
|
967
|
+
contentWrap.className = "dm-bubble-content";
|
|
968
|
+
|
|
969
|
+
var header = document.createElement("div");
|
|
970
|
+
header.className = "dm-bubble-header";
|
|
971
|
+
var nameSpan = document.createElement("span");
|
|
972
|
+
nameSpan.className = "dm-bubble-name";
|
|
973
|
+
nameSpan.textContent = getMyDisplayName();
|
|
974
|
+
header.appendChild(nameSpan);
|
|
975
|
+
var ts = document.createElement("span");
|
|
976
|
+
ts.className = "dm-bubble-time";
|
|
977
|
+
ts.textContent = timeStr();
|
|
978
|
+
header.appendChild(ts);
|
|
979
|
+
contentWrap.appendChild(header);
|
|
980
|
+
contentWrap.appendChild(bubble);
|
|
981
|
+
div.appendChild(contentWrap);
|
|
982
|
+
|
|
983
|
+
// Action bar below bubble (same as regular user messages)
|
|
984
|
+
var actions = document.createElement("div");
|
|
985
|
+
actions.className = "msg-actions";
|
|
986
|
+
var ts2 = timeStr();
|
|
987
|
+
actions.innerHTML =
|
|
988
|
+
'<span class="msg-action-time">' + ts2 + '</span>' +
|
|
989
|
+
'<button class="msg-action-btn msg-action-copy" type="button" title="Copy">' + iconHtml("copy") + '</button>' +
|
|
990
|
+
'<button class="msg-action-btn msg-action-fork" type="button" title="Fork">' + iconHtml("git-branch") + '</button>' +
|
|
991
|
+
(((store.get('vendorCapabilities') || {}).rewind !== false) ? '<button class="msg-action-btn msg-action-rewind msg-user-rewind-btn" type="button" title="Rewind">' + iconHtml("rotate-ccw") + '</button>' : '') +
|
|
992
|
+
'<button class="msg-action-btn msg-action-hidden msg-action-edit" type="button" title="Edit">' + iconHtml("pencil") + '</button>';
|
|
993
|
+
div.appendChild(actions);
|
|
994
|
+
|
|
995
|
+
// Copy handler
|
|
996
|
+
var rawText = (entry.mateName ? "@" + entry.mateName + " " : "") + (entry.text || "");
|
|
997
|
+
actions.querySelector(".msg-action-copy").addEventListener("click", function () {
|
|
998
|
+
var self = this;
|
|
999
|
+
copyToClipboard(rawText);
|
|
1000
|
+
self.innerHTML = iconHtml("check");
|
|
1001
|
+
refreshIcons();
|
|
1002
|
+
setTimeout(function () { self.innerHTML = iconHtml("copy"); refreshIcons(); }, 1200);
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
if (ctx.addToMessages) ctx.addToMessages(div);
|
|
1006
|
+
else if (ctx.messagesEl) ctx.messagesEl.appendChild(div);
|
|
1007
|
+
refreshIcons();
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
export function renderMentionResponse(entry) {
|
|
1011
|
+
var avatarSrc = buildMentionAvatarUrl(entry);
|
|
1012
|
+
|
|
1013
|
+
// DM-style message layout (Mate DM or Wide view)
|
|
1014
|
+
if (isDmLayout()) {
|
|
1015
|
+
var el = document.createElement("div");
|
|
1016
|
+
el.className = "msg-assistant msg-mention-dm";
|
|
1017
|
+
|
|
1018
|
+
var avi = document.createElement("img");
|
|
1019
|
+
avi.className = "dm-bubble-avatar dm-bubble-avatar-mate";
|
|
1020
|
+
avi.src = avatarSrc;
|
|
1021
|
+
el.appendChild(avi);
|
|
1022
|
+
|
|
1023
|
+
var contentWrap = document.createElement("div");
|
|
1024
|
+
contentWrap.className = "dm-bubble-content";
|
|
1025
|
+
|
|
1026
|
+
var header = document.createElement("div");
|
|
1027
|
+
header.className = "dm-bubble-header";
|
|
1028
|
+
var nameSpan = document.createElement("span");
|
|
1029
|
+
nameSpan.className = "dm-bubble-name";
|
|
1030
|
+
nameSpan.style.color = entry.avatarColor || "#6c5ce7";
|
|
1031
|
+
nameSpan.textContent = entry.mateName || "Mate";
|
|
1032
|
+
header.appendChild(nameSpan);
|
|
1033
|
+
|
|
1034
|
+
var badge = document.createElement("span");
|
|
1035
|
+
badge.className = "mention-badge";
|
|
1036
|
+
badge.textContent = "@MENTION";
|
|
1037
|
+
header.appendChild(badge);
|
|
1038
|
+
|
|
1039
|
+
var ts = document.createElement("span");
|
|
1040
|
+
ts.className = "dm-bubble-time";
|
|
1041
|
+
ts.textContent = timeStr();
|
|
1042
|
+
header.appendChild(ts);
|
|
1043
|
+
contentWrap.appendChild(header);
|
|
1044
|
+
|
|
1045
|
+
var contentDiv = document.createElement("div");
|
|
1046
|
+
contentDiv.className = "md-content mention-content";
|
|
1047
|
+
contentDiv.dir = "auto";
|
|
1048
|
+
contentDiv.innerHTML = renderMarkdown(entry.text || "");
|
|
1049
|
+
highlightCodeBlocks(contentDiv);
|
|
1050
|
+
contentWrap.appendChild(contentDiv);
|
|
1051
|
+
el.appendChild(contentWrap);
|
|
1052
|
+
|
|
1053
|
+
if (ctx.addToMessages) ctx.addToMessages(el);
|
|
1054
|
+
else if (ctx.messagesEl) ctx.messagesEl.appendChild(el);
|
|
1055
|
+
} else {
|
|
1056
|
+
// Project chat: use mention block style
|
|
1057
|
+
var el = document.createElement("div");
|
|
1058
|
+
el.className = "msg-mention";
|
|
1059
|
+
el.style.setProperty("--mention-color", entry.avatarColor || "#6c5ce7");
|
|
1060
|
+
|
|
1061
|
+
var mheader = document.createElement("div");
|
|
1062
|
+
mheader.className = "mention-header";
|
|
1063
|
+
|
|
1064
|
+
var avatar = document.createElement("img");
|
|
1065
|
+
avatar.className = "mention-avatar";
|
|
1066
|
+
avatar.src = avatarSrc;
|
|
1067
|
+
avatar.width = 20;
|
|
1068
|
+
avatar.height = 20;
|
|
1069
|
+
mheader.appendChild(avatar);
|
|
1070
|
+
|
|
1071
|
+
var mname = document.createElement("span");
|
|
1072
|
+
mname.className = "mention-name";
|
|
1073
|
+
mname.textContent = entry.mateName || "Mate";
|
|
1074
|
+
mheader.appendChild(mname);
|
|
1075
|
+
|
|
1076
|
+
el.appendChild(mheader);
|
|
1077
|
+
|
|
1078
|
+
var contentDiv = document.createElement("div");
|
|
1079
|
+
contentDiv.className = "md-content mention-content";
|
|
1080
|
+
contentDiv.dir = "auto";
|
|
1081
|
+
contentDiv.innerHTML = renderMarkdown(entry.text || "");
|
|
1082
|
+
highlightCodeBlocks(contentDiv);
|
|
1083
|
+
el.appendChild(contentDiv);
|
|
1084
|
+
|
|
1085
|
+
if (ctx.addToMessages) ctx.addToMessages(el);
|
|
1086
|
+
else if (ctx.messagesEl) ctx.messagesEl.appendChild(el);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
// Add copy handler
|
|
1090
|
+
if (ctx.addCopyHandler && entry.text) {
|
|
1091
|
+
ctx.addCopyHandler(el, entry.text);
|
|
1092
|
+
}
|
|
1093
|
+
}
|