9381a6a9f7
* fix(scripts): launch dev-isolated backend via __backend subcommand The kandev binary became a bundle launcher with the restart supervisor (ADR 0019) and exits without KANDEV_BUNDLE_DIR when invoked bare; the isolated dev instance must run the backend entrypoint directly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * feat(mcp): session spawning, sibling messaging, and renameable tabs - spawn_session_kandev spawns an additional agent session on an existing task (default: the caller's own) via LaunchSession(IntentStart), with optional agent_profile_id (defaults to the spawner's profile) and a session name; the initial prompt carries spawner attribution and reply instructions. - message_task_kandev accepts an optional session_id to target a specific session, enabling same-task sibling messaging. Explicit targets are pinned through dispatch so the idle-path primary-session re-resolution cannot reroute a sibling message back to its sender (regression-tested). - task_sessions gains a name column (migration ordered after the agent_execution_id-drop rebuild), a session.rename WS action, and inline tab rename UI; custom names take precedence over derived agent/model labels across the tab, agents dropdown, mobile list, chat header, and dockview panel titles. - Inter-session messages stamp sender_session_name into metadata so the sender badge shows which session sent the message. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(mcp): address review findings on session spawn/rename/messaging - include name in task-session DTOs (list + full, no omitempty) so persisted tab names survive list hydration and clears propagate - sanitize sender task/session ids embedded in <kandev-system> blocks - reject cross-workspace spawn targets; require sender_task_id - truncate session names by runes, not bytes - distinguish not-found from internal errors in message target lookup - guard TabRenameInput blur-commit after Enter/Escape resolution - cap optimistic rename length client-side and toast on rename failure - add tests: spawn launch-failure and cross-workspace paths, renameSession API client Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(mcp): round-two review fixes for spawn/rename lint and hardening - extract spawn validation/authorization helpers (cyclop/nestif limits) - make stripSystemTag replace until stable to block nested tag evasion - load session before rename so a durable rename can never skip its broadcast; surface lookup failures to the caller instead - drop redundant sessionLauncher nil check (guarded registration) - add maxLength to the rename input matching the server cap - add tests: nested sanitizer evasion, spawn rename-failure tolerance Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Co-authored-by: Kandev Agent <agent@kandev.dev> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
149 lines
4.9 KiB
TypeScript
149 lines
4.9 KiB
TypeScript
import { fetchJson, type ApiRequestOptions } from "../client";
|
|
import type {
|
|
TaskSessionsResponse,
|
|
TaskSessionResponse,
|
|
ListMessagesResponse,
|
|
ListTurnsResponse,
|
|
} from "@/lib/types/http";
|
|
import { getWebSocketClient } from "@/lib/ws/connection";
|
|
|
|
export type MessageSearchHit = {
|
|
id: string;
|
|
turn_id?: string;
|
|
author_type: string;
|
|
type: string;
|
|
snippet: string;
|
|
created_at: string;
|
|
};
|
|
|
|
export type SearchMessagesResponse = {
|
|
hits: MessageSearchHit[];
|
|
total: number;
|
|
};
|
|
|
|
/** Search messages in a single session via WebSocket. */
|
|
export async function searchSessionMessages(
|
|
sessionId: string,
|
|
query: string,
|
|
limit = 50,
|
|
): Promise<SearchMessagesResponse> {
|
|
const client = getWebSocketClient();
|
|
if (!client) return { hits: [], total: 0 };
|
|
return client.request<SearchMessagesResponse>(
|
|
"message.search",
|
|
{ session_id: sessionId, query, limit },
|
|
10000,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Rename a session's tab label. Pass an empty string to clear the custom
|
|
* name and revert to the derived agent/model title. The backend broadcasts
|
|
* a session.state_changed event so every client picks up the new label.
|
|
*/
|
|
export async function renameSession(sessionId: string, name: string): Promise<void> {
|
|
const client = getWebSocketClient();
|
|
if (!client) throw new Error("WebSocket unavailable");
|
|
await client.request("session.rename", { session_id: sessionId, name });
|
|
}
|
|
|
|
// Session operations
|
|
export async function listTaskSessions(taskId: string, options?: ApiRequestOptions) {
|
|
return fetchJson<TaskSessionsResponse>(`/api/v1/tasks/${taskId}/sessions`, options);
|
|
}
|
|
|
|
export async function fetchTaskSession(taskSessionId: string, options?: ApiRequestOptions) {
|
|
return fetchJson<TaskSessionResponse>(`/api/v1/task-sessions/${taskSessionId}`, options);
|
|
}
|
|
|
|
export async function dismissLastAgentError(
|
|
taskSessionId: string,
|
|
stamp: string,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<TaskSessionResponse>(
|
|
`/api/v1/task-sessions/${taskSessionId}/last-agent-error/dismiss`,
|
|
{
|
|
...options,
|
|
init: { ...(options?.init ?? {}), method: "POST", body: JSON.stringify({ stamp }) },
|
|
},
|
|
);
|
|
}
|
|
|
|
export async function listTaskSessionMessages(
|
|
taskSessionId: string,
|
|
params?: { limit?: number; before?: string; after?: string; sort?: "asc" | "desc" },
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
const query = new URLSearchParams();
|
|
if (params?.limit) query.set("limit", params.limit.toString());
|
|
if (params?.before) query.set("before", params.before);
|
|
if (params?.after) query.set("after", params.after);
|
|
if (params?.sort) query.set("sort", params.sort);
|
|
const suffix = query.toString();
|
|
const url = `/api/v1/task-sessions/${taskSessionId}/messages${suffix ? `?${suffix}` : ""}`;
|
|
return fetchJson<ListMessagesResponse>(url, options);
|
|
}
|
|
|
|
export async function listSessionTurns(taskSessionId: string, options?: ApiRequestOptions) {
|
|
return fetchJson<ListTurnsResponse>(`/api/v1/task-sessions/${taskSessionId}/turns`, options);
|
|
}
|
|
|
|
export async function openSessionInEditor(
|
|
sessionId: string,
|
|
payload: Partial<{
|
|
editor_id: string;
|
|
editor_type: string;
|
|
file_path: string;
|
|
line: number;
|
|
column: number;
|
|
}>,
|
|
options?: ApiRequestOptions,
|
|
) {
|
|
return fetchJson<{ url?: string }>(`/api/v1/task-sessions/${sessionId}/open-editor`, {
|
|
...options,
|
|
init: { method: "POST", body: JSON.stringify(payload), ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function openSessionFolder(sessionId: string, options?: ApiRequestOptions) {
|
|
return fetchJson<{ success: boolean }>(`/api/v1/task-sessions/${sessionId}/open-folder`, {
|
|
...options,
|
|
init: { method: "POST", ...(options?.init ?? {}) },
|
|
});
|
|
}
|
|
|
|
export async function setSessionMode(sessionId: string, modeId: string) {
|
|
return fetchJson<{ ok: boolean }>(`/api/v1/task-sessions/${sessionId}/set-mode`, {
|
|
init: { method: "POST", body: JSON.stringify({ mode_id: modeId }) },
|
|
});
|
|
}
|
|
|
|
export async function setSessionModel(sessionId: string, modelId: string) {
|
|
return fetchJson<{ ok: boolean }>(`/api/v1/task-sessions/${sessionId}/set-model`, {
|
|
init: { method: "POST", body: JSON.stringify({ model_id: modelId }) },
|
|
});
|
|
}
|
|
|
|
export async function setSessionConfigOption(sessionId: string, configId: string, value: string) {
|
|
return fetchJson<{ ok: boolean }>(`/api/v1/task-sessions/${sessionId}/set-config-option`, {
|
|
init: { method: "POST", body: JSON.stringify({ config_id: configId, value }) },
|
|
});
|
|
}
|
|
|
|
export async function authenticateSession(sessionId: string, methodId: string) {
|
|
return fetchJson<{ ok: boolean }>(`/api/v1/task-sessions/${sessionId}/authenticate`, {
|
|
init: { method: "POST", body: JSON.stringify({ method_id: methodId }) },
|
|
});
|
|
}
|
|
|
|
export { launchSession, type LaunchSessionResponse } from "@/lib/services/session-launch-service";
|
|
export {
|
|
buildPRPrepareRequest,
|
|
buildPrepareRequest,
|
|
buildStartRequest,
|
|
buildStartCreatedRequest,
|
|
buildResumeRequest,
|
|
buildWorkflowStepRequest,
|
|
} from "@/lib/services/session-launch-helpers";
|