Merge branch 'main' into web-run-live
# Conflicts: # web/test/ui-smoke.mjs
This commit is contained in:
+244
-10
@@ -2,7 +2,7 @@
|
||||
// Deliberately small and DOM-only (no framework, no build step). Every value
|
||||
// that came from the server is set with textContent, never innerHTML.
|
||||
import { PipelinesClient } from "./client.js";
|
||||
import { PipelinesRepository, SHELL_OUTPUT_LIMIT } from "./repository.js";
|
||||
import { PipelinesRepository, SHELL_OUTPUT_LIMIT, newChatOperationId } from "./repository.js";
|
||||
import { PROTOCOL_VERSION, Protocol, ChatKeys } from "./protocol.js";
|
||||
import { validateServerUrl, resolveArtifactUrl } from "./serverUrl.js";
|
||||
import {
|
||||
@@ -249,6 +249,13 @@ import {
|
||||
CHAT_COMMAND_DISMISS_LABEL,
|
||||
CHAT_COMMAND_GLYPH,
|
||||
CHAT_COMPOSER_PLACEHOLDER,
|
||||
CHAT_CREATE_BACK_LABEL,
|
||||
CHAT_CREATE_CANCEL,
|
||||
CHAT_CREATE_CONFIRM,
|
||||
CHAT_CREATE_LOADING,
|
||||
CHAT_CREATE_MODEL_NOTE,
|
||||
CHAT_CREATE_PROMPT,
|
||||
CHAT_CREATE_TITLE,
|
||||
CHAT_EMPTY,
|
||||
CHAT_FOLLOW_THRESHOLD_PX,
|
||||
CHAT_HIDE_ACTION,
|
||||
@@ -310,6 +317,8 @@ import {
|
||||
chatCommandEffect,
|
||||
chatCommandHelp,
|
||||
chatCommandSuggestions,
|
||||
chatCreateFailed,
|
||||
chatCreateSucceeded,
|
||||
chatFirstScroll,
|
||||
chatFollowsAt,
|
||||
chatHeaderMeta,
|
||||
@@ -317,6 +326,7 @@ import {
|
||||
chatNoticeLabel,
|
||||
chatOpensAtNewest,
|
||||
chatShowJumpToLatest,
|
||||
chatStartInLabel,
|
||||
chatStreamState,
|
||||
closeChatConfirmation,
|
||||
composerAction,
|
||||
@@ -325,6 +335,8 @@ import {
|
||||
composerSubmit,
|
||||
decodeChatOverrides,
|
||||
decodeChatSeen,
|
||||
defaultDirectoryChoice,
|
||||
directoryChoices,
|
||||
directoryLabel,
|
||||
dismissChatNotice as dismissChatNoticeModel,
|
||||
emptyChatOverrides,
|
||||
@@ -340,6 +352,7 @@ import {
|
||||
markChatUnseen,
|
||||
mergeHistoryPage,
|
||||
mergeShellFrame,
|
||||
newChatCreateState,
|
||||
newChatThread,
|
||||
parseChatInput,
|
||||
queuedAfterFrame,
|
||||
@@ -357,6 +370,7 @@ import {
|
||||
sessionChipLabel,
|
||||
sessionMeta,
|
||||
sessionStatusLabel,
|
||||
selectChatDirectory as selectChatDirectoryModel,
|
||||
sessionTitle,
|
||||
sessionWorkLabel,
|
||||
settledThread,
|
||||
@@ -568,6 +582,11 @@ const state = {
|
||||
// is set with textContent and the markdown renderer builds DOM nodes, never
|
||||
// innerHTML.
|
||||
chatSessions: [],
|
||||
// The verification chats this page itself created (C2's automation flag). The
|
||||
// server deliberately never lists them; the page keeps its own in-memory row so
|
||||
// the creator can keep working with the chat it just opened. The set is
|
||||
// memory-only, so a reload cannot turn one into a permanent list entry.
|
||||
chatEphemeralIds: new Set(),
|
||||
chatLoading: false,
|
||||
chatLoaded: false,
|
||||
chatError: "",
|
||||
@@ -616,6 +635,14 @@ const state = {
|
||||
// re-established for the open chat on reconnect. A refused subscription simply
|
||||
// never joins the set, so the badge reads "not live" honestly.
|
||||
chatSubscriptions: new Set(),
|
||||
// C2: the create flow. `chatCreate` is the ChatCreateState analogue (null until
|
||||
// the New chat entry point is used); the directory reply is cached so cancelling
|
||||
// and reopening does not re-ask, and a failed load keeps its own reason.
|
||||
chatDirectories: [],
|
||||
chatDirectoriesLoading: false,
|
||||
chatDirectoriesLoaded: false,
|
||||
chatDirectoriesError: "",
|
||||
chatCreate: null,
|
||||
};
|
||||
|
||||
// The app-wide run-event watch (R10), owned by the connection rather than any
|
||||
@@ -1222,7 +1249,9 @@ function renderContent() {
|
||||
} else if (state.view === "runs") {
|
||||
split.append(renderRunList(), renderRunDetail());
|
||||
} else if (state.view === "chat") {
|
||||
split.append(renderChatList(), renderChatConversation());
|
||||
// While the create flow is open it owns the detail pane; the session list
|
||||
// stays visible beside it, exactly as the app's two-pane chat stack does.
|
||||
split.append(renderChatList(), state.chatCreate ? renderChatCreate() : renderChatConversation());
|
||||
} else {
|
||||
split.append(renderTemplateGallery(), renderTemplateDetail());
|
||||
}
|
||||
@@ -4264,7 +4293,15 @@ async function loadChatSessions(force = false) {
|
||||
state.chatError = "";
|
||||
renderContent();
|
||||
try {
|
||||
state.chatSessions = await repo.chatSessions();
|
||||
const listed = await repo.chatSessions();
|
||||
// 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.
|
||||
const held = state.chatSessions.filter(
|
||||
(session) =>
|
||||
state.chatEphemeralIds.has(session.id) && !listed.some((entry) => entry.id === session.id),
|
||||
);
|
||||
state.chatSessions = [...held, ...listed];
|
||||
state.chatLoaded = true;
|
||||
// Fold this device's seen state in: the active chat has been read, and every
|
||||
// session seen for the first time gets a baseline so pre-existing chats are
|
||||
@@ -4277,6 +4314,85 @@ async function loadChatSessions(force = false) {
|
||||
renderContent();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The create flow (C2, ChatCreatePane.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Open the create pane with a fresh operation id. The id is minted once per
|
||||
* intent, so a retry after a refusal reuses it and the server can dedupe the
|
||||
* create rather than starting a second session.
|
||||
*/
|
||||
function startNewChat() {
|
||||
state.chatCreate = newChatCreateState(newChatOperationId());
|
||||
state.chatDirectoriesError = "";
|
||||
renderContent();
|
||||
loadChatDirectories();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch `chat_directories` for the open picker. A failure keeps the reason for the
|
||||
* pane's error state; blank entries are dropped here as well as in the pure model
|
||||
* so a malformed reply can never produce an empty row. An already-loaded list is
|
||||
* reused unless [force] (the error state's Retry) asks again.
|
||||
*/
|
||||
async function loadChatDirectories(force = false) {
|
||||
if (!state.chatCreate || state.chatDirectoriesLoading) return;
|
||||
if (state.chatDirectoriesLoaded && !force) return;
|
||||
state.chatDirectoriesLoading = true;
|
||||
state.chatDirectoriesError = "";
|
||||
renderContent();
|
||||
try {
|
||||
const directories = await repo.chatDirectories();
|
||||
state.chatDirectories = (directories ?? []).filter((entry) => String(entry ?? "").trim() !== "");
|
||||
state.chatDirectoriesLoaded = true;
|
||||
} catch (error) {
|
||||
state.chatDirectoriesError = describeError(error);
|
||||
}
|
||||
state.chatDirectoriesLoading = false;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** Select one directory row (the value is what chat_create will send). */
|
||||
function selectChatDirectory(value) {
|
||||
if (!state.chatCreate) return;
|
||||
state.chatCreate = selectChatDirectoryModel(state.chatCreate, value);
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/** Leave the create flow without creating anything. */
|
||||
function cancelNewChat() {
|
||||
state.chatCreate = null;
|
||||
renderContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the chat in the chosen directory. Guarded against a double submit: the
|
||||
* guard reads the held state, so a second click while the request is in flight
|
||||
* sends nothing. On success the pane closes, the created session goes to the head
|
||||
* of the list, becomes the open conversation and loads its (empty) history; on
|
||||
* failure the server's own reason stays in the pane, which does not close.
|
||||
*/
|
||||
async function createNewChat() {
|
||||
const create = state.chatCreate;
|
||||
if (!create || create.creating) return;
|
||||
state.chatCreate = { ...create, creating: true, error: "" };
|
||||
renderContent();
|
||||
try {
|
||||
// Not ephemeral: this is the operator's own create path (the UI smoke uses the
|
||||
// same path for its one real session and closes it afterwards).
|
||||
const created = await repo.chatCreate("New chat", create.directory, create.operationId);
|
||||
state.chatCreate = null;
|
||||
state.chatSessions = chatCreateSucceeded(state.chatSessions, created);
|
||||
await openChatSession(created.id);
|
||||
await loadChatSessions();
|
||||
} catch (error) {
|
||||
if (!state.chatCreate) return;
|
||||
state.chatCreate = chatCreateFailed(state.chatCreate, describeError(error));
|
||||
renderContent();
|
||||
}
|
||||
}
|
||||
|
||||
/** Open a session: select it, subscribe its stream and load its newest history page. */
|
||||
async function openChatSession(id) {
|
||||
if (state.chatActiveId === id && state.chatThreads.get(id)?.loaded) return;
|
||||
@@ -5020,9 +5136,9 @@ async function startChatSession(directory) {
|
||||
// An automated check (the UI smoke) can mark its throwaway chat ephemeral, so
|
||||
// creating one for verification never adds a stray "New chat" to the
|
||||
// operator's list. Set only by test tooling; a normal page leaves it unset.
|
||||
const created = await repo.chatCreate("New chat", directory, undefined, {
|
||||
ephemeral: globalThis.__pipelinesEphemeralChat === true,
|
||||
});
|
||||
const ephemeral = globalThis.__pipelinesEphemeralChat === true;
|
||||
const created = await repo.chatCreate("New chat", directory, undefined, { ephemeral });
|
||||
if (ephemeral) state.chatEphemeralIds = new Set(state.chatEphemeralIds).add(created.id);
|
||||
// The list is the server's; insert the created session so the row is present
|
||||
// before the conversation opens, then refresh from the server.
|
||||
state.chatSessions = [created, ...state.chatSessions.filter((s) => s.id !== created.id)];
|
||||
@@ -5212,6 +5328,14 @@ function renderChatList() {
|
||||
fillChatRows(rows);
|
||||
},
|
||||
}),
|
||||
// C2: the create path stays one tap away while the list is narrowed, the same
|
||||
// trailing action the app keeps beside its search control.
|
||||
h("button", {
|
||||
class: "ghost chat-new",
|
||||
type: "button",
|
||||
text: CHAT_NEW_ACTION,
|
||||
onclick: startNewChat,
|
||||
}),
|
||||
);
|
||||
list.append(toolbar);
|
||||
const rows = h("div", { id: "chatRows", class: "chat-rows" });
|
||||
@@ -5254,16 +5378,13 @@ function fillChatRows(rows) {
|
||||
return;
|
||||
}
|
||||
if (filtered.length === 0) {
|
||||
// The create path is the C2 item; the action is shown but deliberately not
|
||||
// wired here, exactly as the item says.
|
||||
const empty = chatEmpty(CHAT_EMPTY);
|
||||
empty.append(
|
||||
h("button", {
|
||||
class: "ghost chat-new",
|
||||
type: "button",
|
||||
text: CHAT_NEW_ACTION,
|
||||
disabled: true,
|
||||
title: "Creating a chat lands with the C2 item",
|
||||
onclick: startNewChat,
|
||||
}),
|
||||
);
|
||||
rows.append(empty);
|
||||
@@ -5351,6 +5472,119 @@ function renderChatRow(session) {
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* The create pane (C2): the app's NewChatPane. A back control leaves without
|
||||
* creating, then the directory error / loading / picker states in the app's own
|
||||
* order, the model note and the footer naming the value that will be sent. Every
|
||||
* server string is set with textContent.
|
||||
*/
|
||||
function renderChatCreate() {
|
||||
const create = state.chatCreate;
|
||||
const pane = h("div", { class: "detail chat-detail chat-create" });
|
||||
|
||||
const bar = h("div", { class: "chat-bar chat-create-bar" });
|
||||
bar.append(
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
class: "ghost chat-create-back",
|
||||
type: "button",
|
||||
"aria-label": CHAT_CREATE_BACK_LABEL,
|
||||
title: CHAT_CREATE_BACK_LABEL,
|
||||
onclick: cancelNewChat,
|
||||
},
|
||||
h("span", { class: "chat-create-back-glyph", "aria-hidden": "true", text: "←" }),
|
||||
),
|
||||
h("h2", { class: "chat-bar-title chat-create-title", text: CHAT_CREATE_TITLE }),
|
||||
);
|
||||
pane.append(bar);
|
||||
|
||||
if (state.chatDirectoriesError && !state.chatDirectoriesLoaded) {
|
||||
const empty = chatEmpty(state.chatDirectoriesError);
|
||||
empty.classList.add("chat-create-directories-error");
|
||||
empty.append(
|
||||
h("button", {
|
||||
class: "ghost chat-create-retry",
|
||||
type: "button",
|
||||
text: "Retry",
|
||||
onclick: () => loadChatDirectories(true),
|
||||
}),
|
||||
);
|
||||
pane.append(empty);
|
||||
} else if (!state.chatDirectoriesLoaded) {
|
||||
pane.append(h("div", { class: "chat-create-loading muted", text: CHAT_CREATE_LOADING }));
|
||||
} else {
|
||||
pane.append(h("div", { class: "chat-create-prompt muted", text: CHAT_CREATE_PROMPT }));
|
||||
|
||||
const choices = directoryChoices(state.chatDirectories);
|
||||
const selected =
|
||||
choices.find((choice) => choice.createDirectory === create.directory) ??
|
||||
defaultDirectoryChoice(choices);
|
||||
const list = h("div", {
|
||||
class: "chat-create-choices",
|
||||
role: "listbox",
|
||||
"aria-label": CHAT_CREATE_PROMPT,
|
||||
});
|
||||
for (const choice of choices) {
|
||||
const active = choice.createDirectory === selected?.createDirectory;
|
||||
const row = h("button", {
|
||||
class: `row chat-create-choice${active ? " selected" : ""}`,
|
||||
type: "button",
|
||||
role: "option",
|
||||
"aria-selected": active ? "true" : "false",
|
||||
"data-directory": choice.createDirectory,
|
||||
onclick: () => selectChatDirectory(choice.createDirectory),
|
||||
});
|
||||
row.append(h("span", { class: "row-title chat-create-choice-label", text: choice.label }));
|
||||
if (choice.secondary) {
|
||||
row.append(h("span", { class: "row-meta chat-create-choice-path", text: choice.secondary }));
|
||||
}
|
||||
list.append(row);
|
||||
}
|
||||
pane.append(list);
|
||||
|
||||
// A refresh that failed after a successful first load keeps the choices and
|
||||
// says why the list may be stale (the app's own bodySmall error line).
|
||||
if (state.chatDirectoriesError) {
|
||||
pane.append(h("div", { class: "chat-create-directories-error", text: state.chatDirectoriesError }));
|
||||
}
|
||||
if (create.error) {
|
||||
pane.append(h("div", { class: "chat-create-error", text: create.error }));
|
||||
}
|
||||
pane.append(h("p", { class: "chat-create-model-note muted", text: CHAT_CREATE_MODEL_NOTE }));
|
||||
|
||||
const directory = selected?.createDirectory ?? create.directory;
|
||||
const footer = h("div", { class: "chat-create-footer" });
|
||||
footer.append(h("span", { class: "chat-create-start", text: chatStartInLabel(directory) }));
|
||||
footer.append(
|
||||
h("button", {
|
||||
class: "ghost chat-create-cancel",
|
||||
type: "button",
|
||||
text: CHAT_CREATE_CANCEL,
|
||||
disabled: create.creating,
|
||||
onclick: cancelNewChat,
|
||||
}),
|
||||
);
|
||||
const confirm = h("button", {
|
||||
class: "chat-create-confirm",
|
||||
type: "button",
|
||||
"aria-label": CHAT_CREATE_CONFIRM,
|
||||
disabled: create.creating,
|
||||
onclick: createNewChat,
|
||||
});
|
||||
if (create.creating) {
|
||||
confirm.append(h("span", { class: "spinner chat-create-spinner", "aria-hidden": "true" }));
|
||||
} else {
|
||||
confirm.append(document.createTextNode(CHAT_CREATE_CONFIRM));
|
||||
}
|
||||
footer.append(confirm);
|
||||
pane.append(footer);
|
||||
}
|
||||
|
||||
appendChatDialogs(pane);
|
||||
return pane;
|
||||
}
|
||||
|
||||
/**
|
||||
* One row's Chat actions menu, with Android's items in its order: Rename…, then
|
||||
* Close chat… (open) or Reopen (closed), then Hide on this device. Closing is the
|
||||
|
||||
Reference in New Issue
Block a user