web: create a chat through the directory picker (C2)
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
// toolLongRunning (the chip and its panel)
|
||||
// ui/chat/ChatListFilter.kt sessionMatchesQuery, filterChatSessions,
|
||||
// groupChatSessionsByDirectory
|
||||
// ui/chat/ChatDirectories.kt HOME_DIRECTORY, directoryChoices,
|
||||
// defaultDirectoryChoice (the create picker)
|
||||
// ui/chat/ChatCreatePane.kt the create flow's wording, NewChatActions footer
|
||||
// and the create state transitions
|
||||
// ui/chat/ChatScroll.kt chatBottomDistancePx, chatFollowsAt,
|
||||
// chatShowJumpToLatest, chatOpensAtNewest,
|
||||
// chatFirstScroll
|
||||
@@ -114,6 +118,25 @@ export const CONVERSATION_EMPTY = "This chat has no messages yet. Ask something
|
||||
export const LOAD_OLDER_ACTION = "Load older messages";
|
||||
export const SELECT_CHAT_HINT = "Select a chat to open it.";
|
||||
|
||||
// The create flow (C2, ChatCreatePane.kt), verbatim. The home choice's row is
|
||||
// `Home (~)` while chat_create sends the `~` the server documents; the footer
|
||||
// names the value that will be sent (see chatStartInLabel).
|
||||
export const HOME_DIRECTORY = "~";
|
||||
export const HOME_LABEL = `Home (${HOME_DIRECTORY})`;
|
||||
export const CHAT_CREATE_TITLE = "Start a chat";
|
||||
export const CHAT_CREATE_BACK_LABEL = "Cancel new chat";
|
||||
export const CHAT_CREATE_LOADING = "Loading directories…";
|
||||
export const CHAT_CREATE_PROMPT = "Where should this chat live?";
|
||||
export const CHAT_CREATE_MODEL_NOTE =
|
||||
"This server has no request for choosing a chat's model, so a new chat uses the server's default.";
|
||||
export const CHAT_CREATE_CONFIRM = "New chat";
|
||||
export const CHAT_CREATE_CANCEL = "Cancel";
|
||||
|
||||
/** The create footer's line: `Start in {directory}` with the value that is sent. */
|
||||
export function chatStartInLabel(directory) {
|
||||
return `Start in ${str(directory)}`;
|
||||
}
|
||||
|
||||
/** The listing's narrowed-to-nothing message: `No chats match "{query}".` */
|
||||
export function chatNoMatchMessage(query) {
|
||||
return `No chats match "${str(query).trim()}".`;
|
||||
@@ -610,6 +633,78 @@ export function directoryLabel(directory) {
|
||||
return isBlank(directory) ? NO_DIRECTORY_LABEL : str(directory);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// The create flow's directory choices (ChatDirectories.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The picker's choices from the server's reported directories. The first entry is
|
||||
* the operator's home — the one entry the server always returns first — and the
|
||||
* rest keep the server's most-recently-used order. A blank entry is dropped, and a
|
||||
* reply with nothing in it still yields the home choice, so the picker is never
|
||||
* empty. A recent's `label` is its full path; only the home row carries the path
|
||||
* as `secondary`, because its own label is `Home (~)`.
|
||||
*/
|
||||
export function directoryChoices(directories) {
|
||||
const cleaned = (directories ?? []).map((entry) => str(entry)).filter((entry) => !isBlank(entry));
|
||||
const home = cleaned.length > 0 ? cleaned[0] : HOME_DIRECTORY;
|
||||
return [
|
||||
{
|
||||
label: HOME_LABEL,
|
||||
path: home,
|
||||
home: true,
|
||||
createDirectory: HOME_DIRECTORY,
|
||||
secondary: home,
|
||||
},
|
||||
...cleaned.slice(1).map((path) => ({
|
||||
label: path,
|
||||
path,
|
||||
home: false,
|
||||
createDirectory: path,
|
||||
secondary: null,
|
||||
})),
|
||||
];
|
||||
}
|
||||
|
||||
/** The choice a freshly opened picker starts on: home, first. */
|
||||
export function defaultDirectoryChoice(choices) {
|
||||
return (choices ?? [])[0] ?? null;
|
||||
}
|
||||
|
||||
/** A fresh create state: home selected, the caller's operation id, not sending. */
|
||||
export function newChatCreateState(operationId) {
|
||||
return {
|
||||
directory: HOME_DIRECTORY,
|
||||
operationId: str(operationId),
|
||||
creating: false,
|
||||
error: "",
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose one directory for the create. Kept pure so the view can re-render from a
|
||||
* single state object; the error a previous refusal left is cleared because it
|
||||
* described the old choice, not this one.
|
||||
*/
|
||||
export function selectChatDirectory(create, choice) {
|
||||
const directory =
|
||||
typeof choice === "string" ? choice : str(choice?.createDirectory ?? "");
|
||||
if (isBlank(directory)) return { ...create };
|
||||
return { ...create, directory, error: "" };
|
||||
}
|
||||
|
||||
/** The create failed: stop sending and keep the server's own reason in the pane. */
|
||||
export function chatCreateFailed(create, message) {
|
||||
return { ...create, creating: false, error: str(message) };
|
||||
}
|
||||
|
||||
/** The create succeeded: the new session goes to the head of the list, deduped by id. */
|
||||
export function chatCreateSucceeded(sessions, session) {
|
||||
const list = sessions ?? [];
|
||||
if (!session) return list;
|
||||
return [session, ...list.filter((entry) => entry?.id !== session.id)];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Transcript (ChatFormat.kt)
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user