@clagentic/console 1.12.0-beta.1 → 1.12.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/LICENSES/README.md +5 -0
  2. package/README.md +1 -0
  3. package/bin/cli.js +5 -2
  4. package/lib/agent-roster-ws.js +84 -0
  5. package/lib/agent-roster.js +312 -0
  6. package/lib/auth-required-notify.js +42 -0
  7. package/lib/build-changes.js +8 -2
  8. package/lib/build-sha.json +2 -2
  9. package/lib/build-update-notify.js +45 -0
  10. package/lib/build-update-offer.js +34 -11
  11. package/lib/build-update-standing.js +34 -14
  12. package/lib/claude-settings-env.js +142 -0
  13. package/lib/cli/duration.js +27 -0
  14. package/lib/cli/schedule-input-subcommands.js +1 -22
  15. package/lib/cli/session-subcommands.js +60 -11
  16. package/lib/client-address.js +44 -0
  17. package/lib/daemon.js +31 -10
  18. package/lib/idle-compaction-setting.js +203 -0
  19. package/lib/mcp-bridge-credential.js +41 -0
  20. package/lib/notification-prefs.js +18 -22
  21. package/lib/notify/core.js +210 -0
  22. package/lib/notify/index.js +31 -0
  23. package/lib/notify/live-prompts.js +36 -0
  24. package/lib/notify/payload.js +62 -0
  25. package/lib/notify/target.js +5 -0
  26. package/lib/notify/type-registry.js +81 -0
  27. package/lib/notify/types.js +57 -0
  28. package/lib/open-sockets.js +27 -0
  29. package/lib/outbound-access.js +85 -0
  30. package/lib/outbound-entry.js +116 -0
  31. package/lib/outbound-ledger.js +306 -0
  32. package/lib/outbound-query.js +153 -0
  33. package/lib/pending-prompts.js +31 -16
  34. package/lib/project-connection.js +48 -8
  35. package/lib/project-filesystem.js +43 -5
  36. package/lib/project-http.js +9 -1
  37. package/lib/project-loop.js +38 -26
  38. package/lib/project-notifications.js +122 -39
  39. package/lib/project-prompt-responses.js +1 -1
  40. package/lib/project-sessions.js +11 -1
  41. package/lib/project-user-mention.js +22 -34
  42. package/lib/project-user-message.js +208 -4
  43. package/lib/project-user-shell.js +298 -0
  44. package/lib/project.js +41 -5
  45. package/lib/prompt-answer.js +145 -0
  46. package/lib/prompt-expiry.js +50 -0
  47. package/lib/prompt-registry.js +98 -25
  48. package/lib/prompt-reminders.js +38 -33
  49. package/lib/prompt-source.js +59 -8
  50. package/lib/public/app.js +32 -2
  51. package/lib/public/css/agent-messages.css +96 -0
  52. package/lib/public/css/agent-roster.css +93 -0
  53. package/lib/public/css/diagnostics.css +29 -1
  54. package/lib/public/css/home-hub.css +12 -0
  55. package/lib/public/css/icon-strip.css +9 -0
  56. package/lib/public/css/input.css +20 -141
  57. package/lib/public/css/login-panel.css +73 -0
  58. package/lib/public/css/menus.css +2 -2
  59. package/lib/public/css/mobile-nav.css +11 -0
  60. package/lib/public/css/sidebar.css +18 -0
  61. package/lib/public/css/team-panel.css +1 -6
  62. package/lib/public/css/team-view.css +101 -0
  63. package/lib/public/css/title-bar.css +10 -0
  64. package/lib/public/css/user-shell.css +144 -0
  65. package/lib/public/index.html +44 -7
  66. package/lib/public/modules/activity-state.js +20 -4
  67. package/lib/public/modules/agent-avatar-picker.js +162 -0
  68. package/lib/public/modules/agent-avatar.js +153 -0
  69. package/lib/public/modules/agent-messages.js +285 -0
  70. package/lib/public/modules/agent-roster.js +157 -0
  71. package/lib/public/modules/app-connection.js +34 -5
  72. package/lib/public/modules/app-messages.js +55 -16
  73. package/lib/public/modules/app-notifications.js +104 -75
  74. package/lib/public/modules/app-panels.js +26 -3
  75. package/lib/public/modules/app-projects.js +3 -1
  76. package/lib/public/modules/app-rate-limit.js +8 -165
  77. package/lib/public/modules/app-rendering.js +32 -7
  78. package/lib/public/modules/build-update-sessions.js +81 -0
  79. package/lib/public/modules/collapsible-text.js +33 -18
  80. package/lib/public/modules/compaction-state.js +34 -0
  81. package/lib/public/modules/custom-icons.js +23 -5
  82. package/lib/public/modules/diagnostics.js +61 -57
  83. package/lib/public/modules/env-shadow-notice.js +34 -0
  84. package/lib/public/modules/injected-identity.js +24 -21
  85. package/lib/public/modules/input.js +176 -15
  86. package/lib/public/modules/login-panel.js +136 -0
  87. package/lib/public/modules/login-parser.js +73 -0
  88. package/lib/public/modules/login-tab.js +66 -0
  89. package/lib/public/modules/notifications.js +9 -1
  90. package/lib/public/modules/notify-client.js +246 -0
  91. package/lib/public/modules/pending-term-request.js +30 -0
  92. package/lib/public/modules/project-icon.js +22 -2
  93. package/lib/public/modules/project-settings.js +5 -0
  94. package/lib/public/modules/prompt-state.js +3 -3
  95. package/lib/public/modules/prompts.js +1 -1
  96. package/lib/public/modules/queued-button.js +11 -0
  97. package/lib/public/modules/scheduled-input-actions.js +12 -4
  98. package/lib/public/modules/scheduled-outbox.js +230 -0
  99. package/lib/public/modules/send-now.js +200 -0
  100. package/lib/public/modules/server-settings.js +50 -1
  101. package/lib/public/modules/shell-card.js +76 -0
  102. package/lib/public/modules/shell-line.js +49 -0
  103. package/lib/public/modules/shell-queue.js +253 -0
  104. package/lib/public/modules/shell-settings-controls.js +76 -0
  105. package/lib/public/modules/sidebar-mobile.js +3 -3
  106. package/lib/public/modules/sidebar-sessions.js +8 -0
  107. package/lib/public/modules/sidebar-users.js +5 -7
  108. package/lib/public/modules/team-panel.js +30 -88
  109. package/lib/public/modules/team-view.js +211 -0
  110. package/lib/public/modules/terminal-links.js +193 -0
  111. package/lib/public/modules/terminal.js +84 -107
  112. package/lib/public/modules/tools.js +19 -0
  113. package/lib/public/modules/user-shell.js +824 -0
  114. package/lib/public/notify-sw-logic.js +252 -0
  115. package/lib/public/notify-target.js +157 -0
  116. package/lib/public/style.css +5 -0
  117. package/lib/public/sw.js +20 -69
  118. package/lib/push.js +63 -19
  119. package/lib/queued-chat.js +392 -0
  120. package/lib/runtime-env.js +1 -0
  121. package/lib/scheduled-input/ws.js +67 -9
  122. package/lib/sdk-bridge.js +184 -73
  123. package/lib/sdk-message-processor.js +124 -76
  124. package/lib/server-auth.js +6 -4
  125. package/lib/server-dm.js +11 -20
  126. package/lib/server-settings.js +39 -1
  127. package/lib/server.js +112 -16
  128. package/lib/session-directory.js +39 -12
  129. package/lib/session-end.js +97 -0
  130. package/lib/session-input-ipc.js +37 -1
  131. package/lib/session-input.js +263 -21
  132. package/lib/session-liveness.js +53 -0
  133. package/lib/session-reclaim.js +37 -2
  134. package/lib/session-resume.js +1 -0
  135. package/lib/session-settings-file.js +53 -0
  136. package/lib/sessions.js +80 -9
  137. package/lib/team-traffic-ws.js +68 -0
  138. package/lib/team-traffic.js +318 -0
  139. package/lib/usage-store.js +36 -7
  140. package/lib/user-shell-settings.js +105 -0
  141. package/lib/vendor-auth.js +33 -2
  142. package/lib/ws-schema.js +33 -5
  143. package/lib/yoke/adapters/claude-capabilities.js +2 -0
  144. package/lib/yoke/adapters/claude-vendor.js +17 -1
  145. package/lib/yoke/adapters/claude-worker.js +39 -11
  146. package/lib/yoke/adapters/claude.js +225 -6
  147. package/lib/yoke/adapters/codex-capabilities.js +6 -1
  148. package/lib/yoke/adapters/codex-user-shell.js +265 -0
  149. package/lib/yoke/adapters/codex-vendor.js +7 -0
  150. package/lib/yoke/adapters/codex.js +186 -52
  151. package/lib/yoke/auth-checks.js +17 -2
  152. package/lib/yoke/codex-app-server.js +8 -2
  153. package/lib/yoke/index.js +21 -3
  154. package/lib/yoke/interface.js +54 -1
  155. package/lib/yoke/mcp-bridge-server.js +12 -8
  156. package/lib/yoke/provider-credentials.js +24 -0
  157. package/lib/yoke/registry.js +40 -1
  158. package/lib/yoke/user-shell.js +224 -0
  159. package/package.json +2 -2
  160. package/scripts/check-test-count.js +14 -0
  161. package/lib/public/modules/build-notice-gate.js +0 -73
