web: compose with Enter, share chat titles, reserve the star
Enter inserts a newline and Ctrl/Cmd+Enter sends; slash commands still run on Enter. Chat renames are stored in the server registry so every device sees the same title, with a one-time upload of old local titles. The star no longer covers the row status, and shell frames patch the background bar in place so the composer stays mounted while streaming.
This commit is contained in:
@@ -212,6 +212,15 @@ func (s *Store) ReopenOperatorSession(ctx context.Context, sessionID string) err
|
||||
return err
|
||||
}
|
||||
|
||||
// SetOperatorSessionTitle records the operator's shared chat title in one
|
||||
// UPDATE. It deliberately does not touch last_used_at: renaming is not use and
|
||||
// must not reorder the list. A session id that is not an operator session
|
||||
// updates no row and is not an error.
|
||||
func (s *Store) SetOperatorSessionTitle(ctx context.Context, sessionID, title string) error {
|
||||
_, err := s.db.ExecContext(ctx, "UPDATE operator_sessions SET title=? WHERE session_id=?", title, sessionID)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetOperatorSessionStar records the shared star state in one UPDATE. A session
|
||||
// id that is not an operator session updates no row and is not an error, so a
|
||||
// pipeline-owned run session is never affected.
|
||||
|
||||
@@ -51,3 +51,42 @@ func TestOperatorSessionStarIsSharedAndReversible(t *testing.T) {
|
||||
t.Fatalf("star toggling changed other session fields: %+v", plain)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOperatorSessionTitleIsShared proves the shared rename contract: the
|
||||
// registry title is updated without changing the OpenCode session id, other
|
||||
// fields or recency, and listing returns the new title for every client.
|
||||
func TestOperatorSessionTitleIsShared(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
store, err := Open(filepath.Join(t.TempDir(), "rename.db"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer store.Close()
|
||||
if err := store.RecordOperatorSession(ctx, "ses_a", "/work/a", "New chat", "operator"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, found, err := store.OperatorSession(ctx, "ses_a")
|
||||
if err != nil || !found {
|
||||
t.Fatalf("lookup: found=%v err=%v", found, err)
|
||||
}
|
||||
if err := store.SetOperatorSessionTitle(ctx, "ses_a", "Shared name"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
after, found, err := store.OperatorSession(ctx, "ses_a")
|
||||
if err != nil || !found {
|
||||
t.Fatalf("lookup after rename: found=%v err=%v", found, err)
|
||||
}
|
||||
if after.Title != "Shared name" {
|
||||
t.Fatalf("title = %q", after.Title)
|
||||
}
|
||||
if after.ID != before.ID || after.Directory != before.Directory || after.UpdatedAt != before.UpdatedAt {
|
||||
t.Fatalf("rename changed unrelated fields:\nbefore %+v\nafter %+v", before, after)
|
||||
}
|
||||
listed, err := store.OperatorSessions(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(listed) != 1 || listed[0].Title != "Shared name" {
|
||||
t.Fatalf("list did not return the shared title: %+v", listed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,9 @@ const (
|
||||
// only records the finished state, it never detaches a client.
|
||||
ChatClose = "chat_close"
|
||||
ChatReopen = "chat_reopen"
|
||||
// ChatRename records the operator's shared chat title on the server. Unlike
|
||||
// a local override, every browser and device then lists the same name.
|
||||
ChatRename = "chat_rename"
|
||||
// ChatStar records the operator's star on the server, so every browser and
|
||||
// device shows the same starred group. It takes a ChatQuery with SessionID
|
||||
// and Starred, and echoes the updated session like close/reopen.
|
||||
@@ -431,6 +434,13 @@ type ChatFormOption struct {
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// ChatRenameRequest is the chat_rename body: the session id and the trimmed
|
||||
// shared title. An empty title is refused rather than clearing the name.
|
||||
type ChatRenameRequest struct {
|
||||
SessionID string `json:"session_id"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// ChatAnswerRequest is the chat_answer body: the form id and a field-keyed
|
||||
// answer object. It is deliberately separate from ChatQuery because its payload
|
||||
// is structured answers, not a session-scoped read.
|
||||
|
||||
@@ -186,6 +186,8 @@ type Message struct {
|
||||
// ChatAnswer is the chat_answer body; the form update arrives through the
|
||||
// normal chat_event stream.
|
||||
ChatAnswer *ChatAnswerRequest `json:"chat_answer,omitempty"`
|
||||
// ChatRename is the chat_rename body; the reply echoes the updated session.
|
||||
ChatRename *ChatRenameRequest `json:"chat_rename,omitempty"`
|
||||
// ChatSubscribe attaches this connection to one session's shared stream; the
|
||||
// body names the session like ChatQuery. A chat_prompt response sets
|
||||
// ChatQueued when the prompt had to wait for an in-flight turn and was
|
||||
|
||||
@@ -91,6 +91,7 @@ type operatorRegistry interface {
|
||||
CloseOperatorSession(ctx context.Context, sessionID string) error
|
||||
ReopenOperatorSession(ctx context.Context, sessionID string) error
|
||||
SetOperatorSessionStar(ctx context.Context, sessionID string, starred bool) error
|
||||
SetOperatorSessionTitle(ctx context.Context, sessionID, title string) error
|
||||
}
|
||||
|
||||
var chatTokenSequence atomic.Uint64
|
||||
@@ -153,6 +154,9 @@ func handleChat(ctx context.Context, request protocol.Message, broker chatBroker
|
||||
case protocol.ChatStar:
|
||||
handleChatStar(ctx, request, registry, write)
|
||||
return true
|
||||
case protocol.ChatRename:
|
||||
handleChatRename(ctx, request, registry, write)
|
||||
return true
|
||||
case protocol.ChatShells:
|
||||
handleChatShells(ctx, request, broker, registry, write)
|
||||
return true
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.a-wan.net/alan/pipelines/internal/opencode"
|
||||
"git.a-wan.net/alan/pipelines/internal/protocol"
|
||||
)
|
||||
|
||||
// chatTitleLimit bounds a shared chat title. The UI disables Save on a blank
|
||||
// value; the server enforces the same rule so a direct client cannot erase a
|
||||
// title or store an unbounded string.
|
||||
const chatTitleLimit = 200
|
||||
|
||||
// handleChatRename records the operator's shared chat title. The operator-session
|
||||
// registry's title overrides OpenCode's own title in chat_sessions, so every
|
||||
// browser and device lists the same name. The OpenCode session, its transcript
|
||||
// and its generated title are untouched, and a session that is not an operator
|
||||
// chat is refused before anything is written.
|
||||
func handleChatRename(ctx context.Context, request protocol.Message, registry operatorRegistry, write func(protocol.Message) error) {
|
||||
if registry == nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "operator session registry is not configured on this server"})
|
||||
return
|
||||
}
|
||||
rename := request.ChatRename
|
||||
if rename == nil || !opencode.ValidSessionID(rename.SessionID) {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a valid OpenCode session id is required"})
|
||||
return
|
||||
}
|
||||
title := strings.TrimSpace(rename.Title)
|
||||
if title == "" {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat title with usable text is required"})
|
||||
return
|
||||
}
|
||||
if utf8.RuneCountInString(title) > chatTitleLimit {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "a chat title must be at most 200 characters"})
|
||||
return
|
||||
}
|
||||
if _, found, err := registry.OperatorSession(ctx, rename.SessionID); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
} else if !found {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + rename.SessionID + " is not an operator chat session"})
|
||||
return
|
||||
}
|
||||
if err := registry.SetOperatorSessionTitle(ctx, rename.SessionID, title); err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
session, found, err := registry.OperatorSession(ctx, rename.SessionID)
|
||||
if err != nil {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: err.Error()})
|
||||
return
|
||||
}
|
||||
if !found {
|
||||
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "session " + rename.SessionID + " is no longer an operator session"})
|
||||
return
|
||||
}
|
||||
wire := chatSessionFromOperator(session)
|
||||
write(protocol.Message{
|
||||
Type: protocol.ChatRename,
|
||||
ID: request.ID,
|
||||
ChatSession: &wire,
|
||||
ChatSessions: []protocol.ChatSession{wire},
|
||||
})
|
||||
}
|
||||
@@ -165,6 +165,8 @@ to it, but the server never lists it and a reload drops it.
|
||||
| B2 | Pipeline list mini graph | `list_pipelines` (`shape`) | done — each summary now carries the current version's parsed graph as `shape`; the browser draws a label-free miniature from the real `layoutGraph` with terminal-free stage routes. The row shows the name, the shape and only `{N stages}`; the cryptic `id {n} · v{n} · …` line is gone. Verified at 390×844 against the live server: 9 rows, 9 miniatures, and the detail still owns the full Graph tab. Additive field; older clients ignore it. |
|
||||
| B3 | Equal phone dock cells | — | done — the narrow dock is a four-cell grid (one cell per destination plus Search) with a subgrid for the tablist, so every control has the same width and height. At 390×844 the measured widths are 92/92/92/92 and the row is 48px high. The phone shell uses `100svh` so a browser toolbar cannot hide the tab row while leaving only the Connected/Settings status row visible. |
|
||||
| B4 | Full-height pipeline Source | — | done — the Source block no longer caps itself at `60vh`; it is as tall as its content and the detail pane owns the scroll. Verified at 390×844: a 4386px definition sits in the full pane (656px viewport) and scrolls. |
|
||||
| B11 | Enter composes; live shell bars stay in place | — | done — Enter now inserts a newline (a real CDP Enter produced `first\n` and no prompt), while Ctrl/Cmd+Enter sends; a slash draft still runs its command on Enter. The chat star reserves a 26px corner in the row head, so it no longer covers Streaming/New/Idle. Background-shell frames patch the tasks bar in place instead of full-rendering the pane, keeping the composer mounted. The shell cache was bumped to v2 so an installed PWA picks up these client changes. |
|
||||
| B10 | Chat titles are shared across devices | `chat_rename` | done — the rename dialog writes the title to the server's operator-session registry (`SetOperatorSessionTitle`) instead of a device-local override. `chat_sessions` already prefers that title, so a second browser opened with a fresh profile showed `Shared rename probe` without any local storage; restoring it to `New chat` did the same. Old local titles are uploaded once on the next list load and then removed. The helper now reads `This name is shared with every device.` |
|
||||
| B9 | Scroll intent, stable overlays and a Settings refresh | — | done — a touch/pointer scroll now marks operator intent, so scrolling up during streaming is not snapped back by the next frame (verified: scrollTop stayed at the top while a synthetic text frame arrived). Open rename/close dialogs are marked `data-modal-stable`; the modal controller keeps the mounted panel, focus, typed value and selection across streaming re-renders, so the rename no longer blinks/reappears and its `modal-in` animation runs once. Bursts of chat frames are coalesced to one paint per animation frame. Settings gained a `Refresh` action that pings the server and repaints the build/time card. |
|
||||
| B8 | Composer keeps focus and the running line stays stable | — | done — a live frame re-renders the transcript, so the composer now captures and restores its focus, value and selection (verified in a real browser: a synthetic `chat_event` arrived while the caret sat at 8–14 and the input stayed focused with the same value/selection). The running indicator is one ellipsised line that updates in place for the longest-running tool instead of adding/removing a line per call; measured height stayed 52px across tool start/finish until the step ended. Pipeline-list miniatures are right-aligned at the row's trailing edge. |
|
||||
| B7 | Chat detail is a real history entry with a compact Back | `/chat/:id` | done — opening a session pushes `/chat/:id`, so Android's back gesture/browser Back returns to the chat list instead of the previous destination. The conversation header now owns a 32px back control matching the create pane (the full-width "Back to list" row is gone for chat; it remains on the other detail panes). Verified at 390×844: the header control reads `Back to chats`, the URL changes to `/chat/ses_…`, pressing it returns to `/chat` with the list restored, and `history.back()` from a reopened chat does the same. |
|
||||
|
||||
+10
-1
@@ -134,7 +134,16 @@
|
||||
/* The inner session button must never take the generic button hover fill: on a
|
||||
selected row it read as a darker rectangle inside the row's own padding. */
|
||||
.chat-session-button:hover { background: none; }
|
||||
.chat-row .row-head { grid-column: 1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
|
||||
.chat-row .row-head {
|
||||
grid-column: 1;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
/* The star is an absolute top-right overlay; reserve its corner so it never
|
||||
covers the Streaming/New/Idle word on a touch screen where it is always on. */
|
||||
padding-right: 26px;
|
||||
}
|
||||
.chat-row .row-title { min-width: 0; }
|
||||
.chat-row .row-meta { grid-column: 1; }
|
||||
.chat-row-model { font-size: 11px; }
|
||||
|
||||
+1
-2
@@ -600,8 +600,7 @@ export const CHAT_REMOVED_MESSAGE = "Hidden on this device; the chat stays on th
|
||||
export const CHAT_UNDO_ACTION = "Undo";
|
||||
export const CHAT_RENAME_TITLE = "Rename chat";
|
||||
export const CHAT_RENAME_FIELD_LABEL = "Name";
|
||||
export const CHAT_RENAME_HELPER =
|
||||
"The server has no rename for a chat, so this name is kept on this device.";
|
||||
export const CHAT_RENAME_HELPER = "This name is shared with every device.";
|
||||
export const CHAT_RENAME_SAVE = "Save";
|
||||
export const CHAT_RENAME_DISMISS = "Cancel";
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ export const Protocol = Object.freeze({
|
||||
CHAT_CLOSE: "chat_close",
|
||||
CHAT_REOPEN: "chat_reopen",
|
||||
CHAT_STAR: "chat_star",
|
||||
CHAT_RENAME: "chat_rename",
|
||||
// The shared live stream (C5). `chat_subscribe` attaches this connection to one
|
||||
// session's stream (body: the session id); the server then pushes `chat_event`
|
||||
// frames without a matching request id, so every client watching a session sees
|
||||
@@ -114,6 +115,7 @@ export const ChatKeys = Object.freeze({
|
||||
SUBSCRIBE: "chat_subscribe",
|
||||
EVENT: "chat_event",
|
||||
ANSWER: "chat_answer",
|
||||
RENAME: "chat_rename",
|
||||
// The composer's payloads (C8/C9). `chat_interrupt` deliberately has no key of
|
||||
// its own: its body is the same `chat_query` the other session-scoped commands
|
||||
// carry (internal/protocol/chat.go ChatQuery, Chat.kt interruptRequest), so a
|
||||
|
||||
@@ -371,6 +371,18 @@ export class PipelinesRepository {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Records the shared chat title on the server (chat_rename), so every browser
|
||||
* and device lists the same name. Returns the updated session row.
|
||||
*/
|
||||
async renameChat(sessionId, title) {
|
||||
const response = await this.#client.call({
|
||||
type: Protocol.CHAT_RENAME,
|
||||
[ChatKeys.RENAME]: { session_id: sessionId, title: String(title ?? "").trim() },
|
||||
});
|
||||
return response[ChatKeys.SESSION] ?? null;
|
||||
}
|
||||
|
||||
/** Clears the closed state again, so a finished chat can be resumed. */
|
||||
async reopenChat(sessionId) {
|
||||
const response = await this.#client.call({
|
||||
|
||||
+153
-32
@@ -427,6 +427,32 @@ async function loadChatSessions(force = false) {
|
||||
}
|
||||
writeChatStars(new Set());
|
||||
}
|
||||
// One-time migration from device-local chat titles. The server now owns the
|
||||
// shared title; upload any saved local title, then drop it so other devices
|
||||
// cannot be outvoted by a stale override.
|
||||
const localTitles = { ...(state.chatOverrides?.titles ?? {}) };
|
||||
let titlesChanged = false;
|
||||
for (const [id, title] of Object.entries(localTitles)) {
|
||||
const session = listed.find((entry) => entry.id === id);
|
||||
if (!session) continue;
|
||||
if (String(session.title ?? "").trim() === title) {
|
||||
delete localTitles[id];
|
||||
titlesChanged = true;
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
const updated = await repo.renameChat(id, title);
|
||||
if (updated) Object.assign(session, updated);
|
||||
delete localTitles[id];
|
||||
titlesChanged = true;
|
||||
} catch {
|
||||
// Keep the local title and retry on a later list load.
|
||||
}
|
||||
}
|
||||
if (titlesChanged) {
|
||||
state.chatOverrides = { ...state.chatOverrides, titles: localTitles };
|
||||
saveChatOverrides();
|
||||
}
|
||||
// Keep this page's own verification chats, which the server intentionally
|
||||
// never returns, at the head of the in-memory list (memory-only; see
|
||||
// chatEphemeralIds). Everything else is the server's list, in its order.
|
||||
@@ -629,24 +655,78 @@ function settleChatThreads() {
|
||||
* to, so this is a no-op in practice until a chat is opened.
|
||||
*/
|
||||
let chatRenderScheduled = false;
|
||||
let chatRenderMode = null;
|
||||
|
||||
/**
|
||||
* Coalesce a burst of pushed frames into one paint. A turn can emit many text
|
||||
* and tool frames in the same animation frame; rebuilding the transcript for
|
||||
* each one made the text flicker and restarted in-flight animations. State is
|
||||
* folded immediately; only the DOM paint is deferred.
|
||||
* and tool frames in the same animation frame; rebuilding the whole page for
|
||||
* each one made the text flicker and replaced the composer, which on a phone
|
||||
* drops the virtual keyboard. Transcript-only paints replace just the message
|
||||
* scroller and leave the composer DOM untouched.
|
||||
*/
|
||||
function scheduleChatRender() {
|
||||
function scheduleChatRender(mode = "full") {
|
||||
if (mode === "full" || chatRenderMode == null) chatRenderMode = mode === "full" ? "full" : chatRenderMode ?? "transcript";
|
||||
if (chatRenderScheduled) return;
|
||||
chatRenderScheduled = true;
|
||||
const paint = () => {
|
||||
chatRenderScheduled = false;
|
||||
const chosen = chatRenderMode;
|
||||
chatRenderMode = null;
|
||||
if (chosen === "transcript" && refreshChatTranscript(state.chatActiveId)) return;
|
||||
renderContent();
|
||||
};
|
||||
if (typeof requestAnimationFrame === "function") requestAnimationFrame(paint);
|
||||
else setTimeout(paint, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repaint only the transcript scroller for a live frame. The composer, its
|
||||
* focused textarea, the chat bar and the background-task bar are left mounted,
|
||||
* so a phone keeps its keyboard open while an answer streams. Returns false
|
||||
* when the page is not in a shape this can update safely; the caller then does
|
||||
* a full render.
|
||||
*/
|
||||
function refreshChatTranscript(sessionId) {
|
||||
if (!sessionId || state.chatActiveId !== sessionId || state.view !== "chat") return false;
|
||||
const oldWrap = document.querySelector(".chat-transcript-wrap");
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
if (!oldWrap || !thread) return false;
|
||||
const rows = transcriptRows(thread.messages ?? []);
|
||||
const notices = thread.notices ?? [];
|
||||
const approval = approvalCard(thread.permission, thread.permissionAnswer);
|
||||
const form =
|
||||
thread.form && thread.form.resolved !== true && thread.form.cancelled !== true
|
||||
? thread.form
|
||||
: null;
|
||||
if (rows.length === 0 && notices.length === 0 && !thread.running && !approval && !form) {
|
||||
return false;
|
||||
}
|
||||
const running = thread.running === true && approval?.actionable !== true;
|
||||
captureChatPosition();
|
||||
// The background-tasks bar sits outside the transcript but is driven by the
|
||||
// same shell frames. Patch it in place instead of full-rendering the pane (and
|
||||
// closing the phone keyboard) when a background command starts or exits.
|
||||
const oldTasks = document.getElementById("chatBackgroundTasks");
|
||||
const nextTasks = renderBackgroundTasks(thread);
|
||||
if (nextTasks) {
|
||||
if (oldTasks) oldTasks.replaceWith(nextTasks);
|
||||
else oldWrap.before(nextTasks);
|
||||
} else if (oldTasks) {
|
||||
oldTasks.remove();
|
||||
}
|
||||
const next = renderChatTranscript(sessionId, rows, {
|
||||
notices,
|
||||
running,
|
||||
now: Date.now(),
|
||||
approval,
|
||||
form,
|
||||
});
|
||||
oldWrap.replaceWith(next);
|
||||
afterChatRender();
|
||||
refreshChatClock();
|
||||
return true;
|
||||
}
|
||||
|
||||
function onChatEvent(frame) {
|
||||
const sessionId = String(frame?.session_id ?? "").trim();
|
||||
if (!sessionId || !state.chatThreads.has(sessionId)) return;
|
||||
@@ -660,7 +740,7 @@ function onChatEvent(frame) {
|
||||
// missed) appears without a manual refresh.
|
||||
const knownTurn = messageId !== "" && (thread.messages ?? []).some((m) => m?.id === messageId);
|
||||
state.chatThreads.set(sessionId, applyChatEvent(thread, frame, Date.now()));
|
||||
scheduleChatRender();
|
||||
scheduleChatRender("transcript");
|
||||
if (!knownTurn) scheduleHistorySync(sessionId, messageId);
|
||||
}
|
||||
|
||||
@@ -892,7 +972,10 @@ async function loadChatHistory(id) {
|
||||
} catch (error) {
|
||||
setThread(id, { loading: false, loaded: true, error: describeError(error) });
|
||||
}
|
||||
renderContent();
|
||||
// A streaming turn triggers this resync after its first unseen message. Keep
|
||||
// the composer mounted when the transcript already exists; replacing the whole
|
||||
// page here closed the phone keyboard mid-turn.
|
||||
if (!refreshChatTranscript(id)) renderContent();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -916,7 +999,7 @@ async function loadOlderChatHistory(id) {
|
||||
} catch (error) {
|
||||
setThread(id, { loading: false, error: describeError(error) });
|
||||
}
|
||||
renderContent();
|
||||
if (!refreshChatTranscript(id)) renderContent();
|
||||
}
|
||||
|
||||
/** Open the Close chat? confirm for [session] (the mutation only on confirm). */
|
||||
@@ -1057,31 +1140,39 @@ function dismissChatRename() {
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a local rename, persist it and reflect it at once: the row shows the
|
||||
* local title on the next render (and every later refresh), and an open
|
||||
* conversation's own title follows. Nothing is sent to the server — the
|
||||
* brokered protocol has no chat rename.
|
||||
*/
|
||||
function applyLocalChatRename(sessionId, title) {
|
||||
const next = renameChatOverride(state.chatOverrides, sessionId, title);
|
||||
if (next === state.chatOverrides) return false;
|
||||
state.chatOverrides = next;
|
||||
/** Drop this device's old local title now that the server carries it. */
|
||||
function clearLocalChatTitle(sessionId) {
|
||||
const id = String(sessionId ?? "");
|
||||
const titles = { ...(state.chatOverrides?.titles ?? {}) };
|
||||
if (!(id in titles)) return;
|
||||
delete titles[id];
|
||||
state.chatOverrides = { ...state.chatOverrides, titles };
|
||||
saveChatOverrides();
|
||||
const local = next.titles[String(sessionId)];
|
||||
if (local != null) setThread(sessionId, { title: local });
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The dialog's Save: trim, record the override, close the dialog and re-render.
|
||||
* A blank title is ignored (Save is already disabled while trimmed-blank).
|
||||
* The dialog's Save: trim, write the shared title through `chat_rename`, close
|
||||
* the dialog and re-render. The server's registry title is authoritative; a
|
||||
* failure leaves the dialog open and surfaces the server's reason. A blank title
|
||||
* is ignored (Save is already disabled while trimmed-blank).
|
||||
*/
|
||||
function acceptChatRename(session, title) {
|
||||
async function acceptChatRename(session, title) {
|
||||
if (state.chatBusy) return;
|
||||
const trimmed = String(title ?? "").trim();
|
||||
if (trimmed === "") return;
|
||||
applyLocalChatRename(session.id, trimmed);
|
||||
state.chatRename = null;
|
||||
state.chatBusy = true;
|
||||
try {
|
||||
const updated = await repo.renameChat(session.id, trimmed);
|
||||
if (updated) {
|
||||
applyChatSessionUpdate(session.id, updated, updated.closed === true);
|
||||
clearLocalChatTitle(session.id);
|
||||
setThread(session.id, { title: updated.title ?? trimmed });
|
||||
}
|
||||
state.chatRename = null;
|
||||
} catch (error) {
|
||||
state.actionError = describeError(error);
|
||||
}
|
||||
state.chatBusy = false;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
@@ -1183,6 +1274,32 @@ function releaseAttachments(attachments) {
|
||||
* the rest of the frame fold; this only keeps the composer honest while C5 is
|
||||
* still to land.
|
||||
*/
|
||||
/**
|
||||
* Update the composer's primary control and queued notice in place when only
|
||||
* the running/queued flags changed. The textarea and its listeners stay mounted,
|
||||
* so a phone keeps the keyboard open across the start and end of a turn.
|
||||
*/
|
||||
function refreshChatComposerState(sessionId) {
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
if (!thread || state.chatActiveId !== sessionId) return;
|
||||
const primary = document.querySelector("#chatComposer .chat-composer-primary");
|
||||
if (primary) {
|
||||
const session = state.chatSessions.find((row) => row.id === sessionId) ?? null;
|
||||
fillComposerPrimary(primary, thread, {
|
||||
onSend: () => submitChatComposer(sessionId, session, { selected: 0 }),
|
||||
onStop: () => stopChatTurn(sessionId),
|
||||
});
|
||||
}
|
||||
const composer = document.getElementById("chatComposer");
|
||||
if (!composer) return;
|
||||
const existing = document.getElementById("chatQueued");
|
||||
if (thread.queued && !existing) {
|
||||
composer.prepend(h("div", { class: "chat-queued", id: "chatQueued", text: CHAT_QUEUED_NOTICE }));
|
||||
} else if (!thread.queued && existing) {
|
||||
existing.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function onChatFrame(message) {
|
||||
const frame = message?.chat_event;
|
||||
if (!frame || !frame.session_id) return;
|
||||
@@ -1194,7 +1311,10 @@ function onChatFrame(message) {
|
||||
const running = runningAfterFrame(thread.running, frame);
|
||||
if (queued === thread.queued && running === thread.running) return;
|
||||
setThread(sessionId, { queued, running });
|
||||
if (sessionId === state.chatActiveId) scheduleChatRender();
|
||||
if (sessionId === state.chatActiveId) {
|
||||
refreshChatComposerState(sessionId);
|
||||
scheduleChatRender("transcript");
|
||||
}
|
||||
}
|
||||
|
||||
/** Add one local command line to a conversation's transcript. */
|
||||
@@ -1242,11 +1362,9 @@ function onComposerInput(event, sessionId, session, controls) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The composer's key handling. While the offer list is showing, Up/Down move the
|
||||
* highlight and Enter runs the highlighted command (mirrors ChatComposer's
|
||||
* preview handler). Enter otherwise submits — which is inert while a turn is
|
||||
* running unless the palette or a slash draft is present (see composerSubmit);
|
||||
* Shift+Enter is left to insert a newline.
|
||||
* The composer's key handling. Enter inserts a newline (so a phone keyboard can
|
||||
* compose multi-line text); Ctrl/Cmd+Enter sends. A slash draft still runs on
|
||||
* Enter, matching the command palette. Up/Down move the highlighted command.
|
||||
*/
|
||||
function onComposerKeydown(event, sessionId, session, controls) {
|
||||
const thread = state.chatThreads.get(sessionId);
|
||||
@@ -1259,7 +1377,9 @@ function onComposerKeydown(event, sessionId, session, controls) {
|
||||
refreshComposerControls(sessionId, session, controls);
|
||||
return;
|
||||
}
|
||||
if (event.key === "Enter" && !event.shiftKey) {
|
||||
if (event.key !== "Enter") return;
|
||||
const slash = String(thread.draft ?? "").trimStart().startsWith("/");
|
||||
if (slash || event.metaKey || event.ctrlKey) {
|
||||
event.preventDefault();
|
||||
submitChatComposer(sessionId, session, controls);
|
||||
}
|
||||
@@ -3190,6 +3310,7 @@ function renderChatComposer(thread, session, sessionId) {
|
||||
rows: "1",
|
||||
placeholder: CHAT_COMPOSER_PLACEHOLDER,
|
||||
"aria-label": CHAT_COMPOSER_PLACEHOLDER,
|
||||
title: "Enter adds a new line · Ctrl/Cmd+Enter sends",
|
||||
spellcheck: "false",
|
||||
});
|
||||
input.value = thread.draft ?? "";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// A shell cache for an installed Pipelines app. The API (the WebSocket proxy and
|
||||
// artifact files) is never cached; static files prefer the network and fall back
|
||||
// to the last good copy so an installed app still opens when the server is away.
|
||||
const CACHE = "pipelines-shell-v1";
|
||||
const CACHE = "pipelines-shell-v2";
|
||||
const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
|
||||
@@ -1930,7 +1930,7 @@ test("the C13 wording matches the Android sources verbatim", () => {
|
||||
assert.equal(CHAT_RENAME_FIELD_LABEL, "Name");
|
||||
assert.equal(
|
||||
CHAT_RENAME_HELPER,
|
||||
"The server has no rename for a chat, so this name is kept on this device.",
|
||||
"This name is shared with every device.",
|
||||
);
|
||||
assert.equal(CHAT_RENAME_SAVE, "Save");
|
||||
assert.equal(CHAT_RENAME_DISMISS, "Cancel");
|
||||
|
||||
@@ -6011,7 +6011,7 @@ try {
|
||||
// A real prompt to the throwaway session turns the Send control into Stop.
|
||||
await page.fill("#chatInput", "Reply with exactly one word: hi");
|
||||
await page.evaluate(
|
||||
`document.querySelector("#chatInput").dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }))`,
|
||||
`document.querySelector("#chatInput").dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true, bubbles: true, cancelable: true }))`,
|
||||
);
|
||||
await page.waitForSelector("#chatStop", { timeout: 20000 });
|
||||
const running = await page.evaluate(`(() => ({
|
||||
@@ -7904,7 +7904,7 @@ try {
|
||||
if (renameDialog.value !== "New chat") throw new Error(`rename pre-fill: ${JSON.stringify(renameDialog.value)}`);
|
||||
if (
|
||||
renameDialog.helper !==
|
||||
"The server has no rename for a chat, so this name is kept on this device."
|
||||
"This name is shared with every device."
|
||||
) {
|
||||
throw new Error(`rename helper: ${renameDialog.helper}`);
|
||||
}
|
||||
@@ -8099,7 +8099,7 @@ try {
|
||||
// prompt then advances the server's updated_at past it.
|
||||
await page.fill("#chatInput", "Reply with exactly one word: hi");
|
||||
await page.evaluate(
|
||||
`document.querySelector("#chatInput").dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true, cancelable: true }))`,
|
||||
`document.querySelector("#chatInput").dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", ctrlKey: true, bubbles: true, cancelable: true }))`,
|
||||
);
|
||||
await page.waitForSelector("#chatStop", { timeout: 20000 });
|
||||
await page.click("#chatStop");
|
||||
|
||||
Reference in New Issue
Block a user