samagotchi 0.137.0 → 0.138.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,6 @@ import {
23
23
  listParticipants, inviteParticipant, revokeParticipant, setParticipantCap,
24
24
  getContext,
25
25
  detachContext,
26
- addContext,
27
26
  renderText,
28
27
  getWorkingSet,
29
28
  updateChi,
@@ -156,7 +155,7 @@ const infoTextEl = $("#infoText");
156
155
  // (updateInfoBar redraws #infoText every tick; the chips keep their popover).
157
156
  const contextChips = createContextChips({
158
157
  el: $("#contextChips"),
159
- api: { list: listContext, show: getContext, detach: detachContext, add: addContext },
158
+ api: { list: listContext, show: getContext, detach: detachContext },
160
159
  toast: (text) => showToast(text),
161
160
  });
162
161
  // The open session's ⚙ chip in the info bar, and its panel (thinking,
@@ -226,10 +225,8 @@ let pageCapabilities = {};
226
225
  let pageEditorUrl = null;
227
226
  const promptEl = $("#prompt");
228
227
  const actionBtn = $("#actionBtn");
229
- const cancelBtn = $("#cancelBtn");
230
228
  const attachBtn = $("#attachBtn");
231
229
  const attachInput = $("#attachInput");
232
- const infoCancelBtn = $("#infoCancelBtn");
233
230
  const composeHintEl = $("#composeHint");
234
231
 
235
232
  // The open session (store.selected), its fields (store.current: session_state.js;
@@ -354,6 +351,8 @@ const turnDom = createStageView({
354
351
  renderMarkdown,
355
352
  linkRefs: linkRefsIn,
356
353
  workingSet,
354
+ // Stop turn in its status row (disabled until the request settles).
355
+ onCancel: () => handleCancel(),
357
356
  });
358
357
  // The history's bottom reserve and the toast's place follow the composer
359
358
  // card and the stage floating over the history (dock_reserve.js).
@@ -684,6 +683,7 @@ const lists = createListsView({
684
683
  showToast: (text, action) => showToast(text, action),
685
684
  allViewOpen: () => allViewOpen(),
686
685
  openAllView: () => openAllView(),
686
+ closeAllView: () => closeAllView(),
687
687
  leaveAllView: (hash) => leaveAllView(hash),
688
688
  renameShown,
689
689
  onRename: () => rename.open(),
@@ -849,6 +849,8 @@ function applyView() {
849
849
  topStripEl.scrollLeft = 0; // a phone's strip scrolls sideways to the tile
850
850
  }
851
851
  document.body.classList.toggle("all-view", open);
852
+ // The sessions pill is the view's button there: pressed while it is open.
853
+ $("#stripStatus").setAttribute("aria-pressed", String(open));
852
854
  updateSessionTitle();
853
855
  // Its chip was in the list just hidden (the strip, or all sessions).
854
856
  lists.chainPop.close();
@@ -866,7 +868,6 @@ window.addEventListener("hashchange", () => {
866
868
  applyView();
867
869
  selectFromHash();
868
870
  });
869
- $("#allBack").addEventListener("click", closeAllView);
870
871
 
871
872
  // A phone's composer fits a few words and has no Shift+Enter: the short
872
873
  // placeholder there.
@@ -898,9 +899,9 @@ function updateComposerMode() {
898
899
  // The start page's choice was for a new session: opening a session drops it.
899
900
  if (store.selected) startPage.dropChoices();
900
901
  const running = liveTurn.running && !!store.selected;
901
- cancelBtn.style.display = running ? "" : "none";
902
902
  // No images for a session a terminal owns (it takes no message from here);
903
- // on a phone none while a turn runs either: Stop turn needs the row's room.
903
+ // on a phone none while a turn runs either: the row keeps its room for the
904
+ // message box (steering).
904
905
  attachBtn.hidden = (!!store.selected && store.current.owner === "tui") || (running && narrowScreen.matches);
905
906
  syncDeliveryLine();
906
907
  if (running) {
@@ -942,6 +943,8 @@ function syncDeliveryLine() {
942
943
  }
943
944
 
944
945
  function setTurnRunning(running) {
946
+ // A running turn the stage held none of goes with it (runningWithoutTurn).
947
+ if (!running) turnDom.runningWithoutTurn?.(false);
945
948
  store.batch(() => {
946
949
  liveTurn.running = !!running;
947
950
  // A fresh link's picker goes now, not at the timing re-read after the turn.
@@ -1202,6 +1205,8 @@ function renderSessionView(data, { kept = [] } = {}) {
1202
1205
  liveTurn.serverGen = gen ? { ...gen, at: Date.now() } : null;
1203
1206
  if (!data.current_turn) {
1204
1207
  setTurnRunning(store.current.status === "running");
1208
+ // Running with no turn to draw: the stage's status row still holds Stop turn.
1209
+ turnDom.runningWithoutTurn?.(liveTurn.running);
1205
1210
  if (liveTurn.running && store.current.timing.activeTurn?.started_at) liveTurn.timing.start(store.current.timing.activeTurn.started_at, activeTurnId);
1206
1211
  } else if (liveTurn.running) {
1207
1212
  // The replayed turn_started carries no id: the running turn's record's.
@@ -1499,6 +1504,8 @@ function updateInfoBar() {
1499
1504
  continueBtn.style.display = buttons.continue.shown ? "" : "none";
1500
1505
  continueBtn.disabled = buttons.continue.disabled;
1501
1506
  continueBtn.textContent = buttons.continue.text;
1507
+ // The accent on an archived session, where it is the thing to do.
1508
+ continueBtn.classList.toggle("accent", buttons.archive.archived);
1502
1509
  }
1503
1510
  if (deleteBtn) deleteBtn.style.display = buttons.delete.shown ? "" : "none";
1504
1511
  if (archiveBtn) {
@@ -1866,18 +1873,14 @@ function queueRefused(altKey) {
1866
1873
  return true;
1867
1874
  }
1868
1875
 
1876
+ // The stage's Stop turn (its button stays disabled until this settles).
1869
1877
  async function handleCancel() {
1870
1878
  if (!store.selected) return;
1871
- cancelBtn.disabled = true;
1872
- infoCancelBtn.disabled = true;
1873
1879
  try {
1874
1880
  await cancelTurn(store.selected);
1875
1881
  } catch (e) {
1876
1882
  // The turn ended meanwhile: nothing left to cancel.
1877
1883
  if (e.code !== "not_running") alert(e.message);
1878
- } finally {
1879
- cancelBtn.disabled = false;
1880
- infoCancelBtn.disabled = false;
1881
1884
  }
1882
1885
  }
1883
1886
 
@@ -1901,7 +1904,7 @@ function promptMinPx() {
1901
1904
  // The composer (composer_mount.js): the box, its height, image chips, grip
1902
1905
  // and fold, ↑/↓ history and keys. The owner's parts come in as hooks: the
1903
1906
  // draft's origin (noteDraft), the / list's keys, the delivery line's Esc and
1904
- // queue, the info bar's Stop turn and drop while folded, typing anywhere.
1907
+ // queue, the info bar's drop while folded, typing anywhere.
1905
1908
  const composer = mountComposer({
1906
1909
  els: {
1907
1910
  composer: composerEl, prompt: promptEl, button: actionBtn, chips: $("#chips"), attachBtn, attachInput,
@@ -1922,11 +1925,9 @@ const composer = mountComposer({
1922
1925
  // Esc lets go of a choice armed on the delivery line.
1923
1926
  escape: () => deliveryControl.disarm(),
1924
1927
  fold: {
1925
- infoCancelBtn,
1926
1928
  infoBarEl: $("#infoBar"),
1927
1929
  session: () => store.selected,
1928
1930
  waiting: () => !!(waitingOn(store.sessions.find((s) => s.id === store.selected)) || questionCards.pendingQuestion()),
1929
- turnRunning: () => liveTurn.running,
1930
1931
  allViewOpen,
1931
1932
  lightboxOpen: () => !lightboxEl.hidden,
1932
1933
  },
@@ -1972,8 +1973,6 @@ lightboxEl.addEventListener("click", () => { lightboxEl.hidden = true; });
1972
1973
  document.addEventListener("keydown", (e) => {
1973
1974
  if (e.key === "Escape" && !lightboxEl.hidden) lightboxEl.hidden = true;
1974
1975
  });
1975
- cancelBtn.addEventListener("click", () => handleCancel());
1976
- infoCancelBtn.addEventListener("click", () => handleCancel());
1977
1976
 
1978
1977
  // The / autocomplete (command_list.js): the session's commands while the
1979
1978
  // composer holds one "/word".
@@ -2195,7 +2194,7 @@ store.on("infoBar", updateInfoBar);
2195
2194
 
2196
2195
  applyView();
2197
2196
 
2198
- // Where sessions live: under the all-sessions search (the server fills it in).
2197
+ // Where sessions live: a footer line under the all-sessions list (the server fills it in).
2199
2198
  if (document.body.dataset.sessionsDir) {
2200
2199
  $("#allPath code").textContent = document.body.dataset.sessionsDir;
2201
2200
  $("#allPath").hidden = false;
@@ -9,7 +9,7 @@
9
9
  import { normalize, previewForCard, relativeTime } from "./format.js";
10
10
  import { stoppedBadge, waitingBadge } from "./sessions_list.js";
11
11
  import { waitingOn } from "./notify.js";
12
- import { archivedBadge, rowBadgesTemplate, rowDotTemplate } from "./families_view.js";
12
+ import { archivedBadge, rowBadgesTemplate } from "./families_view.js";
13
13
  import { html, nothing } from "./vendor/lit-html.js";
14
14
 
15
15
  // The opener a new link's composer is filled with (never sent: the user
@@ -242,10 +242,11 @@ export function chainChipTemplate(f, { open = false } = {}) {
242
242
  }
243
243
 
244
244
  // The chain's list (the chip's popover): one row per other link, newest
245
- // first: status dot, "#N", its date (with its HH:MM when another link of
245
+ // first: "#N", its date (with its HH:MM when another link of
246
246
  // the chain, the head too, started the same day: chainStamp), its own title (/title) when it
247
247
  // differs from the head's (a link inherits its chain's: the card says it), else its recap's
248
- // first sentence, else its preview, the waiting / stopped badge, archived. A row's click opens
248
+ // first sentence, else its preview, the waiting / error / stopped badge, archived (no status dot: the status
249
+ // is in the row's tooltip, as a family row's). A row's click opens
249
250
  // that link (families_view.js's popover binds .family-row[data-id]).
250
251
  // @param activeId the open session's id (its row is .active)
251
252
  // A chain row's words: a name of its own (not the one it shares with the
@@ -270,9 +271,9 @@ export function chainRowsTemplate(f, { activeId = null, now = Date.now() } = {})
270
271
  const ago = relativeTime(s.updated_at || s.created_at || "", now);
271
272
  const tip = `${s.id} · ${s.status || ""}${ago ? ` · updated ${ago}` : ""}`;
272
273
  return html`<div class=${cls.join(" ")} data-id=${s.id} style=${"--depth:1"} role=${"listitem"}><button type="button" class="fr-open"
273
- title=${tip}>${rowDotTemplate(s, waiting)}<span class="cr-n">#${n}</span>${
274
+ title=${tip}><span class="cr-n">#${n}</span>${
274
275
  date ? html`<span class=${date.length > 10 ? "cr-date timed" : "cr-date"}>${date}</span>` : nothing}<span class="fr-preview">${rowTitle(s, headTitle, byId)}</span>${
275
- rowBadgesTemplate(waiting, stopped)}${s.archived ? archivedBadge : nothing}</button></div>`;
276
+ rowBadgesTemplate(waiting, stopped, s.status)}${s.archived ? archivedBadge : nothing}</button></div>`;
276
277
  });
277
278
  return html`<div class="family-rows chain-rows" role="list">${rows}</div>`;
278
279
  }
@@ -1,7 +1,7 @@
1
1
  /* The composer (composer_mount.js): the message box, its image chips, grip and fold, its key hint and its toolbar row
2
2
  (the image button, Send). Shared by the owner's page (index.html) and the participant page (participant.html);
3
3
  linked after tokens.css and before a page's own <style>, so a page's rules of the same weight win. The owner's
4
- own parts stay in index.html: the card's placing (#dock), the delivery line's links, Stop turn, the start page's picker and chips,
4
+ own parts stay in index.html: the card's placing (#dock), the delivery line's links, the start page's picker and chips,
5
5
  the / list, and the 16px text fields for iOS. */
6
6
  /* The image button's icon mask (the stroke only shapes the mask; the icon takes currentColor); index.html's phone info
7
7
  bar and all view's cards use it too. */
@@ -18,7 +18,7 @@ body.no-glass .composer-card{background:var(--bg-panel);-webkit-backdrop-filter:
18
18
  .composer-card-foot{padding:8px 14px 10px;border-top:1px solid var(--glass-border)}
19
19
  .composer-line{flex:1 0 100%;min-width:0;height:20px;padding:0 2px;overflow:hidden;font-size:12px;line-height:18px;color:var(--text-muted);user-select:none}
20
20
  #composer{display:flex;flex-direction:column;gap:8px;padding:14px 14px 10px}
21
- #composer .compose-col{flex:1;display:flex;flex-direction:column;gap:6px;min-width:0}
21
+ #composer .compose-col{position:relative;flex:1;display:flex;flex-direction:column;gap:6px;min-width:0}
22
22
  #composer.dropping{outline:2px dashed var(--accent);outline-offset:-4px}
23
23
  /* In a session the composer is a row: the line's row wraps above the text field and the buttons. */
24
24
  body.has-session #composer{flex-wrap:wrap;row-gap:6px}
@@ -66,24 +66,28 @@ body.has-session.composer-folded #composeGrip::after{opacity:1;width:48px;margin
66
66
  #composeGrip::after{top:17px;opacity:1}
67
67
  }
68
68
  #composer textarea::placeholder{color:var(--text-faint)}
69
- /* Key hint: its line is always reserved, so focusing never shifts the layout. */
70
- #composeHint{order:1;flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:11px;line-height:14px;color:var(--text-faint);padding-left:2px;opacity:0;transition:opacity .12s ease;user-select:none}
71
- #composer:focus-within #composeHint:not(:empty){opacity:1}
69
+ /* Key hint (the start page's): a second faint line under the placeholder, inside the text box (over it, out of the
70
+ flow: it never moves the layout), only while the box is focused and empty; typing hides it. Not over image chips. */
71
+ #composeHint{position:absolute;left:2px;right:2px;top:calc(2px + 1.45em * 15 / 11);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:11px;line-height:14px;color:var(--text-faint);opacity:0;transition:opacity .12s ease;pointer-events:none;user-select:none}
72
+ #composer:focus-within #prompt:placeholder-shown ~ #composeHint:not(:empty){opacity:1}
73
+ #composer #chips:not([hidden]) ~ #composeHint{display:none}
72
74
  #composer textarea:focus{outline:none}
73
- /* The toolbar row: model picker · hint · Cancel · Send (the JS display toggles decide what shows). */
75
+ /* The toolbar row, two clusters: the new session's setup (model picker · ⚙ · 🧰 · the override chips) on the left, what
76
+ is sent (🖼 · Start / Send) on the right; the image button's auto margin is the gap (Send's own when it is hidden). */
74
77
  #composer .actions-col{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:8px}
75
78
  #composer .actions-col button{white-space:nowrap;font-size:12px;padding:0 12px;height:28px;min-height:28px;line-height:28px}
76
- #composer .actions-col .split{order:3;display:flex;gap:4px;margin-left:auto}
79
+ #composer .actions-col .split{order:4;display:flex;gap:4px;margin-left:auto}
80
+ #composer .actions-col .attach-btn:not([hidden]) ~ .split{margin-left:0}
77
81
  #composer #actionBtn{min-width:64px;font-weight:600}
78
82
  /* The image button (app.js: a click opens #attachInput, the hidden file picker; a phone's offers the camera and the photo library):
79
83
  an icon just left of Start / Send, quiet like the model picker; hidden in a session a terminal owns, and on a phone while a turn runs. */
80
- #composer .actions-col .attach-btn{order:2;flex:none;width:28px;padding:0;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--text-muted)}
84
+ #composer .actions-col .attach-btn{order:3;margin-left:auto;flex:none;width:28px;padding:0;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--text-muted)}
81
85
  #composer .actions-col .attach-btn::before{content:"";display:block;width:16px;height:16px;margin:auto;background:currentColor;-webkit-mask:var(--icon-image) center/contain no-repeat;mask:var(--icon-image) center/contain no-repeat}
82
86
  #composer .actions-col .attach-btn:hover{filter:none;color:var(--text);background:color-mix(in srgb,var(--bg-hover) 75%,transparent)}
83
87
  #composer .actions-col .attach-btn[hidden]{display:none}
84
- /* An icon button on the row (the start page's ⚙ and 🧰, start_settings.js and start_toolkit.js): quiet like the image button, its icon a mask in --icon; before it (order 2, earlier in the markup).
88
+ /* An icon button on the row (the start page's ⚙ and 🧰, start_settings.js and start_toolkit.js): quiet like the image button, its icon a mask in --icon; right after the model picker (order 1), before the override chips they set (order 2).
85
89
  .set: something under it is set, an accent dot on a phone (the override chips say it on a wider row). */
86
- #composer .actions-col .icon-btn{order:2;position:relative;flex:none;width:28px;padding:0;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--text-muted)}
90
+ #composer .actions-col .icon-btn{order:1;position:relative;flex:none;width:28px;padding:0;border:1px solid transparent;border-radius:8px;background:transparent;color:var(--text-muted)}
87
91
  #composer .actions-col .icon-btn::before{content:"";display:block;width:16px;height:16px;margin:auto;background:currentColor;-webkit-mask:var(--icon) center/contain no-repeat;mask:var(--icon) center/contain no-repeat}
88
92
  #composer .actions-col .icon-btn:hover{filter:none}
89
93
  #composer .actions-col .icon-btn[aria-expanded="true"]{color:var(--text);background:color-mix(in srgb,var(--bg-hover) 75%,transparent)}
@@ -94,7 +98,7 @@ body.has-session.composer-folded #composeGrip::after{opacity:1;width:48px;margin
94
98
  @media(max-width:600px){#composer .actions-col .icon-btn.set{color:var(--accent)}#composer .actions-col .icon-btn.set::after{content:"";position:absolute;top:3px;right:3px;width:6px;height:6px;border-radius:50%;background:var(--accent)}}
95
99
  @media(pointer:coarse){#composer .actions-col .icon-btn{width:36px;height:36px;min-height:36px}}
96
100
  /* In a session the composer is one row: the text field (one line, growing with its text; fitPrompt sets its height)
97
- and Cancel · Send at its bottom right. The key hint is in the placeholder there, so its row goes. */
101
+ and 🖼 · Send at its bottom right. The key hint is in the placeholder there, so the hint line goes. */
98
102
  body.has-session #composer{flex-direction:row;align-items:flex-end;padding:10px}
99
103
  body.has-session #composer textarea{min-height:0}
100
104
  body.has-session #composeHint{display:none}
@@ -9,23 +9,22 @@ import { readStored, removeStored, writeStored } from "./storage.js";
9
9
  export const GRIP_KEY = "chi_composer_floor";
10
10
 
11
11
  // +session+: the open session's id, or null (the start page). +draft+,
12
- // +waiting+, +turnRunning+, +allViewOpen+, +lightboxOpen+: what the page
13
- // shows now. +imageFiles+ / +addImageFiles+: a drop's images and the chips.
12
+ // +waiting+, +allViewOpen+, +lightboxOpen+: what the page shows now.
13
+ // +imageFiles+ / +addImageFiles+: a drop's images and the chips.
14
14
  // The owner page's own parts (composer_mount.js passes them through):
15
- // +infoCancelBtn+ (Stop turn in the info bar while folded) and +infoBarEl+
16
- // (a file dropped on it while folded), either may be null; +typeAnywhere+:
17
- // typing on the page opens a folded composer.
15
+ // +infoBarEl+ (a file dropped on it while folded; may be null);
16
+ // +typeAnywhere+: typing on the page opens a folded composer. Stop turn
17
+ // isn't the composer's: it sits in the stage's status row (stage_view.js).
18
18
  export function createComposerGrip({
19
- composeGrip, promptEl, infoCancelBtn = null, infoBarEl = null,
19
+ composeGrip, promptEl, infoBarEl = null,
20
20
  session, fitPrompt, promptMinPx, floor, setFloor,
21
- draft, waiting = () => false, turnRunning = () => false, allViewOpen = () => false, lightboxOpen = () => false,
21
+ draft, waiting = () => false, allViewOpen = () => false, lightboxOpen = () => false,
22
22
  imageFiles, addImageFiles, typeAnywhere = true,
23
23
  doc = globalThis.document, win = globalThis.window,
24
24
  }) {
25
25
  // The composer's fold (composer_fold.js): the grip, which is the handle
26
- // while folded, and the info bar's Stop turn while folded (the composer's
27
- // #cancelBtn is folded away then). +gripWillFold+: the drag in progress is
28
- // past the fold threshold.
26
+ // while folded. +gripWillFold+: the drag in progress is past the fold
27
+ // threshold.
29
28
  const gripStartTitle = composeGrip.title;
30
29
  let gripWillFold = false;
31
30
  // A click on the expanded grip folds GRIP_CLICK_FOLD_MS after it, so a
@@ -214,11 +213,10 @@ export function createComposerGrip({
214
213
  }
215
214
  promptEl.focus();
216
215
  }
217
- // The grip as the fold's handle (its title, marks, aria-expanded) and Stop turn
218
- // while folded. The start page's grip only resizes: no role, no fold state.
216
+ // The grip as the fold's handle (its title, marks, aria-expanded). The
217
+ // start page's grip only resizes: no role, no fold state.
219
218
  function drawFoldControls() {
220
219
  const folded = isComposerFolded();
221
- if (infoCancelBtn) infoCancelBtn.style.display = folded && turnRunning() ? "" : "none";
222
220
  if (!session()) {
223
221
  composeGrip.removeAttribute("role");
224
222
  composeGrip.removeAttribute("aria-expanded");
@@ -23,8 +23,8 @@ import { readStored } from "./storage.js";
23
23
  // +escape()+ Esc, true when it let go of something. +imagesOff+: why this
24
24
  // page takes no images (the participant page, until its upload path): a
25
25
  // paste, drop or pick of one toasts it and adds no chip; null takes them.
26
- // +fold+: createComposerGrip's page hooks (session, waiting, turnRunning,
27
- // allViewOpen, lightboxOpen, infoCancelBtn, infoBarEl, typeAnywhere).
26
+ // +fold+: createComposerGrip's page hooks (session, waiting, allViewOpen,
27
+ // lightboxOpen, infoBarEl, typeAnywhere).
28
28
  // @return {el, button, chips(), setChips(list), addImageFiles(files), fit(),
29
29
  // hasDraft(), refreshHistory(), and the grip's isComposerFolded,
30
30
  // openForVisit, focusPrompt, drawFoldControls, newVisit, decideVisit}
@@ -3,16 +3,15 @@
3
3
  // red for a failing refresh), and a popover with its summary, hint link,
4
4
  // text and detach. The chips refresh when a context note arrives in the
5
5
  // stream and when the page gets focus (no event of their own), and their
6
- // ages tick every minute. A "+ URL" chip (when an installed bundle's
7
- // provider can attach one: GET …/context's can_add_url) opens a form that
8
- // attaches a URL (a GitHub PR); the web never adds a command.
6
+ // ages tick every minute. The web attaches nothing itself (`chi context
7
+ // add` does; GET …/context's can_add_url is left unread).
9
8
 
10
9
  import { html, nothing, render } from "./vendor/lit-html.js";
11
10
  import { keepFocus } from "./keep_focus.js";
12
11
  import { popoverPlace } from "./chip_popover.js";
13
12
  import { focusBack, modalDialog } from "./popover_modal.js";
14
13
  import { cantText } from "./format.js";
15
- import { createLatest, stillOn } from "./latest.js";
14
+ import { createLatest } from "./latest.js";
16
15
 
17
16
  // "now", "3m", "2h", "4d" since an ISO time; "" for none.
18
17
  export function ageText(iso, now = Date.now()) {
@@ -45,30 +44,13 @@ export function chipModel(rows, now = Date.now()) {
45
44
  });
46
45
  }
47
46
 
48
- const ADD_TITLE = "Attach a URL (a GitHub PR) the agent can read and hears about when it changes";
49
-
50
47
  // The chips (a lit-html template; attributes after a bound one are bound
51
- // too, so they keep their order). addUrl: end with the "+ URL" chip;
52
- // open: the chip whose popover is open (a source's name), addOpen: the
53
- // "+ URL" form is.
54
- export function chipsTemplate(chips, { addUrl = false, open = null, addOpen = false } = {}) {
48
+ // too, so they keep their order). open: the chip whose popover is open (a
49
+ // source's name).
50
+ export function chipsTemplate(chips, { open = null } = {}) {
55
51
  return html`${chips.map((chip) => html`<button type="button" class=${`ctx-chip ${chip.state}${chip.name === open ? " open" : ""}`}
56
52
  data-name=${chip.name} title=${chip.title} aria-haspopup=${"dialog"} aria-expanded=${chip.name === open ? "true" : "false"}>${
57
- chip.state === "unread" ? html`<span class="ctx-dot" aria-hidden="true"></span>` : nothing}${chip.label}</button>`)}${
58
- addUrl ? html`<button type="button" class=${`ctx-chip ctx-add${addOpen ? " open" : ""}`} data-act=${"add"} title=${ADD_TITLE}
59
- aria-haspopup=${"dialog"} aria-expanded=${addOpen ? "true" : "false"}>+ URL</button>` : nothing}`;
60
- }
61
-
62
- // The "+ URL" popover: the URL, an optional why, Attach; +error+ after a
63
- // try that failed, +busy+ while one runs.
64
- export function addFormTemplate({ error = null, busy = false } = {}) {
65
- return html`<form class="ctx-add-form"><div class="ctx-pop-head"><strong>Attach a URL</strong
66
- ><button type="button" class="ctx-pop-close" data-act="close" aria-label="Close">×</button></div
67
- ><div class="ctx-pop-meta">A link an installed bundle knows (github-pr: a pull request). The agent gets a note when it changes.</div
68
- ><input class="ctx-add-input" name="url" type="url" inputmode="url" placeholder="https://github.com/owner/repo/pull/123" required autocomplete="off"
69
- ><input class="ctx-add-input" name="why" type="text" placeholder="why (optional)" maxlength="300" autocomplete="off"
70
- >${error ? html`<div class="ctx-pop-error" role="alert">${error}</div>` : nothing
71
- }<div class="ctx-pop-actions"><button type="submit" class="ctx-add-submit" ?disabled=${busy}>Attach</button></div></form>`;
53
+ chip.state === "unread" ? html`<span class="ctx-dot" aria-hidden="true"></span>` : nothing}${chip.label}</button>`)}`;
72
54
  }
73
55
 
74
56
  // The popover's inside for one row (GET …/context's); +text+ the row's
@@ -100,22 +82,19 @@ export function popoverTemplate(row, { text = null, now = Date.now() } = {}) {
100
82
  }
101
83
 
102
84
  // The chips for the session bar. el: #contextChips; api: {list(id),
103
- // show(id, name), detach(id, name), add(id, {url, why})}; toast(text).
104
- // Chips, popover and form are lit templates: a redraw (a refresh, the
105
- // minute's tick) keeps their nodes, so focus and typed text stay. The
85
+ // show(id, name), detach(id, name)}; toast(text). Chips and popover are
86
+ // lit templates: a redraw (a refresh, the minute's tick) keeps their nodes,
87
+ // so focus stays. The
106
88
  // popover behaves as every popover does (popover_modal.js): a modal dialog, its chip's
107
89
  // aria-expanded, Esc closes it and focus goes back to the chip.
108
90
  export function createContextChips({ el, api, toast = () => {}, doc = document, win = window }) {
109
91
  let sessionId = null;
110
92
  let rows = [];
111
- let canAdd = false;
112
93
  let openName = null;
113
94
  // Only the newest list read for the open session is drawn (latest.js).
114
95
  const latest = createLatest(() => sessionId);
115
- // The open row's text once read (view text), and the "+ URL" form's
116
- // state ({error, busy}).
96
+ // The open row's text once read (view text).
117
97
  let text = null;
118
- let addState = {};
119
98
  const pop = doc.createElement("div");
120
99
  pop.id = "contextPopover";
121
100
  pop.className = "ctx-popover";
@@ -123,22 +102,16 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
123
102
  doc.body.appendChild(pop);
124
103
  modalDialog(pop, { isOpen: () => openName !== null, doc });
125
104
 
126
- // openName ADD: the "+ URL" form is open.
127
- const ADD = "\u0000add";
128
-
129
105
  function drawChips() {
130
106
  const chips = chipModel(rows);
131
107
  // A source inserted before the focused chip: the focus stays on its source.
132
- keepFocus(el, "data-name", () => render(chipsTemplate(chips, { addUrl: canAdd, open: openName === ADD ? null : openName,
133
- addOpen: openName === ADD }), el));
134
- el.hidden = chips.length === 0 && !canAdd;
135
- // The "+ URL" chip alone sits inline, not on a row of its own.
136
- el.classList.toggle("only-add", chips.length === 0 && canAdd);
108
+ keepFocus(el, "data-name", () => render(chipsTemplate(chips, { open: openName }), el));
109
+ el.hidden = chips.length === 0;
137
110
  }
138
111
 
139
112
  // The chips, and the open popover closed when what it is for has gone.
140
113
  function draw() {
141
- if (openName === ADD ? !canAdd : openName && !chipModel(rows).some((chip) => chip.name === openName)) close();
114
+ if (openName && !chipModel(rows).some((chip) => chip.name === openName)) close();
142
115
  else drawChips();
143
116
  }
144
117
 
@@ -150,16 +123,14 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
150
123
  const data = await api.list(id);
151
124
  if (!fresh()) return;
152
125
  rows = data.sources || [];
153
- canAdd = data.can_add_url === true;
154
126
  } catch {
155
127
  // A session the server doesn't know (gone, or an older chi web): no chips.
156
128
  if (!fresh()) return;
157
129
  rows = [];
158
- canAdd = false;
159
130
  }
160
131
  draw();
161
132
  // An open popover follows its row, but not while it shows the text.
162
- if (openName && openName !== ADD && text === null) {
133
+ if (openName && text === null) {
163
134
  const row = rows.find((r) => r.name === openName);
164
135
  if (row) fill(row);
165
136
  }
@@ -168,7 +139,6 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
168
139
  function load(id) {
169
140
  sessionId = id;
170
141
  rows = [];
171
- canAdd = false;
172
142
  close();
173
143
  return refresh();
174
144
  }
@@ -176,7 +146,6 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
176
146
  function clear() {
177
147
  sessionId = null;
178
148
  rows = [];
179
- canAdd = false;
180
149
  close();
181
150
  }
182
151
 
@@ -218,62 +187,21 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
218
187
  drawChips();
219
188
  }
220
189
 
221
- const drawAdd = (changes = {}) => {
222
- addState = { ...addState, ...changes };
223
- render(addFormTemplate(addState), pop);
224
- };
225
-
226
- function openAdd(chip) {
227
- render(nothing, pop);
228
- openName = ADD;
229
- text = null;
230
- pop.setAttribute("aria-label", "Attach a URL");
231
- addState = {};
232
- drawAdd();
233
- pop.hidden = false;
234
- place(chip);
235
- drawChips();
236
- pop.querySelector('input[name="url"]')?.focus();
237
- }
238
-
239
- async function submitAdd(form) {
240
- const id = sessionId;
241
- const url = form.elements.url.value.trim();
242
- const why = form.elements.why.value.trim();
243
- if (!id || !url) return;
244
- const still = stillOn(() => sessionId);
245
- drawAdd({ busy: true });
246
- try {
247
- const data = await api.add(id, { url, why: why || undefined });
248
- if (!still()) return;
249
- close();
250
- await refresh();
251
- toast(`Attached ${data.name}: the agent gets a note before your next message`);
252
- } catch (e) {
253
- if (!still() || openName !== ADD) return;
254
- // The same form again: what the user typed stays; the URL gets focus.
255
- drawAdd({ busy: false, error: e.message });
256
- pop.querySelector('input[name="url"]')?.focus();
257
- }
258
- }
259
-
260
190
  // Focus that was in it (or +refocus+: Esc) goes back to its chip.
261
191
  function close({ refocus = false } = {}) {
262
192
  const back = focusBack(pop, { refocus, doc });
263
193
  const name = openName;
264
194
  openName = null;
265
195
  text = null;
266
- addState = {};
267
196
  pop.hidden = true;
268
197
  render(nothing, pop);
269
198
  drawChips();
270
- if (name !== null) back(name === ADD ? el.querySelector('.ctx-chip[data-act="add"]')
271
- : [...el.querySelectorAll(".ctx-chip[data-name]")].find((chip) => chip.dataset.name === name));
199
+ if (name !== null) back([...el.querySelectorAll(".ctx-chip[data-name]")].find((chip) => chip.dataset.name === name));
272
200
  }
273
201
 
274
202
  async function viewText() {
275
203
  const name = openName;
276
- if (!name || name === ADD) return;
204
+ if (!name) return;
277
205
  try {
278
206
  const data = await api.show(sessionId, name);
279
207
  if (name !== openName) return;
@@ -308,16 +236,9 @@ export function createContextChips({ el, api, toast = () => {}, doc = document,
308
236
  if (!chip) return;
309
237
  // On to the document: a session-bar chip's popover closes (the close
310
238
  // below leaves clicks in +el+ alone).
311
- if (chip.dataset.act === "add") {
312
- if (openName === ADD) close();
313
- else openAdd(chip);
314
- } else if (openName === chip.dataset.name) close();
239
+ if (openName === chip.dataset.name) close();
315
240
  else open(chip.dataset.name, chip);
316
241
  });
317
- pop.addEventListener("submit", (e) => {
318
- e.preventDefault();
319
- submitAdd(e.target);
320
- });
321
242
  pop.addEventListener("click", (e) => {
322
243
  const act = e.target.closest("[data-act]")?.dataset.act;
323
244
  if (act === "close") close();
@@ -397,6 +397,8 @@ export function getContext(id, name, opts = {}) {
397
397
  }
398
398
 
399
399
  // A URL an installed bundle's provider attaches: {url, why} → {name}.
400
+ // Unused since the web's "+ URL" went; kept while an older app.js that
401
+ // imports it may still be cached (internals/web-frontend.md, new exports).
400
402
  export function addContext(id, body, opts = {}) {
401
403
  return api(`/api/sessions/${encodeURIComponent(id)}/context`, {
402
404
  method: "POST", body: JSON.stringify(body), ...opts,