@@ -3,8 +3,6 @@
3
3
 
4
4
  import { iconHtml, refreshIcons } from './icons.js';
5
5
  import { store } from './store.js';
6
- import { addToMessages, scrollToBottom } from './app-rendering.js';
7
- import { userAvatarUrl } from './avatar.js';
8
6
  import { clearScheduleDelay, setScheduleDelayForSession, clearScheduleDelayForSession, restoreScheduleDelayUi, refreshScheduleControls } from './input.js';
9
7
  import { isSonnetModel, isOpusModel } from './model-families.js';
10
8
  import {
@@ -14,9 +12,8 @@ import {
14
12
  setScheduledInputs, getScheduledInputs,
15
13
  clearSession as clearSessionRateLimitState,
16
14
  } from './rate-limit-state.js';
17
- import { countdownText } from './schedule-time.js';
18
- import { buildCollapsibleText } from './collapsible-text.js';
19
- import { sendScheduledNow, cancelScheduledInput, requestScheduledInputList } from './scheduled-input-actions.js';
15
+ import { requestScheduledInputList } from './scheduled-input-actions.js';
16
+ import { renderScheduledOutbox, removeScheduledOutbox, resetScheduledOutboxRequests, getScheduledOutboxEl } from './scheduled-outbox.js';
20
17
 
21
18
  // --- Module-owned state ---
22
19
  // lr-0827ba: rateLimitResetsAt / rateLimitResetTimer / rateLimitResetState /
@@ -31,11 +28,6 @@ var rateLimitIndicatorEl = null;
31
28
  var rateLimitUsageEl = null;
32
29
  var rateLimitTickTimer = null;
33
30
  var _rateLimitUsageLastHtml = null; // guard against redundant innerHTML + refreshIcons()
34
- // The scheduled-message bubbles of the session on screen share one container;
35
- // each has a countdown the one interval below keeps current.
36
- var scheduledMsgEl = null;
37
- var scheduledCountdownTimer = null;
38
- var scheduledCountdowns = [];
39
31
  var fastModeIndicatorEl = null;
40
32
 
41
33
  function currentSessionId() {
@@ -382,166 +374,16 @@ export function applyScheduledInputList(msg) {
382
374
  if (targetSessionId === currentSessionId()) renderScheduledBubbles(targetSessionId);
383
375
  }
384
376
 
385
- // Draws one bubble per armed input of the session on screen, in one container
386
- // so the message list keeps them together at its end.
377
+ // Draws the session on screen's armed inputs as outbox items (scheduled-outbox.js).
387
378
  function renderScheduledBubbles(sessionId) {
388
- removeScheduledMessageBubble();
389
- var inputs = getScheduledInputs(sessionId);
390
- if (inputs.length === 0) return;
391
- var container = document.createElement("div");
392
- container.className = "scheduled-msgs";
393
- inputs.forEach(function (input) {
394
- var built = buildScheduledBubble(input);
395
- container.appendChild(built.wrap);
396
- scheduledCountdowns.push({ el: built.countdownEl, input: input });
397
- });
398
- addToMessages(container);
399
- scheduledMsgEl = container;
400
- scrollToBottom();
401
- updateScheduledCountdowns();
402
- scheduledCountdownTimer = setInterval(updateScheduledCountdowns, 1000);
403
- }
404
-
405
- function updateScheduledCountdowns() {
406
- var now = Date.now();
407
- scheduledCountdowns.forEach(function (c) { c.el.textContent = countdownText(c.input, now); });
408
- }
409
-
410
- function buildScheduledBubble(input) {
411
- var text = input.text;
412
- var isChannel = document.body.classList.contains("wide-view");
413
- var wrap = document.createElement("div");
414
- wrap.className = "msg-user scheduled-msg-wrap";
415
- wrap.setAttribute("data-id", input.id);
416
-
417
- var countdownEl;
418
- var cancelBtn;
419
-
420
- // Collapsed by default to one line; the card's own state, not persisted.
421
- var collapsible = buildCollapsibleText(text, {
422
- onChange: function (collapsed) { wrap.classList.toggle("is-collapsed", collapsed); },
423
- });
424
-
425
- if (isChannel) {
426
- // Channel mode: avatar + header with scheduled badge + message
427
- var _me = store.get('cachedAllUsers').find(function (u) { return u.id === store.get('myUserId'); });
428
- if (!_me) { try { _me = JSON.parse(localStorage.getItem("clagentic_my_user") || localStorage.getItem("clay_my_user") || "null"); } catch(e) {} }
429
- var _myName = document.body.dataset.myDisplayName || (_me && (_me.displayName || _me.username)) || "Me";
430
-
431
- var avi = document.createElement("img");
432
- avi.className = "dm-bubble-avatar dm-bubble-avatar-me";
433
- avi.src = document.body.dataset.myAvatarUrl || userAvatarUrl(_me || { id: store.get('myUserId') }, 36);
434
- wrap.appendChild(avi);
435
-
436
- var content = document.createElement("div");
437
- content.className = "dm-bubble-content";
438
-
439
- var header = document.createElement("div");
440
- header.className = "dm-bubble-header";
441
-
442
- var nameSpan = document.createElement("span");
443
- nameSpan.className = "dm-bubble-name";
444
- nameSpan.textContent = _myName;
445
- header.appendChild(nameSpan);
446
-
447
- var badge = document.createElement("span");
448
- badge.className = "scheduled-msg-badge";
449
- badge.innerHTML = iconHtml("clock");
450
- countdownEl = document.createElement("span");
451
- countdownEl.className = "scheduled-msg-countdown";
452
- badge.appendChild(countdownEl);
453
- header.appendChild(badge);
454
-
455
- var actions = document.createElement("span");
456
- actions.className = "scheduled-msg-actions";
457
-
458
- actions.appendChild(collapsible.button);
459
-
460
- var sendNowBtn = document.createElement("button");
461
- sendNowBtn.className = "scheduled-msg-send-now";
462
- sendNowBtn.textContent = "Send now";
463
- sendNowBtn.addEventListener("click", function () { sendScheduledNow(input.id); });
464
- actions.appendChild(sendNowBtn);
465
-
466
- var sep = document.createElement("span");
467
- sep.className = "scheduled-msg-sep";
468
- sep.textContent = "\u00b7";
469
- actions.appendChild(sep);
470
-
471
- cancelBtn = document.createElement("button");
472
- cancelBtn.className = "scheduled-msg-cancel";
473
- cancelBtn.textContent = "Cancel";
474
- cancelBtn.addEventListener("click", function () { cancelScheduledInput(input.id); });
475
- actions.appendChild(cancelBtn);
476
-
477
- header.appendChild(actions);
478
-
479
- content.appendChild(header);
480
-
481
- var bubble = document.createElement("div");
482
- bubble.className = "bubble scheduled-msg-bubble";
483
- bubble.appendChild(collapsible.el);
484
- content.appendChild(bubble);
485
-
486
- wrap.appendChild(content);
487
- } else {
488
- // Bubble mode: original layout
489
- var bubble = document.createElement("div");
490
- bubble.className = "bubble scheduled-msg-bubble";
491
-
492
- bubble.appendChild(collapsible.el);
493
-
494
- var metaEl = document.createElement("div");
495
- metaEl.className = "scheduled-msg-meta";
496
-
497
- var clockIcon = document.createElement("span");
498
- clockIcon.className = "scheduled-msg-icon";
499
- clockIcon.innerHTML = iconHtml("clock");
500
- metaEl.appendChild(clockIcon);
501
-
502
- countdownEl = document.createElement("span");
503
- countdownEl.className = "scheduled-msg-countdown";
504
- metaEl.appendChild(countdownEl);
505
-
506
- metaEl.appendChild(collapsible.button);
507
-
508
- var sendNowBtn2 = document.createElement("button");
509
- sendNowBtn2.className = "scheduled-msg-send-now";
510
- sendNowBtn2.textContent = "Send now";
511
- sendNowBtn2.addEventListener("click", function () { sendScheduledNow(input.id); });
512
- metaEl.appendChild(sendNowBtn2);
513
-
514
- var sep2 = document.createElement("span");
515
- sep2.className = "scheduled-msg-sep";
516
- sep2.textContent = "\u00b7";
517
- metaEl.appendChild(sep2);
518
-
519
- cancelBtn = document.createElement("button");
520
- cancelBtn.className = "scheduled-msg-cancel";
521
- cancelBtn.textContent = "Cancel";
522
- cancelBtn.addEventListener("click", function () { cancelScheduledInput(input.id); });
523
- metaEl.appendChild(cancelBtn);
524
-
525
- wrap.appendChild(bubble);
526
- wrap.appendChild(metaEl);
527
- }
528
-
529
- return { wrap: wrap, countdownEl: countdownEl };
379
+ renderScheduledOutbox(getScheduledInputs(sessionId));
530
380
  }
531
381
 
532
- // Clears the visible DOM bubbles and their countdown only; the per-session
382
+ // Clears the drawn outbox rows and their countdown only; the per-session
533
383
  // list is untouched. Used when re-drawing for the same session and when the
534
384
  // view moves to another project.
535
385
  export function removeScheduledMessageBubble() {
536
- if (scheduledMsgEl) {
537
- scheduledMsgEl.remove();
538
- scheduledMsgEl = null;
539
- }
540
- scheduledCountdowns = [];
541
- if (scheduledCountdownTimer) {
542
- clearInterval(scheduledCountdownTimer);
543
- scheduledCountdownTimer = null;
544
- }
386
+ removeScheduledOutbox();
545
387
  }
546
388
 
547
389
  export function handleFastModeState(state) {
@@ -571,7 +413,7 @@ export function handleFastModeState(state) {
571
413
  refreshIcons();
572
414
  }
573
415
 
574
- export function getScheduledMsgEl() { return scheduledMsgEl; }
416
+ export function getScheduledMsgEl() { return getScheduledOutboxEl(); }
575
417
 
576
418
  // lr-0827ba: this used to also null out the bare module-scoped
577
419
  // rateLimitResetsAt/rateLimitResetTimer/rateLimitResetState variables —
@@ -594,6 +436,7 @@ export function resetRateLimitState() {
594
436
  if (rateLimitUsageEl) { rateLimitUsageEl.remove(); rateLimitUsageEl = null; }
595
437
  if (fastModeIndicatorEl) { fastModeIndicatorEl.remove(); fastModeIndicatorEl = null; }
596
438
  removeScheduledMessageBubble();
439
+ resetScheduledOutboxRequests();
597
440
  }
598
441
 
599
442
  // Called when a session is actually destroyed/removed (not merely
@@ -9,8 +9,9 @@ import { renderMarkdown, renderMarkdownAsync, highlightCodeBlocks, renderMermaid
9
9
  import { iconHtml, refreshIcons } from './icons.js';
10
10
  import { userAvatarUrl } from './avatar.js';
11
11
  import { injectedSenderName, injectedLabel, injectedSessionNote } from './injected-label.js';
12
- import { buildCollapsibleText, needsCollapse, isScheduledInitiator } from './collapsible-text.js';
12
+ import { buildCollapsibleText, needsCollapse, isNonTypedInput } from './collapsible-text.js';
13
13
  import { resolveInjectedIdentity } from './injected-identity.js';
14
+ import { applyIdentityAvatar } from './agent-avatar.js';
14
15
  import { getProjectAgents } from './at-agents.js';
15
16
  import { closeToolGroup } from './tools.js';
16
17
  import { showImageModal, showPasteModal } from './app-misc.js';
@@ -37,6 +38,16 @@ var currentFullTextLocal = ""; // module-local accumulator — not in store duri
37
38
  export function resetCurrentFullText(v) {
38
39
  currentFullTextLocal = v || "";
39
40
  }
41
+
42
+ // Drops undrawn stream text and in-flight render bookkeeping. Without this a
43
+ // reset (reconnect, session or project switch) leaves buffered text that is
44
+ // then drawn in front of the next replayed block.
45
+ export function resetStreamState() {
46
+ if (streamDrainTimer) { cancelAnimationFrame(streamDrainTimer); streamDrainTimer = null; }
47
+ streamBuffer = "";
48
+ streamRenderPending = false;
49
+ streamRenderLen = 0;
50
+ }
40
51
  var isUserScrolledUp = false;
41
52
  var scrollThreshold = 150;
42
53
 
@@ -479,7 +490,7 @@ export function finalizeAssistantBlock() {
479
490
  // message another process sent into the session. It always renders through the
480
491
  // other-sender path, never as the local user. All of its text is untrusted and
481
492
  // is set with textContent.
482
- export function addUserMessage(text, images, pastes, fromUserId, fromUserName, injected) {
493
+ export function addUserMessage(text, images, pastes, fromUserId, fromUserName, injected, sentMidTurn) {
483
494
  if (!text && (!images || images.length === 0) && (!pastes || pastes.length === 0)) return;
484
495
  var myUserId = store.get('myUserId');
485
496
  // Only treat as "other user" if we're in multi-user mode AND myUserId is
@@ -539,11 +550,12 @@ export function addUserMessage(text, images, pastes, fromUserId, fromUserName, i
539
550
  bubble.appendChild(pasteRow);
540
551
  }
541
552
 
542
- // A long scheduled input that has fired collapses like its pending card did.
553
+ // Long input pushed into the session (trigger, loop, scheduled) collapses to a
554
+ // few lines; the operator's own typed message never does.
543
555
  // Labelling of injected input is untouched; only the text node is swapped.
544
556
  var firedCollapse = null;
545
557
  if (text) {
546
- if (injected && isScheduledInitiator(injected.initiator) && needsCollapse(text)) {
558
+ if (isNonTypedInput(injected) && needsCollapse(text)) {
547
559
  firedCollapse = buildCollapsibleText(text);
548
560
  bubble.appendChild(firedCollapse.el);
549
561
  } else {
@@ -553,6 +565,14 @@ export function addUserMessage(text, images, pastes, fromUserId, fromUserName, i
553
565
  }
554
566
  }
555
567
 
568
+ // A message delivered into a running turn says so, in place in the transcript.
569
+ if (sentMidTurn) {
570
+ var midTurnMark = document.createElement("span");
571
+ midTurnMark.className = "msg-sent-midturn";
572
+ midTurnMark.textContent = "Sent mid-turn";
573
+ bubble.appendChild(midTurnMark);
574
+ }
575
+
556
576
 
557
577
  var cachedAllUsers = store.get('cachedAllUsers');
558
578
  var _targetUser;
@@ -577,9 +597,13 @@ export function addUserMessage(text, images, pastes, fromUserId, fromUserName, i
577
597
 
578
598
  var avi = document.createElement("img");
579
599
  avi.className = "dm-bubble-avatar" + (isOtherUser ? " dm-bubble-avatar-other" : " dm-bubble-avatar-me");
580
- avi.src = _injectedIdentity ? _injectedIdentity.avatarUrl : isOtherUser
581
- ? userAvatarUrl(_targetUser || { id: fromUserId }, 36)
582
- : (document.body.dataset.myAvatarUrl || userAvatarUrl(_targetUser || { id: myUserId }, 36));
600
+ if (_injectedIdentity) {
601
+ applyIdentityAvatar(avi, _injectedIdentity, 36);
602
+ } else {
603
+ avi.src = isOtherUser
604
+ ? userAvatarUrl(_targetUser || { id: fromUserId }, 36)
605
+ : (document.body.dataset.myAvatarUrl || userAvatarUrl(_targetUser || { id: myUserId }, 36));
606
+ }
583
607
  div.appendChild(avi);
584
608
 
585
609
  var contentWrap = document.createElement("div");
@@ -653,6 +677,7 @@ export function addSystemMessage(text, isError) {
653
677
  div.querySelector(".sys-text").textContent = text;
654
678
  addToMessages(div);
655
679
  scrollToBottom();
680
+ return div;
656
681
  }
657
682
 
658
683
  export function addConflictMessage(msg) {
@@ -0,0 +1,81 @@
1
+ // build-update-sessions.js — the sessions a restart would end, as a count line
2
+ // with an expand control instead of one line each in the card's message. A
3
+ // card that lists every session grows with the session count until its
4
+ // action buttons leave the screen; collapsed by default, and bounded and
5
+ // scrolling when expanded, the list can never push them out. The card places
6
+ // this block above its actions, never around them. Every value is set with
7
+ // textContent: session titles are content, never markup.
8
+
9
+ function plural(n, word) {
10
+ return n + ' ' + word + (n === 1 ? '' : 's');
11
+ }
12
+
13
+ // The session lines the offer carries, or [] when it has none to set apart.
14
+ export function sessionLinesOf(offer) {
15
+ var i = offer && offer.interruptions;
16
+ if (!i || !Array.isArray(i.lines)) return [];
17
+ return i.lines.filter(function (l) { return typeof l === 'string' && l !== ''; });
18
+ }
19
+
20
+ /**
21
+ * The card's message without the per-session lines. Each line is dropped once,
22
+ * by exact match on the "- " form the daemon writes, so nothing else in the
23
+ * message can be mistaken for a session.
24
+ */
25
+ export function messageWithoutSessions(message, lines) {
26
+ if (lines.length === 0) return message;
27
+ var pending = lines.map(function (l) { return '- ' + l; });
28
+ return String(message).split('\n').filter(function (l) {
29
+ var at = pending.indexOf(l);
30
+ if (at === -1) return true;
31
+ pending.splice(at, 1);
32
+ return false;
33
+ }).join('\n');
34
+ }
35
+
36
+ /**
37
+ * @param {string[]} lines
38
+ * @param {{collapsed?: boolean}} [opts]
39
+ * @returns {?HTMLElement} null when there is no session to list
40
+ */
41
+ export function buildSessionsEl(lines, opts) {
42
+ if (!lines || lines.length === 0) return null;
43
+ var collapsed = !(opts && opts.collapsed === false);
44
+
45
+ var root = document.createElement('div');
46
+ root.className = 'build-update-sessions';
47
+
48
+ var head = document.createElement('div');
49
+ head.className = 'build-update-sessions-head';
50
+ var count = document.createElement('span');
51
+ count.className = 'build-update-sessions-count';
52
+ count.textContent = 'Ends ' + plural(lines.length, 'live session');
53
+ var toggle = document.createElement('button');
54
+ toggle.type = 'button';
55
+ toggle.className = 'collapsible-toggle build-update-sessions-toggle';
56
+ head.appendChild(count);
57
+ head.appendChild(toggle);
58
+
59
+ var list = document.createElement('ul');
60
+ list.className = 'build-update-session-list';
61
+ lines.forEach(function (l) {
62
+ var item = document.createElement('li');
63
+ item.textContent = l;
64
+ list.appendChild(item);
65
+ });
66
+
67
+ function apply() {
68
+ root.classList.toggle('is-collapsed', collapsed);
69
+ toggle.setAttribute('aria-expanded', collapsed ? 'false' : 'true');
70
+ toggle.textContent = collapsed ? 'Expand' : 'Collapse';
71
+ }
72
+ toggle.addEventListener('click', function () {
73
+ collapsed = !collapsed;
74
+ apply();
75
+ });
76
+ apply();
77
+
78
+ root.appendChild(head);
79
+ root.appendChild(list);
80
+ return root;
81
+ }
@@ -1,31 +1,46 @@
1
- // collapsible-text.js - one-line collapsed view of a multi-line prompt, with a
2
- // real expand/collapse button. Shared by the pending scheduled-input card and a
3
- // fired scheduled message, so the two cannot drift apart. The stored text is
4
- // never cut: the preview carries the first line and CSS truncates it with an
5
- // ellipsis; the full text stays in the DOM and is only hidden while collapsed.
6
- // State lives in the closure, so it is per card and gone on reload.
1
+ // collapsible-text.js - a collapsed view of long input that was pushed into a
2
+ // session, with a real expand/collapse button. The one component for every
3
+ // surface that shows such input: a delivered trigger, loop or scheduled message
4
+ // in the transcript and an armed schedule's row in the composer outbox, so they
5
+ // cannot drift apart. The stored text is never cut: the preview carries the
6
+ // first lines and CSS clamps it with an ellipsis; the full text stays in the DOM
7
+ // and is only hidden while collapsed. State lives in the closure, so it is per
8
+ // message and gone on reload.
7
9
 
8
- // A fired message collapses only when it is long: more than one line, or over
10
+ // Lines the collapsed view shows; a text of more lines collapses.
11
+ export var COLLAPSE_LINES = 3;
12
+
13
+ // A text collapses when it has more than COLLAPSE_LINES lines or is longer than
9
14
  // this many characters.
10
15
  export var COLLAPSE_CHAR_LIMIT = 280;
11
16
 
12
- // The turn initiators a scheduled input fires under (lib/turn-initiator.js).
13
- export function isScheduledInitiator(initiator) {
14
- return initiator === "scheduled" || initiator === "scheduled-now";
17
+ // Input pushed into a session rather than typed by the operator. The injected
18
+ // descriptor (injected-label.js injectedFromMessage) is null for the operator's
19
+ // own entry, so any descriptor means a trigger, loop, scheduled or scheduled-now
20
+ // input, or a legacy entry another process sent. The session agent's replies
21
+ // are not user input and never pass through here.
22
+ export function isNonTypedInput(injected) {
23
+ if (!injected) return false;
24
+ return !(injected.initiator === "human" && !injected.senderKind);
25
+ }
26
+
27
+ function lineList(text) {
28
+ return String(text == null ? "" : text).trim().split(/\r?\n/);
15
29
  }
16
30
 
17
31
  export function needsCollapse(text) {
18
32
  var s = String(text == null ? "" : text).trim();
19
- return s.indexOf("\n") !== -1 || s.length > COLLAPSE_CHAR_LIMIT;
33
+ return lineList(s).length > COLLAPSE_LINES || s.length > COLLAPSE_CHAR_LIMIT;
20
34
  }
21
35
 
22
- // First non-empty line, for the collapsed preview.
23
- export function firstLine(text) {
36
+ // The first COLLAPSE_LINES non-empty lines, for the collapsed preview.
37
+ export function previewLines(text) {
38
+ var out = [];
24
39
  var lines = String(text == null ? "" : text).split(/\r?\n/);
25
- for (var i = 0; i < lines.length; i++) {
26
- if (lines[i].trim() !== "") return lines[i];
40
+ for (var i = 0; i < lines.length && out.length < COLLAPSE_LINES; i++) {
41
+ if (lines[i].trim() !== "") out.push(lines[i]);
27
42
  }
28
- return "";
43
+ return out.join("\n");
29
44
  }
30
45
 
31
46
  // Builds { el, button }. `el` holds the preview and the full text; `button`
@@ -40,12 +55,12 @@ export function buildCollapsibleText(text, opts) {
40
55
  el.className = "collapsible-text";
41
56
 
42
57
  // One line of text needs no second copy: the one node is the preview while
43
- // collapsed (CSS cuts it) and the whole text once expanded. Several lines get
58
+ // collapsed (CSS clamps it) and the whole text once expanded. Several lines get
44
59
  // a preview node and the full node, one shown at a time.
45
60
  var single = String(text == null ? "" : text).indexOf("\n") === -1;
46
61
  var preview = document.createElement("span");
47
62
  preview.className = "collapsible-preview";
48
- preview.textContent = single ? text : firstLine(text);
63
+ preview.textContent = single ? text : previewLines(text);
49
64
  el.appendChild(preview);
50
65
  if (single) {
51
66
  el.classList.add("collapsible-single");
@@ -0,0 +1,34 @@
1
+ // compaction-state.js - DOM-free derivations for the compaction signals the
2
+ // session view shows: whether the active session is compacting, and whether its
3
+ // context is nearing the vendor's auto-compaction point.
4
+
5
+ // Fraction of the vendor-reported auto-compact threshold at which the meter
6
+ // starts to say compaction is near. A fixed margin: the threshold itself always
7
+ // comes from the vendor (getContextUsage), never from a table of model windows.
8
+ export var NEARING_FRACTION = 0.9;
9
+
10
+ /**
11
+ * @param {?object} usage vendor context usage (getContextUsage shape)
12
+ * @returns {boolean} true only when the vendor reports auto-compaction on with a
13
+ * threshold and usage is within the margin of it (or already past it)
14
+ */
15
+ export function isNearingCompaction(usage) {
16
+ if (!usage || usage.isAutoCompactEnabled !== true) return false;
17
+ var threshold = usage.autoCompactThreshold;
18
+ var total = usage.totalTokens;
19
+ if (typeof threshold !== "number" || !(threshold > 0)) return false;
20
+ if (typeof total !== "number" || !(total >= 0)) return false;
21
+ return total >= threshold * NEARING_FRACTION;
22
+ }
23
+
24
+ /**
25
+ * @param {object[]} sessions a session_list payload
26
+ * @param {?number} activeSessionId
27
+ * @returns {{found: boolean, compacting: boolean}}
28
+ */
29
+ export function compactingFromSessionList(sessions, activeSessionId) {
30
+ for (var i = 0; i < sessions.length; i++) {
31
+ if (sessions[i].id === activeSessionId) return { found: true, compacting: !!sessions[i].compacting };
32
+ }
33
+ return { found: false, compacting: false };
34
+ }
@@ -35,10 +35,25 @@ export function slugifyFilename(filename) {
35
35
  * @returns {Promise<Array<{slug: string, url: string, size?: number, ext?: string}>>}
36
36
  */
37
37
  export function fetchCustomIconList() {
38
+ return fetchCustomIconListStrict().catch(function () { return []; });
39
+ }
40
+
41
+ /**
42
+ * The same list, but a failed request rejects, for a caller that must tell
43
+ * "no icons" from "could not load them".
44
+ *
45
+ * @returns {Promise<Array<{slug: string, url: string, size?: number, ext?: string}>>}
46
+ */
47
+ export function fetchCustomIconListStrict() {
38
48
  return fetch("/api/custom-emoji")
39
- .then(function (r) { return r.json(); })
40
- .then(function (data) { return Array.isArray(data) ? data : []; })
41
- .catch(function () { return []; });
49
+ .then(function (r) {
50
+ if (r.ok === false) throw new Error("HTTP " + r.status);
51
+ return r.json();
52
+ })
53
+ .then(function (data) {
54
+ if (!Array.isArray(data)) throw new Error("unexpected response");
55
+ return data;
56
+ });
42
57
  }
43
58
 
44
59
  /**
@@ -48,9 +63,12 @@ export function fetchCustomIconList() {
48
63
  *
49
64
  * @param {string} slug
50
65
  * @param {File|Blob} file
66
+ * @param {{createOnly?: boolean}} [opts] createOnly: the server refuses a slug
67
+ * that already exists instead of replacing its image.
51
68
  * @returns {Promise<{ok: boolean, slug?: string, url?: string, error?: string}>}
52
69
  */
53
- export function uploadCustomIcon(slug, file) {
70
+ export function uploadCustomIcon(slug, file, opts) {
71
+ var query = opts && opts.createOnly ? "?create=1" : "";
54
72
  return new Promise(function (resolve) {
55
73
  // Defense-in-depth (lr-6c9930): FileReader.readAsArrayBuffer(null/undefined)
56
74
  // throws synchronously inside the Promise executor rather than firing
@@ -64,7 +82,7 @@ export function uploadCustomIcon(slug, file) {
64
82
  }
65
83
  var reader = new FileReader();
66
84
  reader.onload = function (ev) {
67
- fetch("/api/custom-emoji/" + encodeURIComponent(slug), {
85
+ fetch("/api/custom-emoji/" + encodeURIComponent(slug) + query, {
68
86
  method: "POST",
69
87
  body: ev.target.result,
70
88
  }).then(function (r) {